25template <
typename ToolInterface,
typename SetToolPropertiesFn>
27 std::vector<ToolHandle<ToolInterface> >& toolsFactory,
28 ToolHandleArray<ToolInterface>& effTools,
29 ToolHandleArray<ToolInterface>& sfTools,
30 const std::map<std::string, std::string>& legsPerKey,
31 const std::string& toolNamePrefix,
32 const std::string& toolNameSuffix,
33 const SetToolPropertiesFn& setToolProperties,
34 std::map<std::string, std::string>& legsPerTool)
38 for (
const auto &[trigKey, triggers] : legsPerKey) {
39 if (trigKey == nameForDefaultSF) {
40 auto [itr, added] = legsPerTool.emplace(nameForDefaultSF, triggers);
41 if (!added) itr->second +=
"," + triggers;
45 for (
bool isSFTool : {
true,
false}) {
46 asg::AsgToolConfig config(toolNamePrefix + std::to_string(isSFTool) +
"_" + std::to_string(nTools) + toolNameSuffix);
48 ANA_CHECK(config.setProperty(
"TriggerKey", isSFTool ? trigKey :
"Eff_" + trigKey ));
50 ANA_CHECK(config.setProperty(
"OutputLevel",
msg().level()));
51 ToolHandle<ToolInterface>& t = toolsFactory.emplace_back();
52 std::shared_ptr<void> cleanup;
56 auto& handles = (isSFTool? sfTools : effTools);
58 legsPerTool[handles[handles.size()-1].name()] = triggers;
63 return StatusCode::SUCCESS;
72 return StatusCode::FAILURE;
93 const std::vector<std::pair<std::string, const std::vector<std::string>*> > trigMap {
104 std::map<std::string, std::string> triggerCombination;
105 for (
const auto &[year, triggers] : trigMap) {
106 if (triggers->empty())
continue;
107 std::string& combinedString = triggerCombination[year];
108 combinedString = triggers->front();
109 for (std::size_t i = 1; i < triggers->size(); ++i) {
110 combinedString +=
" || " + (*triggers)[i];
115 std::map<std::string,std::string> electronLegsPerKey, photonLegsPerKey;
126 std::map<std::string, std::string> legsPerTool;
129 ToolHandleArray<IAsgElectronEfficiencyCorrectionTool> electronEffTools, electronSFTools;
132 ATH_MSG_ERROR(
"Electron ID was not set for TrigGlobalEfficiencyAlg!");
133 return StatusCode::FAILURE;
136 "AsgElectronEfficiencyCorrectionTool/ElTrigEff_",
139 ANA_CHECK(config.setProperty(
"MapFilePath", std::string(
"ElectronEfficiencyCorrection/2015_2025/rel22.2/") +
140 (m_isRun3Geo ?
"2025_Run3_Consolidated_Recommendation_v4/map2.txt" :
"2025_Run2Rel22_Recommendation_v3/map1.txt")));
141 ANA_CHECK(config.setProperty(
"IdKey", m_electronID.value()));
142 ANA_CHECK(config.setProperty(
"IsoKey", m_electronIsol.value()));
143 ANA_CHECK(config.setProperty(
"CorrelationModel",
"TOTAL"));
144 return StatusCode::SUCCESS;
150 ToolHandleArray<IAsgPhotonEfficiencyCorrectionTool> photonEffTools, photonSFTools;
153 ATH_MSG_ERROR(
"Photon Isolation was not set for TrigGlobalEfficiencyAlg!");
154 return StatusCode::FAILURE;
157 "AsgPhotonEfficiencyCorrectionTool/PhTrigEff_",
161 ANA_CHECK(config.setProperty(
"MapFilePath",
"PhotonEfficiencyCorrection/2015_2018/rel21.2/Summer2020_Rec_v1/map3.txt"));
164 return StatusCode::SUCCESS;
170 ToolHandleArray<CP::IMuonTriggerScaleFactors> muonTools;
171 if (!m_muonsHandle.empty() && !m_doMatchingOnly) {
172 if (m_muonID.empty()) {
173 ATH_MSG_ERROR(
"Muon ID was not set for TrigGlobalEfficiencyAlg!");
174 return StatusCode::FAILURE;
177 ANA_CHECK(m_muonTool.setProperty(
"MuonQuality", m_muonID.value()));
178 ANA_CHECK(m_muonTool.setProperty(
"AllowZeroSF",
true));
179 ANA_CHECK(m_muonTool.setProperty(
"Campaign", m_campaign.value()));
182 muonTools.push_back(m_muonTool.getHandle());
184 ANA_CHECK(m_systematicsList.addSystematics( *m_muonTool ));
188 for(
const std::string& trig : m_separateMatchingTriggers) {
190 ANA_CHECK(m_separateMatchingDecorators.at(trig).initialize(m_systematicsList, m_eventInfoHandle));
192 m_separateMatchingFlags[trig] =
false;
196 m_tgecTool = asg::AnaToolHandle<ITrigGlobalEfficiencyCorrectionTool>(
"TrigGlobalEfficiencyCorrectionTool/TrigGlobal_" + this->
name() );
197 ANA_CHECK(m_tgecTool.setProperty(
"ElectronEfficiencyTools", electronEffTools));
198 ANA_CHECK(m_tgecTool.setProperty(
"ElectronScaleFactorTools", electronSFTools));
199 ANA_CHECK(m_tgecTool.setProperty(
"PhotonEfficiencyTools", photonEffTools));
200 ANA_CHECK(m_tgecTool.setProperty(
"PhotonScaleFactorTools", photonSFTools));
201 ANA_CHECK(m_tgecTool.setProperty(
"MuonTools", muonTools));
202 ANA_CHECK(m_tgecTool.setProperty(
"ListOfLegsPerTool", legsPerTool));
203 ANA_CHECK(m_tgecTool.setProperty(
"TriggerCombination", triggerCombination));
204 ANA_CHECK(m_tgecTool.setProperty(
"TriggerMatchingTool", m_trigMatchingTool));
205 ANA_CHECK(m_tgecTool.setProperty(
"NumberOfToys", m_numToys));
206 ANA_CHECK(m_tgecTool.setProperty(
"OutputLevel", MSG::ERROR));
209 ANA_CHECK(m_systematicsList.initialize());
211 return StatusCode::SUCCESS;
226 std::vector<const xAOD::Electron*> selectedElectrons;
227 std::vector<const xAOD::Photon*> selectedPhotons;
228 std::vector<const xAOD::Muon*> selectedMuons;
253 if (selectedElectrons.empty() && selectedMuons.empty() && selectedPhotons.empty()) sf = 1.0;
261 ATH_MSG_WARNING(
"Global trigger scale factor computation failed (CorrectionCode " << code.code() <<
") for systematic '" << syst.name() <<
"', scale factor set to " << sf
272 bool matched =
false;
273 if (!(selectedElectrons.empty() && selectedMuons.empty() && selectedPhotons.empty())) {
275 ANA_CHECK(
m_tgecTool->checkTriggerMatching(matched, selectedElectrons, selectedMuons, selectedPhotons));
279 if(flag) matched =
true;
286 decorator.set(*evtInfo,
false, syst);
289 if (matched) filter.setPassed(
true);
296 return StatusCode::SUCCESS;
306 return StatusCode::SUCCESS;
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Return value from object correction CP tools.
@ Ok
The correction was done successfully.
a reporter class that combines the filter decisions for all systematics
a systematics aware filter reporter
a data handle for reading systematics varied input data
SysListHandle m_systematicsList
asg::AnaToolHandle< ITrigGlobalEfficiencyCorrectionTool > m_tgecTool
Trigger Global Efficiency Correction Tool handle.
Gaudi::Property< std::vector< std::string > > m_trigList_2024
SysReadHandle< xAOD::EventInfo > m_eventInfoHandle
EventInfo to decorate.
Gaudi::Property< std::vector< std::string > > m_trigList_2018
virtual StatusCode finalize() final override
Gaudi::Property< std::string > m_electronIsol
electron Isolation
Gaudi::Property< std::vector< std::string > > m_trigList_2023
std::unordered_map< std::string, SysWriteDecorHandle< bool > > m_separateMatchingDecorators
Gaudi::Property< std::vector< std::string > > m_separateMatchingTriggers
store separate trigger matching flags for each trigger
Gaudi::Property< std::string > m_electronID
electron ID
ToolHandle< Trig::IMatchingTool > m_trigMatchingTool
trigger matching tool
Gaudi::Property< std::string > m_photonIsol
photon Isolation
std::vector< std::shared_ptr< void > > m_toolsCleanup
keeps the tools created via m_electronToolsFactory/m_photonToolsFactory alive in AnalysisBase
SysWriteDecorHandle< char > m_matchingDecoration
decoration of the global trigger matching flag
SysReadSelectionHandle m_muonSelection
input muon selection
Gaudi::Property< std::vector< std::string > > m_trigList_2017
Gaudi::Property< bool > m_noFilter
whether to not apply an event filter
unsigned long long m_nScaleFactorFailures
number of events for which the global trigger scale factor computation failed
StatusCode makeEgammaTools(std::vector< ToolHandle< ToolInterface > > &toolsFactory, ToolHandleArray< ToolInterface > &effTools, ToolHandleArray< ToolInterface > &sfTools, const std::map< std::string, std::string > &legsPerKey, const std::string &toolNamePrefix, const std::string &toolNameSuffix, const SetToolPropertiesFn &setToolProperties, std::map< std::string, std::string > &legsPerTool)
create one efficiency and one scale factor tool per electron/photon trigger key
std::vector< ToolHandle< IAsgPhotonEfficiencyCorrectionTool > > m_photonToolsFactory
on-the-fly public tool creation for photons
SysReadSelectionHandle m_electronSelection
input electron selection
Gaudi::Property< std::vector< std::string > > m_trigList_2015
list of triggers or trigger chains
Gaudi::Property< bool > m_doMatchingOnly
whether to only run the global trigger matching, and not compute efficiency SFs
SysWriteDecorHandle< float > m_scaleFactorDecoration
decoration of the global trigger SF
TrigGlobalEfficiencyAlg(const std::string &name, ISvcLocator *pSvcLocator=nullptr)
Gaudi::Property< std::vector< std::string > > m_trigList_2022
virtual StatusCode initialize() final override
SysReadSelectionHandle m_photonSelection
input photon selection
Gaudi::Property< std::vector< std::string > > m_trigList_2016
std::vector< ToolHandle< IAsgElectronEfficiencyCorrectionTool > > m_electronToolsFactory
on-the-fly public tool creation for electrons
Gaudi::Property< std::vector< std::string > > m_trigList_2025
std::unordered_map< std::string, bool > m_separateMatchingFlags
SysReadHandle< xAOD::PhotonContainer > m_photonsHandle
input photon collection
SysReadHandle< xAOD::ElectronContainer > m_electronsHandle
input electron collection
SysFilterReporterParams m_filterParams
the filter reporter params
Gaudi::Property< bool > m_isRun3Geo
whether to use Run 3 settings
SysReadHandle< xAOD::MuonContainer > m_muonsHandle
input muon collection
AnaAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
constructor with parameters
virtual::StatusCode execute()
execute this algorithm
std::string sanitizeTriggerChainName(std::string chain)
convert a trigger chain name into a string usable in decoration/branch names (.
This module defines the arguments passed from the BATCH driver to the BATCH worker.
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
EventInfo_v1 EventInfo
Definition of the latest event info version.
Muon_v1 Muon
Reference the current persistent version:
Photon_v1 Photon
Definition of the current "egamma version".
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
Electron_v1 Electron
Definition of the current "egamma version".