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 firstSampleShift,
22  const int samplesToAdd,
23  const float phaseNS,
24  const float timeShift,
25  const bool correctForPhaseContainment,
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  psFitOOTpuCorr_(std::move(m2)),
37  hltOOTpuCorr_(std::move(detFit)),
38  mahiOOTpuCorr_(std::move(mahi))
39 {
40  hcalTimeSlew_delay_ = nullptr;
41 }
42 
44  const edm::EventSetup& es)
45 {
47  es.get<HcalTimeSlewRecord>().get("HBHE", delay);
48  hcalTimeSlew_delay_ = &*delay;
49 
50  runnum_ = r.run();
51  pulseCorr_.beginRun(es);
52 }
53 
55 {
56  runnum_ = 0;
57 }
58 
60  const HcalRecoParam* params,
61  const HcalCalibrations& calibs,
62  const bool isData)
63 {
64  HBHERecHit rh;
65 
66  const HcalDetId channelId(info.id());
67 
68  // Calculate "Method 0" quantities
69  float m0t = 0.f, m0E = 0.f;
70  {
71  int ibeg = static_cast<int>(info.soi()) + firstSampleShift_;
72  if (ibeg < 0)
73  ibeg = 0;
74  const int nSamplesToAdd = params ? params->samplesToAdd() : samplesToAdd_;
75  const double fc_ampl = info.chargeInWindow(ibeg, ibeg + nSamplesToAdd);
76  const bool applyContainment = params ? params->correctForPhaseContainment() : corrFPC_;
77  const float phasens = params ? params->correctionPhaseNS() : phaseNS_;
78  m0E = m0Energy(info, fc_ampl, applyContainment, phasens, nSamplesToAdd);
79  m0E *= hbminusCorrectionFactor(channelId, m0E, isData);
80  m0t = m0Time(info, fc_ampl, calibs, nSamplesToAdd);
81  }
82 
83  // Run "Method 2"
84  float m2t = 0.f, m2E = 0.f, chi2 = -1.f;
85  bool useTriple = false;
87  if (method2)
88  {
89  psFitOOTpuCorr_->setPulseShapeTemplate(theHcalPulseShapes_.getShape(info.recoShape()),
91  // "phase1Apply" call below sets m2E, m2t, useTriple, and chi2.
92  // These parameters are pased by non-const reference.
93  method2->phase1Apply(info, m2E, m2t, useTriple, chi2);
94  m2E *= hbminusCorrectionFactor(channelId, m2E, isData);
95  }
96 
97  // Run "Method 3"
98  float m3t = 0.f, m3E = 0.f;
99  const HcalDeterministicFit* method3 = hltOOTpuCorr_.get();
100  if (method3)
101  {
102  // "phase1Apply" sets m3E and m3t (pased by non-const reference)
103  method3->phase1Apply(info, m3E, m3t, hcalTimeSlew_delay_);
104  m3E *= hbminusCorrectionFactor(channelId, m3E, isData);
105  }
106 
107  // Run Mahi
108  float m4E = 0.f, m4chi2 = -1.f;
109  float m4T = 0.f;
110  bool m4UseTriple=false;
111 
112  const MahiFit* mahi = mahiOOTpuCorr_.get();
113 
114  if (mahi) {
116  mahi->phase1Apply(info,m4E,m4T,m4UseTriple,m4chi2);
117  m4E *= hbminusCorrectionFactor(channelId, m4E, isData);
118  }
119 
120  // Finally, construct the rechit
121  float rhE = m0E;
122  float rht = m0t;
123  float rhX = -1.f;
124  if (mahi)
125  {
126  rhE = m4E;
127  rht = m4T;
128  rhX = m4chi2;
129  }
130  else if (method2)
131  {
132  rhE = m2E;
133  rht = m2t;
134  rhX = chi2;
135  }
136  else if (method3)
137  {
138  rhE = m3E;
139  rht = m3t;
140  }
141  float tdcTime = info.soiRiseTime();
142  if (!HcalSpecialTimes::isSpecial(tdcTime))
143  tdcTime += timeShift_;
144  rh = HBHERecHit(channelId, rhE, rht, tdcTime);
145  rh.setRawEnergy(m0E);
146  rh.setAuxEnergy(m3E);
147  rh.setChiSquared(rhX);
148 
149  // Set rechit aux words
150  HBHERecHitAuxSetter::setAux(info, &rh);
151 
152  // Set some rechit flags (here, for Method 2/Mahi)
153  if (useTriple || m4UseTriple)
155 
156  return rh;
157 }
158 
160  const float energy,
161  const bool isRealData) const
162 {
163  float corr = 1.f;
164  if (isRealData && runnum_ > 0)
165  if (cell.subdet() == HcalBarrel)
166  {
167  const int ieta = cell.ieta();
168  const int iphi = cell.iphi();
169  corr = hbminus_special_ecorr(ieta, iphi, energy, runnum_);
170  }
171  return corr;
172 }
173 
175  const double fc_ampl,
176  const bool applyContainmentCorrection,
177  const double phaseNs,
178  const int nSamplesToAdd)
179 {
180  int ibeg = static_cast<int>(info.soi()) + firstSampleShift_;
181  if (ibeg < 0)
182  ibeg = 0;
183  double e = info.energyInWindow(ibeg, ibeg + nSamplesToAdd);
184 
185  // Pulse containment correction
186  {
187  double corrFactor = 1.0;
188  if (applyContainmentCorrection)
189  corrFactor = pulseCorr_.get(info.id(), nSamplesToAdd, phaseNs)->getCorrection(fc_ampl);
190  e *= corrFactor;
191  }
192 
193  return e;
194 }
195 
197  const double fc_ampl,
198  const HcalCalibrations& calibs,
199  const int nSamplesToExamine) const
200 {
201  float time = -9999.f; // historic value
202 
203  const unsigned nSamples = info.nSamples();
204  if (nSamples > 2U)
205  {
206  const int soi = info.soi();
207  int ibeg = soi + firstSampleShift_;
208  if (ibeg < 0)
209  ibeg = 0;
210  const int iend = ibeg + nSamplesToExamine;
211  unsigned maxI = info.peakEnergyTS(ibeg, iend);
212  if (maxI < HBHEChannelInfo::MAXSAMPLES)
213  {
214  if (!maxI)
215  maxI = 1U;
216  else if (maxI >= nSamples - 1U)
217  maxI = nSamples - 2U;
218 
219  // The remaining code in this scope emulates
220  // the historic algorithm
221  float t0 = info.tsEnergy(maxI - 1U);
222  float maxA = info.tsEnergy(maxI);
223  float t2 = info.tsEnergy(maxI + 1U);
224 
225  // Handle negative excursions by moving "zero"
226  float minA = t0;
227  if (maxA < minA) minA = maxA;
228  if (t2 < minA) minA=t2;
229  if (minA < 0.f) { maxA-=minA; t0-=minA; t2-=minA; }
230  float wpksamp = (t0 + maxA + t2);
231  if (wpksamp) wpksamp = (maxA + 2.f*t2) / wpksamp;
232  time = (maxI - soi)*25.f + timeshift_ns_hbheho(wpksamp);
233 
234  // Legacy QIE8 timing correction
235  time -= hcalTimeSlew_delay_->delay(std::max(1.0, fc_ampl), HcalTimeSlew::Medium);
236  // Time calibration
237  time -= calibs.timecorr();
238  }
239  }
240  return time;
241 }
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:33
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
Definition: MahiFit.cc:40
static const TGPicture * info(bool iBackgroundIsBlack)
float timeshift_ns_hbheho(float wpksamp)
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:142
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
double delay(double 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:14
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
#define constexpr
constexpr void setFlagField(uint32_t value, int base, int width=1)
Definition: CaloRecHit.h:38
static const unsigned MAXSAMPLES
constexpr float correctionPhaseNS() const
Definition: HcalRecoParam.h:31
float m0Time(const HBHEChannelInfo &info, double reconstructedCharge, const HcalCalibrations &calibs, int nSamplesToExamine) const
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
constexpr bool isSpecial(const float t)
SimpleHBHEPhase1Algo(int firstSampleShift, int samplesToAdd, float phaseNS, float timeShift, bool correctForPhaseContainment, std::unique_ptr< PulseShapeFitOOTPileupCorrection > m2, std::unique_ptr< HcalDeterministicFit > detFit, std::unique_ptr< MahiFit > mahi)
int recoShape() const
float hbminusCorrectionFactor(const HcalDetId &cell, float energy, bool isRealData) const
constexpr size_t nSamples
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:29
HcalPulseShapes theHcalPulseShapes_
double tsEnergy(const unsigned ts) const
void beginRun(edm::EventSetup const &es)
constexpr double timecorr() const
get time correction factor
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:50
T get() const
Definition: EventSetup.h:62
void setChiSquared(const float chi2)
Definition: HBHERecHit.h:44
unsigned nSamples() const
std::unique_ptr< PulseShapeFitOOTPileupCorrection > psFitOOTpuCorr_
void setRawEnergy(const float en)
Definition: HBHERecHit.h:47
unsigned peakEnergyTS(const unsigned begin, const unsigned end) const
def move(src, dest)
Definition: eostools.py:511
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, const HcalTimeSlew *hcalTimeSlew_delay) const
Definition: Run.h:44