CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HGCalTriggerGeometryHexImp2.cc
Go to the documentation of this file.
2 
6 
7 #include <vector>
8 #include <iostream>
9 #include <fstream>
10 
11 
13 {
14  public:
16 
17  virtual void initialize(const es_info& ) override final;
18 
19  virtual unsigned getTriggerCellFromCell( const unsigned ) const override final;
20  virtual unsigned getModuleFromCell( const unsigned ) const override final;
21  virtual unsigned getModuleFromTriggerCell( const unsigned ) const override final;
22 
23  virtual geom_set getCellsFromTriggerCell( const unsigned ) const override final;
24  virtual geom_set getCellsFromModule( const unsigned ) const override final;
25  virtual geom_set getTriggerCellsFromModule( const unsigned ) const override final;
26 
27  virtual geom_ordered_set getOrderedCellsFromModule( const unsigned ) const override final;
28  virtual geom_ordered_set getOrderedTriggerCellsFromModule( const unsigned ) const override final;
29 
30  virtual GlobalPoint getTriggerCellPosition(const unsigned ) const override final;
31  virtual GlobalPoint getModulePosition(const unsigned ) const override final;
32 
33  private:
36 
37  es_info es_info_;
38 
39  std::unordered_map<short, short> wafer_to_module_ee_;
40  std::unordered_map<short, short> wafer_to_module_fh_;
41  std::unordered_multimap<short, short> module_to_wafers_ee_;
42  std::unordered_multimap<short, short> module_to_wafers_fh_;
43 
44  std::map<std::pair<short,short>, short> cells_to_trigger_cells_; // FIXME: something else than map<pair,short>?
45  std::multimap<std::pair<short,short>, short> trigger_cells_to_cells_;// FIXME: something else than map<pair,short>?
46  std::unordered_map<short, short> number_trigger_cells_in_wafers_; // the map key is the wafer type
47  std::unordered_map<short, short> number_cells_in_wafers_; // the map key is the wafer type
48 
49  void fillMaps(const es_info&);
50 };
51 
52 
56  l1tCellsMapping_(conf.getParameter<edm::FileInPath>("L1TCellsMapping")),
57  l1tModulesMapping_(conf.getParameter<edm::FileInPath>("L1TModulesMapping"))
58 {
59 }
60 
61 
62 void
64 initialize(const es_info& esInfo)
65 {
66  edm::LogWarning("HGCalTriggerGeometry") << "WARNING: This HGCal trigger geometry is incomplete.\n"\
67  << "WARNING: There is no neighbor information.\n";
68  es_info_ = esInfo;
69  fillMaps(esInfo);
70 
71 }
72 
73 unsigned
75 getTriggerCellFromCell( const unsigned cell_id ) const
76 {
77  HGCalDetId cell_det_id(cell_id);
78  int wafer_type = cell_det_id.waferType();
79  unsigned cell = cell_det_id.cell();
80  // FIXME: better way to do this cell->TC mapping?
81  unsigned trigger_cell = cells_to_trigger_cells_.at(std::make_pair(wafer_type,cell));
82  return HGCalDetId((ForwardSubdetector)cell_det_id.subdetId(), cell_det_id.zside(), cell_det_id.layer(), cell_det_id.waferType(), cell_det_id.wafer(), trigger_cell).rawId();
83 }
84 
85 unsigned
87 getModuleFromCell( const unsigned cell_id ) const
88 {
89  HGCalDetId cell_det_id(cell_id);
90  unsigned wafer = cell_det_id.wafer();
91  unsigned subdet = cell_det_id.subdetId();
92  unsigned module = 0;
93  switch(subdet)
94  {
96  module = wafer_to_module_ee_.at(wafer);
97  break;
99  module = wafer_to_module_fh_.at(wafer);
100  break;
101  default:
102  edm::LogError("HGCalTriggerGeometry") << "Unknown wafer->module mapping for subdet "<<subdet<<"\n";
103  return 0;
104  };
105  return HGCalDetId((ForwardSubdetector)cell_det_id.subdetId(), cell_det_id.zside(), cell_det_id.layer(), cell_det_id.waferType(), module, HGCalDetId::kHGCalCellMask).rawId();
106 }
107 
108 unsigned
110 getModuleFromTriggerCell( const unsigned trigger_cell_id ) const
111 {
112  HGCalDetId trigger_cell_det_id(trigger_cell_id);
113  unsigned wafer = trigger_cell_det_id.wafer();
114  unsigned subdet = trigger_cell_det_id.subdetId();
115  unsigned module = 0;
116  switch(subdet)
117  {
119  module = wafer_to_module_ee_.at(wafer);
120  break;
122  module = wafer_to_module_fh_.at(wafer);
123  break;
124  default:
125  edm::LogError("HGCalTriggerGeometry") << "Unknown wafer->module mapping for subdet "<<subdet<<"\n";
126  return 0;
127  };
128  return HGCalDetId((ForwardSubdetector)trigger_cell_det_id.subdetId(), trigger_cell_det_id.zside(), trigger_cell_det_id.layer(), trigger_cell_det_id.waferType(), module, HGCalDetId::kHGCalCellMask).rawId();
129 }
130 
133 getCellsFromTriggerCell( const unsigned trigger_cell_id ) const
134 {
135  HGCalDetId trigger_cell_det_id(trigger_cell_id);
136  int wafer_type = trigger_cell_det_id.waferType();
137  unsigned trigger_cell = trigger_cell_det_id.cell();
138  // FIXME: better way to do this TC->cell mapping?
139  const auto& cell_range = trigger_cells_to_cells_.equal_range(std::make_pair(wafer_type,trigger_cell));
140  geom_set cell_det_ids;
141  for(auto tc_c_itr=cell_range.first; tc_c_itr!=cell_range.second; tc_c_itr++)
142  {
143  cell_det_ids.emplace(HGCalDetId((ForwardSubdetector)trigger_cell_det_id.subdetId(), trigger_cell_det_id.zside(), trigger_cell_det_id.layer(), trigger_cell_det_id.waferType(), trigger_cell_det_id.wafer(), tc_c_itr->second).rawId());
144  }
145  return cell_det_ids;
146 }
147 
150 getCellsFromModule( const unsigned module_id ) const
151 {
152 
153  HGCalDetId module_det_id(module_id);
154  unsigned module = module_det_id.wafer();
155  int wafer_type = module_det_id.waferType();
156  unsigned subdet = module_det_id.subdetId();
157  std::pair<std::unordered_multimap<short, short>::const_iterator,
158  std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
159  switch(subdet)
160  {
162  wafer_itrs = module_to_wafers_ee_.equal_range(module);
163  break;
165  wafer_itrs = module_to_wafers_fh_.equal_range(module);
166  break;
167  default:
168  edm::LogError("HGCalTriggerGeometry") << "Unknown module->wafers mapping for subdet "<<subdet<<"\n";
169  return geom_set();
170  };
171  geom_set cell_det_ids;
172  for(auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
173  {
174  // loop on the cells in each wafer
175  for(int cell=0; cell<number_cells_in_wafers_.at(wafer_type); cell++)
176  {
177  cell_det_ids.emplace(HGCalDetId((ForwardSubdetector)module_det_id.subdetId(), module_det_id.zside(), module_det_id.layer(), module_det_id.waferType(), wafer_itr->second, cell).rawId());
178  }
179  }
180  return cell_det_ids;
181 }
182 
185 getOrderedCellsFromModule( const unsigned module_id ) const
186 {
187  HGCalDetId module_det_id(module_id);
188  unsigned module = module_det_id.wafer();
189  int wafer_type = module_det_id.waferType();
190  unsigned subdet = module_det_id.subdetId();
191  std::pair<std::unordered_multimap<short, short>::const_iterator,
192  std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
193  switch(subdet)
194  {
196  wafer_itrs = module_to_wafers_ee_.equal_range(module);
197  break;
199  wafer_itrs = module_to_wafers_fh_.equal_range(module);
200  break;
201  default:
202  edm::LogError("HGCalTriggerGeometry") << "Unknown module->wafers mapping for subdet "<<subdet<<"\n";
203  return geom_ordered_set();
204  };
205  geom_ordered_set cell_det_ids;
206  for(auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
207  {
208  // loop on the cells in each wafer
209  for(int cell=0; cell<number_cells_in_wafers_.at(wafer_type); cell++)
210  {
211  cell_det_ids.emplace(HGCalDetId((ForwardSubdetector)module_det_id.subdetId(), module_det_id.zside(), module_det_id.layer(), module_det_id.waferType(), wafer_itr->second, cell).rawId());
212  }
213  }
214  return cell_det_ids;
215 }
216 
219 getTriggerCellsFromModule( const unsigned module_id ) const
220 {
221  HGCalDetId module_det_id(module_id);
222  unsigned module = module_det_id.wafer();
223  int wafer_type = module_det_id.waferType();
224  unsigned subdet = module_det_id.subdetId();
225  std::pair<std::unordered_multimap<short, short>::const_iterator,
226  std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
227  switch(subdet)
228  {
230  wafer_itrs = module_to_wafers_ee_.equal_range(module);
231  break;
233  wafer_itrs = module_to_wafers_fh_.equal_range(module);
234  break;
235  default:
236  edm::LogError("HGCalTriggerGeometry") << "Unknown module->wafers mapping for subdet "<<subdet<<"\n";
237  return geom_set();
238  };
239  geom_set trigger_cell_det_ids;
240  // loop on the wafers included in the module
241  for(auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
242  {
243  // loop on the trigger cells in each wafer
244  for(int trigger_cell=0; trigger_cell<number_trigger_cells_in_wafers_.at(wafer_type); trigger_cell++)
245  {
246  trigger_cell_det_ids.emplace(HGCalDetId((ForwardSubdetector)module_det_id.subdetId(), module_det_id.zside(), module_det_id.layer(), module_det_id.waferType(), wafer_itr->second, trigger_cell).rawId());
247  }
248  }
249  return trigger_cell_det_ids;
250 }
251 
254 getOrderedTriggerCellsFromModule( const unsigned module_id ) const
255 {
256  HGCalDetId module_det_id(module_id);
257  unsigned module = module_det_id.wafer();
258  int wafer_type = module_det_id.waferType();
259  unsigned subdet = module_det_id.subdetId();
260  std::pair<std::unordered_multimap<short, short>::const_iterator,
261  std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
262  switch(subdet)
263  {
265  wafer_itrs = module_to_wafers_ee_.equal_range(module);
266  break;
268  wafer_itrs = module_to_wafers_fh_.equal_range(module);
269  break;
270  default:
271  edm::LogError("HGCalTriggerGeometry") << "Unknown module->wafers mapping for subdet "<<subdet<<"\n";
272  return geom_ordered_set();
273  };
274  geom_ordered_set trigger_cell_det_ids;
275  // loop on the wafers included in the module
276  for(auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
277  {
278  // loop on the trigger cells in each wafer
279  for(int trigger_cell=0; trigger_cell<number_trigger_cells_in_wafers_.at(wafer_type); trigger_cell++)
280  {
281  trigger_cell_det_ids.emplace(HGCalDetId((ForwardSubdetector)module_det_id.subdetId(), module_det_id.zside(), module_det_id.layer(), module_det_id.waferType(), wafer_itr->second, trigger_cell).rawId());
282  }
283  }
284  return trigger_cell_det_ids;
285 }
286 
287 
290 getTriggerCellPosition(const unsigned trigger_cell_det_id) const
291 {
292  // Position: barycenter of the trigger cell.
293  Basic3DVector<float> triggerCellVector(0.,0.,0.);
294  const auto cell_ids = getCellsFromTriggerCell(trigger_cell_det_id);
295  for(const auto& cell : cell_ids)
296  {
297  HGCalDetId cellDetId(cell);
298  triggerCellVector += (cellDetId.subdetId()==ForwardSubdetector::HGCEE ? es_info_.geom_ee->getPosition(cellDetId) : es_info_.geom_fh->getPosition(cellDetId)).basicVector();
299  }
300  return GlobalPoint( triggerCellVector/cell_ids.size() );
301 
302 }
303 
306 getModulePosition(const unsigned module_det_id) const
307 {
308  // Position: barycenter of the module.
309  Basic3DVector<float> moduleVector(0.,0.,0.);
310  const auto cell_ids = getCellsFromModule(module_det_id);
311  for(const auto& cell : cell_ids)
312  {
313  HGCalDetId cellDetId(cell);
314  moduleVector += (cellDetId.subdetId()==ForwardSubdetector::HGCEE ? es_info_.geom_ee->getPosition(cellDetId) : es_info_.geom_fh->getPosition(cellDetId)).basicVector();
315  }
316  return GlobalPoint( moduleVector/cell_ids.size() );
317 }
318 
319 
320 void
322 fillMaps(const es_info& esInfo)
323 {
324  //
325  // read module mapping file
326  std::ifstream l1tModulesMappingStream(l1tModulesMapping_.fullPath());
327  if(!l1tModulesMappingStream.is_open()) edm::LogError("HGCalTriggerGeometry") << "Cannot open L1TModulesMapping file\n";
328  short subdet = 0;
329  short wafer = 0;
330  short module = 0;
331  for(; l1tModulesMappingStream>>subdet>>wafer>>module; )
332  {
333  switch(subdet)
334  {
336  {
337  // fill module <-> wafers mappings
338  wafer_to_module_ee_.emplace(wafer,module);
339  module_to_wafers_ee_.emplace(module, wafer);
340  // fill number of cells for a given wafer type
341  // translate wafer type 1/2 to 1/-1
342  int wafer_type = esInfo.topo_ee->dddConstants().waferTypeT(wafer)==1?1:-1;
343  number_cells_in_wafers_.emplace(wafer_type, esInfo.topo_ee->dddConstants().numberCellsHexagon(wafer));
344  break;
345  }
347  {
348  // fill module <-> wafers mappings
349  wafer_to_module_fh_.emplace(wafer,module);
350  module_to_wafers_fh_.emplace(module, wafer);
351  // fill number of cells for a given wafer type
352  // translate wafer type 1/2 to 1/-1
353  int wafer_type = esInfo.topo_fh->dddConstants().waferTypeT(wafer)==1?1:-1;
354  number_cells_in_wafers_.emplace(wafer_type, esInfo.topo_fh->dddConstants().numberCellsHexagon(wafer));
355  break;
356  }
357  default:
358  edm::LogWarning("HGCalTriggerGeometry") << "Unsupported subdetector number ("<<subdet<<") in L1TModulesMapping file\n";
359  break;
360  }
361  }
362  if(!l1tModulesMappingStream.eof()) edm::LogWarning("HGCalTriggerGeometry") << "Error reading L1TModulesMapping '"<<wafer<<" "<<module<<"' \n";
363  l1tModulesMappingStream.close();
364  // read trigger cell mapping file
365  std::ifstream l1tCellsMappingStream(l1tCellsMapping_.fullPath());
366  if(!l1tCellsMappingStream.is_open()) edm::LogError("HGCalTriggerGeometry") << "Cannot open L1TCellsMapping file\n";
367  short waferType = 0;
368  short cell = 0;
369  short triggerCell = 0;
370  for(; l1tCellsMappingStream>>waferType>>cell>>triggerCell; )
371  {
372  // fill cell <-> trigger cell mappings
373  cells_to_trigger_cells_.emplace(std::make_pair((waferType?1:-1),cell), triggerCell);
374  trigger_cells_to_cells_.emplace(std::make_pair((waferType?1:-1),triggerCell), cell);
375  // fill number of cells for a given wafer type
376  auto itr_insert = number_trigger_cells_in_wafers_.emplace((waferType?1:-1), 0);
377  if(triggerCell+1 > itr_insert.first->second) itr_insert.first->second = triggerCell+1;
378  }
379  if(!l1tCellsMappingStream.eof()) edm::LogWarning("HGCalTriggerGeometry") << "Error reading L1TCellsMapping'"<<waferType<<" "<<cell<<" "<<triggerCell<<"' \n";
380  l1tCellsMappingStream.close();
381 }
382 
383 
384 
385 
388  "HGCalTriggerGeometryHexImp2");
virtual geom_set getCellsFromTriggerCell(const unsigned) const overridefinal
std::unordered_map< short, short > number_cells_in_wafers_
std::unordered_map< short, short > number_trigger_cells_in_wafers_
virtual geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned) const overridefinal
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::unordered_multimap< short, short > module_to_wafers_fh_
ForwardSubdetector
virtual unsigned getModuleFromCell(const unsigned) const overridefinal
static const int kHGCalCellMask
Definition: HGCalDetId.h:13
virtual GlobalPoint getModulePosition(const unsigned) const overridefinal
int zside() const
get the z-side of the cell (1/-1)
Definition: HGCalDetId.h:51
virtual geom_set getCellsFromModule(const unsigned) const overridefinal
edm::ESHandle< HGCalGeometry > geom_ee
virtual geom_set getTriggerCellsFromModule(const unsigned) const overridefinal
edm::ESHandle< HGCalGeometry > geom_fh
std::unordered_multimap< short, short > module_to_wafers_ee_
int wafer() const
get the wafer #
Definition: HGCalDetId.h:42
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
virtual unsigned getModuleFromTriggerCell(const unsigned) const overridefinal
std::unordered_map< short, short > wafer_to_module_ee_
virtual GlobalPoint getTriggerCellPosition(const unsigned) const overridefinal
virtual geom_ordered_set getOrderedCellsFromModule(const unsigned) const overridefinal
int cell() const
get the absolute value of the cell #&#39;s in x and y
Definition: HGCalDetId.h:39
std::unordered_map< short, short > wafer_to_module_fh_
std::set< unsigned > geom_ordered_set
std::unordered_set< unsigned > geom_set
virtual unsigned getTriggerCellFromCell(const unsigned) const overridefinal
virtual void initialize(const es_info &) overridefinal
int waferType() const
get the wafer type
Definition: HGCalDetId.h:45
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::map< std::pair< short, short >, short > cells_to_trigger_cells_
std::string fullPath() const
Definition: FileInPath.cc:184
std::multimap< std::pair< short, short >, short > trigger_cells_to_cells_
Definition: vlib.h:208
int layer() const
get the layer #
Definition: HGCalDetId.h:48
HGCalTriggerGeometryHexImp2(const edm::ParameterSet &conf)