Skip to content

Commit

Permalink
Merge pull request #8 from perrozzi/74X
Browse files Browse the repository at this point in the history
first implementation of miniIsolation
  • Loading branch information
gpetruc committed Aug 31, 2015
2 parents 0d48950 + b4c7884 commit 8f304f6
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 2 deletions.
150 changes: 150 additions & 0 deletions plugins/MuonMiniIso.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// system include files
#include <memory>
#include <cmath>

// 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<reco::PFCandidate> > 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<typename Hand, typename T>
void storeMap(edm::Event &iEvent,
const Hand & handle,
const std::vector<T> & 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<edm::InputTag>("probes")),
pfCandidates_(iConfig.getParameter<edm::InputTag>("pfCandidates")),
dRCandProbeVeto_(iConfig.getParameter<double>("dRCandProbeVeto")),
CandPtThreshold_(iConfig.getParameter<double>("CandPtThreshold"))
{
produces<edm::ValueMap<float> >();
}


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<View<reco::Muon> > probes;
iEvent.getByLabel(probes_, probes);

//Handle<View<reco::PFCandidate> > pfCandidates;
Handle<PFCollection> pfCandidates;
iEvent.getByLabel(pfCandidates_, pfCandidates);

View<reco::Muon>::const_iterator probe, endprobes=probes->end();
PFCollection::const_iterator iP, beginpf = pfCandidates->begin(), endpf=pfCandidates->end();
unsigned int n = probes->size();

std::vector<float> 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<typename Hand, typename T>
void
MuonMiniIso::storeMap(edm::Event &iEvent,
const Hand & handle,
const std::vector<T> & values,
const std::string & label) const {
using namespace edm; using namespace std;
auto_ptr<ValueMap<T> > valMap(new ValueMap<T>());
typename edm::ValueMap<T>::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);
28 changes: 28 additions & 0 deletions python/common_modules_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##
Expand Down
16 changes: 15 additions & 1 deletion test/zmumu/tp_from_aod_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 15 additions & 1 deletion test/zmumu/tp_from_aod_MC.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 8f304f6

Please sign in to comment.