ATLAS Offline Software
PFlowAugmentationTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // PFlowAugmentationTool.cxx, (c) ATLAS Detector software
8 // Author: Fabrice Balli (fabrice.balli@cern.ch), Chris Young (christopher.young@cern.ch)
9 //
10 
11 #include "PFlowAugmentationTool.h"
12 
14 
15 namespace DerivationFramework {
16 
18  const std::string& n,
19  const IInterface* p) :
20  base_class(t,n,p),
21  m_weightPFOTool("CP::WeightPFOTool/WeightPFOTool")
22  {
23  declareProperty("WeightPFOTool", m_weightPFOTool );
24  }
25 
27  {
28 
29  ATH_CHECK(m_vertexContainer_key.initialize());
30  ATH_CHECK(m_pfoContainer_key.initialize());
31  ATH_CHECK(m_corrP4_ptKey.initialize());
32  ATH_CHECK(m_z0Key.initialize());
33  ATH_CHECK(m_vzKey.initialize());
34  ATH_CHECK(m_d0Key.initialize());
35  ATH_CHECK(m_thetaKey.initialize());
36  ATH_CHECK(m_envWeightKey.initialize());
37 
38  return StatusCode::SUCCESS;
39  }
40 
42  {
43  return StatusCode::SUCCESS;
44  }
45 
46  StatusCode PFlowAugmentationTool::addBranches(const EventContext& ctx) const
47  {
48  // Get the vertex.
49  const xAOD::Vertex* pv{};
50 
51  auto vertexContainer = SG::makeHandle (m_vertexContainer_key, ctx);
52  if (!vertexContainer.isValid()){
53  ATH_MSG_WARNING("Invalid xAOD::VertexContainer datahandle"
54  << m_vertexContainer_key.key());
55  return StatusCode::FAILURE;
56  }
57  auto pvcont = vertexContainer.cptr();
58  if ( pvcont == 0 || pvcont->size()==0 ) {
59  ATH_MSG_WARNING(" Failed to retrieve PrimaryVertices collection" );
60  return StatusCode::FAILURE;
61  }
62  for (const auto vx : *pvcont) {
63  if (vx->vertexType() == xAOD::VxType::PriVtx) {
64  pv = vx;
65  break;
66  }//If we have a vertex of type primary vertex
67  }//iterate over the vertices and check their type
68 
69  // Use NoVtx as fall-back in case no PV is found, but the events should be rejected by the user
70  // If there is no such then mark all CPFOs as unmatched
71  if (pv == nullptr) {
72  ATH_MSG_DEBUG("Could not find a primary vertex in this event" );
73  for (auto theVertex : *pvcont) {
74  if (xAOD::VxType::NoVtx == theVertex->vertexType() ) {
75  pv = theVertex;
76  break;
77  }
78  }
79  if (nullptr == pv) {
80  ATH_MSG_WARNING("Found neither PriVtx nor NoVtx in this event" );
81  }
82  }
83 
90 
91  auto pfoContainer = SG::makeHandle (m_pfoContainer_key, ctx);
92  if (!pfoContainer.isValid()){
93  ATH_MSG_WARNING("Invalid xAOD::PFOContainer datahandle"
94  << m_pfoContainer_key.key());
95  return StatusCode::FAILURE;
96  }
97  auto cpfos = pfoContainer.cptr();
98 
99  for ( const xAOD::FlowElement* cpfo : *cpfos ) {
100  if ( cpfo == 0 ) {
101  ATH_MSG_WARNING("Have NULL pointer to charged PFO");
102  continue;
103  }
104  const xAOD::TrackParticle* ptrk = dynamic_cast<const xAOD::TrackParticle*>(cpfo->chargedObject(0));
105  if ( ptrk == 0 ) {
106  ATH_MSG_WARNING("Skipping charged PFO with null track pointer.");
107  continue;
108  }
109 
110  // decorate the track properties
111  dec_z0(*cpfo) = ptrk->z0();
112  dec_vz(*cpfo) = ptrk->vz();
113  dec_d0(*cpfo) = ptrk->d0();
114  dec_theta(*cpfo) = ptrk->theta();
115 
116  //find the weights from the tool
117  float weight = 1.0;
118  const static SG::AuxElement::ConstAccessor<int> accIsInDE("IsInDenseEnvironment");
119  if(accIsInDE.isAvailable(*cpfo)){
120  ATH_CHECK( m_weightPFOTool->fillWeight( *cpfo, weight ) );
121  }
122 
123  // decorate the computed variables
124  dec_corrP4_pt(*cpfo) = weight*cpfo->pt();
125  dec_envWeight(*cpfo) = weight;
126  }
127 
128  return StatusCode::SUCCESS;
129  }
130 }
DerivationFramework::PFlowAugmentationTool::m_z0Key
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_z0Key
Definition: PFlowAugmentationTool.h:45
DerivationFramework::PFlowAugmentationTool::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const
Definition: PFlowAugmentationTool.cxx:46
DerivationFramework::PFlowAugmentationTool::m_pfoContainer_key
SG::ReadHandleKey< xAOD::FlowElementContainer > m_pfoContainer_key
Definition: PFlowAugmentationTool.h:42
xAOD::TrackParticle_v1::vz
float vz() const
The z origin for the parameters.
DerivationFramework::PFlowAugmentationTool::m_thetaKey
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_thetaKey
Definition: PFlowAugmentationTool.h:48
xAOD::TrackParticle_v1::z0
float z0() const
Returns the parameter.
DerivationFramework::PFlowAugmentationTool::initialize
StatusCode initialize()
Definition: PFlowAugmentationTool.cxx:26
DerivationFramework::PFlowAugmentationTool::finalize
StatusCode finalize()
Definition: PFlowAugmentationTool.cxx:41
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::PFlowAugmentationTool::m_corrP4_ptKey
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_corrP4_ptKey
Definition: PFlowAugmentationTool.h:44
xAOD::VxType::NoVtx
@ NoVtx
Dummy vertex. TrackParticle was not used in vertex fit.
Definition: TrackingPrimitives.h:571
DerivationFramework::PFlowAugmentationTool::PFlowAugmentationTool
PFlowAugmentationTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: PFlowAugmentationTool.cxx:17
xAOD::TrackParticle_v1::d0
float d0() const
Returns the parameter.
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:190
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
beamspotman.n
n
Definition: beamspotman.py:727
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
WriteDecorHandle.h
Handle class for adding a decoration to an object.
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:572
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DerivationFramework::PFlowAugmentationTool::m_weightPFOTool
ToolHandle< CP::IWeightPFOTool > m_weightPFOTool
Definition: PFlowAugmentationTool.h:39
DerivationFramework::PFlowAugmentationTool::m_d0Key
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_d0Key
Definition: PFlowAugmentationTool.h:47
DerivationFramework::PFlowAugmentationTool::m_vertexContainer_key
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainer_key
Retrieval tool.
Definition: PFlowAugmentationTool.h:41
PFlowAugmentationTool.h
DerivationFramework::PFlowAugmentationTool::m_envWeightKey
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_envWeightKey
Definition: PFlowAugmentationTool.h:49
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.changerun.pv
pv
Definition: changerun.py:79
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
DerivationFramework::PFlowAugmentationTool::m_vzKey
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_vzKey
Definition: PFlowAugmentationTool.h:46
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:44
xAOD::TrackParticle_v1::theta
float theta() const
Returns the parameter, which has range 0 to .
xAOD::FlowElement_v1
A detector object made of other lower level object(s)
Definition: FlowElement_v1.h:25