Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /** \class MuonIDFilterProducerForHLT
0002  *
0003  *  \author S. Folgueras <santiago.folgueras@cern.ch>
0004  */
0005 
0006 // system include files
0007 #include <memory>
0008 
0009 // user include files
0010 #include "FWCore/Framework/interface/Frameworkfwd.h"
0011 
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 
0017 #include "DataFormats/Common/interface/Handle.h"
0018 #include "RecoMuon/MuonIdentification/plugins/MuonIDFilterProducerForHLT.h"
0019 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0021 #include "FWCore/Utilities/interface/InputTag.h"
0022 
0023 //#include <algorithm>
0024 
0025 MuonIDFilterProducerForHLT::MuonIDFilterProducerForHLT(const edm::ParameterSet& iConfig)
0026     : muonTag_(iConfig.getParameter<edm::InputTag>("inputMuonCollection")),
0027       muonToken_(consumes<reco::MuonCollection>(muonTag_)),
0028       applyTriggerIdLoose_(iConfig.getParameter<bool>("applyTriggerIdLoose")),
0029       type_(muon::SelectionType(iConfig.getParameter<unsigned int>("typeMuon"))),
0030       allowedTypeMask_(iConfig.getParameter<unsigned int>("allowedTypeMask")),
0031       requiredTypeMask_(iConfig.getParameter<unsigned int>("requiredTypeMask")),
0032       min_NMuonHits_(iConfig.getParameter<int>("minNMuonHits")),
0033       min_NMuonStations_(iConfig.getParameter<int>("minNMuonStations")),
0034       min_NTrkLayers_(iConfig.getParameter<int>("minNTrkLayers")),
0035       min_NTrkHits_(iConfig.getParameter<int>("minTrkHits")),
0036       min_PixLayers_(iConfig.getParameter<int>("minPixLayer")),
0037       min_PixHits_(iConfig.getParameter<int>("minPixHits")),
0038       min_Pt_(iConfig.getParameter<double>("minPt")),
0039       max_NormalizedChi2_(iConfig.getParameter<double>("maxNormalizedChi2")) {
0040   produces<reco::MuonCollection>();
0041 }
0042 
0043 MuonIDFilterProducerForHLT::~MuonIDFilterProducerForHLT() {}
0044 void MuonIDFilterProducerForHLT::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0045   edm::ParameterSetDescription desc;
0046   desc.add<edm::InputTag>("inputMuonCollection", edm::InputTag("hltIterL3MuonsNoID"));
0047   desc.add<bool>("applyTriggerIdLoose", true);
0048   desc.add<unsigned int>("typeMuon", 0);
0049   desc.add<unsigned int>("allowedTypeMask", 0);
0050   desc.add<unsigned int>("requiredTypeMask", 0);
0051   desc.add<int>("minNMuonHits", 0);
0052   desc.add<int>("minNMuonStations", 0);
0053   desc.add<int>("minNTrkLayers", 0);
0054   desc.add<int>("minTrkHits", 0);
0055   desc.add<int>("minPixLayer", 0);
0056   desc.add<int>("minPixHits", 0);
0057   desc.add<double>("minPt", 0.);
0058   desc.add<double>("maxNormalizedChi2", 9999.);
0059   descriptions.addWithDefaultLabel(desc);
0060 }
0061 void MuonIDFilterProducerForHLT::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0062   auto output = std::make_unique<reco::MuonCollection>();
0063 
0064   edm::Handle<reco::MuonCollection> muons;
0065   iEvent.getByToken(muonToken_, muons);
0066 
0067   for (unsigned int i = 0; i < muons->size(); ++i) {
0068     const reco::Muon& muon(muons->at(i));
0069     if (applyTriggerIdLoose_ && muon::isLooseTriggerMuon(muon)) {
0070       output->push_back(muon);
0071     } else {  // Implement here manually all the required/desired cuts
0072       if ((muon.type() & allowedTypeMask_) == 0)
0073         continue;
0074       if ((muon.type() & requiredTypeMask_) != requiredTypeMask_)
0075         continue;
0076       // tracker cuts
0077       if (!muon.innerTrack().isNull()) {
0078         if (muon.innerTrack()->hitPattern().trackerLayersWithMeasurement() < min_NTrkLayers_)
0079           continue;
0080         if (muon.innerTrack()->numberOfValidHits() < min_NTrkHits_)
0081           continue;
0082         if (muon.innerTrack()->hitPattern().pixelLayersWithMeasurement() < min_PixLayers_)
0083           continue;
0084         if (muon.innerTrack()->hitPattern().numberOfValidPixelHits() < min_PixHits_)
0085           continue;
0086       }
0087       // muon cuts
0088       if (muon.numberOfMatchedStations() < min_NMuonStations_)
0089         continue;
0090       if (!muon.globalTrack().isNull()) {
0091         if (muon.globalTrack()->normalizedChi2() > max_NormalizedChi2_)
0092           continue;
0093         if (muon.globalTrack()->hitPattern().numberOfValidMuonHits() < min_NMuonHits_)
0094           continue;
0095       }
0096       if (!muon::isGoodMuon(muon, type_))
0097         continue;
0098       if (muon.pt() < min_Pt_)
0099         continue;
0100 
0101       output->push_back(muon);
0102     }
0103   }
0104 
0105   iEvent.put(std::move(output));
0106 }