CMS 3D CMS Logo

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