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