Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:44

0001 #include "FWCore/Framework/interface/stream/EDProducer.h"
0002 #include "FWCore/Framework/interface/Run.h"
0003 #include "FWCore/Framework/interface/EventSetup.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/Utilities/interface/EDGetToken.h"
0007 #include "FWCore/Utilities/interface/EDPutToken.h"
0008 #include "FWCore/Utilities/interface/ESGetToken.h"
0009 #include "FWCore/Utilities/interface/InputTag.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "DataFormats/Common/interface/Handle.h"
0012 
0013 #include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
0014 #include "L1Trigger/TrackTrigger/interface/Setup.h"
0015 #include "L1Trigger/TrackerTFP/interface/DataFormats.h"
0016 #include "L1Trigger/TrackerTFP/interface/ZHoughTransform.h"
0017 
0018 #include <string>
0019 #include <numeric>
0020 
0021 using namespace std;
0022 using namespace edm;
0023 using namespace tt;
0024 
0025 namespace trackerTFP {
0026 
0027   /*! \class  trackerTFP::ProducerZHT
0028    *  \brief  L1TrackTrigger r-z Hough Transform emulator
0029    *  \author Thomas Schuh
0030    *  \date   2021, May
0031    */
0032   class ProducerZHT : public stream::EDProducer<> {
0033   public:
0034     explicit ProducerZHT(const ParameterSet&);
0035     ~ProducerZHT() override {}
0036 
0037   private:
0038     void beginRun(const Run&, const EventSetup&) override;
0039     void produce(Event&, const EventSetup&) override;
0040     virtual void endJob() {}
0041 
0042     // ED input token of gp stubs
0043     EDGetTokenT<StreamsStub> edGetToken_;
0044     // ED output token for accepted stubs
0045     EDPutTokenT<StreamsStub> edPutTokenAccepted_;
0046     // ED output token for lost stubs
0047     EDPutTokenT<StreamsStub> edPutTokenLost_;
0048     // Setup token
0049     ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0050     // DataFormats token
0051     ESGetToken<DataFormats, DataFormatsRcd> esGetTokenDataFormats_;
0052     // configuration
0053     ParameterSet iConfig_;
0054     // helper class to store configurations
0055     const Setup* setup_ = nullptr;
0056     // helper class to extract structured data from tt::Frames
0057     const DataFormats* dataFormats_ = nullptr;
0058   };
0059 
0060   ProducerZHT::ProducerZHT(const ParameterSet& iConfig) : iConfig_(iConfig) {
0061     const string& label = iConfig.getParameter<string>("LabelMHT");
0062     const string& branchAccepted = iConfig.getParameter<string>("BranchAcceptedStubs");
0063     const string& branchLost = iConfig.getParameter<string>("BranchLostStubs");
0064     // book in- and output ED products
0065     edGetToken_ = consumes<StreamsStub>(InputTag(label, branchAccepted));
0066     edPutTokenAccepted_ = produces<StreamsStub>(branchAccepted);
0067     edPutTokenLost_ = produces<StreamsStub>(branchLost);
0068     // book ES products
0069     esGetTokenSetup_ = esConsumes<Setup, SetupRcd, Transition::BeginRun>();
0070     esGetTokenDataFormats_ = esConsumes<DataFormats, DataFormatsRcd, Transition::BeginRun>();
0071   }
0072 
0073   void ProducerZHT::beginRun(const Run& iRun, const EventSetup& iSetup) {
0074     // helper class to store configurations
0075     setup_ = &iSetup.getData(esGetTokenSetup_);
0076     if (!setup_->configurationSupported())
0077       return;
0078     // check process history if desired
0079     if (iConfig_.getParameter<bool>("CheckHistory"))
0080       setup_->checkHistory(iRun.processHistory());
0081     // helper class to extract structured data from tt::Frames
0082     dataFormats_ = &iSetup.getData(esGetTokenDataFormats_);
0083   }
0084 
0085   void ProducerZHT::produce(Event& iEvent, const EventSetup& iSetup) {
0086     // empty MHT products
0087     StreamsStub accepted(dataFormats_->numStreams(Process::mht));
0088     StreamsStub lost(dataFormats_->numStreams(Process::mht));
0089     // read in HT Product and produce MHT product
0090     if (setup_->configurationSupported()) {
0091       Handle<StreamsStub> handle;
0092       iEvent.getByToken<StreamsStub>(edGetToken_, handle);
0093       const StreamsStub& streams = *handle.product();
0094       for (int region = 0; region < setup_->numRegions(); region++) {
0095         // object to find in a region finer rough candidates in r-phi
0096         ZHoughTransform zht(iConfig_, setup_, dataFormats_, region);
0097         // read in and organize input product
0098         zht.consume(streams);
0099         // fill output products
0100         zht.produce(accepted, lost);
0101       }
0102     }
0103     // store products
0104     iEvent.emplace(edPutTokenAccepted_, std::move(accepted));
0105     iEvent.emplace(edPutTokenLost_, std::move(lost));
0106   }
0107 
0108 }  // namespace trackerTFP
0109 
0110 DEFINE_FWK_MODULE(trackerTFP::ProducerZHT);