18 correctForTimeslew_(correctForTimeslew),
19 correctForPulse_(correctForPulse),
20 phaseNS_(phaseNS), runnum_(0), setLeakCorrection_(
false), puCorrMethod_(0)
23 pulseCorr_ = std::auto_ptr<HcalPulseContainmentManager>(
30 correctForTimeslew_(
false), runnum_(0), puCorrMethod_(0)
59 bool iUnConstrainedFit,
bool iApplyTimeSlew,
double iTS4Min,
double iTS4Max,
60 double iPulseJitter,
double iTimeMean,
double iTimeSig,
double iPedMean,
double iPedSig,
61 double iNoise,
double iTMin,
double iTMax,
62 double its3Chi2,
double its4Chi2,
double its345Chi2,
double iChargeThreshold,
int iFitTimes) {
63 if( iPedestalConstraint )
assert ( iPedSig );
64 if( iTimeConstraint )
assert( iTimeSig );
65 psFitOOTpuCorr_->setPUParams(iPedestalConstraint,iTimeConstraint,iAddPulseJitter,iUnConstrainedFit,iApplyTimeSlew,
66 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);
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, 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);
367 psFitOOTpuCorr->
apply(cs, capidvec, calibs, correctedOutput);
368 if( correctedOutput.back() == 0 && correctedOutput.size() >1 ){
369 time = correctedOutput[1]; ampl = correctedOutput[0];
376 if ( puCorrMethod == 3){
377 std::vector<double> hltCorrOutput;
383 std::vector<int> capidvec;
384 for(
int ip=0; ip<cs.
size(); ip++){
385 const int capid = digi[ip].capid();
386 capidvec.push_back(capid);
389 hltOOTpuCorr->
apply(cs, capidvec, calibs, hltCorrOutput);
390 if( hltCorrOutput.size() > 1 ){
391 time = hltCorrOutput[1]; ampl = hltCorrOutput[0];
400 const int ieta = cell.
ieta();
401 const int iphi = cell.
iphi();
402 ampl *=
eCorr(ieta, iphi, ampl, runnum);
403 uncorr_ampl *=
eCorr(ieta, iphi, uncorr_ampl, runnum);
408 if(useLeak && !leakCorrApplied) {
410 uncorr_ampl *=
leakCorr(uncorr_ampl);
413 RecHit rh(digi.id(),ampl,
time);
421 return HcalSimpleRecAlgoImpl::reco<HBHEDataFrame,HBHERecHit>(digi,coder,calibs,
432 return HcalSimpleRecAlgoImpl::reco<HODataFrame,HORecHit>(digi,coder,calibs,
442 return HcalSimpleRecAlgoImpl::reco<HcalCalibDataFrame,HcalCalibRecHit>(digi,coder,calibs,
452 HBHERecHit result = HcalSimpleRecAlgoImpl::reco<HcalUpgradeDataFrame,HBHERecHit>(digi, coder, calibs,
459 tdcReco.reconstruct(digi, result);
472 double amp_fC, ampl, uncorr_ampl, maxA;
474 bool leakCorrApplied;
480 &maxA, &l, &uncorr_ampl, &_fC, &nRead,
481 &
maxI, &leakCorrApplied, &t0, &t2);
484 if (maxI > 0 && maxI < (nRead - 1))
504 double amp_fC, ampl, uncorr_ampl, maxA;
506 bool leakCorrApplied;
512 &maxA, &l, &uncorr_ampl, &_fC, &nRead,
513 &
maxI, &leakCorrApplied, &t0, &t2);
516 if (maxI > 0 && maxI < (nRead - 1))
531 static const float low32[7] = {0.741,0.721,0.730,0.698,0.708,0.751,0.861};
532 static const float high32[7] = {0.973,0.925,0.900,0.897,0.950,0.935,1};
533 static const float low6[15] = {0.635,0.623,0.670,0.633,0.644,0.648,0.600,
534 0.570,0.595,0.554,0.505,0.513,0.515,0.561,0.579};
535 static const float high6[15] = {0.875,0.937,0.942,0.900,0.922,0.925,0.901,
536 0.850,0.852,0.818,0.731,0.717,0.782,0.853,0.778};
539 double slope, mid, en;
542 if (!(iphi==6 && ieta<0 && ieta>-16) && !(iphi==32 && ieta<0 && ieta>-8))
546 double xeta = (double) ieta;
547 if (energy > 0.) en=
energy;
552 mid = 17.14 + 0.7147*xeta;
553 if (en > 100.) corr = high32[jeta];
554 else corr = low32[jeta]+(high32[jeta]-low32[jeta])/(1.0+
exp(-(en-mid)*
slope));
556 else if (iphi == 6 && runnum < 216091 ) {
558 mid = 15.96 + 0.3075*xeta;
559 if (en > 100.0) corr = high6[jeta];
560 else corr = low6[jeta]+(high6[jeta]-low6[jeta])/(1.0+
exp(-(en-mid)*slope));
648 int index = (int)flx;
658 yval = y1 + (y2-y1)*(flx-(
float)
index);
772 int index = (int)flx;
785 yval = y1 + (y2-y1)*(flx-(
float)
index);
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
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 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]
void apply(const CaloSamples &cs, const std::vector< int > &capidvec, const HcalCalibrations &calibs, std::vector< double > &HLTOutput) const
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)
void init(HcalTimeSlew::ParaSource tsParam, HcalTimeSlew::BiasSetting bias, NegStrategy nStrat, PedestalSub pedSubFxn_)
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
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_
void init(Method method, int runCond, float threshold, float quantile)
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)