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  AthAlgTool(t,n,p),
21  m_weightPFOTool("CP::WeightPFOTool/WeightPFOTool")
22  {
23  declareInterface<DerivationFramework::IAugmentationTool>(this);
24  declareProperty("WeightPFOTool", m_weightPFOTool );
25  }
26 
28  {
29 
30  ATH_CHECK(m_vertexContainer_key.initialize());
31  ATH_CHECK(m_pfoContainer_key.initialize());
32  ATH_CHECK(m_corrP4_ptKey.initialize());
33  ATH_CHECK(m_z0Key.initialize());
34  ATH_CHECK(m_vzKey.initialize());
35  ATH_CHECK(m_d0Key.initialize());
36  ATH_CHECK(m_thetaKey.initialize());
37  ATH_CHECK(m_envWeightKey.initialize());
38 
39  return StatusCode::SUCCESS;
40  }
41 
43  {
44  return StatusCode::SUCCESS;
45  }
46 
48  {
49 
50  // Get the vertex.
51  const xAOD::Vertex* pv(0);
52 
53  auto vertexContainer = SG::makeHandle (m_vertexContainer_key);
54  if (!vertexContainer.isValid()){
55  ATH_MSG_WARNING("Invalid xAOD::VertexContainer datahandle"
56  << m_vertexContainer_key.key());
57  return StatusCode::FAILURE;
58  }
59  auto pvcont = vertexContainer.cptr();
60  if ( pvcont == 0 || pvcont->size()==0 ) {
61  ATH_MSG_WARNING(" Failed to retrieve PrimaryVertices collection" );
62  return StatusCode::FAILURE;
63  }
64  for (const auto vx : *pvcont) {
65  if (vx->vertexType() == xAOD::VxType::PriVtx) {
66  pv = vx;
67  break;
68  }//If we have a vertex of type primary vertex
69  }//iterate over the vertices and check their type
70 
71  // Use NoVtx as fall-back in case no PV is found, but the events should be rejected by the user
72  // If there is no such then mark all CPFOs as unmatched
73  if (pv == nullptr) {
74  ATH_MSG_DEBUG("Could not find a primary vertex in this event" );
75  for (auto theVertex : *pvcont) {
76  if (xAOD::VxType::NoVtx == theVertex->vertexType() ) {
77  pv = theVertex;
78  break;
79  }
80  }
81  if (nullptr == pv) {
82  ATH_MSG_WARNING("Found neither PriVtx nor NoVtx in this event" );
83  }
84  }
85 
92 
93  auto pfoContainer = SG::makeHandle (m_pfoContainer_key);
94  if (!pfoContainer.isValid()){
95  ATH_MSG_WARNING("Invalid xAOD::PFOContainer datahandle"
96  << m_pfoContainer_key.key());
97  return StatusCode::FAILURE;
98  }
99  auto cpfos = pfoContainer.cptr();
100 
101  for ( const xAOD::FlowElement* cpfo : *cpfos ) {
102  if ( cpfo == 0 ) {
103  ATH_MSG_WARNING("Have NULL pointer to charged PFO");
104  continue;
105  }
106  const xAOD::TrackParticle* ptrk = dynamic_cast<const xAOD::TrackParticle*>(cpfo->chargedObject(0));
107  if ( ptrk == 0 ) {
108  ATH_MSG_WARNING("Skipping charged PFO with null track pointer.");
109  continue;
110  }
111 
112  // decorate the track properties
113  dec_z0(*cpfo) = ptrk->z0();
114  dec_vz(*cpfo) = ptrk->vz();
115  dec_d0(*cpfo) = ptrk->d0();
116  dec_theta(*cpfo) = ptrk->theta();
117 
118  //find the weights from the tool
119  float weight = 1.0;
120  const static SG::AuxElement::ConstAccessor<int> accIsInDE("IsInDenseEnvironment");
121  if(accIsInDE.isAvailable(*cpfo)){
122  ATH_CHECK( m_weightPFOTool->fillWeight( *cpfo, weight ) );
123  }
124 
125  // decorate the computed variables
126  dec_corrP4_pt(*cpfo) = weight*cpfo->pt();
127  dec_envWeight(*cpfo) = weight;
128  }
129 
130  return StatusCode::SUCCESS;
131  }
132 }
DerivationFramework::PFlowAugmentationTool::m_z0Key
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_z0Key
Definition: PFlowAugmentationTool.h:45
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
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:27
DerivationFramework::PFlowAugmentationTool::finalize
StatusCode finalize()
Definition: PFlowAugmentationTool.cxx:42
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:570
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:189
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
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
WriteDecorHandle.h
Handle class for adding a decoration to an object.
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
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:81
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:43
AthAlgTool
Definition: AthAlgTool.h:26
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
DerivationFramework::PFlowAugmentationTool::addBranches
virtual StatusCode addBranches() const
Pass the thinning service
Definition: PFlowAugmentationTool.cxx:47