19 correctForTimeslew_(correctForTimeslew),
20 correctForPulse_(correctForPulse),
21 phaseNS_(phaseNS), runnum_(0), setLeakCorrection_(
false), puCorrMethod_(0)
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,
86 boost::shared_ptr<AbsOOTPileupCorrection>
corr)
92 boost::shared_ptr<AbsOOTPileupCorrection>
corr)
98 boost::shared_ptr<AbsOOTPileupCorrection>
corr)
104 const unsigned lenInfo)
121 static float eCorr(
int ieta,
int iphi,
double ampl,
int runnum);
127 namespace HcalSimpleRecAlgoImpl {
130 const bool slewCorrect,
double maxA,
float t0,
float t2)
144 if (wpksamp != 0.
f) wpksamp = maxA/wpksamp;
147 if (wpksamp != 0.
f) wpksamp = 1.+(t2/wpksamp);
150 float time = (maxI - digi.presamples())*25.0 +
timeshift_ns_hf(wpksamp);
152 if (slewCorrect && amp_fC > 0.0) {
154 double tslew=
exp(0.337681-5.94689
e-4*amp_fC)+
exp(2.44628-1.34888
e-2*amp_fC);
155 time -= (float)tslew;
165 const int ifirst,
const int n,
166 const bool pulseCorrect,
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)
176 const int nRead = cs.
size();
177 const int iStop =
std::min(nRead, n + ifirst);
184 double* correctedEnergy = 0;
185 double fc_ampl = 0.0, corr_fc_ampl = 0.0;
186 bool pulseShapeCorrApplied =
false, readjustTiming =
false;
187 *leakCorrApplied =
false;
189 if (pileupCorrection)
191 correctedEnergy = &buf[0];
196 for (
int i=0;
i<nRead; ++
i)
198 const int capid = digi[
i].capid();
199 correctionInput[
i] = cs[
i] - calibs.
pedestal(capid);
203 for (
int i=ifirst;
i<iStop; ++
i)
204 fc_ampl += correctionInput[
i];
207 for (
int i=0;
i<nRead; ++
i)
209 uncorrectedEnergy[
i] = correctionInput[
i]*gains[
i];
211 correctionInput[
i] = uncorrectedEnergy[
i];
214 pileupCorrection->
apply(digi.id(), correctionInput, nRead,
215 bxInfo, lenInfo, ifirst,
n,
217 &pulseShapeCorrApplied, leakCorrApplied,
223 for (
int i=ifirst;
i<iStop; ++
i)
225 corr_fc_ampl += correctedEnergy[
i]/gains[
i];
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];
237 correctedEnergy = &uncorrectedEnergy[0];
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)
244 const int capid = digi[
i].capid();
245 float ta = cs[
i] - calibs.
pedestal(capid);
246 if (
i >= ifirst &&
i < iStop)
249 uncorrectedEnergy[
i] = ta;
251 corr_fc_ampl = fc_ampl;
255 double ampl = 0.0, corr_ampl = 0.0;
256 for (
int i=ifirst;
i<iStop; ++
i)
258 ampl += uncorrectedEnergy[
i];
259 corr_ampl += correctedEnergy[
i];
263 if (corr && pulseCorrect)
266 if (pileupCorrection)
268 if (!pulseShapeCorrApplied)
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)
288 *p_uncorr_ampl = ampl;
289 *p_fc_ampl = readjustTiming ? corr_fc_ampl : fc_ampl;
293 if (maxI <= 0 || maxI >= (nRead-1))
295 LogDebug(
"HCAL Pulse") <<
"HcalSimpleRecAlgoImpl::removePileup :"
296 <<
" Invalid max amplitude position, "
297 <<
" max Amplitude: " << maxI
298 <<
" first: " << ifirst
299 <<
" last: " << ifirst + n
306 *p_t0 = etime[maxI - 1];
307 *p_t2 = etime[maxI + 1];
312 template<
class Digi,
class RecHit>
315 const int ifirst,
const int n,
const bool slewCorrect,
318 const int runnum,
const bool useLeak,
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;
333 pulseCorrect, corr, inputAbsOOTpuCorr,
334 bxInfo, lenInfo, &maxA, &l,
335 &uncorr_ampl, &fc_ampl, &nRead, &
maxI,
336 &leakCorrApplied, &t0, &
t2);
342 if (maxA<minA) minA=maxA;
343 if (
t2<minA) minA=
t2;
344 if (minA<0) { maxA-=minA; t0-=minA;
t2-=minA; }
346 float wpksamp = (t0 + maxA +
t2);
347 if (wpksamp!=0) wpksamp=(maxA + 2.0*
t2) / wpksamp;
356 if( puCorrMethod == 2 ){
357 std::vector<double> correctedOutput;
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);
366 psFitOOTpuCorr->
apply(cs, capidvec, calibs, correctedOutput);
367 if( correctedOutput.back() == 0 && correctedOutput.size() >1 ){
368 time = correctedOutput[1]; ampl = correctedOutput[0];
375 std::vector<double> hltCorrOutput;
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);
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];
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);
406 if(useLeak && !leakCorrApplied) {
407 uncorr_ampl *=
leakCorr(uncorr_ampl);
408 if (puCorrMethod < 2)
412 RecHit rh(digi.id(),ampl,time);
418 template<
class Digi,
class RecHit>
421 const int ifirst,
const int n,
const bool slewCorrect,
424 const int runnum,
const bool useLeak,
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;
433 bool useTriple =
false;
440 pulseCorrect, corr, inputAbsOOTpuCorr,
441 bxInfo, lenInfo, &maxA, &l,
442 &uncorr_ampl, &fc_ampl, &nRead, &
maxI,
443 &leakCorrApplied, &t0, &
t2);
449 if (maxA<minA) minA=maxA;
450 if (
t2<minA) minA=
t2;
451 if (minA<0) { maxA-=minA; t0-=minA;
t2-=minA; }
453 float wpksamp = (t0 + maxA +
t2);
454 if (wpksamp!=0) wpksamp=(maxA + 2.0*
t2) / wpksamp;
463 if( puCorrMethod == 2 ){
464 std::vector<double> correctedOutput;
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);
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];
483 std::vector<double> hltCorrOutput;
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);
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];
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);
514 if(useLeak && !leakCorrApplied) {
515 uncorr_ampl *=
leakCorr(uncorr_ampl);
516 if (puCorrMethod < 2)
533 return HcalSimpleRecAlgoImpl::recoHBHE<HBHEDataFrame,HBHERecHit>(digi,coder,calibs,
544 return HcalSimpleRecAlgoImpl::reco<HODataFrame,HORecHit>(digi,coder,calibs,
554 return HcalSimpleRecAlgoImpl::reco<HcalCalibDataFrame,HcalCalibRecHit>(digi,coder,calibs,
564 HBHERecHit result = HcalSimpleRecAlgoImpl::reco<HcalUpgradeDataFrame,HBHERecHit>(digi, coder, calibs,
571 tdcReco.reconstruct(digi, result);
584 double amp_fC, ampl, uncorr_ampl, maxA;
586 bool leakCorrApplied;
592 &maxA, &l, &uncorr_ampl, &_fC, &nRead,
593 &
maxI, &leakCorrApplied, &t0, &
t2);
596 if (maxI > 0 && maxI < (nRead - 1))
613 double amp_fC, ampl, uncorr_ampl, maxA;
615 bool leakCorrApplied;
621 &maxA, &l, &uncorr_ampl, &_fC, &nRead,
622 &
maxI, &leakCorrApplied, &t0, &
t2);
625 if (maxI > 0 && maxI < (nRead - 1))
645 double amp_fC, ampl, uncorr_ampl, maxA;
647 bool leakCorrApplied;
653 &maxA, &l, &uncorr_ampl, &_fC, &nRead,
654 &
maxI, &leakCorrApplied, &t0, &
t2);
657 if (maxI > 0 && maxI < (nRead - 1))
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};
680 double slope, mid, en;
683 if (!(iphi==6 && ieta<0 && ieta>-16) && !(iphi==32 && ieta<0 && ieta>-8))
687 double xeta = (double) ieta;
688 if (energy > 0.) en=
energy;
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));
697 else if (iphi == 6 && runnum < 216091 ) {
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));
789 int index = (int)flx;
799 yval = y1 + (y2-y1)*(flx-(
float)
index);
913 int index = (int)flx;
926 yval = y1 + (y2-y1)*(flx-(
float)
index);
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
static const float actual_ns_hf[num_bins_hf]
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
static const int MAXSAMPLES
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)
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
const BunchXParameter * bunchCrossingInfo_
boost::shared_ptr< AbsOOTPileupCorrection > hoPileupCorr_
static const float wpksamp0_hbheho
void setBXInfo(const BunchXParameter *info, unsigned lenInfo)
boost::shared_ptr< AbsOOTPileupCorrection > hbhePileupCorr_
static const float wpksamp0_hf
void setRawEnergy(HcalRecHit &h, float e)
static const float actual_ns_hbheho[num_bins_hbheho]
auto const T2 &decltype(t1.eta()) t2
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
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)
HcalSimpleRecAlgo(bool correctForTimeslew, bool correctForContainment, float fixedPhaseNs)
static float leakCorr(double energy)
Leak correction.
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)
static float timeshift_ns_hbheho(float wpksamp)
int iphi() const
get the cell iphi
void setRecoParams(bool correctForTimeslew, bool correctForPulse, bool setLeakCorrection, int pileupCleaningID, float phaseNS)
int size() const
get the size
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)
std::auto_ptr< HcalDeterministicFit > hltOOTpuCorr_
volatile std::atomic< bool > shutdown_flag false
const HcalDetId & id() const
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)
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...
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)