65 #ifdef XAOD_STANDALONE
97 namespace {
vector<string> split_comma_delimited(
const std::string&); }
99 #define MSGSOURCE "Example 3a"
103 using namespace Test;
108 bool debug =
false, cmdline_error =
false, toys =
false;
111 if(
string(
argv[
i]) ==
"--debug")
debug =
true;
112 else if(
string(
argv[
i]) ==
"--toys") toys =
true;
114 else cmdline_error =
true;
122 #ifdef XAOD_STANDALONE
132 StatusCode::enableFailure();
138 event.readFrom(
file).ignore();
139 Long64_t
entries =
event.getEntries();
144 Info(
MSGSOURCE,
"Configuring the electron CP tools");
146 ToolHandleArray<IAsgElectronEfficiencyCorrectionTool> electronEffTools;
148 ToolHandleArray<IAsgElectronEfficiencyCorrectionTool> electronSFTools;
150 std::map<std::string,std::string> legsPerTool;
152 std::map<std::string,std::string> tagsPerTool;
154 std::map<std::string,std::string> legsPerTag;
159 vector<asg::AnaToolHandle<IAsgElectronEfficiencyCorrectionTool>> factory;
160 enum{ cLEGS, cTAG, cKEY, cPID, cISO };
161 std::vector<std::array<std::string,5> > toolConfigs = {
164 {
"e12_lhloose_L1EM10VH",
"Signal",
"2015_e12_lhloose_L1EM10VH",
"Tight",
"FixedCutTightTrackOnly"},
166 {
"e12_lhloose_L1EM10VH",
"*",
"2015_e12_lhloose_L1EM10VH",
"LooseBLayer",
""}
169 const char* mapPath =
"ElectronEfficiencyCorrection/2015_2017/"
170 "rel21.2/Moriond_February2018_v2/map6.txt";
171 for(
auto&
cfg : toolConfigs)
174 string name =
"AsgElectronEfficiencyCorrectionTool/"
175 + ((j?
"ElTrigEff_" :
"ElTrigSF_")
177 auto t = factory.emplace(factory.end(),
name);
178 t->setProperty(
"MapFilePath", mapPath).ignore();
179 t->setProperty(
"TriggerKey",
string(j?
"":
"Eff_") +
cfg[cKEY]).
ignore();
180 t->setProperty(
"IdKey",
cfg[cPID]).ignore();
181 t->setProperty(
"IsoKey",
cfg[cISO]).ignore();
183 t->setProperty(
"CorrelationModel",
"TOTAL").ignore();
185 if(
t->initialize() != StatusCode::SUCCESS)
187 Error(
MSGSOURCE,
"Unable to initialize the electron CP tool <%s>!",
191 auto& handles = (j? electronSFTools : electronEffTools);
192 handles.push_back(
t->getHandle());
195 name = handles[handles.size()-1].name();
196 legsPerTool[
name] =
cfg[cLEGS];
200 for(
auto&
tag : ::split_comma_delimited(
cfg[cTAG]))
202 if(legsPerTag[
tag]==
"") legsPerTag[
tag] =
cfg[cLEGS];
203 else legsPerTag[
tag] +=
"," +
cfg[cLEGS];
211 Info(
MSGSOURCE,
"Configuring the global trigger SF tool");
213 myTool.
setProperty(
"ElectronEfficiencyTools", electronEffTools).ignore();
214 myTool.
setProperty(
"ElectronScaleFactorTools", electronSFTools).ignore();
215 const char* triggers2015 =
"2e12_lhloose_L12EM10VH";
216 myTool.
setProperty(
"TriggerCombination2015", triggers2015).ignore();
217 myTool.
setProperty(
"LeptonTagDecorations",
"Signal").ignore();
218 myTool.
setProperty(
"ListOfLegsPerTool", legsPerTool).ignore();
219 myTool.
setProperty(
"ListOfTagsPerTool", tagsPerTool).ignore();
220 myTool.
setProperty(
"ListOfLegsPerTag", legsPerTag).ignore();
223 if(toys) myTool.
setProperty(
"NumberOfToys", 1000).ignore();
224 if(myTool.
initialize() != StatusCode::SUCCESS)
232 const unsigned periodRuns[] = {
234 276073, 278727, 279932, 280423, 281130, 282625
236 std::uniform_int_distribution<unsigned> uniformPdf(0,
237 sizeof(periodRuns)/
sizeof(*periodRuns) - 1);
238 std::default_random_engine randomEngine;
245 Info(
MSGSOURCE,
"Starting the event loop");
247 double nSuitableEvents = 0., sumW = 0.;
251 event.getEntry(
entry);
255 event.retrieve(eventInfo,
"EventInfo").ignore();
256 unsigned runNumber = periodRuns[uniformPdf(randomEngine)];
257 RandomRunNumberDec(*eventInfo) =
runNumber;
258 vector<const xAOD::Electron*> myTriggeringElectrons;
260 event.retrieve(
electrons,
"Electrons").ignore();
263 if(!
electron->caloCluster())
continue;
264 float eta = fabs(
electron->caloCluster()->etaBE(2));
266 if(pt<10e3f || eta>=2.47)
continue;
270 if(
t!=2 || !(o==10 || (o>=12 && o<=22) || o==43))
continue;
272 if(
pt < 13e3f)
continue;
274 myTriggeringElectrons.push_back(
electron);
277 vector<const xAOD::Muon*> myTriggeringMuons;
280 if(myTriggeringElectrons.size() < 2)
continue;
285 {
return e1->pt() <
e2->pt(); };
286 auto leadingElectron = *std::max_element(myTriggeringElectrons.begin(),
287 myTriggeringElectrons.end(), compareByPt);
288 for(
auto electron : myTriggeringElectrons)
299 myTriggeringMuons,
sf);
302 nSuitableEvents += 1;
307 Warning(
MSGSOURCE,
"Scale factor evaluation failed");
316 Info(
MSGSOURCE,
"Average scale factor: %f (over %ld events)",
317 sumW / nSuitableEvents,
long(nSuitableEvents));
318 #ifndef XAOD_STANDALONE
329 std::stringstream
ss(
s);
330 std::vector<std::string>
tokens;
332 while(std::getline(
ss, token,
','))
334 if(token.length())
tokens.push_back(token);