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: AliITSInitGeometryUpg.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 "AliITSgeomTGeoUpg.h"
49 #include "AliITSInitGeometryUpg.h"
52 ClassImp(AliITSInitGeometryUpg)
54 //______________________________________________________________________
55 AliITSInitGeometryUpg::AliITSInitGeometryUpg():
56 TObject(), // Base Class
57 fName(0), // Geometry name
58 fMinorVersion(-1), // Minor version number/type
59 fMajorVersion(kvDefault), // Major versin number
60 fTiming(kFALSE), // Flag to start inilization timing
61 fSegGeom(kFALSE), // Flag to switch between the old use of
62 // AliITSgeomS?D class, or AliITSsegmentation
63 // class in fShape of AliITSgeom class.
64 fDecode(kFALSE), // Flag for new/old decoding
65 fDebug(0){ // Debug flag
72 // A default inilized AliITSInitGeometryUpg object
76 //______________________________________________________________________
77 AliITSInitGeometryUpg::AliITSInitGeometryUpg(AliITSVersion_t version,
79 TObject(), // Base Class
80 fName(0), // Geometry name
81 fMinorVersion(minorversion), // Minor version number/type
82 fMajorVersion(version), // Major versin number
83 fTiming(kFALSE), // Flag to start inilization timing
84 fSegGeom(kFALSE), // Flag to switch between the old use of
85 // AliITSgeomS?D class, or AliITSsegmentation
86 // class in fShape of AliITSgeom class.
87 fDecode(kFALSE), // Flag for new/old decoding
88 fDebug(0){ // Debug flag
95 // A default inilized AliITSInitGeometryUpg object
102 fName="AliITSvUpgrade";
106 AliFatal(Form("Undefined geometry: fMajorVersion=%d, "
107 "fMinorVersion= %d",(Int_t)fMajorVersion,fMinorVersion));
112 //______________________________________________________________________
113 AliITSgeom* AliITSInitGeometryUpg::CreateAliITSgeom(){
114 // Creates and Initilizes the geometry transformation class AliITSgeom
115 // to values appropreate to this specific geometry. Now that
116 // the segmentation is part of AliITSgeom, the detector
117 // segmentations are also defined here.
123 // A pointer to a new properly inilized AliITSgeom class. If
124 // pointer = 0 then failed to init.
127 AliITSVersion_t version = kvDefault;
130 TGeoVolume *itsV = gGeoManager->GetVolume(AliITSgeomTGeoUpg::GetITSVolPattern());
132 Error("CreateAliITSgeom","Can't find ITS volume ITSV, aborting");
135 const Char_t *title = itsV->GetTitle();
136 if(!ReadVersionString(title,(Int_t)strlen(title),version,minor,
138 Warning("UpdateInternalGeometry","Can't read title=%s\n",title);
142 AliITSgeom *geom = CreateAliITSgeom(version,minor);
143 AliDebug(1,"AliITSgeom object has been initialized from TGeo\n");
146 //______________________________________________________________________
147 AliITSgeom* AliITSInitGeometryUpg::CreateAliITSgeom(Int_t major,Int_t minor){
148 // Creates and Initilizes the geometry transformation class AliITSgeom
149 // to values appropreate to this specific geometry. Now that
150 // the segmentation is part of AliITSgeom, the detector
151 // segmentations are also defined here.
153 // Int_t major major version, see AliITSVersion_t
154 // Int_t minor minor version
158 // A pointer to a new properly inilized AliITSgeom class. If
159 // pointer = 0 then failed to init.
163 SetGeometryName("AliITSv11");
164 SetVersion(kv11,minor);
167 SetGeometryName("AliITSvUpgrade");
168 SetVersion(kvUpgrade,minor);
172 SetGeometryName("Undefined");
173 SetVersion(kvDefault,minor);
176 AliITSgeom *geom = new AliITSgeom();
177 if(!InitAliITSgeom(geom)){ // Error initilization failed
183 //______________________________________________________________________
184 Bool_t AliITSInitGeometryUpg::InitAliITSgeom(AliITSgeom *geom){
185 // Initilizes the geometry transformation class AliITSgeom
186 // to values appropreate to this specific geometry. Now that
187 // the segmentation is part of AliITSgeom, the detector
188 // segmentations are also defined here.
190 // AliITSgeom *geom A pointer to the AliITSgeom class
192 // AliITSgeom *geom This pointer recreated and properly inilized.
197 AliFatal("The geometry manager has not been initialized (e.g. "
198 "TGeoManager::Import(\"geometry.root\")should be "
199 "called in advance) - exit forced");
202 switch(fMajorVersion) {
204 return InitAliITSgeomV11(geom);
207 return InitAliITSgeomVUpgrade(geom);
209 case kvDefault: default: {
210 AliFatal("Undefined geometry");
216 //______________________________________________________________________
217 void AliITSInitGeometryUpg::TransposeTGeoHMatrix(TGeoHMatrix *m)const{
218 // Transpose the rotation matrix part of a TGeoHMatrix. This
219 // is needed because TGeo stores the transpose of the rotation
220 // matrix as compared to what AliITSgeomMatrix uses (and Geant3).
222 // TGeoHMatrix *m The matrix to be transposed
224 // TGEoHMatrix *m The transposed matrix
230 if(m==0) return; // no matrix to transpose.
231 for(i=0;i<9;i += 4) r[i] = m->GetRotationMatrix()[i]; // diagonals
232 r[1] = m->GetRotationMatrix()[3];
233 r[2] = m->GetRotationMatrix()[6];
234 r[3] = m->GetRotationMatrix()[1];
235 r[5] = m->GetRotationMatrix()[7];
236 r[6] = m->GetRotationMatrix()[2];
237 r[7] = m->GetRotationMatrix()[5];
243 //______________________________________________________________________
244 Bool_t AliITSInitGeometryUpg::InitAliITSgeomV11(AliITSgeom *geom){
245 // Initilizes the geometry transformation class AliITSgeom
246 // Now that the segmentation is part of AliITSgeom, the detector
247 // segmentations are also defined here.
250 // AliITSgeom *geom A pointer to the AliITSgeom class
252 // AliITSgeom *geom This pointer recreated and properly inilized.
255 const Int_t kItype = 0; // Type of transformation defined 0=> Geant
256 const Int_t klayers = 6; // number of layers in the ITS
257 const Int_t kladders[klayers] = {20,40,14,22,34,38}; // Number of ladders
258 const Int_t kdetectors[klayers] = {4,4,6,8,22,25};// number of detector/lad
259 const AliITSDetector kIdet[6] = {kSPD,kSPD,kSDD,kSDD,kSSD,kSSD};
260 const TString kPathbase = "/ALIC_1/ITSV_1/";
262 const char *pathSPDsens1, *pathSPDsens2;
263 pathSPDsens1="%sITSSPD_1/ITSSPDCarbonFiberSectorV_%d/ITSSPDSensitiveVirtualvolumeM0_1/ITSSPDlay1-Stave_%d/ITSSPDhalf-Stave%d_1/ITSSPDlay1-Ladder_%d/ITSSPDlay1-sensor_1";
264 pathSPDsens2="%sITSSPD_1/ITSSPDCarbonFiberSectorV_%d/ITSSPDSensitiveVirtualvolumeM0_1/ITSSPDlay2-Stave_%d/ITSSPDhalf-Stave%d_1/ITSSPDlay2-Ladder_%d/ITSSPDlay2-sensor_1";
266 const char *pathSDDsens1, *pathSDDsens2;
267 pathSDDsens1 = "%sITSsddLayer3_1/ITSsddLadd_%d/ITSsddSensor3_%d/ITSsddWafer3_%d/ITSsddSensitivL3_1";
268 pathSDDsens2 = "%sITSsddLayer4_1/ITSsddLadd_%d/ITSsddSensor4_%d/ITSsddWafer4_%d/ITSsddSensitivL4_1";
270 const char *pathSSDsens1, *pathSSDsens2;
271 pathSSDsens1 = "%sITSssdLayer5_1/ITSssdLay5Ladd_%d/ITSssdSensor5_%d/ITSssdSensitivL5_1";
272 pathSSDsens2 = "%sITSssdLayer6_1/ITSssdLay6Ladd_%d/ITSssdSensor6_%d/ITSssdSensitivL6_1";
274 const TString kNames[klayers] = {
275 pathSPDsens1, // lay=1
276 pathSPDsens2, // lay=2
277 pathSDDsens1, // lay=3
278 pathSDDsens2, // lay=4
279 pathSSDsens1, // lay=5
280 pathSSDsens2};// Lay=6
282 Int_t mod,nmods=0, lay, lad, det, cpn0, cpn1, cpn2, cpnHS=1;
283 Double_t tran[3]={0.,0.,0.}, rot[10]={9*0.0,1.0};
285 TString path, shapeName;
287 Bool_t initSeg[3]={kFALSE, kFALSE, kFALSE};
288 TStopwatch *time = 0x0;
289 if(fTiming) time = new TStopwatch();
291 if(fTiming) time->Start();
292 for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
293 geom->Init(kItype,klayers,kladders,kdetectors,nmods);
295 for(mod=0; mod<nmods; mod++) {
297 DecodeDetectorLayers(mod,lay,lad,det);
298 geom->CreateMatrix(mod,lay,lad,det,kIdet[lay-1],tran,rot);
299 RecodeDetector(mod,cpn0,cpn1,cpn2);
301 if (kIdet[lay-1]==kSPD) { // we need 1 more copy number because of the half-stave
302 if (det<3) cpnHS = 0; else cpnHS = 1;
303 path.Form(kNames[lay-1].Data(),kPathbase.Data(),cpn0,cpn1,cpnHS,cpn2);
305 path.Form(kNames[lay-1].Data(),kPathbase.Data(),cpn0,cpn1,cpn2);
308 geom->GetGeomMatrix(mod)->SetPath(path);
309 GetTransformation(path.Data(),matrix);
310 geom->SetTrans(mod,matrix.GetTranslation());
311 TransposeTGeoHMatrix(&matrix); //Transpose TGeo's rotation matrixes
312 geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
313 if(initSeg[kIdet[lay-1]]) continue;
314 GetShape(path,shapeName,shapePar);
315 if(shapeName.CompareTo("BOX")){
316 Error("InitITSgeom","Geometry changed without proper code update"
317 "or error in reading geometry. Shape is not BOX.");
329 //______________________________________________________________________
330 Bool_t AliITSInitGeometryUpg::InitAliITSgeomVUpgrade(AliITSgeom *geom){
331 // Initilizes the geometry transformation class AliITSgeom
332 // Now that the segmentation is part of AliITSgeom, the detector
333 // segmentations are also defined here.
336 // AliITSgeom *geom A pointer to the AliITSgeom class
338 // AliITSgeom *geom This pointer recreated and properly inilized.
341 const Int_t kItype = 0; // Type of transformation defined 0=> Geant
342 const Int_t klayers = GetNumberOfLayers(); // Number of layers in the ITS
343 const AliITSDetector kIdet = AliITSDetector(0); //kUPG; RS temporary
344 TString pathbase = Form("/ALIC_1/%s_2/",AliITSgeomTGeoUpg::GetITSVolPattern()); // We have 2 to cheat AliGeoManager::CheckSymNamesLUT
347 AliError("No layers found in ITSV");
351 Int_t *kladders = new Int_t[klayers]; // Number of ladders
352 Int_t *kdetectors = new Int_t[klayers]; // Number of detectors/ladder
354 for (Int_t j=0; j<klayers; j++) {
355 kladders[j] = GetNumberOfLadders(j);
356 kdetectors[j] = GetNumberOfModules(j);
358 const TString kPathBase = Form("/ALIC_1/%s_1/",AliITSgeomTGeoUpg::GetITSVolPattern());
359 const TString kNames = Form("%%s%s%%d_1/%s%%d_%%d/%s%%d_%%d/%s%%d_%%d"
360 ,AliITSgeomTGeoUpg::GetITSLayerPattern()
361 ,AliITSgeomTGeoUpg::GetITSLadderPattern()
362 ,AliITSgeomTGeoUpg::GetITSModulePattern()
363 ,AliITSgeomTGeoUpg::GetITSSensorPattern()
365 Int_t mod,nmods=0, lay, lad, det, cpn0, cpn1, cpn2;
366 Double_t tran[3]={0.,0.,0.}, rot[10]={9*0.0,1.0};
368 TString path, shapeName;
370 // Bool_t initSeg[3]={kFALSE, kFALSE, kFALSE};
371 TStopwatch *time = 0x0;
372 if(fTiming) time = new TStopwatch();
374 if(fTiming) time->Start();
375 for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
376 geom->Init(kItype,klayers,kladders,kdetectors,nmods);
378 for(mod=0; mod<nmods; mod++) {
380 DecodeDetectorLayers(mod,lay,lad,det);
381 geom->CreateMatrix(mod,lay,lad,det,kIdet,tran,rot);
382 RecodeDetector(mod,cpn0,cpn1,cpn2);
384 path.Form(kNames.Data(),kPathBase.Data(),lay,lay,cpn0,lay,cpn1,lay,cpn2);
386 geom->GetGeomMatrix(mod)->SetPath(path);
387 GetTransformation(path.Data(),matrix);
388 geom->SetTrans(mod,matrix.GetTranslation());
389 TransposeTGeoHMatrix(&matrix); //Transpose TGeo's rotation matrixes
390 geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
391 // if(initSeg[kIdet[lay-1]]) continue;
392 GetShape(path,shapeName,shapePar);
393 if(shapeName.CompareTo("BOX")){
394 Error("InitITSgeom","Geometry changed without proper code update"
395 "or error in reading geometry. Shape is not BOX.");
408 //_______________________________________________________________________
409 Bool_t AliITSInitGeometryUpg::GetTransformation(const TString &volumePath,
411 // Returns the Transformation matrix between the volume specified
412 // by the path volumePath and the Top or mater volume. The format
413 // of the path volumePath is as follows (assuming ALIC is the Top volume)
414 // "/ALIC_1/DDIP_1/S05I_2/S05H_1/S05G_3". Here ALIC is the top most
415 // or master volume which has only 1 instance of. Of all of the daughter
416 // volumes of ALICE, DDIP volume copy #1 is indicated. Similarly for
417 // the daughter volume of DDIP is S05I copy #2 and so on.
419 // TString& volumePath The volume path to the specific volume
420 // for which you want the matrix. Volume name
421 // hierarchy is separated by "/" while the
422 // copy number is appended using a "_".
424 // TGeoHMatrix &mat A matrix with its values set to those
425 // appropriate to the Local to Master transformation
427 // A logical value if kFALSE then an error occurred and no change to
430 // We have to preserve the modeler state
432 // Preserve the modeler state.
433 gGeoManager->PushPath();
434 if (!gGeoManager->cd(volumePath.Data())) {
435 gGeoManager->PopPath();
436 Error("GetTransformation","Error in cd-ing to %s",volumePath.Data());
438 } // end if !gGeoManager
439 mat = *gGeoManager->GetCurrentMatrix();
440 // Retstore the modeler state.
441 gGeoManager->PopPath();
444 //______________________________________________________________________
445 Bool_t AliITSInitGeometryUpg::GetShape(const TString &volumePath,
446 TString &shapeType,TArrayD &par){
447 // Returns the shape and its parameters for the volume specified
450 // TString& volumeName The volume name
452 // TString &shapeType Shape type
453 // TArrayD &par A TArrayD of parameters with all of the
454 // parameters of the specified shape.
456 // A logical indicating whether there was an error in getting this
459 gGeoManager->PushPath();
460 if (!gGeoManager->cd(volumePath.Data())) {
461 gGeoManager->PopPath();
464 TGeoVolume * vol = gGeoManager->GetCurrentVolume();
465 gGeoManager->PopPath();
466 if (!vol) return kFALSE;
467 TGeoShape *shape = vol->GetShape();
468 TClass *classType = shape->IsA();
469 if (classType==TGeoBBox::Class()) {
473 TGeoBBox *box = (TGeoBBox*)shape;
474 par.AddAt(box->GetDX(),0);
475 par.AddAt(box->GetDY(),1);
476 par.AddAt(box->GetDZ(),2);
479 if (classType==TGeoTrd1::Class()) {
483 TGeoTrd1 *trd1 = (TGeoTrd1*)shape;
484 par.AddAt(trd1->GetDx1(),0);
485 par.AddAt(trd1->GetDx2(),1);
486 par.AddAt(trd1->GetDy(), 2);
487 par.AddAt(trd1->GetDz(), 3);
490 if (classType==TGeoTrd2::Class()) {
494 TGeoTrd2 *trd2 = (TGeoTrd2*)shape;
495 par.AddAt(trd2->GetDx1(),0);
496 par.AddAt(trd2->GetDx2(),1);
497 par.AddAt(trd2->GetDy1(),2);
498 par.AddAt(trd2->GetDy2(),3);
499 par.AddAt(trd2->GetDz(), 4);
502 if (classType==TGeoTrap::Class()) {
506 TGeoTrap *trap = (TGeoTrap*)shape;
507 Double_t tth = TMath::Tan(trap->GetTheta()*TMath::DegToRad());
508 par.AddAt(trap->GetDz(),0);
509 par.AddAt(tth*TMath::Cos(trap->GetPhi()*TMath::DegToRad()),1);
510 par.AddAt(tth*TMath::Sin(trap->GetPhi()*TMath::DegToRad()),2);
511 par.AddAt(trap->GetH1(),3);
512 par.AddAt(trap->GetBl1(),4);
513 par.AddAt(trap->GetTl1(),5);
514 par.AddAt(TMath::Tan(trap->GetAlpha1()*TMath::DegToRad()),6);
515 par.AddAt(trap->GetH2(),7);
516 par.AddAt(trap->GetBl2(),8);
517 par.AddAt(trap->GetTl2(),9);
518 par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
521 if (classType==TGeoTube::Class()) {
525 TGeoTube *tube = (TGeoTube*)shape;
526 par.AddAt(tube->GetRmin(),0);
527 par.AddAt(tube->GetRmax(),1);
528 par.AddAt(tube->GetDz(),2);
531 if (classType==TGeoTubeSeg::Class()) {
535 TGeoTubeSeg *tubs = (TGeoTubeSeg*)shape;
536 par.AddAt(tubs->GetRmin(),0);
537 par.AddAt(tubs->GetRmax(),1);
538 par.AddAt(tubs->GetDz(),2);
539 par.AddAt(tubs->GetPhi1(),3);
540 par.AddAt(tubs->GetPhi2(),4);
543 if (classType==TGeoCone::Class()) {
547 TGeoCone *cone = (TGeoCone*)shape;
548 par.AddAt(cone->GetDz(),0);
549 par.AddAt(cone->GetRmin1(),1);
550 par.AddAt(cone->GetRmax1(),2);
551 par.AddAt(cone->GetRmin2(),3);
552 par.AddAt(cone->GetRmax2(),4);
555 if (classType==TGeoConeSeg::Class()) {
559 TGeoConeSeg *cons = (TGeoConeSeg*)shape;
560 par.AddAt(cons->GetDz(),0);
561 par.AddAt(cons->GetRmin1(),1);
562 par.AddAt(cons->GetRmax1(),2);
563 par.AddAt(cons->GetRmin2(),3);
564 par.AddAt(cons->GetRmax2(),4);
565 par.AddAt(cons->GetPhi1(),5);
566 par.AddAt(cons->GetPhi2(),6);
569 if (classType==TGeoSphere::Class()) {
574 TGeoSphere *sphe = (TGeoSphere*)shape;
575 par.AddAt(sphe->GetRmin(),0);
576 par.AddAt(sphe->GetRmax(),1);
577 par.AddAt(sphe->GetTheta1(),2);
578 par.AddAt(sphe->GetTheta2(),3);
579 par.AddAt(sphe->GetPhi1(),4);
580 par.AddAt(sphe->GetPhi2(),5);
583 if (classType==TGeoPara::Class()) {
587 TGeoPara *para = (TGeoPara*)shape;
588 par.AddAt(para->GetX(),0);
589 par.AddAt(para->GetY(),1);
590 par.AddAt(para->GetZ(),2);
591 par.AddAt(para->GetTxy(),3);
592 par.AddAt(para->GetTxz(),4);
593 par.AddAt(para->GetTyz(),5);
596 if (classType==TGeoPgon::Class()) {
598 TGeoPgon *pgon = (TGeoPgon*)shape;
599 Int_t nz = pgon->GetNz();
600 const Double_t *rmin = pgon->GetRmin();
601 const Double_t *rmax = pgon->GetRmax();
602 const Double_t *z = pgon->GetZ();
605 par.AddAt(pgon->GetPhi1(),0);
606 par.AddAt(pgon->GetDphi(),1);
607 par.AddAt(pgon->GetNedges(),2);
608 par.AddAt(pgon->GetNz(),3);
609 for (Int_t i=0; i<nz; i++) {
610 par.AddAt(z[i], 4+3*i);
611 par.AddAt(rmin[i], 4+3*i+1);
612 par.AddAt(rmax[i], 4+3*i+2);
616 if (classType==TGeoPcon::Class()) {
618 TGeoPcon *pcon = (TGeoPcon*)shape;
619 Int_t nz = pcon->GetNz();
620 const Double_t *rmin = pcon->GetRmin();
621 const Double_t *rmax = pcon->GetRmax();
622 const Double_t *z = pcon->GetZ();
625 par.AddAt(pcon->GetPhi1(),0);
626 par.AddAt(pcon->GetDphi(),1);
627 par.AddAt(pcon->GetNz(),2);
628 for (Int_t i=0; i<nz; i++) {
629 par.AddAt(z[i], 3+3*i);
631 par.AddAt(rmin[i], 3+3*i+1);
632 par.AddAt(rmax[i], 3+3*i+2);
636 if (classType==TGeoEltu::Class()) {
640 TGeoEltu *eltu = (TGeoEltu*)shape;
641 par.AddAt(eltu->GetA(),0);
642 par.AddAt(eltu->GetB(),1);
643 par.AddAt(eltu->GetDz(),2);
646 if (classType==TGeoHype::Class()) {
650 TGeoHype *hype = (TGeoHype*)shape;
651 par.AddAt(TMath::Sqrt(hype->RadiusHypeSq(0.,kTRUE)),0);
652 par.AddAt(TMath::Sqrt(hype->RadiusHypeSq(0.,kFALSE)),1);
653 par.AddAt(hype->GetDZ(),2);
654 par.AddAt(hype->GetStIn(),3);
655 par.AddAt(hype->GetStOut(),4);
658 if (classType==TGeoGtra::Class()) {
662 TGeoGtra *trap = (TGeoGtra*)shape;
663 Double_t tth = TMath::Tan(trap->GetTheta()*TMath::DegToRad());
664 par.AddAt(trap->GetDz(),0);
665 par.AddAt(tth*TMath::Cos(trap->GetPhi()*TMath::DegToRad()),1);
666 par.AddAt(tth*TMath::Sin(trap->GetPhi()*TMath::DegToRad()),2);
667 par.AddAt(trap->GetH1(),3);
668 par.AddAt(trap->GetBl1(),4);
669 par.AddAt(trap->GetTl1(),5);
670 par.AddAt(TMath::Tan(trap->GetAlpha1()*TMath::DegToRad()),6);
671 par.AddAt(trap->GetH2(),7);
672 par.AddAt(trap->GetBl2(),8);
673 par.AddAt(trap->GetTl2(),9);
674 par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
675 par.AddAt(trap->GetTwistAngle(),11);
678 if (classType==TGeoCtub::Class()) {
682 TGeoCtub *ctub = (TGeoCtub*)shape;
683 const Double_t *lx = ctub->GetNlow();
684 const Double_t *tx = ctub->GetNhigh();
685 par.AddAt(ctub->GetRmin(),0);
686 par.AddAt(ctub->GetRmax(),1);
687 par.AddAt(ctub->GetDz(),2);
688 par.AddAt(ctub->GetPhi1(),3);
689 par.AddAt(ctub->GetPhi2(),4);
698 Error("GetShape","Getting shape parameters for shape %s not implemented",
700 shapeType = "Unknown";
703 //______________________________________________________________________
704 void AliITSInitGeometryUpg::DecodeDetector(
705 Int_t &mod,Int_t layer,Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
706 // decode geometry into detector module number. There are two decoding
707 // Scheams. Old which does not follow the ALICE coordinate system
708 // requirements, and New which dose.
710 // Int_t layer The ITS layer
711 // Int_t cpn0 The lowest copy number
712 // Int_t cpn1 The middle copy number
713 // Int_t cpn2 the highest copy number
715 // Int_t &mod The module number assoicated with this set
720 // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't
721 // like them but I see not better way for the moment.
722 switch (fMajorVersion){
724 Error("DecodeDetector","Major version = kvDefault, not supported");
727 return DecodeDetectorv11(mod,layer,cpn0,cpn1,cpn2);
730 return DecodeDetectorvUpgrade(mod,layer,cpn0,cpn1,cpn2);
733 Error("DecodeDetector","Major version = %d, not supported",
734 (Int_t)fMajorVersion);
740 //______________________________________________________________________
741 void AliITSInitGeometryUpg::RecodeDetector(Int_t mod,Int_t &cpn0,
742 Int_t &cpn1,Int_t &cpn2){
743 // decode geometry into detector module number. There are two decoding
744 // Scheams. Old which does not follow the ALICE coordinate system
745 // requirements, and New which dose.
747 // Int_t mod The module number assoicated with this set
750 // Int_t cpn0 The lowest copy number
751 // Int_t cpn1 The middle copy number
752 // Int_t cpn2 the highest copy number
756 // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't
757 // like them but I see not better way for the moment.
758 switch (fMajorVersion){
760 Error("RecodeDetector","Major version = kvDefault, not supported");
764 return RecodeDetectorv11(mod,cpn0,cpn1,cpn2);
767 return RecodeDetectorvUpgrade(mod,cpn0,cpn1,cpn2);
770 Error("RecodeDetector","Major version = %d, not supported",
771 (Int_t)fMajorVersion);
777 //______________________________________________________________________
778 void AliITSInitGeometryUpg::DecodeDetectorLayers(Int_t mod,Int_t &layer,
779 Int_t &lad,Int_t &det){
780 // decode geometry into detector module number. There are two decoding
781 // Scheams. Old which does not follow the ALICE coordinate system
782 // requirements, and New which dose. Note, this use of layer ladder
783 // and detector numbers are strictly for internal use of this
784 // specific code. They do not represent the "standard" layer ladder
785 // or detector numbering except in a very old and obsoleate sence.
787 // Int_t mod The module number assoicated with this set
790 // Int_t lay The layer number
791 // Int_t lad The ladder number
792 // Int_t det the dettector number
796 // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't
797 // like them but I see not better way for the moment.
798 switch (fMajorVersion) {
800 Error("DecodeDetectorLayers",
801 "Major version = kvDefault, not supported");
805 return DecodeDetectorLayersv11(mod,layer,lad,det);
808 return DecodeDetectorLayersvUpgrade(mod,layer,lad,det);
811 Error("DecodeDetectorLayers","Major version = %d, not supported",
812 (Int_t)fMajorVersion);
819 //______________________________________________________________________
820 void AliITSInitGeometryUpg::DecodeDetectorv11(Int_t &mod,Int_t layer,
821 Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
822 // decode geometry into detector module number
824 // Int_t layer The ITS layer
825 // Int_t cpn0 The lowest copy number
826 // Int_t cpn1 The middle copy number
827 // Int_t cpn2 the highest copy number
829 // Int_t &mod The module number assoicated with this set
833 const Int_t kDetPerLadderSPD[2]={2,4};
834 const Int_t kDetPerLadder[6]={4,4,6,8,22,25};
835 const Int_t kLadPerLayer[6]={20,40,14,22,34,38};
840 lad = cpn1+kDetPerLadderSPD[layer-1]*(cpn0-1);
855 for(Int_t i=0;i<layer-1;i++) mod += kLadPerLayer[i]*kDetPerLadder[i];
856 mod += kDetPerLadder[layer-1]*(lad-1)+det-1;// module start at zero.
860 //______________________________________________________________________
861 void AliITSInitGeometryUpg::DecodeDetectorvUpgrade(Int_t &mod,Int_t layer,
862 Int_t cpn0,Int_t cpn1,Int_t /*cpn2*/) const {
863 // decode geometry into detector module number
865 // Int_t layer The ITS layer
866 // Int_t cpn0 The lowest copy number
867 // Int_t cpn1 The middle copy number
868 // Int_t cpn2 the highest copy number
870 // Int_t &mod The module number assoicated with this set
876 layer--; // starts from 1!
880 for(Int_t i=0;i<layer;i++) mod += GetNumberOfLadders(i)*GetNumberOfModules(i);
881 mod += GetNumberOfModules(layer)*(lad-1)+det-1;// module start at zero.
885 //______________________________________________________________________
886 void AliITSInitGeometryUpg::RecodeDetectorv11(Int_t mod,Int_t &cpn0,
887 Int_t &cpn1,Int_t &cpn2) {
888 // decode geometry into detector module number using the new decoding
891 // Int_t mod The module number assoicated with this set
894 // Int_t cpn0 The lowest copy number (SPD sector or SDD/SSD ladder)
895 // Int_t cpn1 The middle copy number (SPD stave or SDD/SSD module)
896 // Int_t cpn2 the highest copy number (SPD ladder or 1 for SDD/SSD)
899 const Int_t kDetPerLadderSPD[2]={2,4};
902 DecodeDetectorLayersv11(mod,lay,lad,det);
904 cpn2 = det; // Detector 1-4
905 cpn0 = (lad+kDetPerLadderSPD[lay-1]-1)/kDetPerLadderSPD[lay-1];
906 cpn1 = (lad+kDetPerLadderSPD[lay-1]-1)%kDetPerLadderSPD[lay-1] + 1;
907 } else { // SDD and SSD
917 } // end if Lay<5/else
918 } // end if lay<3/else
919 /*printf("AliITSInitGeometryUpg::RecodeDetectorv11:"
920 "mod=%d lay=%d lad=%d det=%d cpn0=%d cpn1=%d cpn2=%d\n",
921 mod,lay,lad,det,cpn0,cpn1,cpn2);*/
924 //______________________________________________________________________
925 void AliITSInitGeometryUpg::RecodeDetectorvUpgrade(Int_t mod,Int_t &cpn0,
926 Int_t &cpn1,Int_t &cpn2) {
927 // decode geometry into detector module number using the new decoding
930 // Int_t mod The module number assoicated with this set
933 // Int_t cpn0 The lowest copy number (ladder)
934 // Int_t cpn1 The middle copy number (module)
935 // Int_t cpn2 the highest copy number (sensor - always 1 for now)
938 // MS - 23jun11 - cross your fingers and hope for the best
941 DecodeDetectorLayersvUpgrade(mod,lay,lad,det);
947 /*printf("AliITSInitGeometryUpg::RecodeDetectorv11:"
948 "mod=%d lay=%d lad=%d det=%d cpn0=%d cpn1=%d cpn2=%d\n",
949 mod,lay,lad,det,cpn0,cpn1,cpn2);*/
952 //______________________________________________________________________
953 void AliITSInitGeometryUpg::DecodeDetectorLayersv11(Int_t mod,Int_t &lay,
954 Int_t &lad,Int_t &det) {
956 // decode module number into detector indices for v11
958 // lay, lad, det start from 1
961 // Int_t mod The module number associated with this set
964 // Int_t lay The layer number
965 // Int_t lad The ladder number
966 // Int_t det the dettector number
968 const Int_t kDetPerLadder[6] = {4,4,6,8,22,25};
969 const Int_t kLadPerLayer[6] = {20,40,14,22,34,38};
975 mod2 += kLadPerLayer[lay]*kDetPerLadder[lay];
977 } while(mod2<=mod); // end while
978 if(lay>6) Error("DecodeDetectorLayers","lay=%d>6",lay);
980 mod2 = kLadPerLayer[lay-1]*kDetPerLadder[lay-1] - mod2+mod;
981 lad = mod2/kDetPerLadder[lay-1];
983 if(lad>=kLadPerLayer[lay-1]||lad<0) Error("DecodeDetectorLayers",
984 "lad=%d not in the correct range",lad);
985 det = (mod2 - lad*kDetPerLadder[lay-1])+1;
986 if(det>kDetPerLadder[lay-1]||det<1) Error("DecodeDetectorLayers",
987 "det=%d not in the correct range",det);
991 //______________________________________________________________________
992 void AliITSInitGeometryUpg::DecodeDetectorLayersvUpgrade(Int_t mod,Int_t &lay,
993 Int_t &lad,Int_t &det){
995 // decode module number into detector indices for vUpgrade
997 // lay, lad, det start from 1
1000 // Int_t mod The module number associated with this set
1003 // Int_t lay The layer number
1004 // Int_t lad The ladder number
1005 // Int_t det the dettector number
1008 const Int_t kLayers = GetNumberOfLayers();
1014 mod2 += GetNumberOfLadders(lay)*GetNumberOfModules(lay);
1016 } while(mod2<=mod); // end while
1017 if(lay>kLayers) Error("DecodeDetectorLayers","lay=%d>%d",lay,kLayers);
1019 mod2 = GetNumberOfLadders(lay-1)*GetNumberOfModules(lay-1) - mod2+mod;
1020 lad = mod2/GetNumberOfModules(lay-1);
1022 if(lad>=GetNumberOfLadders(lay-1)||lad<0) Error("DecodeDetectorLayers",
1023 "lad=%d not in the correct range",lad);
1024 det = (mod2 - lad*GetNumberOfModules(lay-1))+1;
1025 if(det>GetNumberOfModules(lay-1)||det<1) Error("DecodeDetectorLayers",
1027 "det=%d not in the correct range",det);
1032 //______________________________________________________________________
1033 Bool_t AliITSInitGeometryUpg::WriteVersionString(Char_t *str,Int_t length,
1034 AliITSVersion_t maj,Int_t min,
1035 const Char_t *cvsDate,const Char_t *cvsRevision)const{
1036 // fills the string str with the major and minor version number
1038 // Char_t *str The character string to hold the major
1039 // and minor version numbers in
1040 // Int_t length The maximum number of characters which
1041 // can be accomidated by this string.
1042 // str[length-1] must exist and will be set to zero
1043 // AliITSVersion_t maj The major number
1044 // Int_t min The minor number
1045 // Char_t *cvsDate The date string from cvs
1046 // Char_t *cvsRevision The Revision string from cvs
1048 // Char_t *str The character string holding the major and minor
1049 // version numbers. str[length-1] must exist
1050 // and will be set to zero
1052 // kTRUE if no errors
1053 Char_t cvslikedate[30];
1054 Int_t i,n,cvsDateLength,cvsRevisionLength;
1056 cvsDateLength = (Int_t)strlen(cvsDate);
1057 if(cvsDateLength>30){ // svn string, make a cvs like string
1060 cvslikedate[i] = cvsDate[i];
1061 if(cvsDate[i]=='+' || cvsDate[i++]=='-'){
1062 n++; // count number of -
1063 cvslikedate[i-1] = '/'; // replace -'s by /'s.
1065 } while(n<3&&i<30); // once additonal - of time zone reach exit
1066 cvslikedate[i-1] = '$'; // put $ at end then zero.
1067 for(;i<30;i++) cvslikedate[i]=0;// i starts wher do loop left off.
1069 for(i=0;i<cvsDateLength&&i<30;i++) cvslikedate[i]=cvsDate[i];
1071 cvsDateLength = (Int_t)strlen(cvslikedate);
1072 cvsRevisionLength = (Int_t)strlen(cvsRevision);
1074 n = 50+(Int_t)(TMath::Log10(TMath::Abs((Double_t)i)))+1+
1075 (Int_t)(TMath::Log10(TMath::Abs((Double_t)min)))+1
1076 +cvsDateLength-6+cvsRevisionLength-10;
1077 if(GetDebug()>1) printf("AliITSInitGeometryUpg::WriteVersionString:"
1078 "length=%d major=%d minor=%d cvsDate=%s[%d] "
1079 "cvsRevision=%s[%d] n=%d\n",length,i,min,cvslikedate,
1080 cvsDateLength,cvsRevision,cvsRevisionLength,n);
1083 if(length<n){// not enough space to write in output string.
1084 Warning("WriteVersionString","Output string not long enough "
1085 "lenght=%d must be at least %d long\n",length,n);
1087 } // end if length<n
1088 char *cvsrevision = new char[cvsRevisionLength-10];
1089 char *cvsdate = new char[cvsDateLength-6];
1090 for(i=0;i<cvsRevisionLength-10;i++)
1091 if(10+i<cvsRevisionLength-1)
1092 cvsrevision[i] = cvsRevision[10+i]; else cvsrevision[i] = 0;
1093 for(i=0;i<cvsDateLength-6;i++) if(6+i<cvsDateLength-1)
1094 cvsdate[i] = cvslikedate[6+i]; else cvsdate[i] = 0;
1095 for(i=0;i<length;i++) str[i] = 0; // zero it out for now.
1097 snprintf(str,length-1,"Major Version= %d Minor Version= %d Revision: %s Date: %s",i,min,cvsrevision,cvsdate);
1098 /* this gives compilation warnings on some compilers: descriptor zu
1099 if(GetDebug()>1)printf("AliITSInitGeometryUpg::WriteVersionString: "
1100 "n=%d str=%s revision[%zu] date[%zu]\n",
1101 n,str,strlen(cvsrevision),strlen(cvsdate));
1103 delete[] cvsrevision;
1107 //______________________________________________________________________
1108 Bool_t AliITSInitGeometryUpg::ReadVersionString(const Char_t *str,Int_t length,
1109 AliITSVersion_t &maj,Int_t &min,
1111 // fills the string str with the major and minor version number
1113 // Char_t *str The character string to holding the major and minor
1114 // version numbers in
1115 // Int_t length The maximum number of characters which can be
1116 // accomidated by this string. str[length-1] must exist
1118 // Char_t *str The character string holding the major and minor
1119 // version numbers unchanged. str[length-1] must exist.
1120 // AliITSVersion_t maj The major number
1121 // Int_t min The minor number
1122 // TDatime dt The date and time of the cvs commit
1124 // kTRUE if no errors
1126 Char_t cvsRevision[10],cvsDate[11],cvsTime[9];
1127 Int_t i,m,n=strlen(str),year,month,day,hours,minuits,seconds;
1128 memset(cvsRevision,0,10*sizeof(Char_t));
1129 memset(cvsDate,0,11*sizeof(Char_t));
1130 memset(cvsTime,0,9*sizeof(Char_t));
1132 if(GetDebug()>1)printf("AliITSInitGeometryUpg::ReadVersionString:"
1133 "str=%s length=%d\n",
1135 if(n<35) return kFALSE; // not enough space for numbers
1136 m = sscanf(str,"Major Version= %d Minor Version= %d Revision: %9s "
1137 "Date: %10s %8s",&i,&min,cvsRevision,cvsDate,cvsTime);
1140 m = sscanf(cvsDate,"%d/%d/%d",&year,&month,&day);
1143 m = sscanf(cvsTime,"%d:%d:%d",&hours,&minuits,&seconds);
1146 dt.Set(year,month,day,hours,minuits,seconds);
1147 if(GetDebug()>1)printf("AliITSInitGeometryUpg::ReadVersionString: i=%d "
1148 "min=%d cvsRevision=%s cvsDate=%s cvsTime=%s m=%d\n",
1149 i,min,cvsRevision,cvsDate,cvsTime,m);
1150 if(GetDebug()>1)printf("AliITSInitGeometryUpg::ReadVersionString: year=%d"
1151 " month=%d day=%d hours=%d minuits=%d seconds=%d\n",
1152 year,month,day,hours,minuits,seconds);
1166 //______________________________________________________________________
1167 Int_t AliITSInitGeometryUpg::GetNumberOfLayers(){
1168 // Determines the number of layers in the Upgrade Geometry
1175 // the number of layers in the current geometry
1176 // -1 if not Upgrade Geometry
1179 Int_t numberOfLayers = 0;
1181 if (fMajorVersion != kvUpgrade) {
1182 AliError("Not Upgrade Geometry!");
1186 // This checks should be redundant, but let's do things neatly
1188 AliError("gGeoManager is null");
1192 if (!gGeoManager->GetVolume(AliITSgeomTGeoUpg::GetITSVolPattern())) {
1193 AliError(Form("can't find %s volume",AliITSgeomTGeoUpg::GetITSVolPattern()));
1197 // Loop on all ITSV nodes, count Layer volumes by checking names
1198 Int_t nNodes = gGeoManager->GetVolume(AliITSgeomTGeoUpg::GetITSVolPattern())->GetNodes()->GetEntries();
1203 for (Int_t j=0; j<nNodes; j++)
1204 if (strstr(gGeoManager->GetVolume(AliITSgeomTGeoUpg::GetITSVolPattern())->GetNodes()->At(j)->GetName(),
1205 AliITSgeomTGeoUpg::GetITSLayerPattern()))
1209 return numberOfLayers;
1212 //______________________________________________________________________
1213 Int_t AliITSInitGeometryUpg::GetNumberOfLadders(const Int_t lay) const {
1214 // Determines the number of layers in the Upgrade Geometry
1217 // lay: layer number
1221 // the number of ladders in layer lay
1222 // -1 if not Upgrade Geometry
1225 Int_t numberOfLadders = 0;
1227 if (fMajorVersion != kvUpgrade) {
1228 AliError("Not Upgrade Geometry!");
1232 // This checks should be redundant, but let's do things neatly
1234 AliError("gGeoManager is null");
1239 snprintf(laynam, 15, "%s%d", AliITSgeomTGeoUpg::GetITSLayerPattern(),lay+1);
1240 if (!gGeoManager->GetVolume(laynam)) {
1241 AliError(Form("can't find %s volume",laynam));
1245 // Loop on all layer nodes, count Ladder volumes by checking names
1246 Int_t nNodes = gGeoManager->GetVolume(laynam)->GetNodes()->GetEntries();
1251 for (Int_t j=0; j<nNodes; j++)
1252 if (strstr(gGeoManager->GetVolume(laynam)->GetNodes()->At(j)->GetName(),
1253 AliITSgeomTGeoUpg::GetITSLadderPattern()))
1257 return numberOfLadders;
1260 //______________________________________________________________________
1261 Int_t AliITSInitGeometryUpg::GetLayerDetTypeID(const Int_t lay) const
1263 // Determines the layers det. type in the Upgrade Geometry
1266 // lay: layer number
1271 // -1 if not Upgrade Geometry
1274 if (fMajorVersion != kvUpgrade) {
1275 AliError("Not Upgrade Geometry!");
1279 // This checks should be redundant, but let's do things neatly
1281 AliError("gGeoManager is null");
1286 snprintf(laynam, 15, "%s%d", AliITSgeomTGeoUpg::GetITSLayerPattern(),lay+1);
1287 TGeoVolume* volLr = gGeoManager->GetVolume(laynam);
1289 AliError(Form("can't find %s volume",laynam));
1293 return volLr->GetUniqueID();
1297 //______________________________________________________________________
1298 Int_t AliITSInitGeometryUpg::GetNumberOfModules(const Int_t lay) const {
1299 // Determines the number of layers in the Upgrade Geometry
1302 // lay: layer number
1306 // the number of modules per ladder in layer lay
1307 // -1 if not Upgrade Geometry
1310 Int_t numberOfModules = 0;
1312 if (fMajorVersion != kvUpgrade) {
1313 AliError("Not Upgrade Geometry!");
1317 // This checks should be redundant, but let's do things neatly
1319 AliError("gGeoManager is null");
1324 snprintf(laddnam, 15, "%s%d", AliITSgeomTGeoUpg::GetITSLadderPattern(),lay+1);
1325 if (!gGeoManager->GetVolume(laddnam)) {
1326 AliError(Form("can't find %s volume",laddnam));
1330 // Loop on all ladder nodes, count Module volumes by checking names
1331 Int_t nNodes = gGeoManager->GetVolume(laddnam)->GetNodes()->GetEntries();
1336 for (Int_t j=0; j<nNodes; j++)
1337 if (strstr(gGeoManager->GetVolume(laddnam)->GetNodes()->At(j)->GetName(),
1338 AliITSgeomTGeoUpg::GetITSModulePattern()))
1342 return numberOfModules;