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
18 constexpr float PulseContainmentFractionalError = 0.002f;
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),
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);
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(
81  theHcalPulseShapes_.getShape(info.recoShape()), !info.hasTimeInfo(), info.nSamples(), hcalTimeSlew_delay_);
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(
106  theHcalPulseShapes_.getShape(info.recoShape()), info.hasTimeInfo(), hcalTimeSlew_delay_, info.nSamples());
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
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();
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
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
216  }
217  }
218  return time;
219 }
HcalPhase1FlagLabels::HBHEPulseFitBit
Definition: HcalPhase1FlagLabels.h:14
SimpleHBHEPhase1Algo::theHcalPulseShapes_
HcalPulseShapes theHcalPulseShapes_
Definition: SimpleHBHEPhase1Algo.h:110
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
SimpleHBHEPhase1Algo::psFitOOTpuCorr_
std::unique_ptr< PulseShapeFitOOTPileupCorrection > psFitOOTpuCorr_
Definition: SimpleHBHEPhase1Algo.h:102
HcalSpecialTimes::isSpecial
constexpr bool isSpecial(const float t)
Definition: HcalSpecialTimes.h:53
HBHERecHit::setAuxEnergy
constexpr void setAuxEnergy(const float en)
Definition: HBHERecHit.h:47
HBHERecHitAuxSetter::setAux
constexpr static void setAux(const HBHEChannelInfo &info, HBHERecHit *rechit)
Definition: HBHERecHitAuxSetter.h:47
ESHandle.h
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
HcalTimeSlew::Medium
Definition: HcalTimeSlew.h:71
MahiFit
Definition: MahiFit.h:89
HcalDetId::iphi
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
PulseShapeFitOOTPileupCorrection
Definition: PulseShapeFitOOTPileupCorrection.h:23
HcalDeterministicFit
Definition: HcalDeterministicFit.h:16
HLT_2018_cff.applyLegacyHBMCorrection
applyLegacyHBMCorrection
Definition: HLT_2018_cff.py:7111
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm::Run
Definition: Run.h:45
min
T min(T a, T b)
Definition: MathUtil.h:58
HBHERecHit
Definition: HBHERecHit.h:13
HcalDeterministicFit::phase1Apply
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, const HcalTimeSlew *hcalTimeSlew_delay) const
Definition: HcalDeterministicFit.cc:89
SimpleHBHEPhase1Algo::firstSampleShift_
int firstSampleShift_
Definition: SimpleHBHEPhase1Algo.h:93
HBHERecHitAuxSetter.h
SimpleHBHEPhase1Algo::endRun
void endRun() override
Definition: SimpleHBHEPhase1Algo.cc:52
HcalTimeSlew.h
HcalPhase1FlagLabels.h
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
MahiFit::phase1Apply
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
Definition: MahiFit.cc:46
castor_dqm_sourceclient-live_cfg.samplesToAdd
samplesToAdd
Definition: castor_dqm_sourceclient-live_cfg.py:56
findQualityFiles.maxI
int maxI
Definition: findQualityFiles.py:182
HcalBarrel
Definition: HcalAssistant.h:33
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
SimpleHBHEPhase1Algo::hltOOTpuCorr_
std::unique_ptr< HcalDeterministicFit > hltOOTpuCorr_
Definition: SimpleHBHEPhase1Algo.h:105
HcalPulseContainmentManager::get
const HcalPulseContainmentCorrection * get(const HcalDetId &detId, int toAdd, float fixedphase_ns)
Definition: HcalPulseContainmentManager.cc:45
PresampleTask_cfi.nSamples
nSamples
Definition: PresampleTask_cfi.py:7
HcalTimeSlew::delay
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
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
HcalRecoParam
Definition: HcalRecoParam.h:16
SimpleHBHEPhase1Algo::SimpleHBHEPhase1Algo
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)
Definition: SimpleHBHEPhase1Algo.cc:20
alignCSCRings.corr
dictionary corr
Definition: alignCSCRings.py:124
PulseShapeFitOOTPileupCorrection::phase1Apply
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
Definition: PulseShapeFitOOTPileupCorrection.cc:300
HLTBitAnalyser_cfi.isData
isData
Definition: HLTBitAnalyser_cfi.py:29
HcalPulseShapes::getShape
const Shape & getShape(int shapeType) const
Definition: HcalPulseShapes.cc:448
Run.h
edm::ESHandle
Definition: DTSurvey.h:22
HcalCorrectionFunctions.h
HcalTimeSlewRecord
Definition: HcalTimeSlewRecord.h:4
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
HcalCalibrations
Definition: HcalCalibrations.h:9
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
SimpleHBHEPhase1Algo::phaseNS_
float phaseNS_
Definition: SimpleHBHEPhase1Algo.h:95
HBHERecHit::setChiSquared
constexpr void setChiSquared(const float chi2)
Definition: HBHERecHit.h:41
HBHERecHit::setRawEnergy
constexpr void setRawEnergy(const float en)
Definition: HBHERecHit.h:44
SimpleHBHEPhase1Algo::hbminusCorrectionFactor
float hbminusCorrectionFactor(const HcalDetId &cell, float energy, bool isRealData) const
Definition: SimpleHBHEPhase1Algo.cc:147
SimpleHBHEPhase1Algo::mahiOOTpuCorr_
std::unique_ptr< MahiFit > mahiOOTpuCorr_
Definition: SimpleHBHEPhase1Algo.h:108
HLT_2018_cff.firstSampleShift
firstSampleShift
Definition: HLT_2018_cff.py:7106
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
HcalDetId::ieta
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
castor_dqm_sourceclient-live_cfg.correctForPhaseContainment
correctForPhaseContainment
Definition: castor_dqm_sourceclient-live_cfg.py:59
SimpleHBHEPhase1Algo::m0Time
float m0Time(const HBHEChannelInfo &info, double reconstructedCharge, int nSamplesToExamine) const
Definition: SimpleHBHEPhase1Algo.cc:181
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
HcalDetId::subdet
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
HcalDetId
Definition: HcalDetId.h:12
SimpleHBHEPhase1Algo::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: SimpleHBHEPhase1Algo.cc:43
createfilelist.int
int
Definition: createfilelist.py:10
SimpleHBHEPhase1Algo::timeShift_
float timeShift_
Definition: SimpleHBHEPhase1Algo.h:96
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
SimpleHBHEPhase1Algo.h
SimpleHBHEPhase1Algo::hcalTimeSlew_delay_
const HcalTimeSlew * hcalTimeSlew_delay_
Definition: SimpleHBHEPhase1Algo.h:72
SimpleHBHEPhase1Algo::corrFPC_
bool corrFPC_
Definition: SimpleHBHEPhase1Algo.h:98
PulseContainmentFractionalError
constexpr float PulseContainmentFractionalError
Definition: SimpleHBHEPhase1Algo.cc:18
alignCSCRings.r
r
Definition: alignCSCRings.py:93
hbminus_special_ecorr
float hbminus_special_ecorr(int ieta, int iphi, double energy, int runnum)
Special energy correction for some HB- cells.
Definition: HcalSimpleRecAlgo.cc:461
HBHEChannelInfo::MAXSAMPLES
static const unsigned MAXSAMPLES
Definition: HBHEChannelInfo.h:19
SimpleHBHEPhase1Algo::samplesToAdd_
int samplesToAdd_
Definition: SimpleHBHEPhase1Algo.h:94
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
SimpleHBHEPhase1Algo::runnum_
int runnum_
Definition: SimpleHBHEPhase1Algo.h:97
EventSetup.h
SimpleHBHEPhase1Algo::applyLegacyHBMCorrection_
bool applyLegacyHBMCorrection_
Definition: SimpleHBHEPhase1Algo.h:99
SimpleHBHEPhase1Algo::reconstruct
HBHERecHit reconstruct(const HBHEChannelInfo &info, const HcalRecoParam *params, const HcalCalibrations &calibs, bool isRealData) override
Definition: SimpleHBHEPhase1Algo.cc:54
CaloRecHit::setFlagField
constexpr void setFlagField(uint32_t value, int base, int width=1)
Definition: CaloRecHit.h:36
phase2TrackerDigitizer_cfi.delay
delay
Definition: phase2TrackerDigitizer_cfi.py:67
HcalTimeSlewRecord.h
SimpleHBHEPhase1Algo::m0Energy
float m0Energy(const HBHEChannelInfo &info, double reconstructedCharge, bool applyContainmentCorrection, double phaseNS, int nSamplesToAdd)
Definition: SimpleHBHEPhase1Algo.cc:160
ntuplemaker.time
time
Definition: ntuplemaker.py:310
SimpleHBHEPhase1Algo::pulseCorr_
HcalPulseContainmentManager pulseCorr_
Definition: SimpleHBHEPhase1Algo.h:91
HcalPulseContainmentManager::beginRun
void beginRun(edm::EventSetup const &es)
Definition: HcalPulseContainmentManager.cc:12
HLT_2018_cff.timeShift
timeShift
Definition: HLT_2018_cff.py:7169
HBHEChannelInfo
Definition: HBHEChannelInfo.h:15
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37