16 std::vector<int32_t> activeBXs = ps.
getParameter<std::vector<int32_t>>(
"activeBXs");
18 for (
unsigned int ibx = 0; ibx < activeBXs.size(); ++ibx) {
19 activeBX.coeffRef(ibx) = activeBXs[ibx];
26 if (useLumiInfoRunHeader_) {
64 if (timeAlgoName ==
"RatioMethod")
66 else if (timeAlgoName ==
"WeightsMethod")
68 else if (timeAlgoName ==
"crossCorrelationMethod") {
71 double stopTime = ps.
getParameter<
double>(
"crossCorrelationStopTime");
72 double targetTimePrecision = ps.
getParameter<
double>(
"crossCorrelationTargetTimePrecision");
73 computeCC_ = std::make_unique<EcalUncalibRecHitTimingCCAlgo>(
startTime, stopTime, targetTimePrecision);
74 }
else if (timeAlgoName !=
"None")
75 edm::LogError(
"EcalUncalibRecHitError") <<
"No time estimation algorithm defined";
140 int nnoise = SampleVector::RowsAtCompileTime;
148 for (
int i = 0;
i < nnoise; ++
i) {
149 for (
int j = 0;
j < nnoise; ++
j) {
162 unsigned int bunchspacing = 450;
167 bunchspacing = *bunchSpacingH;
173 if (bunchspacing == 25) {
175 activeBX << -5, -4, -3, -2, -1, 0, 1, 2, 3, 4;
194 const std::vector<float>& amplitudeBins,
195 const std::vector<float>& shiftBins) {
198 double theCorrection = 0;
201 if (amplitudeBins.empty()) {
202 edm::LogError(
"EcalRecHitError") <<
"timeCorrAmplitudeBins is empty, forcing no time bias corrections.";
207 if (amplitudeBins.size() != shiftBins.size()) {
208 edm::LogError(
"EcalRecHitError") <<
"Size of timeCorrAmplitudeBins different from "
209 "timeCorrShiftBins. Forcing no time bias corrections. ";
216 for (
int bin = 0;
bin < (int)amplitudeBins.size();
bin++) {
217 if (ampli > amplitudeBins[
bin]) {
225 theCorrection = shiftBins[0];
226 }
else if (myBin == ((
int)(amplitudeBins.size() - 1))) {
227 theCorrection = shiftBins[myBin];
230 theCorrection = (shiftBins[myBin + 1] - shiftBins[myBin]);
231 theCorrection *= (((double)ampli) - amplitudeBins[myBin]) / (amplitudeBins[myBin + 1] - amplitudeBins[myBin]);
232 theCorrection += shiftBins[myBin];
236 constexpr
double inv25 = 1. / 25.;
237 return theCorrection * inv25;
273 for (
auto itdg = digis.
begin(); itdg != digis.
end(); ++itdg) {
274 DetId detid(itdg->id());
279 float offsetTime = 0;
289 aped = &
peds->barrel(hashedIndex);
290 aGain = &
gains->barrel(hashedIndex);
291 gid = &
grps->barrel(hashedIndex);
294 offsetTime =
offtime->getEBValue();
297 aped = &
peds->endcap(hashedIndex);
298 aGain = &
gains->endcap(hashedIndex);
299 gid = &
grps->endcap(hashedIndex);
302 offsetTime =
offtime->getEEValue();
305 double pedVec[3] = {aped->mean_x12, aped->mean_x6, aped->mean_x1};
306 double pedRMSVec[3] = {aped->rms_x12, aped->rms_x6, aped->rms_x1};
310 fullpulse(
i + 7) = aPulse->pdfval[
i];
314 fullpulsecov(
i + 7,
j + 7) = aPulseCov->covval[
i][
j];
319 if (it !=
itime->end()) {
322 edm::LogError(
"EcalRecHitError") <<
"No time intercalib const found for xtal " << detid.rawId()
323 <<
"! something wrong with EcalTimeCalibConstants in your DB? ";
326 int lastSampleBeforeSaturation = -2;
329 lastSampleBeforeSaturation = iSample - 1;
336 if (lastSampleBeforeSaturation == 4) {
337 result.emplace_back((*itdg).id(), 4095 * 12, 0, 0, 0);
338 auto& uncalibRecHit = result.
back();
341 uncalibRecHit.setChi2(0);
342 }
else if (lastSampleBeforeSaturation >=
348 auto gainratio = gainRatios[gainId - 1];
350 result.emplace_back((*itdg).id(), amplitude, 0, 0, 0);
351 auto& uncalibRecHit = result.
back();
354 uncalibRecHit.setChi2(0);
360 auto& uncalibRecHit = result.
back();
365 constexpr
float clockToNsConstant = 25.;
366 constexpr
float invClockToNs = 1. / clockToNsConstant;
376 uncalibRecHit.setJitter(crh.timeMax - 5 + theTimeCorrectionEE);
377 uncalibRecHit.setJitterError(
387 if (uncalibRecHit.amplitude() > 3000.) {
397 float correctedTime = (crh.timeMax - 5) * clockToNsConstant + itimeconst + offsetTime;
399 float sigmaped = pedRMSVec[0];
400 float nterm =
EEtimeNconst_ * sigmaped / uncalibRecHit.amplitude();
401 float sigmat =
std::sqrt(nterm * nterm + cterm * cterm);
402 if ((correctedTime > sigmat * outOfTimeThreshP) || (correctedTime < -sigmat * outOfTimeThreshM)) {
418 uncalibRecHit.setJitter(crh.timeMax - 5 + theTimeCorrectionEB);
419 uncalibRecHit.setJitterError(std::hypot(crh.timeError,
EBtimeConstantTerm_ / clockToNsConstant));
428 if (uncalibRecHit.amplitude() > 3000.) {
438 float correctedTime = (crh.timeMax - 5) * clockToNsConstant + itimeconst + offsetTime;
440 float sigmaped = pedRMSVec[0];
441 float nterm =
EBtimeNconst_ * sigmaped / uncalibRecHit.amplitude();
442 float sigmat =
std::sqrt(nterm * nterm + cterm * cterm);
443 if ((correctedTime > sigmat * outOfTimeThreshP) || (correctedTime < -sigmat * outOfTimeThreshM)) {
450 std::vector<double> amplitudes;
451 for (
unsigned int ibx = 0; ibx <
activeBX.
size(); ++ibx)
452 amplitudes.push_back(uncalibRecHit.outOfTimeAmplitude(ibx));
456 EcalTBWeights::EcalTBWeightMap::const_iterator wit;
457 wit = wgtsMap.find(std::make_pair(*gid, tdcid));
458 if (wit == wgtsMap.end()) {
460 <<
"No weights found for EcalGroupId: " << gid->
id() <<
" and EcalTDCId: " << tdcid
461 <<
"\n skipping digi with id: " << detid.rawId();
479 uncalibRecHit.setJitter(timerh);
480 uncalibRecHit.setJitterError(0.);
484 for (
unsigned int ibx = 0; ibx <
activeBX.
size(); ++ibx)
485 amplitudes[ibx] = uncalibRecHit.outOfTimeAmplitude(ibx);
487 float jitterError = 0.;
488 float jitter =
computeCC_->computeTimeCC(*itdg, amplitudes, aped, aGain, fullpulse, uncalibRecHit, jitterError);
490 uncalibRecHit.setJitter(jitter);
491 uncalibRecHit.setJitterError(jitterError);
494 uncalibRecHit.setJitter(0.);
495 uncalibRecHit.setJitterError(0.);
500 auto& uncalibRecHit = result.
back();
544 "EBCorrNoiseMatrixG12",
545 {1.00000, 0.71073, 0.55721, 0.46089, 0.40449, 0.35931, 0.33924, 0.32439, 0.31581, 0.30481},
548 "EECorrNoiseMatrixG12",
549 {1.00000, 0.71373, 0.44825, 0.30152, 0.21609, 0.14786, 0.11772, 0.10165, 0.09465, 0.08098},
552 "EBCorrNoiseMatrixG06",
553 {1.00000, 0.70946, 0.58021, 0.49846, 0.45006, 0.41366, 0.39699, 0.38478, 0.37847, 0.37055},
556 "EECorrNoiseMatrixG06",
557 {1.00000, 0.71217, 0.47464, 0.34056, 0.26282, 0.20287, 0.17734, 0.16256, 0.15618, 0.14443},
560 "EBCorrNoiseMatrixG01",
561 {1.00000, 0.73354, 0.64442, 0.58851, 0.55425, 0.53082, 0.51916, 0.51097, 0.50732, 0.50409},
564 "EECorrNoiseMatrixG01",
565 {1.00000, 0.72698, 0.62048, 0.55691, 0.51848, 0.49147, 0.47813, 0.47007, 0.46621, 0.46265},
572 "EBPulseShapeCovariance",
573 {3.001e-06, 1.233e-05, 0.000e+00, -4.416e-06, -4.571e-06, -3.614e-06, -2.636e-06, -1.286e-06, -8.410e-07,
574 -5.296e-07, 0.000e+00, 0.000e+00, 1.233e-05, 6.154e-05, 0.000e+00, -2.200e-05, -2.309e-05, -1.838e-05,
575 -1.373e-05, -7.334e-06, -5.088e-06, -3.745e-06, -2.428e-06, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00,
576 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00,
577 -4.416e-06, -2.200e-05, 0.000e+00, 8.319e-06, 8.545e-06, 6.792e-06, 5.059e-06, 2.678e-06, 1.816e-06,
578 1.223e-06, 8.245e-07, 5.589e-07, -4.571e-06, -2.309e-05, 0.000e+00, 8.545e-06, 9.182e-06, 7.219e-06,
579 5.388e-06, 2.853e-06, 1.944e-06, 1.324e-06, 9.083e-07, 6.335e-07, -3.614e-06, -1.838e-05, 0.000e+00,
580 6.792e-06, 7.219e-06, 6.016e-06, 4.437e-06, 2.385e-06, 1.636e-06, 1.118e-06, 7.754e-07, 5.556e-07,
581 -2.636e-06, -1.373e-05, 0.000e+00, 5.059e-06, 5.388e-06, 4.437e-06, 3.602e-06, 1.917e-06, 1.322e-06,
582 9.079e-07, 6.529e-07, 4.752e-07, -1.286e-06, -7.334e-06, 0.000e+00, 2.678e-06, 2.853e-06, 2.385e-06,
583 1.917e-06, 1.375e-06, 9.100e-07, 6.455e-07, 4.693e-07, 3.657e-07, -8.410e-07, -5.088e-06, 0.000e+00,
584 1.816e-06, 1.944e-06, 1.636e-06, 1.322e-06, 9.100e-07, 9.115e-07, 6.062e-07, 4.436e-07, 3.422e-07,
585 -5.296e-07, -3.745e-06, 0.000e+00, 1.223e-06, 1.324e-06, 1.118e-06, 9.079e-07, 6.455e-07, 6.062e-07,
586 7.217e-07, 4.862e-07, 3.768e-07, 0.000e+00, -2.428e-06, 0.000e+00, 8.245e-07, 9.083e-07, 7.754e-07,
587 6.529e-07, 4.693e-07, 4.436e-07, 4.862e-07, 6.509e-07, 4.418e-07, 0.000e+00, 0.000e+00, 0.000e+00,
588 5.589e-07, 6.335e-07, 5.556e-07, 4.752e-07, 3.657e-07, 3.422e-07, 3.768e-07, 4.418e-07, 6.142e-07},
591 "EEPulseShapeCovariance",
592 {3.941e-05, 3.333e-05, 0.000e+00, -1.449e-05, -1.661e-05, -1.424e-05, -1.183e-05, -6.842e-06, -4.915e-06,
593 -3.411e-06, 0.000e+00, 0.000e+00, 3.333e-05, 2.862e-05, 0.000e+00, -1.244e-05, -1.431e-05, -1.233e-05,
594 -1.032e-05, -5.883e-06, -4.154e-06, -2.902e-06, -2.128e-06, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00,
595 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00, 0.000e+00,
596 -1.449e-05, -1.244e-05, 0.000e+00, 5.840e-06, 6.649e-06, 5.720e-06, 4.812e-06, 2.708e-06, 1.869e-06,
597 1.330e-06, 9.186e-07, 6.446e-07, -1.661e-05, -1.431e-05, 0.000e+00, 6.649e-06, 7.966e-06, 6.898e-06,
598 5.794e-06, 3.157e-06, 2.184e-06, 1.567e-06, 1.084e-06, 7.575e-07, -1.424e-05, -1.233e-05, 0.000e+00,
599 5.720e-06, 6.898e-06, 6.341e-06, 5.347e-06, 2.859e-06, 1.991e-06, 1.431e-06, 9.839e-07, 6.886e-07,
600 -1.183e-05, -1.032e-05, 0.000e+00, 4.812e-06, 5.794e-06, 5.347e-06, 4.854e-06, 2.628e-06, 1.809e-06,
601 1.289e-06, 9.020e-07, 6.146e-07, -6.842e-06, -5.883e-06, 0.000e+00, 2.708e-06, 3.157e-06, 2.859e-06,
602 2.628e-06, 1.863e-06, 1.296e-06, 8.882e-07, 6.108e-07, 4.283e-07, -4.915e-06, -4.154e-06, 0.000e+00,
603 1.869e-06, 2.184e-06, 1.991e-06, 1.809e-06, 1.296e-06, 1.217e-06, 8.669e-07, 5.751e-07, 3.882e-07,
604 -3.411e-06, -2.902e-06, 0.000e+00, 1.330e-06, 1.567e-06, 1.431e-06, 1.289e-06, 8.882e-07, 8.669e-07,
605 9.522e-07, 6.717e-07, 4.293e-07, 0.000e+00, -2.128e-06, 0.000e+00, 9.186e-07, 1.084e-06, 9.839e-07,
606 9.020e-07, 6.108e-07, 5.751e-07, 6.717e-07, 7.911e-07, 5.493e-07, 0.000e+00, 0.000e+00, 0.000e+00,
607 6.446e-07, 7.575e-07, 6.886e-07, 6.146e-07, 4.283e-07, 3.882e-07, 4.293e-07, 5.493e-07, 7.027e-07},
613 edm::ParameterDescription<std::vector<int>>(
"activeBXs", {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4},
true) and
675 "ebPulseShape", {5.2e-05, -5.26e-05, 6.66e-05, 0.1168, 0.7575, 1., 0.8876, 0.6732, 0.4741, 0.3194},
true) and
677 "eePulseShape", {5.2e-05, -5.26e-05, 6.66e-05, 0.1168, 0.7575, 1., 0.8876, 0.6732, 0.4741, 0.3194},
true) and
696 "EcalUncalibRecHitWorkerMultiFit");
edm::ESGetToken< EcalPulseCovariances, EcalPulseCovariancesRcd > pulseConvariancesToken_
edm::ParameterSetDescription getAlgoDescription() override
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
bool mitigateBadSamplesEB_
std::array< SampleMatrixGainArray, 2 > noisecors_
EcalPulseShapesMap EcalPulseShapes
int hashedIndex() const
get a compact index for arrays
const edm::EventSetup & c
void computeAmplitude(std::vector< double > &litudeFitParameters)
unsigned size(int bx) const
EcalUncalibRecHitMultiFitAlgo multiFitMethod_
bool simplifiedNoiseModelForGainSwitch_
std::array< SampleMatrix, NGains > SampleMatrixGainArray
EcalUncalibRecHitTimeWeightsAlgo< EEDataFrame > weightsMethod_endcap_
double EEtimeConstantTerm_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
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::map< std::pair< EcalXtalGroupId, EcalTDCId >, EcalWeightSet > EcalTBWeightMap
void computeTime(std::vector< double > &timeFitParameters, std::pair< double, double > &timeFitLimits, std::vector< double > &litudeFitParameters)
edm::ESGetToken< EcalGainRatios, EcalGainRatiosRcd > gainsToken_
EcalCondObjectContainer< EcalXtalGroupId > EcalWeightXtalGroups
static const int TEMPLATESAMPLES
edm::ESHandle< EcalWeightXtalGroups > grps
void push_back(T const &t)
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
double amplitudeThreshEE_
math::Matrix< 3, 10 >::type EcalWeightMatrix
const_iterator begin() const
The iterator returned can not safely be used across threads.
Log< level::Error, false > LogError
double outOfTimeThreshG61pEE_
edm::ESHandle< EcalGainRatios > gains
bool selectiveBadSampleCriteriaEE_
edm::ESGetToken< EcalSamplesCorrelation, EcalSamplesCorrelationRcd > noiseConvariancesToken_
edm::EDGetTokenT< unsigned int > bunchSpacing_
EcalUncalibRecHitRatioMethodAlgo< EBDataFrame > ratioMethod_barrel_
bool gainSwitchUseMaxSampleEE_
edm::ESGetToken< EcalPedestals, EcalPedestalsRcd > pedsToken_
edm::ESHandle< EcalPedestals > peds
int hashedIndex(int ieta, int iphi)
edm::ESGetToken< EcalTBWeights, EcalTBWeightsRcd > wgtsToken_
void setAddPedestalUncertainty(double x)
std::vector< double > EBtimeFitParameters_
std::vector< double > ebPulseShape_
std::vector< double > EBamplitudeFitParameters_
EcalGainRatioMap EcalGainRatios
EcalUncalibRecHitRatioMethodAlgo< EEDataFrame > ratioMethod_endcap_
edm::ESHandle< EcalPulseShapes > pulseshapes
void setDynamicPedestals(bool b)
Abs< T >::type abs(const T &t)
EcalPulseCovariancesMap EcalPulseCovariances
ParameterDescriptionNode * addOptionalNode(ParameterDescriptionNode const &node, bool writeToCfi)
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_
EcalWeightMatrix & getWeightsAfterGainSwitch()
double outOfTimeThreshG12pEB_
std::vector< double > eePulseShape_
void setSelectiveBadSampleCriteria(bool b)
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
edm::ESHandle< EcalTimeBiasCorrections > timeCorrBias_
EcalPedestalsMap EcalPedestals
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
bool fixMGPAslew(const C &dataFrame)
double outOfTimeThreshG61mEE_
std::vector< Item >::const_iterator const_iterator
void resize(int bx, unsigned size)
T const * product() const
T getParameter(std::string const &) const
float gain12Over6() const
edm::ESGetToken< EcalTimeBiasCorrections, EcalTimeBiasCorrectionsRcd > timeCorrBiasToken_
std::pair< double, double > EBtimeFitLimits_
Eigen::Matrix< double, SampleVectorSize, SampleVectorSize > SampleMatrix
EcalUncalibRecHitTimeWeightsAlgo< EBDataFrame > weightsMethod_barrel_
edm::ESHandle< EcalTimeOffsetConstant > offtime
const_iterator end() const
bool selectiveBadSampleCriteriaEB_
bool gainSwitchUseMaxSampleEB_
float EcalTimeCalibConstant
edm::ESGetToken< EcalSampleMask, EcalSampleMaskRcd > sampleMaskToken_
edm::ESGetToken< EcalTimeCalibConstants, EcalTimeCalibConstantsRcd > itimeToken_
void reserve(size_type n)
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
const SampleMatrix & noisecor(bool barrel, int gain) const
static constexpr int MAXSAMPLES
void setSimplifiedNoiseModelForGainSwitch(bool b)
edm::ESHandle< EcalSampleMask > sampleMaskHand_
const EcalWeightSet::EcalWeightMatrix * weights[2]
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
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_
edm::ESHandle< EcalTBWeights > wgts
std::vector< double > EEamplitudeFitParameters_
Power< A, B >::type pow(const A &a, const B &b)
edm::ESGetToken< EcalWeightXtalGroups, EcalWeightXtalGroupsRcd > grpsToken_
const_reference back() const
double addPedestalUncertaintyEB_
EcalUncalibRecHitWorkerMultiFit()
std::vector< double > EEtimeFitParameters_
double EBtimeConstantTerm_