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