55int main(
int argc,
char* argv[])
58 const char* filename =
nullptr;
59 bool debug =
false,
fast =
false, cmdline_error =
false;
60 for(
int i=1;i<argc;++i)
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;
67 if(!filename || cmdline_error)
69 Error(
MSGSOURCE,
"No file name received!");
70 Error(
MSGSOURCE,
" Usage: %s [--debug] [--fast] [DxAOD file name]", argv[0]);
73 #ifdef XAOD_STANDALONE
75 TFile*
file = TFile::Open(filename,
"READ");
83 StatusCode::enableFailure();
87 TString
file(filename);
89 event.readFrom(
file).ignore();
90 Long64_t
entries =
event.getEntries();
96 if(trigConfTool.
initialize() != StatusCode::SUCCESS)
98 Error(
MSGSOURCE,
"Unable to initialize the trigger config tool!");
103 trigDecTool.
setProperty(
"TrigDecisionKey",
"xTrigDecision").ignore();
104 if(trigDecTool.
initialize() != StatusCode::SUCCESS)
106 Error(
MSGSOURCE,
"Unable to initialize the trigger matching tool!");
111 if(trigMatchTool.
initialize() != StatusCode::SUCCESS)
113 Error(
MSGSOURCE,
"Unable to initialize the trigger matching tool!");
119 Info(
MSGSOURCE,
"Configuring the global trigger SF tool");
121 const char* triggers2015 =
122 "mu20_iloose_L1MU15_OR_mu50"
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"
130 "|| e26_lhtight_nod0_ivarloose_OR_e60_lhmedium_nod0_OR_e140_lhloose_nod0"
131 "|| 2e17_lhvloose_nod0";
132 myTool.
setProperty(
"TriggerCombination2016", triggers2016).ignore();
135 if(myTool.
initialize() != StatusCode::SUCCESS)
137 Error(
MSGSOURCE,
"Unable to initialize the TrigGlob tool!");
143 const unsigned periodRuns[] = {
144 276073, 278727, 279932, 280423, 281130, 282625,
145 296939, 300345, 301912, 302737, 303638, 303943, 305291, 307124,
146 305359, 309311, 310015
148 std::uniform_int_distribution<unsigned> uniformPdf(0,
149 sizeof(periodRuns)/
sizeof(*periodRuns) - 1);
150 std::default_random_engine randomEngine;
157 Info(
MSGSOURCE,
"Starting the event loop");
159 double nSuitableEvents = 0., nMatched = 0.;
161 const std::string evInfoStr{
"EventInfo"};
162 const std::string electronsStr{
"Electrons"};
163 const std::string muonsStr{
"Muons"};
164 for(Long64_t entry = 0; entry <
entries; ++entry)
166 event.getEntry(entry);
170 event.retrieve(eventInfo,evInfoStr).ignore();
171 unsigned runNumber = periodRuns[uniformPdf(randomEngine)];
172 RandomRunNumberDec(*eventInfo) = runNumber;
173 vector<const xAOD::Electron*> myTriggeringElectrons;
175 event.retrieve(electrons,electronsStr).ignore();
176 for(
auto electron : *electrons)
178 if(!electron->caloCluster())
continue;
179 float eta = fabs(electron->caloCluster()->etaBE(2));
180 float pt = electron->pt();
181 if(pt<10e3f || eta>=2.47)
continue;
182 if(!truthType.isAvailable(*electron))
continue;
183 if(!truthOrigin.isAvailable(*electron))
continue;
184 int t = truthType(*electron), o = truthOrigin(*electron);
185 if(t!=2 || !(o==10 || (o>=12 && o<=22) || o==43))
continue;
186 myTriggeringElectrons.push_back(electron);
189 vector<const xAOD::Muon*> myTriggeringMuons;
191 event.retrieve(muons,muonsStr).ignore();
192 for(
auto muon : *muons)
194 float pt = muon->pt();
195 if(pt<10e3f || fabs(muon->eta())>=2.5)
continue;
196 auto mt = muon->muonType();
197 if(mt!=xAOD::Muon::MuonType::Combined && mt!=xAOD::Muon::MuonType::MuonStandAlone)
continue;
198 auto& mtp = *(muon->trackParticle(xAOD::Muon::TrackParticleType::Primary));
199 if(!truthType.isAvailable(mtp))
continue;
200 if(!truthOrigin.isAvailable(mtp))
continue;
201 int t = truthType(mtp), o = truthOrigin(mtp);
202 if(t!=6 || !(o==10 || (o>=12 && o<=22) || o==43))
continue;
203 myTriggeringMuons.push_back(muon);
206 if(myTriggeringElectrons.size()+myTriggeringMuons.size() < 1)
continue;
207 nSuitableEvents += 1;
209 bool matched =
false;
210 if(myTool->checkTriggerMatching(matched, myTriggeringElectrons, myTriggeringMuons) !=
CP::CorrectionCode::Ok)
212 Error(
MSGSOURCE,
"trigger matching could not be checked, interrupting execution");
217 if(matched) nMatched += 1;
220 if(nSuitableEvents!= 0 && errors < nSuitableEvents)
222 Info(
MSGSOURCE,
"Fraction of trigger-matched events: %f (over %ld events)",
223 nMatched / nSuitableEvents,
long(nSuitableEvents));
226 #ifndef XAOD_STANDALONE
229 return errors? 4 : 0;