CMS 3D CMS Logo

HGCalTriggerGeometryImp1.cc
Go to the documentation of this file.
2 
6 
7 #include <vector>
8 #include <iostream>
9 #include <fstream>
10 
12 public:
14 
15  void initialize(const edm::ESHandle<CaloGeometry>&) final;
18  const edm::ESHandle<HGCalGeometry>&) final;
19 
20 private:
22 
23  void buildMaps();
24 };
25 
26 /*****************************************************************/
29  l1tCellsMapping_(conf.getParameter<edm::FileInPath>("L1TCellsMapping"))
30 /*****************************************************************/
31 {}
32 
33 /*****************************************************************/
35 /*****************************************************************/
36 {
37  // FIXME: !!!Only for HGCEE for the moment!!!
38  edm::LogWarning("HGCalTriggerGeometry") << "WARNING: This HGCal trigger geometry is incomplete.\n"
39  << "WARNING: Only the EE part is covered.\n"
40  << "WARNING: There is no neighbor information.\n";
41  setCaloGeometry(calo_geometry);
42 }
43 
44 /*****************************************************************/
46  const edm::ESHandle<HGCalGeometry>& hgc_hsi_geometry,
47  const edm::ESHandle<HGCalGeometry>& hgc_hsc_geometry)
48 /*****************************************************************/
49 {
50  throw cms::Exception("BadGeometry")
51  << "HGCalTriggerGeometryImp1 geometry cannot be initialized with the V9 HGCAL geometry";
52 }
53 
54 /*****************************************************************/
56 /*****************************************************************/
57 {
58  //
59  // read trigger cell mapping file
60  std::ifstream l1tCellsMappingStream(l1tCellsMapping_.fullPath());
61  if (!l1tCellsMappingStream.is_open())
62  edm::LogError("HGCalTriggerGeometry") << "Cannot open L1TCellsMapping file\n";
63  short layer = 0;
64  short subsector = 0;
65  short cell = 0;
66  short module = 0;
67  short triggercell = 0;
68  for (; l1tCellsMappingStream >> layer >> subsector >> cell >> module >> triggercell;) {
69  if (layer > 30 || layer <= 0) {
70  edm::LogWarning("HGCalTriggerGeometry") << "Bad layer index in L1TCellsMapping\n";
71  continue;
72  }
73  // Loop on all sectors
74  // FIXME: Number of sectors in each zside should not be hardcoded
75  for (unsigned z = 0; z <= 1; z++) {
76  int zside = (z == 0 ? -1 : 1);
77  for (unsigned sector = 1; sector <= 18; sector++) {
78  HGCEEDetId detid(HGCEE, zside, layer, sector, subsector, cell);
79  //
80  // Fill cell -> trigger cell mapping
81  HGCTriggerDetId triggerDetid(HGCTrigger, zside, layer, sector, module, triggercell);
82  const auto& ret = cells_to_trigger_cells_.insert(std::make_pair(detid, triggerDetid));
83  if (!ret.second)
84  edm::LogWarning("HGCalTriggerGeometry") << "Duplicate cell in L1TCellsMapping\n";
85  // Fill trigger cell -> module mapping
86  HGCTriggerDetId moduleDetid(HGCTrigger, zside, layer, sector, module, HGCTriggerDetId::UndefinedCell());
88  std::make_pair(triggerDetid, moduleDetid)); // do nothing if trigger cell has already been inserted
89  }
90  }
91  }
92  if (!l1tCellsMappingStream.eof())
93  edm::LogWarning("HGCalTriggerGeometry")
94  << "Error reading L1TCellsMapping'" << layer << " " << cell << " " << triggercell << " " << subsector << "' \n";
95  l1tCellsMappingStream.close();
96  //
97  // Build trigger cells and fill map
99  // make list of cells in trigger cells
100  std::map<unsigned, list_cells> trigger_cells_to_cells;
101  for (const auto& cell_triggercell : cells_to_trigger_cells_) {
102  unsigned cell = cell_triggercell.first;
103  unsigned triggercell = cell_triggercell.second;
104  trigger_cells_to_cells.insert(std::make_pair(triggercell, list_cells()));
105  trigger_cells_to_cells.at(triggercell).insert(cell);
106  }
107  for (const auto& triggercell_cells : trigger_cells_to_cells) {
108  unsigned triggercellId = triggercell_cells.first;
109  list_cells cellIds = triggercell_cells.second;
110  // Position: for the moment, barycenter of the trigger cell.
111  Basic3DVector<float> triggercellVector(0., 0., 0.);
112  for (const auto& cell : cellIds) {
113  HGCTriggerDetId cellId(cell);
114  triggercellVector += eeGeometry()->getPosition(cellId).basicVector();
115  }
116  GlobalPoint triggercellPoint(triggercellVector / cellIds.size());
117  const auto& tc2mItr = trigger_cells_to_modules_.find(triggercellId);
118  unsigned moduleId =
119  (tc2mItr != trigger_cells_to_modules_.end() ? tc2mItr->second
120  : 0); // 0 if the trigger cell doesn't belong to a module
121  //unsigned moduleId = trigger_cells_to_modules_.at(triggercellId);
122  // FIXME: empty neighbours
123  std::unique_ptr<const HGCalTriggerGeometry::TriggerCell> triggercellPtr(
124  new HGCalTriggerGeometry::TriggerCell(triggercellId, moduleId, triggercellPoint, list_cells(), cellIds));
125  trigger_cells_.insert(std::make_pair(triggercellId, std::move(triggercellPtr)));
126  }
127  //
128  // Build modules and fill map
129  typedef HGCalTriggerGeometry::Module::list_type list_triggercells;
130  typedef HGCalTriggerGeometry::Module::tc_map_type tc_map_to_cells;
131  // make list of trigger cells in modules
132  std::map<unsigned, list_triggercells> modules_to_trigger_cells;
133  for (const auto& triggercell_module : trigger_cells_to_modules_) {
134  unsigned triggercell = triggercell_module.first;
135  unsigned module = triggercell_module.second;
136  modules_to_trigger_cells.insert(std::make_pair(module, list_triggercells()));
137  modules_to_trigger_cells.at(module).insert(triggercell);
138  }
139  for (const auto& module_triggercell : modules_to_trigger_cells) {
140  unsigned moduleId = module_triggercell.first;
141  list_triggercells triggercellIds = module_triggercell.second;
142  tc_map_to_cells cellsInTriggerCells;
143  // Position: for the moment, barycenter of the module, from trigger cell positions
144  Basic3DVector<float> moduleVector(0., 0., 0.);
145  for (const auto& triggercell : triggercellIds) {
146  const auto& cells_in_tc = trigger_cells_to_cells[triggercell];
147  for (const unsigned cell : cells_in_tc) {
148  cellsInTriggerCells.emplace(triggercell, cell);
149  }
150  moduleVector += trigger_cells_.at(triggercell)->position().basicVector();
151  }
152  GlobalPoint modulePoint(moduleVector / triggercellIds.size());
153  // FIXME: empty neighbours
154  std::unique_ptr<const HGCalTriggerGeometry::Module> modulePtr(new HGCalTriggerGeometry::Module(
155  moduleId, modulePoint, list_triggercells(), triggercellIds, cellsInTriggerCells));
156  modules_.insert(std::make_pair(moduleId, std::move(modulePtr)));
157  }
158 }
159 
std::unordered_set< unsigned > list_type
std::unordered_multimap< unsigned, unsigned > tc_map_type
const HGCalGeometry * eeGeometry() const
GlobalPoint getPosition(const DetId &id) const
int zside(DetId const &)
void initialize(const edm::ESHandle< CaloGeometry > &) final
HGCalTriggerGeometryImp1(const edm::ParameterSet &conf)
void setCaloGeometry(const edm::ESHandle< CaloGeometry > &geom)
static const uint32_t UndefinedCell()
HLT enums.
std::string fullPath() const
Definition: FileInPath.cc:163
#define DEFINE_EDM_PLUGIN(factory, type, name)
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
Definition: vlib.h:208
def move(src, dest)
Definition: eostools.py:511