ATLAS Offline Software
Loading...
Searching...
No Matches
xAODVertexRetriever.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
11
12#include "AthenaKernel/Units.h"
13using Athena::Units::cm;
14
15namespace JiveXML {
16
24 xAODVertexRetriever::xAODVertexRetriever(const std::string& type,const std::string& name,const IInterface* parent):
25 AthAlgTool(type,name,parent){}
26
27
29 ATH_CHECK(m_keys.initialize());
30 return StatusCode::SUCCESS;
31 }
32
33
38 StatusCode xAODVertexRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
39
40 ATH_MSG_DEBUG("In retrieve()");
41
42 // Loop through the keys and retrieve the corresponding data
43 for (const auto& key : m_keys) {
45 if (cont.isValid()) {
46 DataMap data = getData(&(*cont));
47 if (FormatTool->AddToEvent(dataTypeName(), key.key() + "_xAOD", &data).isFailure()) {
48 ATH_MSG_WARNING("Failed to add collection " << key.key());
49 } else {
50 ATH_MSG_DEBUG(" (" << key.key() << ") retrieved");
51 }
52 } else {
53 ATH_MSG_WARNING("Collection " << key.key() << " not found in SG");
54 }
55 }
56
57 return StatusCode::SUCCESS;
58 }
59
65
66 ATH_MSG_DEBUG("in getData()");
67
68 float chi2val = 0.;
69
71
72 DataVect x;
73 DataVect y;
74 DataVect z;
76 DataVect vertexType;
77 DataVect primVxCand;
78 DataVect covMatrix;
79 DataVect numTracks;
80 DataVect tracks;
81 DataVect sgkey;
82
83
84 int counter = 0;
85
86 //Loop over vertices
88 for ( ; VertexItr != cont->end(); ++VertexItr) {
89
90 ATH_MSG_DEBUG(" Vertex #" << counter++ << " : x = " << (*VertexItr)->x()/cm << ", y = "
91 << (*VertexItr)->y()/cm << ", z[GeV] = " << (*VertexItr)->z()/cm
92 << ", vertexType = " << (*VertexItr)->vertexType()
93 << ", chiSquared = " << (*VertexItr)->chiSquared()
94 << ", numberDoF = " << (*VertexItr)->numberDoF());
95
96 x.emplace_back(DataType((*VertexItr)->x()/cm));
97 y.emplace_back(DataType((*VertexItr)->y()/cm));
98 z.emplace_back(DataType((*VertexItr)->z()/cm));
99
100 vertexType.emplace_back( DataType((*VertexItr)->vertexType()));
101
102 if ((*VertexItr)->vertexType() == 1 ){
103 primVxCand.emplace_back( 1 );
104 }else{
105 primVxCand.emplace_back( 0 );
106 }
107 sgkey.emplace_back (m_tracksName.value());
108
110 covMatrix.emplace_back(DataType("2 -.1 .5 -.01 0.002 .01"));
111
112 //degrees of freedom might be zero - beware
113 if ( (*VertexItr)->numberDoF() != 0 ){
114 chi2val = (*VertexItr)->chiSquared()/(*VertexItr)->numberDoF() ;
115 }else{
116 chi2val = -1.;
117 }
118 chi2.emplace_back(DataType( chi2val ));
119
120 // track-vertex association code in xAOD from Nick Styles, Apr14:
121 // InnerDetector/InDetRecAlgs/InDetPriVxFinder/InDetVxLinksToTrackParticles
122
123 int trkCnt = 0;
124 const std::vector< ElementLink< xAOD::TrackParticleContainer > > tpLinks = (*VertexItr)->trackParticleLinks();
125
126 //iterating over the links
127 unsigned int tp_size = tpLinks.size();
128 numTracks.emplace_back(DataType( tp_size ));
129 if(tp_size){ // links exist
130 for(unsigned int tp = 0; tp<tp_size; ++tp)
131 {
133
134 ATH_MSG_DEBUG(" Vertex #" << counter << " track association index: " << tpl.index()
135 << ", collection : " << tpl.key()
136 << ", Tracks : " << tp << " out of " << tp_size << ", own count: " << trkCnt++);
137
138 if ( tpl.index() < 1000 ){ // sanity check, this can be huge number
139 tracks.emplace_back(DataType( tpl.index() ));
140 }else{
141 tracks.emplace_back(DataType( 0 ));
142 }
143 } //links exist
144 }//end of track particle collection size check
145
146 } // end VertexIterator
147
148 // four-vectors
149 const std::size_t nEntries = x.size();
150 DataMap["x"] = std::move(x);
151 DataMap["y"] = std::move(y);
152 DataMap["z"] = std::move(z);
153 DataMap["chi2"] = std::move(chi2);
154 DataMap["vertexType"] = std::move(vertexType);
155 DataMap["primVxCand"] = std::move(primVxCand);
156 DataMap["covMatrix multiple=\"6\""] = std::move(covMatrix);
157 const std::size_t nTracks = numTracks.size();
158 DataMap["numTracks"] = std::move(numTracks);
159 DataMap["sgkey"] = std::move(sgkey);
160
161 //This is needed once we know numTracks and associations:
162 //If there had been any tracks, add a tag
163 if (nTracks != 0){
164 //Calculate average number of tracks per vertex
165 double NTracksPerVertex = tracks.size()*1./nTracks;
166 std::string tag = "tracks multiple=\"" +DataType(NTracksPerVertex).toString()+"\"";
167 DataMap[tag] = std::move(tracks);
168 }
169
170 ATH_MSG_DEBUG(dataTypeName() << " retrieved with " << nEntries << " entries");
171
172 return DataMap;
173
174 }
175
176
177} // JiveXML namespace
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Wrapper to avoid constant divisions when using units.
#define y
#define x
#define z
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:861
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
xAODVertexRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
const DataMap getData(const xAOD::VertexContainer *)
Puts the variables into a DataMap.
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
For each Vertex collections retrieve basic parameters.
virtual std::string dataTypeName() const
Return the name of the data type that is generated by this retriever.
Gaudi::Property< std::string > m_tracksName
SG::ReadHandleKeyArray< xAOD::VertexContainer > m_keys
virtual bool isValid() override final
Can the handle be successfully dereferenced?
double chi2(TH1 *h0, TH1 *h1)
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
std::map< std::string, DataVect > DataMap
Definition DataType.h:59
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition DataType.h:58
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".