CMS 3D CMS Logo

HDRShower.cc
Go to the documentation of this file.
1 //FastSimulation Headers
6 
7 //CMSSW headers
9 
10 using namespace edm;
11 
13 // What's this? Doesn't seem to be needed. Maybe Geometry/CaloGeometry/interface/CaloCellGeometry.h?
14 //#include "Calorimetry/CaloDetector/interface/CellGeometry.h"
15 
16 // number attempts for transverse distribution if exit on a spec. condition
17 #define infinity 5000
18 // debugging flag ( 0, 1, 2, 3)
19 #define debug 0
20 
21 using namespace std;
22 
24  HDShowerParametrization* myParam,
25  EcalHitMaker* myGrid,
26  HcalHitMaker* myHcalHitMaker,
27  int onECAL,
28  double epart)
29  : theParam(myParam), theGrid(myGrid), theHcalHitMaker(myHcalHitMaker), onEcal(onECAL), e(epart), random(engine) {
30  eHDspot = 0.2;
31  EsCut = 0.050;
32  EcalShift = 0.12;
33  nthetaStep = 10;
34  thetaStep = 0.5 * M_PI / nthetaStep;
35 
36  if (e < 0)
37  e = 0.;
38  setFuncParam();
39 }
40 
42  if (onEcal) {
43  depthECAL = theGrid->ecalTotalL0(); // ECAL depth segment
44  depthGAP = theGrid->ecalHcalGapTotalL0(); // GAP depth segment
45  } else
46  depthECAL = depthGAP = 0;
47 
48  float depthHCAL = theGrid->hcalTotalL0(); // HCAL depth segment
49 
50  // maxDepth = depthECAL + depthGAP + depthHCAL - 1.0;
51  maxDepth = depthECAL + depthHCAL - 0.5;
52  depthStart = log(1. / random->flatShoot()); // starting point lambda unts
53 
54  if (depthStart > maxDepth) {
56  if (depthStart < 0.)
57  depthStart = 0.;
58  }
59 
60  if (depthStart < EcalShift)
62 
63  decal = (depthECAL + depthStart) * 0.5;
64  qstatus = false;
65  if (decal < depthECAL) {
67  // if(!qstatus)
68  // cout<<" depth rejected by getQuads(decal="<<decal<<") status="<<qstatus
69  // <<" depthECAL="<<depthECAL<<endl;
70  }
71 
73  int maxLoops = 10000;
74  for (int itheta = 0; itheta < nthetaStep; itheta++) {
75  float theta, es;
76  for (int i = 0; i <= thetaSpots[itheta]; i++) {
77  if (i == thetaSpots[itheta])
78  es = elastspot[itheta];
79  else
80  es = eHDspot;
81  float loops = 0;
82  for (int j = 0; j < maxLoops; j++) {
83  theta = (itheta + random->flatShoot()) * thetaStep;
84  if (setHit(es, theta))
85  break;
86  loops++;
87  }
88  }
89  }
90  return (true);
91 }
92 
93 bool HDRShower::setHit(float espot, float theta) {
94  float phi = 2. * M_PI * random->flatShoot(); // temporary: 1st approximation
95  float rshower = getR(); // temporary: 1st approximation
96 
97  float d = depthStart + rshower * cos(theta);
98  if (d + depthGAP > maxDepth)
99  return (false);
100 
101  // Commented (F.B) to remove a warning. Not used anywhere ?
102  // bool inHcal = !onEcal || d>depthECAL || !qstatus;
103  bool result = false;
104  if (!onEcal || d > depthECAL || !qstatus) { // in HCAL (HF or HB, HE)
105  d += depthGAP;
106  bool setHDdepth = theHcalHitMaker->setDepth(d);
107  if (setHDdepth) {
109  result = theHcalHitMaker->addHit(rshower * sin(theta), phi, 0);
110  } else
111  LogWarning("FastCalorimetry") << " setHit in HCAL failed d=" << d << " maxDepth=" << maxDepth << " onEcal'"
112  << onEcal << endl;
113  } else {
114  // bool status = theGrid->getQuads(d);
115  theGrid->setSpotEnergy(espot);
116  result = theGrid->addHit(rshower * sin(theta), phi, 0);
117  }
118  return (result);
119 }
120 
122  float p = random->flatShoot();
123  unsigned int i = 1;
124  while (rpdf[i] < p && i < R_range - 1) {
125  i++;
126  }
127  float r;
128  float dr = rpdf[i] - rpdf[i - 1];
129  if (dr != 0.0)
130  r = (float(i) + (p - rpdf[i - 1]) / dr) / lambdaHD;
131  else
132  r = float(i) / lambdaHD;
133  return (r);
134 }
135 
136 void HDRShower::thetaFunction(int nthetaStep) {
137  unsigned int i = 0;
138  while (EgridTable[i] < e && i < NEnergyScan - 1) {
139  i++;
140  }
141 
142  float amean, asig, lambda1, lambda1sig, lam21, lam21sig;
143  amean = Theta1amp[i];
144  asig = Theta1ampSig[i];
145  lambda1 = Theta1Lambda[i];
146  lambda1sig = Theta1LambdaSig[i];
147  lam21 = ThetaLam21[i];
148  lam21sig = ThetaLam21Sig[i];
149  if (i == 0)
150  i = 1; //extrapolation to the left
151  float c = (e - EgridTable[i - 1]) / (EgridTable[i] - EgridTable[i - 1]);
152 
153  amean += (Theta1amp[i] - Theta1amp[i - 1]) * c;
154  asig += (Theta1ampSig[i] - Theta1ampSig[i - 1]) * c;
155  lambda1 += (Theta1Lambda[i] - Theta1Lambda[i - 1]) * c;
156  lambda1sig += (Theta1LambdaSig[i] - Theta1LambdaSig[i - 1]) * c;
157  lam21 += (ThetaLam21[i] - ThetaLam21[i - 1]) * c;
158  lam21sig += (ThetaLam21Sig[i] - ThetaLam21Sig[i - 1]) * c;
159 
160  float a = exp(amean + asig * random->gaussShoot());
161  float L1 = lambda1 + lambda1sig * random->gaussShoot();
162  if (L1 < 0.02)
163  L1 = 0.02;
164  float L2 = L1 * (lam21 + lam21sig * random->gaussShoot());
165 
166  vector<double> pdf;
167  pdf.erase(pdf.begin(), pdf.end());
168  thetaSpots.erase(thetaSpots.begin(), thetaSpots.end());
169  elastspot.erase(elastspot.begin(), elastspot.end());
170  double sum = 0;
171  for (int it = 0; it < nthetaStep; it++) {
172  float theta = it * thetaStep;
173  float p = a * exp(L1 * theta) + exp(L2 * theta);
174  sum += p;
175  pdf.push_back(p);
176  }
177  float ntot = e / eHDspot;
178  float esum = 0;
179  for (int it = 0; it < nthetaStep; it++) {
180  float fn = ntot * pdf[it] / sum;
181  thetaSpots.push_back(int(fn));
182  elastspot.push_back((fn - int(fn)) * eHDspot);
183  }
184 
185  for (int it = 0; it < nthetaStep; it++)
186  if (elastspot[it] < EsCut) {
187  esum += elastspot[it];
188  elastspot[it] = 0;
189  }
190 
191  float en = esum / EsCut;
192  int n = int(en);
193  en = esum - n * EsCut;
194 
195  for (int ie = 0; ie <= n; ie++) {
196  int k = int(nthetaStep * random->flatShoot());
197  if (k < 0 || k > nthetaStep - 1)
198  k = k % nthetaStep;
199  if (ie == n)
200  elastspot[k] += en;
201  else
202  elastspot[k] += EsCut;
203  }
204 }
205 
209  if (onEcal)
211  else
212  lambdaEM = lambdaHD;
213 
214  if (debug)
215  LogDebug("FastCalorimetry") << "setFuncParam-> lambdaEM=" << lambdaEM << " lambdaHD=" << lambdaHD << endl;
216 
217  float _EgridTable[NEnergyScan] = {10, 20, 30, 50, 100, 300, 500};
218  float _Theta1amp[NEnergyScan] = {1.57, 2.05, 2.27, 2.52, 2.66, 2.76, 2.76};
219  float _Theta1ampSig[NEnergyScan] = {2.40, 1.50, 1.25, 1.0, 0.8, 0.52, 0.52};
220 
221  float _Theta1Lambda[NEnergyScan] = {0.086, 0.092, 0.88, 0.80, 0.0713, 0.0536, 0.0536};
222  float _Theta1LambdaSig[NEnergyScan] = {0.038, 0.037, 0.027, 0.03, 0.023, 0.018, 0.018};
223 
224  float _ThetaLam21[NEnergyScan] = {2.8, 2.44, 2.6, 2.77, 3.16, 3.56, 3.56};
225  float _ThetaLam21Sig[NEnergyScan] = {1.8, 0.97, 0.87, 0.77, 0.7, 0.49, 0.49};
226 
227  for (int i = 0; i < NEnergyScan; i++) {
228  EgridTable[i] = _EgridTable[i];
229  Theta1amp[i] = _Theta1amp[i];
230  Theta1ampSig[i] = _Theta1ampSig[i];
231  Theta1Lambda[i] = _Theta1Lambda[i];
232  Theta1LambdaSig[i] = _Theta1LambdaSig[i];
233  ThetaLam21[i] = _ThetaLam21[i];
234  ThetaLam21Sig[i] = _ThetaLam21Sig[i];
235  }
236 
237 #define lambdafit 15.05
238  float R_alfa = -0.0993 + 0.1114 * log(e);
239  float R_p = 0.589191 + 0.0463392 * log(e);
240  float R_beta_lam = (0.54134 - 0.00011148 * e) / 4.0 * lambdafit; //was fitted in 4cmbin
241  float LamOverX0 = lambdaHD / x0HD; // 10.52
242  // int R_range = 100; // 7 lambda
243  // rpdf.erase(rpdf.begin(),rpdf.end());
244 
245  rpdf[0] = 0.;
246  for (int i = 1; i < R_range; i++) {
247  float x = (float(i)) / lambdaHD;
248  float r = pow(x, R_alfa) * (R_p * exp(-R_beta_lam * x) + (1 - R_p) * exp(-LamOverX0 * R_beta_lam * x));
249  rpdf[i] = r;
250  // rpdf.push_back(r);
251  }
252 
253  for (int i = 1; i < R_range; i++)
254  rpdf[i] += rpdf[i - 1];
255  for (int i = 0; i < R_range; i++)
256  rpdf[i] /= rpdf[R_range - 1];
257 }
double ecalHcalGapTotalL0() const
ECAL-HCAL transition.
Definition: EcalHitMaker.h:91
bool addHit(double r, double phi, unsigned layer=0) override
float Theta1amp[7]
Definition: HDRShower.h:67
double lambdaHD
Definition: HDRShower.h:51
double radLenIncm() const override
Radiation length in cm.
double ecalTotalL0() const
in the ECAL
Definition: EcalHitMaker.h:85
int nthetaStep
Definition: HDRShower.h:56
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
double x0HD
Definition: HDRShower.h:51
HcalHitMaker * theHcalHitMaker
Definition: HDRShower.h:43
#define R_range
Definition: HDRShower.h:16
double interactionLength() const override
Interaction length in cm.
bool qstatus
Definition: HDRShower.h:63
float ThetaLam21[7]
Definition: HDRShower.h:71
float eHDspot
Definition: HDRShower.h:53
double depthStart
Definition: HDRShower.h:52
int onEcal
Definition: HDRShower.h:44
float Theta1ampSig[7]
Definition: HDRShower.h:68
bool addHit(double r, double phi, unsigned layer=0) override
add the hit in the HCAL in local coordinates
Definition: HcalHitMaker.cc:30
#define NEnergyScan
Definition: HDRShower.h:14
std::vector< int > thetaSpots
Definition: HDRShower.h:60
double e
Definition: HDRShower.h:45
float ThetaLam21Sig[7]
Definition: HDRShower.h:72
float Theta1LambdaSig[7]
Definition: HDRShower.h:70
void thetaFunction(int nthetaStep)
Definition: HDRShower.cc:136
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
float depthECAL
Definition: HDRShower.h:59
void setFuncParam()
Definition: HDRShower.cc:206
float EgridTable[7]
Definition: HDRShower.h:66
bool setHit(float espot, float theta)
Definition: HDRShower.cc:93
void setSpotEnergy(double e) override
Set the spot energy.
Definition: HcalHitMaker.h:26
EcalHitMaker * theGrid
Definition: HDRShower.h:42
HDShowerParametrization * theParam
Definition: HDRShower.h:41
float getR()
Definition: HDRShower.cc:121
d
Definition: ztail.py:151
double gaussShoot(double mean=0.0, double sigma=1.0) const
float thetaStep
Definition: HDRShower.h:58
#define M_PI
float EsCut
Definition: HDRShower.h:54
#define lambdafit
float EcalShift
Definition: HDRShower.h:55
#define debug
Definition: HDRShower.cc:19
HDRShower(const RandomEngineAndDistribution *engine, HDShowerParametrization *myParam, EcalHitMaker *myGrid, HcalHitMaker *myHcalHitMaker, int onECAL, double epart)
Definition: HDRShower.cc:23
float maxDepth
Definition: HDRShower.h:59
const HCALProperties * hcalProperties() const
std::vector< float > elastspot
Definition: HDRShower.h:61
bool getPads(double depth, bool inCm=false)
double hcalTotalL0() const
in the HCAL
Definition: EcalHitMaker.h:88
float rpdf[100]
Definition: HDRShower.h:62
HLT enums.
const ECALProperties * ecalProperties() const
double a
Definition: hdecay.h:119
float Theta1Lambda[7]
Definition: HDRShower.h:69
float depthGAP
Definition: HDRShower.h:59
double flatShoot(double xmin=0.0, double xmax=1.0) const
Log< level::Warning, false > LogWarning
const RandomEngineAndDistribution * random
Definition: HDRShower.h:75
float decal
Definition: HDRShower.h:64
double interactionLength() const override
Interaction length in cm: 18.5 for Standard ECAL.
Geom::Theta< T > theta() const
__shared__ uint32_t ntot
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
double lambdaEM
Definition: HDRShower.h:51
bool setDepth(double, bool inCm=false)
set the depth in X0 or Lambda0 units depending on showerType
void setSpotEnergy(double e) override
Definition: EcalHitMaker.h:112
bool computeShower()
Definition: HDRShower.cc:41
#define LogDebug(id)