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