1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 $Id: AliITSUInitGeometry.cxx $
19 ////////////////////////////////////////////////////////////////
20 // This class initializes the class AliITSgeom
21 // The initialization is done starting from
22 // a geometry coded by means of the ROOT geometrical modeler
23 // This initialization can be used both for simulation and reconstruction
24 ///////////////////////////////////////////////////////////////
28 #include <TStopwatch.h>
29 #include <TGeoManager.h>
30 #include <TGeoMatrix.h>
31 #include <TGeoVolume.h>
32 #include <TGeoShape.h>
39 #include <TGeoSphere.h>
48 #include "AliITSUGeomTGeo.h"
49 #include "AliITSUInitGeometry.h"
51 using namespace TMath;
53 ClassImp(AliITSUInitGeometry)
55 //______________________________________________________________________
56 AliITSUInitGeometry::AliITSUInitGeometry()
64 //______________________________________________________________________
65 AliITSgeom* AliITSUInitGeometry::CreateAliITSgeom()
67 // Creates and Initilizes the geometry transformation class AliITSgeom
68 // to values appropreate to this specific geometry. Now that
69 // the segmentation is part of AliITSgeom, the detector
70 // segmentations are also defined here.
73 AliITSVersion_t version = kvDefault;
76 TGeoVolume *itsV = gGeoManager->GetVolume(AliITSUGeomTGeo::GetITSVolPattern());
78 Error("CreateAliITSgeom","Can't find ITS volume ITSV, aborting");
85 AliITSgeom *geom = CreateAliITSgeom(version,minor);
86 AliDebug(1,"AliITSgeom object has been initialized from TGeo\n");
90 //______________________________________________________________________
91 AliITSgeom* AliITSUInitGeometry::CreateAliITSgeom(Int_t major,Int_t minor){
92 // Creates and Initilizes the geometry transformation class AliITSgeom
93 // to values appropreate to this specific geometry. Now that
94 // the segmentation is part of AliITSgeom, the detector
95 // segmentations are also defined here.
97 // Int_t major major version, see AliITSVersion_t
98 // Int_t minor minor version
102 // A pointer to a new properly inilized AliITSgeom class. If
103 // pointer = 0 then failed to init.
107 SetGeometryName("AliITSv11");
108 SetVersion(kv11,minor);
111 SetGeometryName("AliITSUv11");
112 SetVersion(kvUpgrade,minor);
116 SetGeometryName("Undefined");
117 SetVersion(kvDefault,minor);
120 AliITSgeom *geom = new AliITSgeom();
121 if(!InitAliITSgeom(geom)){ // Error initilization failed
127 //______________________________________________________________________
128 Bool_t AliITSUInitGeometry::InitAliITSgeom(AliITSgeom *geom){
129 // Initilizes the geometry transformation class AliITSgeom
130 // to values appropreate to this specific geometry. Now that
131 // the segmentation is part of AliITSgeom, the detector
132 // segmentations are also defined here.
134 // AliITSgeom *geom A pointer to the AliITSgeom class
136 // AliITSgeom *geom This pointer recreated and properly inilized.
141 AliFatal("The geometry manager has not been initialized (e.g. "
142 "TGeoManager::Import(\"geometry.root\")should be "
143 "called in advance) - exit forced");
146 switch(fMajorVersion) {
148 return InitAliITSgeomV11(geom);
151 return InitAliITSgeomVUpgrade(geom);
153 case kvDefault: default: {
154 AliFatal("Undefined geometry");
160 //______________________________________________________________________
161 void AliITSUInitGeometry::TransposeTGeoHMatrix(TGeoHMatrix *m)const{
162 // Transpose the rotation matrix part of a TGeoHMatrix. This
163 // is needed because TGeo stores the transpose of the rotation
164 // matrix as compared to what AliITSgeomMatrix uses (and Geant3).
166 // TGeoHMatrix *m The matrix to be transposed
168 // TGEoHMatrix *m The transposed matrix
174 if(m==0) return; // no matrix to transpose.
175 for(i=0;i<9;i += 4) r[i] = m->GetRotationMatrix()[i]; // diagonals
176 r[1] = m->GetRotationMatrix()[3];
177 r[2] = m->GetRotationMatrix()[6];
178 r[3] = m->GetRotationMatrix()[1];
179 r[5] = m->GetRotationMatrix()[7];
180 r[6] = m->GetRotationMatrix()[2];
181 r[7] = m->GetRotationMatrix()[5];
187 //______________________________________________________________________
188 Bool_t AliITSUInitGeometry::InitAliITSgeomV11(AliITSgeom *geom){
189 // Initilizes the geometry transformation class AliITSgeom
190 // Now that the segmentation is part of AliITSgeom, the detector
191 // segmentations are also defined here.
194 // AliITSgeom *geom A pointer to the AliITSgeom class
196 // AliITSgeom *geom This pointer recreated and properly inilized.
199 const Int_t kItype = 0; // Type of transformation defined 0=> Geant
200 const Int_t klayers = 6; // number of layers in the ITS
201 const Int_t kladders[klayers] = {20,40,14,22,34,38}; // Number of ladders
202 const Int_t kdetectors[klayers] = {4,4,6,8,22,25};// number of detector/lad
203 const AliITSDetector kIdet[6] = {kSPD,kSPD,kSDD,kSDD,kSSD,kSSD};
204 const TString kPathbase = "/ALIC_1/ITSV_1/";
206 const char *pathSPDsens1, *pathSPDsens2;
207 pathSPDsens1="%sITSSPD_1/ITSSPDCarbonFiberSectorV_%d/ITSSPDSensitiveVirtualvolumeM0_1/ITSSPDlay1-Stave_%d/ITSSPDhalf-Stave%d_1/ITSSPDlay1-Ladder_%d/ITSSPDlay1-sensor_1";
208 pathSPDsens2="%sITSSPD_1/ITSSPDCarbonFiberSectorV_%d/ITSSPDSensitiveVirtualvolumeM0_1/ITSSPDlay2-Stave_%d/ITSSPDhalf-Stave%d_1/ITSSPDlay2-Ladder_%d/ITSSPDlay2-sensor_1";
210 const char *pathSDDsens1, *pathSDDsens2;
211 pathSDDsens1 = "%sITSsddLayer3_1/ITSsddLadd_%d/ITSsddSensor3_%d/ITSsddWafer3_%d/ITSsddSensitivL3_1";
212 pathSDDsens2 = "%sITSsddLayer4_1/ITSsddLadd_%d/ITSsddSensor4_%d/ITSsddWafer4_%d/ITSsddSensitivL4_1";
214 const char *pathSSDsens1, *pathSSDsens2;
215 pathSSDsens1 = "%sITSssdLayer5_1/ITSssdLay5Ladd_%d/ITSssdSensor5_%d/ITSssdSensitivL5_1";
216 pathSSDsens2 = "%sITSssdLayer6_1/ITSssdLay6Ladd_%d/ITSssdSensor6_%d/ITSssdSensitivL6_1";
218 const TString kNames[klayers] = {
219 pathSPDsens1, // lay=1
220 pathSPDsens2, // lay=2
221 pathSDDsens1, // lay=3
222 pathSDDsens2, // lay=4
223 pathSSDsens1, // lay=5
224 pathSSDsens2};// Lay=6
226 Int_t mod,nmods=0, lay, lad, det, cpn0, cpn1, cpn2, cpnHS=1;
227 Double_t tran[3]={0.,0.,0.}, rot[10]={9*0.0,1.0};
229 TString path, shapeName;
231 Bool_t initSeg[3]={kFALSE, kFALSE, kFALSE};
232 TStopwatch *time = 0x0;
233 if(fTiming) time = new TStopwatch();
235 if(fTiming) time->Start();
236 for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
237 geom->Init(kItype,klayers,kladders,kdetectors,nmods);
239 for(mod=0; mod<nmods; mod++) {
241 DecodeDetectorLayers(mod,lay,lad,det);
242 geom->CreateMatrix(mod,lay,lad,det,kIdet[lay-1],tran,rot);
243 RecodeDetector(mod,cpn0,cpn1,cpn2);
245 if (kIdet[lay-1]==kSPD) { // we need 1 more copy number because of the half-stave
246 if (det<3) cpnHS = 0; else cpnHS = 1;
247 path.Form(kNames[lay-1].Data(),kPathbase.Data(),cpn0,cpn1,cpnHS,cpn2);
249 path.Form(kNames[lay-1].Data(),kPathbase.Data(),cpn0,cpn1,cpn2);
252 geom->GetGeomMatrix(mod)->SetPath(path);
253 GetTransformation(path.Data(),matrix);
254 geom->SetTrans(mod,matrix.GetTranslation());
255 TransposeTGeoHMatrix(&matrix); //Transpose TGeo's rotation matrixes
256 geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
257 if(initSeg[kIdet[lay-1]]) continue;
258 GetShape(path,shapeName,shapePar);
259 if(shapeName.CompareTo("BOX")){
260 Error("InitITSgeom","Geometry changed without proper code update"
261 "or error in reading geometry. Shape is not BOX.");
273 //______________________________________________________________________
274 Bool_t AliITSUInitGeometry::InitAliITSgeomVUpgrade(AliITSgeom *geom){
275 // Initilizes the geometry transformation class AliITSgeom
276 // Now that the segmentation is part of AliITSgeom, the detector
277 // segmentations are also defined here.
280 // AliITSgeom *geom A pointer to the AliITSgeom class
282 // AliITSgeom *geom This pointer recreated and properly inilized.
285 const Int_t kItype = 0; // Type of transformation defined 0=> Geant
286 const Int_t klayers = GetNumberOfLayers(); // Number of layers in the ITS
287 const AliITSDetector kIdet = AliITSDetector(0); //kUPG; RS temporary
289 AliError("No layers found in ITSV");
293 Int_t *kladders = new Int_t[klayers]; // Number of ladders
294 Int_t *kdetectors = new Int_t[klayers]; // Number of detectors/ladder
296 for (Int_t j=0; j<klayers; j++) {
297 kladders[j] = GetNumberOfLadders(j);
298 kdetectors[j] = GetNumberOfModules(j);
300 const TString kPathBase = Form("/ALIC_1/%s_1/",AliITSUGeomTGeo::GetITSVolPattern());
301 const TString kNames = Form("%%s%s%%d_1/%s%%d_%%d/%s%%d_%%d/%s%%d_%%d"
302 ,AliITSUGeomTGeo::GetITSLayerPattern()
303 ,AliITSUGeomTGeo::GetITSLadderPattern()
304 ,AliITSUGeomTGeo::GetITSModulePattern()
305 ,AliITSUGeomTGeo::GetITSSensorPattern()
307 Int_t mod,nmods=0, lay, lad, det, cpn0, cpn1, cpn2;
308 Double_t tran[3]={0.,0.,0.}, rot[10]={9*0.0,1.0};
310 TString path, shapeName;
312 // Bool_t initSeg[3]={kFALSE, kFALSE, kFALSE};
313 TStopwatch *time = 0x0;
314 if(fTiming) time = new TStopwatch();
316 if(fTiming) time->Start();
317 for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
318 geom->Init(kItype,klayers,kladders,kdetectors,nmods);
320 for(mod=0; mod<nmods; mod++) {
322 DecodeDetectorLayers(mod,lay,lad,det);
323 geom->CreateMatrix(mod,lay,lad,det,kIdet,tran,rot);
324 RecodeDetector(mod,cpn0,cpn1,cpn2);
326 path.Form(kNames.Data(),kPathBase.Data(),lay,lay,cpn0,lay,cpn1,lay,cpn2);
328 geom->GetGeomMatrix(mod)->SetPath(path);
329 GetTransformation(path.Data(),matrix);
330 geom->SetTrans(mod,matrix.GetTranslation());
331 TransposeTGeoHMatrix(&matrix); //Transpose TGeo's rotation matrixes
332 geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
333 // if(initSeg[kIdet[lay-1]]) continue;
334 GetShape(path,shapeName,shapePar);
335 if(shapeName.CompareTo("BOX")){
336 Error("InitITSgeom","Geometry changed without proper code update"
337 "or error in reading geometry. Shape is not BOX.");
350 //_______________________________________________________________________
351 Bool_t AliITSUInitGeometry::GetTransformation(const TString &volumePath,
353 // Returns the Transformation matrix between the volume specified
354 // by the path volumePath and the Top or mater volume. The format
355 // of the path volumePath is as follows (assuming ALIC is the Top volume)
356 // "/ALIC_1/DDIP_1/S05I_2/S05H_1/S05G_3". Here ALIC is the top most
357 // or master volume which has only 1 instance of. Of all of the daughter
358 // volumes of ALICE, DDIP volume copy #1 is indicated. Similarly for
359 // the daughter volume of DDIP is S05I copy #2 and so on.
361 // TString& volumePath The volume path to the specific volume
362 // for which you want the matrix. Volume name
363 // hierarchy is separated by "/" while the
364 // copy number is appended using a "_".
366 // TGeoHMatrix &mat A matrix with its values set to those
367 // appropriate to the Local to Master transformation
369 // A logical value if kFALSE then an error occurred and no change to
372 // We have to preserve the modeler state
374 // Preserve the modeler state.
375 gGeoManager->PushPath();
376 if (!gGeoManager->cd(volumePath.Data())) {
377 gGeoManager->PopPath();
378 Error("GetTransformation","Error in cd-ing to %s",volumePath.Data());
380 } // end if !gGeoManager
381 mat = *gGeoManager->GetCurrentMatrix();
382 // Retstore the modeler state.
383 gGeoManager->PopPath();
386 //______________________________________________________________________
387 Bool_t AliITSUInitGeometry::GetShape(const TString &volumePath,
388 TString &shapeType,TArrayD &par){
389 // Returns the shape and its parameters for the volume specified
392 // TString& volumeName The volume name
394 // TString &shapeType Shape type
395 // TArrayD &par A TArrayD of parameters with all of the
396 // parameters of the specified shape.
398 // A logical indicating whether there was an error in getting this
401 gGeoManager->PushPath();
402 if (!gGeoManager->cd(volumePath.Data())) {
403 gGeoManager->PopPath();
406 TGeoVolume * vol = gGeoManager->GetCurrentVolume();
407 gGeoManager->PopPath();
408 if (!vol) return kFALSE;
409 TGeoShape *shape = vol->GetShape();
410 TClass *classType = shape->IsA();
411 if (classType==TGeoBBox::Class()) {
415 TGeoBBox *box = (TGeoBBox*)shape;
416 par.AddAt(box->GetDX(),0);
417 par.AddAt(box->GetDY(),1);
418 par.AddAt(box->GetDZ(),2);
421 if (classType==TGeoTrd1::Class()) {
425 TGeoTrd1 *trd1 = (TGeoTrd1*)shape;
426 par.AddAt(trd1->GetDx1(),0);
427 par.AddAt(trd1->GetDx2(),1);
428 par.AddAt(trd1->GetDy(), 2);
429 par.AddAt(trd1->GetDz(), 3);
432 if (classType==TGeoTrd2::Class()) {
436 TGeoTrd2 *trd2 = (TGeoTrd2*)shape;
437 par.AddAt(trd2->GetDx1(),0);
438 par.AddAt(trd2->GetDx2(),1);
439 par.AddAt(trd2->GetDy1(),2);
440 par.AddAt(trd2->GetDy2(),3);
441 par.AddAt(trd2->GetDz(), 4);
444 if (classType==TGeoTrap::Class()) {
448 TGeoTrap *trap = (TGeoTrap*)shape;
449 Double_t tth = Tan(trap->GetTheta()*DegToRad());
450 par.AddAt(trap->GetDz(),0);
451 par.AddAt(tth*Cos(trap->GetPhi()*DegToRad()),1);
452 par.AddAt(tth*Sin(trap->GetPhi()*DegToRad()),2);
453 par.AddAt(trap->GetH1(),3);
454 par.AddAt(trap->GetBl1(),4);
455 par.AddAt(trap->GetTl1(),5);
456 par.AddAt(Tan(trap->GetAlpha1()*DegToRad()),6);
457 par.AddAt(trap->GetH2(),7);
458 par.AddAt(trap->GetBl2(),8);
459 par.AddAt(trap->GetTl2(),9);
460 par.AddAt(Tan(trap->GetAlpha2()*DegToRad()),10);
463 if (classType==TGeoTube::Class()) {
467 TGeoTube *tube = (TGeoTube*)shape;
468 par.AddAt(tube->GetRmin(),0);
469 par.AddAt(tube->GetRmax(),1);
470 par.AddAt(tube->GetDz(),2);
473 if (classType==TGeoTubeSeg::Class()) {
477 TGeoTubeSeg *tubs = (TGeoTubeSeg*)shape;
478 par.AddAt(tubs->GetRmin(),0);
479 par.AddAt(tubs->GetRmax(),1);
480 par.AddAt(tubs->GetDz(),2);
481 par.AddAt(tubs->GetPhi1(),3);
482 par.AddAt(tubs->GetPhi2(),4);
485 if (classType==TGeoCone::Class()) {
489 TGeoCone *cone = (TGeoCone*)shape;
490 par.AddAt(cone->GetDz(),0);
491 par.AddAt(cone->GetRmin1(),1);
492 par.AddAt(cone->GetRmax1(),2);
493 par.AddAt(cone->GetRmin2(),3);
494 par.AddAt(cone->GetRmax2(),4);
497 if (classType==TGeoConeSeg::Class()) {
501 TGeoConeSeg *cons = (TGeoConeSeg*)shape;
502 par.AddAt(cons->GetDz(),0);
503 par.AddAt(cons->GetRmin1(),1);
504 par.AddAt(cons->GetRmax1(),2);
505 par.AddAt(cons->GetRmin2(),3);
506 par.AddAt(cons->GetRmax2(),4);
507 par.AddAt(cons->GetPhi1(),5);
508 par.AddAt(cons->GetPhi2(),6);
511 if (classType==TGeoSphere::Class()) {
516 TGeoSphere *sphe = (TGeoSphere*)shape;
517 par.AddAt(sphe->GetRmin(),0);
518 par.AddAt(sphe->GetRmax(),1);
519 par.AddAt(sphe->GetTheta1(),2);
520 par.AddAt(sphe->GetTheta2(),3);
521 par.AddAt(sphe->GetPhi1(),4);
522 par.AddAt(sphe->GetPhi2(),5);
525 if (classType==TGeoPara::Class()) {
529 TGeoPara *para = (TGeoPara*)shape;
530 par.AddAt(para->GetX(),0);
531 par.AddAt(para->GetY(),1);
532 par.AddAt(para->GetZ(),2);
533 par.AddAt(para->GetTxy(),3);
534 par.AddAt(para->GetTxz(),4);
535 par.AddAt(para->GetTyz(),5);
538 if (classType==TGeoPgon::Class()) {
540 TGeoPgon *pgon = (TGeoPgon*)shape;
541 Int_t nz = pgon->GetNz();
542 const Double_t *rmin = pgon->GetRmin();
543 const Double_t *rmax = pgon->GetRmax();
544 const Double_t *z = pgon->GetZ();
547 par.AddAt(pgon->GetPhi1(),0);
548 par.AddAt(pgon->GetDphi(),1);
549 par.AddAt(pgon->GetNedges(),2);
550 par.AddAt(pgon->GetNz(),3);
551 for (Int_t i=0; i<nz; i++) {
552 par.AddAt(z[i], 4+3*i);
553 par.AddAt(rmin[i], 4+3*i+1);
554 par.AddAt(rmax[i], 4+3*i+2);
558 if (classType==TGeoPcon::Class()) {
560 TGeoPcon *pcon = (TGeoPcon*)shape;
561 Int_t nz = pcon->GetNz();
562 const Double_t *rmin = pcon->GetRmin();
563 const Double_t *rmax = pcon->GetRmax();
564 const Double_t *z = pcon->GetZ();
567 par.AddAt(pcon->GetPhi1(),0);
568 par.AddAt(pcon->GetDphi(),1);
569 par.AddAt(pcon->GetNz(),2);
570 for (Int_t i=0; i<nz; i++) {
571 par.AddAt(z[i], 3+3*i);
573 par.AddAt(rmin[i], 3+3*i+1);
574 par.AddAt(rmax[i], 3+3*i+2);
578 if (classType==TGeoEltu::Class()) {
582 TGeoEltu *eltu = (TGeoEltu*)shape;
583 par.AddAt(eltu->GetA(),0);
584 par.AddAt(eltu->GetB(),1);
585 par.AddAt(eltu->GetDz(),2);
588 if (classType==TGeoHype::Class()) {
592 TGeoHype *hype = (TGeoHype*)shape;
593 par.AddAt(Sqrt(hype->RadiusHypeSq(0.,kTRUE)),0);
594 par.AddAt(Sqrt(hype->RadiusHypeSq(0.,kFALSE)),1);
595 par.AddAt(hype->GetDZ(),2);
596 par.AddAt(hype->GetStIn(),3);
597 par.AddAt(hype->GetStOut(),4);
600 if (classType==TGeoGtra::Class()) {
604 TGeoGtra *trap = (TGeoGtra*)shape;
605 Double_t tth = Tan(trap->GetTheta()*DegToRad());
606 par.AddAt(trap->GetDz(),0);
607 par.AddAt(tth*Cos(trap->GetPhi()*DegToRad()),1);
608 par.AddAt(tth*Sin(trap->GetPhi()*DegToRad()),2);
609 par.AddAt(trap->GetH1(),3);
610 par.AddAt(trap->GetBl1(),4);
611 par.AddAt(trap->GetTl1(),5);
612 par.AddAt(Tan(trap->GetAlpha1()*DegToRad()),6);
613 par.AddAt(trap->GetH2(),7);
614 par.AddAt(trap->GetBl2(),8);
615 par.AddAt(trap->GetTl2(),9);
616 par.AddAt(Tan(trap->GetAlpha2()*DegToRad()),10);
617 par.AddAt(trap->GetTwistAngle(),11);
620 if (classType==TGeoCtub::Class()) {
624 TGeoCtub *ctub = (TGeoCtub*)shape;
625 const Double_t *lx = ctub->GetNlow();
626 const Double_t *tx = ctub->GetNhigh();
627 par.AddAt(ctub->GetRmin(),0);
628 par.AddAt(ctub->GetRmax(),1);
629 par.AddAt(ctub->GetDz(),2);
630 par.AddAt(ctub->GetPhi1(),3);
631 par.AddAt(ctub->GetPhi2(),4);
640 Error("GetShape","Getting shape parameters for shape %s not implemented",
642 shapeType = "Unknown";
645 //______________________________________________________________________
646 void AliITSUInitGeometry::DecodeDetector(
647 Int_t &mod,Int_t layer,Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
648 // decode geometry into detector module number. There are two decoding
649 // Scheams. Old which does not follow the ALICE coordinate system
650 // requirements, and New which dose.
652 // Int_t layer The ITS layer
653 // Int_t cpn0 The lowest copy number
654 // Int_t cpn1 The middle copy number
655 // Int_t cpn2 the highest copy number
657 // Int_t &mod The module number assoicated with this set
662 // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't
663 // like them but I see not better way for the moment.
664 switch (fMajorVersion){
666 Error("DecodeDetector","Major version = kvDefault, not supported");
669 return DecodeDetectorv11(mod,layer,cpn0,cpn1,cpn2);
672 return DecodeDetectorvUpgrade(mod,layer,cpn0,cpn1,cpn2);
675 Error("DecodeDetector","Major version = %d, not supported",
676 (Int_t)fMajorVersion);
682 //______________________________________________________________________
683 void AliITSUInitGeometry::RecodeDetector(Int_t mod,Int_t &cpn0,
684 Int_t &cpn1,Int_t &cpn2){
685 // decode geometry into detector module number. There are two decoding
686 // Scheams. Old which does not follow the ALICE coordinate system
687 // requirements, and New which dose.
689 // Int_t mod The module number assoicated with this set
692 // Int_t cpn0 The lowest copy number
693 // Int_t cpn1 The middle copy number
694 // Int_t cpn2 the highest copy number
698 // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't
699 // like them but I see not better way for the moment.
700 switch (fMajorVersion){
702 Error("RecodeDetector","Major version = kvDefault, not supported");
706 return RecodeDetectorv11(mod,cpn0,cpn1,cpn2);
709 return RecodeDetectorvUpgrade(mod,cpn0,cpn1,cpn2);
712 Error("RecodeDetector","Major version = %d, not supported",
713 (Int_t)fMajorVersion);
719 //______________________________________________________________________
720 void AliITSUInitGeometry::DecodeDetectorLayers(Int_t mod,Int_t &layer,
721 Int_t &lad,Int_t &det){
722 // decode geometry into detector module number. There are two decoding
723 // Scheams. Old which does not follow the ALICE coordinate system
724 // requirements, and New which dose. Note, this use of layer ladder
725 // and detector numbers are strictly for internal use of this
726 // specific code. They do not represent the "standard" layer ladder
727 // or detector numbering except in a very old and obsoleate sence.
729 // Int_t mod The module number assoicated with this set
732 // Int_t lay The layer number
733 // Int_t lad The ladder number
734 // Int_t det the dettector number
738 // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't
739 // like them but I see not better way for the moment.
740 switch (fMajorVersion) {
742 Error("DecodeDetectorLayers",
743 "Major version = kvDefault, not supported");
747 return DecodeDetectorLayersv11(mod,layer,lad,det);
750 return DecodeDetectorLayersvUpgrade(mod,layer,lad,det);
753 Error("DecodeDetectorLayers","Major version = %d, not supported",
754 (Int_t)fMajorVersion);
761 //______________________________________________________________________
762 void AliITSUInitGeometry::DecodeDetectorv11(Int_t &mod,Int_t layer,
763 Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
764 // decode geometry into detector module number
766 // Int_t layer The ITS layer
767 // Int_t cpn0 The lowest copy number
768 // Int_t cpn1 The middle copy number
769 // Int_t cpn2 the highest copy number
771 // Int_t &mod The module number assoicated with this set
775 const Int_t kDetPerLadderSPD[2]={2,4};
776 const Int_t kDetPerLadder[6]={4,4,6,8,22,25};
777 const Int_t kLadPerLayer[6]={20,40,14,22,34,38};
782 lad = cpn1+kDetPerLadderSPD[layer-1]*(cpn0-1);
797 for(Int_t i=0;i<layer-1;i++) mod += kLadPerLayer[i]*kDetPerLadder[i];
798 mod += kDetPerLadder[layer-1]*(lad-1)+det-1;// module start at zero.
802 //______________________________________________________________________
803 void AliITSUInitGeometry::DecodeDetectorvUpgrade(Int_t &mod,Int_t layer,
804 Int_t cpn0,Int_t cpn1,Int_t /*cpn2*/) const {
805 // decode geometry into detector module number
807 // Int_t layer The ITS layer
808 // Int_t cpn0 The lowest copy number
809 // Int_t cpn1 The middle copy number
810 // Int_t cpn2 the highest copy number
812 // Int_t &mod The module number assoicated with this set
818 layer--; // starts from 1!
822 for(Int_t i=0;i<layer;i++) mod += GetNumberOfLadders(i)*GetNumberOfModules(i);
823 mod += GetNumberOfModules(layer)*(lad-1)+det-1;// module start at zero.
827 //______________________________________________________________________
828 void AliITSUInitGeometry::RecodeDetectorv11(Int_t mod,Int_t &cpn0,
829 Int_t &cpn1,Int_t &cpn2) {
830 // decode geometry into detector module number using the new decoding
833 // Int_t mod The module number assoicated with this set
836 // Int_t cpn0 The lowest copy number (SPD sector or SDD/SSD ladder)
837 // Int_t cpn1 The middle copy number (SPD stave or SDD/SSD module)
838 // Int_t cpn2 the highest copy number (SPD ladder or 1 for SDD/SSD)
841 const Int_t kDetPerLadderSPD[2]={2,4};
844 DecodeDetectorLayersv11(mod,lay,lad,det);
846 cpn2 = det; // Detector 1-4
847 cpn0 = (lad+kDetPerLadderSPD[lay-1]-1)/kDetPerLadderSPD[lay-1];
848 cpn1 = (lad+kDetPerLadderSPD[lay-1]-1)%kDetPerLadderSPD[lay-1] + 1;
849 } else { // SDD and SSD
859 } // end if Lay<5/else
860 } // end if lay<3/else
861 /*printf("AliITSUInitGeometry::RecodeDetectorv11:"
862 "mod=%d lay=%d lad=%d det=%d cpn0=%d cpn1=%d cpn2=%d\n",
863 mod,lay,lad,det,cpn0,cpn1,cpn2);*/
866 //______________________________________________________________________
867 void AliITSUInitGeometry::RecodeDetectorvUpgrade(Int_t mod,Int_t &cpn0,
868 Int_t &cpn1,Int_t &cpn2) {
869 // decode geometry into detector module number using the new decoding
872 // Int_t mod The module number assoicated with this set
875 // Int_t cpn0 The lowest copy number (ladder)
876 // Int_t cpn1 The middle copy number (module)
877 // Int_t cpn2 the highest copy number (sensor - always 1 for now)
880 // MS - 23jun11 - cross your fingers and hope for the best
883 DecodeDetectorLayersvUpgrade(mod,lay,lad,det);
889 /*printf("AliITSUInitGeometry::RecodeDetectorv11:"
890 "mod=%d lay=%d lad=%d det=%d cpn0=%d cpn1=%d cpn2=%d\n",
891 mod,lay,lad,det,cpn0,cpn1,cpn2);*/
894 //______________________________________________________________________
895 void AliITSUInitGeometry::DecodeDetectorLayersv11(Int_t mod,Int_t &lay,
896 Int_t &lad,Int_t &det) {
898 // decode module number into detector indices for v11
900 // lay, lad, det start from 1
903 // Int_t mod The module number associated with this set
906 // Int_t lay The layer number
907 // Int_t lad The ladder number
908 // Int_t det the dettector number
910 const Int_t kDetPerLadder[6] = {4,4,6,8,22,25};
911 const Int_t kLadPerLayer[6] = {20,40,14,22,34,38};
917 mod2 += kLadPerLayer[lay]*kDetPerLadder[lay];
919 } while(mod2<=mod); // end while
920 if(lay>6) Error("DecodeDetectorLayers","lay=%d>6",lay);
922 mod2 = kLadPerLayer[lay-1]*kDetPerLadder[lay-1] - mod2+mod;
923 lad = mod2/kDetPerLadder[lay-1];
925 if(lad>=kLadPerLayer[lay-1]||lad<0) Error("DecodeDetectorLayers",
926 "lad=%d not in the correct range",lad);
927 det = (mod2 - lad*kDetPerLadder[lay-1])+1;
928 if(det>kDetPerLadder[lay-1]||det<1) Error("DecodeDetectorLayers",
929 "det=%d not in the correct range",det);
933 //______________________________________________________________________
934 void AliITSUInitGeometry::DecodeDetectorLayersvUpgrade(Int_t mod,Int_t &lay,
935 Int_t &lad,Int_t &det){
937 // decode module number into detector indices for vUpgrade
939 // lay, lad, det start from 1
942 // Int_t mod The module number associated with this set
945 // Int_t lay The layer number
946 // Int_t lad The ladder number
947 // Int_t det the dettector number
950 const Int_t kLayers = GetNumberOfLayers();
956 mod2 += GetNumberOfLadders(lay)*GetNumberOfModules(lay);
958 } while(mod2<=mod); // end while
959 if(lay>kLayers) Error("DecodeDetectorLayers","lay=%d>%d",lay,kLayers);
961 mod2 = GetNumberOfLadders(lay-1)*GetNumberOfModules(lay-1) - mod2+mod;
962 lad = mod2/GetNumberOfModules(lay-1);
964 if(lad>=GetNumberOfLadders(lay-1)||lad<0) Error("DecodeDetectorLayers",
965 "lad=%d not in the correct range",lad);
966 det = (mod2 - lad*GetNumberOfModules(lay-1))+1;
967 if(det>GetNumberOfModules(lay-1)||det<1) Error("DecodeDetectorLayers",
969 "det=%d not in the correct range",det);
974 //______________________________________________________________________
975 Bool_t AliITSUInitGeometry::WriteVersionString(Char_t *str,Int_t length,
976 AliITSVersion_t maj,Int_t min,
977 const Char_t *cvsDate,const Char_t *cvsRevision)const{
978 // fills the string str with the major and minor version number
980 // Char_t *str The character string to hold the major
981 // and minor version numbers in
982 // Int_t length The maximum number of characters which
983 // can be accomidated by this string.
984 // str[length-1] must exist and will be set to zero
985 // AliITSVersion_t maj The major number
986 // Int_t min The minor number
987 // Char_t *cvsDate The date string from cvs
988 // Char_t *cvsRevision The Revision string from cvs
990 // Char_t *str The character string holding the major and minor
991 // version numbers. str[length-1] must exist
992 // and will be set to zero
994 // kTRUE if no errors
995 Char_t cvslikedate[30];
996 Int_t i,n,cvsDateLength,cvsRevisionLength;
998 cvsDateLength = (Int_t)strlen(cvsDate);
999 if(cvsDateLength>30){ // svn string, make a cvs like string
1002 cvslikedate[i] = cvsDate[i];
1003 if(cvsDate[i]=='+' || cvsDate[i++]=='-'){
1004 n++; // count number of -
1005 cvslikedate[i-1] = '/'; // replace -'s by /'s.
1007 } while(n<3&&i<30); // once additonal - of time zone reach exit
1008 cvslikedate[i-1] = '$'; // put $ at end then zero.
1009 for(;i<30;i++) cvslikedate[i]=0;// i starts wher do loop left off.
1011 for(i=0;i<cvsDateLength&&i<30;i++) cvslikedate[i]=cvsDate[i];
1013 cvsDateLength = (Int_t)strlen(cvslikedate);
1014 cvsRevisionLength = (Int_t)strlen(cvsRevision);
1016 n = 50+(Int_t)(Log10(Abs((Double_t)i)))+1+
1017 (Int_t)(Log10(Abs((Double_t)min)))+1
1018 +cvsDateLength-6+cvsRevisionLength-10;
1019 if(GetDebug()>1) printf("AliITSUInitGeometry::WriteVersionString:"
1020 "length=%d major=%d minor=%d cvsDate=%s[%d] "
1021 "cvsRevision=%s[%d] n=%d\n",length,i,min,cvslikedate,
1022 cvsDateLength,cvsRevision,cvsRevisionLength,n);
1025 if(length<n){// not enough space to write in output string.
1026 Warning("WriteVersionString","Output string not long enough "
1027 "lenght=%d must be at least %d long\n",length,n);
1029 } // end if length<n
1030 char *cvsrevision = new char[cvsRevisionLength-10];
1031 char *cvsdate = new char[cvsDateLength-6];
1032 for(i=0;i<cvsRevisionLength-10;i++)
1033 if(10+i<cvsRevisionLength-1)
1034 cvsrevision[i] = cvsRevision[10+i]; else cvsrevision[i] = 0;
1035 for(i=0;i<cvsDateLength-6;i++) if(6+i<cvsDateLength-1)
1036 cvsdate[i] = cvslikedate[6+i]; else cvsdate[i] = 0;
1037 for(i=0;i<length;i++) str[i] = 0; // zero it out for now.
1039 snprintf(str,length-1,"Major Version= %d Minor Version= %d Revision: %s Date: %s",i,min,cvsrevision,cvsdate);
1040 /* this gives compilation warnings on some compilers: descriptor zu
1041 if(GetDebug()>1)printf("AliITSUInitGeometry::WriteVersionString: "
1042 "n=%d str=%s revision[%zu] date[%zu]\n",
1043 n,str,strlen(cvsrevision),strlen(cvsdate));
1045 delete[] cvsrevision;
1049 //______________________________________________________________________
1050 Bool_t AliITSUInitGeometry::ReadVersionString(const Char_t *str,Int_t length,
1051 AliITSVersion_t &maj,Int_t &min,
1053 // fills the string str with the major and minor version number
1055 // Char_t *str The character string to holding the major and minor
1056 // version numbers in
1057 // Int_t length The maximum number of characters which can be
1058 // accomidated by this string. str[length-1] must exist
1060 // Char_t *str The character string holding the major and minor
1061 // version numbers unchanged. str[length-1] must exist.
1062 // AliITSVersion_t maj The major number
1063 // Int_t min The minor number
1064 // TDatime dt The date and time of the cvs commit
1066 // kTRUE if no errors
1068 Char_t cvsRevision[10],cvsDate[11],cvsTime[9];
1069 Int_t i,m,n=strlen(str),year,month,day,hours,minuits,seconds;
1070 memset(cvsRevision,0,10*sizeof(Char_t));
1071 memset(cvsDate,0,11*sizeof(Char_t));
1072 memset(cvsTime,0,9*sizeof(Char_t));
1074 if(GetDebug()>1)printf("AliITSUInitGeometry::ReadVersionString:"
1075 "str=%s length=%d\n",
1077 if(n<35) return kFALSE; // not enough space for numbers
1078 m = sscanf(str,"Major Version= %d Minor Version= %d Revision: %9s "
1079 "Date: %10s %8s",&i,&min,cvsRevision,cvsDate,cvsTime);
1082 m = sscanf(cvsDate,"%d/%d/%d",&year,&month,&day);
1085 m = sscanf(cvsTime,"%d:%d:%d",&hours,&minuits,&seconds);
1088 dt.Set(year,month,day,hours,minuits,seconds);
1089 if(GetDebug()>1)printf("AliITSUInitGeometry::ReadVersionString: i=%d "
1090 "min=%d cvsRevision=%s cvsDate=%s cvsTime=%s m=%d\n",
1091 i,min,cvsRevision,cvsDate,cvsTime,m);
1092 if(GetDebug()>1)printf("AliITSUInitGeometry::ReadVersionString: year=%d"
1093 " month=%d day=%d hours=%d minuits=%d seconds=%d\n",
1094 year,month,day,hours,minuits,seconds);
1108 //______________________________________________________________________
1109 Int_t AliITSUInitGeometry::GetNumberOfLayers(){
1110 // Determines the number of layers in the Upgrade Geometry
1117 // the number of layers in the current geometry
1118 // -1 if not Upgrade Geometry
1121 Int_t numberOfLayers = 0;
1123 if (fMajorVersion != kvUpgrade) {
1124 AliError("Not Upgrade Geometry!");
1128 // This checks should be redundant, but let's do things neatly
1130 AliError("gGeoManager is null");
1134 if (!gGeoManager->GetVolume(AliITSUGeomTGeo::GetITSVolPattern())) {
1135 AliError(Form("can't find %s volume",AliITSUGeomTGeo::GetITSVolPattern()));
1139 // Loop on all ITSV nodes, count Layer volumes by checking names
1140 Int_t nNodes = gGeoManager->GetVolume(AliITSUGeomTGeo::GetITSVolPattern())->GetNodes()->GetEntries();
1145 for (Int_t j=0; j<nNodes; j++)
1146 if (strstr(gGeoManager->GetVolume(AliITSUGeomTGeo::GetITSVolPattern())->GetNodes()->At(j)->GetName(),
1147 AliITSUGeomTGeo::GetITSLayerPattern()))
1151 return numberOfLayers;
1154 //______________________________________________________________________
1155 Int_t AliITSUInitGeometry::GetNumberOfLadders(const Int_t lay) const {
1156 // Determines the number of layers in the Upgrade Geometry
1159 // lay: layer number
1163 // the number of ladders in layer lay
1164 // -1 if not Upgrade Geometry
1167 Int_t numberOfLadders = 0;
1169 if (fMajorVersion != kvUpgrade) {
1170 AliError("Not Upgrade Geometry!");
1174 // This checks should be redundant, but let's do things neatly
1176 AliError("gGeoManager is null");
1181 snprintf(laynam, 15, "%s%d", AliITSUGeomTGeo::GetITSLayerPattern(),lay+1);
1182 if (!gGeoManager->GetVolume(laynam)) {
1183 AliError(Form("can't find %s volume",laynam));
1187 // Loop on all layer nodes, count Ladder volumes by checking names
1188 Int_t nNodes = gGeoManager->GetVolume(laynam)->GetNodes()->GetEntries();
1193 for (Int_t j=0; j<nNodes; j++)
1194 if (strstr(gGeoManager->GetVolume(laynam)->GetNodes()->At(j)->GetName(),
1195 AliITSUGeomTGeo::GetITSLadderPattern()))
1199 return numberOfLadders;
1202 //______________________________________________________________________
1203 Int_t AliITSUInitGeometry::GetLayerDetTypeID(const Int_t lay) const
1205 // Determines the layers det. type in the Upgrade Geometry
1208 // lay: layer number
1213 // -1 if not Upgrade Geometry
1216 if (fMajorVersion != kvUpgrade) {
1217 AliError("Not Upgrade Geometry!");
1221 // This checks should be redundant, but let's do things neatly
1223 AliError("gGeoManager is null");
1228 snprintf(laynam, 15, "%s%d", AliITSUGeomTGeo::GetITSLayerPattern(),lay+1);
1229 TGeoVolume* volLr = gGeoManager->GetVolume(laynam);
1231 AliError(Form("can't find %s volume",laynam));
1235 return volLr->GetUniqueID();
1239 //______________________________________________________________________
1240 Int_t AliITSUInitGeometry::GetNumberOfModules(const Int_t lay) const {
1241 // Determines the number of layers in the Upgrade Geometry
1244 // lay: layer number
1248 // the number of modules per ladder in layer lay
1249 // -1 if not Upgrade Geometry
1252 Int_t numberOfModules = 0;
1254 if (fMajorVersion != kvUpgrade) {
1255 AliError("Not Upgrade Geometry!");
1259 // This checks should be redundant, but let's do things neatly
1261 AliError("gGeoManager is null");
1266 snprintf(laddnam, 15, "%s%d", AliITSUGeomTGeo::GetITSLadderPattern(),lay+1);
1267 if (!gGeoManager->GetVolume(laddnam)) {
1268 AliError(Form("can't find %s volume",laddnam));
1272 // Loop on all ladder nodes, count Module volumes by checking names
1273 Int_t nNodes = gGeoManager->GetVolume(laddnam)->GetNodes()->GetEntries();
1278 for (Int_t j=0; j<nNodes; j++)
1279 if (strstr(gGeoManager->GetVolume(laddnam)->GetNodes()->At(j)->GetName(),
1280 AliITSUGeomTGeo::GetITSModulePattern()))
1284 return numberOfModules;