Skip to content

Commit

Permalink
Merge pull request #45388 from jking79/pr_master_cc_slew_correction
Browse files Browse the repository at this point in the history
Backport to 14_0_X of PR#45386 "Updated EcalUncalibRecHitTimingCCAlgo to correct for bias at high energies"
  • Loading branch information
cmsbuild authored Jul 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents dfbad95 + 15b297b commit e077eec
Showing 3 changed files with 50 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -24,7 +24,8 @@ class EcalUncalibRecHitTimingCCAlgo {
const EcalMGPAGainRatio* aGain,
const FullSampleVector& fullpulse,
const float targetTimePrecision,
const bool correctForOOT = true) const;
const bool correctForOOT = true,
const bool correctForSlew = true) const;

private:
const float startTime_;
@@ -38,7 +39,10 @@ class EcalUncalibRecHitTimingCCAlgo {
static constexpr float ONE_MINUS_GOLDEN_RATIO = 1.0 - GOLDEN_RATIO;

FullSampleVector interpolatePulse(const FullSampleVector& fullpulse, const float t = 0) const;
float computeCC(const std::vector<float>& samples, const FullSampleVector& sigmalTemplate, const float t) const;
float computeCC(const std::vector<float>& samples,
const std::vector<float>& weights,
const FullSampleVector& sigmalTemplate,
const float t) const;
};

#endif
32 changes: 22 additions & 10 deletions RecoLocalCalo/EcalRecAlgos/src/EcalUncalibRecHitTimingCCAlgo.cc
Original file line number Diff line number Diff line change
@@ -9,13 +9,15 @@ double EcalUncalibRecHitTimingCCAlgo::computeTimeCC(const EcalDataFrame& dataFra
const EcalMGPAGainRatio* aGain,
const FullSampleVector& fullpulse,
const float targetTimePrecision,
const bool correctForOOT) const {
const bool correctForOOT,
const bool correctForSlew) const {
constexpr unsigned int nsample = EcalDataFrame::MAXSAMPLES;

double maxamplitude = -std::numeric_limits<double>::max();
float pulsenorm = 0.;

std::vector<float> pedSubSamples(nsample);
std::vector<float> weights(nsample, 1.f);
for (unsigned int iSample = 0; iSample < nsample; iSample++) {
const EcalMGPASample& sample = dataFrame.sample(iSample);

@@ -45,10 +47,19 @@ double EcalUncalibRecHitTimingCCAlgo::computeTimeCC(const EcalDataFrame& dataFra

pedSubSamples[iSample] = amplitude;

pulsenorm += fullpulse(iSample);

if (amplitude > maxamplitude) {
maxamplitude = amplitude;
}
pulsenorm += fullpulse(iSample);

if (iSample > 0 && correctForSlew) {
int GainIdPrev = dataFrame.sample(iSample - 1).gainId();
bool GainIdInRange = GainIdPrev >= 1 && GainIdPrev <= 3 && gainId >= 1 && gainId <= 3;
bool GainSlew = GainIdPrev < gainId;
if (GainIdInRange && GainSlew)
weights[iSample - 1] = 0.f;
}
}

if (correctForOOT) {
@@ -61,7 +72,7 @@ double EcalUncalibRecHitTimingCCAlgo::computeTimeCC(const EcalDataFrame& dataFra

for (unsigned int isample = firstsamplet; isample < nsample; ++isample) {
auto const pulse = fullpulse(isample + offset);
pedSubSamples[isample] = std::max(0., pedSubSamples[isample] - amplit * pulse / pulsenorm);
pedSubSamples[isample] = pedSubSamples[isample] - (amplit * pulse / pulsenorm);
}
}
}
@@ -74,9 +85,9 @@ double EcalUncalibRecHitTimingCCAlgo::computeTimeCC(const EcalDataFrame& dataFra

int counter = 0;

float cc1 = computeCC(pedSubSamples, fullpulse, t1);
float cc1 = computeCC(pedSubSamples, weights, fullpulse, t1);
++counter;
float cc2 = computeCC(pedSubSamples, fullpulse, t2);
float cc2 = computeCC(pedSubSamples, weights, fullpulse, t2);
++counter;

while (std::abs(t3 - t0) > targetTimePrecision && counter < MAX_NUM_OF_ITERATIONS) {
@@ -85,14 +96,14 @@ double EcalUncalibRecHitTimingCCAlgo::computeTimeCC(const EcalDataFrame& dataFra
t1 = t2;
t2 = GOLDEN_RATIO * t2 + ONE_MINUS_GOLDEN_RATIO * t3;
cc1 = cc2;
cc2 = computeCC(pedSubSamples, fullpulse, t2);
cc2 = computeCC(pedSubSamples, weights, fullpulse, t2);
++counter;
} else {
t3 = t2;
t2 = t1;
t1 = GOLDEN_RATIO * t1 + ONE_MINUS_GOLDEN_RATIO * t0;
cc2 = cc1;
cc1 = computeCC(pedSubSamples, fullpulse, t1);
cc1 = computeCC(pedSubSamples, weights, fullpulse, t1);
++counter;
}
}
@@ -144,6 +155,7 @@ FullSampleVector EcalUncalibRecHitTimingCCAlgo::interpolatePulse(const FullSampl
}

float EcalUncalibRecHitTimingCCAlgo::computeCC(const std::vector<float>& samples,
const std::vector<float>& weights,
const FullSampleVector& signalTemplate,
const float time) const {
constexpr int exclude = 1;
@@ -152,9 +164,9 @@ float EcalUncalibRecHitTimingCCAlgo::computeCC(const std::vector<float>& samples
float cc = 0.;
auto interpolated = interpolatePulse(signalTemplate, time);
for (int i = exclude; i < int(samples.size() - exclude); ++i) {
powerSamples += std::pow(samples[i], 2);
powerTemplate += std::pow(interpolated[i], 2);
cc += interpolated[i] * samples[i];
powerSamples += std::pow(samples[i], 2) * weights[i];
powerTemplate += std::pow(interpolated[i], 2) * weights[i];
cc += interpolated[i] * samples[i] * weights[i];
}

float denominator = std::sqrt(powerTemplate * powerSamples);
Original file line number Diff line number Diff line change
@@ -169,6 +169,8 @@ class EcalUncalibRecHitWorkerMultiFit final : public EcalUncalibRecHitWorkerBase
double CCTimeShiftWrtRations_;
double CCtargetTimePrecision_;
double CCtargetTimePrecisionForDelayedPulses_;
bool crossCorrelationUseSlewCorrectionEB_;
bool crossCorrelationUseSlewCorrectionEE_;
};

EcalUncalibRecHitWorkerMultiFit::EcalUncalibRecHitWorkerMultiFit(const edm::ParameterSet& ps, edm::ConsumesCollector& c)
@@ -238,11 +240,13 @@ EcalUncalibRecHitWorkerMultiFit::EcalUncalibRecHitWorkerMultiFit(const edm::Para
CCminTimeToBeLateMin_ = ps.getParameter<double>("crossCorrelationMinTimeToBeLateMin") / ecalcctiming::clockToNS;
CCminTimeToBeLateMax_ = ps.getParameter<double>("crossCorrelationMinTimeToBeLateMax") / ecalcctiming::clockToNS;
CCTimeShiftWrtRations_ = ps.getParameter<double>("crossCorrelationTimeShiftWrtRations");
crossCorrelationUseSlewCorrectionEB_ = ps.getParameter<bool>("crossCorrelationUseSlewCorrectionEB");
crossCorrelationUseSlewCorrectionEE_ = ps.getParameter<bool>("crossCorrelationUseSlewCorrectionEE");
computeCC_ = std::make_unique<EcalUncalibRecHitTimingCCAlgo>(startTime, stopTime);
} else if (timeAlgoName != "None")
edm::LogError("EcalUncalibRecHitError") << "No time estimation algorithm defined";

// ratio method parameters
// time reco parameters
EBtimeFitParameters_ = ps.getParameter<std::vector<double>>("EBtimeFitParameters");
EEtimeFitParameters_ = ps.getParameter<std::vector<double>>("EEtimeFitParameters");
EBamplitudeFitParameters_ = ps.getParameter<std::vector<double>>("EBamplitudeFitParameters");
@@ -640,13 +644,21 @@ void EcalUncalibRecHitWorkerMultiFit::run(const edm::Event& evt,
for (unsigned int ibx = 0; ibx < activeBX.size(); ++ibx)
amplitudes[ibx] = uncalibRecHit.outOfTimeAmplitude(ibx);

float jitter =
computeCC_->computeTimeCC(*itdg, amplitudes, aped, aGain, fullpulse, CCtargetTimePrecision_, true) +
CCTimeShiftWrtRations_ / ecalcctiming::clockToNS;
float noCorrectedJitter =
computeCC_->computeTimeCC(
*itdg, amplitudes, aped, aGain, fullpulse, CCtargetTimePrecisionForDelayedPulses_, false) +
CCTimeShiftWrtRations_ / ecalcctiming::clockToNS;
bool const doSlewCorrection =
barrel ? crossCorrelationUseSlewCorrectionEB_ : crossCorrelationUseSlewCorrectionEE_;

float jitter = computeCC_->computeTimeCC(
*itdg, amplitudes, aped, aGain, fullpulse, CCtargetTimePrecision_, true, doSlewCorrection) +
CCTimeShiftWrtRations_ / ecalcctiming::clockToNS;
float noCorrectedJitter = computeCC_->computeTimeCC(*itdg,
amplitudes,
aped,
aGain,
fullpulse,
CCtargetTimePrecisionForDelayedPulses_,
false,
doSlewCorrection) +
CCTimeShiftWrtRations_ / ecalcctiming::clockToNS;

uncalibRecHit.setJitter(jitter);
uncalibRecHit.setNonCorrectedTime(jitter, noCorrectedJitter);
@@ -783,6 +795,8 @@ edm::ParameterSetDescription EcalUncalibRecHitWorkerMultiFit::getAlgoDescription
edm::ParameterDescription<double>("outOfTimeThresholdGain61mEE", 1000, true) and
edm::ParameterDescription<double>("amplitudeThresholdEB", 10, true) and
edm::ParameterDescription<double>("amplitudeThresholdEE", 10, true) and
edm::ParameterDescription<bool>("crossCorrelationUseSlewCorrectionEB", true, true) and
edm::ParameterDescription<bool>("crossCorrelationUseSlewCorrectionEE", false, true) and
edm::ParameterDescription<double>("crossCorrelationStartTime", -25.0, true) and
edm::ParameterDescription<double>("crossCorrelationStopTime", 25.0, true) and
edm::ParameterDescription<double>("crossCorrelationTargetTimePrecision", 0.01, true) and

0 comments on commit e077eec

Please sign in to comment.