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