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