ATLAS Offline Software
JetVoronoiDiagramHelpers.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // JetVoronoiDiagramHelpers.h
6 
7 #ifndef JETMOMENTTOOLS_JETVORONOIDIAGRAMHELPERS_H
8 #define JETMOMENTTOOLS_JETVORONOIDIAGRAMHELPERS_H
9 
15 
16 // athena
17 #include "AsgTools/AsgTool.h"
18 
19 //stl
20 #include <string>
21 #include <vector>
22 //using std::vector;
23 
24 // boost polygon
25 #include <boost/polygon/voronoi.hpp>
26 //using boost::polygon::voronoi_builder;
27 //using boost::polygon::voronoi_diagram;
28 typedef boost::polygon::voronoi_diagram<double> VoronoiBoost;
29 typedef boost::polygon::voronoi_diagram<double>::vertex_type VoronoiVtxBoost;
30 typedef boost::polygon::voronoi_diagram<double>::cell_type VoronoiCellBoost;
31 typedef boost::polygon::voronoi_diagram<double>::edge_type VoronoiEdgeBoost;
32 
33 // boost geometry
34 #include <boost/geometry.hpp>
35 #include <boost/geometry/geometries/point_xy.hpp>
36 #include <boost/geometry/geometries/polygon.hpp>
37 //using boost::geometry::area;
38 //using boost::geometry::intersection;
39 typedef boost::geometry::model::d2::point_xy<double> VoronoiPointBoost;
40 typedef boost::geometry::model::polygon<VoronoiPointBoost> VoronoiPolygonBoost;
41 
45  typedef double coord;
46 
47 
50  struct Point{
51  Point(coord the_x=0, coord the_y=0): x(the_x), y(the_y){};
52  Point(const Point &a): x(a.x), y(a.y) {};
53  // data members
56  };
57 
58  // operators *
59  Point operator*(double a, const Point &b);
60  Point operator*(const Point &b,double a);
61  double operator*(const Point &a, const Point &b);
62 
63  // operators +
64  Point operator+(const Point &a, const Point &b);
65  Point operator+(double a, const Point &b);
66  Point operator+(const Point &b, double a);
67 
68  // operators -
69  Point operator-(const Point &a, const Point &b);
70  Point operator-(const Point &b);
71 
72  // logic operators
73  bool operator== (const Point &a, const Point &b);
74  bool operator!= (const Point &a, const Point &b);
75 
76  // space functions
77  Point Center(const Point &a, const Point &b) ;
78  Point Norm(const Point &a);
79 
80 
83  struct Segment{
85  Segment(Point a, Point b) : p0(a), p1(b) {}
86  // data members
89  };
90 
91 
94  struct Polygon : public std::vector<Point> {
95  void Add(coord x, coord y){
96  push_back(Point(x,y));
97  }
99  if (empty()) return;
100  // add all
101  for ( const Point& p : *this ) out.outer().push_back(VoronoiPointBoost(p.x,p.y));
102  // add first again to close shape if necessary
103  if ( front() != back() ) out.outer().push_back(VoronoiPointBoost(front().x,front().y));
104  // correct geometry
105  boost::geometry::correct(out);
106  }
107  };
108 
109 
112  typedef std::vector<Polygon> PolygonList;
113 
114 
117  struct SegmentList : public std::vector<Segment> {
119  push_back(Segment(x1,y1,x2,y2));
120  }
121  };
122 
123 
126  struct Diagram : public asg::AsgTool {
127  Diagram ( const std::string & name);
128  // functions
130  float getCellArea( const coord x, const coord y) const;
131  size_t findPointIndex(const Point &a) const;
132  void clearDiagram();
134  Point interpolateInfinityVertex(const int i_a, const int i_b);
135  bool checkSameNumber(double in, double out, const std::string & description);
136  StatusCode checkStatus(const VoronoiBoost &vd, size_t n_cells_processed);
138 
139  // Data members
140  double m_x_min;
141  double m_x_max;
142  double m_y_min;
143  double m_y_max;
147  std::vector<double> m_area_cells;
149  // Polygon m_voro_cells; //!< needed for future implementation of "within"
150  size_t m_N_points;
151  };
152 } // JetVoronoiDiagramHelpers
153 
154 
155 // interfacing Helpers to Boost
156 //using JetVoronoiDiagramHelpers::coord;
157 //using JetVoronoiDiagramHelpers::Point;
158 //using JetVoronoiDiagramHelpers::Segment;
159 //using JetVoronoiDiagramHelpers::SegmentList;
160 //using JetVoronoiDiagramHelpers::Polygon;
161 //using JetVoronoiDiagramHelpers::PolygonList;
162 //using JetVoronoiDiagramHelpers::Diagram;
163 
164 namespace boost {
165  namespace polygon {
166  // Point concept
167  template <>
168  struct geometry_concept<JetVoronoiDiagramHelpers::Point> {
169  typedef point_concept type;
170  };
171  template <>
172  struct point_traits<JetVoronoiDiagramHelpers::Point> {
174  static inline coordinate_type get(
175  const JetVoronoiDiagramHelpers::Point& point, orientation_2d orient) {
176  return (orient == HORIZONTAL) ? point.x : point.y;
177  }
178  };
179  template <>
180  struct point_mutable_traits<JetVoronoiDiagramHelpers::Point> {
182  static inline void set(JetVoronoiDiagramHelpers::Point& point, orientation_2d orient, int value) {
183  if(orient == HORIZONTAL)
184  point.x = value;
185  else
186  point.y = value;
187  }
188  static inline JetVoronoiDiagramHelpers::Point construct(int x_value, int y_value) {
190  retval.x = x_value;
191  retval.y = y_value;
192  return retval;
193  }
194  };
195 
196  // Segment concept
197  template <>
198  struct geometry_concept<JetVoronoiDiagramHelpers::Segment> {
199  typedef segment_concept type;
200  };
201  template <>
202  struct segment_traits<JetVoronoiDiagramHelpers::Segment> {
205  static inline point_type get(const JetVoronoiDiagramHelpers::Segment& segment, direction_1d dir) {
206  return dir.to_int() ? segment.p1 : segment.p0;
207  }
208  };
209  } // polygon
210 } // boost
211 
212 #endif
213 
boost::polygon::point_traits< JetVoronoiDiagramHelpers::Point >::coordinate_type
JetVoronoiDiagramHelpers::coord coordinate_type
Definition: JetVoronoiDiagramHelpers.h:173
JetVoronoiDiagramHelpers::operator+
Point operator+(const Point &a, const Point &b)
Definition: JetVoronoiDiagramHelpers.cxx:32
VoronoiEdgeBoost
boost::polygon::voronoi_diagram< double >::edge_type VoronoiEdgeBoost
Definition: JetVoronoiDiagramHelpers.h:31
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
asg::AsgTool
Base class for the dual-use tool implementation classes.
Definition: AsgTool.h:47
VoronoiPolygonBoost
boost::geometry::model::polygon< VoronoiPointBoost > VoronoiPolygonBoost
Definition: JetVoronoiDiagramHelpers.h:40
JetVoronoiDiagramHelpers::Diagram::m_x_min
double m_x_min
Definition: JetVoronoiDiagramHelpers.h:140
JetVoronoiDiagramHelpers::Diagram::checkSameNumber
bool checkSameNumber(double in, double out, const std::string &description)
Definition: JetVoronoiDiagramHelpers.cxx:197
JetVoronoiDiagramHelpers::Polygon::FillVoroPolygon
void FillVoroPolygon(VoronoiPolygonBoost &out) const
Definition: JetVoronoiDiagramHelpers.h:98
JetVoronoiDiagramHelpers::Diagram::Diagram
Diagram(const std::string &name)
Definition: JetVoronoiDiagramHelpers.cxx:85
JetVoronoiDiagramHelpers::Point::Point
Point(coord the_x=0, coord the_y=0)
Definition: JetVoronoiDiagramHelpers.h:51
JetVoronoiDiagramHelpers::PolygonList
std::vector< Polygon > PolygonList
Definition: JetVoronoiDiagramHelpers.h:112
JetVoronoiDiagramHelpers::Diagram::intersectionAndArea
double intersectionAndArea(JetVoronoiDiagramHelpers::Polygon const &geo1, JetVoronoiDiagramHelpers::Polygon const &geo2, JetVoronoiDiagramHelpers::Polygon &out)
Definition: JetVoronoiDiagramHelpers.cxx:221
Trk::TrackState::Segment
@ Segment
Definition: TrackStateDefs.h:37
boost::polygon::point_mutable_traits< JetVoronoiDiagramHelpers::Point >::construct
static JetVoronoiDiagramHelpers::Point construct(int x_value, int y_value)
Definition: JetVoronoiDiagramHelpers.h:188
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
JetVoronoiDiagramHelpers::operator==
bool operator==(const Point &a, const Point &b)
Definition: JetVoronoiDiagramHelpers.cxx:62
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
boost::polygon::point_traits< JetVoronoiDiagramHelpers::Point >::get
static coordinate_type get(const JetVoronoiDiagramHelpers::Point &point, orientation_2d orient)
Definition: JetVoronoiDiagramHelpers.h:174
JetVoronoiDiagramHelpers::Polygon
Definition: JetVoronoiDiagramHelpers.h:94
athena.value
value
Definition: athena.py:124
VoronoiBoost
boost::polygon::voronoi_diagram< double > VoronoiBoost
Jakub Cuth May 2015.
Definition: JetVoronoiDiagramHelpers.h:28
boost
Definition: DVLIterator.h:29
JetVoronoiDiagramHelpers::operator!=
bool operator!=(const Point &a, const Point &b)
Definition: JetVoronoiDiagramHelpers.cxx:69
x
#define x
empty
bool empty(TH1 *h)
Definition: computils.cxx:295
JetVoronoiDiagramHelpers::Segment::p0
Point p0
Definition: JetVoronoiDiagramHelpers.h:87
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
JetVoronoiDiagramHelpers::Point
Definition: JetVoronoiDiagramHelpers.h:50
JetVoronoiDiagramHelpers::Diagram::m_area_borders
double m_area_borders
Definition: JetVoronoiDiagramHelpers.h:148
JetVoronoiDiagramHelpers::Diagram::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: JetVoronoiDiagramHelpers.cxx:98
LArCellBinning_test.retval
def retval
Definition: LArCellBinning_test.py:112
VoronoiVtxBoost
boost::polygon::voronoi_diagram< double >::vertex_type VoronoiVtxBoost
Definition: JetVoronoiDiagramHelpers.h:29
boost::polygon::segment_traits< JetVoronoiDiagramHelpers::Segment >::point_type
JetVoronoiDiagramHelpers::Point point_type
Definition: JetVoronoiDiagramHelpers.h:204
JetVoronoiDiagramHelpers::Point::Point
Point(const Point &a)
Definition: JetVoronoiDiagramHelpers.h:52
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
JetVoronoiDiagramHelpers::SegmentList::Add
void Add(coord x1, coord y1, coord x2, coord y2)
Definition: JetVoronoiDiagramHelpers.h:118
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
JetVoronoiDiagramHelpers::Diagram::checkStatus
StatusCode checkStatus(const VoronoiBoost &vd, size_t n_cells_processed)
Definition: JetVoronoiDiagramHelpers.cxx:206
makeTRTBarrelCans.y2
tuple y2
Definition: makeTRTBarrelCans.py:18
JetVoronoiDiagramHelpers::Norm
Point Norm(const Point &a)
Definition: JetVoronoiDiagramHelpers.cxx:79
JetVoronoiDiagramHelpers::Segment::Segment
Segment(Point a, Point b)
Definition: JetVoronoiDiagramHelpers.h:85
JetVoronoiDiagramHelpers::Diagram::m_voro_vtx
Polygon m_voro_vtx
Definition: JetVoronoiDiagramHelpers.h:146
JetVoronoiDiagramHelpers::Diagram
Definition: JetVoronoiDiagramHelpers.h:126
JetVoronoiDiagramHelpers::Point::x
coord x
Definition: JetVoronoiDiagramHelpers.h:52
VoronoiCellBoost
boost::polygon::voronoi_diagram< double >::cell_type VoronoiCellBoost
Definition: JetVoronoiDiagramHelpers.h:30
JetVoronoiDiagramHelpers::Segment::Segment
Segment(coord x1, coord y1, coord x2, coord y2)
Definition: JetVoronoiDiagramHelpers.h:84
JetVoronoiDiagramHelpers::Point::y
coord y
Definition: JetVoronoiDiagramHelpers.h:55
boost::polygon::point_mutable_traits< JetVoronoiDiagramHelpers::Point >::coordinate_type
JetVoronoiDiagramHelpers::coord coordinate_type
Definition: JetVoronoiDiagramHelpers.h:181
JetVoronoiDiagramHelpers::Diagram::m_y_max
double m_y_max
Definition: JetVoronoiDiagramHelpers.h:143
JetVoronoiDiagramHelpers::Diagram::createVoronoiDiagram
StatusCode createVoronoiDiagram()
Definition: JetVoronoiDiagramHelpers.cxx:148
JetVoronoiDiagramHelpers::Segment::p1
Point p1
Definition: JetVoronoiDiagramHelpers.h:88
beamspotman.dir
string dir
Definition: beamspotman.py:623
JetVoronoiDiagramHelpers::Diagram::m_x_max
double m_x_max
Definition: JetVoronoiDiagramHelpers.h:141
boost::polygon::geometry_concept< JetVoronoiDiagramHelpers::Point >::type
point_concept type
Definition: JetVoronoiDiagramHelpers.h:169
JetVoronoiDiagramHelpers::Diagram::m_borders
Polygon m_borders
Definition: JetVoronoiDiagramHelpers.h:145
VoronoiPointBoost
boost::geometry::model::d2::point_xy< double > VoronoiPointBoost
Definition: JetVoronoiDiagramHelpers.h:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
ChargedTracksWeightFilter::Spline::Point
Linear spline representation of a function used to calculate weights.
Definition: ChargedTracksWeightFilter.h:28
JetVoronoiDiagramHelpers::operator*
Point operator*(double a, const Point &b)
Definition: JetVoronoiDiagramHelpers.cxx:14
JetVoronoiDiagramHelpers::Diagram::m_area_cells
std::vector< double > m_area_cells
Definition: JetVoronoiDiagramHelpers.h:147
JetVoronoiDiagramHelpers::Diagram::m_N_points
size_t m_N_points
Definition: JetVoronoiDiagramHelpers.h:150
JetVoronoiDiagramHelpers::SegmentList
Definition: JetVoronoiDiagramHelpers.h:117
JetVoronoiDiagramHelpers::Diagram::m_scaleIntFloat
double m_scaleIntFloat
Definition: JetVoronoiDiagramHelpers.h:144
JetVoronoiDiagramHelpers::coord
double coord
Definition: JetVoronoiDiagramHelpers.h:45
JetVoronoiDiagramHelpers::Center
Point Center(const Point &a, const Point &b)
Definition: JetVoronoiDiagramHelpers.cxx:75
JetVoronoiDiagramHelpers::Polygon::Add
void Add(coord x, coord y)
Definition: JetVoronoiDiagramHelpers.h:95
boost::polygon::point_mutable_traits< JetVoronoiDiagramHelpers::Point >::set
static void set(JetVoronoiDiagramHelpers::Point &point, orientation_2d orient, int value)
Definition: JetVoronoiDiagramHelpers.h:182
boost::polygon::geometry_concept< JetVoronoiDiagramHelpers::Segment >::type
segment_concept type
Definition: JetVoronoiDiagramHelpers.h:199
a
TList * a
Definition: liststreamerinfos.cxx:10
JetVoronoiDiagramHelpers::Diagram::m_y_min
double m_y_min
Definition: JetVoronoiDiagramHelpers.h:142
y
#define y
JetVoronoiDiagramHelpers::Segment
Definition: JetVoronoiDiagramHelpers.h:83
JetVoronoiDiagramHelpers::Diagram::findPointIndex
size_t findPointIndex(const Point &a) const
Definition: JetVoronoiDiagramHelpers.cxx:129
JetVoronoiDiagramHelpers::Diagram::interpolateInfinityVertex
Point interpolateInfinityVertex(const int i_a, const int i_b)
Definition: JetVoronoiDiagramHelpers.cxx:189
JetVoronoiDiagramHelpers::Diagram::getCellArea
float getCellArea(const coord x, const coord y) const
Definition: JetVoronoiDiagramHelpers.cxx:118
boost::polygon::segment_traits< JetVoronoiDiagramHelpers::Segment >::get
static point_type get(const JetVoronoiDiagramHelpers::Segment &segment, direction_1d dir)
Definition: JetVoronoiDiagramHelpers.h:205
boost::polygon::segment_traits< JetVoronoiDiagramHelpers::Segment >::coordinate_type
JetVoronoiDiagramHelpers::coord coordinate_type
Definition: JetVoronoiDiagramHelpers.h:203
AsgTool.h
JetVoronoiDiagramHelpers::operator-
Point operator-(const Point &a, const Point &b)
Definition: JetVoronoiDiagramHelpers.cxx:50
JetVoronoiDiagramHelpers::Diagram::clearDiagram
void clearDiagram()
Definition: JetVoronoiDiagramHelpers.cxx:140
JetVoronoiDiagramHelpers
Jakub Cuth May 2015.
Definition: JetVoronoiDiagramHelpers.h:42
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88