Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-16 02:43:04

0001 #include <memory>
0002 #include "FWCore/Framework/interface/Frameworkfwd.h"
0003 #include "FWCore/Framework/interface/stream/EDProducer.h"
0004 
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Utilities/interface/StreamID.h"
0010 #include "DataFormats/L1TMuonPhase2/interface/TrackerMuon.h"
0011 #include "L1Trigger/Phase2L1GMT/interface/TPS.h"
0012 
0013 //
0014 // class declaration
0015 //
0016 using namespace Phase2L1GMT;
0017 using namespace l1t;
0018 
0019 class Phase2L1TGMTTkMuonProducer : public edm::stream::EDProducer<> {
0020 public:
0021   explicit Phase2L1TGMTTkMuonProducer(const edm::ParameterSet&);
0022   ~Phase2L1TGMTTkMuonProducer() override;
0023 
0024   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0025 
0026 private:
0027   void beginStream(edm::StreamID) override;
0028   void produce(edm::Event&, const edm::EventSetup&) override;
0029   void endStream() override;
0030   std::unique_ptr<TPS> tps_;
0031   edm::EDGetTokenT<l1t::TrackerMuon::L1TTTrackCollection> srcTracks_;
0032   edm::EDGetTokenT<std::vector<l1t::MuonStub> > srcStubs_;
0033   int minTrackStubs_;
0034   int bxMin_;
0035   int bxMax_;
0036 };
0037 
0038 Phase2L1TGMTTkMuonProducer::Phase2L1TGMTTkMuonProducer(const edm::ParameterSet& iConfig)
0039     : tps_(new TPS(iConfig)),
0040       srcTracks_(consumes<l1t::TrackerMuon::L1TTTrackCollection>(iConfig.getParameter<edm::InputTag>("srcTracks"))),
0041       srcStubs_(consumes<std::vector<l1t::MuonStub> >(iConfig.getParameter<edm::InputTag>("srcStubs"))),
0042       minTrackStubs_(iConfig.getParameter<int>("minTrackStubs")),
0043       bxMin_(iConfig.getParameter<int>("muonBXMin")),
0044       bxMax_(iConfig.getParameter<int>("muonBXMax"))
0045 
0046 {
0047   produces<std::vector<l1t::TrackerMuon> >();
0048 }
0049 
0050 Phase2L1TGMTTkMuonProducer::~Phase2L1TGMTTkMuonProducer() {
0051   // do anything here that needs to be done at destruction time
0052   // (e.g. close files, deallocate resources etc.)
0053 }
0054 
0055 //
0056 // member functions
0057 //
0058 
0059 // ------------ method called to produce the data  ------------
0060 void Phase2L1TGMTTkMuonProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0061   using namespace edm;
0062   Handle<l1t::TrackerMuon::L1TTTrackCollection> trackHandle;
0063   iEvent.getByToken(srcTracks_, trackHandle);
0064   std::vector<edm::Ptr<l1t::TrackerMuon::L1TTTrackType> > tracks;
0065   for (uint i = 0; i < trackHandle->size(); ++i) {
0066     edm::Ptr<l1t::TrackerMuon::L1TTTrackType> track(trackHandle, i);
0067     if (track->momentum().transverse() < 2.0)
0068       continue;
0069     if (track->getStubRefs().size() >= (unsigned int)(minTrackStubs_))
0070       tracks.push_back(track);
0071   }
0072 
0073   l1t::MuonStubRefVector muonStubs;
0074   Handle<std::vector<l1t::MuonStub> > stubHandle;
0075   iEvent.getByToken(srcStubs_, stubHandle);
0076   for (size_t i = 0; i < stubHandle->size(); ++i) {
0077     MuonStubRef stub(stubHandle, i);
0078     muonStubs.push_back(stub);
0079   }
0080 
0081   std::vector<l1t::TrackerMuon> out = tps_->processEvent(tracks, muonStubs);
0082   std::unique_ptr<std::vector<l1t::TrackerMuon> > out1 = std::make_unique<std::vector<l1t::TrackerMuon> >(out);
0083   iEvent.put(std::move(out1));
0084 }
0085 
0086 // ------------ method called once each stream before processing any runs, lumis or events  ------------
0087 void Phase2L1TGMTTkMuonProducer::beginStream(edm::StreamID) {}
0088 
0089 // ------------ method called once each stream after processing all runs, lumis and events  ------------
0090 void Phase2L1TGMTTkMuonProducer::endStream() {}
0091 
0092 void Phase2L1TGMTTkMuonProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0093   //The following says we do not know what parameters are allowed so do no validation
0094   // Please change this to state exactly what you do use, even if it is no parameters
0095   edm::ParameterSetDescription desc;
0096   desc.setUnknown();
0097   descriptions.addDefault(desc);
0098 }
0099 
0100 //define this as a plug-in
0101 DEFINE_FWK_MODULE(Phase2L1TGMTTkMuonProducer);