]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSvBeamTestITS04.cxx
Removing extra line, adding EINCLUDE
[u/mrichter/AliRoot.git] / ITS / AliITSvBeamTestITS04.cxx
1 ////////////////////////////////////////////////////////
2 // ITS geometry class and step manager for the        //
3 //   integrated ITS test beam of Nov. 04              //
4 //  Author: mercedes.lopez.noriega@cern.ch            //
5 ////////////////////////////////////////////////////////
6
7 #include <TLorentzVector.h>
8
9 #include <TGeoManager.h>
10 #include <TGeoVolume.h>
11 #include <TGeoMatrix.h>
12 #include <TGeoPcon.h>
13 #include "AliRun.h"
14 #include "AliITSvBeamTestITS04.h"
15 #include <TClonesArray.h>
16 #include <TString.h>
17 #include "AliITS.h"
18 #include "AliMagF.h"
19 #include "TVirtualMC.h"
20 #include "AliMC.h"
21 #include "AliTrackReference.h"
22 #include "AliITSgeom.h"
23 #include "AliITShit.h"
24
25 const Int_t AliITSvBeamTestITS04::fgkNumberOfSPD = 4;
26 const Int_t AliITSvBeamTestITS04::fgkNumberOfSDD = 2;
27 const Int_t AliITSvBeamTestITS04::fgkNumberOfSSD = 4;
28 // Dimension (thickness:Y (beam direction), width:X, length:Z)
29
30 const char*    AliITSvBeamTestITS04::fgSPDsensitiveVolName = "ITSspdSensitiv";
31 //dimensions (preliminary values from Petra (in cms))
32 const Double_t AliITSvBeamTestITS04::fgkSPDthickness    = 0.02;
33 const Double_t AliITSvBeamTestITS04::fgkSPDwidth        = 1.4; 
34 const Double_t AliITSvBeamTestITS04::fgkSPDlength       = 7.2;
35 const Double_t AliITSvBeamTestITS04::fgkSPDthickSens    = 0.02;
36 const Double_t AliITSvBeamTestITS04::fgkSPDwidthSens    = 1.2; 
37 const Double_t AliITSvBeamTestITS04::fgkSPDlengthSens   = 7.0;
38 //position
39 const Double_t AliITSvBeamTestITS04::fgkSPD0y = 23.7;
40 const Double_t AliITSvBeamTestITS04::fgkSPD1y = 33.7;
41
42 //===
43 const char*    AliITSvBeamTestITS04::fgSDDsensitiveVolName = "ITSsddSensitiv";
44 //dimensions (preliminary values from Ludovic (in cms))
45 const Double_t AliITSvBeamTestITS04::fgkSDDthickness     = 0.03;
46 const Double_t AliITSvBeamTestITS04::fgkSDDwidth         = 7.22;
47 const Double_t AliITSvBeamTestITS04::fgkSDDlength        = 8.76;
48 const Double_t AliITSvBeamTestITS04::fgkSDDthickSens     = 0.02998;
49 const Double_t AliITSvBeamTestITS04::fgkSDDwidthSens     = 7.017;
50 const Double_t AliITSvBeamTestITS04::fgkSDDlengthSens    = 7.497;
51 //position
52 const Double_t AliITSvBeamTestITS04::fgkSDD0y = 51.7;
53 const Double_t AliITSvBeamTestITS04::fgkSDD1y = 57.2;
54
55 //===
56 const char*    AliITSvBeamTestITS04::fgSSDsensitiveVolName = "ITSssdSensitiv";
57 //dimensions (final values from Javier (in cms))
58 const Double_t AliITSvBeamTestITS04::fgkSSDthickness    = 0.03;
59 const Double_t AliITSvBeamTestITS04::fgkSSDwidth        = 7.7;
60 const Double_t AliITSvBeamTestITS04::fgkSSDlength       = 4.4;
61 const Double_t AliITSvBeamTestITS04::fgkSSDthickSens    = 0.03;
62 const Double_t AliITSvBeamTestITS04::fgkSSDwidthSens    = 7.5;
63 const Double_t AliITSvBeamTestITS04::fgkSSDlengthSens   = 4.2;
64 //position
65 const Double_t AliITSvBeamTestITS04::fgkSSD0y = 73.6;
66 const Double_t AliITSvBeamTestITS04::fgkSSD1y = 80.6;
67
68 //===============================================================
69
70
71
72 ClassImp(AliITSvBeamTestITS04)
73     
74 //_____________________________________________________________
75   AliITSvBeamTestITS04::AliITSvBeamTestITS04() : 
76 AliITS(),              // Base class
77 fITSmotherVolume(0),   // Pointer to ITS mother volume.
78 fNspd(fgkNumberOfSPD), //Number of SPD modules
79 fNsdd(fgkNumberOfSDD), //Number of SDD modules
80 fNssd(fgkNumberOfSSD), //Number of SSD modules
81 fGeomDetOut(kFALSE),   // Flag to write .det file out
82 fGeomDetIn(kFALSE),    // Flag to read geometry file (JC)
83 fWrite(),              //! file name to write .det file 
84 fRead(),               // file name to read .det file (JC)
85 fMajorVersion(kvITS04),// Major Version
86 fMinorVersion(1),      // Minor Version
87 fIgm(kvITS04)          //! Init geometry object
88 {
89     //
90     // Constructor
91     //
92
93     fIdN = 3;         
94     fIdName    = new TString[fIdN];
95     fIdName[0] = fgSPDsensitiveVolName;
96     fIdName[1] = fgSDDsensitiveVolName;
97     fIdName[2] = fgSSDsensitiveVolName;
98     fIdSens    = new Int_t[fIdN];
99     for(Int_t i=0; i<fIdN; i++) fIdSens[i] = 0;
100     
101     for(Int_t a=0;a<60;a++) fWrite[a] = '\0';
102 }
103 //_____________________________________________________________
104 AliITSvBeamTestITS04::AliITSvBeamTestITS04(const char* name,const char *title):
105 AliITS(name,title),   // Base class
106 fITSmotherVolume(0),   // Pointer to ITS mother volume.
107 fNspd(fgkNumberOfSPD), //Number of SPD modules
108 fNsdd(fgkNumberOfSDD), //Number of SDD modules
109 fNssd(fgkNumberOfSSD), //Number of SSD modules
110 fGeomDetOut(kFALSE),   // Flag to write .det file out
111 fGeomDetIn(kFALSE),    // Flag to read geometry file (JC)
112 fWrite(),              //! file name to write .det file 
113 fRead(),               // file name to read .det file (JC)
114 fMajorVersion(kvITS04),// Major Version
115 fMinorVersion(1),       // Minor Version
116 fIgm(kvITS04)          //! Init geometry object
117 {
118     //
119     // Constructor
120     //
121
122     fIdN = 3;         
123     fIdName    = new TString[fIdN];
124     fIdName[0] = fgSPDsensitiveVolName;
125     fIdName[1] = fgSDDsensitiveVolName;
126     fIdName[2] = fgSSDsensitiveVolName;
127     fIdSens    = new Int_t[fIdN];
128     for(Int_t i=0; i<fIdN; i++) fIdSens[i] = 0;
129     for(Int_t a=0;a<60;a++) fWrite[a] = '\0';    
130 }
131 //__________________________________________________________________
132 AliITSvBeamTestITS04::~AliITSvBeamTestITS04(){
133     //
134     // Destructor
135     //
136 }
137 //______________________________________________________________________
138 void AliITSvBeamTestITS04::CreateMaterials(){
139     // Media defined here should correspond to the one defined in galice.cuts
140     // This file is read in (AliMC*) fMCApp::Init() { ReadTransPar(); }
141     // Create ITS materials
142     Int_t   ifield = gAlice->Field()->Integ();
143     Float_t fieldm = gAlice->Field()->Max();
144     
145     Float_t tmaxfdSi = 0.1;
146     Float_t stemaxSi = 0.0075;
147     Float_t deemaxSi = 0.1;
148     Float_t epsilSi  = 1.0E-4;
149     Float_t stminSi  = 0.0;
150     
151     Float_t tmaxfdAir = 0.1;
152     Float_t stemaxAir = .10000E+01;
153     Float_t deemaxAir = 0.1;
154     Float_t epsilAir  = 1.0E-4;
155     Float_t stminAir  = 0.0;
156  
157     // AIR
158     Float_t aAir[4]={12.0107,14.0067,15.9994,39.948};
159     Float_t zAir[4]={6.,7.,8.,18.};
160     Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
161     Float_t dAir = 1.20479E-3;
162     
163     AliMaterial(51,"ITSspdSi",0.28086E+02,0.14000E+02,0.23300E+01,0.93600E+01,0.99900E+03);
164     AliMedium(51,"ITSspdSi",51,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
165     
166     AliMaterial(1,"ITSsddSi",0.28086E+02,0.14000E+02,0.23300E+01,0.93600E+01,0.99900E+03);
167     AliMedium(1,"ITSsddSi",1,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
168     
169     //AliMaterial(?,"ITSssdSi",0.28086E+02,0.14000E+02,0.23300E+01,0.93600E+01,0.99900E+03);
170     //AliMedium(?,"ITSssdSi",51,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
171     
172     AliMixture(5,"ITSair",aAir,zAir,dAir,4,wAir);
173     AliMedium(5,"ITSair",5,0,ifield,fieldm,tmaxfdAir,stemaxAir,deemaxAir,epsilAir,stminAir);
174     
175 //NEED TO ADD PLASTIC OF SCINTILLATORS!!
176
177 }
178
179 //______________________________________________________________________
180 void AliITSvBeamTestITS04::CreateGeometry(){    
181     //Creates geometry
182     // These constant character strings are set by cvs during commit
183     // do not change them unless you know what you are doing!
184     const Char_t *cvsDate="$Date$";
185     const Char_t *cvsRevision="$Revision$";
186     TGeoManager *geoManager = gGeoManager;
187     TGeoVolume *vALIC = geoManager->GetTopVolume();
188     
189     //================================
190     //       ITS mother volume
191     //================================
192     TGeoPcon *sITS = new TGeoPcon("ITS Top Volume",0.0,360.0,2);
193     // DefineSection(section number, Z, Rmin, Rmax).
194     sITS->DefineSection(0,-100.0,0.01,100.0); // Units in cms
195     sITS->DefineSection(1,+100.0,0.01,100.0);
196     
197     TGeoMedium *air = geoManager->GetMedium("ITSair");
198     fITSmotherVolume = new TGeoVolume("ITSV",sITS,air);
199     const Int_t kLength=100;
200     Char_t vstrng[kLength];
201     if(fIgm.WriteVersionString(vstrng,kLength,(AliITSVersion_t)IsVersion(),
202                                fMinorVersion,cvsDate,cvsRevision))
203         fITSmotherVolume->SetTitle(vstrng);
204     else Error("CreateGeometry","Error writing/setting version string");
205     //printf("Title set to %s\n",vstrng);
206     if(vALIC==0) {
207         Error("CreateGeometry","alic=0");
208         return;
209     } // end if
210     fITSmotherVolume->SetVisibility(kFALSE);
211     vALIC->AddNode(fITSmotherVolume,1,0);
212     
213 //     //Scintillators
214 //     TGeoMedium *plasticScint = new TGeoMedium("plasticScint",1,Plastic);
215 //     //First Scintillator
216 //     TGeoBBox *Scint1Shape = new TGeoBBox("Scint1Shape",0.5,0.1,0.5,0); //1x1cm
217 //     TGeoVolume *Scint1 = new TGeoVolume("Scint1",Scint1Shape,plasticScint);
218 //     TGeoTranslation *firstScint = new TGeoTranslation(0,0.7,0);
219 //     vALIC->AddNode(Scint1,2,firstScint);
220 //     //Second Scintillator
221 //     TGeoBBox *Scint2Shape = new TGeoBBox("Scint2Shape",1.,0.1,1.,0); //2x2cm
222 //     TGeoVolume *Scint2 = new TGeoVolume("Scint2",Scint2Shape,plasticScint);
223 //     TGeoTranslation *secondScint = new TGeoTranslation(0,90.,0);
224 //     vALIC->AddNode(Scint2,3,secondScint);
225     
226     AddSPDGeometry(fITSmotherVolume);
227     AddSDDGeometry(fITSmotherVolume);
228     AddSSDGeometry(fITSmotherVolume);
229 }
230
231 //______________________________________________________________________
232 void AliITSvBeamTestITS04::Init()
233 {
234     // Initialize the ITS after it has been created.
235     // Inputs:
236     //   none.
237     // Outputs:
238     //   none.
239     // Return:
240     //   none.
241
242     AliDebug(1,Form("Init: Major version %d Minor version %d",fMajorVersion,
243                  fMinorVersion));
244     //
245     UpdateInternalGeometry();
246     AliITS::Init();
247     if(fGeomDetOut) GetITSgeom()->WriteNewFile(fWrite);
248
249     //
250 }
251 /*
252 //______________________________________________________________________
253 void AliITSvBeamTestITS04::InitAliITSgeom()
254 {    
255   //initialisation of ITSgeom
256     const Int_t knlayers = 6;
257     Int_t nlad[knlayers], ndet[knlayers];
258     
259     nlad[0] = 1; ndet[0] = 2;
260     nlad[1] = 1; ndet[1] = 2;
261     nlad[2] = 1; ndet[2] = 1;
262     nlad[3] = 1; ndet[3] = 1;
263     nlad[4] = 1; ndet[4] = 2;
264     nlad[5] = 1; ndet[5] = 2;
265
266     Int_t nModTot = fNspd + fNsdd + fNssd;
267     if (GetITSgeom()) SetITSgeom(0x0);
268     AliITSgeom* geom = new AliITSgeom(0,knlayers,nlad,ndet,nModTot);
269     SetITSgeom(geom);
270     // *** Set default shapes 
271     const Float_t kDxyzSPD[] = {fgkSPDwidthSens/2, fgkSPDthickSens/2,fgkSPDlengthSens/2};  
272     if(!(GetITSgeom()->IsShapeDefined(kSPD)))
273         GetITSgeom()->ReSetShape(kSPD,new AliITSgeomSPD425Short(3,(Float_t *)kDxyzSPD));
274     
275     const Float_t kDxyzSDD[] = {fgkSDDwidthSens/2., fgkSDDthickSens/2.,fgkSDDlengthSens/2.};
276     if(!(GetITSgeom()->IsShapeDefined(kSDD)))
277         GetITSgeom()->ReSetShape(kSDD, new AliITSgeomSDD256(3,(Float_t *)kDxyzSDD));
278     
279     const Float_t kDxyzSSD[] = {fgkSSDlengthSens/2, fgkSSDthickSens/2,fgkSSDwidthSens/2};
280     if(!(GetITSgeom()->IsShapeDefined(kSSD)))
281         GetITSgeom()->ReSetShape(kSSD,new AliITSgeomSSD75and275(3,(Float_t *)kDxyzSSD));
282     
283     // Creating the matrices in AliITSgeom for each sensitive volume
284     // (like in AliITSv11GeometrySDD) mln
285     // Here, each layer is one detector
286     
287     char layerName[30];
288     Int_t startMod = 0;
289     
290     // SPD
291     for (Int_t i=0; i<fNspd;i++) {
292         sprintf(layerName, "ITSspdWafer_%i",i+1);
293         TGeoNode *layNode = fITSmotherVolume->GetNode(layerName);
294         if (layNode) {
295             TGeoHMatrix layMatrix(*layNode->GetMatrix());           
296             Double_t *trans  = layMatrix.GetTranslation();
297             Double_t *r      = layMatrix.GetRotationMatrix();
298             Double_t rot[10] = {r[0],r[1],r[2],
299                                 r[3],r[4],r[5],
300                                 r[6],r[7],r[8], 1.0};
301             Int_t iDet = 1;
302             if ((i+1==2)||(i+1==4)) iDet = 2;
303             Int_t iLad = 1;
304             Int_t iLay = 1;
305             if (i+1>2) iLay = 2;
306             GetITSgeom()->CreateMatrix(startMod,iLay,iLad,iDet,kSPD,trans,rot);
307             startMod++;
308         };
309     };
310     
311     // SDD
312     for (Int_t i=0; i<fNsdd;i++) {
313         sprintf(layerName, "ITSsddWafer_%i",i+fNspd+1);
314         TGeoNode *layNode = fITSmotherVolume->GetNode(layerName);
315         if (layNode) {
316             TGeoHMatrix layMatrix(*layNode->GetMatrix());
317             Double_t *trans  = layMatrix.GetTranslation();
318             Double_t *r      = layMatrix.GetRotationMatrix();
319             Double_t rot[10] = {r[0],r[1],r[2],
320                                 r[3],r[4],r[5],
321                                 r[6],r[7],r[8], 1.0};
322             Int_t iDet = 1;
323             Int_t iLad = 1;
324             Int_t iLay = fNspd-1+i;
325             GetITSgeom()->CreateMatrix(startMod,iLay,iLad,iDet,kSDD,trans,rot);
326             startMod++;
327         };
328     };
329     
330     // SSD
331     for (Int_t i=0; i<fNssd;i++) {
332         sprintf(layerName, "ITSssdWafer_%i",i+fNspd+fNsdd+1);
333         TGeoNode *layNode = fITSmotherVolume->GetNode(layerName);
334         if (layNode) {
335             TGeoHMatrix layMatrix(*layNode->GetMatrix());           
336             Double_t *trans  = layMatrix.GetTranslation();
337             Double_t *r      = layMatrix.GetRotationMatrix();
338             Double_t rot[10] = {r[0],r[1],r[2],
339                                 r[3],r[4],r[5],
340                                 r[6],r[7],r[8], 1.0};
341             Int_t iDet = 1;
342             if ((i+1==2)||(i+1==4)) iDet = 2;
343             Int_t iLad = 1;
344             Int_t iLay = 5;
345             if (i+1>2) iLay = 6;
346             GetITSgeom()->CreateMatrix(startMod,iLay,iLad,iDet,kSSD,trans,rot);
347             startMod++;
348         };
349     };
350     
351     return;
352 }
353 //______________________________________________________________________
354 void AliITSvBeamTestITS04::SetDefaults()
355 {
356     // (from AliITSv11) mln
357     
358     const Float_t kconv = 1.0e+04; // convert cm to microns
359     
360     if(!fDetTypeSim) fDetTypeSim = new AliITSDetTypeSim();
361     fDetTypeSim->SetITSgeom(GetITSgeom());
362     fDetTypeSim->ResetCalibrationArray();
363     fDetTypeSim->ResetSegmentation();
364  
365     AliITSgeomSPD *s0;
366     AliITSgeomSDD *s1;
367     AliITSgeomSSD *s2;
368     Int_t i;
369     Float_t bx[256],bz[280];
370
371     // If fGeomDetIn is set true the geometry will
372     // be initialised from file (JC)
373     if(GetITSgeom()!=0) SetITSgeom(0x0);
374     AliITSgeom* geom = new AliITSgeom();
375     SetITSgeom(geom);
376     if(fGeomDetIn) GetITSgeom()->ReadNewFile(fRead);
377     if(!fGeomDetIn) this->InitAliITSgeom();
378     if(fGeomDetOut) GetITSgeom()->WriteNewFile(fWrite);
379
380    
381     // SPD
382
383     s0 = (AliITSgeomSPD*) GetITSgeom()->GetShape(kSPD);// Get shape info.
384     if (s0) {
385         AliITSCalibration *resp0=new AliITSCalibrationSPD();
386         SetCalibrationModel(kSPD,resp0);
387
388         AliITSsegmentationSPD *seg0=new AliITSsegmentationSPD();
389         seg0->SetDetSize(s0->GetDx()*2.*kconv, // base this on AliITSgeomSPD
390                          s0->GetDz()*2.*kconv, // for now.
391                          s0->GetDy()*2.*kconv);// x,z,y full width in microns.
392         seg0->SetNPads(256,160);               // Number of Bins in x and z
393         for(i=000;i<256;i++) bx[i] =  50.0;    // in x all are 50 microns.
394         for(i=000;i<160;i++) bz[i] = 425.0;    // most are 425 microns except below
395         for(i=160;i<280;i++) bz[i] =   0.0;    // Outside of detector.
396         bz[ 31] = bz[ 32] = 625.0;             // first chip boundry
397         bz[ 63] = bz[ 64] = 625.0;             // first chip boundry
398         bz[ 95] = bz[ 96] = 625.0;             // first chip boundry
399         bz[127] = bz[128] = 625.0;             // first chip boundry
400         bz[160] = 425.0;                       // Set so that there is no zero pixel size for fNz.
401         seg0->SetBinSize(bx,bz);               // Based on AliITSgeomSPD for now.
402         SetSegmentationModel(kSPD,seg0);
403     }
404   
405     // SDD
406    
407     s1 = (AliITSgeomSDD*) GetITSgeom()->GetShape(kSDD);// Get shape info.
408     if (s1) {
409       AliITSCalibrationSDD *resp1=new AliITSCalibrationSDD("simulated");
410       SetCalibrationModel(kSDD,resp1);
411       AliITSsegmentationSDD *seg1=new AliITSsegmentationSDD();
412       seg1->SetDetSize(s1->GetDx()*kconv, // base this on AliITSgeomSDD
413                        s1->GetDz()*4.*kconv, // for now.
414                        s1->GetDy()*4.*kconv); // x,z,y full width in microns.
415       seg1->SetDriftSpeed(AliITSresponseSDD::DefaultDriftSpeed());
416       seg1->SetNPads(256,256);// Use AliITSgeomSDD for now
417       SetSegmentationModel(kSDD,seg1);
418     }
419     
420     // SSD
421     
422     s2 = (AliITSgeomSSD*) GetITSgeom()->GetShape(kSSD);// Get shape info. Do it this way for now.
423     if (s2) {
424       AliITSCalibration *resp2=new AliITSCalibrationSSD("simulated");
425       SetCalibrationModel(kSSD,resp2);
426
427       AliITSsegmentationSSD *seg2=new AliITSsegmentationSSD();
428       seg2->SetDetSize(s2->GetDx()*2.*kconv, // base this on AliITSgeomSSD
429                        s2->GetDz()*2.*kconv, // for now.
430                        s2->GetDy()*2.*kconv); // x,z,y full width in microns.
431       seg2->SetPadSize(95.,0.); // strip x pitch in microns
432       seg2->SetNPads(768,0); // number of strips on each side.
433       seg2->SetAngles(0.0075,0.0275); // strip angels rad P and N side.
434       seg2->SetAnglesLay5(0.0075,0.0275); // strip angels rad P and N side.
435       seg2->SetAnglesLay6(0.0275,0.0075); // strip angels rad P and N side.
436       SetSegmentationModel(kSSD,seg2); 
437     }
438     
439   if(fgkNTYPES>3){Warning("SetDefaults","Only the four basic detector types are initialised!");}
440   return;
441 }
442 */
443 //______________________________________________________________________
444 void AliITSvBeamTestITS04::AddSPDGeometry(TGeoVolume *moth) const
445 {
446   //Adds SPD geometry
447     TGeoMedium *siliconSPD = gGeoManager->GetMedium("ITSspdSi");
448     
449     //outer volume
450     TGeoBBox *waferSPDshape = new TGeoBBox("ITSspdWaferShape",fgkSPDwidth/2,fgkSPDthickness/2,fgkSPDlength/2,0);
451     TGeoVolume *waferSPD = new TGeoVolume("ITSspdWafer",waferSPDshape,siliconSPD);
452     //sensitive volume
453     TGeoBBox *sensSPDbox = new TGeoBBox("ITSsddSensorSensBox",fgkSPDwidthSens/2,fgkSPDthickSens/2,fgkSPDlengthSens/2,0);
454     TGeoVolume *sensVolSPD = new TGeoVolume(fgSPDsensitiveVolName,sensSPDbox,siliconSPD);
455     waferSPD->AddNode(sensVolSPD, 1, 0); //added to outer volume
456     
457     //locate them in space (with respect top volume)
458     TGeoTranslation *spd1tr = new TGeoTranslation(0,fgkSPD0y,fgkSPDlength/2);
459     TGeoTranslation *spd2tr = new TGeoTranslation(0,fgkSPD0y,-fgkSPDlength/2);
460
461     TGeoTranslation *spd3tr = new TGeoTranslation(0,fgkSPD1y,fgkSPDlength/2);
462     TGeoTranslation *spd4tr = new TGeoTranslation(0,fgkSPD1y,-fgkSPDlength/2);
463     
464     //add to top volume
465     moth->AddNode(waferSPD, 1, spd1tr);
466     moth->AddNode(waferSPD, 2, spd2tr);
467     moth->AddNode(waferSPD, 3, spd3tr);
468     moth->AddNode(waferSPD, 4, spd4tr);
469     
470     //draw options
471     waferSPD->SetLineColor(4);
472     sensVolSPD->SetLineColor(4);
473 }
474
475
476 //______________________________________________________________________
477 void AliITSvBeamTestITS04::AddSDDGeometry(TGeoVolume *moth) const
478 {
479   //Adds SDD geometry
480     TGeoMedium *siliconSDD = gGeoManager->GetMedium("ITSsddSi");
481     
482     //outer volume
483     TGeoBBox *waferSDDshape = new TGeoBBox("ITSsddWaferShape",fgkSDDwidth/2,fgkSDDthickness/2,fgkSDDlength/2,0);
484     TGeoVolume *waferSDD = new TGeoVolume("ITSsddWafer",waferSDDshape,siliconSDD);
485     //sensitive volume
486     TGeoBBox *sensSDDbox = new TGeoBBox("ITSsddSensorSensBox",fgkSDDwidthSens/2,fgkSDDthickSens/2,fgkSDDlengthSens/2,0);
487     TGeoVolume *sensVolSDD = new TGeoVolume(fgSDDsensitiveVolName,sensSDDbox,siliconSDD);
488     waferSDD->AddNode(sensVolSDD, 1, 0); //added to outer volume
489     
490     //locate them in space
491     TGeoTranslation *sdd1tr = new TGeoTranslation(0,fgkSDD0y,0);
492     TGeoTranslation *sdd2tr = new TGeoTranslation(0,fgkSDD1y,0);
493         
494     //add to top volume
495     moth->AddNode(waferSDD, fNspd+1, sdd1tr);
496     moth->AddNode(waferSDD, fNspd+2, sdd2tr);
497     
498     //draw options
499     waferSDD->SetLineColor(3);
500     sensVolSDD->SetLineColor(3);
501 }
502
503
504 //______________________________________________________________________
505 void AliITSvBeamTestITS04::AddSSDGeometry(TGeoVolume *moth) const
506 {
507   //Adds SSD geometry
508     TGeoMedium *siliconSSD = gGeoManager->GetMedium("ITSspdSi"); // SSD medium still needed!!!
509     
510     //outer volume 
511     TGeoBBox *waferSSDshape = new TGeoBBox("ITSssdWaferShape",fgkSSDwidth/2,fgkSSDthickness/2,fgkSSDlength/2,0);
512     TGeoVolume *waferSSD = new TGeoVolume("ITSssdWafer",waferSSDshape,siliconSSD);
513     //sensitive volume
514     TGeoBBox *sensSSDbox = new TGeoBBox("ITSssdSensorSensBox",fgkSSDwidthSens/2,fgkSSDthickSens/2,fgkSSDlengthSens/2,0);
515     TGeoVolume *sensVolSSD = new TGeoVolume(fgSSDsensitiveVolName,sensSSDbox,siliconSSD);
516     waferSSD->AddNode(sensVolSSD, 1, 0);
517     
518     //locate them in space
519     /* In the SSD, there was an overlap of sensitive volumes of 2.9mm = 0.29cm (0.29/2=0.145) 
520        in the modules in the same plane, therefore the modules where not in the same plane in 
521        the Y direction, there was a "thickness" (0.03cm) difference */
522     TGeoTranslation *ssd1tr = new TGeoTranslation(0,fgkSSD0y,fgkSSDlength/2-0.145);
523     TGeoTranslation *ssd2tr = new TGeoTranslation(0,fgkSSD0y+0.03,-fgkSSDlength/2+0.145);
524
525     TGeoTranslation *ssd3tr = new TGeoTranslation(0,fgkSSD1y,fgkSSDlength/2-0.145);
526     TGeoTranslation *ssd4tr = new TGeoTranslation(0,fgkSSD1y+0.03,-fgkSSDlength/2+0.145);
527
528     //add to top volume
529     moth->AddNode(waferSSD, fNspd+fNsdd+1, ssd1tr);
530     moth->AddNode(waferSSD, fNspd+fNsdd+2, ssd2tr);
531     moth->AddNode(waferSSD, fNspd+fNsdd+3, ssd3tr);
532     moth->AddNode(waferSSD, fNspd+fNsdd+4, ssd4tr);
533     
534     //draw options
535     waferSSD->SetLineColor(2);
536     sensVolSSD->SetLineColor(2);
537 }
538
539 //______________________________________________________________________
540 void AliITSvBeamTestITS04::StepManager()
541 {
542     // Called for every step in the ITS, then calles the AliITShit class
543     // creator with the information to be recoreded about that hit.
544
545     // "Standard" StepManager. (Similar to AliITSv11) mln
546     Int_t cpy0,mod,status,id,kk;
547     TLorentzVector position, momentum;
548     static AliITShit hit;// Saves on calls to construtors
549     
550     if(!(this->IsActive())) return;
551     if(!(gMC->TrackCharge())) return;
552     //TClonesArray &lhits = *(GetDetTypeSim()->GetHits());
553     TClonesArray &lhits = *(Hits());
554     //
555     // Track status
556     // Track status
557     status = 0;
558     if(gMC->IsTrackInside())      status +=  1;
559     if(gMC->IsTrackEntering())    status +=  2;
560     if(gMC->IsTrackExiting())     status +=  4;
561     if(gMC->IsTrackOut())         status +=  8;
562     if(gMC->IsTrackDisappeared()) status += 16;
563     if(gMC->IsTrackStop())        status += 32;
564     if(gMC->IsTrackAlive())       status += 64;
565     
566     id=gMC->CurrentVolID(cpy0);
567     
568     Bool_t sensvol = kFALSE;
569     for(kk=0;kk<fIdN;kk++) if(id == fIdSens[kk]) sensvol = kTRUE;
570     if(!sensvol) return;
571
572     fIgm.DecodeDetector(mod,gGeoManager->GetMother(1)->GetNumber(),1,1,1);
573     //
574     // Fill hit structure.
575     //
576     hit.SetModule(mod);
577     hit.SetTrack(gAlice->GetMCApp()->GetCurrentTrackNumber());
578     gMC->TrackPosition(position);
579     gMC->TrackMomentum(momentum);
580     hit.SetPosition(position);
581     hit.SetTime(gMC->TrackTime());
582     hit.SetMomentum(momentum);
583     hit.SetStatus(status);
584     hit.SetEdep(gMC->Edep());
585     hit.SetShunt(GetIshunt());
586     if(gMC->IsTrackEntering()){
587         hit.SetStartPosition(position);
588         hit.SetStartTime(gMC->TrackTime());
589         hit.SetStartStatus(status);
590         return; // don't save entering hit.
591     } // end if IsEntering
592     // Fill hit structure with this new hit.
593     //Info("StepManager","Calling Copy Constructor");
594     new(lhits[fNhits++]) AliITShit(hit); // Use Copy Construtor.
595     // Save old position... for next hit.
596     hit.SetStartPosition(position);
597     hit.SetStartTime(gMC->TrackTime());
598     hit.SetStartStatus(status);
599     return;
600 }
601 /*
602 //______________________________________________________________________
603 Int_t AliITSvBeamTestITS04::GetCurrentLayLaddDet(Int_t &lay,Int_t &ladd, Int_t &det) const
604
605   // Function which gives the layer, ladder and det.
606   // index of the current volume. To be used in
607   // AliITS::StepManager()
608
609     det  = 1;   ladd = 1;
610     
611     TGeoNode *node = gGeoManager->GetMother(1);
612     if (!node) return kFALSE;
613     Int_t nodeNum = node->GetNumber();
614     
615     // GetNumber() return the index recorded in the node
616     
617     if (nodeNum==5||nodeNum==6) {         // SDD: one layer, one detector
618         lay = nodeNum-2;
619     } else if (nodeNum==3||nodeNum==4) {  // SPD layer 2
620         lay = 2;
621         if (nodeNum==4) det = 2;
622     } else if (nodeNum==1||nodeNum==2){   // SPD layer 1
623         lay = 1;
624         if (nodeNum==2) det = 2; 
625     } else if (nodeNum==9||nodeNum==10) { // SSD layer 2
626         lay = 6;
627         if (nodeNum==10) det = 2;
628     } else if (nodeNum==7||nodeNum==8){   // SSD layer 1
629         lay = 5;
630         if (nodeNum==8) det = 2; 
631     };  
632     
633     return kTRUE;
634 }
635 */
636 //_____________________________________________________________
637
638  Int_t AliITSvBeamTestITS04::GetNumberOfSubDet(const TString& det) const{
639     
640    //Get number of individual detectors
641     if(det.Contains("SPD")) return fNspd;
642     if(det.Contains("SDD")) return fNsdd;
643     if(det.Contains("SSD")) return fNssd;
644     return 0;
645   }