CMS 3D CMS Logo

HcalSimpleRecAlgo.cc
Go to the documentation of this file.
8 
9 #include <algorithm>
10 #include <cmath>
11 
12 //--- temporary for printouts
13 // #include<iostream>
14 
15 constexpr double MaximumFractionalError = 0.002; // 0.2% error allowed from this source
18 
19 HcalSimpleRecAlgo::HcalSimpleRecAlgo(bool correctForTimeslew, bool correctForPulse, float phaseNS) :
20  correctForTimeslew_(correctForTimeslew),
21  correctForPulse_(correctForPulse),
22  phaseNS_(phaseNS), runnum_(0), setLeakCorrection_(false), puCorrMethod_(0)
23 {
24  pulseCorr_ = std::make_unique<HcalPulseContainmentManager>(MaximumFractionalError);
25  pedSubFxn_ = std::make_unique<PedestalSub>();
26  hltOOTpuCorr_ = std::make_unique<HcalDeterministicFit>();
27 }
28 
29 
31 {
32  pulseCorr_->beginRun(es);
33 }
34 
35 
37 {
38  pulseCorr_->endRun();
39 }
40 
41 
43 }
44 
45 void HcalSimpleRecAlgo::setRecoParams(bool correctForTimeslew, bool correctForPulse, bool setLeakCorrection, int pileupCleaningID, float phaseNS){
47  correctForPulse_=correctForPulse;
48  phaseNS_=phaseNS;
50  pileupCleaningID_=pileupCleaningID;
51 }
52 
53 void HcalSimpleRecAlgo::setpuCorrParams(bool iPedestalConstraint, bool iTimeConstraint,bool iAddPulseJitter,
54  bool iApplyTimeSlew,double iTS4Min, const std::vector<double> & iTS4Max,
55  double iPulseJitter,
56  double iTimeMean, double iTimeSig, double iTimeSigSiPM,
57  double iPedMean, double iPedSig, double iPedSigSiPM,
58  double iNoise, double iNoiseSiPM,
59  double iTMin,double iTMax,
60  const std::vector<double> & its4Chi2, int iFitTimes) {
61  if( iPedestalConstraint ) assert ( iPedSig );
62  if( iTimeConstraint ) assert( iTimeSig );
63  psFitOOTpuCorr_->setPUParams(iPedestalConstraint,iTimeConstraint,iAddPulseJitter,iApplyTimeSlew,
64  iTS4Min, iTS4Max, iPulseJitter,iTimeMean,iTimeSig,iTimeSigSiPM,iPedMean,iPedSig,iPedSigSiPM,iNoise,iNoiseSiPM,iTMin,iTMax,its4Chi2,
65  HcalTimeSlew::Medium, iFitTimes);
66 
67  psFitOOTpuCorr_->setChi2Term(1); // isHPD all the time
68 
69 // int shapeNum = HPDShapev3MCNum;
70 // psFitOOTpuCorr_->setPulseShapeTemplate(theHcalPulseShapes_.getShape(shapeNum));
71 }
72 
73 void HcalSimpleRecAlgo::setMeth3Params( bool iApplyTimeSlew, float iPedSubThreshold, int iTimeSlewParsType, std::vector<double> iTimeSlewPars, double irespCorrM3) {
74 
75  pedSubFxn_->init(0, iPedSubThreshold, 0.0);
76  hltOOTpuCorr_->init((HcalTimeSlew::ParaSource)iTimeSlewParsType, HcalTimeSlew::Medium, iApplyTimeSlew, *pedSubFxn_, iTimeSlewPars,irespCorrM3);
77 
78 }
79 
81  runnum_ = runnum;
82  if( puCorrMethod_ ==2 ){
83  int shapeNum = HPDShapev3MCNum;
84  if( runnum_ > 0 ){
85  shapeNum = HPDShapev3DataNum;
86  }
87  bool isHPD=true;
88  psFitOOTpuCorr_->setPulseShapeTemplate(theHcalPulseShapes_.getShape(shapeNum),isHPD);
89  }
90 }
91 
93 
95  boost::shared_ptr<AbsOOTPileupCorrection> corr)
96 {
98 }
99 
101  boost::shared_ptr<AbsOOTPileupCorrection> corr)
102 {
104 }
105 
107  boost::shared_ptr<AbsOOTPileupCorrection> corr)
108 {
110 }
111 
112 void HcalSimpleRecAlgo::setBXInfo(const BunchXParameter* info,
113  const unsigned lenInfo)
114 {
116  lenBunchCrossingInfo_ = lenInfo;
117 }
118 
120 static float timeshift_ns_hf(float wpksamp);
121 
123 static float leakCorr(double energy);
124 
125 
127  template<class Digi>
128  inline float recoHFTime(const Digi& digi, const int maxI, const double amp_fC,
129  const bool slewCorrect, double maxA, float t0, float t2)
130  {
131  // Handle negative excursions by moving "zero":
132  float zerocorr=std::min(t0,t2);
133  if (zerocorr<0.f) {
134  t0 -= zerocorr;
135  t2 -= zerocorr;
136  maxA -= zerocorr;
137  }
138 
139  // pair the peak with the larger of the two neighboring time samples
140  float wpksamp=0.f;
141  if (t0>t2) {
142  wpksamp = t0+maxA;
143  if (wpksamp != 0.f) wpksamp = maxA/wpksamp;
144  } else {
145  wpksamp = maxA+t2;
146  if (wpksamp != 0.f) wpksamp = 1.+(t2/wpksamp);
147  }
148 
149  float time = (maxI - digi.presamples())*25.0 + timeshift_ns_hf(wpksamp);
150 
151  if (slewCorrect && amp_fC > 0.0) {
152  // -5.12327 - put in calibs.timecorr()
153  double tslew=exp(0.337681-5.94689e-4*amp_fC)+exp(2.44628-1.34888e-2*amp_fC);
154  time -= (float)tslew;
155  }
156 
157  return time;
158  }
159 
160 
161  template<class Digi>
162  inline void removePileup(const Digi& digi, const HcalCoder& coder,
163  const HcalCalibrations& calibs,
164  const int ifirst, const int n,
165  const bool pulseCorrect,
167  const AbsOOTPileupCorrection* pileupCorrection,
168  const BunchXParameter* bxInfo, const unsigned lenInfo,
169  double* p_maxA, double* p_ampl, double* p_uncorr_ampl,
170  double* p_fc_ampl, int* p_nRead, int* p_maxI,
171  bool* leakCorrApplied, float* p_t0, float* p_t2)
172  {
173  CaloSamples cs;
174  coder.adc2fC(digi,cs);
175  const int nRead = cs.size();
176  const int iStop = std::min(nRead, n + ifirst);
177 
178  // Signal energy will be calculated both with
179  // and without OOT pileup corrections. Try to
180  // arrange the calculations so that we do not
181  // repeat them.
182  double uncorrectedEnergy[CaloSamples::MAXSAMPLES] {}, buf[CaloSamples::MAXSAMPLES] {};
183  double* correctedEnergy = 0;
184  double fc_ampl = 0.0, corr_fc_ampl = 0.0;
185  bool pulseShapeCorrApplied = false, readjustTiming = false;
186  *leakCorrApplied = false;
187 
188  if (pileupCorrection)
189  {
190  correctedEnergy = &buf[0];
191 
192  double correctionInput[CaloSamples::MAXSAMPLES] {};
193  double gains[CaloSamples::MAXSAMPLES] {};
194 
195  for (int i=0; i<nRead; ++i)
196  {
197  const int capid = digi[i].capid();
198  correctionInput[i] = cs[i] - calibs.pedestal(capid);
199  gains[i] = calibs.respcorrgain(capid);
200  }
201 
202  for (int i=ifirst; i<iStop; ++i)
203  fc_ampl += correctionInput[i];
204 
205  const bool useGain = pileupCorrection->inputIsEnergy();
206  for (int i=0; i<nRead; ++i)
207  {
208  uncorrectedEnergy[i] = correctionInput[i]*gains[i];
209  if (useGain)
210  correctionInput[i] = uncorrectedEnergy[i];
211  }
212 
213  pileupCorrection->apply(digi.id(), correctionInput, nRead,
214  bxInfo, lenInfo, ifirst, n,
215  correctedEnergy, CaloSamples::MAXSAMPLES,
216  &pulseShapeCorrApplied, leakCorrApplied,
217  &readjustTiming);
218  if (useGain)
219  {
220  // Gain factors have been already applied.
221  // Divide by them for accumulating corr_fc_ampl.
222  for (int i=ifirst; i<iStop; ++i)
223  if (gains[i])
224  corr_fc_ampl += correctedEnergy[i]/gains[i];
225  }
226  else
227  {
228  for (int i=ifirst; i<iStop; ++i)
229  corr_fc_ampl += correctedEnergy[i];
230  for (int i=0; i<nRead; ++i)
231  correctedEnergy[i] *= gains[i];
232  }
233  }
234  else
235  {
236  correctedEnergy = &uncorrectedEnergy[0];
237 
238  // In this situation, we do not need to process all time slices
239  const int istart = std::max(ifirst - 1, 0);
240  const int iend = std::min(n + ifirst + 1, nRead);
241  for (int i=istart; i<iend; ++i)
242  {
243  const int capid = digi[i].capid();
244  float ta = cs[i] - calibs.pedestal(capid);
245  if (i >= ifirst && i < iStop)
246  fc_ampl += ta;
247  ta *= calibs.respcorrgain(capid);
248  uncorrectedEnergy[i] = ta;
249  }
250  corr_fc_ampl = fc_ampl;
251  }
252 
253  // Uncorrected and corrected energies
254  double ampl = 0.0, corr_ampl = 0.0;
255  for (int i=ifirst; i<iStop; ++i)
256  {
257  ampl += uncorrectedEnergy[i];
258  corr_ampl += correctedEnergy[i];
259  }
260 
261  // Apply phase-based amplitude correction:
262  if (corr && pulseCorrect)
263  {
264  ampl *= corr->getCorrection(fc_ampl);
265  if (pileupCorrection)
266  {
267  if (!pulseShapeCorrApplied)
268  corr_ampl *= corr->getCorrection(corr_fc_ampl);
269  }
270  else
271  corr_ampl = ampl;
272  }
273 
274  // Which energies we want to use for timing?
275  const double *etime = readjustTiming ? &correctedEnergy[0] : &uncorrectedEnergy[0];
276  int maxI = -1; double maxA = -1.e300;
277  for (int i=ifirst; i<iStop; ++i)
278  if (etime[i] > maxA)
279  {
280  maxA = etime[i];
281  maxI = i;
282  }
283 
284  // Fill out the output
285  *p_maxA = maxA;
286  *p_ampl = corr_ampl;
287  *p_uncorr_ampl = ampl;
288  *p_fc_ampl = readjustTiming ? corr_fc_ampl : fc_ampl;
289  *p_nRead = nRead;
290  *p_maxI = maxI;
291 
292  if (maxI <= 0 || maxI >= (nRead-1))
293  {
294  LogDebug("HCAL Pulse") << "HcalSimpleRecAlgoImpl::removePileup :"
295  << " Invalid max amplitude position, "
296  << " max Amplitude: " << maxI
297  << " first: " << ifirst
298  << " last: " << ifirst + n
299  << std::endl;
300  *p_t0 = 0.f;
301  *p_t2 = 0.f;
302  }
303  else
304  {
305  *p_t0 = etime[maxI - 1];
306  *p_t2 = etime[maxI + 1];
307  }
308  }
309 
310 
311  template<class Digi, class RecHit>
312  inline RecHit reco(const Digi& digi, const HcalCoder& coder,
313  const HcalCalibrations& calibs,
314  const int ifirst, const int n, const bool slewCorrect,
315  const bool pulseCorrect, const HcalPulseContainmentCorrection* corr,
316  const HcalTimeSlew::BiasSetting slewFlavor,
317  const int runnum, const bool useLeak,
318  const AbsOOTPileupCorrection* pileupCorrection,
319  const BunchXParameter* bxInfo, const unsigned lenInfo, const int puCorrMethod, const PulseShapeFitOOTPileupCorrection * psFitOOTpuCorr, HcalDeterministicFit * hltOOTpuCorr, PedestalSub * hltPedSub /* whatever don't know what to do with the pointer...*/)// const on end
320  {
321  double fc_ampl =0, ampl =0, uncorr_ampl =0, m3_ampl =0, maxA = -1.e300;
322  int nRead = 0, maxI = -1;
323  bool leakCorrApplied = false;
324  float t0 =0, t2 =0;
325  float time = -9999;
326  float m3_time = -9999;
327 
328 // Disable method 1 inside the removePileup function this way!
329 // Some code in removePileup does NOT do pileup correction & to make sure maximum share of code
330  const AbsOOTPileupCorrection * inputAbsOOTpuCorr = ( puCorrMethod == 1 ? pileupCorrection: 0 );
331 
332  removePileup(digi, coder, calibs, ifirst, n,
333  pulseCorrect, corr, inputAbsOOTpuCorr,
334  bxInfo, lenInfo, &maxA, &ampl,
335  &uncorr_ampl, &fc_ampl, &nRead, &maxI,
336  &leakCorrApplied, &t0, &t2);
337 
338  if (maxI > 0 && maxI < (nRead - 1))
339  {
340  // Handle negative excursions by moving "zero":
341  float minA=t0;
342  if (maxA<minA) minA=maxA;
343  if (t2<minA) minA=t2;
344  if (minA<0) { maxA-=minA; t0-=minA; t2-=minA; } // positivizes all samples
345 
346  float wpksamp = (t0 + maxA + t2);
347  if (wpksamp!=0) wpksamp=(maxA + 2.0*t2) / wpksamp;
348  time = (maxI - digi.presamples())*25.0 + timeshift_ns_hbheho(wpksamp);
349 
350  if (slewCorrect) time-=HcalTimeSlew::delay(std::max(1.0,fc_ampl),slewFlavor);
351 
352  time=time-calibs.timecorr(); // time calibration
353  }
354 
355  // Note that uncorr_ampl is always set from outside of method 2!
356  if( puCorrMethod == 2 ){
357 
358  bool useTriple=false;
359  float chi2=-1;
360 
361  CaloSamples cs;
362  coder.adc2fC(digi,cs);
363  std::vector<int> capidvec;
364  for(int ip=0; ip<cs.size(); ip++){
365  const int capid = digi[ip].capid();
366  capidvec.push_back(capid);
367  }
368  psFitOOTpuCorr->apply(cs, capidvec, calibs, ampl, time, useTriple,chi2);
369  }
370 
371  // S. Brandt - Feb 19th : Adding Section for HLT
372  // Run "Method 3" all the time.
373  {
374 
375  CaloSamples cs;
376  coder.adc2fC(digi,cs);
377  std::vector<int> capidvec;
378  for(int ip=0; ip<cs.size(); ip++){
379  const int capid = digi[ip].capid();
380  capidvec.push_back(capid);
381  }
382  hltOOTpuCorr->apply(cs, capidvec, calibs, digi, m3_ampl,m3_time);
383  if (puCorrMethod == 3) {ampl = m3_ampl; time=m3_time;}
384  }
385 
386  // Temporary hack to apply energy-dependent corrections to some HB- cells
387  if (runnum > 0) {
388  const HcalDetId& cell = digi.id();
389  if (cell.subdet() == HcalBarrel) {
390  const int ieta = cell.ieta();
391  const int iphi = cell.iphi();
392  uncorr_ampl *= hbminus_special_ecorr(ieta, iphi, uncorr_ampl, runnum);
393  ampl *= hbminus_special_ecorr(ieta, iphi, ampl, runnum);
394  m3_ampl *= hbminus_special_ecorr(ieta, iphi, m3_ampl, runnum);
395  }
396  }
397 
398  // Correction for a leak to pre-sample
399  if(useLeak && !leakCorrApplied) {
400  uncorr_ampl *= leakCorr(uncorr_ampl);
401  if (puCorrMethod < 2)
402  ampl *= leakCorr(ampl);
403  }
404 
405  RecHit rh(digi.id(),ampl,time);
406  setRawEnergy(rh, static_cast<float>(uncorr_ampl));
407  setAuxEnergy(rh, static_cast<float>(m3_ampl));
408  return rh;
409  }
410 
411  template<class Digi, class RecHit>
412  inline RecHit recoHBHE(const Digi& digi, const HcalCoder& coder,
413  const HcalCalibrations& calibs,
414  const int ifirst, const int n, const bool slewCorrect,
415  const bool pulseCorrect, const HcalPulseContainmentCorrection* corr,
416  const HcalTimeSlew::BiasSetting slewFlavor,
417  const int runnum, const bool useLeak,
418  const AbsOOTPileupCorrection* pileupCorrection,
419  const BunchXParameter* bxInfo, const unsigned lenInfo, const int puCorrMethod, const PulseShapeFitOOTPileupCorrection * psFitOOTpuCorr, HcalDeterministicFit * hltOOTpuCorr, PedestalSub * hltPedSub)// const on end
420  {
421  double fc_ampl =0, ampl =0, uncorr_ampl =0, m3_ampl =0, maxA = -1.e300;
422  int nRead = 0, maxI = -1;
423  bool leakCorrApplied = false;
424  float t0 =0, t2 =0;
425  float time = -9999;
426  bool useTriple = false;
427  float chi2 = -1;
428 
429  // Disable method 1 inside the removePileup function this way!
430  // Some code in removePileup does NOT do pileup correction & to make sure maximum share of code
431  const AbsOOTPileupCorrection * inputAbsOOTpuCorr = ( puCorrMethod == 1 ? pileupCorrection: 0 );
432 
433  removePileup(digi, coder, calibs, ifirst, n,
434  pulseCorrect, corr, inputAbsOOTpuCorr,
435  bxInfo, lenInfo, &maxA, &ampl,
436  &uncorr_ampl, &fc_ampl, &nRead, &maxI,
437  &leakCorrApplied, &t0, &t2);
438 
439  if (maxI > 0 && maxI < (nRead - 1))
440  {
441  // Handle negative excursions by moving "zero":
442  float minA=t0;
443  if (maxA<minA) minA=maxA;
444  if (t2<minA) minA=t2;
445  if (minA<0) { maxA-=minA; t0-=minA; t2-=minA; } // positivizes all samples
446 
447  float wpksamp = (t0 + maxA + t2);
448  if (wpksamp!=0) wpksamp=(maxA + 2.0*t2) / wpksamp;
449  time = (maxI - digi.presamples())*25.0 + timeshift_ns_hbheho(wpksamp);
450 
451  if (slewCorrect) time-=HcalTimeSlew::delay(std::max(1.0,fc_ampl),slewFlavor);
452 
453  time=time-calibs.timecorr(); // time calibration
454  }
455 
456  // Note that uncorr_ampl is always set from outside of method 2!
457  if( puCorrMethod == 2 ){
458 
459  CaloSamples cs;
460  coder.adc2fC(digi,cs);
461  std::vector<int> capidvec;
462  for(int ip=0; ip<cs.size(); ip++){
463  const int capid = digi[ip].capid();
464  capidvec.push_back(capid);
465  }
466  psFitOOTpuCorr->apply(cs, capidvec, calibs, ampl, time, useTriple,chi2);
467  }
468 
469  // S. Brandt - Feb 19th : Adding Section for HLT
470  // Run "Method 3" all the time.
471  {
472 
473  CaloSamples cs;
474  coder.adc2fC(digi,cs);
475  std::vector<int> capidvec;
476  for(int ip=0; ip<cs.size(); ip++){
477  const int capid = digi[ip].capid();
478  capidvec.push_back(capid);
479  }
480 
481  float m3_time=0;
482 
483  hltOOTpuCorr->apply(cs, capidvec, calibs, digi, m3_ampl, m3_time);
484  if (puCorrMethod == 3) { ampl = m3_ampl; time = m3_time; }
485 
486  }
487 
488  // Temporary hack to apply energy-dependent corrections to some HB- cells
489  if (runnum > 0) {
490  const HcalDetId& cell = digi.id();
491  if (cell.subdet() == HcalBarrel) {
492  const int ieta = cell.ieta();
493  const int iphi = cell.iphi();
494  uncorr_ampl *= hbminus_special_ecorr(ieta, iphi, uncorr_ampl, runnum);
495  ampl *= hbminus_special_ecorr(ieta, iphi, ampl, runnum);
496  m3_ampl *= hbminus_special_ecorr(ieta, iphi, m3_ampl, runnum);
497  }
498  }
499 
500  // Correction for a leak to pre-sample
501  if(useLeak && !leakCorrApplied) {
502  uncorr_ampl *= leakCorr(uncorr_ampl);
503  if (puCorrMethod < 2)
504  ampl *= leakCorr(ampl);
505  }
506 
507  HBHERecHit rh(digi.id(),ampl,time);
508  if(useTriple)
509  {
511  }
512  rh.setChiSquared(chi2);
513  setRawEnergy(rh, static_cast<float>(uncorr_ampl));
514  setAuxEnergy(rh, static_cast<float>(m3_ampl));
515  return rh;
516  }
517 }
518 
519 
520 HBHERecHit HcalSimpleRecAlgo::reconstruct(const HBHEDataFrame& digi, int first, int toadd, const HcalCoder& coder, const HcalCalibrations& calibs) const {
521  return HcalSimpleRecAlgoImpl::recoHBHE<HBHEDataFrame,HBHERecHit>(digi,coder,calibs,
523  pulseCorr_->get(digi.id(), toadd, phaseNS_),
526  hbhePileupCorr_.get(),
528 }
529 
530 
531 HORecHit HcalSimpleRecAlgo::reconstruct(const HODataFrame& digi, int first, int toadd, const HcalCoder& coder, const HcalCalibrations& calibs) const {
532  return HcalSimpleRecAlgoImpl::reco<HODataFrame,HORecHit>(digi,coder,calibs,
534  pulseCorr_->get(digi.id(), toadd, phaseNS_),
536  runnum_, false, hoPileupCorr_.get(),
538 }
539 
540 
541 HcalCalibRecHit HcalSimpleRecAlgo::reconstruct(const HcalCalibDataFrame& digi, int first, int toadd, const HcalCoder& coder, const HcalCalibrations& calibs) const {
542  return HcalSimpleRecAlgoImpl::reco<HcalCalibDataFrame,HcalCalibRecHit>(digi,coder,calibs,
544  pulseCorr_->get(digi.id(), toadd, phaseNS_),
546  runnum_, false, 0,
548 }
549 
550 
552  const int first,
553  const int toadd,
554  const HcalCoder& coder,
555  const HcalCalibrations& calibs) const
556 {
557  const HcalPulseContainmentCorrection* corr = pulseCorr_->get(digi.id(), toadd, phaseNS_);
558 
559  double amp_fC, ampl, uncorr_ampl, maxA;
560  int nRead, maxI;
561  bool leakCorrApplied;
562  float t0, t2;
563 
564  HcalSimpleRecAlgoImpl::removePileup(digi, coder, calibs, first, toadd,
565  correctForPulse_, corr, hfPileupCorr_.get(),
567  &maxA, &ampl, &uncorr_ampl, &amp_fC, &nRead,
568  &maxI, &leakCorrApplied, &t0, &t2);
569 
570  float time=-9999.f;
571  if (maxI > 0 && maxI < (nRead - 1))
572  time = HcalSimpleRecAlgoImpl::recoHFTime(digi,maxI,amp_fC,correctForTimeslew_,maxA,t0,t2) -
573  calibs.timecorr();
574 
575  HFRecHit rh(digi.id(),ampl,time);
576  setRawEnergy(rh, static_cast<float>(uncorr_ampl));
577  return rh;
578 }
579 
581  const int first,
582  const int toadd,
583  const HcalCoder& coder,
584  const HcalCalibrations& calibs) const
585 {
586  const HcalPulseContainmentCorrection* corr = pulseCorr_->get(digi.id(), toadd, phaseNS_);
587 
588  double amp_fC, ampl, uncorr_ampl, maxA;
589  int nRead, maxI;
590  bool leakCorrApplied;
591  float t0, t2;
592 
593  HcalSimpleRecAlgoImpl::removePileup(digi, coder, calibs, first, toadd,
594  correctForPulse_, corr, hfPileupCorr_.get(),
596  &maxA, &ampl, &uncorr_ampl, &amp_fC, &nRead,
597  &maxI, &leakCorrApplied, &t0, &t2);
598 
599  float time=-9999.f;
600  if (maxI > 0 && maxI < (nRead - 1))
601  time = HcalSimpleRecAlgoImpl::recoHFTime(digi,maxI,amp_fC,correctForTimeslew_,maxA,t0,t2) -
602  calibs.timecorr();
603 
604  HFRecHit rh(digi.id(),ampl,time);
605  setRawEnergy(rh, static_cast<float>(uncorr_ampl));
606  return rh;
607 }
608 
609 
611 float hbminus_special_ecorr(int ieta, int iphi, double energy, int runnum) {
612 // return energy correction factor for HBM channels
613 // iphi=6 ieta=(-1,-15) and iphi=32 ieta=(-1,-7)
614 // I.Vodopianov 28 Feb. 2011
615  static const float low32[7] = {0.741,0.721,0.730,0.698,0.708,0.751,0.861};
616  static const float high32[7] = {0.973,0.925,0.900,0.897,0.950,0.935,1};
617  static const float low6[15] = {0.635,0.623,0.670,0.633,0.644,0.648,0.600,
618  0.570,0.595,0.554,0.505,0.513,0.515,0.561,0.579};
619  static const float high6[15] = {0.875,0.937,0.942,0.900,0.922,0.925,0.901,
620  0.850,0.852,0.818,0.731,0.717,0.782,0.853,0.778};
621 
622 
623  double slope, mid, en;
624  double corr = 1.0;
625 
626  if (!(iphi==6 && ieta<0 && ieta>-16) && !(iphi==32 && ieta<0 && ieta>-8))
627  return corr;
628 
629  int jeta = -ieta-1;
630  double xeta = (double) ieta;
631  if (energy > 0.) en=energy;
632  else en = 0.;
633 
634  if (iphi == 32) {
635  slope = 0.2272;
636  mid = 17.14 + 0.7147*xeta;
637  if (en > 100.) corr = high32[jeta];
638  else corr = low32[jeta]+(high32[jeta]-low32[jeta])/(1.0+exp(-(en-mid)*slope));
639  }
640  else if (iphi == 6 && runnum < 216091 ) {
641  slope = 0.1956;
642  mid = 15.96 + 0.3075*xeta;
643  if (en > 100.0) corr = high6[jeta];
644  else corr = low6[jeta]+(high6[jeta]-low6[jeta])/(1.0+exp(-(en-mid)*slope));
645  }
646 
647  // std::cout << "HBHE cell: ieta, iphi = " << ieta << " " << iphi
648  // << " -> energy = " << en << " corr = " << corr << std::endl;
649 
650  return corr;
651 }
652 
653 
654 // Actual leakage (to pre-sample) correction
655 float leakCorr(double energy) {
656  double corr = 1.0;
657  return corr;
658 }
659 
660 
661 // timeshift implementation
662 
663 static const float wpksamp0_hbheho = 0.5;
664 static const int num_bins_hbheho = 61;
665 
666 static const float actual_ns_hbheho[num_bins_hbheho] = {
667 -5.44000, // 0.500, 0.000-0.017
668 -4.84250, // 0.517, 0.017-0.033
669 -4.26500, // 0.533, 0.033-0.050
670 -3.71000, // 0.550, 0.050-0.067
671 -3.18000, // 0.567, 0.067-0.083
672 -2.66250, // 0.583, 0.083-0.100
673 -2.17250, // 0.600, 0.100-0.117
674 -1.69000, // 0.617, 0.117-0.133
675 -1.23000, // 0.633, 0.133-0.150
676 -0.78000, // 0.650, 0.150-0.167
677 -0.34250, // 0.667, 0.167-0.183
678  0.08250, // 0.683, 0.183-0.200
679  0.50250, // 0.700, 0.200-0.217
680  0.90500, // 0.717, 0.217-0.233
681  1.30500, // 0.733, 0.233-0.250
682  1.69500, // 0.750, 0.250-0.267
683  2.07750, // 0.767, 0.267-0.283
684  2.45750, // 0.783, 0.283-0.300
685  2.82500, // 0.800, 0.300-0.317
686  3.19250, // 0.817, 0.317-0.333
687  3.55750, // 0.833, 0.333-0.350
688  3.91750, // 0.850, 0.350-0.367
689  4.27500, // 0.867, 0.367-0.383
690  4.63000, // 0.883, 0.383-0.400
691  4.98500, // 0.900, 0.400-0.417
692  5.33750, // 0.917, 0.417-0.433
693  5.69500, // 0.933, 0.433-0.450
694  6.05000, // 0.950, 0.450-0.467
695  6.40500, // 0.967, 0.467-0.483
696  6.77000, // 0.983, 0.483-0.500
697  7.13500, // 1.000, 0.500-0.517
698  7.50000, // 1.017, 0.517-0.533
699  7.88250, // 1.033, 0.533-0.550
700  8.26500, // 1.050, 0.550-0.567
701  8.66000, // 1.067, 0.567-0.583
702  9.07000, // 1.083, 0.583-0.600
703  9.48250, // 1.100, 0.600-0.617
704  9.92750, // 1.117, 0.617-0.633
705 10.37750, // 1.133, 0.633-0.650
706 10.87500, // 1.150, 0.650-0.667
707 11.38000, // 1.167, 0.667-0.683
708 11.95250, // 1.183, 0.683-0.700
709 12.55000, // 1.200, 0.700-0.717
710 13.22750, // 1.217, 0.717-0.733
711 13.98500, // 1.233, 0.733-0.750
712 14.81500, // 1.250, 0.750-0.767
713 15.71500, // 1.267, 0.767-0.783
714 16.63750, // 1.283, 0.783-0.800
715 17.53750, // 1.300, 0.800-0.817
716 18.38500, // 1.317, 0.817-0.833
717 19.16500, // 1.333, 0.833-0.850
718 19.89750, // 1.350, 0.850-0.867
719 20.59250, // 1.367, 0.867-0.883
720 21.24250, // 1.383, 0.883-0.900
721 21.85250, // 1.400, 0.900-0.917
722 22.44500, // 1.417, 0.917-0.933
723 22.99500, // 1.433, 0.933-0.950
724 23.53250, // 1.450, 0.950-0.967
725 24.03750, // 1.467, 0.967-0.983
726 24.53250, // 1.483, 0.983-1.000
727 25.00000 // 1.500, 1.000-1.017 - keep for interpolation
728 };
729 
730 float timeshift_ns_hbheho(float wpksamp) {
731  float flx = (num_bins_hbheho-1)*(wpksamp - wpksamp0_hbheho);
732  int index = (int)flx;
733  float yval;
734 
735  if (index < 0) return actual_ns_hbheho[0];
736  else if (index >= num_bins_hbheho-1) return actual_ns_hbheho[num_bins_hbheho-1];
737 
738  // else interpolate:
739  float y1 = actual_ns_hbheho[index];
740  float y2 = actual_ns_hbheho[index+1];
741 
742  yval = y1 + (y2-y1)*(flx-(float)index);
743 
744  return yval;
745 }
746 
747 static const int num_bins_hf = 101;
748 static const float wpksamp0_hf = 0.5;
749 
750 static const float actual_ns_hf[num_bins_hf] = {
751  0.00250, // 0.000-0.010
752  0.04500, // 0.010-0.020
753  0.08750, // 0.020-0.030
754  0.13000, // 0.030-0.040
755  0.17250, // 0.040-0.050
756  0.21500, // 0.050-0.060
757  0.26000, // 0.060-0.070
758  0.30250, // 0.070-0.080
759  0.34500, // 0.080-0.090
760  0.38750, // 0.090-0.100
761  0.42750, // 0.100-0.110
762  0.46000, // 0.110-0.120
763  0.49250, // 0.120-0.130
764  0.52500, // 0.130-0.140
765  0.55750, // 0.140-0.150
766  0.59000, // 0.150-0.160
767  0.62250, // 0.160-0.170
768  0.65500, // 0.170-0.180
769  0.68750, // 0.180-0.190
770  0.72000, // 0.190-0.200
771  0.75250, // 0.200-0.210
772  0.78500, // 0.210-0.220
773  0.81750, // 0.220-0.230
774  0.85000, // 0.230-0.240
775  0.88250, // 0.240-0.250
776  0.91500, // 0.250-0.260
777  0.95500, // 0.260-0.270
778  0.99250, // 0.270-0.280
779  1.03250, // 0.280-0.290
780  1.07000, // 0.290-0.300
781  1.10750, // 0.300-0.310
782  1.14750, // 0.310-0.320
783  1.18500, // 0.320-0.330
784  1.22500, // 0.330-0.340
785  1.26250, // 0.340-0.350
786  1.30000, // 0.350-0.360
787  1.34000, // 0.360-0.370
788  1.37750, // 0.370-0.380
789  1.41750, // 0.380-0.390
790  1.48750, // 0.390-0.400
791  1.55750, // 0.400-0.410
792  1.62750, // 0.410-0.420
793  1.69750, // 0.420-0.430
794  1.76750, // 0.430-0.440
795  1.83750, // 0.440-0.450
796  1.90750, // 0.450-0.460
797  2.06750, // 0.460-0.470
798  2.23250, // 0.470-0.480
799  2.40000, // 0.480-0.490
800  2.82250, // 0.490-0.500
801  3.81000, // 0.500-0.510
802  6.90500, // 0.510-0.520
803  8.99250, // 0.520-0.530
804 10.50000, // 0.530-0.540
805 11.68250, // 0.540-0.550
806 12.66250, // 0.550-0.560
807 13.50250, // 0.560-0.570
808 14.23750, // 0.570-0.580
809 14.89750, // 0.580-0.590
810 15.49000, // 0.590-0.600
811 16.03250, // 0.600-0.610
812 16.53250, // 0.610-0.620
813 17.00000, // 0.620-0.630
814 17.44000, // 0.630-0.640
815 17.85250, // 0.640-0.650
816 18.24000, // 0.650-0.660
817 18.61000, // 0.660-0.670
818 18.96750, // 0.670-0.680
819 19.30500, // 0.680-0.690
820 19.63000, // 0.690-0.700
821 19.94500, // 0.700-0.710
822 20.24500, // 0.710-0.720
823 20.54000, // 0.720-0.730
824 20.82250, // 0.730-0.740
825 21.09750, // 0.740-0.750
826 21.37000, // 0.750-0.760
827 21.62750, // 0.760-0.770
828 21.88500, // 0.770-0.780
829 22.13000, // 0.780-0.790
830 22.37250, // 0.790-0.800
831 22.60250, // 0.800-0.810
832 22.83000, // 0.810-0.820
833 23.04250, // 0.820-0.830
834 23.24500, // 0.830-0.840
835 23.44250, // 0.840-0.850
836 23.61000, // 0.850-0.860
837 23.77750, // 0.860-0.870
838 23.93500, // 0.870-0.880
839 24.05500, // 0.880-0.890
840 24.17250, // 0.890-0.900
841 24.29000, // 0.900-0.910
842 24.40750, // 0.910-0.920
843 24.48250, // 0.920-0.930
844 24.55500, // 0.930-0.940
845 24.62500, // 0.940-0.950
846 24.69750, // 0.950-0.960
847 24.77000, // 0.960-0.970
848 24.84000, // 0.970-0.980
849 24.91250, // 0.980-0.990
850 24.95500, // 0.990-1.000
851 24.99750, // 1.000-1.010 - keep for interpolation
852 };
853 
854 float timeshift_ns_hf(float wpksamp) {
855  float flx = (num_bins_hf-1)*(wpksamp-wpksamp0_hf);
856  int index = (int)flx;
857  float yval;
858 
859  if (index < 0) return actual_ns_hf[0];
860  else if (index >= num_bins_hf-1) return actual_ns_hf[num_bins_hf-1];
861 
862  // else interpolate:
863  float y1 = actual_ns_hf[index];
864  float y2 = actual_ns_hf[index+1];
865 
866  // float delta_x = 1/(float)num_bins_hf;
867  // yval = y1 + (y2-y1)*(flx-(float)index)/delta_x;
868 
869  yval = y1 + (y2-y1)*(flx-(float)index);
870  return yval;
871 }
#define LogDebug(id)
const Shape & getShape(int shapeType) const
static const float actual_ns_hf[num_bins_hf]
static const TGPicture * info(bool iBackgroundIsBlack)
HBHERecHit reconstruct(const HBHEDataFrame &digi, int first, int toadd, const HcalCoder &coder, const HcalCalibrations &calibs) const
void apply(const CaloSamples &cs, const std::vector< int > &capidvec, const HcalCalibrations &calibs, double &reconstructedEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
double respcorrgain(int fCapId) const
get response corrected gain for capid=0..3
auto_ptr< ClusterSequence > cs
static float timeshift_ns_hf(float wpksamp)
Timeshift correction for the HF PMTs.
void setMeth3Params(bool iApplyTimeSlew, float iPedSubThreshold, int iTimeSlewParsType, std::vector< double > iTimeSlewPars, double irespCorrM3)
std::unique_ptr< HcalDeterministicFit > hltOOTpuCorr_
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
static const int MAXSAMPLES
Definition: CaloSamples.h:74
void setpuCorrParams(bool iPedestalConstraint, bool iTimeConstraint, bool iAddPulseJitter, bool iApplyTimeSlew, double iTS4Min, const std::vector< double > &iTS4Max, double iPulseJitter, double iTimeMean, double iTimeSig, double iTimeSigSiPM, double iPedMean, double iPedSig, double iPedSigSiPM, double iNoise, double iNoiseSiPM, double iTMin, double iTMax, const std::vector< double > &its4Chi2, int iFitTimes)
virtual void apply(const HcalDetId &id, const double *inputCharge, unsigned lenInputCharge, const BunchXParameter *bcParams, unsigned lenBcParams, unsigned firstTimeSlice, unsigned nTimeSlices, double *correctedCharge, unsigned lenCorrectedCharge, bool *pulseShapeCorrApplied, bool *leakCorrApplied, bool *readjustTiming) const =0
double getCorrection(double fc_ampl) const
void beginRun(edm::EventSetup const &es)
static const double slope[3]
void setFlagField(uint32_t value, int base, int width=1)
Definition: CaloRecHit.cc:20
void setHOPileupCorrection(boost::shared_ptr< AbsOOTPileupCorrection > corr)
edm::DataFrame::id_type id() const
double pedestal(int fCapId) const
get pedestal for capid=0..3
HcalPulseShapes theHcalPulseShapes_
std::tuple< unsigned int, int, int, DigiType, int, int, int, float > Digi
Definition: GenericDigi.h:30
const BunchXParameter * bunchCrossingInfo_
boost::shared_ptr< AbsOOTPileupCorrection > hoPileupCorr_
#define constexpr
std::unique_ptr< HcalPulseContainmentManager > pulseCorr_
static const float wpksamp0_hbheho
void setBXInfo(const BunchXParameter *info, unsigned lenInfo)
boost::shared_ptr< AbsOOTPileupCorrection > hbhePileupCorr_
static const float wpksamp0_hf
int HPDShapev3MCNum
void setRawEnergy(HcalRecHit &h, float e)
Definition: rawEnergy.h:215
static const float actual_ns_hbheho[num_bins_hbheho]
auto const T2 &decltype(t1.eta()) t2
Definition: deltaR.h:16
unsigned lenBunchCrossingInfo_
double MaximumFractionalError
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
std::unique_ptr< PedestalSub > pedSubFxn_
void initPulseCorr(int toadd)
double f[11][100]
HcalSimpleRecAlgo(bool correctForTimeslew, bool correctForContainment, float fixedPhaseNs)
static float leakCorr(double energy)
Leak correction.
T min(T a, T b)
Definition: MathUtil.h:58
void removePileup(const Digi &digi, const HcalCoder &coder, const HcalCalibrations &calibs, const int ifirst, const int n, const bool pulseCorrect, const HcalPulseContainmentCorrection *corr, const AbsOOTPileupCorrection *pileupCorrection, const BunchXParameter *bxInfo, const unsigned lenInfo, double *p_maxA, double *p_ampl, double *p_uncorr_ampl, double *p_fc_ampl, int *p_nRead, int *p_maxI, bool *leakCorrApplied, float *p_t0, float *p_t2)
JetCorrectorParameters corr
Definition: classes.h:5
virtual void adc2fC(const HBHEDataFrame &df, CaloSamples &lf) const =0
float timeshift_ns_hbheho(float wpksamp)
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:103
void apply(const CaloSamples &cs, const std::vector< int > &capidvec, const HcalCalibrations &calibs, const Digi &digi, double &ampl, float &time) const
int HPDShapev3DataNum
void setRecoParams(bool correctForTimeslew, bool correctForPulse, bool setLeakCorrection, int pileupCleaningID, float phaseNS)
int size() const
get the size
Definition: CaloSamples.h:24
double timecorr() const
get time correction factor
void setHBHEPileupCorrection(boost::shared_ptr< AbsOOTPileupCorrection > corr)
HFRecHit reconstructQIE10(const QIE10DataFrame &digi, int first, int toadd, const HcalCoder &coder, const HcalCalibrations &calibs) const
void setForData(int runnum)
static const int num_bins_hf
boost::shared_ptr< AbsOOTPileupCorrection > hfPileupCorr_
static const int num_bins_hbheho
float hbminus_special_ecorr(int ieta, int iphi, double energy, int runnum)
Ugly hack to apply energy corrections to some HB- cells.
RecHit recoHBHE(const Digi &digi, const HcalCoder &coder, const HcalCalibrations &calibs, const int ifirst, const int n, const bool slewCorrect, const bool pulseCorrect, const HcalPulseContainmentCorrection *corr, const HcalTimeSlew::BiasSetting slewFlavor, const int runnum, const bool useLeak, const AbsOOTPileupCorrection *pileupCorrection, const BunchXParameter *bxInfo, const unsigned lenInfo, const int puCorrMethod, const PulseShapeFitOOTPileupCorrection *psFitOOTpuCorr, HcalDeterministicFit *hltOOTpuCorr, PedestalSub *hltPedSub)
float recoHFTime(const Digi &digi, const int maxI, const double amp_fC, const bool slewCorrect, double maxA, float t0, float t2)
const HcalDetId & id() const
Definition: HFDataFrame.h:22
RecHit reco(const Digi &digi, const HcalCoder &coder, const HcalCalibrations &calibs, const int ifirst, const int n, const bool slewCorrect, const bool pulseCorrect, const HcalPulseContainmentCorrection *corr, const HcalTimeSlew::BiasSetting slewFlavor, const int runnum, const bool useLeak, const AbsOOTPileupCorrection *pileupCorrection, const BunchXParameter *bxInfo, const unsigned lenInfo, const int puCorrMethod, const PulseShapeFitOOTPileupCorrection *psFitOOTpuCorr, HcalDeterministicFit *hltOOTpuCorr, PedestalSub *hltPedSub)
std::unique_ptr< PulseShapeFitOOTPileupCorrection > psFitOOTpuCorr_
void setHFPileupCorrection(boost::shared_ptr< AbsOOTPileupCorrection > corr)
virtual bool inputIsEnergy() const =0
void setAuxEnergy(HcalRecHit &h, float e)
Definition: rawEnergy.h:232
static double delay(double fC, BiasSetting bias=Medium)
Returns the amount (ns) by which a pulse of the given number of fC will be delayed by the timeslew ef...
Definition: HcalTimeSlew.cc:16