ATLAS Offline Software
TiledEtaPhiMap.icc
Go to the documentation of this file.
1 // emacs, this is -*- C++ -*-
2 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 
8 namespace JetTiledMap {
9 
10 
11 
12  template<class POINT, class DIST2>
13  void Tile<POINT,DIST2>::fillPointsInDr2(POINT &p, double r2, pointvec_t& points ) const {
14  //double r2= r*r;
15  if(this->empty()) return;
16  const_iterator it = this->begin();
17  const_iterator itE = this->end();
18  //std::cout <<"fillPointsInDr2 around "<< center << std::endl;
19  for(;it !=itE; ++it){
20  //std::cout << " ->> "<< dr2( p, *it) << " for "<< *it<<std::endl;
21  if( dr2( p, *it) < r2) points.push_back(*it);
22  }
23  }
24 
25  template<class POINT, class DIST2>
26  const DIST2 Tile<POINT, DIST2>::dr2;
27  template<class POINT, class DIST2>
28  const Tile<POINT, DIST2> Tile<POINT, DIST2>::voidTile =
29  Tile<POINT, DIST2>(POINT(100, 2*M_PI*10)); // unphysical dummy coordinates
30 
31 
32  template<class POINT, class DIST2 >
33  void TiledEtaPhiMap<POINT,DIST2>::init(double rmax){
34 
35  m_rmax = rmax;
36 
37  m_ndivX = int(m_etarange/rmax);
38  m_sizeX = m_etarange/m_ndivX;
39 
40  const double twopi = 2.0*acos(-1.0);
41  m_ndivY = int(twopi/rmax);
42  m_sizeY = twopi/m_ndivY;
43 
44  m_tiles.resize(m_ndivY*m_ndivX);
45 
46  for(size_t i=0;i<m_ndivX; i++){
47  for(size_t j=0;j<m_ndivY; j++){
48  tile_t & thisTile = m_tiles[ tileIndex_i(i,j) ];
49  thisTile.center = POINT( (i+0.5)*m_sizeX -m_halfetarange , M_PI - (j+0.5)*m_sizeY );
50  size_t jnorth = j-1;
51  if(j==0) jnorth=m_ndivY-1;
52  size_t jsouth = j+1;
53  if(jsouth==m_ndivY) jsouth=0;
54 
55 
56 
57  if(i>0){
58  thisTile.m_neighbour[NW] = &m_tiles[tileIndex_i(i-1, jnorth)] ;
59  thisTile.m_neighbour[W] = &m_tiles[tileIndex_i(i-1, j)] ;
60  thisTile.m_neighbour[SW] = &m_tiles[tileIndex_i(i-1, jsouth)] ;
61  } else { // west side
62  thisTile.m_neighbour[NW] = &tile_t::voidTile;
63  thisTile.m_neighbour[W] = &tile_t::voidTile;
64  thisTile.m_neighbour[SW] = &tile_t::voidTile;
65  }
66 
67  thisTile.m_neighbour[N] = &m_tiles[tileIndex_i(i, jnorth)] ;
68  thisTile.m_neighbour[S] = &m_tiles[tileIndex_i(i, jsouth)] ;
69 
70  //std::cout<<" south = "<< thisTile.m_neighbour[S]<< " ind="<< tileIndex_i(i, jsouth) << std::endl;
71 
72  if(i< (m_ndivX-1) ){
73  thisTile.m_neighbour[NE] = &m_tiles[tileIndex_i(i+1, jnorth)] ;
74  thisTile.m_neighbour[E] = &m_tiles[tileIndex_i(i+1, j)] ;
75  thisTile.m_neighbour[SE] = &m_tiles[tileIndex_i(i+1, jsouth)] ;
76  }else{ //east side
77  thisTile.m_neighbour[NE] = &tile_t::voidTile;
78  thisTile.m_neighbour[E] = &tile_t::voidTile;
79  thisTile.m_neighbour[SE] = &tile_t::voidTile;
80  }
81 
82  }
83  }
84 
85  }
86 
87  template<class POINT, class DIST2 >
88  void TiledEtaPhiMap<POINT,DIST2>::insert(POINT & p) {
89  m_size++;
90  size_t ind = tileIndex(p);
91  m_tiles[ind].push_back(p);
92  }
93 
94 
95  template<class POINT, class DIST2 >
96  std::vector<POINT> TiledEtaPhiMap<POINT,DIST2>::pointsInDr(POINT &p, double r) const {
97 
98  std::vector<POINT> vec;
99 
100  double r2=r*r;
101 
102  //std::cout << "pointsinDR "<< p.x()<< ", "<< p.y() << " " << tileIndex(p)<< " "<< m_tiles.size() << std::endl;
103  // p is part of thisTile
104  const tile_t & thisTile = m_tiles[tileIndex(p)];
105  const POINT& center = thisTile.center;
106 
107 
108  // compute distance to edges of thisTile
109  double d_to_N2 = jet::JetDistances::deltaPhi(p.y(), (center.y() + m_sizeY/2) ); d_to_N2*=d_to_N2;
110  double d_to_E2 = ( p.x() - (center.x() + m_sizeX/2) ) ; d_to_E2*=d_to_E2;
111  double d_to_S2 = jet::JetDistances::deltaPhi(p.y(), (center.y() - m_sizeY/2) ); d_to_S2*=d_to_S2;
112  double d_to_W2 = ( p.x() - (center.x() - m_sizeX/2) ) ; d_to_W2*=d_to_W2;
113 
114  // get points in this tile :
115  thisTile.fillPointsInDr2(p,r2,vec);
116 
117  //std::cout << "pointsinDR "<< p << " " << tileIndex(p)<< " "<< &thisTile <<" center="<<thisTile.center << std::endl;
118 
119  // check if close to neighbouring tiles. if so consider points in these tiles :
120  if(d_to_N2 < r2) thisTile.m_neighbour[N]->fillPointsInDr2(p,r2,vec);
121  if(d_to_E2 < r2) thisTile.m_neighbour[E]->fillPointsInDr2(p,r2,vec);
122  if(d_to_S2 < r2) thisTile.m_neighbour[S]->fillPointsInDr2(p,r2,vec);
123  if(d_to_W2 < r2) thisTile.m_neighbour[W]->fillPointsInDr2(p,r2,vec);
124 
125  if( (d_to_N2+ d_to_E2) < r2 ) thisTile.m_neighbour[NE]->fillPointsInDr2(p,r2,vec);
126  if( (d_to_S2+ d_to_E2) < r2 ) thisTile.m_neighbour[SE]->fillPointsInDr2(p,r2,vec);
127 
128  if((d_to_N2+ d_to_W2) < r2 ) thisTile.m_neighbour[NW]->fillPointsInDr2(p,r2,vec);
129  if((d_to_S2+ d_to_W2) < r2 ) thisTile.m_neighbour[SW]->fillPointsInDr2(p,r2,vec);
130 
131  return vec;
132 
133  }
134 
135 
136  template<class POINT, class DIST2 >
137  void TiledEtaPhiMap<POINT,DIST2>::clear(){
138  for(size_t i=0; i<m_tiles.size();i++){
139  m_tiles[i].clear();
140  }
141  m_size=0;
142  }
143 
144 }