ATLAS Offline Software
ElectronJetDRAssociator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
18 #include "StoreGate/StoreGateSvc.h"
21 #include "xAODTracking/Vertex.h"
24 #include <cmath>
25 
26 
27 namespace D3PD {
28 
29 
37  const std::string& name,
38  const IInterface* parent)
39  : Base (type, name, parent),
40  m_target(0),
41  m_eg(0)
42 {
43  declareProperty ("Target", m_targetLabel,
44  "Target label for the getter for the jets to which"
45  " to associate.");
46 
47  declareProperty ("VertexContainerName",
48  m_vertexContainerName = "VxPrimaryCandidate",
49  "Primary vertex container name");
50 
51  declareProperty ("DRCut", m_drcut = 0.7,
52  "DR cut between electrons and jets");
53 
54  declareProperty ("CollectionGetterRegistry", m_registry,
55  "The ICollectionGetterRegistryTool instance.");
56 
57  book().ignore(); // Avoid coverity warnings.
58 }
59 
60 
65 {
66  CHECK( m_trackToVertexIPEstimator.retrieve() );
68  return StatusCode::SUCCESS;
69 }
70 
71 
82  const std::type_info& ti)
83 {
84  CHECK( m_registry.retrieve() );
85  CHECK( m_registry->get (m_targetLabel, this, m_target) );
87  return StatusCode::SUCCESS;
88 }
89 
90 
96 {
97  m_eg = &eg;
98  if (m_target)
99  CHECK( m_target->reset (true) );
100  return StatusCode::SUCCESS;
101 }
102 
103 
110 {
111  if (!m_target) return 0;
112 
113  const xAOD::CaloCluster * clus= m_eg->caloCluster();
114  if (!clus){
115  ATH_MSG_WARNING("No cluster from the electron found!");
116  return 0;
117  }
118 
119  while (const xAOD::Jet* myjet = m_target->next<xAOD::Jet>()) {
120 
121  float dr = hypot (clus->p4().DeltaPhi(myjet->p4()),
122  myjet->eta() - clus->etaBE(2));
123  ATH_MSG_DEBUG("The value of DR between Electron and Jet is dr= "<<dr);
124  if (dr < m_drcut) {
125  float signedIP=-9999.9;
126  float PTRel=-9999.9;
127  float reducedPt=-9999.9;
128  ATH_MSG_DEBUG("CATA egamma pt clus " << clus->et() );
130  signedIP, PTRel ).isFailure() )
131  {
132  continue;
133  }
134  if ( findReducedPt ( m_eg, myjet, reducedPt ).isFailure() )
135  {
136  continue;
137  }
138 
139  *m_signedIP = signedIP;
140  *m_ptrel = PTRel;
141  *m_dr = dr;
142  *m_jetSize = myjet->numConstituents();
143  *m_reducedPt = reducedPt;
144 
145  return myjet;
146  }
147  }
148 
149  return 0;
150 }
151 
152 
159 {
160  CHECK( addVariable( "dr" , m_dr,
161  "DR between electron and associated jet.") );
162  CHECK( addVariable( "signedIP" , m_signedIP,
163  "Signed impact parameter between electron and jet.") );
164  CHECK( addVariable( "ptrel", m_ptrel,
165  "Relative Pt between electron and jet.") );
166  CHECK( addVariable( "jetSize", m_jetSize,
167  "Number of jet constituents.") );
168  CHECK( addVariable( "reducedPt", m_reducedPt,
169  "Jet Pt with electron removed.") );
170  CHECK( Base::book() );
171  return StatusCode::SUCCESS;
172 }
173 
182  const xAOD::Jet* j,
183  float& reducedPt )
184 {
185  reducedPt=-9999.;
186 
187  if ( !eg || !j )
188  return StatusCode::SUCCESS;
189 
190  const xAOD::TrackParticle* track = eg->trackParticle();
191  if (!track) {
192  // Could legitimately be 0 for forward electrons...
193  return StatusCode::SUCCESS;
194  }
195 
196  float px = j->px() - track->p4().Px();
197  float py = j->py() - track->p4().Py();
198  reducedPt = hypot (px, py);
199 
200  return StatusCode::SUCCESS;
201 }
202 
203 
212  const xAOD::Jet* j0,
213  float& signedIP,
214  float& PTRel )
215 {
216  signedIP=-9999;
217  PTRel =-9999;
218 
219  if( j0==0 )
220  return StatusCode::SUCCESS;
221 
222  const xAOD::TrackParticle* track = eg->trackParticle();
223  if (!track) {
224  // Could legitimately be 0 for forward electrons...
225  return StatusCode::SUCCESS;
226  }
227 
228  PTRel= track->p4().Perp (j0->p4().Vect());
229 
230  CLHEP::Hep3Vector jetDirection( (j0)->px(), (j0)->py(), (j0)->pz());
231  CLHEP::Hep3Vector unit = jetDirection.unit();
232 
233  if (!evtStore()->contains<xAOD::VertexContainer>(m_vertexContainerName))
234  return StatusCode::SUCCESS;
235 
236  const xAOD::Vertex* vx = 0;
237  {
238  const xAOD::VertexContainer * vxcontainer = nullptr;
239  if ( evtStore()->retrieve(vxcontainer, m_vertexContainerName).isFailure() )
240  REPORT_MESSAGE (MSG::WARNING)
241  << "Vertex container " << m_vertexContainerName
242  << " not found in StoreGate!";
243  else if (!vxcontainer->empty())
244  vx = vxcontainer->front();
245  }
246 
247  if (!vx) {
248  REPORT_MESSAGE (MSG::WARNING)
249  << "No vertex found.";
250  return StatusCode::SUCCESS;
251  }
252 
253  signedIP = m_trackToVertexIPEstimator->get2DLifetimeSignOfTrack
254  (track->perigeeParameters(), unit, *vx);
255 
256  return StatusCode::SUCCESS;
257 }
258 
259 
260 } // namespace D3PD
261 
262 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
D3PD::IAddVariable
Common interface for adding a variable to a tuple.
Definition: IAddVariable.h:70
ICollectionGetterRegistryTool.h
Abstract interface to keep a registry of collection getter tools.
test_pyathena.px
px
Definition: test_pyathena.py:18
D3PD::ElectronJetDRAssociator::initialize
virtual StatusCode initialize() override
Standard Gaudi initialize method.
Definition: ElectronJetDRAssociator.cxx:64
D3PD::ElectronJetDRAssociator::m_reducedPt
float * m_reducedPt
Variable: Jet pT with electron removed.
Definition: ElectronJetDRAssociator.h:158
ParticleTest.eg
eg
Definition: ParticleTest.py:29
D3PD::ElectronJetDRAssociator::m_trackToVertexIPEstimator
ToolHandle< Trk::ITrackToVertexIPEstimator > m_trackToVertexIPEstimator
Property: Tool for the estimation of the IPs to the vertex.
Definition: ElectronJetDRAssociator.h:133
D3PD::ElectronJetDRAssociator::m_ptrel
float * m_ptrel
Variable: Relative Pt between electron and jet.
Definition: ElectronJetDRAssociator.h:152
D3PD::MultiAssociationToolImpl::book
virtual StatusCode book()
Create any needed tuple variables.
Definition: MultiAssociationToolImpl.cxx:92
D3PD::ElectronJetDRAssociator::m_signedIP
float * m_signedIP
Variable: Signed impact parameter between electron and jet.
Definition: ElectronJetDRAssociator.h:149
initialize
void initialize()
Definition: run_EoverP.cxx:894
D3PD::ElectronJetDRAssociator::m_targetLabel
std::string m_targetLabel
Property: Target label for the getter for the jets to which to associate.
Definition: ElectronJetDRAssociator.h:123
tree
TChain * tree
Definition: tile_monitor.h:30
xAOD::CaloCluster_v1::et
double et() const
Definition: CaloCluster_v1.h:856
D3PD::ElectronJetDRAssociator::ElectronJetDRAssociator
ElectronJetDRAssociator(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Definition: ElectronJetDRAssociator.cxx:36
ICollectionGetterTool.h
Abstract interface to get a collection of objects and iterate over it.
D3PD::MultiAssociationTool< xAOD::Electron, xAOD::Jet >
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::ElectronJetDRAssociator::m_registry
ToolHandle< ICollectionGetterRegistryTool > m_registry
Property: The ICollectionGetterRegistryTool instance.
Definition: ElectronJetDRAssociator.h:136
D3PD::ElectronJetDRAssociator::findReducedPt
StatusCode findReducedPt(const xAOD::Electron *eg, const xAOD::Jet *j, float &reducedPt)
Find the pT of the jet with electron removed.
Definition: ElectronJetDRAssociator.cxx:181
D3PD::MultiAssociationToolImpl::configureD3PD
virtual StatusCode configureD3PD(IAddVariable *tree, const std::type_info &ti)
Configure during initialization: type-check.
Definition: MultiAssociationToolImpl.cxx:51
D3PD::ElectronJetDRAssociator::m_jetSize
unsigned int * m_jetSize
Variable: Number of jet constituents.
Definition: ElectronJetDRAssociator.h:155
D3PD::ElectronJetDRAssociator::configureD3PD
virtual StatusCode configureD3PD(IAddVariable *tree, const std::type_info &ti) override
Configure during initialization: type-check.
Definition: ElectronJetDRAssociator.cxx:81
D3PD::ElectronJetDRAssociator::next
virtual const xAOD::Jet * next() override
Return a pointer to the next element in the association.
Definition: ElectronJetDRAssociator.cxx:109
D3PD::ElectronJetDRAssociator::m_eg
const xAOD::Electron * m_eg
Definition: ElectronJetDRAssociator.h:143
xAOD::CaloCluster_v1::etaBE
float etaBE(const unsigned layer) const
Get the eta in one layer of the EM Calo.
Definition: CaloCluster_v1.cxx:644
D3PD::ICollectionGetterTool::next
const T * next()
Type-safe wrapper for next.
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
D3PD
Block filler tool for noisy FEB information.
Definition: InnerDetector/InDetMonitoring/InDetGlobalMonitoring/macros/EnhancedPrimaryVertexMonitoring/TrigD3PD/ChainGroup.h:21
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
D3PD::ElectronJetDRAssociator::m_drcut
double m_drcut
Property: DR cut between electrons and jets.
Definition: ElectronJetDRAssociator.h:129
D3PD::ElectronJetDRAssociator::book
virtual StatusCode book() final
Create any needed tuple variables.
Definition: ElectronJetDRAssociator.cxx:158
xAOD::Egamma_v1::caloCluster
const xAOD::CaloCluster * caloCluster(size_t index=0) const
Pointer to the xAOD::CaloCluster/s that define the electron candidate.
Definition: Egamma_v1.cxx:388
DataVector::front
const T * front() const
Access the first element in the collection as an rvalue.
Amg::pz
@ pz
Definition: GeoPrimitives.h:40
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
xAOD::Jet_v1::py
float py() const
The y-component of the jet's momentum.
Definition: Jet_v1.cxx:94
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Vertex.h
xAOD::CaloCluster_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: CaloCluster_v1.cxx:465
D3PD::ElectronJetDRAssociator::m_vertexContainerName
std::string m_vertexContainerName
Property: Vertex container name.
Definition: ElectronJetDRAssociator.h:126
Amg::py
@ py
Definition: GeoPrimitives.h:39
D3PD::ElectronJetDRAssociator::m_target
ICollectionGetterTool * m_target
Getter defining the collection within which to index.
Definition: ElectronJetDRAssociator.h:140
D3PD::ElectronJetDRAssociator::reset
virtual StatusCode reset(const xAOD::Electron &eg) override
Start the iteration for a new association.
Definition: ElectronJetDRAssociator.cxx:95
D3PD::ICollectionGetterTool::reset
virtual StatusCode reset(bool allowMissing=false)=0
Reset the iteration to the start of the collection.
xAOD::Jet_v1::px
float px() const
The x-component of the jet's momentum.
Definition: Jet_v1.cxx:90
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
ElectronJetDRAssociator.h
xAOD::Electron_v1
Definition: Electron_v1.h:34
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
TrackParticle.h
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
xAOD::Jet_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: Jet_v1.cxx:71
VertexContainer.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
unit
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
Definition: AmgMatrixBasePlugin.h:20
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
ITrackToVertexIPEstimator.h
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
D3PD::ElectronJetDRAssociator::findSignedIPAndPTRelEleJetPair
StatusCode findSignedIPAndPTRelEleJetPair(const xAOD::Electron *eg, const xAOD::Jet *j0, float &signedIP, float &PTRel)
Find the signed impact parameter and PTRel of EG's track relative to the beamspot.
Definition: ElectronJetDRAssociator.cxx:211
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
D3PD::ElectronJetDRAssociator::m_dr
float * m_dr
Variable: DR between electron and jet.
Definition: ElectronJetDRAssociator.h:146
StoreGateSvc.h
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.