CMS 3D CMS Logo

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