15 :
EL::AnaAlgorithm(
name, svcLoc)
23 if (m_trigList_2015.empty() && m_trigList_2016.empty() && m_trigList_2017.empty() && m_trigList_2018.empty()
24 && m_trigList_2022.empty() && m_trigList_2023.empty() && m_trigList_2024.empty() && m_trigList_2025.empty()) {
26 return StatusCode::FAILURE;
37 ANA_CHECK(m_eventInfoHandle.initialize(m_systematicsList));
38 ANA_CHECK(m_scaleFactorDecoration.initialize(m_systematicsList, m_eventInfoHandle));
39 ANA_CHECK(m_matchingDecoration.initialize(m_systematicsList, m_eventInfoHandle));
41 ANA_CHECK (m_filterParams.initialize(m_systematicsList));
50 std::unordered_map<std::string, TrigGlobEffCorr::ImportData::TrigDef> triggerDefs;
52 auto it = triggerDict.find(
key);
53 if (
it != triggerDict.end()) {
54 triggerDefs[
it->second] = trigDef;
59 std::unordered_map<std::string, std::vector<std::string> > trigMap;
60 trigMap[
"2015"] = m_trigList_2015;
61 trigMap[
"2016"] = m_trigList_2016;
62 trigMap[
"2017"] = m_trigList_2017;
63 trigMap[
"2018"] = m_trigList_2018;
64 trigMap[
"2022"] = m_trigList_2022;
65 trigMap[
"2023"] = m_trigList_2023;
66 trigMap[
"2024"] = m_trigList_2024;
67 trigMap[
"2025"] = m_trigList_2025;
70 std::map<std::string, std::string> triggerCombination;
71 auto combineStrings = [](
const std::vector<std::string>&
input ) {
72 std::string combinedString;
74 for (
const auto &
i :
input) {
76 combinedString +=
" || ";
81 return combinedString;
85 if (triggerCombination.find(
year) == triggerCombination.end()) {
86 triggerCombination[
year] =
"";
88 triggerCombination[
year] +=
" || ";
94 std::map<std::string,std::string> electronLegsPerKey, photonLegsPerKey;
103 std::map<std::string, std::string> legsPerTool;
107 ToolHandleArray<IAsgElectronEfficiencyCorrectionTool> electronEffTools, electronSFTools;
109 if (!m_electronsHandle.empty() && !m_doMatchingOnly) {
110 if (m_electronID.empty())
ATH_MSG_ERROR(
"Electron ID was not set for TrigGlobalEfficiencyAlg!");
111 for (
const auto &[trigKey,
triggers] : electronLegsPerKey) {
112 if (trigKey == nameForDefaultSF) {
113 auto [itr, added] = legsPerTool.emplace(nameForDefaultSF,
triggers);
114 if (!added) itr->second +=
"," +
triggers;
118 for (
bool isSFTool : {
true,
false}) {
119 auto t = m_electronToolsFactory.emplace(m_electronToolsFactory.end(),
120 "AsgElectronEfficiencyCorrectionTool/ElTrigEff_"
123 ANA_CHECK(
t->setProperty(
"MapFilePath",
"ElectronEfficiencyCorrection/2015_2018/rel21.2/Precision_Summer2020_v1/map4.txt"));
125 ANA_CHECK(
t->setProperty(
"IdKey", m_electronID.value()));
126 ANA_CHECK(
t->setProperty(
"IsoKey", m_electronIsol.value()));
127 ANA_CHECK(
t->setProperty(
"TriggerKey", isSFTool ? trigKey :
"Eff_" + trigKey ));
128 ANA_CHECK(
t->setProperty(
"CorrelationModel",
"TOTAL"));
133 auto& handles = (isSFTool? electronSFTools : electronEffTools);
134 handles.push_back(
t->getHandle());
135 std::string
name = handles[handles.size()-1].name();
138 ANA_CHECK(m_systematicsList.addSystematics( *handles[handles.size()-1] ));
144 ToolHandleArray<IAsgPhotonEfficiencyCorrectionTool> photonEffTools, photonSFTools;
146 if (!m_photonsHandle.empty() && !m_doMatchingOnly) {
147 if (m_photonIsol.empty())
ATH_MSG_ERROR(
"Photon Isolation was not set for TrigGlobalEfficiencyAlg!");
148 for (
const auto &[trigKey,
triggers] : photonLegsPerKey) {
149 if (trigKey == nameForDefaultSF) {
150 auto [itr, added] = legsPerTool.emplace(nameForDefaultSF,
triggers);
151 if (!added) itr->second +=
"," +
triggers;
155 for (
bool isSFTool : {
true,
false}) {
156 auto t = m_photonToolsFactory.emplace(m_photonToolsFactory.end(),
157 "AsgPhotonEfficiencyCorrectionTool/PhTrigEff_"
160 ANA_CHECK(
t->setProperty(
"MapFilePath",
"PhotonEfficiencyCorrection/2015_2018/rel21.2/Summer2020_Rec_v1/map3.txt"));
162 ANA_CHECK(
t->setProperty(
"IsoKey", m_photonIsol.value()));
163 ANA_CHECK(
t->setProperty(
"TriggerKey", isSFTool ? trigKey :
"Eff_" + trigKey ));
168 auto& handles = (isSFTool? photonSFTools : photonEffTools);
169 handles.push_back(
t->getHandle());
170 std::string
name = handles[handles.size()-1].name();
173 ANA_CHECK(m_systematicsList.addSystematics( *handles[handles.size()-1] ));
179 ToolHandleArray<CP::IMuonTriggerScaleFactors> muonTools;
180 if (!m_muonsHandle.empty() && !m_doMatchingOnly) {
181 if (m_muonID.empty())
ATH_MSG_ERROR(
"Muon ID was not set for TrigGlobalEfficiencyAlg!");
183 ANA_CHECK(m_muonTool.setProperty(
"MuonQuality", m_muonID.value()));
184 ANA_CHECK(m_muonTool.setProperty(
"AllowZeroSF",
true));
187 muonTools.push_back(m_muonTool.getHandle());
189 ANA_CHECK(m_systematicsList.addSystematics( *m_muonTool ));
194 ANA_CHECK(m_tgecTool.setProperty(
"ElectronEfficiencyTools", electronEffTools));
195 ANA_CHECK(m_tgecTool.setProperty(
"ElectronScaleFactorTools", electronSFTools));
196 ANA_CHECK(m_tgecTool.setProperty(
"PhotonEfficiencyTools", photonEffTools));
197 ANA_CHECK(m_tgecTool.setProperty(
"PhotonScaleFactorTools", photonSFTools));
198 ANA_CHECK(m_tgecTool.setProperty(
"MuonTools", muonTools));
199 ANA_CHECK(m_tgecTool.setProperty(
"ListOfLegsPerTool", legsPerTool));
200 ANA_CHECK(m_tgecTool.setProperty(
"TriggerCombination", triggerCombination));
201 ANA_CHECK(m_tgecTool.setProperty(
"TriggerMatchingTool", m_trigMatchingTool));
202 ANA_CHECK(m_tgecTool.setProperty(
"OutputLevel", MSG::ERROR));
205 ANA_CHECK(m_systematicsList.initialize());
207 return StatusCode::SUCCESS;
215 for (
const auto & syst : m_systematicsList.systematicsVector()) {
222 std::vector<const xAOD::Electron*> selectedElectrons;
223 std::vector<const xAOD::Photon*> selectedPhotons;
224 std::vector<const xAOD::Muon*> selectedMuons;
226 if (!m_electronsHandle.empty()) {
229 if (m_electronSelection.getBool(*
el, syst)) selectedElectrons.push_back(
el);
232 if (!m_photonsHandle.empty()) {
233 ANA_CHECK(m_photonsHandle.retrieve(photons, syst));
235 if (m_photonSelection.getBool(*ph, syst)) selectedPhotons.push_back(ph);
238 if (!m_muonsHandle.empty()) {
239 ANA_CHECK(m_muonsHandle.retrieve(muons, syst));
241 if (m_muonSelection.getBool(*
mu, syst)) selectedMuons.push_back(
mu);
245 ANA_CHECK(m_tgecTool->applySystematicVariation(syst));
249 if (selectedElectrons.empty() && selectedMuons.empty() && selectedPhotons.empty())
sf = 1.0;
250 else if (m_doMatchingOnly)
sf = 1.0;
253 m_tgecTool->getEfficiencyScaleFactor(selectedElectrons, selectedMuons, selectedPhotons,
259 if (!(selectedElectrons.empty() && selectedMuons.empty() && selectedPhotons.empty())) {
260 ANA_CHECK(m_tgecTool->checkTriggerMatching(
matched, selectedElectrons, selectedMuons, selectedPhotons));
266 ANA_CHECK(m_eventInfoHandle.retrieve(evtInfo, syst));
267 m_scaleFactorDecoration.set(*evtInfo,
sf, syst);
268 m_matchingDecoration.set(*evtInfo,
matched, syst);
272 return StatusCode::SUCCESS;
279 return StatusCode::SUCCESS;