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