CMS 3D CMS Logo

SimpleHBHEPhase1Algo.cc
Go to the documentation of this file.
1 #include <algorithm>
2 
4 
7 
9 
12 
13 
14 // Maximum fractional error for calculating Method 0
15 // pulse containment correction
17 
19  const int firstSampleShift,
20  const int samplesToAdd,
21  const float phaseNS,
22  const float timeShift,
23  const bool correctForPhaseContainment,
24  std::unique_ptr<PulseShapeFitOOTPileupCorrection> m2,
25  std::unique_ptr<HcalDeterministicFit> detFit)
26  : pulseCorr_(PulseContainmentFractionalError),
27  firstSampleShift_(firstSampleShift),
28  samplesToAdd_(samplesToAdd),
29  phaseNS_(phaseNS),
30  timeShift_(timeShift),
31  runnum_(0),
32  corrFPC_(correctForPhaseContainment),
33  psFitOOTpuCorr_(std::move(m2)),
34  hltOOTpuCorr_(std::move(detFit))
35 {
36 }
37 
39  const edm::EventSetup& es)
40 {
41  runnum_ = r.run();
42  pulseCorr_.beginRun(es);
43 }
44 
46 {
47  runnum_ = 0;
49 }
50 
52  const HcalRecoParam* params,
53  const HcalCalibrations& calibs,
54  const bool isData)
55 {
56  HBHERecHit rh;
57 
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, calibs, 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  {
81  psFitOOTpuCorr_->setPulseShapeTemplate(theHcalPulseShapes_.getShape(info.recoShape()),
82  !info.hasTimeInfo());
83  // "phase1Apply" call below sets m2E, m2t, useTriple, and chi2.
84  // These parameters are pased by non-const reference.
85  method2->phase1Apply(info, m2E, m2t, useTriple, chi2);
86  m2E *= hbminusCorrectionFactor(channelId, m2E, isData);
87  }
88 
89  // Run "Method 3"
90  float m3t = 0.f, m3E = 0.f;
91  const HcalDeterministicFit* method3 = hltOOTpuCorr_.get();
92  if (method3)
93  {
94  // "phase1Apply" sets m3E and m3t (pased by non-const reference)
95  method3->phase1Apply(info, m3E, m3t);
96  m3E *= hbminusCorrectionFactor(channelId, m3E, isData);
97  }
98 
99  // Finally, construct the rechit
100  float rhE = m0E;
101  float rht = m0t;
102  if (method2)
103  {
104  rhE = m2E;
105  rht = m2t;
106  }
107  else if (method3)
108  {
109  rhE = m3E;
110  rht = m3t;
111  }
112  float tdcTime = info.soiRiseTime();
113  if (!HcalSpecialTimes::isSpecial(tdcTime))
114  tdcTime += timeShift_;
115  rh = HBHERecHit(channelId, rhE, rht, tdcTime);
116  rh.setRawEnergy(m0E);
117  rh.setAuxEnergy(m3E);
118  rh.setChiSquared(chi2);
119 
120  // Set rechit aux words
121  HBHERecHitAuxSetter::setAux(info, &rh);
122 
123  // Set some rechit flags (here, for Method 2)
124  if (useTriple)
126 
127  return rh;
128 }
129 
131  const float energy,
132  const bool isRealData) const
133 {
134  float corr = 1.f;
135  if (isRealData && runnum_ > 0)
136  if (cell.subdet() == HcalBarrel)
137  {
138  const int ieta = cell.ieta();
139  const int iphi = cell.iphi();
140  corr = hbminus_special_ecorr(ieta, iphi, energy, runnum_);
141  }
142  return corr;
143 }
144 
146  const double fc_ampl,
147  const bool applyContainmentCorrection,
148  const double phaseNs,
149  const int nSamplesToAdd)
150 {
151  int ibeg = static_cast<int>(info.soi()) + firstSampleShift_;
152  if (ibeg < 0)
153  ibeg = 0;
154  double e = info.energyInWindow(ibeg, ibeg + nSamplesToAdd);
155 
156  // Pulse containment correction
157  {
158  double corrFactor = 1.0;
159  if (applyContainmentCorrection)
160  corrFactor = pulseCorr_.get(info.id(), nSamplesToAdd, phaseNs)->getCorrection(fc_ampl);
161  e *= corrFactor;
162  }
163 
164  return e;
165 }
166 
168  const double fc_ampl,
169  const HcalCalibrations& calibs,
170  const int nSamplesToExamine) const
171 {
172  float time = -9999.f; // historic value
173 
174  const unsigned nSamples = info.nSamples();
175  if (nSamples > 2U)
176  {
177  const int soi = info.soi();
178  int ibeg = soi + firstSampleShift_;
179  if (ibeg < 0)
180  ibeg = 0;
181  const int iend = ibeg + nSamplesToExamine;
182  unsigned maxI = info.peakEnergyTS(ibeg, iend);
183  if (maxI < HBHEChannelInfo::MAXSAMPLES)
184  {
185  if (!maxI)
186  maxI = 1U;
187  else if (maxI >= nSamples - 1U)
188  maxI = nSamples - 2U;
189 
190  // The remaining code in this scope emulates
191  // the historic algorithm
192  float t0 = info.tsEnergy(maxI - 1U);
193  float maxA = info.tsEnergy(maxI);
194  float t2 = info.tsEnergy(maxI + 1U);
195 
196  // Handle negative excursions by moving "zero"
197  float minA = t0;
198  if (maxA < minA) minA = maxA;
199  if (t2 < minA) minA=t2;
200  if (minA < 0.f) { maxA-=minA; t0-=minA; t2-=minA; }
201  float wpksamp = (t0 + maxA + t2);
202  if (wpksamp) wpksamp = (maxA + 2.f*t2) / wpksamp;
203  time = (maxI - soi)*25.f + timeshift_ns_hbheho(wpksamp);
204 
205  // Legacy QIE8 timing correction
206  time -= HcalTimeSlew::delay(std::max(1.0, fc_ampl),
208  // Time calibration
209  time -= calibs.timecorr();
210  }
211  }
212  return time;
213 }
const Shape & getShape(int shapeType) const
virtual HBHERecHit reconstruct(const HBHEChannelInfo &info, const HcalRecoParam *params, const HcalCalibrations &calibs, bool isRealData) override
static const TGPicture * info(bool iBackgroundIsBlack)
float timeshift_ns_hbheho(float wpksamp)
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
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_
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
float PulseContainmentFractionalError
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime) const
bool correctForPhaseContainment() const
Definition: HcalRecoParam.h:29
void setFlagField(uint32_t value, int base, int width=1)
Definition: CaloRecHit.cc:20
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
static const unsigned MAXSAMPLES
bool isSpecial(const float t)
auto const T2 &decltype(t1.eta()) t2
Definition: deltaR.h:16
float m0Time(const HBHEChannelInfo &info, double reconstructedCharge, const HcalCalibrations &calibs, int nSamplesToExamine) const
float soiRiseTime() const
SimpleHBHEPhase1Algo(int firstSampleShift, int samplesToAdd, float phaseNS, float timeShift, bool correctForPhaseContainment, std::unique_ptr< PulseShapeFitOOTPileupCorrection > m2, std::unique_ptr< HcalDeterministicFit > detFit)
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
double energyInWindow(const unsigned begin, const unsigned end) const
double f[11][100]
double chargeInWindow(const unsigned begin, const unsigned end) const
int recoShape() const
unsigned int samplesToAdd() const
Definition: HcalRecoParam.h:33
float hbminusCorrectionFactor(const HcalDetId &cell, float energy, bool isRealData) const
constexpr size_t nSamples
virtual void endRun() override
float correctionPhaseNS() const
Definition: HcalRecoParam.h:31
JetCorrectorParameters corr
Definition: classes.h:5
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:103
HcalPulseShapes theHcalPulseShapes_
double tsEnergy(const unsigned ts) const
double timecorr() const
get time correction factor
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:33
void setChiSquared(const float chi2)
Definition: HBHERecHit.h:27
unsigned nSamples() const
std::unique_ptr< PulseShapeFitOOTPileupCorrection > psFitOOTpuCorr_
void setRawEnergy(const float en)
Definition: HBHERecHit.h:30
unsigned peakEnergyTS(const unsigned begin, const unsigned end) const
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:42
static double delay(double fC, BiasSetting bias=Medium)
Returns the amount (ns) by which a pulse of the given number of fC will be delayed by the timeslew ef...
Definition: HcalTimeSlew.cc:16