-
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 45 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
43 changes: 43 additions & 0 deletions
43
RecoLocalCalo/EcalRecAlgos/interface/EcalUncalibRecHitTimingCCAlgo.h
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitTimingCCAlgo_HH | ||
#define RecoLocalCalo_EcalRecAlgos_EcalUncalibRecHitTimingCCAlgo_HH | ||
|
||
/** \class EcalUncalibRecHitTimingCCAlgo | ||
* CrossCorrelation algorithm for timing reconstruction | ||
* | ||
* \author N. Minafra, J. King, C. Rogan | ||
*/ | ||
|
||
#include "RecoLocalCalo/EcalRecAlgos/interface/EcalUncalibRecHitRecAbsAlgo.h" | ||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
|
||
#include "CondFormats/EcalObjects/interface/EcalPedestals.h" | ||
#include "CondFormats/EcalObjects/interface/EcalGainRatios.h" | ||
#include "DataFormats/EcalDigi/interface/EcalConstants.h" | ||
#include "RecoLocalCalo/EcalRecAlgos/interface/EigenMatrixTypes.h" | ||
|
||
class EcalUncalibRecHitTimingCCAlgo { | ||
public: | ||
EcalUncalibRecHitTimingCCAlgo(const float startTime, const float stopTime, const float targetTimePrecision); | ||
double computeTimeCC(const EcalDataFrame& dataFrame, | ||
const std::vector<double>& amplitudes, | ||
const EcalPedestals::Item* aped, | ||
const EcalMGPAGainRatio* aGain, | ||
const FullSampleVector& fullpulse, | ||
EcalUncalibratedRecHit& uncalibRecHit, | ||
float errOnTime) const; | ||
|
||
private: | ||
float startTime_; | ||
float stopTime_; | ||
float targetTimePrecision_; | ||
nminafra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
static constexpr int TIME_WHEN_NOT_CONVERGING = 100; | ||
static constexpr int MAX_NUM_OF_ITERATIONS = 30; | ||
static constexpr int MIN_NUM_OF_ITERATIONS = 2; | ||
static constexpr float GLOBAL_TIME_SHIFT = 100; | ||
|
||
FullSampleVector interpolatePulse(const FullSampleVector& fullpulse, const float t = 0) const; | ||
float computeCC(const std::vector<float>& samples, const FullSampleVector& sigmalTemplate, const float t) const; | ||
}; | ||
|
||
#endif |
157 changes: 157 additions & 0 deletions
157
RecoLocalCalo/EcalRecAlgos/src/EcalUncalibRecHitTimingCCAlgo.cc
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 |
---|---|---|
@@ -0,0 +1,157 @@ | ||
#include "RecoLocalCalo/EcalRecAlgos/interface/EcalUncalibRecHitTimingCCAlgo.h" | ||
|
||
EcalUncalibRecHitTimingCCAlgo::EcalUncalibRecHitTimingCCAlgo(const float startTime, | ||
const float stopTime, | ||
const float targetTimePrecision) | ||
: startTime_(startTime), stopTime_(stopTime), targetTimePrecision_(targetTimePrecision) {} | ||
|
||
double EcalUncalibRecHitTimingCCAlgo::computeTimeCC(const EcalDataFrame& dataFrame, | ||
const std::vector<double>& amplitudes, | ||
const EcalPedestals::Item* aped, | ||
const EcalMGPAGainRatio* aGain, | ||
const FullSampleVector& fullpulse, | ||
EcalUncalibratedRecHit& uncalibRecHit, | ||
float errOnTime) const { | ||
constexpr unsigned int nsample = EcalDataFrame::MAXSAMPLES; | ||
|
||
double maxamplitude = -std::numeric_limits<double>::max(); | ||
float pulsenorm = 0.; | ||
|
||
std::vector<float> pedSubSamples(nsample); | ||
for (unsigned int iSample = 0; iSample < nsample; iSample++) { | ||
const EcalMGPASample& sample = dataFrame.sample(iSample); | ||
|
||
float amplitude = 0.; | ||
int gainId = sample.gainId(); | ||
|
||
double pedestal = 0.; | ||
double gainratio = 1.; | ||
|
||
if (gainId == 0 || gainId == 3) { | ||
pedestal = aped->mean_x1; | ||
gainratio = aGain->gain6Over1() * aGain->gain12Over6(); | ||
} else if (gainId == 1) { | ||
pedestal = aped->mean_x12; | ||
gainratio = 1.; | ||
} else if (gainId == 2) { | ||
pedestal = aped->mean_x6; | ||
gainratio = aGain->gain12Over6(); | ||
} | ||
|
||
amplitude = (static_cast<float>(sample.adc()) - pedestal) * gainratio; | ||
|
||
if (gainId == 0) { | ||
//saturation | ||
amplitude = (4095. - pedestal) * gainratio; | ||
} | ||
|
||
pedSubSamples[iSample] = amplitude; | ||
|
||
if (amplitude > maxamplitude) { | ||
maxamplitude = amplitude; | ||
} | ||
pulsenorm += fullpulse(iSample); | ||
} | ||
|
||
int ipulse = -1; | ||
for (auto const& amplit : amplitudes) { | ||
ipulse++; | ||
int bxp3 = ipulse - 2; | ||
int firstsamplet = std::max(0, bxp3); | ||
int offset = 7 - bxp3; | ||
|
||
for (unsigned int isample = firstsamplet; isample < nsample; ++isample) { | ||
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; | ||
|
||
float distStart, distStop; | ||
int counter = 0; | ||
|
||
do { | ||
++counter; | ||
distStart = computeCC(pedSubSamples, fullpulse, tStart); | ||
distStop = computeCC(pedSubSamples, fullpulse, tStop); | ||
|
||
if (distStart > distStop) { | ||
tStop = tM; | ||
} else { | ||
tStart = tM; | ||
} | ||
tM = (tStart + tStop) / 2; | ||
|
||
} while (tStop - tStart > targetTimePrecision_ && counter < MAX_NUM_OF_ITERATIONS); | ||
|
||
tM -= GLOBAL_TIME_SHIFT; | ||
|
||
if (counter < MIN_NUM_OF_ITERATIONS || counter > MAX_NUM_OF_ITERATIONS - 1) { | ||
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 |
||
} | ||
|
||
return -tM / ecalPh1::Samp_Period; | ||
} | ||
|
||
FullSampleVector EcalUncalibRecHitTimingCCAlgo::interpolatePulse(const FullSampleVector& fullpulse, | ||
const float time) const { | ||
// t is in ns | ||
int shift = time / ecalPh1::Samp_Period; | ||
if (time < 0) | ||
shift -= 1; | ||
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 = | ||
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] = 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) { | ||
if (i + shift >= 0 && i + shift < interpPulse.size()) | ||
interpPulseShifted[i] = interpPulse[i + shift]; | ||
else | ||
interpPulseShifted[i] = 0; | ||
} | ||
return interpPulseShifted; | ||
} | ||
|
||
float EcalUncalibRecHitTimingCCAlgo::computeCC(const std::vector<float>& samples, | ||
const FullSampleVector& sigmalTemplate, | ||
nminafra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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); | ||
powerTemplate += std::pow(interpolated[i], 2); | ||
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
97 changes: 97 additions & 0 deletions
97
RecoLocalCalo/EcalRecProducers/test/testEcalUncalibRechitProducerWithCC_cfg.py
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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
from Configuration.StandardSequences.Eras import eras | ||
|
||
process = cms.Process('RECO', eras.Run2_2018) | ||
|
||
# import of standard configurations | ||
process.load('Configuration.StandardSequences.Services_cff') | ||
process.load('FWCore.MessageService.MessageLogger_cfi') | ||
process.load('Configuration.StandardSequences.GeometryRecoDB_cff') | ||
process.load('Configuration.StandardSequences.MagneticField_AutoFromDBCurrent_cff') | ||
process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') | ||
process.load('Configuration.StandardSequences.Reconstruction_cff') | ||
|
||
|
||
|
||
process.source = cms.Source('PoolSource', | ||
fileNames = cms.untracked.vstring( | ||
'/store/data/Run2018D/EGamma/RAW/v1/000/323/414/00000/042D6023-E0A2-8649-8D86-445F752A8F6B.root', | ||
), | ||
) | ||
|
||
|
||
# Other statements | ||
from Configuration.AlCa.GlobalTag import GlobalTag | ||
process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_data', '') | ||
|
||
|
||
process.maxEvents = cms.untracked.PSet( | ||
input = cms.untracked.int32(1000) | ||
) | ||
|
||
#----------------------------------------- | ||
# CMSSW/Hcal non-DQM Related Module import | ||
#----------------------------------------- | ||
process.load('Configuration.StandardSequences.GeometryRecoDB_cff') | ||
process.load("RecoLocalCalo.Configuration.hcalLocalReco_cff") | ||
process.load("RecoLocalCalo.Configuration.ecalLocalRecoSequence_cff") | ||
process.load("EventFilter.HcalRawToDigi.HcalRawToDigi_cfi") | ||
process.load("EventFilter.EcalRawToDigi.EcalUnpackerData_cfi") | ||
process.load("RecoLuminosity.LumiProducer.bunchSpacingProducer_cfi") | ||
|
||
# load both cpu plugins | ||
process.load("RecoLocalCalo.EcalRecProducers.ecalMultiFitUncalibRecHit_cfi") | ||
nminafra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## | ||
## force HLT configuration for ecalMultiFitUncalibRecHit | ||
## | ||
|
||
process.ecalMultiFitUncalibRecHit.algoPSet = cms.PSet( | ||
# for crossCorrelationMethod | ||
timealgo = cms.string( "crossCorrelationMethod" ), | ||
crossCorrelationStartTime = cms.double(-25), | ||
crossCorrelationStopTime = cms.double(25), | ||
crossCorrelationTargetTimePrecision = cms.double(0.01), | ||
) | ||
nminafra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## | ||
|
||
process.ecalDigis = process.ecalEBunpacker.clone() | ||
process.ecalDigis.InputLabel = cms.InputTag('rawDataCollector') | ||
|
||
process.out = cms.OutputModule( | ||
"PoolOutputModule", | ||
fileName = cms.untracked.string("test_uncalib.root") | ||
) | ||
|
||
process.finalize = cms.EndPath(process.out) | ||
|
||
process.bunchSpacing = cms.Path( | ||
process.bunchSpacingProducer | ||
) | ||
|
||
process.digiPath = cms.Path( | ||
process.ecalDigis | ||
) | ||
|
||
process.recoPath = cms.Path( | ||
process.ecalMultiFitUncalibRecHit | ||
*process.ecalRecHit | ||
) | ||
|
||
process.schedule = cms.Schedule( | ||
process.bunchSpacing, | ||
process.digiPath, | ||
process.recoPath, | ||
process.finalize | ||
) | ||
|
||
process.options = cms.untracked.PSet( | ||
numberOfThreads = cms.untracked.uint32(8), | ||
numberOfStreams = cms.untracked.uint32(8), | ||
SkipEvent = cms.untracked.vstring('ProductNotFound'), | ||
wantSummary = cms.untracked.bool(True) | ||
) | ||
|
||
|
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.