Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport to 14_0_X of PR#45386 "Updated EcalUncalibRecHitTimingCCAlgo to correct for bias at high energies" #45388

Merged
merged 5 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand All @@ -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
Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}
}
Expand All @@ -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) {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down