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