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

Pileup jet ID for JPT #1872

Merged
merged 3 commits into from Dec 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions RecoJets/JetProducers/BuildFile.xml
Expand Up @@ -8,6 +8,7 @@
<use name="SimDataFormats/CaloHit"/>
<use name="RecoJets/JetAlgorithms"/>
<use name="DataFormats/CastorReco"/>
<use name="CommonTools/Utils"/>
<use name="fastjet"/>
<use name="roottmva"/>
<use name="vdt"/>
Expand Down
6 changes: 6 additions & 0 deletions RecoJets/JetProducers/data/download.url
@@ -0,0 +1,6 @@
http://cmsdoc.cern.ch/cms/data/CMSSW/RecoJets/JetProducers/data/TMVAClassificationCategory_JetID_53X_Dec2012.weights.xml.gz
http://cmsdoc.cern.ch/cms/data/CMSSW/RecoJets/JetProducers/data/TMVAClassificationCategory_JetID_MET_53X_Dec2012.weights.xml.gz
http://cmsdoc.cern.ch/cms/data/CMSSW/RecoJets/JetProducers/data/TMVAClassification_5x_BDT_chsFullPlusRMS.weights.xml.gz
http://cmsdoc.cern.ch/cms/data/CMSSW/RecoJets/JetProducers/data/TMVAClassification_PUJetID_JPT_BDTG.weights.xml.gz
http://cmsdoc.cern.ch/cms/data/CMSSW/RecoJets/JetProducers/data/TMVAClassification_PUJetID_JPT_BDTG.weights_F.xml.gz

53 changes: 53 additions & 0 deletions RecoJets/JetProducers/interface/PileupJPTJetIdAlgo.h
@@ -0,0 +1,53 @@
#ifndef JetProducers_PileupJPTJetIdAlgo_h
#define JetProducers_PileupJPTJetIdAlgo_h

#include "DataFormats/JetReco/interface/JPTJet.h"

// user include files
#include <string>
#include <memory>
#include <map>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<vector>

using namespace std;
using namespace reco;

namespace edm {
class Event;
class EventSetup;
class ParameterSets;
}
// For MVA analysis

#include "TMVA/Tools.h"
#include "TMVA/Reader.h"

namespace cms
{

class PileupJPTJetIdAlgo
{
public:

PileupJPTJetIdAlgo(const edm::ParameterSet& fParameters);

virtual ~PileupJPTJetIdAlgo();

void bookMVAReader();

float fillJPTBlock(const reco::JPTJet* jet
);
private:
int verbosity;
// Variables for multivariate analysis

float Nvtx,PtJ,EtaJ,Beta,MultCalo,dAxis1c,dAxis2c,MultTr,dAxis1t,dAxis2t;
TMVA::Reader * reader_;
TMVA::Reader * readerF_;
std::string tmvaWeights_, tmvaWeightsF_, tmvaMethod_;
};
}
#endif
150 changes: 150 additions & 0 deletions RecoJets/JetProducers/plugins/PileupJPTJetIdProducer.cc
@@ -0,0 +1,150 @@
// system include files
#include <memory>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "DataFormats/JetReco/interface/Jet.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EventSetup.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "RecoJets/JetProducers/interface/PileupJPTJetIdAlgo.h"
#include "DataFormats/JetReco/interface/JPTJetCollection.h"
#include "DataFormats/JetReco/interface/JPTJet.h"


// ------------------------------------------------------------------------------------------
class PileupJPTJetIdProducer : public edm::EDProducer {
public:
explicit PileupJPTJetIdProducer(const edm::ParameterSet&);
~PileupJPTJetIdProducer();

private:
virtual void produce(edm::Event&, const edm::EventSetup&);

virtual void beginRun(edm::Run&, edm::EventSetup const&);
virtual void endRun(edm::Run&, edm::EventSetup const&);
virtual void beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
virtual void endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);

edm::InputTag jets_;
edm::EDGetTokenT<edm::View<reco::JPTJet> > input_token_;
bool allowMissingInputs_;
int verbosity;
cms::PileupJPTJetIdAlgo* pualgo;

};

// ------------------------------------------------------------------------------------------
PileupJPTJetIdProducer::PileupJPTJetIdProducer(const edm::ParameterSet& iConfig)
{
jets_ = iConfig.getParameter<edm::InputTag>("jets");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is new, please use the consumes right away!

input_token_ = consumes<edm::View<reco::JPTJet> >(jets_);
verbosity = iConfig.getParameter<int>("Verbosity");
allowMissingInputs_=iConfig.getUntrackedParameter<bool>("AllowMissingInputs",false);
pualgo = new cms::PileupJPTJetIdAlgo(iConfig);
pualgo->bookMVAReader();
produces<edm::ValueMap<float> > ("JPTPUDiscriminant");
produces<edm::ValueMap<int> > ("JPTPUId");
}



// ------------------------------------------------------------------------------------------
PileupJPTJetIdProducer::~PileupJPTJetIdProducer()
{
}


// ------------------------------------------------------------------------------------------
void
PileupJPTJetIdProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
{
using namespace edm;
using namespace std;
using namespace reco;
edm::Handle<View<JPTJet> > jets;
iEvent.getByToken(input_token_, jets);
vector<float> mva;
vector<int> idflag;
for ( unsigned int i=0; i<jets->size(); ++i ) {
int b = -1;
const JPTJet & jet = jets->at(i);

float mvapu = pualgo->fillJPTBlock(&jet);

mva.push_back(mvapu);

// Get PUid type
///|eta|<2.6
//WP 95% JPT PUID > 0.3
//WP 90% JPT PUID > 0.7
//WP 80% JPT PUID > 0.9

//|eta|>=2.6
//WP 90% JPT PUID > -0.55
//WP 80% JPT PUID > -0.3
//WP 70% JPT PUID > -0.1

if(fabs(jet.eta()) < 2.6 ) {
if( mvapu > 0.3 ) b = 0;
if( mvapu > 0.7 ) b = 1;
if( mvapu > 0.9 ) b = 2;
} else {
if( mvapu > -0.55 ) b = 0;
if( mvapu > -0.3 ) b = 1;
if( mvapu > -0.1 ) b = 2;
}

idflag.push_back(b);

if(verbosity > 0) std::cout<<" PUID producer::Corrected JPT Jet is "<<jet.pt()<<" "<<jet.eta()<<" "<<jet.phi()<<" "<<jet.getSpecific().Zch<<std::endl;

}

auto_ptr<ValueMap<float> > mvaout(new ValueMap<float>());
ValueMap<float>::Filler mvafiller(*mvaout);
mvafiller.insert(jets,mva.begin(),mva.end());
mvafiller.fill();
iEvent.put(mvaout,"JPTPUDiscriminant");

auto_ptr<ValueMap<int> > idflagout(new ValueMap<int>());
ValueMap<int>::Filler idflagfiller(*idflagout);
idflagfiller.insert(jets,idflag.begin(),idflag.end());
idflagfiller.fill();
iEvent.put(idflagout,"JPTPUId");

}

// ------------------------------------------------------------------------------------------
void
PileupJPTJetIdProducer::beginRun(edm::Run&, edm::EventSetup const&)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove begin/end Run/Job from .h and .cc , since they are empty

{
}

// ------------------------------------------------------------------------------------------
void
PileupJPTJetIdProducer::endRun(edm::Run&, edm::EventSetup const&)
{
}

// ------------------------------------------------------------------------------------------
void
PileupJPTJetIdProducer::beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&)
{
}

// ------------------------------------------------------------------------------------------
void
PileupJPTJetIdProducer::endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&)
{
}

//define this as a plug-in
DEFINE_FWK_MODULE(PileupJPTJetIdProducer);
10 changes: 10 additions & 0 deletions RecoJets/JetProducers/python/PileupJPTJetID_cfi.py
@@ -0,0 +1,10 @@
import FWCore.ParameterSet.Config as cms

pileupJPTJetIdProducer = cms.EDProducer("PileupJPTJetIdProducer",
jets = cms.InputTag("ak5JPTJetsL1L2L3"),
Verbosity = cms.int32(0),
tmvaWeightsCentral = cms.string('RecoJets/JetProducers/data/TMVAClassification_PUJetID_JPT_BDTG.weights.xml.gz'),
tmvaWeightsForward = cms.string('RecoJets/JetProducers/data/TMVAClassification_PUJetID_JPT_BDTG.weights_F.xml.gz'),
tmvaMethod = cms.string('BDTG method')
)

89 changes: 1 addition & 88 deletions RecoJets/JetProducers/python/PileupJetIDParams_cfi.py
@@ -1,40 +1,11 @@
import FWCore.ParameterSet.Config as cms
from RecoJets.JetProducers.PileupJetIDCutParams_cfi import *

####################################################################################################################
full_5x = cms.PSet(
impactParTkThreshold = cms.double(1.) ,
cutBased = cms.bool(False),
tmvaWeights = cms.string("RecoJets/JetProducers/data/TMVAClassification_5x_BDT_fullPlusRMS.weights.xml"),
tmvaMethod = cms.string("BDT_fullPlusRMS"),
version = cms.int32(-1),
tmvaVariables = cms.vstring(
"frac01",
"frac02",
"frac03",
"frac04",
"frac05",
"dR2Mean",
"nvtx",
"nNeutrals",
"beta",
"betaStar",
"dZ",
"nCharged",
),
tmvaSpectators = cms.vstring(
"jetPt",
"jetEta",
),
JetIdParams = full_5x_wp,
label = cms.string("full")
)

####################################################################################################################
full_5x_chs = cms.PSet(
impactParTkThreshold = cms.double(1.) ,
cutBased = cms.bool(False),
tmvaWeights = cms.string("RecoJets/JetProducers/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 All @@ -59,68 +30,10 @@
label = cms.string("full")
)
####################################################################################################################
full = cms.PSet(
impactParTkThreshold = cms.double(1.) ,
cutBased = cms.bool(False),
tmvaWeights = cms.string("RecoJets/JetProducers/data/TMVAClassification_PuJetIdOptMVA.weights.xml"),
tmvaMethod = cms.string("PuJetIdOptMVA"),
version = cms.int32(-1),
tmvaVariables = cms.vstring(
"frac01",
"frac02",
"frac03",
"frac04",
"frac05",
"nvtx",
"nNeutrals",
"beta",
"betaStar",
"dZ",
"nCharged",
),
tmvaSpectators = cms.vstring(
"jetPt",
"jetEta",
),
JetIdParams = PuJetIdOptMVA_wp,
label = cms.string("full")
)

####################################################################################################################
cutbased = cms.PSet(
impactParTkThreshold = cms.double(1.),
cutBased = cms.bool(True),
JetIdParams = PuJetIdCutBased_wp,
label = cms.string("cutbased")
)

####################################################################################################################
PhilV1 = cms.PSet(
impactParTkThreshold = cms.double(1.) ,
cutBased = cms.bool(False),
tmvaWeights = cms.string("RecoJets/JetProducers/data/mva_JetID_v1.weights.xml"),
tmvaMethod = cms.string("JetID"),
version = cms.int32(-1),
tmvaVariables = cms.vstring(
"nvtx",
"jetPt",
"jetEta",
"jetPhi",
"dZ",
"d0",
"beta",
"betaStar",
"nCharged",
"nNeutrals",
"dRMean",
"frac01",
"frac02",
"frac03",
"frac04",
"frac05",
),
tmvaSpectators = cms.vstring(),
JetIdParams = JetIdParams,
label = cms.string("philv1")
)