]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSvtest.cxx
Fixed bug with GetCovMatrix returning a pointer to a deleted local array.
[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.4  2001/01/18 06:25:09  barbera
19 ITS geometry using test Euclid files
20
21 Revision 1.1.2.8  2000/10/05 20:28:18  nilsen
22 Now using root generated streamer function.
23
24 Revision 1.1.2.7  2000/07/31 13:51:22  barbera
25 Updated from the release
26
27 Revision 1.2  2000/07/10 16:07:19  fca
28 Release version of ITS code
29
30 Revision 1.1.2.2  2000/03/02 21:53:36  nilsen
31 to make it compatable with the changes in AliRun/AliModule.
32
33 Revision 1.1.2.1  2000/01/12 20:19:03  nilsen
34         The changes made with this latest inclusion of code is very large.
35 Many of the new files were added just in December when P. Cerello added his
36 SDD simulations to the distrobutions. Also added are some file of P. Skowronski
37 for SSD cluster finding and ghost RecPoints. None of this "new" code has been
38 proporly tested. Other code new to this cvs repository is explained in the
39 ITS Off-line web page. In general the changes are too large to give a resonable
40 discription of them but probably should be taken as the starting point for
41 the developement branch (ITS-working).
42     B. S. Nilsen
43
44 Revision 1.13  1999/10/16 19:49:00  BSN
45 $Name$
46 $Author$
47 $Id$
48 */
49
50 ///////////////////////////////////////////////////////////////////////////////
51 //                                                                           //
52 //  Inner Traking System version Test                                        //
53 //  This class contains the base procedures for the Inner Tracking System    //
54 //                                                                           //
55 // Authors: R. Barbera, B. S. Nilsen.                                        //
56 // version  Test                                                             //
57 // Created October 16 1999.                                                  //
58 //                                                                           //
59 ///////////////////////////////////////////////////////////////////////////////
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <TMath.h>
63 #include <TGeometry.h>
64 #include <TNode.h>
65 #include <TTUBE.h>
66 #include <TFile.h>    // only required for Tracking function?
67 #include <TCanvas.h>
68 #include <TObjArray.h>
69 #include <TObjString.h>
70 #include <TClonesArray.h>
71 #include <TLorentzVector.h>
72 #include <TBRIK.h>
73 #include <TSystem.h>
74
75 #include "AliMC.h"
76 #include "AliRun.h"
77 #include "AliITShit.h"
78 #include "AliITS.h"
79 #include "AliITSvtest.h"
80 #include "AliITSgeom.h"
81
82 ClassImp(AliITSvtest)
83  
84 //_____________________________________________________________________________
85 AliITSvtest::AliITSvtest() {
86     //
87     // Standard constructor for the ITS
88     //
89     fIdN    = 0;
90     fIdName = 0;
91     fIdSens = 0;
92     fMajorVersion = -1;
93     fMinorVersion = -1;
94 }
95 //____________________________________________________________________________
96 AliITSvtest::AliITSvtest(const AliITSvtest &source){
97 ////////////////////////////////////////////////////////////////////////
98 //     Copy Constructor for ITS test version.
99 ////////////////////////////////////////////////////////////////////////
100     if(&source == this) return;
101     printf("Not allowed to copy AliITSvtest\n");
102     return;
103 }
104 //_____________________________________________________________________________
105 AliITSvtest& AliITSvtest::operator=(const AliITSvtest &source){
106 ////////////////////////////////////////////////////////////////////////
107 //    Assignment operator for the ITS version 1.
108 ////////////////////////////////////////////////////////////////////////
109         if(&source == this) return *this;
110         printf("Not allowed to copy AliITSvtest\n");
111         return *this;
112 }
113 //_____________________________________________________________________________
114 AliITSvtest::~AliITSvtest() {
115     //
116     // Standard destructor for the ITS
117     //
118 }
119 //_____________________________________________________________________________
120 AliITSvtest::AliITSvtest(const char *fileeuc,const char *filetme,
121                          const char *name, const char *title) 
122     : AliITS(name, title){
123     //
124     // Standard constructor for the ITS
125     //
126     fIdN    = 6;
127 /*
128 //  TObjArray of TObjStrings
129     fIdName = new TObjArray(fIdN);
130     fIdName->AddAt(new TObjString("ITS1"),0);
131     fIdName->AddAt(new TObjString("ITS2"),1);
132     fIdName->AddAt(new TObjString("ITS3"),2);
133     fIdName->AddAt(new TObjString("ITS4"),3);
134     fIdName->AddAt(new TObjString("ITS5"),4);
135     fIdName->AddAt(new TObjString("ITS6"),5);
136 */
137 //  Array of TStrings.
138     fIdName    = new TString[fIdN];
139     fIdName[0] = "ITS1";
140     fIdName[1] = "ITS2";
141     fIdName[2] = "ITS3";
142     fIdName[3] = "ITS4";
143     fIdName[4] = "ITS5";
144     fIdName[5] = "ITS6";
145     fIdSens    = new Int_t[fIdN];
146     for (Int_t i=0;i<fIdN;i++) fIdSens[i] = 0;
147     fMajorVersion = -1;
148     fMinorVersion = 1;
149
150     fEuclidMaterial = filetme;
151     fEuclidGeometry = fileeuc;
152 //  The .det file for the geometry must have the same name as fileeuc with
153 //  .euc replaced by .det.
154 }
155
156  
157 //_____________________________________________________________________________
158 void AliITSvtest::CreateMaterials(){
159   //
160   // Read materials for the ITS
161   //
162     char *filtmp;
163 //
164   filtmp = gSystem->ExpandPathName(fEuclidMaterial.Data());
165 //  FILE *file = fopen(fEuclidMaterial.Data(),"r");
166   FILE *file = fopen(filtmp,"r");
167   if(file) {
168     fclose(file);
169 //    ReadEuclidMedia(fEuclidMaterial.Data(),this);
170     ReadEuclidMedia(filtmp);
171   } else {
172     Error("CreateMaterials"," THE MEDIA FILE %s DOES NOT EXIST !",
173 //        fEuclidMaterial.Data());
174           filtmp);
175     exit(1);
176   } // end if(file)
177 }
178
179 //_____________________________________________________________________________
180 void AliITSvtest::CreateGeometry(){
181 //////////////////////////////////////////////////////////////////////
182 ////////////////////////////////////////////////////////////////////////
183 // Read geometry for the ITS
184 //
185
186     Int_t size;
187     char topvol[5];
188     char *filtmp;
189 //
190   filtmp = gSystem->ExpandPathName(fEuclidGeometry.Data());
191   FILE *file = fopen(filtmp,"r");
192   delete [] filtmp;
193   if(file) {
194     fclose(file);
195     printf("Ready to read Euclid geometry file\n");
196     ReadEuclid(fEuclidGeometry.Data(),topvol);
197     printf("Read in euclid geometries\n");
198   } else {
199     Error("CreateGeometry"," THE GEOM FILE %s DOES NOT EXIST !",
200           fEuclidGeometry.Data());
201     exit(1);
202   } // end if(file)
203   //
204   //---Place the ITS ghost volume ITSV in its mother volume (ALIC) and make it
205   //     invisible
206   //
207   gMC->Gspos("ITSV",1,"ALIC",0,0,0,0,"ONLY");
208   //
209   //---Outputs the geometry tree in the EUCLID/CAD format
210   
211     if (fEuclidOut) {
212       gMC->WriteEuclid("ITSgeometry", "ITSV", 1, 5);
213     } // end if (fEuclidOut)
214
215     filtmp = gSystem->ExpandPathName(fEuclidGeometry.Data());
216     size = strlen(filtmp);
217     if(size>4){
218         filtmp[size-3] = 'd'; // change from .euc to .det
219         filtmp[size-2] = 'e';
220         filtmp[size-1] = 't';
221         file = fopen(filtmp,"r");
222         if(file){ // if file exists use it to fill AliITSgeom structure.
223             fclose(file);
224             printf("ready to read .det file %s\n",filtmp);
225             fITSgeom = new AliITSgeom(filtmp);
226         }else{
227             fITSgeom = 0;
228             // fill AliITSgeom structure from geant structure just filled above
229         }// end if(file)
230         delete [] filtmp;
231     }// end if(size>4)
232     printf("finished with euclid geometrys\n");
233 }
234
235 //_____________________________________________________________________________
236 void AliITSvtest::Init(){
237     //
238     // Initialise the ITS after it has been created
239     //
240     AliITS::Init();
241     fMajorVersion = -1;
242     fMinorVersion = 0;
243
244  
245 //_____________________________________________________________________________
246 void AliITSvtest::StepManager(){
247   //
248   // Called for every step in the ITS
249   //
250   Int_t          copy, id;
251   Int_t          copy1,copy2;
252   Float_t        hits[8];
253   Int_t          vol[4];
254   TLorentzVector position, momentum;
255   TClonesArray   &lhits = *fHits;
256   //
257   // Track status
258   vol[3] = 0;
259   if(gMC->IsTrackInside())      vol[3] +=  1;
260   if(gMC->IsTrackEntering())    vol[3] +=  2;
261   if(gMC->IsTrackExiting())     vol[3] +=  4;
262   if(gMC->IsTrackOut())         vol[3] +=  8;
263   if(gMC->IsTrackDisappeared()) vol[3] += 16;
264   if(gMC->IsTrackStop())        vol[3] += 32;
265   if(gMC->IsTrackAlive())       vol[3] += 64;
266   //
267   // Fill hit structure.
268   if(!(gMC->TrackCharge())) return;
269   //
270   // Only entering charged tracks
271   if((id = gMC->CurrentVolID(copy)) == fIdSens[0]) {
272       vol[0] = 1;
273       id = gMC->CurrentVolOffID(0,copy);
274       //detector copy in the ladder = 1<->4  (ITS1)
275       vol[1] = copy;
276       gMC->CurrentVolOffID(1,copy1);
277       //ladder copy in the module   = 1<->2  (I186)
278       gMC->CurrentVolOffID(2,copy2);
279       //module copy in the layer    = 1<->10 (I132)
280       vol[2] = copy1+(copy2-1)*2;//# of ladders in one module  = 2
281   } else if(id == fIdSens[1]){
282       vol[0] = 2;
283       id = gMC->CurrentVolOffID(0,copy);
284       //detector copy in the ladder = 1<->4  (ITS2)
285       vol[1] = copy;
286       gMC->CurrentVolOffID(1,copy1);
287       //ladder copy in the module   = 1<->4  (I131)
288       gMC->CurrentVolOffID(2,copy2);
289       //module copy in the layer    = 1<->10 (I132)
290       vol[2] = copy1+(copy2-1)*4;//# of ladders in one module  = 4
291   } else if(id == fIdSens[2]){
292       vol[0] = 3;
293       id = gMC->CurrentVolOffID(1,copy);
294       //detector copy in the ladder = 1<->5  (ITS3 is inside I314)
295       vol[1] = copy;
296       id = gMC->CurrentVolOffID(2,copy);
297       //ladder copy in the layer    = 1<->12 (I316)
298       vol[2] = copy;
299   } else if(id == fIdSens[3]){
300       vol[0] = 4;
301       id = gMC->CurrentVolOffID(1,copy);
302       //detector copy in the ladder = 1<->8  (ITS4 is inside I414)
303       vol[1] = copy;
304       id = gMC->CurrentVolOffID(2,copy);
305       //ladder copy in the layer    = 1<->22 (I417)
306       vol[2] = copy;
307   }else if(id == fIdSens[4]){
308       vol[0] = 5;
309       id = gMC->CurrentVolOffID(1,copy);
310       //detector copy in the ladder = 1<->23  (ITS5 is inside I562)
311       vol[1] = copy;
312       id = gMC->CurrentVolOffID(2,copy);
313      //ladder copy in the layer    = 1<->34 (I565)
314       vol[2] = copy;
315   }else if(id == fIdSens[5]){
316       vol[0] = 6;
317       id = gMC->CurrentVolOffID(1,copy);
318       //detector copy in the ladder = 1<->26  (ITS6 is inside I566)
319       vol[1] = copy;
320       id = gMC->CurrentVolOffID(2,copy);
321       //ladder copy in the layer = 1<->38 (I569)
322       vol[2] = copy;
323   } else {
324       return; // not an ITS volume?
325   } // end if/else if (gMC->CurentVolID(copy) == fIdSens[i])
326 //
327   gMC->TrackPosition(position);
328   gMC->TrackMomentum(momentum);
329   hits[0]=position[0];
330   hits[1]=position[1];
331   hits[2]=position[2];
332   hits[3]=momentum[0];
333   hits[4]=momentum[1];
334   hits[5]=momentum[2];
335   hits[6]=gMC->Edep();
336   hits[7]=gMC->TrackTime();
337   // Fill hit structure with this new hit.
338   new(lhits[fNhits++]) AliITShit(fIshunt,gAlice->CurrentTrack(),vol,hits);
339   return;
340 }
341