16 correctForTimeslew_(correctForTimeslew),
17 correctForPulse_(correctForPulse),
18 phaseNS_(phaseNS), runnum_(0), setLeakCorrection_(
false)
21 pulseCorr_ = std::auto_ptr<HcalPulseContainmentManager>(
28 correctForTimeslew_(
false), runnum_(0) { }
59 boost::shared_ptr<AbsOOTPileupCorrection>
corr)
65 boost::shared_ptr<AbsOOTPileupCorrection>
corr)
71 boost::shared_ptr<AbsOOTPileupCorrection>
corr)
77 const unsigned lenInfo)
94 static float eCorr(
int ieta,
int iphi,
double ampl,
int runnum);
100 namespace HcalSimpleRecAlgoImpl {
103 const bool slewCorrect,
double maxA,
float t0,
float t2)
117 if (wpksamp != 0.
f) wpksamp = maxA/wpksamp;
120 if (wpksamp != 0.
f) wpksamp = 1.+(t2/wpksamp);
125 if (slewCorrect && amp_fC > 0.0) {
127 double tslew=
exp(0.337681-5.94689
e-4*amp_fC)+
exp(2.44628-1.34888
e-2*amp_fC);
128 time -= (float)tslew;
138 const int ifirst,
const int n,
139 const bool pulseCorrect,
142 const BunchXParameter* bxInfo,
const unsigned lenInfo,
143 double* p_maxA,
double* p_ampl,
double* p_uncorr_ampl,
144 double* p_fc_ampl,
int* p_nRead,
int* p_maxI,
145 bool* leakCorrApplied,
float* p_t0,
float* p_t2)
149 const int nRead = cs.
size();
150 const int iStop =
std::min(nRead, n + ifirst);
157 double* correctedEnergy = 0;
158 double fc_ampl = 0.0, corr_fc_ampl = 0.0;
159 bool pulseShapeCorrApplied =
false, readjustTiming =
false;
160 *leakCorrApplied =
false;
162 if (pileupCorrection)
164 correctedEnergy = &buf[0];
169 for (
int i=0;
i<nRead; ++
i)
171 const int capid = digi[
i].capid();
172 correctionInput[
i] = cs[
i] - calibs.
pedestal(capid);
176 for (
int i=ifirst;
i<iStop; ++
i)
177 fc_ampl += correctionInput[
i];
180 for (
int i=0;
i<nRead; ++
i)
182 uncorrectedEnergy[
i] = correctionInput[
i]*gains[
i];
184 correctionInput[
i] = uncorrectedEnergy[
i];
187 pileupCorrection->
apply(digi.id(), correctionInput, nRead,
188 bxInfo, lenInfo, ifirst,
n,
190 &pulseShapeCorrApplied, leakCorrApplied,
196 for (
int i=ifirst;
i<iStop; ++
i)
198 corr_fc_ampl += correctedEnergy[
i]/gains[
i];
202 for (
int i=ifirst;
i<iStop; ++
i)
203 corr_fc_ampl += correctedEnergy[
i];
204 for (
int i=0;
i<nRead; ++
i)
205 correctedEnergy[
i] *= gains[
i];
210 correctedEnergy = &uncorrectedEnergy[0];
213 const int istart =
std::max(ifirst - 1, 0);
214 const int iend =
std::min(n + ifirst + 1, nRead);
215 for (
int i=istart;
i<iend; ++
i)
217 const int capid = digi[
i].capid();
218 float ta = cs[
i] - calibs.
pedestal(capid);
219 if (
i >= ifirst &&
i < iStop)
222 uncorrectedEnergy[
i] = ta;
224 corr_fc_ampl = fc_ampl;
228 double ampl = 0.0, corr_ampl = 0.0;
229 for (
int i=ifirst;
i<iStop; ++
i)
231 ampl += uncorrectedEnergy[
i];
232 corr_ampl += correctedEnergy[
i];
236 if (corr && pulseCorrect)
239 if (pileupCorrection)
241 if (!pulseShapeCorrApplied)
249 const double *etime = readjustTiming ? &correctedEnergy[0] : &uncorrectedEnergy[0];
250 int maxI = -1;
double maxA = -1.e300;
251 for (
int i=ifirst;
i<iStop; ++
i)
261 *p_uncorr_ampl = ampl;
262 *p_fc_ampl = readjustTiming ? corr_fc_ampl : fc_ampl;
266 if (maxI <= 0 || maxI >= (nRead-1))
268 LogDebug(
"HCAL Pulse") <<
"HcalSimpleRecAlgoImpl::removePileup :"
269 <<
" Invalid max amplitude position, "
270 <<
" max Amplitude: " << maxI
271 <<
" first: " << ifirst
272 <<
" last: " << ifirst + n
279 *p_t0 = etime[maxI - 1];
280 *p_t2 = etime[maxI + 1];
285 template<
class Digi,
class RecHit>
288 const int ifirst,
const int n,
const bool slewCorrect,
291 const int runnum,
const bool useLeak,
293 const BunchXParameter* bxInfo,
const unsigned lenInfo)
295 double fc_ampl, ampl, uncorr_ampl, maxA;
297 bool leakCorrApplied;
301 pulseCorrect, corr, pileupCorrection,
302 bxInfo, lenInfo, &maxA, &l,
303 &uncorr_ampl, &fc_ampl, &nRead, &maxI,
304 &leakCorrApplied, &t0, &t2);
307 if (maxI > 0 && maxI < (nRead - 1))
311 if (maxA<minA) minA=maxA;
312 if (t2<minA) minA=t2;
313 if (minA<0) { maxA-=minA; t0-=minA; t2-=minA; }
315 float wpksamp = (t0 + maxA + t2);
316 if (wpksamp!=0) wpksamp=(maxA + 2.0*t2) / wpksamp;
328 const int ieta = cell.
ieta();
329 const int iphi = cell.
iphi();
330 ampl *=
eCorr(ieta, iphi, ampl, runnum);
331 uncorr_ampl *=
eCorr(ieta, iphi, uncorr_ampl, runnum);
336 if(useLeak && !leakCorrApplied) {
338 uncorr_ampl *=
leakCorr(uncorr_ampl);
341 RecHit rh(digi.id(),ampl,
time);
349 return HcalSimpleRecAlgoImpl::reco<HBHEDataFrame,HBHERecHit>(digi,coder,calibs,
360 return HcalSimpleRecAlgoImpl::reco<HODataFrame,HORecHit>(digi,coder,calibs,
370 return HcalSimpleRecAlgoImpl::reco<HcalCalibDataFrame,HcalCalibRecHit>(digi,coder,calibs,
380 HBHERecHit result = HcalSimpleRecAlgoImpl::reco<HcalUpgradeDataFrame,HBHERecHit>(digi, coder, calibs,
387 tdcReco.reconstruct(digi, result);
400 double amp_fC, ampl, uncorr_ampl, maxA;
402 bool leakCorrApplied;
408 &maxA, &l, &uncorr_ampl, &_fC, &nRead,
409 &
maxI, &leakCorrApplied, &t0, &t2);
412 if (maxI > 0 && maxI < (nRead - 1))
432 double amp_fC, ampl, uncorr_ampl, maxA;
434 bool leakCorrApplied;
440 &maxA, &l, &uncorr_ampl, &_fC, &nRead,
441 &
maxI, &leakCorrApplied, &t0, &t2);
444 if (maxI > 0 && maxI < (nRead - 1))
459 static const float low32[7] = {0.741,0.721,0.730,0.698,0.708,0.751,0.861};
460 static const float high32[7] = {0.973,0.925,0.900,0.897,0.950,0.935,1};
461 static const float low6[15] = {0.635,0.623,0.670,0.633,0.644,0.648,0.600,
462 0.570,0.595,0.554,0.505,0.513,0.515,0.561,0.579};
463 static const float high6[15] = {0.875,0.937,0.942,0.900,0.922,0.925,0.901,
464 0.850,0.852,0.818,0.731,0.717,0.782,0.853,0.778};
467 double slope, mid, en;
470 if (!(iphi==6 && ieta<0 && ieta>-16) && !(iphi==32 && ieta<0 && ieta>-8))
474 double xeta = (double) ieta;
475 if (energy > 0.) en=
energy;
480 mid = 17.14 + 0.7147*xeta;
481 if (en > 100.) corr = high32[jeta];
482 else corr = low32[jeta]+(high32[jeta]-low32[jeta])/(1.0+
exp(-(en-mid)*
slope));
484 else if (iphi == 6 && runnum < 216091 ) {
486 mid = 15.96 + 0.3075*xeta;
487 if (en > 100.0) corr = high6[jeta];
488 else corr = low6[jeta]+(high6[jeta]-low6[jeta])/(1.0+
exp(-(en-mid)*slope));
576 int index = (int)flx;
586 yval = y1 + (y2-y1)*(flx-(
float)
index);
700 int index = (int)flx;
713 yval = y1 + (y2-y1)*(flx-(
float)
index);
virtual bool inputIsEnergy() const =0
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
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_
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
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
float recoHFTime(const Digi &digi, const int maxI, const double amp_fC, const bool slewCorrect, double maxA, float t0, float t2)
volatile std::atomic< bool > shutdown_flag false
const HcalDetId & id() const
static float eCorr(int ieta, int iphi, double ampl, int runnum)
Ugly hack to apply energy corrections to some HB- cells.
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)
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...