18 virtual void initialize(
const es_info& )
override final;
19 virtual void reset()
override final;
81 bool validCellId(
unsigned subdet,
unsigned cell_id)
const;
126 int wafer_type = cell_det_id.
waferType();
127 unsigned cell = cell_det_id.
cell();
133 <<
"HGCalTriggerGeometry: HGCal cell " << cell <<
" is not mapped to any trigger cell for the wafer type " << wafer_type
134 <<
". The trigger cell mapping should be modified.\n";
136 unsigned trigger_cell = trigger_cell_itr->second;
145 unsigned wafer = cell_det_id.
wafer();
146 unsigned subdet = cell_det_id.
subdetId();
147 std::unordered_map<short, short>::const_iterator module_itr;
148 bool out_of_range_error =
false;
160 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer->module mapping for subdet "<<subdet<<
"\n";
163 if(out_of_range_error)
166 <<
"HGCalTriggerGeometry: Wafer " << wafer <<
" is not mapped to any trigger module for subdetector " << subdet
167 <<
". The module mapping should be modified. See https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for details.\n";
169 unsigned module = module_itr->second;
177 HGCalDetId trigger_cell_det_id(trigger_cell_id);
178 unsigned wafer = trigger_cell_det_id.
wafer();
179 unsigned subdet = trigger_cell_det_id.
subdetId();
180 std::unordered_map<short, short>::const_iterator module_itr;
181 bool out_of_range_error =
false;
193 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer->module mapping for subdet "<<subdet<<
"\n";
196 if(out_of_range_error)
199 <<
"HGCalTriggerGeometry: Wafer " << wafer <<
" is not mapped to any trigger module for subdetector " << subdet
200 <<
". The module mapping should be modified. See https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for details.\n";
202 unsigned module = module_itr->second;
210 HGCalDetId trigger_cell_det_id(trigger_cell_id);
211 int wafer_type = trigger_cell_det_id.
waferType();
212 unsigned trigger_cell = trigger_cell_det_id.
cell();
216 for(
auto tc_c_itr=cell_range.first; tc_c_itr!=cell_range.second; tc_c_itr++)
230 unsigned subdet = module_det_id.
subdetId();
231 std::pair<std::unordered_multimap<short, short>::const_iterator,
232 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
242 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
246 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
249 if(wafer_type==0) wafer_type = module_det_id.
waferType();
254 if(
validCellId(subdet, cell_id)) cell_det_ids.emplace(cell_id.rawId());
266 unsigned subdet = module_det_id.
subdetId();
267 std::pair<std::unordered_multimap<short, short>::const_iterator,
268 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
278 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
282 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
285 if(wafer_type==0) wafer_type = module_det_id.
waferType();
290 if(
validCellId(subdet, cell_id)) cell_det_ids.emplace(cell_id.rawId());
302 unsigned subdet = module_det_id.
subdetId();
303 std::pair<std::unordered_multimap<short, short>::const_iterator,
304 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
314 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
319 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
322 if(wafer_type==0) wafer_type = module_det_id.
waferType();
327 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
330 return trigger_cell_det_ids;
339 unsigned subdet = module_det_id.
subdetId();
340 std::pair<std::unordered_multimap<short, short>::const_iterator,
341 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
351 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
356 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
359 if(wafer_type==0) wafer_type = module_det_id.
waferType();
364 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
367 return trigger_cell_det_ids;
376 HGCalDetId trigger_cell_det_id(trigger_cell_id);
377 unsigned wafer = trigger_cell_det_id.
wafer();
378 int wafer_type = trigger_cell_det_id.
waferType();
379 unsigned subdet = trigger_cell_det_id.
subdetId();
380 unsigned trigger_cell = trigger_cell_det_id.
cell();
383 std::unordered_map<short, std::vector<short>>::const_iterator surrounding_wafers_itr;
384 bool out_of_range_error =
false;
396 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer neighbours for subdet "<<subdet<<
"\n";
399 if(out_of_range_error)
402 <<
"HGCalTriggerGeometry: Neighbors are not defined for wafer " << wafer <<
" in subdetector " << subdet
403 <<
". The wafer neighbor mapping should be modified. \n";
405 const std::vector<short>& surrounding_wafers = surrounding_wafers_itr->second;
407 std::vector<int>
types;
408 types.reserve(surrounding_wafers.size()+1);
409 types.emplace_back(wafer_type);
410 for(
const auto w : surrounding_wafers)
417 types.emplace_back(wt);
426 <<
"HGCalTriggerGeometry: Neighbors are not defined for trigger cell " << trigger_cell <<
" with wafer configuration " 427 << std::bitset<7>(trigger_cell_key >> 8) <<
". The trigger cell neighbor mapping should be modified. \n";
429 const auto& neighbors = neighbors_itr->second;
431 neighbor_detids.reserve(neighbors.size());
432 for(
const auto& wafer_tc : neighbors)
434 if(wafer_tc.first-1>=(
int)surrounding_wafers.size())
437 <<
"HGCalTriggerGeometry: Undefined wafer neighbor number "<<wafer_tc.first
438 <<
" for wafer " << wafer <<
" and trigger cell " << trigger_cell
439 <<
". The neighbor mapping files should be modified.";
441 int neighbor_wafer = (wafer_tc.first==0 ? wafer : surrounding_wafers.at(wafer_tc.first-1));
442 if(neighbor_wafer==-1)
continue;
443 int type = types.at(wafer_tc.first);
447 neighbor_detids.emplace(neighbor_det_id.rawId());
450 return neighbor_detids;
461 for(
const auto& cell : cell_ids)
466 return GlobalPoint( triggerCellVector/cell_ids.size() );
477 for(
const auto& cell : cell_ids)
482 return GlobalPoint( moduleVector/cell_ids.size() );
493 if(!l1tModulesMappingStream.is_open())
edm::LogError(
"HGCalTriggerGeometry") <<
"Cannot open L1TModulesMapping file\n";
497 for(; l1tModulesMappingStream>>subdet>>wafer>>
module; )
521 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Unsupported subdetector number ("<<subdet<<
") in L1TModulesMapping file\n";
525 if(!l1tModulesMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TModulesMapping '"<<wafer<<
" "<<module<<
"' \n";
526 l1tModulesMappingStream.close();
529 if(!l1tCellsMappingStream.is_open())
edm::LogError(
"HGCalTriggerGeometry") <<
"Cannot open L1TCellsMapping file\n";
532 short triggerCell = 0;
533 for(; l1tCellsMappingStream>>waferType>>cell>>triggerCell; )
540 if(triggerCell+1 > itr_insert.first->second) itr_insert.first->second = triggerCell+1;
542 if(!l1tCellsMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellsMapping'"<<waferType<<
" "<<cell<<
" "<<triggerCell<<
"' \n";
543 l1tCellsMappingStream.close();
552 if(!l1tCellNeighborsMappingStream.is_open())
edm::LogError(
"HGCalTriggerGeometry") <<
"Cannot open L1TCellNeighborsMapping file\n";
553 for(std::array<char,512>
buffer; l1tCellNeighborsMappingStream.getline(&
buffer[0], 512); )
561 std::regex key_regex(
"\\(\\s*[01]{7}\\s*,\\s*\\d{1,3}\\s*\\)");
562 std::vector<std::string> key_tokens {
563 std::sregex_token_iterator(line.begin(), line.end(), key_regex), {}
565 if(key_tokens.size()!=1)
568 <<
"Syntax error in the L1TCellNeighborsMapping:\n" 569 <<
" Cannot find the trigger cell key in line:\n" 570 <<
" '"<<&
buffer[0]<<
"'\n";
572 std::regex digits_regex(
"([01]{7})|(\\d{1,3})");
573 std::vector<std::string> type_tc {
574 std::sregex_token_iterator(key_tokens[0].
begin(), key_tokens[0].
end(), digits_regex), {}
577 int trigger_cell = std::stoi(type_tc[1]);
578 std::vector<int> wafer_types;
579 wafer_types.reserve(type_tc[0].
size());
581 for(
const char c : type_tc[0]) wafer_types.emplace_back( (std::stoi(
std::string(&
c))?1:-1) );
587 std::regex neighbors_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d\\s*\\)");
588 std::vector<std::string> neighbors_tokens {
589 std::sregex_token_iterator(line.begin(), line.end(), neighbors_regex), {}
591 if(neighbors_tokens.size()==0)
594 <<
"Syntax error in the L1TCellNeighborsMapping:\n" 595 <<
" Cannot find any neighbor in line:\n" 596 <<
" '"<<&
buffer[0]<<
"'\n";
599 for(
const auto&
neighbor : neighbors_tokens)
601 std::vector<std::string> pair_neighbor {
602 std::sregex_token_iterator(
neighbor.begin(),
neighbor.end(), digits_regex), {}
604 short neighbor_wafer(std::stoi(pair_neighbor[1]));
605 short neighbor_cell(std::stoi(pair_neighbor[0]));
606 itr_insert.first->second.emplace(neighbor_wafer, neighbor_cell);
609 if(!l1tCellNeighborsMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellNeighborsMapping'\n";
610 l1tCellNeighborsMappingStream.close();
614 if(!l1tWaferNeighborsMappingStream.is_open())
edm::LogError(
"HGCalTriggerGeometry") <<
"Cannot open L1TWaferNeighborsMapping file\n";
615 for(std::array<char,512>
buffer; l1tWaferNeighborsMappingStream.getline(&
buffer[0], 512); )
620 std::vector<std::string> tokens {
621 std::sregex_token_iterator(line.begin(), line.end(),
delimiter, -1), {}
626 <<
"Syntax error in the L1TWaferNeighborsMapping in line:\n" 627 <<
" '"<<&
buffer[0]<<
"'\n" 628 <<
" A line should be composed of 8 integers separated by spaces:\n" 629 <<
" subdet waferid neighbor1 neighbor2 neighbor3 neighbor4 neighbor5 neighbor6\n";
631 short subdet(std::stoi(tokens[0]));
632 short wafer(std::stoi(tokens[1]));
634 std::unordered_map<short, std::vector<short>>* wafer_neighbors;
645 <<
"Unknown subdet " << subdet <<
" in L1TWaferNeighborsMapping:\n" 646 <<
" '"<<&
buffer[0]<<
"'\n";
648 auto wafer_itr = wafer_neighbors->emplace(wafer, std::vector<short>());
649 for(
auto neighbor_itr=tokens.cbegin()+2; neighbor_itr!=tokens.cend(); ++neighbor_itr)
651 wafer_itr.first->second.emplace_back(std::stoi(*neighbor_itr));
662 for(
unsigned layer=1; layer<=n_layers_ee; layer++)
666 unsigned wafer = wafer_module.first;
679 for(
unsigned layer=1; layer<=n_layers_fh; layer++)
683 unsigned wafer = wafer_module.first;
701 unsigned packed_value = trigger_cell;
702 for(
unsigned i=0;
i<wafer_types.size();
i++)
706 if(wafer_types.at(
i)==1) packed_value += (0x1<<(8+
i));
749 HGCalDetId trigger_cell_det_id(trigger_cell_id);
750 unsigned subdet = trigger_cell_det_id.
subdetId();
753 for(
const auto cell_id : cells)
786 "HGCalTriggerGeometryHexImp2");
virtual geom_set getCellsFromTriggerCell(const unsigned) const override final
edm::FileInPath l1tWaferNeighborsMapping_
std::unordered_map< short, short > number_cells_in_wafers_
std::unordered_map< short, short > number_trigger_cells_in_wafers_
bool is_valid(const Digi &d)
void fillInvalidTriggerCells(const es_info &)
edm::ESHandle< HGCalTopology > topo_ee
virtual GlobalPoint getModulePosition(const unsigned) const override final
edm::FileInPath l1tModulesMapping_
Global3DPoint GlobalPoint
unsigned packTriggerCell(unsigned, const std::vector< int > &) const
virtual geom_ordered_set getOrderedCellsFromModule(const unsigned) const override final
GlobalPoint getPosition(const DetId &id) const
std::unordered_multimap< short, short > module_to_wafers_fh_
bool neighbor(int endcap, int sector, int SectIndex, int id, int sub, int station)
std::unordered_set< unsigned > invalid_triggercells_
edm::FileInPath l1tCellsMapping_
virtual void initialize(const es_info &) override final
uint32_t rawId() const
get the raw id
bool validCellId(unsigned subdet, unsigned cell_id) const
static const int kHGCalCellMask
unsigned int layers(bool reco) const
int zside() const
get the z-side of the cell (1/-1)
std::unordered_map< short, std::vector< short > > wafer_neighbors_fh_
edm::ESHandle< HGCalGeometry > geom_ee
std::unordered_map< short, std::vector< short > > wafer_neighbors_ee_
virtual bool valid(const DetId &id) const
Is this a valid cell id.
edm::ESHandle< HGCalGeometry > geom_fh
virtual void reset() override final
std::unordered_multimap< short, short > module_to_wafers_ee_
virtual GlobalPoint getTriggerCellPosition(const unsigned) const override final
int wafer() const
get the wafer #
virtual unsigned getTriggerCellFromCell(const unsigned) const override final
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
virtual geom_set getNeighborsFromTriggerCell(const unsigned) const override final
edm::ESHandle< HGCalTopology > topo_fh
std::unordered_map< short, short > wafer_to_module_ee_
void fillNeighborMaps(const es_info &)
int cell() const
get the absolute value of the cell #'s in x and y
const HGCalDDDConstants & dddConstants() const
virtual unsigned getModuleFromCell(const unsigned) const override final
std::unordered_map< short, short > wafer_to_module_fh_
std::set< unsigned > geom_ordered_set
void fillMaps(const es_info &)
virtual geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned) const override final
std::unordered_set< unsigned > geom_set
virtual geom_set getTriggerCellsFromModule(const unsigned) const override final
int detIdWaferType(unsigned subdet, short wafer) const
int waferType() const
get the wafer type
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::map< std::pair< short, short >, short > cells_to_trigger_cells_
virtual bool validTriggerCell(const unsigned) const override final
std::unordered_map< int, std::set< std::pair< short, short > > > trigger_cell_neighbors_
virtual unsigned getModuleFromTriggerCell(const unsigned) const override final
std::string fullPath() const
bool validTriggerCellFromCells(const unsigned) const
std::multimap< std::pair< short, short >, short > trigger_cells_to_cells_
virtual geom_set getCellsFromModule(const unsigned) const override final
int waferTypeT(int wafer) const
edm::FileInPath l1tCellNeighborsMapping_
int layer() const
get the layer #
HGCalTriggerGeometryHexImp2(const edm::ParameterSet &conf)