CMS 3D CMS Logo

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