ATLAS Offline Software
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 
7 #include "CxxUtils/fpcompare.h"
8 
9 using namespace TrigCompositeUtils;
10 
11 TrigHLTMonitorAlgorithm::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 
30 StatusCode 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 
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 
Trig::FeatureRequestDescriptor::setCondition
FeatureRequestDescriptor & setCondition(const unsigned int condition)
Set the Condition: TrigDefs::Physics - (default), only returns features from paths through the naviga...
Definition: FeatureRequestDescriptor.cxx:83
TrigHLTMonitorAlgorithm::m_onlineKey
SG::ReadHandleKey< xAOD::TrigConfKeys > m_onlineKey
Definition: TrigHLTMonitorAlgorithm.h:30
Trig::FeatureRequestDescriptor
Definition: FeatureRequestDescriptor.h:37
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
AthMonitorAlgorithm::m_trigDecTool
PublicToolHandle< Trig::TrigDecisionTool > m_trigDecTool
Tool to tell whether a specific trigger is passed.
Definition: AthMonitorAlgorithm.h:340
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.outputTest_v2.streams
streams
Definition: outputTest_v2.py:55
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
Trig::FeatureRequestDescriptor::setChainGroup
FeatureRequestDescriptor & setChainGroup(const std::string &chainGroupName)
Set the desired Chain or Chain Group.
Definition: FeatureRequestDescriptor.cxx:77
AthMonitorAlgorithm::getTrigDecisionTool
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
Definition: AthMonitorAlgorithm.cxx:189
xAOD::TrigConfKeys_v1::smk
uint32_t smk() const
Get the Super Master Key of this configuration.
Definition: TrigConfKeys_v1.cxx:18
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
TrigConf::HLTChain
HLT chain configuration information.
Definition: TrigConfHLTData/TrigConfHLTData/HLTChain.h:35
TrigHLTMonitorAlgorithm::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: TrigHLTMonitorAlgorithm.cxx:30
CxxUtils::fpcompare::equal
bool equal(double a, double b)
Compare two FP numbers, working around x87 precision issues.
Definition: fpcompare.h:114
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
TrigCompositeUtils::initialRoIString
const std::string & initialRoIString()
Definition: TrigCompositeUtilsRoot.cxx:868
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
TrigHLTMonitorAlgorithm::fillResultAndConsistencyHistograms
StatusCode fillResultAndConsistencyHistograms(const EventContext &ctx) const
Definition: TrigHLTMonitorAlgorithm.cxx:212
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
fpcompare.h
Workaround x86 precision issues for FP inequality comparisons.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
hist_file_dump.f
f
Definition: hist_file_dump.py:135
AthMonitorAlgorithm::fill
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable >> &&variables) const
Fills a vector of variables to a group by reference.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Trig::FeatureRequestDescriptor::setRestrictRequestToLeg
FeatureRequestDescriptor & setRestrictRequestToLeg(const int restrictToLegIndex)
Set to -1 by default, indicating that all legs of multi-leg chains are searched.
Definition: FeatureRequestDescriptor.cxx:113
Trig::ChainGroup
Definition: ChainGroup.h:51
python.hypoToolDisplay.toolname
def toolname(tool)
Definition: hypoToolDisplay.py:13
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
TrigHLTMonitorAlgorithm::TrigHLTMonitorAlgorithm
TrigHLTMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigHLTMonitorAlgorithm.cxx:11
Trig::FeatureRequestDescriptor::setLinkName
FeatureRequestDescriptor & setLinkName(const std::string &navElementLinkKey)
Set the Link Name Key.
Definition: FeatureRequestDescriptor.cxx:107
TrigHLTMonitorAlgorithm::m_trigConfigSvc
ServiceHandle< TrigConf::ITrigConfigSvc > m_trigConfigSvc
Definition: TrigHLTMonitorAlgorithm.h:32
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
TrigCompositeUtils::LinkInfo
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition: LinkInfo.h:28
CaloLCW_tf.group
group
Definition: CaloLCW_tf.py:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
RoiDescriptor::phi
virtual double phi() const override final
Methods to retrieve data members.
Definition: RoiDescriptor.h:100
TrigRoiDescriptorCollection
Definition: TrigRoiDescriptorCollection.h:21
TrigHLTMonitorAlgorithm::m_eventKey
SG::ReadHandleKey< xAOD::TrigConfKeys > m_eventKey
Definition: TrigHLTMonitorAlgorithm.h:29
Trig::ChainGroup::isPassedForEach
std::vector< bool > isPassedForEach(unsigned int condition=TrigDefs::Physics) const
return vector with isPassed decision for each chain
Definition: ChainGroup.cxx:193
RoiDescriptor::isFullscan
virtual bool isFullscan() const override final
is this a full scan RoI?
Definition: RoiDescriptor.h:132
TrigHLTMonitorAlgorithm::~TrigHLTMonitorAlgorithm
virtual ~TrigHLTMonitorAlgorithm()
Definition: TrigHLTMonitorAlgorithm.cxx:17
TrigHLTMonitorAlgorithm.h
RoiDescriptor::eta
virtual double eta() const override final
Definition: RoiDescriptor.h:101
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
Trig::ChainGroup::getListOfTriggers
std::vector< std::string > getListOfTriggers() const
Definition: ChainGroup.cxx:467
xAOD::TrigConfKeys_v1::hltpsk
uint32_t hltpsk() const
Get the HLT prescale key of this configuration.
Definition: TrigConfKeys_v1.cxx:40
python.compressB64.c
def c
Definition: compressB64.py:93
AthMonitorAlgorithm::getGroup
const ToolHandle< GenericMonitoringTool > & getGroup(const std::string &name) const
Get a specific monitoring tool from the tool handle array.
Definition: AthMonitorAlgorithm.cxx:164
TrigHLTMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: TrigHLTMonitorAlgorithm.cxx:20