diff --git a/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h b/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h index c3af33d98ac51..43023659ab2ad 100644 --- a/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h +++ b/RecoLocalCalo/HcalRecAlgos/interface/PulseShapeFitOOTPileupCorrection.h @@ -117,6 +117,7 @@ class PulseShapeFitOOTPileupCorrection double iTMin, double iTMax, const std::vector & its4Chi2, HcalTimeSlew::BiasSetting slewFlavor, int iFitTimes); + const HcalPulseShapes::Shape* currentPulseShape_=NULL; void setChi2Term( bool isHPD ); void setPulseShapeTemplate (const HcalPulseShapes::Shape& ps, bool isHPD); @@ -135,9 +136,9 @@ class PulseShapeFitOOTPileupCorrection int fitTimes_; std::unique_ptr psfPtr_; - ROOT::Math::Functor *spfunctor_; - ROOT::Math::Functor *dpfunctor_; - ROOT::Math::Functor *tpfunctor_; + std::unique_ptr spfunctor_; + std::unique_ptr dpfunctor_; + std::unique_ptr tpfunctor_; int TSMin_; int TSMax_; mutable double ts4Chi2_; @@ -164,6 +165,7 @@ class PulseShapeFitOOTPileupCorrection double noiseSiPM_; HcalTimeSlew::BiasSetting slewFlavor_; + bool isCurrentChannelHPD_; }; #endif // PulseShapeFitOOTPileupCorrection_h diff --git a/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc b/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc index e75500ec4ebb4..14eeaeebeaf23 100644 --- a/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc +++ b/RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc @@ -219,9 +219,6 @@ PulseShapeFitOOTPileupCorrection::PulseShapeFitOOTPileupCorrection() : cntsetPul PulseShapeFitOOTPileupCorrection::~PulseShapeFitOOTPileupCorrection() { if(hybridfitter) delete hybridfitter; - if(spfunctor_) delete spfunctor_; - if(dpfunctor_) delete dpfunctor_; - if(tpfunctor_) delete tpfunctor_; } void PulseShapeFitOOTPileupCorrection::setChi2Term( bool isHPD ) { @@ -278,24 +275,25 @@ void PulseShapeFitOOTPileupCorrection::setPUParams(bool iPedestalConstraint, b } void PulseShapeFitOOTPileupCorrection::setPulseShapeTemplate(const HcalPulseShapes::Shape& ps, bool isHPD) { - // initialize for every hit now to avoid incorrect settings for different channel types (HPD vs SiPM) - // FIXME: keep this as a reminder to improve and reduce CPU use - // if( cntsetPulseShape ) return; - - // set the M2 parameters before defining the shape - setChi2Term(isHPD); - - resetPulseShapeTemplate(ps); - + // initialize for every different channel types (HPD vs SiPM) + + if (!(&ps == currentPulseShape_ && isHPD == isCurrentChannelHPD_)) + { + setChi2Term(isHPD); + resetPulseShapeTemplate(ps); + currentPulseShape_ = &ps; + isCurrentChannelHPD_ = isHPD; + } } void PulseShapeFitOOTPileupCorrection::resetPulseShapeTemplate(const HcalPulseShapes::Shape& ps) { ++ cntsetPulseShape; psfPtr_.reset(new FitterFuncs::PulseShapeFunctor(ps,pedestalConstraint_,timeConstraint_,addPulseJitter_,applyTimeSlew_, pulseJitter_,timeMean_,timeSig_,pedMean_,pedSig_,noise_)); - spfunctor_ = new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::singlePulseShapeFunc, 3); - dpfunctor_ = new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::doublePulseShapeFunc, 5); - tpfunctor_ = new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::triplePulseShapeFunc, 7); + spfunctor_ = std::unique_ptr( new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::singlePulseShapeFunc, 3) ); + dpfunctor_ = std::unique_ptr( new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::doublePulseShapeFunc, 5) ); + tpfunctor_ = std::unique_ptr( new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::triplePulseShapeFunc, 7) ); + } void PulseShapeFitOOTPileupCorrection::apply(const CaloSamples & cs,