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