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  float esum = e;
75  for (int itheta = 0; itheta < nthetaStep; itheta++) {
76  float theta, es;
77  for (int i = 0; i <= thetaSpots[itheta]; i++) {
78  if (i == thetaSpots[itheta])
79  es = elastspot[itheta];
80  else
81  es = eHDspot;
82  float loops = 0;
83  for (int j = 0; j < maxLoops; j++) {
84  theta = (itheta + random->flatShoot()) * thetaStep;
85  if (setHit(es, theta))
86  break;
87  loops++;
88  }
89  esum -= es; // to check only
90  }
91  }
92  return (true);
93 }
94 
95 bool HDRShower::setHit(float espot, float theta) {
96  float phi = 2. * M_PI * random->flatShoot(); // temporary: 1st approximation
97  float rshower = getR(); // temporary: 1st approximation
98 
99  float d = depthStart + rshower * cos(theta);
100  if (d + depthGAP > maxDepth)
101  return (false);
102 
103  // Commented (F.B) to remove a warning. Not used anywhere ?
104  // bool inHcal = !onEcal || d>depthECAL || !qstatus;
105  bool result = false;
106  if (!onEcal || d > depthECAL || !qstatus) { // in HCAL (HF or HB, HE)
107  d += depthGAP;
108  bool setHDdepth = theHcalHitMaker->setDepth(d);
109  if (setHDdepth) {
111  result = theHcalHitMaker->addHit(rshower * sin(theta), phi, 0);
112  } else
113  LogWarning("FastCalorimetry") << " setHit in HCAL failed d=" << d << " maxDepth=" << maxDepth << " onEcal'"
114  << onEcal << endl;
115  } else {
116  // bool status = theGrid->getQuads(d);
117  theGrid->setSpotEnergy(espot);
118  result = theGrid->addHit(rshower * sin(theta), phi, 0);
119  }
120  return (result);
121 }
122 
124  float p = random->flatShoot();
125  unsigned int i = 1;
126  while (rpdf[i] < p && i < R_range - 1) {
127  i++;
128  }
129  float r;
130  float dr = rpdf[i] - rpdf[i - 1];
131  if (dr != 0.0)
132  r = (float(i) + (p - rpdf[i - 1]) / dr) / lambdaHD;
133  else
134  r = float(i) / lambdaHD;
135  return (r);
136 }
137 
138 void HDRShower::thetaFunction(int nthetaStep) {
139  unsigned int i = 0;
140  while (EgridTable[i] < e && i < NEnergyScan - 1) {
141  i++;
142  }
143 
144  float amean, asig, lambda1, lambda1sig, lam21, lam21sig;
145  amean = Theta1amp[i];
146  asig = Theta1ampSig[i];
147  lambda1 = Theta1Lambda[i];
148  lambda1sig = Theta1LambdaSig[i];
149  lam21 = ThetaLam21[i];
150  lam21sig = ThetaLam21Sig[i];
151  if (i == 0)
152  i = 1; //extrapolation to the left
153  float c = (e - EgridTable[i - 1]) / (EgridTable[i] - EgridTable[i - 1]);
154 
155  amean += (Theta1amp[i] - Theta1amp[i - 1]) * c;
156  asig += (Theta1ampSig[i] - Theta1ampSig[i - 1]) * c;
157  lambda1 += (Theta1Lambda[i] - Theta1Lambda[i - 1]) * c;
158  lambda1sig += (Theta1LambdaSig[i] - Theta1LambdaSig[i - 1]) * c;
159  lam21 += (ThetaLam21[i] - ThetaLam21[i - 1]) * c;
160  lam21sig += (ThetaLam21Sig[i] - ThetaLam21Sig[i - 1]) * c;
161 
162  float a = exp(amean + asig * random->gaussShoot());
163  float L1 = lambda1 + lambda1sig * random->gaussShoot();
164  if (L1 < 0.02)
165  L1 = 0.02;
166  float L2 = L1 * (lam21 + lam21sig * random->gaussShoot());
167 
168  vector<double> pdf;
169  pdf.erase(pdf.begin(), pdf.end());
170  thetaSpots.erase(thetaSpots.begin(), thetaSpots.end());
171  elastspot.erase(elastspot.begin(), elastspot.end());
172  double sum = 0;
173  for (int it = 0; it < nthetaStep; it++) {
174  float theta = it * thetaStep;
175  float p = a * exp(L1 * theta) + exp(L2 * theta);
176  sum += p;
177  pdf.push_back(p);
178  }
179  float ntot = e / eHDspot;
180  float esum = 0;
181  for (int it = 0; it < nthetaStep; it++) {
182  float fn = ntot * pdf[it] / sum;
183  thetaSpots.push_back(int(fn));
184  elastspot.push_back((fn - int(fn)) * eHDspot);
185  }
186 
187  for (int it = 0; it < nthetaStep; it++)
188  if (elastspot[it] < EsCut) {
189  esum += elastspot[it];
190  elastspot[it] = 0;
191  }
192 
193  float en = esum / EsCut;
194  int n = int(en);
195  en = esum - n * EsCut;
196 
197  for (int ie = 0; ie <= n; ie++) {
198  int k = int(nthetaStep * random->flatShoot());
199  if (k < 0 || k > nthetaStep - 1)
200  k = k % nthetaStep;
201  if (ie == n)
202  elastspot[k] += en;
203  else
204  elastspot[k] += EsCut;
205  }
206 }
207 
211  if (onEcal)
213  else
214  lambdaEM = lambdaHD;
215 
216  if (debug)
217  LogDebug("FastCalorimetry") << "setFuncParam-> lambdaEM=" << lambdaEM << " lambdaHD=" << lambdaHD << endl;
218 
219  float _EgridTable[NEnergyScan] = {10, 20, 30, 50, 100, 300, 500};
220  float _Theta1amp[NEnergyScan] = {1.57, 2.05, 2.27, 2.52, 2.66, 2.76, 2.76};
221  float _Theta1ampSig[NEnergyScan] = {2.40, 1.50, 1.25, 1.0, 0.8, 0.52, 0.52};
222 
223  float _Theta1Lambda[NEnergyScan] = {0.086, 0.092, 0.88, 0.80, 0.0713, 0.0536, 0.0536};
224  float _Theta1LambdaSig[NEnergyScan] = {0.038, 0.037, 0.027, 0.03, 0.023, 0.018, 0.018};
225 
226  float _ThetaLam21[NEnergyScan] = {2.8, 2.44, 2.6, 2.77, 3.16, 3.56, 3.56};
227  float _ThetaLam21Sig[NEnergyScan] = {1.8, 0.97, 0.87, 0.77, 0.7, 0.49, 0.49};
228 
229  for (int i = 0; i < NEnergyScan; i++) {
230  EgridTable[i] = _EgridTable[i];
231  Theta1amp[i] = _Theta1amp[i];
232  Theta1ampSig[i] = _Theta1ampSig[i];
233  Theta1Lambda[i] = _Theta1Lambda[i];
234  Theta1LambdaSig[i] = _Theta1LambdaSig[i];
235  ThetaLam21[i] = _ThetaLam21[i];
236  ThetaLam21Sig[i] = _ThetaLam21Sig[i];
237  }
238 
239 #define lambdafit 15.05
240  float R_alfa = -0.0993 + 0.1114 * log(e);
241  float R_p = 0.589191 + 0.0463392 * log(e);
242  float R_beta_lam = (0.54134 - 0.00011148 * e) / 4.0 * lambdafit; //was fitted in 4cmbin
243  float LamOverX0 = lambdaHD / x0HD; // 10.52
244  // int R_range = 100; // 7 lambda
245  // rpdf.erase(rpdf.begin(),rpdf.end());
246 
247  rpdf[0] = 0.;
248  for (int i = 1; i < R_range; i++) {
249  float x = (float(i)) / lambdaHD;
250  float r = pow(x, R_alfa) * (R_p * exp(-R_beta_lam * x) + (1 - R_p) * exp(-LamOverX0 * R_beta_lam * x));
251  rpdf[i] = r;
252  // rpdf.push_back(r);
253  }
254 
255  for (int i = 1; i < R_range; i++)
256  rpdf[i] += rpdf[i - 1];
257  for (int i = 0; i < R_range; i++)
258  rpdf[i] /= rpdf[R_range - 1];
259 }
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:138
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
float depthECAL
Definition: HDRShower.h:59
void setFuncParam()
Definition: HDRShower.cc:208
float EgridTable[7]
Definition: HDRShower.h:66
bool setHit(float espot, float theta)
Definition: HDRShower.cc:95
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:123
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)