ATLAS Offline Software
xAODTauRetriever.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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 
31  xAODTauRetriever::xAODTauRetriever(const std::string& type,const std::string& name,const IInterface* parent):
32  AthAlgTool(type,name,parent), m_typeName("TauJet"),
33  m_sgKey("TauJets")
34  {
35  //Only declare the interface
36  declareInterface<IDataRetriever>(this);
37 
38  //In xAOD: AntiKt6TopoEMTaus, AntiKt6LCTopoTaus, AntiKt4TopoEMTaus, AntiKt4LCTopoTaus
39  declareProperty("StoreGateKey", m_sgKey,
40  "Collection to be first in output, shown in Atlantis without switching");
41  declareProperty ( "TracksName", m_tracksName = "InDetTrackParticles_xAOD" );
42  }
43 
48  StatusCode xAODTauRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
49 
50  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "in retrieveAll()" << endmsg;
51 
53  const xAOD::TauJetContainer* Taus;
54 
55  //obtain the default collection first
56  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Trying to retrieve " << dataTypeName() << " (" << m_sgKey << ")" << endmsg;
57  StatusCode sc = evtStore()->retrieve(Taus, m_sgKey);
58  if (sc.isFailure() ) {
59  if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << m_sgKey << " not found in SG " << endmsg;
60  }else{
61  DataMap data = getData(Taus);
62  if ( FormatTool->AddToEvent(dataTypeName(), m_sgKey+"_xAOD", &data).isFailure()){
63  if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << m_sgKey << " not found in SG " << endmsg;
64  }else{
65  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << dataTypeName() << " (" << m_sgKey << ") Tau retrieved" << endmsg;
66  }
67  }
68 
69  //All collections retrieved okay
70  return StatusCode::SUCCESS;
71  }
72 
73  // code reference:
74  // Event/xAOD/xAODTau/trunk/xAODTau/versions/TauJet_v1.h
75 
81 
82  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "in getData()" << endmsg;
83 
85 
86  DataVect pt; pt.reserve(tauCont->size());
87  DataVect phi; phi.reserve(tauCont->size());
88  DataVect eta; eta.reserve(tauCont->size());
89  DataVect charge; charge.reserve(tauCont->size());
90 
91  DataVect numTracks; numTracks.reserve(tauCont->size());
92  DataVect isolFrac; isolFrac.reserve(tauCont->size());
93  DataVect logLhRatio; logLhRatio.reserve(tauCont->size());
94  DataVect label; label.reserve(tauCont->size());
95  DataVect tracks; tracks.reserve(tauCont->size());
96  DataVect sgKey; sgKey.reserve(tauCont->size());
97  DataVect trackLinkCount; trackLinkCount.reserve(tauCont->size());
98  DataVect isTauString; isTauString.reserve(tauCont->size());
99 
100  DataVect mass; mass.reserve(tauCont->size());
101  DataVect energy; energy.reserve(tauCont->size());
102 
103  xAOD::TauJetContainer::const_iterator tauItr = tauCont->begin();
104  xAOD::TauJetContainer::const_iterator tauItrE = tauCont->end();
105 
106  int counter = 0;
107 
108  for (; tauItr != tauItrE; ++tauItr) {
109 
110  if (msgLvl(MSG::DEBUG)) {
111  msg(MSG::DEBUG) << " Tau #" << counter++ << " : eta = " << (*tauItr)->eta() << ", phi = "
112  << (*tauItr)->phi() << endmsg;
113  }
114 
115  phi.push_back(DataType((*tauItr)->phi()));
116  eta.push_back(DataType((*tauItr)->eta()));
117  pt.push_back(DataType((*tauItr)->pt()/GeV));
118 
119  isolFrac.push_back(DataType( 1. ));
120  logLhRatio.push_back(DataType( 1. ));
121  label.push_back(DataType( "xAOD_tauJet_withoutQuality" ));
122  charge.push_back(DataType( (*tauItr)->charge() ));
123  isTauString.push_back(DataType( "xAOD_tauJet_withoutQuality" ));
124 
125  mass.push_back(DataType((*tauItr)->m()/GeV));
126  energy.push_back( DataType((*tauItr)->e()/GeV ) );
127 
128  // track-vertex association code in xAOD from Nick Styles, Apr14:
129  // InnerDetector/InDetRecAlgs/InDetPriVxFinder/InDetVxLinksToTrackParticles
130 
131  int trkCnt = 0;
132 #ifndef XAODTAU_VERSIONS_TAUTRACK_V1_H
133  const std::vector< ElementLink< xAOD::TrackParticleContainer > > tpLinks = (*tauItr)->trackLinks();
134 #else
135  const std::vector< ElementLink< xAOD::TrackParticleContainer > > tpLinks = xAOD::TauHelpers::trackParticleLinks(*tauItr);
136 #endif
137 
138  //iterating over the links
139  unsigned int tp_size = tpLinks.size();
140  numTracks.push_back(DataType( tp_size )); // same as: (*tauItr)->nTracks()
141  trackLinkCount.push_back(DataType( tp_size ));
142  if(tp_size){ // links exist
143  for(unsigned int tp = 0; tp<tp_size; ++tp)
144  {
146 
147  //checking a container name consitency
148  // if(tpl.key() == m_tracksName) // doesn't work. tpl.key is a number ?
149 
150  if (msgLvl(MSG::DEBUG)) {
151  msg(MSG::DEBUG) << " tau #" << counter << " track association index: " << tpl.index()
152  << ", collection : " << tpl.key()
153  << ", Tracks : " << tp << " out of " << tp_size << ", own count: " << trkCnt++ << endmsg;
154  }
155  tracks.push_back(DataType( tpl.index() ));
156  sgKey.push_back( m_tracksName );
157  } //links exist
158  }
159 
160  } // end TauIterator
161 
162  // four-vectors
163  DataMap["phi"] = phi;
164  DataMap["eta"] = eta;
165  DataMap["pt"] = pt;
166  DataMap["mass"] = mass;
167  DataMap["energy"] = energy;
168 
169  DataMap["numTracks"] = numTracks;
170  DataMap["isolFrac"] = isolFrac;
171  DataMap["logLhRatio"] = logLhRatio;
172  DataMap["label"] = label;
173  DataMap["charge"] = charge;
174  DataMap["trackLinkCount"] = trackLinkCount;
175  DataMap["isTauString"] = isTauString;
176 
177  //This is needed once we know numTracks and associations:
178  //If there had been any tracks, add a tag
179  if ((numTracks.size()) != 0){
180  //Calculate average number of tracks per vertex
181  double NTracksPerVertex = tracks.size()*1./numTracks.size();
182  std::string tag = "trackIndex multiple=\"" +DataType(NTracksPerVertex).toString()+"\"";
183  DataMap[tag] = tracks;
184  tag = "trackKey multiple=\"" +DataType(NTracksPerVertex).toString()+"\"";
185  DataMap[tag] = sgKey;
186  }
187 
188 // DataMap["energy"] = energy;
189 // DataMap["mass"] = mass;
190 
191  if (msgLvl(MSG::DEBUG)) {
192  msg(MSG::DEBUG) << dataTypeName() << " retrieved with " << phi.size() << " entries"<< endmsg;
193  }
194 
195  //All collections retrieved okay
196  return DataMap;
197 
198  } // retrieve
199 
200  //--------------------------------------------------------------------------
201 
202 } // JiveXML namespace
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
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
JiveXML::xAODTauRetriever::m_tracksName
std::string m_tracksName
Definition: xAODTauRetriever.h:52
Base_Fragment.mass
mass
Definition: Sherpa_i/share/common/Base_Fragment.py:59
JiveXML::xAODTauRetriever::m_sgKey
std::string m_sgKey
Definition: xAODTauRetriever.h:51
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
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
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
JiveXML::xAODTauRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
Definition: xAODTauRetriever.cxx:48
JiveXML::xAODTauRetriever::getData
const DataMap getData(const xAOD::TauJetContainer *)
Retrieve basic parameters, mainly four-vectors, for each collection.
Definition: xAODTauRetriever.cxx:80
JiveXML::DataMap
std::map< std::string, DataVect > DataMap
Definition: DataType.h:59
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
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
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TauxAODHelpers.h
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
TauJetContainer.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
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:221
charge
double charge(const T &p)
Definition: AtlasPID.h:538
JiveXML::xAODTauRetriever::xAODTauRetriever
xAODTauRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
Definition: xAODTauRetriever.cxx:31
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.
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
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.
Definition: xAODTauRetriever.h:45
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
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
SG::ConstIterator
Definition: SGIterator.h:163
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.