]>
Commit | Line | Data |
---|---|---|
ce886e8e | 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 | /////////////////////////////////////////////////////////////////////////// | |
451f5018 | 17 | // AliITSUGeomTGeo is a simple interface class to TGeoManager // |
ce886e8e | 18 | // It is used in the simulation and reconstruction in order to // |
19 | // query the TGeo ITS geometry // | |
20 | // // | |
21 | // author - cvetan.cheshkov@cern.ch // | |
22 | // 15/02/2007 // | |
23 | // adapted to ITSupg 18/07/2012 - ruben.shahoyan@cern.ch // | |
24 | // // | |
451f5018 | 25 | // ATTENTION: In opposite to ols AliITSgeomTGeo, all indices start // |
26 | // from 0, not from 1!!! // | |
27 | // // | |
ce886e8e | 28 | /////////////////////////////////////////////////////////////////////////// |
29 | ||
30 | #include <TClass.h> | |
31 | #include <TString.h> | |
32 | #include <TGeoManager.h> | |
33 | #include <TGeoPhysicalNode.h> | |
34 | #include <TDatime.h> | |
af4b47c9 | 35 | #include <TMath.h> |
546d00d8 | 36 | #include <TSystem.h> |
ce886e8e | 37 | |
451f5018 | 38 | #include "AliITSUGeomTGeo.h" |
ce886e8e | 39 | #include "AliLog.h" |
40 | #include "AliAlignObj.h" | |
546d00d8 | 41 | #include "AliITSsegmentation.h" |
42 | #include "AliITSUSegmentationPix.h" | |
af4b47c9 | 43 | using namespace TMath; |
ce886e8e | 44 | |
451f5018 | 45 | ClassImp(AliITSUGeomTGeo) |
46 | ||
ce886e8e | 47 | |
451f5018 | 48 | const char* AliITSUGeomTGeo::fgkITSVolName = "ITSV"; |
02d6eccc | 49 | const char* AliITSUGeomTGeo::fgkITSLrName = "ITSULayer"; |
50 | const char* AliITSUGeomTGeo::fgkITSLadName = "ITSULadder"; | |
51 | const char* AliITSUGeomTGeo::fgkITSModName = "ITSUModule"; | |
52 | const char* AliITSUGeomTGeo::fgkITSSensName ="ITSUSensor"; | |
43361342 | 53 | const char* AliITSUGeomTGeo::fgkITSWrapVolName = "ITSUWrapVol"; |
02d6eccc | 54 | const char* AliITSUGeomTGeo::fgkITSDetTypeName[AliITSUGeomTGeo::kNDetTypes] = {"Pix"}; |
451f5018 | 55 | // |
56 | TString AliITSUGeomTGeo::fgITSsegmFileName = "itsSegmentations.root"; | |
ce886e8e | 57 | |
451f5018 | 58 | //______________________________________________________________________ |
546d00d8 | 59 | AliITSUGeomTGeo::AliITSUGeomTGeo(Bool_t build, Bool_t loadSegm) |
cf457606 | 60 | :fVersion(kITSVNA) |
451f5018 | 61 | ,fNLayers(0) |
62 | ,fNModules(0) | |
63 | ,fNLadders(0) | |
64 | ,fLrDetType(0) | |
65 | ,fNDetectors(0) | |
66 | ,fLastModIndex(0) | |
cf457606 | 67 | ,fMatSens(0) |
68 | ,fMatT2L(0) | |
546d00d8 | 69 | ,fSegm(0) |
451f5018 | 70 | { |
71 | // default c-tor | |
43361342 | 72 | for (int i=AliITSUAux::kMaxLayers;i--;) fLr2Wrapper[i] = -1; |
546d00d8 | 73 | if (build) BuildITS(loadSegm); |
451f5018 | 74 | } |
ce886e8e | 75 | |
451f5018 | 76 | //______________________________________________________________________ |
77 | AliITSUGeomTGeo::AliITSUGeomTGeo(const AliITSUGeomTGeo &src) | |
78 | :TObject(src) | |
79 | ,fVersion(src.fVersion) | |
80 | ,fNLayers(src.fNLayers) | |
81 | ,fNModules(src.fNModules) | |
82 | ,fNLadders(0) | |
83 | ,fLrDetType(0) | |
84 | ,fNDetectors(0) | |
85 | ,fLastModIndex(0) | |
cf457606 | 86 | ,fMatSens(0) |
87 | ,fMatT2L(0) | |
546d00d8 | 88 | ,fSegm(0) |
451f5018 | 89 | { |
90 | // copy c-tor | |
91 | if (fNLayers) { | |
92 | fNLadders = new Int_t[fNLayers]; | |
93 | fNDetectors = new Int_t[fNLayers]; | |
94 | fLrDetType = new Int_t[fNLayers]; | |
95 | fLastModIndex = new Int_t[fNLayers]; | |
96 | for (int i=fNLayers;i--;) { | |
97 | fNLadders[i] = src.fNLadders[i]; | |
98 | fNDetectors[i] = src.fNDetectors[i]; | |
99 | fLrDetType[i] = src.fLrDetType[i]; | |
100 | fLastModIndex[i] = src.fLastModIndex[i]; | |
101 | } | |
cf457606 | 102 | if (src.fMatSens) { |
103 | fMatSens = new TObjArray(fNModules); | |
104 | fMatSens->SetOwner(kTRUE); | |
105 | for (int i=0;i<fNModules;i++) { | |
106 | const TGeoHMatrix* mat = (TGeoHMatrix*)src.fMatSens->At(i); | |
107 | fMatSens->AddAt(new TGeoHMatrix(*mat),i); | |
108 | } | |
109 | } | |
110 | if (src.fMatT2L) { | |
111 | fMatT2L = new TObjArray(fNModules); | |
112 | fMatT2L->SetOwner(kTRUE); | |
113 | for (int i=0;i<fNModules;i++) { | |
114 | const TGeoHMatrix* mat =(TGeoHMatrix*) src.fMatT2L->At(i); | |
546d00d8 | 115 | fMatT2L->AddAt(new TGeoHMatrix(*mat),i); |
116 | } | |
117 | } | |
118 | if (src.fSegm) { | |
119 | int sz = src.fSegm->GetEntriesFast(); | |
120 | fSegm = new TObjArray(sz); | |
121 | fSegm->SetOwner(kTRUE); | |
122 | for (int i=0;i<sz;i++) { | |
123 | AliITSsegmentation* sg = (AliITSsegmentation*)src.fSegm->UncheckedAt(i); | |
124 | if (!sg) continue; | |
125 | fSegm->AddAt(sg->Clone(),i); | |
cf457606 | 126 | } |
127 | } | |
451f5018 | 128 | } |
43361342 | 129 | for (int i=AliITSUAux::kMaxLayers;i--;) fLr2Wrapper[i] = src.fLr2Wrapper[i]; |
451f5018 | 130 | } |
ce886e8e | 131 | |
451f5018 | 132 | //______________________________________________________________________ |
133 | AliITSUGeomTGeo::~AliITSUGeomTGeo() | |
134 | { | |
135 | //d-tor | |
136 | delete[] fNLadders; | |
137 | delete[] fLrDetType; | |
138 | delete[] fNDetectors; | |
139 | delete[] fLastModIndex; | |
cf457606 | 140 | delete fMatT2L; |
141 | delete fMatSens; | |
546d00d8 | 142 | delete fSegm; |
451f5018 | 143 | } |
ce886e8e | 144 | |
145 | ||
146 | //______________________________________________________________________ | |
451f5018 | 147 | AliITSUGeomTGeo& AliITSUGeomTGeo::operator=(const AliITSUGeomTGeo &src) |
148 | { | |
149 | // cp op. | |
150 | if (this!=&src) { | |
151 | delete[] fNLadders; | |
152 | delete[] fLrDetType; | |
153 | delete[] fNDetectors; | |
154 | delete[] fLastModIndex; | |
155 | fNLadders = fLrDetType = fNDetectors = fLastModIndex = 0; | |
156 | fVersion = src.fVersion; | |
157 | fNLayers = src.fNLayers; | |
158 | fNModules = src.fNModules; | |
cf457606 | 159 | if (src.fMatSens) { |
160 | delete fMatSens; | |
161 | fMatSens = new TObjArray(fNModules); | |
162 | fMatSens->SetOwner(kTRUE); | |
163 | for (int i=0;i<fNModules;i++) { | |
164 | const TGeoHMatrix* mat = (TGeoHMatrix*) src.fMatSens->At(i); | |
165 | fMatSens->AddAt(new TGeoHMatrix(*mat),i); | |
166 | } | |
167 | } | |
168 | if (src.fMatT2L) { | |
169 | delete fMatT2L; | |
170 | fMatT2L = new TObjArray(fNModules); | |
171 | fMatT2L->SetOwner(kTRUE); | |
172 | for (int i=0;i<fNModules;i++) { | |
173 | const TGeoHMatrix* mat = (TGeoHMatrix*) src.fMatT2L->At(i); | |
174 | fMatT2L->AddAt(new TGeoHMatrix(*mat),i); | |
175 | } | |
176 | } | |
546d00d8 | 177 | if (src.fSegm) { |
178 | int sz = src.fSegm->GetEntriesFast(); | |
179 | fSegm = new TObjArray(sz); | |
180 | fSegm->SetOwner(kTRUE); | |
181 | for (int i=0;i<sz;i++) { | |
182 | AliITSsegmentation* sg = (AliITSsegmentation*)src.fSegm->UncheckedAt(i); | |
183 | if (!sg) continue; | |
184 | fSegm->AddAt(sg->Clone(),i); | |
185 | } | |
186 | } | |
cf457606 | 187 | // |
451f5018 | 188 | if (fNLayers) { |
189 | fNLadders = new Int_t[fNLayers]; | |
190 | fNDetectors = new Int_t[fNLayers]; | |
191 | fLrDetType = new Int_t[fNLayers]; | |
192 | fLastModIndex = new Int_t[fNLayers]; | |
193 | for (int i=fNLayers;i--;) { | |
194 | fNLadders[i] = src.fNLadders[i]; | |
195 | fNDetectors[i] = src.fNDetectors[i]; | |
196 | fLrDetType[i] = src.fLrDetType[i]; | |
197 | fLastModIndex[i] = src.fLastModIndex[i]; | |
198 | } | |
199 | } | |
200 | } | |
201 | return *this; | |
202 | } | |
203 | ||
204 | //______________________________________________________________________ | |
205 | Int_t AliITSUGeomTGeo::GetModuleIndex(Int_t lay,Int_t lad,Int_t det) const | |
ce886e8e | 206 | { |
ce886e8e | 207 | // This routine computes the module index number from the layer, |
208 | // ladder, and detector numbers. The number of ladders and detectors | |
209 | // per layer is set statically | |
210 | // see above for details. | |
211 | // Inputs: | |
451f5018 | 212 | // Int_t lay The layer number. Starting from 0. |
213 | // Int_t lad The ladder number. Starting from 0 | |
214 | // Int_t det The detector number in the ladder. Starting from 0 | |
ce886e8e | 215 | // |
451f5018 | 216 | return GetFirstModIndex(lay) + fNDetectors[lay]*lad + det; |
ce886e8e | 217 | } |
218 | ||
219 | //______________________________________________________________________ | |
451f5018 | 220 | Bool_t AliITSUGeomTGeo::GetLayer(Int_t index,Int_t &lay,Int_t &index2) const |
ce886e8e | 221 | { |
ce886e8e | 222 | // This routine computes the layer number for a |
451f5018 | 223 | // given the module index. The |
ce886e8e | 224 | // Inputs: |
225 | // Int_t index The module index number, starting from zero. | |
226 | // Outputs: | |
227 | // Int_t index2 The module index inside a layer, starting from zero. | |
451f5018 | 228 | // Int_t lay The layer number. Starting from 0. |
229 | // | |
230 | lay = GetLayer(index); | |
231 | index2 = index - GetFirstModIndex(lay); | |
232 | return kTRUE; | |
233 | // | |
234 | } | |
ce886e8e | 235 | |
451f5018 | 236 | //______________________________________________________________________ |
237 | Int_t AliITSUGeomTGeo::GetLayer(Int_t index) const | |
238 | { | |
239 | // Get module layer, from 0 | |
240 | // | |
241 | int lay = 0; | |
02d6eccc | 242 | while(index>fLastModIndex[lay]) lay++; |
243 | return lay; | |
451f5018 | 244 | } |
ce886e8e | 245 | |
451f5018 | 246 | //______________________________________________________________________ |
247 | Int_t AliITSUGeomTGeo::GetLadder(Int_t index) const | |
248 | { | |
249 | // Get module ladder, from 0 | |
250 | // | |
251 | int lay = 0; | |
02d6eccc | 252 | while(index>fLastModIndex[lay]) lay++; |
253 | index -= GetFirstModIndex(lay); | |
451f5018 | 254 | return index/fNDetectors[lay]; |
ce886e8e | 255 | } |
256 | ||
257 | //______________________________________________________________________ | |
451f5018 | 258 | Int_t AliITSUGeomTGeo::GetModIdInLayer(Int_t index) const |
259 | { | |
260 | // Get module number within layer, from 0 | |
261 | // | |
262 | int lay = 0; | |
02d6eccc | 263 | while(index>fLastModIndex[lay]) lay++; |
264 | index -= GetFirstModIndex(lay); | |
451f5018 | 265 | return index; |
266 | } | |
267 | ||
268 | //______________________________________________________________________ | |
269 | Int_t AliITSUGeomTGeo::GetModIdInLadder(Int_t index) const | |
270 | { | |
271 | // Get module number within ladder, from 0 | |
272 | // | |
273 | int lay = 0; | |
02d6eccc | 274 | while(index>fLastModIndex[lay]) lay++; |
275 | index -= GetFirstModIndex(lay); | |
451f5018 | 276 | return index%fNDetectors[lay]; |
277 | } | |
278 | ||
279 | //______________________________________________________________________ | |
280 | Bool_t AliITSUGeomTGeo::GetModuleId(Int_t index,Int_t &lay,Int_t &lad,Int_t &det) const | |
ce886e8e | 281 | { |
282 | // The method is taken from the old AliITSgeom class by Bjorn Nilsen | |
283 | // | |
284 | // This routine computes the layer, ladder and detector number | |
451f5018 | 285 | // given the module index number. |
ce886e8e | 286 | // Inputs: |
287 | // Int_t index The module index number, starting from zero. | |
288 | // Outputs: | |
451f5018 | 289 | // Int_t lay The layer number. Starting from 0 |
290 | // Int_t lad The ladder number. Starting from 0 | |
291 | // Int_t det The detector number. Starting from 0 | |
292 | // | |
293 | lay = GetLayer(index); | |
294 | index -= GetFirstModIndex(lay); | |
295 | lad = index/fNDetectors[lay]; | |
296 | det = index%fNDetectors[lay]; | |
ce886e8e | 297 | return kTRUE; |
298 | } | |
299 | ||
300 | //______________________________________________________________________ | |
451f5018 | 301 | const char* AliITSUGeomTGeo::GetSymName(Int_t index) const |
ce886e8e | 302 | { |
303 | // Get the TGeoPNEntry symbolic name | |
304 | // for a given module identified by 'index' | |
ce886e8e | 305 | // |
ce886e8e | 306 | Int_t lay, index2; |
307 | if (!GetLayer(index,lay,index2)) return NULL; | |
451f5018 | 308 | // return AliGeomManager::SymName((AliGeomManager::ELayerID)((lay-1)+AliGeomManager::kSPD1),index2); |
309 | // RS: this is not optimal, but we cannod access directly AliGeomManager, since the latter has hardwired layers | |
02d6eccc | 310 | // TGeoPNEntry* pne = gGeoManager->GetAlignableEntryByUID( AliGeomManager::LayerToVolUID(lay+1,index2) ); |
311 | TGeoPNEntry* pne = gGeoManager->GetAlignableEntryByUID( ModuleVolUID(index) ); | |
451f5018 | 312 | if (!pne) { |
313 | AliError(Form("Failed to find alignable entry with index %d: (Lr%d Mod:%d) !",index,lay,index2)); | |
314 | return NULL; | |
ce886e8e | 315 | } |
451f5018 | 316 | return pne->GetName(); |
ce886e8e | 317 | } |
318 | ||
392efe73 | 319 | //______________________________________________________________________ |
320 | const char* AliITSUGeomTGeo::ComposeSymNameITS() | |
321 | { | |
322 | // sym name of the layer | |
323 | return "ITS"; | |
324 | } | |
325 | ||
326 | //______________________________________________________________________ | |
327 | const char* AliITSUGeomTGeo::ComposeSymNameLayer(Int_t lr) | |
328 | { | |
329 | // sym name of the layer | |
330 | return Form("%s/%s%d",ComposeSymNameITS(),GetITSLayerPattern(),lr); | |
331 | } | |
332 | ||
333 | //______________________________________________________________________ | |
334 | const char* AliITSUGeomTGeo::ComposeSymNameLadder(Int_t lr, Int_t ladder) | |
335 | { | |
336 | // sym name of the ladder at given layer | |
337 | return Form("%s/%s%d",ComposeSymNameLayer(lr),GetITSLadderPattern(),ladder); | |
338 | } | |
339 | ||
340 | //______________________________________________________________________ | |
341 | const char* AliITSUGeomTGeo::ComposeSymNameModule(Int_t lr, Int_t lad, int det) | |
342 | { | |
343 | // sym name of the module | |
344 | return Form("%s/%s%d",ComposeSymNameLadder(lr,lad),GetITSModulePattern(),det); | |
345 | } | |
346 | ||
ce886e8e | 347 | //______________________________________________________________________ |
451f5018 | 348 | TGeoHMatrix* AliITSUGeomTGeo::GetMatrix(Int_t index) const |
ce886e8e | 349 | { |
350 | // Get the transformation matrix for a given module 'index' | |
351 | // by quering the TGeoManager | |
dde91d5d | 352 | static TGeoHMatrix matTmp; |
ce886e8e | 353 | TGeoPNEntry *pne = GetPNEntry(index); |
354 | if (!pne) return NULL; | |
355 | ||
356 | TGeoPhysicalNode *pnode = pne->GetPhysicalNode(); | |
357 | if (pnode) return pnode->GetMatrix(); | |
358 | ||
359 | const char* path = pne->GetTitle(); | |
451f5018 | 360 | gGeoManager->PushPath(); // Preserve the modeler state. |
ce886e8e | 361 | if (!gGeoManager->cd(path)) { |
451f5018 | 362 | gGeoManager->PopPath(); |
363 | AliError(Form("Volume path %s not valid!",path)); | |
ce886e8e | 364 | return NULL; |
365 | } | |
dde91d5d | 366 | matTmp = *gGeoManager->GetCurrentMatrix(); |
451f5018 | 367 | gGeoManager->PopPath(); |
dde91d5d | 368 | return &matTmp; |
ce886e8e | 369 | } |
370 | ||
371 | //______________________________________________________________________ | |
451f5018 | 372 | Bool_t AliITSUGeomTGeo::GetTranslation(Int_t index, Double_t t[3]) const |
ce886e8e | 373 | { |
374 | // Get the translation vector for a given module 'index' | |
375 | // by quering the TGeoManager | |
ce886e8e | 376 | TGeoHMatrix *m = GetMatrix(index); |
377 | if (!m) return kFALSE; | |
378 | ||
379 | Double_t *trans = m->GetTranslation(); | |
380 | for (Int_t i = 0; i < 3; i++) t[i] = trans[i]; | |
381 | ||
382 | return kTRUE; | |
383 | } | |
384 | ||
385 | //______________________________________________________________________ | |
451f5018 | 386 | Bool_t AliITSUGeomTGeo::GetRotation(Int_t index, Double_t r[9]) const |
ce886e8e | 387 | { |
388 | // Get the rotation matrix for a given module 'index' | |
389 | // by quering the TGeoManager | |
ce886e8e | 390 | TGeoHMatrix *m = GetMatrix(index); |
391 | if (!m) return kFALSE; | |
392 | ||
393 | Double_t *rot = m->GetRotationMatrix(); | |
394 | for (Int_t i = 0; i < 9; i++) r[i] = rot[i]; | |
395 | ||
396 | return kTRUE; | |
397 | } | |
398 | ||
399 | //______________________________________________________________________ | |
451f5018 | 400 | Bool_t AliITSUGeomTGeo::GetOrigMatrix(Int_t index, TGeoHMatrix &m) const |
ce886e8e | 401 | { |
402 | // Get the original (ideal geometry) TGeo matrix for | |
403 | // a given module identified by 'index'. | |
404 | // The method is slow, so it should be used | |
405 | // with great care. | |
ce886e8e | 406 | m.Clear(); |
407 | ||
408 | const char *symname = GetSymName(index); | |
409 | if (!symname) return kFALSE; | |
410 | ||
411 | return AliGeomManager::GetOrigGlobalMatrix(symname,m); | |
412 | } | |
413 | ||
414 | //______________________________________________________________________ | |
451f5018 | 415 | Bool_t AliITSUGeomTGeo::GetOrigTranslation(Int_t index, Double_t t[3]) const |
ce886e8e | 416 | { |
417 | // Get the original translation vector (ideal geometry) | |
418 | // for a given module 'index' by quering the TGeoManager | |
ce886e8e | 419 | TGeoHMatrix m; |
420 | if (!GetOrigMatrix(index,m)) return kFALSE; | |
421 | ||
422 | Double_t *trans = m.GetTranslation(); | |
423 | for (Int_t i = 0; i < 3; i++) t[i] = trans[i]; | |
424 | ||
425 | return kTRUE; | |
426 | } | |
427 | ||
428 | //______________________________________________________________________ | |
451f5018 | 429 | Bool_t AliITSUGeomTGeo::GetOrigRotation(Int_t index, Double_t r[9]) const |
ce886e8e | 430 | { |
431 | // Get the original rotation matrix (ideal geometry) | |
432 | // for a given module 'index' by quering the TGeoManager | |
ce886e8e | 433 | TGeoHMatrix m; |
434 | if (!GetOrigMatrix(index,m)) return kFALSE; | |
435 | ||
436 | Double_t *rot = m.GetRotationMatrix(); | |
437 | for (Int_t i = 0; i < 9; i++) r[i] = rot[i]; | |
438 | ||
439 | return kTRUE; | |
440 | } | |
441 | ||
442 | //______________________________________________________________________ | |
cf457606 | 443 | TGeoHMatrix* AliITSUGeomTGeo::ExtractMatrixT2L(Int_t index) const |
ce886e8e | 444 | { |
445 | // Get the matrix which transforms from the tracking to local r.s. | |
446 | // The method queries directly the TGeoPNEntry | |
ce886e8e | 447 | TGeoPNEntry *pne = GetPNEntry(index); |
448 | if (!pne) return NULL; | |
449 | ||
cf457606 | 450 | TGeoHMatrix *m = (TGeoHMatrix*) pne->GetMatrix(); |
451 | if (!m) AliError(Form("TGeoPNEntry (%s) contains no matrix !",pne->GetName())); | |
ce886e8e | 452 | |
453 | return m; | |
454 | } | |
455 | ||
456 | //______________________________________________________________________ | |
cf457606 | 457 | Bool_t AliITSUGeomTGeo::GetTrackingMatrix(Int_t index, TGeoHMatrix &m) |
ce886e8e | 458 | { |
459 | // Get the matrix which transforms from the tracking r.s. to | |
460 | // the global one. | |
461 | // Returns kFALSE in case of error. | |
ce886e8e | 462 | m.Clear(); |
463 | ||
464 | TGeoHMatrix *m1 = GetMatrix(index); | |
465 | if (!m1) return kFALSE; | |
466 | ||
cf457606 | 467 | const TGeoHMatrix *m2 = GetMatrixT2L(index); |
ce886e8e | 468 | if (!m2) return kFALSE; |
469 | ||
470 | m = *m1; | |
471 | m.Multiply(m2); | |
472 | ||
473 | return kTRUE; | |
474 | } | |
475 | ||
476 | //______________________________________________________________________ | |
cf457606 | 477 | TGeoHMatrix* AliITSUGeomTGeo::ExtractMatrixSens(Int_t index) const |
451f5018 | 478 | { |
cf457606 | 479 | // Get the transformation matrix of the SENSOR (not ncessary the same as the module) |
480 | // for a given module 'index' by quering the TGeoManager | |
616016f9 | 481 | static TGeoHMatrix matTmp; |
02d6eccc | 482 | const TString kPathBase = Form("/ALIC_1/%s_2/",AliITSUGeomTGeo::GetITSVolPattern()); |
43361342 | 483 | const TString kNames = Form("%%s%%s%s%%d_1/%s%%d_%%d/%s%%d_%%d/%s%%d_%%d" |
451f5018 | 484 | ,AliITSUGeomTGeo::GetITSLayerPattern() |
485 | ,AliITSUGeomTGeo::GetITSLadderPattern() | |
486 | ,AliITSUGeomTGeo::GetITSModulePattern() | |
487 | ,AliITSUGeomTGeo::GetITSSensorPattern()); | |
488 | TString path; | |
cf457606 | 489 | Int_t lay,ladd,detInLad; |
490 | GetModuleId(index,lay,ladd,detInLad); | |
451f5018 | 491 | // |
43361342 | 492 | int wrID = fLr2Wrapper[lay]; |
493 | path.Form(kNames.Data(),kPathBase.Data(),wrID>=0 ? Form("%s%d_1/",GetITSWrapVolPattern(),wrID) : "", | |
494 | lay,lay,ladd,lay,detInLad,lay,1); | |
451f5018 | 495 | gGeoManager->PushPath(); |
496 | if (!gGeoManager->cd(path.Data())) { | |
497 | gGeoManager->PopPath(); | |
498 | AliError(Form("Error in cd-ing to %s",path.Data())); | |
499 | return 0; | |
500 | } // end if !gGeoManager | |
616016f9 | 501 | matTmp = *gGeoManager->GetCurrentMatrix(); // matrix may change after cd |
4fa9d550 | 502 | //RSS |
503 | // printf("%d/%d/%d %s\n",lay,ladd,detInLad,path.Data()); | |
504 | // mat->Print(); | |
451f5018 | 505 | // Retstore the modeler state. |
506 | gGeoManager->PopPath(); | |
616016f9 | 507 | return &matTmp; |
451f5018 | 508 | } |
509 | ||
510 | ||
511 | //______________________________________________________________________ | |
512 | TGeoPNEntry* AliITSUGeomTGeo::GetPNEntry(Int_t index) const | |
ce886e8e | 513 | { |
514 | // Get a pointer to the TGeoPNEntry of a module | |
515 | // identified by 'index' | |
516 | // Returns NULL in case of invalid index, | |
517 | // missing TGeoManager or invalid symbolic name | |
ce886e8e | 518 | // |
451f5018 | 519 | if (index >= fNModules) { |
520 | AliError(Form("Invalid ITS module index: %d (0 -> %d) !",index,fNModules)); | |
ce886e8e | 521 | return NULL; |
522 | } | |
523 | ||
524 | if (!gGeoManager || !gGeoManager->IsClosed()) { | |
451f5018 | 525 | AliError("Can't get the matrix! gGeoManager doesn't exist or it is still opened!"); |
ce886e8e | 526 | return NULL; |
527 | } | |
528 | ||
529 | TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(GetSymName(index)); | |
451f5018 | 530 | if (!pne) AliError(Form("The symbolic volume name %s does not correspond to a physical entry!",GetSymName(index))); |
531 | // | |
ce886e8e | 532 | return pne; |
533 | } | |
534 | ||
ce886e8e | 535 | //______________________________________________________________________ |
546d00d8 | 536 | void AliITSUGeomTGeo::BuildITS(Bool_t loadSegm) |
ce886e8e | 537 | { |
538 | // exract upg ITS parameters from TGeo | |
451f5018 | 539 | if (fVersion!=kITSVNA) {AliWarning("Already built"); return; // already initialized} |
540 | if (!gGeoManager) AliFatal("Geometry is not loaded"); | |
ce886e8e | 541 | } |
451f5018 | 542 | fNLayers = ExtractNumberOfLayers(); |
543 | if (!fNLayers) return; | |
544 | // | |
545 | fNLadders = new Int_t[fNLayers]; | |
546 | fNDetectors = new Int_t[fNLayers]; | |
547 | fLrDetType = new Int_t[fNLayers]; | |
548 | fLastModIndex = new Int_t[fNLayers]; | |
549 | fNModules = 0; | |
550 | for (int i=0;i<fNLayers;i++) { | |
551 | fNLadders[i] = ExtractNumberOfLadders(i); | |
552 | fNDetectors[i] = ExtractNumberOfDetectors(i); | |
553 | fLrDetType[i] = ExtractLayerDetType(i); | |
554 | fNModules += fNLadders[i]*fNDetectors[i]; | |
555 | fLastModIndex[i] = fNModules-1; | |
556 | } | |
557 | // | |
cf457606 | 558 | FetchMatrices(); |
451f5018 | 559 | fVersion = kITSVUpg; |
ce886e8e | 560 | // |
546d00d8 | 561 | if (loadSegm) { // fetch segmentations |
562 | fSegm = new TObjArray(); | |
563 | AliITSUSegmentationPix::LoadSegmentations(fSegm,GetITSsegmentationFileName()); | |
564 | } | |
565 | // | |
ce886e8e | 566 | } |
567 | ||
568 | //______________________________________________________________________ | |
43361342 | 569 | Int_t AliITSUGeomTGeo::ExtractNumberOfLayers() |
ce886e8e | 570 | { |
571 | // Determines the number of layers in the Upgrade Geometry | |
572 | // | |
ce886e8e | 573 | Int_t numberOfLayers = 0; |
574 | // | |
575 | TGeoVolume *itsV = gGeoManager->GetVolume(fgkITSVolName); | |
451f5018 | 576 | if (!itsV) AliFatal(Form("ITS volume %s is not in the geometry",fgkITSVolName)); |
ce886e8e | 577 | // |
578 | // Loop on all ITSV nodes, count Layer volumes by checking names | |
43361342 | 579 | // Build on the fly layer - wrapper correspondence |
580 | TObjArray* nodes = itsV->GetNodes(); | |
581 | Int_t nNodes = nodes->GetEntriesFast(); | |
582 | // | |
583 | int nWrp = 0; | |
584 | for (Int_t j=0; j<nNodes; j++) { | |
585 | TGeoNode* nd = (TGeoNode*)nodes->At(j); | |
586 | const char* name = nd->GetName(); | |
587 | if (strstr(name,fgkITSLrName)) numberOfLayers++; | |
588 | else if (strstr(name,fgkITSWrapVolName)) { // this is a wrapper volume, may cointain layers | |
589 | TObjArray* nodesW = nd->GetNodes(); | |
590 | int nNodesW = nodesW->GetEntriesFast(); | |
591 | for (Int_t jw=0; jw<nNodesW; jw++) { | |
592 | TGeoNode* ndW = (TGeoNode*)nodesW->At(jw); | |
593 | if (strstr(ndW->GetName(),fgkITSLrName)) fLr2Wrapper[numberOfLayers++] = nWrp; | |
594 | } | |
595 | nWrp++; | |
596 | } | |
597 | } | |
ce886e8e | 598 | // |
599 | return numberOfLayers; | |
600 | } | |
601 | ||
602 | //______________________________________________________________________ | |
451f5018 | 603 | Int_t AliITSUGeomTGeo::ExtractNumberOfLadders(Int_t lay) const |
ce886e8e | 604 | { |
605 | // Determines the number of layers in the Upgrade Geometry | |
606 | // | |
607 | // Inputs: | |
451f5018 | 608 | // lay: layer number, starting from 0 |
609 | // | |
ce886e8e | 610 | // MS |
611 | Int_t numberOfLadders = 0; | |
612 | char laynam[30]; | |
613 | snprintf(laynam, 30, "%s%d",fgkITSLrName,lay); | |
614 | TGeoVolume* volLr = gGeoManager->GetVolume(laynam); | |
451f5018 | 615 | if (!volLr) AliFatal(Form("can't find %s volume",laynam)); |
ce886e8e | 616 | // |
617 | // Loop on all layer nodes, count Ladder volumes by checking names | |
618 | Int_t nNodes = volLr->GetNodes()->GetEntries(); | |
619 | for (Int_t j=0; j<nNodes; j++) if (strstr(volLr->GetNodes()->At(j)->GetName(),fgkITSLadName)) numberOfLadders++; | |
620 | // | |
621 | return numberOfLadders; | |
622 | // | |
623 | } | |
624 | ||
625 | //______________________________________________________________________ | |
451f5018 | 626 | Int_t AliITSUGeomTGeo::ExtractNumberOfDetectors(Int_t lay) const |
ce886e8e | 627 | { |
628 | // Determines the number of detectors per ladder in the Upgrade Geometry | |
629 | // | |
630 | // Inputs: | |
451f5018 | 631 | // lay: layer number from 0 |
ce886e8e | 632 | // MS |
633 | Int_t numberOfModules = 0; | |
634 | char laddnam[30]; | |
635 | snprintf(laddnam, 30, "%s%d", fgkITSLadName,lay); | |
636 | TGeoVolume* volLd = gGeoManager->GetVolume(laddnam); | |
451f5018 | 637 | if (!volLd) AliFatal(Form("can't find %s volume",laddnam)); |
ce886e8e | 638 | // |
639 | // Loop on all ladder nodes, count Module volumes by checking names | |
640 | Int_t nNodes = volLd->GetNodes()->GetEntries(); | |
535d15f5 | 641 | for (Int_t j=0; j<nNodes; j++) if (strstr(volLd->GetNodes()->At(j)->GetName(),fgkITSModName)) numberOfModules++; |
ce886e8e | 642 | // |
643 | return numberOfModules; | |
644 | // | |
645 | } | |
535d15f5 | 646 | |
647 | //______________________________________________________________________ | |
451f5018 | 648 | Int_t AliITSUGeomTGeo::ExtractLayerDetType(Int_t lay) const |
535d15f5 | 649 | { |
650 | // Determines the layer detector type the Upgrade Geometry | |
651 | // | |
652 | // Inputs: | |
75875328 | 653 | // lay: layer number from 0 |
535d15f5 | 654 | // Outputs: |
655 | // none | |
656 | // Return: | |
657 | // detector type id for the layer | |
658 | // MS | |
659 | char laddnam[30]; | |
660 | snprintf(laddnam, 30, "%s%d", fgkITSLrName,lay); | |
661 | TGeoVolume* volLd = gGeoManager->GetVolume(laddnam); | |
451f5018 | 662 | if (!volLd) {AliFatal(Form("can't find %s volume",laddnam)); return -1;} |
535d15f5 | 663 | // |
664 | return volLd->GetUniqueID(); | |
665 | // | |
666 | } | |
451f5018 | 667 | |
668 | //______________________________________________________________________ | |
669 | UInt_t AliITSUGeomTGeo::ComposeDetTypeID(UInt_t segmId) | |
670 | { | |
671 | if (segmId>=kMaxSegmPerDetType) AliFatalClass(Form("Id=%d is >= max.allowed %d",segmId,kMaxSegmPerDetType)); | |
02d6eccc | 672 | return segmId + kDetTypePix*kMaxSegmPerDetType; |
673 | } | |
674 | ||
675 | //______________________________________________________________________ | |
676 | void AliITSUGeomTGeo::Print(Option_t *) const | |
677 | { | |
678 | ||
679 | printf("Geometry version %d, NLayers:%d NModules:%d\n",fVersion,fNLayers,fNModules); | |
680 | if (fVersion==kITSVNA) return; | |
681 | for (int i=0;i<fNLayers;i++) { | |
43361342 | 682 | printf("Lr%2d\tNLadd:%2d\tNDet:%2d\tDetType:%3d\tMod#:%4d:%4d\tWrapVol:%d\n", |
683 | i,fNLadders[i],fNDetectors[i],fLrDetType[i],GetFirstModIndex(i),GetLastModIndex(i),fLr2Wrapper[i]); | |
02d6eccc | 684 | } |
451f5018 | 685 | } |
cf457606 | 686 | |
687 | //______________________________________________________________________ | |
688 | void AliITSUGeomTGeo::FetchMatrices() | |
689 | { | |
690 | // store pointer on often used matrices for faster access | |
691 | if (!gGeoManager) AliFatal("Geometry is not loaded"); | |
692 | fMatSens = new TObjArray(fNModules); | |
693 | fMatSens->SetOwner(kTRUE); | |
af4b47c9 | 694 | for (int i=0;i<fNModules;i++) fMatSens->AddAt(new TGeoHMatrix(*ExtractMatrixSens(i)),i); |
695 | CreateT2LMatrices(); | |
696 | } | |
697 | ||
698 | //______________________________________________________________________ | |
699 | void AliITSUGeomTGeo::CreateT2LMatrices() | |
700 | { | |
701 | // create tracking to local (Sensor!) matrices | |
cf457606 | 702 | fMatT2L = new TObjArray(fNModules); |
703 | fMatT2L->SetOwner(kTRUE); | |
af4b47c9 | 704 | TGeoHMatrix matLtoT; |
705 | double loc[3]={0,0,0},glo[3]; | |
706 | const double *rotm; | |
707 | for (int isn=0;isn<fNModules;isn++) { | |
708 | const TGeoHMatrix* matSens = GetMatrixSens(isn); | |
709 | if (!matSens) {AliFatal(Form("Failed to get matrix for sensor %d",isn)); return;} | |
710 | matSens->LocalToMaster(loc,glo); | |
711 | rotm = matSens->GetRotationMatrix(); | |
712 | Double_t al = -ATan2(rotm[1],rotm[0]); | |
3b9474b3 | 713 | double sn=Sin(al), cs=Cos(al), r=glo[0]*sn-glo[1]*cs, x=r*sn, y=-r*cs; // sensor plane PCA to origin |
af4b47c9 | 714 | TGeoHMatrix* t2l = new TGeoHMatrix(); |
715 | t2l->RotateZ(ATan2(y,x)*RadToDeg()); // rotate in direction of normal to the sensor plane | |
716 | t2l->SetDx(x); | |
717 | t2l->SetDy(y); | |
718 | t2l->MultiplyLeft(&matSens->Inverse()); | |
719 | fMatT2L->AddAt(t2l,isn); | |
720 | /* | |
721 | const double *gtrans = matSens->GetTranslation(); | |
722 | memcpy(&rotMatrix[0], matSens->GetRotationMatrix(), 9*sizeof(Double_t)); | |
723 | Double_t al = -ATan2(rotMatrix[1],rotMatrix[0]); | |
724 | Double_t rSens = Sqrt(gtrans[0]*gtrans[0] + gtrans[1]*gtrans[1]); | |
725 | Double_t tanAl = ATan2(gtrans[1],gtrans[0]) - Pi()/2; //angle of tangent | |
726 | Double_t alTr = tanAl - al; | |
727 | // | |
728 | // The X axis of tracking frame must always look outward | |
729 | loc[1] = rSens/2; | |
730 | matSens->LocalToMaster(loc,glo); | |
731 | double rPos = Sqrt(glo[0]*glo[0] + glo[1]*glo[1]); | |
732 | Bool_t rotOutward = rPos>rSens ? kFALSE : kTRUE; | |
733 | // | |
734 | // Transformation matrix | |
735 | matLtoT.Clear(); | |
736 | matLtoT.SetDx(-rSens*Sin(alTr)); // translation | |
737 | matLtoT.SetDy(0.); | |
738 | matLtoT.SetDz(gtrans[2]); | |
739 | // Rotation matrix | |
740 | rotMatrix[0]= 0; rotMatrix[1]= 1; rotMatrix[2]= 0; // + rotation | |
741 | rotMatrix[3]=-1; rotMatrix[4]= 0; rotMatrix[5]= 0; | |
742 | rotMatrix[6]= 0; rotMatrix[7]= 0; rotMatrix[8]= 1; | |
743 | // | |
744 | TGeoRotation rot; | |
745 | rot.SetMatrix(rotMatrix); | |
746 | matLtoT.MultiplyLeft(&rot); | |
747 | if (rotOutward) matLtoT.RotateZ(180.); | |
748 | // Inverse transformation Matrix | |
749 | fMatT2L->AddAt(new TGeoHMatrix(matLtoT.Inverse()),isn); | |
750 | */ | |
cf457606 | 751 | } |
af4b47c9 | 752 | // |
cf457606 | 753 | } |
af4b47c9 | 754 |