Loading [MathJax]/jax/output/SVG/config.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
28  StatusCode xAODTauRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
29 
30  ATH_MSG_DEBUG("In retrieve()");
31 
32  std::vector<std::string> keys = getKeys();
33 
34  if(keys.empty()){
35  ATH_MSG_WARNING("No StoreGate keys found");
36  return StatusCode::SUCCESS;
37  }
38 
39  // Loop through the keys and retrieve the corresponding data
40  for (const std::string& key : keys) {
42  if (cont.isValid()) {
43  DataMap data = getData(&(*cont));
44  if (FormatTool->AddToEvent(dataTypeName(), key + "_xAOD", &data).isFailure()) {
45  ATH_MSG_WARNING("Failed to retrieve Collection " << key);
46  } else {
47  ATH_MSG_DEBUG(" (" << key << ") retrieved");
48  }
49  } else {
50  ATH_MSG_WARNING("Collection " << 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  const std::vector<std::string> xAODTauRetriever::getKeys() {
174 
175  ATH_MSG_DEBUG("in getKeys()");
176 
177  std::vector<std::string> keys = {};
178 
179  // Remove m_priorityKey from m_otherKeys if it exists, we don't want to write it twice
180  auto it = std::find(m_otherKeys.begin(), m_otherKeys.end(), m_priorityKey);
181  if(it != m_otherKeys.end()){
182  m_otherKeys.erase(it);
183  }
184 
185  // Add m_priorityKey as the first element if it is not ""
186  if(m_priorityKey!=""){
187  keys.push_back(m_priorityKey);
188  }
189 
190  if(!m_otherKeys.empty()){
191  keys.insert(keys.end(), m_otherKeys.begin(), m_otherKeys.end());
192  }
193 
194  // If all collections are requested, obtain all available keys from StoreGate
195  std::vector<std::string> allKeys;
197  evtStore()->keys<xAOD::TauJetContainer>(allKeys);
198  // Add keys that are not the priority key and do not add containers with "HLT" in their name if requested
199  for(const std::string& key : allKeys){
200  // Don't include key if it's already in keys
201  auto it2 = std::find(keys.begin(), keys.end(), key);
202  if(it2 != keys.end())continue;
203  if(key.find("HLT") == std::string::npos || m_doWriteHLT){
204  keys.emplace_back(key);
205  }
206  }
207  }
208  return keys;
209  }
210 
211 } // JiveXML namespace
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
Base_Fragment.mass
mass
Definition: Sherpa_i/share/common/Base_Fragment.py:59
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
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
skel.it
it
Definition: skel.GENtoEVGEN.py:407
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:28
JiveXML::xAODTauRetriever::getData
const DataMap getData(const xAOD::TauJetContainer *)
Return the name of the data type that is generated by this retriever.
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_doWriteAllCollections
Gaudi::Property< bool > m_doWriteAllCollections
Definition: xAODTauRetriever.h:57
JiveXML::xAODTauRetriever::m_tracksName
Gaudi::Property< std::string > m_tracksName
Definition: xAODTauRetriever.h:60
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
JiveXML::xAODTauRetriever::m_priorityKey
Gaudi::Property< std::string > m_priorityKey
Definition: xAODTauRetriever.h:59
JiveXML::xAODTauRetriever::m_otherKeys
Gaudi::Property< std::vector< std::string > > m_otherKeys
Definition: xAODTauRetriever.h:58
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:22
JiveXML::xAODTauRetriever::m_doWriteHLT
Gaudi::Property< bool > m_doWriteHLT
Definition: xAODTauRetriever.h:56
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:228
charge
double charge(const T &p)
Definition: AtlasPID.h:931
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.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::TauJetParameters::isolFrac
@ isolFrac
Get isolation fraction.
Definition: TauDefs.h:198
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
JiveXML::xAODTauRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type that is generated by this retriever.
Definition: xAODTauRetriever.h:49
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
AthAlgTool
Definition: AthAlgTool.h:26
test_pyathena.counter
counter
Definition: test_pyathena.py:15
xAODTauRetriever.h
JiveXML::xAODTauRetriever::getKeys
const std::vector< std::string > getKeys()
Gets the StoreGate keys for the desired containers.
Definition: xAODTauRetriever.cxx:173
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