ATLAS Offline Software
Loading...
Searching...
No Matches
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"
22#else
25#endif
26
28// EDM include(s):
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"
43using namespace Test;
44
45StatusCode testElectrons(const char* APP_NAME, bool quiet);
46StatusCode testPhotons(const char* APP_NAME, bool quiet);
47
48int main(int argc, char* argv[])
49{
50 bool quiet = false;
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
75StatusCode testElectrons(const char* APP_NAME, bool quiet)
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);
107 if(cc == CP::CorrectionCode::Ok)
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
178StatusCode testPhotons(const char* APP_NAME, bool quiet)
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);
188 if(cc == CP::CorrectionCode::Ok)
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}
#define APP_NAME
macros for messaging and checking status codes
#define ANA_CHECK(EXP)
check whether the given expression was successful
#define ANA_MSG_HEADER(NAME)
for standalone code this creates a new message category
#define ANA_MSG_SOURCE(NAME, TITLE)
the source code part of ANA_MSG_SOURCE
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
StatusCode testPhotons(const char *APP_NAME, bool quiet)
StatusCode testElectrons(const char *APP_NAME, bool quiet)
@ Ok
The correction was done successfully.
static CP::CorrectionCode suggestPhotonMapKeys(const std::map< std::string, std::string > &triggerCombination, const std::string &version, std::map< std::string, std::string > &legsPerKey)
static CP::CorrectionCode suggestElectronMapKeys(const std::map< std::string, std::string > &triggerCombination, const std::string &version, std::map< std::string, std::string > &legsPerKey)
a modified tool handle that allows its owner to configure new tools from the C++ side
StatusCode setProperty(const std::string &property, const T2 &value)
set the given property of the tool.
StatusCode initialize()
initialize the tool
const ToolHandle< T > & getHandle() const noexcept
the tool handle we wrap
int main()
Definition hello.cxx:18
IAppMgrUI * Init(const char *options="POOLRootAccess/basic.opts")
Bootstraps (creates and configures) the Gaudi Application with the provided options file.
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
#define MSGSOURCE
Test code to test ElectronPhotonVariableCorrectionTool Dictionaries.
MsgStream & msg
Definition testRead.cxx:32