Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:13:08

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 "Node.h"
0012 
0013 //
0014 // class declaration
0015 //
0016 using namespace Phase2L1GMT;
0017 using namespace l1t;
0018 
0019 class Phase2L1TGMTProducer : public edm::stream::EDProducer<> {
0020 public:
0021   explicit Phase2L1TGMTProducer(const edm::ParameterSet&);
0022   ~Phase2L1TGMTProducer() 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<Node> node_;
0031   edm::EDGetTokenT<l1t::TrackerMuon::L1TTTrackCollection> srcTracks_;
0032   edm::EDGetTokenT<std::vector<l1t::MuonStub> > srcStubs_;
0033   edm::EDGetTokenT<BXVector<RegionalMuonCand> > bmtfTracks_;
0034   edm::EDGetTokenT<BXVector<RegionalMuonCand> > emtfTracks_;
0035   edm::EDGetTokenT<BXVector<RegionalMuonCand> > omtfTracks_;
0036   int minTrackStubs_;
0037   int bxMin_;
0038   int bxMax_;
0039 };
0040 
0041 Phase2L1TGMTProducer::Phase2L1TGMTProducer(const edm::ParameterSet& iConfig)
0042     : node_(new Node(iConfig)),
0043       srcTracks_(consumes<l1t::TrackerMuon::L1TTTrackCollection>(iConfig.getParameter<edm::InputTag>("srcTracks"))),
0044       srcStubs_(consumes<std::vector<l1t::MuonStub> >(iConfig.getParameter<edm::InputTag>("srcStubs"))),
0045       bmtfTracks_(consumes<BXVector<RegionalMuonCand> >(iConfig.getParameter<edm::InputTag>("srcBMTF"))),
0046       emtfTracks_(consumes<BXVector<RegionalMuonCand> >(iConfig.getParameter<edm::InputTag>("srcEMTF"))),
0047       omtfTracks_(consumes<BXVector<RegionalMuonCand> >(iConfig.getParameter<edm::InputTag>("srcOMTF"))),
0048       minTrackStubs_(iConfig.getParameter<int>("minTrackStubs")),
0049       bxMin_(iConfig.getParameter<int>("muonBXMin")),
0050       bxMax_(iConfig.getParameter<int>("muonBXMax"))
0051 
0052 {
0053   produces<std::vector<l1t::TrackerMuon> >();
0054 }
0055 
0056 Phase2L1TGMTProducer::~Phase2L1TGMTProducer() {
0057   // do anything here that needs to be done at destruction time
0058   // (e.g. close files, deallocate resources etc.)
0059 }
0060 
0061 //
0062 // member functions
0063 //
0064 
0065 // ------------ method called to produce the data  ------------
0066 void Phase2L1TGMTProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0067   using namespace edm;
0068   Handle<l1t::TrackerMuon::L1TTTrackCollection> trackHandle;
0069   iEvent.getByToken(srcTracks_, trackHandle);
0070   std::vector<edm::Ptr<l1t::TrackerMuon::L1TTTrackType> > tracks;
0071   for (uint i = 0; i < trackHandle->size(); ++i) {
0072     edm::Ptr<l1t::TrackerMuon::L1TTTrackType> track(trackHandle, i);
0073     if (track->momentum().transverse() < 2.0)
0074       continue;
0075     if (track->getStubRefs().size() >= (unsigned int)(minTrackStubs_))
0076       tracks.push_back(track);
0077   }
0078 
0079   Handle<std::vector<l1t::MuonStub> > stubHandle;
0080   iEvent.getByToken(srcStubs_, stubHandle);
0081   l1t::MuonStubRefVector stubs;
0082   for (uint i = 0; i < stubHandle->size(); ++i) {
0083     l1t::MuonStubRef stub(stubHandle, i);
0084     if (stub->bxNum() >= bxMin_ && stub->bxNum() <= bxMax_)
0085       stubs.push_back(stub);
0086   }
0087 
0088   ObjectRefBxCollection<RegionalMuonCand> muonTracks;
0089   //   BXVector<RegionalMuonCand> muonTracks;
0090 
0091   Handle<BXVector<RegionalMuonCand> > bmtfHandle;
0092   iEvent.getByToken(bmtfTracks_, bmtfHandle);
0093   Handle<BXVector<RegionalMuonCand> > emtfHandle;
0094   iEvent.getByToken(emtfTracks_, emtfHandle);
0095   Handle<BXVector<RegionalMuonCand> > omtfHandle;
0096   iEvent.getByToken(omtfTracks_, omtfHandle);
0097 
0098   for (int bx = bxMin_; bx <= bxMax_; ++bx) {
0099     if (bx >= bmtfHandle->getFirstBX() && bx <= bmtfHandle->getLastBX())
0100       for (size_t i = 0; i < bmtfHandle->size(bx); ++i) {
0101         RegionalMuonCandRef muon(bmtfHandle, i);
0102         muonTracks.push_back(bx, muon);
0103       }
0104     if (bx >= omtfHandle->getFirstBX() && bx <= omtfHandle->getLastBX())
0105       for (size_t i = 0; i < omtfHandle->size(bx); ++i) {
0106         RegionalMuonCandRef muon(omtfHandle, i);
0107         muonTracks.push_back(bx, muon);
0108       }
0109     if (bx >= emtfHandle->getFirstBX() && bx <= emtfHandle->getLastBX())
0110       for (size_t i = 0; i < emtfHandle->size(bx); ++i) {
0111         RegionalMuonCandRef muon(emtfHandle, i);
0112         muonTracks.push_back(bx, muon);
0113       }
0114   }
0115 
0116   std::vector<l1t::TrackerMuon> out = node_->processEvent(tracks, muonTracks, stubs);
0117   std::unique_ptr<std::vector<l1t::TrackerMuon> > out1 = std::make_unique<std::vector<l1t::TrackerMuon> >(out);
0118   iEvent.put(std::move(out1));
0119 }
0120 
0121 // ------------ method called once each stream before processing any runs, lumis or events  ------------
0122 void Phase2L1TGMTProducer::beginStream(edm::StreamID) {}
0123 
0124 // ------------ method called once each stream after processing all runs, lumis and events  ------------
0125 void Phase2L1TGMTProducer::endStream() {}
0126 
0127 void Phase2L1TGMTProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0128   //The following says we do not know what parameters are allowed so do no validation
0129   // Please change this to state exactly what you do use, even if it is no parameters
0130   edm::ParameterSetDescription desc;
0131   desc.setUnknown();
0132   descriptions.addDefault(desc);
0133 }
0134 
0135 //define this as a plug-in
0136 DEFINE_FWK_MODULE(Phase2L1TGMTProducer);