Belle II Software  release-08-01-10
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 
9 #include <hlt/softwaretrigger/core/FinalTriggerDecisionCalculator.h>
10 #include <mdst/dataobjects/SoftwareTriggerResult.h>
11 #include <hlt/softwaretrigger/core/SoftwareTriggerDBHandler.h>
12 #include <gtest/gtest.h>
13 
14 using namespace std;
15 
16 namespace Belle2 {
21  namespace SoftwareTrigger {
23  TEST(FinalTriggerDecisionCalculatorTest, basic)
24  {
25  SoftwareTriggerResult result;
26 
27  // No results stored
28  EXPECT_EQ(SoftwareTriggerCutResult::c_accept, FinalTriggerDecisionCalculator::getModuleResult(result, "test", true));
29  EXPECT_EQ(SoftwareTriggerCutResult::c_reject, FinalTriggerDecisionCalculator::getModuleResult(result, "test", false));
30 
31  // First result: an accept result
32  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutOne"), SoftwareTriggerCutResult::c_accept);
33 
34  EXPECT_EQ(SoftwareTriggerCutResult::c_accept, result.getResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutOne")));
35  EXPECT_THROW(result.getResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutTwo")), std::out_of_range);
36 
37  EXPECT_EQ(SoftwareTriggerCutResult::c_accept, FinalTriggerDecisionCalculator::getModuleResult(result, "test", true));
38  EXPECT_EQ(SoftwareTriggerCutResult::c_accept, FinalTriggerDecisionCalculator::getModuleResult(result, "test", false));
39 
40  // Another first result: a reject result
41  result.clear();
42  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutOne"), SoftwareTriggerCutResult::c_reject);
43 
44  EXPECT_EQ(SoftwareTriggerCutResult::c_reject, result.getResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutOne")));
45  EXPECT_EQ(SoftwareTriggerCutResult::c_reject, FinalTriggerDecisionCalculator::getModuleResult(result, "test", true));
46  EXPECT_EQ(SoftwareTriggerCutResult::c_reject, FinalTriggerDecisionCalculator::getModuleResult(result, "test", false));
47 
48  // Another first result: a don't know result
49  result.clear();
50  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutOne"), SoftwareTriggerCutResult::c_noResult);
51 
52  EXPECT_EQ(SoftwareTriggerCutResult::c_noResult, result.getResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutOne")));
53  EXPECT_EQ(SoftwareTriggerCutResult::c_accept, FinalTriggerDecisionCalculator::getModuleResult(result, "test", true));
54  EXPECT_EQ(SoftwareTriggerCutResult::c_reject, FinalTriggerDecisionCalculator::getModuleResult(result, "test", false));
55 
56  // Add an unrelated result: should not change anything
57  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("other_test", "cutOne"), SoftwareTriggerCutResult::c_accept);
58 
59  EXPECT_EQ(SoftwareTriggerCutResult::c_accept, result.getResult(SoftwareTriggerDBHandler::makeFullCutName("other_test", "cutOne")));
60 
61  EXPECT_EQ(SoftwareTriggerCutResult::c_accept, FinalTriggerDecisionCalculator::getModuleResult(result, "test", true));
62  EXPECT_EQ(SoftwareTriggerCutResult::c_reject, FinalTriggerDecisionCalculator::getModuleResult(result, "test", false));
63 
64  // Three result
65  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutOne"), SoftwareTriggerCutResult::c_accept);
66  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutTwo"), SoftwareTriggerCutResult::c_noResult);
67  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutThree"), SoftwareTriggerCutResult::c_reject);
68 
69  EXPECT_EQ(SoftwareTriggerCutResult::c_accept, result.getResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutOne")));
70  EXPECT_EQ(SoftwareTriggerCutResult::c_noResult, result.getResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutTwo")));
71  EXPECT_EQ(SoftwareTriggerCutResult::c_reject, result.getResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutThree")));
72 
73  EXPECT_EQ(SoftwareTriggerCutResult::c_accept, FinalTriggerDecisionCalculator::getModuleResult(result, "test", true));
74  EXPECT_EQ(SoftwareTriggerCutResult::c_reject, FinalTriggerDecisionCalculator::getModuleResult(result, "test", false));
75 
76  // Add another accept result: should not change anything
77  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutFour"), SoftwareTriggerCutResult::c_accept);
78 
79  EXPECT_EQ(SoftwareTriggerCutResult::c_accept, FinalTriggerDecisionCalculator::getModuleResult(result, "test", true));
80  EXPECT_EQ(SoftwareTriggerCutResult::c_reject, FinalTriggerDecisionCalculator::getModuleResult(result, "test", false));
81 
82  // More accept than reject: should be the same
83  result.clear();
84  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutOne"), SoftwareTriggerCutResult::c_accept);
85  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutTwo"), SoftwareTriggerCutResult::c_accept);
86  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutThree"), SoftwareTriggerCutResult::c_reject);
87 
88  EXPECT_EQ(SoftwareTriggerCutResult::c_accept, FinalTriggerDecisionCalculator::getModuleResult(result, "test", true));
89  EXPECT_EQ(SoftwareTriggerCutResult::c_reject, FinalTriggerDecisionCalculator::getModuleResult(result, "test", false));
90 
91  // More reject than accept: should be the same
92  result.clear();
93  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutOne"), SoftwareTriggerCutResult::c_reject);
94  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutTwo"), SoftwareTriggerCutResult::c_accept);
95  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutThree"), SoftwareTriggerCutResult::c_reject);
96 
97  EXPECT_EQ(SoftwareTriggerCutResult::c_accept, FinalTriggerDecisionCalculator::getModuleResult(result, "test", true));
98  EXPECT_EQ(SoftwareTriggerCutResult::c_reject, FinalTriggerDecisionCalculator::getModuleResult(result, "test", false));
99 
100  // Add two other accept result: should not change anything
101  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutSix"), SoftwareTriggerCutResult::c_accept);
102  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("test", "cutSeven"), SoftwareTriggerCutResult::c_accept);
103 
104  EXPECT_EQ(SoftwareTriggerCutResult::c_accept, FinalTriggerDecisionCalculator::getModuleResult(result, "test", true));
105  EXPECT_EQ(SoftwareTriggerCutResult::c_reject, FinalTriggerDecisionCalculator::getModuleResult(result, "test", false));
106  }
107 
109  TEST(FinalTriggerDecisionCalculatorTest, result)
110  {
111  SoftwareTriggerResult result;
112 
113  // No results stored -> ne event is accepted.
114  EXPECT_EQ(true, FinalTriggerDecisionCalculator::getFinalTriggerDecision(result));
115 
116  // No total results should not change anything.
117  result.addResult(SoftwareTriggerDBHandler::makeFullCutName("filter", "some_cut"), SoftwareTriggerCutResult::c_reject);
118  EXPECT_EQ(true, FinalTriggerDecisionCalculator::getFinalTriggerDecision(result));
119 
120  // Revision 2
121  // filter has rejected -> reject
122  result.clear();
123  result.addResult(SoftwareTriggerDBHandler::makeTotalResultName("filter"), SoftwareTriggerCutResult::c_reject);
124  EXPECT_EQ(false, FinalTriggerDecisionCalculator::getFinalTriggerDecision(result));
125 
126  // filter has accepted and skim also -> accept
127  result.clear();
128  result.addResult(SoftwareTriggerDBHandler::makeTotalResultName("filter"), SoftwareTriggerCutResult::c_accept);
129  result.addResult(SoftwareTriggerDBHandler::makeTotalResultName("skim"), SoftwareTriggerCutResult::c_accept);
130  EXPECT_EQ(true, FinalTriggerDecisionCalculator::getFinalTriggerDecision(result));
131 
132  // filter has rejected and skim should not change anything -> reject
133  result.clear();
134  result.addResult(SoftwareTriggerDBHandler::makeTotalResultName("filter"), SoftwareTriggerCutResult::c_reject);
135  result.addResult(SoftwareTriggerDBHandler::makeTotalResultName("skim"), SoftwareTriggerCutResult::c_accept);
136  EXPECT_EQ(false, FinalTriggerDecisionCalculator::getFinalTriggerDecision(result));
137 
138  // filter has accepted, skim does not matter -> accept
139  result.clear();
140  result.addResult(SoftwareTriggerDBHandler::makeTotalResultName("filter"), SoftwareTriggerCutResult::c_accept);
141  result.addResult(SoftwareTriggerDBHandler::makeTotalResultName("skim"), SoftwareTriggerCutResult::c_reject);
142  EXPECT_EQ(true, FinalTriggerDecisionCalculator::getFinalTriggerDecision(result));
143 
144  // Revision 1
145  // fast reco has rejected -> reject
146  result.clear();
147  result.addResult(SoftwareTriggerDBHandler::makeTotalResultName("fast_reco"), SoftwareTriggerCutResult::c_reject);
148  EXPECT_EQ(false, FinalTriggerDecisionCalculator::getFinalTriggerDecision(result));
149 
150  // fast reco has accepted and hlt also -> accept
151  result.clear();
152  result.addResult(SoftwareTriggerDBHandler::makeTotalResultName("fast_reco"), SoftwareTriggerCutResult::c_accept);
153  result.addResult(SoftwareTriggerDBHandler::makeTotalResultName("hlt"), SoftwareTriggerCutResult::c_accept);
154  EXPECT_EQ(true, FinalTriggerDecisionCalculator::getFinalTriggerDecision(result));
155 
156  // fast reco has rejected and hlt should not change anything -> reject
157  result.clear();
158  result.addResult(SoftwareTriggerDBHandler::makeTotalResultName("fast_reco"), SoftwareTriggerCutResult::c_reject);
159  result.addResult(SoftwareTriggerDBHandler::makeTotalResultName("hlt"), SoftwareTriggerCutResult::c_accept);
160  EXPECT_EQ(false, FinalTriggerDecisionCalculator::getFinalTriggerDecision(result));
161 
162  // fast reco and hlt have accepted, calib does not matter -> accept
163  result.clear();
164  result.addResult(SoftwareTriggerDBHandler::makeTotalResultName("fast_reco"), SoftwareTriggerCutResult::c_accept);
165  result.addResult(SoftwareTriggerDBHandler::makeTotalResultName("hlt"), SoftwareTriggerCutResult::c_accept);
166  result.addResult(SoftwareTriggerDBHandler::makeTotalResultName("calib"), SoftwareTriggerCutResult::c_reject);
167 
168  }
169  }
171 }
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Abstract base class for different kinds of events.