]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSvtest.cxx
to be substituted by the new version
[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 /*
17 $Log$
18 Revision 1.10  2001/05/30 15:55:35  hristov
19 Strings compared instead of pointers
20
21 Revision 1.9  2001/05/30 14:04:31  hristov
22 Dynamic cast replaced (F.Carminati)
23
24 Revision 1.8  2001/02/13 16:53:35  nilsen
25 Fixed a but when trying to use GEANT4. Needed to replace
26 if(!((TGeant3*)gMC)) with if(!(dynamic_casst<TGeant3*>(gMC)))
27 because just casting gMC to be TGeant3* even when it realy is a TGeant3 pointer
28 did not result in a zero value. For AliITSv5asymm and AliITSv5symm, needed
29 to fix a bug in the initilizers and a bug in BuildGeometry. This is now done
30 in the same way as in AliITSv5.cxx.
31
32 Revision 1.7  2001/02/09 20:06:26  nilsen
33 Fixed bug in distructor. Can't distroy fixxed length arrays. Thanks Peter.
34
35 Revision 1.6  2001/02/09 00:05:31  nilsen
36 Added fMajor/MinorVersion variables and made other changes to better make
37 use of the new code changes in AliITSgeom related classes.
38
39 Revision 1.5  2001/01/30 09:23:14  hristov
40 Streamers removed (R.Brun)
41
42 Revision 1.4  2001/01/18 06:25:09  barbera
43 ITS geometry using test Euclid files
44
45 Revision 1.1.2.8  2000/10/05 20:28:18  nilsen
46 Now using root generated streamer function.
47
48 Revision 1.1.2.7  2000/07/31 13:51:22  barbera
49 Updated from the release
50
51 Revision 1.2  2000/07/10 16:07:19  fca
52 Release version of ITS code
53
54 Revision 1.1.2.2  2000/03/02 21:53:36  nilsen
55 to make it compatable with the changes in AliRun/AliModule.
56
57 Revision 1.1.2.1  2000/01/12 20:19:03  nilsen
58         The changes made with this latest inclusion of code is very large.
59 Many of the new files were added just in December when P. Cerello added his
60 SDD simulations to the distrobutions. Also added are some file of P. Skowronski
61 for SSD cluster finding and ghost RecPoints. None of this "new" code has been
62 proporly tested. Other code new to this cvs repository is explained in the
63 ITS Off-line web page. In general the changes are too large to give a resonable
64 discription of them but probably should be taken as the starting point for
65 the developement branch (ITS-working).
66     B. S. Nilsen
67
68 Revision 1.13  1999/10/16 19:49:00  BSN
69 $Name$
70 $Author$
71 $Id$
72 */
73
74 ///////////////////////////////////////////////////////////////////////////////
75 //                                                                           //
76 //  Inner Traking System version Test                                        //
77 //  This class contains the base procedures for the Inner Tracking System    //
78 //                                                                           //
79 // Authors: R. Barbera, B. S. Nilsen.                                        //
80 // version  Test                                                             //
81 // Created October 16 1999.                                                  //
82 //                                                                           //
83 ///////////////////////////////////////////////////////////////////////////////
84 #include <stdio.h>
85 #include <stdlib.h>
86 #include <TMath.h>
87 #include <TGeometry.h>
88 #include <TNode.h>
89 #include <TTUBE.h>
90 #include <TFile.h>    // only required for Tracking function?
91 #include <TCanvas.h>
92 #include <TObjArray.h>
93 #include <TObjString.h>
94 #include <TClonesArray.h>
95 #include <TLorentzVector.h>
96 #include <TBRIK.h>
97 #include <TSystem.h>
98
99 #include "AliMC.h"
100 #include "AliRun.h"
101 #include "AliGeant3.h"
102 #include "AliITSGeant3Geometry.h"
103 #include "AliITShit.h"
104 #include "AliITS.h"
105 #include "AliITSvtest.h"
106 #include "AliITSgeom.h"
107 #include "AliITSgeomSPD.h"
108 #include "AliITSgeomSDD.h"
109 #include "AliITSgeomSSD.h"
110
111 ClassImp(AliITSvtest)
112  
113 //_____________________________________________________________________________
114 AliITSvtest::AliITSvtest() {
115     // Standard constructor for the ITS
116     Int_t i;
117
118     fIdN    = 0;
119     fIdName = 0;
120     fIdSens = 0;
121     fEuclidOut    = kFALSE; // Don't write Euclide file
122     fGeomDetOut   = kFALSE; // Don't write .det file
123     fGeomDetIn    = kTRUE; // Read .det file
124     fMajorVersion = IsVersion();
125     fMinorVersion = -1;
126     for(i=0;i<60;i++) fRead[i] = '\0';
127     for(i=0;i<60;i++) fWrite[i] = '\0';
128     for(i=0;i<60;i++) fEuclidGeomDet[i] = '\0';
129 }
130 //____________________________________________________________________________
131 AliITSvtest::AliITSvtest(const AliITSvtest &source){
132 ////////////////////////////////////////////////////////////////////////
133 //     Copy Constructor for ITS test version.
134 ////////////////////////////////////////////////////////////////////////
135     if(&source == this) return;
136     Warning("Copy Constructor","Not allowed to copy AliITSvtest");
137     return;
138 }
139 //_____________________________________________________________________________
140 AliITSvtest& AliITSvtest::operator=(const AliITSvtest &source){
141 ////////////////////////////////////////////////////////////////////////
142 //    Assignment operator for the ITS version 1.
143 ////////////////////////////////////////////////////////////////////////
144         if(&source == this) return *this;
145         Warning("= operator","Not allowed to copy AliITSvtest");
146         return *this;
147 }
148 //_____________________________________________________________________________
149 AliITSvtest::~AliITSvtest() {
150     // Standard destructor for the ITS
151 }
152 //_____________________________________________________________________________
153 AliITSvtest::AliITSvtest(const char *fileeuc,const char *filetme,
154                          const char *name, const char *title) 
155     : AliITS(name, title){
156     //
157     // Standard constructor for the ITS
158     //
159     fIdN    = 6;
160     fIdName    = new TString[fIdN];
161     fIdName[0] = "ITS1";
162     fIdName[1] = "ITS2";
163     fIdName[2] = "ITS3";
164     fIdName[3] = "ITS4";
165     fIdName[4] = "ITS5";
166     fIdName[5] = "ITS6";
167     fIdSens    = new Int_t[fIdN];
168     for (Int_t i=0;i<fIdN;i++) fIdSens[i] = 0;
169     fMajorVersion = IsVersion();
170     fMinorVersion = 1;
171     fEuclidOut    = kFALSE; // Don't write Euclide file
172     fGeomDetOut   = kFALSE; // Don't write .det file
173     fGeomDetIn    = kTRUE; // Read .det file
174
175     fEuclidMaterial = filetme;
176     fEuclidGeometry = fileeuc;
177     strncpy(fEuclidGeomDet,"$ALICE_ROOT/ITS/ITSgeometry_PPR.det",60);
178     strncpy(fRead,fEuclidGeomDet,60);
179     strncpy(fWrite,fEuclidGeomDet,60);
180 //  The .det file for the geometry must have the same name as fileeuc with
181 //  .euc replaced by .det.
182 }
183
184  
185 //_____________________________________________________________________________
186 void AliITSvtest::CreateMaterials(){
187   //
188   // Read materials for the ITS
189   //
190     char *filtmp;
191 //
192   filtmp = gSystem->ExpandPathName(fEuclidMaterial.Data());
193 //  FILE *file = fopen(fEuclidMaterial.Data(),"r");
194   FILE *file = fopen(filtmp,"r");
195   if(file) {
196     fclose(file);
197 //    ReadEuclidMedia(fEuclidMaterial.Data(),this);
198     ReadEuclidMedia(filtmp);
199   } else {
200     Error("CreateMaterials"," THE MEDIA FILE %s DOES NOT EXIST !",
201 //        fEuclidMaterial.Data());
202           filtmp);
203     exit(1);
204   } // end if(file)
205 }
206
207 //_____________________________________________________________________________
208 void AliITSvtest::CreateGeometry(){
209 //////////////////////////////////////////////////////////////////////
210 ////////////////////////////////////////////////////////////////////////
211 // Read geometry for the ITS
212 //
213     char topvol[5];
214     char *filtmp;
215 //
216   filtmp = gSystem->ExpandPathName(fEuclidGeometry.Data());
217   FILE *file = fopen(filtmp,"r");
218   delete [] filtmp;
219   if(file) {
220     fclose(file);
221     printf("Ready to read Euclid geometry file\n");
222     ReadEuclid(fEuclidGeometry.Data(),topvol);
223     printf("Read in euclid geometries\n");
224   } else {
225     Error("CreateGeometry"," THE GEOM FILE %s DOES NOT EXIST !",
226           fEuclidGeometry.Data());
227     exit(1);
228   } // end if(file)
229   //
230   //---Place the ITS ghost volume ITSV in its mother volume (ALIC) and make it
231   //     invisible
232   //
233   gMC->Gspos("ITSV",1,"ALIC",0,0,0,0,"ONLY");
234   //
235   //---Outputs the geometry tree in the EUCLID/CAD format
236   
237     if (fEuclidOut) {
238       gMC->WriteEuclid("ITSgeometry", "ITSV", 1, 5);
239     } // end if (fEuclidOut)
240     cout <<"finished with euclid geometrys"<< endl;
241 }
242 //______________________________________________________________________
243 void AliITSvtest::InitAliITSgeom(){
244 //     Based on the geometry tree defined in Geant 3.21, this
245 // routine initilizes the Class AliITSgeom from the Geant 3.21 ITS geometry
246 // sturture.
247     if(gMC->IsA()!=AliGeant3::Class()) {
248         Error("InitAliITSgeom",
249                 "Wrong Monte Carlo. InitAliITSgeom uses TGeant3 calls");
250         return;
251     } // end if
252     cout << "Reading Geometry transformation directly from Geant 3." << endl;
253     const Int_t nlayers = 6;
254     const Int_t ndeep = 9;
255     Int_t itsGeomTreeNames[nlayers][ndeep],lnam[20],lnum[20];
256     Int_t nlad[nlayers],ndet[nlayers];
257     Double_t t[3],r[10];
258     Float_t  par[20],att[20];
259     Int_t    npar,natt,idshape,imat,imed;
260     AliITSGeant3Geometry *ig = new AliITSGeant3Geometry();
261     Int_t mod,lay,lad,det,i,j,k;
262     char *names[nlayers][ndeep] = {
263      {"ALIC","ITSV","ITSD","IT12","I12B","I10B","I107","I101","ITS1"}, // lay=1
264      {"ALIC","ITSV","ITSD","IT12","I12B","I20B","I1D7","I1D1","ITS2"}, // lay=2
265      {"ALIC","ITSV","ITSD","IT34","I004","I302","ITS3","    ","    "}, // lay=3
266      {"ALIC","ITSV","ITSD","IT34","I005","I402","ITS4","    ","    "}, // lay=4
267      {"ALIC","ITSV","ITSD","IT56","I565","I562","ITS5","    ","    "}, // lay=5
268      {"ALIC","ITSV","ITSD","IT56","I569","I566","ITS6","    ","    "}};// lay=6
269     Int_t itsGeomTreeCopys[nlayers][ndeep] = {{1,1,1,1,10, 2, 4, 1, 1},// lay=1
270                                               {1,1,1,1,10, 4, 4, 1, 1},// lay=2
271                                               {1,1,1,1,14, 6, 1, 0, 0},// lay=3
272                                               {1,1,1,1,22, 8, 1, 0, 0},// lay=4
273                                               {1,1,1,1,34,22, 1, 0, 0},// lay=5
274                                               {1,1,1,1,38,25, 1, 0, 0}};//lay=6
275
276     // Sorry, but this is not very pritty code. It should be replaced
277     // at some point with a version that can search through the geometry
278     // tree its self.
279     cout << "Reading Geometry informaton from Geant3 common blocks" << endl;
280     for(i=0;i<20;i++) lnam[i] = lnum[i] = 0;
281     for(i=0;i<nlayers;i++)for(j=0;j<ndeep;j++) 
282         itsGeomTreeNames[i][j] = ig->StringToInt(names[i][j]);
283     mod = 0;
284     for(i=0;i<nlayers;i++){
285         k = 1;
286         for(j=0;j<ndeep;j++) if(itsGeomTreeCopys[i][j]!=0)
287             k *= TMath::Abs(itsGeomTreeCopys[i][j]);
288         mod += k;
289     } // end for i
290
291     if(fITSgeom!=0) delete fITSgeom;
292     nlad[0]=20;nlad[1]=40;nlad[2]=14;nlad[3]=22;nlad[4]=34;nlad[5]=38;
293     ndet[0]=4;ndet[1]=4;ndet[2]=6;ndet[3]=8;ndet[4]=22;ndet[5]=25;
294     fITSgeom = new AliITSgeom(0,6,nlad,ndet,mod);
295     mod = -1;
296     for(lay=1;lay<=nlayers;lay++){
297         for(j=0;j<ndeep;j++) lnam[j] = itsGeomTreeNames[lay-1][j];
298         for(j=0;j<ndeep;j++) lnum[j] = itsGeomTreeCopys[lay-1][j];
299         switch (lay){
300         case 1: case 2: // layers 1 and 2 are a bit special
301             lad = 0;
302             for(j=1;j<=itsGeomTreeCopys[lay-1][4];j++){
303                 lnum[4] = j;
304                 for(k=1;k<=itsGeomTreeCopys[lay-1][5];k++){
305                     lad++;
306                     lnum[5] = k;
307                     for(det=1;det<=itsGeomTreeCopys[lay-1][6];det++){
308                         lnum[6] = det;
309                         mod++;
310                         ig->GetGeometry(ndeep,lnam,lnum,t,r,idshape,npar,natt,
311                                         par,att,imat,imed);
312                         fITSgeom->CreatMatrix(mod,lay,lad,det,kSPD,t,r);
313                         if(!(fITSgeom->IsShapeDefined((Int_t)kSPD)))
314                             if(fMinorVersion==1){
315                              fITSgeom->ReSetShape(kSPD,
316                                                   new AliITSgeomSPD425Short());
317                             } else if(fMinorVersion==2)
318                              fITSgeom->ReSetShape(kSPD,
319                                                   new AliITSgeomSPD425Short());
320                     } // end for det
321                 } // end for k
322             } // end for j
323             break;
324         case 3: case 4: case 5: case 6: // layers 3-6
325             lnum[6] = 1;
326             for(lad=1;lad<=itsGeomTreeCopys[lay-1][4];lad++){
327                 lnum[4] = lad;
328                 for(det=1;det<=itsGeomTreeCopys[lay-1][5];det++){
329                     lnum[5] = det;
330                     mod++;
331                     ig->GetGeometry(7,lnam,lnum,t,r,idshape,npar,natt,
332                                     par,att,imat,imed);
333                     switch (lay){
334                     case 3: case 4:
335                         fITSgeom->CreatMatrix(mod,lay,lad,det,kSDD,t,r);
336                         if(!(fITSgeom->IsShapeDefined(kSDD))) 
337                             fITSgeom->ReSetShape(kSDD,new AliITSgeomSDD256());
338                             break;
339                         case 5:
340                             fITSgeom->CreatMatrix(mod,lay,lad,det,kSSD,t,r);
341                             if(!(fITSgeom->IsShapeDefined(kSSD))) 
342                                 fITSgeom->ReSetShape(kSSD,new AliITSgeomSSD275and75());
343                             break;
344                         case 6:
345                             fITSgeom->CreatMatrix(mod,lay,lad,det,kSSDp,t,r);
346                             if(!(fITSgeom->IsShapeDefined(kSSDp))) 
347                                 fITSgeom->ReSetShape(kSSDp,new AliITSgeomSSD75and275());
348                             break;
349                         } // end switch
350                 } // end for det
351             } // end for lad
352             break;
353         } // end switch
354     } // end for lay
355     return;
356 }
357 //_____________________________________________________________________________
358 void AliITSvtest::Init(){
359 ////////////////////////////////////////////////////////////////////////
360 //     Initialise the ITS after it has been created.
361 ////////////////////////////////////////////////////////////////////////
362     Int_t i;
363
364     cout << endl;
365     for(i=0;i<29;i++) cout << "*";cout << " ITSvtest_Init ";
366     for(i=0;i<28;i++) cout << "*";cout << endl;
367 //
368     if(fRead[0]=='\0') strncpy(fRead,fEuclidGeomDet,60);
369     if(fWrite[0]=='\0') strncpy(fWrite,fEuclidGeomDet,60);
370     if(fITSgeom!=0) delete fITSgeom;
371     fITSgeom = new AliITSgeom();
372     if(fGeomDetIn) fITSgeom->ReadNewFile(fRead);
373     if(!fGeomDetIn) this->InitAliITSgeom();
374     if(fGeomDetOut) fITSgeom->WriteNewFile(fWrite);
375     AliITS::Init();
376 //
377     for(i=0;i<72;i++) cout << "*";
378     cout << endl;
379 }
380 //_____________________________________________________________________________
381 void AliITSvtest::StepManager(){
382   //
383   // Called for every step in the ITS
384   //
385   Int_t          copy, id;
386   Int_t          copy1,copy2;
387   Float_t        hits[8];
388   Int_t          vol[4];
389   TLorentzVector position, momentum;
390   TClonesArray   &lhits = *fHits;
391   //
392   // Track status
393   vol[3] = 0;
394   if(gMC->IsTrackInside())      vol[3] +=  1;
395   if(gMC->IsTrackEntering())    vol[3] +=  2;
396   if(gMC->IsTrackExiting())     vol[3] +=  4;
397   if(gMC->IsTrackOut())         vol[3] +=  8;
398   if(gMC->IsTrackDisappeared()) vol[3] += 16;
399   if(gMC->IsTrackStop())        vol[3] += 32;
400   if(gMC->IsTrackAlive())       vol[3] += 64;
401   //
402   // Fill hit structure.
403   if(!(gMC->TrackCharge())) return;
404   //
405   // Only entering charged tracks
406   if((id = gMC->CurrentVolID(copy)) == fIdSens[0]) {
407       vol[0] = 1;
408       id = gMC->CurrentVolOffID(0,copy);
409       //detector copy in the ladder = 1<->4  (ITS1)
410       vol[1] = copy;
411       gMC->CurrentVolOffID(1,copy1);
412       //ladder copy in the module   = 1<->2  (I186)
413       gMC->CurrentVolOffID(2,copy2);
414       //module copy in the layer    = 1<->10 (I132)
415       vol[2] = copy1+(copy2-1)*2;//# of ladders in one module  = 2
416   } else if(id == fIdSens[1]){
417       vol[0] = 2;
418       id = gMC->CurrentVolOffID(0,copy);
419       //detector copy in the ladder = 1<->4  (ITS2)
420       vol[1] = copy;
421       gMC->CurrentVolOffID(1,copy1);
422       //ladder copy in the module   = 1<->4  (I131)
423       gMC->CurrentVolOffID(2,copy2);
424       //module copy in the layer    = 1<->10 (I132)
425       vol[2] = copy1+(copy2-1)*4;//# of ladders in one module  = 4
426   } else if(id == fIdSens[2]){
427       vol[0] = 3;
428       id = gMC->CurrentVolOffID(1,copy);
429       //detector copy in the ladder = 1<->5  (ITS3 is inside I314)
430       vol[1] = copy;
431       id = gMC->CurrentVolOffID(2,copy);
432       //ladder copy in the layer    = 1<->12 (I316)
433       vol[2] = copy;
434   } else if(id == fIdSens[3]){
435       vol[0] = 4;
436       id = gMC->CurrentVolOffID(1,copy);
437       //detector copy in the ladder = 1<->8  (ITS4 is inside I414)
438       vol[1] = copy;
439       id = gMC->CurrentVolOffID(2,copy);
440       //ladder copy in the layer    = 1<->22 (I417)
441       vol[2] = copy;
442   }else if(id == fIdSens[4]){
443       vol[0] = 5;
444       id = gMC->CurrentVolOffID(1,copy);
445       //detector copy in the ladder = 1<->23  (ITS5 is inside I562)
446       vol[1] = copy;
447       id = gMC->CurrentVolOffID(2,copy);
448      //ladder copy in the layer    = 1<->34 (I565)
449       vol[2] = copy;
450   }else if(id == fIdSens[5]){
451       vol[0] = 6;
452       id = gMC->CurrentVolOffID(1,copy);
453       //detector copy in the ladder = 1<->26  (ITS6 is inside I566)
454       vol[1] = copy;
455       id = gMC->CurrentVolOffID(2,copy);
456       //ladder copy in the layer = 1<->38 (I569)
457       vol[2] = copy;
458   } else {
459       return; // not an ITS volume?
460   } // end if/else if (gMC->CurentVolID(copy) == fIdSens[i])
461 //
462   gMC->TrackPosition(position);
463   gMC->TrackMomentum(momentum);
464   hits[0]=position[0];
465   hits[1]=position[1];
466   hits[2]=position[2];
467   hits[3]=momentum[0];
468   hits[4]=momentum[1];
469   hits[5]=momentum[2];
470   hits[6]=gMC->Edep();
471   hits[7]=gMC->TrackTime();
472   // Fill hit structure with this new hit.
473   new(lhits[fNhits++]) AliITShit(fIshunt,gAlice->CurrentTrack(),vol,hits);
474   return;
475 }
476