ATLAS Offline Software
Classes | Typedefs | Functions
JetGeom Namespace Reference

A collection of routines for geometric tasks in 2D and on a cylinder. More...

Classes

class  line_t
 
class  point_set_t
 
class  point_t
 Very basic point objects. More...
 
class  point_vect_t
 

Typedefs

typedef std::list< point_tpoint_list_t
 

Functions

template<class inT , class ouT >
void findConvexHull (inT &inSet, ouT &outSet)
 Find convex hull of a set of points in euclidian plan. More...
 
template<class ouT >
void findConvexHull (point_set_t &inSet, ouT &outSet)
 specialization for point_set_t More...
 
template<class inT >
void _findConvexHull (point_set_t &inSet, inT &outSet)
 
void testHullLine (point_list_t &hull, point_t p)
 
template<class T >
float polygon_area (T &line)
 
template<class T >
float polygon_lenght (T &line)
 
template<class T >
float getMeanPhi (T &set)
 return average phi (i.e. More...
 
template<class T >
float max_deltaR (point_t p, T &set)
 Return max distance betweens point. More...
 
template<class T , class T2 >
void recenter_set (T &inSet, T2 &outSet, float phicenter)
 copy More...
 
template<class T , class T2 >
void recenter_set (T &inSet, T2 &outSet)
 copy More...
 
float in_mPI_pPI (float phi)
 convert More...
 
void fix2pi (point_t &p)
 convert More...
 
float deltaR (point_t &p1, point_t &p2)
 distances between points More...
 
float deltaR2 (point_t &p1, point_t &p2)
 
float deltaPhi (point_t &p1, point_t &p2)
 
float deltaPhi (float phi1, float phi2)
 
void listToSet (point_list_t &inList, point_set_t &outSet)
 
template<class T >
void clear_delete (T &container)
 
template<class T >
void delete_content (T &container)
 
float abs_dphi (float phi1, float phi2)
 
point_t recenter (const point_t &p, const point_t &center)
 
point_t recenter (const point_t &p, float phicenter)
 
template<class T >
void _findConvexHull (point_set_t &inSet, T &outSet)
 

Detailed Description

A collection of routines for geometric tasks in 2D and on a cylinder.

Including a convex hull finder.

Author
P.A. Delsart
Date
(first implementation) June , 2007

Typedef Documentation

◆ point_list_t

typedef std::list<point_t> JetGeom::point_list_t

Definition at line 32 of file cyl_geom.h.

Function Documentation

◆ _findConvexHull() [1/2]

template<class inT >
void JetGeom::_findConvexHull ( point_set_t inSet,
inT &  outSet 
)

◆ _findConvexHull() [2/2]

template<class T >
void JetGeom::_findConvexHull ( point_set_t inSet,
T &  outSet 
)

Definition at line 332 of file cyl_geom.h.

332  {
333 
334  if(inSet.size()<4){
335  outSet.insert(outSet.begin(), inSet.begin(), inSet.end() );
336  return;
337  }
338 
339  point_set_t::iterator s_it = inSet.begin();
340  point_t point00 = (*s_it);
341  point_t point01= point00;
342  while(point01.first == point00.first){
343  ++s_it;
344  point01 = *s_it;
345  }
346  --s_it; point01 = *s_it;
347 
348  s_it = inSet.end(); --s_it;
349  point_t point11 = (*s_it);
350  point_t point10= point11;
351  while(point10.first == point11.first){
352  --s_it;
353  point10 = *s_it;
354  }
355  ++s_it; point10 = *s_it;
356 
357  // lower line :
358  line_t lmin(point00, point10);
359  // lower line :
360  line_t lmax(point01, point11);
361 
362  // fill upper and lower list :
363  point_list_t lowPoints, upPoints;
364 
365  s_it = inSet.begin();
366  if(point00 == point01 ){ // make sure point is in both list
367  lowPoints.push_back(point00);
368  upPoints.push_back(point00);
369  ++s_it;
370  }
371  //std::cout << " lp size =" << lowPoints.size() << std::endl;
372  point_set_t::iterator s_itE = inSet.end();
373  --s_itE; // we'll deal ws_ith the end by hand
374  for(; s_it!= s_itE; ++s_it){
375  point_t p = *s_it;
376  //std::cout << " point "<< p.first << " , "<< p.second << std::endl;
377  if( lmin.is_below(p)) {
378  lowPoints.push_back(p);
379  continue;
380  }
381  if( lmax.is_above(p)) {
382  upPoints.push_front(p); // insert front soit is well sorted
383  }
384 
385  }
386  //std::cout << " lp size =" << lowPoints.size() << std::endl;
387  if(point11 == point10 ){ // make sure point is in both list
388  lowPoints.push_back(point11);
389  upPoints.push_front(point11);
390  ++s_it;
391  }else{
392  lowPoints.push_back(point10);
393  upPoints.push_front(point00);
394  }
395  //std::cout << " lp size =" << lowPoints.size() << std::endl;
396  //std::cout << lowPoints.size() << " " << upPoints.size() << std::endl;
397 
398  // find lower hull :
399  point_list_t lowHull;
400  point_list_t::iterator it = lowPoints.begin();
401  point_list_t::iterator itE = lowPoints.end();
402  lowHull.push_back(point00); // here point00 == (*it)
403  ++it;
404  lowHull.push_back(*it); // always put next point in stack
405  ++it;
406  unsigned int nn = lowPoints.size();
407  if(nn>2){
408  //std::cout << "building low hull : "<< lowPoints.size() <<std::endl;
409  while(it!=itE){
410  testHullLine(lowHull, *it);
411  ++it;
412  }
413  }
414  // find upper hull :
415  point_list_t upHull;
416  it = upPoints.begin();
417  itE = upPoints.end();
418  upHull.push_back(point11); // here point11 == (*it)
419  ++it;
420  upHull.push_back(*it); // always put next point in stack
421  ++it;
422  if(upPoints.size()>2){
423  //std::cout << "building up hull : "<< upPoints.size() <<std::endl;
424  while(it!=itE){
425  testHullLine(upHull, *it);
426  ++it;
427  }
428  }
429 // std::cout << " low size = "<< lowHull.size() << std::endl;
430 // std::cout << " up size = "<< upHull.size() << std::endl;
431  // join Hull !
432  outSet.insert(outSet.begin(), lowHull.begin(), lowHull.end() );
433  outSet.insert((outSet.end()), ++(upHull.begin()), --(upHull.end()) ); // avoid duplication
434 
435  // std::cout << " Out size = "<< outSet.size() << std::endl;
436 
437 }

◆ abs_dphi()

float JetGeom::abs_dphi ( float  phi1,
float  phi2 
)
inline

Definition at line 206 of file cyl_geom.h.

206  {
207  float d = fabs(phi1 - phi2);
208  return d < M_PI ? d: fabs(d-2*M_PI);
209 }

◆ clear_delete()

template<class T >
void JetGeom::clear_delete ( T &  container)

Definition at line 148 of file cyl_geom.h.

148  {
149  typedef typename T::iterator it_t;
150  it_t it = container.begin();
151  it_t itE = container.end();
152  for(; it != itE; ++it) delete *it;
153  container.clear();
154 }

◆ delete_content()

template<class T >
void JetGeom::delete_content ( T &  container)

Definition at line 156 of file cyl_geom.h.

156  {
157  typedef typename T::iterator it_t;
158  it_t it = container.begin();
159  it_t itE = container.end();
160  for(; it != itE; ++it) delete *it;
161 }

◆ deltaPhi() [1/2]

float JetGeom::deltaPhi ( float  phi1,
float  phi2 
)
inline

Definition at line 210 of file cyl_geom.h.

210  {
211  return in_mPI_pPI(phi1-phi2);
212 }

◆ deltaPhi() [2/2]

float JetGeom::deltaPhi ( point_t p1,
point_t p2 
)
inline

Definition at line 213 of file cyl_geom.h.

213  {
214  return deltaPhi(p1.second,p2.second);
215 }

◆ deltaR()

float JetGeom::deltaR ( point_t p1,
point_t p2 
)
inline

distances between points

Definition at line 240 of file cyl_geom.h.

240  {
241  return sqrt( deltaR2(p1,p2) );
242 }

◆ deltaR2()

float JetGeom::deltaR2 ( point_t p1,
point_t p2 
)
inline

Definition at line 236 of file cyl_geom.h.

236  {
237  return (p1.first-p2.first)*(p1.first-p2.first) +
238  abs_dphi(p1.second,p2.second)*abs_dphi(p1.second,p2.second) ;
239 }

◆ findConvexHull() [1/2]

template<class inT , class ouT >
void JetGeom::findConvexHull ( inT &  inSet,
ouT &  outSet 
)

Find convex hull of a set of points in euclidian plan.

The hull points are filled into

Parameters
outSet

Definition at line 317 of file cyl_geom.h.

317  {
318  point_set_t rset;
319  typedef typename inT::iterator it_t;
320  it_t it = inSet.begin();
321  it_t itE = inSet.end();
322  for(; it!=itE; ++it) rset.insert(*it);
323  _findConvexHull(rset,outSet);
324 }

◆ findConvexHull() [2/2]

template<class ouT >
void JetGeom::findConvexHull ( point_set_t inSet,
ouT &  outSet 
)

specialization for point_set_t

Definition at line 327 of file cyl_geom.h.

327  {
328  _findConvexHull(inSet, outSet);
329 }

◆ fix2pi()

void JetGeom::fix2pi ( point_t p)
inline

convert

Parameters
psecond coordinate (phi) into a value in [-Pi,Pi]

Definition at line 221 of file cyl_geom.h.

221  {
222  while(p.second < -M_PI) p.second += 2*M_PI;
223  while(p.second >= M_PI) p.second -= 2*M_PI;
224 }

◆ getMeanPhi()

template<class T >
float JetGeom::getMeanPhi ( T &  set)

return average phi (i.e.

second coordinate) of the point container

Parameters
set,ifmax(deltaphi) < pi (i.e. points are located on one side of cylinder) otherwise return -10.

Definition at line 263 of file cyl_geom.h.

263  {
264  // return mean
265  typedef typename T::iterator it_t;
266  it_t it = set.begin();
267  it_t end = set.end();
268  point_t fp = (*it);
269  float max= 0,min=0, mean=0;
270  int n=0;
271  for(; it!= end; ++it){
272  float phi = recenter((*it),fp).second;
273  if( phi >0){
274  max = phi>max ? phi : max;
275  }else{
276  min = phi<min ? phi : min;
277  }
278  mean+=phi; n++;
279  }
280  if ( (max-min) <= (M_PI) )
281  return in_mPI_pPI(mean/n+fp.second);
282  else return -10;
283 }

◆ in_mPI_pPI()

float JetGeom::in_mPI_pPI ( float  phi)
inline

convert

Parameters
phiinto a value in [-Pi,Pi]

Definition at line 216 of file cyl_geom.h.

216  {
217  while(phi < -M_PI) phi += 2*M_PI;
218  while(phi >= M_PI) phi -= 2*M_PI;
219  return phi;
220 }

◆ listToSet()

void JetGeom::listToSet ( point_list_t inList,
point_set_t outSet 
)

Definition at line 27 of file cyl_geom.cxx.

27  {
28  point_list_t::iterator it = inList.begin();
29  point_list_t::iterator itE = inList.end();
30  point_set_t::iterator s_it = outSet.begin();
31  for(; it!=itE; ++it){
32  s_it = outSet.insert(s_it, *it);
33  }
34 }

◆ max_deltaR()

template<class T >
float JetGeom::max_deltaR ( point_t  p,
T &  set 
)

Return max distance betweens point.

Parameters
pand points of
set

Definition at line 164 of file cyl_geom.h.

164  {
165  typedef typename T::iterator it_t;
166  it_t it = set.begin();
167  it_t itE = set.end();
168  float r=0;
169  for(; it != itE; ++it){
170  float t = deltaR(p, *it);
171  if(t>r) r=t;
172  }
173  return r;
174 }

◆ polygon_area()

template<class T >
float JetGeom::polygon_area ( T &  line)

Definition at line 177 of file cyl_geom.h.

177  {
178  typedef typename T::iterator it_t;
179  it_t it = line.begin();
180  it_t itE = line.end();
181  float a=0;
182  for(; it != itE; ++it){
183  it_t itp=it;
184  ++itp;
185  if(itp == itE) itp = line.begin();
186  a += ( (*it).first*(*itp).second - (*itp).first*(*it).second );
187  }
188  return a/2;
189 }

◆ polygon_lenght()

template<class T >
float JetGeom::polygon_lenght ( T &  line)

Definition at line 192 of file cyl_geom.h.

192  {
193  typedef typename T::iterator it_t;
194  it_t it = line.begin();
195  it_t itE = line.end();
196  float a=0;
197  for(; it != itE; ++it){
198  it_t itp=it;
199  ++itp;
200  if(itp == itE) itp = line.begin();
201  a += deltaR(*it,*itp);
202  }
203  return a;
204 }

◆ recenter() [1/2]

point_t JetGeom::recenter ( const point_t p,
const point_t center 
)
inline

Definition at line 226 of file cyl_geom.h.

226  {
227  point_t n(p.first, p.second - center.second);
228  fix2pi(n);
229  return n;
230 }

◆ recenter() [2/2]

point_t JetGeom::recenter ( const point_t p,
float  phicenter 
)
inline

Definition at line 231 of file cyl_geom.h.

231  {
232  point_t n(p.first, p.second - phicenter);
233  fix2pi(n);
234  return n;
235 }

◆ recenter_set() [1/2]

template<class T , class T2 >
void JetGeom::recenter_set ( T &  inSet,
T2 &  outSet 
)

copy

Parameters
inSetinto
outSetwith all phi coordonitates recentered by average phi of
inSet

Definition at line 256 of file cyl_geom.h.

256  {
257  float phicenter = getMeanPhi(inSet);
258  if (phicenter <-9) return;
259  recenter_set(inSet,outSet,phicenter);
260 }

◆ recenter_set() [2/2]

template<class T , class T2 >
void JetGeom::recenter_set ( T &  inSet,
T2 &  outSet,
float  phicenter 
)

copy

Parameters
inSetinto
outSetwith all phi coordonitates recnetered by phicenter

Definition at line 245 of file cyl_geom.h.

245  {
246  typedef typename T::iterator it_t;
247  typedef typename T2::iterator it_t2;
248  it_t it = inSet.begin();
249  it_t itE = inSet.end();
250  it_t2 it2 = outSet.begin();
251  for(; it!= itE; ++it){
252  it2 = outSet.insert(it2,recenter(*it,phicenter));
253  }
254 }

◆ testHullLine()

void JetGeom::testHullLine ( point_list_t hull,
point_t  p 
)

Definition at line 9 of file cyl_geom.cxx.

9  {
10  // helper function for findConvexHull
11  point_list_t::iterator it_prev = hull.end();--it_prev;
12  point_list_t::iterator it_pprev = it_prev; --it_pprev;
13  line_t l(*it_pprev, *it_prev);
14  // std::cout << " hull : "<< hull.size()<< " p.phi ="<<p.second <<std::endl;
15  // std::cout << " "<< (*it_prev).first<< " " << (*it_prev).second << std::endl;
16  // std::cout << " "<< (*it_pprev).first << " "<<(*it_pprev).second << std::endl;
17  // std::cout << " -> "<< p.first << " "<< p.second << std::endl;
18  if ( ! l.is_left(p) && (hull.size()>2)){
19  //std::cout << " is right !" << std::endl;
20  hull.pop_back(); // remove last
21  testHullLine(hull, p);
22  }else{
23  //std::cout << " is left !" << std::endl;
24  hull.push_back(p);
25  }
26 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
beamspotman.r
def r
Definition: beamspotman.py:676
JetGeom::fix2pi
void fix2pi(point_t &p)
convert
Definition: cyl_geom.h:221
TruthTest.itp
itp
Definition: TruthTest.py:46
checkFileSG.line
line
Definition: checkFileSG.py:75
mean
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
Definition: dependence.cxx:254
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
max
#define max(a, b)
Definition: cfImp.cxx:41
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
JetGeom::recenter
point_t recenter(const point_t &p, float phicenter)
Definition: cyl_geom.h:231
hist_file_dump.d
d
Definition: hist_file_dump.py:137
skel.it
it
Definition: skel.GENtoEVGEN.py:423
M_PI
#define M_PI
Definition: ActiveFraction.h:11
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
JetGeom::abs_dphi
float abs_dphi(float phi1, float phi2)
Definition: cyl_geom.h:206
JetGeom::point_list_t
std::list< point_t > point_list_t
Definition: cyl_geom.h:32
JetGeom::deltaR
float deltaR(point_t &p1, point_t &p2)
distances between points
Definition: cyl_geom.h:240
TruthTest.itE
itE
Definition: TruthTest.py:25
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
JetGeom::deltaPhi
float deltaPhi(float phi1, float phi2)
Definition: cyl_geom.h:210
JetGeom::getMeanPhi
float getMeanPhi(T &set)
return average phi (i.e.
Definition: cyl_geom.h:263
JetGeom::testHullLine
void testHullLine(point_list_t &hull, point_t p)
Definition: cyl_geom.cxx:9
trigmenu_modify_prescale_json.fp
fp
Definition: trigmenu_modify_prescale_json.py:53
beamspotman.n
n
Definition: beamspotman.py:731
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:224
min
#define min(a, b)
Definition: cfImp.cxx:40
a
TList * a
Definition: liststreamerinfos.cxx:10
JetGeom::_findConvexHull
void _findConvexHull(point_set_t &inSet, T &outSet)
Definition: cyl_geom.h:332
JetGeom::in_mPI_pPI
float in_mPI_pPI(float phi)
convert
Definition: cyl_geom.h:216
JetGeom::deltaR2
float deltaR2(point_t &p1, point_t &p2)
Definition: cyl_geom.h:236
JetGeom::recenter_set
void recenter_set(T &inSet, T2 &outSet)
copy
Definition: cyl_geom.h:256