CMS 3D CMS Logo

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