Skip to content

Commit

Permalink
Merge pull request #17822 from mariadalfonso/fixMemLeakM2_90
Browse files Browse the repository at this point in the history
HBHE M2 = fix Memory Leak (90X)
  • Loading branch information
cmsbuild committed Mar 13, 2017
2 parents fbff60f + ba6a953 commit 337d390
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class PulseShapeFitOOTPileupCorrection
double iTMin, double iTMax,
const std::vector<double> & its4Chi2, HcalTimeSlew::BiasSetting slewFlavor, int iFitTimes);

const HcalPulseShapes::Shape* currentPulseShape_=NULL;
void setChi2Term( bool isHPD );

void setPulseShapeTemplate (const HcalPulseShapes::Shape& ps, bool isHPD);
Expand All @@ -135,9 +136,9 @@ class PulseShapeFitOOTPileupCorrection
int fitTimes_;

std::unique_ptr<FitterFuncs::PulseShapeFunctor> psfPtr_;
ROOT::Math::Functor *spfunctor_;
ROOT::Math::Functor *dpfunctor_;
ROOT::Math::Functor *tpfunctor_;
std::unique_ptr<ROOT::Math::Functor> spfunctor_;
std::unique_ptr<ROOT::Math::Functor> dpfunctor_;
std::unique_ptr<ROOT::Math::Functor> tpfunctor_;
int TSMin_;
int TSMax_;
mutable double ts4Chi2_;
Expand All @@ -164,6 +165,7 @@ class PulseShapeFitOOTPileupCorrection
double noiseSiPM_;
HcalTimeSlew::BiasSetting slewFlavor_;

bool isCurrentChannelHPD_;
};

#endif // PulseShapeFitOOTPileupCorrection_h
28 changes: 13 additions & 15 deletions RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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<ROOT::Math::Functor>( new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::singlePulseShapeFunc, 3) );
dpfunctor_ = std::unique_ptr<ROOT::Math::Functor>( new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::doublePulseShapeFunc, 5) );
tpfunctor_ = std::unique_ptr<ROOT::Math::Functor>( new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::triplePulseShapeFunc, 7) );

}

void PulseShapeFitOOTPileupCorrection::apply(const CaloSamples & cs,
Expand Down

0 comments on commit 337d390

Please sign in to comment.