Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronize MET recipe with 93X Puppi #23

Open
wants to merge 7 commits into
base: METRecipe_80X_part2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CommonTools/PileupAlgos/interface/PuppiContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class PuppiContainer{
double fNeutralMinPt;
double fNeutralSlope;
double fPuppiWeightCut;
double fPtMax;
int fNAlgos;
int fNPV;
double fPVFrac;
Expand Down
45 changes: 34 additions & 11 deletions CommonTools/PileupAlgos/plugins/PuppiPhoton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,19 @@
PuppiPhoton::PuppiPhoton(const edm::ParameterSet& iConfig) {
tokenPFCandidates_ = consumes<CandidateView>(iConfig.getParameter<edm::InputTag>("candName"));
tokenPuppiCandidates_ = consumes<CandidateView>(iConfig.getParameter<edm::InputTag>("puppiCandName"));
tokenPhotonCandidates_ = consumes<CandidateView>(iConfig.getParameter<edm::InputTag>("photonName"));
reco2pf_ = mayConsume<edm::ValueMap<std::vector<reco::PFCandidateRef> > >(iConfig.getParameter<edm::InputTag>("recoToPFMap"));
tokenPhotonId_ = mayConsume<edm::ValueMap<bool> >(iConfig.getParameter<edm::InputTag>("photonId"));
usePFphotons_ = iConfig.getParameter<bool>("usePFphotons");
if(!usePFphotons_)
tokenPhotonCandidates_ = consumes<CandidateView>(iConfig.getParameter<edm::InputTag>("photonName"));
usePhotonId_ = (iConfig.getParameter<edm::InputTag>("photonId")).label().size() != 0;
if(usePhotonId_)
tokenPhotonId_ = consumes<edm::ValueMap<bool> >(iConfig.getParameter<edm::InputTag>("photonId"));
runOnMiniAOD_ = iConfig.getParameter<bool>("runOnMiniAOD");
if(!runOnMiniAOD_)
reco2pf_ = consumes<edm::ValueMap<std::vector<reco::PFCandidateRef> > >(iConfig.getParameter<edm::InputTag>("recoToPFMap"));
useValueMap_ = iConfig.getParameter<bool>("useValueMap");
if(useValueMap_)
tokenWeights_ = consumes<edm::ValueMap<float> >(iConfig.getParameter<edm::InputTag>("weightsName"));

pt_ = iConfig.getParameter<double>("pt");
eta_ = iConfig.getParameter<double>("eta");
dRMatch_ = iConfig.getParameter<std::vector<double> > ("dRMatch");
Expand All @@ -51,13 +61,6 @@ PuppiPhoton::PuppiPhoton(const edm::ParameterSet& iConfig) {
PuppiPhoton::~PuppiPhoton(){}
// ------------------------------------------------------------------------------------------
void PuppiPhoton::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {

edm::Handle<CandidateView> hPhoProduct;
iEvent.getByToken(tokenPhotonCandidates_,hPhoProduct);
const CandidateView *phoCol = hPhoProduct.product();

edm::Handle<edm::ValueMap<bool> > photonId;
if(usePhotonId_) iEvent.getByToken(tokenPhotonId_,photonId);
int iC = -1;
std::vector<const reco::Candidate*> phoCands;
std::vector<uint16_t> phoIndx;
Expand All @@ -73,7 +76,25 @@ void PuppiPhoton::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::Handle<CandidateView> hPuppiProduct;
iEvent.getByToken(tokenPuppiCandidates_,hPuppiProduct);
const CandidateView *pupCol = hPuppiProduct.product();
for(CandidateView::const_iterator itPho = phoCol->begin(); itPho!=phoCol->end(); itPho++) {
if(usePFphotons_) {
for(const auto & pho : *pfCol) {
iC++;
if(pho.pt() < pt_) continue;
if(std::abs(pho.pdgId())!=22) continue;
if(fabs(pho.eta()) < eta_ ) {
phoIndx.push_back(iC);
phoCands.push_back(&pho);
}
}
} else {
edm::Handle<CandidateView> hPhoProduct;
iEvent.getByToken(tokenPhotonCandidates_,hPhoProduct);
const CandidateView *phoCol = hPhoProduct.product();

edm::Handle<edm::ValueMap<bool> > photonId;
if(usePhotonId_) iEvent.getByToken(tokenPhotonId_,photonId);

for(CandidateView::const_iterator itPho = phoCol->begin(); itPho!=phoCol->end(); itPho++) {
iC++;
bool passObject = false;
if(itPho->isPhoton() && usePhotonId_) passObject = (*photonId) [phoCol->ptrAt(iC)];
Expand Down Expand Up @@ -106,6 +127,7 @@ void PuppiPhoton::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
}
}
}
}
}
//Get Weights
edm::Handle<edm::ValueMap<float> > pupWeights;
Expand Down Expand Up @@ -182,6 +204,7 @@ void PuppiPhoton::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
}
// ------------------------------------------------------------------------------------------
bool PuppiPhoton::matchPFCandidate(const reco::Candidate *iPF,const reco::Candidate *iPho) {
if(iPF->pdgId() != iPho->pdgId()) return false;
double lDR = deltaR(iPF->eta(),iPF->phi(),iPho->eta(),iPho->phi());
for(unsigned int i0 = 0; i0 < pdgIds_.size(); i0++) {
if(std::abs(iPF->pdgId()) == pdgIds_[i0] && lDR < dRMatch_[i0]) return true;
Expand Down
1 change: 1 addition & 0 deletions CommonTools/PileupAlgos/plugins/PuppiPhoton.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class PuppiPhoton : public edm::stream::EDProducer<> {
double pt_;
double eta_;
bool usePFRef_;
bool usePFphotons_;
bool runOnMiniAOD_;
bool usePhotonId_;
std::vector<double> dRMatch_;
Expand Down
1 change: 1 addition & 0 deletions CommonTools/PileupAlgos/plugins/PuppiProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ PuppiProducer::PuppiProducer(const edm::ParameterSet& iConfig) {
fPuppiForLeptons = iConfig.getParameter<bool>("puppiForLeptons");
fUseDZ = iConfig.getParameter<bool>("UseDeltaZCut");
fDZCut = iConfig.getParameter<double>("DeltaZCut");
fPtMax = iConfig.getParameter<double>("PtMaxNeutrals");
fUseExistingWeights = iConfig.getParameter<bool>("useExistingWeights");
fUseWeightsNoLep = iConfig.getParameter<bool>("useWeightsNoLep");
fClonePackedCands = iConfig.getParameter<bool>("clonePackedCands");
Expand Down
1 change: 1 addition & 0 deletions CommonTools/PileupAlgos/plugins/PuppiProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class PuppiProducer : public edm::stream::EDProducer<> {
bool fPuppiForLeptons;
bool fUseDZ;
float fDZCut;
float fPtMax;
bool fUseExistingWeights;
bool fUseWeightsNoLep;
bool fClonePackedCands;
Expand Down
13 changes: 7 additions & 6 deletions CommonTools/PileupAlgos/python/PhotonPuppi_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
puppiPhoton = cms.EDProducer("PuppiPhoton",
candName = cms.InputTag('particleFlow'),
puppiCandName = cms.InputTag('puppi'),
usePFphotons = cms.bool(True), # Use PF photons and not GED photons
photonName = cms.InputTag('reducedEgamma','reducedGedPhotons'),
recoToPFMap = cms.InputTag("reducedEgamma","reducedPhotonPfCandMap"),
photonId = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring15-25ns-V1-standalone-loose"),
pt = cms.double(10),
recoToPFMap = cms.InputTag("reducedEgamma","reducedPhotonPfCandMap"),
photonId = cms.InputTag(""),
pt = cms.double(20),
eta = cms.double(2.5),
runOnMiniAOD = cms.bool(False),
runOnMiniAOD = cms.bool(False), # If set to true photon ID is taken from pat::Photon, otherwise from the value map at RECO/AOD level
useRefs = cms.bool(True),
dRMatch = cms.vdouble(0.005,0.005,0.005,0.005),
pdgids = cms.vint32 (22,11,211,130),
Expand All @@ -20,14 +21,14 @@


def setupPuppiPhoton(process):
my_id_modules = ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring15_25ns_V1_cff']
my_id_modules = [] # Add photon ID used by puppiPhoton producer here
switchOnVIDPhotonIdProducer(process, DataFormat.AOD)
for idmod in my_id_modules:
setupAllVIDIdsInModule(process,idmod,setupVIDPhotonSelection)


def setupPuppiPhotonMiniAOD(process):
my_id_modules = ['RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring15_25ns_V1_cff']
my_id_modules = [] # Add photon ID used by puppiPhoton producer here
switchOnVIDPhotonIdProducer(process, DataFormat.MiniAOD)
for idmod in my_id_modules:
setupAllVIDIdsInModule(process,idmod,setupVIDPhotonSelection)
Expand Down
1 change: 1 addition & 0 deletions CommonTools/PileupAlgos/python/Puppi_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
puppiForLeptons = cms.bool(False),
UseDeltaZCut = cms.bool(True),
DeltaZCut = cms.double(0.3),
PtMaxNeutrals = cms.double(200.),
candName = cms.InputTag('particleFlow'),
vertexName = cms.InputTag('offlinePrimaryVertices'),
#candName = cms.string('packedPFCandidates'),
Expand Down
2 changes: 2 additions & 0 deletions CommonTools/PileupAlgos/src/PuppiContainer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ PuppiContainer::PuppiContainer(const edm::ParameterSet &iConfig) {
fInvert = iConfig.getParameter<bool>("invertPuppi");
fUseExp = iConfig.getParameter<bool>("useExp");
fPuppiWeightCut = iConfig.getParameter<double>("MinPuppiWeight");
fPtMax = iConfig.getParameter<double>("PtMaxNeutrals");
std::vector<edm::ParameterSet> lAlgos = iConfig.getParameter<std::vector<edm::ParameterSet> >("algos");
fNAlgos = lAlgos.size();
for(unsigned int i0 = 0; i0 < lAlgos.size(); i0++) {
Expand Down Expand Up @@ -262,6 +263,7 @@ std::vector<double> const & PuppiContainer::puppiWeights() {
if(pWeight*fPFParticles[i0].pt() < fPuppiAlgo[pPupId].neutralPt(fNPV) && fRecoParticles[i0].id == 0 ) pWeight = 0; //threshold cut on the neutral Pt
if(fInvert) pWeight = 1.-pWeight;
//std::cout << "fRecoParticles[i0].pt = " << fRecoParticles[i0].pt << ", fRecoParticles[i0].charge = " << fRecoParticles[i0].charge << ", fRecoParticles[i0].id = " << fRecoParticles[i0].id << ", weight = " << pWeight << std::endl;
if((fPtMax>0) && (fRecoParticles[i0].id == 0)) pWeight=min(max(pWeight,fPFParticles[i0].pt()/fPtMax),1.);

fWeights .push_back(pWeight);
fAlphaMed.push_back(fPuppiAlgo[pPupId].median());
Expand Down