Skip to content

Commit

Permalink
Merge pull request cms-sw#162 from steggema/HTauTauMiniAOD
Browse files Browse the repository at this point in the history
Update H->tau tau miniAOD setup
  • Loading branch information
steggema committed Dec 5, 2014
2 parents c1a36be + 5412ec5 commit 17549cd
Show file tree
Hide file tree
Showing 32 changed files with 1,347 additions and 560 deletions.
121 changes: 46 additions & 75 deletions CMGTools/Common/plugins/MetFlavorProducer.cc
Expand Up @@ -24,9 +24,6 @@
#include "FWCore/Utilities/interface/Exception.h"
#include "CMGTools/Common/plugins/MetFlavorProducer.h"

using namespace edm;
using namespace std;
using namespace reco;

MetFlavorProducer::MetFlavorProducer(const edm::ParameterSet& iConfig) {
produces<reco::PFMETCollection>();
Expand All @@ -40,8 +37,10 @@ MetFlavorProducer::MetFlavorProducer(const edm::ParameterSet& iConfig) {
fDZMin = iConfig.getParameter<double> ("dZMin");
fMetFlavor = iConfig.getParameter<int> ("MetFlavor");
fUtils = new MetUtilities( iConfig.getParameter<unsigned>("WorkingPointId") );
fPUJetIdAlgo = new PileupJetIdAlgo(iConfig.getParameter<edm::ParameterSet>("PUJetId"));
fPUJetIdAlgoLowPt = new PileupJetIdAlgo(iConfig.getParameter<edm::ParameterSet>("PUJetIdLowPt"));
fPUJetIDName = iConfig.getParameter<std::string>("puJetIDName");
fPUJetIDNameLowPt = iConfig.getParameter<std::string>("puJetIDNameLowPt");
// fPUJetIdAlgo = new PileupJetIdAlgo(iConfig.getParameter<edm::ParameterSet>("PUJetId"));
// fPUJetIdAlgoLowPt = new PileupJetIdAlgo(iConfig.getParameter<edm::ParameterSet>("PUJetIdLowPt"));
}
MetFlavorProducer::~MetFlavorProducer() {
delete fUtils;
Expand All @@ -52,12 +51,12 @@ void MetFlavorProducer::endJob() { }

void MetFlavorProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
//Uncorrected Jets
// Handle<PFJetCollection> lHUCJets;
// edm::Handle<PFJetCollection> lHUCJets;
// iEvent.getByLabel(fUnCorrJetName, lHUCJets);
// PFJetCollection lUCJets = *lHUCJets;

//Corrected Jets
Handle< std::vector<pat::Jet> > lHCJets;
edm::Handle< std::vector<pat::Jet> > lHCJets;
iEvent.getByLabel(fCorrJetName , lHCJets);
const std::vector<pat::Jet>& lCJets = *lHCJets;

Expand All @@ -67,27 +66,33 @@ void MetFlavorProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetu
//PFJetCollection lCJets = *lHCJets;

//Get pfCandidates
// Handle<PFCandidateCollection> lHCands;
Handle<std::vector<pat::PackedCandidate>> lHCands;
// edm::Handle<PFCandidateCollection> lHCands;
edm::Handle<std::vector<pat::PackedCandidate>> lHCands;
iEvent.getByLabel(fPFCandName , lHCands);
const std::vector<pat::PackedCandidate>& lCands = *lHCands;
const std::vector<pat::PackedCandidate>& lCands = *lHCands;

// vertices
Handle<reco::VertexCollection> lHVertices;
edm::Handle<reco::VertexCollection> lHVertices;
iEvent.getByLabel(fVertexName , lHVertices);
const VertexCollection& lVertices = *lHVertices;
const Vertex *lPV = 0; if(lVertices.size() > 0) lPV = &lVertices[0];
const reco::VertexCollection& lVertices = *lHVertices;
const reco::Vertex *lPV = 0;
if(lVertices.size() > 0)
lPV = &lVertices[0];

//Get Rho
Handle<double> lHRho;
iEvent.getByLabel(fRhoName , lHRho);
edm::Handle<double> lHRho;
iEvent.getByLabel(fRhoName, lHRho);
double lRho = *lHRho;

//Make Generic Objects
std::vector<LorentzVector > lVisible;
std::vector<std::pair<LorentzVector,double> > lPFInfo; makeCandidates(lPFInfo, lCands,lPV);
std::vector<MetUtilities::JetInfo> lJetInfo; makeJets (lJetInfo, lCJets,lVertices,lRho);
std::vector<Vector> lVtxInfo; makeVertices (lVtxInfo,lVertices);
std::vector<std::pair<LorentzVector,double> > lPFInfo;
makeCandidates(lPFInfo, lCands,lPV);

std::vector<MetUtilities::JetInfo> lJetInfo;
makeJets(lJetInfo, lCJets, lVertices, lRho);

std::vector<Vector> lVtxInfo;
makeVertices(lVtxInfo, lVertices);

//Calculate the Met
std::pair<LorentzVector,double> lMetInfo; //MET, SumEt
Expand All @@ -98,21 +103,21 @@ void MetFlavorProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetu
if(fMetFlavor == 4) lMetInfo = fUtils->PUCMet (lPFInfo,lJetInfo,fDZMin);

//Add a PF Met object and put it in the event
PFMET lDummy;
PFMET lMet(lDummy.getSpecific(),lMetInfo.second,lMetInfo.first,lPV->position()); //Use PFMET sum Et
reco::PFMET lDummy;
reco::PFMET lMet(lDummy.getSpecific(), lMetInfo.second, lMetInfo.first, lPV->position()); //Use PFMET sum Et

std::auto_ptr<reco::PFMETCollection> lPFMetColl;
lPFMetColl.reset ( new reco::PFMETCollection);
lPFMetColl->push_back( lMet);
iEvent.put( lPFMetColl );
lPFMetColl.reset(new reco::PFMETCollection);
lPFMetColl->push_back(lMet);
iEvent.put(lPFMetColl);
}

void MetFlavorProducer::makeJets(std::vector<MetUtilities::JetInfo> &iJetInfo,
const std::vector<pat::Jet>& iCJets,
const VertexCollection &iVertices,double iRho) {
const reco::VertexCollection &iVertices,double iRho) {

for(int i1 = 0; i1 < (int) iCJets .size(); i1++) { // corrected jets collection
const pat::Jet *pCJet = &(iCJets.at(i1));
const pat::Jet* pCJet = &(iCJets.at(i1));

//std::cout<<" MetFlavorProducer::makeJets input : "<<i1<<" "<<pCJet->pt()<<" "<<pCJet->eta()<<" "<<pCJet->correctedJet(0).pt()<<" "<<pCJet->neutralEmEnergy()<<" "<<pCJet->neutralHadronEnergy()<<std::endl;

Expand All @@ -122,8 +127,7 @@ void MetFlavorProducer::makeJets(std::vector<MetUtilities::JetInfo> &iJetInfo,

//std::cout<<" MetFlavorProducer::makeJets PFLooseId : "<<i1<<" "<<pCJet->pt()<<" "<<pCJet->eta()<<" "<<pCJet->correctedJet(0).pt()<<" "<<pCJet->neutralEmEnergy()<<" "<<pCJet->neutralHadronEnergy()<<std::endl;

double lJec = 0;
double lMVA = jetMVA(pCJet,lJec,iVertices[0],iVertices,false);
double lMVA = jetMVA(pCJet);
double lJetEnergy = pCJet->correctedJet(0).pt()/pCJet->pt()*pCJet->energy();
// COLIN 53
double lNeuFrac = 1.;
Expand All @@ -140,7 +144,7 @@ void MetFlavorProducer::makeJets(std::vector<MetUtilities::JetInfo> &iJetInfo,
}
}

void MetFlavorProducer::makeCandidates(std::vector<std::pair<LorentzVector,double> > &iPFInfo,const std::vector<pat::PackedCandidate> &iCands,const Vertex *iPV) {
void MetFlavorProducer::makeCandidates(std::vector<std::pair<LorentzVector,double> > &iPFInfo,const std::vector<pat::PackedCandidate> &iCands,const reco::Vertex *iPV) {
for(int i0 = 0; i0 < (int)iCands.size(); i0++) {
const pat::PackedCandidate* pflowCand = &(iCands.at(i0));
double pDZ = -999;
Expand All @@ -150,9 +154,9 @@ void MetFlavorProducer::makeCandidates(std::vector<std::pair<LorentzVector,doubl
iPFInfo.push_back(pPFObject);
}
}
void MetFlavorProducer::makeVertices(std::vector<Vector> &iPVInfo,const VertexCollection &iVertices) {
void MetFlavorProducer::makeVertices(std::vector<Vector> &iPVInfo,const reco::VertexCollection &iVertices) {
for(int i0 = 0; i0 < (int)iVertices.size(); i0++) {
const Vertex *pVertex = &(iVertices.at(i0));
const reco::Vertex *pVertex = &(iVertices.at(i0));

if(fabs(pVertex->z()) > 24.) continue;
if(pVertex->ndof() < 4.) continue;
Expand All @@ -178,53 +182,20 @@ bool MetFlavorProducer::passPFLooseId(const pat::Jet *iJet) {
if(iJet->chargedMultiplicity() < 1 && fabs(iJet->eta()) < 2.4 ) return false;
return true;
}
double MetFlavorProducer::pfCandDz(const pat::PackedCandidate* iPFCand, const Vertex *iPV) {
double MetFlavorProducer::pfCandDz(const pat::PackedCandidate* iPFCand, const reco::Vertex *iPV) {
double lDz = -999;
// if(iPFCand->trackRef().isNonnull()) lDz = fabs(iPFCand-> trackRef()->dz(iPV->position()));
// FIXME - JAN - understand what the pseudoTrack gives
lDz = fabs(iPFCand->pseudoTrack().dz(iPV->position()));
// else if(iPFCand->gsfTrackRef().isNonnull()) lDz = fabs(iPFCand->gsfTrackRef()->dz(iPV->position()));
// FIXME - JAN - does pseudoTrack give something different from
// PackedCandidate::dz(..) ?
lDz = fabs(iPFCand->dz(iPV->position()));
return lDz;
}
double MetFlavorProducer::jetMVA (const pat::Jet *iCorrJet,double iJec, const Vertex& iPV, const reco::VertexCollection &iAllvtx, bool iPrintDebug) {

return iCorrJet->userFloat("pileupJetId:fullDiscriminant");
// std::cout << "jet " << iCorrJet << std::endl;
// std::cout << "iJec " << iJec << std::endl;
// std::cout << "vertex x " << iPV.x() << std::endl;
// std::cout << "vertex coll size " << iAllvtx.size() << std::endl;


// std::cout << "Is a PF jet? " << (dynamic_cast<const pat::Jet*>(iCorrJet))->isPFJet() << std::endl;

// PileupJetIdentifier lPUJetId = fPUJetIdAlgo->computeIdVariables(iCorrJet,iJec,&iPV,iAllvtx,true);
// // PileupJetIdentifier *lPUJetIdRef = &lPUJetId;
// if(iCorrJet->pt() < 10) {
// PileupJetIdentifier pPUJetId = fPUJetIdAlgoLowPt->computeIdVariables(iCorrJet,iJec,&iPV,iAllvtx,true);
// // lPUJetIdRef = &pPUJetId;
// }
// if(iPrintDebug) { std::cout << "Debug Jet MVA: "
// << lPUJetId.nvtx() << " "
// << iCorrJet->pt() << " "
// << lPUJetId.jetEta() << " "
// << lPUJetId.jetPhi() << " "
// << lPUJetId.d0() << " "
// << lPUJetId.dZ() << " "
// << lPUJetId.beta() << " "
// << lPUJetId.betaStar() << " "
// << lPUJetId.nCharged() << " "
// << lPUJetId.nNeutrals() << " "
// << lPUJetId.dRMean() << " "
// << lPUJetId.frac01() << " "
// << lPUJetId.frac02() << " "
// << lPUJetId.frac03() << " "
// << lPUJetId.frac04() << " "
// << lPUJetId.frac05()
// << " === : === "
// << lPUJetId.mva() << " " << endl;
// }

// return lPUJetId.mva();
double MetFlavorProducer::jetMVA (const pat::Jet *iCorrJet) {
// JAN - this returns the pre-computed PU jet ID present in miniAOD
// if you need another primary vertex, simply redo the PU jet ID production
if (iCorrJet->pt() > 10.)
return iCorrJet->userFloat(fPUJetIDName);

return iCorrJet->userFloat(fPUJetIDNameLowPt);
}

#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down
18 changes: 8 additions & 10 deletions CMGTools/Common/plugins/MetFlavorProducer.h
Expand Up @@ -13,12 +13,9 @@
#include "DataFormats/JetReco/interface/Jet.h"
#include "DataFormats/JetReco/interface/PFJet.h"
#include "DataFormats/PatCandidates/interface/PackedCandidate.h"
#include "RecoJets/JetProducers/interface/PileupJetIdAlgo.h"

#include "CMGTools/Common/interface/MetUtilities.h"

//COLIN don't do that!!
using namespace reco;

namespace pat {
class Jet;
Expand Down Expand Up @@ -49,23 +46,24 @@ class MetFlavorProducer : public edm::EDProducer {
edm::InputTag fVertexName;
edm::InputTag fRhoName;

std::string fPUJetIDName;
std::string fPUJetIDNameLowPt;

double fJetPtMin;
double fDZMin;
PileupJetIdAlgo *fPUJetIdAlgo;
PileupJetIdAlgo *fPUJetIdAlgoLowPt;
MetUtilities *fUtils;
int fMetFlavor;

void makeCandidates(std::vector<std::pair<LorentzVector,double> > &iPFInfo,
const std::vector<pat::PackedCandidate> &iCands,const Vertex *iPV);
const std::vector<pat::PackedCandidate> &iCands,const reco::Vertex *iPV);
void makeVertices (std::vector<Vector>& iPVInfo,
const VertexCollection &iVertices);
const reco:: VertexCollection &iVertices);

void makeJets (std::vector<MetUtilities::JetInfo> &iJetInfo,
const std::vector<pat::Jet>& CJets,
const VertexCollection& iVertices,double iRho);
const reco::VertexCollection& iVertices,double iRho);

bool passPFLooseId(const pat::Jet *iJet);
double pfCandDz(const pat::PackedCandidate* iPFCand, const Vertex *iPV) ;
double jetMVA (const pat::Jet *iuncorrJet,double iJec, const Vertex& iPV, const reco::VertexCollection &iAllvtx,bool iPrintDebug=false);
double pfCandDz(const pat::PackedCandidate* iPFCand, const reco::Vertex *iPV) ;
double jetMVA (const pat::Jet *iuncorrJet);
};
23 changes: 6 additions & 17 deletions CMGTools/Common/python/miscProducers/mvaMET/metRegression_cff.py
@@ -1,29 +1,18 @@
import FWCore.ParameterSet.Config as cms

from CMGTools.External.puJetIDAlgo_cff import *
from CMGTools.Common.Tools.cmsswRelease import cmsswIs44X, isNewerThan


if isNewerThan('CMSSW_5_3_0'):
jetPtMin = 0.
puJetIdAlgo = met_53x.clone()
wpId = 3
else:
jetPtMin = 1.
puJetIdAlgo = PhilV1.clone()
wpId = 2 # see MetUtilies.cc
pfMetForRegression = cms.EDProducer(
"MetFlavorProducer",
CorrJetName = cms.InputTag("slimmedJets"),
CorrJetName = cms.InputTag("patJetsAK4PF"),
PFCandidateName = cms.InputTag("packedPFCandidates"),
VertexName = cms.InputTag("offlineSlimmedPrimaryVertices"),
RhoName = cms.InputTag('fixedGridRhoFastjetAll'),
JetPtMin = cms.double(jetPtMin), # should be 0 for 5X and 1 for 4X
JetPtMin = cms.double(0.), # should be 0 for 5X and 1 for 4X
dZMin = cms.double(0.1),
MetFlavor = cms.int32(0), # 0 PF 1 TK 2 No PU 3 PU 4 PUC
WorkingPointId = cms.uint32(wpId),
PUJetId = puJetIdAlgo,
PUJetIdLowPt = puJetIdAlgo,
WorkingPointId = cms.uint32(3), # 3 for 5X and higher
puJetIDName = cms.string('pileupJetIdMET:met53xDiscriminant'),
puJetIDNameLowPt = cms.string('pileupJetIdMET:met53xDiscriminant')
)

tkMet = pfMetForRegression.clone(MetFlavor = cms.int32(1))
Expand All @@ -33,7 +22,7 @@
pcMet = pfMetForRegression.clone(MetFlavor = cms.int32(4))


MetRegressionSequence = cms.Sequence (
metRegressionSequence = cms.Sequence (
pfMetForRegression +
nopuMet +
puMet +
Expand Down
22 changes: 11 additions & 11 deletions CMGTools/External/python/puJetIDAlgo_cff.py
Expand Up @@ -5,7 +5,7 @@
full_53x = cms.PSet(
impactParTkThreshold = cms.double(1.) ,
cutBased = cms.bool(False),
tmvaWeights = cms.string("CMGTools/External/data/TMVAClassificationCategory_JetID_53X_Dec2012.weights.xml"),
tmvaWeights = cms.string("RecoJets/JetProducers/data/TMVAClassificationCategory_JetID_53X_Dec2012.weights.xml.gz"),
tmvaMethod = cms.string("JetIDMVAHighPt"),
version = cms.int32(-1),
tmvaVariables = cms.vstring(
Expand Down Expand Up @@ -36,7 +36,7 @@
full_53x_chs = cms.PSet(
impactParTkThreshold = cms.double(1.) ,
cutBased = cms.bool(False),
tmvaWeights = cms.string("RecoJets/JetProducers/data/TMVAClassificationCategory_JetID_53X_chs_Dec2012.weights.xml"),
tmvaWeights = cms.string("RecoJets/JetProducers/data/TMVAClassificationCategory_JetID_53X_chs_Dec2012.weights.xml.gz"),
tmvaMethod = cms.string("JetIDMVAHighPt"),
version = cms.int32(-1),
tmvaVariables = cms.vstring(
Expand Down Expand Up @@ -66,7 +66,7 @@
met_53x = cms.PSet(
impactParTkThreshold = cms.double(1.) ,
cutBased = cms.bool(False),
tmvaWeights = cms.string("CMGTools/External/data/TMVAClassificationCategory_JetID_MET_53X_Dec2012.weights.xml"),
tmvaWeights = cms.string("RecoJets/JetProducers/data/TMVAClassificationCategory_JetID_MET_53X_Dec2012.weights.xml.gz"),
tmvaMethod = cms.string("JetIDMVAMET"),
version = cms.int32(-1),
tmvaVariables = cms.vstring(
Expand Down Expand Up @@ -95,7 +95,7 @@
full_5x = cms.PSet(
impactParTkThreshold = cms.double(1.) ,
cutBased = cms.bool(False),
tmvaWeights = cms.string("CMGTools/External/data/TMVAClassification_5x_BDT_fullPlusRMS.weights.xml"),
tmvaWeights = cms.string("RecoJets/JetProducers/data/TMVAClassification_5x_BDT_fullPlusRMS.weights.xml.gz"),
tmvaMethod = cms.string("BDT_fullPlusRMS"),
version = cms.int32(-1),
tmvaVariables = cms.vstring(
Expand Down Expand Up @@ -124,7 +124,7 @@
simple_5x = cms.PSet(
impactParTkThreshold = cms.double(1.) ,
cutBased = cms.bool(False),
tmvaWeights = cms.string("CMGTools/External/data/TMVAClassification_5x_BDT_simpleNoVtxCat.weights.xml"),
tmvaWeights = cms.string("RecoJets/JetProducers/data/TMVAClassification_5x_BDT_simpleNoVtxCat.weights.xml.gz"),
tmvaMethod = cms.string("BDT_simpleNoVtxCat"),
version = cms.int32(-1),
tmvaVariables = cms.vstring(
Expand All @@ -149,7 +149,7 @@
full_5x_chs = cms.PSet(
impactParTkThreshold = cms.double(1.) ,
cutBased = cms.bool(False),
tmvaWeights = cms.string("CMGTools/External/data/TMVAClassification_5x_BDT_chsFullPlusRMS.weights.xml"),
tmvaWeights = cms.string("RecoJets/JetProducers/data/TMVAClassification_5x_BDT_chsFullPlusRMS.weights.xml.gz"),
tmvaMethod = cms.string("BDT_chsFullPlusRMS"),
version = cms.int32(-1),
tmvaVariables = cms.vstring(
Expand Down Expand Up @@ -178,7 +178,7 @@
simple_5x_chs = cms.PSet(
impactParTkThreshold = cms.double(1.) ,
cutBased = cms.bool(False),
tmvaWeights = cms.string("CMGTools/External/data/TMVAClassification_5x_BDT_chsSimpleNoVtxCat.weights.xml"),
tmvaWeights = cms.string("RecoJets/JetProducers/data/TMVAClassification_5x_BDT_chsSimpleNoVtxCat.weights.xml.gz"),
tmvaMethod = cms.string("BDT_chsSimpleNoVtxCat"),
version = cms.int32(-1),
tmvaVariables = cms.vstring(
Expand All @@ -203,7 +203,7 @@
full = cms.PSet(
impactParTkThreshold = cms.double(1.) ,
cutBased = cms.bool(False),
tmvaWeights = cms.string("CMGTools/External/data/TMVAClassification_PuJetIdOptMVA.weights.xml"),
tmvaWeights = cms.string("RecoJets/JetProducers/data/TMVAClassification_PuJetIdOptMVA.weights.xml.gz"),
tmvaMethod = cms.string("PuJetIdOptMVA"),
version = cms.int32(-1),
tmvaVariables = cms.vstring(
Expand Down Expand Up @@ -231,7 +231,7 @@
simple = cms.PSet(
impactParTkThreshold = cms.double(1.) ,
cutBased = cms.bool(False),
tmvaWeights = cms.string("CMGTools/External/data/TMVAClassification_PuJetIdMinMVA.weights.xml"),
tmvaWeights = cms.string("RecoJets/JetProducers/data/TMVAClassification_PuJetIdMinMVA.weights.xml.gz"),
tmvaMethod = cms.string("PuJetIdMinMVA"),
version = cms.int32(-1),
tmvaVariables = cms.vstring(
Expand Down Expand Up @@ -263,7 +263,7 @@
PhilV0 = cms.PSet(
impactParTkThreshold = cms.double(1.) ,
cutBased = cms.bool(False),
tmvaWeights = cms.string("CMGTools/External/data/mva_JetID.weights.xml"),
tmvaWeights = cms.string("RecoJets/JetProducers/data/mva_JetID.weights.xml.gz"),
tmvaMethod = cms.string("JetID"),
version = cms.int32(0),
JetIdParams = EmptyJetIdParams
Expand All @@ -274,7 +274,7 @@
PhilV1 = cms.PSet(
impactParTkThreshold = cms.double(1.) ,
cutBased = cms.bool(False),
tmvaWeights = cms.string("CMGTools/External/data/mva_JetID_v1.weights.xml"),
tmvaWeights = cms.string("RecoJets/JetProducers/data/mva_JetID_v1.weights.xml.gz"),
tmvaMethod = cms.string("JetID"),
version = cms.int32(-1),
tmvaVariables = cms.vstring(
Expand Down

0 comments on commit 17549cd

Please sign in to comment.