]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRD.cxx
Add detailed geometry and simple simulator
[u/mrichter/AliRoot.git] / TRD / AliTRD.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.32  2001/10/08 06:57:33  hristov
19 Branches for  TRD digits are created only during the digitisation
20
21 Revision 1.31  2001/08/30 09:30:30  hristov
22 The split level of branches is set to 99
23
24 Revision 1.30  2001/05/28 17:07:58  hristov
25 Last minute changes; ExB correction in AliTRDclusterizerV1; taking into account of material in G10 TEC frames and material between TEC planes (C.Blume,S.Sedykh)
26
27 Revision 1.29  2001/05/21 16:45:47  hristov
28 Last minute changes (C.Blume)
29
30 Revision 1.28  2001/05/16 14:57:27  alibrary
31 New files for folders and Stack
32
33 Revision 1.27  2001/05/08 07:05:02  hristov
34 Loop variable declared once (HP, Sun)
35
36 Revision 1.26  2001/05/07 08:03:22  cblume
37 Generate also hits in the amplification region
38
39 Revision 1.25  2001/03/13 09:30:35  cblume
40 Update of digitization. Moved digit branch definition to AliTRD
41
42 Revision 1.24  2001/01/26 19:56:49  hristov
43 Major upgrade of AliRoot code
44
45 Revision 1.23  2000/11/01 14:53:20  cblume
46 Merge with TRD-develop
47
48 Revision 1.17.2.6  2000/10/15 23:29:08  cblume
49 Introduced more detailed geometry for the display
50
51 Revision 1.17.2.5  2000/10/06 16:49:46  cblume
52 Made Getters const
53
54 Revision 1.17.2.4  2000/10/04 16:34:57  cblume
55 Replace include files by forward declarations
56
57 Revision 1.17.2.3  2000/09/22 14:45:17  cblume
58 Included changes for the tracking
59
60 Revision 1.17.2.2  2000/09/18 13:25:13  cblume
61 Included LoadPoints() method to display the TR photons
62
63 Revision 1.22  2000/10/02 21:28:19  fca
64 Removal of useless dependecies via forward declarations
65
66 Revision 1.21  2000/06/09 11:10:07  cblume
67 Compiler warnings and coding conventions, next round
68
69 Revision 1.20  2000/06/08 18:32:57  cblume
70 Make code compliant to coding conventions
71
72 Revision 1.19  2000/06/07 16:25:37  cblume
73 Try to remove compiler warnings on Sun and HP
74
75 Revision 1.18  2000/05/08 16:17:27  cblume
76 Merge TRD-develop
77
78 Revision 1.21  2000/06/09 11:10:07  cblume
79 Compiler warnings and coding conventions, next round
80
81 Revision 1.20  2000/06/08 18:32:57  cblume
82 Make code compliant to coding conventions
83
84 Revision 1.19  2000/06/07 16:25:37  cblume
85 Try to remove compiler warnings on Sun and HP
86
87 Revision 1.18  2000/05/08 16:17:27  cblume
88 Merge TRD-develop
89
90 Revision 1.17.2.1  2000/05/08 14:28:59  cblume
91 Introduced SetPHOShole() and SetRICHhole(). AliTRDrecPoint container is now a TObjArray
92
93 Revision 1.17  2000/02/28 19:10:26  cblume
94 Include the new TRD classes
95
96 Revision 1.16.2.2  2000/02/28 17:53:24  cblume
97 Introduce TRD geometry classes
98
99 Revision 1.16.2.1  2000/02/28 17:04:19  cblume
100 Include functions and data members for AliTRDrecPoint
101
102 Revision 1.16  2000/01/19 17:17:35  fca
103 Introducing a list of lists of hits -- more hits allowed for detector now
104
105 Revision 1.15  1999/11/02 17:04:25  fca
106 Small syntax change for HP compiler
107
108 Revision 1.14  1999/11/02 16:57:02  fca
109 Avoid non ansi warnings on HP compilers
110
111 Revision 1.13  1999/11/02 16:35:56  fca
112 New version of TRD introduced
113
114 Revision 1.12  1999/11/01 20:41:51  fca
115 Added protections against using the wrong version of FRAME
116
117 Revision 1.11  1999/09/29 09:24:34  fca
118 Introduction of the Copyright and cvs Log
119
120 */
121
122 ///////////////////////////////////////////////////////////////////////////////
123 //                                                                           //
124 //  Transition Radiation Detector                                            //
125 //  This class contains the basic functions for the Transition Radiation     //
126 //  Detector.                                                                //
127 //                                                                           //
128 ///////////////////////////////////////////////////////////////////////////////
129
130 #include <stdlib.h>
131 #include <iostream.h>
132
133 #include <TMath.h>
134 #include <TNode.h>
135 #include <TGeometry.h>
136 #include <TTree.h>                                                              
137 #include <TPGON.h> 
138
139 #include "AliRun.h"
140 #include "AliConst.h"
141 #include "AliDigit.h"
142 #include "AliMagF.h"
143 #include "AliMC.h"                                                              
144  
145 #include "AliTRD.h"
146 #include "AliTRDhit.h"
147 #include "AliTRDpoints.h"
148 #include "AliTRDdigit.h"
149 #include "AliTRDdigitizer.h"
150 #include "AliTRDclusterizer.h"
151 #include "AliTRDgeometryHole.h"
152 #include "AliTRDgeometryFull.h"
153 #include "AliTRDrecPoint.h"
154 #include "AliTRDcluster.h"
155 #include "AliTRDdigitsManager.h"
156 #include "AliTRDdataArrayI.h"
157 #include "AliTRDsegmentArray.h"
158
159 ClassImp(AliTRD)
160  
161 //_____________________________________________________________________________
162 AliTRD::AliTRD()
163 {
164   //
165   // Default constructor
166   //
167
168   fIshunt        = 0;
169   fGasMix        = 0;
170   fHits          = 0;
171   fDigits        = 0;
172
173   fRecPoints     = 0;
174   fNRecPoints    = 0;
175
176   fGeometry      = 0;
177
178   fGasDensity    = 0;
179   fFoilDensity   = 0;
180
181   fDrawTR        = 0;
182   fDisplayType   = 0; 
183
184   fDigitsArray   = 0; 
185   for (Int_t iDict = 0; iDict < AliTRDdigitsManager::NDict(); iDict++) {
186     fDictionaryArray[iDict] = 0; 
187   }
188
189 }
190  
191 //_____________________________________________________________________________
192 AliTRD::AliTRD(const char *name, const char *title)
193        : AliDetector(name,title)
194 {
195   //
196   // Standard constructor for the TRD
197   //
198
199   // Check that FRAME is there otherwise we have no place where to
200   // put TRD
201   AliModule* frame = gAlice->GetModule("FRAME");
202   if (!frame) {
203     Error("Ctor","TRD needs FRAME to be present\n");
204     exit(1);
205   } 
206
207   // Define the TRD geometry according to the FRAME geometry
208   if      (frame->IsVersion() == 0) {
209     // Geometry with hole
210     fGeometry = new AliTRDgeometryHole();
211   }
212   else if (frame->IsVersion() == 1) {
213     // Geometry without hole
214     fGeometry = new AliTRDgeometryFull();
215   }
216   else {
217     Error("Ctor","Could not find valid FRAME version\n");
218     exit(1);
219   }
220
221   // Allocate the hit array
222   fHits           = new TClonesArray("AliTRDhit"     ,405);
223   gAlice->AddHitList(fHits);
224
225   // Allocate the digits array
226   fDigits         = 0;
227
228   // Allocate the rec point array
229   fRecPoints     = new TObjArray(400);
230   fNRecPoints    = 0;
231    
232   fIshunt        = 0;
233   fGasMix        = 1;
234
235   fGasDensity    = 0;
236   fFoilDensity   = 0;
237
238   fDrawTR        = 0;
239   fDisplayType   = 0;
240
241   fDigitsArray   = 0; 
242   for (Int_t iDict = 0; iDict < AliTRDdigitsManager::NDict(); iDict++) {
243     fDictionaryArray[iDict] = 0; 
244   }
245
246   SetMarkerColor(kWhite);   
247
248 }
249
250 //_____________________________________________________________________________
251 AliTRD::AliTRD(const AliTRD &trd)
252 {
253   //
254   // Copy constructor
255   //
256
257   ((AliTRD &) trd).Copy(*this);
258
259 }
260
261 //_____________________________________________________________________________
262 AliTRD::~AliTRD()
263 {
264   //
265   // TRD destructor
266   //
267
268   fIshunt = 0;
269
270   delete fGeometry;
271   delete fHits;
272   delete fRecPoints;
273   if (fDigitsArray) delete fDigitsArray;
274   for (Int_t iDict = 0; iDict < AliTRDdigitsManager::NDict(); iDict++) {
275     if (fDictionaryArray[iDict]) delete fDictionaryArray[iDict];
276   }
277
278 }
279
280 //_____________________________________________________________________________
281 void AliTRD::AddCluster(Float_t *pos, Int_t *digits, Int_t det, Float_t amp
282                        , Int_t *tracks, Float_t sigmaY2, Int_t iType)
283 {
284   //
285   // Add a cluster for the TRD
286   //
287
288   Int_t   pla = fGeometry->GetPlane(det);
289   Int_t   cha = fGeometry->GetChamber(det);
290   Int_t   sec = fGeometry->GetSector(det);
291
292   Float_t padRow  = pos[0]; 
293   Float_t padCol  = pos[1]; 
294   Float_t row0    = fGeometry->GetRow0(pla,cha,sec);
295   Float_t col0    = fGeometry->GetCol0(pla);
296   Float_t rowSize = fGeometry->GetRowPadSize(pla,cha,sec);
297   Float_t colSize = fGeometry->GetColPadSize(pla);
298
299   AliTRDcluster *c = new AliTRDcluster();
300
301   c->SetDetector(det);
302   c->AddTrackIndex(tracks);
303
304   c->SetQ(amp);
305
306   c->SetLocalTimeBin(((Int_t) pos[2]));
307   c->SetY(- (col0 + padCol * colSize));
308   c->SetZ(   row0 + padRow * rowSize);
309   
310   c->SetSigmaY2((sigmaY2 + 1./12.) * colSize*colSize);   
311   c->SetSigmaZ2(rowSize * rowSize / 12.);
312
313   switch (iType) {
314   case 0:
315     c->Set2pad();
316     break;
317   case 1:
318     c->Set3pad();
319     break;
320   case 2:
321     c->Set4pad();
322     break;
323   case 3:
324     c->Set5pad();
325     break;
326   case 4:
327     c->SetLarge();
328     break;
329   };
330
331   fRecPoints->Add(c);
332
333 }
334
335 //_____________________________________________________________________________
336 void AliTRD::Hits2Digits()
337 {
338   //
339   // Create digits
340   //
341
342   AliTRDdigitizer *digitizer = new AliTRDdigitizer("TRDdigitizer"
343                                                   ,"TRD digitizer class");
344
345   // Set the parameter
346   digitizer->SetDiffusion();
347   digitizer->SetExB();
348   digitizer->SetEvent(gAlice->GetEvNumber());
349   // Initialization
350   digitizer->InitDetector();
351     
352   // Create the digits
353   digitizer->MakeDigits();
354   
355   // Write the digits into the input file
356   if (digitizer->Digits()->MakeBranch(fDigitsFile)) {
357
358     digitizer->WriteDigits();
359
360     // Save the digitizer class in the AliROOT 
361     digitizer->Write();
362
363   }
364
365 }
366
367 //_____________________________________________________________________________
368 void AliTRD::Hits2SDigits()
369 {
370   //
371   // Create summable digits
372   //
373
374   AliTRDdigitizer *digitizer = new AliTRDdigitizer("TRDdigitizer"
375                                                   ,"TRD digitizer class");
376
377   // For the summable digits
378   digitizer->SetSDigits(kTRUE);
379
380   // Set the parameter
381   digitizer->SetDiffusion();
382   digitizer->SetExB();
383   digitizer->SetEvent(gAlice->GetEvNumber());
384
385   // Initialization
386   digitizer->InitDetector();
387     
388   // Create the digits
389   digitizer->MakeDigits();
390   
391   // Write the digits into the input file
392   if (digitizer->Digits()->MakeBranch(fDigitsFile)) {
393
394     digitizer->WriteDigits();
395
396     // Save the digitizer class in the AliROOT 
397     digitizer->Write();
398
399   }
400
401 }
402
403 //_____________________________________________________________________________
404 void AliTRD::SDigits2Digits()
405 {
406   //
407   // Create final digits from summable digits
408   //
409
410 }
411
412 //_____________________________________________________________________________
413 void AliTRD::AddDigit(Int_t *digits, Int_t *amp)
414 {
415   //
416   // Add a digit for the TRD
417   //
418
419   TClonesArray &ldigits = *fDigits;
420   new(ldigits[fNdigits++]) AliTRDdigit(kFALSE,digits,amp);
421
422 }
423
424 //_____________________________________________________________________________
425 void AliTRD::AddHit(Int_t track, Int_t det, Float_t *hits, Int_t q)
426 {
427   //
428   // Add a hit for the TRD
429   //
430
431   TClonesArray &lhits = *fHits;
432   new(lhits[fNhits++]) AliTRDhit(fIshunt,track,det,hits,q);
433
434 }
435
436 //_____________________________________________________________________________
437 void AliTRD::BuildGeometry()
438 {
439   //
440   // Create the ROOT TNode geometry for the TRD
441   //
442
443   TNode *node, *top;
444   TPGON *pgon;
445
446   Float_t rmin, rmax;
447   Float_t zmax1, zmax2;
448
449   Int_t   iPlan;
450  
451   const Int_t kColorTRD = 46;
452   
453   // Find the top node alice
454   top = gAlice->GetGeometry()->GetNode("alice");
455   
456   if      (fDisplayType == 0) {
457
458     pgon = new TPGON("S_TRD","TRD","void",0,360,AliTRDgeometry::Nsect(),4);
459     rmin = AliTRDgeometry::Rmin();
460     rmax = AliTRDgeometry::Rmax();
461     pgon->DefineSection(0,-AliTRDgeometry::Zmax1(),rmax,rmax);
462     pgon->DefineSection(1,-AliTRDgeometry::Zmax2(),rmin,rmax);
463     pgon->DefineSection(2, AliTRDgeometry::Zmax2(),rmin,rmax);
464     pgon->DefineSection(3, AliTRDgeometry::Zmax1(),rmax,rmax);
465     top->cd();
466     node = new TNode("TRD","TRD","S_TRD",0,0,0,"");
467     node->SetLineColor(kColorTRD);
468     fNodes->Add(node);
469
470   }
471   else if (fDisplayType == 1) {
472
473     Char_t name[7];
474
475     Float_t slope = (AliTRDgeometry::Zmax1() - AliTRDgeometry::Zmax2())
476                   / (AliTRDgeometry::Rmax()  - AliTRDgeometry::Rmin());
477
478     rmin  = AliTRDgeometry::Rmin() + AliTRDgeometry::Ccframe()/2.
479                                    + AliTRDgeometry::DrZpos()
480                                    - AliTRDgeometry::DrThick()/2.;
481     rmax  = rmin + AliTRDgeometry::DrThick();
482
483     Float_t thickness = rmin - AliTRDgeometry::Rmin();
484     zmax2 = AliTRDgeometry::Zmax2() + slope * thickness;
485     zmax1 = zmax2 + slope * AliTRDgeometry::DrThick();
486
487     for (iPlan = 0; iPlan < AliTRDgeometry::Nplan(); iPlan++) {
488
489       sprintf(name,"S_TR1%d",iPlan);
490       pgon  = new TPGON(name,"TRD","void",0,360,AliTRDgeometry::Nsect(),4);
491       pgon->DefineSection(0,-zmax1,rmax,rmax);
492       pgon->DefineSection(1,-zmax2,rmin,rmax);
493       pgon->DefineSection(2, zmax2,rmin,rmax);
494       pgon->DefineSection(3, zmax1,rmax,rmax);
495       top->cd();
496       node = new TNode("TRD","TRD",name,0,0,0,"");
497       node->SetLineColor(kColorTRD);
498       fNodes->Add(node);
499
500       Float_t height = AliTRDgeometry::Cheight() + AliTRDgeometry::Cspace(); 
501       rmin  = rmin  + height;
502       rmax  = rmax  + height;
503       zmax1 = zmax1 + slope * height;
504       zmax2 = zmax2 + slope * height;
505
506     }
507
508     thickness += AliTRDgeometry::DrThick();
509     rmin  = AliTRDgeometry::Rmin() + thickness;
510     rmax  = rmin + AliTRDgeometry::AmThick();
511     zmax2 = AliTRDgeometry::Zmax2() + slope * thickness;
512     zmax1 = zmax2 + slope * AliTRDgeometry::AmThick();
513
514     for (iPlan = 0; iPlan < AliTRDgeometry::Nplan(); iPlan++) {
515
516       sprintf(name,"S_TR2%d",iPlan);
517       pgon  = new TPGON(name,"TRD","void",0,360,AliTRDgeometry::Nsect(),4);
518       pgon->DefineSection(0,-zmax1,rmax,rmax);
519       pgon->DefineSection(1,-zmax2,rmin,rmax);
520       pgon->DefineSection(2, zmax2,rmin,rmax);
521       pgon->DefineSection(3, zmax1,rmax,rmax);
522       top->cd();
523       node = new TNode("TRD","TRD",name,0,0,0,"");
524       node->SetLineColor(kColorTRD);
525       fNodes->Add(node);
526
527       Float_t height = AliTRDgeometry::Cheight() + AliTRDgeometry::Cspace(); 
528       rmin  = rmin  + height;
529       rmax  = rmax  + height;
530       zmax1 = zmax1 + slope * height;
531       zmax2 = zmax2 + slope * height;
532
533     }
534
535   }
536
537 }
538  
539 //_____________________________________________________________________________
540 void AliTRD::Copy(TObject &trd)
541 {
542   //
543   // Copy function
544   //
545
546   ((AliTRD &) trd).fGasMix      = fGasMix;
547   ((AliTRD &) trd).fGeometry    = fGeometry;       
548   ((AliTRD &) trd).fRecPoints   = fRecPoints;
549   ((AliTRD &) trd).fNRecPoints  = fNRecPoints;
550   ((AliTRD &) trd).fGasDensity  = fGasDensity;
551   ((AliTRD &) trd).fFoilDensity = fFoilDensity;
552   ((AliTRD &) trd).fDrawTR      = fDrawTR;
553   ((AliTRD &) trd).fDisplayType = fDisplayType;
554
555   //AliDetector::Copy(trd);
556
557 }
558
559 //_____________________________________________________________________________
560 void AliTRD::CreateGeometry()
561 {
562   //
563   // Creates the volumes for the TRD chambers
564   //
565
566   // Check that FRAME is there otherwise we have no place where to put the TRD
567   AliModule* frame = gAlice->GetModule("FRAME");
568   if (!frame) {
569     printf(" The TRD needs the FRAME to be defined first\n");
570     return;
571   }
572
573   fGeometry->CreateGeometry(fIdtmed->GetArray() - 1299);
574
575 }
576  
577 //_____________________________________________________________________________
578 void AliTRD::CreateMaterials()
579 {
580   //
581   // Create the materials for the TRD
582   // Origin Y.Foka
583   //
584
585   Int_t   isxfld = gAlice->Field()->Integ();
586   Float_t sxmgmx = gAlice->Field()->Max();
587   
588   // For polyethilene (CH2) 
589   Float_t ape[2] = { 12., 1. };
590   Float_t zpe[2] = {  6., 1. };
591   Float_t wpe[2] = {  1., 2. };
592   Float_t dpe    = 0.95;
593
594   // For mylar (C5H4O2) 
595   Float_t amy[3] = { 12., 1., 16. };
596   Float_t zmy[3] = {  6., 1.,  8. };
597   Float_t wmy[3] = {  5., 4.,  2. };
598   Float_t dmy    = 1.39;
599
600   // For CO2 
601   Float_t aco[2] = { 12., 16. };
602   Float_t zco[2] = {  6.,  8. };
603   Float_t wco[2] = {  1.,  2. };
604   Float_t dco    = 0.001977;
605
606   // For water
607   Float_t awa[2] = {  1., 16. };
608   Float_t zwa[2] = {  1.,  8. };
609   Float_t wwa[2] = {  2.,  1. };
610   Float_t dwa    = 1.0;
611
612   // For isobutane (C4H10)
613   Float_t ais[2] = { 12.,  1. };
614   Float_t zis[2] = {  6.,  1. };
615   Float_t wis[2] = {  4., 10. };
616   Float_t dis    = 0.00267;
617
618   // For plexiglas (C5H8O2)
619   Float_t apg[3] = { 12.011 ,  1.0    , 15.9994 };
620   Float_t zpg[3] = {  6.0   ,  1.0    ,  8.0    };
621   Float_t wpg[3] = {  5.0   ,  8.0    ,  2.0    };
622   Float_t dpg    = 1.18; 
623
624   // For Xe/CO2-gas-mixture 
625   // Xe-content of the Xe/CO2-mixture (85% / 15%) 
626   Float_t fxc    = .85;
627   // Xe-content of the Xe/Isobutane-mixture (97% / 3%) 
628   Float_t fxi    = .97;
629   Float_t dxe    = .005858;
630   
631   // General tracking parameter
632   Float_t tmaxfd = -10.;
633   Float_t stemax = -1e10;
634   Float_t deemax = -0.1;
635   Float_t epsil  =  1e-4;
636   Float_t stmin  = -0.001;
637   
638   Float_t absl, radl, d, buf[1];
639   Float_t agm[2], zgm[2], wgm[2];
640   Float_t dgm1, dgm2;
641   Int_t   nbuf;
642   
643   //////////////////////////////////////////////////////////////////////////
644   //     Define Materials 
645   //////////////////////////////////////////////////////////////////////////
646
647   AliMaterial( 1, "Al"   ,  26.98, 13.0, 2.7     ,     8.9 ,    37.2);
648   AliMaterial( 2, "Air"  ,  14.61,  7.3, 0.001205, 30420.0 , 67500.0);
649   AliMaterial( 4, "Xe"   , 131.29, 54.0, dxe     ,  1447.59,     0.0);
650   AliMaterial( 5, "Cu"   ,  63.54, 29.0, 8.96    ,     1.43,    14.8);
651   AliMaterial( 6, "C"    ,  12.01,  6.0, 2.265   ,    18.8 ,    74.4);
652   AliMaterial(12, "G10"  ,  20.00, 10.0, 1.7     ,    19.4 ,   999.0);
653   AliMaterial(15, "Sn"   , 118.71, 50.0, 7.31    ,     1.21,    14.8);
654   AliMaterial(16, "Si"   ,  28.09, 14.0, 2.33    ,     9.36,    37.2);
655   AliMaterial(17, "Epoxy",  17.75,  8.9, 1.8     ,    21.82,   999.0);
656
657   // Mixtures 
658   AliMixture(3, "Polyethilene",   ape, zpe, dpe, -2, wpe);
659   AliMixture(7, "Mylar",          amy, zmy, dmy, -3, wmy);
660   AliMixture(8, "CO2",            aco, zco, dco, -2, wco);
661   AliMixture(9, "Isobutane",      ais, zis, dis, -2, wis);
662   AliMixture(13,"Water",          awa, zwa, dwa, -2, wwa);
663   AliMixture(14,"Plexiglas",      apg, zpg, dpg, -3, wpg);
664
665   // Gas mixtures
666   Char_t namate[21];
667   // Xe/CO2-mixture
668   // Get properties of Xe 
669   gMC->Gfmate((*fIdmate)[4], namate, agm[0], zgm[0], d, radl, absl, buf, nbuf);
670   // Get properties of CO2 
671   gMC->Gfmate((*fIdmate)[8], namate, agm[1], zgm[1], d, radl, absl, buf, nbuf);
672   // Create gas mixture 
673   wgm[0] = fxc;
674   wgm[1] = 1. - fxc;
675   dgm1   = wgm[0] * dxe + wgm[1] * dco;
676   AliMixture(10, "Gas mixture 1", agm, zgm, dgm1,  2, wgm);
677   // Xe/Isobutane-mixture
678   // Get properties of Xe 
679   gMC->Gfmate((*fIdmate)[4], namate, agm[0], zgm[0], d, radl, absl, buf, nbuf);
680   // Get properties of Isobutane
681   gMC->Gfmate((*fIdmate)[9], namate, agm[1], zgm[1], d, radl, absl, buf, nbuf);
682   // Create gas mixture 
683   wgm[0] = fxi;
684   wgm[1] = 1. - fxi;
685   dgm2   = wgm[0] * dxe + wgm[1] * dis;
686   AliMixture(11, "Gas mixture 2", agm, zgm, dgm2,  2, wgm);
687  
688   //////////////////////////////////////////////////////////////////////////
689   //     Tracking Media Parameters 
690   //////////////////////////////////////////////////////////////////////////
691
692   // Al Frame 
693   AliMedium(1, "Al Frame",   1, 0, isxfld, sxmgmx
694                 , tmaxfd, stemax, deemax, epsil, stmin);
695   // Air 
696   AliMedium(2, "Air",        2, 0, isxfld, sxmgmx
697                 , tmaxfd, stemax, deemax, epsil, stmin);
698   // Polyethilene 
699   AliMedium(3, "Radiator",   3, 0, isxfld, sxmgmx
700                 , tmaxfd, stemax, deemax, epsil, stmin);
701   // Xe 
702   AliMedium(4, "Xe",         4, 1, isxfld, sxmgmx
703                 , tmaxfd, stemax, deemax, epsil, stmin);
704   // Cu pads 
705   AliMedium(5, "Padplane",   5, 1, isxfld, sxmgmx
706                 , tmaxfd, stemax, deemax, epsil, stmin);
707   // Fee + cables 
708   AliMedium(6, "Readout",    1, 0, isxfld, sxmgmx
709                 , tmaxfd, stemax, deemax, epsil, stmin);
710   // C frame 
711   AliMedium(7, "C Frame",    6, 0, isxfld, sxmgmx
712                 , tmaxfd, stemax, deemax, epsil, stmin);
713   // Mylar foils 
714   AliMedium(8, "Mylar",      7, 0, isxfld, sxmgmx
715                 , tmaxfd, stemax, deemax, epsil, stmin);
716   if (fGasMix == 1) {
717     // Gas-mixture (Xe/CO2) 
718     AliMedium(9, "Gas-mix",   10, 1, isxfld, sxmgmx
719                   , tmaxfd, stemax, deemax, epsil, stmin);
720   }
721   else {
722     // Gas-mixture (Xe/Isobutane) 
723     AliMedium(9, "Gas-mix",   11, 1, isxfld, sxmgmx
724                   , tmaxfd, stemax, deemax, epsil, stmin);
725   }
726   // Nomex-honeycomb (use carbon for the time being) 
727   AliMedium(10, "Nomex",      6, 0, isxfld, sxmgmx
728                 , tmaxfd, stemax, deemax, epsil, stmin);
729   // Kapton foils (use Mylar for the time being) 
730   AliMedium(11, "Kapton",     7, 0, isxfld, sxmgmx
731                 , tmaxfd, stemax, deemax, epsil, stmin);
732   // Gas-filling of the radiator 
733   AliMedium(12, "CO2",        8, 0, isxfld, sxmgmx
734                 , tmaxfd, stemax, deemax, epsil, stmin);
735   // G10-plates
736   AliMedium(13, "G10-plates",12, 0, isxfld, sxmgmx
737                 , tmaxfd, stemax, deemax, epsil, stmin);
738   // Cooling water
739   AliMedium(14, "Water",     13, 0, isxfld, sxmgmx
740                 , tmaxfd, stemax, deemax, epsil, stmin);
741   // Rohacell (plexiglas) for the radiator
742   AliMedium(15, "Rohacell",  14, 0, isxfld, sxmgmx
743                 , tmaxfd, stemax, deemax, epsil, stmin);
744   // Al layer in MCMs
745   AliMedium(16, "MCM-Al"  ,   1, 0, isxfld, sxmgmx
746                 , tmaxfd, stemax, deemax, epsil, stmin);
747   // Sn layer in MCMs
748   AliMedium(17, "MCM-Sn"  ,  15, 0, isxfld, sxmgmx
749                 , tmaxfd, stemax, deemax, epsil, stmin);
750   // Cu layer in MCMs
751   AliMedium(18, "MCM-Cu"  ,   5, 0, isxfld, sxmgmx
752                 , tmaxfd, stemax, deemax, epsil, stmin);
753   // G10 layer in MCMs
754   AliMedium(19, "MCM-G10" ,  12, 0, isxfld, sxmgmx
755                 , tmaxfd, stemax, deemax, epsil, stmin);
756   // Si in readout chips
757   AliMedium(20, "Chip-Si" ,  16, 0, isxfld, sxmgmx
758                 , tmaxfd, stemax, deemax, epsil, stmin);
759   // Epoxy in readout chips
760   AliMedium(21, "Chip-Ep" ,  17, 0, isxfld, sxmgmx
761                 , tmaxfd, stemax, deemax, epsil, stmin);
762   // PE in connectors
763   AliMedium(22, "Conn-PE" ,   3, 0, isxfld, sxmgmx
764                 , tmaxfd, stemax, deemax, epsil, stmin);
765   // Cu in connectors
766   AliMedium(23, "Chip-Cu" ,   5, 0, isxfld, sxmgmx
767                 , tmaxfd, stemax, deemax, epsil, stmin);
768   // Al of cooling pipes
769   AliMedium(24, "Cooling" ,   1, 0, isxfld, sxmgmx
770                 , tmaxfd, stemax, deemax, epsil, stmin);
771
772   // Save the density values for the TRD absorbtion
773   fFoilDensity = dmy;
774   if (fGasMix == 1)
775     fGasDensity = dgm1;
776   else
777     fGasDensity = dgm2;
778
779 }
780
781 //_____________________________________________________________________________
782 void AliTRD::DrawModule()
783 {
784   //
785   // Draw a shaded view of the Transition Radiation Detector version 0
786   //
787
788   // Set everything unseen
789   gMC->Gsatt("*"   ,"SEEN",-1);
790   
791   // Set ALIC mother transparent
792   gMC->Gsatt("ALIC","SEEN", 0);
793   
794   // Set the volumes visible
795   if (fGeometry->IsVersion() == 0) {
796     gMC->Gsatt("B071","SEEN", 0);
797     gMC->Gsatt("B074","SEEN", 0);
798     gMC->Gsatt("B075","SEEN", 0);
799     gMC->Gsatt("B077","SEEN", 0);
800     gMC->Gsatt("BTR1","SEEN", 0);
801     gMC->Gsatt("BTR2","SEEN", 0);
802     gMC->Gsatt("BTR3","SEEN", 0);
803     gMC->Gsatt("TRD1","SEEN", 0);
804     gMC->Gsatt("TRD2","SEEN", 0);
805     gMC->Gsatt("TRD3","SEEN", 0);
806   }
807   else {
808     gMC->Gsatt("B071","SEEN", 0);
809     gMC->Gsatt("B074","SEEN", 0);
810     gMC->Gsatt("B075","SEEN", 0);
811     gMC->Gsatt("B077","SEEN", 0);
812     gMC->Gsatt("BTR1","SEEN", 0);
813     gMC->Gsatt("BTR2","SEEN", 0);
814     gMC->Gsatt("BTR3","SEEN", 0);
815     gMC->Gsatt("TRD1","SEEN", 0);
816     if (fGeometry->GetPHOShole())
817       gMC->Gsatt("TRD2","SEEN", 0);
818     if (fGeometry->GetRICHhole())
819       gMC->Gsatt("TRD3","SEEN", 0);
820   }
821   gMC->Gsatt("UCII","SEEN", 0);
822   gMC->Gsatt("UCIM","SEEN", 0);
823   gMC->Gsatt("UCIO","SEEN", 0);
824   gMC->Gsatt("UL02","SEEN", 1);
825   gMC->Gsatt("UL05","SEEN", 1);
826   gMC->Gsatt("UL06","SEEN", 1);
827   
828   gMC->Gdopt("hide", "on");
829   gMC->Gdopt("shad", "on");
830   gMC->Gsatt("*", "fill", 7);
831   gMC->SetClipBox(".");
832   gMC->SetClipBox("*", 0, 2000, -2000, 2000, -2000, 2000);
833   gMC->DefaultRange();
834   gMC->Gdraw("alic", 40, 30, 0, 12, 9.4, .021, .021);
835   gMC->Gdhead(1111, "Transition Radiation Detector");
836   gMC->Gdman(18, 4, "MAN");
837
838 }
839
840 //_____________________________________________________________________________
841 Int_t AliTRD::DistancetoPrimitive(Int_t , Int_t )
842 {
843   //
844   // Distance between the mouse and the TRD detector on the screen
845   // Dummy routine
846   
847   return 9999;
848
849 }
850  
851 //_____________________________________________________________________________
852 void AliTRD::Init()
853 {
854   //
855   // Initialize the TRD detector after the geometry has been created
856   //
857
858   Int_t i;
859
860   if(fDebug) {
861     printf("\n%s: ",ClassName());
862     for (i = 0; i < 35; i++) printf("*");
863     printf(" TRD_INIT ");
864     for (i = 0; i < 35; i++) printf("*");
865     printf("\n");
866   }
867
868   if      (fGeometry->IsVersion() == 0) {
869     printf("%s: Geometry for spaceframe with holes initialized\n",ClassName());
870   }
871   else if (fGeometry->IsVersion() == 1) {
872     printf("%s: Geometry for spaceframe without holes initialized\n",ClassName());
873     if (fGeometry->GetPHOShole())
874       printf("%s: Leave space in front of PHOS free\n",ClassName());
875     if (fGeometry->GetRICHhole())
876       printf("%s: Leave space in front of RICH free\n",ClassName());
877   }
878   
879   if (fGasMix == 1)
880     printf("%s: Gas Mixture: 85%% Xe + 15%% CO2\n",ClassName());
881   else
882     printf("%s: Gas Mixture: 97%% Xe + 3%% Isobutane\n",ClassName());
883
884 }
885
886 //_____________________________________________________________________________
887 void AliTRD::LoadPoints(Int_t track)
888 {
889   //
890   // Store x, y, z of all hits in memory.
891   // Hit originating from TR photons are given a different color
892   //
893
894   if (!fDrawTR) {
895     AliDetector::LoadPoints(track);
896     return;
897   }
898
899   if (fHits == 0) return;
900
901   Int_t nhits  = fHits->GetEntriesFast();
902   if (nhits == 0) return;
903
904   Int_t tracks = gAlice->GetNtrack();
905   if (fPoints == 0) fPoints = new TObjArray(tracks);
906
907   AliTRDhit *ahit;
908   
909   Int_t    *ntrkE = new Int_t[tracks];
910   Int_t    *ntrkT = new Int_t[tracks];
911   Int_t    *limiE = new Int_t[tracks];
912   Int_t    *limiT = new Int_t[tracks];
913   Float_t **coorE = new Float_t*[tracks];
914   Float_t **coorT = new Float_t*[tracks];
915   for(Int_t i = 0; i < tracks; i++) {
916     ntrkE[i] = 0;
917     ntrkT[i] = 0;
918     coorE[i] = 0;
919     coorT[i] = 0;
920     limiE[i] = 0;
921     limiT[i] = 0;
922   }
923   
924   AliTRDpoints  *points = 0;
925   Float_t       *fp     = 0;
926   Int_t          trk;
927   Int_t          chunk  = nhits / 4 + 1;
928
929   // Loop over all the hits and store their position
930   for (Int_t hit = 0; hit < nhits; hit++) {
931
932     ahit = (AliTRDhit *) fHits->UncheckedAt(hit);
933
934     // dEdx hits
935     if (ahit->FromDrift() || ahit->FromAmplification()) {
936
937       trk = ahit->GetTrack();
938       if (ntrkE[trk] == limiE[trk]) {
939         // Initialise a new track
940         fp = new Float_t[3*(limiE[trk]+chunk)];
941         if (coorE[trk]) {
942           memcpy(fp,coorE[trk],sizeof(Float_t)*3*limiE[trk]);
943           delete [] coorE[trk];
944         }
945         limiE[trk] += chunk;
946         coorE[trk]  = fp;
947       } 
948       else {
949         fp = coorE[trk];
950       }
951       fp[3*ntrkE[trk]  ] = ahit->X();
952       fp[3*ntrkE[trk]+1] = ahit->Y();
953       fp[3*ntrkE[trk]+2] = ahit->Z();
954       ntrkE[trk]++;
955
956     }
957     // TR photon hits
958     else if (ahit->FromTRphoton()) {
959
960       trk = ahit->GetTrack();
961       if (ntrkT[trk] == limiT[trk]) {
962         // Initialise a new track
963         fp = new Float_t[3*(limiT[trk]+chunk)];
964         if (coorT[trk]) {
965           memcpy(fp,coorT[trk],sizeof(Float_t)*3*limiT[trk]);
966           delete [] coorT[trk];
967         }
968         limiT[trk] += chunk;
969         coorT[trk]  = fp;
970       } 
971       else {
972         fp = coorT[trk];
973       }
974       fp[3*ntrkT[trk]  ] = ahit->X();
975       fp[3*ntrkT[trk]+1] = ahit->Y();
976       fp[3*ntrkT[trk]+2] = ahit->Z();
977       ntrkT[trk]++;
978
979     }
980
981   }
982
983   for (trk = 0; trk < tracks; ++trk) {
984
985     if (ntrkE[trk] || ntrkT[trk]) {
986
987       points = new AliTRDpoints();
988       points->SetDetector(this);
989       points->SetParticle(trk);
990
991       // Set the dEdx points
992       if (ntrkE[trk]) {
993         points->SetMarkerColor(GetMarkerColor());
994         points->SetMarkerSize(GetMarkerSize());
995         points->SetPolyMarker(ntrkE[trk],coorE[trk],GetMarkerStyle());
996         delete [] coorE[trk];
997         coorE[trk] = 0;
998       }
999
1000       // Set the TR photon points
1001       if (ntrkT[trk]) {
1002         points->SetTRpoints(ntrkT[trk],coorT[trk]);
1003         delete [] coorT[trk];
1004         coorT[trk] = 0;
1005       }
1006
1007       fPoints->AddAt(points,trk);
1008
1009     }
1010
1011   }
1012
1013   delete [] coorE;
1014   delete [] coorT;
1015   delete [] ntrkE;
1016   delete [] ntrkT;
1017   delete [] limiE;
1018   delete [] limiT;
1019
1020 }
1021
1022 //_____________________________________________________________________________
1023 void AliTRD::MakeBranch(Option_t* option, const char *file)
1024 {
1025   //
1026   // Create Tree branches for the TRD digits and cluster.
1027   //
1028
1029   //Int_t  buffersize = 4000;
1030   //Char_t branchname[15];
1031
1032   const char *cD = strstr(option,"D");
1033
1034   AliDetector::MakeBranch(option,file);
1035
1036   Int_t buffersize = 64000;
1037
1038   if (cD) {
1039     fDigitsArray = new AliTRDdataArrayI();
1040     MakeBranchInTree(gAlice->TreeD() 
1041                    ,"TRDdigits", fDigitsArray->IsA()->GetName()
1042                    ,&fDigitsArray,buffersize,99,file);
1043
1044     for (Int_t iDict = 0; iDict < AliTRDdigitsManager::NDict(); iDict++) {
1045       Char_t branchname[15];
1046       sprintf(branchname,"TRDdictionary%d",iDict);
1047       fDictionaryArray[iDict] = new AliTRDdataArrayI();
1048       MakeBranchInTree(gAlice->TreeD() 
1049                        ,branchname,fDictionaryArray[iDict]->IsA()->GetName()
1050                        ,&fDictionaryArray[iDict],buffersize,99,file);
1051     }
1052   }
1053 }
1054
1055 //_____________________________________________________________________________
1056 void AliTRD::ResetDigits()
1057 {
1058   //
1059   // Resets the digits
1060   //
1061
1062   if (gAlice->TreeD()) {
1063     TBranch *branch;
1064     branch = gAlice->TreeD()->GetBranch("TRDdigits");
1065     if (branch) {
1066       branch->Reset();
1067       for (Int_t iDict = 0; iDict < AliTRDdigitsManager::NDict(); iDict++) {
1068         Char_t branchname[15];
1069         sprintf(branchname,"TRDdictionary%d",iDict);
1070         branch = gAlice->TreeD()->GetBranch(branchname);
1071         branch->Reset();
1072       }
1073     }
1074   }
1075
1076 }
1077
1078 //_____________________________________________________________________________
1079 void AliTRD::ResetRecPoints()
1080 {
1081   //
1082   // Reset number of reconstructed points and the point array
1083   //
1084
1085   if (fRecPoints) {
1086     fNRecPoints = 0;
1087     Int_t nentr = fRecPoints->GetEntriesFast();
1088     for (Int_t i = 0; i < nentr; i++) delete fRecPoints->RemoveAt(i);
1089   }
1090
1091 }
1092
1093 //_____________________________________________________________________________
1094 void AliTRD::SetTreeAddress()
1095 {
1096   //
1097   // Set the branch addresses for the trees.
1098   //
1099
1100   Char_t branchname[15];
1101
1102   AliDetector::SetTreeAddress();
1103
1104   TBranch *branch;
1105   TTree   *treeR = gAlice->TreeR();
1106
1107   if (treeR) {
1108     sprintf(branchname,"%scluster",GetName());
1109     if (fRecPoints) {
1110       branch = treeR->GetBranch(branchname);
1111       if (branch) {
1112         branch->SetAddress(&fRecPoints);
1113       }
1114     }
1115   }
1116
1117 }
1118
1119 //_____________________________________________________________________________
1120 void AliTRD::SetGasMix(Int_t imix)
1121 {
1122   //
1123   // Defines the gas mixture (imix=0:  Xe/Isobutane imix=1: Xe/CO2)
1124   //
1125   
1126   if ((imix < 0) || (imix > 1)) {
1127     printf("Wrong input value: %d\n",imix);
1128     printf("Use standard setting\n");
1129     fGasMix = 1;
1130     return;
1131   }
1132
1133   fGasMix = imix;
1134
1135 }
1136
1137 //_____________________________________________________________________________
1138 void AliTRD::SetPHOShole()
1139 {
1140   //
1141   // Selects a geometry with a hole in front of the PHOS
1142   //
1143
1144   fGeometry->SetPHOShole();
1145
1146 }
1147
1148 //_____________________________________________________________________________
1149 void AliTRD::SetRICHhole()
1150 {
1151   //
1152   // Selects a geometry with a hole in front of the RICH
1153   //
1154
1155   fGeometry->SetRICHhole();
1156
1157 }
1158
1159 //_____________________________________________________________________________
1160 AliTRD &AliTRD::operator=(const AliTRD &trd)
1161 {
1162   //
1163   // Assignment operator
1164   //
1165
1166   if (this != &trd) ((AliTRD &) trd).Copy(*this);
1167   return *this;
1168
1169