CMS 3D CMS Logo

EcalUncalibRecHitWorkerMultiFit.cc
Go to the documentation of this file.
1 
49 
51 public:
54 
55 private:
56  void set(const edm::EventSetup& es) override;
57  void set(const edm::Event& evt) override;
58  void run(const edm::Event& evt, const EcalDigiCollection& digis, EcalUncalibratedRecHitCollection& result) override;
59 
60 public:
62 
63 private:
74 
75  double timeCorrection(float ampli, const std::vector<float>& amplitudeBins, const std::vector<float>& shiftBins);
76 
77  const SampleMatrix& noisecor(bool barrel, int gain) const { return noisecors_[barrel ? 1 : 0][gain]; }
78  const SampleMatrixGainArray& noisecor(bool barrel) const { return noisecors_[barrel ? 1 : 0]; }
79 
80  // multifit method
81  std::array<SampleMatrixGainArray, 2> noisecors_;
86 
89 
90  // determine which of the samples must actually be used by ECAL local reco
93 
94  // time algorithm to be used to set the jitter and its uncertainty
97 
98  // time weights method
121 
122  // ratio method
123  std::vector<double> EBtimeFitParameters_;
124  std::vector<double> EEtimeFitParameters_;
125  std::vector<double> EBamplitudeFitParameters_;
126  std::vector<double> EEamplitudeFitParameters_;
127  std::pair<double, double> EBtimeFitLimits_;
128  std::pair<double, double> EEtimeFitLimits_;
129 
132 
148 
151 
156  std::vector<double> ebPulseShape_;
157  std::vector<double> eePulseShape_;
158 
159  // chi2 thresholds for flags settings
164 
165  //Timing Cross Correlation Algo
166  std::unique_ptr<EcalUncalibRecHitTimingCCAlgo> computeCC_;
172 };
173 
176  // get the BX for the pulses to be activated
177  std::vector<int32_t> activeBXs = ps.getParameter<std::vector<int32_t>>("activeBXs");
178  activeBX.resize(activeBXs.size());
179  for (unsigned int ibx = 0; ibx < activeBXs.size(); ++ibx) {
180  activeBX.coeffRef(ibx) = activeBXs[ibx];
181  }
182 
183  // uncertainty calculation (CPU intensive)
184  ampErrorCalculation_ = ps.getParameter<bool>("ampErrorCalculation");
185  useLumiInfoRunHeader_ = ps.getParameter<bool>("useLumiInfoRunHeader");
186 
187  if (useLumiInfoRunHeader_) {
188  bunchSpacing_ = c.consumes<unsigned int>(edm::InputTag("bunchSpacingProducer"));
190  } else {
191  bunchSpacingManual_ = ps.getParameter<int>("bunchSpacing");
192  }
193 
194  doPrefitEB_ = ps.getParameter<bool>("doPrefitEB");
195  doPrefitEE_ = ps.getParameter<bool>("doPrefitEE");
196 
197  prefitMaxChiSqEB_ = ps.getParameter<double>("prefitMaxChiSqEB");
198  prefitMaxChiSqEE_ = ps.getParameter<double>("prefitMaxChiSqEE");
199 
200  dynamicPedestalsEB_ = ps.getParameter<bool>("dynamicPedestalsEB");
201  dynamicPedestalsEE_ = ps.getParameter<bool>("dynamicPedestalsEE");
202  mitigateBadSamplesEB_ = ps.getParameter<bool>("mitigateBadSamplesEB");
203  mitigateBadSamplesEE_ = ps.getParameter<bool>("mitigateBadSamplesEE");
204  gainSwitchUseMaxSampleEB_ = ps.getParameter<bool>("gainSwitchUseMaxSampleEB");
205  gainSwitchUseMaxSampleEE_ = ps.getParameter<bool>("gainSwitchUseMaxSampleEE");
206  selectiveBadSampleCriteriaEB_ = ps.getParameter<bool>("selectiveBadSampleCriteriaEB");
207  selectiveBadSampleCriteriaEE_ = ps.getParameter<bool>("selectiveBadSampleCriteriaEE");
208  addPedestalUncertaintyEB_ = ps.getParameter<double>("addPedestalUncertaintyEB");
209  addPedestalUncertaintyEE_ = ps.getParameter<double>("addPedestalUncertaintyEE");
210  simplifiedNoiseModelForGainSwitch_ = ps.getParameter<bool>("simplifiedNoiseModelForGainSwitch");
211  pedsToken_ = c.esConsumes<EcalPedestals, EcalPedestalsRcd>();
218  wgtsToken_ = c.esConsumes<EcalTBWeights, EcalTBWeightsRcd>();
220  itimeToken_ =
223  ps.getParameter<edm::ESInputTag>("timeOffsetTag"));
224 
225  // algorithm to be used for timing
226  auto const& timeAlgoName = ps.getParameter<std::string>("timealgo");
227  if (timeAlgoName == "RatioMethod")
229  else if (timeAlgoName == "WeightsMethod")
231  else if (timeAlgoName == "crossCorrelationMethod") {
233  double startTime = ps.getParameter<double>("crossCorrelationStartTime");
234  double stopTime = ps.getParameter<double>("crossCorrelationStopTime");
235  CCtargetTimePrecision_ = ps.getParameter<double>("crossCorrelationTargetTimePrecision");
237  ps.getParameter<double>("crossCorrelationTargetTimePrecisionForDelayedPulses");
238  CCminTimeToBeLateMin_ = ps.getParameter<double>("crossCorrelationMinTimeToBeLateMin") / ecalcctiming::clockToNS;
239  CCminTimeToBeLateMax_ = ps.getParameter<double>("crossCorrelationMinTimeToBeLateMax") / ecalcctiming::clockToNS;
240  CCTimeShiftWrtRations_ = ps.getParameter<double>("crossCorrelationTimeShiftWrtRations");
241  computeCC_ = std::make_unique<EcalUncalibRecHitTimingCCAlgo>(startTime, stopTime);
242  } else if (timeAlgoName != "None")
243  edm::LogError("EcalUncalibRecHitError") << "No time estimation algorithm defined";
244 
245  // ratio method parameters
246  EBtimeFitParameters_ = ps.getParameter<std::vector<double>>("EBtimeFitParameters");
247  EEtimeFitParameters_ = ps.getParameter<std::vector<double>>("EEtimeFitParameters");
248  EBamplitudeFitParameters_ = ps.getParameter<std::vector<double>>("EBamplitudeFitParameters");
249  EEamplitudeFitParameters_ = ps.getParameter<std::vector<double>>("EEamplitudeFitParameters");
250  EBtimeFitLimits_.first = ps.getParameter<double>("EBtimeFitLimits_Lower");
251  EBtimeFitLimits_.second = ps.getParameter<double>("EBtimeFitLimits_Upper");
252  EEtimeFitLimits_.first = ps.getParameter<double>("EEtimeFitLimits_Lower");
253  EEtimeFitLimits_.second = ps.getParameter<double>("EEtimeFitLimits_Upper");
254  EBtimeConstantTerm_ = ps.getParameter<double>("EBtimeConstantTerm");
255  EEtimeConstantTerm_ = ps.getParameter<double>("EEtimeConstantTerm");
256  EBtimeNconst_ = ps.getParameter<double>("EBtimeNconst");
257  EEtimeNconst_ = ps.getParameter<double>("EEtimeNconst");
258  outOfTimeThreshG12pEB_ = ps.getParameter<double>("outOfTimeThresholdGain12pEB");
259  outOfTimeThreshG12mEB_ = ps.getParameter<double>("outOfTimeThresholdGain12mEB");
260  outOfTimeThreshG61pEB_ = ps.getParameter<double>("outOfTimeThresholdGain61pEB");
261  outOfTimeThreshG61mEB_ = ps.getParameter<double>("outOfTimeThresholdGain61mEB");
262  outOfTimeThreshG12pEE_ = ps.getParameter<double>("outOfTimeThresholdGain12pEE");
263  outOfTimeThreshG12mEE_ = ps.getParameter<double>("outOfTimeThresholdGain12mEE");
264  outOfTimeThreshG61pEE_ = ps.getParameter<double>("outOfTimeThresholdGain61pEE");
265  outOfTimeThreshG61mEE_ = ps.getParameter<double>("outOfTimeThresholdGain61mEE");
266  amplitudeThreshEB_ = ps.getParameter<double>("amplitudeThresholdEB");
267  amplitudeThreshEE_ = ps.getParameter<double>("amplitudeThresholdEE");
268 }
269 
271  // common setup
273  peds = es.getHandle(pedsToken_);
274 
275  // for the multifit method
281 
282  // weights parameters for the time
283  grps = es.getHandle(grpsToken_);
284  wgts = es.getHandle(wgtsToken_);
285 
286  // which of the samples need be used
288 
289  // for the ratio method
292 
293  // for the time correction methods
295 
296  int nnoise = SampleVector::RowsAtCompileTime;
297  SampleMatrix& noisecorEBg12 = noisecors_[1][0];
298  SampleMatrix& noisecorEBg6 = noisecors_[1][1];
299  SampleMatrix& noisecorEBg1 = noisecors_[1][2];
300  SampleMatrix& noisecorEEg12 = noisecors_[0][0];
301  SampleMatrix& noisecorEEg6 = noisecors_[0][1];
302  SampleMatrix& noisecorEEg1 = noisecors_[0][2];
303 
304  for (int i = 0; i < nnoise; ++i) {
305  for (int j = 0; j < nnoise; ++j) {
306  int vidx = std::abs(j - i);
307  noisecorEBg12(i, j) = noisecovariances->EBG12SamplesCorrelation[vidx];
308  noisecorEEg12(i, j) = noisecovariances->EEG12SamplesCorrelation[vidx];
309  noisecorEBg6(i, j) = noisecovariances->EBG6SamplesCorrelation[vidx];
310  noisecorEEg6(i, j) = noisecovariances->EEG6SamplesCorrelation[vidx];
311  noisecorEBg1(i, j) = noisecovariances->EBG1SamplesCorrelation[vidx];
312  noisecorEEg1(i, j) = noisecovariances->EEG1SamplesCorrelation[vidx];
313  }
314  }
315 }
316 
318  unsigned int bunchspacing = 450;
319 
320  if (useLumiInfoRunHeader_) {
321  edm::Handle<unsigned int> bunchSpacingH;
322  evt.getByToken(bunchSpacing_, bunchSpacingH);
323  bunchspacing = *bunchSpacingH;
324  } else {
325  bunchspacing = bunchSpacingManual_;
326  }
327 
329  if (bunchspacing == 25) {
330  activeBX.resize(10);
331  activeBX << -5, -4, -3, -2, -1, 0, 1, 2, 3, 4;
332  } else {
333  //50ns configuration otherwise (also for no pileup)
334  activeBX.resize(5);
335  activeBX << -4, -2, 0, 2, 4;
336  }
337  }
338 }
339 
350  const std::vector<float>& amplitudeBins,
351  const std::vector<float>& shiftBins) {
352  // computed initially in ns. Than turned in the BX's, as
353  // EcalUncalibratedRecHit need be.
354  double theCorrection = 0;
355 
356  // sanity check for arrays
357  if (amplitudeBins.empty()) {
358  edm::LogError("EcalRecHitError") << "timeCorrAmplitudeBins is empty, forcing no time bias corrections.";
359 
360  return 0;
361  }
362 
363  if (amplitudeBins.size() != shiftBins.size()) {
364  edm::LogError("EcalRecHitError") << "Size of timeCorrAmplitudeBins different from "
365  "timeCorrShiftBins. Forcing no time bias corrections. ";
366 
367  return 0;
368  }
369 
370  // FIXME? what about a binary search?
371  int myBin = -1;
372  for (int bin = 0; bin < (int)amplitudeBins.size(); bin++) {
373  if (ampli > amplitudeBins[bin]) {
374  myBin = bin;
375  } else {
376  break;
377  }
378  }
379 
380  if (myBin == -1) {
381  theCorrection = shiftBins[0];
382  } else if (myBin == ((int)(amplitudeBins.size() - 1))) {
383  theCorrection = shiftBins[myBin];
384  } else {
385  // interpolate linearly between two assingned points
386  theCorrection = (shiftBins[myBin + 1] - shiftBins[myBin]);
387  theCorrection *= (((double)ampli) - amplitudeBins[myBin]) / (amplitudeBins[myBin + 1] - amplitudeBins[myBin]);
388  theCorrection += shiftBins[myBin];
389  }
390 
391  // convert ns into clocks
392  constexpr double inv25 = 1. / 25.;
393  return theCorrection * inv25;
394 }
395 
397  const EcalDigiCollection& digis,
399  if (digis.empty())
400  return;
401 
402  // assume all digis come from the same subdetector (either barrel or endcap)
403  DetId detid(digis.begin()->id());
404  bool barrel = (detid.subdetId() == EcalBarrel);
405 
407  if (barrel) {
415  } else {
423  }
424 
425  FullSampleVector fullpulse(FullSampleVector::Zero());
426  FullSampleMatrix fullpulsecov(FullSampleMatrix::Zero());
427 
428  result.reserve(result.size() + digis.size());
429  for (auto itdg = digis.begin(); itdg != digis.end(); ++itdg) {
430  DetId detid(itdg->id());
431 
432  const EcalSampleMask* sampleMask_ = sampleMaskHand_.product();
433 
434  // intelligence for recHit computation
435  float offsetTime = 0;
436 
437  const EcalPedestals::Item* aped = nullptr;
438  const EcalMGPAGainRatio* aGain = nullptr;
439  const EcalXtalGroupId* gid = nullptr;
440  const EcalPulseShapes::Item* aPulse = nullptr;
441  const EcalPulseCovariances::Item* aPulseCov = nullptr;
442 
443  if (barrel) {
444  unsigned int hashedIndex = EBDetId(detid).hashedIndex();
445  aped = &peds->barrel(hashedIndex);
446  aGain = &gains->barrel(hashedIndex);
447  gid = &grps->barrel(hashedIndex);
448  aPulse = &pulseshapes->barrel(hashedIndex);
449  aPulseCov = &pulsecovariances->barrel(hashedIndex);
450  offsetTime = offtime->getEBValue();
451  } else {
452  unsigned int hashedIndex = EEDetId(detid).hashedIndex();
453  aped = &peds->endcap(hashedIndex);
454  aGain = &gains->endcap(hashedIndex);
455  gid = &grps->endcap(hashedIndex);
456  aPulse = &pulseshapes->endcap(hashedIndex);
457  aPulseCov = &pulsecovariances->endcap(hashedIndex);
458  offsetTime = offtime->getEEValue();
459  }
460 
461  double pedVec[3] = {aped->mean_x12, aped->mean_x6, aped->mean_x1};
462  double pedRMSVec[3] = {aped->rms_x12, aped->rms_x6, aped->rms_x1};
463  double gainRatios[3] = {1., aGain->gain12Over6(), aGain->gain6Over1() * aGain->gain12Over6()};
464 
465  for (int i = 0; i < EcalPulseShape::TEMPLATESAMPLES; ++i)
466  fullpulse(i + 7) = aPulse->pdfval[i];
467 
468  for (int i = 0; i < EcalPulseShape::TEMPLATESAMPLES; i++)
469  for (int j = 0; j < EcalPulseShape::TEMPLATESAMPLES; j++)
470  fullpulsecov(i + 7, j + 7) = aPulseCov->covval[i][j];
471 
472  // compute the right bin of the pulse shape using time calibration constants
474  EcalTimeCalibConstant itimeconst = 0;
475  if (it != itime->end()) {
476  itimeconst = (*it);
477  } else {
478  edm::LogError("EcalRecHitError") << "No time intercalib const found for xtal " << detid.rawId()
479  << "! something wrong with EcalTimeCalibConstants in your DB? ";
480  }
481 
482  int lastSampleBeforeSaturation = -2;
483  for (unsigned int iSample = 0; iSample < EcalDataFrame::MAXSAMPLES; iSample++) {
484  if (((EcalDataFrame)(*itdg)).sample(iSample).gainId() == 0) {
485  lastSampleBeforeSaturation = iSample - 1;
486  break;
487  }
488  }
489 
490  // === amplitude computation ===
491 
492  if (lastSampleBeforeSaturation == 4) { // saturation on the expected max sample
493  result.emplace_back((*itdg).id(), 4095 * 12, 0, 0, 0);
494  auto& uncalibRecHit = result.back();
495  uncalibRecHit.setFlagBit(EcalUncalibratedRecHit::kSaturated);
496  // do not propagate the default chi2 = -1 value to the calib rechit (mapped to 64), set it to 0 when saturation
497  uncalibRecHit.setChi2(0);
498  } else if (lastSampleBeforeSaturation >=
499  -1) { // saturation on other samples: cannot extrapolate from the fourth one
500  int gainId = ((EcalDataFrame)(*itdg)).sample(5).gainId();
501  if (gainId == 0)
502  gainId = 3;
503  auto pedestal = pedVec[gainId - 1];
504  auto gainratio = gainRatios[gainId - 1];
505  double amplitude = ((double)(((EcalDataFrame)(*itdg)).sample(5).adc()) - pedestal) * gainratio;
506  result.emplace_back((*itdg).id(), amplitude, 0, 0, 0);
507  auto& uncalibRecHit = result.back();
508  uncalibRecHit.setFlagBit(EcalUncalibratedRecHit::kSaturated);
509  // do not propagate the default chi2 = -1 value to the calib rechit (mapped to 64), set it to 0 when saturation
510  uncalibRecHit.setChi2(0);
511  } else {
512  // multifit
513  const SampleMatrixGainArray& noisecors = noisecor(barrel);
514 
515  result.push_back(multiFitMethod_.makeRecHit(*itdg, aped, aGain, noisecors, fullpulse, fullpulsecov, activeBX));
516  auto& uncalibRecHit = result.back();
517 
518  // === time computation ===
519  if (timealgo_ == ratioMethod) {
520  // ratio method
521  constexpr float clockToNsConstant = 25.;
522  constexpr float invClockToNs = 1. / clockToNsConstant;
523  if (not barrel) {
524  ratioMethod_endcap_.init(*itdg, *sampleMask_, pedVec, pedRMSVec, gainRatios);
529  double theTimeCorrectionEE = timeCorrection(
531 
532  uncalibRecHit.setJitter(crh.timeMax - 5 + theTimeCorrectionEE);
533  uncalibRecHit.setJitterError(
534  std::sqrt(std::pow(crh.timeError, 2) + std::pow(EEtimeConstantTerm_ * invClockToNs, 2)));
535 
536  // consider flagging as kOutOfTime only if above noise
537  if (uncalibRecHit.amplitude() > pedRMSVec[0] * amplitudeThreshEE_) {
538  float outOfTimeThreshP = outOfTimeThreshG12pEE_;
539  float outOfTimeThreshM = outOfTimeThreshG12mEE_;
540  // determine if gain has switched away from gainId==1 (x12 gain)
541  // and determine cuts (number of 'sigmas') to ose for kOutOfTime
542  // >3k ADC is necessasry condition for gain switch to occur
543  if (uncalibRecHit.amplitude() > 3000.) {
544  for (int iSample = 0; iSample < EEDataFrame::MAXSAMPLES; iSample++) {
545  int GainId = ((EcalDataFrame)(*itdg)).sample(iSample).gainId();
546  if (GainId != 1) {
547  outOfTimeThreshP = outOfTimeThreshG61pEE_;
548  outOfTimeThreshM = outOfTimeThreshG61mEE_;
549  break;
550  }
551  }
552  }
553  float correctedTime = (crh.timeMax - 5) * clockToNsConstant + itimeconst + offsetTime;
554  float cterm = EEtimeConstantTerm_;
555  float sigmaped = pedRMSVec[0]; // approx for lower gains
556  float nterm = EEtimeNconst_ * sigmaped / uncalibRecHit.amplitude();
557  float sigmat = std::sqrt(nterm * nterm + cterm * cterm);
558  if ((correctedTime > sigmat * outOfTimeThreshP) || (correctedTime < -sigmat * outOfTimeThreshM)) {
559  uncalibRecHit.setFlagBit(EcalUncalibratedRecHit::kOutOfTime);
560  }
561  }
562 
563  } else {
564  ratioMethod_barrel_.init(*itdg, *sampleMask_, pedVec, pedRMSVec, gainRatios);
570 
571  double theTimeCorrectionEB = timeCorrection(
573 
574  uncalibRecHit.setJitter(crh.timeMax - 5 + theTimeCorrectionEB);
575  uncalibRecHit.setJitterError(std::hypot(crh.timeError, EBtimeConstantTerm_ / clockToNsConstant));
576 
577  // consider flagging as kOutOfTime only if above noise
578  if (uncalibRecHit.amplitude() > pedRMSVec[0] * amplitudeThreshEB_) {
579  float outOfTimeThreshP = outOfTimeThreshG12pEB_;
580  float outOfTimeThreshM = outOfTimeThreshG12mEB_;
581  // determine if gain has switched away from gainId==1 (x12 gain)
582  // and determine cuts (number of 'sigmas') to ose for kOutOfTime
583  // >3k ADC is necessasry condition for gain switch to occur
584  if (uncalibRecHit.amplitude() > 3000.) {
585  for (int iSample = 0; iSample < EBDataFrame::MAXSAMPLES; iSample++) {
586  int GainId = ((EcalDataFrame)(*itdg)).sample(iSample).gainId();
587  if (GainId != 1) {
588  outOfTimeThreshP = outOfTimeThreshG61pEB_;
589  outOfTimeThreshM = outOfTimeThreshG61mEB_;
590  break;
591  }
592  }
593  }
594  float correctedTime = (crh.timeMax - 5) * clockToNsConstant + itimeconst + offsetTime;
595  float cterm = EBtimeConstantTerm_;
596  float sigmaped = pedRMSVec[0]; // approx for lower gains
597  float nterm = EBtimeNconst_ * sigmaped / uncalibRecHit.amplitude();
598  float sigmat = std::sqrt(nterm * nterm + cterm * cterm);
599  if ((correctedTime > sigmat * outOfTimeThreshP) || (correctedTime < -sigmat * outOfTimeThreshM)) {
600  uncalibRecHit.setFlagBit(EcalUncalibratedRecHit::kOutOfTime);
601  }
602  }
603  }
604  } else if (timealgo_ == weightsMethod) {
605  // weights method on the PU subtracted pulse shape
606  std::vector<double> amplitudes;
607  for (unsigned int ibx = 0; ibx < activeBX.size(); ++ibx)
608  amplitudes.push_back(uncalibRecHit.outOfTimeAmplitude(ibx));
609 
610  EcalTBWeights::EcalTDCId tdcid(1);
611  EcalTBWeights::EcalTBWeightMap const& wgtsMap = wgts->getMap();
612  EcalTBWeights::EcalTBWeightMap::const_iterator wit;
613  wit = wgtsMap.find(std::make_pair(*gid, tdcid));
614  if (wit == wgtsMap.end()) {
615  edm::LogError("EcalUncalibRecHitError")
616  << "No weights found for EcalGroupId: " << gid->id() << " and EcalTDCId: " << tdcid
617  << "\n skipping digi with id: " << detid.rawId();
618  result.pop_back();
619  continue;
620  }
621  const EcalWeightSet& wset = wit->second; // this is the EcalWeightSet
622 
625 
626  weights[0] = &mat1;
627  weights[1] = &mat2;
628 
629  double timerh;
630  if (detid.subdetId() == EcalEndcap) {
631  timerh = weightsMethod_endcap_.time(*itdg, amplitudes, aped, aGain, fullpulse, weights);
632  } else {
633  timerh = weightsMethod_barrel_.time(*itdg, amplitudes, aped, aGain, fullpulse, weights);
634  }
635  uncalibRecHit.setJitter(timerh);
636  uncalibRecHit.setJitterError(0.); // not computed with weights
637 
638  } else if (timealgo_ == crossCorrelationMethod) {
639  std::vector<double> amplitudes(activeBX.size());
640  for (unsigned int ibx = 0; ibx < activeBX.size(); ++ibx)
641  amplitudes[ibx] = uncalibRecHit.outOfTimeAmplitude(ibx);
642 
643  float jitter =
644  computeCC_->computeTimeCC(*itdg, amplitudes, aped, aGain, fullpulse, CCtargetTimePrecision_, true) +
646  float noCorrectedJitter =
647  computeCC_->computeTimeCC(
648  *itdg, amplitudes, aped, aGain, fullpulse, CCtargetTimePrecisionForDelayedPulses_, false) +
650 
651  uncalibRecHit.setJitter(jitter);
652  uncalibRecHit.setNonCorrectedTime(jitter, noCorrectedJitter);
653 
654  float retreivedNonCorrectedTime = uncalibRecHit.nonCorrectedTime();
655  float noCorrectedTime = ecalcctiming::clockToNS * noCorrectedJitter;
656  if (retreivedNonCorrectedTime > -29.0 && std::abs(retreivedNonCorrectedTime - noCorrectedTime) > 0.05) {
657  edm::LogError("EcalUncalibRecHitError") << "Problem with noCorrectedJitter: true value:" << noCorrectedTime
658  << "\t received: " << retreivedNonCorrectedTime << std::endl;
659  } //<<>>if (abs(retreivedNonCorrectedTime - noCorrectedJitter)>1);
660 
661  // consider flagging as kOutOfTime only if above noise
662  float threshold, cterm, timeNconst;
663  float timeThrP = 0.;
664  float timeThrM = 0.;
665  if (barrel) {
666  threshold = pedRMSVec[0] * amplitudeThreshEB_;
667  cterm = EBtimeConstantTerm_;
668  timeNconst = EBtimeNconst_;
669  timeThrP = outOfTimeThreshG12pEB_;
670  timeThrM = outOfTimeThreshG12mEB_;
671  if (uncalibRecHit.amplitude() > 3000.) { // Gain switch
672  for (int iSample = 0; iSample < EBDataFrame::MAXSAMPLES; iSample++) {
673  int GainId = ((EcalDataFrame)(*itdg)).sample(iSample).gainId();
674  if (GainId != 1) {
675  timeThrP = outOfTimeThreshG61pEB_;
676  timeThrM = outOfTimeThreshG61mEB_;
677  break;
678  }
679  }
680  }
681  } else { //EndCap
682  threshold = pedRMSVec[0] * amplitudeThreshEE_;
683  cterm = EEtimeConstantTerm_;
684  timeNconst = EEtimeNconst_;
685  timeThrP = outOfTimeThreshG12pEE_;
686  timeThrM = outOfTimeThreshG12mEE_;
687  if (uncalibRecHit.amplitude() > 3000.) { // Gain switch
688  for (int iSample = 0; iSample < EEDataFrame::MAXSAMPLES; iSample++) {
689  int GainId = ((EcalDataFrame)(*itdg)).sample(iSample).gainId();
690  if (GainId != 1) {
691  timeThrP = outOfTimeThreshG61pEE_;
692  timeThrM = outOfTimeThreshG61mEE_;
693  break;
694  }
695  }
696  }
697  }
698  if (uncalibRecHit.amplitude() > threshold) {
699  float correctedTime = noCorrectedJitter * ecalcctiming::clockToNS + itimeconst + offsetTime;
700  float sigmaped = pedRMSVec[0]; // approx for lower gains
701  float nterm = timeNconst * sigmaped / uncalibRecHit.amplitude();
702  float sigmat = std::sqrt(nterm * nterm + cterm * cterm);
703  if ((correctedTime > sigmat * timeThrP) || (correctedTime < -sigmat * timeThrM))
704  uncalibRecHit.setFlagBit(EcalUncalibratedRecHit::kOutOfTime);
705  }
706 
707  } else { // no time method;
708  uncalibRecHit.setJitter(0.);
709  uncalibRecHit.setJitterError(0.);
710  }
711  }
712 
713  // set flags if gain switch has occurred
714  auto& uncalibRecHit = result.back();
715  if (((EcalDataFrame)(*itdg)).hasSwitchToGain6())
716  uncalibRecHit.setFlagBit(EcalUncalibratedRecHit::kHasSwitchToGain6);
717  if (((EcalDataFrame)(*itdg)).hasSwitchToGain1())
718  uncalibRecHit.setFlagBit(EcalUncalibratedRecHit::kHasSwitchToGain1);
719  }
720 }
721 
724  psd.addNode(edm::ParameterDescription<std::vector<int>>("activeBXs", {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4}, true) and
725  edm::ParameterDescription<bool>("ampErrorCalculation", true, true) and
726  edm::ParameterDescription<bool>("useLumiInfoRunHeader", true, true) and
727  edm::ParameterDescription<int>("bunchSpacing", 0, true) and
728  edm::ParameterDescription<bool>("doPrefitEB", false, true) and
729  edm::ParameterDescription<bool>("doPrefitEE", false, true) and
730  edm::ParameterDescription<double>("prefitMaxChiSqEB", 25., true) and
731  edm::ParameterDescription<double>("prefitMaxChiSqEE", 10., true) and
732  edm::ParameterDescription<bool>("dynamicPedestalsEB", false, true) and
733  edm::ParameterDescription<bool>("dynamicPedestalsEE", false, true) and
734  edm::ParameterDescription<bool>("mitigateBadSamplesEB", false, true) and
735  edm::ParameterDescription<bool>("mitigateBadSamplesEE", false, true) and
736  edm::ParameterDescription<bool>("gainSwitchUseMaxSampleEB", true, true) and
737  edm::ParameterDescription<bool>("gainSwitchUseMaxSampleEE", false, true) and
738  edm::ParameterDescription<bool>("selectiveBadSampleCriteriaEB", false, true) and
739  edm::ParameterDescription<bool>("selectiveBadSampleCriteriaEE", false, true) and
740  edm::ParameterDescription<double>("addPedestalUncertaintyEB", 0., true) and
741  edm::ParameterDescription<double>("addPedestalUncertaintyEE", 0., true) and
742  edm::ParameterDescription<bool>("simplifiedNoiseModelForGainSwitch", true, true) and
743  edm::ParameterDescription<std::string>("timealgo", "RatioMethod", true) and
744  edm::ParameterDescription<std::vector<double>>("EBtimeFitParameters",
745  {-2.015452e+00,
746  3.130702e+00,
747  -1.234730e+01,
748  4.188921e+01,
749  -8.283944e+01,
750  9.101147e+01,
751  -5.035761e+01,
752  1.105621e+01},
753  true) and
754  edm::ParameterDescription<std::vector<double>>("EEtimeFitParameters",
755  {-2.390548e+00,
756  3.553628e+00,
757  -1.762341e+01,
758  6.767538e+01,
759  -1.332130e+02,
760  1.407432e+02,
761  -7.541106e+01,
762  1.620277e+01},
763  true) and
764  edm::ParameterDescription<std::vector<double>>("EBamplitudeFitParameters", {1.138, 1.652}, true) and
765  edm::ParameterDescription<std::vector<double>>("EEamplitudeFitParameters", {1.890, 1.400}, true) and
767  edm::ParameterDescription<edm::ESInputTag>("timeOffsetTag", edm::ESInputTag(), true) and
768  edm::ParameterDescription<double>("EBtimeFitLimits_Lower", 0.2, true) and
769  edm::ParameterDescription<double>("EBtimeFitLimits_Upper", 1.4, true) and
770  edm::ParameterDescription<double>("EEtimeFitLimits_Lower", 0.2, true) and
771  edm::ParameterDescription<double>("EEtimeFitLimits_Upper", 1.4, true) and
772  edm::ParameterDescription<double>("EBtimeConstantTerm", .6, true) and
773  edm::ParameterDescription<double>("EEtimeConstantTerm", 1.0, true) and
774  edm::ParameterDescription<double>("EBtimeNconst", 28.5, true) and
775  edm::ParameterDescription<double>("EEtimeNconst", 31.8, true) and
776  edm::ParameterDescription<double>("outOfTimeThresholdGain12pEB", 5., true) and
777  edm::ParameterDescription<double>("outOfTimeThresholdGain12mEB", 5., true) and
778  edm::ParameterDescription<double>("outOfTimeThresholdGain61pEB", 5., true) and
779  edm::ParameterDescription<double>("outOfTimeThresholdGain61mEB", 5., true) and
780  edm::ParameterDescription<double>("outOfTimeThresholdGain12pEE", 1000, true) and
781  edm::ParameterDescription<double>("outOfTimeThresholdGain12mEE", 1000, true) and
782  edm::ParameterDescription<double>("outOfTimeThresholdGain61pEE", 1000, true) and
783  edm::ParameterDescription<double>("outOfTimeThresholdGain61mEE", 1000, true) and
784  edm::ParameterDescription<double>("amplitudeThresholdEB", 10, true) and
785  edm::ParameterDescription<double>("amplitudeThresholdEE", 10, true) and
786  edm::ParameterDescription<double>("crossCorrelationStartTime", -25.0, true) and
787  edm::ParameterDescription<double>("crossCorrelationStopTime", 25.0, true) and
788  edm::ParameterDescription<double>("crossCorrelationTargetTimePrecision", 0.01, true) and
789  edm::ParameterDescription<double>("crossCorrelationTargetTimePrecisionForDelayedPulses", 0.05, true) and
790  edm::ParameterDescription<double>("crossCorrelationTimeShiftWrtRations", 0., true) and
791  edm::ParameterDescription<double>("crossCorrelationMinTimeToBeLateMin", 2., true) and
792  edm::ParameterDescription<double>("crossCorrelationMinTimeToBeLateMax", 5., true));
793 
794  return psd;
795 }
796 
803  "EcalUncalibRecHitWorkerMultiFit");
edm::ESGetToken< EcalPulseCovariances, EcalPulseCovariancesRcd > pulseConvariancesToken_
edm::ParameterSetDescription getAlgoDescription() override
std::array< SampleMatrixGainArray, 2 > noisecors_
EcalPulseShapesMap EcalPulseShapes
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
MPlex< T, D1, D2, N > hypot(const MPlex< T, D1, D2, N > &a, const MPlex< T, D1, D2, N > &b)
Definition: Matriplex.h:436
void computeAmplitude(std::vector< double > &amplitudeFitParameters)
std::vector< float > EBTimeCorrShiftBins
EcalUncalibRecHitMultiFitAlgo multiFitMethod_
const EcalTBWeightMap & getMap() const
Definition: EcalTBWeights.h:28
std::array< SampleMatrix, NGains > SampleMatrixGainArray
EcalUncalibRecHitTimeWeightsAlgo< EEDataFrame > weightsMethod_endcap_
edm::ESGetToken< EcalPulseShapes, EcalPulseShapesRcd > pulseShapesToken_
Eigen::Matrix< double, FullSampleVectorSize, FullSampleVectorSize > FullSampleMatrix
double time(const C &dataFrame, const std::vector< double > &amplitudes, const EcalPedestals::Item *aped, const EcalMGPAGainRatio *aGain, const FullSampleVector &fullpulse, const EcalWeightSet::EcalWeightMatrix **weights)
Compute time.
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
std::vector< double > EBG12SamplesCorrelation
std::map< std::pair< EcalXtalGroupId, EcalTDCId >, EcalWeightSet > EcalTBWeightMap
Definition: EcalTBWeights.h:18
void computeTime(std::vector< double > &timeFitParameters, std::pair< double, double > &timeFitLimits, std::vector< double > &amplitudeFitParameters)
edm::ESGetToken< EcalGainRatios, EcalGainRatiosRcd > gainsToken_
EcalCondObjectContainer< EcalXtalGroupId > EcalWeightXtalGroups
static const int TEMPLATESAMPLES
edm::ESHandle< EcalWeightXtalGroups > grps
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
math::Matrix< 3, 10 >::type EcalWeightMatrix
Definition: EcalWeightSet.h:19
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
Log< level::Error, false > LogError
constexpr const float clockToNS
Definition: EcalConstants.h:10
edm::ESGetToken< EcalSamplesCorrelation, EcalSamplesCorrelationRcd > noiseConvariancesToken_
edm::EDGetTokenT< unsigned int > bunchSpacing_
EcalUncalibRecHitRatioMethodAlgo< EBDataFrame > ratioMethod_barrel_
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
int hashedIndex(int ieta, int iphi)
Definition: EcalPyUtils.cc:36
edm::ESGetToken< EcalTBWeights, EcalTBWeightsRcd > wgtsToken_
T const * product() const
Definition: ESHandle.h:86
EcalGainRatioMap EcalGainRatios
EcalUncalibRecHitRatioMethodAlgo< EEDataFrame > ratioMethod_endcap_
std::vector< float > EETimeCorrAmplitudeBins
T sqrt(T t)
Definition: SSEVec.h:19
edm::ESHandle< EcalPulseShapes > pulseshapes
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
EcalPulseCovariancesMap EcalPulseCovariances
edm::ESHandle< EcalTimeCalibConstants > itime
double timeCorrection(float ampli, const std::vector< float > &amplitudeBins, const std::vector< float > &shiftBins)
unsigned int id() const
std::unique_ptr< EcalUncalibRecHitTimingCCAlgo > computeCC_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
EcalWeightMatrix & getWeightsAfterGainSwitch()
Definition: EcalWeightSet.h:27
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
Definition: DetId.h:17
EcalPedestalsMap EcalPedestals
Definition: EcalPedestals.h:50
edm::ESGetToken< EcalTimeOffsetConstant, EcalTimeOffsetConstantRcd > offtimeToken_
void set(const edm::EventSetup &es) override
edm::ESHandle< EcalPulseCovariances > pulsecovariances
constexpr int gainId(sample_type sample)
get the gainId (2 bits)
EcalWeightMatrix & getWeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:26
EcalTimeCalibConstantMap EcalTimeCalibConstants
std::vector< double > EBG1SamplesCorrelation
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)
edm::ESGetToken< EcalTimeBiasCorrections, EcalTimeBiasCorrectionsRcd > timeCorrBiasToken_
float gain6Over1() const
Eigen::Matrix< double, SampleVectorSize, SampleVectorSize > SampleMatrix
EcalUncalibRecHitTimeWeightsAlgo< EBDataFrame > weightsMethod_barrel_
edm::ESHandle< EcalTimeOffsetConstant > offtime
std::vector< double > EEG1SamplesCorrelation
float EcalTimeCalibConstant
edm::ESGetToken< EcalSampleMask, EcalSampleMaskRcd > sampleMaskToken_
edm::ESGetToken< EcalTimeCalibConstants, EcalTimeCalibConstantsRcd > itimeToken_
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:82
#define DEFINE_EDM_PLUGIN(factory, type, name)
void run(const edm::Event &evt, const EcalDigiCollection &digis, EcalUncalibratedRecHitCollection &result) override
static constexpr int MAXSAMPLES
Definition: EcalDataFrame.h:48
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)
int hashedIndex() const
Definition: EEDetId.h:183
std::vector< double > EEG6SamplesCorrelation
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
edm::ESGetToken< EcalWeightXtalGroups, EcalWeightXtalGroupsRcd > grpsToken_