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