ATLAS Offline Software
Loading...
Searching...
No Matches
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"
13
14#include <string>
15#include <map>
16#include <unordered_map>
17#include <set>
18#include <vector>
19#include <memory>
20#include <functional>
21
22namespace FakeBkgTools
23{
25 struct ParticleData;
26 class FinalState;
27 class Database;
28 struct Efficiency;
29 enum class Client;
30}
31
32namespace CP
33{
34
35 class ISelectionReadAccessor;
36
37/*
38 * Base class of concrete tools implementations, providing common helper methods
39 */
41{
42 public:
43
44 BaseFakeBkgTool(const std::string& toolname);
45 virtual ~BaseFakeBkgTool();
46
47 virtual StatusCode initialize() override;
48
49 virtual StatusCode addEvent(const xAOD::IParticleContainer& particles, float extraWeight = 1.f) override final;
50 virtual StatusCode addEvent(const ConstDataVector<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;
81
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
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
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
176
178
179 private:
180 template<class C> StatusCode addEventImpl(const C& iparticles, float mcWeight);
181
183 bool importEfficiencies(bool resetDB = false);
184
185 std::pair<uint16_t, float> identifyCpSystematicVariation(const CP::SystematicVariation& systematic) const;
186
188};
189
190}
191
192#endif
Helper class to provide constant type-safe access to aux data.
Define macros for attributes used to control the static checker.
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
virtual bool affectsElectrons(const CP::SystematicVariation &systematic) const override final
checks whether the specified source of uncertainty affects electrons
virtual CP::SystematicSet affectingSystematics() const override
the list of all systematics this tool can be affected by
virtual bool affectsMuons(const CP::SystematicVariation &systematic) const override final
checks whether the specified source of uncertainty affects muons
virtual bool affectsRealEfficiencies(const CP::SystematicVariation &systematic) const override final
checks whether the specified source of uncertainty affects real efficiencies
virtual CP::SystematicSet recommendedSystematics() const override
the list of all systematics this tool recommends to use
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 ...
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
virtual bool isAffectedBySystematic(const CP::SystematicVariation &systematic) const override
Declare the interface that this class provides.
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...
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...
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 the ...
BaseFakeBkgTool(const std::string &toolname)
virtual CP::SystematicSet affectingSystematicsFor(const std::string &nuisanceParameter) const override
These functions are slow, don't use them in the tools implementations.
virtual bool affectsTaus(const CP::SystematicVariation &systematic) const override final
checks whether the specified source of uncertainty affects taus
virtual bool affectsFakeEfficiencies(const CP::SystematicVariation &systematic) const override final
checks whether the specified source of uncertainty affects fake efficiencies
virtual StatusCode applySystematicVariation(const CP::SystematicSet &systConfig) override
effects: configure this tool for the given list of systematic variations.
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 ...
virtual bool affectsFakeFactors(const CP::SystematicVariation &systematic) const override final
checks whether the specified source of uncertainty affects fake factors
virtual void printUncertaintyDescription(const CP::SystematicVariation &systematic) const override final
prints a human-readable description of the source of systematic uncertainty specified as argument
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...
virtual StatusCode addEventCustom()=0
std::vector< FakeBkgTools::ParticleData > m_particles
StatusCode CheckHistogramCompatibility(const TH1 *lhs, const TH1 *rhs)
UncertaintyList * m_selectedUncertainties
Pointer to a value of the 'm_systSetDict' map it must be invalidated each time the map is updated in ...
bool m_unlimitedSystematicVariations
used to prevent multiple calls to applySystematicVariation() when unsupported set to true in a partic...
std::map< TH2 *, std::pair< const float *, const float * > > m_values_2dhisto_map
std::string m_progressFileName
property ProgressFileName
StatusCode addEventImpl(const C &iparticles, float mcWeight)
only used when m_useDB is false
CP::ISelectionReadAccessor * m_tightAccessor
this can't be a unique_ptr as this can cause issues with the dictionary in some particular circumstan...
std::string getListOfEfficienciesAffectedBy(uint16_t uid) const
std::string m_progressFileDirectory
property ProgressFileDirectory
SG::ConstAccessor< float > m_accRealEff
std::map< TH3 *, std::tuple< const float *, const float *, const float * > > m_values_3dhisto_map
std::set< FakeBkgTools::FinalState > m_cachedFinalStates
std::string m_selection
'selection' settings used to compute the total yield / fill histograms
std::unique_ptr< FakeBkgTools::Database > m_database
bool importEfficiencies(bool resetDB=false)
load the config file(s) storing efficiencies
std::unordered_map< CP::SystematicSet, UncertaintyList > m_systSetDict
List of uncertainties in internal format, associated with a particular SystematicSet the m_selectedUn...
std::pair< uint16_t, float > identifyCpSystematicVariation(const CP::SystematicVariation &systematic) const
std::vector< std::string > m_inputFiles
property InputFiles
virtual FakeBkgTools::Client clientForDB()=0
This indicates which type of efficiencies/fake factor need to be filled.
std::hash< std::string > m_hasher
comes from Event passed to addEvent()
std::string m_tightDecoNameAndType
property TightDecoration
bool m_lockedSystematicVariations
when m_unlimitedSystematicVariations=false, keeps track of prior calls to applySystematicVariation() ...
std::string m_process
'process' settings used to compute the total yield / fill histograms
FakeBkgTools::FinalState getCachedFinalState(uint8_t nparticles, const std::string &strPID, const std::string &strProc, bool &success)
std::map< TH1 *, const float * > m_values_1dhisto_map
virtual const IFakeBkgSystDescriptor & getSystDescriptor() const override
retrieves an interface to various helper methods to identify what the different SystematicVariations ...
std::string m_energyUnit
property EnergyUnit user can choose between MeV or GeV to indicate the unit of the pT parametrization...
SG::ConstAccessor< float > m_accFakeEff
only used when m_useDB is false
Auxiliary interface equiping the tools derived from IFakeBkgTool with helper methods to identify what...
Top-level interface for the tools providing an estimate of the fake lepton background All the tools,...
static constexpr const char * defaultSelection()
default value taken by the 'selection' argument of several methods or properties It indicates how the...
static constexpr const char * defaultProcess()
default value taken by the 'process' argument of several methods or properties It indicates what shou...
a specialized accessor to read a selection decoration from/to an xAOD object
Class to wrap a set of SystematicVariations.
DataVector adapter that acts like it holds const pointers.
Helper class to provide constant type-safe access to aux data.
Base class for the dual-use tool implementation classes.
Definition AsgTool.h:47
struct color C
Select isolated Photons, Electrons and Muons.
setWord1 uint16_t
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.
void initialize()
UncertaintyList(uint16_t first_UID, float first_sigma)
List of systematic variations (UID + sigma) to be considered This is implemented as a basic linked li...
void extraVariation(uint16_t extra_UID, float extra_sigma)
std::unique_ptr< UncertaintyList > m_next
UncertaintyList(uint16_t first_UID, float first_sigma)
const UncertaintyList * next() const
a structure to hold an efficiency together with a variable number of uncertainties