ATLAS Offline Software
EtaPhiLUT.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <cmath>
6 #include <algorithm>
7 
8 #include "eflowRec/EtaPhiLUT.h"
9 
10 namespace eflowRec {
11 
13  static constexpr float TWOPI = 2*M_PI;
14 
16  float phiInRange(float phi) {
17  while (phi >= M_PI) phi -= TWOPI;
18  while (phi < -M_PI) phi += TWOPI;
19  return phi;
20  }
21 
23  unsigned int phiIndex(float phi, float binsize) { return (phi + M_PI)/binsize; }
24 
25  EtaPhiLUT::EtaPhiLUT( unsigned int nbins ) :
26  m_nphiBins(nbins),
27  m_phiBinSize(TWOPI/m_nphiBins),
28  m_phiBinnedLookUpTable(m_nphiBins)
29  {}
30 
32  {
33  for(eflowRecCluster* cluster : clustersin) {
34  int index = phiIndex(cluster->getCluster()->phi(), m_phiBinSize);
35  m_phiBinnedLookUpTable[index].push_back(cluster);
36  }
37 
38  for( auto& vec : m_phiBinnedLookUpTable ) {
39  std::stable_sort(vec.begin(),vec.end(),[](const eflowRecCluster* c1, const eflowRecCluster* c2) { return c1->getCluster()->eta() < c2->getCluster()->eta(); });
40  }
41  }
42 
43  std::vector<eflowRecCluster*> EtaPhiLUT::clustersInCone( float eta, float phi, float dr ) const {
44  std::vector<eflowRecCluster*> result;
45 
46  // Indices corresponding to phi range
47  unsigned int iPhiMin = phiIndex( phiInRange(phi-dr), m_phiBinSize );
48  unsigned int iPhiMax = phiIndex( phiInRange(phi+dr), m_phiBinSize );
49 
50  // Extract index ranges to iterate over
51  std::vector< std::pair<int,int> > iPhiRanges;
52  if( iPhiMin < iPhiMax ) {
53  iPhiRanges.emplace_back(iPhiMin,iPhiMax );
54  } else { // special treatment for phi-wrapping
55  iPhiRanges.emplace_back(0,iPhiMax );
56  iPhiRanges.emplace_back(iPhiMin,m_nphiBins-1 );
57  }
58 
59  float dr2Cut = dr*dr;
60 
61  // loop over ranges
62  for( auto& range : iPhiRanges ){
63  unsigned int indexMin = range.first;
64  unsigned int indexMax = range.second;
65  for( ; indexMin <= indexMax; ++indexMin ){
66  const std::vector<eflowRecCluster*>& phiClusters = m_phiBinnedLookUpTable[indexMin];
67 
68  // Get iterators for clusters in relevant eta range
69  auto it_min = std::lower_bound (phiClusters.begin(), phiClusters.end(), eta-dr, [] (const eflowRecCluster* cl, float etaval) {return cl->getCluster()->eta()<etaval;} );
70  auto it_max = std::upper_bound (it_min, phiClusters.end(), eta+dr, [] (float etaval, const eflowRecCluster* cl) {return etaval<cl->getCluster()->eta();} );
71 
72  // Apply deltaR cut
73  for( ;it_min!=it_max;++it_min ){
74  const xAOD::CaloCluster& xcluster = *(*it_min)->getCluster();
75  float deta = eta - xcluster.eta();
76  float dphi = phiInRange(phi - xcluster.phi());
77  float dr2 = deta*deta + dphi*dphi;
78  if( dr2 < dr2Cut ) result.push_back(*it_min);
79  }
80  }
81  }
82  return result;
83  }
84 
85 } // namespace
eflowRecCluster
This class extends the information about a xAOD::CaloCluster.
Definition: eflowRecCluster.h:40
xAOD::CaloCluster_v1::phi
virtual double phi() const
The azimuthal angle ( ) of the particle.
Definition: CaloCluster_v1.cxx:256
get_generator_info.result
result
Definition: get_generator_info.py:21
eflowRec::EtaPhiLUT::clustersInCone
std::vector< eflowRecCluster * > clustersInCone(float eta, float phi, float dr) const
collect eflowRecClusters in a given cone
Definition: EtaPhiLUT.cxx:43
eflowRec
Definition: EtaPhiLUT.h:23
index
Definition: index.py:1
eflowRecClusterContainer
Definition: eflowRecCluster.h:275
extractSporadic.c1
c1
Definition: extractSporadic.py:134
M_PI
#define M_PI
Definition: ActiveFraction.h:11
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
eflowRec::EtaPhiLUT::m_phiBinSize
float m_phiBinSize
number of bins
Definition: EtaPhiLUT.h:39
eflowRec::EtaPhiLUT::m_nphiBins
unsigned int m_nphiBins
Definition: EtaPhiLUT.h:38
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
xAOD::CaloCluster_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition: CaloCluster_v1.cxx:251
eflowRec::EtaPhiLUT::fill
void fill(eflowRecClusterContainer &clustersin)
Definition: EtaPhiLUT.cxx:31
eflowRec::phiInRange
float phiInRange(float phi)
hepler function to ensure phi is within +-Pi
Definition: EtaPhiLUT.cxx:16
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
EtaPhiLUT.h
eflowRec::phiIndex
unsigned int phiIndex(float phi, float binsize)
calculate phi index for a given phi
Definition: EtaPhiLUT.cxx:23
python.DataFormatRates.c2
c2
Definition: DataFormatRates.py:123
DeMoScan.index
string index
Definition: DeMoScan.py:364
eflowRec::EtaPhiLUT::m_phiBinnedLookUpTable
std::vector< std::vector< eflowRecCluster * > > m_phiBinnedLookUpTable
bin size
Definition: EtaPhiLUT.h:40
eflowRec::EtaPhiLUT::EtaPhiLUT
EtaPhiLUT(unsigned int nbins=50)
constructor taking the desired binsize
Definition: EtaPhiLUT.cxx:25
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
python.samplers.TWOPI
int TWOPI
Definition: samplers.py:8