]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/UPGRADE/AliITSUGeomTGeo.cxx
Add fine bin option and fix the pt weight option
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUGeomTGeo.cxx
CommitLineData
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 43using namespace TMath;
ce886e8e 44
451f5018 45ClassImp(AliITSUGeomTGeo)
46
ce886e8e 47
451f5018 48const char* AliITSUGeomTGeo::fgkITSVolName = "ITSV";
02d6eccc 49const char* AliITSUGeomTGeo::fgkITSLrName = "ITSULayer";
50const char* AliITSUGeomTGeo::fgkITSLadName = "ITSULadder";
51const char* AliITSUGeomTGeo::fgkITSModName = "ITSUModule";
52const char* AliITSUGeomTGeo::fgkITSSensName ="ITSUSensor";
53const char* AliITSUGeomTGeo::fgkITSDetTypeName[AliITSUGeomTGeo::kNDetTypes] = {"Pix"};
451f5018 54//
55TString AliITSUGeomTGeo::fgITSsegmFileName = "itsSegmentations.root";
ce886e8e 56
451f5018 57//______________________________________________________________________
546d00d8 58AliITSUGeomTGeo::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//______________________________________________________________________
75AliITSUGeomTGeo::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//______________________________________________________________________
130AliITSUGeomTGeo::~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 144AliITSUGeomTGeo& 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//______________________________________________________________________
202Int_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 217Bool_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//______________________________________________________________________
234Int_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//______________________________________________________________________
244Int_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 255Int_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//______________________________________________________________________
266Int_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//______________________________________________________________________
277Bool_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 298const 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//______________________________________________________________________
317const char* AliITSUGeomTGeo::ComposeSymNameITS()
318{
319 // sym name of the layer
320 return "ITS";
321}
322
323//______________________________________________________________________
324const 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//______________________________________________________________________
331const 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//______________________________________________________________________
338const 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 345TGeoHMatrix* 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 368Bool_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 382Bool_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 396Bool_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 411Bool_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 425Bool_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 439TGeoHMatrix* 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 453Bool_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 473TGeoHMatrix* 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
02d6eccc 477 const TString kPathBase = Form("/ALIC_1/%s_2/",AliITSUGeomTGeo::GetITSVolPattern());
451f5018 478 const TString kNames = Form("%%s%s%%d_1/%s%%d_%%d/%s%%d_%%d/%s%%d_%%d"
479 ,AliITSUGeomTGeo::GetITSLayerPattern()
480 ,AliITSUGeomTGeo::GetITSLadderPattern()
481 ,AliITSUGeomTGeo::GetITSModulePattern()
482 ,AliITSUGeomTGeo::GetITSSensorPattern());
483 TString path;
cf457606 484 Int_t lay,ladd,detInLad;
485 GetModuleId(index,lay,ladd,detInLad);
451f5018 486 //
487 path.Form(kNames.Data(),kPathBase.Data(),lay,lay,ladd,lay,detInLad,lay,1);
488 gGeoManager->PushPath();
489 if (!gGeoManager->cd(path.Data())) {
490 gGeoManager->PopPath();
491 AliError(Form("Error in cd-ing to %s",path.Data()));
492 return 0;
493 } // end if !gGeoManager
494 TGeoHMatrix* mat = gGeoManager->GetCurrentMatrix();
4fa9d550 495 //RSS
496 // printf("%d/%d/%d %s\n",lay,ladd,detInLad,path.Data());
497 // mat->Print();
451f5018 498 // Retstore the modeler state.
499 gGeoManager->PopPath();
500 return mat;
501}
502
503
504//______________________________________________________________________
505TGeoPNEntry* AliITSUGeomTGeo::GetPNEntry(Int_t index) const
ce886e8e 506{
507 // Get a pointer to the TGeoPNEntry of a module
508 // identified by 'index'
509 // Returns NULL in case of invalid index,
510 // missing TGeoManager or invalid symbolic name
ce886e8e 511 //
451f5018 512 if (index >= fNModules) {
513 AliError(Form("Invalid ITS module index: %d (0 -> %d) !",index,fNModules));
ce886e8e 514 return NULL;
515 }
516
517 if (!gGeoManager || !gGeoManager->IsClosed()) {
451f5018 518 AliError("Can't get the matrix! gGeoManager doesn't exist or it is still opened!");
ce886e8e 519 return NULL;
520 }
521
522 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(GetSymName(index));
451f5018 523 if (!pne) AliError(Form("The symbolic volume name %s does not correspond to a physical entry!",GetSymName(index)));
524 //
ce886e8e 525 return pne;
526}
527
ce886e8e 528//______________________________________________________________________
546d00d8 529void AliITSUGeomTGeo::BuildITS(Bool_t loadSegm)
ce886e8e 530{
531 // exract upg ITS parameters from TGeo
451f5018 532 if (fVersion!=kITSVNA) {AliWarning("Already built"); return; // already initialized}
533 if (!gGeoManager) AliFatal("Geometry is not loaded");
ce886e8e 534 }
451f5018 535 fNLayers = ExtractNumberOfLayers();
536 if (!fNLayers) return;
537 //
538 fNLadders = new Int_t[fNLayers];
539 fNDetectors = new Int_t[fNLayers];
540 fLrDetType = new Int_t[fNLayers];
541 fLastModIndex = new Int_t[fNLayers];
542 fNModules = 0;
543 for (int i=0;i<fNLayers;i++) {
544 fNLadders[i] = ExtractNumberOfLadders(i);
545 fNDetectors[i] = ExtractNumberOfDetectors(i);
546 fLrDetType[i] = ExtractLayerDetType(i);
547 fNModules += fNLadders[i]*fNDetectors[i];
548 fLastModIndex[i] = fNModules-1;
549 }
550 //
cf457606 551 FetchMatrices();
451f5018 552 fVersion = kITSVUpg;
ce886e8e 553 //
546d00d8 554 if (loadSegm) { // fetch segmentations
555 fSegm = new TObjArray();
556 AliITSUSegmentationPix::LoadSegmentations(fSegm,GetITSsegmentationFileName());
557 }
558 //
ce886e8e 559}
560
561//______________________________________________________________________
451f5018 562Int_t AliITSUGeomTGeo::ExtractNumberOfLayers() const
ce886e8e 563{
564 // Determines the number of layers in the Upgrade Geometry
565 //
ce886e8e 566 Int_t numberOfLayers = 0;
567 //
568 TGeoVolume *itsV = gGeoManager->GetVolume(fgkITSVolName);
451f5018 569 if (!itsV) AliFatal(Form("ITS volume %s is not in the geometry",fgkITSVolName));
ce886e8e 570 //
571 // Loop on all ITSV nodes, count Layer volumes by checking names
572 Int_t nNodes = itsV->GetNodes()->GetEntries();
573 for (Int_t j=0; j<nNodes; j++) if (strstr(itsV->GetNodes()->At(j)->GetName(),fgkITSLrName)) numberOfLayers++;
574 //
575 return numberOfLayers;
576}
577
578//______________________________________________________________________
451f5018 579Int_t AliITSUGeomTGeo::ExtractNumberOfLadders(Int_t lay) const
ce886e8e 580{
581 // Determines the number of layers in the Upgrade Geometry
582 //
583 // Inputs:
451f5018 584 // lay: layer number, starting from 0
585 //
ce886e8e 586 // MS
587 Int_t numberOfLadders = 0;
588 char laynam[30];
589 snprintf(laynam, 30, "%s%d",fgkITSLrName,lay);
590 TGeoVolume* volLr = gGeoManager->GetVolume(laynam);
451f5018 591 if (!volLr) AliFatal(Form("can't find %s volume",laynam));
ce886e8e 592 //
593 // Loop on all layer nodes, count Ladder volumes by checking names
594 Int_t nNodes = volLr->GetNodes()->GetEntries();
595 for (Int_t j=0; j<nNodes; j++) if (strstr(volLr->GetNodes()->At(j)->GetName(),fgkITSLadName)) numberOfLadders++;
596 //
597 return numberOfLadders;
598 //
599}
600
601//______________________________________________________________________
451f5018 602Int_t AliITSUGeomTGeo::ExtractNumberOfDetectors(Int_t lay) const
ce886e8e 603{
604 // Determines the number of detectors per ladder in the Upgrade Geometry
605 //
606 // Inputs:
451f5018 607 // lay: layer number from 0
ce886e8e 608 // MS
609 Int_t numberOfModules = 0;
610 char laddnam[30];
611 snprintf(laddnam, 30, "%s%d", fgkITSLadName,lay);
612 TGeoVolume* volLd = gGeoManager->GetVolume(laddnam);
451f5018 613 if (!volLd) AliFatal(Form("can't find %s volume",laddnam));
ce886e8e 614 //
615 // Loop on all ladder nodes, count Module volumes by checking names
616 Int_t nNodes = volLd->GetNodes()->GetEntries();
535d15f5 617 for (Int_t j=0; j<nNodes; j++) if (strstr(volLd->GetNodes()->At(j)->GetName(),fgkITSModName)) numberOfModules++;
ce886e8e 618 //
619 return numberOfModules;
620 //
621}
535d15f5 622
623//______________________________________________________________________
451f5018 624Int_t AliITSUGeomTGeo::ExtractLayerDetType(Int_t lay) const
535d15f5 625{
626 // Determines the layer detector type the Upgrade Geometry
627 //
628 // Inputs:
75875328 629 // lay: layer number from 0
535d15f5 630 // Outputs:
631 // none
632 // Return:
633 // detector type id for the layer
634 // MS
635 char laddnam[30];
636 snprintf(laddnam, 30, "%s%d", fgkITSLrName,lay);
637 TGeoVolume* volLd = gGeoManager->GetVolume(laddnam);
451f5018 638 if (!volLd) {AliFatal(Form("can't find %s volume",laddnam)); return -1;}
535d15f5 639 //
640 return volLd->GetUniqueID();
641 //
642}
451f5018 643
644//______________________________________________________________________
645UInt_t AliITSUGeomTGeo::ComposeDetTypeID(UInt_t segmId)
646{
647 if (segmId>=kMaxSegmPerDetType) AliFatalClass(Form("Id=%d is >= max.allowed %d",segmId,kMaxSegmPerDetType));
02d6eccc 648 return segmId + kDetTypePix*kMaxSegmPerDetType;
649}
650
651//______________________________________________________________________
652void AliITSUGeomTGeo::Print(Option_t *) const
653{
654 // print
655 printf("Geometry version %d, NLayers:%d NModules:%d\n",fVersion,fNLayers,fNModules);
656 if (fVersion==kITSVNA) return;
657 for (int i=0;i<fNLayers;i++) {
658 printf("Lr%2d\tNLadd:%2d\tNDet:%2d\tDetType:%3d\tMod#:%4d:%4d\n",
659 i,fNLadders[i],fNDetectors[i],fLrDetType[i],GetFirstModIndex(i),GetLastModIndex(i));
660 }
451f5018 661}
cf457606 662
663//______________________________________________________________________
664void AliITSUGeomTGeo::FetchMatrices()
665{
666 // store pointer on often used matrices for faster access
667 if (!gGeoManager) AliFatal("Geometry is not loaded");
668 fMatSens = new TObjArray(fNModules);
669 fMatSens->SetOwner(kTRUE);
af4b47c9 670 for (int i=0;i<fNModules;i++) fMatSens->AddAt(new TGeoHMatrix(*ExtractMatrixSens(i)),i);
671 CreateT2LMatrices();
672}
673
674//______________________________________________________________________
675void AliITSUGeomTGeo::CreateT2LMatrices()
676{
677 // create tracking to local (Sensor!) matrices
cf457606 678 fMatT2L = new TObjArray(fNModules);
679 fMatT2L->SetOwner(kTRUE);
af4b47c9 680 TGeoHMatrix matLtoT;
681 double loc[3]={0,0,0},glo[3];
682 const double *rotm;
683 for (int isn=0;isn<fNModules;isn++) {
684 const TGeoHMatrix* matSens = GetMatrixSens(isn);
685 if (!matSens) {AliFatal(Form("Failed to get matrix for sensor %d",isn)); return;}
686 matSens->LocalToMaster(loc,glo);
687 rotm = matSens->GetRotationMatrix();
688 Double_t al = -ATan2(rotm[1],rotm[0]);
3b9474b3 689 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 690 TGeoHMatrix* t2l = new TGeoHMatrix();
691 t2l->RotateZ(ATan2(y,x)*RadToDeg()); // rotate in direction of normal to the sensor plane
692 t2l->SetDx(x);
693 t2l->SetDy(y);
694 t2l->MultiplyLeft(&matSens->Inverse());
695 fMatT2L->AddAt(t2l,isn);
696 /*
697 const double *gtrans = matSens->GetTranslation();
698 memcpy(&rotMatrix[0], matSens->GetRotationMatrix(), 9*sizeof(Double_t));
699 Double_t al = -ATan2(rotMatrix[1],rotMatrix[0]);
700 Double_t rSens = Sqrt(gtrans[0]*gtrans[0] + gtrans[1]*gtrans[1]);
701 Double_t tanAl = ATan2(gtrans[1],gtrans[0]) - Pi()/2; //angle of tangent
702 Double_t alTr = tanAl - al;
703 //
704 // The X axis of tracking frame must always look outward
705 loc[1] = rSens/2;
706 matSens->LocalToMaster(loc,glo);
707 double rPos = Sqrt(glo[0]*glo[0] + glo[1]*glo[1]);
708 Bool_t rotOutward = rPos>rSens ? kFALSE : kTRUE;
709 //
710 // Transformation matrix
711 matLtoT.Clear();
712 matLtoT.SetDx(-rSens*Sin(alTr)); // translation
713 matLtoT.SetDy(0.);
714 matLtoT.SetDz(gtrans[2]);
715 // Rotation matrix
716 rotMatrix[0]= 0; rotMatrix[1]= 1; rotMatrix[2]= 0; // + rotation
717 rotMatrix[3]=-1; rotMatrix[4]= 0; rotMatrix[5]= 0;
718 rotMatrix[6]= 0; rotMatrix[7]= 0; rotMatrix[8]= 1;
719 //
720 TGeoRotation rot;
721 rot.SetMatrix(rotMatrix);
722 matLtoT.MultiplyLeft(&rot);
723 if (rotOutward) matLtoT.RotateZ(180.);
724 // Inverse transformation Matrix
725 fMatT2L->AddAt(new TGeoHMatrix(matLtoT.Inverse()),isn);
726 */
cf457606 727 }
af4b47c9 728 //
cf457606 729}
af4b47c9 730