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";
128 int nnoise = SampleVector::RowsAtCompileTime;
136 for (
int i = 0;
i < nnoise; ++
i) {
137 for (
int j = 0;
j < nnoise; ++
j) {
150 unsigned int bunchspacing = 450;
155 bunchspacing = *bunchSpacingH;
161 if (bunchspacing == 25) {
163 activeBX << -5, -4, -3, -2, -1, 0, 1, 2, 3, 4;
182 const std::vector<float>& amplitudeBins,
183 const std::vector<float>& shiftBins) {
186 double theCorrection = 0;
189 if (amplitudeBins.empty()) {
190 edm::LogError(
"EcalRecHitError") <<
"timeCorrAmplitudeBins is empty, forcing no time bias corrections.";
195 if (amplitudeBins.size() != shiftBins.size()) {
196 edm::LogError(
"EcalRecHitError") <<
"Size of timeCorrAmplitudeBins different from "
197 "timeCorrShiftBins. Forcing no time bias corrections. ";
204 for (
int bin = 0;
bin < (int)amplitudeBins.size();
bin++) {
205 if (ampli > amplitudeBins[
bin]) {
213 theCorrection = shiftBins[0];
214 }
else if (myBin == ((
int)(amplitudeBins.size() - 1))) {
215 theCorrection = shiftBins[myBin];
218 theCorrection = (shiftBins[myBin + 1] - shiftBins[myBin]);
219 theCorrection *= (((double)ampli) - amplitudeBins[myBin]) / (amplitudeBins[myBin + 1] - amplitudeBins[myBin]);
220 theCorrection += shiftBins[myBin];
224 constexpr
double inv25 = 1. / 25.;
225 return theCorrection * inv25;
261 for (
auto itdg = digis.
begin(); itdg != digis.
end(); ++itdg) {
262 DetId detid(itdg->id());
267 float offsetTime = 0;
277 aped = &
peds->barrel(hashedIndex);
278 aGain = &
gains->barrel(hashedIndex);
279 gid = &
grps->barrel(hashedIndex);
282 offsetTime =
offtime->getEBValue();
285 aped = &
peds->endcap(hashedIndex);
286 aGain = &
gains->endcap(hashedIndex);
287 gid = &
grps->endcap(hashedIndex);
290 offsetTime =
offtime->getEEValue();
293 double pedVec[3] = {aped->mean_x12, aped->mean_x6, aped->mean_x1};
294 double pedRMSVec[3] = {aped->rms_x12, aped->rms_x6, aped->rms_x1};
298 fullpulse(
i + 7) = aPulse->pdfval[
i];
302 fullpulsecov(
i + 7,
j + 7) = aPulseCov->covval[
i][
j];
307 if (it !=
itime->end()) {
310 edm::LogError(
"EcalRecHitError") <<
"No time intercalib const found for xtal " << detid.rawId()
311 <<
"! something wrong with EcalTimeCalibConstants in your DB? ";
314 int lastSampleBeforeSaturation = -2;
317 lastSampleBeforeSaturation = iSample - 1;
324 if (lastSampleBeforeSaturation == 4) {
325 result.emplace_back((*itdg).id(), 4095 * 12, 0, 0, 0);
326 auto& uncalibRecHit = result.
back();
329 uncalibRecHit.setChi2(0);
330 }
else if (lastSampleBeforeSaturation >=
336 auto gainratio = gainRatios[gainId - 1];
338 result.emplace_back((*itdg).id(), amplitude, 0, 0, 0);
339 auto& uncalibRecHit = result.
back();
342 uncalibRecHit.setChi2(0);
348 auto& uncalibRecHit = result.
back();
353 constexpr
float clockToNsConstant = 25.;
354 constexpr
float invClockToNs = 1. / clockToNsConstant;
364 uncalibRecHit.setJitter(crh.timeMax - 5 + theTimeCorrectionEE);
365 uncalibRecHit.setJitterError(
375 if (uncalibRecHit.amplitude() > 3000.) {
385 float correctedTime = (crh.timeMax - 5) * clockToNsConstant + itimeconst + offsetTime;
387 float sigmaped = pedRMSVec[0];
388 float nterm =
EEtimeNconst_ * sigmaped / uncalibRecHit.amplitude();
389 float sigmat =
std::sqrt(nterm * nterm + cterm * cterm);
390 if ((correctedTime > sigmat * outOfTimeThreshP) || (correctedTime < -sigmat * outOfTimeThreshM)) {
406 uncalibRecHit.setJitter(crh.timeMax - 5 + theTimeCorrectionEB);
407 uncalibRecHit.setJitterError(std::hypot(crh.timeError,
EBtimeConstantTerm_ / clockToNsConstant));
416 if (uncalibRecHit.amplitude() > 3000.) {
426 float correctedTime = (crh.timeMax - 5) * clockToNsConstant + itimeconst + offsetTime;
428 float sigmaped = pedRMSVec[0];
429 float nterm =
EBtimeNconst_ * sigmaped / uncalibRecHit.amplitude();
430 float sigmat =
std::sqrt(nterm * nterm + cterm * cterm);
431 if ((correctedTime > sigmat * outOfTimeThreshP) || (correctedTime < -sigmat * outOfTimeThreshM)) {
438 std::vector<double> amplitudes;
439 for (
unsigned int ibx = 0; ibx <
activeBX.
size(); ++ibx)
440 amplitudes.push_back(uncalibRecHit.outOfTimeAmplitude(ibx));
444 EcalTBWeights::EcalTBWeightMap::const_iterator wit;
445 wit = wgtsMap.find(std::make_pair(*gid, tdcid));
446 if (wit == wgtsMap.end()) {
448 <<
"No weights found for EcalGroupId: " << gid->
id() <<
" and EcalTDCId: " << tdcid
449 <<
"\n skipping digi with id: " << detid.rawId();
467 uncalibRecHit.setJitter(timerh);
468 uncalibRecHit.setJitterError(0.);
472 for (
unsigned int ibx = 0; ibx <
activeBX.
size(); ++ibx)
473 amplitudes[ibx] = uncalibRecHit.outOfTimeAmplitude(ibx);
475 float jitterError = 0.;
476 float jitter =
computeCC_->computeTimeCC(*itdg, amplitudes, aped, aGain, fullpulse, uncalibRecHit, jitterError);
478 uncalibRecHit.setJitter(jitter);
479 uncalibRecHit.setJitterError(jitterError);
482 uncalibRecHit.setJitter(0.);
483 uncalibRecHit.setJitterError(0.);
488 auto& uncalibRecHit = result.
back();
498 psd.
addNode(
edm::ParameterDescription<std::vector<int>>(
"activeBXs", {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4},
true) and
571 "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 > EBamplitudeFitParameters_
EcalGainRatioMap EcalGainRatios
EcalUncalibRecHitRatioMethodAlgo< EEDataFrame > ratioMethod_endcap_
edm::ESHandle< EcalPulseShapes > pulseshapes
void setDynamicPedestals(bool b)
Abs< T >::type abs(const T &t)
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_
EcalWeightMatrix & getWeightsAfterGainSwitch()
double outOfTimeThreshG12pEB_
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_