Belle II Software  release-05-02-19
FinalTriggerDecisionCalculator.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <hlt/softwaretrigger/core/FinalTriggerDecisionCalculator.h>
11 #include <hlt/softwaretrigger/core/SoftwareTriggerDBHandler.h>
12 
13 using namespace Belle2;
14 using namespace SoftwareTrigger;
15 
16 bool
18 {
19  const auto& results = result.getResults();
20 
21  // Handle different revisions of the trigger menu
22  // Revision 2: if there is a final decision already stored, just use it (if not forgetTotalResult is set)
23  const std::string& allTotalResultName = SoftwareTriggerDBHandler::makeTotalResultName();
24 
25  auto allTotalResultIterator = results.find(allTotalResultName);
26  if (allTotalResultIterator != results.end() and not forgetTotalResult) {
27  auto allTotalResult = static_cast<SoftwareTriggerCutResult>(allTotalResultIterator->second);
28  return allTotalResult == SoftwareTriggerCutResult::c_accept;
29  }
30 
31  // Revision 2: filters are called "filter" and "skim". skim does not change the result.
32  // if "filter" rejected the event, the event is rejected
33  const std::string& filterTotalResultName = SoftwareTriggerDBHandler::makeTotalResultName("filter");
34 
35  auto filterTotalResultIterator = results.find(filterTotalResultName);
36 
37  if (filterTotalResultIterator != results.end()) {
38  auto filterTotalResult = static_cast<SoftwareTriggerCutResult>(filterTotalResultIterator->second);
39  if (filterTotalResult == SoftwareTriggerCutResult::c_reject) {
40  return false;
41  }
42  }
43 
44  // Revision 1: filters are called "fast_reco", "hlt" and "calib". calib does not change result.
45  // if any of fast_reco or hlt rejected the event, the event was rejected at all
46  const std::string& fastRecoTotalResultName = SoftwareTriggerDBHandler::makeTotalResultName("fast_reco");
47  const std::string& hltTotalResultName = SoftwareTriggerDBHandler::makeTotalResultName("hlt");
48 
49  auto fastRecoTotalResultIterator = results.find(fastRecoTotalResultName);
50  auto hltTotalResultIterator = results.find(hltTotalResultName);
51 
52  if (fastRecoTotalResultIterator != results.end()) {
53  B2WARNING("You are using an old trigger result with a newer version of the software. Make sure this is what you want.");
54  auto fastRecoTotalResult = static_cast<SoftwareTriggerCutResult>(fastRecoTotalResultIterator->second);
55  if (fastRecoTotalResult == SoftwareTriggerCutResult::c_reject) {
56  return false;
57  }
58  }
59  if (hltTotalResultIterator != results.end()) {
60  B2WARNING("You are using an old trigger result with a newer version of the software. Make sure this is what you want.");
61  auto hltTotalResult = static_cast<SoftwareTriggerCutResult>(hltTotalResultIterator->second);
62  if (hltTotalResult == SoftwareTriggerCutResult::c_reject) {
63  return false;
64  }
65  }
66 
67  // If there is no reject information (or no total information at all), accept the event :-)
68  return true;
69 }
70 
71 
73  const std::string& baseIdentifier,
74  bool acceptOverridesReject)
75 {
76  bool hasOneAcceptCut = false;
77  bool hasOneRejectCut = false;
78 
79  for (const auto& resultWithName : result.getResults()) {
80  const std::string& cutName = resultWithName.first;
81 
82  if (not SoftwareTriggerDBHandler::hasBaseIdentifier(cutName, baseIdentifier)) {
83  continue;
84  }
85 
86  if (cutName == SoftwareTriggerDBHandler::makeTotalResultName(baseIdentifier)) {
87  B2WARNING("The store object already includes a result for this module. Will overwrite it.");
88  continue;
89  }
90 
91  const SoftwareTriggerCutResult cutResult = static_cast<SoftwareTriggerCutResult>(resultWithName.second);
92 
93  if (cutResult == SoftwareTriggerCutResult::c_accept) {
94  hasOneAcceptCut = true;
95  } else if (cutResult == SoftwareTriggerCutResult::c_reject) {
96  hasOneRejectCut = true;
97  }
98  }
99 
100  if (acceptOverridesReject) {
101  if (hasOneAcceptCut or (not hasOneRejectCut)) {
103  } else {
105  }
106  } else {
107  if (hasOneAcceptCut and (not hasOneRejectCut)) {
109  } else {
111  }
112  }
113 }
Belle2::SoftwareTrigger::SoftwareTriggerDBHandler::hasBaseIdentifier
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 ...
Definition: SoftwareTriggerDBHandler.cc:60
Belle2::SoftwareTrigger::FinalTriggerDecisionCalculator::getFinalTriggerDecision
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...
Definition: FinalTriggerDecisionCalculator.cc:17
Belle2::SoftwareTriggerCutResult::c_accept
@ c_accept
Accept this event.
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SoftwareTriggerCutResult::c_reject
@ c_reject
Reject this event.
Belle2::SoftwareTriggerResult
Dataobject to store the results of the cut calculations performed by the SoftwareTriggerModule.
Definition: SoftwareTriggerResult.h:46
Belle2::SoftwareTrigger::SoftwareTriggerDBHandler::makeTotalResultName
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...
Definition: SoftwareTriggerDBHandler.cc:48
Belle2::SoftwareTrigger::FinalTriggerDecisionCalculator::getModuleResult
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...
Definition: FinalTriggerDecisionCalculator.cc:72
Belle2::SoftwareTriggerCutResult
SoftwareTriggerCutResult
Enumeration with all possible results of the SoftwareTriggerCut.
Definition: SoftwareTriggerResult.h:31