ATLAS Offline Software
Macros | Functions
TrigGlobEffCorrExample4.cxx File Reference
#include <TFile.h>
#include <TError.h>
#include "AthAnalysisBaseComps/AthAnalysisHelper.h"
#include "POOLRootAccess/TEvent.h"
#include "AsgMessaging/MessageCheck.h"
#include "xAODEventInfo/EventInfo.h"
#include "xAODEgamma/ElectronContainer.h"
#include "PATCore/PATCoreEnums.h"
#include "AsgTools/AnaToolHandle.h"
#include "EgammaAnalysisInterfaces/IAsgElectronEfficiencyCorrectionTool.h"
#include "TrigGlobalEfficiencyCorrection/TrigGlobalEfficiencyCorrectionTool.h"
#include <random>

Go to the source code of this file.

Macros

#define MSGSOURCE   "Example 4"
 

Functions

StatusCode testElectrons (const char *APP_NAME, bool quiet)
 
StatusCode testPhotons (const char *APP_NAME, bool quiet)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ MSGSOURCE

#define MSGSOURCE   "Example 4"

Definition at line 41 of file TrigGlobEffCorrExample4.cxx.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 48 of file TrigGlobEffCorrExample4.cxx.

49 {
50  bool quiet = false;
51  ANA_CHECK_SET_TYPE(bool)
52  const std::string flagQuiet("--quiet");
53  for(int i=1;i<argc;++i)
54  {
55  if(argv[i] == flagQuiet) quiet = true;
56  }
57  const char* APP_NAME = argv[0];
58  #ifdef XAOD_STANDALONE
59  xAOD::Init(APP_NAME).ignore();
60  StatusCode::enableFailure();
61  #else
62  IAppMgrUI* app = POOL::Init();
63  #endif
64 
67 
68  #ifndef XAOD_STANDALONE
69  ANA_CHECK(app->finalize())
70  #endif
71  return 0;
72 }

◆ testElectrons()

StatusCode testElectrons ( const char *  APP_NAME,
bool  quiet 
)

Retrieve the list of electron map keys for the chosen trigger combination

Then create all the needed electron tools and initialize the TrigGlob tool using the information returned by suggestElectronMapKeys()

Trigger efficiency/scale factor CP tools for electrons and muons

one tool instance for efficiencies, another for scale factors

Safer to retrieve the name from the final ToolHandle, it might be prefixed (by the parent tool name) when the handle is copied

Definition at line 75 of file TrigGlobEffCorrExample4.cxx.

76 {
78  std::map<std::string,std::string> triggerCombination;
79  triggerCombination["2015"] = "2e12_lhloose_L12EM10VH || e17_lhloose_mu14 || mu18_mu8noL1"
80  "|| e24_lhmedium_L1EM20VH_OR_e60_lhmedium_OR_e120_lhloose || mu20_iloose_L1MU15";
81  triggerCombination["2016"] = "2e17_lhvloose_nod0 || e17_lhloose_nod0_mu14 || mu22_mu8noL1 "
82  "|| e26_lhtight_nod0_ivarloose_OR_e60_lhmedium_nod0_OR_e140_lhloose_nod0 || mu26_ivarmedium";
83  triggerCombination["2017"] = "2e17_lhvloose_nod0_L12EM15VHI || 2e24_lhvloose_nod0 || e17_lhloose_nod0_mu14 || mu22_mu8noL1 "
84  "|| e26_lhtight_nod0_ivarloose_OR_e60_lhmedium_nod0_OR_e140_lhloose_nod0 || mu26_ivarmedium";
85  triggerCombination["2018"] = triggerCombination["2017"];
86  std::map<std::string,std::string> legsPerKey, legsAlone;
87  auto cc = TrigGlobalEfficiencyCorrectionTool::suggestElectronMapKeys(triggerCombination, "", legsAlone);
89  {
90  if(!quiet)
91  {
92  std::string msg = "List of trigger legs for this combination of triggers:\n";
93  for(auto& kv : legsAlone)
94  {
95  msg += " - " + kv.second + '\n';
96  }
97  Info(APP_NAME, "%s", msg.c_str());
98  }
99  }
100  else
101  {
102  Error(APP_NAME, "Unable to find list of trigger legs!");
103  return StatusCode::FAILURE;
104  }
105 
106  cc = TrigGlobalEfficiencyCorrectionTool::suggestElectronMapKeys(triggerCombination, "2015_2018/rel21.2/Precision_Summer2020_v1", legsPerKey);
108  {
109  if(!quiet)
110  {
111  std::string msg = "List of map keys necessary for this combination of triggers:\n";
112  for(auto& kv : legsPerKey)
113  {
114  msg += " - tool with key \"" + kv.first + "\" chosen for legs " + kv.second + '\n';
115  }
116  Info(APP_NAME, "%s", msg.c_str());
117  }
118  }
119  else
120  {
121  Error(APP_NAME, "Unable to find list of map keys!");
122  return StatusCode::FAILURE;
123  }
124 
127 
129  ToolHandleArray<IAsgElectronEfficiencyCorrectionTool> electronEffTools, electronSFTools;
130  std::vector<asg::AnaToolHandle<IAsgElectronEfficiencyCorrectionTool> > electronToolsFactory; // for RAII
131  std::map<std::string,std::string> legsPerTool;
132  int nTools = 0;
133  for(auto& kv : legsPerKey)
134  {
135  const std::string& trigKey = kv.first;
136  for(int j=0;j<2;++j)
137  {
138  auto t = electronToolsFactory.emplace(electronToolsFactory.end(), "AsgElectronEfficiencyCorrectionTool/ElTrigEff_"+std::to_string(nTools++));
139  t->setProperty("MapFilePath", "ElectronEfficiencyCorrection/2015_2018/rel21.2/Precision_Summer2020_v1/map4.txt").ignore();
140  t->setProperty("TriggerKey", (j? trigKey : "Eff_"+trigKey)).ignore();
141  t->setProperty("IdKey", "Tight").ignore();
142  t->setProperty("IsoKey", "FCTight").ignore();
143  t->setProperty("CorrelationModel", "TOTAL").ignore();
144  t->setProperty("ForceDataType", (int)PATCore::ParticleDataType::Full).ignore();
145  t->setProperty("OutputLevel", MSG::ERROR).ignore();
146  ANA_CHECK(t->initialize());
147  auto& handles = j? electronSFTools : electronEffTools;
148  handles.push_back(t->getHandle());
150  std::string name = handles[handles.size()-1].name();
151  legsPerTool[name] = legsPerKey[trigKey];
152  }
153  }
154 
155  ToolHandleArray<CP::IMuonTriggerScaleFactors> muonTools;
156  asg::AnaToolHandle<CP::IMuonTriggerScaleFactors> muonTool("CP::MuonTriggerScaleFactors/MuonTrigEff");
157  muonTool.setProperty("MuonQuality", "Medium").ignore();
158  muonTool.setProperty("OutputLevel", MSG::ERROR).ignore();
159  if(muonTool.initialize() != StatusCode::SUCCESS)
160  {
161  Error(APP_NAME, "Unable to initialize the muon CP tool!");
162  return StatusCode::FAILURE;
163  }
164  muonTools.push_back(muonTool.getHandle());
165 
166  asg::AnaToolHandle<ITrigGlobalEfficiencyCorrectionTool> myTool("TrigGlobalEfficiencyCorrectionTool/MyTool1");
167  myTool.setProperty("ElectronEfficiencyTools", electronEffTools).ignore();
168  myTool.setProperty("ElectronScaleFactorTools", electronSFTools).ignore();
169  myTool.setProperty("MuonTools", muonTools).ignore();
170  myTool.setProperty("TriggerCombination", triggerCombination).ignore();
171  myTool.setProperty("ListOfLegsPerTool", legsPerTool).ignore();
172  myTool.setProperty("OutputLevel", quiet? MSG::WARNING : MSG::INFO).ignore();
173  ANA_CHECK(myTool.initialize());
174  return StatusCode::SUCCESS;
175 }

◆ testPhotons()

StatusCode testPhotons ( const char *  APP_NAME,
bool  quiet 
)

Retrieve the list of electron map keys for the chosen trigger combination

Then create all the needed photon tools and initialize the TrigGlob tool using the information returned by suggestPhotonMapKeys()

Trigger efficiency/scale factor CP tools for photons

one tool instance for efficiencies, another for scale factors

Definition at line 178 of file TrigGlobEffCorrExample4.cxx.

179 {
181  std::map<std::string,std::string> triggerCombination;
182  triggerCombination["2015"] = "g35_loose_g25_loose || 2g20_tight";
183  triggerCombination["2016"] = " g35_loose_g25_loose || 2g22_tight";
184  triggerCombination["2017"] = "g35_medium_g25_medium_L12EM20VH || 2g22_tight_L12EM15VHI";
185  triggerCombination["2018"] = triggerCombination["2017"];
186  std::map<std::string,std::string> legsPerKey;
187  auto cc = TrigGlobalEfficiencyCorrectionTool::suggestPhotonMapKeys(triggerCombination, "2015_2018/rel21.2/Summer2020_Rec_v1", legsPerKey);
189  {
190  if(!quiet)
191  {
192  std::string msg = "List of map keys necessary for this combination of triggers:\n";
193  for(auto& kv : legsPerKey)
194  {
195  msg += " - tool with key \"" + kv.first + "\" chosen for legs " + kv.second + '\n';
196  }
197  Info(APP_NAME, "%s", msg.c_str());
198  }
199  }
200  else
201  {
202  Error(APP_NAME, "Unable to find list of map keys!");
203  return StatusCode::FAILURE;
204  }
205 
208 
210  ToolHandleArray<IAsgPhotonEfficiencyCorrectionTool> photonEffTools, photonSFTools;
211  std::vector<asg::AnaToolHandle<IAsgPhotonEfficiencyCorrectionTool> > photonToolsFactory; // for RAII
212  std::map<std::string,std::string> legsPerTool;
213  int nTools = 0;
214  for(auto& kv : legsPerKey)
215  {
216  const std::string& trigKey = kv.first;
217  for(int j=0;j<2;++j)
218  {
219  auto t = photonToolsFactory.emplace(photonToolsFactory.end(), "AsgPhotonEfficiencyCorrectionTool/PhTrigEff_"+std::to_string(nTools++));
220  t->setProperty("MapFilePath", "PhotonEfficiencyCorrection/2015_2018/rel21.2/Summer2020_Rec_v1/map3.txt").ignore();
221  t->setProperty("TriggerKey", (j? trigKey : "Eff_"+trigKey)).ignore();
222  t->setProperty("IsoKey", "TightCaloOnly").ignore();
223  t->setProperty("ForceDataType", (int)PATCore::ParticleDataType::Full).ignore();
224  t->setProperty("OutputLevel", MSG::ERROR).ignore();
225  ANA_CHECK(t->initialize());
226  auto& handles = j? photonSFTools : photonEffTools;
227  handles.push_back(t->getHandle());
228  std::string name = handles[handles.size()-1].name();
229  legsPerTool[name] = legsPerKey[trigKey];
230  }
231  }
232  asg::AnaToolHandle<ITrigGlobalEfficiencyCorrectionTool> myTool("TrigGlobalEfficiencyCorrectionTool/MyTool2");
233  myTool.setProperty("PhotonEfficiencyTools", photonEffTools).ignore();
234  myTool.setProperty("PhotonScaleFactorTools", photonSFTools).ignore();
235  myTool.setProperty("TriggerCombination", triggerCombination).ignore();
236  myTool.setProperty("ListOfLegsPerTool", legsPerTool).ignore();
237  myTool.setProperty("OutputLevel", quiet? MSG::WARNING : MSG::INFO).ignore();
238  ANA_CHECK(myTool.initialize());
239  return StatusCode::SUCCESS;
240 }
asg::AnaToolHandle< CP::IMuonTriggerScaleFactors >
TrigGlobalEfficiencyCorrectionTool::suggestElectronMapKeys
static CP::CorrectionCode suggestElectronMapKeys(const std::map< std::string, std::string > &triggerCombination, const std::string &version, std::map< std::string, std::string > &legsPerKey)
Definition: TrigGlobalEfficiencyCorrectionTool.h:62
quiet
bool quiet
Definition: TrigGlobEffCorrValidation.cxx:190
testElectrons
StatusCode testElectrons(const char *APP_NAME, bool quiet)
Definition: TrigGlobEffCorrExample4.cxx:75
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ZDCMsg::Info
@ Info
Definition: ZDCMsg.h:20
POOL::Init
IAppMgrUI * Init(const char *options="POOLRootAccess/basic.opts")
Bootstraps (creates and configures) the Gaudi Application with the provided options file.
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:29
PATCore::ParticleDataType::Full
@ Full
Definition: PATCoreEnums.h:22
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
ANA_CHECK_SET_TYPE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:314
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
testPhotons
StatusCode testPhotons(const char *APP_NAME, bool quiet)
Definition: TrigGlobEffCorrExample4.cxx:178
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
TrigGlobalEfficiencyCorrectionTool::suggestPhotonMapKeys
static CP::CorrectionCode suggestPhotonMapKeys(const std::map< std::string, std::string > &triggerCombination, const std::string &version, std::map< std::string, std::string > &legsPerKey)
Definition: TrigGlobalEfficiencyCorrectionTool.h:67
python.handimod.cc
int cc
Definition: handimod.py:523
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31