]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSvtest.cxx
Moving to the new VMC naming convention
[u/mrichter/AliRoot.git] / ITS / AliITSvtest.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 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  Inner Traking System version Test                                        //
21 //  This class contains the base procedures for the Inner Tracking System    //
22 //                                                                           //
23 // Authors: R. Barbera, B. S. Nilsen.                                        //
24 // version  Test                                                             //
25 // Created October 16 1999.                                                  //
26 //                                                                           //
27 ///////////////////////////////////////////////////////////////////////////////
28
29 #include <Riostream.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <TMath.h>
33 #include <TNode.h>
34 #include <TObjArray.h>
35 #include <TObjString.h>
36 #include <TSystem.h>
37 #include <TTUBE.h>
38 #include <TVirtualMC.h>
39
40 #include "AliRun.h"
41 #include "AliITSGeant3Geometry.h"
42 #include "AliITSgeom.h"
43 #include "AliITSgeomSDD.h"
44 #include "AliITSgeomSPD.h"
45 #include "AliITSgeomSSD.h"
46 #include "AliITShit.h"
47 #include "AliITSvtest.h"
48 #include "AliRun.h"
49
50 ClassImp(AliITSvtest)
51  
52 //_____________________________________________________________________________
53 AliITSvtest::AliITSvtest() {
54     // Standard constructor for the ITS
55     Int_t i;
56
57     fIdN    = 0;
58     fIdName = 0;
59     fIdSens = 0;
60     fEuclidOut    = kFALSE; // Don't write Euclide file
61     fGeomDetOut   = kFALSE; // Don't write .det file
62     fGeomDetIn    = kTRUE; // Read .det file
63     fMajorVersion = IsVersion();
64     fMinorVersion = -1;
65     for(i=0;i<60;i++) fRead[i] = '\0';
66     for(i=0;i<60;i++) fWrite[i] = '\0';
67     for(i=0;i<60;i++) fEuclidGeomDet[i] = '\0';
68 }
69 //____________________________________________________________________________
70 AliITSvtest::AliITSvtest(const AliITSvtest &source){
71 ////////////////////////////////////////////////////////////////////////
72 //     Copy Constructor for ITS test version.
73 ////////////////////////////////////////////////////////////////////////
74     if(&source == this) return;
75     Warning("Copy Constructor","Not allowed to copy AliITSvtest");
76     return;
77 }
78 //_____________________________________________________________________________
79 AliITSvtest& AliITSvtest::operator=(const AliITSvtest &source){
80 ////////////////////////////////////////////////////////////////////////
81 //    Assignment operator for the ITS version 1.
82 ////////////////////////////////////////////////////////////////////////
83         if(&source == this) return *this;
84         Warning("= operator","Not allowed to copy AliITSvtest");
85         return *this;
86 }
87 //_____________________________________________________________________________
88 AliITSvtest::~AliITSvtest() {
89     // Standard destructor for the ITS
90 }
91 //_____________________________________________________________________________
92 AliITSvtest::AliITSvtest(const char *fileeuc,const char *filetme,
93                          const char *name, const char *title) 
94     : AliITS(name, title){
95     //
96     // Standard constructor for the ITS
97     //
98     fIdN    = 6;
99     fIdName    = new TString[fIdN];
100     fIdName[0] = "ITS1";
101     fIdName[1] = "ITS2";
102     fIdName[2] = "ITS3";
103     fIdName[3] = "ITS4";
104     fIdName[4] = "ITS5";
105     fIdName[5] = "ITS6";
106     fIdSens    = new Int_t[fIdN];
107     for (Int_t i=0;i<fIdN;i++) fIdSens[i] = 0;
108     fMajorVersion = IsVersion();
109     fMinorVersion = 1;
110     fEuclidOut    = kFALSE; // Don't write Euclide file
111     fGeomDetOut   = kFALSE; // Don't write .det file
112     fGeomDetIn    = kTRUE; // Read .det file
113
114     fEuclidMaterial = filetme;
115     fEuclidGeometry = fileeuc;
116     strncpy(fEuclidGeomDet,"$ALICE_ROOT/ITS/ITSgeometry_PPR.det",60);
117     strncpy(fRead,fEuclidGeomDet,60);
118     strncpy(fWrite,fEuclidGeomDet,60);
119 //  The .det file for the geometry must have the same name as fileeuc with
120 //  .euc replaced by .det.
121 }
122
123  
124 //_____________________________________________________________________________
125 void AliITSvtest::CreateMaterials(){
126   //
127   // Read materials for the ITS
128   //
129     char *filtmp;
130 //
131   filtmp = gSystem->ExpandPathName(fEuclidMaterial.Data());
132 //  FILE *file = fopen(fEuclidMaterial.Data(),"r");
133   FILE *file = fopen(filtmp,"r");
134   if(file) {
135     fclose(file);
136 //    ReadEuclidMedia(fEuclidMaterial.Data(),this);
137     ReadEuclidMedia(filtmp);
138   } else {
139     Error("CreateMaterials"," THE MEDIA FILE %s DOES NOT EXIST !",
140 //        fEuclidMaterial.Data());
141           filtmp);
142     exit(1);
143   } // end if(file)
144 }
145
146 //_____________________________________________________________________________
147 void AliITSvtest::CreateGeometry(){
148 //////////////////////////////////////////////////////////////////////
149 ////////////////////////////////////////////////////////////////////////
150 // Read geometry for the ITS
151 //
152     char topvol[5];
153     char *filtmp;
154 //
155   filtmp = gSystem->ExpandPathName(fEuclidGeometry.Data());
156   FILE *file = fopen(filtmp,"r");
157   delete [] filtmp;
158   if(file) {
159     fclose(file);
160     printf("Ready to read Euclid geometry file\n");
161     ReadEuclid(fEuclidGeometry.Data(),topvol);
162     printf("Read in euclid geometries\n");
163   } else {
164     Error("CreateGeometry"," THE GEOM FILE %s DOES NOT EXIST !",
165           fEuclidGeometry.Data());
166     exit(1);
167   } // end if(file)
168   //
169   //---Place the ITS ghost volume ITSV in its mother volume (ALIC) and make it
170   //     invisible
171   //
172   gMC->Gspos("ITSV",1,"ALIC",0,0,0,0,"ONLY");
173   //
174   //---Outputs the geometry tree in the EUCLID/CAD format
175   
176     if (fEuclidOut) {
177       gMC->WriteEuclid("ITSgeometry", "ITSV", 1, 5);
178     } // end if (fEuclidOut)
179     cout <<"finished with euclid geometrys"<< endl;
180 }
181 //______________________________________________________________________
182 void AliITSvtest::InitAliITSgeom(){
183 //     Based on the geometry tree defined in Geant 3.21, this
184 // routine initilizes the Class AliITSgeom from the Geant 3.21 ITS geometry
185 // sturture.
186 //    if(gMC->IsA()!=TGeant3::Class()) {
187   if(strcmp(gMC->GetName(),"TGeant3")) {
188         Error("InitAliITSgeom",
189                 "Wrong Monte Carlo. InitAliITSgeom uses TGeant3 calls");
190         return;
191     } // end if
192     cout << "Reading Geometry transformation directly from Geant 3." << endl;
193     const Int_t nlayers = 6;
194     const Int_t ndeep = 9;
195     Int_t itsGeomTreeNames[nlayers][ndeep],lnam[20],lnum[20];
196     Int_t nlad[nlayers],ndet[nlayers];
197     Double_t t[3],r[10];
198     Float_t  par[20],att[20];
199     Int_t    npar,natt,idshape,imat,imed;
200     AliITSGeant3Geometry *ig = new AliITSGeant3Geometry();
201     Int_t mod,lay,lad,det,i,j,k;
202     char *names[nlayers][ndeep] = {
203      {"ALIC","ITSV","ITSD","IT12","I12B","I10B","I107","I101","ITS1"}, // lay=1
204      {"ALIC","ITSV","ITSD","IT12","I12B","I20B","I1D7","I1D1","ITS2"}, // lay=2
205      {"ALIC","ITSV","ITSD","IT34","I004","I302","ITS3","    ","    "}, // lay=3
206      {"ALIC","ITSV","ITSD","IT34","I005","I402","ITS4","    ","    "}, // lay=4
207      {"ALIC","ITSV","ITSD","IT56","I565","I562","ITS5","    ","    "}, // lay=5
208      {"ALIC","ITSV","ITSD","IT56","I569","I566","ITS6","    ","    "}};// lay=6
209     Int_t itsGeomTreeCopys[nlayers][ndeep] = {{1,1,1,1,10, 2, 4, 1, 1},// lay=1
210                                               {1,1,1,1,10, 4, 4, 1, 1},// lay=2
211                                               {1,1,1,1,14, 6, 1, 0, 0},// lay=3
212                                               {1,1,1,1,22, 8, 1, 0, 0},// lay=4
213                                               {1,1,1,1,34,22, 1, 0, 0},// lay=5
214                                               {1,1,1,1,38,25, 1, 0, 0}};//lay=6
215
216     // Sorry, but this is not very pritty code. It should be replaced
217     // at some point with a version that can search through the geometry
218     // tree its self.
219     cout << "Reading Geometry informaton from Geant3 common blocks" << endl;
220     for(i=0;i<20;i++) lnam[i] = lnum[i] = 0;
221     for(i=0;i<nlayers;i++)for(j=0;j<ndeep;j++) 
222         itsGeomTreeNames[i][j] = ig->StringToInt(names[i][j]);
223     mod = 0;
224     for(i=0;i<nlayers;i++){
225         k = 1;
226         for(j=0;j<ndeep;j++) if(itsGeomTreeCopys[i][j]!=0)
227             k *= TMath::Abs(itsGeomTreeCopys[i][j]);
228         mod += k;
229     } // end for i
230
231     if(fITSgeom!=0) delete fITSgeom;
232     nlad[0]=20;nlad[1]=40;nlad[2]=14;nlad[3]=22;nlad[4]=34;nlad[5]=38;
233     ndet[0]=4;ndet[1]=4;ndet[2]=6;ndet[3]=8;ndet[4]=22;ndet[5]=25;
234     fITSgeom = new AliITSgeom(0,6,nlad,ndet,mod);
235     mod = -1;
236     for(lay=1;lay<=nlayers;lay++){
237         for(j=0;j<ndeep;j++) lnam[j] = itsGeomTreeNames[lay-1][j];
238         for(j=0;j<ndeep;j++) lnum[j] = itsGeomTreeCopys[lay-1][j];
239         switch (lay){
240         case 1: case 2: // layers 1 and 2 are a bit special
241             lad = 0;
242             for(j=1;j<=itsGeomTreeCopys[lay-1][4];j++){
243                 lnum[4] = j;
244                 for(k=1;k<=itsGeomTreeCopys[lay-1][5];k++){
245                     lad++;
246                     lnum[5] = k;
247                     for(det=1;det<=itsGeomTreeCopys[lay-1][6];det++){
248                         lnum[6] = det;
249                         mod++;
250                         ig->GetGeometry(ndeep,lnam,lnum,t,r,idshape,npar,natt,
251                                         par,att,imat,imed);
252                         fITSgeom->CreatMatrix(mod,lay,lad,det,kSPD,t,r);
253                         if(!(fITSgeom->IsShapeDefined((Int_t)kSPD)))
254                             if(fMinorVersion==1){
255                              fITSgeom->ReSetShape(kSPD,
256                                                   new AliITSgeomSPD425Short());
257                             } else if(fMinorVersion==2)
258                              fITSgeom->ReSetShape(kSPD,
259                                                   new AliITSgeomSPD425Short());
260                     } // end for det
261                 } // end for k
262             } // end for j
263             break;
264         case 3: case 4: case 5: case 6: // layers 3-6
265             lnum[6] = 1;
266             for(lad=1;lad<=itsGeomTreeCopys[lay-1][4];lad++){
267                 lnum[4] = lad;
268                 for(det=1;det<=itsGeomTreeCopys[lay-1][5];det++){
269                     lnum[5] = det;
270                     mod++;
271                     ig->GetGeometry(7,lnam,lnum,t,r,idshape,npar,natt,
272                                     par,att,imat,imed);
273                     switch (lay){
274                     case 3: case 4:
275                         fITSgeom->CreatMatrix(mod,lay,lad,det,kSDD,t,r);
276                         if(!(fITSgeom->IsShapeDefined(kSDD))) 
277                             fITSgeom->ReSetShape(kSDD,new AliITSgeomSDD256());
278                             break;
279                         case 5:
280                             fITSgeom->CreatMatrix(mod,lay,lad,det,kSSD,t,r);
281                             if(!(fITSgeom->IsShapeDefined(kSSD))) 
282                                 fITSgeom->ReSetShape(kSSD,new AliITSgeomSSD275and75());
283                             break;
284                         case 6:
285                             fITSgeom->CreatMatrix(mod,lay,lad,det,kSSD,t,r);
286                             if(!(fITSgeom->IsShapeDefined(kSSD))) 
287                                 fITSgeom->ReSetShape(kSSD,new AliITSgeomSSD75and275());
288                             break;
289                         } // end switch
290                 } // end for det
291             } // end for lad
292             break;
293         } // end switch
294     } // end for lay
295     return;
296 }
297 //_____________________________________________________________________________
298 void AliITSvtest::Init(){
299 ////////////////////////////////////////////////////////////////////////
300 //     Initialise the ITS after it has been created.
301 ////////////////////////////////////////////////////////////////////////
302     Int_t i;
303
304     cout << endl;
305     for(i=0;i<29;i++) cout << "*";cout << " ITSvtest_Init ";
306     for(i=0;i<28;i++) cout << "*";cout << endl;
307 //
308     if(fRead[0]=='\0') strncpy(fRead,fEuclidGeomDet,60);
309     if(fWrite[0]=='\0') strncpy(fWrite,fEuclidGeomDet,60);
310     if(fITSgeom!=0) delete fITSgeom;
311     fITSgeom = new AliITSgeom();
312     if(fGeomDetIn) fITSgeom->ReadNewFile(fRead);
313     if(!fGeomDetIn) this->InitAliITSgeom();
314     if(fGeomDetOut) fITSgeom->WriteNewFile(fWrite);
315     AliITS::Init();
316 //
317     for(i=0;i<72;i++) cout << "*";
318     cout << endl;
319 }
320 //_____________________________________________________________________________
321 void AliITSvtest::StepManager(){
322   //
323   // Called for every step in the ITS
324   //
325   Int_t          copy, id;
326   Int_t          copy1,copy2;
327   Float_t        hits[8];
328   Int_t          vol[4];
329   TLorentzVector position, momentum;
330   TClonesArray   &lhits = *fHits;
331   //
332   // Track status
333   vol[3] = 0;
334   if(gMC->IsTrackInside())      vol[3] +=  1;
335   if(gMC->IsTrackEntering())    vol[3] +=  2;
336   if(gMC->IsTrackExiting())     vol[3] +=  4;
337   if(gMC->IsTrackOut())         vol[3] +=  8;
338   if(gMC->IsTrackDisappeared()) vol[3] += 16;
339   if(gMC->IsTrackStop())        vol[3] += 32;
340   if(gMC->IsTrackAlive())       vol[3] += 64;
341   //
342   // Fill hit structure.
343   if(!(gMC->TrackCharge())) return;
344   //
345   // Only entering charged tracks
346   if((id = gMC->CurrentVolID(copy)) == fIdSens[0]) {
347       vol[0] = 1;
348       id = gMC->CurrentVolOffID(0,copy);
349       //detector copy in the ladder = 1<->4  (ITS1)
350       vol[1] = copy;
351       gMC->CurrentVolOffID(1,copy1);
352       //ladder copy in the module   = 1<->2  (I186)
353       gMC->CurrentVolOffID(2,copy2);
354       //module copy in the layer    = 1<->10 (I132)
355       vol[2] = copy1+(copy2-1)*2;//# of ladders in one module  = 2
356   } else if(id == fIdSens[1]){
357       vol[0] = 2;
358       id = gMC->CurrentVolOffID(0,copy);
359       //detector copy in the ladder = 1<->4  (ITS2)
360       vol[1] = copy;
361       gMC->CurrentVolOffID(1,copy1);
362       //ladder copy in the module   = 1<->4  (I131)
363       gMC->CurrentVolOffID(2,copy2);
364       //module copy in the layer    = 1<->10 (I132)
365       vol[2] = copy1+(copy2-1)*4;//# of ladders in one module  = 4
366   } else if(id == fIdSens[2]){
367       vol[0] = 3;
368       id = gMC->CurrentVolOffID(1,copy);
369       //detector copy in the ladder = 1<->5  (ITS3 is inside I314)
370       vol[1] = copy;
371       id = gMC->CurrentVolOffID(2,copy);
372       //ladder copy in the layer    = 1<->12 (I316)
373       vol[2] = copy;
374   } else if(id == fIdSens[3]){
375       vol[0] = 4;
376       id = gMC->CurrentVolOffID(1,copy);
377       //detector copy in the ladder = 1<->8  (ITS4 is inside I414)
378       vol[1] = copy;
379       id = gMC->CurrentVolOffID(2,copy);
380       //ladder copy in the layer    = 1<->22 (I417)
381       vol[2] = copy;
382   }else if(id == fIdSens[4]){
383       vol[0] = 5;
384       id = gMC->CurrentVolOffID(1,copy);
385       //detector copy in the ladder = 1<->23  (ITS5 is inside I562)
386       vol[1] = copy;
387       id = gMC->CurrentVolOffID(2,copy);
388      //ladder copy in the layer    = 1<->34 (I565)
389       vol[2] = copy;
390   }else if(id == fIdSens[5]){
391       vol[0] = 6;
392       id = gMC->CurrentVolOffID(1,copy);
393       //detector copy in the ladder = 1<->26  (ITS6 is inside I566)
394       vol[1] = copy;
395       id = gMC->CurrentVolOffID(2,copy);
396       //ladder copy in the layer = 1<->38 (I569)
397       vol[2] = copy;
398   } else {
399       return; // not an ITS volume?
400   } // end if/else if (gMC->CurentVolID(copy) == fIdSens[i])
401 //
402   gMC->TrackPosition(position);
403   gMC->TrackMomentum(momentum);
404   hits[0]=position[0];
405   hits[1]=position[1];
406   hits[2]=position[2];
407   hits[3]=momentum[0];
408   hits[4]=momentum[1];
409   hits[5]=momentum[2];
410   hits[6]=gMC->Edep();
411   hits[7]=gMC->TrackTime();
412   // Fill hit structure with this new hit.
413   new(lhits[fNhits++]) AliITShit(fIshunt,gAlice->GetCurrentTrackNumber(),vol,hits);
414   return;
415 }
416