Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:39

0001 #include "L1Trigger/L1THGCal/interface/HGCalProcessorBase.h"
0002 
0003 #include "DataFormats/L1THGCal/interface/HGCalTriggerCell.h"
0004 #include "DataFormats/L1THGCal/interface/HGCalCluster.h"
0005 #include "DataFormats/L1THGCal/interface/HGCalMulticluster.h"
0006 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0007 #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h"
0008 #include "L1Trigger/L1THGCal/interface/backend/HGCalMulticlusteringImpl.h"
0009 #include "L1Trigger/L1THGCal/interface/backend/HGCalHistoSeedingImpl.h"
0010 #include "L1Trigger/L1THGCal/interface/backend/HGCalHistoClusteringImpl.h"
0011 #include "L1Trigger/L1THGCal/interface/backend/HGCalTriggerClusterInterpreterBase.h"
0012 
0013 #include <utility>
0014 
0015 class HGCalBackendLayer2Processor3DClustering : public HGCalBackendLayer2ProcessorBase {
0016 public:
0017   HGCalBackendLayer2Processor3DClustering(const edm::ParameterSet& conf) : HGCalBackendLayer2ProcessorBase(conf) {
0018     std::string typeMulticluster(conf.getParameterSet("C3d_parameters").getParameter<std::string>("type_multicluster"));
0019     if (typeMulticluster == "dRC3d") {
0020       multiclusteringAlgoType_ = dRC3d;
0021       multiclustering_ = std::make_unique<HGCalMulticlusteringImpl>(conf.getParameterSet("C3d_parameters"));
0022     } else if (typeMulticluster == "DBSCANC3d") {
0023       multiclusteringAlgoType_ = DBSCANC3d;
0024       multiclustering_ = std::make_unique<HGCalMulticlusteringImpl>(conf.getParameterSet("C3d_parameters"));
0025     } else if (typeMulticluster == "Histo") {
0026       multiclusteringAlgoType_ = HistoC3d;
0027       multiclusteringHistoSeeding_ = std::make_unique<HGCalHistoSeedingImpl>(
0028           conf.getParameterSet("C3d_parameters").getParameterSet("histoMax_C3d_seeding_parameters"));
0029       multiclusteringHistoClustering_ = std::make_unique<HGCalHistoClusteringImpl>(
0030           conf.getParameterSet("C3d_parameters").getParameterSet("histoMax_C3d_clustering_parameters"));
0031     } else {
0032       throw cms::Exception("HGCTriggerParameterError") << "Unknown Multiclustering type '" << typeMulticluster << "'";
0033     }
0034 
0035     for (const auto& interpretationPset : conf.getParameter<std::vector<edm::ParameterSet>>("energy_interpretations")) {
0036       std::unique_ptr<HGCalTriggerClusterInterpreterBase> interpreter{
0037           HGCalTriggerClusterInterpreterFactory::get()->create(interpretationPset.getParameter<std::string>("type"))};
0038       interpreter->initialize(interpretationPset);
0039       energy_interpreters_.push_back(std::move(interpreter));
0040     }
0041   }
0042 
0043   void run(const edm::Handle<l1t::HGCalClusterBxCollection>& collHandle,
0044            std::pair<l1t::HGCalMulticlusterBxCollection, l1t::HGCalClusterBxCollection>& be_output) override {
0045     if (multiclustering_)
0046       multiclustering_->setGeometry(geometry());
0047     if (multiclusteringHistoSeeding_)
0048       multiclusteringHistoSeeding_->setGeometry(geometry());
0049     if (multiclusteringHistoClustering_)
0050       multiclusteringHistoClustering_->setGeometry(geometry());
0051 
0052     auto& collCluster3D = be_output.first;
0053     auto& rejectedClusters = be_output.second;
0054 
0055     /* create a persistent vector of pointers to the trigger-cells */
0056     std::vector<edm::Ptr<l1t::HGCalCluster>> clustersPtrs;
0057     for (unsigned i = 0; i < collHandle->size(); ++i) {
0058       edm::Ptr<l1t::HGCalCluster> ptr(collHandle, i);
0059       clustersPtrs.push_back(ptr);
0060     }
0061 
0062     /* create a vector of seed positions and their energy*/
0063     std::vector<std::pair<GlobalPoint, double>> seedPositionsEnergy;
0064 
0065     /* call to multiclustering and compute shower shape*/
0066     switch (multiclusteringAlgoType_) {
0067       case dRC3d:
0068         multiclustering_->clusterizeDR(clustersPtrs, collCluster3D, *geometry());
0069         break;
0070       case DBSCANC3d:
0071         multiclustering_->clusterizeDBSCAN(clustersPtrs, collCluster3D, *geometry());
0072         break;
0073       case HistoC3d:
0074         multiclusteringHistoSeeding_->findHistoSeeds(clustersPtrs, seedPositionsEnergy);
0075         multiclusteringHistoClustering_->clusterizeHisto(
0076             clustersPtrs, seedPositionsEnergy, *geometry(), collCluster3D, rejectedClusters);
0077         break;
0078       default:
0079         // Should not happen, clustering type checked in constructor
0080         break;
0081     }
0082 
0083     // Call all the energy interpretation modules on the cluster collection
0084     for (const auto& interpreter : energy_interpreters_) {
0085       interpreter->setGeometry(geometry());
0086       interpreter->interpret(collCluster3D);
0087     }
0088   }
0089 
0090 private:
0091   enum MulticlusterType { dRC3d, DBSCANC3d, HistoC3d };
0092 
0093   /* algorithms instances */
0094   std::unique_ptr<HGCalMulticlusteringImpl> multiclustering_;
0095   std::unique_ptr<HGCalHistoSeedingImpl> multiclusteringHistoSeeding_;
0096   std::unique_ptr<HGCalHistoClusteringImpl> multiclusteringHistoClustering_;
0097 
0098   /* algorithm type */
0099   MulticlusterType multiclusteringAlgoType_;
0100 
0101   std::vector<std::unique_ptr<HGCalTriggerClusterInterpreterBase>> energy_interpreters_;
0102 };
0103 
0104 DEFINE_EDM_PLUGIN(HGCalBackendLayer2Factory,
0105                   HGCalBackendLayer2Processor3DClustering,
0106                   "HGCalBackendLayer2Processor3DClustering");