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