HGCal Test Beam  03a93d6239a951948e06fb3ef8dae4cbdebfad30
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
HGCCellMap.cc
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // Description: map sim cell id to (u, v) coordinates and (x, y) to (u, v)
3 // Created: 06-Apr-2016 Harrison B. Prosper
4 // -------------------------------------------------------------------------
5 #include <fstream>
6 #include <iostream>
7 #include <cassert>
8 #include "TSystem.h"
9 #include "HGCal/Geometry/interface/HGCalTBCellParameters.h"
10 #include "HGCal/Geometry/interface/HGCalTBCellVertices.h"
11 #include "HGCal/Geometry/interface/HGCalTBTopology.h"
12 #include "HGCal/TBStandaloneSimulator/interface/HGCCellMap.h"
13 // -------------------------------------------------------------------------
14 using namespace std;
15 namespace
16 {
17 int MODEL = 5; // TB2016 model
18 int NCELL = 11; // number of pixels from side to side in sensor
19 // side length of one pixel (cell) in mm
20 double CELL_SIDE = 10 * HGCAL_TB_CELL::FULL_CELL_SIDE;
21 // side length of sensor
22 double SENSOR_SIDE = NCELL * CELL_SIDE;
23 double WIDTH = 2 * SENSOR_SIDE; // width of sensor corner to corner
24 };
25 
26 HGCCellMap::HGCCellMap(string inputFilename)
27  : _uvmap(map<size_t, pair<int, int> >()),
28  _posid(map<pair<int, int>, int>()),
29  _xymap(map<pair<int, int>, pair<double, double> >()),
30  _celltype(map<uint32_t, int>()),
31  _eidmap(map<uint32_t, pair<int, int> >()),
32  _cells(map<uint32_t, vector<HGCCellMap::Cell> >()),
33  _geom(HGCSSGeometryConversion(MODEL, WIDTH, CELL_SIDE)),
34  _map(0)
35 {
36  if ( inputFilename == "" )
37  inputFilename = string("$CMSSW_BASE/src/HGCal/TBStandaloneSimulator/data/"
38  "sensor_map.txt");
39 
40  char inpfile[1024];
41  sprintf(inpfile, "%s", gSystem->ExpandPathName(inputFilename.c_str()));
42  ifstream fin(inpfile);
43  if ( ! fin.good() ) {
44  cout << "** HGCCellMap - unable to open file "
45  << inpfile << endl;
46  exit(0);
47  }
48  // initialize hexagonal map
49  _geom.initialiseHoneyComb(WIDTH, CELL_SIDE);
50  _map = _geom.hexagonMap();
51 
52  string line;
53  getline(fin, line);
54 
55  int layer, posid, cellid,
56  sensor_u, sensor_v, u, v,
57  skiroc, channel, celltype;
58  double x, y;
59 
60  while (fin
61  >> layer >> posid >> cellid
62  >> sensor_u >> sensor_v >> u >> v
63  >> skiroc >> channel >> celltype
64  >> x >> y) {
65  pair<int, int> uv(u, v);
66  if ( layer == 1 ) {
67  _uvmap[cellid] = uv;
68  _posid[uv] = posid;
69 
70  pair<double, double> xy(x, y);
71  _xymap[uv] = xy;
72  }
73  HGCCellMap::Cell cell;
74  cell.skiroc = skiroc;
75  cell.channel = channel;
76  cell.u = u;
77  cell.v = v;
78  cell.x = x;
79  cell.y = y;
80  cell.z = 0;
81  cell.count = 0;
82  cell.posid = posid;
83  cell.celltype = celltype;
84 
85  HGCalTBDetId detid1(layer, sensor_u, sensor_v, 0, 0, 0);
86  uint32_t key = detid1.rawId();
87  if ( _cells.find(key) == _cells.end() )
88  _cells[key] = std::vector<HGCCellMap::Cell>();
89  _cells[key].push_back(cell);
90 
91  HGCalTBDetId detid2(layer, sensor_u, sensor_v, u, v, 0);
92  key = detid2.rawId();
93  // the raw ID should be unique; make sure it is
94  assert( _celltype.find(key) == _celltype.end() );
95 
96  _celltype[key] = celltype;
97  _eidmap[key] = pair<int, int>(skiroc, channel);
98  }
99  fin.close();
100 }
101 
103 {
104 }
105 
106 std::vector<HGCCellMap::Cell>
107 HGCCellMap::cells(int layer, int sensor_u, int sensor_v)
108 {
109  HGCalTBDetId detid(layer, sensor_u, sensor_v, 0, 0, 0);
110  int key = detid.rawId();
111  if ( _cells.find(key) != _cells.end() )
112  return _cells[key];
113  else
114  return std::vector<HGCCellMap::Cell>();
115 }
116 
117 
118 pair<int, int>
120 {
121  if ( _uvmap.find(cellid) != _uvmap.end() )
122  return _uvmap[cellid];
123  else
124  return pair<int, int>(-123456, -123456);
125 }
126 
127 pair<double, double>
128 HGCCellMap::operator()(pair<int, int>& uv)
129 {
130  return uv2xy(uv.first, uv.second);
131 }
132 
133 
134 pair<double, double>
135 HGCCellMap::uv2xy(int u, int v)
136 {
137  pair<int, int> key(u, v);
138  if ( _xymap.find(key) != _xymap.end() )
139  return _xymap[key];
140  else
141  return pair<double, double>(-123456, -123456);
142 }
143 
144 pair<int, int>
145 HGCCellMap::uv2eid(int layer, int sensor_u, int sensor_v, int u, int v)
146 {
147  HGCalTBDetId detid(layer, sensor_u, sensor_v, u, v, 0);
148  int key = detid.rawId();
149  if ( _eidmap.find(key) != _eidmap.end() )
150  return _eidmap[key];
151  else
152  return pair<int, int>(-123456, -123456);
153 }
154 
155 pair<int, int>
156 HGCCellMap::xy2uv(double x, double y)
157 {
158  size_t cellid = _map->FindBin(x, y);
159  return (*this)(cellid);
160 }
161 
162 int
163 HGCCellMap::celltype(int layer, int sensor_u, int sensor_v, int u, int v)
164 {
165  HGCalTBDetId detid(layer, sensor_u, sensor_v, u, v, 0);
166  int key = detid.rawId();
167  if ( _celltype.find(key) != _celltype.end() )
168  return _celltype[key];
169  else
170  return -123456;
171 }
172 
173 int
174 HGCCellMap::posid(int u, int v)
175 {
176  pair<int, int> key(u, v);
177  if ( _posid.find(key) != _posid.end() )
178  return _posid[key];
179  else
180  return -1;
181 }
HGCCellMap(std::string inputFilename="")
Definition: HGCCellMap.cc:26
std::pair< int, int > uv2eid(int layer, int sensor_u, int sensor_v, int u, int v)
Definition: HGCCellMap.cc:145
std::vector< HGCCellMap::Cell > cells(int layer=1, int sensor_u=0, int sensor_v=0)
Definition: HGCCellMap.cc:107
virtual ~HGCCellMap()
Definition: HGCCellMap.cc:102
int posid(int u, int v)
Definition: HGCCellMap.cc:174
std::pair< int, int > operator()(size_t cellid)
Definition: HGCCellMap.cc:119
std::pair< double, double > uv2xy(int u, int v)
Definition: HGCCellMap.cc:135
std::pair< int, int > xy2uv(double x, double y)
Definition: HGCCellMap.cc:156
int celltype(int layer, int sensor_u, int sensor_v, int u, int v)
Definition: HGCCellMap.cc:163