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