ATLAS Offline Software
Loading...
Searching...
No Matches
MuonClusterHypoAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5//
6// MuonClusterHypoAlg
7// (see header for history/etc..)
8//
10
11#include <cmath>
12#include <algorithm>
13#include <sstream>
14#include "GaudiKernel/MsgStream.h"
15#include "GaudiKernel/StatusCode.h"
16#include "GaudiKernel/ITHistSvc.h"
17
20
24
25#include "CLHEP/Units/SystemOfUnits.h"
26
27class ISvcLocator;
28
43
44MuonClusterHypoAlg::MuonClusterHypoAlg(const std::string & name, ISvcLocator* pSvcLocator):
45 HypoBase(name, pSvcLocator){
46}
47
50
52{
53
54 ATH_MSG_DEBUG("in initialize()");
55 ATH_CHECK( m_outputCompositesKey.initialize() );
56
57 if (!m_hypoTools.empty()) ATH_CHECK(m_hypoTools.retrieve());
58 if (!m_monTool.empty()) ATH_CHECK(m_monTool.retrieve());
59
60
61 ATH_MSG_INFO("initialize() success");
62 return StatusCode::SUCCESS;
63}
64
65StatusCode MuonClusterHypoAlg::execute(const EventContext& ctx) const
66{
67
68 ATH_MSG_DEBUG("in execute()");
69
70 auto CluNum = Monitored::Scalar("NumClu", 3);
71
72 auto acceptAll = Monitored::Scalar<bool>("AcceptAll", false);
73 auto nRoIEndCap = Monitored::Scalar<int>("nRoIEndCap", 4);
74 auto nRoIBarrel = Monitored::Scalar<int>("nRoIBarrel", 3);
75 auto etaMax = Monitored::Scalar<float>("maxEta", 2.5);
76 auto etaMid = Monitored::Scalar<float>("midEta", 1.0);
77 auto isPass = Monitored::Scalar<bool>("isPass", 0);
78
79 auto t1 = Monitored::Timer("TIME_HypoAlg");
80 auto t2 = Monitored::Timer("TIME_HypoAlg_DecisionLoop");
81
82 t1.start();
83
84 auto mon = Monitored::Group(m_monTool, acceptAll, nRoIEndCap, nRoIBarrel, etaMax, etaMid, CluNum, isPass, t1, t2);
85
86 if(acceptAll) {
87 ATH_MSG_DEBUG("Accepting all the events with no cuts!");
88 } else {
89 ATH_MSG_DEBUG("Selecting barrel muon RoI clusters with |eta|< " << etaMid << " and >= " << nRoIBarrel << " RoIs");
90 ATH_MSG_DEBUG("and endcap muon RoI clusters with |eta| > : " << etaMid << "and >= " <<nRoIEndCap << " RoIs");
91 }
92
93 // Obtain incoming Decision Objects (one per L1 muon ROI)
94 auto previousDecisionsHandle = SG::makeHandle( decisionInput(), ctx );
95 ATH_CHECK( previousDecisionsHandle.isValid() );
96 ATH_MSG_DEBUG( "Running with "<< previousDecisionsHandle->size() <<" previous decisions");
97
98 // New output trigger decisions container
100 auto decisions = outputHandle.ptr();
101
102 if (previousDecisionsHandle->size() == 0) {
103 ATH_MSG_DEBUG( "No incoming decision objects, nothing to do");
104 return StatusCode::SUCCESS;
105 }
106
107 // Get the TrigCompositeContainer linked to the ReadHandleKey
108 // it contains the Muon RoI Cluster information
109 auto compContHdl = SG::makeHandle(m_outputCompositesKey, ctx);
110 auto compCont = compContHdl.get();
111
112 if (compCont->size() == 0) {
113 ATH_MSG_DEBUG( "No reconstructed muon-roi-cluster summary object, nothing to do");
114 return StatusCode::SUCCESS;
115 } else if (compCont->size() > 1) {
116 ATH_MSG_ERROR( "This HypoAlg is only expecting exactly one reconstructed muon cluster object, but MuonCluster reconstruction has output " << compCont->size() << ". Cannot currently deal with this.");
117 return StatusCode::FAILURE;
118 }
119
120 // Creating a DecisionIDContainer to hold all active chain IDs
122
123 // Create new output decision object
124 // as we have only one output physics object ("muCluster") and many inputs (L1 muon ROI) we link multiple parents
125 Decision* d = newDecisionIn(decisions, hypoAlgNodeName());
126
127 // Link our physics object ("muCluster")
128 d->setObjectLink( featureString(), ElementLink<xAOD::TrigCompositeContainer>(*compCont, 0, ctx) );
129
130 // Link our parents (L1 muon ROI)
131 for (const Decision* previousDecision : *previousDecisionsHandle) {
132 linkToPrevious(d, previousDecision, ctx);
133 decisionIDs(previousDecision, prev); // Collate active chains on this L1 ROI (previousDecision) into prev
134 }
135
136 // Creating the DecisionInfo struct to pass to the HypoTool
137 MuonClusterHypoTool::DecisionInfo tool_info{d, compCont, std::move(prev)};
138
139 t2.start();
140 for ( auto& tool: m_hypoTools ){
141 ATH_CHECK( tool->decide(tool_info) );
142 }
143 t2.stop();
144
145 // We only have 1 decision. If more decisions are needed in the future, wrap 'if' in a loop over the decision container.
146 if (!allFailed(d)) {isPass = 1;} // allFailed returns true is d is empty, else returns false.
147
148 ATH_CHECK(hypoBaseOutputProcessing(outputHandle));
149
150 return StatusCode::SUCCESS;
151
152}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Decision * newDecisionIn(DecisionContainer *dc, const std::string &name="")
Helper method to create a Decision object, place it in the container and return a pointer to it.
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
const std::string & hypoAlgNodeName()
void decisionIDs(const Decision *d, DecisionIDContainer &id)
Extracts DecisionIDs stored in the Decision object.
const std::string & featureString()
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
bool allFailed(const Decision *d)
return true if there is no positive decision stored
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
const SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > & decisionInput() const
methods for derived classes to access handles of the base class input other read/write handles may be...
Definition HypoBase.cxx:18
const SG::WriteHandleKey< TrigCompositeUtils::DecisionContainer > & decisionOutput() const
methods for derived classes to access handles of the base class output other read/write handles may b...
Definition HypoBase.cxx:22
StatusCode hypoBaseOutputProcessing(SG::WriteHandle< TrigCompositeUtils::DecisionContainer > &outputHandle, MSG::Level lvl=MSG::DEBUG) const
Base class function to be called once slice specific code has finished. Handles debug printing and va...
Definition HypoBase.cxx:35
HypoBase(const std::string &name, ISvcLocator *pSvcLocator)
constructor, to be called by sub-class constructors
Definition HypoBase.cxx:12
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
A monitored timer.
ToolHandleArray< MuonClusterHypoTool > m_hypoTools
virtual StatusCode initialize() override
method to initialize.
~MuonClusterHypoAlg()
Destructor.
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_outputCompositesKey
ToolHandle< GenericMonitoringTool > m_monTool
virtual StatusCode execute(const EventContext &ctx) const override
method to execute.
MuonClusterHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
pointer_type ptr()
Dereference the pointer.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
const std::string & viewString()
Decision * newDecisionIn(DecisionContainer *dc, const std::string &name)
Helper method to create a Decision object, place it in the container and return a pointer to it.
const std::string & featureString()
xAOD::TrigCompositeAuxContainer DecisionAuxContainer
std::set< DecisionID > DecisionIDContainer
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
const std::string & hypoAlgNodeName()
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
bool allFailed(const Decision *d)
return true if there is no positive decision stored
LinkInfo< T > findLink(const Decision *start, const std::string &linkName, const bool suppressMultipleLinksWarning=false)
Perform a recursive search for ElementLinks of type T and name 'linkName', starting from Decision obj...
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22