Skip to content

Commit

Permalink
use heap memory saver solution instead of vector
Browse files Browse the repository at this point in the history
  • Loading branch information
mariadalfonso committed Aug 15, 2016
1 parent 900f14c commit 3551190
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 61 deletions.
14 changes: 7 additions & 7 deletions RecoLocalCalo/HcalRecAlgos/interface/HcalDeterministicFit.h
Expand Up @@ -21,11 +21,12 @@ class HcalDeterministicFit {
void init(HcalTimeSlew::ParaSource tsParam, HcalTimeSlew::BiasSetting bias, PedestalSub pedSubFxn_, std::vector<double> pars, double respCorr);

void phase1Apply(const HBHEChannelInfo& channelData,
std::vector<double> & Output) const;
float& reconstructedEnergy,
float& reconstructedTime) const;

// This is the CMSSW Implementation of the apply function
template<class Digi>
void apply(const CaloSamples & cs, const std::vector<int> & capidvec, const HcalCalibrations & calibs, const Digi & digi, std::vector<double> & Output) const;
void apply(const CaloSamples & cs, const std::vector<int> & capidvec, const HcalCalibrations & calibs, const Digi & digi, double& ampl, float &time) const;
void getLandauFrac(float tStart, float tEnd, float &sum) const;

private:
Expand Down Expand Up @@ -58,7 +59,7 @@ class HcalDeterministicFit {
};

template<class Digi>
void HcalDeterministicFit::apply(const CaloSamples & cs, const std::vector<int> & capidvec, const HcalCalibrations & calibs, const Digi & digi, std::vector<double> & Output) const {
void HcalDeterministicFit::apply(const CaloSamples & cs, const std::vector<int> & capidvec, const HcalCalibrations & calibs, const Digi & digi, double & reconstructedEnergy, float & reconstructedTime) const {
std::vector<double> corrCharge;
std::vector<double> inputCharge;
std::vector<double> inputPedestal;
Expand Down Expand Up @@ -149,11 +150,10 @@ void HcalDeterministicFit::apply(const CaloSamples & cs, const std::vector<int>
if (ch5<1) {
ch5=0;
}
Output.clear();
Output.push_back(ch4*gainCorr*respCorr);// amplitude
Output.push_back(tsShift4); // time shift of in-time pulse
Output.push_back(ch5); // whatever

double ampl=ch4*gainCorr*respCorr;
reconstructedEnergy=ampl;
reconstructedTime=tsShift4;
}


Expand Down
Expand Up @@ -91,9 +91,17 @@ class PulseShapeFitOOTPileupCorrection
~PulseShapeFitOOTPileupCorrection();

void phase1Apply(const HBHEChannelInfo& channelData,
std::vector<double> & correctedOutput) const;
float& reconstructedEnergy,
float& reconstructedTime,
bool & useTriple) const;

void apply(const CaloSamples & cs,
const std::vector<int> & capidvec,
const HcalCalibrations & calibs,
double& reconstructedEnergy,
float& reconstructedTime,
bool & useTriple) const;

void apply(const CaloSamples & cs, const std::vector<int> & capidvec, const HcalCalibrations & calibs, std::vector<double> & correctedOutput) const;
void setPUParams(bool iPedestalConstraint, bool iTimeConstraint,bool iAddPulseJitter,bool iUnConstrainedFit,bool iApplyTimeSlew,
double iTS4Min, std::vector<double> iTS4Max,
double iPulseJitter,
Expand All @@ -110,7 +118,7 @@ class PulseShapeFitOOTPileupCorrection

private:
int pulseShapeFit(const double * energyArr, const double * pedenArr, const double *chargeArr,
const double *pedArr, const double *gainArr, const double tsTOTen, std::vector<double> &fitParsVec, bool) const;
const double *pedArr, const double *gainArr, const double tsTOTen, std::vector<float> &fitParsVec, bool) const;
void fit(int iFit,float &timevalfit,float &chargevalfit,float &pedvalfit,float &chi2,bool &fitStatus,double &iTSMax,
const double &iTSTOTen,double *iEnArr,int (&iBX)[3]) const;

Expand Down
9 changes: 4 additions & 5 deletions RecoLocalCalo/HcalRecAlgos/src/HcalDeterministicFit.cc
Expand Up @@ -43,7 +43,8 @@ void HcalDeterministicFit::getLandauFrac(float tStart, float tEnd, float &sum) c
}

void HcalDeterministicFit::phase1Apply(const HBHEChannelInfo& channelData,
std::vector<double> & Output) const
float& reconstructedEnergy,
float& reconstructedTime) const
{

std::vector<double> corrCharge;
Expand Down Expand Up @@ -139,9 +140,7 @@ void HcalDeterministicFit::phase1Apply(const HBHEChannelInfo& channelData,
if (ch5<1) {
ch5=0;
}
Output.clear();
Output.push_back(ch4*gainCorr*respCorr);// amplitude
Output.push_back(tsShift4); // time shift of in-time pulse
Output.push_back(ch5); // whatever

reconstructedEnergy=ch4*gainCorr*respCorr;
reconstructedTime=tsShift4;
}
37 changes: 10 additions & 27 deletions RecoLocalCalo/HcalRecAlgos/src/HcalSimpleRecAlgo.cc
Expand Up @@ -349,7 +349,8 @@ namespace HcalSimpleRecAlgoImpl {

// Note that uncorr_ampl is always set from outside of method 2!
if( puCorrMethod == 2 ){
std::vector<double> correctedOutput;

bool useTriple=false;

CaloSamples cs;
coder.adc2fC(digi,cs);
Expand All @@ -358,16 +359,12 @@ namespace HcalSimpleRecAlgoImpl {
const int capid = digi[ip].capid();
capidvec.push_back(capid);
}
psFitOOTpuCorr->apply(cs, capidvec, calibs, correctedOutput);
if( correctedOutput.back() == 0 && correctedOutput.size() >1 ){
time = correctedOutput[1]; ampl = correctedOutput[0];
}
psFitOOTpuCorr->apply(cs, capidvec, calibs, ampl, time, useTriple);
}

// S. Brandt - Feb 19th : Adding Section for HLT
// Run "Method 3" all the time.
{
std::vector<double> hltCorrOutput;

CaloSamples cs;
coder.adc2fC(digi,cs);
Expand All @@ -376,13 +373,8 @@ namespace HcalSimpleRecAlgoImpl {
const int capid = digi[ip].capid();
capidvec.push_back(capid);
}
hltOOTpuCorr->apply(cs, capidvec, calibs, digi, hltCorrOutput);
if( hltCorrOutput.size() > 1 ){
m3_ampl = hltCorrOutput[0];
if (puCorrMethod == 3) {
time = hltCorrOutput[1]; ampl = hltCorrOutput[0];
}
}
hltOOTpuCorr->apply(cs, capidvec, calibs, digi, m3_ampl,time);
if (puCorrMethod == 3) ampl = m3_ampl;
}

// Temporary hack to apply energy-dependent corrections to some HB- cells
Expand Down Expand Up @@ -456,7 +448,6 @@ namespace HcalSimpleRecAlgoImpl {

// Note that uncorr_ampl is always set from outside of method 2!
if( puCorrMethod == 2 ){
std::vector<double> correctedOutput;

CaloSamples cs;
coder.adc2fC(digi,cs);
Expand All @@ -465,17 +456,12 @@ namespace HcalSimpleRecAlgoImpl {
const int capid = digi[ip].capid();
capidvec.push_back(capid);
}
psFitOOTpuCorr->apply(cs, capidvec, calibs, correctedOutput);
if( correctedOutput.back() == 0 && correctedOutput.size() >1 ){
time = correctedOutput[1]; ampl = correctedOutput[0];
useTriple = correctedOutput[4];
}
psFitOOTpuCorr->apply(cs, capidvec, calibs, ampl, time, useTriple);
}

// S. Brandt - Feb 19th : Adding Section for HLT
// Run "Method 3" all the time.
{
std::vector<double> hltCorrOutput;

CaloSamples cs;
coder.adc2fC(digi,cs);
Expand All @@ -484,13 +470,10 @@ namespace HcalSimpleRecAlgoImpl {
const int capid = digi[ip].capid();
capidvec.push_back(capid);
}
hltOOTpuCorr->apply(cs, capidvec, calibs, digi, hltCorrOutput);
if (hltCorrOutput.size() > 1) {
m3_ampl = hltCorrOutput[0];
if (puCorrMethod == 3) {
time = hltCorrOutput[1]; ampl = hltCorrOutput[0];
}
}

hltOOTpuCorr->apply(cs, capidvec, calibs, digi, m3_ampl, time);
if (puCorrMethod == 3) ampl = m3_ampl;

}

// Temporary hack to apply energy-dependent corrections to some HB- cells
Expand Down
31 changes: 22 additions & 9 deletions RecoLocalCalo/HcalRecAlgos/src/PulseShapeFitOOTPileupCorrection.cc
Expand Up @@ -293,7 +293,12 @@ void PulseShapeFitOOTPileupCorrection::resetPulseShapeTemplate(const HcalPulseSh
tpfunctor_ = new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::triplePulseShapeFunc, 7);
}

void PulseShapeFitOOTPileupCorrection::apply(const CaloSamples & cs, const std::vector<int> & capidvec, const HcalCalibrations & calibs, std::vector<double> & correctedOutput) const
void PulseShapeFitOOTPileupCorrection::apply(const CaloSamples & cs,
const std::vector<int> & capidvec,
const HcalCalibrations & calibs,
double& reconstructedEnergy,
float& reconstructedTime,
bool& useTriple) const
{
psfPtr_->setDefaultcntNANinfit();

Expand Down Expand Up @@ -325,7 +330,7 @@ void PulseShapeFitOOTPileupCorrection::apply(const CaloSamples & cs, const std::

ts4Max_=vts4Max_[0]; // HB and HE are identical for Run2

std::vector<double> fitParsVec;
std::vector<float> fitParsVec;
if(tstrig >= ts4Min_&& tsTOTen > 0.) { //Two sigma from 0
pulseShapeFit(energyArr, pedenArr, chargeArr, pedArr, gainArr, tsTOTen, fitParsVec,true);
}
Expand All @@ -337,12 +342,16 @@ void PulseShapeFitOOTPileupCorrection::apply(const CaloSamples & cs, const std::
fitParsVec.push_back(999.);
fitParsVec.push_back(false);
}
correctedOutput.swap(fitParsVec); correctedOutput.push_back(psfPtr_->getcntNANinfit());

reconstructedEnergy=fitParsVec[0];
reconstructedTime=fitParsVec[1];
useTriple=fitParsVec[4];

}

constexpr char const* varNames[] = {"time", "energy","time1","energy1","time2","energy2", "ped"};

int PulseShapeFitOOTPileupCorrection::pulseShapeFit(const double * energyArr, const double * pedenArr, const double *chargeArr, const double *pedArr, const double *gainArr, const double tsTOTen, std::vector<double> &fitParsVec, bool useADCgranularity) const {
int PulseShapeFitOOTPileupCorrection::pulseShapeFit(const double * energyArr, const double * pedenArr, const double *chargeArr, const double *pedArr, const double *gainArr, const double tsTOTen, std::vector<float> &fitParsVec, bool useADCgranularity) const {
double tsMAX=0;
int nAboveThreshold = 0;
double tmpx[HcalConst::maxSamples], tmpy[HcalConst::maxSamples], tmperry[HcalConst::maxSamples],tmperry2[HcalConst::maxSamples],tmpslew[HcalConst::maxSamples];
Expand Down Expand Up @@ -504,9 +513,10 @@ void PulseShapeFitOOTPileupCorrection::fit(int iFit,float &timevalfit,float &cha
}
}

void PulseShapeFitOOTPileupCorrection::phase1Apply(
const HBHEChannelInfo& channelData,
std::vector<double> & correctedOutput) const
void PulseShapeFitOOTPileupCorrection::phase1Apply(const HBHEChannelInfo& channelData,
float& reconstructedEnergy,
float& reconstructedTime,
bool& useTriple) const
{

psfPtr_->setDefaultcntNANinfit();
Expand Down Expand Up @@ -546,7 +556,7 @@ void PulseShapeFitOOTPileupCorrection::phase1Apply(
if(channelData.id().subdet() == HcalSubdetector::HcalBarrel) ts4Max_=vts4Max_[0];
if(channelData.id().subdet() == HcalSubdetector::HcalEndcap) ts4Max_=vts4Max_[1];

std::vector<double> fitParsVec;
std::vector<float> fitParsVec;
if(tstrig >= ts4Min_ && tsTOTen > 0.) { //Two sigma from 0
pulseShapeFit(energyArr, pedenArr, chargeArr, pedArr, gainArr, tsTOTen, fitParsVec,useADC);
}
Expand All @@ -558,6 +568,9 @@ void PulseShapeFitOOTPileupCorrection::phase1Apply(
fitParsVec.push_back(999.);
fitParsVec.push_back(false);
}
correctedOutput.swap(fitParsVec); correctedOutput.push_back(psfPtr_->getcntNANinfit());

reconstructedEnergy = fitParsVec[0];
reconstructedTime = fitParsVec[1];
useTriple = fitParsVec[4];

}
12 changes: 2 additions & 10 deletions RecoLocalCalo/HcalRecAlgos/src/SimpleHBHEPhase1Algo.cc
Expand Up @@ -95,12 +95,7 @@ HBHERecHit SimpleHBHEPhase1Algo::reconstruct(const HBHEChannelInfo& info,
if(info.id().subdet() == HcalSubdetector::HcalEndcap) psFitOOTpuCorr_->setPulseShapeTemplate(theHcalPulseShapes_.getShape(SiPMShapev3MCNum),1);
}

std::vector<double> correctedOutput;
method2->phase1Apply(info, correctedOutput);

m2E = correctedOutput[0];
m2t = correctedOutput[1];
// useTriple=correctedOutput[4];
method2->phase1Apply(info, m2E, m2t, useTriple);

m2E *= hbminusCorrectionFactor(channelId, m2E, isData); // not sure what this does

Expand All @@ -112,10 +107,7 @@ HBHERecHit SimpleHBHEPhase1Algo::reconstruct(const HBHEChannelInfo& info,
if (method3)
{

std::vector<double> hltCorrOutput;

method3->phase1Apply(info, hltCorrOutput);
m3t = hltCorrOutput[1]; m3E = hltCorrOutput[0];
method3->phase1Apply(info, m3E, m3t);

m3E *= hbminusCorrectionFactor(channelId, m3E, isData); // not sure what this does

Expand Down

0 comments on commit 3551190

Please sign in to comment.