diff --git a/plugins/MuonMiniIso.cc b/plugins/MuonMiniIso.cc new file mode 100644 index 00000000000..abb11450ad6 --- /dev/null +++ b/plugins/MuonMiniIso.cc @@ -0,0 +1,150 @@ +// system include files +#include +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/ESHandle.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +#include "DataFormats/Math/interface/deltaR.h" +#include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/MuonReco/interface/Muon.h" +#include "DataFormats/EgammaCandidates/interface/GsfElectron.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" + +// +// class declaration +// + +class MuonMiniIso : public edm::EDProducer { +public: + + typedef std::vector< edm::FwdPtr > PFCollection; + + explicit MuonMiniIso(const edm::ParameterSet&); + ~MuonMiniIso(); + +private: + virtual void produce(edm::Event&, const edm::EventSetup&); + + // ----------member data --------------------------- + const edm::InputTag probes_; + const edm::InputTag pfCandidates_; + double dRCandProbeVeto_; + double CandPtThreshold_; + double ChargedPVdZ_; + bool usePUcands_; + + /// Store extra information in a ValueMap + template + void storeMap(edm::Event &iEvent, + const Hand & handle, + const std::vector & values, + const std::string & label) const ; +}; + +// +// constants, enums and typedefs +// + + +// +// static data member definitions +// + +// +// constructors and destructor +// +MuonMiniIso::MuonMiniIso(const edm::ParameterSet& iConfig): +probes_(iConfig.getParameter("probes")), +pfCandidates_(iConfig.getParameter("pfCandidates")), +dRCandProbeVeto_(iConfig.getParameter("dRCandProbeVeto")), +CandPtThreshold_(iConfig.getParameter("CandPtThreshold")) +{ + produces >(); +} + + +MuonMiniIso::~MuonMiniIso() +{ +} + + +// +// member functions +// + +// ------------ method called to produce the data ------------ +void +MuonMiniIso::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + using namespace edm; + + // read input + Handle > probes; + iEvent.getByLabel(probes_, probes); + + //Handle > pfCandidates; + Handle pfCandidates; + iEvent.getByLabel(pfCandidates_, pfCandidates); + + View::const_iterator probe, endprobes=probes->end(); + PFCollection::const_iterator iP, beginpf = pfCandidates->begin(), endpf=pfCandidates->end(); + unsigned int n = probes->size(); + + std::vector iso(n,0); + + // loop on PROBES + unsigned int imu = 0; + for (probe = probes->begin(); probe != endprobes; ++probe, ++imu) { + const reco::Muon &mu = *probe; + + // loop on PF candidates + int ipf=0; + for (iP = beginpf; iP != endpf; ++iP, ++ipf) { + + // check pf candidate threshold + if(iP->get()->pt() < CandPtThreshold_) continue; + + double dr = deltaR( *(iP->get() ) , mu ); + // check dr min + if (dr < dRCandProbeVeto_) continue; + + // miniiso definition + if (mu.pt()<=50 && dr > 0.2) continue; + if (50 < mu.pt() && mu.pt() < 200 && dr > 10/mu.pt()) continue; + if (mu.pt()>200 && dr > 0.05) continue; + + iso[imu] += iP->get()->pt(); + + } + }// end loop on probes + + storeMap(iEvent, probes, iso, ""); +} + +template +void +MuonMiniIso::storeMap(edm::Event &iEvent, +const Hand & handle, +const std::vector & values, +const std::string & label) const { + using namespace edm; using namespace std; + auto_ptr > valMap(new ValueMap()); + typename edm::ValueMap::Filler filler(*valMap); + filler.insert(handle, values.begin(), values.end()); + filler.fill(); + iEvent.put(valMap, label); +} + +//define this as a plug-in +DEFINE_FWK_MODULE(MuonMiniIso); diff --git a/python/common_modules_cff.py b/python/common_modules_cff.py index c8289e3ddd9..45639d1507b 100644 --- a/python/common_modules_cff.py +++ b/python/common_modules_cff.py @@ -117,6 +117,34 @@ ) * probeMuonsIsoValueMaps ) +muonMiniIsoCharged = cms.EDProducer("MuonMiniIso", + probes = cms.InputTag("probeMuons"), + pfCandidates = cms.InputTag("pfAllChargedHadronsPFBRECO"), + dRCandProbeVeto = cms.double(0.0001), + CandPtThreshold = cms.double(0.0), +) + +muonMiniIsoPUCharged = cms.EDProducer("MuonMiniIso", + probes = cms.InputTag("probeMuons"), + pfCandidates = cms.InputTag("pfPileUpAllChargedParticlesPFBRECO"), + dRCandProbeVeto = cms.double(0.0001), + CandPtThreshold = cms.double(0.0), +) + +muonMiniIsoNeutrals = cms.EDProducer("MuonMiniIso", + probes = cms.InputTag("probeMuons"), + pfCandidates = cms.InputTag("pfAllNeutralHadronsPFBRECO"), + dRCandProbeVeto = cms.double(0.01), + CandPtThreshold = cms.double(1.0), +) + +muonMiniIsoPhotons = cms.EDProducer("MuonMiniIso", + probes = cms.InputTag("probeMuons"), + pfCandidates = cms.InputTag("pfAllPhotonsPFBRECO"), + dRCandProbeVeto = cms.double(0.01), + CandPtThreshold = cms.double(0.5), +) + ######################################################################################### ## Other modules ## diff --git a/test/zmumu/tp_from_aod_Data.py b/test/zmumu/tp_from_aod_Data.py index 4c2a30ee692..f244bd40bff 100644 --- a/test/zmumu/tp_from_aod_Data.py +++ b/test/zmumu/tp_from_aod_Data.py @@ -174,6 +174,10 @@ dxyPVdzmin = cms.InputTag("muonDxyPVdzmin","dxyPVdzmin"), dzPV = cms.InputTag("muonDxyPVdzmin","dzPV"), radialIso = cms.InputTag("radialIso"), + miniIsoCharged = cms.InputTag("muonMiniIsoCharged"), + miniIsoPUCharged = cms.InputTag("muonMiniIsoPUCharged"), + miniIsoNeutrals = cms.InputTag("muonMiniIsoNeutrals"), + miniIsoPhotons = cms.InputTag("muonMiniIsoPhotons"), nSplitTk = cms.InputTag("splitTrackTagger"), ), flags = cms.PSet( @@ -239,13 +243,23 @@ process.load("MuonAnalysis.TagAndProbe.muon.tag_probe_muon_extraIso_cfi") +process.load("PhysicsTools.PatAlgos.recoLayer0.pfParticleSelectionForIso_cff") + +process.miniIsoSeq = cms.Sequence( + process.pfParticleSelectionForIsoSequence + + process.muonMiniIsoCharged + + process.muonMiniIsoPUCharged + + process.muonMiniIsoNeutrals + + process.muonMiniIsoPhotons +) process.extraProbeVariablesSeq = cms.Sequence( process.probeMuonsIsoSequence + process.computeCorrectedIso + process.mvaIsoVariablesSeq * process.mvaIsoVariablesTag * process.radialIso + process.splitTrackTagger + - process.muonDxyPVdzmin + process.muonDxyPVdzmin + + process.miniIsoSeq ) process.tnpSimpleSequence = cms.Sequence( diff --git a/test/zmumu/tp_from_aod_MC.py b/test/zmumu/tp_from_aod_MC.py index fbb766f7f34..b62d16d8c2a 100644 --- a/test/zmumu/tp_from_aod_MC.py +++ b/test/zmumu/tp_from_aod_MC.py @@ -144,6 +144,10 @@ dxyPVdzmin = cms.InputTag("muonDxyPVdzmin","dxyPVdzmin"), dzPV = cms.InputTag("muonDxyPVdzmin","dzPV"), radialIso = cms.InputTag("radialIso"), + miniIsoCharged = cms.InputTag("muonMiniIsoCharged"), + miniIsoPUCharged = cms.InputTag("muonMiniIsoPUCharged"), + miniIsoNeutrals = cms.InputTag("muonMiniIsoNeutrals"), + miniIsoPhotons = cms.InputTag("muonMiniIsoPhotons"), nSplitTk = cms.InputTag("splitTrackTagger"), ), flags = cms.PSet( @@ -213,13 +217,23 @@ process.load("MuonAnalysis.TagAndProbe.muon.tag_probe_muon_extraIso_cfi") +process.load("PhysicsTools.PatAlgos.recoLayer0.pfParticleSelectionForIso_cff") + +process.miniIsoSeq = cms.Sequence( + process.pfParticleSelectionForIsoSequence + + process.muonMiniIsoCharged + + process.muonMiniIsoPUCharged + + process.muonMiniIsoNeutrals + + process.muonMiniIsoPhotons +) process.extraProbeVariablesSeq = cms.Sequence( process.probeMuonsIsoSequence + process.computeCorrectedIso + process.mvaIsoVariablesSeq * process.mvaIsoVariablesTag * process.radialIso + process.splitTrackTagger + - process.muonDxyPVdzmin + process.muonDxyPVdzmin + + process.miniIsoSeq ) process.tnpSimpleSequence = cms.Sequence(