]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSv5.cxx
Add tmevsin and mevsim libraries.
[u/mrichter/AliRoot.git] / ITS / AliITSv5.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.31  2001/02/13 16:53:35  nilsen
19 Fixed a but when trying to use GEANT4. Needed to replace
20 if(!((TGeant3*)gMC)) with if(!(dynamic_casst<TGeant3*>(gMC)))
21 because just casting gMC to be TGeant3* even when it realy is a TGeant3 pointer
22 did not result in a zero value. For AliITSv5asymm and AliITSv5symm, needed
23 to fix a bug in the initilizers and a bug in BuildGeometry. This is now done
24 in the same way as in AliITSv5.cxx.
25
26 Revision 1.30  2001/02/09 20:06:26  nilsen
27 Fixed bug in distructor. Can't distroy fixxed length arrays. Thanks Peter.
28
29 Revision 1.29  2001/02/09 00:05:31  nilsen
30 Added fMajor/MinorVersion variables and made other changes to better make
31 use of the new code changes in AliITSgeom related classes.
32
33 Revision 1.28  2001/02/02 23:57:28  nilsen
34 Added include file that are no londer included in AliITSgeom.h
35
36 Revision 1.27  2001/01/30 09:23:13  hristov
37 Streamers removed (R.Brun)
38
39 Revision 1.26  2000/11/30 11:13:11  barbera
40  Added changes suggested by Federico Carminati on nov, 30, 2000
41
42 Revision 1.25  2000/10/05 20:50:00  nilsen
43 Now using root generated streamers.
44
45 Revision 1.14.4.12  2000/10/02 16:04:03  barbera
46 Forward declarations added
47
48 Revision 1.22  2000/07/10 16:07:19  fca
49 Release version of ITS code
50
51 Revision 1.14.4.4  2000/05/19 10:10:21  nilsen
52 fix for bug with HP and Sun unix + fix for event display in ITS-working branch
53
54 Revision 1.14.4.3  2000/03/04 23:46:38  nilsen
55 Fixed up the comments/documentation.
56
57 Revision 1.14.4.2  2000/03/02 21:53:02  nilsen
58 To make it compatable with the changes in AliRun/AliModule.
59
60 Revision 1.14.4.1  2000/01/12 19:03:33  nilsen
61 This is the version of the files after the merging done in December 1999.
62 See the ReadMe110100.txt file for details
63
64 Revision 1.14  1999/10/22 08:16:49  fca
65 Correct destructors, thanks to I.Hrivnacova
66
67 Revision 1.13  1999/10/06 10:15:19  fca
68 Correct bug in allocation of layer name and add destructor
69
70 Revision 1.12  1999/10/05 08:05:09  fca
71 Minor corrections for uninitialised variables.
72
73 Revision 1.11  1999/09/29 09:24:20  fca
74 Introduction of the Copyright and cvs Log
75
76 */
77
78 ///////////////////////////////////////////////////////////////////////////////
79 //
80 //  Inner Traking System version 5
81 //  This class contains the base procedures for the Inner Tracking System
82 //
83 // Authors: R. Barbera, B. S. Nilsen.
84 // version 5.
85 // Created September 17 1999.
86 //
87 ///////////////////////////////////////////////////////////////////////////////
88 #include <iostream.h>
89 #include <iomanip.h>
90 #include <stdio.h>
91 #include <stdlib.h>
92 #include <TMath.h>
93 #include <TGeometry.h>
94 #include <TNode.h>
95 #include <TTUBE.h>
96 #include <TFile.h>    // only required for Tracking function?
97 #include <TCanvas.h>
98 #include <TObjArray.h>
99 #include <TLorentzVector.h>
100 #include <TObjString.h>
101 #include <TClonesArray.h>
102 #include <TBRIK.h>
103 #include <TSystem.h>
104
105 #include "AliMC.h"
106 #include "AliRun.h"
107 #include "../TGeant3/TGeant3.h"
108 #include "AliITShit.h"
109 #include "AliITSGeant3Geometry.h"
110 #include "AliITS.h"
111 #include "AliITSv5.h"
112 #include "AliITSgeom.h"
113 #include "AliITSgeomSPD.h"
114 #include "AliITSgeomSDD.h"
115 #include "AliITSgeomSSD.h"
116
117 ClassImp(AliITSv5)
118  
119 //_____________________________________________________________________________
120 AliITSv5::AliITSv5() {
121 ////////////////////////////////////////////////////////////////////////
122 //    Standard default constructor for the ITS version 5.
123 ////////////////////////////////////////////////////////////////////////
124     Int_t i;
125
126     fIdN    = 0;
127     fIdName = 0;
128     fIdSens = 0;
129     fEuclidOut    = kFALSE; // Don't write Euclide file
130     fGeomDetOut   = kFALSE; // Don't write .det file
131     fGeomDetIn    = kFALSE; // Don't Read .det file
132     fGeomOldDetIn = kFALSE; // Don't Read old formatted .det file
133     fMajorVersion = IsVersion();
134     fMinorVersion = 1;
135     for(i=0;i<60;i++) fRead[i] = '\0';
136     for(i=0;i<60;i++) fWrite[i] = '\0';
137     for(i=0;i<60;i++) fEuclidGeomDet[i] = '\0';
138 }
139 //_____________________________________________________________________________
140 AliITSv5::AliITSv5(const char *name, const char *title) : AliITS(name, title){
141 ////////////////////////////////////////////////////////////////////////
142 //    Standard constructor for the ITS version 5.
143 ////////////////////////////////////////////////////////////////////////
144     Int_t i;
145
146     fIdN    = 6;
147     fIdName    = new TString[fIdN];
148     fIdName[0] = "ITS1";
149     fIdName[1] = "ITS2";
150     fIdName[2] = "ITS3";
151     fIdName[3] = "ITS4";
152     fIdName[4] = "ITS5";
153     fIdName[5] = "ITS6";
154     fIdSens    = new Int_t[fIdN];
155     for (i=0;i<fIdN;i++) fIdSens[i] = 0;
156     fEuclidOut    = kFALSE; // Don't write Euclide file
157     fGeomDetOut   = kFALSE; // Don't write .det file
158     fGeomDetIn    = kFALSE; // Don't Read .det file
159     fGeomOldDetIn = kFALSE; // Don't Read old formatted .det file
160     fMajorVersion = IsVersion();
161     fMinorVersion = 1;
162     for(i=0;i<60;i++) fRead[i] = '\0';
163     for(i=0;i<60;i++) fWrite[i] = '\0';
164
165     fEuclidMaterial = "$ALICE_ROOT/Euclid/ITSgeometry_5.tme";
166     fEuclidGeometry = "$ALICE_ROOT/Euclid/ITSgeometry_5.euc";
167     strncpy(fEuclidGeomDet,"$ALICE_ROOT/ITS/ITSgeometry_v5.det",60);
168     strncpy(fRead,fEuclidGeomDet,60);
169     strncpy(fWrite,fEuclidGeomDet,60);
170 }
171 //____________________________________________________________________________
172 AliITSv5::AliITSv5(const AliITSv5 &source){
173 ////////////////////////////////////////////////////////////////////////
174 //     Copy Constructor for ITS version 5.
175 ////////////////////////////////////////////////////////////////////////
176     if(&source == this) return;
177     Warning("Copy Constructor","Not allowed to copy AliITSv5");
178     return;
179 }
180 //_____________________________________________________________________________
181 AliITSv5& AliITSv5::operator=(const AliITSv5 &source){
182 ////////////////////////////////////////////////////////////////////////
183 //    Assignment operator for the ITS version 5.
184 ////////////////////////////////////////////////////////////////////////
185
186     if(&source == this) return *this;
187     Warning("= operator","Not allowed to copy AliITSv5");
188     return *this;
189
190 }
191 //_____________________________________________________________________________
192 AliITSv5::~AliITSv5() {
193 ////////////////////////////////////////////////////////////////////////
194 //    Standard destructor for the ITS version 5.
195 ////////////////////////////////////////////////////////////////////////
196 }
197 //______________________________________________________________________
198 void AliITSv5::BuildGeometry(){
199 ////////////////////////////////////////////////////////////////////////
200 //    Geometry builder for the ITS version 5.
201 ////////////////////////////////////////////////////////////////////////
202   //
203   // Build ITS TNODE geometry for event display using detailed geometry.
204   // This function builds a simple ITS geometry used by the ROOT macro
205   // ITSdisplay.C.
206
207   TNode *top;
208   TNode *nd;
209   //const int kColorITSSPD=kRed;
210   //const int kColorITSSDD=kGreen;
211   const int kColorITSSSD=kBlue;
212   //
213   AliITSgeom  *gm = this->GetITSgeom();
214   if(gm==0) return;
215   top=gAlice->GetGeometry()->GetNode("alice");
216
217   Int_t       lay,lad,det,i;
218   Text_t      name[10];
219   Float_t     xg[3];
220   Float_t     rt[9];
221   Double_t    rtd[9];
222   TBRIK       *box;
223   TRotMatrix  *rm;
224   //TCanvas     *c1 = new TCanvas("c1","ITS");
225
226   for(lay=1;lay<=2;lay++)
227    for(lad=1;lad<=gm->GetNladders(lay);lad++)
228     for(det=1;det<=gm->GetNdetectors(lay);det++){
229           try {
230               box  = new TBRIK ("ActiveSPD","Active volume of SPD","SPD SI DET",
231                                     0.64,0.0075,4.19); 
232           } catch (...) {
233               cout << "EXCEPTION in box = new TBRIK" << endl;
234               return;
235           }
236           gm->GetTrans(lay,lad,det,xg[0],xg[1],xg[2]);
237           gm->GetRotMatrix(lay,lad,det,rt);
238           //sprintf(name,"ROT%1.1d2.2d2.2d",lay,lad,det);
239           for(i=0;i<9;i++) rtd[i] = rt[i];
240           try {
241                 rm  = new TRotMatrix(name,name,rtd);
242           } catch (...) {
243                 cout << "EXCEPTION in   new TRotMatrix" << endl;
244                 return;
245           }
246          top->cd();
247           //sprintf(name,"ND%1.1d2.2d2.2d",lay,lad,det); 
248          try {
249               nd  = new TNode("SPD"," ",box,xg[0],xg[1],xg[2],rm);
250          } catch (...) {
251               cout << "EXCEPTION in new TNode" << endl;
252               return;
253          }
254          nd->SetLineColor(kColorITSSSD);
255          fNodes->Add(nd);
256     }
257
258   for(lay=3;lay<=3;lay++)
259    for(lad=1;lad<=gm->GetNladders(lay);lad++)
260     for(det=1;det<=gm->GetNdetectors(lay);det++){
261           try {
262               box  = new TBRIK ("ActiveSDD","Active volume of SDD","SDD SI DET",
263                                     3.5,0.014,3.763); 
264           } catch (...) {
265               cout << "EXCEPTION in box = new TBRIK" << endl;
266               return;
267           }
268           gm->GetTrans(lay,lad,det,xg[0],xg[1],xg[2]);
269           gm->GetRotMatrix(lay,lad,det,rt);
270           //sprintf(name,"ROT%1.1d2.2d2.2d",lay,lad,det);
271           for(i=0;i<9;i++) rtd[i] = rt[i];
272           try {
273                 rm  = new TRotMatrix(name,name,rtd);
274           } catch (...) {
275                 cout << "EXCEPTION in   new TRotMatrix" << endl;
276                 return;
277           }
278          top->cd();
279           //sprintf(name,"ND%1.1d2.2d2.2d",lay,lad,det); 
280          try {
281               nd  = new TNode("SDD"," ",box,xg[0],xg[1],xg[2],rm);
282          } catch (...) {
283               cout << "EXCEPTION in new TNode" << endl;
284               return;
285          }
286          nd->SetLineColor(kColorITSSSD);
287          fNodes->Add(nd);
288     }
289
290   for(lay=4;lay<=4;lay++)
291    for(lad=1;lad<=gm->GetNladders(lay);lad++)
292     for(det=1;det<=gm->GetNdetectors(lay);det++){
293           try {
294               box  = new TBRIK ("ActiveSDD","Active volume of SDD","SDD SI DET",
295                                     3.5,0.014,3.763); 
296           } catch (...) {
297               cout << "EXCEPTION in box = new TBRIK" << endl;
298               return;
299           }
300           gm->GetTrans(lay,lad,det,xg[0],xg[1],xg[2]);
301           gm->GetRotMatrix(lay,lad,det,rt);
302           //sprintf(name,"ROT%1.1d2.2d2.2d",lay,lad,det);
303           for(i=0;i<9;i++) rtd[i] = rt[i];
304           try {
305                 rm  = new TRotMatrix(name,name,rtd);
306           } catch (...) {
307                 cout << "EXCEPTION in   new TRotMatrix" << endl;
308                 return;
309           }
310          top->cd();
311           //sprintf(name,"ND%1.1d2.2d2.2d",lay,lad,det); 
312          try {
313               nd  = new TNode("SDD"," ",box,xg[0],xg[1],xg[2],rm);
314          } catch (...) {
315               cout << "EXCEPTION in new TNode" << endl;
316               return;
317          }
318          nd->SetLineColor(kColorITSSSD);
319          fNodes->Add(nd);
320     }
321  for(lay=5;lay<=5;lay++)
322    for(lad=1;lad<=gm->GetNladders(lay);lad++)
323     for(det=1;det<=gm->GetNdetectors(lay);det++){
324           try {
325               box  = new TBRIK ("ActiveSSD","Active volume of SSD","SSD SI DET",
326                                     3.65,0.015,2.0); 
327           } catch (...) {
328               cout << "EXCEPTION in box = new TBRIK" << endl;
329               return;
330           }
331           gm->GetTrans(lay,lad,det,xg[0],xg[1],xg[2]);
332           gm->GetRotMatrix(lay,lad,det,rt);
333           //sprintf(name,"ROT%1.1d2.2d2.2d",lay,lad,det);
334           for(i=0;i<9;i++) rtd[i] = rt[i];
335           try {
336                 rm  = new TRotMatrix(name,name,rtd);
337           } catch (...) {
338                 cout << "EXCEPTION in   new TRotMatrix" << endl;
339                 return;
340           }
341          top->cd();
342           //sprintf(name,"ND%1.1d2.2d2.2d",lay,lad,det); 
343          try {
344               nd  = new TNode("SSD"," ",box,xg[0],xg[1],xg[2],rm);
345          } catch (...) {
346               cout << "EXCEPTION in new TNode" << endl;
347               return;
348          }
349          nd->SetLineColor(kColorITSSSD);
350          fNodes->Add(nd);
351     }
352
353  for(lay=6;lay<=6;lay++)
354    for(lad=1;lad<=gm->GetNladders(lay);lad++)
355     for(det=1;det<=gm->GetNdetectors(lay);det++){
356           try {
357               box  = new TBRIK ("ActiveSSD","Active volume of SSD","SSD SI DET",
358                                     3.65,0.015,2.0); 
359           } catch (...) {
360               cout << "EXCEPTION in box = new TBRIK" << endl;
361               return;
362           }
363
364           gm->GetTrans(lay,lad,det,xg[0],xg[1],xg[2]); 
365           gm->GetRotMatrix(lay,lad,det,rt);
366           //sprintf(name,"ROT%1.1d2.2d2.2d",lay,lad,det);
367           for(i=0;i<9;i++) rtd[i] = rt[i];
368           try {
369                 rm  = new TRotMatrix(name,name,rtd);
370           } catch (...) {
371                 cout << "EXCEPTION in   new TRotMatrix" << endl;
372                 return;
373           }
374          top->cd();
375           //sprintf(name,"ND%1.1d2.2d2.2d",lay,lad,det); 
376          try {
377               nd  = new TNode("SSD"," ",box,xg[0],xg[1],xg[2],rm);
378          } catch (...) {
379               cout << "EXCEPTION in new TNode" << endl;
380               return;
381          }
382          nd->SetLineColor(kColorITSSSD);
383          fNodes->Add(nd);
384     }
385
386
387
388 //_____________________________________________________________________________
389 void AliITSv5::CreateMaterials(){
390 ////////////////////////////////////////////////////////////////////////
391 //     Read a file containing the materials for the ITS version 5.
392 ////////////////////////////////////////////////////////////////////////
393     char *filtmp;
394
395   filtmp = gSystem->ExpandPathName(fEuclidMaterial.Data());
396
397   FILE *file = fopen(filtmp,"r");
398   if(file) {
399     fclose(file);
400     ReadEuclidMedia(filtmp);
401   } else {
402     Error("CreateMaterials"," THE MEDIA FILE %s DOES NOT EXIST !",filtmp);
403     exit(1);
404   } // end if(file)
405 }
406 //_____________________________________________________________________________
407 void AliITSv5::CreateGeometry(){
408 //////////////////////////////////////////////////////////////////////
409 //    This is the geometry used for the ITS Pre-TDR and comes from an 
410 // Euclid to Geant conversion. The only difference
411 // is in the details of the ITS supports. The detectors elements, 
412 // detector numbering, and local and global reference frames are shown in
413 //  the following figures.
414 //Begin_Html
415 /*
416 <img src="picts/ITS/its1+2_convention_front_5.gif">
417 </pre>
418 <br clear=left>
419 <font size=+2 color=red>
420 <p>This shows the front view of the SPDs.
421 </font>
422 <pre>
423 <img src="picts/ITS/its1+2_convention_side_5.gif">
424 </pre>
425 <br clear=left>
426 <font size=+2 color=red>
427 <p>This shows the perspective view of the SPDs.
428 </font>
429 <img src="picts/ITS/its1+2_tree.gif">
430 </pre>
431 <br clear=left>
432 <font size=+2 color=red>
433 <p>This shows the geometry Tree for the SPDs.
434 </font>
435 <pre>
436
437 <pre>
438 <img src="picts/ITS/its3+4_convention_front_5.gif">
439 </pre>
440 <br clear=left>
441 <font size=+2 color=red>
442 <p>This shows the front view of the SDDs.
443 </font>
444 <pre>
445 <img src="picts/ITS/its3+4_convention_side_5.gif">
446 </pre>
447 <br clear=left>
448 <font size=+2 color=red>
449 <p>This shows the perspective view of the SDDs.
450 </font>
451 <img src="picts/ITS/its3+4_tree.gif">
452 </pre>
453 <br clear=left>
454 <font size=+2 color=red>
455 <p>This shows the geometry Tree for the SDDs.
456 </font>
457 <pre>
458
459 <pre>
460 <img src="picts/ITS/its5+6_convention_front_5.gif">
461 </pre>
462 <br clear=left>
463 <font size=+2 color=red>
464 <p>This shows the front view of the SSDs.
465 </font>
466 <pre>
467 <img src="picts/ITS/its5+6_convention_side_5.gif">
468 </pre>
469 <br clear=left>
470 <font size=+2 color=red>
471 <p>This shows the perspective view of the SSDs.
472 </font>
473 <pre>
474 <img src="picts/ITS/its5+6_tree.gif">
475 </pre>
476 <br clear=left>
477 <font size=+2 color=red>
478 <p>This shows the geometry Tree for the SSDs.
479 </font>
480 <pre>
481
482
483 <img src="picts/ITS/its_layer1-6_2.gif">
484 </pre>
485 <br clear=left>
486 <font size=+2 color=red>
487 <p>This shows the front view of the whole ITS..
488 </font>
489 <pre>
490
491 <img src="picts/ITS/its_layer1-6_1.gif">
492 </pre>
493 <br clear=left>
494 <font size=+2 color=red>
495 <p>This shows the perspective view of the whole ITS..
496 </font>
497 <pre>
498
499 <img src="picts/ITS/its1-6_tree.gif">
500 </pre>
501 <br clear=left>
502 <font size=+2 color=red>
503 <p>This shows the geometry Tree for the whole ITS.
504 </font>
505 <pre>
506 */
507 //End_Html
508 //
509 //
510 //      Here are shown the details of the ITS support cones and services.
511 // First is a GEANT tree showing the organization of all of the volumes
512 // that make up the ITS supports and services.
513 //Begin_Html
514 /*
515 <img src="picts/ITS/supports_tree.gif">
516  */
517 //End_Html
518 //     What follows are a number of figures showing what these support
519 // structures look like.
520 //Begin_Html
521 /*
522
523 <img src="picts/ITS/supports_3.gif">
524 </pre>
525 <br clear=left>
526 <font size=+2 color=red>
527 <p>This shows the geometry of the supports for the Drift and Strip layers only.
528 </font>
529 <pre>
530
531 <img src="picts/ITS/supports_2.gif">
532 </pre>
533 <br clear=left>
534 <font size=+2 color=red>
535 <p>This shows the geometry of the supports for the Drift and Strip layers in front cut out.
536 </font>
537 <pre>
538
539 <img src="picts/ITS/supports_1.gif">
540 </pre>
541 <br clear=left>
542 <font size=+2 color=red>
543 <p>This shows the geometry of the supports for the Drift and Strip layers in a back cut out..
544 </font>
545 <pre>
546
547 <img src="picts/ITS/suppssd.gif">
548 </pre>
549 <br clear=left>
550 <font size=+2 color=red>
551 <p>This shows the geometry for the Strip layers supports.
552 </font>
553 <pre>
554
555 <img src="picts/ITS/suppsdd.gif">
556 </pre>
557 <br clear=left>
558 <font size=+2 color=red>
559 <p>This shows the geometry for the Drift layers supports.
560 </font>
561 <pre>
562  */
563 //End_Html
564 //
565 //    Read a file containing the geometry for the ITS version 5.
566 ////////////////////////////////////////////////////////////////////////
567
568
569     char topvol[5];
570     char *filtmp;
571
572   filtmp = gSystem->ExpandPathName(fEuclidGeometry.Data());
573   FILE *file = fopen(filtmp,"r");
574   delete [] filtmp;
575   if(file) {
576     fclose(file);
577     cout << "Ready to read Euclid geometry file" << endl;
578     ReadEuclid(fEuclidGeometry.Data(),topvol);
579     printf("Read in euclid geometries\n");
580   } else {
581     Error("CreateGeometry"," THE GEOM FILE %s DOES NOT EXIST !",
582           fEuclidGeometry.Data());
583     exit(1);
584   } // end if(file)
585   //
586   // Place the ITS ghost volume ITSV in its mother volume (ALIC) and make it
587   // invisible
588   //
589   gMC->Gspos("ITSV",1,"ALIC",0,0,0,0,"ONLY");
590   //
591   // Outputs the geometry tree in the EUCLID/CAD format if requested to do so
592   
593     if (fEuclidOut) {
594       gMC->WriteEuclid("ITSgeometry", "ITSV", 1, 5);
595     } // end if (fEuclidOut)
596
597     cout << "finished with euclid geometrys" << endl;
598 }
599 //______________________________________________________________________
600 void AliITSv5::ReadOldGeometry(const char *filename){
601     // read in the file containing the transformations for the active
602     // volumes for the ITS version 5. This is expected to be in a file
603     // ending in .det. This geometry is kept in the AliITSgeom class.
604     Int_t size;
605     char *filtmp;
606     FILE *file;
607
608     if(fITSgeom!=0) delete fITSgeom;
609     filtmp = gSystem->ExpandPathName(filename);
610     size = strlen(filtmp);
611     if(size>4 && fGeomDetIn){
612         filtmp[size-3] = 'd'; // change from .euc to .det
613         filtmp[size-2] = 'e';
614         filtmp[size-1] = 't';
615         file = fopen(filtmp,"r");
616         if(file){ // if file exists use it to fill AliITSgeom structure.
617             fclose(file);
618             fITSgeom = new AliITSgeom(filtmp);
619             fITSgeom->DefineShapes(3); // if fShape isn't defined define it.
620             // Now define the detector types/shapes.
621             fITSgeom->ReSetShape(kSPD,new AliITSgeomSPD300());
622             fITSgeom->ReSetShape(kSDD,new AliITSgeomSDD300());
623             fITSgeom->ReSetShape(kSSD,new AliITSgeomSSD175());
624         }else{
625             fITSgeom = 0;
626             // fill AliITSgeom structure from geant structure just filled above
627         }// end if(file)
628         delete [] filtmp;
629     }// end if(size>4)
630 }
631 //______________________________________________________________________
632 void AliITSv5::InitAliITSgeom(){
633 //     Based on the geometry tree defined in Geant 3.21, this
634 // routine initilizes the Class AliITSgeom from the Geant 3.21 ITS geometry
635 // sturture.
636     if(!(dynamic_cast<TGeant3*>(gMC))) {
637         Error("InitAliITSgeom",
638                 "Wrong Monte Carlo. InitAliITSgeom uses TGeant3 calls");
639         return;
640     } // end if
641     cout << "Reading Geometry transformation directly from Geant 3." << endl;
642     const Int_t nlayers = 6;
643     const Int_t ndeep = 7;
644     Int_t itsGeomTreeNames[nlayers][ndeep],lnam[20],lnum[20];
645     Int_t nlad[nlayers],ndet[nlayers];
646     Double_t t[3],r[10];
647     Float_t  par[20],att[20];
648     Int_t    npar,natt,idshape,imat,imed;
649     AliITSGeant3Geometry *ig = new AliITSGeant3Geometry();
650     Int_t mod,lay,lad,det,i,j,k;
651     char *names[nlayers][ndeep] = {
652         {"ALIC","ITSV","ITSD","IT12","I132","I186","ITS1"}, // lay=1
653         {"ALIC","ITSV","ITSD","IT12","I132","I131","ITS2"}, // lay=2
654         {"ALIC","ITSV","ITSD","IT34","I004","I302","ITS3"}, // lay=3
655         {"ALIC","ITSV","ITSD","IT34","I005","I402","ITS4"}, // lay=4
656         {"ALIC","ITSV","ITSD","IT56","I565","I562","ITS5"}, // lay=5
657         {"ALIC","ITSV","ITSD","IT56","I569","I566","ITS6"}};// lay=6
658     Int_t itsGeomTreeCopys[nlayers][ndeep] = {{1,1,1,1,10, 2,4}, // lay=1
659                                               {1,1,1,1,10, 4,4}, // lay=2
660                                               {1,1,1,1,14, 6,1}, // lay=3
661                                               {1,1,1,1,22, 8,1}, // lay=4
662                                               {1,1,1,1,34,23,1}, // lay=5
663                                               {1,1,1,1,38,26,1}};// lay=6
664
665     // Sorry, but this is not very pritty code. It should be replaced
666     // at some point with a version that can search through the geometry
667     // tree its self.
668     for(i=0;i<20;i++) lnam[i] = lnum[i] = 0;
669     for(i=0;i<nlayers;i++)for(j=0;j<ndeep;j++) 
670         itsGeomTreeNames[i][j] = ig->StringToInt(names[i][j]);
671     mod = 0;
672     for(i=0;i<nlayers;i++){
673         k = 1;
674         for(j=0;j<ndeep;j++) if(itsGeomTreeCopys[i][j]!=0)
675             k *= TMath::Abs(itsGeomTreeCopys[i][j]);
676         mod += k;
677     } // end for i
678
679     if(fITSgeom!=0) delete fITSgeom;
680     nlad[0]=20;nlad[1]=40;nlad[2]=14;nlad[3]=22;nlad[4]=34;nlad[5]=38;
681     ndet[0]=4;ndet[1]=4;ndet[2]=6;ndet[3]=8;ndet[4]=22;ndet[5]=25;
682     fITSgeom = new AliITSgeom(0,6,nlad,ndet,mod);
683     mod = -1;
684     for(lay=1;lay<=nlayers;lay++){
685         for(j=0;j<ndeep;j++) lnam[j] = itsGeomTreeNames[lay-1][j];
686         for(j=0;j<ndeep;j++) lnum[j] = itsGeomTreeCopys[lay-1][j];
687         switch (lay){
688         case 1: case 2: // layers 1 and 2 are a bit special
689             lad = 0;
690             for(j=1;j<=itsGeomTreeCopys[lay-1][4];j++){
691                 lnum[4] = j;
692                 for(k=1;k<=itsGeomTreeCopys[lay-1][5];k++){
693                     lad++;
694                     lnum[5] = k;
695                     for(det=1;det<=itsGeomTreeCopys[lay-1][6];det++){
696                         lnum[6] = det;
697                         mod++;
698                         ig->GetGeometry(ndeep,lnam,lnum,t,r,idshape,npar,natt,
699                                         par,att,imat,imed);
700                         fITSgeom->CreatMatrix(mod,lay,lad,det,kSPD,t,r);
701                         if(!(fITSgeom->IsShapeDefined((Int_t)kSPD)))
702                              fITSgeom->ReSetShape(kSPD,
703                                                   new AliITSgeomSPD300());
704                     } // end for det
705                 } // end for k
706             } // end for j
707             break;
708         case 3: case 4: case 5: case 6: // layers 3-6
709             lnum[6] = 1;
710             for(lad=1;lad<=itsGeomTreeCopys[lay-1][4];lad++){
711                 lnum[4] = lad;
712                 for(det=1;det<=itsGeomTreeCopys[lay-1][5];det++){
713                     lnum[5] = det;
714                     mod++;
715                     ig->GetGeometry(7,lnam,lnum,t,r,idshape,npar,natt,
716                                     par,att,imat,imed);
717                     switch (lay){
718                     case 3: case 4:
719                         fITSgeom->CreatMatrix(mod,lay,lad,det,kSDD,t,r);
720                         if(!(fITSgeom->IsShapeDefined(kSDD))) 
721                             fITSgeom->ReSetShape(kSDD,new AliITSgeomSDD300());
722                         break;
723                     case 5: case 6:
724                         fITSgeom->CreatMatrix(mod,lay,lad,det,kSSD,t,r);
725                         if(!(fITSgeom->IsShapeDefined(kSSD))) 
726                             fITSgeom->ReSetShape(kSSD,new AliITSgeomSSD175());
727                         break;
728                         } // end switch
729                 } // end for det
730             } // end for lad
731             break;
732         } // end switch
733     } // end for lay
734     return;
735 }
736 //_____________________________________________________________________________
737 void AliITSv5::Init(){
738 ////////////////////////////////////////////////////////////////////////
739 //     Initialise the ITS after it has been created.
740 ////////////////////////////////////////////////////////////////////////
741     Int_t i;
742
743     cout << endl;
744     for(i=0;i<30;i++) cout << "*";cout << " ITSv5_Init ";
745     for(i=0;i<30;i++) cout << "*";cout << endl;
746 //
747     if(fRead[0]=='\0') strncpy(fRead,fEuclidGeomDet,60);
748     if(fWrite[0]=='\0') strncpy(fWrite,fEuclidGeomDet,60);
749     if(fGeomDetIn && !fGeomOldDetIn){
750         if(fITSgeom!=0) delete fITSgeom;
751         fITSgeom = new AliITSgeom();
752         fITSgeom->ReadNewFile(fRead);
753     } // end if
754     if(fGeomDetIn &&  fGeomOldDetIn) ReadOldGeometry(fEuclidGeometry.Data());
755
756     if(!fGeomDetIn) this->InitAliITSgeom();
757     if(fGeomDetOut) fITSgeom->WriteNewFile(fWrite);
758     AliITS::Init();
759 //
760     for(i=0;i<72;i++) cout << "*";
761     cout << endl;
762 }
763 //_____________________________________________________________________________
764 void AliITSv5::StepManager(){
765 ////////////////////////////////////////////////////////////////////////
766 //    Called for every step in the ITS, then calles the AliITShit class
767 // creator with the information to be recoreded about that hit.
768 //     The value of the macro ALIITSPRINTGEOM if set to 1 will allow the
769 // printing of information to a file which can be used to create a .det
770 // file read in by the routine CreateGeometry(). If set to 0 or any other
771 // value except 1, the default behavior, then no such file is created nor
772 // it the extra variables and the like used in the printing allocated.
773 ////////////////////////////////////////////////////////////////////////
774   Int_t          copy, id;
775   Int_t          copy1,copy2;
776   Float_t        hits[8];
777   Int_t          vol[4];
778   TLorentzVector position, momentum;
779   TClonesArray   &lhits = *fHits;
780   //
781   // Track status
782   vol[3] = 0;
783   if(gMC->IsTrackInside())      vol[3] +=  1;
784   if(gMC->IsTrackEntering())    vol[3] +=  2;
785   if(gMC->IsTrackExiting())     vol[3] +=  4;
786   if(gMC->IsTrackOut())         vol[3] +=  8;
787   if(gMC->IsTrackDisappeared()) vol[3] += 16;
788   if(gMC->IsTrackStop())        vol[3] += 32;
789   if(gMC->IsTrackAlive())       vol[3] += 64;
790   //
791   // Fill hit structure.
792   if(!(gMC->TrackCharge())) return;
793   //
794   // Only entering charged tracks
795   if((id = gMC->CurrentVolID(copy)) == fIdSens[0]) {
796       vol[0] = 1;
797       id = gMC->CurrentVolOffID(0,copy);
798       //detector copy in the ladder = 1<->4  (ITS1)
799       vol[1] = copy;
800       gMC->CurrentVolOffID(1,copy1);
801       //ladder copy in the module   = 1<->2  (I186)
802       gMC->CurrentVolOffID(2,copy2);
803       //module copy in the layer    = 1<->10 (I132)
804       vol[2] = copy1+(copy2-1)*2;//# of ladders in one module  = 2
805   } else if(id == fIdSens[1]){
806       vol[0] = 2;
807       id = gMC->CurrentVolOffID(0,copy);
808       //detector copy in the ladder = 1<->4  (ITS2)
809       vol[1] = copy;
810       gMC->CurrentVolOffID(1,copy1);
811       //ladder copy in the module   = 1<->4  (I131)
812       gMC->CurrentVolOffID(2,copy2);
813       //module copy in the layer    = 1<->10 (I132)
814       vol[2] = copy1+(copy2-1)*4;//# of ladders in one module  = 4
815   } else if(id == fIdSens[2]){
816       vol[0] = 3;
817       id = gMC->CurrentVolOffID(1,copy);
818       //detector copy in the ladder = 1<->5  (ITS3 is inside I314)
819       vol[1] = copy;
820       id = gMC->CurrentVolOffID(2,copy);
821       //ladder copy in the layer    = 1<->12 (I316)
822       vol[2] = copy;
823   } else if(id == fIdSens[3]){
824       vol[0] = 4;
825       id = gMC->CurrentVolOffID(1,copy);
826       //detector copy in the ladder = 1<->8  (ITS4 is inside I414)
827       vol[1] = copy;
828       id = gMC->CurrentVolOffID(2,copy);
829       //ladder copy in the layer    = 1<->22 (I417)
830       vol[2] = copy;
831   }else if(id == fIdSens[4]){
832       vol[0] = 5;
833       id = gMC->CurrentVolOffID(1,copy);
834       //detector copy in the ladder = 1<->23  (ITS5 is inside I562)
835       vol[1] = copy;
836       id = gMC->CurrentVolOffID(2,copy);
837      //ladder copy in the layer    = 1<->34 (I565)
838       vol[2] = copy;
839   }else if(id == fIdSens[5]){
840       vol[0] = 6;
841       id = gMC->CurrentVolOffID(1,copy);
842       //detector copy in the ladder = 1<->26  (ITS6 is inside I566)
843       vol[1] = copy;
844       id = gMC->CurrentVolOffID(2,copy);
845       //ladder copy in the layer = 1<->38 (I569)
846       vol[2] = copy;
847   } else {
848       return; // not an ITS volume?
849   } // end if/else if (gMC->CurentVolID(copy) == fIdSens[i])
850 //
851   gMC->TrackPosition(position);
852   gMC->TrackMomentum(momentum);
853   hits[0]=position[0];
854   hits[1]=position[1];
855   hits[2]=position[2];
856   hits[3]=momentum[0];
857   hits[4]=momentum[1];
858   hits[5]=momentum[2];
859   hits[6]=gMC->Edep();
860   hits[7]=gMC->TrackTime();
861   // Fill hit structure with this new hit.
862   new(lhits[fNhits++]) AliITShit(fIshunt,gAlice->CurrentTrack(),vol,hits);
863   return;
864 }