ATLAS Offline Software
Loading...
Searching...
No Matches
TrackCountHypoAlg.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "TrackCountHypoAlg.h"
10
23
24TrackCountHypoAlg::TrackCountHypoAlg(const std::string &name, ISvcLocator *pSvcLocator) : ::HypoBase(name, pSvcLocator)
25{
26}
27
29{
30 ATH_CHECK(m_tracksKey.initialize());
31 ATH_CHECK(m_trackCountKey.initialize());
33 ATH_CHECK(m_minPt.size() == m_maxZ0.size());
34 ATH_CHECK(m_minPt.size() == m_vertexZ.size());
35
36 if (m_tracksKey.key() == "Undefined" || m_trackCountKey.key() == "Undefined")
37 {
38 ATH_MSG_ERROR("either track 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())
44 ATH_CHECK(m_monTool.retrieve());
45
46 return StatusCode::SUCCESS;
47}
48
49StatusCode TrackCountHypoAlg::execute(const EventContext &context) const
50{
51 ATH_MSG_DEBUG("Executing " << name() << "...");
52 auto previousDecisionsHandle = SG::makeHandle(decisionInput(), context);
53
54 if (not previousDecisionsHandle.isValid())
55 { //implicit
56 ATH_MSG_DEBUG("No implicit RH for previous decisions " << decisionInput().key() << ": is this expected?");
57 return StatusCode::SUCCESS;
58 }
59
60 if (previousDecisionsHandle->size() == 0)
61 {
62 ATH_MSG_DEBUG("No previous decision, nothing to do.");
63 return StatusCode::SUCCESS;
64 }
65 else if (previousDecisionsHandle->size() > 1)
66 {
67 ATH_MSG_ERROR("Found " << previousDecisionsHandle->size() << " previous decisions.");
68 return StatusCode::FAILURE;
69 }
70
71 ATH_MSG_DEBUG("Running with " << previousDecisionsHandle->size() << " implicit ReadHandles for previous decisions");
72
73 const auto viewTrk = (previousDecisionsHandle->at(0))->objectLink<ViewContainer>(viewString());
74 ATH_CHECK(viewTrk.isValid());
75 auto tracksHandle = ViewHelper::makeHandle(*viewTrk, m_tracksKey, context);
76 ATH_CHECK(tracksHandle.isValid());
77 ATH_MSG_DEBUG("spacepoint handle size: " << tracksHandle->size() << "...");
78
79 float vertexZ = 0;
80 float maxWeight = -1;
81 auto linkToVertex = findLink<xAOD::TrigCompositeContainer>(previousDecisionsHandle->at(0), featureString());
82 if ( linkToVertex.link.isValid() ) {
83 auto all_vertices = linkToVertex.link.getDataPtr();
84 for ( auto vtxInfo: *all_vertices) {
85 const float weight = vtxInfo->getDetail<float>("zfinder_vtx_weight");
86 if ( weight > maxWeight ) {
87 maxWeight = weight;
88 vertexZ = vtxInfo->getDetail<float>("zfinder_vtx_z");
89 }
90 }
91 ATH_MSG_DEBUG("Obtained vertex from ZFinder z:" << vertexZ << " weight " << maxWeight);
92 } else {
93 ATH_MSG_DEBUG("No vertex from ZFinder");
94 }
95
96
97 const int ntrks = tracksHandle->size();
98 ATH_MSG_DEBUG("Successfully retrieved track container of size" << ntrks);
99 auto trkPt = Monitored::Collection("trkPt", *tracksHandle, [](const auto& trk){ return trk->pt()*1.e-3; } );
100 auto trkEta = Monitored::Collection("trkEta", *tracksHandle, [](const auto& trk){ return trk->eta(); } );
101 Monitored::Group(m_monTool, trkPt, trkEta);
102 std::vector<int> counts(m_minPt.size());
103 for (const auto trackPtr : *tracksHandle)
104 {
105 const double pT = trackPtr->pt();
106 const double z0 = trackPtr->z0();
107 const double sinTheta = std::sin(trackPtr->theta());
108
109 for (long unsigned int i = 0; i < m_minPt.size(); i++)
110 {
111 if (pT >= m_minPt[i]
112 && std::fabs(z0) < m_maxZ0[i]
113 && ( std::abs((z0-vertexZ)*sinTheta) < m_vertexZ[i] ) )
114 counts[i]++;
115 }
116 }
117 for (long unsigned int i = 0; i < m_minPt.size(); i++)
118 {
119 ATH_MSG_DEBUG("Number of tracks found with pT cut= " << m_minPt[i] << " MeV ="
120 << "and z0 cut= " << m_maxZ0[i] << counts[i]);
121 }
122
123 // Recording Data
124 auto trackCountContainer = std::make_unique<xAOD::TrigCompositeContainer>();
125 auto trackCountContainerAux = std::make_unique<xAOD::TrigCompositeAuxContainer>();
126 trackCountContainer->setStore(trackCountContainerAux.get());
127
128 xAOD::TrigComposite *trackCount = new xAOD::TrigComposite();
129 trackCountContainer->push_back(trackCount);
130 trackCount->setDetail("ntrks", ntrks);
131 trackCount->setDetail("pTcuts", static_cast<std::vector<float>>(m_minPt));
132 trackCount->setDetail("z0cuts", static_cast<std::vector<float>>(m_maxZ0));
133 trackCount->setDetail("vertexZcuts", static_cast<std::vector<float>>(m_vertexZ));
134 trackCount->setDetail("counts", counts);
135
136 auto mon_ntrks = Monitored::Scalar<int>("ntrks", ntrks);
137 Monitored::Group(m_monTool, mon_ntrks);
138 for (long unsigned int i = 0; i < counts.size(); i++)
139 {
140 auto mon_counts = Monitored::Scalar<int>("countsSelection" + std::to_string(i), counts[i]);
141 Monitored::Group(m_monTool, mon_counts);
142 }
143
145 auto decisions = outputHandle.ptr();
146
147 auto d = newDecisionIn(decisions, hypoAlgNodeName());
148 linkToPrevious(d, decisionInput().key(), 0);
149
151 TrigCompositeUtils::decisionIDs(previousDecisionsHandle->at(0), prev);
152
153 TrackCountHypoTool::TrkCountsInfo trkinfo{d, trackCount, prev};
154
155 for (auto &tool : m_hypoTools)
156 {
157 ATH_CHECK(tool->decide(trkinfo));
158 }
159
161 ATH_CHECK(trackCountHandle.record(std::move(trackCountContainer), std::move(trackCountContainerAux)));
163 ATH_CHECK( hypoBaseOutputProcessing(outputHandle) );
164 return StatusCode::SUCCESS;
165}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(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()
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.
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...
DataVector< SG::View > ViewContainer
View container for recording in StoreGate.
Definition View.h:290
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)
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.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_tracksKey
ToolHandleArray< TrackCountHypoTool > m_hypoTools
TrackCountHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
Gaudi::Property< std::vector< float > > m_vertexZ
Gaudi::Property< std::vector< float > > m_maxZ0
Gaudi::Property< std::vector< float > > m_minPt
ToolHandle< GenericMonitoringTool > m_monTool
virtual StatusCode execute(const EventContext &context) const override
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_trackCountKey
bool setDetail(const std::string &name, const TYPE &value)
Set an TYPE detail on the object.
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
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.
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
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22