ATLAS Offline Software
MuonClusterHypoAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //
6 // MuonClusterHypoAlg
7 // (see header for history/etc..)
8 //
9 #include "MuonClusterHypoAlg.h"
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 
18 #include "StoreGate/ReadHandle.h"
19 #include "StoreGate/WriteHandle.h"
20 
24 
25 #include "CLHEP/Units/SystemOfUnits.h"
26 
27 class ISvcLocator;
28 
43 
44 MuonClusterHypoAlg::MuonClusterHypoAlg(const std::string & name, ISvcLocator* pSvcLocator):
45  HypoBase(name, pSvcLocator){
46 }
47 
49 }
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 
65 StatusCode 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
121  DecisionIDContainer prev;
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
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, 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 }
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
MuonClusterHypoAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: MuonClusterHypoAlg.h:78
TrigCompositeUtils::DecisionContainer
xAOD::TrigCompositeContainer DecisionContainer
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigCompositeContainer.h:21
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TrigCompositeUtils::newDecisionIn
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.
Definition: TrigCompositeUtilsRoot.cxx:46
hist_file_dump.d
d
Definition: hist_file_dump.py:137
TrigCompositeUtils::hypoAlgNodeName
const std::string & hypoAlgNodeName()
Definition: TrigCompositeUtilsRoot.cxx:904
ALFA_EventTPCnv_Dict::t1
std::vector< ALFA_RawDataCollection_p1 > t1
Definition: ALFA_EventTPCnvDict.h:43
xAOD::etaMax
etaMax
Definition: HIEventShape_v2.cxx:46
HypoBase::decisionInput
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:16
TrigCompositeUtils::createAndStore
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
Definition: TrigCompositeUtilsRoot.cxx:30
HypoBase::decisionOutput
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:20
MuonClusterHypoAlg::MuonClusterHypoAlg
MuonClusterHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: MuonClusterHypoAlg.cxx:44
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
MuonClusterHypoAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
method to execute.
Definition: MuonClusterHypoAlg.cxx:65
WriteHandle.h
Handle class for recording to StoreGate.
MuonClusterHypoAlg::initialize
virtual StatusCode initialize() override
method to initialize.
Definition: MuonClusterHypoAlg.cxx:51
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HypoBase::hypoBaseOutputProcessing
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:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MuonClusterHypoAlg::m_outputCompositesKey
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_outputCompositesKey
Definition: MuonClusterHypoAlg.h:65
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::decisions
decisions
Definition: TrigComposite_v1.cxx:101
TrigCompositeUtils::DecisionAuxContainer
xAOD::TrigCompositeAuxContainer DecisionAuxContainer
Definition: TrigCompositeAuxContainer.h:20
TrigCompositeContainer.h
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:884
MuonClusterHypoTool::DecisionInfo
Definition: MuonClusterHypoTool.h:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
HypoBase
Hypothesis algorithms take the output of reco algorithms and the decision from the preceeding InputMa...
Definition: HypoBase.h:13
TrigCompositeUtils::Decision
xAOD::TrigComposite Decision
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:20
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
TrigCompositeUtils::linkToPrevious
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
Definition: TrigCompositeUtilsRoot.cxx:139
ALFA_EventTPCnv_Dict::t2
std::vector< ALFA_RawDataContainer_p1 > t2
Definition: ALFA_EventTPCnvDict.h:44
MuonClusterHypoAlg.h
TrigCompositeUtils::LinkInfo
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition: LinkInfo.h:28
TrigCompositeUtils::DecisionIDContainer
std::set< DecisionID > DecisionIDContainer
Definition: TrigComposite_v1.h:28
TrigCompositeUtils::findLink
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...
plotBeamSpotMon.mon
mon
Definition: plotBeamSpotMon.py:67
TrigCompositeUtils::allFailed
bool allFailed(const Decision *d)
return true if there is no positive decision stored
Definition: TrigCompositeUtilsRoot.cxx:103
TrigCompositeUtils::decisionIDs
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
Definition: TrigCompositeUtilsRoot.cxx:67
TrigRoiDescriptor.h
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
ReadHandle.h
Handle class for reading from StoreGate.
MuonClusterHypoAlg::~MuonClusterHypoAlg
~MuonClusterHypoAlg()
Destructor.
Definition: MuonClusterHypoAlg.cxx:48
MuonClusterHypoAlg::m_hypoTools
ToolHandleArray< MuonClusterHypoTool > m_hypoTools
Definition: MuonClusterHypoAlg.h:77
TrigComposite.h
TrigCompositeUtils::viewString
const std::string & viewString()
Definition: TrigCompositeUtilsRoot.cxx:880
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32