Belle II Software development
FinalTriggerDecisionCalculator Class Reference

Helper class to give the getFinalTriggerDecision to python. More...

#include <FinalTriggerDecisionCalculator.h>

Static Public Member Functions

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 trigger (filter and skim).
 
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 given base identifier.
 

Detailed Description

Helper class to give the getFinalTriggerDecision to python.

Definition at line 18 of file FinalTriggerDecisionCalculator.h.

Member Function Documentation

◆ getFinalTriggerDecision()

bool getFinalTriggerDecision ( const SoftwareTriggerResult result,
bool  forgetTotalResult = false 
)
static

Calculate the final cut decision using all "total_results" of all sub triggers in the software trigger (filter and skim).

The return value is a bool, which has the values accept (true) and reject (false):

  • accept if and only if the filter stage has accepted the event. The event is also accepted if none of the triggers have run.
  • reject if the filter stage rejected the event

If the final result is already stored to the result, it is returned immediately. Except for forgetTotalResult is st to true.

Deprecated: in an older version, the trigger stages were called "hlt", "fast_reco" and "skim". They are still supported by the function to read in old results, but should not be used anymore for new data. A warning will be issued.

Definition at line 15 of file FinalTriggerDecisionCalculator.cc.

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}
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.

◆ getModuleResult()

SoftwareTriggerCutResult getModuleResult ( const SoftwareTriggerResult result,
const std::string &  baseIdentifier,
bool  acceptOverridesReject 
)
static

Calculate the "total_result" for a given base identifier by looping through all results with the given base identifier.

The result of the function then depends on the setting of accept overrides reject. Please see the SoftwareTriggerModule description, for more information.

Definition at line 70 of file FinalTriggerDecisionCalculator.cc.

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}
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 ...

The documentation for this class was generated from the following files: