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