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