]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSvtest.cxx
Removing obsolete class AliITSGeant3Geometry - Test beam simulation classes back...
[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 <TLorentzVector.h>
33 #include <TMath.h>
34 #include <TSystem.h>
35 #include <TVirtualMC.h>
36 #include <TGeoMatrix.h>
37
38 #include "AliRun.h"
39 #include "AliITSgeom.h"
40 #include "AliITSgeomSDD.h"
41 #include "AliITSgeomSPD.h"
42 #include "AliITSgeomSSD.h"
43 #include "AliITShit.h"
44 #include "AliITSvtest.h"
45 #include "AliRun.h"
46 #include "AliMC.h"
47
48 ClassImp(AliITSvtest)
49  
50 //_____________________________________________________________________________
51 AliITSvtest::AliITSvtest() {
52     // Standard constructor for the ITS
53     Int_t i;
54
55     fIdN    = 0;
56     fIdName = 0;
57     fIdSens = 0;
58     SetEUCLID(kFALSE);
59     fGeomDetOut   = kFALSE; // Don't write .det file
60     fGeomDetIn    = kTRUE; // Read .det file
61     fMajorVersion = IsVersion();
62     fMinorVersion = -1;
63     for(i=0;i<60;i++) fRead[i] = '\0';
64     for(i=0;i<60;i++) fWrite[i] = '\0';
65     for(i=0;i<60;i++) fEuclidGeomDet[i] = '\0';
66 }
67 //____________________________________________________________________________
68 AliITSvtest::AliITSvtest(const AliITSvtest &source) : AliITS(source){
69 ////////////////////////////////////////////////////////////////////////
70 //     Copy Constructor for ITS test version.
71 ////////////////////////////////////////////////////////////////////////
72     if(&source == this) return;
73     Warning("Copy Constructor","Not allowed to copy AliITSvtest");
74     return;
75 }
76 //_____________________________________________________________________________
77 AliITSvtest& AliITSvtest::operator=(const AliITSvtest &source){
78 ////////////////////////////////////////////////////////////////////////
79 //    Assignment operator for the ITS version 1.
80 ////////////////////////////////////////////////////////////////////////
81         if(&source == this) return *this;
82         Warning("= operator","Not allowed to copy AliITSvtest");
83         return *this;
84 }
85 //_____________________________________________________________________________
86 AliITSvtest::~AliITSvtest() {
87     // Standard destructor for the ITS
88 }
89 //_____________________________________________________________________________
90 AliITSvtest::AliITSvtest(const char *fileeuc,const char *filetme,
91                          const char *name, const char *title) 
92     : AliITS(name, title){
93     //
94     // Standard constructor for the ITS
95     //
96     fIdN    = 6;
97     fIdName    = new TString[fIdN];
98     fIdName[0] = "ITS1";
99     fIdName[1] = "ITS2";
100     fIdName[2] = "ITS3";
101     fIdName[3] = "ITS4";
102     fIdName[4] = "ITS5";
103     fIdName[5] = "ITS6";
104     fIdSens    = new Int_t[fIdN];
105     for (Int_t i=0;i<fIdN;i++) fIdSens[i] = 0;
106     fMajorVersion = IsVersion();
107     fMinorVersion = 1;
108     SetEUCLID(kFALSE);
109     fGeomDetOut   = kFALSE; // Don't write .det file
110     fGeomDetIn    = kTRUE; // Read .det file
111
112     fEuclidMaterial = filetme;
113     fEuclidGeometry = fileeuc;
114     strncpy(fEuclidGeomDet,"$ALICE_ROOT/ITS/ITSgeometry_PPR.det",60);
115     strncpy(fRead,fEuclidGeomDet,60);
116     strncpy(fWrite,fEuclidGeomDet,60);
117 //  The .det file for the geometry must have the same name as fileeuc with
118 //  .euc replaced by .det.
119 }
120
121  
122 //_____________________________________________________________________________
123 void AliITSvtest::CreateMaterials(){
124   //
125   // Read materials for the ITS
126   //
127     char *filtmp;
128 //
129   filtmp = gSystem->ExpandPathName(fEuclidMaterial.Data());
130 //  FILE *file = fopen(fEuclidMaterial.Data(),"r");
131   FILE *file = fopen(filtmp,"r");
132   if(file) {
133     fclose(file);
134 //    ReadEuclidMedia(fEuclidMaterial.Data(),this);
135     ReadEuclidMedia(filtmp);
136   } else {
137     Error("CreateMaterials"," THE MEDIA FILE %s DOES NOT EXIST !",
138 //        fEuclidMaterial.Data());
139           filtmp);
140     exit(1);
141   } // end if(file)
142 }
143
144 //_____________________________________________________________________________
145 void AliITSvtest::CreateGeometry(){
146 //////////////////////////////////////////////////////////////////////
147 ////////////////////////////////////////////////////////////////////////
148 // Read geometry for the ITS
149 //
150     char topvol[5];
151     char *filtmp;
152 //
153   filtmp = gSystem->ExpandPathName(fEuclidGeometry.Data());
154   FILE *file = fopen(filtmp,"r");
155   delete [] filtmp;
156   if(file) {
157     fclose(file);
158     printf("Ready to read Euclid geometry file\n");
159     ReadEuclid(fEuclidGeometry.Data(),topvol);
160     printf("Read in euclid geometries\n");
161   } else {
162     Error("CreateGeometry"," THE GEOM FILE %s DOES NOT EXIST !",
163           fEuclidGeometry.Data());
164     exit(1);
165   } // end if(file)
166   //
167   //---Place the ITS ghost volume ITSV in its mother volume (ALIC) and make it
168   //     invisible
169   //
170   gMC->Gspos("ITSV",1,"ALIC",0,0,0,0,"ONLY");
171   //
172   //---Outputs the geometry tree in the EUCLID/CAD format
173   
174     if (fEuclidOut) {
175       gMC->WriteEuclid("ITSgeometry", "ITSV", 1, 5);
176     } // end if (fEuclidOut)
177     cout <<"finished with euclid geometrys"<< endl;
178 }
179 //______________________________________________________________________
180 void AliITSvtest::InitAliITSgeom(){
181     //     Based on the geometry tree defined in Geant 3.21, this
182     // routine initilizes the Class AliITSgeom from the Geant 3.21 ITS geometry
183     // sturture.
184     // Inputs:
185     //   none.
186     // Outputs:
187     //   none.
188     // Return:
189     //   none.
190     const Int_t knlayers = 6;
191     const Int_t kndeep = 3;
192     const AliITSDetector idet[knlayers]={kSPD,kSPD,kSDD,kSDD,kSSD,kSSDp};
193     const TString names[2][knlayers] = {
194      {"/ALIC_1/ITSV_1/ITSD_1/IT12_1/I12A_%d/I10A_%d/I103_%d/I101_1/ITS1_1", // lay=1
195       "/ALIC_1/ITSV_1/ITSD_1/IT12_1/I12A_%d/I20A_%d/I1D3_%d/I1D1_1/ITS2_1", // lay=2
196       "/ALIC_1/ITSV_1/ITSD_1/IT34_1/I004_%d/I302_%d/ITS3_%d", // lay=3
197       "/ALIC_1/ITSV_1/ITSD_1/IT34_1/I005_%d/I402_%d/ITS4_%d", // lay=4
198       "/ALIC_1/ITSV_1/ITSD_1/IT56_1/I565_%d/I562_%d/ITS5_%d", // lay=5
199       "/ALIC_1/ITSV_1/ITSD_1/IT56_1/I569_%d/I566_%d/ITS6_%d"},// lay=6
200      {"/ALIC_1/ITSV_1/ITSD_1/IT12_1/I12B_%d/I10B_%d/I107_%d/I101_1/ITS1_1", // lay=1
201       "/ALIC_1/ITSV_1/ITSD_1/IT12_1/I12B_%d/I20B_%d/I1D7_%d/I1D1_1/ITS2_1", // lay=2
202       "/ALIC_1/ITSV_1/ITSD_1/IT34_1/I004_%d/I302_%d/ITS3_%d", // lay=3
203       "/ALIC_1/ITSV_1/ITSD_1/IT34_1/I005_%d/I402_%d/ITS4_%d", // lay=4
204       "/ALIC_1/ITSV_1/ITSD_1/IT56_1/I565_%d/I562_%d/ITS5_%d", // lay=5
205       "/ALIC_1/ITSV_1/ITSD_1/IT56_1/I569_%d/I566_%d/ITS6_%d"}
206     };
207     const Int_t itsGeomTreeCopys[knlayers][kndeep]= {{10, 2, 4},// lay=1
208                                                      {10, 4, 4},// lay=2
209                                                      {14, 6, 1},// lay=3
210                                                      {22, 8, 1},// lay=4
211                                                      {34,22, 1},// lay=5
212                                                      {38,25, 1}};//lay=6
213     Int_t       nlad[knlayers],ndet[knlayers];
214     Int_t       mod,lay,lad=0,det=0,i,j,k,cp0,cp1,cp2;
215     TString path,shapeName;
216     TGeoHMatrix matrix;
217     Double_t trans[3]={3*0.0},rot[10]={9*0.0,1.0};
218     TArrayD shapePar;
219     TArrayF shapeParF;
220     Bool_t shapeDefined[4]={kFALSE,kFALSE,kFALSE,kFALSE};
221
222     AliDebug(1,"Reading Geometry transformation directly from Modler.");
223     mod = 0;
224     for(i=0;i<knlayers;i++){
225         k = 1;
226         for(j=0;j<kndeep;j++) if(itsGeomTreeCopys[i][j]!=0)
227             k *= TMath::Abs(itsGeomTreeCopys[i][j]);
228         mod += k;
229     } // end for i
230
231     SetITSgeom(0);
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     AliITSgeom* geom = new AliITSgeom(0,6,nlad,ndet,mod);
235     SetITSgeom(geom);
236     mod = 0;
237     for(lay=1;lay<=knlayers;lay++){
238         for(cp0=1;cp0<=itsGeomTreeCopys[lay-1][0];cp0++){
239             for(cp1=1;cp1<=itsGeomTreeCopys[lay-1][1];cp1++){
240                 for(cp2=1;cp2<=itsGeomTreeCopys[lay-1][2];cp2++){
241                     path.Form(names[fMinorVersion-1][lay-1].Data(),
242                               cp0,cp1,cp2);
243                     switch (lay){
244                     case 1:{
245                         det = cp2;
246                         lad = cp1+2*(cp0-1);
247                     }break;
248                     case 2:{
249                         det = cp2;
250                         lad = cp1+4*(cp0-1);
251                     } break;
252                     case 3: case 4: case 5: case 6:{
253                         det = cp1;
254                         lad = cp0;
255                     } break;
256                     } // end switch
257                          //AliInfo(Form("path=%s lay=%d lad=%d det=%d",
258                          //             path.Data(),lay,lad,det));
259                     gMC->GetTransformation(path.Data(),matrix);
260                     gMC->GetShape(path.Data(),shapeName,shapePar);
261                     shapeParF.Set(shapePar.GetSize());
262                     for(i=0;i<shapePar.GetSize();i++) shapeParF[i]=shapePar[i];
263                     geom->CreateMatrix(mod,lay,lad,det,idet[lay-1],trans,rot);
264                     geom->SetTrans(mod,matrix.GetTranslation());
265                     geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
266                     geom->GetGeomMatrix(mod)->SetPath(path.Data());
267                     switch (lay){
268                     case 1: case 2:
269                         if(!shapeDefined[kSPD]){
270                         geom->ReSetShape(kSPD,new AliITSgeomSPD425Short(
271                                 shapeParF.GetSize(),shapeParF.GetArray()));
272                         shapeDefined[kSPD] = kTRUE;
273                     }break;
274                     case 3: case 4:
275                         if(!shapeDefined[kSDD]){
276                         geom->ReSetShape(kSDD,new AliITSgeomSDD256(
277                                 shapeParF.GetSize(),shapeParF.GetArray()));
278                         shapeDefined[kSDD] = kTRUE;
279                     }break;
280                     case 5:
281                         if(!shapeDefined[kSSD]){
282                         geom->ReSetShape(kSSD,new AliITSgeomSSD75and275(
283                                 shapeParF.GetSize(),shapeParF.GetArray()));
284                         shapeDefined[kSSD] = kTRUE;
285                     }break;
286                     case 6:
287                         if(!shapeDefined[kSSDp]){
288                         geom->ReSetShape(kSSDp,new AliITSgeomSSD275and75(
289                                 shapeParF.GetSize(),shapeParF.GetArray()));
290                         shapeDefined[kSSDp] = kTRUE;
291                     }break;
292                     default:{
293                     }break;
294                     } // end switch
295                     mod++;
296                 } /// end for cp2
297             } // end for cp1
298         } // end for cp0
299     } // end for lay
300     return;
301 }
302 //_____________________________________________________________________________
303 void AliITSvtest::Init(){
304 ////////////////////////////////////////////////////////////////////////
305 //     Initialise the ITS after it has been created.
306 ////////////////////////////////////////////////////////////////////////
307     Int_t i;
308
309     cout << endl;
310     for(i=0;i<29;i++) cout << "*";cout << " ITSvtest_Init ";
311     for(i=0;i<28;i++) cout << "*";cout << endl;
312 //
313     if(fRead[0]=='\0') strncpy(fRead,fEuclidGeomDet,60);
314     if(fWrite[0]=='\0') strncpy(fWrite,fEuclidGeomDet,60);
315     if(GetITSgeom()!=0) SetITSgeom(0x0);
316     SetITSgeom(new AliITSgeom());
317     if(fGeomDetIn) GetITSgeom()->ReadNewFile(fRead);
318     if(!fGeomDetIn) this->InitAliITSgeom();
319     if(fGeomDetOut) GetITSgeom()->WriteNewFile(fWrite);
320     AliITS::Init();
321 //
322     for(i=0;i<72;i++) cout << "*";
323     cout << endl;
324 }
325 //_____________________________________________________________________________
326 void AliITSvtest::StepManager(){
327   //
328   // Called for every step in the ITS
329   //
330   Int_t          copy, id;
331   Int_t          copy1,copy2;
332   Float_t        hits[8];
333   Int_t          vol[4];
334   TLorentzVector position, momentum;
335   TClonesArray   &lhits = *fHits;
336   //
337   // Track status
338   vol[3] = 0;
339   if(gMC->IsTrackInside())      vol[3] +=  1;
340   if(gMC->IsTrackEntering())    vol[3] +=  2;
341   if(gMC->IsTrackExiting())     vol[3] +=  4;
342   if(gMC->IsTrackOut())         vol[3] +=  8;
343   if(gMC->IsTrackDisappeared()) vol[3] += 16;
344   if(gMC->IsTrackStop())        vol[3] += 32;
345   if(gMC->IsTrackAlive())       vol[3] += 64;
346   //
347   // Fill hit structure.
348   if(!(gMC->TrackCharge())) return;
349   //
350   // Only entering charged tracks
351   if((id = gMC->CurrentVolID(copy)) == fIdSens[0]) {
352       vol[0] = 1;
353       id = gMC->CurrentVolOffID(0,copy);
354       //detector copy in the ladder = 1<->4  (ITS1)
355       vol[1] = copy;
356       gMC->CurrentVolOffID(1,copy1);
357       //ladder copy in the module   = 1<->2  (I186)
358       gMC->CurrentVolOffID(2,copy2);
359       //module copy in the layer    = 1<->10 (I132)
360       vol[2] = copy1+(copy2-1)*2;//# of ladders in one module  = 2
361   } else if(id == fIdSens[1]){
362       vol[0] = 2;
363       id = gMC->CurrentVolOffID(0,copy);
364       //detector copy in the ladder = 1<->4  (ITS2)
365       vol[1] = copy;
366       gMC->CurrentVolOffID(1,copy1);
367       //ladder copy in the module   = 1<->4  (I131)
368       gMC->CurrentVolOffID(2,copy2);
369       //module copy in the layer    = 1<->10 (I132)
370       vol[2] = copy1+(copy2-1)*4;//# of ladders in one module  = 4
371   } else if(id == fIdSens[2]){
372       vol[0] = 3;
373       id = gMC->CurrentVolOffID(1,copy);
374       //detector copy in the ladder = 1<->5  (ITS3 is inside I314)
375       vol[1] = copy;
376       id = gMC->CurrentVolOffID(2,copy);
377       //ladder copy in the layer    = 1<->12 (I316)
378       vol[2] = copy;
379   } else if(id == fIdSens[3]){
380       vol[0] = 4;
381       id = gMC->CurrentVolOffID(1,copy);
382       //detector copy in the ladder = 1<->8  (ITS4 is inside I414)
383       vol[1] = copy;
384       id = gMC->CurrentVolOffID(2,copy);
385       //ladder copy in the layer    = 1<->22 (I417)
386       vol[2] = copy;
387   }else if(id == fIdSens[4]){
388       vol[0] = 5;
389       id = gMC->CurrentVolOffID(1,copy);
390       //detector copy in the ladder = 1<->23  (ITS5 is inside I562)
391       vol[1] = copy;
392       id = gMC->CurrentVolOffID(2,copy);
393      //ladder copy in the layer    = 1<->34 (I565)
394       vol[2] = copy;
395   }else if(id == fIdSens[5]){
396       vol[0] = 6;
397       id = gMC->CurrentVolOffID(1,copy);
398       //detector copy in the ladder = 1<->26  (ITS6 is inside I566)
399       vol[1] = copy;
400       id = gMC->CurrentVolOffID(2,copy);
401       //ladder copy in the layer = 1<->38 (I569)
402       vol[2] = copy;
403   } else {
404       return; // not an ITS volume?
405   } // end if/else if (gMC->CurentVolID(copy) == fIdSens[i])
406 //
407   gMC->TrackPosition(position);
408   gMC->TrackMomentum(momentum);
409   hits[0]=position[0];
410   hits[1]=position[1];
411   hits[2]=position[2];
412   hits[3]=momentum[0];
413   hits[4]=momentum[1];
414   hits[5]=momentum[2];
415   hits[6]=gMC->Edep();
416   hits[7]=gMC->TrackTime();
417   // Fill hit structure with this new hit.
418   new(lhits[fNhits++]) AliITShit(fIshunt,gAlice->GetMCApp()->GetCurrentTrackNumber(),vol,hits);
419   return;
420 }
421