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