Belle II Software development
SoftwareTriggerCut.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
9#include <hlt/softwaretrigger/core/SoftwareTriggerCut.h>
10#include <mdst/dataobjects/SoftwareTriggerResult.h>
11#include <hlt/softwaretrigger/core/utilities.h>
12
13#include <framework/logging/Logger.h>
14
15namespace Belle2 {
20 namespace SoftwareTrigger {
21 std::unique_ptr<SoftwareTriggerCut> SoftwareTriggerCut::compile(const std::string& cut_string,
22 unsigned int prescaleFactor,
23 const bool rejectCut)
24 {
25 // The prescale is not used for reject cuts, so a prescale of 0 does NOT switch a reject cut off.
26 if (rejectCut and prescaleFactor == 0) {
27 B2WARNING("A reject cut has a prescale factor of 0, but the prescale is ignored for reject cuts: "
28 "this cut is still active and rejects every event fulfilling its condition. "
29 "To switch it off, remove it from the trigger menu."
30 << LogVar("cut condition", cut_string));
31 }
32
33 auto compiledGeneralCut = GeneralCut<SoftwareTriggerVariableManager>::compile(cut_string);
34 std::unique_ptr<SoftwareTriggerCut> compiledSoftwareTriggerCut(new SoftwareTriggerCut(std::move(compiledGeneralCut),
35 prescaleFactor, rejectCut));
36
37 return compiledSoftwareTriggerCut;
38 }
39
40 std::pair<SoftwareTriggerCutResult, SoftwareTriggerCutResult> SoftwareTriggerCut::check(const
41 SoftwareTriggerVariableManager::Object& prefilledObject, uint32_t* counter) const
42 {
43 if (not m_cut) {
44 B2FATAL("Software Trigger is not initialized!");
45 }
46 const bool cutCondition = m_cut->check(&prefilledObject);
47
48 // If the cut is a reject cut, return false if the cut is true and false if the cut is true.
49 if (isRejectCut()) {
50 if (cutCondition) {
52 } else {
54 }
55 } else {
56 // This is the "normal" accept case:
57 // First check if the cut gives a positive result. If not, we can definitely return "noResult".
58 if (cutCondition) {
59 // if yes, we have to use the prescale factor to see, if the result is really yes.
60 if (makePreScale(getPreScaleFactor(), counter)) {
62 } else {
63 // This is the only case were prescaled and non-prescaled results are different.
65 }
66 } else {
68 }
69 }
70 }
71
73 {
74 return check(prefilledObject).first;
75 }
76 }
78}
static std::unique_ptr< GeneralCut > compile(const std::string &cut)
Creates an instance of a cut and returns a unique_ptr to it, if you need a copy-able object instead y...
Definition GeneralCut.h:84
bool isRejectCut() const
Returns true, if the cut is a reject cut and false otherwise.
unsigned int getPreScaleFactor() const
Return the list of pre scale factors.
SoftwareTriggerCutResult checkPreScaled(const SoftwareTriggerVariableManager::Object &prefilledObject) const
Main function of the SoftwareTriggerCut: check the cut condition.
std::unique_ptr< GeneralCut< SoftwareTriggerVariableManager > > m_cut
Internal representation of the cut condition as a general cut.
SoftwareTriggerCut(std::unique_ptr< GeneralCut< SoftwareTriggerVariableManager > > &&cut, unsigned int prescaleFactor, const bool rejectCut)
Make constructor private.
std::pair< SoftwareTriggerCutResult, SoftwareTriggerCutResult > check(const SoftwareTriggerVariableManager::Object &prefilledObject, uint32_t *counter=nullptr) const
Return both the prescaled and the non-prescaled result.
static std::unique_ptr< SoftwareTriggerCut > compile(const std::string &cut_string, const unsigned int prescaleFactor, const bool rejectCut=false)
Compile a new SoftwareTriggerCut from a cut string (by using the GeneralCut::compile function) and an...
SoftwareTriggerObject Object
As an object handed in for every cut to be checked, use a map of variable name -> precompiled value.
Class to store variables with their name which were sent to the logging service.
SoftwareTriggerCutResult
Enumeration with all possible results of the SoftwareTriggerCut.
@ c_noResult
There were not enough information to decide on what to do with the event.
Abstract base class for different kinds of events.