ATLAS Offline Software
Loading...
Searching...
No Matches
PileupUncertaintyComponent.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#include "TFile.h"
9
10namespace jet
11{
12
14// //
15// Constructor/destructor/initialization //
16// //
18
34
36 const float refNPV,
37 const float refMu
38 )
39 : UncertaintyComponent(component,component.pileupType == PileupComp::PtTerm ? 2 : 1)
40 , m_pileupType(component.pileupType)
41 , m_refNPV(refNPV)
42 , m_refMu(refMu)
43 , m_refNPVHist(nullptr)
44 , m_refMuHist(nullptr)
45 , m_absEta(CompParametrization::isAbsEta(component.parametrization))
46 , m_secondUncName(component.uncNames.size()>1?component.uncNames.at(1):"")
47 , m_secondUncHist(nullptr)
50{
51 ATH_MSG_DEBUG("Created PileupUncertaintyComponent named" << m_uncHistName.Data());
52
53 // Ensure that the pileup type and ref values are sensible
55 ATH_MSG_FATAL("Pileup type is UNKNOWN: " << m_uncHistName.Data());
56 if (m_refNPV <= 0 || m_refMu <= 0)
57 ATH_MSG_FATAL(Form("Unexpected pileup reference values. (NPV,mu)=(%.1f,%.1f) for %s",m_refNPV,m_refMu,m_uncHistName.Data()));
58}
59
61 const UncertaintyHistogram* refNPV,
62 const UncertaintyHistogram* refMu
63 )
64 : UncertaintyComponent(component,component.pileupType == PileupComp::PtTerm ? 2 : 1)
65 , m_pileupType(component.pileupType)
66 , m_refNPV(-1)
67 , m_refMu(-1)
68 , m_refNPVHist(refNPV)
69 , m_refMuHist(refMu)
70 , m_absEta(CompParametrization::isAbsEta(component.parametrization))
71 , m_secondUncName(component.uncNames.size()>1?component.uncNames.at(1):"")
72 , m_secondUncHist(nullptr)
75{
76 ATH_MSG_DEBUG("Created PileupUncertaintyComponent named" << m_uncHistName.Data());
77
78 // Ensure that the pileup type and ref values are sensible
80 ATH_MSG_FATAL("Pileup type is UNKNOWN: " << m_uncHistName.Data());
81 if (!m_refNPV || !m_refMu)
82 ATH_MSG_FATAL(Form("Unexpected pileup reference values. (NPV,mu)=(%s,%s) for %s",m_refNPVHist?"OK":"NULL",m_refMuHist?"OK":"NULL",m_uncHistName.Data()));
83}
84
86 const UncertaintyHistogram* refNPV,
87 const float refMu
88 )
89 : UncertaintyComponent(component,component.pileupType == PileupComp::PtTerm ? 2 : 1)
90 , m_pileupType(component.pileupType)
91 , m_refNPV(-1)
92 , m_refMu(refMu)
93 , m_refNPVHist(refNPV)
94 , m_refMuHist(nullptr)
95 , m_absEta(CompParametrization::isAbsEta(component.parametrization))
96 , m_secondUncName(component.uncNames.size()>1?component.uncNames.at(1):"")
97 , m_secondUncHist(nullptr)
100{
101 ATH_MSG_DEBUG("Created PileupUncertaintyComponent named" << m_uncHistName.Data());
102
103 // Ensure that the pileup type and ref values are sensible
105 ATH_MSG_FATAL("Pileup type is UNKNOWN: " << m_uncHistName.Data());
106 if (!m_refNPV || m_refMu <= 0)
107 ATH_MSG_FATAL(Form("Unexpected pileup reference values. (NPV,mu)=(%s,%.1f) for %s",m_refNPVHist?"OK":"NULL",m_refMu,m_uncHistName.Data()));
108}
109
111 const float refNPV,
112 const UncertaintyHistogram* refMu
113 )
114 : UncertaintyComponent(component,component.pileupType == PileupComp::PtTerm ? 2 : 1)
115 , m_pileupType(component.pileupType)
116 , m_refNPV(refNPV)
117 , m_refMu(-1)
118 , m_refNPVHist(nullptr)
119 , m_refMuHist(refMu)
120 , m_absEta(CompParametrization::isAbsEta(component.parametrization))
121 , m_secondUncName(component.uncNames.size()>1?component.uncNames.at(1):"")
122 , m_secondUncHist(nullptr)
125{
126 ATH_MSG_DEBUG("Created PileupUncertaintyComponent named" << m_uncHistName.Data());
127
128 // Ensure that the pileup type and ref values are sensible
130 ATH_MSG_FATAL("Pileup type is UNKNOWN: " << m_uncHistName.Data());
131 if (m_refNPV <= 0 || !m_refMu)
132 ATH_MSG_FATAL(Form("Unusual pileup reference values. (NPV,mu)=(%.1f,%s) for %s",m_refNPV,m_refMuHist?"OK":"NULL",m_uncHistName.Data()));
133}
134
136 : UncertaintyComponent(toCopy)
137 , m_pileupType(toCopy.m_pileupType)
138 , m_refNPV(toCopy.m_refNPV)
139 , m_refMu(toCopy.m_refMu)
140 , m_refNPVHist(toCopy.m_refNPVHist)
141 , m_refMuHist(toCopy.m_refMuHist)
142 , m_absEta(toCopy.m_absEta)
144 , m_secondUncHist(nullptr)
145 , m_refType(toCopy.m_refType)
147{
148 ATH_MSG_DEBUG(Form("Creating copy of PileupUncertaintyComponent named %s",m_uncHistName.Data()));
149 if (toCopy.m_secondUncHist)
151}
152
157
162
163StatusCode PileupUncertaintyComponent::initialize(TFile* histFile)
164{
165 // Call the base class first
166 if (UncertaintyComponent::initialize(histFile).isFailure())
167 return StatusCode::FAILURE;
168
169
170 // Then ensure that the number of histograms matches what is expected for Pileup components
172 {
173 ATH_MSG_ERROR("Expected a single histogram for OffsetNPV: " << getName().Data());
174 return StatusCode::FAILURE;
175 }
177 {
178 ATH_MSG_ERROR("Expected a single histogram for OffsetMu: " << getName().Data());
179 return StatusCode::FAILURE;
180 }
182 {
183 ATH_MSG_ERROR("Expected two histograms for PtTerm: " << getName().Data());
184 return StatusCode::FAILURE;
185 }
186
187 // Get the reference types
195 {
196 if (m_uncHistName.Contains("NPV",TString::kIgnoreCase) && m_secondUncName.Contains("Mu",TString::kIgnoreCase))
197 {
200 }
201 else if (m_uncHistName.Contains("Mu",TString::kIgnoreCase) && m_secondUncName.Contains("NPV",TString::kIgnoreCase))
202 {
205 }
206 else
207 {
208 ATH_MSG_ERROR("Unexpected histogram naming scheme for PtTerm");
209 return StatusCode::FAILURE;
210 }
211 }
212
213 // Create the second histogram if applicable
215 {
217 if (!m_secondUncHist)
218 {
219 ATH_MSG_ERROR("Failed to create second uncertainty histogram for component: " << getName().Data());
220 return StatusCode::FAILURE;
221 }
222 if (m_secondUncHist->initialize(histFile).isFailure()) return StatusCode::FAILURE;
223 }
224
225 return StatusCode::SUCCESS;
226}
227
229// //
230// Validity and uncertainty retrieval //
231// //
233
235{
236 return !m_validHist ? true : getValidBool(m_validHist->getValue(jet.pt()*m_energyScale,m_absEta ? fabs(jet.eta()) : jet.eta()));
237}
238
240{
241 double unc = getPileupWeight(jet,eInfo,m_refType)*m_uncHist->getValue(jet.pt()*m_energyScale,m_absEta ? fabs(jet.eta()) : jet.eta());
242 if (m_secondUncHist) unc += getPileupWeight(jet,eInfo,m_secondRefType)*m_secondUncHist->getValue(jet.pt()*m_energyScale,m_absEta ? fabs(jet.eta()) : jet.eta());
243
244 return unc;
245}
246
248{
249 static const SG::AuxElement::Accessor<float> accNPV("NPV");
250
251 double weight;
252 const float mu = eInfo.averageInteractionsPerCrossing();
253 const float NPV = accNPV.isAvailable(eInfo) ? accNPV(eInfo) : -1;
254
255 if (NPV <= 0)
256 {
257 ATH_MSG_ERROR("Unexpected number of primary vertices, does EventInfo contain NPV? (NPV="<<NPV<<")");
258 return JESUNC_ERROR_CODE;
259 }
260
261 if (refType == PileupRef_NPV)
262 weight = NPV - (m_refNPVHist?m_refNPVHist->getValue(fabs(jet.eta())):m_refNPV);
263 else if (refType == PileupRef_MU)
264 weight = mu - (m_refMuHist?m_refMuHist->getValue(fabs(jet.eta())):m_refMu);
265 else if (refType == PileupRef_NONE)
266 weight = 1;
267 else
268 {
269 ATH_MSG_ERROR(Form("Unknown pileup referencetype for component %s",getName().Data()));
270 return JESUNC_ERROR_CODE;
271 }
272
273 return weight;
274}
275
276
277} // end jet namespace
278
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
@ Data
Definition BaseObject.h:11
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
virtual StatusCode initialize(TFile *histFile)
virtual double getUncertaintyImpl(const xAOD::Jet &jet, const xAOD::EventInfo &eInfo) const
PileupUncertaintyComponent(const ComponentHelper &component, const float refNPV, const float refMu)
const UncertaintyHistogram * m_refNPVHist
const UncertaintyHistogram * m_refMuHist
double getPileupWeight(const xAOD::Jet &jet, const xAOD::EventInfo &eInfo, const PileupRefType refType) const
virtual bool getValidityImpl(const xAOD::Jet &jet, const xAOD::EventInfo &eInfo) const
virtual PileupUncertaintyComponent * clone() const
const Interpolate::TypeEnum m_interpolate
UncertaintyComponent(const ComponentHelper &component, const size_t numHist=1)
virtual TString getName() const
virtual bool getValidBool(const double validity) const
UncertaintyHistogram * m_validHist
virtual StatusCode initialize(TFile *histFile)
UncertaintyHistogram * m_uncHist
float averageInteractionsPerCrossing() const
Average interactions per crossing for all BCIDs - for out-of-time pile-up.
Jet_v1 Jet
Definition of the current "jet version".
EventInfo_v1 EventInfo
Definition of the latest event info version.