19 correctForTimeslew_(correctForTimeslew),
20 correctForPulse_(correctForPulse),
21 phaseNS_(phaseNS), runnum_(0), setLeakCorrection_(
false), puCorrMethod_(0)
24 pulseCorr_ = std::auto_ptr<HcalPulseContainmentManager>(
31 correctForTimeslew_(
false), runnum_(0), puCorrMethod_(0)
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,
93 boost::shared_ptr<AbsOOTPileupCorrection>
corr)
99 boost::shared_ptr<AbsOOTPileupCorrection>
corr)
105 boost::shared_ptr<AbsOOTPileupCorrection>
corr)
111 const unsigned lenInfo)
128 static float eCorr(
int ieta,
int iphi,
double ampl,
int runnum);
134 namespace HcalSimpleRecAlgoImpl {
137 const bool slewCorrect,
double maxA,
float t0,
float t2)
151 if (wpksamp != 0.
f) wpksamp = maxA/wpksamp;
154 if (wpksamp != 0.
f) wpksamp = 1.+(t2/wpksamp);
159 if (slewCorrect && amp_fC > 0.0) {
161 double tslew=
exp(0.337681-5.94689
e-4*amp_fC)+
exp(2.44628-1.34888
e-2*amp_fC);
162 time -= (float)tslew;
172 const int ifirst,
const int n,
173 const bool pulseCorrect,
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)
183 const int nRead = cs.
size();
184 const int iStop =
std::min(nRead, n + ifirst);
191 double* correctedEnergy = 0;
192 double fc_ampl = 0.0, corr_fc_ampl = 0.0;
193 bool pulseShapeCorrApplied =
false, readjustTiming =
false;
194 *leakCorrApplied =
false;
196 if (pileupCorrection)
198 correctedEnergy = &buf[0];
203 for (
int i=0;
i<nRead; ++
i)
205 const int capid = digi[
i].capid();
206 correctionInput[
i] = cs[
i] - calibs.
pedestal(capid);
210 for (
int i=ifirst;
i<iStop; ++
i)
211 fc_ampl += correctionInput[
i];
214 for (
int i=0;
i<nRead; ++
i)
216 uncorrectedEnergy[
i] = correctionInput[
i]*gains[
i];
218 correctionInput[
i] = uncorrectedEnergy[
i];
221 pileupCorrection->
apply(digi.id(), correctionInput, nRead,
222 bxInfo, lenInfo, ifirst,
n,
224 &pulseShapeCorrApplied, leakCorrApplied,
230 for (
int i=ifirst;
i<iStop; ++
i)
232 corr_fc_ampl += correctedEnergy[
i]/gains[
i];
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];
244 correctedEnergy = &uncorrectedEnergy[0];
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)
251 const int capid = digi[
i].capid();
252 float ta = cs[
i] - calibs.
pedestal(capid);
253 if (
i >= ifirst &&
i < iStop)
256 uncorrectedEnergy[
i] = ta;
258 corr_fc_ampl = fc_ampl;
262 double ampl = 0.0, corr_ampl = 0.0;
263 for (
int i=ifirst;
i<iStop; ++
i)
265 ampl += uncorrectedEnergy[
i];
266 corr_ampl += correctedEnergy[
i];
270 if (corr && pulseCorrect)
273 if (pileupCorrection)
275 if (!pulseShapeCorrApplied)
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)
295 *p_uncorr_ampl = ampl;
296 *p_fc_ampl = readjustTiming ? corr_fc_ampl : fc_ampl;
300 if (maxI <= 0 || maxI >= (nRead-1))
302 LogDebug(
"HCAL Pulse") <<
"HcalSimpleRecAlgoImpl::removePileup :"
303 <<
" Invalid max amplitude position, "
304 <<
" max Amplitude: " << maxI
305 <<
" first: " << ifirst
306 <<
" last: " << ifirst + n
313 *p_t0 = etime[maxI - 1];
314 *p_t2 = etime[maxI + 1];
319 template<
class Digi,
class RecHit>
322 const int ifirst,
const int n,
const bool slewCorrect,
325 const int runnum,
const bool useLeak,
329 double fc_ampl =0, ampl =0, uncorr_ampl =0, maxA = -1.e300;
330 int nRead = 0,
maxI = -1;
331 bool leakCorrApplied =
false;
340 pulseCorrect, corr, inputAbsOOTpuCorr,
341 bxInfo, lenInfo, &maxA, &l,
342 &uncorr_ampl, &fc_ampl, &nRead, &
maxI,
343 &leakCorrApplied, &t0, &t2);
349 if (maxA<minA) minA=maxA;
350 if (t2<minA) minA=t2;
351 if (minA<0) { maxA-=minA; t0-=minA; t2-=minA; }
353 float wpksamp = (t0 + maxA + t2);
354 if (wpksamp!=0) wpksamp=(maxA + 2.0*t2) / wpksamp;
363 if( puCorrMethod == 2 ){
364 std::vector<double> correctedOutput;
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);
373 psFitOOTpuCorr->
apply(cs, capidvec, calibs, correctedOutput);
374 if( correctedOutput.back() == 0 && correctedOutput.size() >1 ){
375 time = correctedOutput[1]; ampl = correctedOutput[0];
381 if ( puCorrMethod == 3){
382 std::vector<double> hltCorrOutput;
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);
391 hltOOTpuCorr->
apply(cs, capidvec, calibs, digi, hltCorrOutput);
392 if( hltCorrOutput.size() > 1 ){
393 time = hltCorrOutput[1]; ampl = hltCorrOutput[0];
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);
409 if(useLeak && !leakCorrApplied) {
411 uncorr_ampl *=
leakCorr(uncorr_ampl);
414 RecHit rh(digi.id(),ampl,
time);
419 template<
class Digi,
class RecHit>
422 const int ifirst,
const int n,
const bool slewCorrect,
425 const int runnum,
const bool useLeak,
429 double fc_ampl =0, ampl =0, uncorr_ampl =0, maxA = -1.e300;
430 int nRead = 0,
maxI = -1;
431 bool leakCorrApplied =
false;
434 bool useTriple =
false;
441 pulseCorrect, corr, inputAbsOOTpuCorr,
442 bxInfo, lenInfo, &maxA, &l,
443 &uncorr_ampl, &fc_ampl, &nRead, &
maxI,
444 &leakCorrApplied, &t0, &t2);
450 if (maxA<minA) minA=maxA;
451 if (t2<minA) minA=t2;
452 if (minA<0) { maxA-=minA; t0-=minA; t2-=minA; }
454 float wpksamp = (t0 + maxA + t2);
455 if (wpksamp!=0) wpksamp=(maxA + 2.0*t2) / wpksamp;
464 if( puCorrMethod == 2 ){
465 std::vector<double> correctedOutput;
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);
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];
483 if ( puCorrMethod == 3){
484 std::vector<double> hltCorrOutput;
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);
493 hltOOTpuCorr->
apply(cs, capidvec, calibs, digi, hltCorrOutput);
494 if( hltCorrOutput.size() > 1 ){
495 time = hltCorrOutput[1]; ampl = hltCorrOutput[0];
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);
511 if(useLeak && !leakCorrApplied) {
513 uncorr_ampl *=
leakCorr(uncorr_ampl);
528 return HcalSimpleRecAlgoImpl::recoHBHE<HBHEDataFrame,HBHERecHit>(digi,coder,calibs,
539 return HcalSimpleRecAlgoImpl::reco<HODataFrame,HORecHit>(digi,coder,calibs,
549 return HcalSimpleRecAlgoImpl::reco<HcalCalibDataFrame,HcalCalibRecHit>(digi,coder,calibs,
559 HBHERecHit result = HcalSimpleRecAlgoImpl::reco<HcalUpgradeDataFrame,HBHERecHit>(digi, coder, calibs,
566 tdcReco.reconstruct(digi, result);
579 double amp_fC, ampl, uncorr_ampl, maxA;
581 bool leakCorrApplied;
587 &maxA, &l, &uncorr_ampl, &_fC, &nRead,
588 &
maxI, &leakCorrApplied, &t0, &t2);
591 if (maxI > 0 && maxI < (nRead - 1))
611 double amp_fC, ampl, uncorr_ampl, maxA;
613 bool leakCorrApplied;
619 &maxA, &l, &uncorr_ampl, &_fC, &nRead,
620 &
maxI, &leakCorrApplied, &t0, &t2);
623 if (maxI > 0 && maxI < (nRead - 1))
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};
646 double slope, mid, en;
649 if (!(iphi==6 && ieta<0 && ieta>-16) && !(iphi==32 && ieta<0 && ieta>-8))
653 double xeta = (double) ieta;
654 if (energy > 0.) en=
energy;
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));
663 else if (iphi == 6 && runnum < 216091 ) {
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));
755 int index = (int)flx;
765 yval = y1 + (y2-y1)*(flx-(
float)
index);
879 int index = (int)flx;
892 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)
double pedestal(int fCapId) const
get pedestal for capid=0..3
HcalPulseShapes theHcalPulseShapes_
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]
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)
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)
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)
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)