]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSvSPD02.cxx
New version of SPD raw-data reconstruction. The format now correponds to the actual...
[u/mrichter/AliRoot.git] / ITS / AliITSvSPD02.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 /* $Id$ */
17
18 #include <TGeometry.h>
19 #include <TNode.h>
20 #include <TLorentzVector.h>
21 #include <TClonesArray.h>
22 #include <TBRIK.h>
23 #include <TGeoMatrix.h>
24 #include <TVirtualMC.h>
25
26 #include "AliRun.h"
27 #include "AliMagF.h"
28 #include "AliTrackReference.h"
29
30 #include "AliITShit.h"
31 #include "AliITS.h"
32 #include "AliITSvSPD02.h"
33 #include "AliITSgeom.h"
34 #include "AliITSgeomSPD.h"
35 #include "AliITSDetTypeSim.h"
36 #include "AliITSCalibrationSPD.h"
37 #include "AliITSsegmentationSPD.h"
38 #include "AliITSsimulationSPD.h"
39 #include "AliMC.h"
40
41
42 ///////////////////////////////////////////////////////////////////////
43 // Step manager and 
44 // geometry class
45 // for the ITS 
46 // SPD test beam
47 // geometry of summer 2002
48 // 
49 ///////////////////////////////////////////////////////////////////////
50 ClassImp(AliITSvSPD02)
51
52 //______________________________________________________________________
53 AliITSvSPD02::AliITSvSPD02():
54 AliITS(),
55 fGeomDetOut(kFALSE),
56 fGeomDetIn(kFALSE),
57 fMajorVersion(1),
58 fMinorVersion(2),
59 fGeomNumber(2002),
60 fEuclidGeomDet(),
61 fRead(),
62 fWrite(),
63 fDet1(300.0),
64 fDet2(300.0),
65 fChip1(300.0),
66 fChip2(300.0){
67     ////////////////////////////////////////////////////////////////////////
68     // Standard default constructor for the ITS SPD test beam 2002 version 1.
69     // Inputs:
70     //    none.
71     // Outputs:
72     //    none.
73     // Return:
74     //    A default created class.
75     ////////////////////////////////////////////////////////////////////////
76     Int_t i;
77
78     for(i=0;i<60;i++) fRead[i] = '\0';
79     for(i=0;i<60;i++) fWrite[i] = '\0';
80     for(i=0;i<60;i++) fEuclidGeomDet[i] = '\0';
81 }
82 //______________________________________________________________________
83 AliITSvSPD02::AliITSvSPD02(const char *title,Int_t gn) : AliITS("ITS", title),
84 fGeomDetOut(kFALSE),
85 fGeomDetIn(kFALSE),
86 fMajorVersion(1),
87 fMinorVersion(2),
88 fGeomNumber(2002),
89 fEuclidGeomDet(),
90 fRead(),
91 fWrite(),
92 fDet1(300.0),
93 fDet2(300.0),
94 fChip1(300.0),
95 fChip2(300.0){
96     ////////////////////////////////////////////////////////////////////////
97     //    Standard constructor for the ITS SPD testbeam 2002 version 1.
98     // Inputs:
99     //    const char *title    title for this ITS geometry.
100     //    Int_t      gn        Geometry version number (year) default 2002.
101     // Outputs:
102     //    none.
103     // Return:
104     //    A standard created class.
105     ////////////////////////////////////////////////////////////////////////
106     Int_t i;
107
108     fGeomNumber = gn;
109     fIdN = 2;
110     fIdName = new TString[fIdN];
111     fIdName[0] = "IMBS";
112     fIdName[1] = "ITST";
113     fIdSens    = new Int_t[fIdN];
114     for(i=0;i<fIdN;i++) fIdSens[i] = 0;
115     SetThicknessDet1();
116     SetThicknessDet2();
117     SetThicknessChip1();
118     SetThicknessChip2();                         
119
120     fEuclidGeometry="$ALICE_ROOT/ITS/ITSgeometry_vSPD022.euc";
121     strncpy(fEuclidGeomDet,"$ALICE_ROOT/ITS/ITSgeometry_vSPD022.det",60);
122     strncpy(fRead,fEuclidGeomDet,60);
123     strncpy(fWrite,fEuclidGeomDet,60);
124 }
125 //______________________________________________________________________
126 AliITSvSPD02::~AliITSvSPD02() {
127     ////////////////////////////////////////////////////////////////////////
128     //    Standard destructor for the ITS SPD test beam 2002 version 1.
129     // Inputs:
130     //    none.
131     // Outputs:
132     //    none.
133     // Return:
134     //    none.
135     ////////////////////////////////////////////////////////////////////////
136 }
137 //______________________________________________________________________
138 void AliITSvSPD02::BuildGeometry(){
139     ////////////////////////////////////////////////////////////////////////
140     //    Geometry builder for the ITS SPD test beam 2002 version 1.
141     //    ALIC    ALICE Mother Volume
142     //     |- ITSV     ITS Mother Volume
143     //         |- IDET       Detector under Test
144     //         |   |- ITS0       SPD Si Chip
145     //         |   |  |- ITST      SPD Sensitivve Volume
146     //         |   |- IPC0 *5    Readout chip
147     //         |- ITEL *4    SPD Telescope
148     //             |- IMB0       SPD Si Chip
149     //             |   |- IMBS     SPD Sensitive volume
150     //             |- ICMB       Chip MiniBus.
151     // Inputs:
152     //    none.
153     // Outputs:
154     //    none.
155     // Return:
156     //    none.
157     ////////////////////////////////////////////////////////////////////////
158     // Get the top alice volume.
159
160     switch (fGeomNumber){
161     case 2002:
162         BuildGeometry2002();
163         break;
164     default:
165         BuildGeometry2002();
166         break;
167     } // end switch
168 }
169 //______________________________________________________________________
170 void AliITSvSPD02::BuildGeometry2002(){
171     ////////////////////////////////////////////////////////////////////////
172     //    Geometry builder for the ITS SPD test beam 2002 version 1.
173     //    ALIC    ALICE Mother Volume
174     //     |- ITSV     ITS Mother Volume
175     //         |- IDET       Detector under Test
176     //         |   |- ITS0       SPD Si Chip
177     //         |   |  |- ITST      SPD Sensitivve Volume
178     //         |   |- IPC0 *5    Readout chip
179     //         |- ITEL *4    SPD Telescope
180     //             |- IMB0       SPD Si Chip
181     //             |   |- IMBS     SPD Sensitive volume
182     //             |- ICMB       Chip MiniBus.
183     // Inputs:
184     //    none.
185     // Outputs:
186     //    none.
187     // Return:
188     //    none.
189     ////////////////////////////////////////////////////////////////////////
190     // Get the top alice volume.
191     TNode *aALIC = gAlice->GetGeometry()->GetNode("alice");
192     aALIC->cd();
193
194     // Define ITS Mother Volume
195     Float_t data[3];
196     Float_t ddettest=200.0E-4,ddettelescope=300.0E-4;
197     Float_t dchipMiniBus=750.0E-4,dchiptest=300.0E-4;
198     //Float_t yposition= 0.0;
199     TRotMatrix *r0 = new TRotMatrix("ITSidrotm0","ITSidrotm0",
200                                     90.0,0,0.0,0,90.0,270.0);
201     data[0] = 10.0;
202     data[1] = 50.0;
203     data[2] = 100.0;
204     TBRIK *iITSVshape = new TBRIK("ITSVshape",
205                                   "ITS Logical Mother Volume","Air",
206                                   data[0],data[1],data[2]);
207     TNode *iITSV = new TNode("ITSV","ITS Mother Volume",iITSVshape,
208                              0.0,0.0,0.0,0,0);
209     iITSV->cd(); // set ourselve into ITSV subvolume of aALIC
210
211     // SPD part of telescope (MiniBuS)
212     data[0] = 0.705;
213     data[1] = 0.5*ddettelescope;
214     data[2] = 3.536;
215     TBRIK *iIMB0shape = new TBRIK("IMB0shape","SPD wafer","Si",
216                                  data[0],data[1],data[2]);
217     Float_t detMiniBusX,detMiniBusY,detMiniBusZ;
218     data[0] = detMiniBusX = 0.64;
219     data[1] = detMiniBusY = 0.5*ddettelescope;
220     data[2] = detMiniBusZ = 3.48;
221     TBRIK *iIMBSshape = new TBRIK("IMBSshape","SPD Sensitive volume","Si",
222                                  data[0],data[1],data[2]);
223     Float_t chipMiniBusX,chipMiniBusY,chipMiniBusZ;
224     data[0] = chipMiniBusX = 0.793;
225     data[1] = chipMiniBusY = 0.5*dchipMiniBus;
226     data[2] = chipMiniBusZ = 0.68;
227     TBRIK *iICMBshape = new TBRIK("ICMBshape","chip Minibus","Si",
228                                  data[0],data[1],data[2]);
229     data[0] = TMath::Max(detMiniBusX,chipMiniBusX);
230     data[1] = detMiniBusY+chipMiniBusY;
231     data[2] = TMath::Max(detMiniBusZ,chipMiniBusZ);
232     TBRIK *iITELshape = new TBRIK("ITELshape","ITELshape","Air",
233                                  data[0],data[1],data[2]);
234
235     // SPD under test
236     Float_t spdX,spdY,spdZ,spdchipX,spdchipY,spdchipZ;
237     data[0] = 0.705;
238     data[1] = ddettest;
239     data[2] = 3.536;
240     TBRIK *iITS0shape = new TBRIK("ITS0shape","SPD wafer","Si",
241                                  data[0],data[1],data[2]); // contains detector
242     data[0] = spdX = 0.64;
243     data[1] = spdY = ddettest;
244     data[2] = spdZ = 3.48;
245     TBRIK *iITSTshape = new TBRIK("ITSTshape","SPD sensitive volume","Si",
246                                  data[0],data[1],data[2]);
247     // ITS0 with no translation and unit rotation matrix.
248     data[0] = spdchipX = 0.793;
249     data[1] = spdchipY = dchiptest;
250     data[2] = spdchipZ = 0.68;
251     TBRIK *iIPC0shape = new TBRIK("IPC0shape","Readout Chips","Si",
252                                  data[0],data[1],data[2]); // chip under test
253     data[0] = TMath::Max(spdchipX,spdX);
254     data[1] = spdY+spdchipY;
255     data[2] = TMath::Max(spdchipZ,spdZ);
256     TBRIK *iIDETshape = new TBRIK("IDETshape","Detector Under Test","Air",
257                                  data[0],data[1],data[2]);
258     // Place volumes in geometry
259     Int_t i,j;
260     char name[20],title[50];
261     Double_t px=0.0,py=0.0,pz[4]={-38.0,0.0,0.0,0.0};
262     pz[1] = pz[0]+2.0;
263     pz[2] = pz[1]+38.0+spdY+spdchipY+34.5;
264     pz[3] = pz[2]+2.0;
265     TNode *iITEL[4],*iICMB[4],*iIMB0[4],*iIMBS[4];
266     TNode *iIDET = new TNode("IDET","Detector Under Test",iIDETshape,
267                             0.0,0.0,pz[1]+38.0,r0,0);
268     iIDET->cd();
269     TNode *iITS0 = new TNode("ITS0","SPD Chip",iITS0shape,
270                             0.0,iIDETshape->GetDy()-spdY,0.0,0,0);
271     TNode *iIPC0[5];
272     for(i=0;i<5;i++) { //place readout chips on the back of SPD chip under test
273         sprintf(name,"IPC0%d",i);
274         sprintf(title,"Readout chip #%d",i+1);
275         j = i-2;
276         iIPC0[i] = new TNode(name,title,iIPC0shape,
277                              0.0,spdchipY-iIDETshape->GetDy(),
278                              j*2.0*spdchipZ+j*0.25*(spdZ-5.*spdchipZ),0,0);
279     } // end for i
280     iITS0->cd();
281     TNode *iITST = new TNode("ITST","SPD sensitive volume",iITSTshape,
282                              0.0,0.0,0.0,0,0);
283     for(Int_t i=0;i<4;i++){
284         iITSV->cd();
285         sprintf(name,"ITEL%d",i);
286         sprintf(title,"Test beam telescope element #%d",i+1);
287         iITEL[i] = new TNode(name,title,iITELshape,px,py,pz[i],r0,0);
288         iITEL[i]->cd();
289         iICMB[i] = new TNode("ICMB","Chip MiniBus",iICMBshape,
290                              0.0,-iITELshape->GetDy()+detMiniBusY,0.0,0,0);
291         iIMB0[i] = new TNode("IMB0","Chip MiniBus",iIMB0shape,
292                              0.0, iITELshape->GetDy()-detMiniBusY,0.0,0,0);
293         iIMB0[i]->cd();
294         iIMBS[i] = new TNode("IMBS","IMBS",iIMBSshape,0.0,0.0,0.0,0,0);
295         // place IMBS inside IMB0 with no translation and unit rotation matrix.
296     } // end for i
297     aALIC->cd();
298     iITST->SetLineColor(kYellow);
299     fNodes->Add(iITST);
300     for(i=0;i<4;i++){
301         iIMBS[i]->SetLineColor(kGreen);
302         fNodes->Add(iIMBS[i]);
303     } // end for i
304 }
305 //______________________________________________________________________
306 void AliITSvSPD02::CreateGeometry(){
307     ////////////////////////////////////////////////////////////////////////
308     //  This routine defines and Creates the geometry for version 1 of the ITS.
309     //    ALIC    ALICE Mother Volume
310     //     |- ITSV     ITS Mother Volume
311     //         |- IDET       Detector under Test
312     //         |   |- ITS0       SPD Si Chip
313     //         |   |  |- ITST      SPD Sensitivve Volume
314     //         |   |- IPC0 *5    Readout chip
315     //         |- ITEL *4    SPD Telescope
316     //             |- IMB0       SPD Si Chip
317     //             |   |- IMBS     SPD Sensitive volume
318     //             |- ICMB       Chip MiniBus.
319     // Inputs:
320     //    none.
321     // Outputs:
322     //    none.
323     // Return:
324     //    none.
325     ////////////////////////////////////////////////////////////////////////
326
327     switch (fGeomNumber){
328     case 2002:
329         CreateGeometry2002();
330         break;
331     default:
332         CreateGeometry2002();
333         break;
334     } // end switch
335 }
336 //______________________________________________________________________
337 void AliITSvSPD02::CreateGeometry2002(){
338     ////////////////////////////////////////////////////////////////////////
339     //  This routine defines and Creates the geometry for version 1 of the ITS.
340     //    ALIC    ALICE Mother Volume
341     //     |- ITSV     ITS Mother Volume
342     //         |- IDET       Detector under Test
343     //         |   |- ITS0       SPD Si Chip
344     //         |   |  |- ITST      SPD Sensitivve Volume
345     //         |   |- IPC0 *5    Readout chip
346     //         |- ITEL *4    SPD Telescope
347     //             |- IMB0       SPD Si Chip
348     //             |   |- IMBS     SPD Sensitive volume
349     //             |- ICMB       Chip MiniBus.
350     // Inputs:
351     //    none.
352     // Outputs:
353     //    none.
354     // Return:
355     //    none.
356     ////////////////////////////////////////////////////////////////////////
357     Float_t data[49];
358     // Define media off-set
359     Int_t *idtmed = fIdtmed->GetArray()+1; // array of media indexes
360     Int_t idrotm[4]; // Array of rotation matrix indexes
361     Float_t ddettest=200.0E-4,ddettelescope=300.0E-4;
362     Float_t dchipMiniBus=750.0E-4,dchiptest=300.0E-4;
363     Float_t yposition= 0.0;
364
365     if(gMC==0) return;
366     // Define Rotation-reflextion Matrixes needed
367     // 0 is the unit matrix
368     AliMatrix(idrotm[0], 90.0,0.0, 0.0,0.0, 90.0,270.0);
369     data[0] = 10.0;
370     data[1] = 50.0;
371     data[2] = 100.0;
372     gMC->Gsvolu("ITSV","BOX",idtmed[0],data,3);
373     gMC->Gspos("ITSV",1,"ALIC",0.0,0.0,0.0,0,"ONLY");
374
375     //cout << "idtmed[0]=" << idtmed[0]<<endl;
376     //cout << "idtmed[1]=" << idtmed[1]<<endl;
377     Float_t detMiniBusX,detMiniBusY,detMiniBusZ;
378     // SPD part of telescope (MiniBuS)
379     data[0] = detMiniBusX = 0.705;
380     data[1] = detMiniBusY = 0.5*ddettelescope;
381     data[2] = detMiniBusZ = 3.536;
382     gMC->Gsvolu("IMB0", "BOX ", idtmed[1], data, 3);   // contains detector
383     data[0] = 0.64;
384     data[1] = 0.5*ddettelescope;
385     data[2] = 3.48;
386     gMC->Gsvolu("IMBS","BOX ",idtmed[1],data,3); // sensitive detecor volulme
387     gMC->Gspos("IMBS",1,"IMB0",0.0,0.0,0.0,0,"ONLY"); // place IMBS inside
388     // IMB0 with no translation and unit rotation matrix.
389     Float_t chipMiniBusX,chipMiniBusY,chipMiniBusZ;
390     data[0] = chipMiniBusX = 0.793;
391     data[1] = chipMiniBusY = 0.5*dchipMiniBus;
392     data[2] = chipMiniBusZ = 0.68;
393     gMC->Gsvolu("ICMB","BOX ",idtmed[1],data, 3);   // chip Minibus
394     data[0] = TMath::Max(detMiniBusX,chipMiniBusX);
395     data[1] = detMiniBusY+chipMiniBusY;
396     data[2] = TMath::Max(detMiniBusZ,chipMiniBusZ);
397     gMC->Gsvolu("ITEL","BOX ",idtmed[0],data,3);
398     gMC->Gspos("IMB0",1,"ITEL",0.0,data[1]-detMiniBusY,0.0,0,"ONLY");
399     gMC->Gspos("ICMB",1,"ITEL",0.0,-data[1]+chipMiniBusY,0.0,0,"ONLY");
400
401     // SPD under test
402     Float_t spdX,spdY,spdZ,spdchipX,spdchipY,spdchipZ;
403     data[0] = spdX = 0.705;
404     data[1] = spdY = 0.5*ddettest;
405     data[2] = spdZ = 3.536;
406     gMC->Gsvolu("ITS0", "BOX ", idtmed[1], data, 3);   // contains detector
407     data[0] = 0.64;
408     data[1] = 0.5*ddettest;
409     data[2] = 3.48;
410     gMC->Gsvolu("ITST","BOX ",idtmed[1],data,3);// sensitive detecor volume
411     gMC->Gspos("ITST",1,"ITS0",0.0,0.0,0.0,0,"ONLY"); // place ITST inside
412     // ITS0 with no translation and unit rotation matrix.
413     data[0] = spdchipX = 0.793;
414     data[1] = spdchipY = 0.5*dchiptest;
415     data[2] = spdchipZ = 0.68;
416     gMC->Gsvolu("IPC0", "BOX ", idtmed[1],data,3);   // chip under test
417     data[0] = TMath::Max(spdchipX,spdX);
418     data[1] = spdY+spdchipY;
419     data[2] = TMath::Max(spdchipZ,spdZ);
420     gMC->Gsvolu("IDET","BOX ",idtmed[0],data,3);
421     gMC->Gspos("ITS0",1,"IDET",0.0,data[1]-spdY,0.0,0,"ONLY");
422     for(Int_t i=-2;i<3;i++) gMC->Gspos("IPC0",i+3,"IDET",0.0,-data[1]+spdchipY,
423               i*2.*spdchipZ+i*0.25*(spdZ-5.*spdchipZ),0,"ONLY");
424
425     // Positions detectors, Beam Axis Z, X to the right, Y up to the sky.
426     Float_t p00X,p00Y,p00Z,p01X,p01Y,p01Z,p10X,p10Y,p10Z,p11X,p11Y,p11Z;
427     p00X = 0.0;
428     p00Y = 0.0;
429     p00Z = -38.0;
430     gMC->Gspos("ITEL",1,"ITSV",p00X,p00Y,p00Z,idrotm[0],"ONLY");
431     p01X = 0.0;
432     p01Y = 0.0;
433     p01Z = p00Z+2.0;
434     gMC->Gspos("ITEL",2,"ITSV",p01X,p01Y,p01Z,idrotm[0],"ONLY");
435     Float_t pdetX,pdetY,pdetZ;
436     pdetX = 0.0;
437     pdetY = 0.0+yposition;
438     pdetZ = p01Z+38.0;
439     gMC->Gspos("IDET",1,"ITSV",pdetX,pdetY,pdetZ,idrotm[0],"ONLY");
440     p10X = 0.0;
441     p10Y = 0.0;
442     p10Z = pdetZ + 34.5;
443     gMC->Gspos("ITEL",3,"ITSV",p10X,p10Y,p10Z,idrotm[0],"ONLY");
444     p11X = 0.0;
445     p11Y = 0.0;
446     p11Z = p10Z+2.0;
447     gMC->Gspos("ITEL",4,"ITSV",p11X,p11Y,p11Z,idrotm[0],"ONLY");
448 }
449 //______________________________________________________________________
450 void AliITSvSPD02::CreateMaterials(){
451     ////////////////////////////////////////////////////////////////////////
452     //
453     // Create ITS SPD test beam materials
454     //     This function defines the default materials used in the Geant
455     // Monte Carlo simulations for the geometries AliITSv1, AliITSv3,
456     // AliITSvSPD02.
457     // In general it is automatically replaced by
458     // the CreateMaterials routine defined in AliITSv?. Should the function
459     // CreateMaterials not exist for the geometry version you are using this
460     // one is used. See the definition found in AliITSv5 or the other routine
461     // for a complete definition.
462     //
463     // Inputs:
464     //    none.
465     // Outputs:
466     //    none.
467     // Return:
468     //    none.
469     /////////////////////////////////////////////////////////////////////////
470
471     switch (fGeomNumber){
472     case 2002:
473         CreateMaterials2002();
474         break;
475     default:
476         CreateMaterials2002();
477         break;
478     } // end switch
479 }
480 //______________________________________________________________________
481 void AliITSvSPD02::CreateMaterials2002(){
482     ////////////////////////////////////////////////////////////////////////
483     //
484     // Create ITS SPD test beam materials
485     //     This function defines the default materials used in the Geant
486     // Monte Carlo simulations for the geometries AliITSv1, AliITSv3,
487     // AliITSvSPD02.
488     // In general it is automatically replaced by
489     // the CreateMaterials routine defined in AliITSv?. Should the function
490     // CreateMaterials not exist for the geometry version you are using this
491     // one is used. See the definition found in AliITSv5 or the other routine
492     // for a complete definition.
493     //
494     // Inputs:
495     //    none.
496     // Outputs:
497     //    none.
498     // Return:
499     //    none.
500     /////////////////////////////////////////////////////////////////////////
501     Float_t tmaxfdSi = 0.1; // Degree
502     Float_t stemaxSi = 0.0075; // cm
503     Float_t deemaxSi = 0.1; // Fraction of particle's energy 0<deemax<=1
504     Float_t epsilSi  = 1.0E-4;//
505     Float_t stminSi  = 0.0; // cm "Default value used"
506
507     Float_t tmaxfdAir = 0.1; // Degree
508     Float_t stemaxAir = .10000E+01; // cm
509     Float_t deemaxAir = 0.1; // Fraction of particle's energy 0<deemax<=1
510     Float_t epsilAir  = 1.0E-4;//
511     Float_t stminAir  = 0.0; // cm "Default value used"
512     Int_t   ifield = gAlice->Field()->Integ();
513     Float_t fieldm = gAlice->Field()->Max();
514
515     AliMaterial(1,"AIR$",0.14610E+02,0.73000E+01,0.12050E-02,
516                 0.30423E+05,0.99900E+03);
517     AliMedium(1,"AIR$",1,0,ifield,fieldm,tmaxfdAir,stemaxAir,deemaxAir,
518               epsilAir,stminAir);
519
520     AliMaterial(2,"SI$",0.28086E+02,0.14000E+02,0.23300E+01,
521                 0.93600E+01,0.99900E+03);
522     AliMedium(2,"SI$",2,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,
523               epsilSi,stminSi);
524 }
525 //______________________________________________________________________
526 Int_t AliITSvSPD02::DecodeDetector(Int_t id,Int_t cpy,Int_t &lay,Int_t &lad,
527     Int_t &det)const{
528     //     Based on the geometry tree defined in Geant 3.21, this
529     // routine initilizes the Class AliITSgeom from the Geant 3.21 ITS geometry
530     // sturture.
531     // Inputs:
532     //    Int_t id   Detector volume id
533     //    Int_t cpy  Detector copy number
534     // Outputs:
535     //    Int_t lay  layer number
536     //    Int_t lad  ladder number
537     //    Int_t det  detector number
538     // Return:
539     //    The module number
540     Int_t mod;
541
542     lad = det = 1;
543     lay = cpy;
544     if(cpy>2 && id==fIdSens[0]) lay = cpy + 1;
545     if(id==fIdSens[1]) lay = 3;
546     mod = lay - 1;
547     return mod;
548 }
549 //______________________________________________________________________
550 void AliITSvSPD02::InitAliITSgeom(){
551     //     Based on the geometry tree defined in Geant 3.21, this
552     // routine initilizes the Class AliITSgeom from the Geant 3.21 ITS geometry
553     // sturture.
554     // Inputs:
555     //    none.
556     // Outputs:
557     //    none.
558     // Return:
559     //    none.
560     const Int_t kltypess=2;
561     const Int_t knlayers=5;
562     const TString knames[kltypess]=
563         {"ALIC_1/ITSV_1/ITEL_%d/IMB0_1/IMBS_1",//lay=1,2,4,5
564          "ALIC_1/ITSV_1/IDET_%d/ITS0_1/ITST_1"};// lay=3
565     const Int_t kitsGeomTreeCopys[2]={4,1};
566     const Int_t knlad[knlayers]={knlayers*1},kndet[knlayers]={knlayers*1};
567     TString path,shapeName;
568     TGeoHMatrix matrix;
569     TArrayD shapePar;
570     TArrayF shapeParF;
571     Double_t trans[3]={3*0.0},rot[10]={10*0.0};
572     Int_t npar=3,mod,i,j,lay,lad,det,cpy;
573     Float_t par[20];
574
575     par[0]=0.64;par[1]=0.5*300.0E-4;par[2]=3.48;
576     mod=5;
577     AliITSgeom* geom = new AliITSgeom(0,knlayers,knlad,kndet,mod);
578     SetITSgeom(geom);
579     for(i=0;i<kltypess;i++)for(cpy=1;cpy<=kitsGeomTreeCopys[i];cpy++){
580         path.Form(knames[i].Data(),cpy);
581         gMC->GetTransformation(path.Data(),matrix);
582         gMC->GetShape(path.Data(),shapeName,shapePar);
583         shapeParF.Set(shapePar.GetSize());
584         for(j=0;j<shapePar.GetSize();j++) shapeParF[j]=shapePar[j];
585         mod = DecodeDetector(fIdSens[i],cpy,lay,lad,det);
586         geom->CreateMatrix(mod,lay,lad,det,kSPD,trans,rot);
587         geom->SetTrans(mod,matrix.GetTranslation());
588         geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
589         geom->GetGeomMatrix(mod)->SetPath(path.Data());
590         if(!(geom->IsShapeDefined((Int_t)kSPD)))
591             geom->ReSetShape(kSPD,new AliITSgeomSPD425Short(npar,par));
592     } // end for i,cpy/
593     return;
594 }
595 //______________________________________________________________________
596 void AliITSvSPD02::Init(){
597     ////////////////////////////////////////////////////////////////////////
598     //     Initialise the ITS after it has been created.
599     // Inputs:
600     //    none.
601     // Outputs:
602     //    none.
603     // Return:
604     //    none.
605     ////////////////////////////////////////////////////////////////////////
606     Int_t i;
607
608     cout << endl;
609     for(i=0;i<26;i++) cout << "*";
610     cout << " ITSvSPD02" << fMinorVersion << "_Init ";
611     for(i=0;i<25;i++) cout << "*";cout << endl;
612
613     if(fRead[0]=='\0') strncpy(fRead,fEuclidGeomDet,60);
614     if(fWrite[0]=='\0') strncpy(fWrite,fEuclidGeomDet,60);
615     if(GetITSgeom()!=0) SetITSgeom(0x0);
616     AliITSgeom* geom = new AliITSgeom();
617     SetITSgeom(geom);
618     if(fGeomDetIn) GetITSgeom()->ReadNewFile(fRead);
619     if(!fGeomDetIn) this->InitAliITSgeom();
620     if(fGeomDetOut) GetITSgeom()->WriteNewFile(fWrite);
621     AliITS::Init();
622
623     for(i=0;i<72;i++) cout << "*";
624     cout << endl;
625     if(gMC) fIDMother = gMC->VolId("ITSV"); // ITS Mother Volume ID.
626     else fIDMother = 0;
627 }
628 //______________________________________________________________________
629 void AliITSvSPD02::SetDefaults(){
630     // sets the default segmentation, response, digit and raw cluster classes
631     // Inputs:
632     //    none.
633     // Outputs:
634     //    none.
635     // Return:
636     //    none.
637     const Float_t kconv = 1.0e+04; // convert cm to microns
638
639     Info("SetDefaults","Setting up only SPD detector");
640
641     if(!fDetTypeSim) fDetTypeSim = new AliITSDetTypeSim();
642     fDetTypeSim->SetITSgeom(GetITSgeom());
643     AliITSgeomSPD  *s0;
644     Int_t i;
645     Float_t bx[256],bz[280];
646     fDetTypeSim->ResetCalibrationArray();
647     fDetTypeSim->ResetSegmentation();
648  
649     //SPD
650     // Get shape info. Do it this way for now.
651     s0 = (AliITSgeomSPD*) GetITSgeom()->GetShape(kSPD);
652     AliITSCalibration *resp0=new AliITSCalibrationSPD();
653     resp0->SetTemperature();
654     resp0->SetDistanceOverVoltage();
655     SetCalibrationModel(0,resp0); 
656         
657     AliITSsegmentationSPD *seg0=new AliITSsegmentationSPD();
658     seg0->SetDetSize(s0->GetDx()*2.*kconv, // base this on AliITSgeomSPD
659                      s0->GetDz()*2.*kconv, // for now.
660                      s0->GetDy()*2.*kconv); // x,z,y full width in microns.
661     seg0->SetNPads(256,160);// Number of Bins in x and z
662     for(i=000;i<256;i++) bx[i] =  50.0; // in x all are 50 microns.
663     for(i=000;i<160;i++) bz[i] = 425.0; // most are 425 microns except below
664     for(i=160;i<280;i++) bz[i] =   0.0; // Outside of detector.
665     bz[ 31] = bz[ 32] = 625.0; // first chip boundry
666     bz[ 63] = bz[ 64] = 625.0; // first chip boundry
667     bz[ 95] = bz[ 96] = 625.0; // first chip boundry
668     bz[127] = bz[128] = 625.0; // first chip boundry
669     bz[160] = 425.0; // Set so that there is no zero pixel size for fNz.
670     seg0->SetBinSize(bx,bz); // Based on AliITSgeomSPD for now.
671     SetSegmentationModel(kSPD,seg0);
672     // set digit and raw cluster classes to be used
673     const char *kData0=(fDetTypeSim->GetCalibrationModel(0))->DataType();
674     if (strstr(kData0,"real")) fDetTypeSim->SetDigitClassName(kSPD,"AliITSdigit");
675     else fDetTypeSim->SetDigitClassName(kSPD,"AliITSdigitSPD");
676 //    SetSimulationModel(kSPD,new AliITSsimulationSPDdubna(seg0,resp0));
677 //    iDetType->ReconstructionModel(new AliITSClusterFinderSPD());
678    
679 /*
680     SetResponseModel(kSDD,new AliITSCalibrationSDD());
681     SetSegmentationModel(kSDD,new AliITSsegmentationSDD());
682     DetType(kSDD)->ClassNames("AliITSdigitSDD","AliITSRawClusterSDD");
683
684     SetResponseModel(kSSD,new AliITSCalibrationSSD());
685     SetSegmentationModel(kSSD,new AliITSsegmentationSSD());
686     DetType(kSSD)->ClassNames("AliITSdigitSSD","AliITSRawClusterSSD");
687 */
688     if(fgkNTYPES>3){
689         Warning("SetDefaults",
690                 "Only the four basic detector types are initialised!");
691     }// end if
692     return;
693 }
694 //______________________________________________________________________
695 void AliITSvSPD02::SetDefaultSimulation(){
696     // sets the default simulation.
697     // Inputs:
698     //      none.
699     // Outputs:
700     //      none.
701     // Return:
702     //      none.
703
704   if(GetITSgeom()==0){
705     Warning("SetDefaultSimulation","ITS geometry is null!");
706     return;
707   }
708
709   if(!fDetTypeSim) fDetTypeSim = new AliITSDetTypeSim();
710   AliITSsimulation *sim;
711   //AliITSsegmentation *seg;
712   //AliITSCalibration *res;
713   if(fDetTypeSim){
714     sim = fDetTypeSim->GetSimulationModel(kSPD);
715     if (!sim) {
716       //seg = (AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSPD);
717       //res = (AliITSCalibration*)fDetTypeSim->GetResponseModel(GetITSgeom()->GetStartSPD());
718       sim = new AliITSsimulationSPD(fDetTypeSim);
719       SetSimulationModel(kSPD,sim);
720     }else{ // simulation exists, make sure it is set up properly.
721       sim->SetCalibrationModel(GetITSgeom()->GetStartSPD(),(AliITSCalibration*)fDetTypeSim->GetCalibrationModel(GetITSgeom()->GetStartSPD()));
722       sim->SetSegmentationModel(kSPD,(AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSPD));
723       sim->Init();
724     } // end if
725   } // end if iDetType
726   
727     /*
728       if(fDetTypeSim){
729         sim = fDetTypeSim->GetSimulationModel(kSDD);
730         if (!sim) {
731             seg = (AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSDD);
732             res = (AliITSCalibration*)fDetTypeSim->GetResponseModel(GetITSgeom()->GetStartSDD());
733             sim = new AliITSsimulationSDD(seg,res);
734             SetSimulationModel(kSDD,sim);
735         }else{ // simulation exists, make sure it is set up properly.
736           sim->SetResponseModel((AliITSCalibration*)fDetTypeSim->GetResponseModel(GetITSgeom()->GetStartSDD()));
737           sim->SetSegmentationModel((AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSDD));
738           sim->Init();
739         } //end if
740     } // end if iDetType
741     if(fDetTypeSim){
742         sim = fDetTypeSim->GetSimulationModel(kSSD);
743         if (!sim) {
744             seg = (AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSSD);
745             res = (AliITSCalibration*)fDetTypeSim->GetResponseModel(GetITSgeom()->GetStartSSD());
746             sim = new AliITSsimulationSSD(seg,res);
747             SetSimulationModel(kSSD,sim);
748         }else{ // simulation exists, make sure it is set up properly.
749           sim->SetResponseModel((AliITSCalibration*)fDetTypeSim->GetResponseModel(GetITSgeom()->GetStartSSD()));
750           sim->SetSegmentationModel((AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSSD));
751           sim->Init();
752         } // end if
753     } //
754     */ 
755 }
756 //______________________________________________________________________
757 void AliITSvSPD02::DrawModule() const {
758     ////////////////////////////////////////////////////////////////////////
759     //     Draw a shaded view of the ITS SPD test beam version 1.
760     // Inputs:
761     //    none.
762     // Outputs:
763     //    none.
764     // Return:
765     //    none.
766     ////////////////////////////////////////////////////////////////////////
767     // Set everything unseen
768     gMC->Gsatt("*", "seen", -1);
769     // Set ALIC mother visible
770     gMC->Gsatt("ALIC","SEEN",0);
771     // Set ALIC ITS visible
772     gMC->Gsatt("ITSV","SEEN",0);
773     // Set ALIC Telescopes visible
774     gMC->Gsatt("ITEL","SEEN",0);
775     // Set ALIC detetcor visible
776     gMC->Gsatt("IDET","SEEN",0);
777     // Set Detector chip mother visible and drawn
778     gMC->Gsatt("IPC0","SEEN",1);
779     // Set Detector mother visible and drawn
780     gMC->Gsatt("ITS0","SEEN",1);
781     // Set minibus chip mother visible and drawn
782     gMC->Gsatt("ICMB","SEEN",1);
783     // Set minibus mother visible and drawn
784     gMC->Gsatt("IMB0","SEEN",1);
785 }
786 //______________________________________________________________________
787 void AliITSvSPD02::StepManager(){
788     ////////////////////////////////////////////////////////////////////////
789     //    Called for every step in the ITS SPD test beam, then calles the 
790     // AliITShit class  creator with the information to be recoreded about
791     //  that hit.
792     //     The value of the macro ALIITSPRINTGEOM if set to 1 will allow the
793     // printing of information to a file which can be used to create a .det
794     // file read in by the routine CreateGeometry(). If set to 0 or any other
795     // value except 1, the default behavior, then no such file is created nor
796     // it the extra variables and the like used in the printing allocated.
797     // Inputs:
798     //    none.
799     // Outputs:
800     //    none.
801     // Return:
802     //    none.
803     ////////////////////////////////////////////////////////////////////////
804     Int_t         copy=0, id;
805     TLorentzVector position, momentum;
806     static TLorentzVector position0;
807     static Int_t stat0=0;
808     if((id=gMC->CurrentVolID(copy) == fIDMother)&&
809        (gMC->IsTrackEntering()||gMC->IsTrackExiting())){
810         copy = fTrackReferences->GetEntriesFast();
811         TClonesArray &lTR = *fTrackReferences;
812         // Fill TrackReference structure with this new TrackReference.
813         new(lTR[copy]) AliTrackReference(gAlice->GetMCApp()->
814                                          GetCurrentTrackNumber());
815     } // if Outer ITS mother Volume
816     if(!(this->IsActive())){
817         return;
818     } // end if !Active volume.
819     Int_t   vol[5];
820     TClonesArray &lhits = *fHits;
821     //
822     // Track status
823     vol[3] = 0;
824     vol[4] = 0;
825     if(gMC->IsTrackInside())      vol[3] +=  1;
826     if(gMC->IsTrackEntering())    vol[3] +=  2;
827     if(gMC->IsTrackExiting())     vol[3] +=  4;
828     if(gMC->IsTrackOut())         vol[3] +=  8;
829     if(gMC->IsTrackDisappeared()) vol[3] += 16;
830     if(gMC->IsTrackStop())        vol[3] += 32;
831     if(gMC->IsTrackAlive())       vol[3] += 64;
832     //
833     // Fill hit structure.
834     if(!(gMC->TrackCharge())) return;
835     id = gMC->CurrentVolID(copy);
836     if(id==fIdSens[0]){  // Volume name "IMBS"
837         vol[2] = vol[1] = 1; // Det, ladder
838         id = gMC->CurrentVolOffID(2,copy);
839         //detector copy in the ladder = 1<->4  (ITS1 < I101 < I103 < I10A)
840         vol[0] = copy; // Lay
841         if(copy>2) vol[0]++;
842     } else if(id == fIdSens[1]){ // Volume name "ITST"
843         vol[0] = 3; // layer
844         vol[1] = 1; // ladder
845         id = gMC->CurrentVolOffID(2,copy);
846         //detector copy in the ladder = 1<->4  (ITS2 < I1D1 < I1D3 < I20A)
847         vol[2] = 1;  // detector
848     } else return; // end if
849     //
850     gMC->TrackPosition(position);
851     gMC->TrackMomentum(momentum);
852     vol[4] = stat0;
853     if(gMC->IsTrackEntering()){
854         position0 = position;
855         stat0 = vol[3];
856         return;
857     } // end if IsEntering
858     // Fill hit structure with this new hit only for non-entrerance hits.
859     else new(lhits[fNhits++]) AliITShit(fIshunt,
860                                   gAlice->GetMCApp()->GetCurrentTrackNumber(),
861                                         vol,gMC->Edep(),gMC->TrackTime(),
862                                         position,position0,momentum);
863     //
864     position0 = position;
865     stat0 = vol[3];
866
867     return;
868 }
869