ATLAS Offline Software
GeoUtils.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef GEOUTILS_H
6 #define GEOUTILS_H
7 #include <boost/geometry.hpp>
8 #include <boost/geometry/geometries/point_xy.hpp>
9 #include <boost/geometry/geometries/polygon.hpp>
11 #include "Math/Vector3D.h"
12 #include <vector>
13 #include <cmath>
14 #include <algorithm>
15 
16 namespace NSWL1{
17  using Vertex=boost::geometry::model::d2::point_xy<double>;
18  using Polygon=boost::geometry::model::polygon<Vertex>;
19  using Vertices=std::vector<Vertex>;
20 
21  //to convert from cartesian coordinates
22  float eta(float,float,float);
23  float phi(float,float,float);
24 
25  //given a polygon written on a plane Z=Z0, move it into another Z=Z1 plane keeping eta phi same
26  Polygon Project(const Polygon& ,float ,float );
27 
28  //Print something on the screen in a well defined format
29  Polygon buildPolygon(const Vertices&);//hm
30 
31  template <class T>
32  void print(const T& t){std::cout<<boost::geometry::wkt(t)<<std::endl;}
33  //given two polygons, the number of intersections can be more than one in general
34  //even though we do not expect it for sTGC pad gemotery let us implement it here just in case
35 
36  //Compute the area of a polygon
37  float area(const Polygon&);
38 
39  //compute the geometric center of a polygon
40  Vertex centroid(const Polygon&);
41 
42  std::vector<Polygon> allIntersections(const Polygon&, const Polygon&);
43 
44  //get the first of the intersections of two polygons. We expect to get only one of them for sTGC pad geometry
46 
47  //given two polygons, calculate the overlap with the largest area
49  //given a set of polygons calculate the overlap if there is any at the end...
50 
51  //we take the first overlap(s) into account. For the pad geometry we, in principle, should have only one overlap at each selected pair of layers
52  Polygon intersectionRegion(const std::vector<Polygon>&);
53 
54  //to access vertical& horizontal coordinates of a given vertex
55  template <int XY>
56  float coordinate(const Vertex& v){
57  return boost::geometry::get<XY>(v);
58  }
59 
60  //given a polygon, return the number of vertices... (keep in mind that a polygon is a closed loop in our sense so first and the last vertices are the same)
61  int nVertices(const Polygon&);
62 
63  Vertex getVertex(const Polygon&,unsigned int);
64 
65  //Given a polygon get minimum and maximum bounds of a vertical or horizontal coordinate
66  template <int XY>
67  std::pair<float,float> coordinateRange(const Polygon& p){
68  std::vector<float> values;
69  for(auto vertex : boost::geometry::exterior_ring(p)){
70  float currVal=boost::geometry::get<XY>(vertex);
71  values.push_back(currVal);
72  }
73  std::sort(values.begin(),values.end() );
74  return std::make_pair(values[0],values.back());
75  }
76 
77  Polygon globalToLocal(const Polygon& ,float z,const Trk::PlaneSurface & );//use Z-depth of the given polygon in 3D
78 
79  //Absorbing Element : a closed loop made up of 4 points (0,0)
81  }
82 
83 #endif
NSWL1::eta
float eta(float x, float y, float z)
Definition: GeoUtils.cxx:9
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
NSWL1::nVertices
int nVertices(const Polygon &p)
Definition: GeoUtils.cxx:35
NSWL1::Vertex
boost::geometry::model::d2::point_xy< double > Vertex
Definition: GeoUtils.h:17
NSWL1::Polygon
boost::geometry::model::polygon< Vertex > Polygon
Definition: GeoUtils.h:18
NSWL1::largestIntersection
Polygon largestIntersection(const Polygon &p1, const Polygon &p2)
Definition: GeoUtils.cxx:80
NSWL1::coordinate
float coordinate(const Vertex &v)
Definition: GeoUtils.h:56
NSWL1::allIntersections
std::vector< Polygon > allIntersections(const Polygon &p1, const Polygon &p2)
Definition: GeoUtils.cxx:65
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
NSWL1::NilPolygon
Polygon NilPolygon()
Definition: GeoUtils.cxx:118
NSWL1::Project
Polygon Project(const Polygon &p, float Zinit, float Zfin)
Definition: GeoUtils.cxx:19
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:797
NSWL1::print
void print(const T &t)
Definition: GeoUtils.h:32
NSWL1::area
float area(const Polygon &p)
Definition: GeoUtils.cxx:55
z
#define z
NSWL1::getVertex
Vertex getVertex(const Polygon &p, unsigned int i)
Definition: GeoUtils.cxx:39
NSWL1::firstIntersection
Polygon firstIntersection(const Polygon &p1, const Polygon &p2)
Definition: GeoUtils.cxx:73
NSWL1::coordinateRange
std::pair< float, float > coordinateRange(const Polygon &p)
Definition: GeoUtils.h:67
python.PyAthena.v
v
Definition: PyAthena.py:157
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
Trk::PlaneSurface
Definition: PlaneSurface.h:64
PlaneSurface.h
NSWL1::intersectionRegion
Polygon intersectionRegion(const std::vector< Polygon > &polygons)
Definition: GeoUtils.cxx:91
NSWL1::phi
float phi(float x, float y, float z)
Definition: GeoUtils.cxx:14
NSWL1
A trigger trigger candidate for a stgc sector.
Definition: NSWL1Simulation.cxx:9
NSWL1::globalToLocal
Polygon globalToLocal(const Polygon &pol, float z, const Trk::PlaneSurface &surf)
Definition: GeoUtils.cxx:103
NSWL1::Vertices
std::vector< Vertex > Vertices
Definition: GeoUtils.h:19
NSWL1::centroid
Vertex centroid(const Polygon &p)
Definition: GeoUtils.cxx:59
NSWL1::buildPolygon
Polygon buildPolygon(const Vertices &pts)
Definition: GeoUtils.cxx:44