CMS 3D CMS Logo

SimpleHBHEPhase1Algo.cc
Go to the documentation of this file.
1 #include <algorithm>
2 
4 
7 
10 
15 
16 namespace {
17  // Maximum fractional error for calculating Method 0
18  // pulse containment correction
19  constexpr float PulseContainmentFractionalError = 0.002f;
20 } // namespace
21 
23  const int samplesToAdd,
24  const float phaseNS,
25  const float timeShift,
26  const bool correctForPhaseContainment,
27  const bool applyLegacyHBMCorrection,
28  const bool applyFixPCC,
29  std::unique_ptr<PulseShapeFitOOTPileupCorrection> m2,
30  std::unique_ptr<HcalDeterministicFit> detFit,
31  std::unique_ptr<MahiFit> mahi,
33  : delayToken_(iC.esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "HBHE"))),
34  pulseCorr_(PulseContainmentFractionalError, applyFixPCC, iC),
35  firstSampleShift_(firstSampleShift),
36  samplesToAdd_(samplesToAdd),
37  phaseNS_(phaseNS),
38  timeShift_(timeShift),
39  runnum_(0),
41  applyLegacyHBMCorrection_(applyLegacyHBMCorrection),
42  psFitOOTpuCorr_(std::move(m2)),
43  hltOOTpuCorr_(std::move(detFit)),
44  mahiOOTpuCorr_(std::move(mahi)) {
45  hcalTimeSlew_delay_ = nullptr;
46 }
47 
50 
51  runnum_ = r.run();
52  pulseCorr_.beginRun(es);
53 }
54 
56 
58  const HcalRecoParam* params,
59  const HcalCalibrations& calibs,
60  const bool isData) {
61  const HcalDetId channelId(info.id());
62 
63  // Calculate "Method 0" quantities
64  float m0t = 0.f, m0E = 0.f;
65  {
66  int ibeg = static_cast<int>(info.soi()) + firstSampleShift_;
67  if (ibeg < 0)
68  ibeg = 0;
69  const int nSamplesToAdd = params ? params->samplesToAdd() : samplesToAdd_;
70  const double fc_ampl = info.chargeInWindow(ibeg, ibeg + nSamplesToAdd);
71  const bool applyContainment = params ? params->correctForPhaseContainment() : corrFPC_;
72  const float phasens = params ? params->correctionPhaseNS() : phaseNS_;
73  m0E = m0Energy(info, fc_ampl, applyContainment, phasens, nSamplesToAdd);
74  m0E *= hbminusCorrectionFactor(channelId, m0E, isData);
75  m0t = m0Time(info, fc_ampl, nSamplesToAdd);
76  }
77 
78  // Run "Method 2"
79  float m2t = 0.f, m2E = 0.f, chi2 = -1.f;
80  bool useTriple = false;
82  if (method2) {
83  psFitOOTpuCorr_->setPulseShapeTemplate(
84  theHcalPulseShapes_.getShape(info.recoShape()), !info.hasTimeInfo(), info.nSamples(), hcalTimeSlew_delay_);
85  // "phase1Apply" call below sets m2E, m2t, useTriple, and chi2.
86  // These parameters are pased by non-const reference.
87  method2->phase1Apply(info, m2E, m2t, useTriple, chi2);
88  m2E *= hbminusCorrectionFactor(channelId, m2E, isData);
89  }
90 
91  // Run "Method 3"
92  float m3t = 0.f, m3E = 0.f;
93  const HcalDeterministicFit* method3 = hltOOTpuCorr_.get();
94  if (method3) {
95  // "phase1Apply" sets m3E and m3t (pased by non-const reference)
96  method3->phase1Apply(info, m3E, m3t, hcalTimeSlew_delay_);
97  m3E *= hbminusCorrectionFactor(channelId, m3E, isData);
98  }
99 
100  // Run Mahi
101  float m4E = 0.f, m4ESOIPlusOne = 0.f, m4chi2 = -1.f;
102  float m4T = 0.f;
103  bool m4UseTriple = false;
104 
105  const MahiFit* mahi = mahiOOTpuCorr_.get();
106 
107  if (mahi) {
108  mahiOOTpuCorr_->setPulseShapeTemplate(
109  info.recoShape(), theHcalPulseShapes_, info.hasTimeInfo(), hcalTimeSlew_delay_, info.nSamples(), info.tsGain(0));
110  mahi->phase1Apply(info, m4E, m4ESOIPlusOne, m4T, m4UseTriple, m4chi2);
111  m4E *= hbminusCorrectionFactor(channelId, m4E, isData);
112  m4ESOIPlusOne *= hbminusCorrectionFactor(channelId, m4ESOIPlusOne, isData);
113  }
114 
115  // Finally, construct the rechit
116  HBHERecHit rh;
117 
118  float rhE = m0E;
119  float rht = m0t;
120  float rhX = -1.f;
121  if (mahi) {
122  rhE = m4E;
123  rht = m4T;
124  rhX = m4chi2;
125  } else if (method2) {
126  rhE = m2E;
127  rht = m2t;
128  rhX = chi2;
129  } else if (method3) {
130  rhE = m3E;
131  rht = m3t;
132  }
133  float tdcTime = info.soiRiseTime();
134  if (!HcalSpecialTimes::isSpecial(tdcTime))
135  tdcTime += timeShift_;
136  rh = HBHERecHit(channelId, rhE, rht, tdcTime);
137  rh.setRawEnergy(m0E);
138  if (method3) {
139  rh.setAuxEnergy(m3E);
140  } else {
141  rh.setAuxEnergy(m4ESOIPlusOne);
142  }
143  rh.setChiSquared(rhX);
144 
145  // Set rechit aux words
147 
148  // Set some rechit flags (here, for Method 2/Mahi)
149  if (useTriple || m4UseTriple)
151 
152  return rh;
153 }
154 
156  const float energy,
157  const bool isRealData) const {
158  float corr = 1.f;
159  if (applyLegacyHBMCorrection_ && isRealData && runnum_ > 0)
160  if (cell.subdet() == HcalBarrel) {
161  const int ieta = cell.ieta();
162  const int iphi = cell.iphi();
164  }
165  return corr;
166 }
167 
169  const double fc_ampl,
170  const bool applyContainmentCorrection,
171  const double phaseNs,
172  const int nSamplesToAdd) {
173  int ibeg = static_cast<int>(info.soi()) + firstSampleShift_;
174  if (ibeg < 0)
175  ibeg = 0;
176  double e = info.energyInWindow(ibeg, ibeg + nSamplesToAdd);
177 
178  // Pulse containment correction
179  {
180  double corrFactor = 1.0;
181  if (applyContainmentCorrection)
182  corrFactor = pulseCorr_.get(info.id(), nSamplesToAdd, phaseNs)->getCorrection(fc_ampl);
183  e *= corrFactor;
184  }
185 
186  return e;
187 }
188 
190  const double fc_ampl,
191  const int nSamplesToExamine) const {
192  float time = -9999.f; // historic value
193 
194  const unsigned nSamples = info.nSamples();
195  if (nSamples > 2U) {
196  const int soi = info.soi();
197  int ibeg = soi + firstSampleShift_;
198  if (ibeg < 0)
199  ibeg = 0;
200  const int iend = std::min(ibeg + nSamplesToExamine, (int)nSamples - 1); // actual array
201 
202  unsigned maxI = info.peakEnergyTS((unsigned)ibeg, (unsigned)iend); // requires unsigned params
204  if (maxI >= nSamples)
205  maxI = nSamples - 1U; // just in case
206 
207  // Simplified evaluation for Phase1
208  float emax0 = info.tsEnergy(maxI);
209  float emax1 = 0.f;
210  if (maxI < (nSamples - 1U))
211  emax1 = info.tsEnergy(maxI + 1U);
212 
213  // consider soi reference for collisions
214  int position = (int)maxI;
215  if (nSamplesToExamine < (int)nSamples)
216  position -= soi;
217 
218  time = 25.f * (float)position;
219  if (emax0 > 0.f && emax1 > 0.f)
220  time += 25.f * emax1 / (emax0 + emax1); // 1st order corr.
221 
222  // TimeSlew correction
224  }
225  }
226  return time;
227 }
HBHERecHit reconstruct(const HBHEChannelInfo &info, const HcalRecoParam *params, const HcalCalibrations &calibs, bool isRealData) override
const HcalTimeSlew * hcalTimeSlew_delay_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
static const TGPicture * info(bool iBackgroundIsBlack)
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, const HcalTimeSlew *hcalTimeSlew_delay) const
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const HcalPulseContainmentCorrection * get(const HcalDetId &detId, int toAdd, float fixedphase_ns)
std::unique_ptr< HcalDeterministicFit > hltOOTpuCorr_
void beginRun(const edm::Run &, const edm::EventSetup &) override
HcalPulseContainmentManager pulseCorr_
SimpleHBHEPhase1Algo(int firstSampleShift, int samplesToAdd, float phaseNS, float timeShift, bool correctForPhaseContainment, bool applyLegacyHBMCorrection, bool applyFixPCC, std::unique_ptr< PulseShapeFitOOTPileupCorrection > m2, std::unique_ptr< HcalDeterministicFit > detFit, std::unique_ptr< MahiFit > mahi, edm::ConsumesCollector iC)
edm::ESGetToken< HcalTimeSlew, HcalTimeSlewRecord > delayToken_
float hbminus_special_ecorr(int ieta, int iphi, double energy, int runnum)
Special energy correction for some HB- cells.
static constexpr void setAux(const HBHEChannelInfo &info, HBHERecHit *rechit)
constexpr void setFlagField(uint32_t value, int base, int width=1)
Definition: CaloRecHit.h:36
constexpr void setChiSquared(const float chi2)
Definition: HBHERecHit.h:43
constexpr void setAuxEnergy(const float en)
Definition: HBHERecHit.h:49
float hbminusCorrectionFactor(const HcalDetId &cell, float energy, bool isRealData) const
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &soiPlusOneEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
Definition: MahiFit.cc:50
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
static const unsigned MAXSAMPLES
dictionary corr
float delay(float fC, BiasSetting bias=Medium) const
Returns the amount (ns) by which a pulse of the given number of fC will be delayed by the timeslew ef...
Definition: HcalTimeSlew.cc:20
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
Transition
Definition: Transition.h:12
double f[11][100]
float m0Time(const HBHEChannelInfo &info, double reconstructedCharge, int nSamplesToExamine) const
constexpr bool isSpecial(const float t)
std::unique_ptr< MahiFit > mahiOOTpuCorr_
const Shape & getShape(int shapeType) const
HcalPulseShapes theHcalPulseShapes_
void beginRun(edm::EventSetup const &es)
float m0Energy(const HBHEChannelInfo &info, double reconstructedCharge, bool applyContainmentCorrection, double phaseNS, int nSamplesToAdd)
HLT enums.
static int position[264][3]
Definition: ReadPGInfo.cc:289
std::unique_ptr< PulseShapeFitOOTPileupCorrection > psFitOOTpuCorr_
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
constexpr void setRawEnergy(const float en)
Definition: HBHERecHit.h:46