28 m_grlTool(
"GoodRunsListSelectionTool"),
30 m_trigConfTool(
"xAODConfigTool"),
31 m_trigDecisionTool(
"TrigDecisionTool"),
32 m_trigMatchTool(
"MatchingTool"),
33 m_trigMatchTauTool(
"TrigTauMatchingTool"),
34 m_globalTriggerSF(
"TrigGlobalEfficiencyCorrectionTool::TrigGlobal"),
35 m_globalTriggerSFLoose(
"TrigGlobalEfficiencyCorrectionTool::TrigGlobalLoose"),
37 m_vetoEventsTrigger(false),
38 m_vetoEventsGRL(false),
39 m_vetoEventsGoodCalo(false),
40 m_vetoEventsPriVtx(true) {
54 if (
m_config->isTruthDxAOD())
return StatusCode::SUCCESS;
59 "Failed to retrieve trigger matching tool");
61 "Failed to retrieve TrigMatchTauTool");
69 return StatusCode::SUCCESS;
73 std::set<std::pair<std::string, int> > tmpAllTriggers_Tight;
74 std::set<std::pair<std::string, int> > tmpAllTriggers_Loose;
77 std::vector<std::pair<std::string, int> > globalTriggers_Tight;
78 std::vector<std::pair<std::string, int> > globalTriggers_Loose;
79 std::vector<std::pair<std::string, int> > globalElectronTriggers_Tight;
80 std::vector<std::pair<std::string, int> > globalElectronTriggers_Loose;
81 std::vector<std::pair<std::string, int> > globalMuonTriggers_Tight;
82 std::vector<std::pair<std::string, int> > globalMuonTriggers_Loose;
83 std::vector<std::pair<std::string, int> > globalPhotonTriggers_Tight;
84 std::vector<std::pair<std::string, int> > globalPhotonTriggers_Loose;
87 std::set<std::pair<std::string, int> >
tmp;
88 for (
auto const& triggermap : {
m_config->getGlobalTriggers()}) {
89 for (
auto const& pair : triggermap) {
94 globalTriggers_Tight.assign(
tmp.begin(),
tmp.end());
95 for (std::pair<std::string, int>
const&
trigger : globalTriggers_Tight) {
102 for (
auto const& triggermap : {
m_config->getGlobalTriggersLoose()}) {
103 for (
auto const& pair : triggermap) {
108 globalTriggers_Loose.assign(
tmp.begin(),
tmp.end());
109 for (std::pair<std::string, int>
const&
trigger : globalTriggers_Loose) {
128 std::shared_ptr<std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > > allTriggers_perSelector_Tight(
new std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > );
129 std::shared_ptr<std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > > electronTriggers_perSelector_Tight(
new std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > );
130 std::shared_ptr<std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > > muonTriggers_perSelector_Tight(
new std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > );
131 std::shared_ptr<std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > > tauTriggers_perSelector_Tight(
new std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > );
132 std::shared_ptr<std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > > photonTriggers_perSelector_Tight(
new std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > );
133 std::shared_ptr<std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > > allTriggers_perSelector_Loose(
new std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > );
134 std::shared_ptr<std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > > electronTriggers_perSelector_Loose(
new std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > );
135 std::shared_ptr<std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > > muonTriggers_perSelector_Loose(
new std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > );
136 std::shared_ptr<std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > > tauTriggers_perSelector_Loose(
new std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > );
137 std::shared_ptr<std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > > photonTriggers_perSelector_Loose(
new std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > );
146 std::list<std::pair<std::string, int> > listAllTriggers_thisSelector_Tight;
147 std::vector<std::pair<std::string, int> > allTriggers_thisSelector_Tight;
148 std::vector<std::pair<std::string, int> > electronTriggers_thisSelector_Tight;
149 std::vector<std::pair<std::string, int> > muonTriggers_thisSelector_Tight;
150 std::vector<std::pair<std::string, int> > tauTriggers_thisSelector_Tight;
151 std::vector<std::pair<std::string, int> > photonTriggers_thisSelector_Tight;
152 std::list<std::pair<std::string, int> > listAllTriggers_thisSelector_Loose;
153 std::vector<std::pair<std::string, int> > allTriggers_thisSelector_Loose;
154 std::vector<std::pair<std::string, int> > electronTriggers_thisSelector_Loose;
155 std::vector<std::pair<std::string, int> > muonTriggers_thisSelector_Loose;
156 std::vector<std::pair<std::string, int> > tauTriggers_thisSelector_Loose;
157 std::vector<std::pair<std::string, int> > photonTriggers_thisSelector_Loose;
160 bool selectionHasTriggerCut(
false);
161 bool selectionHasTriggerCut_Tight(
false);
162 bool selectionHasTriggerCut_Loose(
false);
163 bool selectionHasGRLCut(
false);
164 bool selectionHasGOODCALOCut(
false);
165 for (std::string
cut :
sel.m_cutnames) {
168 if (
cut.starts_with(
"GRL ")) {
169 selectionHasGRLCut =
true;
172 if (
cut.starts_with(
"GOODCALO ")) {
173 selectionHasGOODCALOCut =
true;
176 if (
cut.starts_with(
"GTRIGDEC ")) {
177 if (selectionHasTriggerCut || selectionHasTriggerCut_Loose || selectionHasTriggerCut_Tight) {
178 throw std::runtime_error(
"You have multiple TRIGDEC selectors for selection "
179 +
sel.m_name +
". Only one per selection is allowed.");
181 if (!
m_config->useGlobalTrigger()) {
182 throw std::runtime_error(
"The GTRIGDEC selector cannot be used without UseGlobalLeptonTriggerSF option.");
184 selectionHasTriggerCut =
true;
185 allTriggers_perSelector_Tight->insert(std::make_pair(
sel.m_name,
186 std::vector<std::pair<std::string, int> >(globalTriggers_Tight.begin(),
187 globalTriggers_Tight.end())));
188 allTriggers_perSelector_Loose->insert(std::make_pair(
sel.m_name,
189 std::vector<std::pair<std::string, int> >(globalTriggers_Loose.begin(),
190 globalTriggers_Loose.end())));
191 electronTriggers_perSelector_Tight->insert(std::make_pair(
sel.m_name,
192 std::vector<std::pair<std::string, int> >(
193 globalElectronTriggers_Tight.begin(),
194 globalElectronTriggers_Tight.end())));
195 electronTriggers_perSelector_Loose->insert(std::make_pair(
sel.m_name,
196 std::vector<std::pair<std::string, int> >(
197 globalElectronTriggers_Loose.begin(),
198 globalElectronTriggers_Loose.end())));
199 muonTriggers_perSelector_Tight->insert(std::make_pair(
sel.m_name,
200 std::vector<std::pair<std::string, int> >(globalMuonTriggers_Tight.begin(),
201 globalMuonTriggers_Tight.end())));
202 muonTriggers_perSelector_Loose->insert(std::make_pair(
sel.m_name,
203 std::vector<std::pair<std::string, int> >(globalMuonTriggers_Loose.begin(),
204 globalMuonTriggers_Loose.end())));
205 photonTriggers_perSelector_Tight->insert(std::make_pair(
sel.m_name,
206 std::vector<std::pair<std::string, int> >(globalPhotonTriggers_Tight.begin(),
207 globalPhotonTriggers_Tight.end())));
208 photonTriggers_perSelector_Loose->insert(std::make_pair(
sel.m_name,
209 std::vector<std::pair<std::string, int> >(globalPhotonTriggers_Loose.begin(),
210 globalPhotonTriggers_Loose.end())));
214 auto splitTrigger = [](std::string trig) {
216 auto position = trig.find(delim);
218 if (position != std::string::npos) {
219 n = std::stoi(trig.substr(0, position));
220 trig = trig.substr(position+1, trig.size());
222 std::pair<std::string, int>
result = std::make_pair(trig,
n);
226 if (
cut.starts_with(
"TRIGDEC_TIGHT ")) {
227 if (selectionHasTriggerCut_Tight) {
228 throw std::runtime_error(
"You have multiple TRIGDEC_TIGHT selectors for selection "
229 +
sel.m_name +
". Only one per selection is allowed.");
231 if (selectionHasTriggerCut) {
232 throw std::runtime_error(
"Both TRIGDEC and TRIGDEC_TIGHT selectors used for selection "
233 +
sel.m_name +
". Only one of the two per selection is allowed.");
235 selectionHasTriggerCut_Tight =
true;
239 std::stringstream
ss(
cut);
242 while (std::getline(
ss,
item, delim)) {
243 if (
item.size() > 0 &&
item.find(
"TRIGDEC_TIGHT") == std::string::npos) {
244 const std::pair<std::string, int>
tmp = splitTrigger(
item);
245 tmpAllTriggers_Tight.insert(
tmp);
246 listAllTriggers_thisSelector_Tight.push_back(
tmp);
249 listAllTriggers_thisSelector_Tight.sort();
250 listAllTriggers_thisSelector_Tight.unique();
253 for (
auto trigger : listAllTriggers_thisSelector_Tight) {
254 allTriggers_thisSelector_Tight.push_back(
trigger);
258 for (
const auto&
trigger : allTriggers_thisSelector_Tight) {
260 electronTriggers_thisSelector_Tight.push_back(
trigger);
263 muonTriggers_thisSelector_Tight.push_back(
trigger);
265 if ((
trigger.first.find(
"_tau") != std::string::npos)) {
266 tauTriggers_thisSelector_Tight.push_back(
trigger);
269 photonTriggers_thisSelector_Tight.push_back(
trigger);
273 allTriggers_perSelector_Tight->insert(std::make_pair(
sel.m_name, allTriggers_thisSelector_Tight));
274 electronTriggers_perSelector_Tight->insert(std::make_pair(
sel.m_name, electronTriggers_thisSelector_Tight));
275 muonTriggers_perSelector_Tight->insert(std::make_pair(
sel.m_name, muonTriggers_thisSelector_Tight));
276 tauTriggers_perSelector_Tight->insert(std::make_pair(
sel.m_name, tauTriggers_thisSelector_Tight));
277 photonTriggers_perSelector_Tight->insert(std::make_pair(
sel.m_name, photonTriggers_thisSelector_Tight));
279 else if (
cut.starts_with(
"TRIGDEC_LOOSE ")) {
280 if (selectionHasTriggerCut_Loose) {
281 throw std::runtime_error(
"You have multiple TRIGDEC_LOOSE selectors for selection "
282 +
sel.m_name +
". Only one per selection is allowed.");
284 if (selectionHasTriggerCut) {
285 throw std::runtime_error(
"Both TRIGDEC and TRIGDEC_LOOSE selectors used for selection "
286 +
sel.m_name +
". Only one of the two per selection is allowed.");
288 selectionHasTriggerCut_Loose =
true;
292 std::stringstream
ss(
cut);
295 while (std::getline(
ss,
item, delim)) {
296 if (
item.size() > 0 &&
item.find(
"TRIGDEC_LOOSE") == std::string::npos) {
297 const std::pair<std::string, int>
tmp = splitTrigger(
item);
298 tmpAllTriggers_Loose.insert(
tmp);
299 listAllTriggers_thisSelector_Loose.push_back(
tmp);
302 listAllTriggers_thisSelector_Loose.sort();
303 listAllTriggers_thisSelector_Loose.unique();
306 for (
auto trigger : listAllTriggers_thisSelector_Loose) {
307 allTriggers_thisSelector_Loose.push_back(
trigger);
311 for (
const auto&
trigger : allTriggers_thisSelector_Loose) {
313 electronTriggers_thisSelector_Loose.push_back(
trigger);
316 muonTriggers_thisSelector_Loose.push_back(
trigger);
318 if ((
trigger.first.find(
"_tau") != std::string::npos)) {
319 tauTriggers_thisSelector_Loose.push_back(
trigger);
322 photonTriggers_thisSelector_Loose.push_back(
trigger);
326 allTriggers_perSelector_Loose->insert(std::make_pair(
sel.m_name, allTriggers_thisSelector_Loose));
327 electronTriggers_perSelector_Loose->insert(std::make_pair(
sel.m_name, electronTriggers_thisSelector_Loose));
328 muonTriggers_perSelector_Loose->insert(std::make_pair(
sel.m_name, muonTriggers_thisSelector_Loose));
329 tauTriggers_perSelector_Loose->insert(std::make_pair(
sel.m_name, tauTriggers_thisSelector_Loose));
330 photonTriggers_perSelector_Loose->insert(std::make_pair(
sel.m_name, photonTriggers_thisSelector_Loose));
332 else if (
cut.starts_with(
"TRIGDEC ")) {
333 if (selectionHasTriggerCut) {
334 throw std::runtime_error(
"GTRIGDEC/TRIGDEC already used for selection "
335 +
sel.m_name +
". Cannot be used multiple times.");
337 if (selectionHasTriggerCut_Tight) {
338 throw std::runtime_error(
"Both TRIGDEC and TRIGDEC_TIGHT already used for selection "
339 +
sel.m_name +
". Cannot be used simultaneously.");
341 if (selectionHasTriggerCut_Loose) {
342 throw std::runtime_error(
"Both TRIGDEC and TRIGDEC_LOOSE already used for selection "
343 +
sel.m_name +
". Cannot be used simultaneously.");
345 selectionHasTriggerCut =
true;
349 std::stringstream
ss(
cut);
352 while (std::getline(
ss,
item, delim)) {
353 if (
item.size() > 0 &&
item.find(
"TRIGDEC") == std::string::npos) {
354 const std::pair<std::string, int>
tmp = splitTrigger(
item);
355 tmpAllTriggers_Tight.insert(
tmp);
356 listAllTriggers_thisSelector_Tight.push_back(
tmp);
357 tmpAllTriggers_Loose.insert(
tmp);
358 listAllTriggers_thisSelector_Loose.push_back(
tmp);
361 listAllTriggers_thisSelector_Tight.sort();
362 listAllTriggers_thisSelector_Tight.unique();
363 listAllTriggers_thisSelector_Loose.sort();
364 listAllTriggers_thisSelector_Loose.unique();
367 for (
auto trigger : listAllTriggers_thisSelector_Tight) {
368 allTriggers_thisSelector_Tight.push_back(
trigger);
370 for (
auto trigger : listAllTriggers_thisSelector_Loose) {
371 allTriggers_thisSelector_Loose.push_back(
trigger);
374 for (
const auto&
trigger : allTriggers_thisSelector_Tight) {
376 electronTriggers_thisSelector_Tight.push_back(
trigger);
379 muonTriggers_thisSelector_Tight.push_back(
trigger);
381 if ((
trigger.first.find(
"_tau") != std::string::npos)) {
382 tauTriggers_thisSelector_Tight.push_back(
trigger);
385 photonTriggers_thisSelector_Tight.push_back(
trigger);
389 for (
const auto&
trigger : allTriggers_thisSelector_Loose) {
391 electronTriggers_thisSelector_Loose.push_back(
trigger);
394 muonTriggers_thisSelector_Loose.push_back(
trigger);
396 if ((
trigger.first.find(
"_tau") != std::string::npos)) {
397 tauTriggers_thisSelector_Loose.push_back(
trigger);
400 photonTriggers_thisSelector_Loose.push_back(
trigger);
404 allTriggers_perSelector_Tight->insert(std::make_pair(
sel.m_name, allTriggers_thisSelector_Tight));
405 electronTriggers_perSelector_Tight->insert(std::make_pair(
sel.m_name, electronTriggers_thisSelector_Tight));
406 muonTriggers_perSelector_Tight->insert(std::make_pair(
sel.m_name, muonTriggers_thisSelector_Tight));
407 tauTriggers_perSelector_Tight->insert(std::make_pair(
sel.m_name, tauTriggers_thisSelector_Tight));
408 photonTriggers_perSelector_Tight->insert(std::make_pair(
sel.m_name, photonTriggers_thisSelector_Tight));
410 allTriggers_perSelector_Loose->insert(std::make_pair(
sel.m_name, allTriggers_thisSelector_Loose));
411 electronTriggers_perSelector_Loose->insert(std::make_pair(
sel.m_name, electronTriggers_thisSelector_Loose));
412 muonTriggers_perSelector_Loose->insert(std::make_pair(
sel.m_name, muonTriggers_thisSelector_Loose));
413 tauTriggers_perSelector_Loose->insert(std::make_pair(
sel.m_name, tauTriggers_thisSelector_Loose));
414 photonTriggers_perSelector_Loose->insert(std::make_pair(
sel.m_name, photonTriggers_thisSelector_Loose));
418 if (!selectionHasGRLCut) {
422 if (!selectionHasGOODCALOCut) {
426 if (!selectionHasTriggerCut) {
428 ATH_MSG_INFO(
"Selection " <<
sel.m_name <<
" Does not request a trigger. No event veto will be applied");
433 tmpAllTriggers_Tight.insert(globalTriggers_Tight.begin(), globalTriggers_Tight.end());
434 tmpAllTriggers_Loose.insert(globalTriggers_Loose.begin(), globalTriggers_Loose.end());
438 std::vector<std::pair<std::string, int> >
tmp;
439 tmp.assign(tmpAllTriggers_Tight.begin(), tmpAllTriggers_Tight.end());
440 std::sort(
tmp.begin(),
tmp.end());
443 tmp.assign(tmpAllTriggers_Loose.begin(), tmpAllTriggers_Loose.end());
444 std::sort(
tmp.begin(),
tmp.end());
457 std::string outputInfoString(
"True");
459 outputInfoString =
"False";
461 ATH_MSG_INFO(
"Apply event veto on trigger decision = " << outputInfoString);
471 if ((
trigger.first.find(
"_tau") != std::string::npos)) {
486 if ((
trigger.first.find(
"_tau") != std::string::npos)) {
495 m_config->allTriggers_Tight(allTriggers_perSelector_Tight);
496 m_config->electronTriggers_Tight(electronTriggers_perSelector_Tight);
497 m_config->muonTriggers_Tight(muonTriggers_perSelector_Tight);
498 m_config->tauTriggers_Tight(tauTriggers_perSelector_Tight);
499 m_config->photonTriggers_Tight(photonTriggers_perSelector_Tight);
500 m_config->allTriggers_Loose(allTriggers_perSelector_Loose);
501 m_config->electronTriggers_Loose(electronTriggers_perSelector_Loose);
502 m_config->muonTriggers_Loose(muonTriggers_perSelector_Loose);
503 m_config->tauTriggers_Loose(tauTriggers_perSelector_Loose);
504 m_config->photonTriggers_Loose(photonTriggers_perSelector_Loose);
507 if (!
m_config->saveOnlySelectedEvents()) {
521 if (!
m_config->isMC() && asg::ToolStore::contains<IGoodRunsListSelectionTool> (
"GoodRunsListSelectionTool")) {
526 eventInfo->
auxdecor<
char>(
"AnalysisTop_GRL") = passGRL;
549 char passGoodCalo(1);
551 bool badTile(
false), badLAr(
false), badSCT(
false), incompleteEvent(
false);
570 incompleteEvent =
true;
573 if (badTile || badLAr || badSCT || incompleteEvent) {
577 eventInfo->
auxdecor<
char>(
"AnalysisTop_GOODCALO") = passGoodCalo;
581 if (passGoodCalo == 1) {
584 if (passGoodCalo == 0) {
605 for (
auto vtx : *vertices) {
608 pri_vtx_z = vtx->z();
612 eventInfo->
auxdecor<
char>(
"AnalysisTop_PRIVTX") = passPriVtx;
613 if (passPriVtx == 1) eventInfo->
auxdecor<
float>(
"AnalysisTop_PRIVTX_z_position") = pri_vtx_z;
617 if (passPriVtx == 1) {
620 if (passPriVtx == 0) {
634 bool orOfAllTriggers(
false);
635 std::set<std::pair<std::string, int> >
triggers;
641 char decoration = passThisTrigger ? 1 : 0;
643 orOfAllTriggers |= passThisTrigger;
648 float prescale = cg->getPrescale();
661 return orOfAllTriggers;
678 std::set<std::pair<std::string, int> >
triggers;
691 char decoration =
match ? 1 : 0;
692 el->auxdecor<
char>(
"TRIGMATCH_" +
trigger.first) = decoration;
707 std::set<std::pair<std::string, int> >
triggers;
710 for (
const auto*
mu : *muons) {
720 char decoration =
match ? 1 : 0;
721 mu->auxdecor<
char>(
"TRIGMATCH_" +
trigger.first) = decoration;
730 "Failed to retrieve EventInfo");
736 "Failed to retrieve taus");
739 for (
const auto* tau : *taus) {
745 if (tau->isAvailable<
char>(
m_config->getDerivationStream() +
"_" +
trigger.first)) {
750 char decoration =
match ? 1 : 0;
751 tau->auxdecor<
char>(
"TRIGMATCH_" +
trigger.first) = decoration;
756 if (tau->isAvailable<
char>(
"TRIGMATCH_" +
trigger.first))
continue;
760 if (tau->isAvailable<
char>(
m_config->getDerivationStream() +
"_" +
trigger.first)) {
765 char decoration =
match ? 1 : 0;
766 tau->auxdecor<
char>(
"TRIGMATCH_" +
trigger.first) = decoration;
775 "Failed to retrieve EventInfo");
781 "Failed to retrieve photons");
784 std::set<std::pair<std::string, int> >
triggers;
787 for (
const auto*
photon : *photons) {
797 char decoration =
match ? 1 : 0;
798 photon->auxdecor<
char>(
"TRIGMATCH_" +
trigger.first) = decoration;
805 extraBranchList.push_back(
"TRIGDEC_" +
trigger.first);
807 if (
std::find(extraBranchList.begin(), extraBranchList.end(),
808 std::string {
"TRIGDEC_"} +
trigger.first) == extraBranchList.end()) {
809 extraBranchList.push_back(
"TRIGDEC_" +
trigger.first);
821 std::vector<std::pair<std::string, int> >
const&
triggers) {
822 std::vector<std::pair<std::string, int> >
result;
823 std::string
const delim(
"_OR_");
828 bool last = (
next == std::string::npos);
829 result.emplace_back(std::string(
"HLT_") +
trigger.first.substr(
cur, (last ? std::string::npos :
next -
cur)), 1);
838 top::check(
trigger.find(
"HLT_") == 0,
"Expected trigger name to start with `HLT_'");
844 top::check(
trigger.find(
"HLT_") == 0,
"Expected trigger name to start with `HLT_'");
851 if (
trigger.find(
"_1g") != std::string::npos)
return true;
852 if (
trigger.find(
"_2g") != std::string::npos)
return true;
854 top::check(
trigger.find(
"HLT_") == 0,
"Expected trigger name to start with `HLT_'");