Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/stream/EDProducer.h"
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/Utilities/interface/ESGetToken.h"
0007 
0008 #include "DataFormats/L1THGCal/interface/HGCalTriggerCell.h"
0009 #include "DataFormats/L1THGCal/interface/HGCalTriggerSums.h"
0010 #include "DataFormats/HGCDigi/interface/HGCDigiCollections.h"
0011 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0012 #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h"
0013 
0014 #include "L1Trigger/L1THGCal/interface/HGCalProcessorBase.h"
0015 
0016 #include "DataFormats/L1THGCal/interface/HGCalCluster.h"
0017 
0018 #include "L1Trigger/L1THGCal/interface/backend/HGCalClusteringDummyImpl.h"
0019 #include "L1Trigger/L1THGCal/interface/HGCalProcessorBase.h"
0020 
0021 #include <memory>
0022 
0023 class HGCalBackendStage1Producer : public edm::stream::EDProducer<> {
0024 public:
0025   HGCalBackendStage1Producer(const edm::ParameterSet&);
0026   ~HGCalBackendStage1Producer() override = default;
0027 
0028   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0029   void produce(edm::Event&, const edm::EventSetup&) override;
0030 
0031 private:
0032   // inputs
0033   const edm::EDGetToken input_cell_;
0034   edm::ESHandle<HGCalTriggerGeometryBase> triggerGeometry_;
0035   const edm::ESGetToken<HGCalTriggerGeometryBase, CaloGeometryRecord> triggerGeomToken_;
0036 
0037   std::unique_ptr<HGCalBackendStage1ProcessorBase> backendProcess_;
0038 
0039   std::unique_ptr<HGCalClusteringDummyImpl> clusteringDummy_;
0040 };
0041 
0042 DEFINE_FWK_MODULE(HGCalBackendStage1Producer);
0043 
0044 HGCalBackendStage1Producer::HGCalBackendStage1Producer(const edm::ParameterSet& conf)
0045     : input_cell_(consumes<l1t::HGCalTriggerCellBxCollection>(conf.getParameter<edm::InputTag>("InputTriggerCells"))),
0046       triggerGeomToken_(esConsumes<HGCalTriggerGeometryBase, CaloGeometryRecord, edm::Transition::BeginRun>()) {
0047   //setup Backend parameters
0048   const edm::ParameterSet& beParamConfig = conf.getParameterSet("ProcessorParameters");
0049   const std::string& beProcessorName = beParamConfig.getParameter<std::string>("ProcessorName");
0050 
0051   clusteringDummy_ = std::make_unique<HGCalClusteringDummyImpl>(conf.getParameterSet("C2d_parameters"));
0052 
0053   backendProcess_ = std::unique_ptr<HGCalBackendStage1ProcessorBase>{
0054       HGCalBackendStage1Factory::get()->create(beProcessorName, beParamConfig)};
0055 
0056   produces<l1t::HGCalClusterBxCollection>(backendProcess_->name());
0057 }
0058 
0059 void HGCalBackendStage1Producer::beginRun(const edm::Run& /*run*/, const edm::EventSetup& es) {
0060   triggerGeometry_ = es.getHandle(triggerGeomToken_);
0061   backendProcess_->setGeometry(triggerGeometry_.product());
0062   if (clusteringDummy_)
0063     clusteringDummy_->setGeometry(triggerGeometry_.product());
0064 }
0065 
0066 void HGCalBackendStage1Producer::produce(edm::Event& e, const edm::EventSetup& es) {
0067   // Output collections
0068   auto be_cluster_output = std::make_unique<l1t::HGCalClusterBxCollection>();
0069 
0070   // Input collections
0071   edm::Handle<l1t::HGCalTriggerCellBxCollection> trigCellBxColl;
0072 
0073   // Split trigger cell collection per FPGA
0074   e.getByToken(input_cell_, trigCellBxColl);
0075 
0076   std::unordered_map<uint32_t, std::vector<edm::Ptr<l1t::HGCalTriggerCell>>> tcs_per_fpga;
0077 
0078   for (unsigned i = 0; i < trigCellBxColl->size(); ++i) {
0079     edm::Ptr<l1t::HGCalTriggerCell> tc_ptr(trigCellBxColl, i);
0080     uint32_t module = triggerGeometry_->getModuleFromTriggerCell(tc_ptr->detId());
0081     uint32_t fpga = triggerGeometry_->getStage1FpgaFromModule(module);
0082     tcs_per_fpga[fpga].push_back(tc_ptr);
0083   }
0084 
0085   // Apply truncation per FPGA
0086   std::vector<edm::Ptr<l1t::HGCalTriggerCell>> truncated_tcs;
0087 
0088   for (auto& fpga_tcs : tcs_per_fpga) {
0089     backendProcess_->run(fpga_tcs, truncated_tcs);
0090   }
0091 
0092   // Merge truncated tc collections
0093   clusteringDummy_->clusterizeDummy(truncated_tcs, *be_cluster_output);
0094 
0095   e.put(std::move(be_cluster_output), backendProcess_->name());
0096 }