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