Belle II Software prerelease-11-00-00a
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 // Appended new filtering stage: "prefilter" operated before the "filter" stage to reject
32 // background from injection strip, and events with high occupancy.
33
34 // --- Prefilter stage --- //
35 const std::string& prefilterTotalResultName = SoftwareTriggerDBHandler::makeTotalResultName("prefilter");
36
37 auto prefilterTotalResultIterator = results.find(prefilterTotalResultName);
38
39 if (prefilterTotalResultIterator != results.end()) {
40 auto prefilterTotalResult = static_cast<SoftwareTriggerCutResult>(prefilterTotalResultIterator->second);
41 if (prefilterTotalResult == SoftwareTriggerCutResult::c_reject) {
42 return false;
43 }
44 }
45
46 const std::string& filterTotalResultName = SoftwareTriggerDBHandler::makeTotalResultName("filter");
47
48 auto filterTotalResultIterator = results.find(filterTotalResultName);
49
50 if (filterTotalResultIterator != results.end()) {
51 auto filterTotalResult = static_cast<SoftwareTriggerCutResult>(filterTotalResultIterator->second);
52 if (filterTotalResult == SoftwareTriggerCutResult::c_reject) {
53 return false;
54 }
55 }
56
57 // Revision 1: filters are called "fast_reco", "hlt" and "calib". calib does not change result.
58 // if any of fast_reco or hlt rejected the event, the event was rejected at all
59 const std::string& fastRecoTotalResultName = SoftwareTriggerDBHandler::makeTotalResultName("fast_reco");
60 const std::string& hltTotalResultName = SoftwareTriggerDBHandler::makeTotalResultName("hlt");
61
62 auto fastRecoTotalResultIterator = results.find(fastRecoTotalResultName);
63 auto hltTotalResultIterator = results.find(hltTotalResultName);
64
65 if (fastRecoTotalResultIterator != results.end()) {
66 B2WARNING("You are using an old trigger result with a newer version of the software. Make sure this is what you want.");
67 auto fastRecoTotalResult = static_cast<SoftwareTriggerCutResult>(fastRecoTotalResultIterator->second);
68 if (fastRecoTotalResult == SoftwareTriggerCutResult::c_reject) {
69 return false;
70 }
71 }
72 if (hltTotalResultIterator != results.end()) {
73 B2WARNING("You are using an old trigger result with a newer version of the software. Make sure this is what you want.");
74 auto hltTotalResult = static_cast<SoftwareTriggerCutResult>(hltTotalResultIterator->second);
75 if (hltTotalResult == SoftwareTriggerCutResult::c_reject) {
76 return false;
77 }
78 }
79
80 // If there is no reject information (or no total information at all), accept the event :-)
81 return true;
82}
83
84
86 const std::string& baseIdentifier,
87 bool acceptOverridesReject)
88{
89 bool hasOneAcceptCut = false;
90 bool hasOneRejectCut = false;
91
92 for (const auto& resultWithName : result.getResults()) {
93 const std::string& cutName = resultWithName.first;
94
95 if (not SoftwareTriggerDBHandler::hasBaseIdentifier(cutName, baseIdentifier)) {
96 continue;
97 }
98
99 if (cutName == SoftwareTriggerDBHandler::makeTotalResultName(baseIdentifier)) {
100 B2WARNING("The store object already includes a result for this module. Will overwrite it.");
101 continue;
102 }
103
104 const SoftwareTriggerCutResult cutResult = static_cast<SoftwareTriggerCutResult>(resultWithName.second);
105
106 if (cutResult == SoftwareTriggerCutResult::c_accept) {
107 hasOneAcceptCut = true;
108 } else if (cutResult == SoftwareTriggerCutResult::c_reject) {
109 hasOneRejectCut = true;
110 }
111 }
112
113 if (acceptOverridesReject) {
114 if (hasOneAcceptCut or (not hasOneRejectCut)) {
116 } else {
118 }
119 } else {
120 if (hasOneAcceptCut and (not hasOneRejectCut)) {
122 } else {
124 }
125 }
126}
127
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.
Abstract base class for different kinds of events.