]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSInitGeometry.cxx
4edc0c2c7591c9e086487194bcb7ad0e1951573d
[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 <TGeoVolume.h>
31 #include <TGeoShape.h>
32 #include <TGeoBBox.h>
33 #include <TGeoTrd1.h>
34 #include <TGeoTrd2.h>
35 #include <TGeoArb8.h>
36 #include <TGeoTube.h>
37 #include <TGeoCone.h>
38 #include <TGeoSphere.h>
39 #include <TGeoPara.h>
40 #include <TGeoPgon.h>
41 #include <TGeoPcon.h>
42 #include <TGeoEltu.h>
43 #include <TGeoHype.h>
44 #include <TMath.h>
45
46 #include "AliLog.h"
47 #include "AliITSgeomSPD.h"
48 #include "AliITSgeomSDD.h"
49 #include "AliITSgeomSSD.h"
50 #include "AliITSsegmentationSPD.h"
51 #include "AliITSsegmentationSDD.h"
52 #include "AliITSsegmentationSSD.h"
53 #include "AliITSgeom.h"
54 #include "AliITSInitGeometry.h"
55 #include <TDatime.h>
56
57 ClassImp(AliITSInitGeometry)
58
59 const Bool_t AliITSInitGeometry::fgkOldSPDbarrel = kTRUE;
60 const Bool_t AliITSInitGeometry::fgkOldSDDbarrel = kFALSE;
61 const Bool_t AliITSInitGeometry::fgkOldSSDbarrel = kFALSE;
62 const Bool_t AliITSInitGeometry::fgkOldSDDcone   = kTRUE;
63 const Bool_t AliITSInitGeometry::fgkOldSSDcone   = kTRUE;
64 const Bool_t AliITSInitGeometry::fgkOldSPDshield = kTRUE;
65 const Bool_t AliITSInitGeometry::fgkOldSDDshield = kTRUE;
66 const Bool_t AliITSInitGeometry::fgkOldSSDshield = kTRUE;
67 const Bool_t AliITSInitGeometry::fgkOldServices  = kTRUE;
68 const Bool_t AliITSInitGeometry::fgkOldSupports  = kTRUE;
69 //______________________________________________________________________
70 AliITSInitGeometry::AliITSInitGeometry():
71 TObject(),                   // Base Class
72 fName(0),                    // Geometry name
73 fMinorVersion(-1),           // Minor version number/type
74 fMajorVersion(kvDefault),    // Major versin number
75 fTiming(kFALSE),             // Flag to start inilization timing
76 fSegGeom(kFALSE),            // Flag to switch between the old use of
77                              // AliITSgeomS?D class, or AliITSsegmentation
78                              // class in fShape of AliITSgeom class.
79 fDecode(kFALSE),             // Flag for new/old decoding
80 fDebug(0){                   // Debug flag
81     // Default Creator
82     // Inputs:
83     //   none.
84     // Outputs:
85     //   none.
86     // Return:
87     //   A default inilized AliITSInitGeometry object
88
89     fName = "Undefined";
90 }
91 //______________________________________________________________________
92 AliITSInitGeometry::AliITSInitGeometry(AliITSVersion_t version,
93                                        Int_t minorversion):
94 TObject(),                   // Base Class
95 fName(0),                    // Geometry name
96 fMinorVersion(minorversion), // Minor version number/type
97 fMajorVersion(version),      // Major versin number
98 fTiming(kFALSE),             // Flag to start inilization timing
99 fSegGeom(kFALSE),            // Flag to switch between the old use of
100                              // AliITSgeomS?D class, or AliITSsegmentation
101                              // class in fShape of AliITSgeom class.
102 fDecode(kFALSE),             // Flag for new/old decoding
103 fDebug(0){                   // Debug flag
104     // Default Creator
105     // Inputs:
106     //   none.
107     // Outputs:
108     //   none.
109     // Return:
110     //   A default inilized AliITSInitGeometry object
111
112     if(version == kvPPRasymmFMD && (fMinorVersion==1|| fMinorVersion==2)){
113         fName="AliITSvPPRasymmFMD";
114     }else if(version == kv11Hybrid){
115         fName="AliITSv11Hybrid";
116     }else {
117         AliFatal(Form("Undefined geometry: fMajorVersion=%d, "
118                       "fMinorVersion= %d",(Int_t)fMajorVersion,fMinorVersion));
119         fName = "Undefined";
120     } // end if
121     return;
122 }
123 //______________________________________________________________________
124 AliITSgeom* AliITSInitGeometry::CreateAliITSgeom(){
125     // Creates and Initilizes the geometry transformation class AliITSgeom
126     // to values appropreate to this specific geometry. Now that
127     // the segmentation is part of AliITSgeom, the detector
128     // segmentations are also defined here.
129     // Inputs:
130     //   none.
131     // Outputs:
132     //   none.
133     // Return:
134     //   A pointer to a new properly inilized AliITSgeom class. If
135     //   pointer = 0 then failed to init.
136
137
138   AliITSVersion_t version = kvDefault;
139   Int_t minor = 0;
140   TDatime datetime;
141   TGeoVolume *itsV = gGeoManager->GetVolume("ITSV");
142   if(!itsV){
143     Error("CreateAliITSgeom","Can't find ITS volume ITSV, aborting");
144     return 0;
145   }// end if
146   const Char_t *title = itsV->GetTitle();
147   if(!ReadVersionString(title,(Int_t)strlen(title),version,minor,
148                         datetime))
149     Warning("UpdateInternalGeometry","Can't read title=%s\n",title);
150   SetTiming(kFALSE);
151   SetSegGeom(kFALSE);
152   SetDecoding(kFALSE);
153   AliITSgeom *geom = CreateAliITSgeom(version,minor);
154   AliDebug(1,"AliITSgeom object has been initialized from TGeo\n");
155   return geom;
156 }
157 //______________________________________________________________________
158 AliITSgeom* AliITSInitGeometry::CreateAliITSgeom(Int_t major,Int_t minor){
159     // Creates and Initilizes the geometry transformation class AliITSgeom
160     // to values appropreate to this specific geometry. Now that
161     // the segmentation is part of AliITSgeom, the detector
162     // segmentations are also defined here.
163     // Inputs:
164     //   Int_t major   major version, see AliITSVersion_t
165     //   Int_t minor   minor version
166     // Outputs:
167     //   none.
168     // Return:
169     //   A pointer to a new properly inilized AliITSgeom class. If
170     //   pointer = 0 then failed to init.
171
172     switch(major){
173     case kvtest:
174         SetGeometryName("AliITSvtest");
175         SetVersion(kvtest,minor);
176         break;
177     case kvSPD02:
178         SetGeometryName("AliITSvSPD02");
179         SetVersion(kvSPD02,minor);
180         break;
181     case kvSDD03:
182         SetGeometryName("AliITSvSDD03");
183         SetVersion(kvSDD03,minor);
184         break;
185     case kvSSD03:
186         SetGeometryName("AliITSvSSD03");
187         SetVersion(kvSSD03,minor);
188         break;
189     case kvITS04:
190         SetGeometryName("AliITSvBeamTest03");
191         SetVersion(kvITS04,minor);
192         break;
193     case kvPPRcourseasymm:
194         SetGeometryName("AliITSvPPRcourseasymm");
195         SetVersion(kvPPRcourseasymm,minor);
196         break;
197     case kvPPRasymmFMD:
198         SetGeometryName("AliITSvPPRasymmFMD");
199         SetVersion(kvPPRasymmFMD,minor);
200         break;
201     case kv11:
202         SetGeometryName("AliITSv11");
203         SetVersion(kv11,minor);
204         break;
205     case kv11Hybrid:
206         SetGeometryName("AliITSv11Hybrid");
207         SetVersion(kv11Hybrid,minor);
208         break;
209     case kvDefault:
210     default:
211         SetGeometryName("Undefined");
212         SetVersion(kvDefault,minor);
213         break;
214     } // end switch
215     AliITSgeom *geom = new AliITSgeom();
216     if(!InitAliITSgeom(geom)){ // Error initilization failed
217         delete geom;
218         geom = 0;
219     } // end if
220     return geom;
221 }
222 //______________________________________________________________________
223 Bool_t AliITSInitGeometry::InitAliITSgeom(AliITSgeom *geom){
224   // Initilizes the geometry transformation class AliITSgeom
225   // to values appropreate to this specific geometry. Now that
226   // the segmentation is part of AliITSgeom, the detector
227   // segmentations are also defined here.
228   // Inputs:
229   //   AliITSgeom *geom  A pointer to the AliITSgeom class
230   // Outputs:
231   //   AliITSgeom *geom  This pointer recreated and properly inilized.
232   // Return:
233   //   none.
234
235     if(!gGeoManager){
236         AliFatal("The geometry manager has not been initialized (e.g. "
237                  "TGeoManager::Import(\"geometry.root\")should be "
238                  "called in advance) - exit forced");
239         return kFALSE;
240     } // end if
241     switch(fMajorVersion) {
242     case kvtest: {
243         if(GetMinorVersion()==1) return InitAliITSgeomPPRasymmFMD(geom);
244         else if(GetMinorVersion()==2) return InitAliITSgeomtest2(geom);
245     } break; // end case
246     case kvSPD02: { 
247         return InitAliITSgeomSPD02(geom);
248     } break; // end case
249     case kvSDD03: { 
250         return InitAliITSgeomSDD03(geom);
251     } break; // end case
252     case kvSSD03: { 
253         return InitAliITSgeomSSD03(geom);
254     } break; // end case
255     case kvITS04: { 
256         return InitAliITSgeomITS04(geom);
257     } break; // end case
258     case kvPPRasymmFMD: { 
259         return InitAliITSgeomPPRasymmFMD(geom);
260     } break; // end case
261     case kvPPRcourseasymm: { 
262         return kTRUE; // No sensitive detectors in course geometry
263     } break; // end case
264     case kv11Hybrid: { 
265         return InitAliITSgeomV11Hybrid(geom);
266     } break; // end case
267     case kv11: {
268         return InitAliITSgeomV11(geom);
269     } break; // end case
270     case kvDefault: default: {
271         AliFatal("Undefined geometry");
272         return kFALSE;
273     } break; // end case
274     } // end switch
275     return kFALSE;
276 }
277 //______________________________________________________________________
278 void AliITSInitGeometry::TransposeTGeoHMatrix(TGeoHMatrix *m)const{
279     // Transpose the rotation matrix part of a TGeoHMatrix. This
280     // is needed because TGeo stores the transpose of the rotation
281     // matrix as compared to what AliITSgeomMatrix uses (and Geant3).
282     // Inputs:
283     //    TGeoHMatrix *m  The matrix to be transposed
284     // Outputs:
285     //    TGEoHMatrix *m  The transposed matrix
286     // Return:
287     //    none.
288     Int_t i;
289     Double_t r[9];
290
291     if(m==0) return; // no matrix to transpose.
292     for(i=0;i<9;i += 4) r[i] = m->GetRotationMatrix()[i]; // diagonals
293     r[1] = m->GetRotationMatrix()[3];
294     r[2] = m->GetRotationMatrix()[6];
295     r[3] = m->GetRotationMatrix()[1];
296     r[5] = m->GetRotationMatrix()[7];
297     r[6] = m->GetRotationMatrix()[2];
298     r[7] = m->GetRotationMatrix()[5];
299     m->SetRotation(r);
300     return;
301 }
302 //______________________________________________________________________
303 Bool_t AliITSInitGeometry::InitAliITSgeomtest2(AliITSgeom *geom){
304     // Initilizes the geometry transformation class AliITSgeom
305     // to values appropreate to this specific geometry. Now that
306     // the segmentation is part of AliITSgeom, the detector
307     // segmentations are also defined here.
308     // Inputs:
309     //   AliITSgeom *geom  A pointer to the AliITSgeom class
310     // Outputs:
311     //   AliITSgeom *geom  This pointer recreated and properly inilized.
312     // Return:
313     //   none.
314     //  const Double_t kcm2micron = 1.0E4;
315     const Int_t kItype=0; // Type of transormation defined 0=> Geant
316     const Int_t klayers = 6; // number of layers in the ITS
317     const Int_t kladders[klayers]   = {1,1,1,1,1,1}; // Number of ladders
318     const Int_t kdetectors[klayers] = {1,1,1,1,1,1};// number of detector/lad
319     const AliITSDetector kIdet[6]   = {kSPD,kSPD,kSDD,kSDD,kSSD,kSSD};
320     const TString kNames[klayers] = {
321          "/ALIC_1/ITSV_1/ITSspd1_1/ITS1_1", // lay=1
322          "/ALIC_1/ITSV_1/ITSspd2_1/ITS2_1", // lay=2
323          "/ALIC_1/ITSV_1/ITSsdd1_1/ITS3_1", // lay=3
324          "/ALIC_1/ITSV_1/ITSsdd2_1/ITS4_1", // lay=4
325          "/ALIC_1/ITSV_1/ITSssd1_1/ITS5_1", // lay=5
326          "/ALIC_1/ITSV_1/ITSssd2_1/ITS6_1"};// Lay=6
327     Int_t mod,nmods=0,lay,lad,det,cpn0,cpn1,cpn2;
328     Double_t tran[3]={0.0,0.0,0.0},rot[10]={9*0.0,1.0};
329     TArrayD shapePar;
330     TString shapeName;
331     TGeoHMatrix matrix;
332     Bool_t initSeg[3]={kFALSE,kFALSE,kFALSE};
333     TStopwatch *time = 0x0;if(fTiming) time=new TStopwatch();
334
335     if(fTiming) time->Start();
336     for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
337     geom->Init(kItype,klayers,kladders,kdetectors,nmods);
338     for(mod=0;mod<nmods;mod++){
339         DecodeDetectorLayers(mod,lay,lad,det); // Write
340         geom->CreateMatrix(mod,lay,lad,det,kIdet[lay-1],tran,rot);
341         RecodeDetector(mod,cpn0,cpn1,cpn2); // Write reusing lay,lad,det.
342         geom->GetGeomMatrix(mod)->SetPath(kNames[lay-1]);
343         GetTransformation(kNames[lay-1].Data(),matrix);
344         geom->SetTrans(mod,matrix.GetTranslation());
345         TransposeTGeoHMatrix(&matrix); // Transpose TGeo's rotation matrixes
346         geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
347         if(initSeg[kIdet[lay-1]]) continue;
348         GetShape(kNames[lay-1],shapeName,shapePar);
349         if(shapeName.CompareTo("BOX")){
350             Error("InitITSgeom2","Geometry changed without proper code update"
351                   "or error in reading geometry. Shape is not BOX shape is %s",
352                   shapeName.Data());
353             return kFALSE;
354         } // end if
355         InitGeomShapePPRasymmFMD(kIdet[lay-1],initSeg,shapePar,geom);
356     } // end for module
357     if(fTiming){
358         time->Stop();
359         time->Print();
360         delete time;
361     } // end if
362     return kTRUE;
363 }
364 //______________________________________________________________________
365 Bool_t AliITSInitGeometry::InitAliITSgeomSPD02(AliITSgeom *geom){
366     // Initilizes the geometry transformation class AliITSgeom
367     // to values appropreate to this specific geometry. Now that
368     // the segmentation is part of AliITSgeom, the detector
369     // segmentations are also defined here.
370     // Inputs:
371     //   AliITSgeom *geom  A pointer to the AliITSgeom class
372     // Outputs:
373     //   AliITSgeom *geom  This pointer recreated and properly inilized.
374     // Return:
375     //   none.
376     const Int_t kltypess=2;
377     const Int_t knlayers=5;
378     const TString knames[kltypess]=
379         {"ALIC_1/ITSV_1/ITEL_%d/IMB0_1/IMBS_1",//lay=1,2,4,5
380          "ALIC_1/ITSV_1/IDET_%d/ITS0_1/ITST_1"};// lay=3
381     const Int_t kitsGeomTreeCopys[2]={4,1};
382     const Int_t knlad[knlayers]={knlayers*1},kndet[knlayers]={knlayers*1};
383     TString path,shapeName;
384     TGeoHMatrix matrix;
385     TArrayD shapePar;
386     TArrayF shapeParF;
387     Double_t trans[3]={3*0.0},rot[10]={10*0.0};
388     Int_t npar=3,mod,i,j,lay,lad,det,cpy;
389     Float_t par[20];
390     TStopwatch *time = 0x0;if(fTiming) time=new TStopwatch();
391
392     par[0]=0.64;par[1]=0.5*300.0E-4;par[2]=3.48;
393     mod=5;;
394     geom->Init(0,knlayers,knlad,kndet,mod);
395
396     if(fTiming) time->Start();
397     for(i=0;i<kltypess;i++)for(cpy=1;cpy<=kitsGeomTreeCopys[i];cpy++){
398         path.Form(knames[i].Data(),cpy);
399         GetTransformation(path.Data(),matrix);
400         GetShape(path.Data(),shapeName,shapePar);
401         shapeParF.Set(shapePar.GetSize());
402         for(j=0;j<shapePar.GetSize();j++) shapeParF[j]=shapePar[j];
403         lay = cpy;
404         if(i==0&&cpy>2) lay=cpy+1;
405         if(i==1) lay=3;
406         DecodeDetector(mod,kitsGeomTreeCopys[i],1,cpy,0);
407         DecodeDetectorLayers(mod,lay,lad,det);
408         geom->CreateMatrix(mod,lay,lad,det,kSPD,trans,rot);
409         geom->SetTrans(mod,matrix.GetTranslation());
410         geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
411         geom->GetGeomMatrix(mod)->SetPath(path.Data());
412         if(!(geom->IsShapeDefined((Int_t)kSPD)))
413             geom->ReSetShape(kSPD,new AliITSgeomSPD425Short(npar,par));
414     } // end for i,cpy/
415     if(fTiming){
416         time->Stop();
417         time->Print();
418         delete time;
419     } // end if
420     return kTRUE;
421 }
422 //______________________________________________________________________
423 Bool_t AliITSInitGeometry::InitAliITSgeomSDD03(AliITSgeom *geom){
424     // Initilizes the geometry transformation class AliITSgeom
425     // to values appropreate to this specific geometry. Now that
426     // the segmentation is part of AliITSgeom, the detector
427     // segmentations are also defined here.
428     // Inputs:
429     //   AliITSgeom *geom  A pointer to the AliITSgeom class
430     // Outputs:
431     //   AliITSgeom *geom  This pointer recreated and properly inilized.
432     // Return:
433     //   none
434     const Int_t knlayers=12;
435     //   const Int_t kndeep=6;
436     const Int_t kltypess=2;
437     const AliITSDetector kidet[knlayers]={kSSD,kSDD};
438     const TString knames[kltypess]={
439         "/ALIC_1/ITSV_1/ITEL_%d/ITAI_1/IMB0_1/IMBS_1",
440         "/ALIC_1/ITSV_1/IDET_%d/IDAI_1/ITS0_1/ITST_1"};
441     const Int_t kitsGeomTreeCopys[kltypess]={10,2};
442     const Int_t knp=384;
443     const Float_t kpitch=50.E-4;/*cm*/
444     Float_t box[3]={0.5*kpitch*(Float_t)knp,150.E-4,1.0},p[knp+1],n[knp+1];
445     Int_t nlad[knlayers]={knlayers*1};
446     Int_t ndet[knlayers]={knlayers*1};
447     Int_t mod=knlayers,lay=0,lad=0,det=0,i,j,cp0;
448     TString path,shapeName;
449     TGeoHMatrix matrix;
450     Double_t trans[3]={3*0.0},rot[10]={10*0.0};
451     TArrayD shapePar;
452     TArrayF shapeParF;
453     Bool_t isShapeDefined[kltypess]={kltypess*kFALSE};
454
455     geom->Init(0,knlayers,nlad,ndet,mod);
456     p[0]=-box[0];
457     n[0]=box[0];
458     // Fill in anode and cathode strip locations (lower edge)
459     for(i=1;i<knp;i++){
460         p[i] =p[i-1]+kpitch;
461         n[i] =n[i-1]-kpitch;
462     } // end for i
463     p[knp]=box[0];
464     n[knp]=-box[0];
465     for(i=0;i<kltypess;i++)for(cp0=1;cp0<=kitsGeomTreeCopys[i];cp0++){
466         DecodeDetector(mod,kitsGeomTreeCopys[i],cp0,1,2);
467         DecodeDetectorLayers(mod,lay,lad,det);
468         path.Form(knames[i].Data(),cp0);
469         GetTransformation(path.Data(),matrix);
470         GetShape(path.Data(),shapeName,shapePar);
471         shapeParF.Set(shapePar.GetSize());
472         for(j=0;j<shapePar.GetSize();j++)shapeParF[j]=shapePar[j];
473         geom->CreateMatrix(mod,lay,lad,det,kidet[i],trans,rot);
474         geom->SetTrans(mod,matrix.GetTranslation());
475         geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
476         geom->GetGeomMatrix(mod)->SetPath(path.Data());
477         switch (kidet[i]){
478         case kSDD: if(!(geom->IsShapeDefined((Int_t)kSDD))){
479             geom->ReSetShape(kSDD,new AliITSgeomSDD256(shapeParF.GetSize(),
480                                                        shapeParF.GetArray()));
481             isShapeDefined[i]=kTRUE;
482         } break;
483         case kSSD:if(!(geom->IsShapeDefined((Int_t)kSSD))){
484             geom->ReSetShape(kSSD,new AliITSgeomSSD(box,0.0,0.0,
485                                                     knp+1,p,knp+1,n));
486             isShapeDefined[i]=kTRUE;
487         } break;
488         default:{} break;
489         } // end switch
490     } // end for i,cp0
491
492     return kTRUE;
493 }
494 //______________________________________________________________________
495 Bool_t AliITSInitGeometry::InitAliITSgeomSSD03(AliITSgeom *geom){
496     // Initilizes the geometry transformation class AliITSgeom
497     // to values appropreate to this specific geometry. Now that
498     // the segmentation is part of AliITSgeom, the detector
499     // segmentations are also defined here.
500     // Inputs:
501     //   AliITSgeom *geom  A pointer to the AliITSgeom class
502     // Outputs:
503     //   AliITSgeom *geom  This pointer recreated and properly inilized.
504     // Return:
505     //   none.
506     const Int_t knlayers=5;
507     //   const Int_t kndeep=6;
508     const Int_t kltypess=3;
509     const AliITSDetector kIdet[knlayers]={kND,kSSD,kND};
510     const TString knames[kltypess]={
511         "/ALIC_1/ITSV_1/ITSA_%d/ITSS_1",
512         "/ALIC_1/ITSV_1/IGAR_%d/IAIR_1/ITST_1",
513         "/ALIC_1/ITSV_1/IFRA_%d/IFRS_1"};
514     const Int_t kitsGeomTreeCopys[kltypess]={3,1,1};
515     const Int_t kitsGeomDetTypes[kltypess]={1,2,3};
516     const Int_t knp=384;
517     const Float_t kpitch=50.E-4;//cm
518     Bool_t initSeg[3]={kFALSE, kFALSE, kFALSE};
519     Float_t box[3]={0.5*kpitch*(Float_t)knp,150.E-4,1.0},p[knp+1],n[knp+1];
520     Int_t nlad[knlayers]={knlayers*1};
521     Int_t ndet[knlayers]={knlayers*1};
522     Int_t mod=knlayers,lay=0,lad=0,det=0,i,j,cp0;
523     TString path,shapeName;
524     TGeoHMatrix matrix;
525     Double_t trans[3]={3*0.0},rot[10]={10*0.0};
526     TArrayD shapePar;
527     TArrayF shapeParF;
528     Bool_t isShapeDefined[kltypess]={kltypess*kFALSE};
529
530     geom->Init(0,knlayers,nlad,ndet,mod);
531     p[0]=-box[0];
532     n[0]=box[0];
533     // Fill in anode and cathode strip locations (lower edge)
534     for(i=1;i<knp;i++){
535         p[i] =p[i-1]+kpitch;
536         n[i] =n[i-1]-kpitch;
537     } // end for i
538     p[knp]=box[0];
539     n[knp]=-box[0];
540     for(i=0;i<kltypess;i++)for(cp0=1;cp0<=kitsGeomTreeCopys[i];cp0++){
541         DecodeDetector(mod,kitsGeomDetTypes[i],cp0,1,0);
542         DecodeDetectorLayers(mod,lay,lad,det);
543         path.Form(knames[i].Data(),cp0);
544         GetTransformation(path.Data(),matrix);
545         GetShape(path.Data(),shapeName,shapePar);
546         shapeParF.Set(shapePar.GetSize());
547         for(j=0;j<shapePar.GetSize();j++)shapeParF[j]=shapePar[j];
548         geom->CreateMatrix(mod,lay,lad,det,kIdet[i],trans,rot);
549         geom->SetTrans(mod,matrix.GetTranslation());
550         geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
551         geom->GetGeomMatrix(mod)->SetPath(path.Data());
552         switch (kIdet[i]){
553         case kSSD:if(!(geom->IsShapeDefined((Int_t)kSSD))){
554             InitGeomShapePPRasymmFMD(kIdet[lay-1],initSeg,shapePar,geom);
555             isShapeDefined[i]=kTRUE;
556         } break;
557         default:{} break;
558         } // end switch
559     } // end for i,cp0
560
561     return kTRUE;
562 }
563 //______________________________________________________________________
564 Bool_t AliITSInitGeometry::InitAliITSgeomITS04(AliITSgeom *geom){
565     // Initilizes the geometry transformation class AliITSgeom
566     // to values appropreate to this specific geometry. Now that
567     // the segmentation is part of AliITSgeom, the detector
568     // segmentations are also defined here.
569     // Inputs:
570     //   AliITSgeom *geom  A pointer to the AliITSgeom class
571     // Outputs:
572     //   AliITSgeom *geom  This pointer recreated and properly inilized.
573     // Return:
574     //   none.
575
576   // We can not use AliITSvBeamTestITS04::fgk... data members because
577   // AliITSInitGeometry is part of the base library while AliITSvBeamTestITS04
578   // is part of the simulation library. This would introduce a dependance
579   // between the 2 libraries
580
581
582     const Int_t knlayers = 6;
583     Int_t nlad[knlayers], ndet[knlayers];
584     
585     nlad[0] = 1; ndet[0] = 2;
586     nlad[1] = 1; ndet[1] = 2;
587     nlad[2] = 1; ndet[2] = 1;
588     nlad[3] = 1; ndet[3] = 1;
589     nlad[4] = 1; ndet[4] = 2;
590     nlad[5] = 1; ndet[5] = 2;
591
592     Int_t nModTot = 10;
593     geom->Init(0,knlayers,nlad,ndet,nModTot);
594
595     /*
596     //=== Set default shapes 
597     const Float_t kDxyzSPD[] = {AliITSvBeamTestITS04::fgkSPDwidthSens/2,
598                                 AliITSvBeamTestITS04::fgkSPDthickSens/2,
599                                 AliITSvBeamTestITS04::fgkSPDlengthSens/2};  
600     if(!(geom->IsShapeDefined(kSPD)))
601        geom->ReSetShape(kSPD,new AliITSgeomSPD425Short(3,(Float_t *)kDxyzSPD));
602     
603     const Float_t kDxyzSDD[] = {AliITSvBeamTestITS04::fgkSDDwidthSens/2.,
604                                 AliITSvBeamTestITS04::fgkSDDthickSens/2.,
605                                 AliITSvBeamTestITS04::fgkSDDlengthSens/2.};
606     if(!(geom->IsShapeDefined(kSDD)))
607         geom->ReSetShape(kSDD, new AliITSgeomSDD256(3,(Float_t *)kDxyzSDD));
608     
609     const Float_t kDxyzSSD[] = {AliITSvBeamTestITS04::fgkSSDlengthSens/2,
610                                 AliITSvBeamTestITS04::fgkSSDthickSens/2,
611                                 AliITSvBeamTestITS04::fgkSSDwidthSens/2};
612     if(!(geom->IsShapeDefined(kSSD)))
613        geom->ReSetShape(kSSD,new AliITSgeomSSD75and275(3,(Float_t *)kDxyzSSD));
614     
615     // Creating the matrices in AliITSgeom for each sensitive volume
616     // (like in AliITSv11GeometrySDD) mln
617     // Here, each layer is one detector
618     
619     char layerName[30];
620     Int_t startMod = 0,mod;
621     TGeoVolume *itsmotherVolume = gGeoManager->GetVolume("ITSV");
622     // SPD
623     for (Int_t i=0; i<4;i++) {
624         sprintf(layerName, "ITSspdWafer_%i",i+1);
625         TGeoNode *layNode = itsmotherVolume->GetNode(layerName);
626         if (layNode) {
627             TGeoHMatrix layMatrix(*layNode->GetMatrix());           
628             Double_t *trans  = layMatrix.GetTranslation();
629             Double_t *r      = layMatrix.GetRotationMatrix();
630             Double_t rot[10] = {r[0],r[1],r[2],
631                                 r[3],r[4],r[5],
632                                 r[6],r[7],r[8], 1.0};
633             Int_t iDet = 1;
634             Int_t iLad = 1;
635             Int_t iLay = 1;
636             DecodeDetector(mod,layNode->GetNumber(),i+1,0,0);
637             DecodeDetectorLayers(mod,iLay,iLad,iDet);
638             geom->CreateMatrix(startMod,iLay,iLad,iDet,kSPD,trans,rot);
639             startMod++;
640         };
641     };
642     
643     // SDD
644     for (Int_t i=0; i<2;i++) {
645         sprintf(layerName, "ITSsddWafer_%i",i+4+1);
646         TGeoNode *layNode = itsmotherVolume->GetNode(layerName);
647         if (layNode) {
648             TGeoHMatrix layMatrix(*layNode->GetMatrix());
649             Double_t *trans  = layMatrix.GetTranslation();
650             Double_t *r      = layMatrix.GetRotationMatrix();
651             Double_t rot[10] = {r[0],r[1],r[2],
652                                 r[3],r[4],r[5],
653                                 r[6],r[7],r[8], 1.0};
654             Int_t iDet = 1;
655             Int_t iLad = 1;
656             Int_t iLay = 1;
657             DecodeDetector(mod,layNode->GetNumber(),i+1,0,0);
658             DecodeDetectorLayers(mod,iLay,iLad,iDet);
659             geom->CreateMatrix(startMod,iLay,iLad,iDet,kSDD,trans,rot);
660             startMod++;
661         };
662     };
663     
664     // SSD
665     for (Int_t i=0; i<4;i++) {
666         sprintf(layerName, "ITSssdWafer_%i",i+4+2+1);
667         TGeoNode *layNode = itsmotherVolume->GetNode(layerName);
668         if (layNode) {
669             TGeoHMatrix layMatrix(*layNode->GetMatrix());           
670             Double_t *trans  = layMatrix.GetTranslation();
671             Double_t *r      = layMatrix.GetRotationMatrix();
672             Double_t rot[10] = {r[0],r[1],r[2],
673                                 r[3],r[4],r[5],
674                                 r[6],r[7],r[8], 1.0};
675             Int_t iDet = 1;
676             Int_t iLad = 1;
677             Int_t iLay = 5;
678             DecodeDetector(mod,layNode->GetNumber(),i+1,0,0);
679             DecodeDetectorLayers(mod,iLay,iLad,iDet);
680             geom->CreateMatrix(startMod,iLay,iLad,iDet,kSSD,trans,rot);
681             startMod++;
682         };
683     };
684
685     return kTRUE;
686   */
687     return kFALSE;
688 }
689 //______________________________________________________________________
690 Bool_t AliITSInitGeometry::InitAliITSgeomPPRasymmFMD(AliITSgeom *geom){
691     // Initilizes the geometry transformation class AliITSgeom
692     // to values appropreate to this specific geometry. Now that
693     // the segmentation is part of AliITSgeom, the detector
694     // segmentations are also defined here.
695     // Inputs:
696     //   AliITSgeom *geom  A pointer to the AliITSgeom class
697     // Outputs:
698     //   AliITSgeom *geom  This pointer recreated and properly inilized.
699     // Return:
700     //   none.
701   //    const Double_t kcm2micron = 1.0E4;
702     const Int_t kItype=0; // Type of transormation defined 0=> Geant
703     const Int_t klayers = 6; // number of layers in the ITS
704     const Int_t kladders[klayers]   = {20,40,14,22,34,38}; // Number of ladders
705     const Int_t kdetectors[klayers] = {4,4,6,8,22,25};// number of detector/lad
706     const AliITSDetector kIdet[6]   = {kSPD,kSPD,kSDD,kSDD,kSSD,kSSD};
707     const TString kPathbase = "/ALIC_1/ITSV_1/ITSD_1/";
708     const TString kNames[2][klayers] = {
709         {"%sIT12_1/I12A_%d/I10A_%d/I103_%d/I101_1/ITS1_1", // lay=1
710          "%sIT12_1/I12A_%d/I20A_%d/I1D3_%d/I1D1_1/ITS2_1", // lay=2
711          "%sIT34_1/I004_%d/I302_%d/ITS3_%d/", // lay=3
712          "%sIT34_1/I005_%d/I402_%d/ITS4_%d/", // lay=4
713          "%sIT56_1/I565_%d/I562_%d/ITS5_%d/", // lay=5
714          "%sIT56_1/I569_%d/I566_%d/ITS6_%d/"},// lay=6
715         {"%sIT12_1/I12B_%d/I10B_%d/I107_%d/I101_1/ITS1_1", // lay=1
716          "%sIT12_1/I12B_%d/I20B_%d/I1D7_%d/I1D1_1/ITS2_1", // lay=2
717          "%sIT34_1/I004_%d/I302_%d/ITS3_%d", // lay=3
718          "%sIT34_1/I005_%d/I402_%d/ITS4_%d", // lay=4
719          "%sIT56_1/I565_%d/I562_%d/ITS5_%d", // lay=5
720          "%sIT56_1/I569_%d/I566_%d/ITS6_%d"}};// Lay=6
721     /*
722       Int_t itsGeomTreeCopys[knlayers][3]= {{10, 2, 4},// lay=1
723       {10, 4, 4},// lay=2
724       {14, 6, 1},// lay=3
725       {22, 8, 1},// lay=4
726       {34,22, 1},// lay=5
727       {38,25, 1}};//lay=6
728     */
729     Int_t mod,nmods=0,lay,lad,det,cpn0,cpn1,cpn2;
730     Double_t tran[3]={0.0,0.0,0.0},rot[10]={9*0.0,1.0};
731     TArrayD shapePar;
732     TString path,shapeName;
733     TGeoHMatrix matrix;
734     Bool_t initSeg[3]={kFALSE,kFALSE,kFALSE};
735     TStopwatch *time = 0x0;if(fTiming) time=new TStopwatch();
736
737     if(fTiming) time->Start();
738     for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
739     geom->Init(kItype,klayers,kladders,kdetectors,nmods);
740     for(mod=0;mod<nmods;mod++){
741         DecodeDetectorLayers(mod,lay,lad,det); // Write
742         geom->CreateMatrix(mod,lay,lad,det,kIdet[lay-1],tran,rot);
743         RecodeDetector(mod,cpn0,cpn1,cpn2); // Write reusing lay,lad,det.
744         path.Form(kNames[fMinorVersion-1][lay-1].Data(),
745                   kPathbase.Data(),cpn0,cpn1,cpn2);
746         geom->GetGeomMatrix(mod)->SetPath(path);
747         GetTransformation(path.Data(),matrix);
748         geom->SetTrans(mod,matrix.GetTranslation());
749         TransposeTGeoHMatrix(&matrix); //Transpose TGeo's rotation matrixes
750         geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
751         if(initSeg[kIdet[lay-1]]) continue;
752         GetShape(path,shapeName,shapePar);
753         if(shapeName.CompareTo("BOX")){
754           Error("InitITSgeomPPRasymmFMD",
755                 "Geometry changed without proper code update or error "
756                 "in reading geometry. Shape is not BOX. Shape is %s",
757                 shapeName.Data());
758           return kFALSE;
759         } // end if
760         InitGeomShapePPRasymmFMD(kIdet[lay-1],initSeg,shapePar,geom);
761     } // end for module
762     if(fTiming){
763         time->Stop();
764         time->Print();
765         delete time;
766     } // end if
767     return kTRUE;
768 }
769 //______________________________________________________________________
770 Bool_t AliITSInitGeometry::InitAliITSgeomV11Hybrid(AliITSgeom *geom){
771     // Initilizes the geometry transformation class AliITSgeom
772     // to values appropreate to this specific geometry. Now that
773     // the segmentation is part of AliITSgeom, the detector
774     // segmentations are also defined here.
775     // Inputs:
776     //   AliITSgeom *geom  A pointer to the AliITSgeom class
777     // Outputs:
778     //   AliITSgeom *geom  This pointer recreated and properly inilized.
779     // Return:
780     //   none.
781
782   const Int_t kItype  = 0; // Type of transformation defined 0=> Geant
783   const Int_t klayers = 6; // number of layers in the ITS
784   const Int_t kladders[klayers]   = {20,40,14,22,34,38}; // Number of ladders
785   const Int_t kdetectors[klayers] = {4,4,6,8,22,25};// number of detector/lad
786   const AliITSDetector kIdet[6]   = {kSPD,kSPD,kSDD,kSDD,kSSD,kSSD};
787   const TString kPathbase = "/ALIC_1/ITSV_1/";
788   
789   char *pathSDDsens1, *pathSDDsens2;
790   if (SDDIsTGeoNative()) {
791     pathSDDsens1 = "%sITSsddLayer3_1/ITSsddLadd_%d/ITSsddSensor3_%d/ITSsddWafer3_%d/ITSsddSensitivL3_1";
792     pathSDDsens2 = "%sITSsddLayer4_1/ITSsddLadd_%d/ITSsddSensor4_%d/ITSsddWafer4_%d/ITSsddSensitivL4_1";
793   } else{
794     pathSDDsens1 = "%sITSD_1/IT34_1/I004_%d/I302_%d/ITS3_%d";
795     pathSDDsens2 = "%sITSD_1/IT34_1/I005_%d/I402_%d/ITS4_%d";
796   }
797
798   char *pathSSDsens1, *pathSSDsens2;
799   if (SSDIsTGeoNative()) {
800     pathSSDsens1 = "%sITSssdLayer5_1/ITSssdLay5Ladd_%d/ITSsddSensor5_%d/ITSsddSensitivL5_1";
801     pathSSDsens2 = "%sITSssdLayer6_1/ITSssdLay6Ladd_%d/ITSsddSensor6_%d/ITSsddSensitivL6_1";
802   } else{
803     pathSSDsens1 = "%sITSD_1/IT56_1/I565_%d/I562_%d/ITS5_%d";
804     pathSSDsens2 = "%sITSD_1/IT56_1/I569_%d/I566_%d/ITS6_%d";
805   }
806
807   const TString kNames[klayers] = {
808     "%sITSD_1/IT12_1/I12B_%d/I10B_%d/I107_%d/I101_1/ITS1_1", // lay=1
809     "%sITSD_1/IT12_1/I12B_%d/I20B_%d/I1D7_%d/I1D1_1/ITS2_1", // lay=2
810     pathSDDsens1, // lay=3
811     pathSDDsens2, // lay=4
812     pathSSDsens1, // lay=5
813     pathSSDsens2};// Lay=6
814   
815   Int_t mod,nmods=0, lay, lad, det, cpn0, cpn1, cpn2;
816   Double_t tran[3]={0.,0.,0.}, rot[10]={9*0.0,1.0};
817   TArrayD shapePar;
818   TString path, shapeName;
819   TGeoHMatrix matrix;
820   Bool_t initSeg[3]={kFALSE, kFALSE, kFALSE};
821   TStopwatch *time = 0x0;
822   if(fTiming) time = new TStopwatch();
823
824   if(fTiming) time->Start();
825   for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
826   geom->Init(kItype,klayers,kladders,kdetectors,nmods);
827
828   for(mod=0;mod<nmods;mod++) {
829
830 //     DecodeDetectorLayers(mod,lay,lad,det); // Write
831 //     geom->CreateMatrix(mod,lay,lad,det,kIdet[lay-1],tran,rot);
832 //     RecodeDetector(mod,cpn0,cpn1,cpn2); // Write reusing lay,lad,det.
833     DecodeDetectorLayers(mod,lay,lad,det); // Write
834     geom->CreateMatrix(mod,lay,lad,det,kIdet[lay-1],tran,rot);
835     RecodeDetector(mod,cpn0,cpn1,cpn2); // Write reusing lay,lad,det.
836
837     if (SDDIsTGeoNative())
838       if (kIdet[lay-1]==kSDD) {
839         cpn0 = lad-1;
840         cpn1 = det-1;
841         cpn2 = 1;
842       }
843     if (SSDIsTGeoNative())
844       if (kIdet[lay-1]==kSSD) {
845         cpn0 = lad-1;
846         cpn1 = det-1;
847         cpn2 = 1;
848       }
849
850     path.Form(kNames[lay-1].Data(),
851               kPathbase.Data(),cpn0,cpn1,cpn2);
852     geom->GetGeomMatrix(mod)->SetPath(path);
853     GetTransformation(path.Data(),matrix);
854     geom->SetTrans(mod,matrix.GetTranslation());
855     TransposeTGeoHMatrix(&matrix); //Transpose TGeo's rotation matrixes
856     geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
857     if(initSeg[kIdet[lay-1]]) continue;
858     GetShape(path,shapeName,shapePar);
859     if(shapeName.CompareTo("BOX")){
860       Error("InitITSgeom","Geometry changed without proper code update"
861             "or error in reading geometry. Shape is not BOX.");
862       return kFALSE;
863     } // end if
864     InitGeomShapePPRasymmFMD(kIdet[lay-1],initSeg,shapePar,geom);
865   } // end for module
866
867   if(fTiming){
868     time->Stop();
869     time->Print();
870     delete time;
871   } // end if
872   return kTRUE;
873 }
874 //______________________________________________________________________
875 Bool_t AliITSInitGeometry::InitAliITSgeomV11(AliITSgeom *geom){
876   // Initilizes the geometry transformation class AliITSgeom
877   // Now that the segmentation is part of AliITSgeom, the detector
878   // segmentations are also defined here.
879   //
880   // Inputs:
881   //   AliITSgeom *geom  A pointer to the AliITSgeom class
882   // Outputs:
883   //   AliITSgeom *geom  This pointer recreated and properly inilized.
884   // LG
885
886
887   const Int_t kItype=0; // Type of transormation defined 0=> Geant
888   const Int_t klayers = 6; // number of layers in the ITS
889   const Int_t kladders[klayers]   = {20,40,14,22,34,38}; // Number of ladders
890   const Int_t kdetectors[klayers] = {4,4,6,8,22,25};// number of detector/lad
891   const AliITSDetector kIdet[6]   = {kSPD,kSPD,kSDD,kSDD,kSSD,kSSD};
892
893   const TString kPathbase = "/ALIC_1/ITSV_1/";
894   const TString kNames[klayers] =
895     {"AliITSInitGeometry:spd missing", // lay=1
896      "AliITSInitGeometry:spd missing", // lay=2
897      "%sITSsddLayer3_1/ITSsddLadd_%d/ITSsddSensor_%d/ITSsddWafer_1/ITSsddSensitiv_1", // lay=3
898      "%sITSsddLayer4_1/ITSsddLadd_%d/ITSsddSensor_%d/ITSsddWafer_1/ITSsddSensitiv_1", // lay=4
899      "AliITSInitGeometry:ssd missing", // lay=5
900      "AliITSInitGeometry:ssd missing"};// lay=6
901  
902   Int_t mod,nmods=0,lay,lad,det,cpn0,cpn1,cpn2;
903   Double_t tran[3]={0.0,0.0,0.0},rot[10]={9*0.0,1.0};
904   TArrayD shapePar;
905   TString path,shapeName;
906   TGeoHMatrix matrix;
907   Bool_t initSeg[3]={kFALSE,kFALSE,kFALSE};
908   TStopwatch *time = 0x0;if(fTiming) time=new TStopwatch();
909   
910   if(fTiming) time->Start();
911   for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
912   
913   geom->Init(kItype,klayers,kladders,kdetectors,nmods);
914   for(mod=0;mod<nmods;mod++) {
915     
916     DecodeDetectorLayers(mod,lay,lad,det); // Write
917     geom->CreateMatrix(mod,lay,lad,det,kIdet[lay-1],tran,rot);
918     RecodeDetector(mod,cpn0,cpn1,cpn2); // Write reusing lay,lad,det.
919     path.Form(kNames[lay-1].Data(),
920               kPathbase.Data(),cpn0,cpn1,cpn2);
921     geom->GetGeomMatrix(mod)->SetPath(path);
922     if (GetTransformation(path.Data(),matrix)) {
923       geom->SetTrans(mod,matrix.GetTranslation());
924       TransposeTGeoHMatrix(&matrix); //Transpose TGeo's rotation matrixes
925       geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
926     }
927     
928     if(initSeg[kIdet[lay-1]]) continue;
929     GetShape(path,shapeName,shapePar);
930     if(shapeName.CompareTo("BOX")){
931       Error("InitAliITSgeomV11","Geometry changed without proper code update"
932             "or error in reading geometry. Shape is not BOX.");
933       return kFALSE;
934     } // end if
935     InitGeomShapePPRasymmFMD(kIdet[lay-1],initSeg,shapePar,geom);
936     
937   } // end for module
938   
939   if(fTiming){
940     time->Stop();
941     time->Print();
942     delete time;
943   } // end if
944   return kTRUE;
945 }
946
947 //______________________________________________________________________
948 Bool_t AliITSInitGeometry::InitGeomShapePPRasymmFMD(AliITSDetector idet,
949                                                        Bool_t *initSeg,
950                                                        TArrayD &shapePar,
951                                                        AliITSgeom *geom){
952     // Initilizes the geometry segmentation class AliITSgeomS?D, or
953     // AliITSsegmentationS?D depending on the vaule of fSegGeom,
954     // to values appropreate to this specific geometry. Now that
955     // the segmentation is part of AliITSgeom, the detector
956     // segmentations are also defined here.
957     // Inputs:
958     //   Int_t      lay    The layer number/name.
959     //   AliITSgeom *geom  A pointer to the AliITSgeom class
960     // Outputs:
961     //   AliITSgeom *geom  This pointer recreated and properly inilized.
962     // Return:
963     //   none.
964   //   const Double_t kcm2micron = 1.0E4;
965     const Double_t kmicron2cm = 1.0E-4;
966     Int_t i;
967     TArrayF shapeParF;
968
969     shapeParF.Set(shapePar.GetSize());
970     for(i=0;i<shapePar.GetSize();i++) shapeParF[i]=shapePar[i];
971     switch (idet){
972     case kSPD:{
973         initSeg[idet] = kTRUE;
974         AliITSgeomSPD *geomSPD = new AliITSgeomSPD425Short();
975         Float_t bx[256],bz[280];
976         for(i=000;i<256;i++) bx[i] =  50.0*kmicron2cm; // in x all are 50 microns.
977         for(i=000;i<160;i++) bz[i] = 425.0*kmicron2cm; // most are 425 microns
978         // except below
979         for(i=160;i<280;i++) bz[i] =   0.0*kmicron2cm; // Outside of detector.
980         bz[ 31] = bz[ 32] = 625.0*kmicron2cm; // first chip boundry
981         bz[ 63] = bz[ 64] = 625.0*kmicron2cm; // first chip boundry
982         bz[ 95] = bz[ 96] = 625.0*kmicron2cm; // first chip boundry
983         bz[127] = bz[128] = 625.0*kmicron2cm; // first chip boundry
984         bz[160] = 425.0*kmicron2cm;// Set so that there is no zero pixel size for fNz.
985         geomSPD->ReSetBins(shapeParF[1],256,bx,160,bz);
986         geom->ReSetShape(idet,geomSPD);
987     }break;
988     case kSDD:{
989         initSeg[idet] = kTRUE;
990         AliITSgeomSDD *geomSDD = new AliITSgeomSDD256(shapeParF.GetSize(),
991                                                       shapeParF.GetArray());
992         geom->ReSetShape(idet,geomSDD);
993     }break;
994     case kSSD:{
995         initSeg[idet] = kTRUE;
996         AliITSgeomSSD *geomSSD = new AliITSgeomSSD275and75(
997             shapeParF.GetSize(),shapeParF.GetArray());
998         geom->ReSetShape(idet,geomSSD);
999     }break;
1000     default:{// Others, Note no kSDDp or kSSDp in this geometry.
1001         geom->ReSetShape(idet,0);
1002         Info("InitGeomShapePPRasymmFMD",
1003              "default Dx=%f Dy=%f Dz=%f default=%d",
1004              shapePar[0],shapePar[1],shapePar[2],idet);
1005     }break;
1006     } // end switch
1007     return kTRUE;
1008 }
1009 //______________________________________________________________________
1010 Bool_t AliITSInitGeometry::InitSegmentationPPRasymmFMD(AliITSDetector idet,
1011                                                        Bool_t *initSeg,
1012                                                        TArrayD &shapePar,
1013                                                        AliITSgeom *geom){
1014     // Initilizes the geometry segmentation class AliITSgeomS?D, or
1015     // AliITSsegmentationS?D depending on the vaule of fSegGeom,
1016     // to values appropreate to this specific geometry. Now that
1017     // the segmentation is part of AliITSgeom, the detector
1018     // segmentations are also defined here.
1019     // Inputs:
1020     //   Int_t      lay    The layer number/name.
1021     //   AliITSgeom *geom  A pointer to the AliITSgeom class
1022     // Outputs:
1023     //   AliITSgeom *geom  This pointer recreated and properly inilized.
1024     // Return:
1025     //   none.
1026     const Double_t kcm2micron = 1.0E4;
1027     Int_t i;
1028
1029     switch (idet){
1030     case kSPD:{
1031         initSeg[idet] = kTRUE;
1032         AliITSsegmentationSPD *segSPD = new AliITSsegmentationSPD();
1033         segSPD->SetDetSize(2.*shapePar[0]*kcm2micron, // X
1034                            2.*shapePar[2]*kcm2micron, // Z
1035                            2.*shapePar[1]*kcm2micron);// Y  Microns
1036         segSPD->SetNPads(256,160);// Number of Bins in x and z
1037         Float_t bx[256],bz[280];
1038         for(i=000;i<256;i++) bx[i] =  50.0; // in x all are 50 microns.
1039         for(i=000;i<160;i++) bz[i] = 425.0; // most are 425 microns
1040         // except below
1041         for(i=160;i<280;i++) bz[i] =   0.0; // Outside of detector.
1042         bz[ 31] = bz[ 32] = 625.0; // first chip boundry
1043         bz[ 63] = bz[ 64] = 625.0; // first chip boundry
1044         bz[ 95] = bz[ 96] = 625.0; // first chip boundry
1045         bz[127] = bz[128] = 625.0; // first chip boundry
1046         bz[160] = 425.0;// Set so that there is no zero pixel size for fNz.
1047         segSPD->SetBinSize(bx,bz); // Based on AliITSgeomSPD for now.
1048         geom->ReSetShape(idet,segSPD);
1049     }break;
1050     case kSDD:{
1051         initSeg[idet] = kTRUE;
1052         AliITSsegmentationSDD *segSDD = new AliITSsegmentationSDD();
1053         segSDD->SetDetSize(shapePar[0]*kcm2micron, // X
1054                            2.*shapePar[2]*kcm2micron, // Z
1055                            2.*shapePar[1]*kcm2micron);// Y  Microns
1056         segSDD->SetNPads(256,256);// Anodes, Samples
1057         geom->ReSetShape(idet,segSDD);
1058     }break;
1059     case kSSD:{
1060         initSeg[idet] = kTRUE;
1061         AliITSsegmentationSSD *segSSD = new AliITSsegmentationSSD();
1062         segSSD->SetDetSize(2.*shapePar[0]*kcm2micron, // X
1063                            2.*shapePar[2]*kcm2micron, // Z
1064                            2.*shapePar[1]*kcm2micron);// Y  Microns.
1065         segSSD->SetPadSize(95.,0.); // strip x pitch in microns
1066         segSSD->SetNPads(768,2); // number of strips on each side, sides.
1067         segSSD->SetAngles(0.0075,0.0275); // strip angels rad P and N side.
1068         segSSD->SetAnglesLay5(0.0075,0.0275);//strip angels rad P and N
1069         segSSD->SetAnglesLay6(0.0275,0.0075);//strip angels rad P and N
1070         geom->ReSetShape(idet,segSSD);
1071     }break;
1072     default:{// Others, Note no kSDDp or kSSDp in this geometry.
1073         geom->ReSetShape(idet,0);
1074         Info("InitSegmentationPPRasymmFMD",
1075              "default segmentation Dx=%f Dy=%f Dz=%f default=%d",
1076              shapePar[0],shapePar[1],shapePar[2],idet);
1077     }break;
1078     } // end switch
1079     return kTRUE;
1080 }
1081 //______________________________________________________________________
1082 Bool_t AliITSInitGeometry::GetTransformation(const TString &volumePath,
1083                                              TGeoHMatrix &mat){
1084     // Returns the Transformation matrix between the volume specified
1085     // by the path volumePath and the Top or mater volume. The format
1086     // of the path volumePath is as follows (assuming ALIC is the Top volume)
1087     // "/ALIC_1/DDIP_1/S05I_2/S05H_1/S05G_3". Here ALIC is the top most
1088     // or master volume which has only 1 instance of. Of all of the daughter
1089     // volumes of ALICE, DDIP volume copy #1 is indicated. Similarly for
1090     // the daughter volume of DDIP is S05I copy #2 and so on.
1091     // Inputs:
1092     //   TString& volumePath  The volume path to the specific volume
1093     //                        for which you want the matrix. Volume name
1094     //                        hierarchy is separated by "/" while the
1095     //                        copy number is appended using a "_".
1096     // Outputs:
1097     //  TGeoHMatrix &mat      A matrix with its values set to those
1098     //                        appropriate to the Local to Master transformation
1099     // Return:
1100     //   A logical value if kFALSE then an error occurred and no change to
1101     //   mat was made.
1102
1103     // We have to preserve the modeler state
1104
1105     // Preserve the modeler state.
1106     gGeoManager->PushPath();
1107     if (!gGeoManager->cd(volumePath.Data())) {
1108       gGeoManager->PopPath();
1109       Error("GetTransformation","Error in cd-ing to ",volumePath.Data());
1110       return kFALSE;
1111     } // end if !gGeoManager
1112     mat = *gGeoManager->GetCurrentMatrix();
1113     // Retstore the modeler state.
1114     gGeoManager->PopPath();
1115     return kTRUE;
1116 }
1117 //______________________________________________________________________
1118 Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
1119                                     TString &shapeType,TArrayD &par){
1120     // Returns the shape and its parameters for the volume specified
1121     // by volumeName.
1122     // Inputs:
1123     //   TString& volumeName  The volume name
1124     // Outputs:
1125     //   TString &shapeType   Shape type
1126     //   TArrayD &par         A TArrayD of parameters with all of the
1127     //                        parameters of the specified shape.
1128     // Return:
1129     //   A logical indicating whether there was an error in getting this
1130     //   information
1131     Int_t npar;
1132     gGeoManager->PushPath();
1133     if (!gGeoManager->cd(volumePath.Data())) {
1134         gGeoManager->PopPath();
1135         return kFALSE;
1136     }
1137     TGeoVolume * vol = gGeoManager->GetCurrentVolume();
1138     gGeoManager->PopPath();
1139     if (!vol) return kFALSE;
1140     TGeoShape *shape = vol->GetShape();
1141     TClass *classType = shape->IsA();
1142     if (classType==TGeoBBox::Class()) {
1143         shapeType = "BOX";
1144         npar = 3;
1145         par.Set(npar);
1146         TGeoBBox *box = (TGeoBBox*)shape;
1147         par.AddAt(box->GetDX(),0);
1148         par.AddAt(box->GetDY(),1);
1149         par.AddAt(box->GetDZ(),2);
1150         return kTRUE;
1151     } // end if
1152     if (classType==TGeoTrd1::Class()) {
1153         shapeType = "TRD1";
1154         npar = 4;
1155         par.Set(npar);
1156         TGeoTrd1 *trd1 = (TGeoTrd1*)shape;
1157         par.AddAt(trd1->GetDx1(),0);
1158         par.AddAt(trd1->GetDx2(),1);
1159         par.AddAt(trd1->GetDy(), 2);
1160         par.AddAt(trd1->GetDz(), 3);
1161         return kTRUE;
1162     } // end if
1163     if (classType==TGeoTrd2::Class()) {
1164         shapeType = "TRD2";
1165         npar = 5;
1166         par.Set(npar);
1167         TGeoTrd2 *trd2 = (TGeoTrd2*)shape;
1168         par.AddAt(trd2->GetDx1(),0);
1169         par.AddAt(trd2->GetDx2(),1);
1170         par.AddAt(trd2->GetDy1(),2);
1171         par.AddAt(trd2->GetDy2(),3);
1172         par.AddAt(trd2->GetDz(), 4);
1173         return kTRUE;
1174     } // end if
1175     if (classType==TGeoTrap::Class()) {
1176         shapeType = "TRAP";
1177         npar = 11;
1178         par.Set(npar);
1179         TGeoTrap *trap = (TGeoTrap*)shape;
1180         Double_t tth = TMath::Tan(trap->GetTheta()*TMath::DegToRad());
1181         par.AddAt(trap->GetDz(),0);
1182         par.AddAt(tth*TMath::Cos(trap->GetPhi()*TMath::DegToRad()),1);
1183         par.AddAt(tth*TMath::Sin(trap->GetPhi()*TMath::DegToRad()),2);
1184         par.AddAt(trap->GetH1(),3);
1185         par.AddAt(trap->GetBl1(),4);
1186         par.AddAt(trap->GetTl1(),5);
1187         par.AddAt(TMath::Tan(trap->GetAlpha1()*TMath::DegToRad()),6);
1188         par.AddAt(trap->GetH2(),7);
1189         par.AddAt(trap->GetBl2(),8);
1190         par.AddAt(trap->GetTl2(),9);
1191         par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
1192         return kTRUE;
1193     } // end if
1194     if (classType==TGeoTube::Class()) {
1195         shapeType = "TUBE";
1196         npar = 3;
1197         par.Set(npar);
1198         TGeoTube *tube = (TGeoTube*)shape;
1199         par.AddAt(tube->GetRmin(),0);
1200         par.AddAt(tube->GetRmax(),1);
1201         par.AddAt(tube->GetDz(),2);
1202         return kTRUE;
1203     } // end if
1204     if (classType==TGeoTubeSeg::Class()) {
1205         shapeType = "TUBS";
1206         npar = 5;
1207         par.Set(npar);
1208         TGeoTubeSeg *tubs = (TGeoTubeSeg*)shape;
1209         par.AddAt(tubs->GetRmin(),0);
1210         par.AddAt(tubs->GetRmax(),1);
1211         par.AddAt(tubs->GetDz(),2);
1212         par.AddAt(tubs->GetPhi1(),3);
1213         par.AddAt(tubs->GetPhi2(),4);
1214         return kTRUE;
1215     } // end if
1216     if (classType==TGeoCone::Class()) {
1217         shapeType = "CONE";
1218         npar = 5;
1219         par.Set(npar);
1220         TGeoCone *cone = (TGeoCone*)shape;
1221         par.AddAt(cone->GetDz(),0);
1222         par.AddAt(cone->GetRmin1(),1);
1223         par.AddAt(cone->GetRmax1(),2);
1224         par.AddAt(cone->GetRmin2(),3);
1225         par.AddAt(cone->GetRmax2(),4);
1226         return kTRUE;
1227     } // end if
1228     if (classType==TGeoConeSeg::Class()) {
1229         shapeType = "CONS";
1230         npar = 7;
1231         par.Set(npar);
1232         TGeoConeSeg *cons = (TGeoConeSeg*)shape;
1233         par.AddAt(cons->GetDz(),0);
1234         par.AddAt(cons->GetRmin1(),1);
1235         par.AddAt(cons->GetRmax1(),2);
1236         par.AddAt(cons->GetRmin2(),3);
1237         par.AddAt(cons->GetRmax2(),4);
1238         par.AddAt(cons->GetPhi1(),5);
1239         par.AddAt(cons->GetPhi2(),6);
1240         return kTRUE;
1241     } // end if
1242     if (classType==TGeoSphere::Class()) {
1243         shapeType = "SPHE";
1244         npar = 6;
1245         par.Set(npar);
1246         
1247         TGeoSphere *sphe = (TGeoSphere*)shape;
1248         par.AddAt(sphe->GetRmin(),0);
1249         par.AddAt(sphe->GetRmax(),1);
1250         par.AddAt(sphe->GetTheta1(),2);
1251         par.AddAt(sphe->GetTheta2(),3);
1252         par.AddAt(sphe->GetPhi1(),4);
1253         par.AddAt(sphe->GetPhi2(),5);
1254         return kTRUE;
1255     } // end if
1256     if (classType==TGeoPara::Class()) {
1257         shapeType = "PARA";
1258         npar = 6;
1259         par.Set(npar);
1260         TGeoPara *para = (TGeoPara*)shape;
1261         par.AddAt(para->GetX(),0);
1262         par.AddAt(para->GetY(),1);
1263         par.AddAt(para->GetZ(),2);
1264         par.AddAt(para->GetTxy(),3);
1265         par.AddAt(para->GetTxz(),4);
1266         par.AddAt(para->GetTyz(),5);
1267         return kTRUE;
1268     } // end if
1269     if (classType==TGeoPgon::Class()) {
1270         shapeType = "PGON";
1271         TGeoPgon *pgon = (TGeoPgon*)shape;
1272         Int_t nz = pgon->GetNz();
1273         const Double_t *rmin = pgon->GetRmin();
1274         const Double_t *rmax = pgon->GetRmax();
1275         const Double_t *z = pgon->GetZ();
1276         npar = 4 + 3*nz;
1277         par.Set(npar);
1278         par.AddAt(pgon->GetPhi1(),0);
1279         par.AddAt(pgon->GetDphi(),1);
1280         par.AddAt(pgon->GetNedges(),2);
1281         par.AddAt(pgon->GetNz(),3);
1282         for (Int_t i=0; i<nz; i++) {
1283             par.AddAt(z[i], 4+3*i);
1284             par.AddAt(rmin[i], 4+3*i+1);
1285             par.AddAt(rmax[i], 4+3*i+2);
1286         }
1287         return kTRUE;
1288     } // end if
1289     if (classType==TGeoPcon::Class()) {
1290         shapeType = "PCON";
1291         TGeoPcon *pcon = (TGeoPcon*)shape;
1292         Int_t nz = pcon->GetNz();
1293         const Double_t *rmin = pcon->GetRmin();
1294         const Double_t *rmax = pcon->GetRmax();
1295         const Double_t *z = pcon->GetZ();
1296         npar = 3 + 3*nz;
1297         par.Set(npar);
1298         par.AddAt(pcon->GetPhi1(),0);
1299         par.AddAt(pcon->GetDphi(),1);
1300         par.AddAt(pcon->GetNz(),2);
1301         for (Int_t i=0; i<nz; i++) {
1302             par.AddAt(z[i], 3+3*i);
1303             
1304             par.AddAt(rmin[i], 3+3*i+1);
1305             par.AddAt(rmax[i], 3+3*i+2);
1306         }
1307         return kTRUE;
1308     } // end if
1309     if (classType==TGeoEltu::Class()) {
1310         shapeType = "ELTU";
1311         npar = 3;
1312         par.Set(npar);
1313         TGeoEltu *eltu = (TGeoEltu*)shape;
1314         par.AddAt(eltu->GetA(),0);
1315         par.AddAt(eltu->GetB(),1);
1316         par.AddAt(eltu->GetDz(),2);
1317         return kTRUE;
1318     } // end if
1319     if (classType==TGeoHype::Class()) {
1320         shapeType = "HYPE";
1321         npar = 5;
1322         par.Set(npar);
1323         TGeoHype *hype = (TGeoHype*)shape;
1324         par.AddAt(TMath::Sqrt(hype->RadiusHypeSq(0.,kTRUE)),0);
1325         par.AddAt(TMath::Sqrt(hype->RadiusHypeSq(0.,kFALSE)),1);
1326         par.AddAt(hype->GetDZ(),2);
1327         par.AddAt(hype->GetStIn(),3);
1328         par.AddAt(hype->GetStOut(),4);
1329         return kTRUE;
1330     } // end if
1331     if (classType==TGeoGtra::Class()) {
1332         shapeType = "GTRA";
1333         npar = 12;
1334         par.Set(npar);
1335         TGeoGtra *trap = (TGeoGtra*)shape;
1336         Double_t tth = TMath::Tan(trap->GetTheta()*TMath::DegToRad());
1337         par.AddAt(trap->GetDz(),0);
1338         par.AddAt(tth*TMath::Cos(trap->GetPhi()*TMath::DegToRad()),1);
1339         par.AddAt(tth*TMath::Sin(trap->GetPhi()*TMath::DegToRad()),2);
1340         par.AddAt(trap->GetH1(),3);
1341         par.AddAt(trap->GetBl1(),4);
1342         par.AddAt(trap->GetTl1(),5);
1343         par.AddAt(TMath::Tan(trap->GetAlpha1()*TMath::DegToRad()),6);
1344         par.AddAt(trap->GetH2(),7);
1345         par.AddAt(trap->GetBl2(),8);
1346         par.AddAt(trap->GetTl2(),9);
1347         par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
1348         par.AddAt(trap->GetTwistAngle(),11);
1349         return kTRUE;
1350     } // end if
1351     if (classType==TGeoCtub::Class()) {
1352         shapeType = "CTUB";
1353         npar = 11;
1354         par.Set(npar);
1355         TGeoCtub *ctub = (TGeoCtub*)shape;
1356         const Double_t *lx = ctub->GetNlow();
1357         const Double_t *tx = ctub->GetNhigh();
1358         par.AddAt(ctub->GetRmin(),0);
1359         par.AddAt(ctub->GetRmax(),1);
1360         par.AddAt(ctub->GetDz(),2);
1361         par.AddAt(ctub->GetPhi1(),3);
1362         par.AddAt(ctub->GetPhi2(),4);
1363         par.AddAt(lx[0],5);
1364         par.AddAt(lx[1],6);
1365         par.AddAt(lx[2],7);
1366         par.AddAt(tx[0],8);
1367         par.AddAt(tx[1],9);
1368         par.AddAt(tx[2],10);
1369         return kTRUE;
1370     } // end if
1371     Error("GetShape","Getting shape parameters for shape %s not implemented",
1372           shape->ClassName());
1373     shapeType = "Unknown";
1374     return kFALSE;
1375 }
1376 //______________________________________________________________________
1377 void AliITSInitGeometry::DecodeDetector(
1378     Int_t &mod,Int_t layer,Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
1379     // decode geometry into detector module number. There are two decoding
1380     // Scheams. Old which does not follow the ALICE coordinate system
1381     // requirements, and New which dose.
1382     // Inputs:
1383     //    Int_t layer    The ITS layer
1384     //    Int_t cpn0     The lowest copy number
1385     //    Int_t cpn1     The middle copy number
1386     //    Int_t cpn2     the highest copy number
1387     // Output:
1388     //    Int_t &mod     The module number assoicated with this set
1389     //                   of copy numbers.
1390     // Return:
1391     //    none.
1392
1393     // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't 
1394     // like them but I see not better way for the moment.
1395     switch (fMajorVersion){
1396     case kvtest:{
1397         if(GetMinorVersion()==1)
1398             return DecodeDetectorvPPRasymmFMD(mod,layer,cpn0,cpn1,cpn2);
1399         else if(GetMinorVersion()==2)
1400             return DecodeDetectorvtest2(mod,layer,cpn0,cpn1,cpn2);
1401         Warning("DecodeDetector",
1402                 "Geometry is kvtest minor version=%d is not defined",
1403                 GetMinorVersion());
1404     }break;
1405     case kvDefault:{
1406         Error("DecodeDetector","Major version = kvDefault, not supported");
1407     }break;
1408     case kvSPD02:{
1409         return DecodeDetectorvSPD02(mod,layer,cpn0,cpn1,cpn2);
1410     }break;
1411     case kvSDD03:{
1412         return DecodeDetectorvSDD03(mod,layer,cpn0,cpn1,cpn2);
1413     }break;
1414     case kvSSD03:{
1415         return DecodeDetectorvSSD03(mod,layer,cpn0,cpn1,cpn2);
1416     }break;
1417     case kvITS04:{
1418         return DecodeDetectorvITS04(mod,layer,cpn0,cpn1,cpn2);
1419     }break;
1420     case kvPPRcourseasymm:{
1421         return DecodeDetectorvPPRcourseasymm(mod,layer,cpn0,cpn1,cpn2);
1422     }break;
1423     case kvPPRasymmFMD:{
1424         return DecodeDetectorvPPRasymmFMD(mod,layer,cpn0,cpn1,cpn2);
1425     }break;
1426     case kv11:{
1427         return DecodeDetectorv11(mod,layer,cpn0,cpn1,cpn2);
1428     }break;
1429     case kv11Hybrid:{
1430         return DecodeDetectorv11Hybrid(mod,layer,cpn0,cpn1,cpn2);
1431     }break;
1432     default:{
1433         Error("DecodeDetector","Major version = %d, not supported",
1434               (Int_t)fMajorVersion);
1435         return;
1436     }break;
1437     } // end switch
1438     return;
1439 }
1440 //______________________________________________________________________
1441 void AliITSInitGeometry::RecodeDetector(Int_t mod,Int_t &cpn0,
1442                                         Int_t &cpn1,Int_t &cpn2){
1443     // decode geometry into detector module number. There are two decoding
1444     // Scheams. Old which does not follow the ALICE coordinate system
1445     // requirements, and New which dose.
1446     // Inputs:
1447     //    Int_t mod      The module number assoicated with this set
1448     //                   of copy numbers.
1449     // Output:
1450     //    Int_t cpn0     The lowest copy number
1451     //    Int_t cpn1     The middle copy number
1452     //    Int_t cpn2     the highest copy number
1453     // Return:
1454     //    none.
1455
1456     // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't 
1457     // like them but I see not better way for the moment.
1458     switch (fMajorVersion){
1459     case kvtest:{
1460         if(GetMinorVersion()==1) 
1461             return RecodeDetectorvPPRasymmFMD(mod,cpn0,cpn1,cpn2);
1462         else if(GetMinorVersion()==2)
1463             return RecodeDetectorvtest2(mod,cpn0,cpn1,cpn2);
1464         Warning("RecodeDetector",
1465                 "Geometry is kvtest minor version=%d is not defined",
1466                 GetMinorVersion());
1467         return;
1468     }break;
1469     case kvDefault:{
1470         Error("RecodeDetector","Major version = kvDefault, not supported");
1471         return;
1472     }break;
1473     case kvSPD02:{
1474         return RecodeDetectorvSPD02(mod,cpn0,cpn1,cpn2);
1475     }break;
1476     case kvSDD03:{
1477         return RecodeDetectorvSDD03(mod,cpn0,cpn1,cpn2);
1478     }break;
1479     case kvSSD03:{
1480         return RecodeDetectorvSSD03(mod,cpn0,cpn1,cpn2);
1481     }break;
1482     case kvITS04:{
1483         return RecodeDetectorvITS04(mod,cpn0,cpn1,cpn2);
1484     }break;
1485     case kvPPRcourseasymm:{
1486         return RecodeDetectorvPPRcourseasymm(mod,cpn0,cpn1,cpn2);
1487     }break;
1488     case kvPPRasymmFMD:{
1489         return RecodeDetectorvPPRasymmFMD(mod,cpn0,cpn1,cpn2);
1490     }break;
1491     case kv11:{
1492         return RecodeDetectorv11(mod,cpn0,cpn1,cpn2);
1493     }break;
1494     case kv11Hybrid:{
1495         return RecodeDetectorv11Hybrid(mod,cpn0,cpn1,cpn2);
1496     }break;
1497     default:{
1498         Error("RecodeDetector","Major version = %d, not supported",
1499               (Int_t)fMajorVersion);
1500         return;
1501     }break;
1502     } // end switch
1503     return;
1504 }
1505 //______________________________________________________________________
1506 void AliITSInitGeometry::DecodeDetectorLayers(Int_t mod,Int_t &layer,
1507                                               Int_t &lad,Int_t &det){
1508     // decode geometry into detector module number. There are two decoding
1509     // Scheams. Old which does not follow the ALICE coordinate system
1510     // requirements, and New which dose. Note, this use of layer ladder
1511     // and detector numbers are strictly for internal use of this
1512     // specific code. They do not represent the "standard" layer ladder
1513     // or detector numbering except in a very old and obsoleate sence.
1514     // Inputs:
1515     //    Int_t mod      The module number assoicated with this set
1516     //                   of copy numbers.
1517     // Output:
1518     //    Int_t lay     The layer number
1519     //    Int_t lad     The ladder number
1520     //    Int_t det     the dettector number
1521     // Return:
1522     //    none.
1523
1524     // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't 
1525     // like them but I see not better way for the moment.
1526     switch (fMajorVersion){
1527     case kvtest:{
1528         if(GetMinorVersion()==1) 
1529             return DecodeDetectorLayersvPPRasymmFMD(mod,layer,lad,det);
1530         else if(GetMinorVersion()==2)
1531             return DecodeDetectorLayersvtest2(mod,layer,lad,det);
1532         Warning("DecodeDetectorLayers",
1533                 "Geometry is kvtest minor version=%d is not defined",
1534                 GetMinorVersion());
1535         return;
1536     }break;
1537     case kvDefault:{
1538         Error("DecodeDetectorLayers",
1539               "Major version = kvDefault, not supported");
1540         return;
1541     }break;
1542     case kvSPD02:{
1543         return DecodeDetectorLayersvSPD02(mod,layer,lad,det);
1544     }break;
1545     case kvSDD03:{
1546         return DecodeDetectorLayersvSDD03(mod,layer,lad,det);
1547     }break;
1548     case kvSSD03:{
1549         return DecodeDetectorLayersvSSD03(mod,layer,lad,det);
1550     }break;
1551     case kvITS04:{
1552         return DecodeDetectorLayersvITS04(mod,layer,lad,det);
1553     }break;
1554     case kvPPRcourseasymm:{
1555         return DecodeDetectorLayersvPPRcourseasymm(mod,layer,lad,det);
1556     }break;
1557     case kvPPRasymmFMD:{
1558         return DecodeDetectorLayersvPPRasymmFMD(mod,layer,lad,det);
1559     }break;
1560     case kv11:{
1561         return DecodeDetectorLayersv11(mod,layer,lad,det);
1562     }break;
1563     case kv11Hybrid:{
1564         return DecodeDetectorLayersv11Hybrid(mod,layer,lad,det);
1565     }break;
1566     default:{
1567         Error("DecodeDetectorLayers","Major version = %d, not supported",
1568               (Int_t)fMajorVersion);
1569         return;
1570     }break;
1571     } // end switch
1572     return;
1573 }
1574 //______________________________________________________________________
1575 void AliITSInitGeometry::DecodeDetectorvSPD02(
1576     Int_t &mod,Int_t ncpn,Int_t cpy0,Int_t cpy1,Int_t cpy2) const {
1577     // decode geometry into detector module number
1578     // Inputs:
1579     //    Int_t ncpn     The Number of copies of this volume
1580     //    Int_t cpy0     The lowest copy number
1581     //    Int_t cpy1     The middle copy number
1582     //    Int_t cpy2     the highest copy number
1583     // Output:
1584     //    Int_t &mod     The module number assoicated with this set
1585     //                   of copy numbers.
1586     // Return:
1587     //    none.
1588
1589     // detector = ladder = 1
1590     if(ncpn==4 && cpy1>2) mod = cpy1; // layer = 1,2
1591     else mod = cpy1-1; // layer = 4,5
1592     if(ncpn==1) mod = 2; // layer=3
1593     cpy0 = cpy2;
1594     return;
1595 }
1596 //______________________________________________________________________
1597 void AliITSInitGeometry::RecodeDetectorvSPD02(Int_t mod,Int_t &cpn0,
1598                                         Int_t &cpn1,Int_t &cpn2){
1599     // decode geometry into detector module number. There are two decoding
1600     // Scheams. Old which does not follow the ALICE coordinate system
1601     // requirements, and New which dose.
1602     // Inputs:
1603     //    Int_t mod      The module number assoicated with this set
1604     //                   of copy numbers.
1605     // Output:
1606     //    Int_t cpn0     The lowest copy number
1607     //    Int_t cpn1     The middle copy number
1608     //    Int_t cpn2     the highest copy number
1609     // Return:
1610     //    none.
1611
1612     cpn2 = 0;
1613     if(mod==2){
1614         cpn0 = 1;
1615         cpn1 = 1;
1616         return;
1617     } else if(mod<2){
1618         cpn0 = 1;
1619         cpn1 = mod+1;
1620     }else{
1621         cpn0 = 1;
1622         cpn1 = mod;
1623     } // end if
1624     return;
1625 }
1626 //______________________________________________________________________
1627 void AliITSInitGeometry::DecodeDetectorLayersvSPD02(Int_t mod,Int_t &lay,
1628                                                     Int_t &lad,Int_t &det){
1629     // decode geometry into detector module number. There are two decoding
1630     // Scheams. Old which does not follow the ALICE coordinate system
1631     // requirements, and New which dose. Note, this use of layer ladder
1632     // and detector numbers are strictly for internal use of this
1633     // specific code. They do not represent the "standard" layer ladder
1634     // or detector numbering except in a very old and obsoleate sence.
1635     // Inputs:
1636     //    Int_t mod      The module number assoicated with this set
1637     //                   of copy numbers.
1638     // Output:
1639     //    Int_t lay     The layer number
1640     //    Int_t lad     The ladder number
1641     //    Int_t det     the dettector number
1642     // Return:
1643     //    none.
1644
1645     lay = mod+1;
1646     lad = det = 1;
1647     return;
1648 }
1649 //______________________________________________________________________
1650 void AliITSInitGeometry::DecodeDetectorvSDD03(
1651     Int_t &mod,Int_t ncpys,Int_t cpy0,Int_t cpy1,Int_t cpy2) const {
1652     // decode geometry into detector module number. There are two decoding
1653     // Scheams. Old which does not follow the ALICE coordinate system
1654     // requirements, and New which dose.
1655     // Inputs:
1656     //    Int_t ncpys    The number of posible copies cpn1
1657     //    Int_t cpy0     The lowest copy number
1658     //    Int_t cpy1     The middle copy number
1659     //    Int_t cpy2     the highest copy number
1660     // Output:
1661     //    Int_t &mod     The module number assoicated with this set
1662     //                   of copy numbers.
1663     // Return:
1664     //    none.
1665
1666     if(ncpys==10){ // ITEL detectors
1667         if(cpy1>4) mod = cpy1+1;
1668         else mod = cpy1-1;
1669     }else{ // IDET detectors
1670         if(cpy1==1) mod = 4;
1671         else mod = 5;
1672     } // end if
1673     cpy0=cpy2;
1674     return;
1675 }
1676 //______________________________________________________________________
1677 void AliITSInitGeometry::RecodeDetectorvSDD03(Int_t mod,Int_t &cpn0,
1678                                         Int_t &cpn1,Int_t &cpn2){
1679     // decode geometry into detector module number. There are two decoding
1680     // Scheams. Old which does not follow the ALICE coordinate system
1681     // requirements, and New which dose.
1682     // Inputs:
1683     //    Int_t mod      The module number assoicated with this set
1684     //                   of copy numbers.
1685     // Output:
1686     //    Int_t cpn0     The lowest copy number
1687     //    Int_t cpn1     The middle copy number
1688     //    Int_t cpn2     the highest copy number
1689     // Return:
1690     //    none.
1691
1692     cpn0 = 1;
1693     cpn2 = 0;
1694     if(mod<4) cpn1 = mod+1;
1695     else if(mod==4||mod==5) cpn1 = mod-3;
1696     else cpn1 = mod-1;
1697     return;
1698 }
1699 //______________________________________________________________________
1700 void AliITSInitGeometry::DecodeDetectorLayersvSDD03(Int_t mod,Int_t &lay,
1701                                                     Int_t &lad,Int_t &det){
1702     // decode geometry into detector module number. There are two decoding
1703     // Scheams. Old which does not follow the ALICE coordinate system
1704     // requirements, and New which dose. Note, this use of layer ladder
1705     // and detector numbers are strictly for internal use of this
1706     // specific code. They do not represent the "standard" layer ladder
1707     // or detector numbering except in a very old and obsoleate sence.
1708     // Inputs:
1709     //    Int_t mod      The module number assoicated with this set
1710     //                   of copy numbers.
1711     // Output:
1712     //    Int_t lay     The layer number
1713     //    Int_t lad     The ladder number
1714     //    Int_t det     the dettector number
1715     // Return:
1716     //    none.
1717
1718     lad = det = 1;
1719     lay = mod+1;
1720     return;
1721 }
1722 //______________________________________________________________________
1723 void AliITSInitGeometry::DecodeDetectorvSSD03(
1724     Int_t &mod,Int_t dtype,Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
1725     // decode geometry into detector module number. There are two decoding
1726     // Scheams. Old which does not follow the ALICE coordinate system
1727     // requirements, and New which dose.
1728     // Inputs:
1729     //    Int_t dtype    The detector type 1=ITSA 2=IGAR 3=IFRA
1730     //    Int_t cpn0     The lowest copy number
1731     //    Int_t cpn1     The middle copy number
1732     //    Int_t cpn2     the highest copy number
1733     // Output:
1734     //    Int_t &mod     The module number assoicated with this set
1735     //                   of copy numbers.
1736     // Return:
1737     //    none.
1738
1739     if(dtype==2){mod=2; return;}
1740     if(dtype==3){mod=3; return;}
1741     mod = cpn0-1;
1742     if(cpn0==3) mod = 4;
1743     cpn1=cpn2;
1744     return;
1745 }
1746 //______________________________________________________________________
1747 void AliITSInitGeometry::RecodeDetectorvSSD03(Int_t mod,Int_t &cpn0,
1748                                         Int_t &cpn1,Int_t &cpn2){
1749     // decode geometry into detector module number. There are two decoding
1750     // Scheams. Old which does not follow the ALICE coordinate system
1751     // requirements, and New which dose.
1752     // Inputs:
1753     //    Int_t mod      The module number assoicated with this set
1754     //                   of copy numbers.
1755     // Output:
1756     //    Int_t cpn0     The lowest copy number
1757     //    Int_t cpn1     The middle copy number
1758     //    Int_t cpn2     the highest copy number
1759     // Return:
1760     //    none.
1761
1762     cpn1=1;
1763     cpn2=0;
1764     if(mod<2) cpn0=mod+1;
1765     else if (mod==2||mod==3) cpn0=1;
1766     else cpn0 = 3;
1767     return;
1768 }
1769 //______________________________________________________________________
1770 void AliITSInitGeometry::DecodeDetectorLayersvSSD03(Int_t mod,Int_t &lay,
1771                                                     Int_t &lad,Int_t &det){
1772     // decode geometry into detector module number. There are two decoding
1773     // Scheams. Old which does not follow the ALICE coordinate system
1774     // requirements, and New which dose. Note, this use of layer ladder
1775     // and detector numbers are strictly for internal use of this
1776     // specific code. They do not represent the "standard" layer ladder
1777     // or detector numbering except in a very old and obsoleate sence.
1778     // Inputs:
1779     //    Int_t mod      The module number assoicated with this set
1780     //                   of copy numbers.
1781     // Output:
1782     //    Int_t lay     The layer number
1783     //    Int_t lad     The ladder number
1784     //    Int_t det     the dettector number
1785     // Return:
1786     //    none.
1787
1788     lad = det = 1;
1789     lay = mod+1;
1790     return;
1791 }
1792 //______________________________________________________________________
1793 void AliITSInitGeometry::DecodeDetectorvITS04(
1794     Int_t &mod,Int_t dtype,Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
1795     // decode geometry into detector module number. There are two decoding
1796     // Scheams. Old which does not follow the ALICE coordinate system
1797     // requirements, and New which dose.
1798     // Inputs:
1799     //    Int_t dtype    The detector type 1=ITSA 2=IGAR 3=IFRA
1800     //    Int_t cpn0     The lowest copy number
1801     //    Int_t cpn1     The middle copy number
1802     //    Int_t cpn2     the highest copy number
1803     // Output:
1804     //    Int_t &mod     The module number assoicated with this set
1805     //                   of copy numbers.
1806     // Return:
1807     //    none.
1808
1809     mod = dtype-1;
1810     cpn0 = cpn1 = cpn2;
1811     return;
1812 }
1813 //______________________________________________________________________
1814 void AliITSInitGeometry::RecodeDetectorvITS04(Int_t mod,Int_t &cpn0,
1815                                         Int_t &cpn1,Int_t &cpn2){
1816     // decode geometry into detector module number. There are two decoding
1817     // Scheams. Old which does not follow the ALICE coordinate system
1818     // requirements, and New which dose.
1819     // Inputs:
1820     //    Int_t mod      The module number assoicated with this set
1821     //                   of copy numbers.
1822     // Output:
1823     //    Int_t cpn0     The lowest copy number
1824     //    Int_t cpn1     The middle copy number
1825     //    Int_t cpn2     the highest copy number
1826     // Return:
1827     //    none.
1828
1829     cpn1 = cpn2 = 0;
1830     switch(mod){
1831     case 0:case 1:case 2:case 3:{
1832         cpn0 = mod+1;
1833     }break;
1834     case 4: case 5:{
1835         cpn0 = mod-3;
1836     }break;
1837     case 6:case 7:case 8:case 9:{
1838         cpn0 = mod-5;
1839     } break;
1840     default:
1841         cpn0 = 0;
1842         break;
1843     }// end switch
1844     return;
1845 }
1846 //______________________________________________________________________
1847 void AliITSInitGeometry::DecodeDetectorLayersvITS04(Int_t mod,Int_t &lay,
1848                                                     Int_t &lad,Int_t &det){
1849     // decode geometry into detector module number. There are two decoding
1850     // Scheams. Old which does not follow the ALICE coordinate system
1851     // requirements, and New which dose. Note, this use of layer ladder
1852     // and detector numbers are strictly for internal use of this
1853     // specific code. They do not represent the "standard" layer ladder
1854     // or detector numbering except in a very old and obsoleate sence.
1855     // Inputs:
1856     //    Int_t mod      The module number assoicated with this set
1857     //                   of copy numbers.
1858     // Output:
1859     //    Int_t lay     The layer number
1860     //    Int_t lad     The ladder number
1861     //    Int_t det     the dettector number
1862     // Return:
1863     //    none.
1864
1865     lad = 1;
1866     switch(mod){
1867     case 0:case 1:case 2:case 3:{
1868         lay = mod/2 +1;
1869         det = mod%2 +1;
1870     }break;
1871     case 4: case 5:{
1872         lay = mod -1;
1873     }break;
1874     case 6:case 7:case 8:case 9:{
1875         lay = mod/2 +2;
1876         det = mod%2 +1;
1877     }break;
1878     default:
1879         lay = 0;
1880         det = 0;
1881         break;
1882     } // end switch
1883     return;
1884 }
1885 //______________________________________________________________________
1886 void AliITSInitGeometry::DecodeDetectorvPPRasymmFMD(Int_t &mod,Int_t layer,Int_t cpn0,
1887                                         Int_t cpn1,Int_t cpn2) const {
1888     // decode geometry into detector module number. There are two decoding
1889     // Scheams. Old which does not follow the ALICE coordinate system
1890     // requirements, and New which dose.
1891     // Inputs:
1892     //    Int_t layer    The ITS layer
1893     //    Int_t cpn0     The lowest copy number
1894     //    Int_t cpn1     The middle copy number
1895     //    Int_t cpn2     the highest copy number
1896     // Output:
1897     //    Int_t &mod     The module number assoicated with this set
1898     //                   of copy numbers.
1899     // Return:
1900     //    none.
1901     const Int_t kDetPerLadderSPD[2]={2,4};
1902     const Int_t kDetPerLadder[6]={4,4,6,8,22,25};
1903     const Int_t kLadPerLayer[6]={20,40,14,22,34,38};
1904     Int_t lay=-1,lad=-1,det=-1,i;
1905
1906     if(fDecode){ // New decoding scheam
1907         switch (layer){
1908         case 1:{
1909             lay = layer;
1910             det = 5-cpn2;
1911             if(cpn0==4&&cpn1==1) lad=1;
1912             else if(cpn0==4&&cpn1==2) lad=20;
1913             else if(cpn0<4){
1914                 lad = 8-cpn1-kDetPerLadderSPD[layer-1]*(cpn0-1);
1915             }else{ // cpn0>4
1916                 lad = 28-cpn1-kDetPerLadderSPD[layer-1]*(cpn0-1);
1917             } // end if
1918         } break;
1919         case 2:{
1920             lay = layer;
1921             det = 5-cpn2;
1922             if(cpn0==4&&cpn1==1) lad=1;
1923             else if(cpn0<4){
1924                 lad = 14-cpn1-kDetPerLadderSPD[layer-1]*(cpn0-1);
1925             }else{ // cpn0>4
1926                 lad = 54-cpn1-kDetPerLadderSPD[layer-1]*(cpn0-1);
1927             } // end if
1928         } break;
1929         case 3:{
1930             lay = layer;
1931             if(cpn0<5) lad = 5-cpn0;
1932             else lad = 19-cpn0;
1933             det = 7-cpn1;
1934         } break;
1935         case 4:{
1936             lay = layer;
1937             if(cpn0<7) lad = 7-cpn0;
1938             else lad = 29-cpn0;
1939             det = 9-cpn1;
1940         } break;
1941         case 5:{
1942             lay = layer;
1943             if(cpn0<10) lad = 10-cpn0;
1944             else lad = 44-cpn0;
1945             det = 23-cpn1;
1946         } break;
1947         case 6:{
1948             lay = layer;
1949             if(cpn0<9) lad = 9-cpn0;
1950             else lad = 47-cpn0;
1951             det = 26-cpn1;
1952         } break;
1953         } // end switch
1954         mod = 0;
1955         for(i=0;i<layer-1;i++) mod += kLadPerLayer[i]*kDetPerLadder[i];
1956         mod += kDetPerLadder[layer-1]*(lad-1)+det-1;// module start at zero.
1957         return;
1958     } // end if
1959     // Old decoding scheam
1960     switch(layer){
1961     case 1: case 2:{
1962         lay = layer;
1963         lad = cpn1+kDetPerLadderSPD[layer-1]*(cpn0-1);
1964         det = cpn2;
1965         }break;
1966     case 3: case 4:{
1967         lay = layer;
1968         lad = cpn0;
1969         det = cpn1;
1970         }break;
1971     case 5: case 6:{
1972         lay = layer;
1973         lad = cpn0;
1974         det = cpn1;
1975         }break;
1976     default:{
1977         }break;
1978     } // end switch
1979     mod = 0;
1980     for(i=0;i<layer-1;i++) mod += kLadPerLayer[i]*kDetPerLadder[i];
1981     mod += kDetPerLadder[layer-1]*(lad-1)+det-1;// module start at zero.
1982     return;
1983 }
1984 //______________________________________________________________________
1985 void AliITSInitGeometry::RecodeDetectorvPPRasymmFMD(Int_t mod,Int_t &cpn0,
1986                                         Int_t &cpn1,Int_t &cpn2){
1987     // decode geometry into detector module number. There are two decoding
1988     // Scheams. Old which does not follow the ALICE coordinate system
1989     // requirements, and New which dose.
1990     // Inputs:
1991     //    Int_t mod      The module number assoicated with this set
1992     //                   of copy numbers.
1993     // Output:
1994     //    Int_t cpn0     The lowest copy number
1995     //    Int_t cpn1     The middle copy number
1996     //    Int_t cpn2     the highest copy number
1997     // Return:
1998     //    none.
1999     const Int_t kITSgeoTreeCopys[6][3]= {{10, 2, 4},// lay=1
2000                                          {10, 4, 4},// lay=2
2001                                          {14, 6, 1},// lay=3
2002                                          {22, 8, 1},// lay=4
2003                                          {34,22, 1},// lay=5
2004                                          {38,25, 1}};//lay=6
2005     const Int_t kDetPerLadderSPD[2]={2,4};
2006     //    const Int_t kDetPerLadder[6]={4,4,6,8,22,25};
2007     //    const Int_t kLadPerLayer[6]={20,40,14,22,34,38};
2008     Int_t lay,lad,det;
2009
2010     cpn0 = cpn1 = cpn2 = 0;
2011     DecodeDetectorLayers(mod,lay,lad,det);
2012     if(fDecode){ // New decoding scheam
2013         switch (lay){
2014         case 1:{
2015             cpn2 = 5-det;     // Detector 1-4
2016             cpn1 = 1+(lad-1)%kDetPerLadderSPD[lay-1];
2017             cpn0 = 5-(lad+kDetPerLadderSPD[lay-1])/kDetPerLadderSPD[lay-1];
2018             if(mod>27) cpn0 = 15-(lad+kDetPerLadderSPD[lay-1])/
2019                            kDetPerLadderSPD[lay-1];
2020         } break;
2021         case 2:{
2022             cpn2 = 5-det;     // Detector 1-4
2023             cpn1 = 4-(lad+2)%kDetPerLadderSPD[lay-1];
2024             cpn0 = 1+(14-cpn1-lad)/kDetPerLadderSPD[lay-1];
2025             if(mod>131) cpn0 = 1+(54-lad-cpn1)/kDetPerLadderSPD[lay-1];
2026         } break;
2027         case 3:{
2028             cpn2 = 1;
2029             if(lad<5) cpn0 = 5-lad;
2030             else cpn0 = 19-lad;
2031             cpn1 = 7-det;
2032         } break;
2033         case 4:{
2034             cpn2 = 1;
2035             if(lad<7) cpn0 = 7-lad;
2036             else cpn0 = 29-lad;
2037             cpn1 = 9-det;
2038         } break;
2039         case 5:{
2040             cpn2 = 1;
2041             if(lad<10) cpn0 = 10-lad;
2042             else cpn0 = 44-lad;
2043             cpn1 = 23-det;
2044         } break;
2045         case 6:{
2046             cpn2 = 1;
2047             if(lad<9) cpn0 = 9-lad;
2048             else cpn0 = 47-lad;
2049             cpn1 = 26-det;
2050         } break;
2051         default:{
2052             Error("RecodeDetector","New: mod=%d lay=%d not 1-6.");
2053             return;
2054         } break;
2055         } // end switch
2056         if(cpn0<1||cpn1<1||cpn2<1||
2057            cpn0>kITSgeoTreeCopys[lay-1][0]||
2058            cpn1>kITSgeoTreeCopys[lay-1][1]||
2059            cpn2>kITSgeoTreeCopys[lay-1][2])
2060             Error("RecodeDetector",
2061                   "cpn0=%d cpn1=%d cpn2=%d mod=%d lay=%d lad=%d det=%d",
2062                   cpn0,cpn1,cpn2,mod,lay,lad,det);
2063         return;
2064     } // end if
2065     // Old encoding
2066     switch (lay){
2067     case 1: case 2:{
2068         cpn2 = det;     // Detector 1-4
2069         cpn0 = (lad+kDetPerLadderSPD[lay-1]-1)/kDetPerLadderSPD[lay-1];
2070         cpn1 = (lad+kDetPerLadderSPD[lay-1]-1)%kDetPerLadderSPD[lay-1] + 1;
2071     } break;
2072     case 3: case 4: case 5 : case 6:{
2073         cpn2 = 1;
2074         cpn1 = det;
2075         cpn0 = lad;
2076     } break;
2077     default:{
2078         Error("RecodeDetector","Old: mod=%d lay=%d not 1-6.");
2079         return;
2080     } break;
2081     } // end switch
2082     if(cpn0<1||cpn1<1||cpn2<1||
2083        cpn0>kITSgeoTreeCopys[lay-1][0]||
2084        cpn1>kITSgeoTreeCopys[lay-1][1]||
2085        cpn2>kITSgeoTreeCopys[lay-1][2])
2086         Error("RecodeDetector",
2087               "cpn0=%d cpn1=%d cpn2=%d mod=%d lay=%d lad=%d det=%d",
2088               cpn0,cpn1,cpn2,mod,lay,lad,det);
2089     return;
2090 }
2091 //______________________________________________________________________
2092 void AliITSInitGeometry::DecodeDetectorLayersvPPRasymmFMD(Int_t mod,Int_t &lay,
2093                                               Int_t &lad,Int_t &det){
2094     // decode geometry into detector module number. There are two decoding
2095     // Scheams. Old which does not follow the ALICE coordinate system
2096     // requirements, and New which dose. Note, this use of layer ladder
2097     // and detector numbers are strictly for internal use of this
2098     // specific code. They do not represent the "standard" layer ladder
2099     // or detector numbering except in a very old and obsoleate sence.
2100     // Inputs:
2101     //    Int_t mod      The module number assoicated with this set
2102     //                   of copy numbers.
2103     // Output:
2104     //    Int_t lay     The layer number
2105     //    Int_t lad     The ladder number
2106     //    Int_t det     the dettector number
2107     // Return:
2108     //    none.
2109   //    const Int_t kDetPerLadderSPD[2]={2,4};
2110     const Int_t kDetPerLadder[6]={4,4,6,8,22,25};
2111     const Int_t kLadPerLayer[6]={20,40,14,22,34,38};
2112     Int_t mod2;
2113
2114     det  = 0;
2115     lad  = 0;
2116     lay  = 0;
2117     mod2 = 0;
2118     do{
2119         mod2 += kLadPerLayer[lay]*kDetPerLadder[lay];
2120         lay++;
2121     }while(mod2<=mod); // end while
2122     if(lay>6||lay<1) Error("DecodeDetectorLayers","0<lay=%d>6",lay);
2123     mod2 -= kLadPerLayer[lay-1]*kDetPerLadder[lay-1];
2124     do{
2125         lad++;
2126         mod2 += kDetPerLadder[lay-1];
2127     }while(mod2<=mod); // end while
2128     if(lad>kLadPerLayer[lay-1]||lad<1) Error("DecodeDetectorLayers",
2129             "lad=%d>kLadPerLayer[lay-1=%d]=%d mod=%d mod2=%d",lad,lay-1,
2130                                             kLadPerLayer[lay-1],mod,mod2);
2131     mod2 -= kDetPerLadder[lay-1];
2132     det = mod-mod2+1;
2133     if(det>kDetPerLadder[lay-1]||det<1) Error("DecodeDetectorLayers",
2134            "det=%d>detPerLayer[lay-1=%d]=%d mod=%d mod2=%d lad=%d",det,
2135                                   lay-1,kDetPerLadder[lay-1],mod,mod2,lad);
2136     return;
2137 }
2138 //______________________________________________________________________
2139 void AliITSInitGeometry::DecodeDetectorv11Hybrid(Int_t &mod,Int_t layer,Int_t cpn0,
2140                                         Int_t cpn1,Int_t cpn2) const {
2141     // decode geometry into detector module number
2142     // Inputs:
2143     //    Int_t layer    The ITS layer
2144     //    Int_t cpn0     The lowest copy number
2145     //    Int_t cpn1     The middle copy number
2146     //    Int_t cpn2     the highest copy number
2147     // Output:
2148     //    Int_t &mod     The module number assoicated with this set
2149     //                   of copy numbers.
2150     // Return:
2151     //    none.
2152   const Int_t kDetPerLadderSPD[2]={2,4};
2153   const Int_t kDetPerLadder[6]={4,4,6,8,22,25};
2154   const Int_t kLadPerLayer[6]={20,40,14,22,34,38};
2155   Int_t lad=-1,det=-1,i;
2156   
2157   switch(layer) {
2158   case 1: case 2:{
2159     lad = cpn1+kDetPerLadderSPD[layer-1]*(cpn0-1);
2160     det = cpn2;
2161   } break;
2162   case 3: case 4:{
2163     if (SDDIsTGeoNative()) {
2164       lad = cpn0+1;
2165       det = cpn1+1;
2166     } else {
2167       lad = cpn0;
2168       det = cpn1;
2169     }
2170   } break;
2171   case 5: case 6:{
2172     if (SSDIsTGeoNative()) {
2173       lad = cpn0+1;
2174       det = cpn1+1;
2175     } else {
2176       lad = cpn0;
2177       det = cpn1;
2178     }
2179   } break;
2180   default:{
2181   } break;
2182   } // end switch
2183   mod = 0;
2184   for(i=0;i<layer-1;i++) mod += kLadPerLayer[i]*kDetPerLadder[i];
2185   mod += kDetPerLadder[layer-1]*(lad-1)+det-1;// module start at zero.
2186   return;
2187 }
2188 //______________________________________________________________________
2189 void AliITSInitGeometry::RecodeDetectorv11Hybrid(Int_t mod,Int_t &cpn0,
2190                                         Int_t &cpn1,Int_t &cpn2) {
2191     // decode geometry into detector module number. There are two decoding
2192     // Scheams. Old which does not follow the ALICE coordinate system
2193     // requirements, and New which dose.
2194     // Inputs:
2195     //    Int_t mod      The module number assoicated with this set
2196     //                   of copy numbers.
2197     // Output:
2198     //    Int_t cpn0     The lowest copy number
2199     //    Int_t cpn1     The middle copy number
2200     //    Int_t cpn2     the highest copy number
2201     // Return:
2202     //    none.
2203     const Int_t kITSgeoTreeCopys[6][3]= {{10, 2, 4},// lay=1
2204                                          {10, 4, 4},// lay=2
2205                                          {14, 6, 1},// lay=3
2206                                          {22, 8, 1},// lay=4
2207                                          {34,22, 1},// lay=5
2208                                          {38,25, 1}};//lay=6
2209     const Int_t kDetPerLadderSPD[2]={2,4};
2210     //    const Int_t kDetPerLadder[6]={4,4,6,8,22,25};
2211     //    const Int_t kLadPerLayer[6]={20,40,14,22,34,38};
2212     Int_t lay,lad,det;
2213
2214     cpn0 = cpn1 = cpn2 = 0;
2215     DecodeDetectorLayers(mod,lay,lad,det);
2216     // Old encoding
2217     switch (lay){
2218     case 1: case 2:{
2219         cpn2 = det;     // Detector 1-4
2220         cpn0 = (lad+kDetPerLadderSPD[lay-1]-1)/kDetPerLadderSPD[lay-1];
2221         cpn1 = (lad+kDetPerLadderSPD[lay-1]-1)%kDetPerLadderSPD[lay-1] + 1;
2222     } break;
2223     case 3: case 4: case 5 : case 6:{
2224         cpn2 = 1;
2225         cpn1 = det;
2226         cpn0 = lad;
2227     } break;
2228     default:{
2229         Error("RecodeDetector","Old: mod=%d lay=%d not 1-6.");
2230         return;
2231     } break;
2232     } // end switch
2233     if(cpn0<1||cpn1<1||cpn2<1||
2234        cpn0>kITSgeoTreeCopys[lay-1][0]||
2235        cpn1>kITSgeoTreeCopys[lay-1][1]||
2236        cpn2>kITSgeoTreeCopys[lay-1][2])
2237         Error("RecodeDetector",
2238               "cpn0=%d cpn1=%d cpn2=%d mod=%d lay=%d lad=%d det=%d",
2239               cpn0,cpn1,cpn2,mod,lay,lad,det);
2240     return;
2241 }
2242 //______________________________________________________________________
2243 void AliITSInitGeometry::DecodeDetectorLayersv11Hybrid(Int_t mod,Int_t &lay,
2244                                               Int_t &lad,Int_t &det) {
2245
2246     // decode geometry into detector module number for v11Hybrid
2247     // Inputs:
2248     //    Int_t mod      The module number assoicated with this set
2249     //                   of copy numbers.
2250     // Output:
2251     //    Int_t lay     The layer number
2252     //    Int_t lad     The ladder number
2253     //    Int_t det     the dettector number
2254     // Return:
2255     //    none.
2256
2257     const Int_t kDetPerLadder[6]={4,4,6,8,22,25};
2258     const Int_t kLadPerLayer[6]={20,40,14,22,34,38};
2259     Int_t mod2;
2260
2261     det  = 0;
2262     lad  = 0;
2263     lay  = 0;
2264     mod2 = 0;
2265     do{
2266         mod2 += kLadPerLayer[lay]*kDetPerLadder[lay];
2267         lay++;
2268     } while(mod2<=mod); // end while
2269     if(lay>6||lay<1) Error("DecodeDetectorLayers","0<lay=%d>6",lay);
2270     mod2 -= kLadPerLayer[lay-1]*kDetPerLadder[lay-1];
2271     do{
2272         lad++;
2273         mod2 += kDetPerLadder[lay-1];
2274     } while(mod2<=mod); // end while
2275     if(lad>kLadPerLayer[lay-1]||lad<1) Error("DecodeDetectorLayers",
2276             "lad=%d>kLadPerLayer[lay-1=%d]=%d mod=%d mod2=%d",lad,lay-1,
2277                                             kLadPerLayer[lay-1],mod,mod2);
2278     mod2 -= kDetPerLadder[lay-1];
2279     det = mod-mod2+1;
2280     if(det>kDetPerLadder[lay-1]||det<1) Error("DecodeDetectorLayers",
2281            "det=%d>detPerLayer[lay-1=%d]=%d mod=%d mod2=%d lad=%d",det,
2282                                   lay-1,kDetPerLadder[lay-1],mod,mod2,lad);
2283     return;
2284 }
2285
2286 //______________________________________________________________________
2287 Bool_t AliITSInitGeometry::WriteVersionString(Char_t *str,Int_t length,
2288                         AliITSVersion_t maj,Int_t min,
2289                         const Char_t *cvsDate,const Char_t *cvsRevision)const{
2290     // fills the string str with the major and minor version number
2291     // Inputs:
2292     //   Char_t *str          The character string to hold the major 
2293     //                        and minor version numbers in
2294     //   Int_t  length        The maximum number of characters which 
2295     //                        can be accomidated by this string. 
2296     //                        str[length-1] must exist and will be set to zero
2297     //   AliITSVersion_t maj  The major number
2298     //   Int_t           min  The minor number
2299     //   Char_t *cvsDate      The date string from cvs
2300     //   Char_t *cvsRevision  The Revision string from cvs
2301     // Outputs:
2302     //   Char_t *str          The character string holding the major and minor
2303     //                        version numbers. str[length-1] must exist
2304     //                        and will be set to zero
2305     // Return:
2306     //   kTRUE if no errors
2307     Int_t i,n,cvsDateLength,cvsRevisionLength;
2308
2309     cvsDateLength = (Int_t)strlen(cvsDate);
2310     cvsRevisionLength = (Int_t)strlen(cvsRevision);
2311     i = (Int_t)maj;
2312     n = 50+(Int_t)(TMath::Log10(TMath::Abs((Double_t)i)))+1+
2313         (Int_t)(TMath::Log10(TMath::Abs((Double_t)min)))+1
2314         +cvsDateLength-6+cvsRevisionLength-10;
2315     if(GetDebug()>1) printf("AliITSInitGeometry::WriteVersionString:"
2316                         "length=%d major=%d minor=%d cvsDate=%s[%d] "
2317                         "cvsRevision=%s[%d] n=%d\n",length,i,min,cvsDate,
2318                         cvsDateLength,cvsRevision,cvsRevisionLength,n);
2319     if(i<0) n++;
2320     if(min<0) n++;
2321     if(length<n){// not enough space to write in output string.
2322         Warning("WriteVersionString","Output string not long enough "
2323                 "lenght=%d must be at least %d long\n",length,n);
2324         return kFALSE;
2325     } // end if length<n
2326     char *cvsrevision = new char[cvsRevisionLength-10];
2327     char *cvsdate = new char[cvsDateLength-6];
2328     for(i=0;i<cvsRevisionLength-10;i++)
2329         if(10+i<cvsRevisionLength-1)
2330             cvsrevision[i] = cvsRevision[10+i]; else cvsrevision[i] = 0;
2331     for(i=0;i<cvsDateLength-6;i++) if(6+i<cvsDateLength-1)
2332         cvsdate[i] = cvsDate[6+i]; else cvsdate[i] = 0;
2333     for(i=0;i<length;i++) str[i] = 0; // zero it out for now.
2334     i = (Int_t)maj;
2335     sprintf(str,"Major Version= %d Minor Version= %d Revision: %s Date: %s",
2336             i,min,cvsrevision,cvsdate);
2337     if(GetDebug()>1)printf("AliITSInitGeometry::WriteVersionString: "
2338                        "n=%d str=%s revision[%zu] date[%zu]\n",
2339                        n,str,strlen(cvsrevision),strlen(cvsdate));
2340     delete[] cvsrevision;
2341     delete[] cvsdate;
2342     return kTRUE;
2343 }
2344 //______________________________________________________________________
2345 Bool_t AliITSInitGeometry::ReadVersionString(const Char_t *str,Int_t length,
2346                                              AliITSVersion_t &maj,Int_t &min,
2347                                              TDatime &dt)const{
2348     // fills the string str with the major and minor version number
2349     // Inputs:
2350     //   Char_t *str   The character string to holding the major and minor
2351     //                 version numbers in
2352     //   Int_t  length The maximum number of characters which can be
2353     //                 accomidated by this string. str[length-1] must exist
2354     // Outputs:
2355     //   Char_t *str   The character string holding the major and minor
2356     //                 version numbers unchanged. str[length-1] must exist.
2357     //   AliITSVersion_t maj  The major number
2358     //   Int_t           min  The minor number
2359     //   TDatime         dt   The date and time of the cvs commit
2360     // Return:
2361     //   kTRUE if no errors
2362     Bool_t ok;
2363     Char_t cvsRevision[10],cvsDate[11],cvsTime[9];
2364     Int_t i,m,n=strlen(str),year,month,day,hours,minuits,seconds;
2365
2366     if(GetDebug()>1)printf("AliITSInitGeometry::ReadVersionString:"
2367                        "str=%s length=%d\n",
2368                        str,length);
2369     if(n<35) return kFALSE; // not enough space for numbers
2370     m = sscanf(str,"Major Version= %d  Minor Version= %d Revision: %s "
2371                "Date: %s %s",&i,&min,cvsRevision,cvsDate,cvsTime);
2372     ok = m==5;
2373     if(!ok) return !ok;
2374     m = sscanf(cvsDate,"%d/%d/%d",&year,&month,&day);
2375     ok = m==3;
2376     if(!ok) return !ok;
2377     m = sscanf(cvsTime,"%d:%d:%d",&hours,&minuits,&seconds);
2378     ok = m==3;
2379     if(!ok) return !ok;
2380     dt.Set(year,month,day,hours,minuits,seconds);
2381     if(GetDebug()>1)printf("AliITSInitGeometry::ReadVersionString: i=%d min=%d "
2382                        "cvsRevision=%s cvsDate=%s cvsTime=%s m=%d\n",
2383                        i,min,cvsRevision,cvsDate,cvsTime,m);
2384     if(GetDebug()>1)printf("AliITSInitGeometry::ReadVersionString: year=%d"
2385                        " month=%d day=%d hours=%d minuits=%d seconds=%d\n",
2386                        year,month,day,hours,minuits,seconds);
2387     switch (i){
2388     case kvITS04:{
2389         maj = kvITS04;
2390     } break;
2391     case kvSPD02:{
2392         maj = kvSPD02;
2393     } break;
2394     case kvSDD03:{
2395         maj = kvSDD03;
2396     } break;
2397     case kvSSD03:{
2398         maj = kvSSD03;
2399     } break;
2400     case kvPPRasymmFMD:{
2401         maj = kvPPRasymmFMD;
2402     } break;
2403     case kv11:{
2404         maj = kv11;
2405     } break;
2406     case kv11Hybrid:{
2407         maj = kv11Hybrid;
2408     } break;
2409     default:{
2410         maj = kvDefault;
2411     } break;
2412     } // end switch
2413     return ok;
2414 }