]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDv1.cxx
Major upgrades to the strip structure
[u/mrichter/AliRoot.git] / TRD / AliTRDv1.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.26  2000/11/30 17:38:08  cblume
19 Changes to get in line with new STEER and EVGEN
20
21 Revision 1.25  2000/11/15 14:30:16  cblume
22 Fixed bug in calculating detector no. of extra hit
23
24 Revision 1.24  2000/11/10 14:58:36  cblume
25 Introduce additional hit with amplitude 0 at the chamber borders
26
27 Revision 1.23  2000/11/01 14:53:21  cblume
28 Merge with TRD-develop
29
30 Revision 1.17.2.5  2000/10/15 23:40:01  cblume
31 Remove AliTRDconst
32
33 Revision 1.17.2.4  2000/10/06 16:49:46  cblume
34 Made Getters const
35
36 Revision 1.17.2.3  2000/10/04 16:34:58  cblume
37 Replace include files by forward declarations
38
39 Revision 1.17.2.2  2000/09/18 13:50:17  cblume
40 Include TR photon generation and adapt to new AliTRDhit
41
42 Revision 1.22  2000/06/27 13:08:50  cblume
43 Changed to Copy(TObject &A) to appease the HP-compiler
44
45 Revision 1.21  2000/06/09 11:10:07  cblume
46 Compiler warnings and coding conventions, next round
47
48 Revision 1.20  2000/06/08 18:32:58  cblume
49 Make code compliant to coding conventions
50
51 Revision 1.19  2000/06/07 16:27:32  cblume
52 Try to remove compiler warnings on Sun and HP
53
54 Revision 1.18  2000/05/08 16:17:27  cblume
55 Merge TRD-develop
56
57 Revision 1.17.2.1  2000/05/08 14:59:16  cblume
58 Made inline function non-virtual. Bug fix in setting sensitive chamber
59
60 Revision 1.17  2000/02/28 19:10:26  cblume
61 Include the new TRD classes
62
63 Revision 1.16.4.1  2000/02/28 18:04:35  cblume
64 Change to new hit version, introduce geometry class, and move digitization and clustering to AliTRDdigitizer/AliTRDclusterizerV1
65
66 Revision 1.16  1999/11/05 22:50:28  fca
67 Do not use Atan, removed from ROOT too
68
69 Revision 1.15  1999/11/02 17:20:19  fca
70 initialise nbytes before using it
71
72 Revision 1.14  1999/11/02 17:15:54  fca
73 Correct ansi scoping not accepted by HP compilers
74
75 Revision 1.13  1999/11/02 17:14:51  fca
76 Correct ansi scoping not accepted by HP compilers
77
78 Revision 1.12  1999/11/02 16:35:56  fca
79 New version of TRD introduced
80
81 Revision 1.11  1999/11/01 20:41:51  fca
82 Added protections against using the wrong version of FRAME
83
84 Revision 1.10  1999/09/29 09:24:35  fca
85 Introduction of the Copyright and cvs Log
86
87 */
88
89 ///////////////////////////////////////////////////////////////////////////////
90 //                                                                           //
91 //  Transition Radiation Detector version 1 -- slow simulator                //
92 //                                                                           //
93 //Begin_Html
94 /*
95 <img src="picts/AliTRDfullClass.gif">
96 */
97 //End_Html
98 //                                                                           //
99 //                                                                           //
100 ///////////////////////////////////////////////////////////////////////////////
101
102 #include <stdlib.h> 
103
104 #include <TMath.h>
105 #include <TVector.h>
106 #include <TRandom.h>
107 #include <TF1.h>
108 #include <TLorentzVector.h>
109
110 #include "AliRun.h"
111 #include "AliMC.h"
112 #include "AliConst.h"
113
114 #include "AliTRDv1.h"
115 #include "AliTRDhit.h"
116 #include "AliTRDmatrix.h"
117 #include "AliTRDgeometry.h"
118 #include "AliTRDsim.h"
119
120 ClassImp(AliTRDv1)
121  
122 //_____________________________________________________________________________
123 AliTRDv1::AliTRDv1():AliTRD()
124 {
125   //
126   // Default constructor
127   //
128
129   fIdSens          =  0;
130
131   fIdChamber1      =  0;
132   fIdChamber2      =  0;
133   fIdChamber3      =  0;
134
135   fSensSelect      =  0;
136   fSensPlane       = -1;
137   fSensChamber     = -1;
138   fSensSector      = -1;
139   fSensSectorRange =  0;
140
141   fDeltaE          = NULL;
142   fTR              = NULL;
143
144 }
145
146 //_____________________________________________________________________________
147 AliTRDv1::AliTRDv1(const char *name, const char *title) 
148          :AliTRD(name, title) 
149 {
150   //
151   // Standard constructor for Transition Radiation Detector version 1
152   //
153
154   fIdSens          =  0;
155
156   fIdChamber1      =  0;
157   fIdChamber2      =  0;
158   fIdChamber3      =  0;
159
160   fSensSelect      =  0;
161   fSensPlane       = -1;
162   fSensChamber     = -1;
163   fSensSector      = -1;
164   fSensSectorRange =  0;
165
166   fDeltaE          = NULL;
167   fTR              = NULL;
168
169   SetBufferSize(128000);
170
171 }
172
173 //_____________________________________________________________________________
174 AliTRDv1::AliTRDv1(const AliTRDv1 &trd)
175 {
176   //
177   // Copy constructor
178   //
179
180   ((AliTRDv1 &) trd).Copy(*this);
181
182 }
183
184 //_____________________________________________________________________________
185 AliTRDv1::~AliTRDv1()
186 {
187   //
188   // AliTRDv1 destructor
189   //
190
191   if (fDeltaE) delete fDeltaE;
192   if (fTR)     delete fTR;
193
194 }
195  
196 //_____________________________________________________________________________
197 AliTRDv1 &AliTRDv1::operator=(const AliTRDv1 &trd)
198 {
199   //
200   // Assignment operator
201   //
202
203   if (this != &trd) ((AliTRDv1 &) trd).Copy(*this);
204   return *this;
205
206 }
207  
208 //_____________________________________________________________________________
209 void AliTRDv1::Copy(TObject &trd)
210 {
211   //
212   // Copy function
213   //
214
215   ((AliTRDv1 &) trd).fIdSens          = fIdSens;
216
217   ((AliTRDv1 &) trd).fIdChamber1      = fIdChamber1;
218   ((AliTRDv1 &) trd).fIdChamber2      = fIdChamber2;
219   ((AliTRDv1 &) trd).fIdChamber3      = fIdChamber3;
220
221   ((AliTRDv1 &) trd).fSensSelect      = fSensSelect;
222   ((AliTRDv1 &) trd).fSensPlane       = fSensPlane;
223   ((AliTRDv1 &) trd).fSensChamber     = fSensChamber;
224   ((AliTRDv1 &) trd).fSensSector      = fSensSector;
225   ((AliTRDv1 &) trd).fSensSectorRange = fSensSectorRange;
226
227   fDeltaE->Copy(*((AliTRDv1 &) trd).fDeltaE);
228   fTR->Copy(*((AliTRDv1 &) trd).fTR);
229
230 }
231
232 //_____________________________________________________________________________
233 void AliTRDv1::CreateGeometry()
234 {
235   //
236   // Create the GEANT geometry for the Transition Radiation Detector - Version 1
237   // This version covers the full azimuth. 
238   //
239
240   // Check that FRAME is there otherwise we have no place where to put the TRD
241   AliModule* frame = gAlice->GetModule("FRAME");
242   if (!frame) return;
243
244   // Define the chambers
245   AliTRD::CreateGeometry();
246
247 }
248
249 //_____________________________________________________________________________
250 void AliTRDv1::CreateMaterials()
251 {
252   //
253   // Create materials for the Transition Radiation Detector version 1
254   //
255
256   AliTRD::CreateMaterials();
257
258 }
259
260 //_____________________________________________________________________________
261 void AliTRDv1::CreateTRhit(Int_t det)
262 {
263   //
264   // Creates an electron cluster from a TR photon.
265   // The photon is assumed to be created a the end of the radiator. The 
266   // distance after which it deposits its energy takes into account the 
267   // absorbtion of the entrance window and of the gas mixture in drift
268   // volume.
269   //
270
271   // PDG code electron
272   const Int_t   kPdgElectron = 11;
273
274   // Ionization energy
275   const Float_t kWion        = 22.04;
276
277   // Maximum number of TR photons per track
278   const Int_t   kNTR         = 50;
279
280   TLorentzVector mom, pos;
281   TClonesArray  &lhits = *fHits;
282
283   // Create TR only for electrons 
284   Int_t iPdg = gMC->TrackPid();
285   if (TMath::Abs(iPdg) != kPdgElectron) return;
286
287   // Create TR at the entrance of the chamber
288   if (gMC->IsTrackEntering()) {
289
290     Float_t eTR[kNTR];
291     Int_t   nTR;
292
293     // Create TR photons
294     gMC->TrackMomentum(mom);
295     Float_t pTot = mom.Rho();
296     fTR->CreatePhotons(iPdg,pTot,nTR,eTR);
297     if (nTR > kNTR) {
298       printf("AliTRDv1::CreateTRhit -- ");
299       printf("Boundary error: nTR = %d, kNTR = %d\n",nTR,kNTR);
300       exit(1);
301     }
302
303     // Loop through the TR photons
304     for (Int_t iTR = 0; iTR < nTR; iTR++) {
305
306       Float_t energyMeV = eTR[iTR] * 0.001;
307       Float_t energyeV  = eTR[iTR] * 1000.0;
308       Float_t absLength = 0;
309       Float_t sigma     = 0;
310
311       // Take the absorbtion in the entrance window into account
312       Double_t muMy = fTR->GetMuMy(energyMeV);
313       sigma = muMy * fFoilDensity;
314       absLength = gRandom->Exp(sigma);
315       if (absLength < AliTRDgeometry::MyThick()) continue;
316
317       // The absorbtion cross sections in the drift gas
318       if (fGasMix == 1) {
319         // Gas-mixture (Xe/CO2)
320         Double_t muXe = fTR->GetMuXe(energyMeV);
321         Double_t muCO = fTR->GetMuCO(energyMeV);
322         sigma = (0.90 * muXe + 0.10 * muCO) * fGasDensity;
323       }
324       else {
325         // Gas-mixture (Xe/Isobutane) 
326         Double_t muXe = fTR->GetMuXe(energyMeV);
327         Double_t muBu = fTR->GetMuBu(energyMeV);
328         sigma = (0.97 * muXe + 0.03 * muBu) * fGasDensity;
329       }
330
331       // The distance after which the energy of the TR photon
332       // is deposited.
333       absLength = gRandom->Exp(sigma);
334       if (absLength > AliTRDgeometry::DrThick()) continue;
335
336       // The position of the absorbtion
337       Float_t posHit[3];
338       gMC->TrackPosition(pos);
339       posHit[0] = pos[0] + mom[0] / pTot * absLength;
340       posHit[1] = pos[1] + mom[1] / pTot * absLength;
341       posHit[2] = pos[2] + mom[2] / pTot * absLength;      
342
343       // Create the charge 
344       Int_t q = ((Int_t) (energyeV / kWion));
345
346       // Add the hit to the array. TR photon hits are marked 
347       // by negative charge
348       new(lhits[fNhits++]) AliTRDhit(fIshunt,gAlice->CurrentTrack()
349                                     ,det,posHit,-q);
350
351     }
352
353   }
354
355 }
356
357 //_____________________________________________________________________________
358 void AliTRDv1::Init() 
359 {
360   //
361   // Initialise Transition Radiation Detector after geometry has been built.
362   //
363
364   AliTRD::Init();
365
366   printf("          Slow simulator\n\n");
367   if (fSensSelect) {
368     if (fSensPlane   >= 0)
369       printf("          Only plane %d is sensitive\n",fSensPlane);
370     if (fSensChamber >= 0)   
371       printf("          Only chamber %d is sensitive\n",fSensChamber);
372     if (fSensSector  >= 0) {
373       Int_t sens1  = fSensSector;
374       Int_t sens2  = fSensSector + fSensSectorRange;
375             sens2 -= ((Int_t) (sens2 / AliTRDgeometry::Nsect())) 
376                    * AliTRDgeometry::Nsect();
377       printf("          Only sectors %d - %d are sensitive\n",sens1,sens2-1);
378     }
379   }
380   if (fTR) 
381     printf("          TR simulation on\n");
382   else
383     printf("          TR simulation off\n");
384   printf("\n");
385
386   // First ionization potential (eV) for the gas mixture (90% Xe + 10% CO2)
387   const Float_t kPoti = 12.1;
388   // Maximum energy (50 keV);
389   const Float_t kEend = 50000.0;
390   // Ermilova distribution for the delta-ray spectrum
391   Float_t poti = TMath::Log(kPoti);
392   Float_t eEnd = TMath::Log(kEend);
393   fDeltaE = new TF1("deltae",Ermilova,poti,eEnd,0);
394
395   // Identifier of the sensitive volume (drift region)
396   fIdSens     = gMC->VolId("UL05");
397
398   // Identifier of the TRD-driftchambers
399   fIdChamber1 = gMC->VolId("UCIO");
400   fIdChamber2 = gMC->VolId("UCIM");
401   fIdChamber3 = gMC->VolId("UCII");
402
403   for (Int_t i = 0; i < 80; i++) printf("*");
404   printf("\n");
405
406 }
407
408 //_____________________________________________________________________________
409 AliTRDsim *AliTRDv1::CreateTR()
410 {
411   //
412   // Enables the simulation of TR
413   //
414
415   fTR = new AliTRDsim();
416   return fTR;
417
418 }
419
420 //_____________________________________________________________________________
421 void AliTRDv1::SetSensPlane(Int_t iplane)
422 {
423   //
424   // Defines the hit-sensitive plane (0-5)
425   //
426
427   if ((iplane < 0) || (iplane > 5)) {
428     printf("Wrong input value: %d\n",iplane);
429     printf("Use standard setting\n");
430     fSensPlane  = -1;
431     fSensSelect =  0;
432     return;
433   }
434
435   fSensSelect = 1;
436   fSensPlane  = iplane;
437
438 }
439
440 //_____________________________________________________________________________
441 void AliTRDv1::SetSensChamber(Int_t ichamber)
442 {
443   //
444   // Defines the hit-sensitive chamber (0-4)
445   //
446
447   if ((ichamber < 0) || (ichamber > 4)) {
448     printf("Wrong input value: %d\n",ichamber);
449     printf("Use standard setting\n");
450     fSensChamber = -1;
451     fSensSelect  =  0;
452     return;
453   }
454
455   fSensSelect  = 1;
456   fSensChamber = ichamber;
457
458 }
459
460 //_____________________________________________________________________________
461 void AliTRDv1::SetSensSector(Int_t isector)
462 {
463   //
464   // Defines the hit-sensitive sector (0-17)
465   //
466
467   SetSensSector(isector,1);
468
469 }
470
471 //_____________________________________________________________________________
472 void AliTRDv1::SetSensSector(Int_t isector, Int_t nsector)
473 {
474   //
475   // Defines a range of hit-sensitive sectors. The range is defined by
476   // <isector> (0-17) as the starting point and <nsector> as the number 
477   // of sectors to be included.
478   //
479
480   if ((isector < 0) || (isector > 17)) {
481     printf("Wrong input value <isector>: %d\n",isector);
482     printf("Use standard setting\n");
483     fSensSector      = -1;
484     fSensSectorRange =  0;
485     fSensSelect      =  0;
486     return;
487   }
488
489   if ((nsector < 1) || (nsector > 18)) {
490     printf("Wrong input value <nsector>: %d\n",nsector);
491     printf("Use standard setting\n");
492     fSensSector      = -1;
493     fSensSectorRange =  0;
494     fSensSelect      =  0;
495     return;
496   }
497
498   fSensSelect      = 1;
499   fSensSector      = isector;
500   fSensSectorRange = nsector;
501
502 }
503
504 //_____________________________________________________________________________
505 void AliTRDv1::StepManager()
506 {
507   //
508   // Slow simulator. Every charged track produces electron cluster as hits 
509   // along its path across the drift volume. The step size is set acording
510   // to Bethe-Bloch. The energy distribution of the delta electrons follows
511   // a spectrum taken from Ermilova et al.
512   //
513
514   Int_t    iIdSens, icSens;
515   Int_t    iIdSpace, icSpace;
516   Int_t    iIdChamber, icChamber;
517   Int_t    pla = 0;
518   Int_t    cha = 0;
519   Int_t    sec = 0;
520   Int_t    det = 0;
521   Int_t    iPdg;
522   Int_t    qTot;
523
524   Float_t  hits[3];
525   Float_t  moms[3];
526   Float_t  random[1];
527   Float_t  charge;
528   Float_t  aMass;
529
530   Double_t pTot;
531   Double_t eDelta;
532   Double_t betaGamma, pp;
533
534   TLorentzVector pos, mom;
535   TClonesArray  &lhits = *fHits;
536
537   const Double_t kBig     = 1.0E+12;
538
539   // Ionization energy
540   const Float_t  kWion        = 22.04;
541   // Maximum momentum for e+ e- g 
542   const Float_t  kPTotMaxEl   = 0.002;
543   // Minimum momentum for the step size adjustment
544   const Float_t  kPTotMinStep = 1.0e-5;
545   // Plateau value of the energy-loss for electron in xenon
546   // taken from: Allison + Comb, Ann. Rev. Nucl. Sci. (1980), 30, 253
547   //const Double_t kPlateau = 1.70;
548   // the averaged value (26/3/99)
549   const Float_t  kPlateau     = 1.55;
550   // dN1/dx|min for the gas mixture (90% Xe + 10% CO2)
551   const Float_t  kPrim        = 48.0;
552   // First ionization potential (eV) for the gas mixture (90% Xe + 10% CO2)
553   const Float_t  kPoti        = 12.1;
554
555   // PDG code electron
556   const Int_t    kPdgElectron = 11;
557
558   // Set the maximum step size to a very large number for all 
559   // neutral particles and those outside the driftvolume
560   gMC->SetMaxStep(kBig); 
561
562   // Create some special hits with amplitude 0 at the entrance and
563   // exit of each chamber that contain the momentum components of the particle
564   if (gMC->TrackCharge() &&
565      (gMC->IsTrackEntering() || gMC->IsTrackExiting())) {
566
567     // Inside a sensitive volume?
568     iIdSens = gMC->CurrentVolID(icSens);
569     if (iIdSens == fIdSens) { 
570
571       iIdSpace   = gMC->CurrentVolOffID(4,icSpace  );
572       iIdChamber = gMC->CurrentVolOffID(1,icChamber);
573
574       // The hit coordinates
575       gMC->TrackPosition(pos);
576       hits[0] = pos[0];
577       hits[1] = pos[1];
578       hits[2] = pos[2];
579
580       // The track momentum
581       gMC->TrackMomentum(mom);
582       moms[0] = mom[0];
583       moms[1] = mom[1];
584       moms[2] = mom[2];
585
586       // The sector number (0 - 17)
587       // The numbering goes clockwise and starts at y = 0
588       Float_t phi = kRaddeg*TMath::ATan2(pos[0],pos[1]);
589       if (phi < 90.) 
590         phi = phi + 270.;
591       else
592         phi = phi -  90.;
593       sec = ((Int_t) (phi / 20));
594
595       // The chamber number 
596       //   0: outer left
597       //   1: middle left
598       //   2: inner
599       //   3: middle right
600       //   4: outer right
601       if      (iIdChamber == fIdChamber1)
602         cha = (hits[2] < 0 ? 0 : 4);
603       else if (iIdChamber == fIdChamber2)       
604         cha = (hits[2] < 0 ? 1 : 3);
605       else if (iIdChamber == fIdChamber3)       
606         cha = 2;
607
608       // The plane number
609       // The numbering starts at the innermost plane
610       pla = icChamber - TMath::Nint((Float_t) (icChamber / 7)) * 6 - 1;
611
612       // Check on selected volumes
613       Int_t addthishit = 1;
614       if (fSensSelect) {
615         if ((fSensPlane   >= 0) && (pla != fSensPlane  )) addthishit = 0;
616         if ((fSensChamber >= 0) && (cha != fSensChamber)) addthishit = 0;
617         if (fSensSector  >= 0) {
618           Int_t sens1  = fSensSector;
619           Int_t sens2  = fSensSector + fSensSectorRange;
620                 sens2 -= ((Int_t) (sens2 / AliTRDgeometry::Nsect())) 
621                        * AliTRDgeometry::Nsect();
622           if (sens1 < sens2) {
623             if ((sec < sens1) || (sec >= sens2)) addthishit = 0;
624           }
625           else {
626             if ((sec < sens1) && (sec >= sens2)) addthishit = 0;
627           }
628         }
629       }
630
631       // Add this hit
632       if (addthishit) {
633         det = fGeometry->GetDetector(pla,cha,sec);
634         new(lhits[fNhits++]) AliTRDhit(fIshunt
635                                       ,gAlice->CurrentTrack()
636                                       ,det
637                                       ,moms
638                                       ,0);
639       }
640
641     }
642
643   }
644
645   // Use only charged tracks 
646   if (( gMC->TrackCharge()       ) &&
647       (!gMC->IsTrackStop()       ) && 
648       (!gMC->IsTrackDisappeared())) {
649
650     // Inside a sensitive volume?
651     iIdSens = gMC->CurrentVolID(icSens);
652     if (iIdSens == fIdSens) { 
653
654       iIdSpace   = gMC->CurrentVolOffID(4,icSpace  );
655       iIdChamber = gMC->CurrentVolOffID(1,icChamber);
656
657       // Calculate the energy of the delta-electrons
658       eDelta = TMath::Exp(fDeltaE->GetRandom()) - kPoti;
659       eDelta = TMath::Max(eDelta,0.0);
660
661       // The number of secondary electrons created
662       qTot = ((Int_t) (eDelta / kWion) + 1);
663
664       // The hit coordinates and charge
665       gMC->TrackPosition(pos);
666       hits[0] = pos[0];
667       hits[1] = pos[1];
668       hits[2] = pos[2];
669
670       // The sector number (0 - 17)
671       // The numbering goes clockwise and starts at y = 0
672       Float_t phi = kRaddeg*TMath::ATan2(pos[0],pos[1]);
673       if (phi < 90.) 
674         phi = phi + 270.;
675       else
676         phi = phi -  90.;
677       sec = ((Int_t) (phi / 20));
678
679       // The chamber number 
680       //   0: outer left
681       //   1: middle left
682       //   2: inner
683       //   3: middle right
684       //   4: outer right
685       if      (iIdChamber == fIdChamber1)
686         cha = (hits[2] < 0 ? 0 : 4);
687       else if (iIdChamber == fIdChamber2)       
688         cha = (hits[2] < 0 ? 1 : 3);
689       else if (iIdChamber == fIdChamber3)       
690         cha = 2;
691
692       // The plane number
693       // The numbering starts at the innermost plane
694       pla = icChamber - TMath::Nint((Float_t) (icChamber / 7)) * 6 - 1;
695
696       // Check on selected volumes
697       Int_t addthishit = 1;
698       if (fSensSelect) {
699         if ((fSensPlane   >= 0) && (pla != fSensPlane  )) addthishit = 0;
700         if ((fSensChamber >= 0) && (cha != fSensChamber)) addthishit = 0;
701         if (fSensSector  >= 0) {
702           Int_t sens1  = fSensSector;
703           Int_t sens2  = fSensSector + fSensSectorRange;
704                 sens2 -= ((Int_t) (sens2 / AliTRDgeometry::Nsect())) 
705                        * AliTRDgeometry::Nsect();
706           if (sens1 < sens2) {
707             if ((sec < sens1) || (sec >= sens2)) addthishit = 0;
708           }
709           else {
710             if ((sec < sens1) && (sec >= sens2)) addthishit = 0;
711           }
712         }
713       }
714
715       // Add this hit
716       if (addthishit) {
717
718         det = fGeometry->GetDetector(pla,cha,sec);
719
720         // Create the electron cluster from TR photons
721         if (fTR) CreateTRhit(det);
722
723         new(lhits[fNhits++]) AliTRDhit(fIshunt
724                                       ,gAlice->CurrentTrack()
725                                       ,det
726                                       ,hits
727                                       ,qTot);
728
729         // The energy loss according to Bethe Bloch
730         gMC->TrackMomentum(mom);
731         pTot = mom.Rho();
732         iPdg = TMath::Abs(gMC->TrackPid());
733         if ( (iPdg != kPdgElectron) ||
734             ((iPdg == kPdgElectron) && (pTot < kPTotMaxEl))) {
735           aMass     = gMC->TrackMass();
736           betaGamma = pTot / aMass;
737           pp        = kPrim * BetheBloch(betaGamma);
738           // Take charge > 1 into account
739           charge = gMC->TrackCharge();
740           if (TMath::Abs(charge) > 1) pp = pp * charge*charge;
741         }
742         // Electrons above 20 Mev/c are at the plateau
743         else {
744           pp = kPrim * kPlateau;
745         }
746       
747         // Calculate the maximum step size for the next tracking step
748         // introduce a lower momentum cut
749         //if ((pp > 0) && (pTot > kPTotMinStep)) {
750         if (pp > 0) {
751           do 
752             gMC->Rndm(random,1);
753           while ((random[0] == 1.) || (random[0] == 0.));
754           gMC->SetMaxStep( - TMath::Log(random[0]) / pp);
755         }
756
757       }
758       else {
759         // set step size to maximal value
760         gMC->SetMaxStep(kBig); 
761       }
762
763     }
764
765   }
766
767 }
768
769 //_____________________________________________________________________________
770 Double_t AliTRDv1::BetheBloch(Double_t bg) 
771 {
772   //
773   // Parametrization of the Bethe-Bloch-curve
774   // The parametrization is the same as for the TPC and is taken from Lehrhaus.
775   //
776
777   // This parameters have been adjusted to averaged values from GEANT
778   const Double_t kP1 = 7.17960e-02;
779   const Double_t kP2 = 8.54196;
780   const Double_t kP3 = 1.38065e-06;
781   const Double_t kP4 = 5.30972;
782   const Double_t kP5 = 2.83798;
783
784   // This parameters have been adjusted to Xe-data found in:
785   // Allison & Cobb, Ann. Rev. Nucl. Sci. (1980), 30, 253
786   //const Double_t kP1 = 0.76176E-1;
787   //const Double_t kP2 = 10.632;
788   //const Double_t kP3 = 3.17983E-6;
789   //const Double_t kP4 = 1.8631;
790   //const Double_t kP5 = 1.9479;
791
792   if (bg > 0) {
793     Double_t yy = bg / TMath::Sqrt(1. + bg*bg);
794     Double_t aa = TMath::Power(yy,kP4);
795     Double_t bb = TMath::Power((1./bg),kP5);
796              bb = TMath::Log(kP3 + bb);
797     return ((kP2 - aa - bb)*kP1 / aa);
798   }
799   else
800     return 0;
801
802 }
803
804 //_____________________________________________________________________________
805 Double_t Ermilova(Double_t *x, Double_t *)
806 {
807   //
808   // Calculates the delta-ray energy distribution according to Ermilova.
809   // Logarithmic scale !
810   //
811
812   Double_t energy;
813   Double_t dpos;
814   Double_t dnde;
815
816   Int_t    pos1, pos2;
817
818   const Int_t kNv = 31;
819
820   Float_t vxe[kNv] = { 2.3026, 2.9957, 3.4012, 3.6889, 3.9120  
821                      , 4.0943, 4.2485, 4.3820, 4.4998, 4.6052
822                      , 4.7005, 5.0752, 5.2983, 5.7038, 5.9915
823                      , 6.2146, 6.5221, 6.9078, 7.3132, 7.6009
824                      , 8.0064, 8.5172, 8.6995, 8.9872, 9.2103
825                      , 9.4727, 9.9035,10.3735,10.5966,10.8198
826                      ,11.5129 };
827
828   Float_t vye[kNv] = { 80.0  , 31.0  , 23.3  , 21.1  , 21.0
829                      , 20.9  , 20.8  , 20.0  , 16.0  , 11.0
830                      ,  8.0  ,  6.0  ,  5.2  ,  4.6  ,  4.0
831                      ,  3.5  ,  3.0  ,  1.4  ,  0.67 ,  0.44
832                      ,  0.3  ,  0.18 ,  0.12 ,  0.08 ,  0.056
833                      ,  0.04 ,  0.023,  0.015,  0.011,  0.01
834                      ,  0.004 };
835
836   energy = x[0];
837
838   // Find the position 
839   pos1 = pos2 = 0;
840   dpos = 0;
841   do {
842     dpos = energy - vxe[pos2++];
843   } 
844   while (dpos > 0);
845   pos2--; 
846   if (pos2 > kNv) pos2 = kNv;
847   pos1 = pos2 - 1;
848
849   // Differentiate between the sampling points
850   dnde = (vye[pos1] - vye[pos2]) / (vxe[pos2] - vxe[pos1]);
851
852   return dnde;
853
854 }