CMS 3D CMS Logo

HGCalTriggerGeometryHexImp1.cc
Go to the documentation of this file.
2 
5 
6 #include <vector>
7 #include <iostream>
8 #include <fstream>
9 
11 
13 {
14  public:
16 
17  void initialize(const edm::ESHandle<CaloGeometry>& ) final;
18 
19  private:
22 
23  void fillMaps();
25 };
26 
27 
28 /*****************************************************************/
31  l1tCellsMapping_(conf.getParameter<edm::FileInPath>("L1TCellsMapping")),
32  l1tModulesMapping_(conf.getParameter<edm::FileInPath>("L1TModulesMapping"))
33 /*****************************************************************/
34 {
35 }
36 
37 
38 /*****************************************************************/
40 /*****************************************************************/
41 {
42  edm::LogWarning("HGCalTriggerGeometry") << "WARNING: This HGCal trigger geometry is incomplete.\n"\
43  << "WARNING: There is no neighbor information.\n";
44 
45  setCaloGeometry(calo_geometry);
46  fillMaps();
48 
49 }
50 
51 
52 
53 /*****************************************************************/
55 /*****************************************************************/
56 {
57  //
58  // read module mapping file
59  std::unordered_map<short, short> wafer_to_module_ee;
60  std::unordered_map<short, short> wafer_to_module_fh;
61  std::unordered_map<short, std::map<short,short>> module_to_wafers_ee;
62  std::unordered_map<short, std::map<short,short>> module_to_wafers_fh;
63  std::ifstream l1tModulesMappingStream(l1tModulesMapping_.fullPath());
64  if(!l1tModulesMappingStream.is_open()) edm::LogError("HGCalTriggerGeometry") << "Cannot open L1TModulesMapping file\n";
65  short subdet = 0;
66  short wafer = 0;
67  short module = 0;
68  for(; l1tModulesMappingStream>>subdet>>wafer>>module; )
69  {
70  if(subdet==3)
71  {
72  wafer_to_module_ee.emplace(wafer,module);
73  auto itr_insert = module_to_wafers_ee.emplace(module, std::map<short,short>());
74  itr_insert.first->second.emplace(wafer, 0);
75  }
76  else if(subdet==4)
77  {
78  wafer_to_module_fh.emplace(wafer,module);
79  auto itr_insert = module_to_wafers_fh.emplace(module, std::map<short,short>());
80  itr_insert.first->second.emplace(wafer, 0);
81  }
82  else edm::LogWarning("HGCalTriggerGeometry") << "Unsupported subdetector number ("<<subdet<<") in L1TModulesMapping file\n";
83  }
84  if(!l1tModulesMappingStream.eof()) edm::LogWarning("HGCalTriggerGeometry") << "Error reading L1TModulesMapping '"<<wafer<<" "<<module<<"' \n";
85  l1tModulesMappingStream.close();
86  // read trigger cell mapping file
87  std::map<std::pair<short,short>, short> cells_to_trigger_cells;
88  std::unordered_map<short, short> number_trigger_cells_in_wafers; // the map key is the wafer type
89  std::ifstream l1tCellsMappingStream(l1tCellsMapping_.fullPath());
90  if(!l1tCellsMappingStream.is_open()) edm::LogError("HGCalTriggerGeometry") << "Cannot open L1TCellsMapping file\n";
91  short waferType = 0;
92  short cell = 0;
93  short triggerCell = 0;
94  for(; l1tCellsMappingStream>>waferType>>cell>>triggerCell; )
95  {
96  cells_to_trigger_cells.emplace(std::make_pair((waferType?1:-1),cell), triggerCell);
97  auto itr_insert = number_trigger_cells_in_wafers.emplace((waferType?1:-1), 0);
98  if(triggerCell+1 > itr_insert.first->second) itr_insert.first->second = triggerCell+1;
99  }
100  if(!l1tCellsMappingStream.eof()) edm::LogWarning("HGCalTriggerGeometry") << "Error reading L1TCellsMapping'"<<waferType<<" "<<cell<<" "<<triggerCell<<"' \n";
101  l1tCellsMappingStream.close();
102  // For each wafer compute the trigger cell offset according to the wafer position inside
103  // the module. The first wafer will have an offset equal to 0, the second an offset equal to the
104  // number of trigger cells in the first wafer, etc.
105  short offset = 0;
106  for(auto& module_wafers : module_to_wafers_ee)
107  {
108  offset = 0;
109  for(auto& wafer_offset : module_wafers.second)
110  {
111  wafer_offset.second = offset;
112  int wafer_type = (eeTopology().dddConstants().waferTypeT(wafer_offset.first)==1?1:-1);
113  offset += number_trigger_cells_in_wafers.at(wafer_type);
114  }
115  }
116  for(auto& module_wafers : module_to_wafers_fh)
117  {
118  offset = 0;
119  for(auto& wafer_offset : module_wafers.second)
120  {
121  wafer_offset.second = offset;
122  int wafer_type = (fhTopology().dddConstants().waferTypeT(wafer_offset.first)==1?1:-1);
123  offset += number_trigger_cells_in_wafers.at(wafer_type);
124  }
125  }
126  //
127  // Loop over HGC cells
128  // EE
129  for(const auto& id : eeGeometry()->getValidGeomDetIds())
130  {
131  if(id.rawId()==0) continue;
132  HGCalDetId waferDetId(id);
133  short module = wafer_to_module_ee[waferDetId.wafer()];
134  short triggercell_offset = module_to_wafers_ee.at(module).at(waferDetId.wafer());
135  int nCells = eeTopology().dddConstants().numberCellsHexagon(waferDetId.wafer());
136  for(int c=0;c<nCells;c++)
137  {
138  short triggerCellId = cells_to_trigger_cells[std::make_pair(waferDetId.waferType(),c)];
139  // Fill cell -> trigger cell mapping
140  HGCalDetId cellDetId(ForwardSubdetector(waferDetId.subdetId()), waferDetId.zside(), waferDetId.layer(), waferDetId.waferType(), waferDetId.wafer(), c);
141  // The module id is used instead of the wafer id for the trigger cells
142  // Since there are several wafers per module, an offset is applied on the HGCalDetId::cell field
143  if(triggercell_offset+triggerCellId >= HGCalDetId::kHGCalCellMask) edm::LogError("HGCalTriggerGeometry") << "Trigger cell id requested with a cell field larger than available in HGCalDetId (" << triggercell_offset+triggerCellId << " >= " << HGCalDetId::kHGCalCellMask << ")\n";
144  HGCalDetId triggerCellDetId(ForwardSubdetector(waferDetId.subdetId()), waferDetId.zside(), waferDetId.layer(), waferDetId.waferType(), module, triggercell_offset + triggerCellId);
145  cells_to_trigger_cells_.emplace(cellDetId, triggerCellDetId);
146  // Fill trigger cell -> module mapping
147  HGCalDetId moduleDetId(ForwardSubdetector(waferDetId.subdetId()), waferDetId.zside(), waferDetId.layer(), waferDetId.waferType(), module, HGCalDetId::kHGCalCellMask);
148  trigger_cells_to_modules_.emplace(triggerCellDetId, moduleDetId);
149  }
150  }
151  // FH
152  for(const auto& id : fhGeometry()->getValidGeomDetIds())
153  {
154  if(id.rawId()==0) continue;
155  HGCalDetId waferDetId(id);
156  short module = wafer_to_module_fh[waferDetId.wafer()];
157  short triggercell_offset = module_to_wafers_fh.at(module).at(waferDetId.wafer());
158  int nCells = fhTopology().dddConstants().numberCellsHexagon(waferDetId.wafer());
159  for(int c=0;c<nCells;c++)
160  {
161  short triggerCellId = cells_to_trigger_cells[std::make_pair(waferDetId.waferType(),c)];
162  // Fill cell -> trigger cell mapping
163  HGCalDetId cellDetId(ForwardSubdetector(waferDetId.subdetId()), waferDetId.zside(), waferDetId.layer(), waferDetId.waferType(), waferDetId.wafer(), c);
164  // The module id is used instead of the wafer id for the trigger cells
165  // Since there are several wafers per module, an offset is applied on the HGCalDetId::cell field
166  if(triggercell_offset+triggerCellId >= HGCalDetId::kHGCalCellMask) edm::LogError("HGCalTriggerGeometry") << "Trigger cell id requested with a cell field larger than available in HGCalDetId (" << triggercell_offset+triggerCellId << " >= " << HGCalDetId::kHGCalCellMask << ")\n";
167  HGCalDetId triggerCellDetId(ForwardSubdetector(waferDetId.subdetId()), waferDetId.zside(), waferDetId.layer(), waferDetId.waferType(), module, triggercell_offset + triggerCellId);
168  cells_to_trigger_cells_.emplace(cellDetId, triggerCellDetId);
169  // Fill trigger cell -> module mapping
170  HGCalDetId moduleDetId(ForwardSubdetector(waferDetId.subdetId()), waferDetId.zside(), waferDetId.layer(), waferDetId.waferType(), module, HGCalDetId::kHGCalCellMask);
171  trigger_cells_to_modules_.emplace(triggerCellDetId, moduleDetId);
172  }
173  }
174 }
175 
176 
177 
178 /*****************************************************************/
180 /*****************************************************************/
181 {
182  //
183  // Build trigger cells and fill map
185  // make list of cells in trigger cells
186  std::unordered_map<unsigned, list_cells> trigger_cells_to_cells;
187  for(const auto& cell_triggerCell : cells_to_trigger_cells_)
188  {
189  unsigned cell = cell_triggerCell.first;
190  unsigned triggerCell = cell_triggerCell.second;
191  auto itr_exist = trigger_cells_to_cells.emplace(triggerCell, list_cells());
192  itr_exist.first->second.emplace(cell);
193  //trigger_cells_to_cells.at(triggerCell).emplace(cell);
194  }
195  for(const auto& triggerCell_cells : trigger_cells_to_cells)
196  {
197  unsigned triggerCellId = triggerCell_cells.first;
198  list_cells cellIds = triggerCell_cells.second;
199  // Position: barycenter of the trigger cell.
200  Basic3DVector<float> triggerCellVector(0.,0.,0.);
201  for(const auto& cell : cellIds)
202  {
203  HGCalDetId cellDetId(cell);
204  triggerCellVector += (cellDetId.subdetId()==ForwardSubdetector::HGCEE ? eeGeometry()->getPosition(cellDetId) : fhGeometry()->getPosition(cellDetId)).basicVector();
205  }
206  GlobalPoint triggerCellPoint( triggerCellVector/cellIds.size() );
207  const auto& triggerCellToModuleItr = trigger_cells_to_modules_.find(triggerCellId);
208  unsigned moduleId = (triggerCellToModuleItr!=trigger_cells_to_modules_.end() ? triggerCellToModuleItr->second : 0); // 0 if the trigger cell doesn't belong to a module
209  //unsigned moduleId = trigger_cells_to_modules_.at(triggercellId);
210  // FIXME: empty neighbours
211  trigger_cells_.emplace(triggerCellId, std::make_unique<const HGCalTriggerGeometry::TriggerCell>(triggerCellId, moduleId, triggerCellPoint, list_cells(), cellIds));
212  }
213  //
214  // Build modules and fill map
215  typedef HGCalTriggerGeometry::Module::list_type list_triggerCells;
216  typedef HGCalTriggerGeometry::Module::tc_map_type tc_map_to_cells;
217  // make list of trigger cells in modules
218  std::unordered_map<unsigned, list_triggerCells> modules_to_trigger_cells;
219  for(const auto& triggerCell_module : trigger_cells_to_modules_)
220  {
221  unsigned triggerCell = triggerCell_module.first;
222  unsigned module = triggerCell_module.second;
223  auto itr_exist = modules_to_trigger_cells.emplace(module, list_triggerCells());
224  itr_exist.first->second.emplace(triggerCell);
225  //modules_to_trigger_cells.at(module).emplace(triggerCell);
226  }
227  for(const auto& module_triggerCell : modules_to_trigger_cells)
228  {
229  unsigned moduleId = module_triggerCell.first;
230  list_triggerCells triggerCellIds = module_triggerCell.second;
231  tc_map_to_cells cellsInTriggerCells;
232  // Position: barycenter of the module, from trigger cell positions
233  Basic3DVector<float> moduleVector(0.,0.,0.);
234  for(const auto& triggerCell : triggerCellIds)
235  {
236  const auto& cells_in_tc = trigger_cells_to_cells.at(triggerCell);
237  for( const unsigned cell : cells_in_tc )
238  {
239  cellsInTriggerCells.emplace(triggerCell,cell);
240  }
241  moduleVector += trigger_cells_.at(triggerCell)->position().basicVector();
242  }
243  GlobalPoint modulePoint( moduleVector/triggerCellIds.size() );
244  // FIXME: empty neighbours
245  modules_.emplace(moduleId, std::make_unique<const HGCalTriggerGeometry::Module>(moduleId, modulePoint, list_triggerCells(), triggerCellIds, cellsInTriggerCells));
246  }
247 }
248 
249 
252  "HGCalTriggerGeometryHexImp1");
std::unordered_set< unsigned > list_type
const HGCalGeometry * eeGeometry() const
const HGCalTopology & eeTopology() const
GlobalPoint getPosition(const DetId &id) const
ForwardSubdetector
void initialize(const edm::ESHandle< CaloGeometry > &) final
static const int kHGCalCellMask
Definition: HGCalDetId.h:13
int zside() const
get the z-side of the cell (1/-1)
Definition: HGCalDetId.h:51
int numberCellsHexagon(int wafer) const
const HGCalGeometry * fhGeometry() const
std::unordered_multimap< unsigned, unsigned > tc_map_type
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
void setCaloGeometry(const edm::ESHandle< CaloGeometry > &geom)
const HGCalDDDConstants & dddConstants() const
HLT enums.
std::string fullPath() const
Definition: FileInPath.cc:184
int waferType() const
get the wafer type
Definition: HGCalDetId.h:45
#define DEFINE_EDM_PLUGIN(factory, type, name)
HGCalTriggerGeometryHexImp1(const edm::ParameterSet &conf)
int waferTypeT(int wafer) const
Definition: vlib.h:208
const HGCalTopology & fhTopology() const
int layer() const
get the layer #
Definition: HGCalDetId.h:48