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"
13 
14 #include <string>
15 #include <map>
16 #include <unordered_map>
17 #include <set>
18 #include <vector>
19 #include <memory>
20 #include <functional>
21 
22 namespace FakeBkgTools
23 {
25  struct ParticleData;
26  class FinalState;
27  class Database;
28  struct Efficiency;
29  enum class Client;
30 }
31 
32 namespace 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;
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 
133  CP::ISelectionReadAccessor* m_tightAccessor = nullptr;
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 
161  UncertaintyList* m_selectedUncertainties = nullptr;
162 
166  std::unordered_map<CP::SystematicSet, UncertaintyList> m_systSetDict;
167 
170  bool m_unlimitedSystematicVariations = true;
171 
173  bool m_lockedSystematicVariations = false;
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
CP::BaseFakeBkgTool::UncertaintyList::UncertaintyList
UncertaintyList(uint16_t first_UID, float first_sigma)
Definition: BaseFakeBkgTool.h:147
CP::BaseFakeBkgTool
Definition: BaseFakeBkgTool.h:41
asg::AsgTool
Base class for the dual-use tool implementation classes.
Definition: AsgTool.h:47
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
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:557
FakeBkgTools::Efficiency
a structure to hold an efficiency together with a variable number of uncertainties
Definition: FakeBkgInternals.h:40
ATLAS_NOT_THREAD_SAFE
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
Definition: checker_macros.h:212
IFakeBkgSystDescriptor.h
initialize
void initialize()
Definition: run_EoverP.cxx:894
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
FakeBkgTools::Client
Client
Definition: FakeBkgInternals.h:141
CP::BaseFakeBkgTool::UncertaintyList::m_next
std::unique_ptr< UncertaintyList > m_next
Definition: BaseFakeBkgTool.h:155
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
SG::ConstAccessor< float >
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::IFakeBkgTool
Top-level interface for the tools providing an estimate of the fake lepton background All the tools,...
Definition: IFakeBkgTool.h:27
CP::BaseFakeBkgTool::m_tightDecoNameAndType
std::string m_tightDecoNameAndType
property TightDecoration
Definition: BaseFakeBkgTool.h:130
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
plotting.yearwise_efficiency_vs_mu.xval
float xval
Definition: yearwise_efficiency_vs_mu.py:35
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
FakeBkgTools
Definition: BaseFakeBkgTool.h:23
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CP::BaseFakeBkgTool::m_accRealEff
SG::ConstAccessor< float > m_accRealEff
Definition: BaseFakeBkgTool.h:175
CP::BaseFakeBkgTool::m_progressFileDirectory
std::string m_progressFileDirectory
property ProgressFileDirectory
Definition: BaseFakeBkgTool.h:139
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
CP::BaseFakeBkgTool::m_hasher
std::hash< std::string > m_hasher
comes from Event passed to addEvent()
Definition: BaseFakeBkgTool.h:97
hist_file_dump.f
f
Definition: hist_file_dump.py:135
CP::BaseFakeBkgTool::UncertaintyList::sigma
float sigma
Definition: BaseFakeBkgTool.h:146
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
CP::BaseFakeBkgTool::m_values_1dhisto_map
std::map< TH1 *, const float * > m_values_1dhisto_map
Definition: BaseFakeBkgTool.h:108
python.hypoToolDisplay.toolname
def toolname(tool)
Definition: hypoToolDisplay.py:13
FakeBkgTools::Database
Definition: Database.h:29
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
plotting.yearwise_efficiency_vs_mu.yval
float yval
Definition: yearwise_efficiency_vs_mu.py:36
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::addEventCustom
virtual StatusCode addEventCustom()=0
FakeBkgTools::FinalState
Definition: FakeBkgInternals.h:98
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
CP::BaseFakeBkgTool::UncertaintyList::next
const UncertaintyList * next() const
Definition: BaseFakeBkgTool.h:153
CP::ISelectionReadAccessor
a specialized accessor to read a selection decoration from/to an xAOD object
Definition: ISelectionReadAccessor.h:39
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
CP::BaseFakeBkgTool::m_values_2dhisto_map
std::map< TH2 *, std::pair< const float *, const float * > > m_values_2dhisto_map
Definition: BaseFakeBkgTool.h:109
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
AsgTool.h
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
checker_macros.h
Define macros for attributes used to control the static checker.
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::m_accFakeEff
SG::ConstAccessor< float > m_accFakeEff
only used when m_useDB is false
Definition: BaseFakeBkgTool.h:177
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