HGCal Test Beam  03a93d6239a951948e06fb3ef8dae4cbdebfad30
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
HGCalTBCellVertices.cc
Go to the documentation of this file.
1 #include "HGCal/Geometry/interface/HGCalTBCellVertices.h"
2 #include <stdlib.h>
3 #include "math.h"
4 #include <iostream>
5 #include <iomanip>
6 #define PI 3.14159265
7 #define TEST_BEAM_LAYER_ROTATION -PI/2
8 using namespace std;
9 
11 double delta = 0.00001;//needed for comparing two doubles while deciding if the cell is within a sensor
12 
14 {
15 // Initialize the co-ordinates of a hexagonal cell of side a centred at 0,0 with the top vertex numbered as the first with clockwise increments.
16  double x1[] = {0., x_a * a, x_a * a, 0., -x_a * a, -x_a * a};
17  double y1[] = {a, y_a * a, -y_a * a, -a, -y_a * a, y_a * a};
18  for(int iii = 0; iii < 6; iii++) { // May have to be generalized to deal with polygons of any size
19  x_co_FullHex.push_back(x1[iii]);
20  y_co_FullHex.push_back(y1[iii]);
21  }
22 
23 }
24 
25 
26 std::vector<std::pair<double, double>> HGCalTBCellVertices::GetCellCoordinates(int layer, int sensor_iu, int sensor_iv, int iu, int iv, int sensorsize, bool flipX)
27 {
28  bool ValidFlag = Top.iu_iv_valid(layer, sensor_iu, sensor_iv, iu, iv, sensorsize);
29  double vertex_x_tmp = 0., vertex_y_tmp = 0.;
30  Cell_co.clear();
31  if(ValidFlag) {
32  for(int iii = 0; iii < 6; iii++) { // May have to be generalized to deal with polygons of any size
33  vertex_x_tmp = x_co_FullHex[iii] + iu * x0 + iv * vx0;
34  vertex_y_tmp = y_co_FullHex[iii] + iv * vy0;
35 //The general strategy is to translate starting from the central hexagonal cell to the iu,iv desired. If any vertex goes out of the sensor boundary its cordinates are not filled into the vector of pairs.
36  if(fabs(vertex_x_tmp) <= Xmax(iv, fabs(vertex_y_tmp)) + delta) {
37  auto point = RotateLayer(std::make_pair(vertex_x_tmp, vertex_y_tmp), TEST_BEAM_LAYER_ROTATION);
38 // if(flipX==true) point.first=-point.first;
39  Cell_co.push_back(point);
40  }
41  }
42  return Cell_co;
43  } else {
44  Cell_co.push_back(std::make_pair(-123456, -123456)); //iu_iv_Valid() is sufficient to decide if a given iu,iv is a valid sensor index but this is done if some future need may arise.
45  return Cell_co;
46  }
47 
48 }
49 
50 
51 std::pair<double, double> HGCalTBCellVertices::GetCellCentreCoordinates(int layer, int sensor_iu, int sensor_iv, int iu, int iv, int sensorsize, bool flipX)
52 {
53  double centre_x_tmp = 0., centre_y_tmp = 0.;
54  bool ValidFlag = Top.iu_iv_valid(layer, sensor_iu, sensor_iv, iu, iv, sensorsize);
55  if(ValidFlag) {
56  centre_x_tmp = iu * x0 + iv * vx0;
57  centre_y_tmp = iv * vy0;
58  auto point = RotateLayer(std::make_pair(centre_x_tmp, centre_y_tmp), TEST_BEAM_LAYER_ROTATION);
59 // if(flipX==true) point.first = - point.first;
60  return point;
61  } else return std::make_pair(-123456, -123456); //iu_iv_Valid() is sufficient to decide if a given iu,iv is a valid sensor index but this is done if some future need may arise.
62 
63 }
64 
65 double HGCalTBCellVertices::Xmax(int iv, double y)
66 {
67  if(fabs(iv) <= 3) return 11 * x_a * a;
68  else return (11 * a - y) / (1 / (2 * x_a));
69 }
70 
71 std::pair<double, double> HGCalTBCellVertices::RotateLayer(std::pair<double, double> Vertex, double Angle)
72 {
73  double X_new = (Vertex.first) * cos(Angle) - (Vertex.second) * sin(Angle);
74  double Y_new = (Vertex.first) * sin(Angle) - (Vertex.second) * cos(Angle);
75  return std::make_pair(-X_new, Y_new);// The negative sign for the x coordinate is to account for the TB cartesian coordinate system.
76 }
77 
78 // To be added if for reconstruction it is useful to simply know if a cell is full hex, half hex or mouse-bitten
79 /*
80 void HGCalTBCellVertices::CellType(int iu, int iv, bool ValidFlag){
81  bool HalfHex = false;
82  x_max=0.;
83  y_max=0.;
84  }
85 */
86 
87 // To be added after finalizing what all we need to see printed out.
88 /*
89 std::ostream& operator<<(std::ostream& s, const HGCalTBCellVertices& vertices, int type) {
90 
91  if(type == 1){
92  return s << "This cell is a full hexagon"<<endl;
93  for(int iii=0;iii<6;iii++)
94  return s<<" Vertex 1 x co-ordinate = "<<vertices.HX[iii]<<" y co-ordinate = "<<vertices.Hy[iii]<<endl;
95  }
96  else if(type == 2){
97  return s << "This cell is a half hexagon"<<endl;
98  for(int iii=0;iii<4;iii++)
99  return s<<" Vertex 1 x co-ordinate = "<<vertices.HX[iii]<<" y co-ordinate = "<<vertices.Hy[iii]<<endl;
100  }
101 
102 }
103 */
double delta
std::pair< double, double > GetCellCentreCoordinates(int layer, int sensor_iu, int sensor_iv, int iu, int iv, int sensorsize, bool flipX=false)
returns the coordinates of each vertex of cell in the lab frame (x,y)
bool iu_iv_valid(int layer, int sensor_iu, int sensor_iv, int iu, int iv, int sensorSize) const
HGCalTBCellVertices()
Constructor from cell iu &amp; iv, valid sensorSizes are 128 and 256.
#define TEST_BEAM_LAYER_ROTATION
std::vector< std::pair< double, double > > GetCellCoordinates(int layer, int sensor_iu, int sensor_iv, int iu, int iv, int sensorsize, bool flipX=false)
returns the coordinates of each vertex of cell in the lab frame (x,y)
HGCalTBTopology Top