Commit 716728ca authored by Tomas Dado's avatar Tomas Dado Committed by Nils Erik Krumnack
Browse files

AnalysisTop: GlobalTriggers for photons

parent 0495593c
......@@ -27,6 +27,7 @@
#include "EgammaAnalysisInterfaces/IAsgElectronEfficiencyCorrectionTool.h"
#include "MuonAnalysisInterfaces/IMuonTriggerScaleFactors.h"
#include "MuonEfficiencyCorrections/MuonTriggerScaleFactors.h"
#include <EgammaAnalysisInterfaces/IAsgPhotonEfficiencyCorrectionTool.h>
#include "PATCore/PATCoreEnums.h"
#include "xAODBase/ObjectType.h"
#include <boost/algorithm/string.hpp>
......@@ -140,7 +141,8 @@ namespace top {
}
auto getTriggerLegs =
[&](std::unordered_map<std::string, std::vector<std::string> > const& triggerCombination,
std::unordered_map<std::string, std::set<std::string> >& electronLegsByPeriod) {
std::unordered_map<std::string, std::set<std::string> >& electronLegsByPeriod,
std::unordered_map<std::string, std::set<std::string> >& photonLegsByPeriod) {
for (auto&& kv : triggerCombination) {
std::string const& period = kv.first;
for (auto const& trigKey : kv.second) {
......@@ -170,6 +172,10 @@ namespace top {
case xAOD::Type::Muon:
break;
case xAOD::Type::Photon:
photonLegsByPeriod[period].insert(legname);
break;
default:
statusCode = StatusCode::FAILURE;
ATH_MSG_ERROR(
......@@ -189,21 +195,24 @@ namespace top {
triggersByPeriod = (m_config->doTightEvents() ? m_config->getGlobalTriggers() : emptymap),
triggersByPeriodLoose = (m_config->doLooseEvents() ? m_config->getGlobalTriggersLoose() : emptymap);
std::unordered_map<std::string, std::set<std::string> > electronLegsByPeriod, electronLegsByPeriodLoose;
getTriggerLegs(triggersByPeriod, electronLegsByPeriod);
getTriggerLegs(triggersByPeriodLoose, electronLegsByPeriodLoose);
std::unordered_map<std::string, std::set<std::string> > electronLegsByPeriod, electronLegsByPeriodLoose, photonLegsByPeriod, photonLegsByPeriodLoose;
getTriggerLegs(triggersByPeriod, electronLegsByPeriod, photonLegsByPeriod);
getTriggerLegs(triggersByPeriodLoose, electronLegsByPeriodLoose, photonLegsByPeriodLoose);
// Get quality
std::string electronID, electronIDLoose, electronIsolation, electronIsolationLoose, muonQuality, muonQualityLoose;
std::string photonIso, photonIsoLoose;
if (m_config->doTightEvents()) {
electronID = m_config->electronID();
electronIsolation = m_config->electronIsolationSF();
muonQuality = m_config->muonQuality();
photonIso = m_config->photonIsolation();
}
if (m_config->doLooseEvents()) {
electronIDLoose = m_config->electronIDLoose();
electronIsolationLoose = m_config->electronIsolationSFLoose();
muonQualityLoose = m_config->muonQualityLoose();
photonIsoLoose = m_config->photonIsolationLoose();
}
// Tidy name for e/gamma
......@@ -338,6 +347,60 @@ namespace top {
}
}
// Setup photon tools
ToolHandleArray<IAsgPhotonEfficiencyCorrectionTool> photonEffTools;
ToolHandleArray<IAsgPhotonEfficiencyCorrectionTool> photonSFTools;
std::vector<asg::AnaToolHandle<IAsgPhotonEfficiencyCorrectionTool> > factory;
const std::string photonKey = PhotonKeys(triggersByPeriod);
static const std::string mapPath = "PhotonEfficiencyCorrection/2015_2018/rel21.2/Summer2020_Rec_v1/map2.txt";
if (photonKey != "") {
if (m_config->doTightEvents()) {
top::check(CheckPhotonIsolation(photonIso), "Unsupported photon isolation for photon triggers provided: " + photonIso);
for(int j=0;j<2;++j) { /// two instances: 0 -> MC efficiencies, 1 -> SFs
const std::string name = "AsgPhotonEfficiencyCorrectionTool/" + std::string(j? "PhTrigEff" : "PhTrigSF");
auto t = factory.emplace(factory.end(), name);
top::check(t->setProperty("MapFilePath", mapPath.c_str()), "Cannot set MapFilePath");
top::check(t->setProperty("TriggerKey", std::string(j ? "" : "Eff_") + photonKey), "Cannot set TriggerKey");
top::check(t->setProperty("IsoKey", photonIso), "Cannot set IsoKey");
top::check(t->setProperty("ForceDataType", (int)PATCore::ParticleDataType::Full), "Cannot set ForceDataType");
top::check(t->initialize(), "Cannot initialise the photon tools");
auto& photonHandles = (j? photonSFTools : photonEffTools);
photonHandles.push_back(t->getHandle());
for (auto& y_t : photonLegsByPeriod) {
const std::string year = y_t.first;
for (auto& trigKey : y_t.second) {
const std::string name = photonHandles.back().name();
legsPerTool[name] = trigKey + " [" + year + "]";
}
}
}
}
if (m_config->doLooseEvents()) {
top::check(CheckPhotonIsolation(photonIsoLoose), "Unsupported photon isolation for photon triggers provided: " + photonIsoLoose);
for(int j=0;j<2;++j) { /// two instances: 0 -> MC efficiencies, 1 -> SFs
const std::string name = "AsgPhotonEfficiencyCorrectionTool/" + std::string(j? "PhTrigEff" : "PhTrigSF");
auto t = factory.emplace(factory.end(), name);
top::check(t->setProperty("MapFilePath", mapPath.c_str()), "Cannot set MapFilePath");
top::check(t->setProperty("TriggerKey", std::string(j ? "" : "Eff_") + photonKey), "Cannot set TriggerKey");
top::check(t->setProperty("IsoKey", photonIsoLoose), "Cannot set IsoKey");
top::check(t->setProperty("ForceDataType", (int)PATCore::ParticleDataType::Full), "Cannot set ForceDataType");
top::check(t->initialize(), "Cannot initialise the photon tools");
auto& photonHandles = (j? photonSFTools : photonEffTools);
photonHandles.push_back(t->getHandle());
for (auto& y_t : photonLegsByPeriodLoose) {
const std::string year = y_t.first;
for (auto& trigKey : y_t.second) {
const std::string name =photonHandles.back().name();
legsPerTool[name] = trigKey + " [" + year + "]";
}
}
}
}
}
for (auto& key : triggersByPeriod) {
if (triggerCombination.find(key.first) == triggerCombination.end()) {
triggerCombination[key.first] = "";
......@@ -365,6 +428,8 @@ namespace top {
top::check(globalTriggerEffTool->setProperty("ElectronEfficiencyTools", electronEffTools), "Failed to attach electron efficiency tools");
top::check(globalTriggerEffTool->setProperty("ElectronScaleFactorTools", electronSFTools), "Failed to attach electron scale factor tools");
top::check(globalTriggerEffTool->setProperty("MuonTools", muonTools), "Failed to attach muon tools");
top::check(globalTriggerEffTool->setProperty("PhotonEfficiencyTools", photonEffTools), "Failed to attach photon eff tools");
top::check(globalTriggerEffTool->setProperty("PhotonScaleFactorTools", photonSFTools), "Failed to attach photon SF tools");
top::check(globalTriggerEffTool->setProperty("ListOfLegsPerTool", legsPerTool), "Failed to define list of legs per tool");
top::check(globalTriggerEffTool->setProperty("TriggerCombination", triggerCombination), "Failed to define trigger combination");
top::check(globalTriggerEffTool->setProperty("TriggerMatchingTool", m_trigMatchTool), "Failed to set TriggerMatchingTool");
......@@ -378,6 +443,8 @@ namespace top {
top::check(globalTriggerEffToolLoose->setProperty("ElectronEfficiencyTools", electronEffToolsLoose), "Failed to attach electron efficiency tools");
top::check(globalTriggerEffToolLoose->setProperty("ElectronScaleFactorTools", electronSFToolsLoose), "Failed to attach electron scale factor tools");
top::check(globalTriggerEffToolLoose->setProperty("MuonTools", muonToolsLoose), "Failed to attach muon tools");
top::check(globalTriggerEffToolLoose->setProperty("PhotonEfficiencyTools", photonEffTools), "Failed to attach photon eff tools");
top::check(globalTriggerEffToolLoose->setProperty("PhotonScaleFactorTools", photonSFTools), "Failed to attach photon SF tools");
top::check(globalTriggerEffToolLoose->setProperty("ListOfLegsPerTool", legsPerToolLoose), "Failed to define list of legs per tool");
top::check(globalTriggerEffToolLoose->setProperty("TriggerCombination", triggerCombinationLoose), "Failed to define trigger combination");
top::check(globalTriggerEffToolLoose->setProperty("TriggerMatchingTool", m_trigMatchTool), "Failed to set TriggerMatchingTool");
......@@ -421,4 +488,44 @@ namespace top {
return working_point;
}
std::string TriggerCPTools::PhotonKeys(const std::unordered_map<std::string, std::vector<std::string> >& map) const {
// check of the trigger names are one of the supported
std::string result("");
const std::vector<std::pair<std::string,std::string> > supported = {{"2015","3g15_loose"},
{"2016","3g20_loose"},
{"2017","2g25_loose_g15_loose"},
{"2018","2g25_loose_g15_loose"}};
// check if the keys for each year match the supported photon trigger
bool isPhoton(true);
for (const auto& isupported : supported) {
auto it = map.find(isupported.first);
if (it == map.end()) continue;
const std::vector<std::string> keys = it->second;
if (std::find(keys.begin(), keys.end(), isupported.second) == keys.end()) {
isPhoton = false;
}
}
if (isPhoton) {
result = "TRI_PH_2015_g15_loose_2016_g20_loose_2017_2018_g15_loose";
}
return result;
}
StatusCode TriggerCPTools::CheckPhotonIsolation(const std::string& isol) const {
// only these isolations are available for photons triggers
// we need to check for these as the code otherwise crashed
// with a meaningless error
static const std::vector<std::string> allowedIso = {"TightCaloOnly", "Loose"};
if (std::find(allowedIso.begin(), allowedIso.end(), isol) == allowedIso.end()) {
return StatusCode::FAILURE;
}
return StatusCode::SUCCESS;
}
} // namespace top
......@@ -6,8 +6,9 @@
#define TOPCPTOOLS_TOPTRIGGERCPTOOLS_H_
// Include what you use
#include <vector>
#include <unordered_map>
#include <string>
#include <vector>
// Framework include(s):
#include "AsgTools/AsgTool.h"
......@@ -45,6 +46,10 @@ namespace top {
ToolHandle<ITrigGlobalEfficiencyCorrectionTool> m_globalTriggerEffToolLoose;
StatusCode initialiseGlobalTriggerEff();
std::string mapWorkingPoints(const std::string& type);
// check of the trigger names are one of the supported
std::string PhotonKeys(const std::unordered_map<std::string, std::vector<std::string> >& map) const;
// check if the photon isolation is supported by the global triggers
StatusCode CheckPhotonIsolation(const std::string& isol) const;
// Tool handles for the CP tools, need to be members here, or inaccessible to global trigger tool
asg::AnaToolHandle<CP::IMuonTriggerScaleFactors> m_muonTool;
......
......@@ -27,6 +27,7 @@ namespace top {
std::vector<xAOD::IParticle const*> particles;
particles.insert(particles.end(), event.m_electrons.begin(), event.m_electrons.end());
particles.insert(particles.end(), event.m_muons.begin(), event.m_muons.end());
particles.insert(particles.end(), event.m_photons.begin(), event.m_photons.end());
top::check(tool->checkTriggerMatching(result,
particles),
"TrigGlobalEfficiencyCorrectionTool::checkTriggerMatching failed");
......
......@@ -80,6 +80,8 @@ namespace top {
std::vector<std::string> globalElectronTriggers_Loose;
std::vector<std::string> globalMuonTriggers_Tight;
std::vector<std::string> globalMuonTriggers_Loose;
std::vector<std::string> globalPhotonTriggers_Tight;
std::vector<std::string> globalPhotonTriggers_Loose;
if (m_config->useGlobalTrigger()) {
std::set<std::string> tmp;
for (auto const& triggermap : {m_config->getGlobalTriggers()}) {
......@@ -92,6 +94,7 @@ namespace top {
for (std::string const& trigger : globalTriggers_Tight) {
if (isElectronTrigger(trigger)) globalElectronTriggers_Tight.push_back(trigger);
if (isMuonTrigger(trigger)) globalMuonTriggers_Tight.push_back(trigger);
if (isPhotonTrigger(trigger)) globalPhotonTriggers_Tight.push_back(trigger);
}
tmp.clear();
// and the usual copy-paste-s/Tight/Loose/g story:
......@@ -105,6 +108,7 @@ namespace top {
for (std::string const& trigger : globalTriggers_Loose) {
if (isElectronTrigger(trigger)) globalElectronTriggers_Loose.push_back(trigger);
if (isMuonTrigger(trigger)) globalMuonTriggers_Loose.push_back(trigger);
if (isPhotonTrigger(trigger)) globalPhotonTriggers_Loose.push_back(trigger);
}
}
......@@ -208,6 +212,12 @@ namespace top {
muonTriggers_perSelector_Loose->insert(std::make_pair(sel.m_name,
std::vector<std::string>(globalMuonTriggers_Loose.begin(),
globalMuonTriggers_Loose.end())));
photonTriggers_perSelector_Tight->insert(std::make_pair(sel.m_name,
std::vector<std::string>(globalPhotonTriggers_Tight.begin(),
globalPhotonTriggers_Tight.end())));
photonTriggers_perSelector_Loose->insert(std::make_pair(sel.m_name,
std::vector<std::string>(globalPhotonTriggers_Loose.begin(),
globalPhotonTriggers_Loose.end())));
}
if (starts_with(cut, "TRIGDEC_TIGHT ")) {
......@@ -835,6 +845,9 @@ namespace top {
if (trigger.find("_1g") != std::string::npos) return true;
if (trigger.find("_2g") != std::string::npos) return true;
return false;
top::check(trigger.find("HLT_") == 0, "Expected trigger name to start with `HLT_'");
bool success;
return(TrigGlobEffCorr::ImportData::associatedLeptonFlavour(trigger.substr(4), success) == xAOD::Type::Photon);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment