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