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"
52 ClassImp(AliITSUInitGeometry)
54 //______________________________________________________________________
55 AliITSUInitGeometry::AliITSUInitGeometry()
63 //______________________________________________________________________
64 AliITSgeom* AliITSUInitGeometry::CreateAliITSgeom()
66 // Creates and Initilizes the geometry transformation class AliITSgeom
67 // to values appropreate to this specific geometry. Now that
68 // the segmentation is part of AliITSgeom, the detector
69 // segmentations are also defined here.
72 AliITSVersion_t version = kvDefault;
75 TGeoVolume *itsV = gGeoManager->GetVolume(AliITSUGeomTGeo::GetITSVolPattern());
77 Error("CreateAliITSgeom","Can't find ITS volume ITSV, aborting");
84 AliITSgeom *geom = CreateAliITSgeom(version,minor);
85 AliDebug(1,"AliITSgeom object has been initialized from TGeo\n");
89 //______________________________________________________________________
90 AliITSgeom* AliITSUInitGeometry::CreateAliITSgeom(Int_t major,Int_t minor){
91 // Creates and Initilizes the geometry transformation class AliITSgeom
92 // to values appropreate to this specific geometry. Now that
93 // the segmentation is part of AliITSgeom, the detector
94 // segmentations are also defined here.
96 // Int_t major major version, see AliITSVersion_t
97 // Int_t minor minor version
101 // A pointer to a new properly inilized AliITSgeom class. If
102 // pointer = 0 then failed to init.
106 SetGeometryName("AliITSv11");
107 SetVersion(kv11,minor);
110 SetGeometryName("AliITSUv11");
111 SetVersion(kvUpgrade,minor);
115 SetGeometryName("Undefined");
116 SetVersion(kvDefault,minor);
119 AliITSgeom *geom = new AliITSgeom();
120 if(!InitAliITSgeom(geom)){ // Error initilization failed
126 //______________________________________________________________________
127 Bool_t AliITSUInitGeometry::InitAliITSgeom(AliITSgeom *geom){
128 // Initilizes the geometry transformation class AliITSgeom
129 // to values appropreate to this specific geometry. Now that
130 // the segmentation is part of AliITSgeom, the detector
131 // segmentations are also defined here.
133 // AliITSgeom *geom A pointer to the AliITSgeom class
135 // AliITSgeom *geom This pointer recreated and properly inilized.
140 AliFatal("The geometry manager has not been initialized (e.g. "
141 "TGeoManager::Import(\"geometry.root\")should be "
142 "called in advance) - exit forced");
145 switch(fMajorVersion) {
147 return InitAliITSgeomV11(geom);
150 return InitAliITSgeomVUpgrade(geom);
152 case kvDefault: default: {
153 AliFatal("Undefined geometry");
159 //______________________________________________________________________
160 void AliITSUInitGeometry::TransposeTGeoHMatrix(TGeoHMatrix *m)const{
161 // Transpose the rotation matrix part of a TGeoHMatrix. This
162 // is needed because TGeo stores the transpose of the rotation
163 // matrix as compared to what AliITSgeomMatrix uses (and Geant3).
165 // TGeoHMatrix *m The matrix to be transposed
167 // TGEoHMatrix *m The transposed matrix
173 if(m==0) return; // no matrix to transpose.
174 for(i=0;i<9;i += 4) r[i] = m->GetRotationMatrix()[i]; // diagonals
175 r[1] = m->GetRotationMatrix()[3];
176 r[2] = m->GetRotationMatrix()[6];
177 r[3] = m->GetRotationMatrix()[1];
178 r[5] = m->GetRotationMatrix()[7];
179 r[6] = m->GetRotationMatrix()[2];
180 r[7] = m->GetRotationMatrix()[5];
186 //______________________________________________________________________
187 Bool_t AliITSUInitGeometry::InitAliITSgeomV11(AliITSgeom *geom){
188 // Initilizes the geometry transformation class AliITSgeom
189 // Now that the segmentation is part of AliITSgeom, the detector
190 // segmentations are also defined here.
193 // AliITSgeom *geom A pointer to the AliITSgeom class
195 // AliITSgeom *geom This pointer recreated and properly inilized.
198 const Int_t kItype = 0; // Type of transformation defined 0=> Geant
199 const Int_t klayers = 6; // number of layers in the ITS
200 const Int_t kladders[klayers] = {20,40,14,22,34,38}; // Number of ladders
201 const Int_t kdetectors[klayers] = {4,4,6,8,22,25};// number of detector/lad
202 const AliITSDetector kIdet[6] = {kSPD,kSPD,kSDD,kSDD,kSSD,kSSD};
203 const TString kPathbase = "/ALIC_1/ITSV_1/";
205 const char *pathSPDsens1, *pathSPDsens2;
206 pathSPDsens1="%sITSSPD_1/ITSSPDCarbonFiberSectorV_%d/ITSSPDSensitiveVirtualvolumeM0_1/ITSSPDlay1-Stave_%d/ITSSPDhalf-Stave%d_1/ITSSPDlay1-Ladder_%d/ITSSPDlay1-sensor_1";
207 pathSPDsens2="%sITSSPD_1/ITSSPDCarbonFiberSectorV_%d/ITSSPDSensitiveVirtualvolumeM0_1/ITSSPDlay2-Stave_%d/ITSSPDhalf-Stave%d_1/ITSSPDlay2-Ladder_%d/ITSSPDlay2-sensor_1";
209 const char *pathSDDsens1, *pathSDDsens2;
210 pathSDDsens1 = "%sITSsddLayer3_1/ITSsddLadd_%d/ITSsddSensor3_%d/ITSsddWafer3_%d/ITSsddSensitivL3_1";
211 pathSDDsens2 = "%sITSsddLayer4_1/ITSsddLadd_%d/ITSsddSensor4_%d/ITSsddWafer4_%d/ITSsddSensitivL4_1";
213 const char *pathSSDsens1, *pathSSDsens2;
214 pathSSDsens1 = "%sITSssdLayer5_1/ITSssdLay5Ladd_%d/ITSssdSensor5_%d/ITSssdSensitivL5_1";
215 pathSSDsens2 = "%sITSssdLayer6_1/ITSssdLay6Ladd_%d/ITSssdSensor6_%d/ITSssdSensitivL6_1";
217 const TString kNames[klayers] = {
218 pathSPDsens1, // lay=1
219 pathSPDsens2, // lay=2
220 pathSDDsens1, // lay=3
221 pathSDDsens2, // lay=4
222 pathSSDsens1, // lay=5
223 pathSSDsens2};// Lay=6
225 Int_t mod,nmods=0, lay, lad, det, cpn0, cpn1, cpn2, cpnHS=1;
226 Double_t tran[3]={0.,0.,0.}, rot[10]={9*0.0,1.0};
228 TString path, shapeName;
230 Bool_t initSeg[3]={kFALSE, kFALSE, kFALSE};
231 TStopwatch *time = 0x0;
232 if(fTiming) time = new TStopwatch();
234 if(fTiming) time->Start();
235 for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
236 geom->Init(kItype,klayers,kladders,kdetectors,nmods);
238 for(mod=0; mod<nmods; mod++) {
240 DecodeDetectorLayers(mod,lay,lad,det);
241 geom->CreateMatrix(mod,lay,lad,det,kIdet[lay-1],tran,rot);
242 RecodeDetector(mod,cpn0,cpn1,cpn2);
244 if (kIdet[lay-1]==kSPD) { // we need 1 more copy number because of the half-stave
245 if (det<3) cpnHS = 0; else cpnHS = 1;
246 path.Form(kNames[lay-1].Data(),kPathbase.Data(),cpn0,cpn1,cpnHS,cpn2);
248 path.Form(kNames[lay-1].Data(),kPathbase.Data(),cpn0,cpn1,cpn2);
251 geom->GetGeomMatrix(mod)->SetPath(path);
252 GetTransformation(path.Data(),matrix);
253 geom->SetTrans(mod,matrix.GetTranslation());
254 TransposeTGeoHMatrix(&matrix); //Transpose TGeo's rotation matrixes
255 geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
256 if(initSeg[kIdet[lay-1]]) continue;
257 GetShape(path,shapeName,shapePar);
258 if(shapeName.CompareTo("BOX")){
259 Error("InitITSgeom","Geometry changed without proper code update"
260 "or error in reading geometry. Shape is not BOX.");
272 //______________________________________________________________________
273 Bool_t AliITSUInitGeometry::InitAliITSgeomVUpgrade(AliITSgeom *geom){
274 // Initilizes the geometry transformation class AliITSgeom
275 // Now that the segmentation is part of AliITSgeom, the detector
276 // segmentations are also defined here.
279 // AliITSgeom *geom A pointer to the AliITSgeom class
281 // AliITSgeom *geom This pointer recreated and properly inilized.
284 const Int_t kItype = 0; // Type of transformation defined 0=> Geant
285 const Int_t klayers = GetNumberOfLayers(); // Number of layers in the ITS
286 const AliITSDetector kIdet = AliITSDetector(0); //kUPG; RS temporary
288 AliError("No layers found in ITSV");
292 Int_t *kladders = new Int_t[klayers]; // Number of ladders
293 Int_t *kdetectors = new Int_t[klayers]; // Number of detectors/ladder
295 for (Int_t j=0; j<klayers; j++) {
296 kladders[j] = GetNumberOfLadders(j);
297 kdetectors[j] = GetNumberOfModules(j);
299 const TString kPathBase = Form("/ALIC_1/%s_1/",AliITSUGeomTGeo::GetITSVolPattern());
300 const TString kNames = Form("%%s%s%%d_1/%s%%d_%%d/%s%%d_%%d/%s%%d_%%d"
301 ,AliITSUGeomTGeo::GetITSLayerPattern()
302 ,AliITSUGeomTGeo::GetITSLadderPattern()
303 ,AliITSUGeomTGeo::GetITSModulePattern()
304 ,AliITSUGeomTGeo::GetITSSensorPattern()
306 Int_t mod,nmods=0, lay, lad, det, cpn0, cpn1, cpn2;
307 Double_t tran[3]={0.,0.,0.}, rot[10]={9*0.0,1.0};
309 TString path, shapeName;
311 // Bool_t initSeg[3]={kFALSE, kFALSE, kFALSE};
312 TStopwatch *time = 0x0;
313 if(fTiming) time = new TStopwatch();
315 if(fTiming) time->Start();
316 for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
317 geom->Init(kItype,klayers,kladders,kdetectors,nmods);
319 for(mod=0; mod<nmods; mod++) {
321 DecodeDetectorLayers(mod,lay,lad,det);
322 geom->CreateMatrix(mod,lay,lad,det,kIdet,tran,rot);
323 RecodeDetector(mod,cpn0,cpn1,cpn2);
325 path.Form(kNames.Data(),kPathBase.Data(),lay,lay,cpn0,lay,cpn1,lay,cpn2);
327 geom->GetGeomMatrix(mod)->SetPath(path);
328 GetTransformation(path.Data(),matrix);
329 geom->SetTrans(mod,matrix.GetTranslation());
330 TransposeTGeoHMatrix(&matrix); //Transpose TGeo's rotation matrixes
331 geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
332 // if(initSeg[kIdet[lay-1]]) continue;
333 GetShape(path,shapeName,shapePar);
334 if(shapeName.CompareTo("BOX")){
335 Error("InitITSgeom","Geometry changed without proper code update"
336 "or error in reading geometry. Shape is not BOX.");
349 //_______________________________________________________________________
350 Bool_t AliITSUInitGeometry::GetTransformation(const TString &volumePath,
352 // Returns the Transformation matrix between the volume specified
353 // by the path volumePath and the Top or mater volume. The format
354 // of the path volumePath is as follows (assuming ALIC is the Top volume)
355 // "/ALIC_1/DDIP_1/S05I_2/S05H_1/S05G_3". Here ALIC is the top most
356 // or master volume which has only 1 instance of. Of all of the daughter
357 // volumes of ALICE, DDIP volume copy #1 is indicated. Similarly for
358 // the daughter volume of DDIP is S05I copy #2 and so on.
360 // TString& volumePath The volume path to the specific volume
361 // for which you want the matrix. Volume name
362 // hierarchy is separated by "/" while the
363 // copy number is appended using a "_".
365 // TGeoHMatrix &mat A matrix with its values set to those
366 // appropriate to the Local to Master transformation
368 // A logical value if kFALSE then an error occurred and no change to
371 // We have to preserve the modeler state
373 // Preserve the modeler state.
374 gGeoManager->PushPath();
375 if (!gGeoManager->cd(volumePath.Data())) {
376 gGeoManager->PopPath();
377 Error("GetTransformation","Error in cd-ing to %s",volumePath.Data());
379 } // end if !gGeoManager
380 mat = *gGeoManager->GetCurrentMatrix();
381 // Retstore the modeler state.
382 gGeoManager->PopPath();
385 //______________________________________________________________________
386 Bool_t AliITSUInitGeometry::GetShape(const TString &volumePath,
387 TString &shapeType,TArrayD &par){
388 // Returns the shape and its parameters for the volume specified
391 // TString& volumeName The volume name
393 // TString &shapeType Shape type
394 // TArrayD &par A TArrayD of parameters with all of the
395 // parameters of the specified shape.
397 // A logical indicating whether there was an error in getting this
400 gGeoManager->PushPath();
401 if (!gGeoManager->cd(volumePath.Data())) {
402 gGeoManager->PopPath();
405 TGeoVolume * vol = gGeoManager->GetCurrentVolume();
406 gGeoManager->PopPath();
407 if (!vol) return kFALSE;
408 TGeoShape *shape = vol->GetShape();
409 TClass *classType = shape->IsA();
410 if (classType==TGeoBBox::Class()) {
414 TGeoBBox *box = (TGeoBBox*)shape;
415 par.AddAt(box->GetDX(),0);
416 par.AddAt(box->GetDY(),1);
417 par.AddAt(box->GetDZ(),2);
420 if (classType==TGeoTrd1::Class()) {
424 TGeoTrd1 *trd1 = (TGeoTrd1*)shape;
425 par.AddAt(trd1->GetDx1(),0);
426 par.AddAt(trd1->GetDx2(),1);
427 par.AddAt(trd1->GetDy(), 2);
428 par.AddAt(trd1->GetDz(), 3);
431 if (classType==TGeoTrd2::Class()) {
435 TGeoTrd2 *trd2 = (TGeoTrd2*)shape;
436 par.AddAt(trd2->GetDx1(),0);
437 par.AddAt(trd2->GetDx2(),1);
438 par.AddAt(trd2->GetDy1(),2);
439 par.AddAt(trd2->GetDy2(),3);
440 par.AddAt(trd2->GetDz(), 4);
443 if (classType==TGeoTrap::Class()) {
447 TGeoTrap *trap = (TGeoTrap*)shape;
448 Double_t tth = TMath::Tan(trap->GetTheta()*TMath::DegToRad());
449 par.AddAt(trap->GetDz(),0);
450 par.AddAt(tth*TMath::Cos(trap->GetPhi()*TMath::DegToRad()),1);
451 par.AddAt(tth*TMath::Sin(trap->GetPhi()*TMath::DegToRad()),2);
452 par.AddAt(trap->GetH1(),3);
453 par.AddAt(trap->GetBl1(),4);
454 par.AddAt(trap->GetTl1(),5);
455 par.AddAt(TMath::Tan(trap->GetAlpha1()*TMath::DegToRad()),6);
456 par.AddAt(trap->GetH2(),7);
457 par.AddAt(trap->GetBl2(),8);
458 par.AddAt(trap->GetTl2(),9);
459 par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
462 if (classType==TGeoTube::Class()) {
466 TGeoTube *tube = (TGeoTube*)shape;
467 par.AddAt(tube->GetRmin(),0);
468 par.AddAt(tube->GetRmax(),1);
469 par.AddAt(tube->GetDz(),2);
472 if (classType==TGeoTubeSeg::Class()) {
476 TGeoTubeSeg *tubs = (TGeoTubeSeg*)shape;
477 par.AddAt(tubs->GetRmin(),0);
478 par.AddAt(tubs->GetRmax(),1);
479 par.AddAt(tubs->GetDz(),2);
480 par.AddAt(tubs->GetPhi1(),3);
481 par.AddAt(tubs->GetPhi2(),4);
484 if (classType==TGeoCone::Class()) {
488 TGeoCone *cone = (TGeoCone*)shape;
489 par.AddAt(cone->GetDz(),0);
490 par.AddAt(cone->GetRmin1(),1);
491 par.AddAt(cone->GetRmax1(),2);
492 par.AddAt(cone->GetRmin2(),3);
493 par.AddAt(cone->GetRmax2(),4);
496 if (classType==TGeoConeSeg::Class()) {
500 TGeoConeSeg *cons = (TGeoConeSeg*)shape;
501 par.AddAt(cons->GetDz(),0);
502 par.AddAt(cons->GetRmin1(),1);
503 par.AddAt(cons->GetRmax1(),2);
504 par.AddAt(cons->GetRmin2(),3);
505 par.AddAt(cons->GetRmax2(),4);
506 par.AddAt(cons->GetPhi1(),5);
507 par.AddAt(cons->GetPhi2(),6);
510 if (classType==TGeoSphere::Class()) {
515 TGeoSphere *sphe = (TGeoSphere*)shape;
516 par.AddAt(sphe->GetRmin(),0);
517 par.AddAt(sphe->GetRmax(),1);
518 par.AddAt(sphe->GetTheta1(),2);
519 par.AddAt(sphe->GetTheta2(),3);
520 par.AddAt(sphe->GetPhi1(),4);
521 par.AddAt(sphe->GetPhi2(),5);
524 if (classType==TGeoPara::Class()) {
528 TGeoPara *para = (TGeoPara*)shape;
529 par.AddAt(para->GetX(),0);
530 par.AddAt(para->GetY(),1);
531 par.AddAt(para->GetZ(),2);
532 par.AddAt(para->GetTxy(),3);
533 par.AddAt(para->GetTxz(),4);
534 par.AddAt(para->GetTyz(),5);
537 if (classType==TGeoPgon::Class()) {
539 TGeoPgon *pgon = (TGeoPgon*)shape;
540 Int_t nz = pgon->GetNz();
541 const Double_t *rmin = pgon->GetRmin();
542 const Double_t *rmax = pgon->GetRmax();
543 const Double_t *z = pgon->GetZ();
546 par.AddAt(pgon->GetPhi1(),0);
547 par.AddAt(pgon->GetDphi(),1);
548 par.AddAt(pgon->GetNedges(),2);
549 par.AddAt(pgon->GetNz(),3);
550 for (Int_t i=0; i<nz; i++) {
551 par.AddAt(z[i], 4+3*i);
552 par.AddAt(rmin[i], 4+3*i+1);
553 par.AddAt(rmax[i], 4+3*i+2);
557 if (classType==TGeoPcon::Class()) {
559 TGeoPcon *pcon = (TGeoPcon*)shape;
560 Int_t nz = pcon->GetNz();
561 const Double_t *rmin = pcon->GetRmin();
562 const Double_t *rmax = pcon->GetRmax();
563 const Double_t *z = pcon->GetZ();
566 par.AddAt(pcon->GetPhi1(),0);
567 par.AddAt(pcon->GetDphi(),1);
568 par.AddAt(pcon->GetNz(),2);
569 for (Int_t i=0; i<nz; i++) {
570 par.AddAt(z[i], 3+3*i);
572 par.AddAt(rmin[i], 3+3*i+1);
573 par.AddAt(rmax[i], 3+3*i+2);
577 if (classType==TGeoEltu::Class()) {
581 TGeoEltu *eltu = (TGeoEltu*)shape;
582 par.AddAt(eltu->GetA(),0);
583 par.AddAt(eltu->GetB(),1);
584 par.AddAt(eltu->GetDz(),2);
587 if (classType==TGeoHype::Class()) {
591 TGeoHype *hype = (TGeoHype*)shape;
592 par.AddAt(TMath::Sqrt(hype->RadiusHypeSq(0.,kTRUE)),0);
593 par.AddAt(TMath::Sqrt(hype->RadiusHypeSq(0.,kFALSE)),1);
594 par.AddAt(hype->GetDZ(),2);
595 par.AddAt(hype->GetStIn(),3);
596 par.AddAt(hype->GetStOut(),4);
599 if (classType==TGeoGtra::Class()) {
603 TGeoGtra *trap = (TGeoGtra*)shape;
604 Double_t tth = TMath::Tan(trap->GetTheta()*TMath::DegToRad());
605 par.AddAt(trap->GetDz(),0);
606 par.AddAt(tth*TMath::Cos(trap->GetPhi()*TMath::DegToRad()),1);
607 par.AddAt(tth*TMath::Sin(trap->GetPhi()*TMath::DegToRad()),2);
608 par.AddAt(trap->GetH1(),3);
609 par.AddAt(trap->GetBl1(),4);
610 par.AddAt(trap->GetTl1(),5);
611 par.AddAt(TMath::Tan(trap->GetAlpha1()*TMath::DegToRad()),6);
612 par.AddAt(trap->GetH2(),7);
613 par.AddAt(trap->GetBl2(),8);
614 par.AddAt(trap->GetTl2(),9);
615 par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
616 par.AddAt(trap->GetTwistAngle(),11);
619 if (classType==TGeoCtub::Class()) {
623 TGeoCtub *ctub = (TGeoCtub*)shape;
624 const Double_t *lx = ctub->GetNlow();
625 const Double_t *tx = ctub->GetNhigh();
626 par.AddAt(ctub->GetRmin(),0);
627 par.AddAt(ctub->GetRmax(),1);
628 par.AddAt(ctub->GetDz(),2);
629 par.AddAt(ctub->GetPhi1(),3);
630 par.AddAt(ctub->GetPhi2(),4);
639 Error("GetShape","Getting shape parameters for shape %s not implemented",
641 shapeType = "Unknown";
644 //______________________________________________________________________
645 void AliITSUInitGeometry::DecodeDetector(
646 Int_t &mod,Int_t layer,Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
647 // decode geometry into detector module number. There are two decoding
648 // Scheams. Old which does not follow the ALICE coordinate system
649 // requirements, and New which dose.
651 // Int_t layer The ITS layer
652 // Int_t cpn0 The lowest copy number
653 // Int_t cpn1 The middle copy number
654 // Int_t cpn2 the highest copy number
656 // Int_t &mod The module number assoicated with this set
661 // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't
662 // like them but I see not better way for the moment.
663 switch (fMajorVersion){
665 Error("DecodeDetector","Major version = kvDefault, not supported");
668 return DecodeDetectorv11(mod,layer,cpn0,cpn1,cpn2);
671 return DecodeDetectorvUpgrade(mod,layer,cpn0,cpn1,cpn2);
674 Error("DecodeDetector","Major version = %d, not supported",
675 (Int_t)fMajorVersion);
681 //______________________________________________________________________
682 void AliITSUInitGeometry::RecodeDetector(Int_t mod,Int_t &cpn0,
683 Int_t &cpn1,Int_t &cpn2){
684 // decode geometry into detector module number. There are two decoding
685 // Scheams. Old which does not follow the ALICE coordinate system
686 // requirements, and New which dose.
688 // Int_t mod The module number assoicated with this set
691 // Int_t cpn0 The lowest copy number
692 // Int_t cpn1 The middle copy number
693 // Int_t cpn2 the highest copy number
697 // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't
698 // like them but I see not better way for the moment.
699 switch (fMajorVersion){
701 Error("RecodeDetector","Major version = kvDefault, not supported");
705 return RecodeDetectorv11(mod,cpn0,cpn1,cpn2);
708 return RecodeDetectorvUpgrade(mod,cpn0,cpn1,cpn2);
711 Error("RecodeDetector","Major version = %d, not supported",
712 (Int_t)fMajorVersion);
718 //______________________________________________________________________
719 void AliITSUInitGeometry::DecodeDetectorLayers(Int_t mod,Int_t &layer,
720 Int_t &lad,Int_t &det){
721 // decode geometry into detector module number. There are two decoding
722 // Scheams. Old which does not follow the ALICE coordinate system
723 // requirements, and New which dose. Note, this use of layer ladder
724 // and detector numbers are strictly for internal use of this
725 // specific code. They do not represent the "standard" layer ladder
726 // or detector numbering except in a very old and obsoleate sence.
728 // Int_t mod The module number assoicated with this set
731 // Int_t lay The layer number
732 // Int_t lad The ladder number
733 // Int_t det the dettector number
737 // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't
738 // like them but I see not better way for the moment.
739 switch (fMajorVersion) {
741 Error("DecodeDetectorLayers",
742 "Major version = kvDefault, not supported");
746 return DecodeDetectorLayersv11(mod,layer,lad,det);
749 return DecodeDetectorLayersvUpgrade(mod,layer,lad,det);
752 Error("DecodeDetectorLayers","Major version = %d, not supported",
753 (Int_t)fMajorVersion);
760 //______________________________________________________________________
761 void AliITSUInitGeometry::DecodeDetectorv11(Int_t &mod,Int_t layer,
762 Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
763 // decode geometry into detector module number
765 // Int_t layer The ITS layer
766 // Int_t cpn0 The lowest copy number
767 // Int_t cpn1 The middle copy number
768 // Int_t cpn2 the highest copy number
770 // Int_t &mod The module number assoicated with this set
774 const Int_t kDetPerLadderSPD[2]={2,4};
775 const Int_t kDetPerLadder[6]={4,4,6,8,22,25};
776 const Int_t kLadPerLayer[6]={20,40,14,22,34,38};
781 lad = cpn1+kDetPerLadderSPD[layer-1]*(cpn0-1);
796 for(Int_t i=0;i<layer-1;i++) mod += kLadPerLayer[i]*kDetPerLadder[i];
797 mod += kDetPerLadder[layer-1]*(lad-1)+det-1;// module start at zero.
801 //______________________________________________________________________
802 void AliITSUInitGeometry::DecodeDetectorvUpgrade(Int_t &mod,Int_t layer,
803 Int_t cpn0,Int_t cpn1,Int_t /*cpn2*/) const {
804 // decode geometry into detector module number
806 // Int_t layer The ITS layer
807 // Int_t cpn0 The lowest copy number
808 // Int_t cpn1 The middle copy number
809 // Int_t cpn2 the highest copy number
811 // Int_t &mod The module number assoicated with this set
817 layer--; // starts from 1!
821 for(Int_t i=0;i<layer;i++) mod += GetNumberOfLadders(i)*GetNumberOfModules(i);
822 mod += GetNumberOfModules(layer)*(lad-1)+det-1;// module start at zero.
826 //______________________________________________________________________
827 void AliITSUInitGeometry::RecodeDetectorv11(Int_t mod,Int_t &cpn0,
828 Int_t &cpn1,Int_t &cpn2) {
829 // decode geometry into detector module number using the new decoding
832 // Int_t mod The module number assoicated with this set
835 // Int_t cpn0 The lowest copy number (SPD sector or SDD/SSD ladder)
836 // Int_t cpn1 The middle copy number (SPD stave or SDD/SSD module)
837 // Int_t cpn2 the highest copy number (SPD ladder or 1 for SDD/SSD)
840 const Int_t kDetPerLadderSPD[2]={2,4};
843 DecodeDetectorLayersv11(mod,lay,lad,det);
845 cpn2 = det; // Detector 1-4
846 cpn0 = (lad+kDetPerLadderSPD[lay-1]-1)/kDetPerLadderSPD[lay-1];
847 cpn1 = (lad+kDetPerLadderSPD[lay-1]-1)%kDetPerLadderSPD[lay-1] + 1;
848 } else { // SDD and SSD
858 } // end if Lay<5/else
859 } // end if lay<3/else
860 /*printf("AliITSUInitGeometry::RecodeDetectorv11:"
861 "mod=%d lay=%d lad=%d det=%d cpn0=%d cpn1=%d cpn2=%d\n",
862 mod,lay,lad,det,cpn0,cpn1,cpn2);*/
865 //______________________________________________________________________
866 void AliITSUInitGeometry::RecodeDetectorvUpgrade(Int_t mod,Int_t &cpn0,
867 Int_t &cpn1,Int_t &cpn2) {
868 // decode geometry into detector module number using the new decoding
871 // Int_t mod The module number assoicated with this set
874 // Int_t cpn0 The lowest copy number (ladder)
875 // Int_t cpn1 The middle copy number (module)
876 // Int_t cpn2 the highest copy number (sensor - always 1 for now)
879 // MS - 23jun11 - cross your fingers and hope for the best
882 DecodeDetectorLayersvUpgrade(mod,lay,lad,det);
888 /*printf("AliITSUInitGeometry::RecodeDetectorv11:"
889 "mod=%d lay=%d lad=%d det=%d cpn0=%d cpn1=%d cpn2=%d\n",
890 mod,lay,lad,det,cpn0,cpn1,cpn2);*/
893 //______________________________________________________________________
894 void AliITSUInitGeometry::DecodeDetectorLayersv11(Int_t mod,Int_t &lay,
895 Int_t &lad,Int_t &det) {
897 // decode module number into detector indices for v11
899 // lay, lad, det start from 1
902 // Int_t mod The module number associated with this set
905 // Int_t lay The layer number
906 // Int_t lad The ladder number
907 // Int_t det the dettector number
909 const Int_t kDetPerLadder[6] = {4,4,6,8,22,25};
910 const Int_t kLadPerLayer[6] = {20,40,14,22,34,38};
916 mod2 += kLadPerLayer[lay]*kDetPerLadder[lay];
918 } while(mod2<=mod); // end while
919 if(lay>6) Error("DecodeDetectorLayers","lay=%d>6",lay);
921 mod2 = kLadPerLayer[lay-1]*kDetPerLadder[lay-1] - mod2+mod;
922 lad = mod2/kDetPerLadder[lay-1];
924 if(lad>=kLadPerLayer[lay-1]||lad<0) Error("DecodeDetectorLayers",
925 "lad=%d not in the correct range",lad);
926 det = (mod2 - lad*kDetPerLadder[lay-1])+1;
927 if(det>kDetPerLadder[lay-1]||det<1) Error("DecodeDetectorLayers",
928 "det=%d not in the correct range",det);
932 //______________________________________________________________________
933 void AliITSUInitGeometry::DecodeDetectorLayersvUpgrade(Int_t mod,Int_t &lay,
934 Int_t &lad,Int_t &det){
936 // decode module number into detector indices for vUpgrade
938 // lay, lad, det start from 1
941 // Int_t mod The module number associated with this set
944 // Int_t lay The layer number
945 // Int_t lad The ladder number
946 // Int_t det the dettector number
949 const Int_t kLayers = GetNumberOfLayers();
955 mod2 += GetNumberOfLadders(lay)*GetNumberOfModules(lay);
957 } while(mod2<=mod); // end while
958 if(lay>kLayers) Error("DecodeDetectorLayers","lay=%d>%d",lay,kLayers);
960 mod2 = GetNumberOfLadders(lay-1)*GetNumberOfModules(lay-1) - mod2+mod;
961 lad = mod2/GetNumberOfModules(lay-1);
963 if(lad>=GetNumberOfLadders(lay-1)||lad<0) Error("DecodeDetectorLayers",
964 "lad=%d not in the correct range",lad);
965 det = (mod2 - lad*GetNumberOfModules(lay-1))+1;
966 if(det>GetNumberOfModules(lay-1)||det<1) Error("DecodeDetectorLayers",
968 "det=%d not in the correct range",det);
973 //______________________________________________________________________
974 Bool_t AliITSUInitGeometry::WriteVersionString(Char_t *str,Int_t length,
975 AliITSVersion_t maj,Int_t min,
976 const Char_t *cvsDate,const Char_t *cvsRevision)const{
977 // fills the string str with the major and minor version number
979 // Char_t *str The character string to hold the major
980 // and minor version numbers in
981 // Int_t length The maximum number of characters which
982 // can be accomidated by this string.
983 // str[length-1] must exist and will be set to zero
984 // AliITSVersion_t maj The major number
985 // Int_t min The minor number
986 // Char_t *cvsDate The date string from cvs
987 // Char_t *cvsRevision The Revision string from cvs
989 // Char_t *str The character string holding the major and minor
990 // version numbers. str[length-1] must exist
991 // and will be set to zero
993 // kTRUE if no errors
994 Char_t cvslikedate[30];
995 Int_t i,n,cvsDateLength,cvsRevisionLength;
997 cvsDateLength = (Int_t)strlen(cvsDate);
998 if(cvsDateLength>30){ // svn string, make a cvs like string
1001 cvslikedate[i] = cvsDate[i];
1002 if(cvsDate[i]=='+' || cvsDate[i++]=='-'){
1003 n++; // count number of -
1004 cvslikedate[i-1] = '/'; // replace -'s by /'s.
1006 } while(n<3&&i<30); // once additonal - of time zone reach exit
1007 cvslikedate[i-1] = '$'; // put $ at end then zero.
1008 for(;i<30;i++) cvslikedate[i]=0;// i starts wher do loop left off.
1010 for(i=0;i<cvsDateLength&&i<30;i++) cvslikedate[i]=cvsDate[i];
1012 cvsDateLength = (Int_t)strlen(cvslikedate);
1013 cvsRevisionLength = (Int_t)strlen(cvsRevision);
1015 n = 50+(Int_t)(TMath::Log10(TMath::Abs((Double_t)i)))+1+
1016 (Int_t)(TMath::Log10(TMath::Abs((Double_t)min)))+1
1017 +cvsDateLength-6+cvsRevisionLength-10;
1018 if(GetDebug()>1) printf("AliITSUInitGeometry::WriteVersionString:"
1019 "length=%d major=%d minor=%d cvsDate=%s[%d] "
1020 "cvsRevision=%s[%d] n=%d\n",length,i,min,cvslikedate,
1021 cvsDateLength,cvsRevision,cvsRevisionLength,n);
1024 if(length<n){// not enough space to write in output string.
1025 Warning("WriteVersionString","Output string not long enough "
1026 "lenght=%d must be at least %d long\n",length,n);
1028 } // end if length<n
1029 char *cvsrevision = new char[cvsRevisionLength-10];
1030 char *cvsdate = new char[cvsDateLength-6];
1031 for(i=0;i<cvsRevisionLength-10;i++)
1032 if(10+i<cvsRevisionLength-1)
1033 cvsrevision[i] = cvsRevision[10+i]; else cvsrevision[i] = 0;
1034 for(i=0;i<cvsDateLength-6;i++) if(6+i<cvsDateLength-1)
1035 cvsdate[i] = cvslikedate[6+i]; else cvsdate[i] = 0;
1036 for(i=0;i<length;i++) str[i] = 0; // zero it out for now.
1038 snprintf(str,length-1,"Major Version= %d Minor Version= %d Revision: %s Date: %s",i,min,cvsrevision,cvsdate);
1039 /* this gives compilation warnings on some compilers: descriptor zu
1040 if(GetDebug()>1)printf("AliITSUInitGeometry::WriteVersionString: "
1041 "n=%d str=%s revision[%zu] date[%zu]\n",
1042 n,str,strlen(cvsrevision),strlen(cvsdate));
1044 delete[] cvsrevision;
1048 //______________________________________________________________________
1049 Bool_t AliITSUInitGeometry::ReadVersionString(const Char_t *str,Int_t length,
1050 AliITSVersion_t &maj,Int_t &min,
1052 // fills the string str with the major and minor version number
1054 // Char_t *str The character string to holding the major and minor
1055 // version numbers in
1056 // Int_t length The maximum number of characters which can be
1057 // accomidated by this string. str[length-1] must exist
1059 // Char_t *str The character string holding the major and minor
1060 // version numbers unchanged. str[length-1] must exist.
1061 // AliITSVersion_t maj The major number
1062 // Int_t min The minor number
1063 // TDatime dt The date and time of the cvs commit
1065 // kTRUE if no errors
1067 Char_t cvsRevision[10],cvsDate[11],cvsTime[9];
1068 Int_t i,m,n=strlen(str),year,month,day,hours,minuits,seconds;
1069 memset(cvsRevision,0,10*sizeof(Char_t));
1070 memset(cvsDate,0,11*sizeof(Char_t));
1071 memset(cvsTime,0,9*sizeof(Char_t));
1073 if(GetDebug()>1)printf("AliITSUInitGeometry::ReadVersionString:"
1074 "str=%s length=%d\n",
1076 if(n<35) return kFALSE; // not enough space for numbers
1077 m = sscanf(str,"Major Version= %d Minor Version= %d Revision: %9s "
1078 "Date: %10s %8s",&i,&min,cvsRevision,cvsDate,cvsTime);
1081 m = sscanf(cvsDate,"%d/%d/%d",&year,&month,&day);
1084 m = sscanf(cvsTime,"%d:%d:%d",&hours,&minuits,&seconds);
1087 dt.Set(year,month,day,hours,minuits,seconds);
1088 if(GetDebug()>1)printf("AliITSUInitGeometry::ReadVersionString: i=%d "
1089 "min=%d cvsRevision=%s cvsDate=%s cvsTime=%s m=%d\n",
1090 i,min,cvsRevision,cvsDate,cvsTime,m);
1091 if(GetDebug()>1)printf("AliITSUInitGeometry::ReadVersionString: year=%d"
1092 " month=%d day=%d hours=%d minuits=%d seconds=%d\n",
1093 year,month,day,hours,minuits,seconds);
1107 //______________________________________________________________________
1108 Int_t AliITSUInitGeometry::GetNumberOfLayers(){
1109 // Determines the number of layers in the Upgrade Geometry
1116 // the number of layers in the current geometry
1117 // -1 if not Upgrade Geometry
1120 Int_t numberOfLayers = 0;
1122 if (fMajorVersion != kvUpgrade) {
1123 AliError("Not Upgrade Geometry!");
1127 // This checks should be redundant, but let's do things neatly
1129 AliError("gGeoManager is null");
1133 if (!gGeoManager->GetVolume(AliITSUGeomTGeo::GetITSVolPattern())) {
1134 AliError(Form("can't find %s volume",AliITSUGeomTGeo::GetITSVolPattern()));
1138 // Loop on all ITSV nodes, count Layer volumes by checking names
1139 Int_t nNodes = gGeoManager->GetVolume(AliITSUGeomTGeo::GetITSVolPattern())->GetNodes()->GetEntries();
1144 for (Int_t j=0; j<nNodes; j++)
1145 if (strstr(gGeoManager->GetVolume(AliITSUGeomTGeo::GetITSVolPattern())->GetNodes()->At(j)->GetName(),
1146 AliITSUGeomTGeo::GetITSLayerPattern()))
1150 return numberOfLayers;
1153 //______________________________________________________________________
1154 Int_t AliITSUInitGeometry::GetNumberOfLadders(const Int_t lay) const {
1155 // Determines the number of layers in the Upgrade Geometry
1158 // lay: layer number
1162 // the number of ladders in layer lay
1163 // -1 if not Upgrade Geometry
1166 Int_t numberOfLadders = 0;
1168 if (fMajorVersion != kvUpgrade) {
1169 AliError("Not Upgrade Geometry!");
1173 // This checks should be redundant, but let's do things neatly
1175 AliError("gGeoManager is null");
1180 snprintf(laynam, 15, "%s%d", AliITSUGeomTGeo::GetITSLayerPattern(),lay+1);
1181 if (!gGeoManager->GetVolume(laynam)) {
1182 AliError(Form("can't find %s volume",laynam));
1186 // Loop on all layer nodes, count Ladder volumes by checking names
1187 Int_t nNodes = gGeoManager->GetVolume(laynam)->GetNodes()->GetEntries();
1192 for (Int_t j=0; j<nNodes; j++)
1193 if (strstr(gGeoManager->GetVolume(laynam)->GetNodes()->At(j)->GetName(),
1194 AliITSUGeomTGeo::GetITSLadderPattern()))
1198 return numberOfLadders;
1201 //______________________________________________________________________
1202 Int_t AliITSUInitGeometry::GetLayerDetTypeID(const Int_t lay) const
1204 // Determines the layers det. type in the Upgrade Geometry
1207 // lay: layer number
1212 // -1 if not Upgrade Geometry
1215 if (fMajorVersion != kvUpgrade) {
1216 AliError("Not Upgrade Geometry!");
1220 // This checks should be redundant, but let's do things neatly
1222 AliError("gGeoManager is null");
1227 snprintf(laynam, 15, "%s%d", AliITSUGeomTGeo::GetITSLayerPattern(),lay+1);
1228 TGeoVolume* volLr = gGeoManager->GetVolume(laynam);
1230 AliError(Form("can't find %s volume",laynam));
1234 return volLr->GetUniqueID();
1238 //______________________________________________________________________
1239 Int_t AliITSUInitGeometry::GetNumberOfModules(const Int_t lay) const {
1240 // Determines the number of layers in the Upgrade Geometry
1243 // lay: layer number
1247 // the number of modules per ladder in layer lay
1248 // -1 if not Upgrade Geometry
1251 Int_t numberOfModules = 0;
1253 if (fMajorVersion != kvUpgrade) {
1254 AliError("Not Upgrade Geometry!");
1258 // This checks should be redundant, but let's do things neatly
1260 AliError("gGeoManager is null");
1265 snprintf(laddnam, 15, "%s%d", AliITSUGeomTGeo::GetITSLadderPattern(),lay+1);
1266 if (!gGeoManager->GetVolume(laddnam)) {
1267 AliError(Form("can't find %s volume",laddnam));
1271 // Loop on all ladder nodes, count Module volumes by checking names
1272 Int_t nNodes = gGeoManager->GetVolume(laddnam)->GetNodes()->GetEntries();
1277 for (Int_t j=0; j<nNodes; j++)
1278 if (strstr(gGeoManager->GetVolume(laddnam)->GetNodes()->At(j)->GetName(),
1279 AliITSUGeomTGeo::GetITSModulePattern()))
1283 return numberOfModules;