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  const bool applyLegacyHBMCorrection,
27  std::unique_ptr<PulseShapeFitOOTPileupCorrection> m2,
28  std::unique_ptr<HcalDeterministicFit> detFit,
29  std::unique_ptr<MahiFit> mahi)
30  : pulseCorr_(PulseContainmentFractionalError),
31  firstSampleShift_(firstSampleShift),
32  samplesToAdd_(samplesToAdd),
33  phaseNS_(phaseNS),
34  timeShift_(timeShift),
35  runnum_(0),
36  corrFPC_(correctForPhaseContainment),
37  applyLegacyHBMCorrection_(applyLegacyHBMCorrection),
38  psFitOOTpuCorr_(std::move(m2)),
39  hltOOTpuCorr_(std::move(detFit)),
40  mahiOOTpuCorr_(std::move(mahi))
41 {
42  hcalTimeSlew_delay_ = nullptr;
43 }
44 
46  const edm::EventSetup& es)
47 {
49  es.get<HcalTimeSlewRecord>().get("HBHE", delay);
50  hcalTimeSlew_delay_ = &*delay;
51 
52  runnum_ = r.run();
53  pulseCorr_.beginRun(es);
54 }
55 
57 {
58  runnum_ = 0;
59 }
60 
62  const HcalRecoParam* params,
63  const HcalCalibrations& calibs,
64  const bool isData)
65 {
66  HBHERecHit rh;
67 
68  const HcalDetId channelId(info.id());
69 
70  // Calculate "Method 0" quantities
71  float m0t = 0.f, m0E = 0.f;
72  {
73  int ibeg = static_cast<int>(info.soi()) + firstSampleShift_;
74  if (ibeg < 0)
75  ibeg = 0;
76  const int nSamplesToAdd = params ? params->samplesToAdd() : samplesToAdd_;
77  const double fc_ampl = info.chargeInWindow(ibeg, ibeg + nSamplesToAdd);
78  const bool applyContainment = params ? params->correctForPhaseContainment() : corrFPC_;
79  const float phasens = params ? params->correctionPhaseNS() : phaseNS_;
80  m0E = m0Energy(info, fc_ampl, applyContainment, phasens, nSamplesToAdd);
81  m0E *= hbminusCorrectionFactor(channelId, m0E, isData);
82  m0t = m0Time(info, fc_ampl, calibs, nSamplesToAdd);
83  }
84 
85  // Run "Method 2"
86  float m2t = 0.f, m2E = 0.f, chi2 = -1.f;
87  bool useTriple = false;
89  if (method2)
90  {
91  psFitOOTpuCorr_->setPulseShapeTemplate(theHcalPulseShapes_.getShape(info.recoShape()),
93  // "phase1Apply" call below sets m2E, m2t, useTriple, and chi2.
94  // These parameters are pased by non-const reference.
95  method2->phase1Apply(info, m2E, m2t, useTriple, chi2);
96  m2E *= hbminusCorrectionFactor(channelId, m2E, isData);
97  }
98 
99  // Run "Method 3"
100  float m3t = 0.f, m3E = 0.f;
101  const HcalDeterministicFit* method3 = hltOOTpuCorr_.get();
102  if (method3)
103  {
104  // "phase1Apply" sets m3E and m3t (pased by non-const reference)
105  method3->phase1Apply(info, m3E, m3t, hcalTimeSlew_delay_);
106  m3E *= hbminusCorrectionFactor(channelId, m3E, isData);
107  }
108 
109  // Run Mahi
110  float m4E = 0.f, m4chi2 = -1.f;
111  float m4T = 0.f;
112  bool m4UseTriple=false;
113 
114  const MahiFit* mahi = mahiOOTpuCorr_.get();
115 
116  if (mahi) {
118  mahi->phase1Apply(info,m4E,m4T,m4UseTriple,m4chi2);
119  m4E *= hbminusCorrectionFactor(channelId, m4E, isData);
120  }
121 
122  // Finally, construct the rechit
123  float rhE = m0E;
124  float rht = m0t;
125  float rhX = -1.f;
126  if (mahi)
127  {
128  rhE = m4E;
129  rht = m4T;
130  rhX = m4chi2;
131  }
132  else if (method2)
133  {
134  rhE = m2E;
135  rht = m2t;
136  rhX = chi2;
137  }
138  else if (method3)
139  {
140  rhE = m3E;
141  rht = m3t;
142  }
143  float tdcTime = info.soiRiseTime();
144  if (!HcalSpecialTimes::isSpecial(tdcTime))
145  tdcTime += timeShift_;
146  rh = HBHERecHit(channelId, rhE, rht, tdcTime);
147  rh.setRawEnergy(m0E);
148  rh.setAuxEnergy(m3E);
149  rh.setChiSquared(rhX);
150 
151  // Set rechit aux words
152  HBHERecHitAuxSetter::setAux(info, &rh);
153 
154  // Set some rechit flags (here, for Method 2/Mahi)
155  if (useTriple || m4UseTriple)
157 
158  return rh;
159 }
160 
162  const float energy,
163  const bool isRealData) const
164 {
165  float corr = 1.f;
166  if (applyLegacyHBMCorrection_ && isRealData && runnum_ > 0)
167  if (cell.subdet() == HcalBarrel)
168  {
169  const int ieta = cell.ieta();
170  const int iphi = cell.iphi();
171  corr = hbminus_special_ecorr(ieta, iphi, energy, runnum_);
172  }
173  return corr;
174 }
175 
177  const double fc_ampl,
178  const bool applyContainmentCorrection,
179  const double phaseNs,
180  const int nSamplesToAdd)
181 {
182  int ibeg = static_cast<int>(info.soi()) + firstSampleShift_;
183  if (ibeg < 0)
184  ibeg = 0;
185  double e = info.energyInWindow(ibeg, ibeg + nSamplesToAdd);
186 
187  // Pulse containment correction
188  {
189  double corrFactor = 1.0;
190  if (applyContainmentCorrection)
191  corrFactor = pulseCorr_.get(info.id(), nSamplesToAdd, phaseNs)->getCorrection(fc_ampl);
192  e *= corrFactor;
193  }
194 
195  return e;
196 }
197 
199  const double fc_ampl,
200  const HcalCalibrations& calibs,
201  const int nSamplesToExamine) const
202 {
203  float time = -9999.f; // historic value
204 
205  const unsigned nSamples = info.nSamples();
206  if (nSamples > 2U)
207  {
208  const int soi = info.soi();
209  int ibeg = soi + firstSampleShift_;
210  if (ibeg < 0)
211  ibeg = 0;
212  const int iend = std::min(ibeg + nSamplesToExamine, (int)nSamples - 1); // actual array
213 
214  unsigned maxI = info.peakEnergyTS((unsigned)ibeg, (unsigned)iend); // requires unsigned params
215  if (maxI < HBHEChannelInfo::MAXSAMPLES)
216  {
217 
218  if(maxI >= nSamples) maxI = nSamples - 1U; // just in case
219 
220  // Simplified evaluation for Phase1
221  float emax0 = info.tsEnergy(maxI);
222  float emax1 = 0.f;
223  if(maxI < (nSamples - 1U)) emax1 = info.tsEnergy(maxI + 1U);
224 
225  // consider soi reference for collisions
226  int position = (int)maxI;
227  if(nSamplesToExamine < (int)nSamples) position -= soi;
228 
229  time = 25.f * (float)position;
230  if(emax0 > 0.f && emax1 > 0.f) time += 25.f * emax1/(emax0+emax1); // 1st order corr.
231 
232  // TimeSlew correction
233  time -= hcalTimeSlew_delay_->delay(std::max(1.0, fc_ampl), HcalTimeSlew::Medium);
234 
235  }
236  }
237  return time;
238 }
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:41
static const TGPicture * info(bool iBackgroundIsBlack)
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:146
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: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:159
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
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:161
constexpr bool correctForPhaseContainment() const
Definition: HcalRecoParam.h:29
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:50
static int position[264][3]
Definition: ReadPGInfo.cc:509
T get() const
Definition: EventSetup.h:71
void setChiSquared(const float chi2)
Definition: HBHERecHit.h:44
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:14
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
#define constexpr
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, const HcalTimeSlew *hcalTimeSlew_delay) const
Definition: Run.h:45