ATLAS Offline Software
Loading...
Searching...
No Matches
xAODTauRetriever.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
9
10#include "AthenaKernel/Units.h"
11using Athena::Units::GeV;
12
13namespace JiveXML {
14
21 xAODTauRetriever::xAODTauRetriever(const std::string& type,const std::string& name,const IInterface* parent):
22 AthAlgTool(type,name,parent){}
23
24
26 ATH_CHECK(m_keys.initialize());
27 return StatusCode::SUCCESS;
28 }
29
30
35 StatusCode xAODTauRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
36
37 ATH_MSG_DEBUG("In retrieve()");
38
39 // Loop through the keys and retrieve the corresponding data
40 for (const auto& key : m_keys) {
42 if (cont.isValid()) {
43 DataMap data = getData(&(*cont));
44 if (FormatTool->AddToEvent(dataTypeName(), key.key() + "_xAOD", &data).isFailure()) {
45 ATH_MSG_WARNING("Failed to add collection " << key.key());
46 } else {
47 ATH_MSG_DEBUG(" (" << key.key() << ") retrieved");
48 }
49 } else {
50 ATH_MSG_WARNING("Collection " << key.key() << " not found in SG");
51 }
52 }
53 return StatusCode::SUCCESS;
54 }
55
61
62 ATH_MSG_DEBUG("in getData()");
63
65
66 DataVect pt; pt.reserve(tauCont->size());
67 DataVect phi; phi.reserve(tauCont->size());
68 DataVect eta; eta.reserve(tauCont->size());
69 DataVect charge; charge.reserve(tauCont->size());
70
71 DataVect numTracks; numTracks.reserve(tauCont->size());
72 DataVect isolFrac; isolFrac.reserve(tauCont->size());
73 DataVect logLhRatio; logLhRatio.reserve(tauCont->size());
74 DataVect label; label.reserve(tauCont->size());
75 DataVect tracks; tracks.reserve(tauCont->size());
76 DataVect sgKey; sgKey.reserve(tauCont->size());
77 DataVect trackLinkCount; trackLinkCount.reserve(tauCont->size());
78 DataVect isTauString; isTauString.reserve(tauCont->size());
79
80 DataVect mass; mass.reserve(tauCont->size());
81 DataVect energy; energy.reserve(tauCont->size());
82
84 xAOD::TauJetContainer::const_iterator tauItrE = tauCont->end();
85
86 int counter = 0;
87
88 for (; tauItr != tauItrE; ++tauItr) {
89 ATH_MSG_DEBUG(" Tau #" << counter++ << " : eta = " << (*tauItr)->eta() << ", phi = "
90 << (*tauItr)->phi());
91
92 phi.emplace_back(DataType((*tauItr)->phi()));
93 eta.emplace_back(DataType((*tauItr)->eta()));
94 pt.emplace_back(DataType((*tauItr)->pt()/GeV));
95
96 isolFrac.emplace_back(DataType( 1. ));
97 logLhRatio.emplace_back(DataType( 1. ));
98 label.emplace_back(DataType( "xAOD_tauJet_withoutQuality" ));
99 charge.emplace_back(DataType( (*tauItr)->charge() ));
100 isTauString.emplace_back(DataType( "xAOD_tauJet_withoutQuality" ));
101
102 mass.emplace_back(DataType((*tauItr)->m()/GeV));
103 energy.emplace_back( DataType((*tauItr)->e()/GeV ) );
104
105 // track-vertex association code in xAOD from Nick Styles, Apr14:
106 // InnerDetector/InDetRecAlgs/InDetPriVxFinder/InDetVxLinksToTrackParticles
107
108 int trkCnt = 0;
109#ifndef XAODTAU_VERSIONS_TAUTRACK_V1_H
110 const std::vector< ElementLink< xAOD::TrackParticleContainer > > tpLinks = (*tauItr)->trackLinks();
111#else
112 const std::vector< ElementLink< xAOD::TrackParticleContainer > > tpLinks = xAOD::TauHelpers::trackParticleLinks(*tauItr);
113#endif
114
115 //iterating over the links
116 unsigned int tp_size = tpLinks.size();
117 numTracks.emplace_back(DataType( tp_size )); // same as: (*tauItr)->nTracks()
118 trackLinkCount.emplace_back(DataType( tp_size ));
119 if(tp_size){ // links exist
120 for(unsigned int tp = 0; tp<tp_size; ++tp)
121 {
123
124 //checking a container name consitency
125 // if(tpl.key() == m_tracksName) // doesn't work. tpl.key is a number ?
126
127 ATH_MSG_DEBUG(" tau #" << counter << " track association index: " << tpl.index()
128 << ", collection : " << tpl.key()
129 << ", Tracks : " << tp << " out of " << tp_size << ", own count: " << trkCnt++);
130 tracks.emplace_back(DataType( tpl.index() ));
131 sgKey.emplace_back( m_tracksName.value() );
132 }
133 } //links exist
134
135 } // end TauIterator
136
137 // four-vectors
138 DataMap["phi"] = phi;
139 DataMap["eta"] = eta;
140 DataMap["pt"] = pt;
141 DataMap["mass"] = mass;
142 DataMap["energy"] = energy;
143
144 DataMap["numTracks"] = numTracks;
145 DataMap["isolFrac"] = isolFrac;
146 DataMap["logLhRatio"] = logLhRatio;
147 DataMap["label"] = label;
148 DataMap["charge"] = charge;
149 DataMap["trackLinkCount"] = trackLinkCount;
150 DataMap["isTauString"] = isTauString;
151
152 //This is needed once we know numTracks and associations:
153 //If there had been any tracks, add a tag
154 if ((numTracks.size()) != 0){
155 //Calculate average number of tracks per vertex
156 double NTracksPerVertex = tracks.size()*1./numTracks.size();
157 std::string tag = "trackIndex multiple=\"" +DataType(NTracksPerVertex).toString()+"\"";
158 DataMap[tag] = tracks;
159 tag = "trackKey multiple=\"" +DataType(NTracksPerVertex).toString()+"\"";
160 DataMap[tag] = sgKey;
161 }
162
163 // DataMap["energy"] = energy;
164 // DataMap["mass"] = mass;
165
166 ATH_MSG_DEBUG(dataTypeName() << " retrieved with " << phi.size() << " entries");
167
168 return DataMap;
169
170 }
171
172
173} // JiveXML namespace
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
double charge(const T &p)
Definition AtlasPID.h:997
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Wrapper to avoid constant divisions when using units.
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:838
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.
size_type size() const noexcept
Returns the number of elements in the collection.
SG::ReadHandleKeyArray< xAOD::TauJetContainer > m_keys
xAODTauRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
const DataMap getData(const xAOD::TauJetContainer *)
Puts the variables into a DataMap.
Gaudi::Property< std::string > m_tracksName
virtual StatusCode initialize()
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
For each Tau collections retrieve basic parameters.
virtual std::string dataTypeName() const
Return the name of the data type that is generated by this retriever.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::string label(const std::string &format, int i)
Definition label.h:19
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
std::vector< ElementLink< xAOD::TrackParticleContainer > > trackParticleLinks(const xAOD::TauJet *tau, xAOD::TauJetParameters::TauTrackFlag flag=xAOD::TauJetParameters::TauTrackFlag::classifiedCharged)
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".