-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Cross-correlation algorithm for the ECAL timing reconstruction #33119
Merged
Merged
Changes from 25 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
7ba20c8
Rebasing kucc for 11_3
nminafra 38506d2
Simplified inclusion of kucc
nminafra a93f1a2
Implemented thomreis suggestions iteration 1
nminafra c0bdba3
scram build code-format
nminafra a7b115f
kansasMethodCC renamed as crossCorrelationMethod
nminafra 857a61c
added comment for magic constants from EcalUncalibRecHitTimeWeightsAl…
nminafra 4d1c340
kansasMethodCC renamed as crossCorrelationMethod complete
nminafra 13690d6
Second round of thomreis comments
nminafra 465da15
Code cleanup and small performance optimization (EcalUncalibRecHitTim…
nminafra 514e38d
Added parameters in python files
nminafra d183be0
Added parameters to ParameterSetDescription
nminafra a74b1fc
Adding test file dedicated to CC method
nminafra 75833b8
working test file
nminafra 21901ad
LogWarning to LogInfo when too many CC iterations
nminafra 3be47f2
slightly more efficient
nminafra a916b16
Cleanup
nminafra 1e4a5df
Cleanup of test
nminafra 252a9e4
code-checks and code-format
nminafra 45c5972
Further cleanup
nminafra ad7d742
Fixeing clang warnings
nminafra ba9e43b
Removing destructor
nminafra 0179ab0
Passing float by value
nminafra e770087
Constexpr
nminafra 4904d82
More efficient access to vector elements
nminafra ddf38c2
C++ style cast
nminafra f5743f8
Using range loop
nminafra 5d248d8
Efficiency improvement
nminafra c7f9e7d
Efficiency improvement
nminafra 062cc95
Efficiency improvement
nminafra 81c6ce9
const added
nminafra b81a2a7
const added
nminafra 421fe2f
Const added
nminafra 6af8364
rule 2.12
nminafra 03a441f
Avoid repeated computation inside the loop
nminafra d29bd1b
rule 2.12
nminafra f21df41
Constexpr
nminafra 4f60d30
Efficiency improvement
nminafra 3d10143
Reordered public/private
nminafra ad0c604
Using fac,facM1orP2,facP1
nminafra 44df65f
Using fac,facM1orP2,facP1
nminafra 21cd746
Cleaner test file
nminafra cf995bc
Using unique_ptr for EcalUncalibRecHitTimingCCAlgo
nminafra 3f74b66
Using single precision float
nminafra cb78d71
Removed log
nminafra 8442f0b
code-format
nminafra e47da18
Minor fixes
nminafra e10760c
errOnTime fix
nminafra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,18 +11,17 @@ double EcalUncalibRecHitTimingCCAlgo::computeTimeCC(const EcalDataFrame& dataFra | |
const EcalMGPAGainRatio* aGain, | ||
const FullSampleVector& fullpulse, | ||
EcalUncalibratedRecHit& uncalibRecHit, | ||
float& errOnTime) { | ||
const unsigned int nsample = EcalDataFrame::MAXSAMPLES; | ||
float errOnTime) const { | ||
constexpr unsigned int nsample = EcalDataFrame::MAXSAMPLES; | ||
|
||
double maxamplitude = -std::numeric_limits<double>::max(); | ||
float pulsenorm = 0.; | ||
|
||
double pulsenorm = 0.; | ||
|
||
std::vector<double> pedSubSamples(nsample); | ||
std::vector<float> pedSubSamples(nsample); | ||
for (unsigned int iSample = 0; iSample < nsample; iSample++) { | ||
const EcalMGPASample& sample = dataFrame.sample(iSample); | ||
|
||
double amplitude = 0.; | ||
float amplitude = 0.; | ||
int gainId = sample.gainId(); | ||
|
||
double pedestal = 0.; | ||
|
@@ -39,37 +38,35 @@ double EcalUncalibRecHitTimingCCAlgo::computeTimeCC(const EcalDataFrame& dataFra | |
gainratio = aGain->gain12Over6(); | ||
} | ||
|
||
amplitude = ((double)(sample.adc()) - pedestal) * gainratio; | ||
amplitude = (static_cast<float>(sample.adc()) - pedestal) * gainratio; | ||
|
||
if (gainId == 0) { | ||
//saturation | ||
amplitude = (4095. - pedestal) * gainratio; | ||
} | ||
|
||
pedSubSamples.at(iSample) = amplitude; | ||
pedSubSamples[iSample] = amplitude; | ||
|
||
if (amplitude > maxamplitude) { | ||
maxamplitude = amplitude; | ||
} | ||
pulsenorm += fullpulse(iSample); | ||
} | ||
|
||
std::vector<double>::const_iterator amplit; | ||
for (amplit = amplitudes.begin(); amplit < amplitudes.end(); ++amplit) { | ||
int ipulse = std::distance(amplitudes.begin(), amplit); | ||
// The following 3 lines are copied from EcalRecAlgos/interface/EcalUncalibRecHitTimeWeightsAlgo.h | ||
int bx = ipulse - 5; | ||
int firstsamplet = std::max(0, bx + 3); | ||
int offset = 7 - 3 - bx; | ||
int ipulse = -1; | ||
for (auto const& amplit : amplitudes) { | ||
ipulse++; | ||
int bxp3 = ipulse - 2; | ||
int firstsamplet = std::max(0, bxp3); | ||
int offset = 7 - bxp3; | ||
|
||
std::vector<double> pulse(nsample); | ||
for (unsigned int isample = firstsamplet; isample < nsample; ++isample) { | ||
pulse.at(isample) = fullpulse(isample + offset); | ||
pedSubSamples.at(isample) = | ||
std::max(0., pedSubSamples.at(isample) - amplitudes[ipulse] * pulse.at(isample) / pulsenorm); | ||
auto const pulse = fullpulse(isample + offset); | ||
pedSubSamples[isample] = std::max(0., pedSubSamples[isample] - amplit * pulse / pulsenorm); | ||
} | ||
} | ||
|
||
// Start of time computation | ||
float tStart = startTime_ + GLOBAL_TIME_SHIFT; | ||
float tStop = stopTime_ + GLOBAL_TIME_SHIFT; | ||
float tM = (tStart + tStop) / 2; | ||
|
@@ -94,10 +91,6 @@ double EcalUncalibRecHitTimingCCAlgo::computeTimeCC(const EcalDataFrame& dataFra | |
tM -= GLOBAL_TIME_SHIFT; | ||
|
||
if (counter < MIN_NUM_OF_ITERATIONS || counter > MAX_NUM_OF_ITERATIONS - 1) { | ||
if (counter > MAX_NUM_OF_ITERATIONS / 2) | ||
//Produce a log if minimization took too long | ||
edm::LogInfo("EcalUncalibRecHitTimingCCAlgo::computeTimeCC") | ||
<< "Minimization Counter too high: " << counter << std::endl; | ||
tM = TIME_WHEN_NOT_CONVERGING * ecalPh1::Samp_Period; | ||
//Negative error means that there was a problem with the CC | ||
errOnTime = -targetTimePrecision_ / ecalPh1::Samp_Period; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, I do not see a value assigned to |
||
|
@@ -106,33 +99,34 @@ double EcalUncalibRecHitTimingCCAlgo::computeTimeCC(const EcalDataFrame& dataFra | |
return -tM / ecalPh1::Samp_Period; | ||
} | ||
|
||
FullSampleVector EcalUncalibRecHitTimingCCAlgo::interpolatePulse(const FullSampleVector& fullpulse, const float t) { | ||
FullSampleVector EcalUncalibRecHitTimingCCAlgo::interpolatePulse(const FullSampleVector& fullpulse, | ||
const float time) const { | ||
// t is in ns | ||
int shift = t / ecalPh1::Samp_Period; | ||
if (t < 0) | ||
int shift = time / ecalPh1::Samp_Period; | ||
if (time < 0) | ||
shift -= 1; | ||
float timeShift = t - ecalPh1::Samp_Period * shift; | ||
float tt = timeShift / ecalPh1::Samp_Period; | ||
float tt = time / ecalPh1::Samp_Period - shift; | ||
|
||
FullSampleVector interpPulse; | ||
// 2nd poly with avg | ||
unsigned int numberOfSamples = fullpulse.size(); | ||
auto facM1orP2 = 0.25 * tt * (tt - 1); | ||
auto fac = (0.25 * (tt - 2) - 0.5 * (tt + 1)) * (tt - 1); | ||
auto facP1 = (0.25 * (tt + 1) - 0.5 * (tt - 2)) * tt; | ||
for (unsigned int i = 1; i < numberOfSamples - 2; ++i) { | ||
float a = 0.25 * tt * (tt - 1) * fullpulse[i - 1] + (0.25 * (tt - 2) - 0.5 * (tt + 1)) * (tt - 1) * fullpulse[i] + | ||
(0.25 * (tt + 1) - 0.5 * (tt - 2)) * tt * fullpulse[i + 1] + 0.25 * (tt - 1) * tt * fullpulse[i + 2]; | ||
float a = | ||
facM1orP2 * fullpulse[i - 1] + fac * fullpulse[i] + facP1 * fullpulse[i + 1] + facM1orP2 * fullpulse[i + 2]; | ||
if (a > 0) | ||
interpPulse[i] = a; | ||
else | ||
interpPulse[i] = 0; | ||
} | ||
interpPulse[0] = (0.25 * (tt - 2) - 0.5 * (tt + 1)) * ((tt - 1) * fullpulse[0]) + | ||
(0.25 * (tt + 1) + 0.5 * (tt - 2)) * tt * fullpulse[1] + 0.25 * tt * (tt - 1) * fullpulse[2]; | ||
interpPulse[numberOfSamples - 2] = 0.25 * tt * (tt - 1) * fullpulse[numberOfSamples - 3] + | ||
(0.25 * (tt - 2) - 0.5 * (tt + 1)) * (tt - 1) * fullpulse[numberOfSamples - 2] + | ||
(0.25 * (tt + 1) - 0.5 * (tt - 2)) * tt * fullpulse[numberOfSamples - 1]; | ||
interpPulse[numberOfSamples - 1] = 0.5 * tt * (tt - 1) * fullpulse[numberOfSamples - 2] - | ||
(tt * tt - 1) * fullpulse[numberOfSamples - 1] + | ||
(0.25 * (tt + 1) - 0.5 * (tt - 2)) * tt * fullpulse[numberOfSamples - 1]; | ||
interpPulse[0] = facM1orP2 * fullpulse[0] + facP1 * fullpulse[1] + facM1orP2 * fullpulse[2]; | ||
interpPulse[numberOfSamples - 2] = facM1orP2 * fullpulse[numberOfSamples - 3] + fac * fullpulse[numberOfSamples - 2] + | ||
facP1 * fullpulse[numberOfSamples - 1]; | ||
interpPulse[numberOfSamples - 1] = 2 * facM1orP2 * fullpulse[numberOfSamples - 2] - | ||
4 * facM1orP2 * fullpulse[numberOfSamples - 1] + | ||
facP1 * fullpulse[numberOfSamples - 1]; | ||
|
||
FullSampleVector interpPulseShifted; | ||
for (int i = 0; i < interpPulseShifted.size(); ++i) { | ||
|
@@ -144,24 +138,20 @@ FullSampleVector EcalUncalibRecHitTimingCCAlgo::interpolatePulse(const FullSampl | |
return interpPulseShifted; | ||
} | ||
|
||
float EcalUncalibRecHitTimingCCAlgo::computeCC(const std::vector<double>& samples, | ||
float EcalUncalibRecHitTimingCCAlgo::computeCC(const std::vector<float>& samples, | ||
const FullSampleVector& sigmalTemplate, | ||
nminafra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const float& t) { | ||
int exclude = 1; | ||
double powerSamples = 0.; | ||
for (int i = exclude; i < int(samples.size() - exclude); ++i) | ||
const float time) const { | ||
constexpr int exclude = 1; | ||
float powerSamples = 0.; | ||
float powerTemplate = 0.; | ||
float cc = 0.; | ||
auto interpolated = interpolatePulse(sigmalTemplate, time); | ||
for (int i = exclude; i < int(samples.size() - exclude); ++i) { | ||
powerSamples += std::pow(samples[i], 2); | ||
|
||
auto interpolated = interpolatePulse(sigmalTemplate, t); | ||
double powerTemplate = 0.; | ||
for (int i = exclude; i < int(interpolated.size() - exclude); ++i) | ||
powerTemplate += std::pow(interpolated[i], 2); | ||
|
||
double denominator = std::sqrt(powerTemplate * powerSamples); | ||
|
||
double cc = 0.; | ||
for (int i = exclude; i < int(samples.size() - exclude); ++i) { | ||
cc += interpolated[i] * samples[i]; | ||
} | ||
|
||
float denominator = std::sqrt(powerTemplate * powerSamples); | ||
return cc / denominator; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed only now thanks to the static analyzer https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-74f75c/13543/llvm-analysis/report-9ba007.html#EndPath.