Skip to content

Commit

Permalink
Merge pull request #224 from blinkseb/electrons_mva_id
Browse files Browse the repository at this point in the history
Store electron MVA id
  • Loading branch information
OlivierBondu authored Dec 14, 2016
2 parents 52387ce + 1411c4a commit 9293c14
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 4 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,23 @@ git clone -b CMSSW_8_0_6p -o upstream git@github.com:cp3-llbb/Framework.git cp3_

# Stuff not yet in central CMSSW:
# 8010+ electron ID WPs
git cms-merge-topic ikrav:egm_id_80X_v1
git cms-merge-topic ikrav:egm_id_80X_v2
# KalmanMuonCalibrator
git clone -o upstream https://github.com/bachtis/analysis.git -b KaMuCa_V4 KaMuCa
pushd KaMuCa
git checkout 2ad38daae37a41a9c07f482e95f2455e3eb915b0
popd


scram b -j 4

# Add the area containing the MVA weights (from cms-data, to appear in “external”).
# Note: the “external” area appears after “scram build” is run at least once, as above
cd ${CMSSW_BASE}/external/${SCRAM_ARCH}
git clone https://github.com/ikrav/RecoEgamma-ElectronIdentification.git data/RecoEgamma/ElectronIdentification/data
cd data/RecoEgamma/ElectronIdentification/data
git checkout egm_id_80X_v1
cd ${CMSSW_BASE}/src

cd ${CMSSW_BASE}/src/cp3_llbb/Framework
source first_setup.sh
cd ${CMSSW_BASE}/src
Expand Down
2 changes: 1 addition & 1 deletion bootstrap_jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# CMSSW env is already configured
# Current working dir is $CMSSW_BASE/src

git cms-merge-topic ikrav:egm_id_80X_v1
git cms-merge-topic ikrav:egm_id_80X_v2
git clone -o upstream https://github.com/bachtis/analysis.git -b KaMuCa_V4 KaMuCa
pushd KaMuCa
git checkout 2ad38daae37a41a9c07f482e95f2455e3eb915b0
Expand Down
13 changes: 13 additions & 0 deletions interface/ElectronsProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class ElectronsProducer: public LeptonsProducer<pat::Electron>, public Identifia
LeptonsProducer::doConsumes(config, std::forward<edm::ConsumesCollector>(collector));
Identifiable::consumes_id_tokens(config, std::forward<edm::ConsumesCollector>(collector));
m_vertices_token = collector.consumes<std::vector<reco::Vertex>>(config.getUntrackedParameter<edm::InputTag>("vertices", edm::InputTag("offlineSlimmedPrimaryVertices")));

if (config.exists("mva_id")) {
const edm::ParameterSet& mva_id_pset = config.getUntrackedParameter<edm::ParameterSet>("mva_id");
m_mva_id_values_map_token = collector.consumes<edm::ValueMap<float>>(mva_id_pset.getUntrackedParameter<edm::InputTag>("values"));
m_mva_id_categories_map_token = collector.consumes<edm::ValueMap<int>>(mva_id_pset.getUntrackedParameter<edm::InputTag>("categories"));
}
}

virtual void produce(edm::Event& event, const edm::EventSetup& eventSetup) override;
Expand All @@ -29,6 +35,10 @@ class ElectronsProducer: public LeptonsProducer<pat::Electron>, public Identifia
// Tokens
edm::EDGetTokenT<std::vector<reco::Vertex>> m_vertices_token;

// MVA values and categories (optional)
edm::EDGetTokenT<edm::ValueMap<float>> m_mva_id_values_map_token;
edm::EDGetTokenT<edm::ValueMap<int>> m_mva_id_categories_map_token;

public:
// Tree members
BRANCH(isEB, std::vector<bool>);
Expand All @@ -42,6 +52,9 @@ class ElectronsProducer: public LeptonsProducer<pat::Electron>, public Identifia
BRANCH(hcalPFClusterIso, std::vector<float>);
BRANCH(trackIso, std::vector<float>);

BRANCH(mva_id_values, std::vector<float>);
BRANCH(mva_id_categories, std::vector<int>);

std::vector<edm::Ref<std::vector<pat::Electron>>> products;
};

Expand Down
9 changes: 9 additions & 0 deletions jenkins_postbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /bin/sh

# This script is executed after `scram b`

cd ${CMSSW_BASE}/external/${SCRAM_ARCH}
git clone https://github.com/ikrav/RecoEgamma-ElectronIdentification.git data/RecoEgamma/ElectronIdentification/data
cd data/RecoEgamma/ElectronIdentification/data
git checkout egm_id_80X_v1
cd ${CMSSW_BASE}/src
8 changes: 7 additions & 1 deletion python/ElectronsProducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
'egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-loose',
'egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-medium',
'egmGsfElectronIDs:cutBasedElectronID-Summer16-80X-V1-tight',
'egmGsfElectronIDs:cutBasedElectronHLTPreselection-Summer16-V1'
'egmGsfElectronIDs:cutBasedElectronHLTPreselection-Summer16-V1',
'egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp90',
'egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp80'
),
mva_id = cms.untracked.PSet(
values = cms.untracked.InputTag('electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16GeneralPurposeV1Values'),
categories = cms.untracked.InputTag('electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16GeneralPurposeV1Categories')
),
scale_factors = cms.untracked.PSet(
id_veto = cms.untracked.FileInPath('cp3_llbb/Framework/data/ScaleFactors/Electron_EGamma_SF2D_veto.json'),
id_loose = cms.untracked.FileInPath('cp3_llbb/Framework/data/ScaleFactors/Electron_EGamma_SF2D_loose.json'),
Expand Down
1 change: 1 addition & 0 deletions python/Framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ def configureElectronId_(self):
id_modules = [
'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Summer16_80X_V1_cff',
'RecoEgamma.ElectronIdentification.Identification.cutBasedElectronHLTPreselecition_Summer16_V1_cff',
'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff'
]

for mod in id_modules:
Expand Down
14 changes: 14 additions & 0 deletions src/ElectronsProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ void ElectronsProducer::produce(edm::Event& event, const edm::EventSetup& eventS
edm::Handle<std::vector<reco::Vertex>> vertices_handle;
event.getByToken(m_vertices_token, vertices_handle);

edm::Handle<edm::ValueMap<float>> mva_id_values_handle;
edm::Handle<edm::ValueMap<int>> mva_id_categories_handle;

if (! m_mva_id_values_map_token.isUninitialized()) {
event.getByToken(m_mva_id_values_map_token, mva_id_values_handle);
event.getByToken(m_mva_id_categories_map_token, mva_id_categories_handle);
}

const reco::Vertex& primary_vertex = (*vertices_handle)[0];

double rho = *rho_handle;
Expand Down Expand Up @@ -49,6 +57,12 @@ void ElectronsProducer::produce(edm::Event& event, const edm::EventSetup& eventS
hcalPFClusterIso.push_back(electron.hcalPFClusterIso());
trackIso.push_back(electron.trackIso());

// MVA id
if (! m_mva_id_values_map_token.isUninitialized()) {
mva_id_values.push_back((*mva_id_values_handle)[electronRef]);
mva_id_categories.push_back((*mva_id_categories_handle)[electronRef]);
}

Parameters p {{BinningVariable::Eta, electron.eta()}, {BinningVariable::Pt, electron.pt()}};
ScaleFactors::store_scale_factors(p, event.isRealData());
}
Expand Down
Binary file modified test/unit_tests_data_ref.root
Binary file not shown.
Binary file modified test/unit_tests_mc_ref.root
Binary file not shown.
Binary file modified test/unit_tests_mc_with_db_ref.root
Binary file not shown.

0 comments on commit 9293c14

Please sign in to comment.