<key in map file>, <PID WP>, <iso WP> Single electron trigger, only for the leading electron ("Signal")
Safer to retrieve the name from the final ToolHandle, it might be prefixed (by the parent tool name) when the handle is copied
Uniform random run number generation spanning the target dataset. In real life, use the PileupReweightingTool instead!
Let's pretend that the leading electron passes TightLH+isolation, thus the event passes the selection; now we tag the electrons:
Leading electron tagged as 'Signal' -> decorated value set to 1 Subleading electron(s) not tagged -> decorated value set to 0
98{
101 bool debug =
false, cmdline_error =
false, toys =
false;
103 {
104 if(
string(argv[i]) ==
"--debug")
debug =
true;
105 else if(string(argv[i]) == "--toys") toys = true;
107 else cmdline_error = true;
108 }
109 if(!filename || cmdline_error)
110 {
112 Error(
MSGSOURCE,
" Usage: %s [--debug] [--toys] [DxAOD file name]", argv[0]);
113 return 1;
114 }
115 #ifdef XAOD_STANDALONE
117 TFile*
file = TFile::Open(filename,
"READ");
119 {
121 return 2;
122 }
125 StatusCode::enableFailure();
126 #else
129 TString
file(filename);
130 #endif
131 event.readFrom(
file).ignore();
132 Long64_t
entries =
event.getEntries();
134
135
136
139 ToolHandleArray<IAsgElectronEfficiencyCorrectionTool> electronEffTools;
141 ToolHandleArray<IAsgElectronEfficiencyCorrectionTool> electronSFTools;
143 std::map<std::string,std::string> legsPerTool;
145 std::map<std::string,std::string> tagsPerTool;
147 std::map<std::string,std::string> legsPerTag;
151 std::bernoulli_distribution bernoulliPdf(0.9);
152
154 vector<asg::AnaToolHandle<IAsgElectronEfficiencyCorrectionTool>> factory;
155 enum{ cLEGS, cTAG, cKEY, cPID, cISO };
156 std::vector<std::array<std::string,5> > toolConfigs = {
159 {"e24_lhmedium_L1EM20VH_OR_e60_lhmedium_OR_e120_lhloose", "Signal", "2015_e24_lhmedium_L1EM20VH_OR_e60_lhmedium_OR_e120_lhloose", "Tight", "FixedCutTightTrackOnly"},
161 {"e12_lhloose_L1EM10VH", "Signal", "2015_e12_lhloose_L1EM10VH", "Tight", "FixedCutTightTrackOnly"},
163 {"e12_lhloose_L1EM10VH", "*", "2015_e12_lhloose_L1EM10VH", "LooseBLayer", ""}
164 };
165
166 const char* mapPath = "ElectronEfficiencyCorrection/2015_2017/"
167 "rel21.2/Moriond_February2018_v2/map6.txt";
168 for(auto& cfg : toolConfigs)
169 for(int j=0;j<2;++j)
170 {
171 string name =
"AsgElectronEfficiencyCorrectionTool/"
172 + ((j? "ElTrigEff_" : "ElTrigSF_")
173 + std::to_string(factory.size()/2));
174 auto t = factory.emplace(factory.end(), name);
175 t->setProperty(
"MapFilePath", mapPath).ignore();
176 t->setProperty(
"TriggerKey",
string(j?
"":
"Eff_") + cfg[cKEY]).ignore();
177 t->setProperty(
"IdKey", cfg[cPID]).ignore();
178 t->setProperty(
"IsoKey", cfg[cISO]).ignore();
179
180 t->setProperty(
"CorrelationModel",
"TOTAL").ignore();
182 if(
t->initialize() != StatusCode::SUCCESS)
183 {
184 Error(
MSGSOURCE,
"Unable to initialize the electron CP tool <%s>!",
186 return 3;
187 }
188 auto& handles = (j? electronSFTools : electronEffTools);
189 handles.push_back(
t->getHandle());
192 name = handles[handles.size()-1].name();
193 legsPerTool[
name] =
cfg[cLEGS];
195 if(!j)
196 {
197 for(auto& tag : ::split_comma_delimited(cfg[cTAG]))
198 {
199 if(legsPerTag[tag]==
"") legsPerTag[
tag] =
cfg[cLEGS];
200 else legsPerTag[
tag] +=
"," +
cfg[cLEGS];
201 }
202 }
203
204 }
205
206
207
210 myTool.setProperty("ElectronEfficiencyTools", electronEffTools).ignore();
211 myTool.setProperty("ElectronScaleFactorTools", electronSFTools).ignore();
212 const char* triggers2015 =
213 "e24_lhmedium_L1EM20VH_OR_e60_lhmedium_OR_e120_lhloose"
214 "|| 2e12_lhloose_L12EM10VH";
215 myTool.setProperty("TriggerCombination2015", triggers2015).ignore();
216 myTool.setProperty("LeptonTagDecorations", "Signal").ignore();
217 myTool.setProperty("ListOfLegsPerTool", legsPerTool).ignore();
218 myTool.setProperty("ListOfTagsPerTool", tagsPerTool).ignore();
219 myTool.setProperty("ListOfLegsPerTag", legsPerTag).ignore();
220
221 if(
debug) myTool.setProperty(
"OutputLevel", MSG::DEBUG).ignore();
222 if(toys) myTool.setProperty("NumberOfToys", 1000).ignore();
223 if(myTool.initialize() != StatusCode::SUCCESS)
224 {
226 return 3;
227 }
228
231 const unsigned periodRuns[] = {
233 276073, 278727, 279932, 280423, 281130, 282625
234 };
235 std::uniform_int_distribution<unsigned> uniformPdf(0,
236 sizeof(periodRuns)/sizeof(*periodRuns) - 1);
237 std::default_random_engine randomEngine;
238
241
242
243
246 double nSuitableEvents = 0., sumW = 0.;
249 {
250 event.getEntry(entry);
251
254 event.retrieve(eventInfo,"EventInfo").ignore();
255 unsigned runNumber = periodRuns[uniformPdf(randomEngine)];
256 RandomRunNumberDec(*eventInfo) =
runNumber;
257 vector<const xAOD::Electron*> myTriggeringElectrons;
259 event.retrieve(electrons,"Electrons").ignore();
260 for(auto electron : *electrons)
261 {
262 if(!
electron->caloCluster())
continue;
263 float eta = fabs(
electron->caloCluster()->etaBE(2));
265 if(pt<10e3f || eta>=2.47) continue;
266 if(!
truthType.isAvailable(*electron))
continue;
269 if(t!=2 || !(o==10 || (o>=12 && o<=22) || o==43)) continue;
271 if(pt < 13e3f) continue;
272
273 myTriggeringElectrons.push_back(electron);
274 }
275
276 vector<const xAOD::Muon*> myTriggeringMuons;
277
278 if(myTriggeringElectrons.size() < 1) continue;
279
283 {
return e1->pt() <
e2->pt(); };
284 auto leadingElectron = *std::max_element(myTriggeringElectrons.begin(),
285 myTriggeringElectrons.end(), compareByPt);
286 for(auto electron : myTriggeringElectrons)
287 {
290 dec_signal(*electron) = (
electron==leadingElectron)? 1 : 0;
291 }
292
294 if(leadingElectron->pt() < 25e3f
295 && myTriggeringElectrons.size() < 2)
296 {
297 continue;
298 }
299
300
303 auto cc = myTool->getEfficiencyScaleFactor(myTriggeringElectrons,
304 myTriggeringMuons, sf);
306 {
307 nSuitableEvents += 1;
309 }
310 else
311 {
312 Warning(
MSGSOURCE,
"Scale factor evaluation failed");
314 }
315 if(errors>10)
316 {
318 break;
319 }
320 }
321 Info(
MSGSOURCE,
"Average scale factor: %f (over %ld events)",
322 sumW / nSuitableEvents, long(nSuitableEvents));
323 #ifndef XAOD_STANDALONE
325 #endif
327}
Scalar eta() const
pseudorapidity method
@ 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.
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.
int truthOrigin(const U &p)
int truthType(const U &p)
Error
The different types of error that can be flagged in the L1TopoRDO.
IAppMgrUI * Init(const char *options="POOLRootAccess/basic.opts")
Bootstraps (creates and configures) the Gaudi Application with the provided options file.
double e2(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 2nd sampling
double e1(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 1st sampling
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
EventInfo_v1 EventInfo
Definition of the latest event info version.
Electron_v1 Electron
Definition of the current "egamma version".