17 #include <nlohmann/json.hpp>
60 bool validCell(
const unsigned)
const final;
105 bool validCellId(
unsigned det,
unsigned cell_id)
const;
122 hSc_triggercell_size_(conf.getParameter<unsigned>(
"ScintillatorTriggerCellSize")),
123 hSc_module_size_(conf.getParameter<unsigned>(
"ScintillatorModuleSize")),
124 jsonMappingFile_(conf.getParameter<edm::FileInPath>(
"JsonMappingFile")) {
125 const unsigned ntc_per_wafer = 48;
130 std::vector<unsigned> tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedLayers");
156 unsigned trigger_layer = 1;
184 unsigned trigger_layer = 1;
201 unsigned trigger_nose_layer = 1;
204 trigger_nose_layer++;
209 unsigned det =
DetId(cell_id).
det();
210 unsigned trigger_cell_id = 0;
223 cell_nose_id.
zside(),
225 cell_nose_id.
layer(),
244 return trigger_cell_id;
252 unsigned det =
DetId(trigger_cell_id).
det();
254 unsigned tc_type = 1;
256 unsigned module_id = 0;
261 tc_type = trigger_cell_sc_id.
type();
262 layer = trigger_cell_sc_id.
layer();
263 zside = trigger_cell_sc_id.
zside();
276 tc_type = trigger_cell_trig_id.
type();
277 layer = trigger_cell_trig_id.
layer();
278 zside = trigger_cell_trig_id.
zside();
279 int waferu = trigger_cell_trig_id.
waferU();
280 int waferv = trigger_cell_trig_id.
waferV();
289 unsigned subdet = trigger_cell_trig_id.
subdet();
290 tc_type = trigger_cell_trig_id.
type();
291 layer = trigger_cell_trig_id.
layer();
292 zside = trigger_cell_trig_id.
zside();
293 int waferu = trigger_cell_trig_id.
waferU();
294 int waferv = trigger_cell_trig_id.
waferV();
302 const unsigned trigger_cell_id)
const {
303 DetId trigger_cell_det_id(trigger_cell_id);
304 unsigned det = trigger_cell_det_id.
det();
312 int ieta = ietaAbs * trigger_cell_sc_id.
zside();
316 cell_det_ids.emplace(cell_id);
326 int type = trigger_cell_nose_id.
type();
327 int waferu = trigger_cell_nose_id.
waferU();
328 int waferv = trigger_cell_nose_id.
waferV();
329 std::vector<int> cellus = trigger_cell_nose_id.
cellU();
330 std::vector<int> cellvs = trigger_cell_nose_id.
cellV();
331 for (
unsigned ic = 0; ic < cellus.size(); ic++) {
332 HFNoseDetId cell_det_id(zside, type, layer, waferu, waferv, cellus[ic], cellvs[ic]);
333 cell_det_ids.emplace(cell_det_id);
339 unsigned subdet = trigger_cell_trig_id.
subdet();
344 int type = trigger_cell_trig_id.
type();
345 int waferu = trigger_cell_trig_id.
waferU();
346 int waferv = trigger_cell_trig_id.
waferV();
347 std::vector<int> cellus = trigger_cell_trig_id.
cellU();
348 std::vector<int> cellvs = trigger_cell_trig_id.
cellV();
349 for (
unsigned ic = 0; ic < cellus.size(); ic++) {
350 HGCSiliconDetId cell_det_id(cell_det, zside, type, layer, waferu, waferv, cellus[ic], cellvs[ic]);
351 cell_det_ids.emplace(cell_det_id);
362 for (
auto trigger_cell_id : trigger_cells) {
364 cell_det_ids.insert(cells.begin(), cells.end());
370 const unsigned module_id)
const {
373 for (
auto trigger_cell_id : trigger_cells) {
375 cell_det_ids.insert(cells.begin(), cells.end());
381 const unsigned module_id)
const {
391 int iphi0 = hgc_module_id.
phi();
394 for (
int ietaAbs = ieta0; ietaAbs < ieta0 + (int)
hSc_module_size_; ietaAbs++) {
395 int ieta = ietaAbs * hgc_module_id.
zside();
399 trigger_cell_det_ids.emplace(trigger_cell_id);
408 for (
auto const& idx : ids) {
410 trigger_cell_det_ids.emplace(idx);
416 int moduleU = hgc_module_id.
moduleU();
417 int moduleV = hgc_module_id.
moduleV();
425 unsigned wafer_type =
detIdWaferType(det, layer, moduleU, moduleV);
431 for (
const auto& tc_uv : tc_uvs) {
433 subdet, hgc_module_id.
zside(), wafer_type,
layer, moduleU, moduleV, tc_uv.first, tc_uv.second);
435 trigger_cell_det_ids.emplace(trigger_cell_id);
440 return trigger_cell_det_ids;
444 const unsigned module_id)
const {
455 for (
int ietaAbs = ieta0; ietaAbs < ieta0 + (int)
hSc_module_size_; ietaAbs++) {
456 int ieta = ietaAbs * hgc_module_id.
zside();
460 trigger_cell_det_ids.emplace(trigger_cell_id);
470 for (
auto const& idx : ids) {
472 trigger_cell_det_ids.emplace(idx);
478 int moduleU = hgc_module_id.
moduleU();
479 int moduleV = hgc_module_id.
moduleV();
487 unsigned wafer_type =
detIdWaferType(det, layer, moduleU, moduleV);
493 for (
const auto& tc_uv : tc_uvs) {
495 subdet, hgc_module_id.
zside(), wafer_type,
layer, moduleU, moduleV, tc_uv.first, tc_uv.second);
497 trigger_cell_det_ids.emplace(trigger_cell_id);
502 return trigger_cell_det_ids;
506 const unsigned trigger_cell_id)
const {
507 throw cms::Exception(
"FeatureNotImplemented") <<
"Neighbor search is not implemented in HGCalTriggerGeometryV9Imp3";
530 unsigned nWafers = 1;
535 unsigned next_sector = 0;
537 next_sector = sector + 1;
543 unsigned previous_sector = 2;
545 previous_sector = sector - 1;
547 return previous_sector;
551 const unsigned stage2_id)
const {
555 for (
const auto& stage1_link : stage1_links) {
563 const unsigned stage1_id)
const {
567 for (
const auto& stage1_link : stage1_links) {
575 const unsigned stage2_id)
const {
580 for (
auto stage2_itr = stage2_itrs.first; stage2_itr != stage2_itrs.second; stage2_itr++) {
581 if (stage2_itr->second ==
true) {
583 id.
zside(), HGCalTriggerBackendDetId::BackendType::Stage1Link,
id.sector(), stage2_itr->second));
586 HGCalTriggerBackendDetId::BackendType::Stage1Link,
588 stage2_itr->second));
592 return stage1link_ids;
600 id.
zside(), HGCalTriggerBackendDetId::BackendType::Stage1FPGA,
id.sector(), stage1_label);
606 unsigned sector =
id.sector();
616 const unsigned stage1_id)
const {
622 for (
auto stage1_itr = stage1_itrs.first; stage1_itr != stage1_itrs.second; stage1_itr++) {
624 id.
zside(), HGCalTriggerBackendDetId::BackendType::Stage1Link,
id.sector(), stage1_itr->second));
627 return stage1link_ids;
635 for (
auto stage1_itr = stage1_itrs.first; stage1_itr != stage1_itrs.second; stage1_itr++) {
637 id.
zside(), HGCalTriggerBackendDetId::BackendType::LpGBT,
id.sector(), stage1_itr->second));
648 id.
zside(), HGCalTriggerBackendDetId::BackendType::Stage1FPGA,
id.sector(), stage1_label);
656 for (
auto lpgbt_itr = lpgbt_itrs.first; lpgbt_itr != lpgbt_itrs.second; lpgbt_itr++) {
692 for (
auto module_itr = module_itrs.first; module_itr != module_itrs.second; module_itr++) {
694 id.
zside(), HGCalTriggerBackendDetId::BackendType::LpGBT,
id.sector(), module_itr->second));
703 unsigned stage1_label =
707 id.
zside(), HGCalTriggerBackendDetId::BackendType::Stage1FPGA,
id.sector(), stage1_label);
711 unsigned det =
DetId(trigger_cell_det_id).
det();
718 for (
const auto& cell : cell_ids) {
725 for (
const auto& cell : cell_ids) {
732 for (
const auto& cell : cell_ids) {
739 return GlobalPoint(triggerCellVector / cell_ids.size());
749 for (
const auto& cell : cell_ids) {
755 for (
const auto& cell : cell_ids) {
761 for (
const auto& cell : cell_ids) {
769 return GlobalPoint(moduleVector / cell_ids.size());
776 if (!json_input_file.is_open()) {
777 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TMapping file\n";
779 json_input_file >> mapping_config;
783 for (
unsigned stage2_id = 0; stage2_id < mapping_config.at(
"Stage2").size(); stage2_id++) {
784 for (
auto&
link : mapping_config.at(
"Stage2").at(stage2_id).at(
"Stage1Links")) {
790 <<
"The mapping input json file does not have the expected structure for the Stage2 block";
794 for (
unsigned link_id = 0; link_id < mapping_config.at(
"Stage1Links").size(); link_id++) {
799 stage1link_to_stage2_.emplace(link_id, mapping_config.at(
"Stage1Links").at(link_id).at(
"Stage2SameSector"));
803 <<
"The mapping input json file does not have the expected structure for the Stage1Links block";
807 for (
unsigned stage1_id = 0; stage1_id < mapping_config.at(
"Stage1").size(); stage1_id++) {
809 for (
auto& link_id : mapping_config.at(
"Stage1").at(stage1_id).at(
"Stage1Links")) {
814 for (
auto& lpgbt_id : mapping_config.at(
"Stage1").at(stage1_id).at(
"lpgbts")) {
821 <<
"The mapping input json file does not have the expected structure for the Stage1 block";
825 for (
unsigned lpgbt_id = 0; lpgbt_id < mapping_config.at(
"lpgbt").size(); lpgbt_id++) {
827 unsigned stage1_id = mapping_config.at(
"lpgbt").at(lpgbt_id).at(
"Stage1");
831 for (
auto&
modules : mapping_config.at(
"lpgbt").at(lpgbt_id).at(
"Modules")) {
834 bool isSilicon =
modules.at(
"isSilicon");
841 if (
result.second ==
false &&
842 stage1_id !=
result.first->second) {
843 edm::LogError(
"HGCalTriggerGeometryV9Imp3") <<
"One module is connected to two separate Stage1 FPGAs";
850 <<
"The mapping input json file does not have the expected structure for the lpGBT block";
856 unsigned num_elinks = 0;
857 unsigned layer = mapping_config.at(
"Module").at(
module).at(
"layer");
858 unsigned moduleU = mapping_config.at(
"Module").at(
module).at(
"u");
859 unsigned moduleV = mapping_config.at(
"Module").at(
module).at(
"v");
860 bool isSilicon = mapping_config.at(
"Module").at(
module).at(
"isSilicon");
864 for (
auto& lpgbt : mapping_config.at(
"Module").at(
module).at(
"lpgbts")) {
866 num_elinks += unsigned(lpgbt.at(
"nElinks"));
873 <<
"The mapping input json file does not have the expected structure for the Module block";
876 json_input_file.close();
880 unsigned packed_value = 0;
912 if ((layer % 2) == 1) {
921 <<
"HGCalTriggerGeometryV9Imp3: trigger sub-detector expected to be silicon";
946 bool disconnected =
false;
973 bool is_valid =
false;
974 unsigned det =
DetId(cell_id).
det();
1001 bool is_valid =
false;
1002 for (
const auto cell_id : cells) {
1003 unsigned det =
DetId(cell_id).
det();
1012 bool is_valid =
false;
geom_set getNeighborsFromTriggerCell(const unsigned) const final
geom_set getLpgbtsFromModule(const unsigned) const final
GlobalPoint getTriggerCellPosition(const unsigned) const final
HGCalGeomRotation geom_rotation_120_
int zside() const
get the z-side of the module (1/-1)
std::unordered_map< unsigned, unsigned > links_per_module_
geom_set getLpgbtsFromStage1Fpga(const unsigned) const final
std::unordered_map< unsigned, unsigned > stage1link_to_stage1_
unsigned hSc_module_size_
int getTypeTrap(int layer) const
static const int kHGCalTriggerSubdetMask
geom_set getStage2FpgasFromStage1Fpga(const unsigned) const final
geom_set getTriggerCellsFromModule(const unsigned) const final
int zside() const
get the z-side of the cell (1/-1)
geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned) const final
int detIdWaferType(unsigned det, unsigned layer, short waferU, short waferV) const
HGCalTriggerSubdetector subdet() const
get the subdetector
std::unordered_multimap< unsigned, unsigned > stage1_to_stage1links_
uint16_t *__restrict__ id
void setEEGeometry(const HGCalGeometry *geom)
int type() const
get the type
unsigned getStage1FpgaFromLpgbt(const unsigned) const final
int32_t waferU(const int32_t index)
GlobalPoint getModulePosition(const unsigned) const final
const HGCalGeometry * eeGeometry() const
const HGCalTopology & eeTopology() const
bool valid(const DetId &id) const override
Is this a valid cell id.
std::unordered_multimap< unsigned, unsigned > lpgbt_to_modules_
unsigned getTriggerCellFromCell(const unsigned) const final
unsigned hSc_triggercell_size_
HGCalGeomRotation::WaferCentring getWaferCentring(unsigned layer, int subdet) const
Global3DPoint GlobalPoint
static const int kHGCalModuleVOffset
void layerWithoutOffsetAndSubdetId(unsigned &layer, int &subdetId, bool isSilicon) const
int getTypeHex(int layer, int waferU, int waferV) const
void uvMappingFromSector0(WaferCentring waferCentring, int &moduleU, int &moduleV, unsigned sector) const
std::unordered_map< unsigned, unsigned > lpgbt_to_stage1_
int type() const
get/set the type
unsigned getNextSector(const unsigned sector) const
unsigned triggerLayer(const unsigned) const final
edm::FileInPath jsonMappingFile_
std::unordered_multimap< unsigned, unsigned > stage2_to_stage1links_
std::vector< int > cellV() const
static const int kHGCalLayerMask
GlobalPoint getPosition(const DetId &id) const
int zside() const
get the z-side of the cell (1/-1)
int zside() const
get the z-side of the cell (1/-1)
void unpackLayerSubdetWaferId(unsigned wafer, unsigned &layer, int &subdet, int &waferU, int &waferV) const
const HGCalTopology & hsiTopology() const
Log< level::Error, false > LogError
void setHSiGeometry(const HGCalGeometry *geom)
bool validCell(const unsigned) const final
unsigned getStage2FpgaFromStage1Link(const unsigned) const final
std::vector< HFNoseTriggerDetId > getTriggerDetIds(HFNoseDetId const &id) const
int type() const
get the type
std::unordered_multimap< unsigned, unsigned > module_to_lpgbts_
static const int kHGCalModuleUOffset
void setNoseGeometry(const HGCalGeometry *geom)
bool validTriggerCell(const unsigned) const final
constexpr std::array< uint8_t, layerIndexSize > layer
std::vector< std::pair< int, int > > getTriggerId(int roc, int type) const
unsigned getModuleSize(const unsigned module_id) const final
int layer() const
get the layer #
geom_ordered_set getOrderedCellsFromModule(const unsigned) const final
const HGCalGeometry * noseGeometry() const
unsigned hSc_wafers_per_module_
int type() const
get the type
unsigned getModuleFromTriggerCell(const unsigned) const final
unsigned int layers(bool reco) const
unsigned getModuleFromCell(const unsigned) const final
unsigned lastTriggerLayer() const final
unsigned getPreviousSector(const unsigned sector) const
int layer() const
get the layer #
int type() const
get the type
int layer() const
get the layer #
void etaphiMappingFromSector0(int &ieta, int &iphi, unsigned sector) const
bool disconnectedModule(const unsigned) const final
int zside() const
get the z-side of the cell (1/-1)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
int eta() const
get the scintillator panel eta
Abs< T >::type abs(const T &t)
std::vector< int > cellV() const
void setHScGeometry(const HGCalGeometry *geom)
int phi() const
get the scintillator panel phi
int iphi() const
get the phi index
std::vector< unsigned > trigger_layers_
unsigned etaphiMappingToSector0(int &ieta, int &iphi) const
int sector() const
get the sector #
std::pair< int, int > getREtaRange(int lay) const
int layer() const
get the layer #
unsigned getLinksInModule(const unsigned module_id) const final
int moduleU() const
get the module U
HGCalTriggerGeometryV9Imp3(const edm::ParameterSet &conf)
unsigned getStage1FpgaFromModule(const unsigned module_id) const final
unsigned last_trigger_layer_
const HGCalGeometry * hsiGeometry() const
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ cells
std::vector< int > cellU() const
std::unordered_multimap< unsigned, unsigned > stage1_to_lpgbts_
int moduleV() const
get the module V
geom_set getStage1FpgasFromStage2Fpga(const unsigned) const final
static const int kHGCalModuleUMask
const HGCalDDDConstants & dddConstants() const
const HGCalGeometry * hscGeometry() const
const HGCalTopology & hscTopology() const
T getParameter(std::string const &) const
int triggerSubdetId() const
get the trigger sub-detector
std::set< unsigned > geom_ordered_set
int layer() const
get the layer #
int layer() const
get the layer #
unsigned packLayerSubdetWaferId(unsigned layer, int subdet, int waferU, int waferV) const
bool validCellId(unsigned det, unsigned cell_id) const
std::vector< int > cellU() const
int zside() const
get the z-side of the cell (1/-1)
std::unordered_set< unsigned > geom_set
int32_t waferV(const int32_t index)
bool validTriggerCellFromCells(const unsigned) const
const HGCalTopology & noseTopology() const
geom_set getStage1LinksFromStage2Fpga(const unsigned) const final
geom_set getModulesFromLpgbt(const unsigned) const final
std::unordered_map< unsigned, unsigned > stage1link_to_stage2_
std::string fullPath() const
geom_set getCellsFromModule(const unsigned) const final
std::vector< unsigned > trigger_nose_layers_
static const int kHGCalModuleVMask
#define DEFINE_EDM_PLUGIN(factory, type, name)
unsigned layerWithOffset(unsigned) const
unsigned getStage1FpgaFromStage1Link(const unsigned) const final
int type() const
get the type
geom_set getStage1LinksFromStage1Fpga(const unsigned) const final
void initialize(const HGCalGeometry *, const HGCalGeometry *, const HGCalGeometry *) final
unsigned hSc_num_panels_per_sector_
static const int kHGCalLayerOffset
geom_set getCellsFromTriggerCell(const unsigned) const final
const BasicVectorType & basicVector() const
unsigned uvMappingToSector0(WaferCentring waferCentring, int &moduleU, int &moduleV) const
std::unordered_map< unsigned, unsigned > module_to_stage1_
int layer() const
get the layer #
std::unordered_set< unsigned > disconnected_layers_
static const int kHGCalTriggerSubdetOffset
constexpr Detector det() const
get the detector field from this detid