1 // emacs, this is -*- C++ -*-
4 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
8 namespace JetTiledMap {
12 template<class POINT, class DIST2>
13 void Tile<POINT,DIST2>::fillPointsInDr2(POINT &p, double r2, pointvec_t& points ) const {
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;
20 //std::cout << " ->> "<< dr2( p, *it) << " for "<< *it<<std::endl;
21 if( dr2( p, *it) < r2) points.push_back(*it);
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
32 template<class POINT, class DIST2 >
33 void TiledEtaPhiMap<POINT,DIST2>::init(double rmax){
37 m_ndivX = int(m_etarange/rmax);
38 m_sizeX = m_etarange/m_ndivX;
40 const double twopi = 2.0*acos(-1.0);
41 m_ndivY = int(twopi/rmax);
42 m_sizeY = twopi/m_ndivY;
44 m_tiles.resize(m_ndivY*m_ndivX);
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 );
51 if(j==0) jnorth=m_ndivY-1;
53 if(jsouth==m_ndivY) jsouth=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)] ;
62 thisTile.m_neighbour[NW] = &tile_t::voidTile;
63 thisTile.m_neighbour[W] = &tile_t::voidTile;
64 thisTile.m_neighbour[SW] = &tile_t::voidTile;
67 thisTile.m_neighbour[N] = &m_tiles[tileIndex_i(i, jnorth)] ;
68 thisTile.m_neighbour[S] = &m_tiles[tileIndex_i(i, jsouth)] ;
70 //std::cout<<" south = "<< thisTile.m_neighbour[S]<< " ind="<< tileIndex_i(i, jsouth) << std::endl;
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)] ;
77 thisTile.m_neighbour[NE] = &tile_t::voidTile;
78 thisTile.m_neighbour[E] = &tile_t::voidTile;
79 thisTile.m_neighbour[SE] = &tile_t::voidTile;
87 template<class POINT, class DIST2 >
88 void TiledEtaPhiMap<POINT,DIST2>::insert(POINT & p) {
90 size_t ind = tileIndex(p);
91 m_tiles[ind].push_back(p);
95 template<class POINT, class DIST2 >
96 std::vector<POINT> TiledEtaPhiMap<POINT,DIST2>::pointsInDr(POINT &p, double r) const {
98 std::vector<POINT> vec;
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;
108 // compute distance to edges of thisTile
109 double d_to_N2 = xAOD::P4Helpers::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 = xAOD::P4Helpers::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;
114 // get points in this tile :
115 thisTile.fillPointsInDr2(p,r2,vec);
117 //std::cout << "pointsinDR "<< p << " " << tileIndex(p)<< " "<< &thisTile <<" center="<<thisTile.center << std::endl;
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);
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);
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);
136 template<class POINT, class DIST2 >
137 void TiledEtaPhiMap<POINT,DIST2>::clear(){
138 for(size_t i=0; i<m_tiles.size();i++){