ATLAS Offline Software
Loading...
Searching...
No Matches
TrigVSIHypoAlg.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "TrigVSIHypoAlg.h"
6
10
25
26TrigVSIHypoAlg::TrigVSIHypoAlg(const std::string& name, ISvcLocator* pSvcLocator) :
27::HypoBase(name, pSvcLocator)
28{
29}
30
32{
33 ATH_CHECK(m_verticesKey.initialize());
34 ATH_CHECK(m_vtxCountKey.initialize());
36
37 if (m_verticesKey.key() == "Undefined" || m_vtxCountKey.key() == "Undefined") {
38 ATH_MSG_ERROR("either vertex Key name or track count key name is undefined " );
39 return StatusCode::FAILURE;
40 }
41
42 ATH_CHECK(m_hypoTools.retrieve());
43 if (!m_monTool.empty()) ATH_CHECK(m_monTool.retrieve());
44
45 return StatusCode::SUCCESS;
46}
47
48
49StatusCode TrigVSIHypoAlg::execute(const EventContext& context) const
50{
51 // previous decisions
52
53 // Taken from FTFLRT
54 ATH_MSG_DEBUG ( "Executing " << name() << "..." );
55 auto previousDecisionsHandle = SG::makeHandle( decisionInput(), context );
56
57 ATH_CHECK( previousDecisionsHandle.isValid() );
58
59 if (previousDecisionsHandle->size() == 0) {
60 ATH_MSG_DEBUG( "No previous decision, nothing to do.");
61 return StatusCode::SUCCESS;
62 }
63
64 ATH_MSG_DEBUG( "Running with "<< previousDecisionsHandle->size() << " implicit ReadHandles for previous decisions. Looking for :" << viewString());
65 //end taken section
66
67 // new output decisions
69 auto decisions = outputHandle.ptr();
70
71 // monitoring
72 auto mon_nVtx = Monitored::Scalar( "nVtx", -999. );
73 auto mon_preselNVtx = Monitored::Scalar( "preselNVtx", -999. );
74 auto mon_maxVtxNTrk = Monitored::Scalar( "maxVtxNTrk", -999. );
75 auto mon_maxVtxMass = Monitored::Scalar( "maxVtxMass", -999. );
76 auto monitorIt = Monitored::Group( m_monTool, mon_nVtx, mon_preselNVtx, mon_maxVtxNTrk, mon_maxVtxMass );
77
78 // Recording Data
79 auto vtxCountContainer = std::make_unique< xAOD::TrigCompositeContainer>();
80 auto vtxCountContainerAux = std::make_unique< xAOD::TrigCompositeAuxContainer>();
81 vtxCountContainer->setStore(vtxCountContainerAux.get());
82
83 std::unordered_map<Decision*, size_t> mapDecVtxContIdx;
84
85 for( const Decision* previousDecision : *previousDecisionsHandle ) {
86
88
89 if (m_isViewBased) {
90 const auto viewELInfo = findLink<ViewContainer>( previousDecision, viewString() );
91 ATH_CHECK( viewELInfo.isValid() );
92
93 // get vertices from the key
94 ATH_MSG_DEBUG( "Getting Vertex Handle " << m_verticesKey);
95 vtxHandle = ViewHelper::makeHandle(*viewELInfo.link, m_verticesKey, context);
96 } else {
97 ATH_MSG_DEBUG( "Getting Vertex Handle " << m_verticesKey);
98 vtxHandle = SG::makeHandle(m_verticesKey, context );
99 }
100
101 //ATH_CHECK( vtxHandle.isValid() );
102 if ( ! vtxHandle.isValid() ) {
103 ATH_MSG_DEBUG ( "Couldn't find " << m_verticesKey << "..." );
104 continue;
105 }
106
107 ATH_MSG_DEBUG ( "vertex handle size: " << vtxHandle->size() << "..." );
108 int nVtx = vtxHandle->size();
109 const xAOD::VertexContainer* vtxContainer = vtxHandle.get();
110
111 Decision* d = newDecisionIn(decisions, previousDecision, hypoAlgNodeName(), context);
112
114 decisionIDs( previousDecision, prev );
115
116 std::vector<const xAOD::Vertex*> selectedVtx;
117 float maxVtxNTrk = 0.;
118 float maxVtxMass = 0.;
119
120 static const SG::ConstAccessor<float> vsi_massAcc ("vsi_mass");
121 static const SG::ConstAccessor<float> vsi_pTAcc ("vsi_pT");
122
123 // Loop over all vertices and combine them into the std::vector after preselection and create the input for the hypotool
124 for ( const xAOD::Vertex* vertex : *vtxContainer ) {
125 if (vertex == nullptr) continue;
126 const float mass = vsi_massAcc.withDefault(*vertex, 0);
127 const float pT = vsi_pTAcc.withDefault(*vertex, 0);
128 const size_t ntrk = vertex->nTrackParticles();
129
130 const float x_ = vertex->position().x();
131 const float y_ = vertex->position().y();
132 const float r = std::sqrt(x_*x_+y_*y_);
133
134 if ( pT > m_minPt
135 && r > m_minR
136 && ntrk >= m_requiredNTrks )
137 {
138 selectedVtx.push_back(vertex);
139 maxVtxNTrk = std::max(maxVtxNTrk, static_cast<float>(ntrk));
140 maxVtxMass = std::max(maxVtxMass, mass);
141 }
142 }
143
144 // Monitor
145 mon_nVtx = nVtx;
146 mon_preselNVtx = selectedVtx.size();
147 mon_maxVtxNTrk = maxVtxNTrk;
148 mon_maxVtxMass = maxVtxMass;
149
151 vtxCountContainer->push_back(vtxCount);
152 vtxCount->setDetail( "vsiHypo_nVtx", static_cast<float>(nVtx) );
153 vtxCount->setDetail( "vsiHypo_pTcut", static_cast<float>(m_minPt) );
154 vtxCount->setDetail( "vsiHypo_rCut", static_cast<float>(m_minR) );
155 vtxCount->setDetail( "vsiHypo_nTrkCut", static_cast<float>(m_requiredNTrks) );
156 vtxCount->setDetail( "vsiHypo_counts", static_cast<float>(selectedVtx.size()) );
157
158 TrigVSIHypoTool::eventVtxInfo vtxinfo{d, selectedVtx, prev};
159
160 for(auto &tool : m_hypoTools)
161 {
162 ATH_CHECK(tool->decide(vtxinfo));
163 }
164
165 mapDecVtxContIdx.emplace( d, vtxCountContainer->size()-1 );
166
167 }
168
169 // Recording Data
171 ATH_CHECK(vtxCountHandle.record( std::move( vtxCountContainer ), std::move( vtxCountContainerAux ) ) );
172
173 DecisionContainer::iterator it = decisions->begin();
174 while(it != decisions->end()) {
175 ATH_MSG_DEBUG( "+++++ outputDecision: " << *it << " +++++" );
176 if ( allFailed( *it ) ) {
177 ATH_MSG_DEBUG( "---> all failed, erasing" );
178 it = decisions->erase(it);
179 } else {
180 ATH_MSG_DEBUG( "---> not all failed" );
181
182 // Link hitDV object
183 auto decision = *it;
184 size_t idx = mapDecVtxContIdx.at(*it);
185
187 ATH_CHECK( dvEL.isValid() );
188
189 ATH_CHECK( decision->setObjectLink<xAOD::TrigCompositeContainer>( featureString(), dvEL ) );
190
191 ATH_MSG_DEBUG(*decision);
192 ++it;
193 }
194 }
195
196 ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
197 ATH_MSG_DEBUG(" TrigVSIHypoAlg:" << name() << " successfully executed. Returning StatusCode::SUCCESS.");
198 return StatusCode::SUCCESS;
199}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Helper class to provide constant type-safe access to aux data.
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()
bool allFailed(const Decision *d)
return true if there is no positive decision stored
const std::string & viewString()
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...
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
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.
Helper class to provide constant type-safe access to aux data.
const_reference_type withDefault(const ELT &e, const T &deflt) const
Fetch the variable for one element, as a const reference, with a default.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
ToolHandleArray< TrigVSIHypoTool > m_hypoTools
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &context) const override
SG::ReadHandleKey< xAOD::VertexContainer > m_verticesKey
Gaudi::Property< float > m_minPt
Gaudi::Property< bool > m_isViewBased
ToolHandle< GenericMonitoringTool > m_monTool
Gaudi::Property< float > m_minR
Gaudi::Property< float > m_requiredNTrks
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_vtxCountKey
bool setDetail(const std::string &name, const TYPE &value)
Set an TYPE detail on the object.
int r
Definition globals.cxx:22
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.
auto makeHandle(const SG::View *view, const KEY &key, const EventContext &ctx)
Create a view handle from a handle key.
Definition ViewHelper.h:273
TrigCompositeContainer_v1 TrigCompositeContainer
Declare the latest version of the container.
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22