CMS 3D CMS Logo

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