ATLAS Offline Software
TrigGlobEffCorrExample4.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Based on CPToolTester.cxx (A. Kraznahorkay) and ut_ath_checkTrigger_test.cxx (W. Buttinger)
6 // Contact: jmaurer@cern.ch
7 
8 /*
9  * Examples of "automatic" configuration using TrigGlobalEfficiencyCorrectionTool::suggestElectronMapKeys()
10  *
11  */
12 
13 // ROOT include(s):
14 #include <TFile.h>
15 #include <TError.h>
16 
17 // Infrastructure include(s):
18 #ifdef XAOD_STANDALONE
19  #include "xAODRootAccess/Init.h"
20  #include "xAODRootAccess/TEvent.h"
21  #include "xAODRootAccess/TStore.h"
22 #else
24  #include "POOLRootAccess/TEvent.h"
25 #endif
26 
28 // EDM include(s):
31 #include "PATCore/PATCoreEnums.h"
32 #include "AsgTools/AnaToolHandle.h"
34 // The interface header is not sufficient here as this example makes use of a static method of TrigGlobalEfficiencyCorrectionTool
36 
37 // stdlib include(s):
38 #include <random>
39 
40 #define MSGSOURCE "Example 4"
43 using namespace Test;
44 
45 StatusCode testElectrons(const char* APP_NAME, bool quiet);
46 StatusCode testPhotons(const char* APP_NAME, bool quiet);
47 
48 int main(int argc, char* argv[])
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 }
73 
74 
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 }
176 
177 
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::initialize
StatusCode initialize()
initialize the tool
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
IAsgElectronEfficiencyCorrectionTool.h
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
TrigGlobalEfficiencyCorrectionTool.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
asg::AnaToolHandle::setProperty
StatusCode setProperty(const std::string &property, const T2 &value)
set the given property of the tool.
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
ANA_MSG_HEADER
#define ANA_MSG_HEADER(NAME)
for standalone code this creates a new message category
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:113
PATCore::ParticleDataType::Full
@ Full
Definition: PATCoreEnums.h:22
ElectronContainer.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
main
int main(int argc, char *argv[])
Definition: TrigGlobEffCorrExample4.cxx:48
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MessageCheck.h
macros for messaging and checking status codes
PATCoreEnums.h
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
TEvent.h
Init.h
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
AnaToolHandle.h
ANA_MSG_SOURCE
#define ANA_MSG_SOURCE(NAME, TITLE)
the source code part of ANA_MSG_SOURCE
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:133
TEvent.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
EventInfo.h
AthAnalysisHelper.h
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
asg::AnaToolHandle::getHandle
const ToolHandle< T > & getHandle() const noexcept
the tool handle we wrap
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
MSGSOURCE
#define MSGSOURCE
Definition: TrigGlobEffCorrExample4.cxx:40
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
TStore.h
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