Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 "DataFormats/L1TMuonPhase2/interface/SAMuon.h"
0012 
0013 //
0014 // class declaration
0015 //
0016 using namespace Phase2L1GMT;
0017 using namespace l1t;
0018 
0019 class Phase2L1TGMTFilter : public edm::stream::EDProducer<> {
0020 public:
0021   explicit Phase2L1TGMTFilter(const edm::ParameterSet&);
0022   ~Phase2L1TGMTFilter() 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   edm::EDGetTokenT<std::vector<l1t::TrackerMuon> > srcMuons_;
0031   bool applyLowPtFilter_;
0032   int ptBarrelMin_;
0033   int ptEndcapMin_;
0034   double etaBE_;
0035 };
0036 
0037 Phase2L1TGMTFilter::Phase2L1TGMTFilter(const edm::ParameterSet& iConfig)
0038     : srcMuons_(consumes<std::vector<l1t::TrackerMuon> >(iConfig.getParameter<edm::InputTag>("srcMuons"))),
0039       applyLowPtFilter_(iConfig.getParameter<bool>("applyLowPtFilter")),
0040       ptBarrelMin_(iConfig.getParameter<int>("ptBarrelMin")),
0041       ptEndcapMin_(iConfig.getParameter<int>("ptEndcapMin")),
0042       etaBE_(iConfig.getParameter<double>("etaBE")) {
0043   produces<std::vector<l1t::TrackerMuon> >("l1tTkMuonsGmtLowPtFix").setBranchAlias("tkMuLowPtFix");
0044 }
0045 
0046 Phase2L1TGMTFilter::~Phase2L1TGMTFilter() {
0047   // do anything here that needs to be done at destruction time
0048   // (e.g. close files, deallocate resources etc.)
0049 }
0050 
0051 //
0052 // member functions
0053 //
0054 
0055 // ------------ method called to produce the data  ------------
0056 void Phase2L1TGMTFilter::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0057   using namespace edm;
0058   Handle<std::vector<l1t::TrackerMuon> > muonHandle;
0059   iEvent.getByToken(srcMuons_, muonHandle);
0060 
0061   std::vector<l1t::TrackerMuon> out;
0062 
0063   for (uint i = 0; i < muonHandle->size(); ++i) {
0064     auto mu = muonHandle->at(i);
0065     bool noSAMatch = true;
0066     if (applyLowPtFilter_) {
0067       if ((fabs(mu.phEta()) < etaBE_ && mu.phPt() < ptBarrelMin_) ||
0068           (fabs(mu.phEta()) > etaBE_ && mu.phPt() < ptEndcapMin_)) {
0069         // if quality is already set to 0 don't continue the loop.
0070         for (const auto& r : mu.muonRef()) {
0071           if (r.isNonnull()) {
0072             noSAMatch = false;
0073             break;
0074           }
0075         }
0076         if (noSAMatch)
0077           mu.setHwQual(0);
0078       }
0079     }
0080     out.push_back(mu);  // store all muons otherwise
0081   }
0082 
0083   // store results
0084   std::unique_ptr<std::vector<l1t::TrackerMuon> > out1 = std::make_unique<std::vector<l1t::TrackerMuon> >(out);
0085   iEvent.put(std::move(out1), "l1tTkMuonsGmtLowPtFix");
0086 }
0087 
0088 // ------------ method called once each stream before processing any runs, lumis or events  ------------
0089 void Phase2L1TGMTFilter::beginStream(edm::StreamID) {}
0090 
0091 // ------------ method called once each stream after processing all runs, lumis and events  ------------
0092 void Phase2L1TGMTFilter::endStream() {}
0093 
0094 void Phase2L1TGMTFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0095   //The following says we do not know what parameters are allowed so do no validation
0096   // Please change this to state exactly what you do use, even if it is no parameters
0097   edm::ParameterSetDescription desc;
0098   desc.setUnknown();
0099   descriptions.addDefault(desc);
0100 }
0101 
0102 //define this as a plug-in
0103 DEFINE_FWK_MODULE(Phase2L1TGMTFilter);