CMS 3D CMS Logo

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