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