]>
Commit | Line | Data |
---|---|---|
67dd5535 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | //------------------------------------------------------------------------- | |
16 | // Implementation of AliGeomManager, the geometry manager class | |
17 | // which interfaces to TGeo and the look-up table mapping unique | |
18 | // volume indices to symbolic volume names. For that it collects | |
19 | // several static methods. | |
20 | //------------------------------------------------------------------------- | |
21 | ||
22 | #include <TClass.h> | |
23 | #include <TFile.h> | |
24 | #include <TGeoManager.h> | |
25 | #include <TObjString.h> | |
26 | #include <TGeoPhysicalNode.h> | |
27 | #include <TClonesArray.h> | |
28 | #include <TGeoMatrix.h> | |
29 | #include <TGeoPhysicalNode.h> | |
99de26a3 | 30 | #include <TSystem.h> |
67dd5535 | 31 | |
32 | #include "AliGeomManager.h" | |
33 | #include "AliLog.h" | |
34 | #include "AliAlignObj.h" | |
90dbf5fb | 35 | #include "AliAlignObjParams.h" |
67dd5535 | 36 | #include "AliCDBManager.h" |
37 | #include "AliCDBStorage.h" | |
38 | #include "AliCDBEntry.h" | |
39 | ||
40 | ClassImp(AliGeomManager) | |
41 | ||
42 | Int_t AliGeomManager::fgLayerSize[kLastLayer - kFirstLayer] = { | |
43 | 80, 160, // ITS SPD first and second layer | |
44 | 84, 176, // ITS SDD first and second layer | |
45 | 748, 950, // ITS SSD first and second layer | |
46 | 36, 36, // TPC inner and outer chambers | |
47 | 90, 90, 90, 90, 90, 90, // 6 TRD chambers' layers | |
48 | 1638, // TOF | |
df117114 | 49 | 5, 5, // PHOS,CPV |
67dd5535 | 50 | 7, // HMPID ?? |
3dfc15c0 | 51 | 1, // MUON ?? |
52 | 12 // EMCAL | |
67dd5535 | 53 | }; |
54 | ||
55 | const char* AliGeomManager::fgLayerName[kLastLayer - kFirstLayer] = { | |
56 | "ITS inner pixels layer", "ITS outer pixels layer", | |
57 | "ITS inner drifts layer", "ITS outer drifts layer", | |
58 | "ITS inner strips layer", "ITS outer strips layer", | |
59 | "TPC inner chambers layer", "TPC outer chambers layer", | |
60 | "TRD chambers layer 1", "TRD chambers layer 2", "TRD chambers layer 3", | |
61 | "TRD chambers layer 4", "TRD chambers layer 5", "TRD chambers layer 6", | |
62 | "TOF layer", | |
df117114 | 63 | "PHOS EMC layer","PHOS CPV layer", |
3dfc15c0 | 64 | "HMPID layer", |
65 | "MUON ?", | |
66 | "EMCAL layer" | |
67dd5535 | 67 | }; |
68 | ||
69 | TString* AliGeomManager::fgSymName[kLastLayer - kFirstLayer] = { | |
70 | 0x0,0x0, | |
71 | 0x0,0x0, | |
72 | 0x0,0x0, | |
73 | 0x0,0x0, | |
74 | 0x0,0x0,0x0, | |
75 | 0x0,0x0,0x0, | |
76 | 0x0, | |
77 | 0x0,0x0, | |
78 | 0x0, | |
3dfc15c0 | 79 | 0x0, |
67dd5535 | 80 | 0x0 |
81 | }; | |
82 | ||
83 | TGeoPNEntry** AliGeomManager::fgPNEntry[kLastLayer - kFirstLayer] = { | |
84 | 0x0,0x0, | |
85 | 0x0,0x0, | |
86 | 0x0,0x0, | |
87 | 0x0,0x0, | |
88 | 0x0,0x0,0x0, | |
89 | 0x0,0x0,0x0, | |
90 | 0x0, | |
91 | 0x0,0x0, | |
92 | 0x0, | |
3dfc15c0 | 93 | 0x0, |
67dd5535 | 94 | 0x0 |
95 | }; | |
96 | ||
36b010bf | 97 | TGeoHMatrix** AliGeomManager::fgOrigMatrix[kLastLayer - kFirstLayer] = { |
67dd5535 | 98 | 0x0,0x0, |
99 | 0x0,0x0, | |
100 | 0x0,0x0, | |
101 | 0x0,0x0, | |
102 | 0x0,0x0,0x0, | |
103 | 0x0,0x0,0x0, | |
104 | 0x0, | |
105 | 0x0,0x0, | |
106 | 0x0, | |
3dfc15c0 | 107 | 0x0, |
67dd5535 | 108 | 0x0 |
109 | }; | |
110 | ||
36b010bf | 111 | AliAlignObj** AliGeomManager::fgAlignObjs[kLastLayer - kFirstLayer] = { |
112 | 0x0,0x0, | |
113 | 0x0,0x0, | |
114 | 0x0,0x0, | |
115 | 0x0,0x0, | |
116 | 0x0,0x0,0x0, | |
117 | 0x0,0x0,0x0, | |
118 | 0x0, | |
119 | 0x0,0x0, | |
120 | 0x0, | |
3dfc15c0 | 121 | 0x0, |
36b010bf | 122 | 0x0 |
123 | }; | |
67dd5535 | 124 | |
125 | TGeoManager* AliGeomManager::fgGeometry = 0x0; | |
126 | ||
127 | //_____________________________________________________________________________ | |
36b010bf | 128 | void AliGeomManager::LoadGeometry(const char *geomFileName) |
67dd5535 | 129 | { |
9d47e237 | 130 | // initialization |
131 | // Load geometry either from a file | |
132 | // or from the corresponding CDB entry | |
67dd5535 | 133 | |
36b010bf | 134 | fgGeometry = NULL; |
135 | if (geomFileName && (!gSystem->AccessPathName(geomFileName))) { // gemotry.root exists | |
136 | fgGeometry = TGeoManager::Import(geomFileName); | |
137 | AliInfoClass("Using custom geometry.root file"); | |
138 | } | |
139 | ||
140 | if (!fgGeometry) { | |
141 | AliInfoClass("Using geometry from CDB"); | |
142 | ||
143 | AliCDBPath path("GRP","Geometry","Data"); | |
144 | ||
145 | AliCDBEntry *entry=AliCDBManager::Instance()->Get(path.GetPath()); | |
146 | if(!entry) AliFatalClass("Couldn't load geometry data from CDB!"); | |
147 | ||
148 | entry->SetOwner(0); | |
149 | fgGeometry = (TGeoManager*) entry->GetObject(); | |
150 | if (!fgGeometry) AliFatalClass("Couldn't find TGeoManager in the specified CDB entry!"); | |
151 | } | |
67dd5535 | 152 | |
67dd5535 | 153 | InitSymNamesLUT(); |
154 | InitPNEntriesLUT(); | |
36b010bf | 155 | InitOrigMatricesLUT(); |
67dd5535 | 156 | } |
157 | ||
9d47e237 | 158 | //_____________________________________________________________________________ |
159 | void AliGeomManager::SetGeometry(TGeoManager *geom) | |
160 | { | |
161 | // Load already active geometry | |
162 | if (!geom) AliFatalClass("Pointer to the active geometry is 0x0!"); | |
163 | ||
164 | fgGeometry = geom; | |
165 | ||
166 | InitSymNamesLUT(); | |
167 | InitPNEntriesLUT(); | |
168 | InitOrigMatricesLUT(); | |
169 | } | |
170 | ||
67dd5535 | 171 | //_____________________________________________________________________________ |
172 | AliGeomManager::AliGeomManager(): | |
36b010bf | 173 | TObject() |
67dd5535 | 174 | { |
175 | // default constructor | |
176 | } | |
177 | ||
178 | //_____________________________________________________________________________ | |
179 | AliGeomManager::~AliGeomManager() | |
180 | { | |
181 | // dummy destructor | |
67dd5535 | 182 | } |
183 | ||
184 | //_____________________________________________________________________________ | |
185 | Int_t AliGeomManager::LayerSize(Int_t layerId) | |
186 | { | |
187 | // Get the layer size for layer corresponding to layerId. | |
188 | // Implemented only for ITS,TPC,TRD,TOF and HMPID | |
189 | // | |
190 | if (layerId < kFirstLayer || layerId >= kLastLayer) { | |
191 | AliErrorClass(Form("Invalid layer index %d ! Layer range is (%d -> %d) !",layerId,kFirstLayer,kLastLayer)); | |
192 | return 0; | |
193 | } | |
194 | else { | |
195 | return fgLayerSize[layerId - kFirstLayer]; | |
196 | } | |
197 | } | |
198 | ||
199 | //_____________________________________________________________________________ | |
200 | const char* AliGeomManager::LayerName(Int_t layerId) | |
201 | { | |
202 | // Get the layer name corresponding to layerId. | |
203 | // Implemented only for ITS,TPC,TRD,TOF and HMPID | |
204 | // | |
205 | if (layerId < kFirstLayer || layerId >= kLastLayer) { | |
206 | AliErrorClass(Form("Invalid layer index %d ! Layer range is (%d -> %d) !",layerId,kFirstLayer,kLastLayer)); | |
207 | return "Invalid Layer!"; | |
208 | } | |
209 | else { | |
210 | return fgLayerName[layerId - kFirstLayer]; | |
211 | } | |
212 | } | |
213 | ||
214 | //_____________________________________________________________________________ | |
215 | UShort_t AliGeomManager::LayerToVolUID(ELayerID layerId, Int_t modId) | |
216 | { | |
217 | // From detector (layer) name and module number (according to detector | |
218 | // internal numbering) build the unique numerical identity of that volume | |
219 | // inside ALICE | |
220 | // fVolUID is 16 bits, first 5 reserved for layerID (32 possible values), | |
221 | // remaining 11 for module ID inside det (2048 possible values). | |
222 | // NO check for validity of given modId inside the layer for speed's sake. | |
223 | // | |
224 | return ((UShort_t(layerId) << 11) | UShort_t(modId)); | |
225 | } | |
226 | ||
227 | //_____________________________________________________________________________ | |
228 | UShort_t AliGeomManager::LayerToVolUID(Int_t layerId, Int_t modId) | |
229 | { | |
230 | // From detector (layer) name and module number (according to detector | |
231 | // internal numbering) build the unique numerical identity of that volume | |
232 | // inside ALICE | |
233 | // fVolUID is 16 bits, first 5 reserved for layerID (32 possible values), | |
234 | // remaining 11 for module ID inside det (2048 possible values). | |
235 | // NO check for validity of given modId inside the layer for speed's sake. | |
236 | // | |
237 | return ((UShort_t(layerId) << 11) | UShort_t(modId)); | |
238 | } | |
239 | ||
240 | //_____________________________________________________________________________ | |
241 | UShort_t AliGeomManager::LayerToVolUIDSafe(ELayerID layerId, Int_t modId) | |
242 | { | |
243 | // From detector (layer) name and module number (according to detector | |
244 | // internal numbering) build the unique numerical identity of that volume | |
245 | // inside ALICE | |
246 | // fVolUID is 16 bits, first 5 reserved for layerID (32 possible values), | |
247 | // remaining 11 for module ID inside det (2048 possible values). | |
248 | // Check validity of given modId inside the layer. | |
249 | // | |
250 | if(modId < 0 || modId >= LayerSize(layerId)){ | |
251 | AliErrorClass(Form("Invalid volume id %d ! Range of valid ids for layer \"%s\" is [0, %d] !",modId,LayerName(layerId),LayerSize(layerId)-1)); | |
252 | return 0; | |
253 | } | |
254 | return ((UShort_t(layerId) << 11) | UShort_t(modId)); | |
255 | } | |
256 | ||
257 | //_____________________________________________________________________________ | |
258 | UShort_t AliGeomManager::LayerToVolUIDSafe(Int_t layerId, Int_t modId) | |
259 | { | |
260 | // From detector (layer) name and module number (according to detector | |
261 | // internal numbering) build the unique numerical identity of that volume | |
262 | // inside ALICE | |
263 | // fVolUID is 16 bits, first 5 reserved for layerID (32 possible values), | |
264 | // remaining 11 for module ID inside det (2048 possible values). | |
265 | // Check validity of given modId inside the layer. | |
266 | // | |
267 | if(modId < 0 || modId >= LayerSize(layerId)){ | |
268 | AliErrorClass(Form("Invalid volume id %d ! Range of valid ids for layer \"%s\" is [0, %d] !",modId,LayerName(layerId),LayerSize(layerId)-1)); | |
269 | return 0; | |
270 | } | |
271 | return ((UShort_t(layerId) << 11) | UShort_t(modId)); | |
272 | } | |
273 | ||
274 | //_____________________________________________________________________________ | |
275 | AliGeomManager::ELayerID AliGeomManager::VolUIDToLayer(UShort_t voluid, Int_t &modId) | |
276 | { | |
277 | // From voluid, unique numerical identity of that volume inside ALICE, | |
278 | // (voluid is 16 bits, first 5 reserved for layerID (32 possible values), | |
279 | // remaining 11 for module ID inside det (2048 possible values)), return | |
280 | // the identity of the layer to which that volume belongs and sets the | |
281 | // argument modId to the identity of that volume internally to the layer. | |
282 | // NO check for validity of given voluid for speed's sake. | |
283 | // | |
284 | modId = voluid & 0x7ff; | |
285 | ||
286 | return VolUIDToLayer(voluid); | |
287 | } | |
288 | ||
289 | //_____________________________________________________________________________ | |
290 | AliGeomManager::ELayerID AliGeomManager::VolUIDToLayer(UShort_t voluid) | |
291 | { | |
292 | // From voluid, unique numerical identity of that volume inside ALICE, | |
293 | // (voluid is 16 bits, first 5 reserved for layerID (32 possible values), | |
294 | // remaining 11 for module ID inside det (2048 possible values)), return | |
295 | // the identity of the layer to which that volume belongs | |
296 | // NO check for validity of given voluid for speed's sake. | |
297 | // | |
298 | return ELayerID(voluid >> 11); | |
299 | } | |
300 | ||
301 | //_____________________________________________________________________________ | |
302 | AliGeomManager::ELayerID AliGeomManager::VolUIDToLayerSafe(UShort_t voluid, Int_t &modId) | |
303 | { | |
304 | // From voluid, unique numerical identity of that volume inside ALICE, | |
305 | // (voluid is 16 bits, first 5 reserved for layerID (32 possible values), | |
306 | // remaining 11 for module ID inside det (2048 possible values)), returns | |
307 | // the identity of the layer to which that volume belongs and sets the | |
308 | // argument modId to the identity of that volume internally to the layer. | |
309 | // Checks the validity of the given voluid | |
310 | // | |
311 | ELayerID layId = VolUIDToLayerSafe(voluid); | |
312 | if(layId){ | |
313 | Int_t mId = Int_t(voluid & 0x7ff); | |
314 | if( mId>=0 && mId<LayerSize(layId)){ | |
315 | modId = mId; | |
316 | return layId; | |
317 | } | |
318 | } | |
319 | ||
320 | AliErrorClass(Form("Invalid unique volume id: %d !",voluid)); | |
321 | modId = -1; | |
322 | return kInvalidLayer; | |
323 | ||
324 | } | |
325 | ||
326 | //_____________________________________________________________________________ | |
327 | AliGeomManager::ELayerID AliGeomManager::VolUIDToLayerSafe(UShort_t voluid) | |
328 | { | |
329 | // From voluid, unique numerical identity of that volume inside ALICE, | |
330 | // (voluid is 16 bits, first 5 reserved for layerID (32 possible values), | |
331 | // remaining 11 for module ID inside det (2048 possible values)), returns | |
332 | // the identity of the layer to which that volume belongs | |
333 | // Checks the validity of the given voluid | |
334 | // | |
335 | if( (voluid >> 11) < kLastLayer) return ELayerID(voluid >> 11); | |
336 | ||
337 | AliErrorClass(Form("Invalid layer id: %d !",(voluid >> 11))); | |
338 | return kInvalidLayer; | |
339 | ||
340 | } | |
341 | ||
342 | //_____________________________________________________________________________ | |
343 | Bool_t AliGeomManager::GetFromGeometry(const char *symname, AliAlignObj &alobj) | |
344 | { | |
345 | // Get the alignment object which corresponds to the symbolic volume name | |
346 | // symname (in case equal to the TGeo volume path) | |
347 | // The method is extremely slow due to the searching by string, | |
348 | // therefore it should be used with great care!! | |
349 | // This method returns FALSE if the symname of the object was not | |
350 | // valid neither to get a TGeoPEntry nor as a volume path, or if the path | |
351 | // associated to the TGeoPNEntry was not valid. | |
352 | // | |
353 | ||
354 | // Reset the alignment object | |
355 | alobj.SetPars(0,0,0,0,0,0); | |
356 | alobj.SetSymName(symname); | |
357 | ||
36b010bf | 358 | if (!fgGeometry || !fgGeometry->IsClosed()) { |
67dd5535 | 359 | AliErrorClass("Can't get the alignment object! gGeoManager doesn't exist or it is still opened!"); |
360 | return kFALSE; | |
361 | } | |
362 | ||
36b010bf | 363 | if (!fgGeometry->GetListOfPhysicalNodes()) { |
67dd5535 | 364 | AliErrorClass("Can't get the alignment object! gGeoManager doesn't contain any aligned nodes!"); |
365 | return kFALSE; | |
366 | } | |
367 | ||
67dd5535 | 368 | const char *path; |
36b010bf | 369 | TGeoPNEntry* pne = fgGeometry->GetAlignableEntry(symname); |
67dd5535 | 370 | if(pne){ |
371 | path = pne->GetTitle(); | |
372 | }else{ | |
373 | AliWarningClass(Form("The symbolic volume name %s does not correspond to a physical entry. Using it as a volume path!",symname)); | |
374 | path = symname; | |
375 | } | |
36b010bf | 376 | TObjArray* nodesArr = fgGeometry->GetListOfPhysicalNodes(); |
67dd5535 | 377 | TGeoPhysicalNode* node = NULL; |
378 | for (Int_t iNode = 0; iNode < nodesArr->GetEntriesFast(); iNode++) { | |
379 | TGeoPhysicalNode* tempNode = (TGeoPhysicalNode*) nodesArr->UncheckedAt(iNode); | |
380 | const char *nodePath = tempNode->GetName(); | |
381 | if (strcmp(path,nodePath) == 0) { | |
382 | node = tempNode; | |
383 | break; | |
384 | } | |
385 | } | |
386 | ||
387 | if (!node) { | |
36b010bf | 388 | if (!fgGeometry->cd(path)) { |
67dd5535 | 389 | AliErrorClass(Form("%s not valid neither as symbolic volume name nor as volume path!",path)); |
390 | return kFALSE; | |
391 | } | |
392 | else { | |
393 | AliWarningClass(Form("Volume (%s) has not been misaligned!",path)); | |
394 | return kTRUE; | |
395 | } | |
396 | } | |
397 | ||
398 | TGeoHMatrix align,gprime,g,ginv,l; | |
399 | gprime = *node->GetMatrix(); | |
400 | l = *node->GetOriginalMatrix(); | |
401 | g = *node->GetMatrix(node->GetLevel()-1); | |
402 | g *= l; | |
403 | ginv = g.Inverse(); | |
404 | align = gprime * ginv; | |
405 | ||
406 | return alobj.SetMatrix(align); | |
407 | } | |
408 | ||
409 | ||
410 | //_____________________________________________________________________________ | |
411 | void AliGeomManager::InitAlignObjFromGeometry() | |
412 | { | |
413 | // Loop over all alignable volumes and extract | |
414 | // the corresponding alignment objects from | |
415 | // the TGeo geometry | |
416 | ||
417 | if(fgAlignObjs[0]) return; | |
418 | ||
67dd5535 | 419 | for (Int_t iLayer = kFirstLayer; iLayer < AliGeomManager::kLastLayer; iLayer++) { |
420 | fgAlignObjs[iLayer-kFirstLayer] = new AliAlignObj*[LayerSize(iLayer)]; | |
421 | for (Int_t iModule = 0; iModule < LayerSize(iLayer); iModule++) { | |
422 | UShort_t volid = LayerToVolUID(iLayer,iModule); | |
90dbf5fb | 423 | fgAlignObjs[iLayer-kFirstLayer][iModule] = new AliAlignObjParams("",volid,0,0,0,0,0,0,kTRUE); |
67dd5535 | 424 | const char *symname = SymName(volid); |
425 | if (!GetFromGeometry(symname, *fgAlignObjs[iLayer-kFirstLayer][iModule])) | |
426 | AliErrorClass(Form("Failed to extract the alignment object for the volume (ID=%d and path=%s) !",volid,symname)); | |
427 | } | |
428 | } | |
429 | ||
430 | } | |
431 | ||
432 | //_____________________________________________________________________________ | |
433 | AliAlignObj* AliGeomManager::GetAlignObj(UShort_t voluid) { | |
434 | // Returns the alignment object for given volume ID | |
435 | // | |
436 | Int_t modId; | |
437 | ELayerID layerId = VolUIDToLayer(voluid,modId); | |
438 | return GetAlignObj(layerId,modId); | |
439 | } | |
440 | ||
441 | //_____________________________________________________________________________ | |
442 | AliAlignObj* AliGeomManager::GetAlignObj(ELayerID layerId, Int_t modId) | |
443 | { | |
444 | // Returns pointer to alignment object given its layer and module ID | |
445 | // | |
446 | if(modId<0 || modId>=fgLayerSize[layerId-kFirstLayer]){ | |
447 | AliWarningClass(Form("Module number %d not in the valid range (0->%d) !",modId,fgLayerSize[layerId-kFirstLayer]-1)); | |
448 | return NULL; | |
449 | } | |
450 | InitAlignObjFromGeometry(); | |
451 | ||
452 | return fgAlignObjs[layerId-kFirstLayer][modId]; | |
453 | } | |
454 | ||
455 | //_____________________________________________________________________________ | |
456 | const char* AliGeomManager::SymName(UShort_t voluid) { | |
457 | // Returns the symbolic volume name for given volume ID | |
458 | // | |
459 | Int_t modId; | |
460 | ELayerID layerId = VolUIDToLayer(voluid,modId); | |
461 | return SymName(layerId,modId); | |
462 | } | |
463 | ||
464 | //_____________________________________________________________________________ | |
465 | const char* AliGeomManager::SymName(ELayerID layerId, Int_t modId) | |
466 | { | |
467 | // Returns the symbolic volume name given for a given layer | |
468 | // and module ID | |
469 | // | |
470 | if(modId<0 || modId>=fgLayerSize[layerId-kFirstLayer]){ | |
471 | AliWarningClass(Form("Module number %d not in the valid range (0->%d) !",modId,fgLayerSize[layerId-kFirstLayer]-1)); | |
472 | return NULL; | |
473 | } | |
25fad4e5 | 474 | InitSymNamesLUT(); |
67dd5535 | 475 | |
476 | return fgSymName[layerId-kFirstLayer][modId].Data(); | |
477 | } | |
478 | ||
479 | //_____________________________________________________________________________ | |
480 | void AliGeomManager::InitSymNamesLUT() | |
481 | { | |
482 | // Initialize the look-up table which associates the unique | |
483 | // numerical identity of each alignable volume to the | |
484 | // corresponding symbolic volume name | |
485 | // The LUTs are static; they are created at the creation of the | |
486 | // AliGeomManager instance and recreated if the geometry has changed | |
487 | // | |
488 | ||
25fad4e5 | 489 | if(fgSymName[0]) return; |
490 | ||
67dd5535 | 491 | for (Int_t iLayer = 0; iLayer < (kLastLayer - kFirstLayer); iLayer++){ |
492 | if(!fgSymName[iLayer]) fgSymName[iLayer]=new TString[fgLayerSize[iLayer]]; | |
493 | } | |
494 | ||
495 | TString symname; | |
496 | Int_t modnum; // in the following, set it to 0 at the start of each layer | |
497 | ||
498 | /********************* ITS layers ***********************/ | |
499 | TString strSPD = "ITS/SPD"; | |
500 | TString strSDD = "ITS/SDD"; | |
501 | TString strSSD = "ITS/SSD"; | |
502 | TString strStave = "/Stave"; | |
8f8273a4 | 503 | TString strHalfStave = "/HalfStave"; |
67dd5535 | 504 | TString strLadder = "/Ladder"; |
505 | TString strSector = "/Sector"; | |
506 | TString strSensor = "/Sensor"; | |
507 | TString strEntryName1; | |
508 | TString strEntryName2; | |
8f8273a4 | 509 | TString strEntryName3; |
67dd5535 | 510 | |
511 | /********************* SPD layer1 ***********************/ | |
512 | { | |
513 | modnum = 0; | |
8f8273a4 | 514 | |
515 | for(Int_t cSect = 0; cSect<10; cSect++){ | |
67dd5535 | 516 | strEntryName1 = strSPD; |
517 | strEntryName1 += 0; | |
518 | strEntryName1 += strSector; | |
8f8273a4 | 519 | strEntryName1 += cSect; |
520 | ||
521 | for(Int_t cStave =0; cStave<2; cStave++){ | |
67dd5535 | 522 | strEntryName2 = strEntryName1; |
523 | strEntryName2 += strStave; | |
8f8273a4 | 524 | strEntryName2 += cStave; |
525 | ||
526 | for (Int_t cHS=0; cHS<2; cHS++) { | |
527 | strEntryName3 = strEntryName2; | |
528 | strEntryName3 += strHalfStave; | |
529 | strEntryName3 += cHS; | |
530 | ||
531 | for(Int_t cLad =0; cLad<2; cLad++){ | |
532 | symname = strEntryName3; | |
533 | symname += strLadder; | |
534 | symname += cLad+cHS*2; | |
535 | fgSymName[kSPD1-kFirstLayer][modnum] = symname.Data(); | |
536 | modnum++; | |
537 | } | |
67dd5535 | 538 | } |
539 | } | |
540 | } | |
541 | } | |
542 | ||
543 | /********************* SPD layer2 ***********************/ | |
544 | { | |
545 | modnum = 0; | |
546 | ||
8f8273a4 | 547 | for(Int_t cSect = 0; cSect<10; cSect++){ |
67dd5535 | 548 | strEntryName1 = strSPD; |
549 | strEntryName1 += 1; | |
550 | strEntryName1 += strSector; | |
8f8273a4 | 551 | strEntryName1 += cSect; |
552 | ||
553 | for(Int_t cStave =0; cStave<4; cStave++){ | |
67dd5535 | 554 | strEntryName2 = strEntryName1; |
555 | strEntryName2 += strStave; | |
8f8273a4 | 556 | strEntryName2 += cStave; |
557 | ||
558 | for (Int_t cHS=0; cHS<2; cHS++) { | |
559 | strEntryName3 = strEntryName2; | |
560 | strEntryName3 += strHalfStave; | |
561 | strEntryName3 += cHS; | |
562 | ||
563 | for(Int_t cLad =0; cLad<2; cLad++){ | |
564 | symname = strEntryName3; | |
565 | symname += strLadder; | |
566 | symname += cLad+cHS*2; | |
567 | fgSymName[kSPD2-kFirstLayer][modnum] = symname.Data(); | |
568 | modnum++; | |
569 | } | |
67dd5535 | 570 | } |
571 | } | |
572 | } | |
573 | } | |
574 | ||
8f8273a4 | 575 | // /********************* SPD layer1 ***********************/ |
576 | // { | |
577 | // modnum = 0; | |
578 | ||
579 | // for(Int_t c1 = 1; c1<=10; c1++){ | |
580 | // strEntryName1 = strSPD; | |
581 | // strEntryName1 += 0; | |
582 | // strEntryName1 += strSector; | |
583 | // strEntryName1 += (c1-1); | |
584 | // for(Int_t c2 =1; c2<=2; c2++){ | |
585 | // strEntryName2 = strEntryName1; | |
586 | // strEntryName2 += strStave; | |
587 | // strEntryName2 += (c2-1); | |
588 | // for(Int_t c3 =1; c3<=4; c3++){ | |
589 | // symname = strEntryName2; | |
590 | // symname += strLadder; | |
591 | // symname += (c3-1); | |
592 | // fgSymName[kSPD1-kFirstLayer][modnum] = symname.Data(); | |
593 | // modnum++; | |
594 | // } | |
595 | // } | |
596 | // } | |
597 | // } | |
598 | ||
599 | // /********************* SPD layer2 ***********************/ | |
600 | // { | |
601 | // modnum = 0; | |
602 | ||
603 | // for(Int_t c1 = 1; c1<=10; c1++){ | |
604 | // strEntryName1 = strSPD; | |
605 | // strEntryName1 += 1; | |
606 | // strEntryName1 += strSector; | |
607 | // strEntryName1 += (c1-1); | |
608 | // for(Int_t c2 =1; c2<=4; c2++){ | |
609 | // strEntryName2 = strEntryName1; | |
610 | // strEntryName2 += strStave; | |
611 | // strEntryName2 += (c2-1); | |
612 | // for(Int_t c3 =1; c3<=4; c3++){ | |
613 | // symname = strEntryName2; | |
614 | // symname += strLadder; | |
615 | // symname += (c3-1); | |
616 | // fgSymName[kSPD2-kFirstLayer][modnum] = symname.Data(); | |
617 | // modnum++; | |
618 | // } | |
619 | // } | |
620 | // } | |
621 | // } | |
622 | ||
623 | ||
624 | ||
625 | ||
626 | ||
627 | ||
628 | ||
629 | ||
630 | ||
67dd5535 | 631 | /********************* SDD layer1 ***********************/ |
632 | { | |
633 | modnum=0; | |
634 | ||
635 | for(Int_t c1 = 1; c1<=14; c1++){ | |
636 | strEntryName1 = strSDD; | |
637 | strEntryName1 += 2; | |
638 | strEntryName1 +=strLadder; | |
639 | strEntryName1 += (c1-1); | |
640 | for(Int_t c2 =1; c2<=6; c2++){ | |
641 | symname = strEntryName1; | |
642 | symname += strSensor; | |
643 | symname += (c2-1); | |
644 | fgSymName[kSDD1-kFirstLayer][modnum] = symname.Data(); | |
645 | modnum++; | |
646 | } | |
647 | } | |
648 | } | |
649 | ||
650 | /********************* SDD layer2 ***********************/ | |
651 | { | |
652 | modnum=0; | |
653 | ||
654 | for(Int_t c1 = 1; c1<=22; c1++){ | |
655 | strEntryName1 = strSDD; | |
656 | strEntryName1 += 3; | |
657 | strEntryName1 +=strLadder; | |
658 | strEntryName1 += (c1-1); | |
659 | for(Int_t c2 = 1; c2<=8; c2++){ | |
660 | symname = strEntryName1; | |
661 | symname += strSensor; | |
662 | symname += (c2-1); | |
663 | fgSymName[kSDD2-kFirstLayer][modnum] = symname.Data(); | |
664 | modnum++; | |
665 | } | |
666 | } | |
667 | } | |
668 | ||
669 | /********************* SSD layer1 ***********************/ | |
670 | { | |
671 | modnum=0; | |
672 | ||
673 | for(Int_t c1 = 1; c1<=34; c1++){ | |
674 | strEntryName1 = strSSD; | |
675 | strEntryName1 += 4; | |
676 | strEntryName1 +=strLadder; | |
677 | strEntryName1 += (c1-1); | |
678 | for(Int_t c2 = 1; c2<=22; c2++){ | |
679 | symname = strEntryName1; | |
680 | symname += strSensor; | |
681 | symname += (c2-1); | |
682 | fgSymName[kSSD1-kFirstLayer][modnum] = symname.Data(); | |
683 | modnum++; | |
684 | } | |
685 | } | |
686 | } | |
687 | ||
688 | /********************* SSD layer2 ***********************/ | |
689 | { | |
690 | modnum=0; | |
691 | ||
692 | for(Int_t c1 = 1; c1<=38; c1++){ | |
693 | strEntryName1 = strSSD; | |
694 | strEntryName1 += 5; | |
695 | strEntryName1 +=strLadder; | |
696 | strEntryName1 += (c1-1); | |
697 | for(Int_t c2 = 1; c2<=25; c2++){ | |
698 | symname = strEntryName1; | |
699 | symname += strSensor; | |
700 | symname += (c2-1); | |
701 | fgSymName[kSSD2-kFirstLayer][modnum] = symname.Data(); | |
702 | modnum++; | |
703 | } | |
704 | } | |
705 | } | |
706 | ||
707 | ||
708 | /*************** TPC inner and outer layers ****************/ | |
709 | TString sAsector="TPC/EndcapA/Sector"; | |
710 | TString sCsector="TPC/EndcapC/Sector"; | |
711 | TString sInner="/InnerChamber"; | |
712 | TString sOuter="/OuterChamber"; | |
713 | ||
714 | /*************** TPC inner chambers' layer ****************/ | |
715 | { | |
716 | modnum = 0; | |
717 | ||
718 | for(Int_t cnt=1; cnt<=18; cnt++){ | |
719 | symname = sAsector; | |
720 | symname += cnt; | |
721 | symname += sInner; | |
722 | fgSymName[kTPC1-kFirstLayer][modnum] = symname.Data(); | |
723 | modnum++; | |
724 | } | |
725 | for(Int_t cnt=1; cnt<=18; cnt++){ | |
726 | symname = sCsector; | |
727 | symname += cnt; | |
728 | symname += sInner; | |
729 | fgSymName[kTPC1-kFirstLayer][modnum] = symname.Data(); | |
730 | modnum++; | |
731 | } | |
732 | } | |
733 | ||
734 | /*************** TPC outer chambers' layer ****************/ | |
735 | { | |
736 | modnum = 0; | |
737 | ||
738 | for(Int_t cnt=1; cnt<=18; cnt++){ | |
739 | symname = sAsector; | |
740 | symname += cnt; | |
741 | symname += sOuter; | |
742 | fgSymName[kTPC2-kFirstLayer][modnum] = symname.Data(); | |
743 | modnum++; | |
744 | } | |
745 | for(Int_t cnt=1; cnt<=18; cnt++){ | |
746 | symname = sCsector; | |
747 | symname += cnt; | |
748 | symname += sOuter; | |
749 | fgSymName[kTPC2-kFirstLayer][modnum] = symname.Data(); | |
750 | modnum++; | |
751 | } | |
752 | } | |
753 | ||
754 | /********************* TOF layer ***********************/ | |
755 | { | |
756 | modnum=0; | |
757 | ||
758 | Int_t nstrA=15; | |
759 | Int_t nstrB=19; | |
760 | Int_t nstrC=19; | |
761 | Int_t nSectors=18; | |
762 | Int_t nStrips=nstrA+2*nstrB+2*nstrC; | |
763 | ||
764 | TString snSM = "TOF/sm"; | |
765 | TString snSTRIP = "/strip"; | |
766 | ||
767 | for (Int_t isect = 0; isect < nSectors; isect++) { | |
768 | for (Int_t istr = 1; istr <= nStrips; istr++) { | |
769 | symname = snSM; | |
770 | symname += Form("%02d",isect); | |
771 | symname += snSTRIP; | |
772 | symname += Form("%02d",istr); | |
773 | fgSymName[kTOF-kFirstLayer][modnum] = symname.Data(); | |
774 | modnum++; | |
775 | } | |
776 | } | |
777 | } | |
778 | ||
779 | /********************* HMPID layer ***********************/ | |
780 | { | |
781 | TString str = "/HMPID/Chamber"; | |
782 | ||
783 | for (modnum=0; modnum < 7; modnum++) { | |
784 | symname = str; | |
785 | symname += modnum; | |
786 | fgSymName[kHMPID-kFirstLayer][modnum] = symname.Data(); | |
787 | } | |
788 | } | |
789 | ||
790 | /********************* TRD layers 1-6 *******************/ | |
791 | //!! 6 layers with index increasing in outwards direction | |
792 | { | |
793 | Int_t arTRDlayId[6] = {kTRD1, kTRD2, kTRD3, kTRD4, kTRD5, kTRD6}; | |
794 | ||
795 | TString snStr = "TRD/sm"; | |
796 | TString snApp1 = "/st"; | |
797 | TString snApp2 = "/pl"; | |
798 | ||
799 | for(Int_t layer=0; layer<6; layer++){ | |
800 | modnum=0; | |
801 | for (Int_t isect = 0; isect < 18; isect++) { | |
802 | for (Int_t icham = 0; icham < 5; icham++) { | |
803 | symname = snStr; | |
804 | symname += Form("%02d",isect); | |
805 | symname += snApp1; | |
806 | symname += icham; | |
807 | symname += snApp2; | |
808 | symname += layer; | |
809 | fgSymName[arTRDlayId[layer]-kFirstLayer][modnum] = symname.Data(); | |
810 | modnum++; | |
811 | } | |
812 | } | |
813 | } | |
814 | } | |
df117114 | 815 | |
816 | /********************* PHOS EMC layer ***********************/ | |
817 | { | |
818 | TString str = "PHOS/Module"; | |
819 | modnum=0; | |
820 | ||
821 | for (Int_t iModule=1; iModule <= 5; iModule++) { | |
822 | symname = str; | |
823 | symname += iModule; | |
824 | modnum = iModule-1; | |
825 | fgSymName[kPHOS1-kFirstLayer][modnum] = symname.Data(); | |
826 | } | |
827 | } | |
828 | ||
f47b9233 | 829 | /********************* PHOS CPV layer ***********************/ |
830 | { | |
831 | TString str = "PHOS/Module"; | |
832 | modnum=0; | |
833 | ||
834 | for (Int_t iModule=1; iModule <= 5; iModule++) { | |
835 | symname = str; | |
836 | symname += iModule; | |
837 | symname += "/CPV"; | |
838 | modnum = iModule-1; | |
839 | fgSymName[kPHOS2-kFirstLayer][modnum] = symname.Data(); | |
840 | } | |
841 | } | |
842 | ||
3dfc15c0 | 843 | /********************* EMCAL layer ***********************/ |
844 | { | |
845 | TString str = "EMCAL/FullSupermodule"; | |
846 | modnum=0; | |
847 | ||
848 | for (Int_t iModule=1; iModule <= 12; iModule++) { | |
849 | symname = str; | |
850 | symname += iModule; | |
851 | if(iModule >10) { | |
852 | symname = "EMCAL/HalfSupermodule"; | |
853 | symname += iModule-10; | |
854 | } | |
855 | modnum = iModule-1; | |
856 | fgSymName[kEMCAL-kFirstLayer][modnum] = symname.Data(); | |
857 | } | |
858 | } | |
f47b9233 | 859 | |
67dd5535 | 860 | } |
861 | ||
862 | //_____________________________________________________________________________ | |
863 | void AliGeomManager::InitPNEntriesLUT() | |
864 | { | |
865 | // Initialize the look-up table which associates the unique | |
866 | // numerical identity of each alignable volume to the | |
867 | // corresponding TGeoPNEntry. | |
868 | // The LUTs are static; they are created at the creation of the | |
869 | // AliGeomManager instance and recreated if the geometry has changed | |
870 | // | |
36b010bf | 871 | if (fgPNEntry[0]) return; |
67dd5535 | 872 | |
36b010bf | 873 | if(!fgGeometry) { |
874 | AliErrorClass("Impossible to initialize PNEntries LUT without an active geometry"); | |
875 | return; | |
876 | } | |
25fad4e5 | 877 | |
67dd5535 | 878 | for (Int_t iLayer = 0; iLayer < (kLastLayer - kFirstLayer); iLayer++){ |
36b010bf | 879 | fgPNEntry[iLayer] = new TGeoPNEntry*[fgLayerSize[iLayer]]; |
880 | for(Int_t modnum=0; modnum<fgLayerSize[iLayer]; modnum++){ | |
881 | fgPNEntry[iLayer][modnum] = fgGeometry->GetAlignableEntry(fgSymName[iLayer][modnum]); | |
882 | } | |
883 | } | |
884 | } | |
885 | ||
886 | //_____________________________________________________________________________ | |
887 | void AliGeomManager::InitOrigMatricesLUT() | |
888 | { | |
889 | // Initialize the storage for the look-up table with the original global | |
890 | // matrices for each alignable volume. | |
891 | // The LUTs are static; the matrices are created on demand and recreated | |
892 | // if the geometry has changed. | |
893 | if (fgOrigMatrix[0]) return; | |
894 | ||
895 | if (!fgGeometry || !fgGeometry->IsClosed()) { | |
896 | AliErrorClass("Impossible to initialize orignal matrices LUT without an active geometry"); | |
897 | return; | |
67dd5535 | 898 | } |
899 | ||
36b010bf | 900 | for (Int_t iLayer = 0; iLayer < (kLastLayer - kFirstLayer); iLayer++){ |
901 | fgOrigMatrix[iLayer] = new TGeoHMatrix*[fgLayerSize[iLayer]]; | |
25fad4e5 | 902 | for(Int_t modnum=0; modnum<fgLayerSize[iLayer]; modnum++){ |
36b010bf | 903 | if (!fgPNEntry[iLayer][modnum]) continue; |
904 | TGeoHMatrix *m = GetOrigGlobalMatrix(fgPNEntry[iLayer][modnum]); | |
905 | if (!m) continue; | |
906 | fgOrigMatrix[iLayer][modnum] = new TGeoHMatrix(*m); | |
67dd5535 | 907 | } |
908 | } | |
36b010bf | 909 | |
67dd5535 | 910 | } |
911 | ||
912 | //______________________________________________________________________ | |
913 | TGeoHMatrix* AliGeomManager::GetMatrix(TGeoPNEntry* pne) | |
914 | { | |
915 | // Get the transformation matrix for a given PNEntry | |
916 | // by quering the TGeoManager | |
917 | ||
36b010bf | 918 | if (!fgGeometry || !fgGeometry->IsClosed()) { |
25fad4e5 | 919 | AliErrorClass("Can't get the global matrix! gGeoManager doesn't exist or it is still opened!"); |
920 | return NULL; | |
921 | } | |
922 | ||
67dd5535 | 923 | TGeoPhysicalNode *pnode = pne->GetPhysicalNode(); |
924 | if (pnode) return pnode->GetMatrix(); | |
925 | ||
926 | const char* path = pne->GetTitle(); | |
36b010bf | 927 | if (!fgGeometry->cd(path)) { |
67dd5535 | 928 | AliErrorClass(Form("Volume path %s not valid!",path)); |
929 | return NULL; | |
930 | } | |
36b010bf | 931 | return fgGeometry->GetCurrentMatrix(); |
67dd5535 | 932 | } |
933 | ||
934 | //______________________________________________________________________ | |
935 | TGeoHMatrix* AliGeomManager::GetMatrix(Int_t index) | |
936 | { | |
937 | // Get the global transformation matrix for a given alignable volume | |
938 | // identified by its unique ID 'index' by quering the TGeoManager | |
939 | ||
67dd5535 | 940 | TGeoPNEntry *pne = GetPNEntry(index); |
941 | if (!pne) return NULL; | |
942 | ||
943 | return GetMatrix(pne); | |
944 | } | |
945 | ||
946 | //______________________________________________________________________ | |
947 | TGeoHMatrix* AliGeomManager::GetMatrix(const char* symname) | |
948 | { | |
949 | // Get the global transformation matrix for a given alignable volume | |
950 | // identified by its symbolic name 'symname' by quering the TGeoManager | |
951 | ||
36b010bf | 952 | if (!fgGeometry || !fgGeometry->IsClosed()) { |
953 | AliErrorClass("No active geometry or geometry not yet closed!"); | |
954 | return NULL; | |
955 | } | |
956 | ||
957 | TGeoPNEntry* pne = fgGeometry->GetAlignableEntry(symname); | |
67dd5535 | 958 | if (!pne) return NULL; |
959 | ||
960 | return GetMatrix(pne); | |
961 | } | |
962 | ||
963 | //______________________________________________________________________ | |
964 | Bool_t AliGeomManager::GetTranslation(Int_t index, Double_t t[3]) | |
965 | { | |
966 | // Get the translation vector for a given module 'index' | |
967 | // by quering the TGeoManager | |
968 | ||
969 | TGeoHMatrix *m = GetMatrix(index); | |
970 | if (!m) return kFALSE; | |
971 | ||
972 | Double_t *trans = m->GetTranslation(); | |
973 | for (Int_t i = 0; i < 3; i++) t[i] = trans[i]; | |
974 | ||
975 | return kTRUE; | |
976 | } | |
977 | ||
978 | //______________________________________________________________________ | |
979 | Bool_t AliGeomManager::GetRotation(Int_t index, Double_t r[9]) | |
980 | { | |
981 | // Get the rotation matrix for a given module 'index' | |
982 | // by quering the TGeoManager | |
983 | ||
984 | TGeoHMatrix *m = GetMatrix(index); | |
985 | if (!m) return kFALSE; | |
986 | ||
987 | Double_t *rot = m->GetRotationMatrix(); | |
988 | for (Int_t i = 0; i < 9; i++) r[i] = rot[i]; | |
989 | ||
990 | return kTRUE; | |
991 | } | |
992 | ||
5d534fe3 | 993 | //_____________________________________________________________________________ |
994 | Bool_t AliGeomManager::GetDeltaForBranch(Int_t index, TGeoHMatrix &inclusiveD) | |
995 | { | |
996 | // The method sets the matrix passed as argument as the global delta | |
997 | // (for the volume referred by the unique index) including the displacements | |
998 | // of all parent volumes in the branch. | |
999 | // | |
1000 | const char* symname = SymName(index); | |
1001 | if(!symname) return kFALSE; | |
1002 | ||
1003 | TGeoHMatrix go,invgo; | |
1004 | go = *GetOrigGlobalMatrix(index); | |
1005 | invgo = go.Inverse(); | |
1006 | inclusiveD = *GetMatrix(symname); | |
1007 | inclusiveD.Multiply(&invgo); | |
1008 | ||
1009 | return kTRUE; | |
1010 | } | |
1011 | ||
1012 | //_____________________________________________________________________________ | |
1013 | Bool_t AliGeomManager::GetDeltaForBranch(AliAlignObj& aao, TGeoHMatrix &inclusiveD) | |
1014 | { | |
1015 | // The method sets the matrix passed as argument as the global delta | |
1016 | // (for the volume referred by the alignment object) including the displacements | |
1017 | // of all parent volumes in the brach. | |
1018 | // | |
1019 | Int_t index = aao.GetVolUID(); | |
1020 | if(!index){ | |
1021 | AliErrorClass("Either the alignment object or its index are not valid"); | |
1022 | return kFALSE; | |
1023 | } | |
1024 | return GetDeltaForBranch(index, inclusiveD); | |
1025 | } | |
1026 | ||
36b010bf | 1027 | //______________________________________________________________________ |
1028 | Bool_t AliGeomManager::GetOrigGlobalMatrix(const char* symname, TGeoHMatrix &m) | |
67dd5535 | 1029 | { |
36b010bf | 1030 | // Get the global transformation matrix (ideal geometry) for a given alignable volume |
1031 | // identified by its symbolic name 'symname' by quering the TGeoManager | |
1032 | m.Clear(); | |
67dd5535 | 1033 | |
36b010bf | 1034 | if (!fgGeometry || !fgGeometry->IsClosed()) { |
1035 | AliErrorClass("No active geometry or geometry not yet closed!"); | |
67dd5535 | 1036 | return kFALSE; |
1037 | } | |
36b010bf | 1038 | if (!fgGeometry->GetListOfPhysicalNodes()) { |
67dd5535 | 1039 | AliWarningClass("gGeoManager doesn't contain any aligned nodes!"); |
36b010bf | 1040 | if (!fgGeometry->cd(symname)) { |
67dd5535 | 1041 | AliErrorClass(Form("Volume path %s not valid!",symname)); |
1042 | return kFALSE; | |
1043 | } | |
1044 | else { | |
36b010bf | 1045 | m = *fgGeometry->GetCurrentMatrix(); |
67dd5535 | 1046 | return kTRUE; |
1047 | } | |
1048 | } | |
1049 | ||
36b010bf | 1050 | TGeoPNEntry* pne = fgGeometry->GetAlignableEntry(symname); |
67dd5535 | 1051 | const char* path = NULL; |
67dd5535 | 1052 | if(pne){ |
1053 | path = pne->GetTitle(); | |
1054 | }else{ | |
1055 | AliWarningClass(Form("The symbolic volume name %s does not correspond to a physical entry. Using it as a volume path!",symname)); | |
1056 | path=symname; | |
1057 | } | |
1058 | ||
36b010bf | 1059 | return GetOrigGlobalMatrixFromPath(path,m); |
1060 | } | |
1061 | ||
1062 | //_____________________________________________________________________________ | |
1063 | Bool_t AliGeomManager::GetOrigGlobalMatrixFromPath(const char *path, TGeoHMatrix &m) | |
1064 | { | |
1065 | // The method returns global matrix for the ideal detector geometry | |
1066 | // Symname identifies either the corresponding TGeoPNEntry or directly | |
1067 | // the volume path. The output global matrix is stored in 'm'. | |
1068 | // Returns kFALSE in case TGeo has not been initialized or the symname | |
1069 | // is invalid. | |
1070 | // | |
1071 | m.Clear(); | |
1072 | ||
1073 | if (!fgGeometry || !fgGeometry->IsClosed()) { | |
1074 | AliErrorClass("Can't get the original global matrix! gGeoManager doesn't exist or it is still opened!"); | |
67dd5535 | 1075 | return kFALSE; |
1076 | } | |
1077 | ||
36b010bf | 1078 | if (!fgGeometry->CheckPath(path)) { |
1079 | AliErrorClass(Form("Volume path %s not valid!",path)); | |
1080 | return kFALSE; | |
1081 | } | |
67dd5535 | 1082 | |
36b010bf | 1083 | TIter next(fgGeometry->GetListOfPhysicalNodes()); |
1084 | fgGeometry->cd(path); | |
67dd5535 | 1085 | |
36b010bf | 1086 | while(fgGeometry->GetLevel()){ |
67dd5535 | 1087 | |
1088 | TGeoPhysicalNode *physNode = NULL; | |
1089 | next.Reset(); | |
36b010bf | 1090 | TGeoNode *node = fgGeometry->GetCurrentNode(); |
67dd5535 | 1091 | while ((physNode=(TGeoPhysicalNode*)next())) |
1092 | if (physNode->GetNode() == node) break; | |
1093 | ||
1094 | TGeoMatrix *lm = NULL; | |
1095 | if (physNode) { | |
1096 | lm = physNode->GetOriginalMatrix(); | |
1097 | if (!lm) lm = node->GetMatrix(); | |
1098 | } else | |
1099 | lm = node->GetMatrix(); | |
1100 | ||
1101 | m.MultiplyLeft(lm); | |
1102 | ||
36b010bf | 1103 | fgGeometry->CdUp(); |
67dd5535 | 1104 | } |
1105 | ||
1106 | return kTRUE; | |
1107 | } | |
1108 | ||
36b010bf | 1109 | //_____________________________________________________________________________ |
1110 | TGeoHMatrix* AliGeomManager::GetOrigGlobalMatrix(TGeoPNEntry* pne) | |
1111 | { | |
1112 | // The method returns global matrix for the ideal detector geometry | |
1113 | // using the corresponding TGeoPNEntry as an input. | |
1114 | // The method creates a new matrix, so it has to be used carefully in order | |
1115 | // to avoid memory leaks. | |
1116 | // In case of missing TGeoManager the method return NULL. | |
1117 | ||
1118 | if (!fgGeometry || !fgGeometry->IsClosed()) { | |
1119 | AliErrorClass("Can't get the global matrix! gGeoManager doesn't exist or it is still opened!"); | |
1120 | return NULL; | |
1121 | } | |
1122 | ||
1123 | const char* path = pne->GetTitle(); | |
1124 | static TGeoHMatrix m; | |
1125 | if (!GetOrigGlobalMatrixFromPath(path,m)) | |
1126 | return NULL; | |
1127 | ||
1128 | return &m; | |
1129 | } | |
1130 | ||
67dd5535 | 1131 | //______________________________________________________________________ |
36b010bf | 1132 | TGeoHMatrix* AliGeomManager::GetOrigGlobalMatrix(Int_t index) |
67dd5535 | 1133 | { |
1134 | // Get the original (ideal geometry) TGeo matrix for | |
1135 | // a given module identified by 'index'. | |
36b010bf | 1136 | // In general the method is slow, so we use |
1137 | // LUT for fast access. The LUT is reset in case of | |
1138 | // new geometry is loaded. | |
1139 | Int_t modId; | |
1140 | ELayerID layerId = VolUIDToLayer(index,modId); | |
67dd5535 | 1141 | |
36b010bf | 1142 | if (fgOrigMatrix[layerId-kFirstLayer][modId]) |
1143 | return fgOrigMatrix[layerId-kFirstLayer][modId]; | |
1144 | else { | |
1145 | TGeoPNEntry *pne = GetPNEntry(index); | |
1146 | if (!pne) return NULL; | |
1147 | return GetOrigGlobalMatrix(pne); | |
1148 | } | |
67dd5535 | 1149 | } |
1150 | ||
1151 | //______________________________________________________________________ | |
1152 | Bool_t AliGeomManager::GetOrigTranslation(Int_t index, Double_t t[3]) | |
1153 | { | |
1154 | // Get the original translation vector (ideal geometry) | |
1155 | // for a given module 'index' by quering the TGeoManager | |
1156 | ||
36b010bf | 1157 | TGeoHMatrix *m = GetOrigGlobalMatrix(index); |
1158 | if (!m) return kFALSE; | |
67dd5535 | 1159 | |
36b010bf | 1160 | Double_t *trans = m->GetTranslation(); |
67dd5535 | 1161 | for (Int_t i = 0; i < 3; i++) t[i] = trans[i]; |
1162 | ||
1163 | return kTRUE; | |
1164 | } | |
1165 | ||
1166 | //______________________________________________________________________ | |
1167 | Bool_t AliGeomManager::GetOrigRotation(Int_t index, Double_t r[9]) | |
1168 | { | |
1169 | // Get the original rotation matrix (ideal geometry) | |
1170 | // for a given module 'index' by quering the TGeoManager | |
1171 | ||
36b010bf | 1172 | TGeoHMatrix *m = GetOrigGlobalMatrix(index); |
1173 | if (!m) return kFALSE; | |
67dd5535 | 1174 | |
36b010bf | 1175 | Double_t *rot = m->GetRotationMatrix(); |
67dd5535 | 1176 | for (Int_t i = 0; i < 9; i++) r[i] = rot[i]; |
1177 | ||
1178 | return kTRUE; | |
1179 | } | |
1180 | ||
1181 | //______________________________________________________________________ | |
1182 | const TGeoHMatrix* AliGeomManager::GetTracking2LocalMatrix(Int_t index) | |
1183 | { | |
25fad4e5 | 1184 | // Get the matrix which transforms from the tracking to the local RS |
67dd5535 | 1185 | // The method queries directly the TGeoPNEntry |
1186 | ||
67dd5535 | 1187 | TGeoPNEntry *pne = GetPNEntry(index); |
1188 | if (!pne) return NULL; | |
1189 | ||
1190 | const TGeoHMatrix *m = pne->GetMatrix(); | |
1191 | if (!m) | |
1192 | AliErrorClass(Form("TGeoPNEntry (%s) contains no matrix !",pne->GetName())); | |
1193 | ||
1194 | return m; | |
1195 | } | |
1196 | ||
1197 | //______________________________________________________________________ | |
1198 | Bool_t AliGeomManager::GetTrackingMatrix(Int_t index, TGeoHMatrix &m) | |
1199 | { | |
1200 | // Get the matrix which transforms from the tracking r.s. to | |
1201 | // the global one. | |
1202 | // Returns kFALSE in case of error. | |
1203 | ||
1204 | m.Clear(); | |
1205 | ||
1206 | TGeoHMatrix *m1 = GetMatrix(index); | |
1207 | if (!m1) return kFALSE; | |
1208 | ||
1209 | const TGeoHMatrix *m2 = GetTracking2LocalMatrix(index); | |
1210 | if (!m2) return kFALSE; | |
1211 | ||
1212 | m = *m1; | |
1213 | m.Multiply(m2); | |
1214 | ||
1215 | return kTRUE; | |
1216 | } | |
1217 | ||
1218 | //_____________________________________________________________________________ | |
1219 | TGeoPNEntry* AliGeomManager::GetPNEntry(Int_t voluid) { | |
1220 | // Returns the TGeoPNEntry for the given global volume ID "voluid" | |
1221 | // | |
1222 | Int_t modId; | |
1223 | ELayerID layerId = VolUIDToLayer(voluid,modId); | |
1224 | return GetPNEntry(layerId,modId); | |
1225 | } | |
1226 | ||
67dd5535 | 1227 | //_____________________________________________________________________________ |
1228 | TGeoPNEntry* AliGeomManager::GetPNEntry(ELayerID layerId, Int_t modId) | |
1229 | { | |
1230 | // Returns the TGeoPNEntry for a given layer | |
1231 | // and module ID | |
1232 | // | |
25fad4e5 | 1233 | |
67dd5535 | 1234 | if(modId<0 || modId>=fgLayerSize[layerId-kFirstLayer]){ |
1235 | AliWarningClass(Form("Module number %d not in the valid range (0->%d) !",modId,fgLayerSize[layerId-kFirstLayer]-1)); | |
1236 | return NULL; | |
1237 | } | |
1238 | ||
1239 | return fgPNEntry[layerId-kFirstLayer][modId]; | |
1240 | } | |
1241 | ||
1242 | //_____________________________________________________________________________ | |
1243 | Bool_t AliGeomManager::ApplyAlignObjsFromCDB(const char* AlignDetsList) | |
1244 | { | |
1245 | // Calls AddAlignObjsFromCDBSingleDet for the detectors appearing in | |
1246 | // the list passed as argument (called by AliSimulation and | |
1247 | // AliReconstruction) | |
1248 | // Read the alignment objects from CDB. | |
1249 | // Each detector is supposed to have the | |
1250 | // alignment objects in DET/Align/Data CDB path. | |
1251 | // All the detector objects are then collected, | |
1252 | // sorted by geometry level (starting from ALIC) and | |
1253 | // then applied to the TGeo geometry. | |
1254 | // Finally an overlaps check is performed. | |
1255 | // | |
1256 | ||
36b010bf | 1257 | TObjArray alignObjArray; |
1258 | alignObjArray.Clear(); | |
1259 | alignObjArray.SetOwner(0); | |
67dd5535 | 1260 | |
1261 | TString alObjsNotLoaded=""; | |
1262 | TString alObjsLoaded=""; | |
1263 | ||
1264 | TString AlignDetsString(AlignDetsList); | |
1265 | TObjArray *detsarr = AlignDetsString.Tokenize(' '); | |
1266 | TIter iter(detsarr); | |
1267 | TObjString *str = 0; | |
1268 | ||
1269 | while((str = (TObjString*) iter.Next())){ | |
1270 | TString det(str->String()); | |
36b010bf | 1271 | AliInfoClass(Form("Loading alignment objs for %s",det.Data())); |
1272 | if(!LoadAlignObjsFromCDBSingleDet(det.Data(),alignObjArray)){ | |
67dd5535 | 1273 | alObjsNotLoaded += det.Data(); |
1274 | alObjsNotLoaded += " "; | |
1275 | } else { | |
1276 | alObjsLoaded += det.Data(); | |
1277 | alObjsLoaded += " "; | |
1278 | } | |
1279 | } | |
1280 | ||
36b010bf | 1281 | if(!alObjsLoaded.IsNull()) AliInfoClass(Form("Alignment objects loaded for: %s", |
1282 | alObjsLoaded.Data())); | |
1283 | if(!alObjsNotLoaded.IsNull()) AliInfoClass(Form("Didn't/couldn't load alignment objects for: %s", | |
1284 | alObjsNotLoaded.Data())); | |
67dd5535 | 1285 | |
9cb4fe0b | 1286 | return ApplyAlignObjsToGeom(alignObjArray); |
67dd5535 | 1287 | } |
1288 | ||
1289 | //_____________________________________________________________________________ | |
36b010bf | 1290 | Bool_t AliGeomManager::LoadAlignObjsFromCDBSingleDet(const char* detName, TObjArray& alignObjArray) |
67dd5535 | 1291 | { |
1292 | // Adds the alignable objects found in the CDBEntry for the detector | |
1293 | // passed as argument to the array of all alignment objects to be applyed | |
1294 | // to geometry | |
1295 | // | |
1296 | // Fills array of single detector's alignable objects from CDB | |
1297 | ||
36b010bf | 1298 | AliDebugClass(2, Form("Loading alignment objs for detector: %s",detName)); |
67dd5535 | 1299 | |
1300 | AliCDBEntry *entry; | |
1301 | ||
1302 | AliCDBPath path(detName,"Align","Data"); | |
1303 | ||
1304 | entry=AliCDBManager::Instance()->Get(path.GetPath()); | |
1305 | if(!entry){ | |
36b010bf | 1306 | AliDebugClass(2,Form("Couldn't load alignment data for detector %s",detName)); |
67dd5535 | 1307 | return kFALSE; |
1308 | } | |
1309 | entry->SetOwner(1); | |
1310 | TClonesArray *alignArray = (TClonesArray*) entry->GetObject(); | |
1311 | alignArray->SetOwner(0); | |
36b010bf | 1312 | AliDebugClass(2,Form("Found %d alignment objects for %s", |
1313 | alignArray->GetEntries(),detName)); | |
67dd5535 | 1314 | |
1315 | AliAlignObj *alignObj=0; | |
1316 | TIter iter(alignArray); | |
1317 | ||
1318 | // loop over align objects in detector | |
1319 | while( ( alignObj=(AliAlignObj *) iter.Next() ) ){ | |
36b010bf | 1320 | alignObjArray.Add(alignObj); |
67dd5535 | 1321 | } |
1322 | // delete entry --- Don't delete, it is cached! | |
1323 | ||
36b010bf | 1324 | AliDebugClass(2, Form("fAlignObjArray entries: %d",alignObjArray.GetEntries() )); |
67dd5535 | 1325 | return kTRUE; |
1326 | ||
1327 | } | |
1328 | ||
1329 | //_____________________________________________________________________________ | |
36b010bf | 1330 | Bool_t AliGeomManager::ApplyAlignObjsToGeom(TObjArray& alignObjArray) |
67dd5535 | 1331 | { |
1332 | // Read collection of alignment objects (AliAlignObj derived) saved | |
1333 | // in the TClonesArray alObjArray and apply them to gGeoManager | |
1334 | // | |
36b010bf | 1335 | alignObjArray.Sort(); |
1336 | Int_t nvols = alignObjArray.GetEntriesFast(); | |
67dd5535 | 1337 | |
1338 | Bool_t flag = kTRUE; | |
1339 | ||
1340 | for(Int_t j=0; j<nvols; j++) | |
1341 | { | |
36b010bf | 1342 | AliAlignObj* alobj = (AliAlignObj*) alignObjArray.UncheckedAt(j); |
67dd5535 | 1343 | if (alobj->ApplyToGeometry() == kFALSE) flag = kFALSE; |
1344 | } | |
1345 | ||
1346 | if (AliDebugLevelClass() >= 1) { | |
36b010bf | 1347 | fgGeometry->GetTopNode()->CheckOverlaps(1); |
1348 | TObjArray* ovexlist = fgGeometry->GetListOfOverlaps(); | |
67dd5535 | 1349 | if(ovexlist->GetEntriesFast()){ |
36b010bf | 1350 | AliErrorClass("The application of alignment objects to the geometry caused huge overlaps/extrusions!"); |
67dd5535 | 1351 | } |
1352 | } | |
1353 | ||
36b010bf | 1354 | // Update the TGeoPhysicalNodes |
1355 | fgGeometry->RefreshPhysicalNodes(); | |
1356 | ||
67dd5535 | 1357 | return flag; |
1358 | ||
1359 | } | |
1360 | ||
1361 | //_____________________________________________________________________________ | |
1362 | Bool_t AliGeomManager::ApplyAlignObjsToGeom(const char* fileName, const char* clArrayName) | |
1363 | { | |
1364 | // read collection of alignment objects (AliAlignObj derived) saved | |
1365 | // in the TClonesArray ClArrayName in the file fileName and apply | |
1366 | // them to the geometry | |
1367 | // | |
1368 | ||
1369 | TFile* inFile = TFile::Open(fileName,"READ"); | |
1370 | if (!inFile || !inFile->IsOpen()) { | |
1371 | AliErrorClass(Form("Could not open file %s !",fileName)); | |
1372 | return kFALSE; | |
1373 | } | |
1374 | ||
36b010bf | 1375 | TClonesArray* alignObjArray = ((TClonesArray*) inFile->Get(clArrayName)); |
67dd5535 | 1376 | inFile->Close(); |
36b010bf | 1377 | if (!alignObjArray) { |
67dd5535 | 1378 | AliErrorClass(Form("Could not get array (%s) from file (%s) !",clArrayName,fileName)); |
1379 | return kFALSE; | |
1380 | } | |
1381 | ||
36b010bf | 1382 | return ApplyAlignObjsToGeom(*alignObjArray); |
67dd5535 | 1383 | |
1384 | } | |
1385 | ||
1386 | //_____________________________________________________________________________ | |
1387 | Bool_t AliGeomManager::ApplyAlignObjsToGeom(AliCDBParam* param, AliCDBId& Id) | |
1388 | { | |
1389 | // read collection of alignment objects (AliAlignObj derived) saved | |
1390 | // in the TClonesArray ClArrayName in the AliCDBEntry identified by | |
1391 | // param (to get the AliCDBStorage) and Id; apply the alignment objects | |
1392 | // to the geometry | |
1393 | // | |
1394 | ||
1395 | AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage(param); | |
1396 | AliCDBEntry* entry = storage->Get(Id); | |
36b010bf | 1397 | TClonesArray* alignObjArray = ((TClonesArray*) entry->GetObject()); |
67dd5535 | 1398 | |
36b010bf | 1399 | return ApplyAlignObjsToGeom(*alignObjArray); |
67dd5535 | 1400 | |
1401 | } | |
1402 | ||
1403 | //_____________________________________________________________________________ | |
1404 | Bool_t AliGeomManager::ApplyAlignObjsToGeom(const char* uri, const char* path, Int_t runnum, Int_t version, Int_t sversion) | |
1405 | { | |
1406 | // read collection of alignment objects (AliAlignObj derived) saved | |
1407 | // in the TClonesArray ClArrayName in the AliCDBEntry identified by | |
1408 | // param (to get the AliCDBStorage) and Id; apply the alignment objects | |
1409 | // to the geometry | |
1410 | // | |
1411 | ||
1412 | AliCDBParam* param = AliCDBManager::Instance()->CreateParameter(uri); | |
1413 | AliCDBId id(path, runnum, runnum, version, sversion); | |
1414 | ||
1415 | return ApplyAlignObjsToGeom(param, id); | |
1416 | ||
1417 | } | |
1418 | ||
1419 | //_____________________________________________________________________________ | |
1420 | Bool_t AliGeomManager::ApplyAlignObjsToGeom(const char* detName, Int_t runnum, Int_t version, Int_t sversion) | |
1421 | { | |
1422 | // read collection of alignment objects (AliAlignObj derived) saved | |
1423 | // in the TClonesArray ClArrayName in the AliCDBEntry identified by | |
1424 | // param (to get the AliCDBStorage) and Id; apply the alignment objects | |
1425 | // to the geometry | |
1426 | // | |
1427 | ||
1428 | AliCDBPath path(detName,"Align","Data"); | |
1429 | AliCDBEntry* entry = AliCDBManager::Instance()->Get(path.GetPath(),runnum,version,sversion); | |
1430 | ||
1431 | if(!entry) return kFALSE; | |
36b010bf | 1432 | TClonesArray* alignObjArray = ((TClonesArray*) entry->GetObject()); |
25fad4e5 | 1433 | |
36b010bf | 1434 | return ApplyAlignObjsToGeom(*alignObjArray); |
67dd5535 | 1435 | } |