]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDsim.cxx
Adding MUON HLT code to the repository.
[u/mrichter/AliRoot.git] / TRD / AliTRDsim.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 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  TRD simulation - multimodule (regular rad.)                              //
21 //  after: M. CASTELLANO et al., COMP. PHYS. COMM. 51 (1988) 431             //
22 //                             + COMP. PHYS. COMM. 61 (1990) 395             //
23 //                                                                           //
24 //   17.07.1998 - A.Andronic                                                 //
25 //   08.12.1998 - simplified version                                         //
26 //   11.07.2000 - Adapted code to aliroot environment (C.Blume)              //
27 //   04.06.2004 - Momentum dependent parameters implemented (CBL)            //
28 //                                                                           //
29 ///////////////////////////////////////////////////////////////////////////////
30
31 #include <stdlib.h>
32
33 #include <TH1.h>
34 #include <TRandom.h>
35 #include <TMath.h>
36 #include <TParticle.h>
37
38 #include "AliModule.h"
39
40 #include "AliTRDsim.h"
41
42 ClassImp(AliTRDsim)
43
44 //_____________________________________________________________________________
45 AliTRDsim::AliTRDsim():TObject()
46 {
47   //
48   // AliTRDsim default constructor
49   // 
50
51   fSpectrum = 0;
52   fSigma    = 0;
53   fNFoils   = 0;
54   fNFoilsUp = 0;
55
56   Init();
57
58 }
59
60 //_____________________________________________________________________________
61 AliTRDsim::AliTRDsim(AliModule *mod, Int_t foil, Int_t gap)
62 {
63   //
64   // AliTRDsim constructor. Takes the material properties of the radiator
65   // foils and the gas in the gaps from AliModule <mod>.
66   // The default number of foils is 100 with a thickness of 20 mu. The 
67   // thickness of the gaps is 500 mu.
68   //
69
70   Float_t aFoil, zFoil, rhoFoil;
71   Float_t aGap,  zGap,  rhoGap;
72   Float_t rad, abs;
73   Char_t  name[21];
74
75   fSpectrum = 0;
76   fSigma    = 0;
77   fNFoils   = 0;
78   fNFoilsUp = 0;
79
80   Init();
81
82   mod->AliGetMaterial(foil,name,aFoil,zFoil,rhoFoil,rad,abs);
83   mod->AliGetMaterial(gap ,name,aGap ,zGap ,rhoGap ,rad,abs);
84
85   fFoilDens  = rhoFoil;
86   fFoilA     = aFoil;
87   fFoilZ     = zFoil;
88   fFoilOmega = Omega(fFoilDens,fFoilZ,fFoilA);
89
90   fGapDens   = rhoGap;
91   fGapA      = aGap;
92   fGapZ      = zGap;
93   fGapOmega  = Omega(fGapDens ,fGapZ ,fGapA );
94
95 }
96
97 //_____________________________________________________________________________
98 AliTRDsim::AliTRDsim(const AliTRDsim &s):TObject(s)
99 {
100   //
101   // AliTRDsim copy constructor
102   //
103
104   ((AliTRDsim &) s).Copy(*this);
105
106 }
107
108 //_____________________________________________________________________________
109 AliTRDsim::~AliTRDsim() 
110 {
111   //
112   // AliTRDsim destructor
113   //
114
115   //  if (fSpectrum) delete fSpectrum;
116   if (fSigma)    delete [] fSigma;
117   if (fNFoils)   delete [] fNFoils;
118   if (fNFoilsUp) delete [] fNFoilsUp;
119
120 }
121
122 //_____________________________________________________________________________
123 AliTRDsim &AliTRDsim::operator=(const AliTRDsim &s)
124 {
125   //
126   // Assignment operator
127   //
128
129   if (this != &s) ((AliTRDsim &) s).Copy(*this);
130   return *this;
131
132 }
133
134 //_____________________________________________________________________________
135 void AliTRDsim::Copy(TObject &s) const
136 {
137   //
138   // Copy function
139   //
140
141   ((AliTRDsim &) s).fFoilThick  = fFoilThick;
142   ((AliTRDsim &) s).fFoilDens   = fFoilDens;
143   ((AliTRDsim &) s).fFoilOmega  = fFoilOmega;
144   ((AliTRDsim &) s).fFoilZ      = fFoilZ;
145   ((AliTRDsim &) s).fFoilA      = fFoilA;
146   ((AliTRDsim &) s).fGapThick   = fGapThick;
147   ((AliTRDsim &) s).fGapDens    = fGapDens;
148   ((AliTRDsim &) s).fGapOmega   = fGapOmega;
149   ((AliTRDsim &) s).fGapZ       = fGapZ;
150   ((AliTRDsim &) s).fGapA       = fGapA;
151   ((AliTRDsim &) s).fTemp       = fTemp;
152   ((AliTRDsim &) s).fSpNBins    = fSpNBins;
153   ((AliTRDsim &) s).fSpRange    = fSpRange;
154   ((AliTRDsim &) s).fSpBinWidth = fSpBinWidth;
155   ((AliTRDsim &) s).fSpLower    = fSpLower;
156   ((AliTRDsim &) s).fSpUpper    = fSpUpper;
157
158   if (((AliTRDsim &) s).fNFoils) delete [] ((AliTRDsim &) s).fNFoils;
159   ((AliTRDsim &) s).fNFoils   = new Int_t[fNFoilsDim];
160   for (Int_t iFoil = 0; iFoil < fNFoilsDim; iFoil++) {
161     ((AliTRDsim &) s).fNFoils[iFoil] = fNFoils[iFoil];
162   }  
163
164   if (((AliTRDsim &) s).fNFoilsUp) delete [] ((AliTRDsim &) s).fNFoilsUp;
165   ((AliTRDsim &) s).fNFoilsUp = new Double_t[fNFoilsDim];
166   for (Int_t iFoil = 0; iFoil < fNFoilsDim; iFoil++) {
167     ((AliTRDsim &) s).fNFoilsUp[iFoil] = fNFoilsUp[iFoil];
168   }  
169
170   if (((AliTRDsim &) s).fSigma)  delete [] ((AliTRDsim &) s).fSigma;
171   ((AliTRDsim &) s).fSigma = new Double_t[fSpNBins];
172   for (Int_t iBin = 0; iBin < fSpNBins; iBin++) {
173     ((AliTRDsim &) s).fSigma[iBin] = fSigma[iBin];
174   }  
175
176   fSpectrum->Copy(*((AliTRDsim &) s).fSpectrum);
177
178 }
179
180 //_____________________________________________________________________________
181 void AliTRDsim::Init()
182 {
183   //
184   // Initialization 
185   // The default radiator are prolypropilene foils of 10 mu thickness
186   // with gaps of 80 mu filled with N2.
187   // 
188
189   fNFoilsDim   = 7;
190
191   if (fNFoils)   delete [] fNFoils;
192   fNFoils      = new Int_t[fNFoilsDim];
193   fNFoils[0]   = 170;
194   fNFoils[1]   = 250;
195   fNFoils[2]   = 310;
196   fNFoils[3]   = 380;
197   fNFoils[4]   = 430;
198   fNFoils[5]   = 490;
199   fNFoils[6]   = 550;
200
201   if (fNFoilsUp) delete [] fNFoilsUp;
202   fNFoilsUp    = new Double_t[fNFoilsDim];
203   fNFoilsUp[0] = 1.25;
204   fNFoilsUp[1] = 1.75;
205   fNFoilsUp[2] = 2.50;
206   fNFoilsUp[3] = 3.50;
207   fNFoilsUp[4] = 4.50;
208   fNFoilsUp[5] = 5.50;
209   fNFoilsUp[6] = 10000.0;
210
211   fFoilThick  = 0.0013;
212   fFoilDens   = 0.92;   
213   fFoilZ      = 5.28571;
214   fFoilA      = 10.4286;
215   fFoilOmega  = Omega(fFoilDens,fFoilZ,fFoilA);
216
217   fGapThick   = 0.0060;
218   fGapDens    = 0.00125;  
219   fGapZ       = 7.0;
220   fGapA       = 14.00674;
221   fGapOmega   = Omega(fGapDens ,fGapZ ,fGapA );
222
223   fTemp       = 293.16;
224
225   fSpNBins    = 200;
226   fSpRange    = 100;
227   fSpBinWidth = fSpRange / fSpNBins;
228   fSpLower    = 1.0 - 0.5 * fSpBinWidth;
229   fSpUpper    = fSpLower + fSpRange;
230
231   if (fSpectrum) delete fSpectrum;
232   fSpectrum   = new TH1D("TRspectrum","TR spectrum",fSpNBins,fSpLower,fSpUpper);
233   fSpectrum->SetDirectory(0);
234
235   // Set the sigma values 
236   SetSigma();
237
238 }
239
240 //_____________________________________________________________________________
241 Int_t AliTRDsim::CreatePhotons(Int_t pdg, Float_t p
242                              , Int_t &nPhoton, Float_t *ePhoton)
243 {
244   //
245   // Create TRD photons for a charged particle of type <pdg> with the total 
246   // momentum <p>. 
247   // Number of produced TR photons:       <nPhoton>
248   // Energies of the produced TR photons: <ePhoton>
249   //
250
251   // PDG codes
252   const Int_t kPdgEle  =  11;
253   const Int_t kPdgMuon =  13;
254   const Int_t kPdgPion = 211;
255   const Int_t kPdgKaon = 321;
256
257   Float_t  mass        = 0;
258   switch (TMath::Abs(pdg)) {
259   case kPdgEle:
260     mass      =  5.11e-4;
261     break;
262   case kPdgMuon:
263     mass      =  0.10566;
264     break;
265   case kPdgPion:
266     mass      =  0.13957;
267     break;
268   case kPdgKaon:
269     mass      =  0.4937;
270     break;
271   default:
272     return 0;
273     break;
274   };
275
276   // Calculate the TR photons
277   return TrPhotons(p, mass, nPhoton, ePhoton);
278
279 }
280
281 //_____________________________________________________________________________
282 Int_t AliTRDsim::TrPhotons(Float_t p, Float_t mass
283                          , Int_t &nPhoton, Float_t *ePhoton)
284 {
285   //
286   // Produces TR photons.
287   //
288
289   const Double_t kAlpha  = 0.0072973;
290   const Int_t    kSumMax = 10;
291
292   Double_t kappa = fGapThick / fFoilThick;
293
294   // Calculate gamma
295   Double_t gamma = TMath::Sqrt(p*p + mass*mass) / mass;
296
297   // Select the number of foils corresponding to momentum
298   Int_t    foils = SelectNFoils(p);
299
300   fSpectrum->Reset();
301
302   // The TR spectrum
303   Double_t stemp = 0;
304   for (Int_t iBin = 0; iBin < fSpNBins; iBin++) {
305
306     // keV -> eV
307     Double_t energyeV = (fSpBinWidth * iBin + 1.0) * 1e3;
308
309     Double_t csFoil   = fFoilOmega / energyeV;
310     Double_t csGap    = fGapOmega  / energyeV;
311
312     Double_t rho1     = energyeV * fFoilThick * 1e4 * 2.5 
313                                  * (1.0 / (gamma*gamma) + csFoil*csFoil);
314     Double_t rho2     = energyeV * fFoilThick * 1e4 * 2.5 
315                                  * (1.0 / (gamma*gamma) + csGap *csGap);
316
317     // Calculate the sum
318     Double_t sum = 0;
319     for (Int_t iSum = 0; iSum < kSumMax; iSum++) {
320       Double_t tetan = (TMath::Pi() * 2.0 * (iSum+1) - (rho1 + kappa * rho2)) 
321                      / (kappa + 1.0);
322       if (tetan < 0.0) tetan = 0.0;
323       Double_t aux   = 1.0 / (rho1 + tetan) - 1.0 / (rho2 + tetan);
324                sum  += tetan * (aux*aux) * (1.0 - TMath::Cos(rho1 + tetan));
325     }
326
327     // Absorbtion
328     Double_t conv      = 1.0 - TMath::Exp(-foils * fSigma[iBin]);
329
330     // eV -> keV
331     Float_t  energykeV = energyeV * 0.001;
332
333     // dN / domega
334     Double_t wn        = kAlpha * 4.0 / (fSigma[iBin] * (kappa + 1.0)) 
335                                 * conv * sum / energykeV;
336     fSpectrum->SetBinContent(iBin,wn);
337
338     stemp += wn;
339
340   }
341
342   // <nTR> (binsize corr.)
343   Float_t ntr = stemp * fSpBinWidth;
344   // Number of TR photons from Poisson distribution with mean <ntr>
345   nPhoton = gRandom->Poisson(ntr);
346   // Energy of the TR photons
347   for (Int_t iPhoton = 0; iPhoton < nPhoton; iPhoton++) {
348     ePhoton[iPhoton] = fSpectrum->GetRandom();
349   }
350
351   return 1;
352
353 }
354
355 //_____________________________________________________________________________
356 void AliTRDsim::SetSigma() 
357 {
358   //
359   // Sets the absorbtion crosssection for the energies of the TR spectrum
360   //
361
362   if (fSigma) delete [] fSigma;
363   fSigma = new Double_t[fSpNBins];
364   for (Int_t iBin = 0; iBin < fSpNBins; iBin++) {
365     Double_t energykeV = iBin * fSpBinWidth + 1.0;
366     fSigma[iBin]       = Sigma(energykeV);
367     //printf("SetSigma(): iBin = %d fSigma %g\n",iBin,fSigma[iBin]);
368   }
369
370 }
371
372 //_____________________________________________________________________________
373 Double_t AliTRDsim::Sigma(Double_t energykeV)
374 {
375   //
376   // Calculates the absorbtion crosssection for a one-foil-one-gap-radiator
377   //
378
379   // keV -> MeV
380   Double_t energyMeV = energykeV * 0.001;
381   if (energyMeV >= 0.001) {
382     return(GetMuPo(energyMeV) * fFoilDens * fFoilThick +
383            GetMuAi(energyMeV) * fGapDens  * fGapThick  * GetTemp());
384   }
385   else {
386     return 1e6;
387   }
388
389 }
390
391 //_____________________________________________________________________________
392 Double_t AliTRDsim::GetMuPo(Double_t energyMeV)
393 {
394   //
395   // Returns the photon absorbtion cross section for polypropylene
396   //
397
398   const Int_t kN = 36;
399
400   Double_t mu[kN] = { 1.894E+03, 5.999E+02, 2.593E+02
401                     , 7.743E+01, 3.242E+01, 1.643E+01
402                     , 9.432E+00, 3.975E+00, 2.088E+00
403                     , 7.452E-01, 4.315E-01, 2.706E-01
404                     , 2.275E-01, 2.084E-01, 1.970E-01
405                     , 1.823E-01, 1.719E-01, 1.534E-01
406                     , 1.402E-01, 1.217E-01, 1.089E-01
407                     , 9.947E-02, 9.198E-02, 8.078E-02
408                     , 7.262E-02, 6.495E-02, 5.910E-02   
409                     , 5.064E-02, 4.045E-02, 3.444E-02
410                     , 3.045E-02, 2.760E-02, 2.383E-02
411                     , 2.145E-02, 1.819E-02, 1.658E-02 };
412
413   Double_t en[kN] = { 1.000E-03, 1.500E-03, 2.000E-03
414                     , 3.000E-03, 4.000E-03, 5.000E-03
415                     , 6.000E-03, 8.000E-03, 1.000E-02
416                     , 1.500E-02, 2.000E-02, 3.000E-02
417                     , 4.000E-02, 5.000E-02, 6.000E-02
418                     , 8.000E-02, 1.000E-01, 1.500E-01
419                     , 2.000E-01, 3.000E-01, 4.000E-01
420                     , 5.000E-01, 6.000E-01, 8.000E-01
421                     , 1.000E+00, 1.250E+00, 1.500E+00
422                     , 2.000E+00, 3.000E+00, 4.000E+00
423                     , 5.000E+00, 6.000E+00, 8.000E+00
424                     , 1.000E+01, 1.500E+01, 2.000E+01 };
425
426   return Interpolate(energyMeV,en,mu,kN);
427
428 }
429
430 //_____________________________________________________________________________
431 Double_t AliTRDsim::GetMuCO(Double_t energyMeV)
432 {
433   //
434   // Returns the photon absorbtion cross section for CO2
435   //
436
437   const Int_t kN = 36;
438
439   Double_t mu[kN] = { 0.39383E+04, 0.13166E+04, 0.58750E+03
440                     , 0.18240E+03, 0.77996E+02, 0.40024E+02
441                     , 0.23116E+02, 0.96997E+01, 0.49726E+01
442                     , 0.15543E+01, 0.74915E+00, 0.34442E+00
443                     , 0.24440E+00, 0.20589E+00, 0.18632E+00
444                     , 0.16578E+00, 0.15394E+00, 0.13558E+00
445                     , 0.12336E+00, 0.10678E+00, 0.95510E-01
446                     , 0.87165E-01, 0.80587E-01, 0.70769E-01
447                     , 0.63626E-01, 0.56894E-01, 0.51782E-01
448                     , 0.44499E-01, 0.35839E-01, 0.30825E-01
449                     , 0.27555E-01, 0.25269E-01, 0.22311E-01
450                     , 0.20516E-01, 0.18184E-01, 0.17152E-01 };
451
452   Double_t en[kN] = { 0.10000E-02, 0.15000E-02, 0.20000E-02
453                     , 0.30000E-02, 0.40000E-02, 0.50000E-02
454                     , 0.60000E-02, 0.80000E-02, 0.10000E-01
455                     , 0.15000E-01, 0.20000E-01, 0.30000E-01
456                     , 0.40000E-01, 0.50000E-01, 0.60000E-01
457                     , 0.80000E-01, 0.10000E+00, 0.15000E+00
458                     , 0.20000E+00, 0.30000E+00, 0.40000E+00
459                     , 0.50000E+00, 0.60000E+00, 0.80000E+00
460                     , 0.10000E+01, 0.12500E+01, 0.15000E+01
461                     , 0.20000E+01, 0.30000E+01, 0.40000E+01
462                     , 0.50000E+01, 0.60000E+01, 0.80000E+01
463                     , 0.10000E+02, 0.15000E+02, 0.20000E+02 };
464
465   return Interpolate(energyMeV,en,mu,kN);
466
467 }
468
469 //_____________________________________________________________________________
470 Double_t AliTRDsim::GetMuXe(Double_t energyMeV)
471 {
472   //
473   // Returns the photon absorbtion cross section for xenon
474   //
475
476   const Int_t kN = 48;
477
478   Double_t mu[kN] = { 9.413E+03, 8.151E+03, 7.035E+03
479                     , 7.338E+03, 4.085E+03, 2.088E+03
480                     , 7.780E+02, 3.787E+02, 2.408E+02
481                     , 6.941E+02, 6.392E+02, 6.044E+02
482                     , 8.181E+02, 7.579E+02, 6.991E+02
483                     , 8.064E+02, 6.376E+02, 3.032E+02
484                     , 1.690E+02, 5.743E+01, 2.652E+01
485                     , 8.930E+00, 6.129E+00, 3.316E+01
486                     , 2.270E+01, 1.272E+01, 7.825E+00
487                     , 3.633E+00, 2.011E+00, 7.202E-01
488                     , 3.760E-01, 1.797E-01, 1.223E-01
489                     , 9.699E-02, 8.281E-02, 6.696E-02
490                     , 5.785E-02, 5.054E-02, 4.594E-02
491                     , 4.078E-02, 3.681E-02, 3.577E-02
492                     , 3.583E-02, 3.634E-02, 3.797E-02
493                     , 3.987E-02, 4.445E-02, 4.815E-02 };
494
495   Double_t en[kN] = { 1.00000E-03, 1.07191E-03, 1.14900E-03
496                     , 1.14900E-03, 1.50000E-03, 2.00000E-03
497                     , 3.00000E-03, 4.00000E-03, 4.78220E-03
498                     , 4.78220E-03, 5.00000E-03, 5.10370E-03
499                     , 5.10370E-03, 5.27536E-03, 5.45280E-03
500                     , 5.45280E-03, 6.00000E-03, 8.00000E-03
501                     , 1.00000E-02, 1.50000E-02, 2.00000E-02
502                     , 3.00000E-02, 3.45614E-02, 3.45614E-02
503                     , 4.00000E-02, 5.00000E-02, 6.00000E-02
504                     , 8.00000E-02, 1.00000E-01, 1.50000E-01
505                     , 2.00000E-01, 3.00000E-01, 4.00000E-01
506                     , 5.00000E-01, 6.00000E-01, 8.00000E-01
507                     , 1.00000E+00, 1.25000E+00, 1.50000E+00
508                     , 2.00000E+00, 3.00000E+00, 4.00000E+00
509                     , 5.00000E+00, 6.00000E+00, 8.00000E+00
510                     , 1.00000E+01, 1.50000E+01, 2.00000E+01 };
511
512   return Interpolate(energyMeV,en,mu,kN);
513
514 }
515
516 //_____________________________________________________________________________
517 Double_t AliTRDsim::GetMuBu(Double_t energyMeV)
518 {
519   //
520   // Returns the photon absorbtion cross section for isobutane
521   //
522
523   const Int_t kN = 36;
524
525   Double_t mu[kN] = { 0.38846E+03, 0.12291E+03, 0.53225E+02
526                     , 0.16091E+02, 0.69114E+01, 0.36541E+01
527                     , 0.22282E+01, 0.11149E+01, 0.72887E+00
528                     , 0.45053E+00, 0.38167E+00, 0.33920E+00
529                     , 0.32155E+00, 0.30949E+00, 0.29960E+00
530                     , 0.28317E+00, 0.26937E+00, 0.24228E+00
531                     , 0.22190E+00, 0.19289E+00, 0.17288E+00
532                     , 0.15789E+00, 0.14602E+00, 0.12829E+00
533                     , 0.11533E+00, 0.10310E+00, 0.93790E-01
534                     , 0.80117E-01, 0.63330E-01, 0.53229E-01
535                     , 0.46390E-01, 0.41425E-01, 0.34668E-01
536                     , 0.30267E-01, 0.23910E-01, 0.20509E-01 };
537
538   Double_t en[kN] = { 0.10000E-02, 0.15000E-02, 0.20000E-02
539                     , 0.30000E-02, 0.40000E-02, 0.50000E-02
540                     , 0.60000E-02, 0.80000E-02, 0.10000E-01
541                     , 0.15000E-01, 0.20000E-01, 0.30000E-01
542                     , 0.40000E-01, 0.50000E-01, 0.60000E-01
543                     , 0.80000E-01, 0.10000E+00, 0.15000E+00
544                     , 0.20000E+00, 0.30000E+00, 0.40000E+00
545                     , 0.50000E+00, 0.60000E+00, 0.80000E+00
546                     , 0.10000E+01, 0.12500E+01, 0.15000E+01
547                     , 0.20000E+01, 0.30000E+01, 0.40000E+01
548                     , 0.50000E+01, 0.60000E+01, 0.80000E+01
549                     , 0.10000E+02, 0.15000E+02, 0.20000E+02 };
550
551   return Interpolate(energyMeV,en,mu,kN);
552
553 }
554
555 //_____________________________________________________________________________
556 Double_t AliTRDsim::GetMuMy(Double_t energyMeV)
557 {
558   //
559   // Returns the photon absorbtion cross section for mylar
560   //
561
562   const Int_t kN = 36;
563
564   Double_t mu[kN] = { 2.911E+03, 9.536E+02, 4.206E+02
565                     , 1.288E+02, 5.466E+01, 2.792E+01
566                     , 1.608E+01, 6.750E+00, 3.481E+00
567                     , 1.132E+00, 5.798E-01, 3.009E-01
568                     , 2.304E-01, 2.020E-01, 1.868E-01
569                     , 1.695E-01, 1.586E-01, 1.406E-01
570                     , 1.282E-01, 1.111E-01, 9.947E-02
571                     , 9.079E-02, 8.395E-02, 7.372E-02
572                     , 6.628E-02, 5.927E-02, 5.395E-02
573                     , 4.630E-02, 3.715E-02, 3.181E-02
574                     , 2.829E-02, 2.582E-02, 2.257E-02
575                     , 2.057E-02, 1.789E-02, 1.664E-02 };
576
577   Double_t en[kN] = { 1.00000E-03, 1.50000E-03, 2.00000E-03
578                     , 3.00000E-03, 4.00000E-03, 5.00000E-03
579                     , 6.00000E-03, 8.00000E-03, 1.00000E-02
580                     , 1.50000E-02, 2.00000E-02, 3.00000E-02
581                     , 4.00000E-02, 5.00000E-02, 6.00000E-02
582                     , 8.00000E-02, 1.00000E-01, 1.50000E-01
583                     , 2.00000E-01, 3.00000E-01, 4.00000E-01
584                     , 5.00000E-01, 6.00000E-01, 8.00000E-01
585                     , 1.00000E+00, 1.25000E+00, 1.50000E+00
586                     , 2.00000E+00, 3.00000E+00, 4.00000E+00
587                     , 5.00000E+00, 6.00000E+00, 8.00000E+00
588                     , 1.00000E+01, 1.50000E+01, 2.00000E+01 };
589
590   return Interpolate(energyMeV,en,mu,kN);
591
592 }
593
594 //_____________________________________________________________________________
595 Double_t AliTRDsim::GetMuN2(Double_t energyMeV)
596 {
597   //
598   // Returns the photon absorbtion cross section for nitrogen
599   //
600
601   const Int_t kN = 36;
602
603   Double_t mu[kN] = { 3.311E+03, 1.083E+03, 4.769E+02
604                     , 1.456E+02, 6.166E+01, 3.144E+01
605                     , 1.809E+01, 7.562E+00, 3.879E+00
606                     , 1.236E+00, 6.178E-01, 3.066E-01
607                     , 2.288E-01, 1.980E-01, 1.817E-01
608                     , 1.639E-01, 1.529E-01, 1.353E-01
609                     , 1.233E-01, 1.068E-01, 9.557E-02
610                     , 8.719E-02, 8.063E-02, 7.081E-02
611                     , 6.364E-02, 5.693E-02, 5.180E-02
612                     , 4.450E-02, 3.579E-02, 3.073E-02
613                     , 2.742E-02, 2.511E-02, 2.209E-02
614                     , 2.024E-02, 1.782E-02, 1.673E-02 };
615
616   Double_t en[kN] = { 1.00000E-03, 1.50000E-03, 2.00000E-03
617                     , 3.00000E-03, 4.00000E-03, 5.00000E-03
618                     , 6.00000E-03, 8.00000E-03, 1.00000E-02
619                     , 1.50000E-02, 2.00000E-02, 3.00000E-02
620                     , 4.00000E-02, 5.00000E-02, 6.00000E-02
621                     , 8.00000E-02, 1.00000E-01, 1.50000E-01
622                     , 2.00000E-01, 3.00000E-01, 4.00000E-01
623                     , 5.00000E-01, 6.00000E-01, 8.00000E-01
624                     , 1.00000E+00, 1.25000E+00, 1.50000E+00
625                     , 2.00000E+00, 3.00000E+00, 4.00000E+00
626                     , 5.00000E+00, 6.00000E+00, 8.00000E+00
627                     , 1.00000E+01, 1.50000E+01, 2.00000E+01 };
628
629   return Interpolate(energyMeV,en,mu,kN);
630
631 }
632
633 //_____________________________________________________________________________
634 Double_t AliTRDsim::GetMuO2(Double_t energyMeV)
635 {
636   //
637   // Returns the photon absorbtion cross section for oxygen
638   //
639
640   const Int_t kN = 36;
641
642   Double_t mu[kN] = { 4.590E+03, 1.549E+03, 6.949E+02
643                     , 2.171E+02, 9.315E+01, 4.790E+01
644                     , 2.770E+01, 1.163E+01, 5.952E+00
645                     , 1.836E+00, 8.651E-01, 3.779E-01
646                     , 2.585E-01, 2.132E-01, 1.907E-01
647                     , 1.678E-01, 1.551E-01, 1.361E-01
648                     , 1.237E-01, 1.070E-01, 9.566E-02
649                     , 8.729E-02, 8.070E-02, 7.087E-02
650                     , 6.372E-02, 5.697E-02, 5.185E-02
651                     , 4.459E-02, 3.597E-02, 3.100E-02
652                     , 2.777E-02, 2.552E-02, 2.263E-02
653                     , 2.089E-02, 1.866E-02, 1.770E-02 };
654
655   Double_t en[kN] = { 1.00000E-03, 1.50000E-03, 2.00000E-03
656                     , 3.00000E-03, 4.00000E-03, 5.00000E-03
657                     , 6.00000E-03, 8.00000E-03, 1.00000E-02
658                     , 1.50000E-02, 2.00000E-02, 3.00000E-02
659                     , 4.00000E-02, 5.00000E-02, 6.00000E-02
660                     , 8.00000E-02, 1.00000E-01, 1.50000E-01
661                     , 2.00000E-01, 3.00000E-01, 4.00000E-01
662                     , 5.00000E-01, 6.00000E-01, 8.00000E-01
663                     , 1.00000E+00, 1.25000E+00, 1.50000E+00
664                     , 2.00000E+00, 3.00000E+00, 4.00000E+00
665                     , 5.00000E+00, 6.00000E+00, 8.00000E+00
666                     , 1.00000E+01, 1.50000E+01, 2.00000E+01 };
667
668   return Interpolate(energyMeV,en,mu,kN);
669
670 }
671
672 //_____________________________________________________________________________
673 Double_t AliTRDsim::GetMuHe(Double_t energyMeV)
674 {
675   //
676   // Returns the photon absorbtion cross section for helium
677   //
678
679   const Int_t kN = 36;
680
681   Double_t mu[kN] = { 6.084E+01, 1.676E+01, 6.863E+00
682                     , 2.007E+00, 9.329E-01, 5.766E-01
683                     , 4.195E-01, 2.933E-01, 2.476E-01
684                     , 2.092E-01, 1.960E-01, 1.838E-01
685                     , 1.763E-01, 1.703E-01, 1.651E-01
686                     , 1.562E-01, 1.486E-01, 1.336E-01
687                     , 1.224E-01, 1.064E-01, 9.535E-02
688                     , 8.707E-02, 8.054E-02, 7.076E-02
689                     , 6.362E-02, 5.688E-02, 5.173E-02
690                     , 4.422E-02, 3.503E-02, 2.949E-02
691                     , 2.577E-02, 2.307E-02, 1.940E-02
692                     , 1.703E-02, 1.363E-02, 1.183E-02 };
693
694   Double_t en[kN] = { 1.00000E-03, 1.50000E-03, 2.00000E-03
695                     , 3.00000E-03, 4.00000E-03, 5.00000E-03
696                     , 6.00000E-03, 8.00000E-03, 1.00000E-02
697                     , 1.50000E-02, 2.00000E-02, 3.00000E-02
698                     , 4.00000E-02, 5.00000E-02, 6.00000E-02
699                     , 8.00000E-02, 1.00000E-01, 1.50000E-01
700                     , 2.00000E-01, 3.00000E-01, 4.00000E-01
701                     , 5.00000E-01, 6.00000E-01, 8.00000E-01
702                     , 1.00000E+00, 1.25000E+00, 1.50000E+00
703                     , 2.00000E+00, 3.00000E+00, 4.00000E+00
704                     , 5.00000E+00, 6.00000E+00, 8.00000E+00
705                     , 1.00000E+01, 1.50000E+01, 2.00000E+01 };
706
707   return Interpolate(energyMeV,en,mu,kN);
708
709 }
710
711 //_____________________________________________________________________________
712 Double_t AliTRDsim::GetMuAi(Double_t energyMeV)
713 {
714   //
715   // Returns the photon absorbtion cross section for air
716   // Implemented by Oliver Busch
717   //
718
719   const Int_t kN = 38;
720
721   Double_t mu[kN] = { 0.35854E+04, 0.11841E+04, 0.52458E+03,
722                       0.16143E+03, 0.14250E+03, 0.15722E+03,
723                       0.77538E+02, 0.40099E+02, 0.23313E+02,
724                       0.98816E+01, 0.51000E+01, 0.16079E+01,
725                       0.77536E+00, 0.35282E+00, 0.24790E+00,
726                       0.20750E+00, 0.18703E+00, 0.16589E+00,
727                       0.15375E+00, 0.13530E+00, 0.12311E+00,
728                       0.10654E+00, 0.95297E-01, 0.86939E-01,
729                       0.80390E-01, 0.70596E-01, 0.63452E-01,
730                       0.56754E-01, 0.51644E-01, 0.44382E-01,
731                       0.35733E-01, 0.30721E-01, 0.27450E-01,
732                       0.25171E-01, 0.22205E-01, 0.20399E-01,
733                       0.18053E-01, 0.18057E-01 };
734
735
736
737   Double_t en[kN] = { 0.10000E-02, 0.15000E-02, 0.20000E-02,
738                       0.30000E-02, 0.32029E-02, 0.32029E-02,
739                       0.40000E-02, 0.50000E-02, 0.60000E-02,
740                       0.80000E-02, 0.10000E-01, 0.15000E-01,
741                       0.20000E-01, 0.30000E-01, 0.40000E-01,
742                       0.50000E-01, 0.60000E-01, 0.80000E-01,
743                       0.10000E+00, 0.15000E+00, 0.20000E+00,
744                       0.30000E+00, 0.40000E+00, 0.50000E+00,
745                       0.60000E+00, 0.80000E+00, 0.10000E+01,
746                       0.12500E+01, 0.15000E+01, 0.20000E+01,
747                       0.30000E+01, 0.40000E+01, 0.50000E+01,
748                       0.60000E+01, 0.80000E+01, 0.10000E+02,
749                       0.15000E+02, 0.20000E+02 };
750
751   return Interpolate(energyMeV,en,mu,kN);
752
753 }
754
755 //_____________________________________________________________________________
756 Double_t AliTRDsim::Interpolate(Double_t energyMeV
757                               , Double_t *en, Double_t *mu, Int_t n)
758 {
759   //
760   // Interpolates the photon absorbtion cross section 
761   // for a given energy <energyMeV>.
762   //
763
764   Double_t de    = 0;
765   Int_t    index = 0;
766   Int_t    istat = Locate(en,n,energyMeV,index,de);
767   if (istat == 0) {
768     return (mu[index] - de * (mu[index]   - mu[index+1]) 
769                            / (en[index+1] - en[index]  ));
770   }
771   else {
772     return 0.0; 
773   }
774
775 }
776
777 //_____________________________________________________________________________
778 Int_t AliTRDsim::Locate(Double_t *xv, Int_t n, Double_t xval
779                       , Int_t &kl, Double_t &dx) 
780 {
781   //
782   // Locates a point (xval) in a 1-dim grid (xv(n))
783   //
784
785   if (xval >= xv[n-1]) return  1;
786   if (xval <  xv[0])   return -1;
787
788   Int_t km;
789   Int_t kh = n - 1;
790
791   kl = 0;
792   while (kh - kl > 1) {
793     if (xval < xv[km = (kl+kh)/2]) kh = km; 
794     else                           kl = km;
795   }
796   if (xval < xv[kl] || xval > xv[kl+1] || kl >= n-1) {
797     printf("Locate failed xv[%d] %f xval %f xv[%d] %f!!!\n"
798           ,kl,xv[kl],xval,kl+1,xv[kl+1]);
799     exit(1);
800   }
801
802   dx = xval - xv[kl];
803
804   return 0;
805
806 }
807
808 //_____________________________________________________________________________
809 Int_t AliTRDsim::SelectNFoils(Float_t p)
810 {
811   //
812   // Selects the number of foils corresponding to the momentum
813   //
814
815   Int_t foils = fNFoils[fNFoilsDim-1];
816
817   for (Int_t iFoil = 0; iFoil < fNFoilsDim; iFoil++) {
818     if (p < fNFoilsUp[iFoil]) {
819       foils = fNFoils[iFoil];
820       break;
821     }
822   }
823
824   return foils;
825
826 }