Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
xAODMuonRetriever.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "AthenaKernel/Units.h"
8 
10 
11 namespace JiveXML {
12 
19  xAODMuonRetriever::xAODMuonRetriever(const std::string& type,const std::string& name,const IInterface* parent):
21 
26  StatusCode xAODMuonRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
27 
28  ATH_MSG_DEBUG("In retrieve()");
29 
30  std::vector<std::string> keys = getKeys();
31 
32  if(keys.empty()){
33  ATH_MSG_WARNING("No StoreGate keys found");
34  return StatusCode::SUCCESS;
35  }
36 
37  // Loop through the keys and retrieve the corresponding data
38  for (const std::string& key : keys) {
40  if (cont.isValid()) {
41  DataMap data = getData(&(*cont));
42  if (FormatTool->AddToEvent(dataTypeName(), key + "_xAOD", &data).isFailure()) {
43  ATH_MSG_WARNING("Failed to retrieve Collection " << key);
44  } else {
45  ATH_MSG_DEBUG(" (" << key << ") retrieved");
46  }
47  } else {
48  ATH_MSG_WARNING("Collection " << key << " not found in SG");
49  }
50  }
51  return StatusCode::SUCCESS;
52  }
53 
54 
60 
61  ATH_MSG_DEBUG("in getData()");
62 
64 
65  DataVect pt; pt.reserve(muCont->size());
66  DataVect phi; phi.reserve(muCont->size());
67  DataVect eta; eta.reserve(muCont->size());
68  DataVect mass; mass.reserve(muCont->size());
69  DataVect energy; energy.reserve(muCont->size());
70  DataVect chi2; chi2.reserve(muCont->size());
71  DataVect pdgId; pdgId.reserve(muCont->size());
72 
74  xAOD::MuonContainer::const_iterator muItrE = muCont->end();
75 
76  int counter = 0;
77 
78  for (; muItr != muItrE; ++muItr) {
79 
80  ATH_MSG_DEBUG(" Muon #" << counter++ << " : eta = " << (*muItr)->eta()
81  << ", phi = " << (*muItr)->phi() << ", pt = " << (*muItr)->pt()
82  << ", pdgId = " << -13.*(*muItr)->primaryTrackParticle()->charge());
83 
84  phi.emplace_back(DataType((*muItr)->phi()));
85  eta.emplace_back(DataType((*muItr)->eta()));
86  pt.emplace_back(DataType((*muItr)->pt()/GeV));
87 
88  mass.emplace_back(DataType((*muItr)->m()/GeV));
89  energy.emplace_back( DataType((*muItr)->e()/GeV ) );
90  chi2.emplace_back( 1.0 ); //placeholder
91  pdgId.emplace_back(DataType( -13.*(*muItr)->primaryTrackParticle()->charge() )); // pdgId not available anymore in xAOD
92  } // end MuonIterator
93 
94  // four-vectors
95  DataMap["phi"] = phi;
96  DataMap["eta"] = eta;
97  DataMap["pt"] = pt;
98  DataMap["energy"] = energy;
99  DataMap["mass"] = mass;
100  DataMap["chi2"] = chi2;
101  DataMap["pdgId"] = pdgId;
102 
103  ATH_MSG_DEBUG(" retrieved with " << phi.size() << " entries");
104  return DataMap;
105  }
106 
107 
108  const std::vector<std::string> xAODMuonRetriever::getKeys() {
109 
110  ATH_MSG_DEBUG("in getKeys()");
111 
112  std::vector<std::string> keys = {};
113 
114  // Remove m_priorityKey from m_otherKeys if it exists, we don't want to write it twice
115  auto it = std::find(m_otherKeys.begin(), m_otherKeys.end(), m_priorityKey);
116  if(it != m_otherKeys.end()){
117  m_otherKeys.erase(it);
118  }
119 
120  // Add m_priorityKey as the first element if it is not ""
121  if(m_priorityKey!=""){
122  keys.push_back(m_priorityKey);
123  }
124 
125  if(!m_otherKeys.empty()){
126  keys.insert(keys.end(), m_otherKeys.begin(), m_otherKeys.end());
127  }
128 
129  // If all collections are requested, obtain all available keys from StoreGate
130  std::vector<std::string> allKeys;
132  evtStore()->keys<xAOD::MuonContainer>(allKeys);
133  // Add keys that are not the priority key and do not add containers with "HLT" in their name if requested
134  for(const std::string& key : allKeys){
135  // Don't include key if it's already in keys
136  auto it2 = std::find(keys.begin(), keys.end(), key);
137  if(it2 != keys.end())continue;
138  if(key.find("HLT") == std::string::npos || m_doWriteHLT){
139  keys.emplace_back(key);
140  }
141  }
142  }
143  return keys;
144  }
145 } // JiveXML namespace
JiveXML::xAODMuonRetriever::m_doWriteHLT
Gaudi::Property< bool > m_doWriteHLT
Definition: xAODMuonRetriever.h:55
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::xAODMuonRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type that is generated by this retriever.
Definition: xAODMuonRetriever.h:48
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
JiveXML::xAODMuonRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
For each muon collections retrieve basic parameters.
Definition: xAODMuonRetriever.cxx:26
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:19
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
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 *)
Puts the variables into a DataMap.
Definition: xAODMuonRetriever.cxx:59
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
JiveXML::xAODMuonRetriever::m_doWriteAllCollections
Gaudi::Property< bool > m_doWriteAllCollections
Definition: xAODMuonRetriever.h:56
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:525
test_pyathena.parent
parent
Definition: test_pyathena.py:15
JiveXML::xAODMuonRetriever::m_priorityKey
Gaudi::Property< std::string > m_priorityKey
Definition: xAODMuonRetriever.h:58
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
xAODMuonRetriever.h
Units.h
Wrapper to avoid constant divisions when using units.
JiveXML::xAODMuonRetriever::m_otherKeys
Gaudi::Property< std::vector< std::string > > m_otherKeys
Definition: xAODMuonRetriever.h:57
MuonContainer.h
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
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
AthAlgTool
Definition: AthAlgTool.h:26
test_pyathena.counter
counter
Definition: test_pyathena.py:15
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.
JiveXML::xAODMuonRetriever::getKeys
const std::vector< std::string > getKeys()
Gets the StoreGate keys for the desired containers.
Definition: xAODMuonRetriever.cxx:108
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37