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