]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSvSPD02.cxx
bug fix, lets creation of SDigits to works properly.
[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 /*
17 $Log$
18 Revision 1.4  2003/04/08 08:16:50  morsch
19 AliTrackReference constructor without passing pointer to VMC.
20
21 Revision 1.3  2003/03/21 14:34:10  nilsen
22 Removed warning from part of code not properly implimneted yet.
23
24 Revision 1.2  2003/02/12 10:39:05  hristov
25 Updated AliTrackReference class (S.Radomski)
26
27 Revision 1.1  2002/12/05 20:07:25  nilsen
28 Adding new SPD 2002 test-beam geometry, with Config file (setup for testing,
29 50 pions in one event and not 50 events with one pion).
30
31 */
32 #include <Riostream.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <TMath.h>
36 #include <TGeometry.h>
37 #include <TNode.h>
38 #include <TTUBE.h>
39 #include <TTUBS.h>
40 #include <TPCON.h>
41 #include <TFile.h>    // only required for Tracking function?
42 #include <TCanvas.h>
43 #include <TObjArray.h>
44 #include <TLorentzVector.h>
45 #include <TObjString.h>
46 #include <TClonesArray.h>
47 #include <TBRIK.h>
48 #include <TSystem.h>
49
50 #include "AliRun.h"
51 #include "AliMagF.h"
52 #include "AliConst.h"
53 #include "AliITSGeant3Geometry.h"
54 #include "AliTrackReference.h"
55 #include "AliITShit.h"
56 #include "AliITS.h"
57 #include "AliITSvSPD02.h"
58 #include "AliITSgeom.h"
59 #include "AliITSgeomSPD.h"
60 #include "AliITSgeomSDD.h"
61 #include "AliITSgeomSSD.h"
62 #include "AliITSDetType.h"
63 #include "AliITSresponseSPD.h"
64 #include "AliITSresponseSDD.h"
65 #include "AliITSresponseSSD.h"
66 #include "AliITSsegmentationSPD.h"
67 #include "AliITSsegmentationSDD.h"
68 #include "AliITSsegmentationSSD.h"
69 #include "AliITSsimulationSPD.h"
70 #include "AliITSsimulationSDD.h"
71 #include "AliITSsimulationSSD.h"
72 #include "AliITSClusterFinderSPD.h"
73 #include "AliITSClusterFinderSDD.h"
74 #include "AliITSClusterFinderSSD.h"
75
76
77 ClassImp(AliITSvSPD02)
78
79 //______________________________________________________________________
80 AliITSvSPD02::AliITSvSPD02() {
81     ////////////////////////////////////////////////////////////////////////
82     // Standard default constructor for the ITS SPD test beam 2002 version 1.
83     // Inputs:
84     //    none.
85     // Outputs:
86     //    none.
87     // Return:
88     //    A default created class.
89     ////////////////////////////////////////////////////////////////////////
90     Int_t i;
91
92     fIdN          = 0;
93     fIdName       = 0;
94     fIdSens       = 0;
95     fEuclidOut    = kFALSE; // Don't write Euclide file
96     fGeomDetOut   = kFALSE; // Don't write .det file
97     fGeomDetIn    = kFALSE; // Don't Read .det file
98     fMajorVersion = IsVersion();
99     fMinorVersion = -1;
100     for(i=0;i<60;i++) fRead[i] = '\0';
101     for(i=0;i<60;i++) fWrite[i] = '\0';
102     for(i=0;i<60;i++) fEuclidGeomDet[i] = '\0';
103 }
104 //______________________________________________________________________
105 AliITSvSPD02::AliITSvSPD02(const char *title) : AliITS("ITS", title){
106     ////////////////////////////////////////////////////////////////////////
107     //    Standard constructor for the ITS SPD testbeam 2002 version 1.
108     // Inputs:
109     //    const char *title    title for this ITS geometry.
110     // Outputs:
111     //    none.
112     // Return:
113     //    A standard created class.
114     ////////////////////////////////////////////////////////////////////////
115     Int_t i;
116
117     fIdN = 2;
118     fIdName = new TString[fIdN];
119     fIdName[0] = "IMBS";
120     fIdName[1] = "ITST";
121     fIdSens    = new Int_t[fIdN];
122     for(i=0;i<fIdN;i++) fIdSens[i] = 0;
123     fMajorVersion = IsVersion();
124     fMinorVersion = 2;
125     fEuclidOut    = kFALSE; // Don't write Euclide file
126     fGeomDetOut   = kFALSE; // Don't write .det file
127     fGeomDetIn    = kFALSE; // Don't Read .det file
128     SetThicknessDet1();
129     SetThicknessDet2();
130     SetThicknessChip1();
131     SetThicknessChip2();                         
132
133     fEuclidGeometry="$ALICE_ROOT/ITS/ITSgeometry_vSPD022.euc";
134     strncpy(fEuclidGeomDet,"$ALICE_ROOT/ITS/ITSgeometry_vSPD022.det",60);
135     strncpy(fRead,fEuclidGeomDet,60);
136     strncpy(fWrite,fEuclidGeomDet,60);
137 }
138 //______________________________________________________________________
139 AliITSvSPD02::AliITSvSPD02(const AliITSvSPD02 &source){
140     ////////////////////////////////////////////////////////////////////////
141     //     Copy Constructor for ITS SPD test beam 2002 version 1.
142     // This class is not to be copied. Function only dummy.
143     // Inputs:
144     //    const AliITSvSPD02 &source   The class to be copied
145     // Outputs:
146     //    none.
147     // Return:
148     //    A warning message.
149     ////////////////////////////////////////////////////////////////////////
150     if(&source == this) return;
151     Warning("Copy Constructor","Not allowed to copy AliITSvSPD02");
152     return;
153 }
154 //______________________________________________________________________
155 AliITSvSPD02& AliITSvSPD02::operator=(const AliITSvSPD02 &source){
156     ////////////////////////////////////////////////////////////////////////
157     //    Assignment operator for the ITS SPD test beam 2002 version 1.
158     // This class is not to be copied. Function only dummy.
159     // Inputs:
160     //    const AliITSvSPD02 &source   The class to be copied
161     // Outputs:
162     //    none.
163     // Return:
164     //    A Warning message
165     ////////////////////////////////////////////////////////////////////////
166     if(&source == this) return *this;
167     Warning("= operator","Not allowed to copy AliITSvSPD02");
168     return *this;
169 }
170 //______________________________________________________________________
171 AliITSvSPD02::~AliITSvSPD02() {
172     ////////////////////////////////////////////////////////////////////////
173     //    Standard destructor for the ITS SPD test beam 2002 version 1.
174     // Inputs:
175     //    none.
176     // Outputs:
177     //    none.
178     // Return:
179     //    none.
180     ////////////////////////////////////////////////////////////////////////
181 }
182 //______________________________________________________________________
183 void AliITSvSPD02::BuildGeometry(){
184     ////////////////////////////////////////////////////////////////////////
185     //    Geometry builder for the ITS SPD test beam 2002 version 1.
186     //    ALIC    ALICE Mother Volume
187     //     |- ITSV     ITS Mother Volume
188     //         |- IDET       Detector under Test
189     //         |   |- ITS0       SPD Si Chip
190     //         |   |  |- ITST      SPD Sensitivve Volume
191     //         |   |- IPC0 *5    Readout chip
192     //         |- ITEL *4    SPD Telescope
193     //             |- IMB0       SPD Si Chip
194     //             |   |- IMBS     SPD Sensitive volume
195     //             |- ICMB       Chip MiniBus.
196     // Inputs:
197     //    none.
198     // Outputs:
199     //    none.
200     // Return:
201     //    none.
202     ////////////////////////////////////////////////////////////////////////
203     // Get the top alice volume.
204     TNode *ALIC = gAlice->GetGeometry()->GetNode("alice");
205     ALIC->cd();
206
207     // Define ITS Mother Volume
208     Float_t data[3];
209     Float_t ddettest=200.0E-4,ddettelescope=300.0E-4;
210     Float_t dchipMiniBus=750.0E-4,dchiptest=300.0E-4;
211     //Float_t yposition= 0.0;
212     TRotMatrix *r0 = new TRotMatrix("ITSidrotm0","ITSidrotm0",
213                                     90.0,0,0.0,0,90.0,270.0);
214     data[0] = 10.0;
215     data[1] = 50.0;
216     data[2] = 100.0;
217     TBRIK *ITSVshape = new TBRIK("ITSVshape","ITS Logical Mother Volume","Air",
218                                  data[0],data[1],data[2]);
219     TNode *ITSV = new TNode("ITSV","ITS Mother Volume",ITSVshape,
220                             0.0,0.0,0.0,0,0);
221     ITSV->cd(); // set ourselve into ITSV subvolume of ALIC
222
223     // SPD part of telescope (MiniBuS)
224     data[0] = 0.705;
225     data[1] = 0.5*ddettelescope;
226     data[2] = 3.536;
227     TBRIK *IMB0shape = new TBRIK("IMB0shape","SPD wafer","Si",
228                                  data[0],data[1],data[2]);
229     Float_t detMiniBusX,detMiniBusY,detMiniBusZ;
230     data[0] = detMiniBusX = 0.64;
231     data[1] = detMiniBusY = 0.5*ddettelescope;
232     data[2] = detMiniBusZ = 3.48;
233     TBRIK *IMBSshape = new TBRIK("IMBSshape","SPD Sensitive volume","Si",
234                                  data[0],data[1],data[2]);
235     Float_t chipMiniBusX,chipMiniBusY,chipMiniBusZ;
236     data[0] = chipMiniBusX = 0.793;
237     data[1] = chipMiniBusY = 0.5*dchipMiniBus;
238     data[2] = chipMiniBusZ = 0.68;
239     TBRIK *ICMBshape = new TBRIK("ICMBshape","chip Minibus","Si",
240                                  data[0],data[1],data[2]);
241     data[0] = TMath::Max(detMiniBusX,chipMiniBusX);
242     data[1] = detMiniBusY+chipMiniBusY;
243     data[2] = TMath::Max(detMiniBusZ,chipMiniBusZ);
244     TBRIK *ITELshape = new TBRIK("ITELshape","ITELshape","Air",
245                                  data[0],data[1],data[2]);
246
247     // SPD under test
248     Float_t spdX,spdY,spdZ,spdchipX,spdchipY,spdchipZ;
249     data[0] = 0.705;
250     data[1] = ddettest;
251     data[2] = 3.536;
252     TBRIK *ITS0shape = new TBRIK("ITS0shape","SPD wafer","Si",
253                                  data[0],data[1],data[2]); // contains detector
254     data[0] = spdX = 0.64;
255     data[1] = spdY = ddettest;
256     data[2] = spdZ = 3.48;
257     TBRIK *ITSTshape = new TBRIK("ITSTshape","SPD sensitive volume","Si",
258                                  data[0],data[1],data[2]);
259     // ITS0 with no translation and unit rotation matrix.
260     data[0] = spdchipX = 0.793;
261     data[1] = spdchipY = dchiptest;
262     data[2] = spdchipZ = 0.68;
263     TBRIK *IPC0shape = new TBRIK("IPC0shape","Readout Chips","Si",
264                                  data[0],data[1],data[2]); // chip under test
265     data[0] = TMath::Max(spdchipX,spdX);
266     data[1] = spdY+spdchipY;
267     data[2] = TMath::Max(spdchipZ,spdZ);
268     TBRIK *IDETshape = new TBRIK("IDETshape","Detector Under Test","Air",
269                                  data[0],data[1],data[2]);
270     // Place volumes in geometry
271     Int_t i,j;
272     char name[20],title[50];
273     Double_t px=0.0,py=0.0,pz[4]={-38.0,0.0,0.0,0.0};
274     pz[1] = pz[0]+2.0;
275     pz[2] = pz[1]+38.0+spdY+spdchipY+34.5;
276     pz[3] = pz[2]+2.0;
277     TNode *ITEL[4],*ICMB[4],*IMB0[4],*IMBS[4];
278     TNode *IDET = new TNode("IDET","Detector Under Test",IDETshape,
279                             0.0,0.0,pz[1]+38.0,r0,0);
280     IDET->cd();
281     TNode *ITS0 = new TNode("ITS0","SPD Chip",ITS0shape,
282                             0.0,IDETshape->GetDy()-spdY,0.0,0,0);
283     TNode *IPC0[5];
284     for(i=0;i<5;i++) { //place readout chips on the back of SPD chip under test
285         sprintf(name,"IPC0%d",i);
286         sprintf(title,"Readout chip #%d",i+1);
287         j = i-2;
288         IPC0[i] = new TNode(name,title,IPC0shape,
289                             0.0,spdchipY-IDETshape->GetDy(),
290                             j*2.0*spdchipZ+j*0.25*(spdZ-5.*spdchipZ),0,0);
291     } // end for i
292     ITS0->cd();
293     TNode *ITST = new TNode("ITST","SPD sensitive volume",ITSTshape,
294                             0.0,0.0,0.0,0,0);
295     for(Int_t i=0;i<4;i++){
296         ITSV->cd();
297         sprintf(name,"ITEL%d",i);
298         sprintf(title,"Test beam telescope element #%d",i+1);
299         ITEL[i] = new TNode(name,title,ITELshape,px,py,pz[i],r0,0);
300         ITEL[i]->cd();
301         ICMB[i] = new TNode("ICMB","Chip MiniBus",ICMBshape,
302                             0.0,-ITELshape->GetDy()+detMiniBusY,0.0,0,0);
303         IMB0[i] = new TNode("IMB0","Chip MiniBus",IMB0shape,
304                             0.0, ITELshape->GetDy()-detMiniBusY,0.0,0,0);
305         IMB0[i]->cd();
306         IMBS[i] = new TNode("IMBS","IMBS",IMBSshape,0.0,0.0,0.0,0,0);
307         // place IMBS inside IMB0 with no translation and unit rotation matrix.
308     } // end for i
309     ALIC->cd();
310     ITST->SetLineColor(kYellow);
311     fNodes->Add(ITST);
312     for(i=0;i<4;i++){
313         IMBS[i]->SetLineColor(kGreen);
314         fNodes->Add(IMBS[i]);
315     } // end for i
316 }
317 //______________________________________________________________________
318 void AliITSvSPD02::CreateGeometry(){
319     ////////////////////////////////////////////////////////////////////////
320     //  This routine defines and Creates the geometry for version 1 of the ITS.
321     //    ALIC    ALICE Mother Volume
322     //     |- ITSV     ITS Mother Volume
323     //         |- IDET       Detector under Test
324     //         |   |- ITS0       SPD Si Chip
325     //         |   |  |- ITST      SPD Sensitivve Volume
326     //         |   |- IPC0 *5    Readout chip
327     //         |- ITEL *4    SPD Telescope
328     //             |- IMB0       SPD Si Chip
329     //             |   |- IMBS     SPD Sensitive volume
330     //             |- ICMB       Chip MiniBus.
331     // Inputs:
332     //    none.
333     // Outputs:
334     //    none.
335     // Return:
336     //    none.
337     ////////////////////////////////////////////////////////////////////////
338     Float_t data[49];
339     // Define media off-set
340     Int_t *idtmed = fIdtmed->GetArray()+1; // array of media indexes
341     Int_t idrotm[4]; // Array of rotation matrix indexes
342     Float_t ddettest=200.0E-4,ddettelescope=300.0E-4;
343     Float_t dchipMiniBus=750.0E-4,dchiptest=300.0E-4;
344     Float_t yposition= 0.0;
345
346     // Define Rotation-reflextion Matrixes needed
347     // 0 is the unit matrix
348     AliMatrix(idrotm[0], 90.0,0.0, 0.0,0.0, 90.0,270.0);
349     data[0] = 10.0;
350     data[1] = 50.0;
351     data[2] = 100.0;
352     gMC->Gsvolu("ITSV","BOX",idtmed[0],data,3);
353     gMC->Gspos("ITSV",1,"ALIC",0.0,0.0,0.0,0,"ONLY");
354
355     //cout << "idtmed[0]=" << idtmed[0]<<endl;
356     //cout << "idtmed[1]=" << idtmed[1]<<endl;
357     Float_t detMiniBusX,detMiniBusY,detMiniBusZ;
358     // SPD part of telescope (MiniBuS)
359     data[0] = detMiniBusX = 0.705;
360     data[1] = detMiniBusY = 0.5*ddettelescope;
361     data[2] = detMiniBusZ = 3.536;
362     gMC->Gsvolu("IMB0", "BOX ", idtmed[1], data, 3);   // contains detector
363     data[0] = 0.64;
364     data[1] = 0.5*ddettelescope;
365     data[2] = 3.48;
366     gMC->Gsvolu("IMBS","BOX ",idtmed[1],data,3); // sensitive detecor volulme
367     gMC->Gspos("IMBS",1,"IMB0",0.0,0.0,0.0,0,"ONLY"); // place IMBS inside
368     // IMB0 with no translation and unit rotation matrix.
369     Float_t chipMiniBusX,chipMiniBusY,chipMiniBusZ;
370     data[0] = chipMiniBusX = 0.793;
371     data[1] = chipMiniBusY = 0.5*dchipMiniBus;
372     data[2] = chipMiniBusZ = 0.68;
373     gMC->Gsvolu("ICMB","BOX ",idtmed[1],data, 3);   // chip Minibus
374     data[0] = TMath::Max(detMiniBusX,chipMiniBusX);
375     data[1] = detMiniBusY+chipMiniBusY;
376     data[2] = TMath::Max(detMiniBusZ,chipMiniBusZ);
377     gMC->Gsvolu("ITEL","BOX ",idtmed[0],data,3);
378     gMC->Gspos("IMB0",1,"ITEL",0.0,data[1]-detMiniBusY,0.0,0,"ONLY");
379     gMC->Gspos("ICMB",1,"ITEL",0.0,-data[1]+chipMiniBusY,0.0,0,"ONLY");
380
381     // SPD under test
382     Float_t spdX,spdY,spdZ,spdchipX,spdchipY,spdchipZ;
383     data[0] = spdX = 0.705;
384     data[1] = spdY = 0.5*ddettest;
385     data[2] = spdZ = 3.536;
386     gMC->Gsvolu("ITS0", "BOX ", idtmed[1], data, 3);   // contains detector
387     data[0] = 0.64;
388     data[1] = 0.5*ddettest;
389     data[2] = 3.48;
390     gMC->Gsvolu("ITST","BOX ",idtmed[1],data,3);// sensitive detecor volume
391     gMC->Gspos("ITST",1,"ITS0",0.0,0.0,0.0,0,"ONLY"); // place ITST inside
392     // ITS0 with no translation and unit rotation matrix.
393     data[0] = spdchipX = 0.793;
394     data[1] = spdchipY = 0.5*dchiptest;
395     data[2] = spdchipZ = 0.68;
396     gMC->Gsvolu("IPC0", "BOX ", idtmed[1],data,3);   // chip under test
397     data[0] = TMath::Max(spdchipX,spdX);
398     data[1] = spdY+spdchipY;
399     data[2] = TMath::Max(spdchipZ,spdZ);
400     gMC->Gsvolu("IDET","BOX ",idtmed[0],data,3);
401     gMC->Gspos("ITS0",1,"IDET",0.0,data[1]-spdY,0.0,0,"ONLY");
402     for(Int_t i=-2;i<3;i++) gMC->Gspos("IPC0",i+3,"IDET",0.0,-data[1]+spdchipY,
403               i*2.*spdchipZ+i*0.25*(spdZ-5.*spdchipZ),0,"ONLY");
404
405     // Positions detectors, Beam Axis Z, X to the right, Y up to the sky.
406     Float_t p00X,p00Y,p00Z,p01X,p01Y,p01Z,p10X,p10Y,p10Z,p11X,p11Y,p11Z;
407     p00X = 0.0;
408     p00Y = 0.0;
409     p00Z = -38.0;
410     gMC->Gspos("ITEL",1,"ITSV",p00X,p00Y,p00Z,idrotm[0],"ONLY");
411     p01X = 0.0;
412     p01Y = 0.0;
413     p01Z = p00Z+2.0;
414     gMC->Gspos("ITEL",2,"ITSV",p01X,p01Y,p01Z,idrotm[0],"ONLY");
415     Float_t pdetX,pdetY,pdetZ;
416     pdetX = 0.0;
417     pdetY = 0.0+yposition;
418     pdetZ = p01Z+38.0;
419     gMC->Gspos("IDET",1,"ITSV",pdetX,pdetY,pdetZ,idrotm[0],"ONLY");
420     p10X = 0.0;
421     p10Y = 0.0;
422     p10Z = pdetZ + 34.5;
423     gMC->Gspos("ITEL",3,"ITSV",p10X,p10Y,p10Z,idrotm[0],"ONLY");
424     p11X = 0.0;
425     p11Y = 0.0;
426     p11Z = p10Z+2.0;
427     gMC->Gspos("ITEL",4,"ITSV",p11X,p11Y,p11Z,idrotm[0],"ONLY");
428 }
429 //______________________________________________________________________
430 void AliITSvSPD02::CreateMaterials(){
431     ////////////////////////////////////////////////////////////////////////
432     //
433     // Create ITS SPD test beam materials
434     //     This function defines the default materials used in the Geant
435     // Monte Carlo simulations for the geometries AliITSv1, AliITSv3,
436     // AliITSvSPD02.
437     // In general it is automatically replaced by
438     // the CreatMaterials routine defined in AliITSv?. Should the function
439     // CreateMaterials not exist for the geometry version you are using this
440     // one is used. See the definition found in AliITSv5 or the other routine
441     // for a complete definition.
442     //
443     // Inputs:
444     //    none.
445     // Outputs:
446     //    none.
447     // Return:
448     //    none.
449     /////////////////////////////////////////////////////////////////////////
450     Float_t tmaxfdSi = 0.1; // Degree
451     Float_t stemaxSi = 0.0075; // cm
452     Float_t deemaxSi = 0.1; // Fraction of particle's energy 0<deemax<=1
453     Float_t epsilSi  = 1.0E-4;//
454     Float_t stminSi  = 0.0; // cm "Default value used"
455
456     Float_t tmaxfdAir = 0.1; // Degree
457     Float_t stemaxAir = .10000E+01; // cm
458     Float_t deemaxAir = 0.1; // Fraction of particle's energy 0<deemax<=1
459     Float_t epsilAir  = 1.0E-4;//
460     Float_t stminAir  = 0.0; // cm "Default value used"
461     Int_t   ifield = gAlice->Field()->Integ();
462     Float_t fieldm = gAlice->Field()->Max();
463
464     AliMaterial(1,"AIR$",0.14610E+02,0.73000E+01,0.12050E-02,
465                 0.30423E+05,0.99900E+03);
466     AliMedium(1,"AIR$",1,0,ifield,fieldm,tmaxfdAir,stemaxAir,deemaxAir,
467               epsilAir,stminAir);
468
469     AliMaterial(2,"SI$",0.28086E+02,0.14000E+02,0.23300E+01,
470                 0.93600E+01,0.99900E+03);
471     AliMedium(2,"SI$",2,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,
472               epsilSi,stminSi);
473 }
474 //______________________________________________________________________
475 void AliITSvSPD02::InitAliITSgeom(){
476     //     Based on the geometry tree defined in Geant 3.21, this
477     // routine initilizes the Class AliITSgeom from the Geant 3.21 ITS geometry
478     // sturture.
479     // Inputs:
480     //    none.
481     // Outputs:
482     //    none.
483     // Return:
484     //    none.
485     if(strcmp(gMC->GetName(),"TGeant3")) {
486         Error("InitAliITSgeom",
487                 "Wrong Monte Carlo. InitAliITSgeom uses TGeant3 calls");
488         return;
489     } // end if
490     cout << "Reading Geometry transformation directly from Geant 3." << endl;
491     const Int_t ltypess = 2;
492     const Int_t nlayers = 5;
493     const Int_t ndeep = 5;
494     Int_t itsGeomTreeNames[ltypess][ndeep],lnam[20],lnum[20];
495     Int_t nlad[nlayers],ndet[nlayers];
496     Double_t t[3],r[10];
497     Float_t  par[20],att[20];
498     Int_t    npar,natt,idshape,imat,imed;
499     AliITSGeant3Geometry *ig = new AliITSGeant3Geometry();
500     Int_t mod,typ,lay,lad,det,cpy,i,j,k;
501     Char_t names[ltypess][ndeep][4];
502     Int_t itsGeomTreeCopys[ltypess][ndeep];
503     Char_t *namesA[ltypess][ndeep] = {
504      {"ALIC","ITSV","ITEL","IMB0","IMBS"}, // lay=1
505      {"ALIC","ITSV","IDET","ITS0","ITST"}};// Test SPD
506     Int_t itsGeomTreeCopysA[ltypess][ndeep]= {{1,1,4,1,1},// lay=1
507                                               {1,1,1,1,1}};//lay=2 TestSPD
508     for(i=0;i<ltypess;i++)for(j=0;j<ndeep;j++){
509         for(k=0;k<4;k++) names[i][j][k] = namesA[i][j][k];
510         itsGeomTreeCopys[i][j] = itsGeomTreeCopysA[i][j];
511     } // end for i,j
512     // Sorry, but this is not very pritty code. It should be replaced
513     // at some point with a version that can search through the geometry
514     // tree its self.
515     cout << "Reading Geometry informaton from Geant3 common blocks" << endl;
516     for(i=0;i<20;i++) lnam[i] = lnum[i] = 0;
517     for(i=0;i<ltypess;i++)for(j=0;j<ndeep;j++) 
518         itsGeomTreeNames[i][j] = ig->StringToInt(names[i][j]);
519     mod = 5;
520
521     if(fITSgeom!=0) delete fITSgeom;
522     nlad[0]=1;nlad[1]=1;nlad[2]=1;nlad[3]=1;nlad[4]=1;
523     ndet[0]=1;ndet[1]=1;ndet[2]=1;ndet[3]=1;ndet[4]=1;
524     fITSgeom = new AliITSgeom(0,nlayers,nlad,ndet,mod);
525     for(typ=1;typ<=ltypess;typ++){
526         for(j=0;j<ndeep;j++) lnam[j] = itsGeomTreeNames[typ-1][j];
527         for(j=0;j<ndeep;j++) lnum[j] = itsGeomTreeCopys[typ-1][j];
528         lad = 1;
529         det = 1;
530         for(cpy=1;cpy<=itsGeomTreeCopys[typ-1][2];cpy++){
531             lnum[2] = cpy;
532             lay = cpy;
533             if(cpy>2 && typ==1) lay = cpy +1;
534             if(typ==2) lay = 3;
535             mod = lay-1;
536             ig->GetGeometry(ndeep,lnam,lnum,t,r,idshape,npar,natt,par,att,
537                             imat,imed);
538             fITSgeom->CreatMatrix(mod,lay,lad,det,kSPD,t,r);
539             if(!(fITSgeom->IsShapeDefined((Int_t)kSPD)))
540                 fITSgeom->ReSetShape(kSPD,
541                                      new AliITSgeomSPD425Short(npar,par));
542         } // end for cpy
543     } // end for typ
544     return;
545 }
546 //______________________________________________________________________
547 void AliITSvSPD02::Init(){
548     ////////////////////////////////////////////////////////////////////////
549     //     Initialise the ITS after it has been created.
550     // Inputs:
551     //    none.
552     // Outputs:
553     //    none.
554     // Return:
555     //    none.
556     ////////////////////////////////////////////////////////////////////////
557     Int_t i;
558
559     cout << endl;
560     for(i=0;i<26;i++) cout << "*";
561     cout << " ITSvSPD02" << fMinorVersion << "_Init ";
562     for(i=0;i<25;i++) cout << "*";cout << endl;
563 //
564     if(fRead[0]=='\0') strncpy(fRead,fEuclidGeomDet,60);
565     if(fWrite[0]=='\0') strncpy(fWrite,fEuclidGeomDet,60);
566     if(fITSgeom!=0) delete fITSgeom;
567     fITSgeom = new AliITSgeom();
568     if(fGeomDetIn) fITSgeom->ReadNewFile(fRead);
569     if(!fGeomDetIn) this->InitAliITSgeom();
570     if(fGeomDetOut) fITSgeom->WriteNewFile(fWrite);
571     AliITS::Init();
572 //
573     for(i=0;i<72;i++) cout << "*";
574     cout << endl;
575     fIDMother = gMC->VolId("ITSV"); // ITS Mother Volume ID.
576 }
577 //______________________________________________________________________
578 void AliITSvSPD02::SetDefaults(){
579     // sets the default segmentation, response, digit and raw cluster classes
580     // Inputs:
581     //    none.
582     // Outputs:
583     //    none.
584     // Return:
585     //    none.
586     const Float_t kconv = 1.0e+04; // convert cm to microns
587
588     Info("SetDefaults","Setting up only SPD detector");
589
590     AliITSDetType *iDetType;
591     AliITSgeomSPD  *s0;
592     Int_t i;
593     Float_t bx[256],bz[280];
594
595     //SPD
596     iDetType=DetType(kSPD);
597     s0 = (AliITSgeomSPD*) fITSgeom->GetShape(kSPD);// Get shape info. Do it this way for now.
598     AliITSresponse *resp0=new AliITSresponseSPD();
599     SetResponseModel(kSPD,resp0);
600     AliITSsegmentationSPD *seg0=new AliITSsegmentationSPD(fITSgeom);
601     seg0->SetDetSize(s0->GetDx()*2.*kconv, // base this on AliITSgeomSPD
602                      s0->GetDz()*2.*kconv, // for now.
603                      s0->GetDy()*2.*kconv); // x,z,y full width in microns.
604     seg0->SetNPads(256,160);// Number of Bins in x and z
605     for(i=000;i<256;i++) bx[i] =  50.0; // in x all are 50 microns.
606     for(i=000;i<160;i++) bz[i] = 425.0; // most are 425 microns except below
607     for(i=160;i<280;i++) bz[i] =   0.0; // Outside of detector.
608     bz[ 31] = bz[ 32] = 625.0; // first chip boundry
609     bz[ 63] = bz[ 64] = 625.0; // first chip boundry
610     bz[ 95] = bz[ 96] = 625.0; // first chip boundry
611     bz[127] = bz[128] = 625.0; // first chip boundry
612     bz[160] = 425.0; // Set so that there is no zero pixel size for fNz.
613     seg0->SetBinSize(bx,bz); // Based on AliITSgeomSPD for now.
614     SetSegmentationModel(kSPD,seg0);
615     // set digit and raw cluster classes to be used
616     const char *kData0=(iDetType->GetResponseModel())->DataType();
617     if (strstr(kData0,"real")) iDetType->ClassNames("AliITSdigit",
618                                                     "AliITSRawClusterSPD");
619     else iDetType->ClassNames("AliITSdigitSPD","AliITSRawClusterSPD");
620 //    SetSimulationModel(kSPD,new AliITSsimulationSPD(seg0,resp0));
621 //    iDetType->ReconstructionModel(new AliITSClusterFinderSPD());
622
623     SetResponseModel(kSDD,new AliITSresponseSDD());
624     SetSegmentationModel(kSDD,new AliITSsegmentationSDD());
625     DetType(kSDD)->ClassNames("AliITSdigitSDD","AliITSRawClusterSDD");
626
627     SetResponseModel(kSSD,new AliITSresponseSSD());
628     SetSegmentationModel(kSSD,new AliITSsegmentationSSD());
629     DetType(kSSD)->ClassNames("AliITSdigitSSD","AliITSRawClusterSSD");
630
631     if(kNTYPES>3){
632         Warning("SetDefaults",
633                 "Only the four basic detector types are initialised!");
634     }// end if
635     return;
636 }
637 //______________________________________________________________________
638 void AliITSvSPD02::DrawModule(){
639     ////////////////////////////////////////////////////////////////////////
640     //     Draw a shaded view of the ITS SPD test beam version 1.
641     // Inputs:
642     //    none.
643     // Outputs:
644     //    none.
645     // Return:
646     //    none.
647     ////////////////////////////////////////////////////////////////////////
648     // Set everything unseen
649     gMC->Gsatt("*", "seen", -1);
650     // Set ALIC mother visible
651     gMC->Gsatt("ALIC","SEEN",0);
652     // Set ALIC ITS visible
653     gMC->Gsatt("ITSV","SEEN",0);
654     // Set ALIC Telescopes visible
655     gMC->Gsatt("ITEL","SEEN",0);
656     // Set ALIC detetcor visible
657     gMC->Gsatt("IDET","SEEN",0);
658     // Set Detector chip mother visible and drawn
659     gMC->Gsatt("IPC0","SEEN",1);
660     // Set Detector mother visible and drawn
661     gMC->Gsatt("ITS0","SEEN",1);
662     // Set minibus chip mother visible and drawn
663     gMC->Gsatt("ICMB","SEEN",1);
664     // Set minibus mother visible and drawn
665     gMC->Gsatt("IMB0","SEEN",1);
666 }
667 //______________________________________________________________________
668 void AliITSvSPD02::StepManager(){
669     ////////////////////////////////////////////////////////////////////////
670     //    Called for every step in the ITS SPD test beam, then calles the 
671     // AliITShit class  creator with the information to be recoreded about
672     //  that hit.
673     //     The value of the macro ALIITSPRINTGEOM if set to 1 will allow the
674     // printing of information to a file which can be used to create a .det
675     // file read in by the routine CreateGeometry(). If set to 0 or any other
676     // value except 1, the default behavior, then no such file is created nor
677     // it the extra variables and the like used in the printing allocated.
678     // Inputs:
679     //    none.
680     // Outputs:
681     //    none.
682     // Return:
683     //    none.
684     ////////////////////////////////////////////////////////////////////////
685     Int_t         copy, id;
686     TLorentzVector position, momentum;
687     static TLorentzVector position0;
688     static Int_t stat0=0;
689     if((id=gMC->CurrentVolID(copy) == fIDMother)&&
690        (gMC->IsTrackEntering()||gMC->IsTrackExiting())){
691         copy = fTrackReferences->GetEntriesFast();
692         TClonesArray &lTR = *fTrackReferences;
693         // Fill TrackReference structure with this new TrackReference.
694         new(lTR[copy]) AliTrackReference(gAlice->CurrentTrack());
695     } // if Outer ITS mother Volume
696     if(!(this->IsActive())){
697         return;
698     } // end if !Active volume.
699     Int_t   vol[5];
700     TClonesArray &lhits = *fHits;
701     //
702     // Track status
703     vol[3] = 0;
704     vol[4] = 0;
705     if(gMC->IsTrackInside())      vol[3] +=  1;
706     if(gMC->IsTrackEntering())    vol[3] +=  2;
707     if(gMC->IsTrackExiting())     vol[3] +=  4;
708     if(gMC->IsTrackOut())         vol[3] +=  8;
709     if(gMC->IsTrackDisappeared()) vol[3] += 16;
710     if(gMC->IsTrackStop())        vol[3] += 32;
711     if(gMC->IsTrackAlive())       vol[3] += 64;
712     //
713     // Fill hit structure.
714     if(!(gMC->TrackCharge())) return;
715     id = gMC->CurrentVolID(copy);
716     if(id==fIdSens[0]){  // Volume name "IMBS"
717         vol[2] = vol[1] = 1; // Det, ladder
718         id = gMC->CurrentVolOffID(2,copy);
719         //detector copy in the ladder = 1<->4  (ITS1 < I101 < I103 < I10A)
720         vol[0] = copy; // Lay
721         if(copy>2) vol[0]++;
722     } else if(id == fIdSens[1]){ // Volume name "ITST"
723         vol[0] = 3; // layer
724         vol[1] = 1; // ladder
725         id = gMC->CurrentVolOffID(2,copy);
726         //detector copy in the ladder = 1<->4  (ITS2 < I1D1 < I1D3 < I20A)
727         vol[2] = 1;  // detector
728     } else return; // end if
729     //
730     gMC->TrackPosition(position);
731     gMC->TrackMomentum(momentum);
732     vol[4] = stat0;
733     if(gMC->IsTrackEntering()){
734         position0 = position;
735         stat0 = vol[3];
736     } // end if IsEntering
737     // Fill hit structure with this new hit only for non-entrerance hits.
738     else new(lhits[fNhits++]) AliITShit(fIshunt,gAlice->CurrentTrack(),vol,
739                                         gMC->Edep(),gMC->TrackTime(),position,
740                                         position0,momentum);
741     //
742     position0 = position;
743     stat0 = vol[3];
744
745     return;
746 }
747