ATLAS Offline Software
DRAssociationTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
11 // STL include(s):
12 #include <cmath>
13 
14 #include "DRAssociationTool.h"
15 #include "FourMomUtils/P4Helpers.h"
18 #include "GaudiKernel/SystemOfUnits.h"
19 
20 
21 using Gaudi::Units::MeV;
22 
23 
24 namespace D3PD {
25 
26 
34  const std::string& name,
35  const IInterface* parent)
36  : Base (type, name, parent),
37  m_getter (this)
38 {
39  declareProperty ("Getter", m_getter,
40  "ICollectionGetterTool instance defining "
41  "the target collection");
42  declareProperty ("DRCut", m_drcut = 999,
43  "DR cut for the association");
44 
45  DRAssociationTool::book().ignore(); // Avoid coverity warnings.
46 }
47 
48 
53 {
54  // Retrieve the getter tool and configure it, saying that we want
55  // to get @c INavigable4Momentum objects from it.
56  CHECK( m_getter.retrieve() );
57  //CHECK( m_getter->configureD3PD<INavigable4Momentum>() );
58  //CHECK( m_getter->configureElementTypeinfo
59  return Base::initialize();
60 }
61 
62 
72  const std::type_info& ti)
73 {
75  CHECK( m_getter->configureElementTypeinfo (this->typeinfo()));
76  return StatusCode::SUCCESS;
77 }
78 
79 
84 {
85  CHECK( addVariable ("dr", m_dr) );
86  return StatusCode::SUCCESS;
87 }
88 
89 
98 {
99  // Protect against null 4-momenta --- they'll crash deltaR.
100  if (p.p() < 1e-3*MeV) return 0;
101  // Protect against infinite eta. It appears in some circumstances.
102  if( std::isinf(p.eta()) ) return 0;
103 
104  *m_dr = -1;
105 
106  if (m_getter->reset().isFailure()) {
107  REPORT_MESSAGE (MSG::ERROR) << "Can't reset input getter.";
108  return 0;
109  }
110 
111  const INavigable4Momentum* pout = 0;
112  float min_dr = m_drcut;
113  while ( const INavigable4Momentum* obj =
114  m_getter->next<INavigable4Momentum>())
115  {
116  if (obj->pt() < 1e-2*MeV) continue;
117  if( std::isinf( obj->eta() ) ) continue;
118  float dr = static_cast<float> (P4Helpers::deltaR (p, *obj));
119  if (dr < min_dr) {
120  *m_dr = dr;
121  min_dr = dr;
122  pout = obj;
123  }
124  }
125  return pout;
126 }
127 
128 
135 const xAOD::IParticle*
137 {
138  // Protect against null 4-momenta --- they'll crash deltaR.
139  if (p.e() < 1e-3*MeV) return 0;
140  // Protect against infinite eta. It appears in some circumstances.
141  if( std::isinf(p.eta()) ) return 0;
142 
143  *m_dr = -1;
144 
145  if (m_getter->reset().isFailure()) {
146  REPORT_MESSAGE (MSG::ERROR) << "Can't reset input getter.";
147  return 0;
148  }
149 
150  const xAOD::IParticle* pout = 0;
151  float min_dr = m_drcut;
152  while ( const xAOD::IParticle* obj =
153  m_getter->next<xAOD::IParticle>())
154  {
155  if (obj->pt() < 1e-2*MeV) continue;
156  if( std::isinf( obj->eta() ) ) continue;
157  float dr = p.p4().DeltaR (obj->p4());
158  if (dr < min_dr) {
159  *m_dr = dr;
160  min_dr = dr;
161  pout = obj;
162  }
163  }
164  return pout;
165 }
166 
167 
168 } // namespace D3PD
D3PD::DRAssociationTool::configureD3PD
virtual StatusCode configureD3PD(IAddVariable *tree, const std::type_info &ti) override
Configure during initialization: type-check.
Definition: DRAssociationTool.cxx:71
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
D3PD::IAddVariable
Common interface for adding a variable to a tuple.
Definition: IAddVariable.h:70
calibdata.pout
def pout(output, newline=True)
Definition: calibdata.py:130
INavigable4Momentum.h
D3PD::DRAssociationTool::m_getter
ToolHandle< ICollectionGetterTool > m_getter
Property: The getter for the target collection.
Definition: DRAssociationTool.h:106
D3PD::DRAssociationTool::m_dr
float * m_dr
Variable: DR to associated object.
Definition: DRAssociationTool.h:112
initialize
void initialize()
Definition: run_EoverP.cxx:894
tree
TChain * tree
Definition: tile_monitor.h:30
python.SystemOfUnits.MeV
int MeV
Definition: SystemOfUnits.py:154
D3PD::SingleAssociationTool< Types< INavigable4Momentum, xAOD::IParticle > >
D3PD::AddVariable::addVariable
virtual StatusCode addVariable(const std::string &name, const std::type_info &ti, void *&ptr, const std::string &docstring="", const void *defval=0)
Add a variable to the tuple.
Definition: AddVariable.cxx:85
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
D3PD::SingleAssociationToolImpl::configureD3PD
virtual StatusCode configureD3PD(D3PD::IAddVariable *tree, const std::type_info &ti)
Configure during initialization: type-check.
Definition: SingleAssociationToolImpl.cxx:51
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
D3PD
Block filler tool for noisy FEB information.
Definition: CaloCellDetailsFillerTool.cxx:29
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
PyAlgorithmExample.min_dr
def min_dr(p, l)
Definition: PyAlgorithmExample.py:57
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
P4Helpers::deltaR
double deltaR(const I4Momentum &p4, double eta, double phi)
from 1 I4Momentum
Definition: P4Helpers.h:209
D3PD::DRAssociationTool::get
virtual const INavigable4Momentum * get(const INavigable4Momentum &p) override
Return the target object.
Definition: DRAssociationTool.cxx:97
P4Helpers.h
D3PD::DRAssociationTool::initialize
virtual StatusCode initialize() override
Standard Gaudi initialize method.
Definition: DRAssociationTool.cxx:52
D3PD::DRAssociationTool::m_drcut
float m_drcut
Property: DR cut.
Definition: DRAssociationTool.h:109
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
errorcheck.h
Helpers for checking error return status codes and reporting errors.
DRAssociationTool.h
Associate to particle closest in DR.
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
INavigable4Momentum
Definition: INavigable4Momentum.h:21
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
D3PD::DRAssociationTool::book
virtual StatusCode book() override
Create any needed tuple variables.
Definition: DRAssociationTool.cxx:83
python.PyAthena.obj
obj
Definition: PyAthena.py:132
D3PD::DRAssociationTool::DRAssociationTool
DRAssociationTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Definition: DRAssociationTool.cxx:33