Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:55:12

0001 #include "L1Trigger/L1THGCal/interface/HGCalProcessorBase.h"
0002 
0003 #include "DataFormats/L1THGCal/interface/HGCalTriggerCell.h"
0004 #include "DataFormats/L1THGCal/interface/HGCalCluster.h"
0005 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0006 #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h"
0007 #include "L1Trigger/L1THGCal/interface/backend/HGCalClusteringImpl.h"
0008 #include "L1Trigger/L1THGCal/interface/backend/HGCalClusteringDummyImpl.h"
0009 
0010 class HGCalBackendLayer1Processor2DClustering : public HGCalBackendLayer1ProcessorBase {
0011 public:
0012   HGCalBackendLayer1Processor2DClustering(const edm::ParameterSet& conf) : HGCalBackendLayer1ProcessorBase(conf) {
0013     std::string typeCluster(conf.getParameterSet("C2d_parameters").getParameter<std::string>("clusterType"));
0014     if (typeCluster == "dRC2d") {
0015       clusteringAlgorithmType_ = dRC2d;
0016       clustering_ = std::make_unique<HGCalClusteringImpl>(conf.getParameterSet("C2d_parameters"));
0017     } else if (typeCluster == "NNC2d") {
0018       clusteringAlgorithmType_ = NNC2d;
0019       clustering_ = std::make_unique<HGCalClusteringImpl>(conf.getParameterSet("C2d_parameters"));
0020     } else if (typeCluster == "dRNNC2d") {
0021       clusteringAlgorithmType_ = dRNNC2d;
0022       clustering_ = std::make_unique<HGCalClusteringImpl>(conf.getParameterSet("C2d_parameters"));
0023     } else if (typeCluster == "dummyC2d") {
0024       clusteringAlgorithmType_ = dummyC2d;
0025       clusteringDummy_ = std::make_unique<HGCalClusteringDummyImpl>(conf.getParameterSet("C2d_parameters"));
0026     } else {
0027       throw cms::Exception("HGCTriggerParameterError") << "Unknown clustering type '" << typeCluster;
0028     }
0029   }
0030 
0031   void run(const edm::Handle<l1t::HGCalTriggerCellBxCollection>& collHandle,
0032            l1t::HGCalClusterBxCollection& collCluster2D) override {
0033     if (clustering_)
0034       clustering_->setGeometry(geometry());
0035     if (clusteringDummy_)
0036       clusteringDummy_->setGeometry(geometry());
0037 
0038     /* create a persistent vector of pointers to the trigger-cells */
0039     std::vector<edm::Ptr<l1t::HGCalTriggerCell>> triggerCellsPtrs;
0040     for (unsigned i = 0; i < collHandle->size(); ++i) {
0041       edm::Ptr<l1t::HGCalTriggerCell> ptr(collHandle, i);
0042       triggerCellsPtrs.push_back(ptr);
0043     }
0044 
0045     std::sort(triggerCellsPtrs.begin(),
0046               triggerCellsPtrs.end(),
0047               [](const edm::Ptr<l1t::HGCalTriggerCell>& a, const edm::Ptr<l1t::HGCalTriggerCell>& b) -> bool {
0048                 return a->mipPt() > b->mipPt();
0049               });
0050 
0051     /* call to C2d clustering */
0052     switch (clusteringAlgorithmType_) {
0053       case dRC2d:
0054         clustering_->clusterizeDR(triggerCellsPtrs, collCluster2D);
0055         break;
0056       case NNC2d:
0057         clustering_->clusterizeNN(triggerCellsPtrs, collCluster2D, *geometry());
0058         break;
0059       case dRNNC2d:
0060         clustering_->clusterizeDRNN(triggerCellsPtrs, collCluster2D, *geometry());
0061         break;
0062       case dummyC2d:
0063         clusteringDummy_->clusterizeDummy(triggerCellsPtrs, collCluster2D);
0064         break;
0065       default:
0066         // Should not happen, clustering type checked in constructor
0067         break;
0068     }
0069   }
0070 
0071 private:
0072   enum ClusterType { dRC2d, NNC2d, dRNNC2d, dummyC2d };
0073 
0074   /* algorithms instances */
0075   std::unique_ptr<HGCalClusteringImpl> clustering_;
0076   std::unique_ptr<HGCalClusteringDummyImpl> clusteringDummy_;
0077 
0078   /* algorithm type */
0079   ClusterType clusteringAlgorithmType_;
0080 };
0081 
0082 DEFINE_EDM_PLUGIN(HGCalBackendLayer1Factory,
0083                   HGCalBackendLayer1Processor2DClustering,
0084                   "HGCalBackendLayer1Processor2DClustering");