Project
Loading...
Searching...
No Matches
Helpers.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
21#include "CCDB/CcdbApi.h"
22
23#include "Math/GenVector/Cartesian3D.h"
24#include "TGLRnrCtx.h"
25#include "TGLViewer.h"
26#include "TGeoManager.h"
27#include "TGeoVolume.h"
28#include "TH2F.h"
29#include "TFile.h"
30#include "TPRegexp.h"
31#include "TVirtualPad.h"
32#include <iostream>
33
34namespace o2
35{
36namespace mch
37{
38namespace test
39{
40
41TGeoVolume* createAirVacuumCave(const char* name)
42{
43 // create the air medium (only used for the geometry test)
45
46 const int nAir = 4;
47 Float_t aAir[nAir] = {12.0107, 14.0067, 15.9994, 39.948};
48 Float_t zAir[nAir] = {6., 7., 8., 18.};
49 Float_t wAir[nAir] = {0.000124, 0.755267, 0.231781, 0.012827};
50 Float_t dAirVacuum = 1.20479E-10;
51 const int kID = 90; // to avoid conflicts with definitions of other MCH materials
52
53 mgr.Mixture("MCH", kID, "Air", aAir, zAir, dAirVacuum, nAir, wAir);
54 mgr.Medium("MCH", kID, "Air", kID,
55 false, /* isvol */
56 0, /* ifield */
57 -1.0, /* fieldm */
58 -1.0, /* tmaxfd */
59 -1.0, /* stemax */
60 -1.0, /* deemax */
61 -1.0, /* epsil */
62 -1.0 /* stmin */);
63 return gGeoManager->MakeBox(name, gGeoManager->GetMedium("MCH_Air"), 2000.0, 2000.0, 3000.0);
64}
65
66void dump(std::ostream& out, const TGeoNode& n, int level, int maxdepth, std::string prefix)
67{
68 if (level >= maxdepth) {
69 return;
70 }
71
72 if (level == 0) {
73 out << n.GetName() << "\n";
74 }
75
76 if (level < maxdepth) {
77 for (int i = 0; i < n.GetNdaughters(); i++) {
78 TGeoNode* d = n.GetDaughter(i);
79 if (i == n.GetNdaughters() - 1) {
80 out << prefix + "└──" << d->GetName()
81 << "\n";
82 dump(out, *d, level + 1, maxdepth, prefix + " ");
83 } else {
84 out << prefix + "├──" << d->GetName()
85 << "\n";
86 dump(out, *d, level + 1, maxdepth, prefix + "│ ");
87 }
88 }
89 }
90}
91
92void showGeometryAsTextTree(const char* fromPath, int maxdepth, std::ostream& out)
93{
94 if (!gGeoManager) {
95 return;
96 }
97
98 TGeoNavigator* nav = gGeoManager->GetCurrentNavigator();
99
100 if (strlen(fromPath)) {
101 if (!nav->cd(fromPath)) {
102 std::cerr << "Could not get path " << fromPath << "\n";
103 return;
104 }
105 }
106
107 TGeoNode* node = nav->GetCurrentNode();
108
109 dump(out, *node, 0, maxdepth, "");
110}
111
113{
114 if (gGeoManager && gGeoManager->GetTopVolume()) {
115 std::cerr << "Can only call this function with an empty geometry, i.e. gGeoManager==nullptr "
116 << " or gGeoManager->GetTopVolume()==nullptr\n";
117 }
118 TGeoManager* g = new TGeoManager("MCH-ONLY", "ALICE MCH Standalone Geometry");
119 TGeoVolume* top = createAirVacuumCave("cave");
120 g->SetTopVolume(top);
122}
123
124void addAlignableVolumes()
125{
126 if (!gGeoManager) {
127 std::cerr << "gGeoManager == nullptr, must create a geometry first\n";
128 return;
129 }
130 // If not closed, we need to close it
131 if (!gGeoManager->IsClosed()) {
132 gGeoManager->CloseGeometry();
133 }
134 // Then add the alignable volumes
136}
137
138void zeroMisAlignGeometry(const std::string& ccdbHost, const std::string& fileName)
139{
140 // create a regular geometry
142 if (!gGeoManager) {
143 std::cerr << "gGeoManager == nullptr, must create a geometry first\n";
144 return;
145 }
146 // If not closed, we need to close it
147 if (!gGeoManager->IsClosed()) {
148 gGeoManager->CloseGeometry();
149 }
150 // Then add the alignable volumes
151 addAlignableVolumes();
152
153 std::vector<o2::detectors::AlignParam> params;
154
155 // The misaligner
158
159 o2::detectors::DetID detMCH("MCH");
160
161 long tmin = 0;
162 long tmax = -1;
163 const std::string& objectPath = "";
164
165 if (!ccdbHost.empty()) {
166 std::string path = objectPath.empty() ? o2::base::DetectorNameConf::getAlignmentPath(detMCH) : objectPath;
167 LOGP(info, "Storing alignment object on {}/{}", ccdbHost, path);
169 std::map<std::string, std::string> metadata; // can be empty
170 api.init(ccdbHost.c_str()); // or http://localhost:8080 for a local installation
171 // store abitrary user object in strongly typed manner
172 api.storeAsTFileAny(&params, path, metadata, tmin, tmax);
173 }
174
175 if (!fileName.empty()) {
176 LOGP(info, "Storing MCH alignment in local file {}", fileName);
177 TFile algFile(fileName.c_str(), "recreate");
178 algFile.WriteObjectAny(&params, "std::vector<o2::detectors::AlignParam>", "alignment");
179 algFile.Close();
180 }
181}
182
184{
185 if (!gGeoManager) {
186 std::cerr << "gGeoManager == nullptr, must create a geometry first\n";
187 return;
188 }
189 // If not closed, we need to close it
190 if (!gGeoManager->IsClosed()) {
191 gGeoManager->CloseGeometry();
192 }
193 // Check for Alignable Volumes?
194 // addAlignableVolumes();
195
196 std::vector<o2::detectors::AlignParam> params;
197
198 // The misaligner
200 aGMA.setModuleCartMisAlig(0.1, 0., 0.2, 0., 0.3, 0.);
201 aGMA.setModuleAngMisAlig(0.0, 0., 0., 0., 0., 0.);
202 aGMA.setCartMisAlig(0.01, 0., 0.02, 0., 0.03, 0.);
203 aGMA.setAngMisAlig(0.0, 0.0, 0., 0., 0., 0.);
205}
206
207void setVolumeVisibility(const char* pattern, bool visible, bool visibleDaughters)
208{
209 TPRegexp re(pattern);
210 TIter next(gGeoManager->GetListOfVolumes());
211 TGeoVolume* vol;
212
213 while ((vol = static_cast<TGeoVolume*>(next()))) {
214 if (TString(vol->GetName()).Contains(re)) {
215 vol->SetVisibility(visible);
216 vol->SetVisDaughters(visibleDaughters);
217 }
218 }
219}
220
221void setVolumeColor(const char* pattern, int lineColor, int fillColor)
222{
223 TPRegexp re(pattern);
224 TIter next(gGeoManager->GetListOfVolumes());
225 TGeoVolume* vol;
226
227 while ((vol = static_cast<TGeoVolume*>(next()))) {
228 if (TString(vol->GetName()).Contains(re)) {
229 vol->SetFillColor(fillColor);
230 vol->SetLineColor(lineColor);
231 }
232 }
233}
234
236{
237 gGeoManager->SetVisLevel(4);
238
239 setVolumeVisibility("cave", false, true);
240
241 // Hide to half-chamber top volumes
242 setVolumeVisibility("^SC", false, true);
243
244 // Hide St345 support panels
245 setVolumeVisibility("support panel", false, false);
246
247 // Hide St345 LV wires
248 setVolumeVisibility(" LV ", false, false);
249
250 // Make St345 carbon panels dark gray
251 setVolumeColor("panel carbon", kGray + 3);
252
253 // Make St345 insulators dark green
254 setVolumeColor("insulator", kGreen + 3);
255
256 // Hide most of St1
257 setVolumeVisibility("SQ", false, true);
258
259 // Only reveal gas module
260 setVolumeVisibility("SA", true, true);
261 setVolumeColor("SA", kCyan - 10);
262}
263
265{
266 // minimal macro to test setup of the geometry
267
269
271
272 gGeoManager->GetTopVolume()->Draw("ogl");
273
274 TGLViewer* gl = static_cast<TGLViewer*>(gPad->GetViewer3D("ogl"));
275 TGLCamera& c = gl->CurrentCamera();
276
277 // gl->SetStyle(TGLRnrCtx::kWireFrame);
278 gl->SetStyle(TGLRnrCtx::kOutline);
279 // gl->SetStyle(TGLRnrCtx::kFill);
280}
281
282o2::base::GeometryManager::MatBudgetExt getMatBudgetExt(const o2::math_utils::Transform3D& t, math_utils::Vector3D<double>& n, float x, float y, float thickness)
283{
284 math_utils::Point3D<double> point;
285 t.LocalToMaster(math_utils::Point3D<double>{x, y, 0}, point);
286 return o2::base::GeometryManager::meanMaterialBudgetExt(math_utils::Point3D<double>{point + n * thickness / 2.0}, math_utils::Point3D<double>{point - n * thickness / 2.0});
287}
288
290{
291 os << "L=" << m.length << " <Rho>=" << m.meanRho << " <A>=" << m.meanA
292 << " <Z>=" << m.meanZ << " <x/x0>=" << m.meanX2X0 << " nCross=" << m.nCross;
293 return os;
294}
295
296math_utils::Vector3D<double> getNormalVector(const o2::math_utils::Transform3D& t)
297{
298 math_utils::Point3D<double> px, py, po;
299 t.LocalToMaster(math_utils::Point3D<double>{0, 1, 0}, py);
300 t.LocalToMaster(math_utils::Point3D<double>{1, 0, 0}, px);
301 t.LocalToMaster(math_utils::Point3D<double>{0, 0, 0}, po);
302 math_utils::Vector3D<double> a{px - po};
303 math_utils::Vector3D<double> b{py - po};
304 return a.Cross(b).Unit();
305}
306
307TH2* getRadio(int detElemId, float xmin, float ymin, float xmax, float ymax, float xstep, float ystep, float thickness)
308{
309 if (xmin >= xmax || ymin >= ymax) {
310 std::cerr << "incorrect limits\n";
311 return nullptr;
312 }
313 TH2* hmatb = new TH2F("hmatb", "hmatb", (int)((xmax - xmin) / xstep), xmin, xmax, (int)((ymax - ymin) / ystep), ymin, ymax);
314
316 auto t = transformation(detElemId);
317
318 auto normal = getNormalVector(t);
319
320 for (auto x = xmin; x < xmax; x += xstep) {
321 for (auto y = ymin; y < ymax; y += ystep) {
322 auto matb = getMatBudgetExt(t, normal, x, y, thickness);
323 if (std::isfinite(matb.meanX2X0)) {
324 hmatb->Fill(x, y, matb.meanX2X0);
325 }
326 }
327 }
328 return hmatb;
329}
330} // namespace test
331} // namespace mch
332} // namespace o2
Definition of the base alignment parameters class.
Definition of the Names Generator class.
Definition of the GeometryManager class.
std::unique_ptr< expressions::Node > node
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
Interface for MCH geometry creation.
void createStandaloneGeometry(const char *name)
uint32_t c
Definition RawData.h:2
static std::string getAlignmentPath(DId d)
static MatBudgetExt meanMaterialBudgetExt(float x0, float y0, float z0, float x1, float y1, float z1)
static MaterialManager & Instance()
int storeAsTFileAny(const T *obj, std::string const &path, std::map< std::string, std::string > const &metadata, long startValidityTimestamp=-1, long endValidityTimestamp=-1, std::vector< char >::size_type maxSize=0) const
Definition CcdbApi.h:163
void init(std::string const &hosts)
Definition CcdbApi.cxx:240
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:60
void setCartMisAlig(double xmean, double xwidth, double ymean, double ywidth, double zmean=0., double zwidth=0.)
Set cartesian displacement parameters different along x, y.
Definition MisAligner.h:54
void setModuleAngMisAlig(double xmean, double xwidth, double ymean, double ywidth, double zmean, double zwidth)
Set module (half chambers) cartesian displacement parameters.
Definition MisAligner.h:114
void setModuleCartMisAlig(double xmean, double xwidth, double ymean, double ywidth, double zmean, double zwidth)
Set module (half chambers) cartesian displacement parameters.
Definition MisAligner.h:103
void misAlign(std::vector< o2::detectors::AlignParam > &arr, bool verbose=false) const
void setAngMisAlig(double zmean, double zwidth, double xmean=0., double xwidth=0., double ymean=0., double ywidth=0.)
Set angular displacement.
Definition MisAligner.h:74
void dump(const std::string what, DPMAP m, int verbose)
Definition dcs-ccdb.cxx:79
GLboolean GLboolean g
Definition glcorearb.h:1233
GLdouble n
Definition glcorearb.h:1982
GLint GLenum GLint x
Definition glcorearb.h:403
const GLfloat * m
Definition glcorearb.h:4066
GLdouble GLdouble GLdouble GLdouble top
Definition glcorearb.h:4077
GLuint const GLchar * name
Definition glcorearb.h:781
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLint y
Definition glcorearb.h:270
GLenum const GLfloat * params
Definition glcorearb.h:272
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
GLint level
Definition glcorearb.h:275
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
void addAlignableVolumes(TGeoManager &geom)
Definition Geometry.cxx:99
TransformationCreator transformationFromTGeoManager(const TGeoManager &geo)
void createGeometry(TGeoManager &geom, TGeoVolume &topVolume)
Definition Geometry.cxx:74
TH2 * getRadio(int detElemId, float xmin, float ymin, float xmax, float ymax, float xstep, float ystep, float thickness)
get a radlen radiograph of a given detection element within box with the given granularity
Definition Helpers.cxx:307
void setVolumeVisibility(const char *pattern, bool visible, bool visibleDaughters)
set the volume and daughter visibility for all volumes with a name matching the regexp pattern
Definition Helpers.cxx:207
TGeoVolume * createAirVacuumCave(const char *name)
Definition Helpers.cxx:41
void setVolumeColor(const char *pattern, int lineColor, int fillColor)
set the volume line and fill for all volumes with a name matching the regexp pattern
Definition Helpers.cxx:221
void showGeometryAsTextTree(const char *fromPath, int maxdepth, std::ostream &out)
tree like textual dump of the geometry nodes
Definition Helpers.cxx:92
math_utils::Vector3D< double > getNormalVector(const o2::math_utils::Transform3D &t)
Definition Helpers.cxx:296
o2::base::GeometryManager::MatBudgetExt getMatBudgetExt(const o2::math_utils::Transform3D &t, math_utils::Vector3D< double > &n, float x, float y, float thickness)
Definition Helpers.cxx:282
void misAlignGeometry()
generates misalignments for MCH geometry
Definition Helpers.cxx:183
void drawGeometry()
basic drawing of the geometry
Definition Helpers.cxx:264
void zeroMisAlignGeometry(const std::string &ccdbHost, const std::string &fileName)
generates zero misalignments for MCH geometry
Definition Helpers.cxx:138
void drawOptionPresetBasic()
Definition Helpers.cxx:235
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::ostream & operator<<(std::ostream &stream, o2::InteractionRecord const &ir)
FIXME: do not use data model tables.
o2::mch::geo::MisAligner aGMA
auto transformation
o2::math_utils::Point3D< double > po
std::array< uint16_t, 5 > pattern