84 bool validCellId(
unsigned subdet,
unsigned cell_id)
const;
132 <<
"HGCalTriggerGeometryHexImp2 geometry cannot be initialized with the V9 HGCAL geometry";
141 int wafer_type = cell_det_id.
waferType();
142 unsigned cell = cell_det_id.
cell();
148 <<
"HGCalTriggerGeometry: HGCal cell " << cell <<
" is not mapped to any trigger cell for the wafer type " << wafer_type
149 <<
". The trigger cell mapping should be modified.\n";
151 unsigned trigger_cell = trigger_cell_itr->second;
161 unsigned wafer = cell_det_id.
wafer();
162 unsigned subdet = cell_det_id.
subdetId();
163 std::unordered_map<short, short>::const_iterator module_itr;
164 bool out_of_range_error =
false;
176 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer->module mapping for subdet "<<subdet<<
"\n";
179 if(out_of_range_error)
182 <<
"HGCalTriggerGeometry: Wafer " << wafer <<
" is not mapped to any trigger module for subdetector " << subdet
183 <<
". The module mapping should be modified. See https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for details.\n";
185 unsigned module = module_itr->second;
193 HGCalDetId trigger_cell_det_id(trigger_cell_id);
194 unsigned wafer = trigger_cell_det_id.
wafer();
195 unsigned subdet = trigger_cell_det_id.
subdetId();
197 std::unordered_map<short, short>::const_iterator module_itr;
198 bool out_of_range_error =
false;
210 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer->module mapping for subdet "<<subdet<<
"\n";
213 if(out_of_range_error)
216 <<
"HGCalTriggerGeometry: Wafer " << wafer <<
" is not mapped to any trigger module for subdetector " << subdet
217 <<
". The module mapping should be modified. See https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for details.\n";
219 unsigned module = module_itr->second;
227 HGCalDetId trigger_cell_det_id(trigger_cell_id);
228 unsigned subdet = trigger_cell_det_id.
subdetId();
230 int wafer_type = trigger_cell_det_id.
waferType();
231 unsigned trigger_cell = trigger_cell_det_id.
cell();
235 for(
auto tc_c_itr=cell_range.first; tc_c_itr!=cell_range.second; tc_c_itr++)
248 unsigned subdet = module_det_id.
subdetId();
251 std::pair<std::unordered_multimap<short, short>::const_iterator,
252 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
262 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
266 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
269 if(wafer_type==0) wafer_type = module_det_id.
waferType();
274 if(
validCellId(subdet, cell_id)) cell_det_ids.emplace(cell_id.rawId());
285 unsigned subdet = module_det_id.
subdetId();
288 std::pair<std::unordered_multimap<short, short>::const_iterator,
289 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
299 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
303 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
306 if(wafer_type==0) wafer_type = module_det_id.
waferType();
311 if(
validCellId(subdet, cell_id)) cell_det_ids.emplace(cell_id.rawId());
322 unsigned subdet = module_det_id.
subdetId();
325 std::pair<std::unordered_multimap<short, short>::const_iterator,
326 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
336 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
341 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
344 if(wafer_type==0) wafer_type = module_det_id.
waferType();
349 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
352 return trigger_cell_det_ids;
360 unsigned subdet = module_det_id.
subdetId();
363 std::pair<std::unordered_multimap<short, short>::const_iterator,
364 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
374 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
379 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
382 if(wafer_type==0) wafer_type = module_det_id.
waferType();
387 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
390 return trigger_cell_det_ids;
399 HGCalDetId trigger_cell_det_id(trigger_cell_id);
400 unsigned wafer = trigger_cell_det_id.
wafer();
401 int wafer_type = trigger_cell_det_id.
waferType();
402 unsigned subdet = trigger_cell_det_id.
subdetId();
403 unsigned trigger_cell = trigger_cell_det_id.
cell();
407 std::unordered_map<short, std::vector<short>>::const_iterator surrounding_wafers_itr;
408 bool out_of_range_error =
false;
420 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer neighbours for subdet "<<subdet<<
"\n";
423 if(out_of_range_error)
426 <<
"HGCalTriggerGeometry: Neighbors are not defined for wafer " << wafer <<
" in subdetector " << subdet
427 <<
". The wafer neighbor mapping should be modified. \n";
429 const std::vector<short>& surrounding_wafers = surrounding_wafers_itr->second;
431 std::vector<int>
types;
432 types.reserve(surrounding_wafers.size()+1);
433 types.emplace_back(wafer_type);
434 for(
const auto w : surrounding_wafers)
441 types.emplace_back(wt);
450 <<
"HGCalTriggerGeometry: Neighbors are not defined for trigger cell " << trigger_cell <<
" with wafer configuration " 451 << std::bitset<7>(trigger_cell_key >> 8) <<
". The trigger cell neighbor mapping should be modified. \n";
453 const auto& neighbors = neighbors_itr->second;
455 neighbor_detids.reserve(neighbors.size());
456 for(
const auto& wafer_tc : neighbors)
458 if(wafer_tc.first-1>=(
int)surrounding_wafers.size())
461 <<
"HGCalTriggerGeometry: Undefined wafer neighbor number "<<wafer_tc.first
462 <<
" for wafer " << wafer <<
" and trigger cell " << trigger_cell
463 <<
". The neighbor mapping files should be modified.";
465 int neighbor_wafer = (wafer_tc.first==0 ? wafer : surrounding_wafers.at(wafer_tc.first-1));
466 if(neighbor_wafer==-1)
continue;
467 int type = types.at(wafer_tc.first);
471 neighbor_detids.emplace(neighbor_det_id.rawId());
474 return neighbor_detids;
486 for(
const auto& cell : cell_ids)
491 return GlobalPoint( triggerCellVector/cell_ids.size() );
503 for(
const auto& cell : cell_ids)
508 return GlobalPoint( moduleVector/cell_ids.size() );
519 if(!l1tModulesMappingStream.is_open())
522 <<
"Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
527 for(; l1tModulesMappingStream>>subdet>>wafer>>module; )
551 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Unsupported subdetector number ("<<subdet<<
") in L1TModulesMapping file\n";
555 if(!l1tModulesMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TModulesMapping '"<<wafer<<
" "<<module<<
"' \n";
556 l1tModulesMappingStream.close();
559 if(!l1tCellsMappingStream.is_open())
562 <<
"Cannot open HGCalTriggerGeometry L1TCellsMapping file\n";
566 short triggerCell = 0;
567 for(; l1tCellsMappingStream>>waferType>>cell>>triggerCell; )
574 if(triggerCell+1 > itr_insert.first->second) itr_insert.first->second = triggerCell+1;
576 if(!l1tCellsMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellsMapping'"<<waferType<<
" "<<cell<<
" "<<triggerCell<<
"' \n";
577 l1tCellsMappingStream.close();
586 if(!l1tCellNeighborsMappingStream.is_open())
589 <<
"Cannot open HGCalTriggerGeometry L1TCellNeighborsMapping file\n";
591 for(std::array<char,512>
buffer; l1tCellNeighborsMappingStream.getline(&
buffer[0], 512); )
599 std::regex key_regex(
"\\(\\s*[01]{7}\\s*,\\s*\\d{1,3}\\s*\\)");
600 std::vector<std::string> key_tokens {
601 std::sregex_token_iterator(line.begin(), line.end(), key_regex), {}
603 if(key_tokens.size()!=1)
606 <<
"Syntax error in the L1TCellNeighborsMapping:\n" 607 <<
" Cannot find the trigger cell key in line:\n" 608 <<
" '"<<&
buffer[0]<<
"'\n";
610 std::regex digits_regex(
"([01]{7})|(\\d{1,3})");
611 std::vector<std::string> type_tc {
612 std::sregex_token_iterator(key_tokens[0].
begin(), key_tokens[0].
end(), digits_regex), {}
615 int trigger_cell = std::stoi(type_tc[1]);
616 std::vector<int> wafer_types;
617 wafer_types.reserve(type_tc[0].
size());
619 for(
const char c : type_tc[0]) wafer_types.emplace_back( (std::stoi(
std::string(&
c))?1:-1) );
625 std::regex neighbors_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d\\s*\\)");
626 std::vector<std::string> neighbors_tokens {
627 std::sregex_token_iterator(line.begin(), line.end(), neighbors_regex), {}
629 if(neighbors_tokens.empty())
632 <<
"Syntax error in the L1TCellNeighborsMapping:\n" 633 <<
" Cannot find any neighbor in line:\n" 634 <<
" '"<<&
buffer[0]<<
"'\n";
637 for(
const auto& neighbor : neighbors_tokens)
639 std::vector<std::string> pair_neighbor {
640 std::sregex_token_iterator(neighbor.begin(), neighbor.end(), digits_regex), {}
642 short neighbor_wafer(std::stoi(pair_neighbor[1]));
643 short neighbor_cell(std::stoi(pair_neighbor[0]));
644 itr_insert.first->second.emplace(neighbor_wafer, neighbor_cell);
647 if(!l1tCellNeighborsMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellNeighborsMapping'\n";
648 l1tCellNeighborsMappingStream.close();
652 if(!l1tWaferNeighborsMappingStream.is_open())
655 <<
"Cannot open HGCalTriggerGeometry L1TWaferNeighborsMapping file\n";
657 for(std::array<char,512>
buffer; l1tWaferNeighborsMappingStream.getline(&
buffer[0], 512); )
662 std::vector<std::string> tokens {
663 std::sregex_token_iterator(line.begin(), line.end(),
delimiter, -1), {}
668 <<
"Syntax error in the L1TWaferNeighborsMapping in line:\n" 669 <<
" '"<<&
buffer[0]<<
"'\n" 670 <<
" A line should be composed of 8 integers separated by spaces:\n" 671 <<
" subdet waferid neighbor1 neighbor2 neighbor3 neighbor4 neighbor5 neighbor6\n";
673 short subdet(std::stoi(tokens[0]));
674 short wafer(std::stoi(tokens[1]));
676 std::unordered_map<short, std::vector<short>>* wafer_neighbors;
687 <<
"Unknown subdet " << subdet <<
" in L1TWaferNeighborsMapping:\n" 688 <<
" '"<<&
buffer[0]<<
"'\n";
690 auto wafer_itr = wafer_neighbors->emplace(wafer, std::vector<short>());
691 for(
auto neighbor_itr=tokens.cbegin()+2; neighbor_itr!=tokens.cend(); ++neighbor_itr)
693 wafer_itr.first->second.emplace_back(std::stoi(*neighbor_itr));
704 for(
unsigned layer=1; layer<=n_layers_ee; layer++)
708 unsigned wafer = wafer_module.first;
721 for(
unsigned layer=1; layer<=n_layers_fh; layer++)
725 unsigned wafer = wafer_module.first;
743 unsigned packed_value = trigger_cell;
744 for(
unsigned i=0;
i<wafer_types.size();
i++)
748 if(wafer_types.at(
i)==1) packed_value += (0
x1<<(8+
i));
807 HGCalDetId trigger_cell_det_id(trigger_cell_id);
808 unsigned subdet = trigger_cell_det_id.
subdetId();
811 for(
const auto cell_id : cells)
844 "HGCalTriggerGeometryHexImp2");
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)
const HGCalGeometry * eeGeometry() const
const HGCalTopology & eeTopology() const
edm::FileInPath l1tModulesMapping_
Global3DPoint GlobalPoint
constexpr uint32_t rawId() const
get the raw id
unsigned packTriggerCell(unsigned, const std::vector< int > &) const
void initialize(const edm::ESHandle< CaloGeometry > &) final
GlobalPoint getPosition(const DetId &id) const
std::unordered_multimap< short, short > module_to_wafers_fh_
std::unordered_set< unsigned > invalid_triggercells_
edm::FileInPath l1tCellsMapping_
GlobalPoint getTriggerCellPosition(const unsigned) const final
geom_set getNeighborsFromTriggerCell(const unsigned) const final
bool disconnectedModule(const unsigned) const final
bool validCellId(unsigned subdet, unsigned cell_id) const
static const int kHGCalCellMask
unsigned getTriggerCellFromCell(const unsigned) const final
unsigned int layers(bool reco) const
int zside() const
get the z-side of the cell (1/-1)
const HGCalGeometry * fhGeometry() const
std::unordered_map< short, std::vector< short > > wafer_neighbors_fh_
std::unordered_map< short, std::vector< short > > wafer_neighbors_ee_
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::unordered_multimap< short, short > module_to_wafers_ee_
int wafer() const
get the wafer #
void setCaloGeometry(const edm::ESHandle< CaloGeometry > &geom)
geom_set getCellsFromModule(const unsigned) const final
std::unordered_map< short, short > wafer_to_module_ee_
geom_set getCellsFromTriggerCell(const unsigned) const final
geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned) const final
unsigned getModuleFromCell(const unsigned) const final
int cell() const
get the absolute value of the cell #'s in x and y
const HGCalDDDConstants & dddConstants() const
std::unordered_map< short, short > wafer_to_module_fh_
std::set< unsigned > geom_ordered_set
bool validTriggerCell(const unsigned) const final
std::unordered_set< unsigned > geom_set
std::string fullPath() const
int detIdWaferType(unsigned subdet, short wafer) const
int waferType() const
get the wafer type
geom_set getTriggerCellsFromModule(const unsigned) const final
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::map< std::pair< short, short >, short > cells_to_trigger_cells_
unsigned getModuleFromTriggerCell(const unsigned) const final
std::unordered_map< int, std::set< std::pair< short, short > > > trigger_cell_neighbors_
unsigned triggerLayer(const unsigned) const 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_
int waferTypeT(int wafer) const
GlobalPoint getModulePosition(const unsigned) const final
edm::FileInPath l1tCellNeighborsMapping_
geom_ordered_set getOrderedCellsFromModule(const unsigned) const final
const HGCalTopology & fhTopology() const
int layer() const
get the layer #
void fillInvalidTriggerCells()
HGCalTriggerGeometryHexImp2(const edm::ParameterSet &conf)