ATLAS Offline Software
xAODMuonRetriever.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 
7 #include "xAODMuon/MuonContainer.h"
8 
9 #include "AthenaKernel/Units.h"
10 using Athena::Units::GeV;
11 
12 namespace JiveXML {
13 
31  xAODMuonRetriever::xAODMuonRetriever(const std::string& type,const std::string& name,const IInterface* parent):
32  AthAlgTool(type,name,parent), m_typeName("Muon"),
33  m_sgKey("Muons") // is xAOD name
34  {
35 
36  //Only declare the interface
37  declareInterface<IDataRetriever>(this);
38 
39  declareProperty("StoreGateKey", m_sgKey,
40  "Collection to be first in output, shown in Atlantis without switching");
41  declareProperty("OtherCollections" ,m_otherKeys,
42  "Other collections to be retrieved. If list left empty, all available retrieved");
43  }
44 
49  StatusCode xAODMuonRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
50 
51  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "in retrieveAll()" << endmsg;
52 
54  const xAOD::MuonContainer* muons;
55 
56  //obtain the default collection first
57  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Trying to retrieve " << dataTypeName() << " (" << m_sgKey << ")" << endmsg;
58  StatusCode sc = evtStore()->retrieve(muons, m_sgKey);
59  if (sc.isFailure() ) {
60  if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << m_sgKey << " not found in SG " << endmsg;
61  }else{
62  DataMap data = getData(muons);
63  if ( FormatTool->AddToEvent(dataTypeName(), m_sgKey+"_xAOD", &data).isFailure()){ //suffix can be removed later
64  if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << m_sgKey << " not found in SG " << endmsg;
65  }else{
66  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << dataTypeName() << " (" << m_sgKey << ") Muon retrieved" << endmsg;
67  }
68  }
69 
70 
71  if ( m_otherKeys.empty() ) {
72  //obtain all other collections from StoreGate
73  if (( evtStore()->retrieve(iterator, end)).isFailure()){
74  if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) <<
75  "Unable to retrieve iterator for xAOD Muon collection" << endmsg;
76 // return false;
77  }
78 
79  for (; iterator!=end; ++iterator) {
80  if (iterator.key()!=m_sgKey) {
81  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Trying to retrieve all. Current collection: " << dataTypeName() << " (" << iterator.key() << ")" << endmsg;
83  if ( FormatTool->AddToEvent(dataTypeName(), iterator.key()+"_xAOD", &data).isFailure()){
84  if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << iterator.key() << " not found in SG " << endmsg;
85  }else{
86  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << dataTypeName() << " (" << iterator.key() << ") xAOD Muon retrieved" << endmsg;
87  }
88  }
89  }
90  }else {
91  //obtain all collections with the given keys
92  std::vector<std::string>::const_iterator keyIter;
93  for ( keyIter=m_otherKeys.begin(); keyIter!=m_otherKeys.end(); ++keyIter ){
94  StatusCode sc = evtStore()->retrieve( muons, (*keyIter) );
95  if (!sc.isFailure()) {
96  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Trying to retrieve selected " << dataTypeName() << " (" << (*keyIter) << ")" << endmsg;
97  DataMap data = getData(muons);
98  if ( FormatTool->AddToEvent(dataTypeName(), (*keyIter), &data).isFailure()){
99  if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << (*keyIter) << " not found in SG " << endmsg;
100  }else{
101  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << dataTypeName() << " (" << (*keyIter) << ") retrieved" << endmsg;
102  }
103  }
104  }
105  }
106 
107  //All collections retrieved okay
108  return StatusCode::SUCCESS;
109  }
110 
111 
117 
118  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "in getData()" << endmsg;
119 
121 
122  DataVect pt; pt.reserve(muCont->size());
123  DataVect phi; phi.reserve(muCont->size());
124  DataVect eta; eta.reserve(muCont->size());
125  DataVect mass; mass.reserve(muCont->size());
126  DataVect energy; energy.reserve(muCont->size());
127  DataVect chi2; chi2.reserve(muCont->size());
128  DataVect pdgId; pdgId.reserve(muCont->size());
129 
130  xAOD::MuonContainer::const_iterator muItr = muCont->begin();
131  xAOD::MuonContainer::const_iterator muItrE = muCont->end();
132 
133  int counter = 0;
134 
135  for (; muItr != muItrE; ++muItr) {
136 
137  if (msgLvl(MSG::DEBUG)) {
138  msg(MSG::DEBUG) << " Muon #" << counter++ << " : eta = " << (*muItr)->eta()
139  << ", phi = " << (*muItr)->phi() << ", pt = " << (*muItr)->pt()
140  << ", pdgId = " << -13.*(*muItr)->primaryTrackParticle()->charge()
141  << endmsg;
142  }
143 
144  phi.push_back(DataType((*muItr)->phi()));
145  eta.push_back(DataType((*muItr)->eta()));
146  pt.push_back(DataType((*muItr)->pt()/GeV));
147 
148  mass.push_back(DataType((*muItr)->m()/GeV));
149  energy.push_back( DataType((*muItr)->e()/GeV ) );
150  chi2.push_back( 1.0 ); //placeholder
151  pdgId.push_back(DataType( -13.*(*muItr)->primaryTrackParticle()->charge() )); // pdgId not available anymore in xAOD
152  } // end MuonIterator
153 
154  // four-vectors
155  DataMap["phi"] = phi;
156  DataMap["eta"] = eta;
157  DataMap["pt"] = pt;
158  DataMap["energy"] = energy;
159  DataMap["mass"] = mass;
160  DataMap["chi2"] = chi2;
161  DataMap["pdgId"] = pdgId;
162 
163  if (msgLvl(MSG::DEBUG)) {
164  msg(MSG::DEBUG) << dataTypeName() << " retrieved with " << phi.size() << " entries"<< endmsg;
165  }
166 
167  //All collections retrieved okay
168  return DataMap;
169 
170  } // retrieve
171 
172  //--------------------------------------------------------------------------
173 
174 } // JiveXML namespace
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
JiveXML::xAODMuonRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type.
Definition: xAODMuonRetriever.h:45
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
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
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
JiveXML::xAODMuonRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
Definition: xAODMuonRetriever.cxx:49
JiveXML::DataMap
std::map< std::string, DataVect > DataMap
Definition: DataType.h:59
JiveXML::xAODMuonRetriever::xAODMuonRetriever
xAODMuonRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
Definition: xAODMuonRetriever.cxx:31
PowhegPy8EG_H2a.pdgId
dictionary pdgId
Definition: PowhegPy8EG_H2a.py:128
dqt_zlumi_pandas.mass
mass
Definition: dqt_zlumi_pandas.py:170
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
JiveXML::xAODMuonRetriever::getData
const DataMap getData(const xAOD::MuonContainer *)
Retrieve basic parameters, mainly four-vectors, for each collection.
Definition: xAODMuonRetriever.cxx:116
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
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:522
test_pyathena.parent
parent
Definition: test_pyathena.py:15
JiveXML::xAODMuonRetriever::m_sgKey
std::string m_sgKey
Definition: xAODMuonRetriever.h:51
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:21
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
xAODMuonRetriever.h
Units.h
Wrapper to avoid constant divisions when using units.
MuonContainer.h
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
AthAlgTool
Definition: AthAlgTool.h:26
test_pyathena.counter
counter
Definition: test_pyathena.py:15
JiveXML::xAODMuonRetriever::m_otherKeys
std::vector< std::string > m_otherKeys
Definition: xAODMuonRetriever.h:52
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
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.