Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
xAODPhotonRetriever.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  xAODPhotonRetriever::xAODPhotonRetriever(const std::string& type,const std::string& name,const IInterface* parent):
21 
26  StatusCode xAODPhotonRetriever::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(phCont->size());
66  DataVect phi; phi.reserve(phCont->size());
67  DataVect eta; eta.reserve(phCont->size());
68  DataVect mass; mass.reserve(phCont->size());
69  DataVect energy; energy.reserve(phCont->size());
70 
71  DataVect isEMString; isEMString.reserve(phCont->size());
72  DataVect author; author.reserve(phCont->size());
73  DataVect label; label.reserve(phCont->size());
74 
76  xAOD::PhotonContainer::const_iterator phItrE = phCont->end();
77 
78  int counter = 0;
79 
80  for (; phItr != phItrE; ++phItr) {
81  ATH_MSG_DEBUG(" Photon #" << counter++ << " : eta = " << (*phItr)->eta() << ", phi = "
82  << (*phItr)->phi());
83 
84  std::string photonAuthor = "";
85  std::string photonIsEMString = "none";
86  std::string photonLabel = "";
87 
88  phi.emplace_back(DataType((*phItr)->phi()));
89  eta.emplace_back(DataType((*phItr)->eta()));
90  pt.emplace_back(DataType((*phItr)->pt()/GeV));
91 
92  bool passesTight(false);
93  bool passesMedium(false);
94  bool passesLoose(false);
95  const bool tightSelectionExists = (*phItr)->passSelection(passesTight, "Tight");
96  ATH_MSG_VERBOSE("tight exists " << tightSelectionExists
97  << " and passes? " << passesTight);
98  const bool mediumSelectionExists = (*phItr)->passSelection(passesMedium, "Medium");
99  ATH_MSG_VERBOSE("medium exists " << mediumSelectionExists
100  << " and passes? " << passesMedium);
101  const bool looseSelectionExists = (*phItr)->passSelection(passesLoose, "Loose");
102  ATH_MSG_VERBOSE("loose exists " << looseSelectionExists
103  << " and passes? " << passesLoose);
104 
105  photonAuthor = "author"+DataType( (*phItr)->author() ).toString(); // for odd ones eg FWD
106  photonLabel = photonAuthor;
107  if (( (*phItr)->author()) == 0){ photonAuthor = "unknown"; photonLabel += "_unknown"; }
108  if (( (*phItr)->author()) == 8){ photonAuthor = "forward"; photonLabel += "_forward"; }
109  if (( (*phItr)->author()) == 2){ photonAuthor = "softe"; photonLabel += "_softe"; }
110  if (( (*phItr)->author()) == 1){ photonAuthor = "egamma"; photonLabel += "_egamma"; }
111 
112  if ( passesLoose ){
113  photonLabel += "_Loose";
114  photonIsEMString = "Loose"; // assume that hierarchy is obeyed !
115  }
116  if ( passesMedium ){
117  photonLabel += "_Medium";
118  photonIsEMString = "Medium"; // assume that hierarchy is obeyed !
119  }
120  if ( passesTight ){
121  photonLabel += "_Tight";
122  photonIsEMString = "Tight"; // assume that hierarchy is obeyed !
123  }
124  author.emplace_back( DataType( photonAuthor ) );
125  label.emplace_back( DataType( photonLabel ) );
126  isEMString.emplace_back( DataType( photonIsEMString ) );
127 
128  mass.emplace_back(DataType((*phItr)->m()/GeV));
129  energy.emplace_back( DataType((*phItr)->e()/GeV ) );
130  } // end PhotonIterator
131 
132  // four-vectors
133  DataMap["phi"] = phi;
134  DataMap["eta"] = eta;
135  DataMap["pt"] = pt;
136  DataMap["energy"] = energy;
137  DataMap["mass"] = mass;
138  DataMap["isEMString"] = isEMString;
139  DataMap["label"] = label;
140  DataMap["author"] = author;
141 
142  ATH_MSG_DEBUG(dataTypeName() << " retrieved with " << phi.size() << " entries");
143  return DataMap;
144 
145  }
146 
147 
148  const std::vector<std::string> xAODPhotonRetriever::getKeys() {
149 
150  ATH_MSG_DEBUG("in getKeys()");
151 
152  std::vector<std::string> keys = {};
153 
154  // Remove m_priorityKey from m_otherKeys if it exists, we don't want to write it twice
155  auto it = std::find(m_otherKeys.begin(), m_otherKeys.end(), m_priorityKey);
156  if(it != m_otherKeys.end()){
157  m_otherKeys.erase(it);
158  }
159 
160  // Add m_priorityKey as the first element if it is not ""
161  if(m_priorityKey!=""){
162  keys.push_back(m_priorityKey);
163  }
164 
165  if(!m_otherKeys.empty()){
166  keys.insert(keys.end(), m_otherKeys.begin(), m_otherKeys.end());
167  }
168 
169  // If all collections are requested, obtain all available keys from StoreGate
170  std::vector<std::string> allKeys;
172  evtStore()->keys<xAOD::PhotonContainer>(allKeys);
173  // Add keys that are not the priority key and do not add containers with "HLT" in their name if requested
174  for(const std::string& key : allKeys){
175  // Don't include key if it's already in keys
176  auto it2 = std::find(keys.begin(), keys.end(), key);
177  if(it2 != keys.end())continue;
178  if(key.find("HLT") == std::string::npos || m_doWriteHLT){
179  keys.emplace_back(key);
180  }
181  }
182  }
183  return keys;
184  }
185 
186 } // JiveXML namespace
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
JiveXML::xAODPhotonRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
For each photon collection retrieve basic parameters.
Definition: xAODPhotonRetriever.cxx:26
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::xAODPhotonRetriever::getData
const DataMap getData(const xAOD::PhotonContainer *)
Puts the variables into a DataMap.
Definition: xAODPhotonRetriever.cxx:59
JiveXML::xAODPhotonRetriever::m_priorityKey
Gaudi::Property< std::string > m_priorityKey
Definition: xAODPhotonRetriever.h:58
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: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
skel.it
it
Definition: skel.GENtoEVGEN.py:401
test_pyathena.pt
pt
Definition: test_pyathena.py:11
JiveXML::xAODPhotonRetriever::m_otherKeys
Gaudi::Property< std::vector< std::string > > m_otherKeys
Definition: xAODPhotonRetriever.h:57
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
JiveXML::DataMap
std::map< std::string, DataVect > DataMap
Definition: DataType.h:59
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
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
JiveXML::xAODPhotonRetriever::xAODPhotonRetriever
xAODPhotonRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
Definition: xAODPhotonRetriever.cxx:19
JiveXML::xAODPhotonRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type that is generated by this retriever.
Definition: xAODPhotonRetriever.h:48
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
add-xsec-uncert-quadrature-N.label
label
Definition: add-xsec-uncert-quadrature-N.py:104
test_pyathena.parent
parent
Definition: test_pyathena.py:15
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
JiveXML::xAODPhotonRetriever::m_doWriteHLT
Gaudi::Property< bool > m_doWriteHLT
Definition: xAODPhotonRetriever.h:55
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
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
CaloCondBlobAlgs_fillNoiseFromASCII.author
string author
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:26
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
xAODPhotonRetriever.h
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.
JiveXML::xAODPhotonRetriever::getKeys
const std::vector< std::string > getKeys()
Gets the StoreGate keys for the desired containers.
Definition: xAODPhotonRetriever.cxx:148
JiveXML::xAODPhotonRetriever::m_doWriteAllCollections
Gaudi::Property< bool > m_doWriteAllCollections
Definition: xAODPhotonRetriever.h:56
PhotonContainer.h
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