74 double timeCorrection(
float ampli,
const std::vector<float>& amplitudeBins,
const std::vector<float>& shiftBins);
178 for (
unsigned int ibx = 0; ibx <
activeBXs.size(); ++ibx) {
224 if (timeAlgoName ==
"RatioMethod")
226 else if (timeAlgoName ==
"WeightsMethod")
228 else if (timeAlgoName ==
"crossCorrelationMethod") {
231 double stopTime = ps.
getParameter<
double>(
"crossCorrelationStopTime");
234 ps.
getParameter<
double>(
"crossCorrelationTargetTimePrecisionForDelayedPulses");
239 }
else if (timeAlgoName !=
"None")
240 edm::LogError(
"EcalUncalibRecHitError") <<
"No time estimation algorithm defined";
293 int nnoise = SampleVector::RowsAtCompileTime;
301 for (
int i = 0;
i < nnoise; ++
i) {
302 for (
int j = 0;
j < nnoise; ++
j) {
315 unsigned int bunchspacing = 450;
320 bunchspacing = *bunchSpacingH;
326 if (bunchspacing == 25) {
328 activeBX << -5, -4, -3, -2, -1, 0, 1, 2, 3, 4;
347 const std::vector<float>& amplitudeBins,
348 const std::vector<float>& shiftBins) {
351 double theCorrection = 0;
354 if (amplitudeBins.empty()) {
355 edm::LogError(
"EcalRecHitError") <<
"timeCorrAmplitudeBins is empty, forcing no time bias corrections.";
360 if (amplitudeBins.size() != shiftBins.size()) {
361 edm::LogError(
"EcalRecHitError") <<
"Size of timeCorrAmplitudeBins different from " 362 "timeCorrShiftBins. Forcing no time bias corrections. ";
369 for (
int bin = 0;
bin < (
int)amplitudeBins.size();
bin++) {
370 if (ampli > amplitudeBins[
bin]) {
378 theCorrection = shiftBins[0];
379 }
else if (myBin == ((
int)(amplitudeBins.size() - 1))) {
380 theCorrection = shiftBins[myBin];
383 theCorrection = (shiftBins[myBin + 1] - shiftBins[myBin]);
384 theCorrection *= (((double)ampli) - amplitudeBins[myBin]) / (amplitudeBins[myBin + 1] - amplitudeBins[myBin]);
385 theCorrection += shiftBins[myBin];
389 constexpr
double inv25 = 1. / 25.;
390 return theCorrection * inv25;
426 for (
auto itdg = digis.
begin(); itdg != digis.
end(); ++itdg) {
427 DetId detid(itdg->id());
432 float offsetTime = 0;
458 double pedVec[3] = {aped->mean_x12, aped->mean_x6, aped->mean_x1};
459 double pedRMSVec[3] = {aped->rms_x12, aped->rms_x6, aped->rms_x1};
463 fullpulse(
i + 7) = aPulse->pdfval[
i];
467 fullpulsecov(
i + 7,
j + 7) = aPulseCov->covval[
i][
j];
472 if (it !=
itime->end()) {
475 edm::LogError(
"EcalRecHitError") <<
"No time intercalib const found for xtal " << detid.rawId()
476 <<
"! something wrong with EcalTimeCalibConstants in your DB? ";
479 int lastSampleBeforeSaturation = -2;
482 lastSampleBeforeSaturation = iSample - 1;
489 if (lastSampleBeforeSaturation == 4) {
490 result.emplace_back((*itdg).id(), 4095 * 12, 0, 0, 0);
491 auto& uncalibRecHit =
result.back();
494 uncalibRecHit.setChi2(0);
495 }
else if (lastSampleBeforeSaturation >=
501 auto gainratio = gainRatios[
gainId - 1];
504 auto& uncalibRecHit =
result.back();
507 uncalibRecHit.setChi2(0);
513 auto& uncalibRecHit =
result.back();
518 constexpr
float clockToNsConstant = 25.;
519 constexpr
float invClockToNs = 1. / clockToNsConstant;
529 uncalibRecHit.setJitter(crh.timeMax - 5 + theTimeCorrectionEE);
530 uncalibRecHit.setJitterError(
540 if (uncalibRecHit.amplitude() > 3000.) {
550 float correctedTime = (crh.timeMax - 5) * clockToNsConstant + itimeconst + offsetTime;
552 float sigmaped = pedRMSVec[0];
553 float nterm =
EEtimeNconst_ * sigmaped / uncalibRecHit.amplitude();
554 float sigmat =
std::sqrt(nterm * nterm + cterm * cterm);
555 if ((correctedTime > sigmat * outOfTimeThreshP) || (correctedTime < -sigmat * outOfTimeThreshM)) {
571 uncalibRecHit.setJitter(crh.timeMax - 5 + theTimeCorrectionEB);
572 uncalibRecHit.setJitterError(std::hypot(crh.timeError,
EBtimeConstantTerm_ / clockToNsConstant));
581 if (uncalibRecHit.amplitude() > 3000.) {
591 float correctedTime = (crh.timeMax - 5) * clockToNsConstant + itimeconst + offsetTime;
593 float sigmaped = pedRMSVec[0];
594 float nterm =
EBtimeNconst_ * sigmaped / uncalibRecHit.amplitude();
595 float sigmat =
std::sqrt(nterm * nterm + cterm * cterm);
596 if ((correctedTime > sigmat * outOfTimeThreshP) || (correctedTime < -sigmat * outOfTimeThreshM)) {
603 std::vector<double> amplitudes;
604 for (
unsigned int ibx = 0; ibx <
activeBX.
size(); ++ibx)
605 amplitudes.push_back(uncalibRecHit.outOfTimeAmplitude(ibx));
609 EcalTBWeights::EcalTBWeightMap::const_iterator wit;
610 wit = wgtsMap.find(std::make_pair(*gid, tdcid));
611 if (wit == wgtsMap.end()) {
613 <<
"No weights found for EcalGroupId: " << gid->
id() <<
" and EcalTDCId: " << tdcid
614 <<
"\n skipping digi with id: " << detid.rawId();
632 uncalibRecHit.setJitter(timerh);
633 uncalibRecHit.setJitterError(0.);
637 for (
unsigned int ibx = 0; ibx <
activeBX.
size(); ++ibx)
638 amplitudes[ibx] = uncalibRecHit.outOfTimeAmplitude(ibx);
640 float jitterError = 0.;
645 float noCorrectedJitter =
computeCC_->computeTimeCC(*itdg,
656 uncalibRecHit.setJitter(jitter);
657 uncalibRecHit.setNonCorrectedTime(jitter, noCorrectedJitter);
659 float retreivedNonCorrectedTime = uncalibRecHit.nonCorrectedTime();
661 if (retreivedNonCorrectedTime > -29.0 &&
std::abs(retreivedNonCorrectedTime - noCorrectedTime) > 0.05) {
662 edm::LogError(
"EcalUncalibRecHitError") <<
"Problem with noCorrectedJitter: true value:" << noCorrectedTime
663 <<
"\t received: " << retreivedNonCorrectedTime << std::endl;
676 if (uncalibRecHit.amplitude() > 3000.) {
692 if (uncalibRecHit.amplitude() > 3000.) {
703 if (uncalibRecHit.amplitude() >
threshold) {
705 float sigmaped = pedRMSVec[0];
706 float nterm = timeNconst * sigmaped / uncalibRecHit.amplitude();
707 float sigmat =
std::sqrt(nterm * nterm + cterm * cterm);
708 if ((correctedTime > sigmat * timeThrP) || (correctedTime < -sigmat * timeThrM))
713 uncalibRecHit.setJitter(0.);
714 uncalibRecHit.setJitterError(0.);
719 auto& uncalibRecHit =
result.back();
729 psd.
addNode(
edm::ParameterDescription<std::vector<int>>(
"activeBXs", {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4},
true) and
806 "EcalUncalibRecHitWorkerMultiFit");
edm::ESGetToken< EcalPulseCovariances, EcalPulseCovariancesRcd > pulseConvariancesToken_
edm::ParameterSetDescription getAlgoDescription() override
bool mitigateBadSamplesEB_
std::array< SampleMatrixGainArray, 2 > noisecors_
EcalPulseShapesMap EcalPulseShapes
T getParameter(std::string const &) const
void computeAmplitude(std::vector< double > &litudeFitParameters)
std::vector< float > EBTimeCorrShiftBins
EcalUncalibRecHitMultiFitAlgo multiFitMethod_
const EcalTBWeightMap & getMap() const
bool simplifiedNoiseModelForGainSwitch_
std::array< SampleMatrix, NGains > SampleMatrixGainArray
double CCtargetTimePrecision_
EcalUncalibRecHitTimeWeightsAlgo< EEDataFrame > weightsMethod_endcap_
double EEtimeConstantTerm_
edm::ESGetToken< EcalPulseShapes, EcalPulseShapesRcd > pulseShapesToken_
bool useLumiInfoRunHeader_
bool mitigateBadSamplesEE_
Eigen::Matrix< double, FullSampleVectorSize, FullSampleVectorSize > FullSampleMatrix
double addPedestalUncertaintyEE_
double time(const C &dataFrame, const std::vector< double > &litudes, const EcalPedestals::Item *aped, const EcalMGPAGainRatio *aGain, const FullSampleVector &fullpulse, const EcalWeightSet::EcalWeightMatrix **weights)
Compute time.
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
CalculatedRecHit getCalculatedRecHit()
double outOfTimeThreshG12pEE_
std::vector< double > EBG12SamplesCorrelation
std::map< std::pair< EcalXtalGroupId, EcalTDCId >, EcalWeightSet > EcalTBWeightMap
void computeTime(std::vector< double > &timeFitParameters, std::pair< double, double > &timeFitLimits, std::vector< double > &litudeFitParameters)
double CCminTimeToBeLateMin_
edm::ESGetToken< EcalGainRatios, EcalGainRatiosRcd > gainsToken_
EcalCondObjectContainer< EcalXtalGroupId > EcalWeightXtalGroups
static const int TEMPLATESAMPLES
edm::ESHandle< EcalWeightXtalGroups > grps
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
double amplitudeThreshEE_
math::Matrix< 3, 10 >::type EcalWeightMatrix
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Log< level::Error, false > LogError
double outOfTimeThreshG61pEE_
constexpr const float clockToNS
edm::ESHandle< EcalGainRatios > gains
bool selectiveBadSampleCriteriaEE_
edm::ESGetToken< EcalSamplesCorrelation, EcalSamplesCorrelationRcd > noiseConvariancesToken_
edm::EDGetTokenT< unsigned int > bunchSpacing_
EcalUncalibRecHitRatioMethodAlgo< EBDataFrame > ratioMethod_barrel_
bool gainSwitchUseMaxSampleEE_
std::vector< double > EBG6SamplesCorrelation
const SampleMatrixGainArray & noisecor(bool barrel) const
unsigned size(int bx) const
std::vector< float > EBTimeCorrAmplitudeBins
edm::ESGetToken< EcalPedestals, EcalPedestalsRcd > pedsToken_
std::vector< float > EETimeCorrShiftBins
edm::ESHandle< EcalPedestals > peds
int hashedIndex(int ieta, int iphi)
edm::ESGetToken< EcalTBWeights, EcalTBWeightsRcd > wgtsToken_
void setAddPedestalUncertainty(double x)
T const * product() const
std::vector< double > EBtimeFitParameters_
std::vector< double > ebPulseShape_
std::vector< double > EBamplitudeFitParameters_
EcalGainRatioMap EcalGainRatios
EcalUncalibRecHitRatioMethodAlgo< EEDataFrame > ratioMethod_endcap_
std::vector< float > EETimeCorrAmplitudeBins
edm::ESHandle< EcalPulseShapes > pulseshapes
void setDynamicPedestals(bool b)
Abs< T >::type abs(const T &t)
double CCTimeShiftWrtRations_
EcalPulseCovariancesMap EcalPulseCovariances
void setMitigateBadSamples(bool b)
edm::ESHandle< EcalTimeCalibConstants > itime
double timeCorrection(float ampli, const std::vector< float > &litudeBins, const std::vector< float > &shiftBins)
double outOfTimeThreshG12mEB_
void disableErrorCalculation()
double outOfTimeThreshG61mEB_
std::unique_ptr< EcalUncalibRecHitTimingCCAlgo > computeCC_
double outOfTimeThreshG12mEE_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
EcalWeightMatrix & getWeightsAfterGainSwitch()
double outOfTimeThreshG12pEB_
std::vector< double > eePulseShape_
void setSelectiveBadSampleCriteria(bool b)
const SampleMatrix & noisecor(bool barrel, int gain) const
EcalUncalibratedRecHit makeRecHit(const EcalDataFrame &dataFrame, const EcalPedestals::Item *aped, const EcalMGPAGainRatio *aGain, const SampleMatrixGainArray &noisecors, const FullSampleVector &fullpulse, const FullSampleMatrix &fullpulsecov, const BXVector &activeBX)
compute rechits
const_iterator end() const
edm::ESHandle< EcalTimeBiasCorrections > timeCorrBias_
float gain12Over6() const
EcalPedestalsMap EcalPedestals
double CCminTimeToBeLateMax_
bool ampErrorCalculation_
edm::ESGetToken< EcalTimeOffsetConstant, EcalTimeOffsetConstantRcd > offtimeToken_
void set(const edm::EventSetup &es) override
edm::ESHandle< EcalPulseCovariances > pulsecovariances
void setPrefitMaxChiSq(double x)
constexpr int gainId(sample_type sample)
get the gainId (2 bits)
EcalWeightMatrix & getWeightsBeforeGainSwitch()
EcalTimeCalibConstantMap EcalTimeCalibConstants
std::vector< double > EBG1SamplesCorrelation
bool fixMGPAslew(const C &dataFrame)
double outOfTimeThreshG61mEE_
const_iterator begin() const
The iterator returned can not safely be used across threads.
std::vector< Item >::const_iterator const_iterator
void resize(int bx, unsigned size)
double CCtargetTimePrecisionForDelayedPulses_
edm::ESGetToken< EcalTimeBiasCorrections, EcalTimeBiasCorrectionsRcd > timeCorrBiasToken_
std::pair< double, double > EBtimeFitLimits_
Eigen::Matrix< double, SampleVectorSize, SampleVectorSize > SampleMatrix
EcalUncalibRecHitTimeWeightsAlgo< EBDataFrame > weightsMethod_barrel_
edm::ESHandle< EcalTimeOffsetConstant > offtime
bool selectiveBadSampleCriteriaEB_
std::vector< double > EEG1SamplesCorrelation
bool gainSwitchUseMaxSampleEB_
float EcalTimeCalibConstant
edm::ESGetToken< EcalSampleMask, EcalSampleMaskRcd > sampleMaskToken_
edm::ESGetToken< EcalTimeCalibConstants, EcalTimeCalibConstantsRcd > itimeToken_
int hashedIndex() const
get a compact index for arrays
double outOfTimeThreshG61pEB_
void setGainSwitchUseMaxSample(bool b)
#define DEFINE_EDM_PLUGIN(factory, type, name)
void run(const edm::Event &evt, const EcalDigiCollection &digis, EcalUncalibratedRecHitCollection &result) override
static constexpr int MAXSAMPLES
void setSimplifiedNoiseModelForGainSwitch(bool b)
edm::ESHandle< EcalSampleMask > sampleMaskHand_
const EcalWeightSet::EcalWeightMatrix * weights[2]
std::vector< double > EEG12SamplesCorrelation
edm::ESHandle< EcalSamplesCorrelation > noisecovariances
void init(const C &dataFrame, const EcalSampleMask &sampleMask, const double *pedestals, const double *pedestalRMSes, const double *gainRatios)
std::pair< double, double > EEtimeFitLimits_
double amplitudeThreshEB_
std::vector< double > EEG6SamplesCorrelation
edm::ESHandle< EcalTBWeights > wgts
std::vector< double > EEamplitudeFitParameters_
edm::ESGetToken< EcalWeightXtalGroups, EcalWeightXtalGroupsRcd > grpsToken_
double addPedestalUncertaintyEB_
EcalUncalibRecHitWorkerMultiFit()
std::vector< double > EEtimeFitParameters_
double EBtimeConstantTerm_