ATLAS Offline Software
PerJetFlavourUncertaintyComponent.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
8 namespace jet
9 {
10 
12 // //
13 // Constructor/destructor/initialization //
14 // //
16 
19  , m_absEta(false)
20  , m_labels()
21  , m_flavourType(FlavourComp::UNKNOWN)
22  , m_constrainZresponse(false)
23  , m_constrainZresponseFunc("Zjet_qFrac_AntiKt4EMPFlow")
24  , m_ZjetQuarkFrac(nullptr)
25 {
27 }
28 
30  : UncertaintyComponent(component,1)
31  , m_absEta(CompParametrization::isAbsEta(component.parametrization))
32  , m_labels(component.truthLabels)
33  , m_flavourType(component.flavourType)
34  , m_constrainZresponse(component.constrainZresponse)
35  , m_constrainZresponseFunc(component.constrainZresponseFunc)
36 {
37  ATH_MSG_DEBUG("Created PerJetFlavourUncertaintyComponent named " << m_uncHistName.Data());
38 }
39 
41  : UncertaintyComponent(toCopy)
42  , m_absEta(toCopy.m_absEta)
43  , m_labels(toCopy.m_labels)
44  , m_flavourType(toCopy.m_flavourType)
45  , m_constrainZresponse(toCopy.m_constrainZresponse)
46  , m_constrainZresponseFunc(toCopy.m_constrainZresponseFunc)
47 {
48  ATH_MSG_DEBUG("Creating copy of PerJetFlavourUncertaintyComponent named " << m_uncHistName.Data());
49 }
50 
52 {
53  return new PerJetFlavourUncertaintyComponent(*this);
54 }
55 
57 {
58  // Call the base class first
59  if (UncertaintyComponent::initialize(histFile).isFailure())
60  return StatusCode::FAILURE;
61 
62  // Ensure that the labels are sane
63  if (m_labels.empty())
64  {
65  ATH_MSG_ERROR("Specified a PerJetFlavourUncertaintyComponent without the associated labels to use: " << getName().Data());
66  return StatusCode::FAILURE;
67  }
68  for (int aLabel : m_labels)
69  {
70  if (!isSupportedLabel(aLabel))
71  {
72  ATH_MSG_ERROR("Unsupported label ID of " << aLabel << " in " << getName().Data());
73  return StatusCode::FAILURE;
74  }
75  }
76 
77  // Load TF1 for Z-jet gluon fraction
79  {
80  // Find the histogram by name
81  TObject* tmp_tf1 = histFile->Get(m_constrainZresponseFunc);
82  if (!tmp_tf1)
83  {
84  ATH_MSG_ERROR(Form("Histogram file does not contain a histogram named %s",m_constrainZresponseFunc.Data()));
85  return StatusCode::FAILURE;
86  }
87  // Ensure the object is a TF1
88  m_ZjetQuarkFrac = dynamic_cast<const TF1*>(tmp_tf1);
89  if (!m_ZjetQuarkFrac)
90  {
91  ATH_MSG_ERROR(Form("Histogram file contains the expected key, but it's not a TF1* (%s)",m_constrainZresponseFunc.Data()));
92  return StatusCode::FAILURE;
93  }
94  }
95 
96  // Done checking the configuration
97  return StatusCode::SUCCESS;
98 }
99 
100 
102 // //
103 // Validity and uncertainty retrieval //
104 // //
106 
108 {
109  return !m_validHist ? true : getValidBool(m_validHist->getValue(jet.pt()*m_energyScale,m_absEta ? fabs(jet.eta()) : jet.eta()));
110 }
111 
113 {
114  return getFlavourResponseUncertainty(jet,eInfo);
115 }
116 
118 {
119  // sigma_x = l_x * dR_x(x response modelling uncertainty)
120  // sigma_x is the flavour response uncertainty for jet type x
121  // l_x is the jet flavour label, and is 0 or 1
122  // dR_x is the response modelling uncertainty for jets of type x
123  // dR_x is typically taken as the difference in x response between Pythia and Herwig
124 
125  // Check the jet label (is this uncertainty relevant?)
126  if (!checkTruthLabel(jet))
127  return 0;
128 
129  // This is a jet of the relevant type
130  // Now calculate and return the uncertainty
131  const double pT = jet.pt()*m_energyScale;
132  const double eta = m_absEta ? fabs(jet.eta()) : jet.eta();
133 
134  FlavourComp::TypeEnum ThisJetFlavourType = FlavourComp::UNKNOWN;
135  if(m_labels.at(0)==21 || m_labels.at(0)==0) ThisJetFlavourType = FlavourComp::PerJetResponse_Gluon;
136  else if(m_labels.at(0)==1 || m_labels.at(0)==2 || m_labels.at(0)==3) ThisJetFlavourType = FlavourComp::PerJetResponse_LQ;
137  else if(m_labels.at(0)==5) ThisJetFlavourType = FlavourComp::PerJetResponse_B;
138  else if(m_labels.at(0)==4 ) ThisJetFlavourType = FlavourComp::PerJetResponse_C;
139 
140  // bool DoesItPass = false;
141  if(m_flavourType == ThisJetFlavourType){
142  double unc = m_uncHist->getValue(pT,eta);
146  }
147  // Return the uncertainty
148  return unc;
149 
150  }else{ return 0;}
151 
152 }
153 
154 
155 
157 {
158  switch (abs(label))
159  {
160  case 1: // parton-label, up
161  case 2: // parton-label, down
162  case 3: // parton-label, strange
163  case 4: // parton-label, charm
164  case 5: // parton-label, bottom
165  case 21: // parton-label, gluon
166  case 0: // parton-label, PileUp/non-identified
167  return true;
168  default:
169  return false;
170  }
171 }
172 
174 {
175  static const SG::AuxElement::ConstAccessor<int> truthLabelAccessor ("PartonTruthLabelID");
176  if (!truthLabelAccessor.isAvailable(jet))
177  {
178  ATH_MSG_ERROR("Unable to find PartonTruthLabelID on the jet");
179  return JESUNC_ERROR_CODE;
180  }
181  const int truthHighestEparton = abs(truthLabelAccessor(jet));
182 
183  for (const int label : m_labels)
184  if (label == truthHighestEparton)
185  return true;
186  return false;
187 }
188 
189 } // end jet namespace
190 
jet::PerJetFlavourUncertaintyComponent::clone
virtual PerJetFlavourUncertaintyComponent * clone() const
Definition: PerJetFlavourUncertaintyComponent.cxx:51
CalculateHighPtTerm.pT
pT
Definition: ICHEP2016/CalculateHighPtTerm.py:57
jet::PerJetFlavourUncertaintyComponent::PerJetFlavourUncertaintyComponent
PerJetFlavourUncertaintyComponent(const ComponentHelper &component)
Definition: PerJetFlavourUncertaintyComponent.cxx:29
jet::FlavourComp::UNKNOWN
@ UNKNOWN
Definition: UncertaintyEnum.h:178
jet::UncertaintyComponent::m_energyScale
const float m_energyScale
Definition: UncertaintyComponent.h:55
jet::FlavourComp::PerJetResponse_C
@ PerJetResponse_C
Definition: UncertaintyEnum.h:186
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
Data
@ Data
Definition: BaseObject.h:11
jet::PerJetFlavourUncertaintyComponent::initialize
virtual StatusCode initialize(TFile *histFile)
Definition: PerJetFlavourUncertaintyComponent.cxx:56
jet::PerJetFlavourUncertaintyComponent::m_constrainZresponse
const bool m_constrainZresponse
Definition: PerJetFlavourUncertaintyComponent.h:41
jet::ComponentHelper
Definition: ConfigHelper.h:24
jet::PerJetFlavourUncertaintyComponent
Definition: PerJetFlavourUncertaintyComponent.h:15
jet::UncertaintyComponent::m_uncHistName
const TString m_uncHistName
Definition: UncertaintyComponent.h:51
jet::CompParametrization::isAbsEta
bool isAbsEta(const TypeEnum type)
Definition: UncertaintyEnum.cxx:143
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
jet::UncertaintyComponent::initialize
virtual StatusCode initialize(TFile *histFile)
Definition: UncertaintyComponent.cxx:96
jet::PerJetFlavourUncertaintyComponent::m_ZjetQuarkFrac
const TF1 * m_ZjetQuarkFrac
Definition: PerJetFlavourUncertaintyComponent.h:43
jet::PerJetFlavourUncertaintyComponent::getValidityImpl
virtual bool getValidityImpl(const xAOD::Jet &jet, const xAOD::EventInfo &eInfo) const
Definition: PerJetFlavourUncertaintyComponent.cxx:107
jet::FlavourComp::PerJetResponse_B
@ PerJetResponse_B
Definition: UncertaintyEnum.h:185
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
jet::PerJetFlavourUncertaintyComponent::m_flavourType
const FlavourComp::TypeEnum m_flavourType
Definition: PerJetFlavourUncertaintyComponent.h:40
Helpers.h
jet::UncertaintyComponent
Definition: UncertaintyComponent.h:25
jet::PerJetFlavourUncertaintyComponent::getFlavourResponseUncertainty
double getFlavourResponseUncertainty(const xAOD::Jet &jet, const xAOD::EventInfo &eInfo) const
Definition: PerJetFlavourUncertaintyComponent.cxx:117
JESUNC_ERROR_CODE
#define JESUNC_ERROR_CODE
Definition: Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h:23
jet::PerJetFlavourUncertaintyComponent::getUncertaintyImpl
virtual double getUncertaintyImpl(const xAOD::Jet &jet, const xAOD::EventInfo &eInfo) const
Definition: PerJetFlavourUncertaintyComponent.cxx:112
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
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::FlavourComp::PerJetResponse_Gluon
@ PerJetResponse_Gluon
Definition: UncertaintyEnum.h:183
jet::UncertaintyComponent::getName
virtual TString getName() const
Definition: UncertaintyComponent.h:35
PerJetFlavourUncertaintyComponent.h
jet::PerJetFlavourUncertaintyComponent::isSupportedLabel
bool isSupportedLabel(const int label) const
Definition: PerJetFlavourUncertaintyComponent.cxx:156
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
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::FlavourComp::PerJetResponse_LQ
@ PerJetResponse_LQ
Definition: UncertaintyEnum.h:184
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
jet::UncertaintyComponent::m_uncHist
UncertaintyHistogram * m_uncHist
Definition: UncertaintyComponent.h:60
jet::PerJetFlavourUncertaintyComponent::m_absEta
const bool m_absEta
Definition: PerJetFlavourUncertaintyComponent.h:38
jet::PerJetFlavourUncertaintyComponent::m_constrainZresponseFunc
const TString m_constrainZresponseFunc
Definition: PerJetFlavourUncertaintyComponent.h:42
jet::PerJetFlavourUncertaintyComponent::m_labels
const std::vector< int > m_labels
Definition: PerJetFlavourUncertaintyComponent.h:39
jet::FlavourComp::TypeEnum
TypeEnum
Definition: UncertaintyEnum.h:177
LArG4GenerateShowerLib.parametrization
parametrization
Definition: LArG4GenerateShowerLib.py:19
jet::PerJetFlavourUncertaintyComponent::checkTruthLabel
bool checkTruthLabel(const xAOD::Jet &jet) const
Definition: PerJetFlavourUncertaintyComponent.cxx:173