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<IdealGeometryRecord>().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  unsigned int nbin = 100; // to avoid big drop of integral for previous 512
290  // due to negative afterpulse (May 6, 2013. S.Abdullin)
291  siPMShape_.setNBin(nbin);
292  std::vector<float> nt(nbin,0.0); //
293 
294  double norm = 0.;
295  for (unsigned int j = 0; j < nbin; ++j) {
296  if (j <= 31.)
297  nt[j] = 2.15*j;
298  else if ((j > 31) && (j <= 96))
299  nt[j] = 102.1 - 1.12*j;
300  else
301  nt[j] = 0.0076*j - 6.4;
302  norm += (nt[j]>0) ? nt[j] : 0.;
303  }
304 
305  for (unsigned int j = 0; j < nbin; ++j) {
306  nt[j] /= norm;
307  siPMShape_.setShapeBin(j,nt[j]);
308  }
309 }
310 
311 
313 HcalPulseShapes::getShape(int shapeType) const
314 {
315 
316  // std::cout << "- HcalPulseShapes::Shape for type "<< shapeType
317  // << std::endl;
318 
319  ShapeMap::const_iterator shapeMapItr = theShapes.find(shapeType);
320  if(shapeMapItr == theShapes.end()) {
321  throw cms::Exception("HcalPulseShapes") << "unknown shapeType";
322  return hpdShape_; // should not return this, but...
323  } else {
324  return *(shapeMapItr->second);
325  }
326 }
327 
328 
330 HcalPulseShapes::shape(const HcalDetId & detId) const
331 {
332  if(!theMCParams) {
333  return defaultShape(detId);
334  }
335  int shapeType = theMCParams->getValues(detId)->signalShape();
336 
337  /*
338  int sub = detId.subdet();
339  int depth = detId.depth();
340  int inteta = detId.ieta();
341  int intphi = detId.iphi();
342 
343  std::cout << " HcalPulseShapes::shape cell:"
344  << " sub, ieta, iphi, depth = "
345  << sub << " " << inteta << " " << intphi
346  << " " << depth << " => ShapeId "<< shapeType
347  << std::endl;
348  */
349 
350  ShapeMap::const_iterator shapeMapItr = theShapes.find(shapeType);
351  if(shapeMapItr == theShapes.end()) {
352  return defaultShape(detId);
353  } else {
354  return *(shapeMapItr->second);
355  }
356 }
357 
360 {
361  if(!theRecoParams) {
362  return defaultShape(detId);
363  }
364  int shapeType = theRecoParams->getValues(detId.rawId())->pulseShapeID();
365 
366  /*
367  int sub = detId.subdet();
368  int depth = detId.depth();
369  int inteta = detId.ieta();
370  int intphi = detId.iphi();
371 
372  std::cout << ">> HcalPulseShapes::shapeForReco cell:"
373  << " sub, ieta, iphi, depth = "
374  << sub << " " << inteta << " " << intphi
375  << " " << depth << " => ShapeId "<< shapeType
376  << std::endl;
377  */
378 
379  ShapeMap::const_iterator shapeMapItr = theShapes.find(shapeType);
380  if(shapeMapItr == theShapes.end()) {
381  return defaultShape(detId);
382  } else {
383  return *(shapeMapItr->second);
384  }
385 }
386 
387 
390 {
391  edm::LogWarning("HcalPulseShapes") << "Cannot find HCAL MC Params ";
392  HcalSubdetector subdet = detId.subdet();
393  switch(subdet) {
394  case HcalBarrel:
395  return hbShape();
396  case HcalEndcap:
397  return heShape();
398  case HcalForward:
399  return hfShape();
400  case HcalOuter:
401  //FIXME doesn't look for SiPMs
402  return hoShape(false);
403  default:
404  throw cms::Exception("HcalPulseShapes") << "unknown detId";
405  break;
406  }
407 }
408 
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:32
void setShapeBin(int i, float f)
const Shape & hoShape(bool sipm=false) const
void beginRun(edm::EventSetup const &es)
void setTopo(const HcalTopology *topo) const
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:45
auto const T2 &decltype(t1.eta()) t2
Definition: deltaR.h:18
double p4[4]
Definition: TauolaWrapper.h:92
HcalSubdetector
Definition: HcalAssistant.h:32
int j
Definition: DBlmapReader.cc:9
double p2[4]
Definition: TauolaWrapper.h:90
int nt
Definition: AMPTWrapper.h:32
int k[5][pyjets_maxn]
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 HcalRecoParams * theRecoParams
const HcalTopology * theTopology
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
const HcalMCParams * theMCParams
unsigned int signalShape() const
Definition: HcalMCParam.h:38
const Shape & hbShape() const
double p1[4]
Definition: TauolaWrapper.h:89