Uniform random run number generation spanning the target dataset. In real life, use the PileupReweightingTool instead!
54{
57 bool debug =
false, cmdline_error =
false, toys =
false;
59 {
60 if(
string(argv[i]) ==
"--debug")
debug =
true;
61 else if(string(argv[i]) == "--toys") toys = true;
63 else cmdline_error = true;
64 }
65 if(!filename || cmdline_error)
66 {
68 Error(
MSGSOURCE,
" Usage: %s [--debug] [--toys] [DxAOD file name]", argv[0]);
69 return 1;
70 }
71 #ifdef XAOD_STANDALONE
73 TFile*
file = TFile::Open(filename,
"READ");
75 {
77 return 2;
78 }
81 StatusCode::enableFailure();
82 #else
85 TString
file(filename);
86 #endif
87 event.readFrom(
file).ignore();
88 Long64_t
entries =
event.getEntries();
90
91
92
95 ToolHandleArray<IAsgElectronEfficiencyCorrectionTool> electronEffTools;
97 ToolHandleArray<IAsgElectronEfficiencyCorrectionTool> electronSFTools;
99 vector<asg::AnaToolHandle<IAsgElectronEfficiencyCorrectionTool>> factory;
100 const char* mapPath = "ElectronEfficiencyCorrection/2015_2017/"
101 "rel21.2/Consolidation_September2018_v1/map1.txt";
102 for(int j=0;j<2;++j)
103 {
104 string name =
"AsgElectronEfficiencyCorrectionTool/"
105 + ((j? "ElTrigEff_" : "ElTrigSF_")
106 + std::to_string(factory.size()/2));
107 auto t = factory.emplace(factory.end(), name);
108 t->setProperty(
"MapFilePath", mapPath).ignore();
109 t->setProperty(
"TriggerKey",
string(j?
"":
"Eff_")
110 + "SINGLE_E_2015_e24_lhmedium_L1EM20VH_OR_e60_lhmedium_OR_e120_lhloose_2016_2018_e26_lhtight_nod0_ivarloose_OR_e60_lhmedium_nod0_OR_e140_lhloose_nod0").ignore();
111 t->setProperty(
"IdKey",
"Tight").ignore();
112 t->setProperty(
"IsoKey",
"FCTight").ignore();
113 t->setProperty(
"CorrelationModel",
"TOTAL").ignore();
115 if(
t->initialize() != StatusCode::SUCCESS)
116 {
117 Error(
MSGSOURCE,
"Unable to initialize the electron CP tool <%s>!",
119 return 3;
120 }
121 auto& handles = (j? electronSFTools : electronEffTools);
122 handles.push_back(
t->getHandle());
123 }
124
125
126
129 ToolHandleArray<CP::IMuonTriggerScaleFactors> muonTools;
131 muonTool.setProperty("MuonQuality", "Tight").ignore();
132 muonTool.setProperty("useRel207", false).ignore();
133 if(muonTool.initialize() != StatusCode::SUCCESS)
134 {
136 return 3;
137 }
138 muonTools.push_back(muonTool.getHandle());
139
140
141
144 myTool.setProperty("ElectronEfficiencyTools", electronEffTools).ignore();
145 myTool.setProperty("ElectronScaleFactorTools", electronSFTools).ignore();
146 myTool.setProperty("MuonTools", muonTools).ignore();
147 const char* triggers2015 =
148 "mu20_iloose_L1MU15_OR_mu50"
149 "|| e24_lhmedium_L1EM20VH_OR_e60_lhmedium_OR_e120_lhloose";
150 myTool.setProperty("TriggerCombination2015", triggers2015).ignore();
151 const char* triggers2016to2018 =
152 "mu26_ivarmedium_OR_mu50"
153 "|| e26_lhtight_nod0_ivarloose_OR_e60_lhmedium_nod0_OR_e140_lhloose_nod0";
154 myTool.setProperty("TriggerCombination2016", triggers2016to2018).ignore();
155 myTool.setProperty("TriggerCombination2017", triggers2016to2018).ignore();
156 myTool.setProperty("TriggerCombination2018", triggers2016to2018).ignore();
157
158 if(
debug) myTool.setProperty(
"OutputLevel", MSG::DEBUG).ignore();
159 if(toys) myTool.setProperty("NumberOfToys", 1000).ignore();
160 if(myTool.initialize() != StatusCode::SUCCESS)
161 {
163 return 3;
164 }
165
168 const unsigned periodRuns[] = {
170 276073, 278727, 279932, 280423, 281130, 282625,
172 296939, 300345, 301912, 302737, 303638, 303943, 305291, 307124,
173 305359, 309311, 310015,
175 325713, 329385, 330857, 332720, 334842, 336497, 336832, 338183,
177 348885, 349534, 350310, 352274, 354107, 354826, 355261, 355331,
178 355529, 357050, 359191, 361635, 361738, 363664
179 };
180 std::uniform_int_distribution<unsigned> uniformPdf(0,
181 sizeof(periodRuns)/sizeof(*periodRuns) - 1);
182 std::default_random_engine randomEngine;
183
186
187
188
191 double nSuitableEvents = 0., sumW = 0.;
194 {
195 event.getEntry(entry);
196
199 event.retrieve(eventInfo,"EventInfo").ignore();
200 unsigned runNumber = periodRuns[uniformPdf(randomEngine)];
201 RandomRunNumberDec(*eventInfo) =
runNumber;
202 vector<const xAOD::Electron*> myTriggeringElectrons;
204 event.retrieve(electrons,"Electrons").ignore();
205 for(auto electron : *electrons)
206 {
207 if(!
electron->caloCluster())
continue;
208 float eta = fabs(
electron->caloCluster()->etaBE(2));
210 if(pt<10e3f || eta>=2.47) continue;
211 if(!
truthType.isAvailable(*electron))
continue;
214 if(t!=2 || !(o==10 || (o>=12 && o<=22) || o==43)) continue;
216 if(pt < (runNumber>290000? 27e3f : 25e3f)) continue;
217
218 myTriggeringElectrons.push_back(electron);
219 }
220
221 vector<const xAOD::Muon*> myTriggeringMuons;
223 event.retrieve(muons,"Muons").ignore();
224 for(auto muon : *muons)
225 {
227 if(pt<10e3f || fabs(
muon->eta())>=2.5)
continue;
228 auto mt =
muon->muonType();
229 if(mt!=xAOD::Muon::Combined && mt!=xAOD::Muon::MuonStandAlone) continue;
230 auto& mtp = *(
muon->primaryTrackParticle());
231 if(!
truthType.isAvailable(mtp))
continue;
234 if(t!=6 || !(o==10 || (o>=12 && o<=22) || o==43)) continue;
236 if(pt < (runNumber>290000? 27.3e3f : 21e3f)) continue;
237
238 myTriggeringMuons.push_back(muon);
239 }
240
242 if(myTriggeringElectrons.size()+myTriggeringMuons.size() < 1) continue;
243
244
247 auto cc = myTool->getEfficiencyScaleFactor(myTriggeringElectrons,
248 myTriggeringMuons, sf);
250 {
251 nSuitableEvents += 1;
253 }
254 else
255 {
256 Warning(
MSGSOURCE,
"Scale factor evaluation failed");
258 }
259 if(errors>10)
260 {
262 break;
263 }
264 }
265 Info(
MSGSOURCE,
"Average scale factor: %f (over %ld events)",
266 sumW / nSuitableEvents, long(nSuitableEvents));
267 #ifndef XAOD_STANDALONE
269 #endif
271}
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.
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.
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".