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