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