ATLAS Offline Software
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 
12 {
13 }
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 }
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
HIJetDRAssociationTool::m_assocName
Gaudi::Property< std::string > m_assocName
Name of jet attribute providing link between jets and IParticles.
Definition: HIJetDRAssociationTool.h:55
HIJetDRAssociationTool::modify
virtual StatusCode modify(xAOD::JetContainer &jets) const override
Implementing abstract methods from base.
Definition: HIJetDRAssociationTool.cxx:26
HIJetDRAssociationTool::m_DR
Gaudi::Property< float > m_DR
DR cut defining association.
Definition: HIJetDRAssociationTool.h:58
xAOD::etaMax
etaMax
Definition: HIEventShape_v2.cxx:46
xAOD::Jet_v1::phi
virtual double phi() const
The azimuthal angle ( ) of the particle.
Definition: Jet_v1.cxx:54
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
python.AtlRunQueryParser.ap
ap
Definition: AtlRunQueryParser.py:826
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
ParticleVector
std::vector< const IParticle * > ParticleVector
Definition: JetConstituentFiller.cxx:21
HIJetDRAssociationTool::HIJetDRAssociationTool
HIJetDRAssociationTool(const std::string &t)
Definition: HIJetDRAssociationTool.cxx:10
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
detail::ul
unsigned long ul
Definition: PrimitiveHelpers.h:45
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
HIJetDRAssociationTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: HIJetDRAssociationTool.cxx:17
xAOD::Jet_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition: Jet_v1.cxx:49
xAOD::Jet_v1::setAssociatedObjects
void setAssociatedObjects(const std::string &name, const std::vector< const T * > &vec)
set associated objects from a vector of arbitrary object.
eflowRec::phiIndex
unsigned int phiIndex(float phi, float binsize)
calculate phi index for a given phi
Definition: EtaPhiLUT.cxx:23
HIJetDRAssociationTool.h
HIJetDRAssociationTool::m_containerKey
SG::ReadHandleKey< xAOD::IParticleContainer > m_containerKey
name of IParticleContainer w/ particles to associate
Definition: HIJetDRAssociationTool.h:52
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
LArCellBinning.etaMin
etaMin
Definition: LArCellBinning.py:84
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
JetModifierBase
Definition: JetModifierBase.h:22