ATLAS Offline Software
Loading...
Searching...
No Matches
xAODPhotonRetriever.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9using Athena::Units::GeV;
10
11namespace JiveXML {
12
19 xAODPhotonRetriever::xAODPhotonRetriever(const std::string& type,const std::string& name,const IInterface* parent):
20 AthAlgTool(type,name,parent){}
21
22
24 ATH_CHECK(m_keys.initialize());
25 return StatusCode::SUCCESS;
26 }
27
28
33 StatusCode xAODPhotonRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
34
35 ATH_MSG_DEBUG("In retrieve()");
36
37 // Loop through the keys and retrieve the corresponding data
38 for (const auto& key : m_keys) {
40 if (cont.isValid()) {
41 DataMap data = getData(&(*cont));
42 if (FormatTool->AddToEvent(dataTypeName(), key.key() + "_xAOD", &data).isFailure()) {
43 ATH_MSG_WARNING("Failed to add collection " << key.key());
44 } else {
45 ATH_MSG_DEBUG(" (" << key.key() << ") retrieved");
46 }
47 } else {
48 ATH_MSG_WARNING("Collection " << key.key() << " not found in SG");
49 }
50 }
51
52 return StatusCode::SUCCESS;
53 }
54
55
61
62 ATH_MSG_DEBUG("in getData()");
63
65
66 DataVect pt; pt.reserve(phCont->size());
67 DataVect phi; phi.reserve(phCont->size());
68 DataVect eta; eta.reserve(phCont->size());
69 DataVect mass; mass.reserve(phCont->size());
70 DataVect energy; energy.reserve(phCont->size());
71
72 DataVect isEMString; isEMString.reserve(phCont->size());
73 DataVect author; author.reserve(phCont->size());
74 DataVect label; label.reserve(phCont->size());
75
78
79 int counter = 0;
80 const std::string mediumStr{"Medium"};
81 const std::string tightStr{"Tight"};
82 const std::string looseStr{"Loose"};
83 auto prefix = [](const std::string & root)->std::string{
84 return '_'+root;
85 };
86 for (; phItr != phItrE; ++phItr) {
87 ATH_MSG_DEBUG(" Photon #" << counter++ << " : eta = " << (*phItr)->eta() << ", phi = "
88 << (*phItr)->phi());
89
90 std::string photonAuthor = "";
91 std::string photonIsEMString = "none";
92 std::string photonLabel = "";
93
94 phi.emplace_back(DataType((*phItr)->phi()));
95 eta.emplace_back(DataType((*phItr)->eta()));
96 pt.emplace_back(DataType((*phItr)->pt()/GeV));
97
98 bool passesTight(false);
99 bool passesMedium(false);
100 bool passesLoose(false);
101 const bool tightSelectionExists = (*phItr)->passSelection(passesTight, tightStr);
102 ATH_MSG_VERBOSE("tight exists " << tightSelectionExists
103 << " and passes? " << passesTight);
104 const bool mediumSelectionExists = (*phItr)->passSelection(passesMedium, mediumStr);
105 ATH_MSG_VERBOSE("medium exists " << mediumSelectionExists
106 << " and passes? " << passesMedium);
107 const bool looseSelectionExists = (*phItr)->passSelection(passesLoose, looseStr);
108 ATH_MSG_VERBOSE("loose exists " << looseSelectionExists
109 << " and passes? " << passesLoose);
110
111 photonAuthor = "author"+DataType( (*phItr)->author() ).toString(); // for odd ones eg FWD
112 photonLabel = photonAuthor;
113 if (( (*phItr)->author()) == 0){ photonAuthor = "unknown"; photonLabel += "_unknown"; }
114 if (( (*phItr)->author()) == 8){ photonAuthor = "forward"; photonLabel += "_forward"; }
115 if (( (*phItr)->author()) == 2){ photonAuthor = "softe"; photonLabel += "_softe"; }
116 if (( (*phItr)->author()) == 1){ photonAuthor = "egamma"; photonLabel += "_egamma"; }
117
118 if ( passesLoose ){
119 photonLabel += prefix(looseStr);
120 photonIsEMString = looseStr; // assume that hierarchy is obeyed !
121 }
122 if ( passesMedium ){
123 photonLabel += prefix(mediumStr);
124 photonIsEMString = mediumStr; // assume that hierarchy is obeyed !
125 }
126 if ( passesTight ){
127 photonLabel += prefix(tightStr);
128 photonIsEMString = tightStr; // assume that hierarchy is obeyed !
129 }
130 author.emplace_back( DataType( photonAuthor ) );
131 label.emplace_back( DataType( photonLabel ) );
132 isEMString.emplace_back( DataType( photonIsEMString ) );
133
134 mass.emplace_back(DataType((*phItr)->m()/GeV));
135 energy.emplace_back( DataType((*phItr)->e()/GeV ) );
136 } // end PhotonIterator
137
138 // four-vectors
139 std::size_t nEntries = phi.size();
140 DataMap["phi"] = std::move(phi);
141 DataMap["eta"] = std::move(eta);
142 DataMap["pt"] = std::move(pt);
143 DataMap["energy"] = std::move(energy);
144 DataMap["mass"] = std::move(mass);
145 DataMap["isEMString"] = std::move(isEMString);
146 DataMap["label"] = std::move(label);
147 DataMap["author"] = std::move(author);
148
149 ATH_MSG_DEBUG(dataTypeName() << " retrieved with " << nEntries << " entries");
150 return DataMap;
151
152 }
153
154
155} // JiveXML namespace
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Wrapper to avoid constant divisions when using units.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:861
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
const DataMap getData(const xAOD::PhotonContainer *)
Puts the variables into a DataMap.
virtual std::string dataTypeName() const
Return the name of the data type that is generated by this retriever.
SG::ReadHandleKeyArray< xAOD::PhotonContainer > m_keys
xAODPhotonRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
For each photon collection retrieve basic parameters.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::string label(const std::string &format, int i)
Definition label.h:19
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
std::map< std::string, DataVect > DataMap
Definition DataType.h:59
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition DataType.h:58
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".