ATLAS Offline Software
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 
10 namespace jet
11 {
12 
14 // //
15 // Constructor/destructor/initialization //
16 // //
18 
21  , m_pileupType(PileupComp::UNKNOWN)
22  , m_refNPV(-1)
23  , m_refMu(-1)
24  , m_refNPVHist(nullptr)
25  , m_refMuHist(nullptr)
26  , m_absEta(false)
27  , m_secondUncName("")
28  , m_secondUncHist(nullptr)
29  , m_refType(PileupRef_UNKNOWN)
30  , m_secondRefType(PileupRef_UNKNOWN)
31 {
33 }
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)
48  , m_refType(PileupRef_UNKNOWN)
49  , m_secondRefType(PileupRef_UNKNOWN)
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)
73  , m_refType(PileupRef_UNKNOWN)
74  , m_secondRefType(PileupRef_UNKNOWN)
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)
98  , m_refType(PileupRef_UNKNOWN)
99  , m_secondRefType(PileupRef_UNKNOWN)
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)
123  , m_refType(PileupRef_UNKNOWN)
124  , m_secondRefType(PileupRef_UNKNOWN)
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)
143  , m_secondUncName(toCopy.m_secondUncName)
144  , m_secondUncHist(nullptr)
145  , m_refType(toCopy.m_refType)
146  , m_secondRefType(toCopy.m_secondRefType)
147 {
148  ATH_MSG_DEBUG(Form("Creating copy of PileupUncertaintyComponent named %s",m_uncHistName.Data()));
149  if (toCopy.m_secondUncHist)
151 }
152 
154 {
155  return new PileupUncertaintyComponent(*this);
156 }
157 
159 {
161 }
162 
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  }
181  else if (m_pileupType == PileupComp::PtTerm && m_secondUncName == "")
182  {
183  ATH_MSG_ERROR("Expected two histograms for PtTerm: " << getName().Data());
184  return StatusCode::FAILURE;
185  }
186 
187  // Get the reference types
194  else if (m_pileupType == PileupComp::PtTerm)
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());
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 
jet::PileupComp::RhoTopology
@ RhoTopology
Definition: UncertaintyEnum.h:168
jet::PileupComp::UNKNOWN
@ UNKNOWN
Definition: UncertaintyEnum.h:164
jet::PileupUncertaintyComponent::PileupRef_NONE
@ PileupRef_NONE
Definition: PileupUncertaintyComponent.h:53
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
jet::UncertaintyComponent::m_energyScale
const float m_energyScale
Definition: UncertaintyComponent.h:55
jet::UncertaintyComponent::m_interpolate
const Interpolate::TypeEnum m_interpolate
Definition: UncertaintyComponent.h:56
jet::PileupUncertaintyComponent::getValidityImpl
virtual bool getValidityImpl(const xAOD::Jet &jet, const xAOD::EventInfo &eInfo) const
Definition: PileupUncertaintyComponent.cxx:234
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
jet::PileupComp::PtTerm
@ PtTerm
Definition: UncertaintyEnum.h:167
jet::PileupUncertaintyComponent::PileupRef_MU
@ PileupRef_MU
Definition: PileupUncertaintyComponent.h:53
Data
@ Data
Definition: BaseObject.h:11
jet::PileupUncertaintyComponent::m_secondRefType
PileupRefType m_secondRefType
Definition: PileupUncertaintyComponent.h:66
jet::ComponentHelper
Definition: ConfigHelper.h:24
jet::PileupUncertaintyComponent::getUncertaintyImpl
virtual double getUncertaintyImpl(const xAOD::Jet &jet, const xAOD::EventInfo &eInfo) const
Definition: PileupUncertaintyComponent.cxx:239
jet::UncertaintyComponent::m_uncHistName
const TString m_uncHistName
Definition: UncertaintyComponent.h:51
jet::CompParametrization::isAbsEta
bool isAbsEta(const TypeEnum type)
Definition: UncertaintyEnum.cxx:143
jet::UncertaintyComponent::initialize
virtual StatusCode initialize(TFile *histFile)
Definition: UncertaintyComponent.cxx:96
jet::PileupUncertaintyComponent::PileupRefType
PileupRefType
Definition: PileupUncertaintyComponent.h:53
jet::PileupUncertaintyComponent::initialize
virtual StatusCode initialize(TFile *histFile)
Definition: PileupUncertaintyComponent.cxx:163
jet::UncertaintyComponent::getValidBool
virtual bool getValidBool(const double validity) const
Definition: UncertaintyComponent.cxx:301
jet::UncertaintyHistogram::getValue
double getValue(const double var1) const
Definition: UncertaintyHistogram.cxx:141
Helpers.h
jet::UncertaintyComponent
Definition: UncertaintyComponent.h:25
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
jet::PileupUncertaintyComponent
Definition: PileupUncertaintyComponent.h:14
jet::UncertaintyHistogram::initialize
virtual StatusCode initialize(TFile *histFile)
Definition: UncertaintyHistogram.cxx:85
JESUNC_ERROR_CODE
#define JESUNC_ERROR_CODE
Definition: Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h:23
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
jet::PileupUncertaintyComponent::m_absEta
const bool m_absEta
Definition: PileupUncertaintyComponent.h:61
PileupUncertaintyComponent.h
jet::PileupUncertaintyComponent::m_refType
PileupRefType m_refType
Definition: PileupUncertaintyComponent.h:65
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
jet::PileupUncertaintyComponent::clone
virtual PileupUncertaintyComponent * clone() const
Definition: PileupUncertaintyComponent.cxx:153
jet::PileupUncertaintyComponent::m_refNPVHist
const UncertaintyHistogram * m_refNPVHist
Definition: PileupUncertaintyComponent.h:59
JESUNC_SAFE_DELETE
#define JESUNC_SAFE_DELETE(T)
Definition: Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h:25
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
jet::UncertaintyComponent::m_validHist
UncertaintyHistogram * m_validHist
Definition: UncertaintyComponent.h:61
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
jet::UncertaintyComponent::getName
virtual TString getName() const
Definition: UncertaintyComponent.h:35
jet::PileupUncertaintyComponent::m_refNPV
const float m_refNPV
Definition: PileupUncertaintyComponent.h:57
jet::PileupComp::OffsetNPV
@ OffsetNPV
Definition: UncertaintyEnum.h:165
xAOD::EventInfo_v1::averageInteractionsPerCrossing
float averageInteractionsPerCrossing() const
Average interactions per crossing for all BCIDs - for out-of-time pile-up.
Definition: EventInfo_v1.cxx:397
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
jet::UncertaintyHistogram
Definition: UncertaintyHistogram.h:25
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
jet::PileupUncertaintyComponent::m_refMu
const float m_refMu
Definition: PileupUncertaintyComponent.h:58
JESUNC_NO_DEFAULT_CONSTRUCTOR
#define JESUNC_NO_DEFAULT_CONSTRUCTOR
Definition: Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h:24
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
jet::PileupComp::OffsetMu
@ OffsetMu
Definition: UncertaintyEnum.h:166
jet::PileupUncertaintyComponent::m_secondUncName
const TString m_secondUncName
Definition: PileupUncertaintyComponent.h:62
jet::PileupUncertaintyComponent::m_pileupType
const PileupComp::TypeEnum m_pileupType
Definition: PileupUncertaintyComponent.h:56
jet::PileupUncertaintyComponent::getPileupWeight
double getPileupWeight(const xAOD::Jet &jet, const xAOD::EventInfo &eInfo, const PileupRefType refType) const
Definition: PileupUncertaintyComponent.cxx:247
jet::PileupUncertaintyComponent::m_refMuHist
const UncertaintyHistogram * m_refMuHist
Definition: PileupUncertaintyComponent.h:60
SG::ConstAccessor< T, AuxAllocator_t< T > >::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
jet::PileupUncertaintyComponent::PileupUncertaintyComponent
PileupUncertaintyComponent(const ComponentHelper &component, const float refNPV, const float refMu)
Definition: PileupUncertaintyComponent.cxx:35
jet::UncertaintyComponent::m_uncHist
UncertaintyHistogram * m_uncHist
Definition: UncertaintyComponent.h:60
jet::PileupUncertaintyComponent::m_secondUncHist
UncertaintyHistogram * m_secondUncHist
Definition: PileupUncertaintyComponent.h:64
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
LArG4GenerateShowerLib.parametrization
parametrization
Definition: LArG4GenerateShowerLib.py:19
jet::PileupUncertaintyComponent::PileupRef_NPV
@ PileupRef_NPV
Definition: PileupUncertaintyComponent.h:53
jet::PileupUncertaintyComponent::~PileupUncertaintyComponent
virtual ~PileupUncertaintyComponent()
Definition: PileupUncertaintyComponent.cxx:158