Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #include "SimTracker/Common/interface/SiG4UniversalFluctuation.h"
00056 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00057 #include "CLHEP/Units/GlobalPhysicalConstants.h"
00058 #include "CLHEP/Random/RandGaussQ.h"
00059 #include "CLHEP/Random/RandPoisson.h"
00060 #include "CLHEP/Random/RandFlat.h"
00061 #include <math.h>
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 using namespace std;
00073
00074 SiG4UniversalFluctuation::SiG4UniversalFluctuation(CLHEP::HepRandomEngine& eng)
00075 :rndEngine(eng),
00076 gaussQDistribution(0),
00077 poissonDistribution(0),
00078 flatDistribution(0),
00079 minNumberInteractionsBohr(10.0),
00080 theBohrBeta2(50.0*keV/proton_mass_c2),
00081 minLoss(10.*eV),
00082 problim(5.e-3),
00083 alim(10.),
00084 nmaxCont1(4.),
00085 nmaxCont2(16.)
00086 {
00087 sumalim = -log(problim);
00088
00089
00090
00091 chargeSquare = 1.;
00092
00093 ipotFluct = 0.0001736;
00094 electronDensity = 6.797E+20;
00095 f1Fluct = 0.8571;
00096 f2Fluct = 0.1429;
00097 e1Fluct = 0.000116;
00098 e2Fluct = 0.00196;
00099 e1LogFluct = -9.063;
00100 e2LogFluct = -6.235;
00101 rateFluct = 0.4;
00102 ipotLogFluct = -8.659;
00103 e0 = 1.E-5;
00104
00105 gaussQDistribution = new CLHEP::RandGaussQ(rndEngine);
00106 poissonDistribution = new CLHEP::RandPoisson(rndEngine);
00107 flatDistribution = new CLHEP::RandFlat(rndEngine);
00108
00109
00110 }
00111
00112
00113
00114
00115
00116
00117 SiG4UniversalFluctuation::~SiG4UniversalFluctuation()
00118 {
00119 delete gaussQDistribution;
00120 delete poissonDistribution;
00121 delete flatDistribution;
00122
00123 }
00124
00125
00126 double SiG4UniversalFluctuation::SampleFluctuations(const double momentum,
00127 const double mass,
00128 double& tmax,
00129 const double length,
00130 const double meanLoss)
00131 {
00132
00133
00134
00135
00136
00137
00138
00139 if (meanLoss < minLoss) return meanLoss;
00140
00141
00142
00143
00144
00145
00146
00147 particleMass = mass;
00148 double gam2 = (momentum*momentum)/(particleMass*particleMass) + 1.0;
00149 double beta2 = 1.0 - 1.0/gam2;
00150 double gam = sqrt(gam2);
00151
00152 double loss(0.), siga(0.);
00153
00154
00155
00156
00157
00158 if ((particleMass > electron_mass_c2) &&
00159 (meanLoss >= minNumberInteractionsBohr*tmax))
00160 {
00161 double massrate = electron_mass_c2/particleMass ;
00162 double tmaxkine = 2.*electron_mass_c2*beta2*gam2/
00163 (1.+massrate*(2.*gam+massrate)) ;
00164 if (tmaxkine <= 2.*tmax)
00165 {
00166
00167 siga = (1.0/beta2 - 0.5) * twopi_mc2_rcl2 * tmax * length
00168 * electronDensity * chargeSquare;
00169 siga = sqrt(siga);
00170 double twomeanLoss = meanLoss + meanLoss;
00171 if (twomeanLoss < siga) {
00172 double x;
00173 do {
00174 loss = twomeanLoss*flatDistribution->fire();
00175 x = (loss - meanLoss)/siga;
00176 } while (1.0 - 0.5*x*x < flatDistribution->fire());
00177 } else {
00178 do {
00179 loss = gaussQDistribution->fire(meanLoss,siga);
00180 } while (loss < 0. || loss > twomeanLoss);
00181 }
00182 return loss;
00183 }
00184 }
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 double a1 = 0. , a2 = 0., a3 = 0. ;
00202 double p1,p2,p3;
00203 double rate = rateFluct ;
00204
00205 double w1 = tmax/ipotFluct;
00206 double w2 = log(2.*electron_mass_c2*beta2*gam2)-beta2;
00207
00208 if(w2 > ipotLogFluct)
00209 {
00210 double C = meanLoss*(1.-rateFluct)/(w2-ipotLogFluct);
00211 a1 = C*f1Fluct*(w2-e1LogFluct)/e1Fluct;
00212 a2 = C*f2Fluct*(w2-e2LogFluct)/e2Fluct;
00213 if(a2 < 0.)
00214 {
00215 a1 = 0. ;
00216 a2 = 0. ;
00217 rate = 1. ;
00218 }
00219 }
00220 else
00221 {
00222 rate = 1. ;
00223 }
00224
00225 a3 = rate*meanLoss*(tmax-ipotFluct)/(ipotFluct*tmax*log(w1));
00226
00227 double suma = a1+a2+a3;
00228
00229
00230
00231 if (suma > sumalim)
00232 {
00233 p1 = 0., p2 = 0 ;
00234 if((a1+a2) > 0.)
00235 {
00236
00237 if (a1>alim) {
00238 siga=sqrt(a1) ;
00239 p1 = max(0.,gaussQDistribution->fire(a1,siga)+0.5);
00240 } else {
00241 p1 = double(poissonDistribution->fire(a1));
00242 }
00243
00244
00245 if (a2>alim) {
00246 siga=sqrt(a2) ;
00247 p2 = max(0.,gaussQDistribution->fire(a2,siga)+0.5);
00248 } else {
00249 p2 = double(poissonDistribution->fire(a2));
00250 }
00251
00252 loss = p1*e1Fluct+p2*e2Fluct;
00253
00254
00255 if (p2 > 0.)
00256 loss += (1.-2.*flatDistribution->fire())*e2Fluct;
00257 else if (loss>0.)
00258 loss += (1.-2.*flatDistribution->fire())*e1Fluct;
00259 if (loss < 0.) loss = 0.0;
00260 }
00261
00262
00263 if (a3 > 0.) {
00264 if (a3>alim) {
00265 siga=sqrt(a3) ;
00266 p3 = max(0.,gaussQDistribution->fire(a3,siga)+0.5);
00267 } else {
00268 p3 = double(poissonDistribution->fire(a3));
00269 }
00270 double lossc = 0.;
00271 if (p3 > 0) {
00272 double na = 0.;
00273 double alfa = 1.;
00274 if (p3 > nmaxCont2) {
00275 double rfac = p3/(nmaxCont2+p3);
00276 double namean = p3*rfac;
00277 double sa = nmaxCont1*rfac;
00278 na = gaussQDistribution->fire(namean,sa);
00279 if (na > 0.) {
00280 alfa = w1*(nmaxCont2+p3)/(w1*nmaxCont2+p3);
00281 double alfa1 = alfa*log(alfa)/(alfa-1.);
00282 double ea = na*ipotFluct*alfa1;
00283 double sea = ipotFluct*sqrt(na*(alfa-alfa1*alfa1));
00284 lossc += gaussQDistribution->fire(ea,sea);
00285 }
00286 }
00287
00288 if (p3 > na) {
00289 w2 = alfa*ipotFluct;
00290 double w = (tmax-w2)/tmax;
00291 int nb = int(p3-na);
00292 for (int k=0; k<nb; k++) lossc += w2/(1.-w*flatDistribution->fire());
00293 }
00294 }
00295 loss += lossc;
00296 }
00297 return loss;
00298 }
00299
00300
00301
00302
00303
00304 a3 = meanLoss*(tmax-e0)/(tmax*e0*log(tmax/e0));
00305 if (a3 > alim)
00306 {
00307 siga=sqrt(a3);
00308 p3 = max(0.,gaussQDistribution->fire(a3,siga)+0.5);
00309 } else {
00310 p3 = double(poissonDistribution->fire(a3));
00311 }
00312 if (p3 > 0.) {
00313 double w = (tmax-e0)/tmax;
00314 double corrfac = 1.;
00315 if (p3 > nmaxCont2) {
00316 corrfac = p3/nmaxCont2;
00317 p3 = nmaxCont2;
00318 }
00319 int ip3 = (int)p3;
00320 for (int i=0; i<ip3; i++) loss += 1./(1.-w*flatDistribution->fire());
00321 loss *= e0*corrfac;
00322
00323 if(p3 <= 2.)
00324 loss += e0*(1.-2.*flatDistribution->fire()) ;
00325 }
00326
00327 return loss;
00328 }
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350