Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:01

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