ATLAS Offline Software
BaseFakeBkgTool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef BASE_FAKE_BKG_TOOL_H
6 #define BASE_FAKE_BKG_TOOL_H
7 
10 #include "AsgTools/AsgTool.h"
11 
12 #include <string>
13 #include <map>
14 #include <unordered_map>
15 #include <set>
16 #include <vector>
17 #include <memory>
18 #include <functional>
19 
20 namespace FakeBkgTools
21 {
23  struct ParticleData;
24  class FinalState;
25  class Database;
26  struct Efficiency;
27  enum class Client;
28 }
29 
30 namespace CP
31 {
32 
33  class ISelectionReadAccessor;
34 
35 /*
36  * Base class of concrete tools implementations, providing common helper methods
37  */
39 #ifndef FAKEBKGTOOLS_ATLAS_ENVIRONMENT
40  , public FakeBkgTools::PropertyManager<BaseFakeBkgTool>
41 #endif
42 {
43  public:
44 
45  BaseFakeBkgTool(const std::string& toolname);
46  virtual ~BaseFakeBkgTool();
47 
48  virtual StatusCode initialize() override;
49 
50  virtual StatusCode addEvent(const xAOD::IParticleContainer& particles, float extraWeight = 1.f) override final;
51 
52  virtual StatusCode register1DHistogram(TH1* h1, const float *val) override;
53  virtual StatusCode register2DHistogram(TH2* h2, const float *xval, const float *yval) override;
54  virtual StatusCode register3DHistogram(TH3* h3, const float *xval, const float *yval, const float *zval) override;
55 
56  virtual bool isAffectedBySystematic(const CP::SystematicVariation& systematic) const override;
57  virtual CP::SystematicSet affectingSystematics() const override;
58  virtual CP::SystematicSet recommendedSystematics() const override;
59  virtual StatusCode applySystematicVariation(const CP::SystematicSet& systConfig) override;
60 
62  virtual CP::SystematicSet affectingSystematicsFor(const std::string& nuisanceParameter) const override;
63  virtual std::string getUncertaintyDescription(const CP::SystematicVariation& systematic) const override final;
64  virtual void printUncertaintyDescription(const CP::SystematicVariation& systematic) const override final;
65  virtual bool isSystematicUncertainty(const CP::SystematicVariation& systematic) const override final;
66  virtual bool isStatisticalUncertainty(const CP::SystematicVariation& systematic) const override final;
67  virtual bool affectsElectrons(const CP::SystematicVariation& systematic) const override final;
68  virtual bool affectsMuons(const CP::SystematicVariation& systematic) const override final;
69  virtual bool affectsTaus(const CP::SystematicVariation& systematic) const override final;
70  virtual bool affectsRealEfficiencies(const CP::SystematicVariation& systematic) const override final;
71  virtual bool affectsFakeEfficiencies(const CP::SystematicVariation& systematic) const override final;
72  virtual bool affectsFakeFactors(const CP::SystematicVariation& systematic) const override final;
73 
74  virtual const IFakeBkgSystDescriptor& getSystDescriptor() const override {return *this; }
75 
76  protected:
77 
78  bool m_initialized = false;
79  bool m_needEventInfo = true;
80  bool m_convertWhenMissing = false;
81 
83  virtual FakeBkgTools::Client clientForDB() = 0;
84 
85  std::vector<FakeBkgTools::ParticleData> m_particles;
86 
87  virtual StatusCode addEventCustom() = 0;
88  // overridden by derived classes (compute the event weights and update sum of weights/histograms for AM+FF, increment event counters+average efficiencies for LM)
89 
90  #ifndef __CLING__
91  std::unique_ptr<FakeBkgTools::Database> m_database;
92  #else
93  std::unique_ptr<int> m_database;
94  #endif
96 
97  std::hash<std::string> m_hasher;
98  #ifndef __CLING__
99  std::set<FakeBkgTools::FinalState> m_cachedFinalStates;
100  #else
101  std::set<int> m_cachedFinalStates;
102  #endif
103  FakeBkgTools::FinalState getCachedFinalState(uint8_t nparticles, const std::string& strPID, const std::string& strProc, bool& success);
104 
105  std::string getListOfEfficienciesAffectedBy(uint16_t uid) const;
106 
107  // maps to store relationships between histograms and variables
108  std::map<TH1*, const float*> m_values_1dhisto_map;
109  std::map<TH2*, std::pair<const float*, const float*> > m_values_2dhisto_map;
110  std::map<TH3*, std::tuple<const float*, const float*, const float*> > m_values_3dhisto_map;
111 
112  StatusCode CheckHistogramCompatibility(const TH1* lhs, const TH1* rhs);
113 
115  std::string m_selection = defaultSelection();
116 
118  std::string m_process = defaultProcess();
119 
122  std::string m_energyUnit;
123 
124  bool m_useDB = true;
125 
127  std::vector<std::string> m_inputFiles;
128 
131 
134 
136  std::string m_progressFileName;
137 
140 
144  {
146  float sigma;
147  UncertaintyList(uint16_t first_UID, float first_sigma) : UID(first_UID), sigma(first_sigma) {}
148  void extraVariation(uint16_t extra_UID, float extra_sigma)
149  {
150  if(m_next) m_next->extraVariation(extra_UID, extra_sigma);
151  else m_next.reset(new UncertaintyList(extra_UID, extra_sigma));
152  }
153  const UncertaintyList* next() const { return m_next.get(); }
154  protected:
155  std::unique_ptr<UncertaintyList> m_next;
156  };
157 
162 
166  std::unordered_map<CP::SystematicSet, UncertaintyList> m_systSetDict;
167 
171 
174 
175  private:
176 
178  bool importEfficiencies(bool resetDB = false);
179 
180  std::pair<uint16_t, float> identifyCpSystematicVariation(const CP::SystematicVariation& systematic) const;
181 
183 };
184 
185 }
186 
187 #endif
CP::BaseFakeBkgTool::CheckHistogramCompatibility
StatusCode CheckHistogramCompatibility(const TH1 *lhs, const TH1 *rhs)
Definition: BaseFakeBkgTool.cxx:330
CP::BaseFakeBkgTool::register1DHistogram
virtual StatusCode register1DHistogram(TH1 *h1, const float *val) override
associates a 1D histogram to the tool, to obtain a binned estimate of the fake lepton background the ...
Definition: BaseFakeBkgTool.cxx:240
CP::BaseFakeBkgTool::getUncertaintyDescription
virtual std::string getUncertaintyDescription(const CP::SystematicVariation &systematic) const override final
returns a human-readable description of the source of systematic uncertainty specified as argument
Definition: BaseFakeBkgTool.cxx:490
CP::BaseFakeBkgTool::getCachedFinalState
FakeBkgTools::FinalState getCachedFinalState(uint8_t nparticles, const std::string &strPID, const std::string &strProc, bool &success)
Definition: BaseFakeBkgTool.cxx:219
CP::BaseFakeBkgTool::UncertaintyList::UncertaintyList
UncertaintyList(uint16_t first_UID, float first_sigma)
Definition: BaseFakeBkgTool.h:147
CP::BaseFakeBkgTool
Definition: BaseFakeBkgTool.h:42
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
asg::AsgTool
Base class for the dual-use tool implementation classes.
Definition: AsgTool.h:47
CP::IFakeBkgSystDescriptor
Auxiliary interface equiping the tools derived from IFakeBkgTool with helper methods to identify what...
Definition: IFakeBkgSystDescriptor.h:18
CP::BaseFakeBkgTool::m_inputFiles
std::vector< std::string > m_inputFiles
property InputFiles
Definition: BaseFakeBkgTool.h:127
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:575
CP::BaseFakeBkgTool::m_useDB
bool m_useDB
Definition: BaseFakeBkgTool.h:124
FakeBkgTools::Efficiency
a structure to hold an efficiency together with a variable number of uncertainties
Definition: FakeBkgInternals.h:40
CP::BaseFakeBkgTool::identifyCpSystematicVariation
std::pair< uint16_t, float > identifyCpSystematicVariation(const CP::SystematicVariation &systematic) const
Definition: BaseFakeBkgTool.cxx:388
IFakeBkgSystDescriptor.h
CP::BaseFakeBkgTool::recommendedSystematics
virtual CP::SystematicSet recommendedSystematics() const override
the list of all systematics this tool recommends to use
Definition: BaseFakeBkgTool.cxx:431
CP::BaseFakeBkgTool::applySystematicVariation
virtual StatusCode applySystematicVariation(const CP::SystematicSet &systConfig) override
effects: configure this tool for the given list of systematic variations.
Definition: BaseFakeBkgTool.cxx:436
CP::BaseFakeBkgTool::m_lockedSystematicVariations
bool m_lockedSystematicVariations
when m_unlimitedSystematicVariations=false, keeps track of prior calls to applySystematicVariation() ...
Definition: BaseFakeBkgTool.h:173
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
CP::BaseFakeBkgTool::isAffectedBySystematic
virtual bool isAffectedBySystematic(const CP::SystematicVariation &systematic) const override
Declare the interface that this class provides.
Definition: BaseFakeBkgTool.cxx:404
FakeBkgTools::Client
Client
Definition: FakeBkgInternals.h:141
CP::BaseFakeBkgTool::UncertaintyList::m_next
std::unique_ptr< UncertaintyList > m_next
Definition: BaseFakeBkgTool.h:155
CP::BaseFakeBkgTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: BaseFakeBkgTool.cxx:63
CP::BaseFakeBkgTool::UncertaintyList::UID
uint16_t UID
Definition: BaseFakeBkgTool.h:145
FakeBkgTools::ParticleData
Definition: FakeBkgInternals.h:85
CP::BaseFakeBkgTool::m_database
std::unique_ptr< FakeBkgTools::Database > m_database
Definition: BaseFakeBkgTool.h:91
CP::BaseFakeBkgTool::isSystematicUncertainty
virtual bool isSystematicUncertainty(const CP::SystematicVariation &systematic) const override final
checks whether the specified source of uncertainty originates from a systematic uncertainty in the ef...
Definition: BaseFakeBkgTool.cxx:533
CP::BaseFakeBkgTool::importEfficiencies
bool importEfficiencies(bool resetDB=false)
load the config file(s) storing efficiencies
Definition: BaseFakeBkgTool.cxx:109
CP::SystematicVariation
Definition: SystematicVariation.h:47
read_hist_ntuple.h1
h1
Definition: read_hist_ntuple.py:21
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
CP::BaseFakeBkgTool::affectsElectrons
virtual bool affectsElectrons(const CP::SystematicVariation &systematic) const override final
checks whether the specified source of uncertainty affects electrons
Definition: BaseFakeBkgTool.cxx:547
CP::IFakeBkgTool
Top-level interface for the tools providing an estimate of the fake lepton background All the tools,...
Definition: IFakeBkgTool.h:26
CP::BaseFakeBkgTool::BaseFakeBkgTool
BaseFakeBkgTool(const std::string &toolname)
Definition: BaseFakeBkgTool.cxx:29
CP::BaseFakeBkgTool::affectsFakeEfficiencies
virtual bool affectsFakeEfficiencies(const CP::SystematicVariation &systematic) const override final
checks whether the specified source of uncertainty affects fake efficiencies
Definition: BaseFakeBkgTool.cxx:575
CP::BaseFakeBkgTool::m_tightDecoNameAndType
std::string m_tightDecoNameAndType
property TightDecoration
Definition: BaseFakeBkgTool.h:130
CP::BaseFakeBkgTool::register3DHistogram
virtual StatusCode register3DHistogram(TH3 *h3, const float *xval, const float *yval, const float *zval) override
associates a 3D histogram to the tool, to obtain a binned estimate of the fake lepton background
Definition: BaseFakeBkgTool.cxx:300
CP::BaseFakeBkgTool::m_cachedFinalStates
std::set< FakeBkgTools::FinalState > m_cachedFinalStates
Definition: BaseFakeBkgTool.h:99
CP::BaseFakeBkgTool::UncertaintyList::extraVariation
void extraVariation(uint16_t extra_UID, float extra_sigma)
Definition: BaseFakeBkgTool.h:148
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
CP::BaseFakeBkgTool::m_initialized
bool m_initialized
Definition: BaseFakeBkgTool.h:78
CP::BaseFakeBkgTool::affectsMuons
virtual bool affectsMuons(const CP::SystematicVariation &systematic) const override final
checks whether the specified source of uncertainty affects muons
Definition: BaseFakeBkgTool.cxx:554
FakeBkgTools
Definition: BaseFakeBkgTool.h:21
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CP::BaseFakeBkgTool::m_convertWhenMissing
bool m_convertWhenMissing
Definition: BaseFakeBkgTool.h:80
CP::BaseFakeBkgTool::m_progressFileDirectory
std::string m_progressFileDirectory
property ProgressFileDirectory
Definition: BaseFakeBkgTool.h:139
TH3
Definition: rootspy.cxx:440
CP::BaseFakeBkgTool::m_systSetDict
std::unordered_map< CP::SystematicSet, UncertaintyList > m_systSetDict
List of uncertainties in internal format, associated with a particular SystematicSet the m_selectedUn...
Definition: BaseFakeBkgTool.h:166
plotting.yearwise_efficiency.yval
float yval
Definition: yearwise_efficiency.py:43
CP::BaseFakeBkgTool::m_hasher
std::hash< std::string > m_hasher
comes from Event passed to addEvent()
Definition: BaseFakeBkgTool.h:97
CP::BaseFakeBkgTool::m_process
std::string m_process
'process' settings used to compute the total yield / fill histograms
Definition: BaseFakeBkgTool.h:118
CP::BaseFakeBkgTool::register2DHistogram
virtual StatusCode register2DHistogram(TH2 *h2, const float *xval, const float *yval) override
associates a 2D histogram to the tool, to obtain a binned estimate of the fake lepton background the ...
Definition: BaseFakeBkgTool.cxx:270
CP::BaseFakeBkgTool::UncertaintyList::sigma
float sigma
Definition: BaseFakeBkgTool.h:146
CP::BaseFakeBkgTool::m_unlimitedSystematicVariations
bool m_unlimitedSystematicVariations
used to prevent multiple calls to applySystematicVariation() when unsupported set to true in a partic...
Definition: BaseFakeBkgTool.h:170
plotting.yearwise_efficiency.xval
float xval
Definition: yearwise_efficiency.py:42
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
TH2
Definition: rootspy.cxx:373
CP::BaseFakeBkgTool::m_values_1dhisto_map
std::map< TH1 *, const float * > m_values_1dhisto_map
Definition: BaseFakeBkgTool.h:108
CP::BaseFakeBkgTool::getListOfEfficienciesAffectedBy
std::string getListOfEfficienciesAffectedBy(uint16_t uid) const
Definition: BaseFakeBkgTool.cxx:356
CP::BaseFakeBkgTool::isStatisticalUncertainty
virtual bool isStatisticalUncertainty(const CP::SystematicVariation &systematic) const override final
checks whether the specified source of uncertainty originates from a statistical uncertainty in the e...
Definition: BaseFakeBkgTool.cxx:540
CP::BaseFakeBkgTool::m_needEventInfo
bool m_needEventInfo
Definition: BaseFakeBkgTool.h:79
python.hypoToolDisplay.toolname
def toolname(tool)
Definition: hypoToolDisplay.py:13
CP::BaseFakeBkgTool::m_tightAccessor
CP::ISelectionReadAccessor * m_tightAccessor
this can't be a unique_ptr as this can cause issues with the dictionary in some particular circumstan...
Definition: BaseFakeBkgTool.h:133
FakeBkgTools::Database
Definition: Database.h:29
CP::BaseFakeBkgTool::~BaseFakeBkgTool
virtual ~BaseFakeBkgTool()
Definition: BaseFakeBkgTool.cxx:53
CP::BaseFakeBkgTool::m_externalWeight
float m_externalWeight
Definition: BaseFakeBkgTool.h:95
CP::BaseFakeBkgTool::m_particles
std::vector< FakeBkgTools::ParticleData > m_particles
Definition: BaseFakeBkgTool.h:85
CP::BaseFakeBkgTool::UncertaintyList
List of systematic variations (UID + sigma) to be considered This is implemented as a basic linked li...
Definition: BaseFakeBkgTool.h:144
CP::BaseFakeBkgTool::m_selectedUncertainties
UncertaintyList * m_selectedUncertainties
Pointer to a value of the 'm_systSetDict' map it must be invalidated each time the map is updated in ...
Definition: BaseFakeBkgTool.h:161
CP::BaseFakeBkgTool::addEventCustom
virtual StatusCode addEventCustom()=0
CP::IFakeBkgTool::defaultSelection
static constexpr const char * defaultSelection()
default value taken by the 'selection' argument of several methods or properties It indicates how the...
Definition: IFakeBkgTool.h:32
FakeBkgTools::FinalState
Definition: FakeBkgInternals.h:98
CP::BaseFakeBkgTool::affectsTaus
virtual bool affectsTaus(const CP::SystematicVariation &systematic) const override final
checks whether the specified source of uncertainty affects taus
Definition: BaseFakeBkgTool.cxx:561
CP::BaseFakeBkgTool::clientForDB
virtual FakeBkgTools::Client clientForDB()=0
This indicates which type of efficiencies/fake factor need to be filled.
Definition: BaseFakeBkgTool.cxx:58
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
TH1
Definition: rootspy.cxx:268
CP::BaseFakeBkgTool::UncertaintyList::next
const UncertaintyList * next() const
Definition: BaseFakeBkgTool.h:153
CP::BaseFakeBkgTool::printUncertaintyDescription
virtual void printUncertaintyDescription(const CP::SystematicVariation &systematic) const override final
prints a human-readable description of the source of systematic uncertainty specified as argument
Definition: BaseFakeBkgTool.cxx:484
CP::BaseFakeBkgTool::affectingSystematics
virtual CP::SystematicSet affectingSystematics() const override
the list of all systematics this tool can be affected by
Definition: BaseFakeBkgTool.cxx:409
CP::ISelectionReadAccessor
a specialized accessor to read a selection decoration from/to an xAOD object
Definition: ISelectionReadAccessor.h:39
CP::BaseFakeBkgTool::affectsRealEfficiencies
virtual bool affectsRealEfficiencies(const CP::SystematicVariation &systematic) const override final
checks whether the specified source of uncertainty affects real efficiencies
Definition: BaseFakeBkgTool.cxx:568
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
CP::BaseFakeBkgTool::affectsFakeFactors
virtual bool affectsFakeFactors(const CP::SystematicVariation &systematic) const override final
checks whether the specified source of uncertainty affects fake factors
Definition: BaseFakeBkgTool.cxx:582
CP::BaseFakeBkgTool::m_selection
std::string m_selection
'selection' settings used to compute the total yield / fill histograms
Definition: BaseFakeBkgTool.h:115
CP::BaseFakeBkgTool::m_values_2dhisto_map
std::map< TH2 *, std::pair< const float *, const float * > > m_values_2dhisto_map
Definition: BaseFakeBkgTool.h:109
CP::BaseFakeBkgTool::addEvent
virtual StatusCode addEvent(const xAOD::IParticleContainer &particles, float extraWeight=1.f) override final
supply list of leptons / global variables, internal counters incremented Does not return anything; ev...
Definition: BaseFakeBkgTool.cxx:155
AsgTool.h
CP::IFakeBkgTool::defaultProcess
static constexpr const char * defaultProcess()
default value taken by the 'process' argument of several methods or properties It indicates what shou...
Definition: IFakeBkgTool.h:37
CP::BaseFakeBkgTool::m_energyUnit
std::string m_energyUnit
property EnergyUnit user can choose between MeV or GeV to indicate the unit of the pT parametrization...
Definition: BaseFakeBkgTool.h:122
CP::BaseFakeBkgTool::m_values_3dhisto_map
std::map< TH3 *, std::tuple< const float *, const float *, const float * > > m_values_3dhisto_map
Definition: BaseFakeBkgTool.h:110
CP::BaseFakeBkgTool::m_progressFileName
std::string m_progressFileName
property ProgressFileName
Definition: BaseFakeBkgTool.h:136
IFakeBkgTool.h
CP::BaseFakeBkgTool::getSystDescriptor
virtual const IFakeBkgSystDescriptor & getSystDescriptor() const override
retrieves an interface to various helper methods to identify what the different SystematicVariations ...
Definition: BaseFakeBkgTool.h:74
CP::BaseFakeBkgTool::affectingSystematicsFor
virtual CP::SystematicSet affectingSystematicsFor(const std::string &nuisanceParameter) const override
These functions are slow, don't use them in the tools implementations.
Definition: BaseFakeBkgTool.cxx:589