CMS 3D CMS Logo

LandauFP420.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * DISCLAIMER *
4 // * *
5 // * The following disclaimer summarizes all the specific disclaimers *
6 // * of contributors to this software. The specific disclaimers,which *
7 // * govern, are listed with their locations in: *
8 // * http://cern.ch/geant4/license *
9 // * *
10 // * Neither the authors of this software system, nor their employing *
11 // * institutes,nor the agencies providing financial support for this *
12 // * work make any representation or warranty, express or implied, *
13 // * regarding this software system or assume any liability for its *
14 // * use. *
15 // * *
16 // * This code implementation is the intellectual property of the *
17 // * GEANT4 collaboration. *
18 // * By copying, distributing or modifying the Program (or any work *
19 // * based on the Program) you indicate your acceptance of this *
20 // * statement, and all its terms. *
21 // ********************************************************************
22 //
23 // -------------------------------------------------------------------
24 //
25 // GEANT4 Class file
26 //
27 //
28 // File name: G4UniversalFluctuation
29 //
30 // Author: Vladimir Ivanchenko
31 //
32 // Creation date: 03.01.2002
33 //
34 // Modifications:
35 //
36 // 28-12-02 add method Dispersion (V.Ivanchenko)
37 // 07-02-03 change signature (V.Ivanchenko)
38 // 13-02-03 Add name (V.Ivanchenko)
39 // Modified for standalone use in ORCA. d.k. 6/04
40 //
41 // -------------------------------------------------------------------
42 
43 #include "CLHEP/Random/RandFlat.h"
44 #include "CLHEP/Random/RandGaussQ.h"
45 #include "CLHEP/Random/RandPoisson.h"
46 #include "CLHEP/Units/GlobalPhysicalConstants.h"
47 #include "CLHEP/Units/GlobalSystemOfUnits.h"
49 
50 #include <cmath>
51 #include <cstdio>
52 #include <gsl/gsl_fit.h>
53 #include <vector>
54 
55 //#include "Randomize.hh"
56 //#include "G4Poisson.hh"
57 //#include "G4Step.hh"
58 //#include "G4Material.hh"
59 //#include "G4DynamicParticle.hh"
60 //#include "G4ParticleDefinition.hh"
61 using namespace std;
62 
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
64 // The constructor setups various constants pluc eloss parameters
65 // for silicon.
67  : minNumberInteractionsBohr(10.0),
68  theBohrBeta2(50.0 * keV / proton_mass_c2),
69  minLoss(0.000001 * eV),
70  problim(0.01),
71  alim(10.),
72  nmaxCont1(4),
73  nmaxCont2(16) {
74  sumalim = -log(problim);
75 
76  chargeSquare = 1.; // Assume all particles have charge 1
77  // Taken from Geant4 printout, HARDWIRED for Silicon.
78  ipotFluct = 0.0001736; // material->GetIonisation()->GetMeanExcitationEnergy();
79  electronDensity = 6.797E+20; // material->GetElectronDensity();
80  f1Fluct = 0.8571; // material->GetIonisation()->GetF1fluct();
81  f2Fluct = 0.1429; // material->GetIonisation()->GetF2fluct();
82  e1Fluct = 0.000116; // material->GetIonisation()->GetEnergy1fluct();
83  e2Fluct = 0.00196; // material->GetIonisation()->GetEnergy2fluct();
84  e1LogFluct = -9.063; // material->GetIonisation()->GetLogEnergy1fluct();
85  e2LogFluct = -6.235; // material->GetIonisation()->GetLogEnergy2fluct();
86  rateFluct = 0.4; // material->GetIonisation()->GetRateionexcfluct();
87  ipotLogFluct = -8.659; // material->GetIonisation()->GetLogMeanExcEnergy();
88  e0 = 1.E-5; // material->GetIonisation()->GetEnergy0fluct();
89 }
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
93 // The main dedx fluctuation routine.
94 // Arguments: momentum in MeV/c, mass in MeV, delta ray cut (tmax) in
95 // MeV, silicon thickness in mm, mean eloss in MeV.
97  const double momentum, const double mass, double &tmax, const double length, const double meanLoss) {
98  // calculate actual loss from the mean loss
99  // The model used to get the fluctuation is essentially the same
100  // as in Glandz in Geant3.
101 
102  // shortcut for very very small loss
103  if (meanLoss < minLoss)
104  return meanLoss;
105 
106  // if(dp->GetDefinition() != particle) {
107  particleMass = mass; // dp->GetMass();
108  // G4double q = dp->GetCharge();
109  // chargeSquare = q*q;
110  //}
111 
112  // double gam = (dp->GetKineticEnergy())/particleMass + 1.0;
113  // double gam2 = gam*gam;
114  double gam2 = (momentum * momentum) / (particleMass * particleMass) + 1.0;
115  double beta2 = 1.0 - 1.0 / gam2;
116 
117  // Validity range for delta electron cross section
118  double loss, siga;
119  // Gaussian fluctuation
120  if (meanLoss >= minNumberInteractionsBohr * tmax || tmax <= ipotFluct * minNumberInteractionsBohr) {
121  siga = (1.0 / beta2 - 0.5) * twopi_mc2_rcl2 * tmax * length * electronDensity * chargeSquare;
122  siga = sqrt(siga);
123  do {
124  // loss = G4RandGauss::shoot(meanLoss,siga);
125  loss = CLHEP::RandGaussQ::shoot(meanLoss, siga);
126  } while (loss < 0. || loss > 2. * meanLoss);
127 
128  return loss;
129  }
130 
131  // Non Gaussian fluctuation
132  double suma, w1, w2, C, lossc, w;
133  double a1, a2, a3;
134  int p1, p2, p3;
135  int nb;
136  double corrfac, na, alfa, rfac, namean, sa, alfa1, ea, sea;
137  double dp3;
138 
139  w1 = tmax / ipotFluct;
140  w2 = log(2. * electron_mass_c2 * (gam2 - 1.0));
141 
142  C = meanLoss * (1. - rateFluct) / (w2 - ipotLogFluct - beta2);
143 
144  a1 = C * f1Fluct * (w2 - e1LogFluct - beta2) / e1Fluct;
145  a2 = C * f2Fluct * (w2 - e2LogFluct - beta2) / e2Fluct;
146  a3 = rateFluct * meanLoss * (tmax - ipotFluct) / (ipotFluct * tmax * log(w1));
147  if (a1 < 0.)
148  a1 = 0.;
149  if (a2 < 0.)
150  a2 = 0.;
151  if (a3 < 0.)
152  a3 = 0.;
153 
154  suma = a1 + a2 + a3;
155 
156  loss = 0.;
157 
158  if (suma < sumalim) // very small Step
159  {
160  // e0 = material->GetIonisation()->GetEnergy0fluct();//Hardwired in const
161  if (tmax == ipotFluct) {
162  a3 = meanLoss / e0;
163 
164  if (a3 > alim) {
165  siga = sqrt(a3);
166  // p3 = G4std::max(0,int(G4RandGauss::shoot(a3,siga)+0.5));
167  p3 = std::max(0, int(CLHEP::RandGaussQ::shoot(a3, siga) + 0.5));
168  } else
169  p3 = CLHEP::RandPoisson::shoot(a3);
170  // p3 = G4Poisson(a3);
171 
172  loss = p3 * e0;
173 
174  if (p3 > 0)
175  // loss += (1.-2.*G4UniformRand())*e0 ;
176  loss += (1. - 2. * CLHEP::RandFlat::shoot()) * e0;
177 
178  } else {
179  tmax = tmax - ipotFluct + e0;
180  a3 = meanLoss * (tmax - e0) / (tmax * e0 * log(tmax / e0));
181 
182  if (a3 > alim) {
183  siga = sqrt(a3);
184  // p3 = G4std::max(0,int(G4RandGauss::shoot(a3,siga)+0.5));
185  p3 = std::max(0, int(CLHEP::RandGaussQ::shoot(a3, siga) + 0.5));
186  } else
187  p3 = CLHEP::RandPoisson::shoot(a3);
188  // p3 = G4Poisson(a3);
189 
190  if (p3 > 0) {
191  w = (tmax - e0) / tmax;
192  if (p3 > nmaxCont2) {
193  dp3 = float(p3);
194  corrfac = dp3 / float(nmaxCont2);
195  p3 = nmaxCont2;
196  } else
197  corrfac = 1.;
198 
199  // for(int i=0; i<p3; i++) loss += 1./(1.-w*G4UniformRand()) ;
200  for (int i = 0; i < p3; i++)
201  loss += 1. / (1. - w * CLHEP::RandFlat::shoot());
202  loss *= e0 * corrfac;
203  }
204  }
205  }
206 
207  else // not so small Step
208  {
209  // excitation type 1
210  if (a1 > alim) {
211  siga = sqrt(a1);
212  // p1 = std::max(0,int(G4RandGauss::shoot(a1,siga)+0.5));
213  p1 = std::max(0, int(CLHEP::RandGaussQ::shoot(a1, siga) + 0.5));
214  } else
215  p1 = CLHEP::RandPoisson::shoot(a1);
216  // p1 = G4Poisson(a1);
217 
218  // excitation type 2
219  if (a2 > alim) {
220  siga = sqrt(a2);
221  // p2 = std::max(0,int(G4RandGauss::shoot(a2,siga)+0.5));
222  p2 = std::max(0, int(CLHEP::RandGaussQ::shoot(a2, siga) + 0.5));
223  } else
224  p2 = CLHEP::RandPoisson::shoot(a2);
225  // p2 = G4Poisson(a2);
226 
227  loss = p1 * e1Fluct + p2 * e2Fluct;
228 
229  // smearing to avoid unphysical peaks
230  if (p2 > 0)
231  // loss += (1.-2.*G4UniformRand())*e2Fluct;
232  loss += (1. - 2. * CLHEP::RandFlat::shoot()) * e2Fluct;
233  else if (loss > 0.)
234  loss += (1. - 2. * CLHEP::RandFlat::shoot()) * e1Fluct;
235 
236  // ionisation .......................................
237  if (a3 > 0.) {
238  if (a3 > alim) {
239  siga = sqrt(a3);
240  p3 = std::max(0, int(CLHEP::RandGaussQ::shoot(a3, siga) + 0.5));
241  } else
242  p3 = CLHEP::RandPoisson::shoot(a3);
243 
244  lossc = 0.;
245  if (p3 > 0) {
246  na = 0.;
247  alfa = 1.;
248  if (p3 > nmaxCont2) {
249  dp3 = float(p3);
250  rfac = dp3 / (float(nmaxCont2) + dp3);
251  namean = float(p3) * rfac;
252  sa = float(nmaxCont1) * rfac;
253  na = CLHEP::RandGaussQ::shoot(namean, sa);
254  if (na > 0.) {
255  alfa = w1 * float(nmaxCont2 + p3) / (w1 * float(nmaxCont2) + float(p3));
256  alfa1 = alfa * log(alfa) / (alfa - 1.);
257  ea = na * ipotFluct * alfa1;
258  sea = ipotFluct * sqrt(na * (alfa - alfa1 * alfa1));
259  lossc += CLHEP::RandGaussQ::shoot(ea, sea);
260  }
261  }
262 
263  nb = int(float(p3) - na);
264  if (nb > 0) {
265  w2 = alfa * ipotFluct;
266  w = (tmax - w2) / tmax;
267  for (int k = 0; k < nb; k++)
268  lossc += w2 / (1. - w * CLHEP::RandFlat::shoot());
269  }
270  }
271  loss += lossc;
272  }
273  }
274 
275  return loss;
276 }
277 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
double e1Fluct
Definition: LandauFP420.h:87
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
const double w
Definition: UKUtility.cc:23
double e2LogFluct
Definition: LandauFP420.h:91
double e1LogFluct
Definition: LandauFP420.h:90
double chargeSquare
Definition: LandauFP420.h:78
double rateFluct
Definition: LandauFP420.h:89
double minLoss
Definition: LandauFP420.h:97
double alim
Definition: LandauFP420.h:100
double sumalim
Definition: LandauFP420.h:99
double electronDensity
Definition: LandauFP420.h:82
T sqrt(T t)
Definition: SSEVec.h:18
double p2[4]
Definition: TauolaWrapper.h:90
int k[5][pyjets_maxn]
static const double tmax[3]
double minNumberInteractionsBohr
Definition: LandauFP420.h:95
double p1[4]
Definition: TauolaWrapper.h:89
double ipotFluct
Definition: LandauFP420.h:81
double particleMass
Definition: LandauFP420.h:77
double e2Fluct
Definition: LandauFP420.h:88
double SampleFluctuations(const double momentum, const double mass, double &tmax, const double length, const double meanLoss)
Definition: LandauFP420.cc:96
double f1Fluct
Definition: LandauFP420.h:85
double f2Fluct
Definition: LandauFP420.h:86
double problim
Definition: LandauFP420.h:98
double e0
Definition: LandauFP420.h:93
double ipotLogFluct
Definition: LandauFP420.h:92
double p3[4]
Definition: TauolaWrapper.h:91