ATLAS Offline Software
Loading...
Searching...
No Matches
TrigHLTMonitorAlgorithm.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
9using namespace TrigCompositeUtils;
10
11TrigHLTMonitorAlgorithm::TrigHLTMonitorAlgorithm( const std::string& name, ISvcLocator* pSvcLocator )
12 : AthMonitorAlgorithm(name,pSvcLocator)
13{
14}
15
16
18
19
21
22 ATH_CHECK( m_eventKey.initialize() );
23 ATH_CHECK( m_onlineKey.initialize() );
24 ATH_CHECK( m_trigConfigSvc.retrieve() );
25
27}
28
29
30StatusCode TrigHLTMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
31 using namespace Monitored;
32
33 //Fetch the general tool
34 auto tool = getGroup("TrigHLTMonitor");
35
36
38 // Declare the quantities which should be monitored
39 // NB! The variables and histograms defined here must match the ones in the py file exactly!
40
41 auto L1Events = Monitored::Scalar<std::string>("L1Events");
42
43
45 // L1 items monitoring
46
47 const Trig::ChainGroup* l1group = getTrigDecisionTool()->getChainGroup("L1_.*");
48 const std::vector<std::string> L1items = l1group->getListOfTriggers();
49 const std::vector<bool> isPassed = l1group->isPassedForEach();
50
51 ATH_MSG_DEBUG("Filling L1Events histogram");
52 for(size_t i = 0; i<isPassed.size(); i++) {
53 if(isPassed[i]) {
55 L1Events = L1items[i];
56 ATH_MSG_DEBUG("L1Chain " << L1items[i] << " is passed");
57 fill(tool,L1Events);
58 }
59 }
60
61
63 // HLT chain monitoring
64 ATH_MSG_DEBUG( "HLT chain monitoring" );
65
66 //Set up the regex map
67 std::map<std::string,std::string> streams;
68 streams.insert(std::make_pair("HLT_AllChains", "HLT_.*"));
69 streams.insert(std::make_pair("HLT_Electrons", "HLT_[0-9]*e[0-9]+.*"));
70 streams.insert(std::make_pair("HLT_Gamma", "HLT_[0-9]*g[0-9]+.*"));
71 streams.insert(std::make_pair("HLT_Muons", "HLT_[0-9]*mu[0-9]+.*"));
72 streams.insert(std::make_pair("HLT_Taus", "HLT_(tau[0-9]*|trk.*Tau).*"));
73 streams.insert(std::make_pair("HLT_MissingET", "HLT_(t|x)e[0-9]+.*"));
74 streams.insert(std::make_pair("HLT_Jets", "HLT_[0-9]*j[0-9]+.*"));
75 streams.insert(std::make_pair("HLT_MinBias", "HLT_mb.*"));
76
77
79
80 //Number of RoIs per signature
81 std::vector<int> roiN;
82
83 //Iterate over the regex map...
84 std::map<std::string,std::string>::const_iterator strItr;
85 int N_sig = 0;
86 for (strItr=streams.begin();strItr!=streams.end(); ++strItr){
87 std::string signaturename = strItr->first;
88 std::string thisregex = strItr->second;
89
90 //Open the right group
91 std::string toolname = "Trig"+signaturename+"Monitor";
92 ATH_MSG_DEBUG("Initializing tool " << toolname );
93 auto thisTool = getGroup(toolname);
94
95 //RAW and PS
96 std::string histname_raw = signaturename+"RAW";
97 std::string histname_ps = signaturename+"PS";
98 auto HLT_RAW = Monitored::Scalar<std::string>(histname_raw);
99 auto HLT_PS = Monitored::Scalar<std::string>(histname_ps);
100
101 //eta and phi
102 std::string histname_eta=signaturename+"_eta";
103 std::string histname_phi=signaturename+"_phi";
104 auto RoI_eta = Monitored::Scalar(histname_eta,0.0);
105 auto RoI_phi = Monitored::Scalar(histname_phi,0.0);
106
107
108 //Number of RoIs
109 roiN.push_back(0); //initialize roiN at 0 for each signature
110 std::string histname_roiN=signaturename+"RoI_N";
111 auto RoI_N = Monitored::Scalar(histname_roiN,0);
112
113 //Loop over HLT chains
114 ATH_MSG_DEBUG( "Filling HLT" << signaturename << " and RoI information for " << thisregex );
115
116 const Trig::ChainGroup* group = getTrigDecisionTool()->getChainGroup(thisregex);
117 const std::vector<std::string> chainNames = group->getListOfTriggers();
118 const std::vector<bool> isPassed = group->isPassedForEach(TrigDefs::requireDecision);
119
120 for(size_t i=0; i<isPassed.size(); i++) {
121 if(isPassed[i]) {
122 const std::string& chain = chainNames[i];
123 ATH_MSG_DEBUG( " Chain " << chain << " IS passed");
124
126 HLT_RAW = chain;
127 fill(tool,HLT_RAW);
128
129 //If the chain is prescaled
130 const TrigConf::HLTChain* c = getTrigDecisionTool()->ExperimentalAndExpertMethods().getChainConfigurationDetails(chain);
131 float prescale = 0;
132 if (c) {
133 prescale = c->prescale();
134 }
135 else {
136 ATH_MSG_WARNING("No chain found in trigDecTool->ExperimentalAndExpertMethods().getChainConfigurationDetails(" << chain << "). Using prescale 0");
137 }
138 if(!CxxUtils::fpcompare::equal(prescale, 1.0f)) {
139 HLT_PS = chain;
140 ATH_MSG_DEBUG( "HLT_PS: " << chain << " has PS = " << prescale);
141 fill(tool,HLT_PS);
142 }
143
145 Trig::FeatureRequestDescriptor featureRequestDescriptor;
146 featureRequestDescriptor.setChainGroup(chain);
147 featureRequestDescriptor.setCondition(TrigDefs::Physics);
148 featureRequestDescriptor.setLinkName(initialRoIString());
149 featureRequestDescriptor.setRestrictRequestToLeg(0); //look only at first leg in multiple-leg chains such as HLT_eX_tauX, ATR-26626
150 std::vector<LinkInfo<TrigRoiDescriptorCollection>> fvec = m_trigDecTool->features<TrigRoiDescriptorCollection>(featureRequestDescriptor);
151
152 //Loop over RoIs
153 for (const LinkInfo<TrigRoiDescriptorCollection>& li : fvec) {
154 if( li.isValid() ) {
155
156 //Fill 1D histos of roi_N, eta, phi
157 const TrigRoiDescriptor* roi = *(li.link).cptr();
158 if(!roi->isFullscan()) {
159 RoI_eta = roi->eta();
160 RoI_phi = roi->phi();
161 fill(tool,RoI_eta);
162 fill(tool,RoI_phi);
163 roiN[N_sig]++;
164 }
165 else {
166 ATH_MSG_DEBUG( "RoI is FULLSCAN, chain " << chain);
167 }
168
169 //Fill 2D RoI maps
170 auto phi = Monitored::Scalar("phi",0.0);
171 auto eta = Monitored::Scalar("eta",0.0);
172
173 if(!roi->isFullscan()) {
174 auto HLT_RoIs = Monitored::Group(thisTool, eta, phi);
175 const TrigRoiDescriptor* roi = *(li.link).cptr();
176 eta = roi->eta();
177 phi = roi->phi();
178 }
179 }//end if(li.isValid())
180
181 else {
182 ATH_MSG_WARNING( "TrigRoiDescriptorCollection for chain " << chain << " is not valid");
183 }
184
185 }
186 }
187 }
188
189 //Fill RoI count per stream
190 RoI_N = roiN[N_sig];
191 if(roiN[N_sig]>0) {//only fill if we have at least one RoI for the signature
192 fill(tool,RoI_N);
193 }
194
195 N_sig++;
196 }//end loop over streams
197
198
200 // HLTResult and ConfigConsistency
201
203
204
206 // End
207 ATH_MSG_DEBUG( "Finalizing the TrigHLTMonitorAlgorithm..." );
208 return StatusCode::SUCCESS;
209}
210
211
212StatusCode TrigHLTMonitorAlgorithm::fillResultAndConsistencyHistograms( const EventContext& ctx ) const {
213
214 using namespace Monitored;
215 StatusCode sc_hltEvents = StatusCode::FAILURE;
216 StatusCode sc_onlineKeys = StatusCode::FAILURE;
217 StatusCode sc_eventKeys = StatusCode::FAILURE;
218 ATH_MSG_DEBUG("Filling Result and Consistency histograms");
219
220 // Declare the quantities which should be monitored
221 //NB! The variables and histograms defined here must match the ones in the py file exactly!
222 auto HLTEvents = Monitored::Scalar<int>("HLTEvents",0);
223 auto ConfigConsistency_HLT = Monitored::Scalar<int>("ConfigConsistency_HLT",0);
224
227
228 sc_hltEvents = StatusCode::SUCCESS; //This is just a counter variable. If we are executing this code, we fill it.
229
230 if( onlineKeys.isValid() ) {
231 sc_onlineKeys = StatusCode::SUCCESS;
232 ATH_MSG_DEBUG("onlineKeys are valid");
233 }
234 else {
235 ATH_MSG_ERROR("TrigConfKeysOnline not available");
236 }
237 if( eventKeys.isValid() ) {
238 sc_eventKeys = StatusCode::SUCCESS;
239 ATH_MSG_DEBUG("eventKeys are valid");
240 }
241 else {
242 ATH_MSG_ERROR("TrigConfKeys not available");
243 }
244
246 // HLTResult and ConfigConsistency
247
248 uint32_t bskeys_1 = 9999; uint32_t bskeys_2 = 9999;
249
250 // Fill. First argument is the tool (GMT) name as defined in the py file,
251 // all others are the variables to be saved.
252 // Alternative fill method. Get the group yourself, and pass it to the fill function.
253 auto tool = getGroup("TrigHLTMonitor");
254
255 ATH_MSG_DEBUG("Fetching keys from TrigConfKeysOnline");
256 if(sc_onlineKeys == StatusCode::SUCCESS) {
257 bskeys_1 = onlineKeys->smk();
258 bskeys_2 = onlineKeys->hltpsk();
259 ATH_MSG_DEBUG("TrigConfKeysOnline: SMK = bskeys_1 = " << bskeys_1 << ", HLTPSK = bskeys_2 = " << bskeys_2);
260 }
261 else {
262 ATH_MSG_WARNING("===> No online keys");
263 ConfigConsistency_HLT=7;
264 fill(tool,ConfigConsistency_HLT); //Fills the first warning bin in the ConfigConsistency histogram
265 bskeys_1 = 0;
266 bskeys_2 = 0;
267 ATH_MSG_DEBUG("No online keys, reverting to default 0: SMK = bskeys_1 = " << bskeys_1 << ", HLTPSK = bskeys_2 = " << bskeys_2);
268 }
269
270 ATH_MSG_DEBUG("===> Filling ConfigConsistency_HLT");
271
272 uint32_t bskeys[] = {bskeys_1, bskeys_2};
273 uint32_t dbkeys[2];
274 ATH_MSG_DEBUG("Fetching keys from TrigConfKeys");
275 if(sc_eventKeys == StatusCode::SUCCESS) {
276 dbkeys[0] = eventKeys->smk();
277 dbkeys[1] = eventKeys->hltpsk();
278
279 ATH_MSG_DEBUG("TrigConfKeys: SMK = dbkeys[0] = " << dbkeys[0] << ", HLTPSK = dbkeys[1] = " << dbkeys[1]);
280 }
281 else {
282 ATH_MSG_WARNING("===> No event keys");
283 ConfigConsistency_HLT=8;
284 fill(tool,ConfigConsistency_HLT); //Fills the second warning bin in the ConfigConsistency histogram
285 dbkeys[0] = 0;
286 dbkeys[1] = 0;
287 ATH_MSG_DEBUG("No event keys, reverting to default 0: SMK = dbkeys[0] = " << dbkeys[0] << ", HLTPSK = dbkeys[1] = " << dbkeys[0]);
288 }
289
290 for(int i = 0; i < 2; ++i) {
291 ATH_MSG_DEBUG("i = " << i << ", dbkeys[" << i << "] = " << dbkeys[i] << ", bskeys[" << i << "] = " << bskeys[i]);
292 if(dbkeys[i]==0) {
293 ConfigConsistency_HLT=3*i+1;
294 fill(tool,ConfigConsistency_HLT);
295 ATH_MSG_DEBUG("dbkeys[" << i << "] = 0, ConfigConsistency_HLT=" << ConfigConsistency_HLT);
296 }
297 if(bskeys[i]==0) {
298 ConfigConsistency_HLT=3*i+2;
299 fill(tool,ConfigConsistency_HLT);
300 ATH_MSG_DEBUG("bskeys[" << i << "] = 0, ConfigConsistency_HLT=" << ConfigConsistency_HLT);
301 }
302 if(dbkeys[i]!=bskeys[i]) {
303 ConfigConsistency_HLT=3*i+3;
304 fill(tool,ConfigConsistency_HLT);
305 ATH_MSG_DEBUG("dbkeys[" << i << "]!=bskeys[" << i << "], ConfigConsistency_HLT=" << ConfigConsistency_HLT);
306 }
307 }
308
309
310
311 //Fill HLTEvent histogram
312 //this was called HLTResult in Run1-2,
313 //but HLTResult has a slightly different meaning now
314 HLTEvents = (int)sc_hltEvents.isSuccess();
315 fill(tool,HLTEvents); //Always fill, for every event
316
317 return StatusCode::SUCCESS;
318}
319
320
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
const ToolHandle< GenericMonitoringTool > & getGroup(const std::string &name) const
Get a specific monitoring tool from the tool handle array.
virtual StatusCode initialize() override
initialize
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
PublicToolHandle< Trig::TrigDecisionTool > m_trigDecTool
Tool to tell whether a specific trigger is passed.
AthMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
virtual bool isFullscan() const override final
is this a full scan RoI?
virtual double phi() const override final
Methods to retrieve data members.
virtual double eta() const override final
virtual bool isValid() override final
Can the handle be successfully dereferenced?
HLT chain configuration information.
SG::ReadHandleKey< xAOD::TrigConfKeys > m_eventKey
virtual StatusCode initialize() override
initialize
TrigHLTMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
SG::ReadHandleKey< xAOD::TrigConfKeys > m_onlineKey
ServiceHandle< TrigConf::ITrigConfigSvc > m_trigConfigSvc
StatusCode fillResultAndConsistencyHistograms(const EventContext &ctx) const
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
std::vector< bool > isPassedForEach(unsigned int condition=TrigDefs::Physics) const
return vector with isPassed decision for each chain
std::vector< std::string > getListOfTriggers() const
FeatureRequestDescriptor & setCondition(const unsigned int condition)
Set the Condition: TrigDefs::Physics - (default), only returns features from paths through the naviga...
FeatureRequestDescriptor & setLinkName(const std::string &navElementLinkKey)
Set the Link Name Key.
FeatureRequestDescriptor & setChainGroup(const std::string &chainGroupName)
Set the desired Chain or Chain Group.
FeatureRequestDescriptor & setRestrictRequestToLeg(const int restrictToLegIndex)
Set to -1 by default, indicating that all legs of multi-leg chains are searched.
Workaround x86 precision issues for FP inequality comparisons.
bool equal(double a, double b)
Compare two FP numbers, working around x87 precision issues.
Definition fpcompare.h:114
Generic monitoring tool for athena components.
const std::string & initialRoIString()
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22
void fill(H5::Group &out_file, size_t iterations)