Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-18 08:23:36

0001 #include "L1Trigger/L1THGCal/interface/HGCalProcessorBase.h"
0002 
0003 #include "DataFormats/L1THGCal/interface/HGCalCluster.h"
0004 #include "DataFormats/L1THGCal/interface/HGCalMulticluster.h"
0005 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0006 #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h"
0007 #include "L1Trigger/L1THGCal/interface/backend/HGCalHistoSeedingImpl.h"
0008 #include "L1Trigger/L1THGCal/interface/HGCalAlgoWrapperBase.h"
0009 #include "L1Trigger/L1THGCal/interface/backend/HGCalTriggerClusterInterpreterBase.h"
0010 #include "DataFormats/ForwardDetId/interface/HGCalTriggerBackendDetId.h"
0011 #include "L1Trigger/L1THGCal/interface/backend/HGCalStage2ClusterDistribution.h"
0012 
0013 #include <utility>
0014 
0015 class HGCalBackendLayer2Processor3DClusteringSA : public HGCalBackendLayer2ProcessorBase {
0016 public:
0017   HGCalBackendLayer2Processor3DClusteringSA(const edm::ParameterSet& conf)
0018       : HGCalBackendLayer2ProcessorBase(conf),
0019         distributor_(conf.getParameterSet("DistributionParameters")),
0020         conf_(conf) {
0021     multiclusteringHistoSeeding_ = std::make_unique<HGCalHistoSeedingImpl>(
0022         conf.getParameterSet("C3d_parameters").getParameterSet("histoMax_C3d_seeding_parameters"));
0023 
0024     const edm::ParameterSet& clusteringParamConfig =
0025         conf.getParameterSet("C3d_parameters").getParameterSet("histoMax_C3d_clustering_parameters");
0026     const edm::ParameterSet& sortingTruncationParamConfig =
0027         conf.getParameterSet("C3d_parameters").getParameterSet("histoMax_C3d_sorting_truncation_parameters");
0028     const std::string& clusteringAlgoWrapperName = clusteringParamConfig.getParameter<std::string>("AlgoName");
0029     const std::string& sortingTruncationAlgoWrapperName =
0030         sortingTruncationParamConfig.getParameter<std::string>("AlgoName");
0031 
0032     multiclusteringHistoClusteringWrapper_ = std::unique_ptr<HGCalHistoClusteringWrapperBase>{
0033         HGCalHistoClusteringWrapperBaseFactory::get()->create(clusteringAlgoWrapperName, clusteringParamConfig)};
0034     multiclusteringSortingTruncationWrapper_ =
0035         std::unique_ptr<HGCalStage2FilteringWrapperBase>{HGCalStage2FilteringWrapperBaseFactory::get()->create(
0036             sortingTruncationAlgoWrapperName, sortingTruncationParamConfig)};
0037 
0038     for (const auto& interpretationPset : conf.getParameter<std::vector<edm::ParameterSet>>("energy_interpretations")) {
0039       std::unique_ptr<HGCalTriggerClusterInterpreterBase> interpreter{
0040           HGCalTriggerClusterInterpreterFactory::get()->create(interpretationPset.getParameter<std::string>("type"))};
0041       interpreter->initialize(interpretationPset);
0042       energy_interpreters_.push_back(std::move(interpreter));
0043     }
0044   }
0045 
0046   void run(const edm::Handle<l1t::HGCalClusterBxCollection>& collHandle,
0047            std::pair<l1t::HGCalMulticlusterBxCollection, l1t::HGCalClusterBxCollection>& be_output) override {
0048     if (multiclusteringHistoSeeding_)
0049       multiclusteringHistoSeeding_->setGeometry(geometry());
0050     l1t::HGCalMulticlusterBxCollection& collCluster3D_sorted = be_output.first;
0051     l1t::HGCalClusterBxCollection& rejectedClusters = be_output.second;
0052 
0053     /* create a persistent vector of pointers to the trigger-cells */
0054     std::unordered_map<uint32_t, std::vector<edm::Ptr<l1t::HGCalCluster>>> tcs_per_fpga;
0055 
0056     for (unsigned i = 0; i < collHandle->size(); ++i) {
0057       edm::Ptr<l1t::HGCalCluster> tc_ptr(collHandle, i);
0058       uint32_t module = geometry()->getModuleFromTriggerCell(tc_ptr->detId());
0059       uint32_t stage1_fpga = geometry()->getStage1FpgaFromModule(module);
0060       HGCalTriggerGeometryBase::geom_set possible_stage2_fpgas = geometry()->getStage2FpgasFromStage1Fpga(stage1_fpga);
0061 
0062       HGCalTriggerGeometryBase::geom_set stage2_fpgas =
0063           distributor_.getStage2FPGAs(stage1_fpga, possible_stage2_fpgas, tc_ptr);
0064 
0065       for (auto& fpga : stage2_fpgas) {
0066         tcs_per_fpga[fpga].push_back(tc_ptr);
0067       }
0068     }
0069 
0070     // Configuration
0071     const std::pair<const HGCalTriggerGeometryBase* const, const edm::ParameterSet&> configuration{geometry(), conf_};
0072     multiclusteringHistoClusteringWrapper_->configure(configuration);
0073     multiclusteringSortingTruncationWrapper_->configure(configuration);
0074 
0075     for (auto& fpga_tcs : tcs_per_fpga) {
0076       /* create a vector of seed positions and their energy*/
0077       std::vector<std::pair<GlobalPoint, double>> seedPositionsEnergy;
0078 
0079       /* call to multiclustering and compute shower shape*/
0080       multiclusteringHistoSeeding_->findHistoSeeds(fpga_tcs.second, seedPositionsEnergy);
0081 
0082       // Inputs
0083       std::pair<const std::vector<edm::Ptr<l1t::HGCalCluster>>&, const std::vector<std::pair<GlobalPoint, double>>&>
0084           inputClustersAndSeeds{fpga_tcs.second, seedPositionsEnergy};
0085       // Outputs
0086       l1t::HGCalMulticlusterBxCollection collCluster3D_perFPGA;
0087       l1t::HGCalMulticlusterBxCollection collCluster3D_perFPGA_sorted;
0088       l1t::HGCalClusterBxCollection rejectedClusters_perFPGA;
0089 
0090       std::pair<l1t::HGCalMulticlusterBxCollection&, l1t::HGCalClusterBxCollection&>
0091           outputMulticlustersAndRejectedClusters_perFPGA{collCluster3D_perFPGA, rejectedClusters_perFPGA};
0092 
0093       // Process
0094       multiclusteringHistoClusteringWrapper_->process(inputClustersAndSeeds,
0095                                                       outputMulticlustersAndRejectedClusters_perFPGA);
0096 
0097       multiclusteringSortingTruncationWrapper_->process(collCluster3D_perFPGA, collCluster3D_perFPGA_sorted);
0098 
0099       // Call all the energy interpretation modules on the cluster collection
0100       for (const auto& interpreter : energy_interpreters_) {
0101         interpreter->setGeometry(geometry());
0102         interpreter->interpret(collCluster3D_perFPGA_sorted);
0103       }
0104 
0105       for (const auto& collcluster : collCluster3D_perFPGA_sorted) {
0106         collCluster3D_sorted.push_back(0, collcluster);
0107       }
0108       for (const auto& rejectedcluster : rejectedClusters_perFPGA) {
0109         rejectedClusters.push_back(0, rejectedcluster);
0110       }
0111     }
0112   }
0113 
0114 private:
0115   /* algorithms instances */
0116   std::unique_ptr<HGCalHistoSeedingImpl> multiclusteringHistoSeeding_;
0117 
0118   std::unique_ptr<HGCalHistoClusteringWrapperBase> multiclusteringHistoClusteringWrapper_;
0119 
0120   std::unique_ptr<HGCalStage2FilteringWrapperBase> multiclusteringSortingTruncationWrapper_;
0121 
0122   std::vector<std::unique_ptr<HGCalTriggerClusterInterpreterBase>> energy_interpreters_;
0123 
0124   HGCalStage2ClusterDistribution distributor_;
0125   const edm::ParameterSet conf_;
0126 };
0127 
0128 DEFINE_EDM_PLUGIN(HGCalBackendLayer2Factory,
0129                   HGCalBackendLayer2Processor3DClusteringSA,
0130                   "HGCalBackendLayer2Processor3DClusteringSA");