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