ATLAS Offline Software
Loading...
Searching...
No Matches
MbtsHypoTool.cxx
Go to the documentation of this file.
1
2/*
3Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
4*/
5
8
9#include "MbtsHypoTool.h"
10
11using namespace TrigCompositeUtils;
12MbtsHypoTool::MbtsHypoTool(const std::string &type, const std::string &name, const IInterface *parent)
13 : AthAlgTool(type, name, parent),
14 m_decisionId(HLT::Identifier::fromToolName(name)) {}
15
17{
18 if (! m_monTool.empty() ) ATH_CHECK( m_monTool.retrieve() );
19 return StatusCode::SUCCESS;
20}
21
22StatusCode MbtsHypoTool::decide(MbtsHypoInfo &info) const
23{
24 ATH_MSG_DEBUG("Executing this T2MbtsHypo " << name());
25
26 if (info.previousDecisionIDs.count(m_decisionId.numeric()) == 0)
27 {
28 ATH_MSG_DEBUG("Already rejected");
29 return StatusCode::SUCCESS;
30 }
31
32 // Calculate MBTS counter multiplicities after energy and an optional time cut.
33 Counts counts = calculateMultiplicities(info.mbtsBits);
34 if (counts.sideA == 0 && counts.sideC == 0)
35 {
36 ATH_MSG_DEBUG("calculateMultiplicities failed, no multiplicities");
37 return StatusCode::SUCCESS;
38 }
39 bool pass = m_acceptAll;
40 if (m_coincidence)
41 { // Coincidence logic
42 if (!m_veto)
43 {
44 if (counts.sideA >= m_mbtsCounters && counts.sideC >= m_mbtsCounters)
45 pass = true;
46 }
47 else
48 {
49 if (counts.sideA < m_mbtsCounters && counts.sideC < m_mbtsCounters)
50 pass = true;
51 }
52 }
53 else
54 {
55 if (m_or)
56 { // Or logic
57 if (!m_veto)
58 {
59 if ((counts.sideA >= m_mbtsCounters || counts.sideC >= m_mbtsCounters))
60 pass = true;
61 }
62 else
63 {
64 if ((counts.sideA < m_mbtsCounters || counts.sideC < m_mbtsCounters))
65 pass = true;
66 }
67 }
68 else
69 { // Sum logic
70 if (!m_veto)
71 {
72 if ((counts.sideA + counts.sideC) >= m_mbtsCounters)
73 pass = true;
74 }
75 else
76 {
77 if ((counts.sideA + counts.sideC) < m_mbtsCounters)
78 pass = true;
79 }
80 }
81 }
82
83 ATH_MSG_DEBUG("REGTEST: event " << (pass ? "accepted" : "failed") << " with EBA(" << counts.sideA << ") + EBC(" << counts.sideC << ") hits above threshold.");
84
85 if (pass)
86 {
87 addDecisionID(m_decisionId.numeric(), info.decision);
88 ATH_MSG_DEBUG("REGTEST event accepted");
89 }
90 return StatusCode::SUCCESS;
91}
92
94{
95
96 if (!t2mbtsBits)
97 {
98 return {0, 0};
99 }
100
101 ATH_MSG_DEBUG("Getting energy and time values.");
102
103 std::vector<float> triggerEnergies = t2mbtsBits->triggerEnergies();
104 std::vector<float> triggerTimes = t2mbtsBits->triggerTimes();
105
106 if (triggerEnergies.size() != xAOD::TrigT2MbtsBits::NUM_MBTS || triggerTimes.size() != xAOD::TrigT2MbtsBits::NUM_MBTS)
107 {
108 ATH_MSG_WARNING("Vector sizes are not equal to number of MBTS counters.");
109 return {0, 0};
110 }
111
112 ATH_MSG_DEBUG("Forming hit multiplicities.");
113
114 std::bitset<16> ebaTriggerBits;
115 std::bitset<16> ebcTriggerBits;
116
117
118 unsigned ibit;
119 int ebaCounters = 0, ebcCounters = 0;
120
121 // Initialize monitoring variables.
122 double timeDiff_A_C = 0.;
123 double timeMean_A = 0.;
124 double timeMean_C = 0.;
125
126 // Loop over each counter and form bit sets from time and energy (optional).
127 for (ibit = 0; ibit < xAOD::TrigT2MbtsBits::NUM_MBTS; ibit++)
128 {
129 if (m_mbtsmode == 1 && !(ibit < 8 || (ibit >= 16 && ibit < 24)))
130 continue; // count only inner
131 if (m_mbtsmode == 2 && !((ibit >= 8 && ibit < 16) || (ibit >= 24 && ibit < 32)))
132 continue; // count only outer
133
134 // Check the energy threshold.
135 if (triggerEnergies[ibit] <= m_threshold)
136 continue;
137
138 // Calculate the mean time for this side;
139 if (ibit < 16)
140 {
141 timeMean_A += triggerTimes[ibit];
142 ebaCounters++;
143 }
144 else
145 {
146 timeMean_C += triggerTimes[ibit];
147 ebcCounters++;
148 }
149
150 // Check the time cut if it is active.
151 if (m_timeCut >= 0 && std::abs(triggerTimes[ibit] - m_timeOffsets[ibit] - m_globalTimeOffset) >= m_timeCut)
152 continue;
153
154 // Set the bits for this side;
155 if (ibit < 16)
156 {
157 ebaTriggerBits.set(ibit);
158 }
159 else
160 {
161 ebcTriggerBits.set(ibit - 16);
162 }
163 }
164
165 if (ebaCounters > 0)
166 {
167 timeMean_A /= ebaCounters;
168 }
169 else
170 {
171 timeMean_A = -999.0;
172 }
173
174 if (ebcCounters > 0)
175 {
176 timeMean_C /= ebcCounters;
177 }
178 else
179 {
180 timeMean_C = -999.0;
181 }
182
183 if (ebaCounters > 0 && ebcCounters > 0)
184 {
185 timeDiff_A_C = timeMean_A - timeMean_C;
186 }
187 else
188 {
189 timeDiff_A_C = -999.0;
190 }
191 ATH_MSG_DEBUG("average MBTS trigger time"
192 << " side A: " << timeMean_A
193 << ", side C: " << timeMean_C
194 << ", difference A-C: " << timeDiff_A_C);
195
196 ATH_MSG_DEBUG("MBTS EBA trigger bits: " << ebaTriggerBits);
197 ATH_MSG_DEBUG("MBTS EBC trigger bits: " << ebcTriggerBits);
198 if ( ! m_monTool.empty() ) {
199 std::vector<int> counts;
200 counts.reserve(ebaTriggerBits.size() + ebcTriggerBits.size());
201
202 for ( size_t bit = 0; bit < ebaTriggerBits.size(); ++bit )
203 counts.push_back( ebaTriggerBits[bit] ? bit : -1 );
204 for ( size_t bit = 0; bit < ebcTriggerBits.size(); ++bit )
205 counts.push_back( ebcTriggerBits[bit] ? bit+ebaTriggerBits.size() : -1 );
206 auto mon_counts = Monitored::Collection("Counts", counts);
207 Monitored::Group(m_monTool, mon_counts);
208 }
209 return {ebaTriggerBits.count(), ebcTriggerBits.count()};
210}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Header file to be included by clients of the Monitored infrastructure.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Property< bool > m_or
Gaudi::Property< int > m_mbtsmode
Gaudi::Property< bool > m_acceptAll
Gaudi::Property< float > m_timeCut
Gaudi::Property< float > m_threshold
Gaudi::Property< std::vector< float > > m_timeOffsets
MbtsHypoTool(const std::string &type, const std::string &name, const IInterface *parent)
Gaudi::Property< bool > m_coincidence
Gaudi::Property< float > m_globalTimeOffset
Gaudi::Property< bool > m_veto
Gaudi::Property< unsigned int > m_mbtsCounters
HLT::Identifier m_decisionId
StatusCode decide(MbtsHypoInfo &decisions) const
Counts calculateMultiplicities(const xAOD::TrigT2MbtsBits *t2mbtsBits) const
ToolHandle< GenericMonitoringTool > m_monTool
virtual StatusCode initialize() override
Group of local monitoring quantities and retain correlation when filling histograms
const std::vector< float > & triggerEnergies() const
Return the trigger energies of each counter.
const std::vector< float > & triggerTimes() const
Return the relative times of the triggers.
static const unsigned int NUM_MBTS
Prints out data members to MsgStream.
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
void addDecisionID(DecisionID id, Decision *d)
Appends the decision (given as ID) to the decision object.