]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSInitGeometry.cxx
Update of the ITS version number
[u/mrichter/AliRoot.git] / ITS / AliITSInitGeometry.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Id$
18 */
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 ///////////////////////////////////////////////////////////////
25
26 #include <TArrayD.h>
27 #include <TArrayF.h>
28 #include <TStopwatch.h>
29 #include <TGeoManager.h>
30 #include <TGeoMatrix.h>
31 #include <TGeoVolume.h>
32 #include <TGeoShape.h>
33 #include <TGeoBBox.h>
34 #include <TGeoTrd1.h>
35 #include <TGeoTrd2.h>
36 #include <TGeoArb8.h>
37 #include <TGeoTube.h>
38 #include <TGeoCone.h>
39 #include <TGeoSphere.h>
40 #include <TGeoPara.h>
41 #include <TGeoPgon.h>
42 #include <TGeoPcon.h>
43 #include <TGeoEltu.h>
44 #include <TGeoHype.h>
45 #include <TMath.h>
46
47 #include "AliLog.h"
48 #include "AliITSsegmentationSPD.h"
49 #include "AliITSsegmentationSDD.h"
50 #include "AliITSsegmentationSSD.h"
51 #include "AliITSInitGeometry.h"
52 #include <TDatime.h>
53
54 ClassImp(AliITSInitGeometry)
55
56 //______________________________________________________________________
57 AliITSInitGeometry::AliITSInitGeometry():
58 TObject(),                   // Base Class
59 fName(0),                    // Geometry name
60 fMajorVersion(kvDefault),    // Major versin number
61 fTiming(kFALSE),             // Flag to start inilization timing
62 fSegGeom(kFALSE),            // Flag to switch between the old use of
63                              // AliITSgeomS?D class, or AliITSsegmentation
64                              // class in fShape of AliITSgeom class.
65 fDecode(kFALSE),             // Flag for new/old decoding
66 fDebug(0){                   // Debug flag
67     // Default Creator
68     // Inputs:
69     //   none.
70     // Outputs:
71     //   none.
72     // Return:
73     //   A default inilized AliITSInitGeometry object
74
75     fName = "Undefined";
76 }
77 //______________________________________________________________________
78 AliITSInitGeometry::AliITSInitGeometry(AliITSVersion_t version):
79 TObject(),                   // Base Class
80 fName(0),                    // Geometry name
81 fMajorVersion(version),      // Major version number
82 fTiming(kFALSE),             // Flag to start inilization timing
83 fSegGeom(kFALSE),            // Flag to switch between the old use of
84                              // AliITSgeomS?D class, or AliITSsegmentation
85                              // class in fShape of AliITSgeom class.
86 fDecode(kFALSE),             // Flag for new/old decoding
87 fDebug(0){                   // Debug flag
88     // Default Creator
89     // Inputs:
90     //   none.
91     // Outputs:
92     //   none.
93     // Return:
94     //   A default inilized AliITSInitGeometry object
95
96   switch (version) {
97     case kv11:
98         fName="AliITSv11";
99         break;
100     case kvDefault:
101     default:
102         AliFatal(Form("Undefined geometry: fMajorVersion=%d, ",(Int_t)fMajorVersion));
103         fName = "Undefined";
104         break;
105     } // switch
106 }
107 //______________________________________________________________________
108 AliITSgeom* AliITSInitGeometry::CreateAliITSgeom(){
109     // Creates and Initilizes the geometry transformation class AliITSgeom
110     // to values appropreate to this specific geometry. Now that
111     // the segmentation is part of AliITSgeom, the detector
112     // segmentations are also defined here.
113     // Inputs:
114     //   none.
115     // Outputs:
116     //   none.
117     // Return:
118     //   A pointer to a new properly inilized AliITSgeom class. If
119     //   pointer = 0 then failed to init.
120
121
122   AliITSVersion_t version = kvDefault;
123   Int_t minor = 0;
124   TDatime datetime;
125   TGeoVolume *itsV = gGeoManager->GetVolume("ITSV");
126   if(!itsV){
127     AliError("Can't find ITS volume ITSV, exiting - nothing done!");
128     return 0;
129   }// end if
130   const Char_t *title = itsV->GetTitle();
131   if(!ReadVersionString(title,version))
132     Warning("UpdateInternalGeometry","Can't read title=%s\n",title);
133   SetTiming(kFALSE);
134   SetSegGeom(kFALSE);
135   SetDecoding(kFALSE);
136   AliITSgeom *geom = CreateAliITSgeom(version);
137   AliDebug(1,"AliITSgeom object has been initialized from TGeo\n");
138   return geom;
139 }
140 //______________________________________________________________________
141 AliITSgeom* AliITSInitGeometry::CreateAliITSgeom(Int_t major){
142     // Creates and Initilizes the geometry transformation class AliITSgeom
143     // to values appropreate to this specific geometry. Now that
144     // the segmentation is part of AliITSgeom, the detector
145     // segmentations are also defined here.
146     // Inputs:
147     //   Int_t major   major version, see AliITSVersion_t
148     //   
149     // Outputs:
150     //   none.
151     // Return:
152     //   A pointer to a new properly inilized AliITSgeom class. If
153     //   pointer = 0 then failed to init.
154
155     switch(major){
156     case kv11:
157         SetGeometryName("AliITSv11");
158         SetVersion(kv11);
159         break;
160     case kvDefault:
161     default:
162         SetGeometryName("Undefined");
163         SetVersion(kvDefault);
164         break;
165     } // end switch
166     AliITSgeom *geom = new AliITSgeom();
167     if(!InitAliITSgeom(geom)){ // Error initilization failed
168         delete geom;
169         geom = 0;
170     } // end if
171     return geom;
172 }
173 //______________________________________________________________________
174 Bool_t AliITSInitGeometry::InitAliITSgeom(AliITSgeom *geom){
175   // Initilizes the geometry transformation class AliITSgeom
176   // to values appropreate to this specific geometry. Now that
177   // the segmentation is part of AliITSgeom, the detector
178   // segmentations are also defined here.
179   // Inputs:
180   //   AliITSgeom *geom  A pointer to the AliITSgeom class
181   // Outputs:
182   //   AliITSgeom *geom  This pointer recreated and properly inilized.
183   // Return:
184   //   none.
185
186     if(!gGeoManager){
187         AliFatal("The geometry manager has not been initialized (e.g. "
188                  "TGeoManager::Import(\"geometry.root\")should be "
189                  "called in advance) - exit forced");
190         return kFALSE;
191     } // end if
192     switch(fMajorVersion) {
193     case kv11: {
194         return InitAliITSgeomV11(geom);
195     } break; // end case
196     case kvDefault: default: {
197         AliFatal("Undefined geometry");
198         return kFALSE;
199     } break; // end case
200     } // end switch
201     return kFALSE;
202 }
203 //______________________________________________________________________
204 void AliITSInitGeometry::TransposeTGeoHMatrix(TGeoHMatrix *m)const{
205     // Transpose the rotation matrix part of a TGeoHMatrix. This
206     // is needed because TGeo stores the transpose of the rotation
207     // matrix as compared to what AliITSgeomMatrix uses (and Geant3).
208     // Inputs:
209     //    TGeoHMatrix *m  The matrix to be transposed
210     // Outputs:
211     //    TGEoHMatrix *m  The transposed matrix
212     // Return:
213     //    none.
214     Int_t i;
215     Double_t r[9];
216
217     if(m==0) return; // no matrix to transpose.
218     for(i=0;i<9;i += 4) r[i] = m->GetRotationMatrix()[i]; // diagonals
219     r[1] = m->GetRotationMatrix()[3];
220     r[2] = m->GetRotationMatrix()[6];
221     r[3] = m->GetRotationMatrix()[1];
222     r[5] = m->GetRotationMatrix()[7];
223     r[6] = m->GetRotationMatrix()[2];
224     r[7] = m->GetRotationMatrix()[5];
225     m->SetRotation(r);
226     return;
227 }
228
229
230 //______________________________________________________________________
231 Bool_t AliITSInitGeometry::InitAliITSgeomV11(AliITSgeom *geom){
232   // Initilizes the geometry transformation class AliITSgeom
233   // Now that the segmentation is part of AliITSgeom, the detector
234   // segmentations are also defined here.
235   //
236   // Inputs:
237   //   AliITSgeom *geom  A pointer to the AliITSgeom class
238   // Outputs:
239   //   AliITSgeom *geom  This pointer recreated and properly inilized.
240   // LG
241
242   const Int_t kItype  = 0; // Type of transformation defined 0=> Geant
243   const Int_t klayers = 6; // number of layers in the ITS
244   const Int_t kladders[klayers]   = {20,40,14,22,34,38}; // Number of ladders
245   const Int_t kdetectors[klayers] = {4,4,6,8,22,25};// number of detector/lad
246   const AliITSDetector kIdet[6]   = {kSPD,kSPD,kSDD,kSDD,kSSD,kSSD};
247   const TString kPathbase = "/ALIC_1/ITSV_1/";
248
249   const char *pathSPDsens1, *pathSPDsens2;
250   pathSPDsens1="%sITSSPD_1/ITSSPDCarbonFiberSectorV_%d/ITSSPDSensitiveVirtualvolumeM0_1/ITSSPDlay1-Stave_%d/ITSSPDhalf-Stave%d_1/ITSSPDlay1-Ladder_%d/ITSSPDlay1-sensor_1";
251   pathSPDsens2="%sITSSPD_1/ITSSPDCarbonFiberSectorV_%d/ITSSPDSensitiveVirtualvolumeM0_1/ITSSPDlay2-Stave_%d/ITSSPDhalf-Stave%d_1/ITSSPDlay2-Ladder_%d/ITSSPDlay2-sensor_1";
252
253   const char *pathSDDsens1, *pathSDDsens2;
254   pathSDDsens1 = "%sITSsddLayer3_1/ITSsddLadd_%d/ITSsddSensor3_%d/ITSsddWafer3_%d/ITSsddSensitivL3_1";
255   pathSDDsens2 = "%sITSsddLayer4_1/ITSsddLadd_%d/ITSsddSensor4_%d/ITSsddWafer4_%d/ITSsddSensitivL4_1";
256
257   const char *pathSSDsens1, *pathSSDsens2;
258   pathSSDsens1 = "%sITSssdLayer5_1/ITSssdLay5Ladd_%d/ITSssdSensor5_%d/ITSssdSensitivL5_1";
259   pathSSDsens2 = "%sITSssdLayer6_1/ITSssdLay6Ladd_%d/ITSssdSensor6_%d/ITSssdSensitivL6_1";
260
261   const TString kNames[klayers] = {
262     pathSPDsens1, // lay=1
263     pathSPDsens2, // lay=2
264     pathSDDsens1, // lay=3
265     pathSDDsens2, // lay=4
266     pathSSDsens1, // lay=5
267     pathSSDsens2};// Lay=6
268   
269   Int_t mod,nmods=0, lay, lad, det, cpn0, cpn1, cpn2, cpnHS=1;
270   Double_t tran[3]={0.,0.,0.}, rot[10]={9*0.0,1.0};
271   TArrayD shapePar;
272   TString path, shapeName;
273   TGeoHMatrix matrix;
274   Bool_t initSeg[3]={kFALSE, kFALSE, kFALSE};
275   TStopwatch *time = 0x0;
276   if(fTiming) time = new TStopwatch();
277
278   if(fTiming) time->Start();
279   for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
280   geom->Init(kItype,klayers,kladders,kdetectors,nmods);
281
282   for(mod=0; mod<nmods; mod++) {
283
284     DecodeDetectorLayers(mod,lay,lad,det);
285     geom->CreateMatrix(mod,lay,lad,det,kIdet[lay-1],tran,rot);
286     RecodeDetector(mod,cpn0,cpn1,cpn2);
287
288     if (kIdet[lay-1]==kSPD) { // we need 1 more copy number because of the half-stave
289       if (det<3) cpnHS = 0; else cpnHS = 1;
290       path.Form(kNames[lay-1].Data(),kPathbase.Data(),cpn0,cpn1,cpnHS,cpn2);
291     } else {
292       path.Form(kNames[lay-1].Data(),kPathbase.Data(),cpn0,cpn1,cpn2);
293     };
294
295     geom->GetGeomMatrix(mod)->SetPath(path);
296     GetTransformation(path.Data(),matrix);
297     geom->SetTrans(mod,matrix.GetTranslation());
298     TransposeTGeoHMatrix(&matrix); //Transpose TGeo's rotation matrixes
299     geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
300     if(initSeg[kIdet[lay-1]]) continue;
301     GetShape(path,shapeName,shapePar);
302     if(shapeName.CompareTo("BOX")){
303       Error("InitITSgeom","Geometry changed without proper code update"
304             "or error in reading geometry. Shape is not BOX.");
305       return kFALSE;
306     } // end if
307   } // end for module
308
309   if(fTiming){
310     time->Stop();
311     time->Print();
312     delete time;
313   } // end if
314   return kTRUE;
315 }
316
317 //_______________________________________________________________________
318 Bool_t AliITSInitGeometry::GetTransformation(const TString &volumePath,
319                                              TGeoHMatrix &mat){
320     // Returns the Transformation matrix between the volume specified
321     // by the path volumePath and the Top or mater volume. The format
322     // of the path volumePath is as follows (assuming ALIC is the Top volume)
323     // "/ALIC_1/DDIP_1/S05I_2/S05H_1/S05G_3". Here ALIC is the top most
324     // or master volume which has only 1 instance of. Of all of the daughter
325     // volumes of ALICE, DDIP volume copy #1 is indicated. Similarly for
326     // the daughter volume of DDIP is S05I copy #2 and so on.
327     // Inputs:
328     //   TString& volumePath  The volume path to the specific volume
329     //                        for which you want the matrix. Volume name
330     //                        hierarchy is separated by "/" while the
331     //                        copy number is appended using a "_".
332     // Outputs:
333     //  TGeoHMatrix &mat      A matrix with its values set to those
334     //                        appropriate to the Local to Master transformation
335     // Return:
336     //   A logical value if kFALSE then an error occurred and no change to
337     //   mat was made.
338
339     // We have to preserve the modeler state
340
341     // Preserve the modeler state.
342     gGeoManager->PushPath();
343     if (!gGeoManager->cd(volumePath.Data())) {
344       gGeoManager->PopPath();
345       Error("GetTransformation","Error in cd-ing to %s",volumePath.Data());
346       return kFALSE;
347     } // end if !gGeoManager
348     mat = *gGeoManager->GetCurrentMatrix();
349     // Retstore the modeler state.
350     gGeoManager->PopPath();
351     return kTRUE;
352 }
353 //______________________________________________________________________
354 Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
355                                     TString &shapeType,TArrayD &par){
356     // Returns the shape and its parameters for the volume specified
357     // by volumeName.
358     // Inputs:
359     //   TString& volumeName  The volume name
360     // Outputs:
361     //   TString &shapeType   Shape type
362     //   TArrayD &par         A TArrayD of parameters with all of the
363     //                        parameters of the specified shape.
364     // Return:
365     //   A logical indicating whether there was an error in getting this
366     //   information
367     Int_t npar;
368     gGeoManager->PushPath();
369     if (!gGeoManager->cd(volumePath.Data())) {
370         gGeoManager->PopPath();
371         return kFALSE;
372     }
373     TGeoVolume * vol = gGeoManager->GetCurrentVolume();
374     gGeoManager->PopPath();
375     if (!vol) return kFALSE;
376     TGeoShape *shape = vol->GetShape();
377     TClass *classType = shape->IsA();
378     if (classType==TGeoBBox::Class()) {
379         shapeType = "BOX";
380         npar = 3;
381         par.Set(npar);
382         TGeoBBox *box = (TGeoBBox*)shape;
383         par.AddAt(box->GetDX(),0);
384         par.AddAt(box->GetDY(),1);
385         par.AddAt(box->GetDZ(),2);
386         return kTRUE;
387     } // end if
388     if (classType==TGeoTrd1::Class()) {
389         shapeType = "TRD1";
390         npar = 4;
391         par.Set(npar);
392         TGeoTrd1 *trd1 = (TGeoTrd1*)shape;
393         par.AddAt(trd1->GetDx1(),0);
394         par.AddAt(trd1->GetDx2(),1);
395         par.AddAt(trd1->GetDy(), 2);
396         par.AddAt(trd1->GetDz(), 3);
397         return kTRUE;
398     } // end if
399     if (classType==TGeoTrd2::Class()) {
400         shapeType = "TRD2";
401         npar = 5;
402         par.Set(npar);
403         TGeoTrd2 *trd2 = (TGeoTrd2*)shape;
404         par.AddAt(trd2->GetDx1(),0);
405         par.AddAt(trd2->GetDx2(),1);
406         par.AddAt(trd2->GetDy1(),2);
407         par.AddAt(trd2->GetDy2(),3);
408         par.AddAt(trd2->GetDz(), 4);
409         return kTRUE;
410     } // end if
411     if (classType==TGeoTrap::Class()) {
412         shapeType = "TRAP";
413         npar = 11;
414         par.Set(npar);
415         TGeoTrap *trap = (TGeoTrap*)shape;
416         Double_t tth = TMath::Tan(trap->GetTheta()*TMath::DegToRad());
417         par.AddAt(trap->GetDz(),0);
418         par.AddAt(tth*TMath::Cos(trap->GetPhi()*TMath::DegToRad()),1);
419         par.AddAt(tth*TMath::Sin(trap->GetPhi()*TMath::DegToRad()),2);
420         par.AddAt(trap->GetH1(),3);
421         par.AddAt(trap->GetBl1(),4);
422         par.AddAt(trap->GetTl1(),5);
423         par.AddAt(TMath::Tan(trap->GetAlpha1()*TMath::DegToRad()),6);
424         par.AddAt(trap->GetH2(),7);
425         par.AddAt(trap->GetBl2(),8);
426         par.AddAt(trap->GetTl2(),9);
427         par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
428         return kTRUE;
429     } // end if
430     if (classType==TGeoTube::Class()) {
431         shapeType = "TUBE";
432         npar = 3;
433         par.Set(npar);
434         TGeoTube *tube = (TGeoTube*)shape;
435         par.AddAt(tube->GetRmin(),0);
436         par.AddAt(tube->GetRmax(),1);
437         par.AddAt(tube->GetDz(),2);
438         return kTRUE;
439     } // end if
440     if (classType==TGeoTubeSeg::Class()) {
441         shapeType = "TUBS";
442         npar = 5;
443         par.Set(npar);
444         TGeoTubeSeg *tubs = (TGeoTubeSeg*)shape;
445         par.AddAt(tubs->GetRmin(),0);
446         par.AddAt(tubs->GetRmax(),1);
447         par.AddAt(tubs->GetDz(),2);
448         par.AddAt(tubs->GetPhi1(),3);
449         par.AddAt(tubs->GetPhi2(),4);
450         return kTRUE;
451     } // end if
452     if (classType==TGeoCone::Class()) {
453         shapeType = "CONE";
454         npar = 5;
455         par.Set(npar);
456         TGeoCone *cone = (TGeoCone*)shape;
457         par.AddAt(cone->GetDz(),0);
458         par.AddAt(cone->GetRmin1(),1);
459         par.AddAt(cone->GetRmax1(),2);
460         par.AddAt(cone->GetRmin2(),3);
461         par.AddAt(cone->GetRmax2(),4);
462         return kTRUE;
463     } // end if
464     if (classType==TGeoConeSeg::Class()) {
465         shapeType = "CONS";
466         npar = 7;
467         par.Set(npar);
468         TGeoConeSeg *cons = (TGeoConeSeg*)shape;
469         par.AddAt(cons->GetDz(),0);
470         par.AddAt(cons->GetRmin1(),1);
471         par.AddAt(cons->GetRmax1(),2);
472         par.AddAt(cons->GetRmin2(),3);
473         par.AddAt(cons->GetRmax2(),4);
474         par.AddAt(cons->GetPhi1(),5);
475         par.AddAt(cons->GetPhi2(),6);
476         return kTRUE;
477     } // end if
478     if (classType==TGeoSphere::Class()) {
479         shapeType = "SPHE";
480         npar = 6;
481         par.Set(npar);
482         
483         TGeoSphere *sphe = (TGeoSphere*)shape;
484         par.AddAt(sphe->GetRmin(),0);
485         par.AddAt(sphe->GetRmax(),1);
486         par.AddAt(sphe->GetTheta1(),2);
487         par.AddAt(sphe->GetTheta2(),3);
488         par.AddAt(sphe->GetPhi1(),4);
489         par.AddAt(sphe->GetPhi2(),5);
490         return kTRUE;
491     } // end if
492     if (classType==TGeoPara::Class()) {
493         shapeType = "PARA";
494         npar = 6;
495         par.Set(npar);
496         TGeoPara *para = (TGeoPara*)shape;
497         par.AddAt(para->GetX(),0);
498         par.AddAt(para->GetY(),1);
499         par.AddAt(para->GetZ(),2);
500         par.AddAt(para->GetTxy(),3);
501         par.AddAt(para->GetTxz(),4);
502         par.AddAt(para->GetTyz(),5);
503         return kTRUE;
504     } // end if
505     if (classType==TGeoPgon::Class()) {
506         shapeType = "PGON";
507         TGeoPgon *pgon = (TGeoPgon*)shape;
508         Int_t nz = pgon->GetNz();
509         const Double_t *rmin = pgon->GetRmin();
510         const Double_t *rmax = pgon->GetRmax();
511         const Double_t *z = pgon->GetZ();
512         npar = 4 + 3*nz;
513         par.Set(npar);
514         par.AddAt(pgon->GetPhi1(),0);
515         par.AddAt(pgon->GetDphi(),1);
516         par.AddAt(pgon->GetNedges(),2);
517         par.AddAt(pgon->GetNz(),3);
518         for (Int_t i=0; i<nz; i++) {
519             par.AddAt(z[i], 4+3*i);
520             par.AddAt(rmin[i], 4+3*i+1);
521             par.AddAt(rmax[i], 4+3*i+2);
522         }
523         return kTRUE;
524     } // end if
525     if (classType==TGeoPcon::Class()) {
526         shapeType = "PCON";
527         TGeoPcon *pcon = (TGeoPcon*)shape;
528         Int_t nz = pcon->GetNz();
529         const Double_t *rmin = pcon->GetRmin();
530         const Double_t *rmax = pcon->GetRmax();
531         const Double_t *z = pcon->GetZ();
532         npar = 3 + 3*nz;
533         par.Set(npar);
534         par.AddAt(pcon->GetPhi1(),0);
535         par.AddAt(pcon->GetDphi(),1);
536         par.AddAt(pcon->GetNz(),2);
537         for (Int_t i=0; i<nz; i++) {
538             par.AddAt(z[i], 3+3*i);
539             
540             par.AddAt(rmin[i], 3+3*i+1);
541             par.AddAt(rmax[i], 3+3*i+2);
542         }
543         return kTRUE;
544     } // end if
545     if (classType==TGeoEltu::Class()) {
546         shapeType = "ELTU";
547         npar = 3;
548         par.Set(npar);
549         TGeoEltu *eltu = (TGeoEltu*)shape;
550         par.AddAt(eltu->GetA(),0);
551         par.AddAt(eltu->GetB(),1);
552         par.AddAt(eltu->GetDz(),2);
553         return kTRUE;
554     } // end if
555     if (classType==TGeoHype::Class()) {
556         shapeType = "HYPE";
557         npar = 5;
558         par.Set(npar);
559         TGeoHype *hype = (TGeoHype*)shape;
560         par.AddAt(TMath::Sqrt(hype->RadiusHypeSq(0.,kTRUE)),0);
561         par.AddAt(TMath::Sqrt(hype->RadiusHypeSq(0.,kFALSE)),1);
562         par.AddAt(hype->GetDZ(),2);
563         par.AddAt(hype->GetStIn(),3);
564         par.AddAt(hype->GetStOut(),4);
565         return kTRUE;
566     } // end if
567     if (classType==TGeoGtra::Class()) {
568         shapeType = "GTRA";
569         npar = 12;
570         par.Set(npar);
571         TGeoGtra *trap = (TGeoGtra*)shape;
572         Double_t tth = TMath::Tan(trap->GetTheta()*TMath::DegToRad());
573         par.AddAt(trap->GetDz(),0);
574         par.AddAt(tth*TMath::Cos(trap->GetPhi()*TMath::DegToRad()),1);
575         par.AddAt(tth*TMath::Sin(trap->GetPhi()*TMath::DegToRad()),2);
576         par.AddAt(trap->GetH1(),3);
577         par.AddAt(trap->GetBl1(),4);
578         par.AddAt(trap->GetTl1(),5);
579         par.AddAt(TMath::Tan(trap->GetAlpha1()*TMath::DegToRad()),6);
580         par.AddAt(trap->GetH2(),7);
581         par.AddAt(trap->GetBl2(),8);
582         par.AddAt(trap->GetTl2(),9);
583         par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
584         par.AddAt(trap->GetTwistAngle(),11);
585         return kTRUE;
586     } // end if
587     if (classType==TGeoCtub::Class()) {
588         shapeType = "CTUB";
589         npar = 11;
590         par.Set(npar);
591         TGeoCtub *ctub = (TGeoCtub*)shape;
592         const Double_t *lx = ctub->GetNlow();
593         const Double_t *tx = ctub->GetNhigh();
594         par.AddAt(ctub->GetRmin(),0);
595         par.AddAt(ctub->GetRmax(),1);
596         par.AddAt(ctub->GetDz(),2);
597         par.AddAt(ctub->GetPhi1(),3);
598         par.AddAt(ctub->GetPhi2(),4);
599         par.AddAt(lx[0],5);
600         par.AddAt(lx[1],6);
601         par.AddAt(lx[2],7);
602         par.AddAt(tx[0],8);
603         par.AddAt(tx[1],9);
604         par.AddAt(tx[2],10);
605         return kTRUE;
606     } // end if
607     Error("GetShape","Getting shape parameters for shape %s not implemented",
608           shape->ClassName());
609     shapeType = "Unknown";
610     return kFALSE;
611 }
612 //______________________________________________________________________
613 void AliITSInitGeometry::DecodeDetector(
614     Int_t &mod,Int_t layer,Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
615     // decode geometry into detector module number. There are two decoding
616     // Scheams. Old which does not follow the ALICE coordinate system
617     // requirements, and New which dose.
618     // Inputs:
619     //    Int_t layer    The ITS layer
620     //    Int_t cpn0     The lowest copy number
621     //    Int_t cpn1     The middle copy number
622     //    Int_t cpn2     the highest copy number
623     // Output:
624     //    Int_t &mod     The module number assoicated with this set
625     //                   of copy numbers.
626     // Return:
627     //    none.
628
629     // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't 
630     // like them but I see not better way for the moment.
631     switch (fMajorVersion){
632     case kvDefault:{
633         Error("DecodeDetector","Major version = kvDefault, not supported");
634     }break;
635     case kv11:{
636         return DecodeDetectorv11(mod,layer,cpn0,cpn1,cpn2);
637     }break;
638     default:{
639         Error("DecodeDetector","Major version = %d, not supported",
640               (Int_t)fMajorVersion);
641         return;
642     }break;
643     } // end switch
644     return;
645 }
646 //______________________________________________________________________
647 void AliITSInitGeometry::RecodeDetector(Int_t mod,Int_t &cpn0,
648                                         Int_t &cpn1,Int_t &cpn2){
649     // decode geometry into detector module number. There are two decoding
650     // Scheams. Old which does not follow the ALICE coordinate system
651     // requirements, and New which dose.
652     // Inputs:
653     //    Int_t mod      The module number assoicated with this set
654     //                   of copy numbers.
655     // Output:
656     //    Int_t cpn0     The lowest copy number
657     //    Int_t cpn1     The middle copy number
658     //    Int_t cpn2     the highest copy number
659     // Return:
660     //    none.
661
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){
665     case kvDefault:{
666         Error("RecodeDetector","Major version = kvDefault, not supported");
667         return;
668     }
669     case kv11:{
670         return RecodeDetectorv11(mod,cpn0,cpn1,cpn2);
671     }break;
672     default:{
673         Error("RecodeDetector","Major version = %d, not supported",
674               (Int_t)fMajorVersion);
675         return;
676     }break;
677     } // end switch
678     return;
679 }
680 //______________________________________________________________________
681 void AliITSInitGeometry::DecodeDetectorLayers(Int_t mod,Int_t &layer,
682                                               Int_t &lad,Int_t &det){
683     // decode geometry into detector module number. There are two decoding
684     // Scheams. Old which does not follow the ALICE coordinate system
685     // requirements, and New which dose. Note, this use of layer ladder
686     // and detector numbers are strictly for internal use of this
687     // specific code. They do not represent the "standard" layer ladder
688     // or detector numbering except in a very old and obsoleate sence.
689     // Inputs:
690     //    Int_t mod      The module number assoicated with this set
691     //                   of copy numbers.
692     // Output:
693     //    Int_t lay     The layer number
694     //    Int_t lad     The ladder number
695     //    Int_t det     the dettector number
696     // Return:
697     //    none.
698
699     // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't 
700     // like them but I see not better way for the moment.
701     switch (fMajorVersion) {
702     case kvDefault:{
703         Error("DecodeDetectorLayers",
704               "Major version = kvDefault, not supported");
705         return;
706     }break;
707     case kv11:{
708         return DecodeDetectorLayersv11(mod,layer,lad,det);
709     }break;
710     default:{
711         Error("DecodeDetectorLayers","Major version = %d, not supported",
712               (Int_t)fMajorVersion);
713         return;
714     }break;
715     } // end switch
716     return;
717 }
718
719 //______________________________________________________________________
720 void AliITSInitGeometry::DecodeDetectorv11(Int_t &mod,Int_t layer,
721                                  Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
722     // decode geometry into detector module number
723     // Inputs:
724     //    Int_t layer    The ITS layer
725     //    Int_t cpn0     The lowest copy number
726     //    Int_t cpn1     The middle copy number
727     //    Int_t cpn2     the highest copy number
728     // Output:
729     //    Int_t &mod     The module number assoicated with this set
730     //                   of copy numbers.
731     // Return:
732     //    none.
733   const Int_t kDetPerLadderSPD[2]={2,4};
734   const Int_t kDetPerLadder[6]={4,4,6,8,22,25};
735   const Int_t kLadPerLayer[6]={20,40,14,22,34,38};
736   Int_t lad=-1,det=-1;
737   
738   switch(layer) {
739   case 1: case 2:{
740     lad = cpn1+kDetPerLadderSPD[layer-1]*(cpn0-1);
741     det = cpn2;
742   } break;
743   case 3: case 4:{
744     lad = cpn0+1;
745     det = cpn1+1;
746   } break;
747   case 5: case 6:{
748     lad = cpn0+1;
749     det = cpn1+1;
750   } break;
751   default:{
752   } break;
753   } // end switch
754   mod = 0;
755   for(Int_t i=0;i<layer-1;i++) mod += kLadPerLayer[i]*kDetPerLadder[i];
756   mod += kDetPerLadder[layer-1]*(lad-1)+det-1;// module start at zero.
757   return;
758 }
759
760
761 //______________________________________________________________________
762 void AliITSInitGeometry::RecodeDetectorv11(Int_t mod,Int_t &cpn0,
763                                            Int_t &cpn1,Int_t &cpn2) {
764     // decode geometry into detector module number using the new decoding
765     // Scheme.
766     // Inputs:
767     //    Int_t mod      The module number assoicated with this set
768     //                   of copy numbers.
769     // Output:
770     //    Int_t cpn0     The lowest copy number  (SPD sector or SDD/SSD ladder)
771     //    Int_t cpn1     The middle copy number  (SPD stave or SDD/SSD module)
772     //    Int_t cpn2     the highest copy number (SPD ladder or 1 for SDD/SSD)
773     // Return:
774     //    none.
775     const Int_t kDetPerLadderSPD[2]={2,4};
776     Int_t lay,lad,det;
777
778     DecodeDetectorLayersv11(mod,lay,lad,det);
779     if (lay<3) { // SPD
780         cpn2 = det;     // Detector 1-4
781         cpn0 = (lad+kDetPerLadderSPD[lay-1]-1)/kDetPerLadderSPD[lay-1];
782         cpn1 = (lad+kDetPerLadderSPD[lay-1]-1)%kDetPerLadderSPD[lay-1] + 1;
783     } else { // SDD and SSD
784         cpn2 = 1;
785         cpn1 = det;
786         cpn0 = lad;
787         if (lay<5) { // SDD
788           cpn1--;
789           cpn0--;
790         } else { //SSD
791           cpn1--;
792           cpn0--;
793         } // end if Lay<5/else
794     } // end if lay<3/else
795
796 }
797
798
799 //______________________________________________________________________
800 void AliITSInitGeometry::DecodeDetectorLayersv11(Int_t mod,Int_t &lay,
801                                                  Int_t &lad,Int_t &det) {
802
803   // decode module number into detector indices for v11
804   // mod starts from 0
805   // lay, lad, det start from 1
806
807   // Inputs:
808   //    Int_t mod      The module number associated with this set
809   //                   of copy numbers.
810   // Output:
811   //    Int_t lay     The layer number
812   //    Int_t lad     The ladder number
813   //    Int_t det     the dettector number
814
815   const Int_t kDetPerLadder[6] = {4,4,6,8,22,25};
816   const Int_t kLadPerLayer[6]  = {20,40,14,22,34,38};
817   
818   Int_t mod2 = 0;
819   lay  = 0;
820   
821   do {
822     mod2 += kLadPerLayer[lay]*kDetPerLadder[lay];
823     lay++;
824   } while(mod2<=mod); // end while
825   if(lay>6) Error("DecodeDetectorLayers","lay=%d>6",lay);
826
827   mod2 = kLadPerLayer[lay-1]*kDetPerLadder[lay-1] - mod2+mod;
828   lad = mod2/kDetPerLadder[lay-1];
829
830   if(lad>=kLadPerLayer[lay-1]||lad<0) Error("DecodeDetectorLayers",
831                                       "lad=%d not in the correct range",lad);
832   det = (mod2 - lad*kDetPerLadder[lay-1])+1;
833   if(det>kDetPerLadder[lay-1]||det<1) Error("DecodeDetectorLayers",
834                                       "det=%d not in the correct range",det);
835   lad++;
836 }
837
838 //______________________________________________________________________
839 Bool_t AliITSInitGeometry::WriteVersionString(Char_t *str,Int_t length,AliITSVersion_t maj)const{
840     // fills the string str with the major version number
841     // Inputs:
842     //   Char_t *str          The character string to hold the major version number
843     //   Int_t  length        The maximum number of characters which 
844     //                        can be accommodated by this string. 
845     //                        str[length-1] must exist
846     //   AliITSVersion_t maj  The major number
847
848
849     Int_t i = (Int_t)maj;
850  
851     snprintf(str,length-1,"Major Version= %d",i);
852     return kTRUE;
853 }
854 //______________________________________________________________________
855 Bool_t AliITSInitGeometry::ReadVersionString(const Char_t *str,AliITSVersion_t &maj)const{
856     // fills the string str with the major and minor version number
857     // Inputs:
858     //   Char_t *str   The character string to holding the major version number
859     //   Int_t  length The maximum number of characters which can be
860     //                 accommodated by this string. str[length-1] must exist
861     // Outputs:
862     //   AliITSVersion_t maj  The major number
863
864     // Return:
865     //   kTRUE if no errors
866
867   Bool_t retcode=kFALSE;
868   Int_t n=strlen(str);
869   if(n<15) return retcode; // not enough space for numbers
870   Int_t m,i;
871   m = sscanf(str,"Major Version= %d",&i);
872   maj = kvDefault;
873   if(m>0){
874     retcode = kTRUE;
875     if(i==11){
876       maj = kv11;
877     }
878   }
879   return retcode;
880 }
881
882