ATLAS Offline Software
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"
11 using Athena::Units::GeV;
12 
13 namespace JiveXML {
14 
21  xAODTauRetriever::xAODTauRetriever(const std::string& type,const std::string& name,const IInterface* 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 
83  xAOD::TauJetContainer::const_iterator tauItr = tauCont->begin();
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
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:18
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
JiveXML::xAODTauRetriever::m_keys
SG::ReadHandleKeyArray< xAOD::TauJetContainer > m_keys
Definition: xAODTauRetriever.h:50
Base_Fragment.mass
mass
Definition: Sherpa_i/share/common/Base_Fragment.py:59
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
JiveXML::DataVect
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition: DataType.h:58
DataType
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Definition: RoIBResultByteStreamTool.cxx:25
test_pyathena.pt
pt
Definition: test_pyathena.py:11
ParticleTest.tp
tp
Definition: ParticleTest.py:25
JiveXML::xAODTauRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
For each Tau collections retrieve basic parameters.
Definition: xAODTauRetriever.cxx:35
JiveXML::xAODTauRetriever::getData
const DataMap getData(const xAOD::TauJetContainer *)
Puts the variables into a DataMap.
Definition: xAODTauRetriever.cxx:60
JiveXML::DataMap
std::map< std::string, DataVect > DataMap
Definition: DataType.h:59
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
JiveXML::xAODTauRetriever::m_tracksName
Gaudi::Property< std::string > m_tracksName
Definition: xAODTauRetriever.h:52
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TauxAODHelpers.h
add-xsec-uncert-quadrature-N.label
label
Definition: add-xsec-uncert-quadrature-N.py:104
test_pyathena.parent
parent
Definition: test_pyathena.py:15
xAOD::TauHelpers::trackParticleLinks
std::vector< ElementLink< xAOD::TrackParticleContainer > > trackParticleLinks(const xAOD::TauJet *tau, xAOD::TauJetParameters::TauTrackFlag flag=xAOD::TauJetParameters::TauTrackFlag::classifiedCharged)
Definition: TauxAODHelpers.cxx:16
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TauJetContainer.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition: BadLArRetriever.cxx:22
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
charge
double charge(const T &p)
Definition: AtlasPID.h:986
JiveXML::xAODTauRetriever::xAODTauRetriever
xAODTauRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
Definition: xAODTauRetriever.cxx:21
Units.h
Wrapper to avoid constant divisions when using units.
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
JiveXML::xAODTauRetriever::initialize
virtual StatusCode initialize()
Definition: xAODTauRetriever.cxx:25
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::TauJetParameters::isolFrac
@ isolFrac
Get isolation fraction.
Definition: TauDefs.h:198
JiveXML::xAODTauRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type that is generated by this retriever.
Definition: xAODTauRetriever.h:43
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:23
AthAlgTool
Definition: AthAlgTool.h:26
test_pyathena.counter
counter
Definition: test_pyathena.py:15
xAODTauRetriever.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37