ATLAS Offline Software
TElectronEfficiencyCorrectionTool.h
Go to the documentation of this file.
1 // Dear emacs, this is -*- c++ -*-
2 /*
3  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
4 */
5 
6 #ifndef __TELECTRONEFFICIENCYCORRECTIONTOOL__
7 #define __TELECTRONEFFICIENCYCORRECTIONTOOL__
8 
19 // STL includes
20 #include <array>
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 // ROOT includes
26 #include "TH1.h"
27 #include "TH2.h"
28 #include "TObjArray.h"
29 #include "TRandom3.h"
30 // Core includes
32 #include "PATCore/PATCoreEnums.h"
33 
34 namespace Root {
36 {
37 public:
38  //We want to have unique ownership of the Histos
39  using HistArray = std::vector<std::unique_ptr<TH1>>;
40 
41  // The Result
42  struct Result {
43  double SF = 0;
44  double Total = 0;
45  double Stat = 0;
46  double UnCorr = 0;
47  std::vector<double> Corr{};
48  std::vector<double> toys{};
49  int histIndex = -1;
50  int histBinNum = -1;
51  };
52 
55  const char* name = "TElectronEfficiencyCorrectionTool");
56 
59 
66  inline void addFileName(const std::string& val) {
67  m_corrFileNameList.push_back(val);
68  }
71  inline void bookToyMCScaleFactors(const int nToyMC) {
72  m_doToyMC = true;
73  m_nToyMC = nToyMC;
74  }
75  inline void bookCombToyMCScaleFactors(const int nToyMC) {
76  m_doCombToyMC = true;
77  m_nToyMC = nToyMC;
78  }
80  int initialize();
81 
96  const unsigned int runnumber,
97  const double cluster_eta,
98  const double et, /* in MeV */
99  Result& result,
100  const bool onlyTotal = false) const;
101 
104  int getNbins(std::map<float, std::vector<float>>& ptEta) const;
105 
107  inline int getNSyst() const { return m_nSysMax; }
108 
110  inline void setSeed(const unsigned long int seed) { m_seed = seed; }
111 
114 
115 private:
116  // Private methods
118  int getHistograms();
119 
120  int setupHistogramsInFolder(const TObjArray& dirNameArray, int lastIdx);
121 
122  bool setupUncorrToySyst(std::vector<std::vector<TH1*>>& objs,
123  std::vector<std::vector<TH1*>>& sysObjs,
124  std::vector<std::vector<HistArray>>& uncorrToyMCSyst);
125 
126  std::vector<HistArray> buildToyMCTable(
127  const std::vector<TH1*>& sf,
128  const std::vector<TH1*>& eig,
129  const std::vector<TH1*>& stat,
130  const std::vector<TH1*>& uncorr,
131  const std::vector<std::vector<TH1*>>& corr);
132 
133  std::vector<TH2*> buildSingleToyMC(const TH2* sf,
134  const TH2* stat,
135  const TH2* uncorr,
136  const std::vector<TH1*>& corr,
137  int& randomCounter);
138 
139  TH2* buildSingleCombToyMC(const TH2* sf,
140  const TH2* stat,
141  const TH2* uncorr,
142  const std::vector<TH1*>& corr,
143  const int nSys,
144  int& randomCounter);
145 
146  void setupTempMapsHelper(TH1* obj,
147  std::vector<std::vector<TH1*>>& objs,
148  std::vector<std::vector<TH1*>>& sysObjs,
149  int& seenSystematics);
150 
153  int setup(const std::vector<TH1*>& hists,
154  std::vector<HistArray>& histList,
155  std::vector<unsigned int>& beginRunNumberList,
156  std::vector<unsigned int>& endRunNumberList,
157  const int runNumBegin,
158  const int runNumEnd) const;
159 
160  struct HistEdge {
161  double etaMax = 0;
162  double etaMin = 0;
163  double etMax = 0;
164  double etMin = 0;
165  bool isLowPt = false;
166  };
167 
168  static void fillHistEdges(const std::vector<HistArray>& sfPerPeriodHist,
169  std::vector<std::vector<HistEdge>>& sfPerPeriodEdges) ;
170 
172  bool m_doToyMC;
175  int m_nToyMC;
177  unsigned long int m_seed;
180  // The representation of the prepared toy SF tables
181  std::vector<std::vector<HistArray>> m_uncorrToyMCSystFull;
182  std::vector<std::vector<HistArray>> m_uncorrToyMCSystFast;
184  std::vector<std::string> m_corrFileNameList;
186  std::vector<unsigned int> m_begRunNumberList;
189  std::vector<unsigned int> m_endRunNumberList;
191  std::vector<unsigned int> m_begRunNumberListFastSim;
194  std::vector<unsigned int> m_endRunNumberListFastSim;
196  std::vector<std::vector<HistArray>> m_histList;
197  std::vector<std::vector<HistEdge>> m_histEdges;
198  std::vector<std::vector<HistArray>> m_sysList;
200  std::vector<std::vector<HistArray>> m_fastHistList;
201  std::vector<std::vector<HistEdge>> m_fastHistEdges;
202  std::vector<std::vector<HistArray>> m_fastSysList;
203  // The Random generator class
204  TRandom3 m_Rndm;
205  }; // End: class definition
206 } // End: namespace Root
207 
208 #endif
Root::TElectronEfficiencyCorrectionTool::HistEdge::etaMin
double etaMin
Definition: TElectronEfficiencyCorrectionTool.h:162
et
Extra patterns decribing particle interation process.
get_generator_info.result
result
Definition: get_generator_info.py:21
Root::TElectronEfficiencyCorrectionTool::bookCombToyMCScaleFactors
void bookCombToyMCScaleFactors(const int nToyMC)
Definition: TElectronEfficiencyCorrectionTool.h:75
Root::TElectronEfficiencyCorrectionTool::m_Rndm
TRandom3 m_Rndm
Definition: TElectronEfficiencyCorrectionTool.h:204
Root
Definition: GoodRunsListSelectorTool.h:30
Root::TElectronEfficiencyCorrectionTool::m_seed
unsigned long int m_seed
The Random seed.
Definition: TElectronEfficiencyCorrectionTool.h:177
Root::TElectronEfficiencyCorrectionTool::setupUncorrToySyst
bool setupUncorrToySyst(std::vector< std::vector< TH1 * >> &objs, std::vector< std::vector< TH1 * >> &sysObjs, std::vector< std::vector< HistArray >> &uncorrToyMCSyst)
Definition: TElectronEfficiencyCorrectionTool.cxx:859
mapkey::uncorr
@ uncorr
Definition: TElectronEfficiencyCorrectionTool.cxx:41
Root::TElectronEfficiencyCorrectionTool::m_histEdges
std::vector< std::vector< HistEdge > > m_histEdges
Definition: TElectronEfficiencyCorrectionTool.h:197
Root::TElectronEfficiencyCorrectionTool::m_doToyMC
bool m_doToyMC
Flag to control Toys.
Definition: TElectronEfficiencyCorrectionTool.h:172
downloadSingle.dataType
string dataType
Definition: downloadSingle.py:18
Root::TElectronEfficiencyCorrectionTool::m_begRunNumberListFastSim
std::vector< unsigned int > m_begRunNumberListFastSim
List of run numbers where histograms become valid for fast simulation.
Definition: TElectronEfficiencyCorrectionTool.h:191
Root::TElectronEfficiencyCorrectionTool::uncorrEmpty
bool uncorrEmpty(const PATCore::ParticleDataType::DataType dataType)
Check if stat+uncorr has input.
Definition: TElectronEfficiencyCorrectionTool.cxx:151
Root::TElectronEfficiencyCorrectionTool::m_nSysMax
int m_nSysMax
Maximum number of systematics.
Definition: TElectronEfficiencyCorrectionTool.h:179
Root::TElectronEfficiencyCorrectionTool::Result::Stat
double Stat
Definition: TElectronEfficiencyCorrectionTool.h:45
PATCore::ParticleDataType::DataType
DataType
Definition: PATCoreEnums.h:22
Root::TElectronEfficiencyCorrectionTool::m_corrFileNameList
std::vector< std::string > m_corrFileNameList
The list of file name(s)
Definition: TElectronEfficiencyCorrectionTool.h:184
Root::TElectronEfficiencyCorrectionTool::HistEdge::isLowPt
bool isLowPt
Definition: TElectronEfficiencyCorrectionTool.h:165
AsgMessaging.h
Root::TElectronEfficiencyCorrectionTool::m_uncorrToyMCSystFast
std::vector< std::vector< HistArray > > m_uncorrToyMCSystFast
Definition: TElectronEfficiencyCorrectionTool.h:182
Root::TElectronEfficiencyCorrectionTool::Result
Definition: TElectronEfficiencyCorrectionTool.h:42
Root::TElectronEfficiencyCorrectionTool::Result::histIndex
int histIndex
Definition: TElectronEfficiencyCorrectionTool.h:49
Root::TElectronEfficiencyCorrectionTool::Result::UnCorr
double UnCorr
Definition: TElectronEfficiencyCorrectionTool.h:46
Root::TElectronEfficiencyCorrectionTool::HistEdge::etaMax
double etaMax
Definition: TElectronEfficiencyCorrectionTool.h:161
PATCoreEnums.h
Root::TElectronEfficiencyCorrectionTool::m_uncorrToyMCSystFull
std::vector< std::vector< HistArray > > m_uncorrToyMCSystFull
Definition: TElectronEfficiencyCorrectionTool.h:181
checkFileSG.objs
list objs
Definition: checkFileSG.py:93
Root::TElectronEfficiencyCorrectionTool::buildSingleToyMC
std::vector< TH2 * > buildSingleToyMC(const TH2 *sf, const TH2 *stat, const TH2 *uncorr, const std::vector< TH1 * > &corr, int &randomCounter)
Definition: TElectronEfficiencyCorrectionTool.cxx:397
Root::TElectronEfficiencyCorrectionTool::Result::toys
std::vector< double > toys
Definition: TElectronEfficiencyCorrectionTool.h:48
Root::TElectronEfficiencyCorrectionTool::getHistograms
int getHistograms()
Load all histograms from the input file(s)
Definition: TElectronEfficiencyCorrectionTool.cxx:587
Root::TElectronEfficiencyCorrectionTool::Result::SF
double SF
Definition: TElectronEfficiencyCorrectionTool.h:43
MakeTH3DFromTH2Ds.hists
hists
Definition: MakeTH3DFromTH2Ds.py:72
Root::TElectronEfficiencyCorrectionTool::getNSyst
int getNSyst() const
get number of systematics
Definition: TElectronEfficiencyCorrectionTool.h:107
Root::TElectronEfficiencyCorrectionTool::m_endRunNumberListFastSim
std::vector< unsigned int > m_endRunNumberListFastSim
List of run numbers where histograms stop being valid for fast simulation.
Definition: TElectronEfficiencyCorrectionTool.h:194
Root::TElectronEfficiencyCorrectionTool::setSeed
void setSeed(const unsigned long int seed)
Set the Random Seed.
Definition: TElectronEfficiencyCorrectionTool.h:110
Root::TElectronEfficiencyCorrectionTool::m_fastSysList
std::vector< std::vector< HistArray > > m_fastSysList
Definition: TElectronEfficiencyCorrectionTool.h:202
mapkey::eig
@ eig
Definition: TElectronEfficiencyCorrectionTool.cxx:40
Root::TElectronEfficiencyCorrectionTool::m_begRunNumberList
std::vector< unsigned int > m_begRunNumberList
List of run numbers where histograms become valid for full simulation.
Definition: TElectronEfficiencyCorrectionTool.h:186
beamspotman.stat
stat
Definition: beamspotman.py:266
Root::TElectronEfficiencyCorrectionTool
Definition: TElectronEfficiencyCorrectionTool.h:36
DeMoScan.runnumber
runnumber
Definition: DeMoScan.py:266
Root::TElectronEfficiencyCorrectionTool::initialize
int initialize()
Initialize this class.
Definition: TElectronEfficiencyCorrectionTool.cxx:87
Root::TElectronEfficiencyCorrectionTool::m_fastHistEdges
std::vector< std::vector< HistEdge > > m_fastHistEdges
Definition: TElectronEfficiencyCorrectionTool.h:201
Result
Definition: fbtTestBasics.cxx:49
Root::TElectronEfficiencyCorrectionTool::m_doCombToyMC
bool m_doCombToyMC
Definition: TElectronEfficiencyCorrectionTool.h:173
Root::TElectronEfficiencyCorrectionTool::m_histList
std::vector< std::vector< HistArray > > m_histList
List of histograms for full Geant4 simulation.
Definition: TElectronEfficiencyCorrectionTool.h:196
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
Root::TElectronEfficiencyCorrectionTool::m_fastHistList
std::vector< std::vector< HistArray > > m_fastHistList
List of histograms for fast simulation.
Definition: TElectronEfficiencyCorrectionTool.h:200
Root::TElectronEfficiencyCorrectionTool::setup
int setup(const std::vector< TH1 * > &hists, std::vector< HistArray > &histList, std::vector< unsigned int > &beginRunNumberList, std::vector< unsigned int > &endRunNumberList, const int runNumBegin, const int runNumEnd) const
Fill and interpret the setup, depending on which histograms are found in the input file(s)
Definition: TElectronEfficiencyCorrectionTool.cxx:891
Root::TElectronEfficiencyCorrectionTool::buildToyMCTable
std::vector< HistArray > buildToyMCTable(const std::vector< TH1 * > &sf, const std::vector< TH1 * > &eig, const std::vector< TH1 * > &stat, const std::vector< TH1 * > &uncorr, const std::vector< std::vector< TH1 * >> &corr)
Definition: TElectronEfficiencyCorrectionTool.cxx:484
Root::TElectronEfficiencyCorrectionTool::addFileName
void addFileName(const std::string &val)
This is more of an utility so the initialize is different wrt to an athena component.
Definition: TElectronEfficiencyCorrectionTool.h:66
Root::TElectronEfficiencyCorrectionTool::HistArray
std::vector< std::unique_ptr< TH1 > > HistArray
Definition: TElectronEfficiencyCorrectionTool.h:39
Root::TElectronEfficiencyCorrectionTool::fillHistEdges
static void fillHistEdges(const std::vector< HistArray > &sfPerPeriodHist, std::vector< std::vector< HistEdge >> &sfPerPeriodEdges)
Definition: TElectronEfficiencyCorrectionTool.cxx:930
Root::TElectronEfficiencyCorrectionTool::Result::histBinNum
int histBinNum
Definition: TElectronEfficiencyCorrectionTool.h:50
Root::TElectronEfficiencyCorrectionTool::HistEdge::etMin
double etMin
Definition: TElectronEfficiencyCorrectionTool.h:164
Root::TElectronEfficiencyCorrectionTool::setupTempMapsHelper
void setupTempMapsHelper(TH1 *obj, std::vector< std::vector< TH1 * >> &objs, std::vector< std::vector< TH1 * >> &sysObjs, int &seenSystematics)
Definition: TElectronEfficiencyCorrectionTool.cxx:801
Root::TElectronEfficiencyCorrectionTool::TElectronEfficiencyCorrectionTool
TElectronEfficiencyCorrectionTool(const char *name="TElectronEfficiencyCorrectionTool")
Standard constructor.
Definition: TElectronEfficiencyCorrectionTool.cxx:72
Root::TElectronEfficiencyCorrectionTool::Result::Corr
std::vector< double > Corr
Definition: TElectronEfficiencyCorrectionTool.h:47
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
Root::TElectronEfficiencyCorrectionTool::m_endRunNumberList
std::vector< unsigned int > m_endRunNumberList
List of run numbers where histograms stop being valid for full simulation.
Definition: TElectronEfficiencyCorrectionTool.h:189
Root::TElectronEfficiencyCorrectionTool::HistEdge
Definition: TElectronEfficiencyCorrectionTool.h:160
Root::TElectronEfficiencyCorrectionTool::getNbins
int getNbins(std::map< float, std::vector< float >> &ptEta) const
Helpers to get the binning of the uncertainties in a std::map (pt, eta)
Definition: TElectronEfficiencyCorrectionTool.cxx:546
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
Root::TElectronEfficiencyCorrectionTool::m_sysList
std::vector< std::vector< HistArray > > m_sysList
Definition: TElectronEfficiencyCorrectionTool.h:198
Root::TElectronEfficiencyCorrectionTool::m_nToyMC
int m_nToyMC
The number of toys.
Definition: TElectronEfficiencyCorrectionTool.h:175
Root::TElectronEfficiencyCorrectionTool::HistEdge::etMax
double etMax
Definition: TElectronEfficiencyCorrectionTool.h:163
Root::TElectronEfficiencyCorrectionTool::setupHistogramsInFolder
int setupHistogramsInFolder(const TObjArray &dirNameArray, int lastIdx)
Definition: TElectronEfficiencyCorrectionTool.cxx:663
Root::TElectronEfficiencyCorrectionTool::bookToyMCScaleFactors
void bookToyMCScaleFactors(const int nToyMC)
Running these before the initialize will setup the booking of toys.
Definition: TElectronEfficiencyCorrectionTool.h:71
python.PyAthena.obj
obj
Definition: PyAthena.py:132
Root::TElectronEfficiencyCorrectionTool::~TElectronEfficiencyCorrectionTool
~TElectronEfficiencyCorrectionTool()=default
Standard destructor.
Root::TElectronEfficiencyCorrectionTool::calculate
int calculate(const PATCore::ParticleDataType::DataType dataType, const unsigned int runnumber, const double cluster_eta, const double et, Result &result, const bool onlyTotal=false) const
The main calculate method: dataType PATCore::ParticleDataType::DataType (e.g DATA,...
Definition: TElectronEfficiencyCorrectionTool.cxx:160
Root::TElectronEfficiencyCorrectionTool::buildSingleCombToyMC
TH2 * buildSingleCombToyMC(const TH2 *sf, const TH2 *stat, const TH2 *uncorr, const std::vector< TH1 * > &corr, const int nSys, int &randomCounter)
Definition: TElectronEfficiencyCorrectionTool.cxx:437
Root::TElectronEfficiencyCorrectionTool::Result::Total
double Total
Definition: TElectronEfficiencyCorrectionTool.h:44