72 typedef std::unordered_map<int, std::set<std::pair<short,short>>>
neighbor_map;
90 bool validCellId(
unsigned det,
unsigned cell_id)
const;
93 int detIdWaferType(
unsigned det,
unsigned layer,
short waferU,
short waferV)
const;
94 unsigned packWaferCellId(
unsigned subdet,
unsigned wafer,
unsigned cell)
const;
96 unsigned packCellId(
unsigned type,
unsigned cellU,
unsigned cellV)
const;
98 unsigned packIetaIphi(
unsigned ieta,
unsigned iphi)
const;
99 void unpackWaferCellId(
unsigned wafer_cell,
unsigned& wafer,
unsigned& cell)
const;
100 void unpackWaferId(
unsigned wafer,
int& waferU,
int& waferV)
const;
101 void unpackCellId(
unsigned cell,
unsigned& cellU,
unsigned& cellV)
const;
102 void unpackIetaIphi(
unsigned ieta_iphi,
unsigned& ieta,
unsigned& iphi)
const;
118 std::vector<unsigned> tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedModules");
120 tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedLayers");
147 <<
"HGCalTriggerGeometryV9Imp1 geometry cannot be initialized with the V7/V8 HGCAL geometry";
163 unsigned trigger_layer = 0;
188 unsigned det =
DetId(cell_id).
det();
191 unsigned tc_type = 1;
193 unsigned wafer_trigger_cell = 0;
194 unsigned trigger_cell = 0;
199 unsigned ieta = cell_det_id.
ietaAbs();
200 unsigned iphi = cell_det_id.
iphi();
201 tc_type = cell_det_id.
type();
202 layer = cell_det_id.
layer();
204 zside = cell_det_id.
zside();
209 <<
"HGCalTriggerGeometry: scintillator cell ieta=" << ieta <<
", iphi="<<iphi<<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
212 wafer_trigger_cell = 0;
220 layer = cell_det_id.
layer();
221 zside = cell_det_id.
zside();
223 int waferu = cell_det_id.
waferU();
224 int waferv = cell_det_id.
waferV();
225 unsigned cellu = cell_det_id.
cellU();
226 unsigned cellv = cell_det_id.
cellV();
231 <<
"HGCalTriggerGeometry: HGCal cell " << cellu <<
"," << cellv <<
" in wafer type "<<type<<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
237 <<
"HGCalTriggerGeometry: Wafer "<<waferu<<
","<<waferv<<
" is not mapped to any trigger wafer ID. The wafer mapping should be modified.\n";
239 trigger_cell = trigger_cell_itr->second;
240 wafer_trigger_cell = wafer_trigger_cell_itr->second;
259 HGCalDetId trigger_cell_det_id(trigger_cell_id);
265 module = trigger_cell_det_id.
wafer();
274 <<trigger_cell_det_id
275 <<
"HGCalTriggerGeometry: Wafer " << trigger_cell_det_id.
wafer() <<
" is not mapped to any trigger module. The module mapping should be modified. See https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for details.\n";
277 module = module_itr->second;
286 HGCalDetId trigger_cell_det_id(trigger_cell_id);
288 unsigned subdet = trigger_cell_det_id.
subdetId();
289 unsigned trigger_wafer = trigger_cell_det_id.
wafer();
290 unsigned trigger_cell = trigger_cell_det_id.
cell();
291 unsigned layer = trigger_cell_det_id.
layer();
297 for(
auto tc_c_itr=cell_range.first; tc_c_itr!=cell_range.second; tc_c_itr++)
303 if(
validCellId(subdet, cell_det_id)) cell_det_ids.emplace(cell_det_id);
315 <<
"HGCalTriggerGeometry: Trigger wafer ID "<<trigger_wafer<<
" is not mapped to any wafer. The wafer mapping should be modified.\n";
321 for(
auto tc_c_itr=cell_range.first; tc_c_itr!=cell_range.second; tc_c_itr++)
326 unsigned cell_det_id =
HGCSiliconDetId(det, trigger_cell_det_id.
zside(), wafer_type, layer, waferu, waferv, cellu, cellv).rawId();
327 if(
validCellId(subdet, cell_det_id)) cell_det_ids.emplace(cell_det_id);
339 for(
auto trigger_cell_id : trigger_cells)
342 cell_det_ids.insert(cells.begin(), cells.end());
353 for(
auto trigger_cell_id : trigger_cells)
356 cell_det_ids.insert(cells.begin(), cells.end());
375 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
383 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
385 unsigned wafer = wafer_itr->second;
392 unsigned layer = module_det_id.
layer();
398 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
402 return trigger_cell_det_ids;
419 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
427 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
429 unsigned wafer = wafer_itr->second;
436 unsigned layer = module_det_id.
layer();
442 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
446 return trigger_cell_det_ids;
455 HGCalDetId trigger_cell_det_id(trigger_cell_id);
458 unsigned layer = trigger_cell_det_id.
layer();
461 unsigned trigger_cell = trigger_cell_det_id.
cell();
465 auto neighbors_itr = neighbors_map.find(trigger_cell_key);
466 if(neighbors_itr==neighbors_map.end())
469 <<
"HGCalTriggerGeometry: Neighbors are not defined for trigger cell " << trigger_cell <<
" in module " 470 << module <<
". The trigger cell neighbor mapping should be modified. \n";
472 const auto& neighbors = neighbors_itr->second;
474 neighbor_detids.reserve(neighbors.size());
475 for(
const auto& module_tc : neighbors)
480 neighbor_detids.emplace(neighbor_det_id.rawId());
483 return neighbor_detids;
498 for(
const auto& cell : cell_ids)
507 for(
const auto& cell : cell_ids)
513 return GlobalPoint( triggerCellVector/cell_ids.size() );
528 for(
const auto& cell : cell_ids)
537 for(
const auto& cell : cell_ids)
543 return GlobalPoint( moduleVector/cell_ids.size() );
554 if(!l1tModulesMappingStream.is_open())
557 <<
"Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
559 short trigger_wafer = 0;
561 for(; l1tModulesMappingStream>>trigger_wafer>>module; )
566 if(!l1tModulesMappingStream.eof())
569 <<
"Error reading L1TModulesMapping '"<<trigger_wafer<<
" "<<module<<
"' \n";
571 l1tModulesMappingStream.close();
574 if(!l1tCellsMappingStream.is_open())
577 <<
"Cannot open HGCalTriggerGeometry L1TCellsMapping file\n";
582 short trigger_cell = 0;
583 for(; l1tCellsMappingStream>>type>>cellu>>cellv>>trigger_cell; )
585 unsigned cell_key =
packCellId(type,cellu,cellv);
586 unsigned trigger_cell_key =
packCellId(type,trigger_cell);
592 if(trigger_cell+1 > itr_insert.first->second) itr_insert.first->second = trigger_cell+1;
594 if(!l1tCellsMappingStream.eof())
597 <<
"Error reading L1TCellsMapping '"<<type<<
" "<<cellu<<
" "<<cellv<<
" "<<trigger_cell<<
"' \n";
599 l1tCellsMappingStream.close();
602 if(!l1tCellsSciMappingStream.is_open())
605 <<
"Cannot open HGCalTriggerGeometry L1TCellsSciMapping file\n";
611 for(; l1tCellsSciMappingStream>>ieta>>iphi>>trigger_wafer>>trigger_cell; )
620 if(trigger_cell+1 > itr_insert.first->second) itr_insert.first->second = trigger_cell+1;
622 if(!l1tCellsSciMappingStream.eof())
625 <<
"Error reading L1TCellsSciMapping '"<<ieta<<
" "<<iphi<<
" "<<trigger_wafer<<
" "<<trigger_cell<<
"' \n";
627 l1tCellsSciMappingStream.close();
630 if(!l1tWafersMappingStream.is_open())
633 <<
"Cannot open HGCalTriggerGeometry L1TWafersMapping file\n";
638 for(; l1tWafersMappingStream>>waferu>>waferv>>trigger_wafer; )
645 if(!l1tWafersMappingStream.eof())
648 <<
"Error reading L1TWafersMapping '"<<waferu<<
" "<<waferv<<
" "<<trigger_wafer<<
"' \n";
650 l1tWafersMappingStream.close();
659 std::ifstream l1tCellNeighborsMappingStream(file.
fullPath());
660 if(!l1tCellNeighborsMappingStream.is_open())
663 <<
"Cannot open HGCalTriggerGeometry L1TCellNeighborsMapping file\n";
665 const unsigned line_size = 512;
666 for(std::array<char,line_size>
buffer; l1tCellNeighborsMappingStream.getline(&
buffer[0], line_size); )
675 std::regex key_regex(scintillator ?
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)" :
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
676 std::vector<std::string> key_tokens {
677 std::sregex_token_iterator(line.begin(), line.end(), key_regex), {}
679 if(key_tokens.empty())
682 <<
"Syntax error in the L1TCellNeighborsMapping:\n" 683 <<
" Cannot find the trigger cell key in line:\n" 684 <<
" '"<<&
buffer[0]<<
"'\n";
686 std::regex digits_regex(
"\\d{1,3}");
687 std::vector<std::string> module_tc {
688 std::sregex_token_iterator(key_tokens[0].
begin(), key_tokens[0].
end(), digits_regex), {}
691 unsigned map_key = 0;
694 int type = std::stoi(module_tc[0]);
695 int module = std::stoi(module_tc[1]);
696 int trigger_cell = std::stoi(module_tc[2]);
701 int module = std::stoi(module_tc[0]);
702 int trigger_cell = std::stoi(module_tc[1]);
709 std::regex neighbors_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
710 std::vector<std::string> neighbors_tokens {
711 std::sregex_token_iterator(line.begin(), line.end(), neighbors_regex), {}
713 if( (scintillator && neighbors_tokens.empty()) ||
714 (!scintillator && neighbors_tokens.size()<2)
718 <<
"Syntax error in the L1TCellNeighborsMapping:\n" 719 <<
" Cannot find any neighbor in line:\n" 720 <<
" '"<<&
buffer[0]<<
"'\n";
722 auto itr_insert = neighbors_map.emplace(map_key, std::set<std::pair<short,short>>());
724 unsigned first_element = (scintillator ? 0 : 1);
725 for(
unsigned i=first_element;
i<neighbors_tokens.size();
i++)
727 const auto& neighbor = neighbors_tokens[
i];
728 std::vector<std::string> pair_neighbor {
729 std::sregex_token_iterator(neighbor.begin(), neighbor.end(), digits_regex), {}
731 short neighbor_module(std::stoi(pair_neighbor[0]));
732 short neighbor_cell(std::stoi(pair_neighbor[1]));
733 itr_insert.first->second.emplace(neighbor_module, neighbor_cell);
736 if(!l1tCellNeighborsMappingStream.eof())
739 <<
"Error reading L1TCellNeighborsMapping'\n";
741 l1tCellNeighborsMappingStream.close();
751 for(
unsigned layer=1; layer<=n_layers_ee; layer++)
760 unsigned trigger_wafer = waferuv_wafer.second;
764 for(
int zside : {-1,1})
778 for(
int zside : {-1,1})
794 for(
unsigned layer=first_layer_hsc; layer<=first_layer_hsc+n_layers_hsc; layer++)
799 unsigned trigger_wafer = module_ncells.first;
801 for(
int trigger_cell=1; trigger_cell<module_ncells.second; trigger_cell++)
803 for(
int zside : {-1,1})
821 unsigned packed_value = 0;
822 const int kSubdetMask = 0x7;
833 unsigned packed_value = 0;
843 unsigned packed_value = 0;
854 unsigned packed_value = 0;
855 unsigned waferUabs =
std::abs(waferU);
856 unsigned waferVabs =
std::abs(waferV);
857 unsigned waferUsign = (waferU >= 0) ? 0 : 1;
858 unsigned waferVsign = (waferV >= 0) ? 0 : 1;
870 unsigned packed_value = 0;
923 bool disconnected =
false;
946 HGCalDetId trigger_cell_det_id(trigger_cell_id);
947 unsigned subdet = trigger_cell_det_id.
subdetId();
950 for(
const auto cell_id : cells)
986 unsigned packed_value = 0;
996 unsigned packed_value = 0;
1000 return packed_value;
1032 layer = detid.
layer();
1048 "HGCalTriggerGeometryV9Imp1");
int detIdWaferType(unsigned det, unsigned layer, short waferU, short waferV) const
T getParameter(std::string const &) const
unsigned packCellId(unsigned type, unsigned cellU, unsigned cellV) const
static const int kHGCalWaferVOffset
void fillInvalidTriggerCells()
std::unordered_map< int, std::set< std::pair< short, short > > > neighbor_map
edm::FileInPath l1tWafersMapping_
GlobalPoint getTriggerCellPosition(const unsigned) const final
unsigned getModuleFromCell(const unsigned) const final
int getTypeTrap(int layer) const
std::unordered_set< unsigned > disconnected_layers_
GlobalPoint getModulePosition(const unsigned) const final
std::unordered_map< unsigned, unsigned > cells_to_trigger_cells_sci_
neighbor_map trigger_cell_neighbors_sci_
std::unordered_multimap< unsigned, unsigned > trigger_cells_to_cells_
static const int kHGCalTypeMask
bool is_valid(const Digi &d)
bool validTriggerCell(const unsigned) const final
const HGCalGeometry * eeGeometry() const
const HGCalTopology & eeTopology() const
static const int kHGCalWaferVSignOffset
unsigned getModuleFromTriggerCell(const unsigned) const final
std::unordered_map< unsigned, unsigned > cells_to_trigger_cells_
std::unordered_map< unsigned, unsigned short > number_trigger_cells_in_wafers_
static const int kHGCalCellUMask
std::vector< unsigned > trigger_layers_
unsigned packWaferId(int waferU, int waferV) const
Global3DPoint GlobalPoint
constexpr uint32_t rawId() const
get the raw id
int getTypeHex(int layer, int waferU, int waferV) const
void initialize(const edm::ESHandle< CaloGeometry > &) final
geom_set getCellsFromModule(const unsigned) const final
static const int kHGCalWaferTypeOffset
int type() const
get the type
edm::FileInPath l1tCellNeighborsSciMapping_
GlobalPoint getPosition(const DetId &id) const
int zside() const
get the z-side of the cell (1/-1)
bool validCellId(unsigned det, unsigned cell_id) const
std::unordered_map< unsigned, unsigned > wafer_to_module_
const HGCalTopology & hsiTopology() const
void setEEGeometry(const edm::ESHandle< HGCalGeometry > &geom)
static const int kHGCalCellVOffset
unsigned packTriggerCellWithType(unsigned, unsigned, unsigned) const
void unpackIetaIphi(unsigned ieta_iphi, unsigned &ieta, unsigned &iphi) const
int cellU() const
get the cell #'s in u,v or in x,y
edm::FileInPath l1tCellsMapping_
static const int kHGCalTypeOffset
static const int kHGCalCellOffset
static const int kHGCalCellMask
std::unordered_set< unsigned > disconnected_modules_
unsigned int layers(bool reco) const
int zside() const
get the z-side of the cell (1/-1)
std::unordered_multimap< unsigned, unsigned > module_to_wafers_
static const int kHGCalCellVMask
static const int kHGCalWaferTypeMask
void unpackWaferCellId(unsigned wafer_cell, unsigned &wafer, unsigned &cell) const
int type() const
get the type
int layer() const
get the layer #
edm::FileInPath l1tCellNeighborsMapping_
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
void unpackCellId(unsigned cell, unsigned &cellU, unsigned &cellV) const
static const int kHGCalRadiusOffset
Abs< T >::type abs(const T &t)
int iphi() const
get the phi index
int wafer() const
get the wafer #
unsigned packIetaIphi(unsigned ieta, unsigned iphi) const
geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned) const final
unsigned packWaferCellId(unsigned subdet, unsigned wafer, unsigned cell) const
const HGCalGeometry * hsiGeometry() const
geom_ordered_set getOrderedCellsFromModule(const unsigned) const final
std::unordered_multimap< unsigned, unsigned > trigger_cells_to_cells_sci_
static const int kHGCalRadiusMask
static const int kHGCalWaferVMask
static const int kHGCalWaferUSignMask
unsigned layerWithOffset(unsigned) const
static const int kHGCalWaferUMask
edm::FileInPath l1tModulesMapping_
int cell() const
get the absolute value of the cell #'s in x and y
const HGCalDDDConstants & dddConstants() const
std::unordered_map< unsigned, unsigned short > number_trigger_cells_in_wafers_sci_
const HGCalGeometry * hscGeometry() const
const HGCalTopology & hscTopology() const
static const int kHGCalWaferVSignMask
void unpackWaferId(unsigned wafer, int &waferU, int &waferV) const
unsigned packTriggerCell(unsigned, unsigned) const
void fillNeighborMap(const edm::FileInPath &, neighbor_map &, bool)
static const int kHGCalCellUOffset
bool validTriggerCellFromCells(const unsigned) const
static const int kHGCalWaferOffset
std::set< unsigned > geom_ordered_set
static const int kHGCalPhiMask
void setHScGeometry(const edm::ESHandle< HGCalGeometry > &geom)
int layer() const
get the layer #
std::unordered_map< unsigned, unsigned > wafers_to_wafers_old_
int zside() const
get the z-side of the cell (1/-1)
edm::FileInPath l1tCellsSciMapping_
neighbor_map trigger_cell_neighbors_
std::unordered_set< unsigned > geom_set
geom_set getTriggerCellsFromModule(const unsigned) const final
std::string fullPath() const
int waferType() const
get the wafer type
bool disconnectedModule(const unsigned) const final
#define DEFINE_EDM_PLUGIN(factory, type, name)
HGCalTriggerGeometryV9Imp1(const edm::ParameterSet &conf)
static const int kHGCalWaferUOffset
bool valid(const DetId &id) const override
Is this a valid cell id.
static const int kHGCalPhiOffset
const BasicVectorType & basicVector() const
std::unordered_map< unsigned, unsigned > wafers_old_to_wafers_
static const int kHGCalWaferUSignOffset
void setHSiGeometry(const edm::ESHandle< HGCalGeometry > &geom)
int layer() const
get the layer #
geom_set getNeighborsFromTriggerCell(const unsigned) const final
static const int kHGCalWaferMask
unsigned triggerLayer(const unsigned) const final
std::unordered_set< unsigned > invalid_triggercells_
constexpr Detector det() const
get the detector field from this detid
unsigned getTriggerCellFromCell(const unsigned) const final
geom_set getCellsFromTriggerCell(const unsigned) const final