ATLAS Offline Software
Loading...
Searching...
No Matches
HIJetDRAssociationTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <iomanip>
7
8//**********************************************************************
9
14
15//**********************************************************************
16
18{
19 ATH_MSG_VERBOSE("HIJetDRAssociationTool initialize");
20 ATH_CHECK( m_containerKey.initialize( !m_containerKey.key().empty() ) );
21 return StatusCode::SUCCESS;
22}
23
24
25
27{
28
29 const xAOD::IParticleContainer* ppars=0;
30
31 ATH_MSG_DEBUG("Retrieving xAOD container " << m_containerKey.key() );
33 ppars = readHandlePcontainer.get();
34
35 using Grid=std::vector<std::vector<std::vector<const xAOD::IParticle*>>>;
36 const double etaMin = -5;
37 const double etaMax = 5;
38 const double phiMin = -3.1416;
39 const double phiMax = 3.1416;
40
41 // build square grid
42 Grid grid;
43 grid.resize(1+ (etaMax-etaMin)/m_DR);
44 for ( auto& phiVec: grid) {
45 phiVec.resize(1+ (phiMax-phiMin)/m_DR);
46 }
47
48 auto etaToIndex = [etaMin, this](double eta) -> size_t { return (eta-etaMin)/m_DR; };
49 auto phiToIndex = [phiMin, this](double phi) -> size_t { return (phi-phiMin)/m_DR; };
50
51 auto neighborsInEta = [&grid, etaToIndex](double eta) -> std::vector<size_t> {
52 const size_t etaIndex = etaToIndex(eta);
53 if ( etaIndex == 0){
54 return {etaIndex, etaIndex+1};
55 }
56 if ( etaIndex == grid.size()-1){
57 return {etaIndex-1, etaIndex};
58 }
59 return {etaIndex-1, etaIndex, etaIndex+1};
60 };
61
62 auto neighborsInPhi = [&grid, phiToIndex](double phi) -> std::vector<size_t> {
63 const size_t phiIndex = phiToIndex(phi);
64 if ( phiIndex == 0){
65 return {grid[0].size()-1, phiIndex, phiIndex+1};
66 }
67 if ( phiIndex == grid[0].size()-1){
68 return {phiIndex-1, phiIndex, 0ul}; // wrapping condition
69 }
70 return {phiIndex-1, phiIndex, phiIndex+1};
71 };
72
73 for(const auto* ap : *ppars) {
74 grid[etaToIndex(ap->eta())][phiToIndex(ap->phi())].push_back(ap);
75 }
76
77 for (xAOD::JetContainer::iterator ijet=jets.begin(); ijet!=jets.end(); ++ijet)
78 {
79 std::vector<const xAOD::IParticle*> ParticleVector;
80 xAOD::Jet* theJet=(*ijet);
81 auto etaN = neighborsInEta(theJet->eta());
82 auto phiN = neighborsInPhi(theJet->phi());
83
84 for ( size_t etaI : etaN) {
85 for ( size_t phiI : phiN ) {
86 for ( auto ap: grid[etaI][phiI]) {
87 if(theJet->p4().DeltaR( ap->p4()) < m_DR) ParticleVector.push_back(ap);
88 }
89 }
90 }
92 }
93 return StatusCode::SUCCESS;
94}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
std::vector< const IParticle * > ParticleVector
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
Gaudi::Property< float > m_DR
DR cut defining association.
virtual StatusCode modify(xAOD::JetContainer &jets) const override
Implementing abstract methods from base.
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
SG::ReadHandleKey< xAOD::IParticleContainer > m_containerKey
name of IParticleContainer w/ particles to associate
Gaudi::Property< std::string > m_assocName
Name of jet attribute providing link between jets and IParticles.
HIJetDRAssociationTool(const std::string &t)
JetModifierBase(const std::string &myname)
Ctor.
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
virtual double phi() const
The azimuthal angle ( ) of the particle.
Definition Jet_v1.cxx:54
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition Jet_v1.cxx:71
void setAssociatedObjects(const std::string &name, const std::vector< const T * > &vec)
set associated objects from a vector of arbitrary object.
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition Jet_v1.cxx:49
Jet_v1 Jet
Definition of the current "jet version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.