ATLAS Offline Software
Loading...
Searching...
No Matches
TrigGlobEffCorrExample6.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
8/*
9 * Trigger matching example: one can use the same configuration as in other examples;
10 * the only addition is the (mandatory) creation of a Trig::MatchingTool instance
11 * for the "TriggerMatchingTool" property.
12 */
13
14// ROOT include(s):
15#include <TFile.h>
16#include <TError.h>
17
18// Infrastructure include(s):
19#ifdef XAOD_STANDALONE
20 #include "xAODRootAccess/Init.h"
23#else
26#endif
27
29// EDM include(s):
42
43// stdlib include(s):
44#include <random>
45#include <vector>
46#include <array>
47using std::vector;
48using std::string;
49
50#define MSGSOURCE "Example 6"
51// messaging
54using namespace Test;
55int main(int argc, char* argv[])
56{
58 const char* filename = nullptr;
59 bool debug = false, fast = false, cmdline_error = false;
60 for(int i=1;i<argc;++i)
61 {
62 if(string(argv[i]) == "--debug") debug = true;
63 if(string(argv[i]) == "--fast") fast = true;
64 else if(!filename && *argv[i]!='-') filename = argv[i];
65 else cmdline_error = true;
66 }
67 if(!filename || cmdline_error)
68 {
69 Error(MSGSOURCE, "No file name received!");
70 Error(MSGSOURCE, " Usage: %s [--debug] [--fast] [DxAOD file name]", argv[0]);
71 return 1;
72 }
73 #ifdef XAOD_STANDALONE
74 xAOD::Init(MSGSOURCE).ignore();
75 TFile* file = TFile::Open(filename, "READ");
76 if(!file)
77 {
78 Error(MSGSOURCE, "Unable to open file!");
79 return 2;
80 }
82 xAOD::TStore store;
83 StatusCode::enableFailure();
84 #else
85 IAppMgrUI* app = POOL::Init();
87 TString file(filename);
88 #endif
89 event.readFrom(file).ignore();
90 Long64_t entries = event.getEntries();
91 Info(MSGSOURCE, "Number of events in the file: %lli", entries);
92 if(fast) entries = std::min(entries, 1000LL);
93
94 /* ********************************************************************** */
95 asg::AnaToolHandle<TrigConf::ITrigConfigTool> trigConfTool("TrigConf::xAODConfigTool/TrigConfig");
96 if(trigConfTool.initialize() != StatusCode::SUCCESS)
97 {
98 Error(MSGSOURCE, "Unable to initialize the trigger config tool!");
99 return 3;
100 }
101 asg::AnaToolHandle<Trig::TrigDecisionTool> trigDecTool("Trig::TrigDecisionTool/TrigDecision");
102 trigDecTool.setProperty("ConfigTool", trigConfTool.getHandle()).ignore();
103 trigDecTool.setProperty("TrigDecisionKey", "xTrigDecision").ignore();
104 if(trigDecTool.initialize() != StatusCode::SUCCESS)
105 {
106 Error(MSGSOURCE, "Unable to initialize the trigger matching tool!");
107 return 3;
108 }
109 asg::AnaToolHandle<Trig::IMatchingTool> trigMatchTool("Trig::MatchingTool/TrigMatch");
110 trigMatchTool.setProperty("TrigDecisionTool", trigDecTool.getHandle()).ignore();
111 if(trigMatchTool.initialize() != StatusCode::SUCCESS)
112 {
113 Error(MSGSOURCE, "Unable to initialize the trigger matching tool!");
114 return 3;
115 }
116
117 /* ********************************************************************** */
118
119 Info(MSGSOURCE, "Configuring the global trigger SF tool");
120 asg::AnaToolHandle<ITrigGlobalEfficiencyCorrectionTool> myTool("TrigGlobalEfficiencyCorrectionTool/TrigGlobal");
121 const char* triggers2015 =
122 "mu20_iloose_L1MU15_OR_mu50"
123 "|| mu18_mu8noL1"
124 "|| e24_lhmedium_L1EM20VH_OR_e60_lhmedium_OR_e120_lhloose"
125 "|| 2e12_lhloose_L12EM10VH";
126 myTool.setProperty("TriggerCombination2015", triggers2015).ignore();
127 const char* triggers2016 =
128 "mu26_ivarmedium_OR_mu50"
129 "|| mu22_mu8noL1"
130 "|| e26_lhtight_nod0_ivarloose_OR_e60_lhmedium_nod0_OR_e140_lhloose_nod0"
131 "|| 2e17_lhvloose_nod0";
132 myTool.setProperty("TriggerCombination2016", triggers2016).ignore();
133 myTool.setProperty("TriggerMatchingTool", trigMatchTool.getHandle()).ignore();
134 if(debug) myTool.setProperty("OutputLevel", MSG::DEBUG).ignore();
135 if(myTool.initialize() != StatusCode::SUCCESS)
136 {
137 Error(MSGSOURCE, "Unable to initialize the TrigGlob tool!");
138 return 3;
139 }
140
143 const unsigned periodRuns[] = {
144 276073, 278727, 279932, 280423, 281130, 282625,
145 296939, 300345, 301912, 302737, 303638, 303943, 305291, 307124,
146 305359, 309311, 310015
147 };
148 std::uniform_int_distribution<unsigned> uniformPdf(0,
149 sizeof(periodRuns)/sizeof(*periodRuns) - 1);
150 std::default_random_engine randomEngine;
151
152 static const SG::ConstAccessor<int> truthType("truthType");
153 static const SG::ConstAccessor<int> truthOrigin("truthOrigin");
154
155 /* ********************************************************************** */
156
157 Info(MSGSOURCE, "Starting the event loop");
158 unsigned errors = 0;
159 double nSuitableEvents = 0., nMatched = 0.;
160 static const SG::Decorator<unsigned> RandomRunNumberDec("RandomRunNumber");
161 for(Long64_t entry = 0; entry < entries; ++entry)
162 {
163 event.getEntry(entry);
164
166 const xAOD::EventInfo* eventInfo = nullptr;
167 event.retrieve(eventInfo,"EventInfo").ignore();
168 unsigned runNumber = periodRuns[uniformPdf(randomEngine)];
169 RandomRunNumberDec(*eventInfo) = runNumber;
170 vector<const xAOD::Electron*> myTriggeringElectrons;
171 const xAOD::ElectronContainer* electrons = nullptr;
172 event.retrieve(electrons,"Electrons").ignore();
173 for(auto electron : *electrons)
174 {
175 if(!electron->caloCluster()) continue;
176 float eta = fabs(electron->caloCluster()->etaBE(2));
177 float pt = electron->pt();
178 if(pt<10e3f || eta>=2.47) continue;
179 if(!truthType.isAvailable(*electron)) continue;
180 if(!truthOrigin.isAvailable(*electron)) continue;
181 int t = truthType(*electron), o = truthOrigin(*electron);
182 if(t!=2 || !(o==10 || (o>=12 && o<=22) || o==43)) continue;
183 myTriggeringElectrons.push_back(electron);
184 }
185
186 vector<const xAOD::Muon*> myTriggeringMuons;
187 const xAOD::MuonContainer* muons = nullptr;
188 event.retrieve(muons,"Muons").ignore();
189 for(auto muon : *muons)
190 {
191 float pt = muon->pt();
192 if(pt<10e3f || fabs(muon->eta())>=2.5) continue;
193 auto mt = muon->muonType();
194 if(mt!=xAOD::Muon::Combined && mt!=xAOD::Muon::MuonStandAlone) continue;
195 auto& mtp = *(muon->primaryTrackParticle());
196 if(!truthType.isAvailable(mtp)) continue;
197 if(!truthOrigin.isAvailable(mtp)) continue;
198 int t = truthType(mtp), o = truthOrigin(mtp);
199 if(t!=6 || !(o==10 || (o>=12 && o<=22) || o==43)) continue;
200 myTriggeringMuons.push_back(muon);
201 }
203 if(myTriggeringElectrons.size()+myTriggeringMuons.size() < 1) continue;
204 nSuitableEvents += 1;
205
206 bool matched = false;
207 if(myTool->checkTriggerMatching(matched, myTriggeringElectrons, myTriggeringMuons) != CP::CorrectionCode::Ok)
208 {
209 Error(MSGSOURCE, "trigger matching could not be checked, interrupting execution");
210 ++errors;
211 break;
212 }
213
214 if(matched) nMatched += 1;
215 }
216
217 if(errors < nSuitableEvents)
218 {
219 Info(MSGSOURCE, "Fraction of trigger-matched events: %f (over %ld events)",
220 nMatched / nSuitableEvents, long(nSuitableEvents));
221 }
222
223 #ifndef XAOD_STANDALONE
224 ANA_CHECK(app->finalize());
225 #endif
226 return errors? 4 : 0;
227}
228
Scalar eta() const
pseudorapidity method
Base class for elements of a container that can have aux data.
Helper class to provide constant type-safe access to aux data.
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
Helper class to provide type-safe access to aux data.
const bool debug
@ Ok
The correction was done successfully.
Helper class to provide constant type-safe access to aux data.
Helper class to provide type-safe access to aux data.
Definition Decorator.h:59
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
Tool for accessing xAOD files outside of Athena.
@ kClassAccess
Access auxiliary data using the aux containers.
A relatively simple transient store for objects created in analysis.
Definition TStore.h:45
int main()
Definition hello.cxx:18
double entries
Definition listroot.cxx:49
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
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
EventInfo_v1 EventInfo
Definition of the latest event info version.
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
#define MSGSOURCE
Test code to test ElectronPhotonVariableCorrectionTool Dictionaries.
TFile * file