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