Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:56

0001 // -*- C++ -*-
0002 //
0003 // Package:    MuonIdentification
0004 // Class:      MuonRefProducer
0005 //
0006 //
0007 // Original Author:  Dmytro Kovalskyi
0008 //
0009 //
0010 
0011 // user include files
0012 #include "FWCore/Framework/interface/Frameworkfwd.h"
0013 //#include "FWCore/Framework/interface/EDProducer.h"
0014 
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 
0020 #include "DataFormats/Common/interface/Handle.h"
0021 #include "DataFormats/MuonReco/interface/Muon.h"
0022 
0023 #include "RecoMuon/MuonIdentification/plugins/MuonRefProducer.h"
0024 #include "DataFormats/Common/interface/Ref.h"
0025 #include "DataFormats/Common/interface/RefVector.h"
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
0028 
0029 MuonRefProducer::MuonRefProducer(const edm::ParameterSet& iConfig) {
0030   theReferenceCollection_ = iConfig.getParameter<edm::InputTag>("ReferenceCollection");
0031   muonToken_ = consumes<reco::MuonCollection>(theReferenceCollection_);
0032 
0033   type_ = muon::TMLastStation;  // default type
0034   std::string type = iConfig.getParameter<std::string>("algorithmType");
0035   if (type != "TMLastStation")
0036     edm::LogWarning("MuonIdentification")
0037         << "Unknown algorithm type is requested: " << type << "\nUsing the default one.";
0038 
0039   minNumberOfMatches_ = iConfig.getParameter<int>("minNumberOfMatchedStations");
0040   maxAbsDx_ = iConfig.getParameter<double>("maxAbsDx");
0041   maxAbsPullX_ = iConfig.getParameter<double>("maxAbsPullX");
0042   maxAbsDy_ = iConfig.getParameter<double>("maxAbsDy");
0043   maxAbsPullY_ = iConfig.getParameter<double>("maxAbsPullY");
0044   maxChamberDist_ = iConfig.getParameter<double>("maxChamberDistance");
0045   maxChamberDistPull_ = iConfig.getParameter<double>("maxChamberDistancePull");
0046 
0047   std::string arbitrationType = iConfig.getParameter<std::string>("arbitrationType");
0048   if (arbitrationType == "NoArbitration")
0049     arbitrationType_ = reco::Muon::NoArbitration;
0050   else if (arbitrationType == "SegmentArbitration")
0051     arbitrationType_ = reco::Muon::SegmentArbitration;
0052   else if (arbitrationType == "SegmentAndTrackArbitration")
0053     arbitrationType_ = reco::Muon::SegmentAndTrackArbitration;
0054   else {
0055     edm::LogWarning("MuonIdentification")
0056         << "Unknown arbitration type is requested: " << arbitrationType << "\nUsing the default one";
0057     arbitrationType_ = reco::Muon::SegmentAndTrackArbitration;
0058   }
0059   produces<edm::RefVector<std::vector<reco::Muon>>>();
0060 }
0061 
0062 MuonRefProducer::~MuonRefProducer() {}
0063 
0064 void MuonRefProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0065   auto outputCollection = std::make_unique<edm::RefVector<std::vector<reco::Muon>>>();
0066 
0067   edm::Handle<reco::MuonCollection> muons;
0068   iEvent.getByToken(muonToken_, muons);
0069 
0070   // loop over input collection
0071   for (unsigned int i = 0; i < muons->size(); ++i)
0072     if (muon::isGoodMuon((*muons)[i],
0073                          type_,
0074                          minNumberOfMatches_,
0075                          maxAbsDx_,
0076                          maxAbsPullX_,
0077                          maxAbsDy_,
0078                          maxAbsPullY_,
0079                          maxChamberDist_,
0080                          maxChamberDistPull_,
0081                          arbitrationType_))
0082       outputCollection->push_back(edm::RefVector<std::vector<reco::Muon>>::value_type(muons, i));
0083   iEvent.put(std::move(outputCollection));
0084 }