149 std::unordered_map<std::string, TrigGlobEffCorr::ImportData::TrigDef> triggerDefs;
151 auto it = triggerDict.find(kv.first);
152 if (
it != triggerDict.end()) {
153 triggerDefs[
it->second] = kv.second;
156 auto getTriggerLegs =
157 [&](std::unordered_map<std::string, std::vector<std::pair<std::string, int> > >
const& triggerCombination,
158 std::unordered_map<std::string, std::set<std::string> >& electronLegsByPeriod,
159 std::unordered_map<std::string, std::set<std::string> >& photonLegsByPeriod) {
160 for (
auto&& kv : triggerCombination) {
161 std::string
const&
period = kv.first;
162 for (
auto const& trigKey : kv.second) {
163 auto triggerDefsIt = triggerDefs.find(trigKey.first);
164 if (triggerDefsIt == triggerDefs.end()) {
166 ATH_MSG_ERROR(
"unrecognized trigger `" << trigKey.first <<
"'");
169 auto const& trigDef = triggerDefsIt->second;
170 for (
auto const&
leg : trigDef.leg) {
172 std::string
const& legname = triggerDict.at(
leg);
177 ATH_MSG_ERROR(
"could not determine object type for trigger leg `" << legname <<
183 electronLegsByPeriod[
period].insert(legname);
190 photonLegsByPeriod[
period].insert(legname);
196 "trigger leg `" << legname <<
"' has unsupported object type `" << legtype <<
"'");
205 std::map<std::string, std::string> triggerCombination, triggerCombinationLoose;
206 std::vector<std::string> electronSystematics, muonSystematics, photonSystematics, electronToolNames, muonToolNames, photonToolNames;
207 std::unordered_map<std::string, std::vector<std::pair<std::string, int> > >
const emptymap;
208 std::unordered_map<std::string, std::vector<std::pair<std::string, int> > >
const&
209 triggersByPeriod = (
m_config->doTightEvents() ?
m_config->getGlobalTriggers() : emptymap),
210 triggersByPeriodLoose = (
m_config->doLooseEvents() ?
m_config->getGlobalTriggersLoose() : emptymap);
212 std::unordered_map<std::string, std::set<std::string> > electronLegsByPeriod, electronLegsByPeriodLoose, photonLegsByPeriod, photonLegsByPeriodLoose;
213 getTriggerLegs(triggersByPeriod, electronLegsByPeriod, photonLegsByPeriod);
214 getTriggerLegs(triggersByPeriodLoose, electronLegsByPeriodLoose, photonLegsByPeriodLoose);
217 std::string electronID, electronIDLoose, electronIsolation, electronIsolationLoose, muonQuality, muonQualityLoose;
218 std::string photonIso, photonIsoLoose;
220 electronID =
m_config->electronID();
221 electronIsolation =
m_config->electronIsolationSF();
222 muonQuality =
m_config->muonQuality();
223 photonIso =
m_config->photonIsolation();
226 electronIDLoose =
m_config->electronIDLoose();
227 electronIsolationLoose =
m_config->electronIsolationSFLoose();
228 muonQualityLoose =
m_config->muonQualityLoose();
229 photonIsoLoose =
m_config->photonIsolationLoose();
240 ToolHandleArray<IAsgElectronEfficiencyCorrectionTool> electronEffTools, electronSFTools, electronEffToolsLoose,
241 electronSFToolsLoose;
242 std::map<std::string, std::string> legsPerTool, legsPerToolLoose;
246 for (
auto& y_t : electronLegsByPeriod) {
247 std::string
year = y_t.first;
248 for (
auto& trigKey : y_t.second) {
250 for (
int j = 0; j < 2; ++j) {
251 ATH_MSG_INFO(
"TIGHT " <<
year <<
" " << trigKey <<
" " << electronID <<
" " << electronIsolation);
257 "ElectronEfficiencyCorrection/2015_2018/rel21.2/Precision_Summer2020_v1/map4.txt"),
261 (j ?
year +
"_" + trigKey :
"Eff_" +
year +
"_" + trigKey)),
262 "Failed to set TriggerKey");
263 if (electronID !=
"None")
top::check(
t->setProperty(
"IdKey", electronID),
"Failed to set IdKey");
264 if (electronIsolation !=
"None")
top::check(
t->setProperty(
"IsoKey",
265 electronIsolation),
"Failed to set IsoKey");
266 top::check(
t->setProperty(
"CorrelationModel",
"TOTAL"),
"Failed to set CorrelationModel");
269 top::check(
t->setProperty(
"OutputLevel", MSG::INFO),
"Failed to set OutputLevel");
270 top::check(
t->initialize(),
"Failed to initalise");
272 auto& handles = j ? electronSFTools : electronEffTools;
273 handles.push_back(
t->getHandle());
274 std::string
name = handles[handles.size() - 1].name();
275 legsPerTool[
name] = trigKey +
" [" +
year +
"]";
277 electronToolNames.push_back(
name);
279 if (electronSystematics.size() == 0 && j == 1) {
281 handles[handles.size() - 1]->recommendedSystematics().getBaseNames()) electronSystematics.push_back(
s);
290 for (
auto& y_t : electronLegsByPeriodLoose) {
291 std::string
year = y_t.first;
292 for (
auto& trigKey : y_t.second) {
294 for (
int j = 0; j < 2; ++j) {
295 ATH_MSG_INFO(
"LOOSE " <<
year <<
" " << trigKey <<
" " << electronIDLoose <<
" " << electronIsolationLoose);
301 "ElectronEfficiencyCorrection/2015_2018/rel21.2/Precision_Summer2020_v1/map4.txt"),
305 (j ?
year +
"_" + trigKey :
"Eff_" +
year +
"_" + trigKey)),
306 "Failed to set TriggerKey");
307 if (electronIDLoose !=
308 "None")
top::check(tLoose->setProperty(
"IdKey", electronIDLoose),
"Failed to set IdKey");
309 if (electronIsolationLoose !=
"None")
top::check(tLoose->setProperty(
"IsoKey",
310 electronIsolationLoose),
311 "Failed to set IsoKey");
312 top::check(tLoose->setProperty(
"CorrelationModel",
"TOTAL"),
"Failed to set CorrelationModel");
313 top::check(tLoose->setProperty(
"ForceDataType",
315 top::check(tLoose->setProperty(
"OutputLevel", MSG::INFO),
"Failed to set OutputLevel");
316 top::check(tLoose->initialize(),
"Failed to initalise");
318 auto& handlesLoose = j ? electronSFToolsLoose : electronEffToolsLoose;
319 handlesLoose.push_back(tLoose->getHandle());
320 std::string
name = handlesLoose[handlesLoose.size() - 1].name();
321 legsPerToolLoose[
name] = trigKey +
" [" +
year +
"]";
323 electronToolNames.push_back(
name);
325 if (electronSystematics.size() == 0 && j == 1) {
327 handlesLoose[handlesLoose.size() -
328 1]->recommendedSystematics().getBaseNames()) electronSystematics.push_back(
s);
335 ToolHandleArray<CP::IMuonTriggerScaleFactors> muonTools;
336 ToolHandleArray<CP::IMuonTriggerScaleFactors> muonToolsLoose;
340 muonQuality),
"Failed to set MuonQuality");
342 if (
m_config->muonSFCustomInputFolderTrigger() !=
" ") {
345 if (
m_config->muonForcePeriod() !=
" ") {
350 if (
m_config->muonForceYear() != -1) {
355 ATH_MSG_INFO(
"Muon tool name (tight) " << muonTools[muonTools.size() - 1].name());
356 muonToolNames.push_back(muonTools[muonTools.size() - 1].name());
358 if (muonSystematics.size() == 0) {
360 muonTools[muonTools.size() - 1]->recommendedSystematics().getBaseNames()) muonSystematics.push_back(
s);
367 "Failed to set MuonQuality");
369 if (
m_config->muonSFCustomInputFolderTrigger() !=
" ") {
374 ATH_MSG_INFO(
"Muon tool name (loose) " << muonToolsLoose[muonToolsLoose.size() - 1].name());
375 muonToolNames.push_back(muonToolsLoose[muonToolsLoose.size() - 1].name());
377 if (muonSystematics.size() == 0) {
378 for (
auto&
s: muonToolsLoose[muonToolsLoose.size() - 1]->recommendedSystematics().getBaseNames()) muonSystematics.push_back(
s);
383 ToolHandleArray<IAsgPhotonEfficiencyCorrectionTool> photonEffTools;
384 ToolHandleArray<IAsgPhotonEfficiencyCorrectionTool> photonSFTools;
385 ToolHandleArray<IAsgPhotonEfficiencyCorrectionTool> photonEffToolsLoose;
386 ToolHandleArray<IAsgPhotonEfficiencyCorrectionTool> photonSFToolsLoose;
388 const std::string photonKey =
PhotonKeys(triggersByPeriod);
389 const std::string photonKeyLoose =
PhotonKeys(triggersByPeriodLoose);
391 static const std::string mapPath =
"PhotonEfficiencyCorrection/2015_2018/rel21.2/Summer2020_Rec_v1/map2.txt";
392 if (photonKey !=
"" || photonKeyLoose !=
"") {
396 for (
auto& y_t : photonLegsByPeriod) {
397 const std::string
year = y_t.first;
398 for (
auto& trigKey : y_t.second) {
400 for(
int j=0;j<2;++j) {
401 const std::string nameTool =
"AsgPhotonEfficiencyCorrectionTool/" + std::string(j?
"PhTrigEff" :
"PhTrigSF") +
"_" +
std::to_string(nTools);
403 top::check(
t->setProperty(
"MapFilePath", mapPath.c_str()),
"Cannot set MapFilePath");
404 top::check(
t->setProperty(
"TriggerKey", std::string(j ?
"" :
"Eff_") + photonKey),
"Cannot set TriggerKey");
405 top::check(
t->setProperty(
"IsoKey", photonIso),
"Cannot set IsoKey");
407 top::check(
t->setProperty(
"OutputLevel", MSG::ERROR),
"Cannot set OutputLevel");
408 top::check(
t->initialize(),
"Cannot initialise the photon tools");
409 auto& photonHandles = (j? photonSFTools : photonEffTools);
410 photonHandles.push_back(
t->getHandle());
411 const std::string
name = photonHandles.back().name();
412 legsPerTool[
name] = trigKey +
" [" +
year +
"]";
413 photonToolNames.push_back(
name);
414 if (photonSystematics.size() == 0 && j == 1) {
415 for (
const auto&
s : photonHandles.back()->recommendedSystematics().getBaseNames()) {
416 photonSystematics.push_back(
s);
427 for (
auto& y_t : photonLegsByPeriodLoose) {
428 const std::string
year = y_t.first;
429 for (
auto& trigKey : y_t.second) {
431 for(
int j=0;j<2;++j) {
432 const std::string nameTool =
"AsgPhotonEfficiencyCorrectionTool/" + std::string(j?
"PhTrigEff" :
"PhTrigSF") +
"_" +
std::to_string(nTools);
434 top::check(tLoose->setProperty(
"MapFilePath", mapPath.c_str()),
"Cannot set MapFilePath");
435 top::check(tLoose->setProperty(
"TriggerKey", std::string(j ?
"" :
"Eff_") + photonKeyLoose),
"Cannot set TriggerKey");
436 top::check(tLoose->setProperty(
"IsoKey", photonIsoLoose),
"Cannot set IsoKey");
438 top::check(tLoose->setProperty(
"OutputLevel", MSG::ERROR),
"Cannot set OutputLevel");
439 top::check(tLoose->initialize(),
"Cannot initialise the photon tools");
440 auto& photonHandlesLoose = (j? photonSFToolsLoose : photonEffToolsLoose);
441 photonHandlesLoose.push_back(tLoose->getHandle());
442 const std::string
name = photonHandlesLoose.back().name();
443 legsPerToolLoose[
name] = trigKey +
" [" +
year +
"]";
444 photonToolNames.push_back(
name);
445 if (photonSystematics.size() == 0 && j == 1) {
446 for (
const auto&
s : photonHandlesLoose.back()->recommendedSystematics().getBaseNames()) {
447 photonSystematics.push_back(
s);
456 auto combineStrings = [](
const std::vector<std::pair<std::string, int> >&
input ) {
457 std::vector<std::string>
tmp;
458 for (
const auto&
i :
input) {
459 tmp.push_back(
i.first);
464 for (
auto&
key : triggersByPeriod) {
465 if (triggerCombination.find(
key.first) == triggerCombination.end()) {
466 triggerCombination[
key.first] =
"";
468 triggerCombination[
key.first] +=
" || ";
470 triggerCombination[
key.first] += combineStrings(
key.second);
472 for (
auto&
key : triggersByPeriodLoose) {
473 if (triggerCombinationLoose.find(
key.first) == triggerCombinationLoose.end()) {
474 triggerCombinationLoose[
key.first] =
"";
476 triggerCombinationLoose[
key.first] +=
" || ";
478 triggerCombinationLoose[
key.first] += combineStrings(
key.second);
482 for (
auto kv: triggerCombination)
ATH_MSG_DEBUG(
"TRIG (TIGHT): " << kv.first <<
" -> " << kv.second);
483 for (
auto kv: triggerCombinationLoose)
ATH_MSG_DEBUG(
"TRIG (LOOSE): " << kv.first <<
" -> " << kv.second);
488 top::check(globalTriggerEffTool->setProperty(
"ElectronEfficiencyTools", electronEffTools),
"Failed to attach electron efficiency tools");
489 top::check(globalTriggerEffTool->setProperty(
"ElectronScaleFactorTools", electronSFTools),
"Failed to attach electron scale factor tools");
490 top::check(globalTriggerEffTool->setProperty(
"MuonTools", muonTools),
"Failed to attach muon tools");
491 top::check(globalTriggerEffTool->setProperty(
"PhotonEfficiencyTools", photonEffTools),
"Failed to attach photon eff tools");
492 top::check(globalTriggerEffTool->setProperty(
"PhotonScaleFactorTools", photonSFTools),
"Failed to attach photon SF tools");
493 top::check(globalTriggerEffTool->setProperty(
"ListOfLegsPerTool", legsPerTool),
"Failed to define list of legs per tool");
494 top::check(globalTriggerEffTool->setProperty(
"TriggerCombination", triggerCombination),
"Failed to define trigger combination");
495 top::check(globalTriggerEffTool->setProperty(
"TriggerMatchingTool",
m_trigMatchTool),
"Failed to set TriggerMatchingTool");
497 top::check(globalTriggerEffTool->setProperty(
"OutputLevel", MSG::ERROR),
"Failed to set message level");
503 top::check(globalTriggerEffToolLoose->setProperty(
"ElectronEfficiencyTools", electronEffToolsLoose),
"Failed to attach electron efficiency tools");
504 top::check(globalTriggerEffToolLoose->setProperty(
"ElectronScaleFactorTools", electronSFToolsLoose),
"Failed to attach electron scale factor tools");
505 top::check(globalTriggerEffToolLoose->setProperty(
"MuonTools", muonToolsLoose),
"Failed to attach muon tools");
506 top::check(globalTriggerEffToolLoose->setProperty(
"PhotonEfficiencyTools", photonEffToolsLoose),
"Failed to attach photon eff tools");
507 top::check(globalTriggerEffToolLoose->setProperty(
"PhotonScaleFactorTools", photonSFToolsLoose),
"Failed to attach photon SF tools");
508 top::check(globalTriggerEffToolLoose->setProperty(
"ListOfLegsPerTool", legsPerToolLoose),
"Failed to define list of legs per tool");
509 top::check(globalTriggerEffToolLoose->setProperty(
"TriggerCombination", triggerCombinationLoose),
"Failed to define trigger combination");
510 top::check(globalTriggerEffToolLoose->setProperty(
"TriggerMatchingTool",
m_trigMatchTool),
"Failed to set TriggerMatchingTool");
512 top::check(globalTriggerEffToolLoose->setProperty(
"OutputLevel", MSG::ERROR),
"Failed to set message level");
518 m_config->setGlobalTriggerConfiguration(electronSystematics, muonSystematics, photonSystematics, electronToolNames, muonToolNames, photonToolNames);