Belle II Software development
FinalTriggerDecisionCalculator.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <hlt/softwaretrigger/core/FinalTriggerDecisionCalculator.h>
9#include <hlt/softwaretrigger/core/SoftwareTriggerDBHandler.h>
10
11using namespace Belle2;
12using namespace SoftwareTrigger;
13
14bool
16{
17 const auto& results = result.getResults();
18
19 // Handle different revisions of the trigger menu
20 // Revision 2: if there is a final decision already stored, just use it (if not forgetTotalResult is set)
21 const std::string& allTotalResultName = SoftwareTriggerDBHandler::makeTotalResultName();
22
23 auto allTotalResultIterator = results.find(allTotalResultName);
24 if (allTotalResultIterator != results.end() and not forgetTotalResult) {
25 auto allTotalResult = static_cast<SoftwareTriggerCutResult>(allTotalResultIterator->second);
26 return allTotalResult == SoftwareTriggerCutResult::c_accept;
27 }
28
29 // Revision 2: filters are called "filter" and "skim". skim does not change the result.
30 // if "filter" rejected the event, the event is rejected
31 const std::string& filterTotalResultName = SoftwareTriggerDBHandler::makeTotalResultName("filter");
32
33 auto filterTotalResultIterator = results.find(filterTotalResultName);
34
35 if (filterTotalResultIterator != results.end()) {
36 auto filterTotalResult = static_cast<SoftwareTriggerCutResult>(filterTotalResultIterator->second);
37 if (filterTotalResult == SoftwareTriggerCutResult::c_reject) {
38 return false;
39 }
40 }
41
42 // Revision 1: filters are called "fast_reco", "hlt" and "calib". calib does not change result.
43 // if any of fast_reco or hlt rejected the event, the event was rejected at all
44 const std::string& fastRecoTotalResultName = SoftwareTriggerDBHandler::makeTotalResultName("fast_reco");
45 const std::string& hltTotalResultName = SoftwareTriggerDBHandler::makeTotalResultName("hlt");
46
47 auto fastRecoTotalResultIterator = results.find(fastRecoTotalResultName);
48 auto hltTotalResultIterator = results.find(hltTotalResultName);
49
50 if (fastRecoTotalResultIterator != results.end()) {
51 B2WARNING("You are using an old trigger result with a newer version of the software. Make sure this is what you want.");
52 auto fastRecoTotalResult = static_cast<SoftwareTriggerCutResult>(fastRecoTotalResultIterator->second);
53 if (fastRecoTotalResult == SoftwareTriggerCutResult::c_reject) {
54 return false;
55 }
56 }
57 if (hltTotalResultIterator != results.end()) {
58 B2WARNING("You are using an old trigger result with a newer version of the software. Make sure this is what you want.");
59 auto hltTotalResult = static_cast<SoftwareTriggerCutResult>(hltTotalResultIterator->second);
60 if (hltTotalResult == SoftwareTriggerCutResult::c_reject) {
61 return false;
62 }
63 }
64
65 // If there is no reject information (or no total information at all), accept the event :-)
66 return true;
67}
68
69
71 const std::string& baseIdentifier,
72 bool acceptOverridesReject)
73{
74 bool hasOneAcceptCut = false;
75 bool hasOneRejectCut = false;
76
77 for (const auto& resultWithName : result.getResults()) {
78 const std::string& cutName = resultWithName.first;
79
80 if (not SoftwareTriggerDBHandler::hasBaseIdentifier(cutName, baseIdentifier)) {
81 continue;
82 }
83
84 if (cutName == SoftwareTriggerDBHandler::makeTotalResultName(baseIdentifier)) {
85 B2WARNING("The store object already includes a result for this module. Will overwrite it.");
86 continue;
87 }
88
89 const SoftwareTriggerCutResult cutResult = static_cast<SoftwareTriggerCutResult>(resultWithName.second);
90
91 if (cutResult == SoftwareTriggerCutResult::c_accept) {
92 hasOneAcceptCut = true;
93 } else if (cutResult == SoftwareTriggerCutResult::c_reject) {
94 hasOneRejectCut = true;
95 }
96 }
97
98 if (acceptOverridesReject) {
99 if (hasOneAcceptCut or (not hasOneRejectCut)) {
101 } else {
103 }
104 } else {
105 if (hasOneAcceptCut and (not hasOneRejectCut)) {
107 } else {
109 }
110 }
111}
Dataobject to store the results of the cut calculations performed by the SoftwareTriggerModule.
static SoftwareTriggerCutResult getModuleResult(const SoftwareTriggerResult &result, const std::string &baseIdentifier, bool acceptOverridesReject)
Calculate the "total_result" for a given base identifier by looping through all results with the give...
static bool getFinalTriggerDecision(const SoftwareTriggerResult &result, bool forgetTotalResult=false)
Calculate the final cut decision using all "total_results" of all sub triggers in the software trigge...
static bool hasBaseIdentifier(const std::string &cutName, const std::string &baseIdentifier)
Check if a given cut name in the form <package_identifier>&<base_name>&<cut_name> has the given base ...
static std::string makeTotalResultName(const std::string &baseIdentifier="all")
Handy function to create the name related to the total result of a specific trigger stage (either fil...
SoftwareTriggerCutResult
Enumeration with all possible results of the SoftwareTriggerCut.
@ c_accept
Accept this event.
@ c_reject
Reject this event.
Abstract base class for different kinds of events.