19 virtual void reset()
override final;
39 virtual unsigned triggerLayer(
const unsigned)
const override final;
81 bool validCellId(
unsigned subdet,
unsigned cell_id)
const;
127 int wafer_type = cell_det_id.
waferType();
128 unsigned cell = cell_det_id.
cell();
134 <<
"HGCalTriggerGeometry: HGCal cell " << cell <<
" is not mapped to any trigger cell for the wafer type " << wafer_type
135 <<
". The trigger cell mapping should be modified.\n";
137 unsigned trigger_cell = trigger_cell_itr->second;
147 unsigned wafer = cell_det_id.
wafer();
148 unsigned subdet = cell_det_id.
subdetId();
149 std::unordered_map<short, short>::const_iterator module_itr;
150 bool out_of_range_error =
false;
162 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer->module mapping for subdet "<<subdet<<
"\n";
165 if(out_of_range_error)
168 <<
"HGCalTriggerGeometry: Wafer " << wafer <<
" is not mapped to any trigger module for subdetector " << subdet
169 <<
". The module mapping should be modified. See https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for details.\n";
171 unsigned module = module_itr->second;
179 HGCalDetId trigger_cell_det_id(trigger_cell_id);
180 unsigned wafer = trigger_cell_det_id.
wafer();
181 unsigned subdet = trigger_cell_det_id.
subdetId();
183 std::unordered_map<short, short>::const_iterator module_itr;
184 bool out_of_range_error =
false;
196 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer->module mapping for subdet "<<subdet<<
"\n";
199 if(out_of_range_error)
202 <<
"HGCalTriggerGeometry: Wafer " << wafer <<
" is not mapped to any trigger module for subdetector " << subdet
203 <<
". The module mapping should be modified. See https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for details.\n";
205 unsigned module = module_itr->second;
213 HGCalDetId trigger_cell_det_id(trigger_cell_id);
214 unsigned subdet = trigger_cell_det_id.
subdetId();
216 int wafer_type = trigger_cell_det_id.
waferType();
217 unsigned trigger_cell = trigger_cell_det_id.
cell();
221 for(
auto tc_c_itr=cell_range.first; tc_c_itr!=cell_range.second; tc_c_itr++)
234 unsigned subdet = module_det_id.
subdetId();
237 std::pair<std::unordered_multimap<short, short>::const_iterator,
238 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
248 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
252 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
255 if(wafer_type==0) wafer_type = module_det_id.
waferType();
260 if(
validCellId(subdet, cell_id)) cell_det_ids.emplace(cell_id.rawId());
271 unsigned subdet = module_det_id.
subdetId();
274 std::pair<std::unordered_multimap<short, short>::const_iterator,
275 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
285 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
289 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
292 if(wafer_type==0) wafer_type = module_det_id.
waferType();
297 if(
validCellId(subdet, cell_id)) cell_det_ids.emplace(cell_id.rawId());
308 unsigned subdet = module_det_id.
subdetId();
311 std::pair<std::unordered_multimap<short, short>::const_iterator,
312 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
322 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
327 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
330 if(wafer_type==0) wafer_type = module_det_id.
waferType();
335 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
338 return trigger_cell_det_ids;
346 unsigned subdet = module_det_id.
subdetId();
349 std::pair<std::unordered_multimap<short, short>::const_iterator,
350 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
360 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
365 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
368 if(wafer_type==0) wafer_type = module_det_id.
waferType();
373 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
376 return trigger_cell_det_ids;
385 HGCalDetId trigger_cell_det_id(trigger_cell_id);
386 unsigned wafer = trigger_cell_det_id.
wafer();
387 int wafer_type = trigger_cell_det_id.
waferType();
388 unsigned subdet = trigger_cell_det_id.
subdetId();
389 unsigned trigger_cell = trigger_cell_det_id.
cell();
393 std::unordered_map<short, std::vector<short>>::const_iterator surrounding_wafers_itr;
394 bool out_of_range_error =
false;
406 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer neighbours for subdet "<<subdet<<
"\n";
409 if(out_of_range_error)
412 <<
"HGCalTriggerGeometry: Neighbors are not defined for wafer " << wafer <<
" in subdetector " << subdet
413 <<
". The wafer neighbor mapping should be modified. \n";
415 const std::vector<short>& surrounding_wafers = surrounding_wafers_itr->second;
417 std::vector<int>
types;
418 types.reserve(surrounding_wafers.size()+1);
419 types.emplace_back(wafer_type);
420 for(
const auto w : surrounding_wafers)
427 types.emplace_back(wt);
436 <<
"HGCalTriggerGeometry: Neighbors are not defined for trigger cell " << trigger_cell <<
" with wafer configuration " 437 << std::bitset<7>(trigger_cell_key >> 8) <<
". The trigger cell neighbor mapping should be modified. \n";
439 const auto& neighbors = neighbors_itr->second;
441 neighbor_detids.reserve(neighbors.size());
442 for(
const auto& wafer_tc : neighbors)
444 if(wafer_tc.first-1>=(
int)surrounding_wafers.size())
447 <<
"HGCalTriggerGeometry: Undefined wafer neighbor number "<<wafer_tc.first
448 <<
" for wafer " << wafer <<
" and trigger cell " << trigger_cell
449 <<
". The neighbor mapping files should be modified.";
451 int neighbor_wafer = (wafer_tc.first==0 ? wafer : surrounding_wafers.at(wafer_tc.first-1));
452 if(neighbor_wafer==-1)
continue;
453 int type = types.at(wafer_tc.first);
457 neighbor_detids.emplace(neighbor_det_id.rawId());
460 return neighbor_detids;
472 for(
const auto& cell : cell_ids)
477 return GlobalPoint( triggerCellVector/cell_ids.size() );
489 for(
const auto& cell : cell_ids)
494 return GlobalPoint( moduleVector/cell_ids.size() );
505 if(!l1tModulesMappingStream.is_open())
508 <<
"Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
513 for(; l1tModulesMappingStream>>subdet>>wafer>>
module; )
537 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Unsupported subdetector number ("<<subdet<<
") in L1TModulesMapping file\n";
541 if(!l1tModulesMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TModulesMapping '"<<wafer<<
" "<<module<<
"' \n";
542 l1tModulesMappingStream.close();
545 if(!l1tCellsMappingStream.is_open())
548 <<
"Cannot open HGCalTriggerGeometry L1TCellsMapping file\n";
552 short triggerCell = 0;
553 for(; l1tCellsMappingStream>>waferType>>cell>>triggerCell; )
560 if(triggerCell+1 > itr_insert.first->second) itr_insert.first->second = triggerCell+1;
562 if(!l1tCellsMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellsMapping'"<<waferType<<
" "<<cell<<
" "<<triggerCell<<
"' \n";
563 l1tCellsMappingStream.close();
572 if(!l1tCellNeighborsMappingStream.is_open())
575 <<
"Cannot open HGCalTriggerGeometry L1TCellNeighborsMapping file\n";
577 for(std::array<char,512>
buffer; l1tCellNeighborsMappingStream.getline(&
buffer[0], 512); )
585 std::regex key_regex(
"\\(\\s*[01]{7}\\s*,\\s*\\d{1,3}\\s*\\)");
586 std::vector<std::string> key_tokens {
587 std::sregex_token_iterator(line.begin(), line.end(), key_regex), {}
589 if(key_tokens.size()!=1)
592 <<
"Syntax error in the L1TCellNeighborsMapping:\n" 593 <<
" Cannot find the trigger cell key in line:\n" 594 <<
" '"<<&
buffer[0]<<
"'\n";
596 std::regex digits_regex(
"([01]{7})|(\\d{1,3})");
597 std::vector<std::string> type_tc {
598 std::sregex_token_iterator(key_tokens[0].
begin(), key_tokens[0].
end(), digits_regex), {}
601 int trigger_cell = std::stoi(type_tc[1]);
602 std::vector<int> wafer_types;
603 wafer_types.reserve(type_tc[0].
size());
605 for(
const char c : type_tc[0]) wafer_types.emplace_back( (std::stoi(
std::string(&
c))?1:-1) );
611 std::regex neighbors_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d\\s*\\)");
612 std::vector<std::string> neighbors_tokens {
613 std::sregex_token_iterator(line.begin(), line.end(), neighbors_regex), {}
615 if(neighbors_tokens.size()==0)
618 <<
"Syntax error in the L1TCellNeighborsMapping:\n" 619 <<
" Cannot find any neighbor in line:\n" 620 <<
" '"<<&
buffer[0]<<
"'\n";
623 for(
const auto&
neighbor : neighbors_tokens)
625 std::vector<std::string> pair_neighbor {
626 std::sregex_token_iterator(
neighbor.begin(),
neighbor.end(), digits_regex), {}
628 short neighbor_wafer(std::stoi(pair_neighbor[1]));
629 short neighbor_cell(std::stoi(pair_neighbor[0]));
630 itr_insert.first->second.emplace(neighbor_wafer, neighbor_cell);
633 if(!l1tCellNeighborsMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellNeighborsMapping'\n";
634 l1tCellNeighborsMappingStream.close();
638 if(!l1tWaferNeighborsMappingStream.is_open())
641 <<
"Cannot open HGCalTriggerGeometry L1TWaferNeighborsMapping file\n";
643 for(std::array<char,512>
buffer; l1tWaferNeighborsMappingStream.getline(&
buffer[0], 512); )
648 std::vector<std::string> tokens {
649 std::sregex_token_iterator(line.begin(), line.end(),
delimiter, -1), {}
654 <<
"Syntax error in the L1TWaferNeighborsMapping in line:\n" 655 <<
" '"<<&
buffer[0]<<
"'\n" 656 <<
" A line should be composed of 8 integers separated by spaces:\n" 657 <<
" subdet waferid neighbor1 neighbor2 neighbor3 neighbor4 neighbor5 neighbor6\n";
659 short subdet(std::stoi(tokens[0]));
660 short wafer(std::stoi(tokens[1]));
662 std::unordered_map<short, std::vector<short>>* wafer_neighbors;
673 <<
"Unknown subdet " << subdet <<
" in L1TWaferNeighborsMapping:\n" 674 <<
" '"<<&
buffer[0]<<
"'\n";
676 auto wafer_itr = wafer_neighbors->emplace(wafer, std::vector<short>());
677 for(
auto neighbor_itr=tokens.cbegin()+2; neighbor_itr!=tokens.cend(); ++neighbor_itr)
679 wafer_itr.first->second.emplace_back(std::stoi(*neighbor_itr));
690 for(
unsigned layer=1; layer<=n_layers_ee; layer++)
694 unsigned wafer = wafer_module.first;
707 for(
unsigned layer=1; layer<=n_layers_fh; layer++)
711 unsigned wafer = wafer_module.first;
729 unsigned packed_value = trigger_cell;
730 for(
unsigned i=0;
i<wafer_types.size();
i++)
734 if(wafer_types.at(
i)==1) packed_value += (0x1<<(8+
i));
793 HGCalDetId trigger_cell_det_id(trigger_cell_id);
794 unsigned subdet = trigger_cell_det_id.
subdetId();
797 for(
const auto cell_id : cells)
830 "HGCalTriggerGeometryHexImp2");
const HGCalGeometry & eeGeometry() const
virtual geom_set getCellsFromTriggerCell(const unsigned) const override final
edm::FileInPath l1tWaferNeighborsMapping_
std::unordered_map< short, short > number_cells_in_wafers_
const HGCalGeometry & fhGeometry() const
std::unordered_map< short, short > number_trigger_cells_in_wafers_
bool is_valid(const Digi &d)
const HGCalTopology & eeTopology() const
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_
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_
std::unordered_map< short, std::vector< short > > wafer_neighbors_ee_
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) ...
void setCaloGeometry(const edm::ESHandle< CaloGeometry > &geom)
virtual geom_set getNeighborsFromTriggerCell(const unsigned) const override final
std::unordered_map< short, short > wafer_to_module_ee_
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_
virtual bool disconnectedModule(const unsigned) const override final
std::set< unsigned > geom_ordered_set
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
std::string fullPath() const
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
virtual unsigned triggerLayer(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
bool valid(const DetId &id) const override
Is this a valid cell id.
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
virtual void initialize(const edm::ESHandle< CaloGeometry > &) override final
int waferTypeT(int wafer) const
edm::FileInPath l1tCellNeighborsMapping_
const HGCalTopology & fhTopology() const
int layer() const
get the layer #
void fillInvalidTriggerCells()
HGCalTriggerGeometryHexImp2(const edm::ParameterSet &conf)