ATLAS Offline Software
Loading...
Searching...
No Matches
PFlowAugmentationTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6// PFlowAugmentationTool.cxx
8// Author: Fabrice Balli (fabrice.balli@cern.ch), Chris Young (christopher.young@cern.ch)
9//
10
12
14
15namespace DerivationFramework {
16
18 {
19
20 ATH_CHECK(m_vertexContainer_key.initialize());
21 ATH_CHECK(m_pfoContainer_key.initialize());
22 ATH_CHECK(m_corrP4_ptKey.initialize());
23 ATH_CHECK(m_z0Key.initialize());
24 ATH_CHECK(m_vzKey.initialize());
25 ATH_CHECK(m_d0Key.initialize());
26 ATH_CHECK(m_thetaKey.initialize());
27 ATH_CHECK(m_envWeightKey.initialize());
28
29 return StatusCode::SUCCESS;
30 }
31
32 StatusCode PFlowAugmentationTool::addBranches(const EventContext& ctx) const
33 {
34 // Get the vertex.
35 const xAOD::Vertex* pv{};
36
37 auto vertexContainer = SG::makeHandle (m_vertexContainer_key, ctx);
38 if (!vertexContainer.isValid()){
39 ATH_MSG_WARNING("Invalid xAOD::VertexContainer datahandle"
40 << m_vertexContainer_key.key());
41 return StatusCode::FAILURE;
42 }
43 auto pvcont = vertexContainer.cptr();
44 if ( pvcont == 0 || pvcont->size()==0 ) {
45 ATH_MSG_WARNING(" Failed to retrieve PrimaryVertices collection" );
46 return StatusCode::FAILURE;
47 }
48 for (const auto vx : *pvcont) {
49 if (vx->vertexType() == xAOD::VxType::PriVtx) {
50 pv = vx;
51 break;
52 }//If we have a vertex of type primary vertex
53 }//iterate over the vertices and check their type
54
55 // Use NoVtx as fall-back in case no PV is found, but the events should be rejected by the user
56 // If there is no such then mark all CPFOs as unmatched
57 if (pv == nullptr) {
58 ATH_MSG_DEBUG("Could not find a primary vertex in this event" );
59 for (auto theVertex : *pvcont) {
60 if (xAOD::VxType::NoVtx == theVertex->vertexType() ) {
61 pv = theVertex;
62 break;
63 }
64 }
65 if (nullptr == pv) {
66 ATH_MSG_WARNING("Found neither PriVtx nor NoVtx in this event" );
67 }
68 }
69
76
77 auto pfoContainer = SG::makeHandle (m_pfoContainer_key, ctx);
78 if (!pfoContainer.isValid()){
79 ATH_MSG_WARNING("Invalid xAOD::PFOContainer datahandle"
80 << m_pfoContainer_key.key());
81 return StatusCode::FAILURE;
82 }
83 auto cpfos = pfoContainer.cptr();
84
85 for ( const xAOD::FlowElement* cpfo : *cpfos ) {
86 if ( cpfo == 0 ) {
87 ATH_MSG_WARNING("Have NULL pointer to charged PFO");
88 continue;
89 }
90 const xAOD::TrackParticle* ptrk = dynamic_cast<const xAOD::TrackParticle*>(cpfo->chargedObject(0));
91 if ( ptrk == 0 ) {
92 ATH_MSG_WARNING("Skipping charged PFO with null track pointer.");
93 continue;
94 }
95
96 // decorate the track properties
97 dec_z0(*cpfo) = ptrk->z0();
98 dec_vz(*cpfo) = ptrk->vz();
99 dec_d0(*cpfo) = ptrk->d0();
100 dec_theta(*cpfo) = ptrk->theta();
101
102 //find the weights from the tool
103 float weight = 1.0;
104 const static SG::AuxElement::ConstAccessor<int> accIsInDE("IsInDenseEnvironment");
105 if(accIsInDE.isAvailable(*cpfo)){
106 ATH_CHECK( m_weightPFOTool->fillWeight( *cpfo, weight ) );
107 }
108
109 // decorate the computed variables
110 dec_corrP4_pt(*cpfo) = weight*cpfo->pt();
111 dec_envWeight(*cpfo) = weight;
112 }
113
114 return StatusCode::SUCCESS;
115 }
116}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for adding a decoration to an object.
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_d0Key
virtual StatusCode addBranches(const EventContext &ctx) const override final
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_corrP4_ptKey
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_envWeightKey
virtual StatusCode initialize() override final
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_z0Key
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainer_key
SG::ReadHandleKey< xAOD::FlowElementContainer > m_pfoContainer_key
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_vzKey
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_thetaKey
PublicToolHandle< CP::IWeightPFOTool > m_weightPFOTool
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
Handle class for adding a decoration to an object.
float z0() const
Returns the parameter.
float theta() const
Returns the parameter, which has range 0 to .
float vz() const
The z origin for the parameters.
float d0() const
Returns the parameter.
THE reconstruction tool.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
@ PriVtx
Primary vertex.
@ NoVtx
Dummy vertex. TrackParticle was not used in vertex fit.
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition FlowElement.h:16
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.