ATLAS Offline Software
Loading...
Searching...
No Matches
BuildVertexPointingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
12#include <TLorentzVector.h>
16
17#include <numeric>
18#include <utility>
19
21
23 ISvcLocator* svcLoc)
24 : EL::AnaAlgorithm(name, svcLoc) {}
25
27 // read
28 ATH_CHECK(m_photonContainerKey.initialize());
29 ATH_CHECK(m_eventInfoKey.initialize());
30
31 ATH_CHECK(m_photon_zvertex_key.initialize());
32 ATH_CHECK(m_photon_errz_key.initialize());
34 ATH_CHECK(m_photon_HPV_errz_key.initialize());
35
36 // write
38
39 ATH_CHECK(m_nphotons_good_key.initialize());
41 ATH_CHECK(m_photons_px_key.initialize());
42 ATH_CHECK(m_photons_py_key.initialize());
43 ATH_CHECK(m_photons_pz_key.initialize());
44 ATH_CHECK(m_photon_links_key.initialize());
45
46 // tool
47 ATH_CHECK(m_selectionTool.retrieve());
48
49 ATH_MSG_INFO("Use at maximum " << m_nphotons_to_use
50 << " photons for pointing");
51 ATH_MSG_INFO("Selecting photons for pointing with "
52 << m_selectionTool << " with "
53 << m_selectionTool->getAcceptInfo().getNCuts() << "cuts:");
54 for (unsigned int icut = 0;
55 icut < m_selectionTool->getAcceptInfo().getNCuts(); ++icut) {
57 "cut " << icut << ": "
58 << m_selectionTool->getAcceptInfo().getCutDescription(icut));
59 }
60 return StatusCode::SUCCESS;
61}
62
64 // the code has been written with photons in mind, but it is important
65 // the code to work also with electrons since electrons are used as a
66 // proxy of photons in performance studies
68 ATH_CHECK(original_photons.isValid());
69
70 ATH_MSG_DEBUG("number of photon in the container ("
71 << m_photonContainerKey << "): " << original_photons->size());
72
73 // these photons will be used to compute pointing variables
75 selectPhotons(*original_photons, photons_selected);
76
78 const std::pair<float, float> z_common_and_error =
81
82 // create new vertex container
83 auto pointingVertices = std::make_unique<xAOD::VertexContainer>();
84 auto pointingVerticesAux = std::make_unique<xAOD::VertexAuxContainer>();
85 pointingVertices->setStore(pointingVerticesAux.get());
86
87 // create new vertex
88 xAOD::Vertex* vtx_pointing =
89 (*pointingVertices).push_back(std::make_unique<xAOD::Vertex>());
90
92
93 vtx_pointing->setZ(z_common_and_error.first);
94 vtx_pointing->setX(0.0);
95 vtx_pointing->setY(0.0);
96 AmgSymMatrix(3) cov;
97 cov.setZero();
98 cov(2, 2) = z_common_and_error.second * z_common_and_error.second;
99 vtx_pointing->setCovariancePosition(cov);
100
102 ANA_CHECK(writeHandle.record(std::move(pointingVertices),
103 std::move(pointingVerticesAux)));
104
105 // below only decorations to the vertex
106
107 const unsigned int n_good_photons =
108 std::count_if(photons_selected.begin(), photons_selected.end(),
109 [this](const xAOD::Egamma* photon) {
110 return m_goodPhotonSelectionTool->accept(photon);
111 });
112
113 std::vector<ElementLink<xAOD::EgammaContainer>> ph_links;
114 ph_links.reserve(photons_selected.size());
115 for (const xAOD::Egamma* photon : photons_selected) {
116 ph_links.emplace_back(*original_photons, photon->index());
117 }
118
121 auto dec_nphotons_good = SG::makeHandle<unsigned int>(m_nphotons_good_key);
122
123 dec_nphotons(*vtx_pointing) = photons_selected.size();
124 dec_ph_links(*vtx_pointing) = ph_links;
125 dec_nphotons_good(*vtx_pointing) = n_good_photons;
126
127 // compute common vertex from the pointing
128 const TLorentzVector p4_photons = std::accumulate(
129 photons_selected.begin(), photons_selected.end(),
130 TLorentzVector(0, 0, 0, 0),
131 [](TLorentzVector sum, const xAOD::Egamma* photon) {
132 TLorentzVector v_ph;
133 const xAOD::CaloCluster* cluster = photon->caloCluster();
134 v_ph.SetPtEtaPhiM(photon->e() / cosh(cluster->etaBE(2)),
135 cluster->etaBE(2), cluster->phiBE(2), 0.0);
136 sum += v_ph;
137 return sum;
138 });
139
140 auto dec_photons_px = SG::makeHandle<float>(m_photons_px_key);
141 auto dec_photons_py = SG::makeHandle<float>(m_photons_py_key);
142 auto dec_photons_pz = SG::makeHandle<float>(m_photons_pz_key);
143
144 dec_photons_px(*vtx_pointing) = p4_photons.X();
145 dec_photons_py(*vtx_pointing) = p4_photons.Y();
146 dec_photons_pz(*vtx_pointing) = p4_photons.Z();
147
148 return StatusCode::SUCCESS;
149}
150
152 const xAOD::EgammaContainer& original_photons,
153 ConstDataVector<DataVector<xAOD::Egamma>>& photons_selected) const {
154 for (const xAOD::Egamma* photon : original_photons) {
155 if (m_selectionTool->accept(photon)) {
156 photons_selected.push_back(photon);
157 ATH_MSG_DEBUG("photon selected for pointing: pT = " << photon->pt()
158 << " GeV");
159 }
160 }
162 "number of photons selected for pointing: " << photons_selected.size());
163
164 // limit the number of photons to use
165 if (m_nphotons_to_use >= 0 and
166 photons_selected.size() > static_cast<std::size_t>(m_nphotons_to_use)) {
167 std::sort(photons_selected.begin(), photons_selected.end(),
168 [](const xAOD::IParticle* a, const xAOD::IParticle* b) {
169 return a->pt() > b->pt(); // sort from the highest pT
170 });
171
172 photons_selected.resize(m_nphotons_to_use);
173 }
174 ATH_MSG_DEBUG("number of photons selected for pointing after limiting: "
175 << photons_selected.size());
176 if (ATH_UNLIKELY(this->msgLvl(MSG::DEBUG))) {
177 for (const xAOD::Egamma* photon : photons_selected) {
178 ATH_MSG_DEBUG("photon selected for pointing: pT = " << photon->pt()
179 << " GeV");
180 }
181 }
182}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
Handle class for recording to StoreGate.
#define ATH_UNLIKELY(x)
DataVector adapter that acts like it holds const pointers.
#define ANA_CHECK(EXP)
check whether the given expression was successful
#define AmgSymMatrix(dim)
static Double_t a
bool msgLvl(const MSG::Level lvl) const
SG::ReadDecorHandleKey< xAOD::EgammaContainer > m_photon_errz_key
virtual StatusCode initialize()
void selectPhotons(const xAOD::EgammaContainer &original_photons, ConstDataVector< DataVector< xAOD::Egamma > > &photons_selected) const
SG::ReadDecorHandleKey< xAOD::EgammaContainer > m_photon_zvertex_key
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_photons_px_key
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_photon_links_key
Gaudi::Property< int > m_nphotons_to_use
Gaudi::Property< float > m_convPtCut
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_z_common_nphotons_key
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_nphotons_good_key
SG::WriteHandleKey< xAOD::VertexContainer > m_pointingVertexContainerKey
SG::ReadHandleKey< xAOD::EgammaContainer > m_photonContainerKey
BuildVertexPointingAlg(const std::string &name, ISvcLocator *svcLoc=nullptr)
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_photons_py_key
ToolHandle< IAsgSelectionTool > m_selectionTool
SG::ReadDecorHandleKey< xAOD::EgammaContainer > m_photon_HPV_zvertex_key
SG::ReadDecorHandleKey< xAOD::EgammaContainer > m_photon_HPV_errz_key
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_photons_pz_key
DataVector adapter that acts like it holds const pointers.
iterator begin() noexcept
Return an iterator pointing at the beginning of the collection.
iterator end() noexcept
Return an iterator pointing past the end of the collection.
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
Derived DataVector<T>.
Definition DataVector.h:795
AnaAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
constructor with parameters
virtual bool isValid() override final
Can the handle be successfully dereferenced?
float phiBE(const unsigned layer) const
Get the phi in one layer of the EM Calo.
float etaBE(const unsigned layer) const
Get the eta in one layer of the EM Calo.
Class providing the definition of the 4-vector interface.
void setCovariancePosition(const AmgSymMatrix(3)&covariancePosition)
Sets the vertex covariance matrix.
void setZ(float value)
Sets the z position.
void setX(float value)
Sets the x position.
void setY(float value)
Sets the y position.
void setVertexType(VxType::VertexType vType)
Set the type of the vertex.
This module defines the arguments passed from the BATCH driver to the BATCH worker.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
std::pair< float, float > getZCommonAndError(const xAOD::EventInfo *eventInfo, const xAOD::EgammaContainer *egammas, float convPtCut=2e3)
Return zCommon and zCommonError.
@ PriVtx
Primary vertex.
EventInfo_v1 EventInfo
Definition of the latest event info version.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Vertex_v1 Vertex
Define the latest version of the vertex class.
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
EgammaContainer_v1 EgammaContainer
Definition of the current "egamma container version".