ATLAS Offline Software
PhotonVertexSelectionWrapper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include <vector>
8 
9 namespace DerivationFramework {
10 
12  const std::string& n,
13  const IInterface* p)
14  : AthAlgTool(t, n, p)
15  , m_decPrefix("")
16 {
17  declareInterface<DerivationFramework::IAugmentationTool>(this);
19  "DecorationPrefix", m_decPrefix, "Prefix for the decoration name");
20 }
21 
24 {
25  ATH_MSG_DEBUG("Initializing " << name() << "...");
26  ATH_CHECK(m_photonPointingTool.retrieve());
27  ATH_MSG_DEBUG("Retrieved tool " << m_photonPointingTool);
28 
29  ATH_CHECK(m_photonContainer.initialize());
30  ATH_CHECK(m_vertexContainer.initialize());
31 
32  const std::string baseName = m_vertexContainer.key();
33  std::string prefix = "";
34  if(!m_decPrefix.empty()) prefix = m_decPrefix + "_";
35  m_vtxPt = baseName + "." + prefix + "pt";
36  m_vtxEta = baseName + "." + prefix + "eta";
37  m_vtxPhi = baseName + "." + prefix + "phi";
38  m_vtxSumPt = baseName + "." + prefix + "sumPt";
39  m_vtxSumPt2 = baseName + "." + prefix + "sumPt2";
40 
41  ATH_CHECK(m_vtxPt.initialize());
42  ATH_CHECK(m_vtxEta.initialize());
43  ATH_CHECK(m_vtxPhi.initialize());
44  ATH_CHECK(m_vtxSumPt.initialize());
45  ATH_CHECK(m_vtxSumPt2.initialize());
46 
47  ATH_MSG_DEBUG("Initialization successful");
48 
49  return StatusCode::SUCCESS;
50 }
51 
54 {
55  // retrieve the input containers
56  const EventContext& ctx = Gaudi::Hive::currentContext();
59 
60  // Update calo pointing auxdata for photons
61  if (m_photonPointingTool->updatePointingAuxdata(*photons).isFailure()) {
62  ATH_MSG_ERROR("Couldn't update photon calo pointing auxdata");
63  return StatusCode::FAILURE;
64  }
65 
66  // create the decorators
72  bool isMomentum_available = vtxPt.isAvailable();
73  bool isSumPt_available = vtxSumPt.isAvailable();
74  bool isSumPt2_available = vtxSumPt2.isAvailable();
75  bool found_PV = false;
76 
77  // Loop over vertices and update auxdata
78  for (const auto *vertex : *vertices) {
79 
80  float pt = -999.;
81  float eta = -999.;
82  float phi = -999.;
83  float sumPt = -999.;
84  float sumPt2 = -999.;
85 
86  if(vertex->vertexType() == xAOD::VxType::VertexType::PriVtx or
87  vertex->vertexType() == xAOD::VxType::VertexType::PileUp){
88 
89  found_PV = true;
90  // Get momentum vector of vertex and add it as a decoration
91  TLorentzVector vmom = xAOD::PVHelpers::getVertexMomentum(vertex, isMomentum_available);
92  pt = sqrt(vmom.Px() * vmom.Px() + vmom.Py() * vmom.Py());
93  if(pt>0.){
94  eta = asinh(vmom.Pz() / pt);
95  phi = acos(vmom.Px() / pt); // in [0,Pi]
96  }
97  // Calculate additional quantities
98  sumPt = xAOD::PVHelpers::getVertexSumPt(vertex, 1, isSumPt_available);
99  sumPt2 = xAOD::PVHelpers::getVertexSumPt(vertex, 2, isSumPt2_available);
100 
101  }
102 
103  // write decorations
104  if(!isMomentum_available){
105  vtxPt(*vertex) = pt;
106  vtxEta(*vertex) = eta;
107  vtxPhi(*vertex) = phi;
108  }
109  if(!isSumPt_available) vtxSumPt(*vertex) = sumPt;
110  // For events where no PV is reconstructed, beamspot is saved and isSumPt2_available = False
111  // Need to also check found_PV to avoid modifying locked store
112  if(!isSumPt2_available && found_PV) vtxSumPt2(*vertex) = sumPt2;
113 
114  } // end loop o vertices
115 
116  return StatusCode::SUCCESS;
117 }
118 
119 }
xAOD::PVHelpers::getVertexSumPt
float getVertexSumPt(const xAOD::Vertex *vertex, int power=1, bool useAux=true)
Loop over track particles associated with vertex and return scalar sum of pT^power in GeV (from auxda...
Definition: PhotonVertexHelpers.cxx:215
DerivationFramework::PhotonVertexSelectionWrapper::PhotonVertexSelectionWrapper
PhotonVertexSelectionWrapper(const std::string &t, const std::string &n, const IInterface *p)
Definition: PhotonVertexSelectionWrapper.cxx:11
SG::WriteDecorHandle::isAvailable
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DerivationFramework::PhotonVertexSelectionWrapper::m_vertexContainer
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainer
Input primary vertex container.
Definition: PhotonVertexSelectionWrapper.h:63
test_pyathena.pt
pt
Definition: test_pyathena.py:11
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::PhotonVertexSelectionWrapper::m_vtxPt
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_vtxPt
Definition: PhotonVertexSelectionWrapper.h:72
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DerivationFramework::PhotonVertexSelectionWrapper::m_photonPointingTool
ToolHandle< CP::IPhotonPointingTool > m_photonPointingTool
PhotonPointingTool.
Definition: PhotonVertexSelectionWrapper.h:44
beamspotman.n
n
Definition: beamspotman.py:731
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
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
DerivationFramework::PhotonVertexSelectionWrapper::m_decPrefix
std::string m_decPrefix
Prefix for the decorations.
Definition: PhotonVertexSelectionWrapper.h:52
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
python.Dumpers.asinh
def asinh(x)
helper methods ---------------------------------------------------------—
Definition: Dumpers.py:89
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
xAOD::PVHelpers::getVertexMomentum
TLorentzVector getVertexMomentum(const xAOD::Vertex *vertex, bool useAux=true, const std::string &derivationPrefix="")
Return vector sum of tracks associated with vertex (from auxdata if available and useAux = true)
Definition: PhotonVertexHelpers.cxx:175
DerivationFramework::PhotonVertexSelectionWrapper::m_vtxSumPt2
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_vtxSumPt2
Definition: PhotonVertexSelectionWrapper.h:85
PhotonVertexHelpers.h
DerivationFramework::PhotonVertexSelectionWrapper::m_vtxSumPt
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_vtxSumPt
Definition: PhotonVertexSelectionWrapper.h:81
DerivationFramework::PhotonVertexSelectionWrapper::m_vtxPhi
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_vtxPhi
Definition: PhotonVertexSelectionWrapper.h:77
xAOD::VxType::PileUp
@ PileUp
Pile-up vertex.
Definition: TrackingPrimitives.h:573
DerivationFramework::PhotonVertexSelectionWrapper::m_photonContainer
SG::ReadHandleKey< xAOD::PhotonContainer > m_photonContainer
Input photon container.
Definition: PhotonVertexSelectionWrapper.h:55
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
DerivationFramework::PhotonVertexSelectionWrapper::initialize
StatusCode initialize() override final
Definition: PhotonVertexSelectionWrapper.cxx:23
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
DerivationFramework::PhotonVertexSelectionWrapper::m_vtxEta
SG::WriteDecorHandleKey< xAOD::VertexContainer > m_vtxEta
Definition: PhotonVertexSelectionWrapper.h:73
PhotonVertexSelectionWrapper.h
DerivationFramework::PhotonVertexSelectionWrapper::addBranches
virtual StatusCode addBranches() const override final
Pass the thinning service
Definition: PhotonVertexSelectionWrapper.cxx:53
AthAlgTool
Definition: AthAlgTool.h:26