ATLAS Offline Software
Loading...
Searching...
No Matches
DRAssociationTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
10
11// STL include(s):
12#include <cmath>
13
14#include "DRAssociationTool.h"
18#include "GaudiKernel/SystemOfUnits.h"
19
20
21using Gaudi::Units::MeV;
22
23
24namespace 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 =
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
135const 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
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE(LVL)
Report a message.
#define CHECK(...)
Evaluate an expression and check for errors.
Associate to particle closest in DR.
virtual StatusCode addVariable(const std::string &name, const std::type_info &ti, void *&ptr, const std::string &docstring="", const void *defval=0)
SingleAssociationTool< Types< INavigable4Momentum, xAOD::IParticle > > Base
virtual const INavigable4Momentum * get(const INavigable4Momentum &p) override
Return the target object.
virtual StatusCode book() override
Create any needed tuple variables.
DRAssociationTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
virtual StatusCode initialize() override
Standard Gaudi initialize method.
virtual StatusCode configureD3PD(IAddVariable *tree, const std::type_info &ti) override
Configure during initialization: type-check.
float * m_dr
Variable: DR to associated object.
ToolHandle< ICollectionGetterTool > m_getter
Property: The getter for the target collection.
float m_drcut
Property: DR cut.
Common interface for adding a variable to a tuple.
virtual StatusCode configureD3PD(D3PD::IAddVariable *tree, const std::type_info &ti)
Class providing the definition of the 4-vector interface.
Block filler tool for noisy FEB information.
double deltaR(const I4Momentum &p4, double eta, double phi)
from 1 I4Momentum
Definition P4Helpers.h:209
TChain * tree