test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalPulseShapes.cc
Go to the documentation of this file.
14 
15 // #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
16 #include <cmath>
17 
18 #include <iostream>
19 #include <fstream>
20 
22 : theMCParams(0),
23  theTopology(0),
24  theRecoParams(0),
25  theShapes()
26 {
27 /*
28 
29 Reco MC
30 --------------------------------------------------------------------------------------
31 000 not used (reserved)
32 101 101 hpdShape_ HPD (original version)
33 102 102 =101 HPD BV 30 volts in HBP iphi54
34 103 123 hpdShape_v2, hpdShapeMC_v2 HPD (2011. oct version)
35 104 124 hpdBV30Shape_v2, hpdBV30ShapeMC_v2 HPD bv30 in HBP iph54
36 105 125 hpdShape_v2, hpdShapeMC_v2 HPD (2011.11.12 version)
37 201 201 siPMShape_ SiPMs Zecotec shape (HO)
38 202 202 =201, SiPMs Hamamatsu shape (HO)
39 301 301 hfShape_ regular HF PMT shape
40 401 401 regular ZDC shape
41 --------------------------------------------------------------------------------------
42 
43 */
44 
45 
46  float ts1, ts2, ts3, thpd, tpre, wd1, wd2, wd3;
47 
48  // HPD Shape Version 1 (used before CMSSW5, until Oct 2011)
49  ts1=8. ; ts2=10. ; ts3=29.3; thpd=4.0; tpre=9.0; wd1=2.0; wd2=0.7; wd3=1.0;
50  computeHPDShape(ts1,ts2,ts3,thpd,tpre,wd1,wd2,wd3, hpdShape_);
51  theShapes[101] = &hpdShape_;
52  theShapes[102] = theShapes[101];
53 
54  // HPD Shape Version 2 for CMSSW 5. Nov 2011 (RECO and MC separately)
55  ts1=8. ; ts2=10. ; ts3=25.0; thpd=4.0; tpre=9.0; wd1=2.0; wd2=0.7; wd3=1.0;
56  computeHPDShape(ts1,ts2,ts3,thpd,tpre,wd1,wd2,wd3, hpdShape_v2);
57  theShapes[103] = &hpdShape_v2;
58 
59  ts1=8. ; ts2=10. ; ts3=29.3; thpd=4.0; tpre=7.0; wd1=2.0; wd2=0.7; wd3=1.0;
60  computeHPDShape(ts1,ts2,ts3,thpd,tpre,wd1,wd2,wd3, hpdShapeMC_v2);
61  theShapes[123] = &hpdShapeMC_v2;
62 
63  // HPD Shape Version 3 for CMSSW 5. Nov 2011 (RECO and MC separately)
64  ts1=8. ; ts2=19. ; ts3=29.3; thpd=4.0; tpre=9.0; wd1=2.0; wd2=0.7; wd3=0.32;
65  computeHPDShape(ts1,ts2,ts3,thpd,tpre,wd1,wd2,wd3, hpdShape_v3);
66  theShapes[105] = &hpdShape_v3;
67 
68  ts1=8. ; ts2=10. ; ts3=22.3; thpd=4.0; tpre=7.0; wd1=2.0; wd2=0.7; wd3=1.0;
69  computeHPDShape(ts1,ts2,ts3,thpd,tpre,wd1,wd2,wd3, hpdShapeMC_v3);
70  theShapes[125] = &hpdShapeMC_v3;
71 
72  // HPD with Bias Voltage 30 volts, wider pulse. (HBPlus iphi54)
73 
74  ts1=8. ; ts2=12. ; ts3=31.7; thpd=9.0; tpre=9.0; wd1=2.0; wd2=0.7; wd3=1.0;
75  computeHPDShape(ts1,ts2,ts3,thpd,tpre,wd1,wd2,wd3, hpdBV30Shape_v2);
76  theShapes[104] = &hpdBV30Shape_v2;
77 
78  ts1=8. ; ts2=12. ; ts3=31.7; thpd=9.0; tpre=9.0; wd1=2.0; wd2=0.7; wd3=1.0;
79  computeHPDShape(ts1,ts2,ts3,thpd,tpre,wd1,wd2,wd3, hpdBV30ShapeMC_v2);
81 
82  // HF and SiPM
83 
86 
87  theShapes[201] = &siPMShape_;
88  theShapes[202] = theShapes[201];
89  theShapes[301] = &hfShape_;
90  //theShapes[401] = new CaloCachedShapeIntegrator(&theZDCShape);
91 
92  /*
93  // backward-compatibility with old scheme
94  theShapes[0] = theShapes[101];
95  //FIXME "special" HB
96  theShapes[1] = theShapes[101];
97  theShapes[2] = theShapes[201];
98  theShapes[3] = theShapes[301];
99  //theShapes[4] = theShapes[401];
100  */
101 }
102 
103 
105  if (theMCParams) delete theMCParams;
106  if (theRecoParams) delete theRecoParams;
107  if (theTopology) delete theTopology;
108 }
109 
110 
112 {
114  es.get<HcalMCParamsRcd>().get(p);
115  theMCParams = new HcalMCParams(*p.product());
116 
118  es.get<HcalRecNumberingRecord>().get(htopo);
119  theTopology=new HcalTopology(*htopo);
121 
123  es.get<HcalRecoParamsRcd>().get(q);
126 
127 // std::cout<<" skdump in HcalPulseShapes::beginRun dupm MCParams "<<std::endl;
128 // std::ofstream skfile("skdumpMCParamsNewFormat.txt");
129 // HcalDbASCIIIO::dumpObject(skfile, (*theMCParams) );
130 }
131 
132 
134 {
135  if (theMCParams) delete theMCParams;
136  if (theRecoParams) delete theRecoParams;
137  if (theTopology) delete theTopology;
138 
139 
140  theMCParams = 0;
141  theRecoParams = 0;
142  theTopology = 0;
143 }
144 
145 
146 //void HcalPulseShapes::computeHPDShape()
147 void HcalPulseShapes::computeHPDShape(float ts1, float ts2, float ts3, float thpd, float tpre,
148  float wd1, float wd2, float wd3, Shape &tmphpdShape_)
149 {
150 
151  /*
152  std::cout << "o HcalPulseShapes::computeHPDShape "
153  << " ts1, ts2, ts3, thpd, tpre, w1, w2, w3 ="
154  << ts1 << ", " << ts2 << ", " << ts3 << ", "
155  << thpd << ", " << tpre << ", " << wd1 << ", " << wd2
156  << ", " << wd3 << std::endl;
157  */
158 
159 // pulse shape time constants in ns
160 /*
161  const float ts1 = 8.; // scintillation time constants : 1,2,3
162  const float ts2 = 10.;
163  const float ts3 = 29.3;
164  const float thpd = 4.; // HPD current collection drift time
165  const float tpre = 9.; // preamp time constant (refit on TB04 data)
166 
167  const float wd1 = 2.; // relative weights of decay exponents
168  const float wd2 = 0.7;
169  const float wd3 = 1.;
170 */
171  // pulse shape componnts over a range of time 0 ns to 255 ns in 1 ns steps
172  unsigned int nbin = 256;
173  tmphpdShape_.setNBin(nbin);
174  std::vector<float> ntmp(nbin,0.0); // zeroing output pulse shape
175  std::vector<float> nth(nbin,0.0); // zeroing HPD drift shape
176  std::vector<float> ntp(nbin,0.0); // zeroing Binkley preamp shape
177  std::vector<float> ntd(nbin,0.0); // zeroing Scintillator decay shape
178 
179  unsigned int i,j,k;
180  float norm;
181 
182  // HPD starts at I and rises to 2I in thpd of time
183  norm=0.0;
184  for(j=0;j<thpd && j<nbin;j++){
185  nth[j] = 1.0 + ((float)j)/thpd;
186  norm += nth[j];
187  }
188  // normalize integrated current to 1.0
189  for(j=0;j<thpd && j<nbin;j++){
190  nth[j] /= norm;
191  }
192 
193  // Binkley shape over 6 time constants
194  norm=0.0;
195  for(j=0;j<6*tpre && j<nbin;j++){
196  ntp[j] = ((float)j)*exp(-((float)(j*j))/(tpre*tpre));
197  norm += ntp[j];
198  }
199  // normalize pulse area to 1.0
200  for(j=0;j<6*tpre && j<nbin;j++){
201  ntp[j] /= norm;
202  }
203 
204 // ignore stochastic variation of photoelectron emission
205 // <...>
206 
207 // effective tile plus wave-length shifter decay time over 4 time constants
208  unsigned int tmax = 6 * (int)ts3;
209 
210  norm=0.0;
211  for(j=0;j<tmax && j<nbin;j++){
212  ntd[j] = wd1 * exp(-((float)j)/ts1) +
213  wd2 * exp(-((float)j)/ts2) +
214  wd3 * exp(-((float)j)/ts3) ;
215  norm += ntd[j];
216  }
217  // normalize pulse area to 1.0
218  for(j=0;j<tmax && j<nbin;j++){
219  ntd[j] /= norm;
220  }
221 
222  unsigned int t1,t2,t3,t4;
223  for(i=0;i<tmax && i<nbin;i++){
224  t1 = i;
225  // t2 = t1 + top*rand;
226  // ignoring jitter from optical path length
227  t2 = t1;
228  for(j=0;j<thpd && j<nbin;j++){
229  t3 = t2 + j;
230  for(k=0;k<4*tpre && k<nbin;k++){ // here "4" is set deliberately,
231  t4 = t3 + k; // as in test fortran toy MC ...
232  if(t4<nbin){
233  unsigned int ntb=t4;
234  ntmp[ntb] += ntd[i]*nth[j]*ntp[k];
235  }
236  }
237  }
238  }
239 
240  // normalize for 1 GeV pulse height
241  norm = 0.;
242  for(i=0;i<nbin;i++){
243  norm += ntmp[i];
244  }
245 
246  //cout << " Convoluted SHAPE ============== " << endl;
247  for(i=0; i<nbin; i++){
248  ntmp[i] /= norm;
249  // cout << " shape " << i << " = " << ntmp[i] << endl;
250  }
251 
252  for(i=0; i<nbin; i++){
253  tmphpdShape_.setShapeBin(i,ntmp[i]);
254  }
255 }
256 
258  // first create pulse shape over a range of time 0 ns to 255 ns in 1 ns steps
259  unsigned int nbin = 256;
260  hfShape_.setNBin(nbin);
261  std::vector<float> ntmp(nbin,0.0); //
262 
263  const float k0=0.7956; // shape parameters
264  const float p2=1.355;
265  const float p4=2.327;
266  const float p1=4.3; // position parameter
267 
268  float norm = 0.0;
269 
270  for(unsigned int j = 0; j < 25 && j < nbin; ++j){
271 
272  float r0 = j-p1;
273  float sigma0 = (r0<0) ? p2 : p2*p4;
274  r0 /= sigma0;
275  if(r0 < k0) ntmp[j] = exp(-0.5*r0*r0);
276  else ntmp[j] = exp(0.5*k0*k0-k0*r0);
277  norm += ntmp[j];
278  }
279  // normalize pulse area to 1.0
280  for(unsigned int j = 0; j < 25 && j < nbin; ++j){
281  ntmp[j] /= norm;
282  hfShape_.setShapeBin(j,ntmp[j]);
283  }
284 }
285 
286 
288 {
289 
290  unsigned int nbin = 128;
291 
292 //From Jake Anderson: numberical convolution of SiPMs WLC shapes
293  std::vector<float> nt = {
294  2.782980485851731e-6,
295  4.518134885954626e-5,
296  2.7689305197392056e-4,
297  9.18328418900969e-4,
298  .002110072599166349,
299  .003867856860331454,
300  .006120046224897771,
301  .008754774090536956,
302  0.0116469503358586,
303  .01467007449455966,
304  .01770489955229477,
305  .02064621450689512,
306  .02340678093764222,
307  .02591874610854916,
308  .02813325527435303,
309  0.0300189241965647,
310  .03155968107671164,
311  .03275234052577155,
312  .03360415306318798,
313  .03413048377960748,
314  .03435270899678218,
315  .03429637464659661,
316  .03398962975487166,
317  .03346192884394954,
318  .03274298516247742,
319  .03186195009136525,
320  .03084679116113031,
321  0.0297238406141036,
322  .02851748748929785,
323  .02724998816332392,
324  .02594137274487424,
325  .02460942736731527,
326  .02326973510736116,
327  .02193576080366117,
328  0.0206189674254987,
329  .01932895378564653,
330  0.0180736052958666,
331  .01685925112650875,
332  0.0156908225633535,
333  .01457200857138456,
334  .01350540559602467,
335  .01249265947824805,
336  .01153459805300423,
337  .01063135355597282,
338  .009782474412011936,
339  .008987026319784546,
340  0.00824368281357106,
341  .007550805679909604,
342  .006906515742762193,
343  .006308754629755056,
344  .005755338185695127,
345  .005244002229973356,
346  .004772441359900532,
347  .004338341490928299,
348  .003939406800854143,
349  0.00357338171220501,
350  0.0032380685079891,
351  .002931341133259233,
352  .002651155690306086,
353  .002395558090237333,
354  .002162689279320922,
355  .001950788415487319,
356  .001758194329648101,
357  .001583345567913682,
358  .001424779275191974,
359  .001281129147671334,
360  0.00115112265163774,
361  .001033577678808199,
362  9.273987838127585e-4,
363  8.315731274976846e-4,
364  7.451662302008696e-4,
365  6.673176219006913e-4,
366  5.972364609644049e-4,
367  5.341971801529036e-4,
368  4.775352065178378e-4,
369  4.266427928961177e-4,
370  3.8096498904225923e-4,
371  3.3999577417327287e-4,
372  3.032743659102713e-4,
373  2.703817158798329e-4,
374  2.4093719775272793e-4,
375  2.145954900503894e-4,
376  1.9104365317752797e-4,
377  1.6999839784346724e-4,
378  1.5120354022478893e-4,
379  1.3442763782650755e-4,
380  1.1946179895521507e-4,
381  1.0611765796993575e-4,
382  9.422550797617687e-5,
383  8.363258233342666e-5,
384  7.420147621931836e-5,
385  6.580869950304933e-5,
386  5.834335229919868e-5,
387  5.17059147771959e-5,
388  4.5807143072062634e-5,
389  4.0567063461299446e-5,
390  3.591405732740723e-5,
391  3.178402980354131e-5,
392  2.811965539165646e-5,
393  2.4869694240316126e-5,
394  2.1988373166730962e-5,
395  1.9434825899529382e-5,
396  1.717258740121378e-5,
397  1.5169137499243157e-5,
398  1.339548941011129e-5,
399  1.1825819079078403e-5,
400  1.0437131581057595e-5,
401  9.208961130078894e-6,
402  8.12310153137994e-6,
403  7.163364176588591e-6,
404  6.315360932244386e-6,
405  5.566309502463164e-6,
406  4.904859063429651e-6,
407  4.320934164082596e-6,
408  3.8055950719111903e-6,
409  3.350912911083174e-6,
410  2.9498580949517117e-6,
411  2.596200697612328e-6,
412  2.2844215378879293e-6,
413  2.0096328693141094e-6,
414  1.7675076766686654e-6,
415  1.5542166787225756e-6,
416  1.366372225473431e-6,
417  1.200978365778838e-6,
418  1.0553864128982371e-6,
419  9.272554464808518e-7,
420  8.145171945902259e-7,
421  7.153448381918271e-7
422  };
423 
424  siPMShape_.setNBin(nbin);
425 
426  double norm = 0.;
427  for (unsigned int j = 0; j < nbin; ++j) {
428  norm += (nt[j]>0) ? nt[j] : 0.;
429  }
430 
431  for (unsigned int j = 0; j < nbin; ++j) {
432  nt[j] /= norm;
433  siPMShape_.setShapeBin(j,nt[j]);
434  }
435 }
436 
437 // double HcalPulseShapes::gexp(double t, double A, double c, double t0, double s) {
438 // static double const root2(sqrt(2));
439 // return -A*0.5*exp(c*t+0.5*c*c*s*s-c*s)*(erf(-0.5*root2/s*(t-t0+c*s*s))-1);
440 // }
441 
442 
444 HcalPulseShapes::getShape(int shapeType) const
445 {
446 
447  // std::cout << "- HcalPulseShapes::Shape for type "<< shapeType
448  // << std::endl;
449 
450  ShapeMap::const_iterator shapeMapItr = theShapes.find(shapeType);
451  if(shapeMapItr == theShapes.end()) {
452  throw cms::Exception("HcalPulseShapes") << "unknown shapeType";
453  return hpdShape_; // should not return this, but...
454  } else {
455  return *(shapeMapItr->second);
456  }
457 }
458 
459 
461 HcalPulseShapes::shape(const HcalDetId & detId) const
462 {
463  if(!theMCParams) {
464  return defaultShape(detId);
465  }
466  int shapeType = theMCParams->getValues(detId)->signalShape();
467 
468  /*
469  int sub = detId.subdet();
470  int depth = detId.depth();
471  int inteta = detId.ieta();
472  int intphi = detId.iphi();
473 
474  std::cout << " HcalPulseShapes::shape cell:"
475  << " sub, ieta, iphi, depth = "
476  << sub << " " << inteta << " " << intphi
477  << " " << depth << " => ShapeId "<< shapeType
478  << std::endl;
479  */
480 
481  ShapeMap::const_iterator shapeMapItr = theShapes.find(shapeType);
482  if(shapeMapItr == theShapes.end()) {
483  return defaultShape(detId);
484  } else {
485  return *(shapeMapItr->second);
486  }
487 }
488 
491 {
492  if(!theRecoParams) {
493  return defaultShape(detId);
494  }
495  int shapeType = theRecoParams->getValues(detId.rawId())->pulseShapeID();
496 
497  /*
498  int sub = detId.subdet();
499  int depth = detId.depth();
500  int inteta = detId.ieta();
501  int intphi = detId.iphi();
502 
503  std::cout << ">> HcalPulseShapes::shapeForReco cell:"
504  << " sub, ieta, iphi, depth = "
505  << sub << " " << inteta << " " << intphi
506  << " " << depth << " => ShapeId "<< shapeType
507  << std::endl;
508  */
509 
510  ShapeMap::const_iterator shapeMapItr = theShapes.find(shapeType);
511  if(shapeMapItr == theShapes.end()) {
512  return defaultShape(detId);
513  } else {
514  return *(shapeMapItr->second);
515  }
516 }
517 
518 
521 {
522  edm::LogWarning("HcalPulseShapes") << "Cannot find HCAL MC Params ";
523  HcalSubdetector subdet = detId.subdet();
524  switch(subdet) {
525  case HcalBarrel:
526  return hbShape();
527  case HcalEndcap:
528  return heShape();
529  case HcalForward:
530  return hfShape();
531  case HcalOuter:
532  //FIXME doesn't look for SiPMs
533  return hoShape(false);
534  default:
535  throw cms::Exception("HcalPulseShapes") << "unknown detId";
536  break;
537  }
538 }
539 
const Shape & getShape(int shapeType) const
int i
Definition: DBlmapReader.cc:9
void setNBin(int n)
const Shape & heShape() const
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
void setShapeBin(int i, float f)
const Shape & hoShape(bool sipm=false) const
void beginRun(edm::EventSetup const &es)
const Item * getValues(DetId fId, bool throwOnFail=true) const
const Shape & shapeForReco(const HcalDetId &detId) const
const Shape & shape(const HcalDetId &detId) const
automatically figures out which shape to return
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
HcalRecoParams * theRecoParams
auto const T2 &decltype(t1.eta()) t2
Definition: deltaR.h:16
double p4[4]
Definition: TauolaWrapper.h:92
HcalSubdetector
Definition: HcalAssistant.h:31
int j
Definition: DBlmapReader.cc:9
double p2[4]
Definition: TauolaWrapper.h:90
int nt
Definition: AMPTWrapper.h:32
static const double tmax[3]
const Shape & defaultShape(const HcalDetId &detId) const
in case of conditions problems
const Shape & hfShape() const
void computeHPDShape(float, float, float, float, float, float, float, float, Shape &)
const HcalTopology * theTopology
HcalMCParams * theMCParams
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
unsigned int signalShape() const
Definition: HcalMCParam.h:40
const Shape & hbShape() const
double p1[4]
Definition: TauolaWrapper.h:89
void setTopo(const HcalTopology *topo)