Skip to content

Commit

Permalink
Switch by default to new flavour tool based on Hadrons. Update of exa…
Browse files Browse the repository at this point in the history
…mple scripts.
  • Loading branch information
Adrien committed Mar 3, 2015
1 parent 10a4aa9 commit 4e5ee01
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 155 deletions.
2 changes: 2 additions & 0 deletions DQMOffline/RecoB/python/bTagCommon_cff.py
Expand Up @@ -29,6 +29,8 @@
softLeptonInfo = cms.InputTag("softPFElectronsTagInfos"),
# Section for the jet flavour identification
jetMCSrc = cms.InputTag("mcJetFlavour"),
caloJetMCSrc = cms.InputTag(""), #To define only if you use the old flavour tool
useOldFlavourTool = cms.bool(False), #Recommended only for CaloJets, if True then define caloJetMCSrc and ignore jetMCSrc
# eta and pt ranges
ptRanges = cms.vdouble(50.0, 80.0, 120.0),
etaRanges = cms.vdouble(0.0, 1.4, 2.4),
Expand Down
25 changes: 9 additions & 16 deletions DQMOffline/RecoB/python/bTagSequences_cff.py
Expand Up @@ -3,8 +3,6 @@
#define you jet ID
jetID = cms.InputTag("ak4PFJetsCHS")



#JTA for your jets
from RecoJets.JetAssociationProducers.j2tParametersVX_cfi import *
myak4JetTracksAssociatorAtVertex = cms.EDProducer("JetTracksAssociatorAtVertex",
Expand All @@ -20,11 +18,20 @@
softPFElectronsTagInfos.jets = jetID

#for MC do the matching with you jet collection
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
ak4JetFlavourInfos.jets = jetID

from PhysicsTools.JetMCAlgos.CaloJetsMCFlavour_cfi import *
AK4byRef.jets = jetID

#do the matching : only for MC
flavourSeq = cms.Sequence(
selectedHadronsAndPartons *
ak4JetFlavourInfos
)

oldFlavourSeq = cms.Sequence(
myPartons *
AK4Flavour
)
Expand All @@ -42,17 +49,3 @@
from HLTrigger.HLTfilters.hltHighLevel_cfi import *
bTagHLT = hltHighLevel.clone(TriggerResultsTag = "TriggerResults::HLT", HLTPaths = ["HLT_PFJet40_v*"])

#for the use of JEC, could change with time : be careful if recommandations change for the correctors
#define you sequence like process.JECAlgo = cms.Sequence(process.ak4PFJetsJEC * process.PFJetsFilter)
JetCut=cms.string("neutralHadronEnergyFraction < 0.99 && neutralEmEnergyFraction < 0.99 && nConstituents > 1 && chargedHadronEnergyFraction > 0.0 && chargedMultiplicity > 0.0 && chargedEmEnergyFraction < 0.99")
#JetCut=cms.string("chargedEmEnergyFraction < 99999")

from JetMETCorrections.Configuration.DefaultJEC_cff import *
from JetMETCorrections.Configuration.JetCorrectionServices_cff import *


PFJetsFilter = cms.EDFilter("PFJetSelector",
src = cms.InputTag("ak4PFJetsL2L3"),
cut = JetCut,
filter = cms.bool(True)
)
10 changes: 6 additions & 4 deletions DQMOffline/RecoB/python/dqmAnalyzer_cff.py
Expand Up @@ -17,8 +17,10 @@

########## MC ############
#Matching
from PhysicsTools.JetMCAlgos.CaloJetsMCFlavour_cfi import *
AK4byRef.jets = cms.InputTag("ak4PFJetsCHS")
from PhysicsTools.JetMCAlgos.HadronAndPartonSelector_cfi import selectedHadronsAndPartons
from PhysicsTools.JetMCAlgos.AK4PFJetsMCFlavourInfos_cfi import ak4JetFlavourInfos
myak4JetFlavourInfos = ak4JetFlavourInfos.clone(jets = cms.InputTag("ak4PFJetsCHS"))

#Get gen jet collection for real jets
ak4GenJetsForPUid = cms.EDFilter("GenJetSelector",
src = cms.InputTag("ak4GenJets"),
Expand All @@ -36,15 +38,15 @@

# Module execution for MC
from Validation.RecoB.bTagAnalysis_cfi import *
bTagValidation.jetMCSrc = 'AK4byValAlgo'
bTagValidation.jetMCSrc = 'myak4JetFlavourInfos'
bTagValidation.ptRanges = cms.vdouble(0.0)
bTagValidation.etaRanges = cms.vdouble(0.0)
bTagValidation.doJetID = True
bTagValidation.doJEC = True
bTagValidation.JECsource = cms.string("ak4PFCHSL1FastL2L3")
bTagValidation.genJetsMatched = cms.InputTag("newpatJetGenJetMatch")
#to run on fastsim
prebTagSequenceMC = cms.Sequence(ak4GenJetsForPUid*newpatJetGenJetMatch*myPartons*AK4Flavour)
prebTagSequenceMC = cms.Sequence(ak4GenJetsForPUid*newpatJetGenJetMatch*selectedHadronsAndPartons*myak4JetFlavourInfos)
bTagPlotsMC = cms.Sequence(bTagValidation)

#to run on fullsim in the validation sequence, all histograms produced in the dqmoffline sequence
Expand Down
69 changes: 45 additions & 24 deletions Validation/RecoB/plugins/BTagPerformanceAnalyzerMC.cc
Expand Up @@ -7,7 +7,7 @@ using namespace edm;
using namespace std;
using namespace RecoBTag;

typedef std::pair<Jet, reco::JetFlavour> JetWithFlavour;
typedef std::pair<Jet, reco::JetFlavourInfo> JetWithFlavour;

BTagPerformanceAnalyzerMC::BTagPerformanceAnalyzerMC(const edm::ParameterSet& pSet) :
jetSelector(
Expand All @@ -22,6 +22,7 @@ BTagPerformanceAnalyzerMC::BTagPerformanceAnalyzerMC(const edm::ParameterSet& pS
),
etaRanges(pSet.getParameter< vector<double> >("etaRanges")),
ptRanges(pSet.getParameter< vector<double> >("ptRanges")),
useOldFlavourTool(pSet.getParameter<bool>( "useOldFlavourTool" )),
JECsource(pSet.getParameter<std::string>( "JECsource" )),
doJEC(pSet.getParameter<bool>( "doJEC" )),
ptHatWeight(pSet.getParameter< bool >("applyPtHatWeight")),
Expand Down Expand Up @@ -51,7 +52,8 @@ BTagPerformanceAnalyzerMC::BTagPerformanceAnalyzerMC(const edm::ParameterSet& pS

genToken = mayConsume<GenEventInfoProduct>(edm::InputTag("generator"));
genJetsMatchedToken = mayConsume<edm::Association<reco::GenJetCollection>>(pSet.getParameter<InputTag>("genJetsMatched"));
jetToken = consumes<JetFlavourMatchingCollection>(pSet.getParameter<InputTag>("jetMCSrc"));
jetToken = consumes<JetFlavourInfoMatchingCollection>(pSet.getParameter<InputTag>("jetMCSrc"));
caloJetToken = mayConsume<JetFlavourMatchingCollection>(pSet.getParameter<InputTag>("caloJetMCSrc"));
slInfoToken = consumes<SoftLeptonTagInfoCollection>(pSet.getParameter<InputTag>("softLeptonInfo"));
for (vector<edm::ParameterSet>::const_iterator iModule = moduleConfig.begin();
iModule != moduleConfig.end(); ++iModule) {
Expand Down Expand Up @@ -243,17 +245,37 @@ void BTagPerformanceAnalyzerMC::analyze(const edm::Event& iEvent, const edm::Eve

LogDebug("Info") << "Event weight is: " << weight;

edm::Handle<JetFlavourMatchingCollection> jetMC;
FlavourMap flavours;
LeptonMap leptons;

iEvent.getByToken(jetToken, jetMC);
for (JetFlavourMatchingCollection::const_iterator iter = jetMC->begin();
iter != jetMC->end(); ++iter) {
unsigned int fl = std::abs(iter->second.getFlavour());
flavours.insert(std::make_pair(iter->first, fl));
const reco::JetFlavour::Leptons &lep = iter->second.getLeptons();
leptons.insert(std::make_pair(iter->first, lep));

if(!useOldFlavourTool) {
edm::Handle<JetFlavourInfoMatchingCollection> jetMC;
iEvent.getByToken(jetToken, jetMC);
for (JetFlavourInfoMatchingCollection::const_iterator iter = jetMC->begin();
iter != jetMC->end(); ++iter) {
unsigned int fl = std::abs(iter->second.getPartonFlavour());
flavours.insert(std::make_pair(iter->first, fl));
const GenParticleRefVector &lep = iter->second.getLeptons();
reco::JetFlavour::Leptons lepCount;
for (unsigned int i=0; i<lep.size(); i++){
if(abs(lep.at(0)->pdgId())==11) lepCount.electron++;
else if(abs(lep.at(0)->pdgId())==13) lepCount.muon++;
else if(abs(lep.at(0)->pdgId())==15) lepCount.tau++;
}
leptons.insert(std::make_pair(iter->first, lepCount));
}
}
else {
edm::Handle<JetFlavourMatchingCollection> jetMC;
iEvent.getByToken(caloJetToken, jetMC);
for (JetFlavourMatchingCollection::const_iterator iter = jetMC->begin();
iter != jetMC->end(); ++iter) {
unsigned int fl = std::abs(iter->second.getFlavour());
flavours.insert(std::make_pair(iter->first, fl));
const reco::JetFlavour::Leptons &lep = iter->second.getLeptons();
leptons.insert(std::make_pair(iter->first, lep));
}
}

edm::Handle<reco::SoftLeptonTagInfoCollection> infoHandle;
Expand Down Expand Up @@ -292,8 +314,7 @@ void BTagPerformanceAnalyzerMC::analyze(const edm::Event& iEvent, const edm::Eve
((electronPlots && !leptons[tagI->first].electron) ||
(muonPlots && !leptons[tagI->first].muon) ||
(tauPlots && !leptons[tagI->first].tau)))
continue;

continue;
//JEC
reco::Jet correctedJet = *(tagI->first);
double jec = 1.0;
Expand All @@ -304,15 +325,15 @@ void BTagPerformanceAnalyzerMC::analyze(const edm::Event& iEvent, const edm::Eve
JetWithFlavour jetWithFlavour;
if (!getJetWithFlavour(tagI->first, flavours, jetWithFlavour, iSetup, genJetsMatched))
continue;
if (!jetSelector(jetWithFlavour.first, std::abs(jetWithFlavour.second.getFlavour()), infoHandle, jec))
if (!jetSelector(jetWithFlavour.first, std::abs(jetWithFlavour.second.getPartonFlavour()), infoHandle, jec))
continue;

for (int iPlotter = 0; iPlotter != plotterSize; ++iPlotter) {
bool inBin = false;
inBin = binJetTagPlotters[iJetLabel][iPlotter]->etaPtBin().inBin(jetWithFlavour.first, jec);
// Fill histograms if in desired pt/rapidity bin.
if (inBin)
binJetTagPlotters[iJetLabel][iPlotter]->analyzeTag(jetWithFlavour.first, jec, tagI->second, std::abs(jetWithFlavour.second.getFlavour()),weight);
binJetTagPlotters[iJetLabel][iPlotter]->analyzeTag(jetWithFlavour.first, jec, tagI->second, std::abs(jetWithFlavour.second.getPartonFlavour()),weight);
}
}
for (int iPlotter = 0; iPlotter != plotterSize; ++iPlotter) {
Expand All @@ -339,7 +360,7 @@ void BTagPerformanceAnalyzerMC::analyze(const edm::Event& iEvent, const edm::Eve
(muonPlots && !leptons[tagI->first].muon) ||
(tauPlots && !leptons[tagI->first].tau)))
continue;

//JEC
reco::Jet correctedJet = *(tagI->first);
double jec = 1.0;
Expand All @@ -350,7 +371,7 @@ void BTagPerformanceAnalyzerMC::analyze(const edm::Event& iEvent, const edm::Eve
JetWithFlavour jetWithFlavour;
if (!getJetWithFlavour(tagI->first, flavours, jetWithFlavour, iSetup, genJetsMatched))
continue;
if (!jetSelector(jetWithFlavour.first, std::abs(jetWithFlavour.second.getFlavour()), infoHandle, jec))
if (!jetSelector(jetWithFlavour.first, std::abs(jetWithFlavour.second.getPartonFlavour()), infoHandle, jec))
continue;

for(int iPlotter = 0; iPlotter != plotterSize; ++iPlotter) {
Expand All @@ -360,7 +381,7 @@ void BTagPerformanceAnalyzerMC::analyze(const edm::Event& iEvent, const edm::Eve
if(inBin)
{
double discr2 = tagColl2[tagI->first];
binTagCorrelationPlotters[iJetLabel][iPlotter]->analyzeTags(tagI->second, discr2, std::abs(jetWithFlavour.second.getFlavour()),weight);
binTagCorrelationPlotters[iJetLabel][iPlotter]->analyzeTags(tagI->second, discr2, std::abs(jetWithFlavour.second.getPartonFlavour()),weight);
}
}
}
Expand Down Expand Up @@ -431,7 +452,7 @@ void BTagPerformanceAnalyzerMC::analyze(const edm::Event& iEvent, const edm::Eve
(muonPlots && !leptons[jetRef].muon) ||
(tauPlots && !leptons[jetRef].tau)))
continue;

//JEC
reco::Jet correctedJet = *(jetRef);
double jec = 1.0;
Expand All @@ -442,15 +463,15 @@ void BTagPerformanceAnalyzerMC::analyze(const edm::Event& iEvent, const edm::Eve
JetWithFlavour jetWithFlavour;
if (!getJetWithFlavour(jetRef, flavours, jetWithFlavour, iSetup, genJetsMatched))
continue;
if (!jetSelector(jetWithFlavour.first, std::abs(jetWithFlavour.second.getFlavour()), infoHandle, jec))
if (!jetSelector(jetWithFlavour.first, std::abs(jetWithFlavour.second.getPartonFlavour()), infoHandle, jec))
continue;

for (int iPlotter = 0; iPlotter != plotterSize; ++iPlotter) {
bool inBin = false;
inBin = binTagInfoPlotters[iJetLabel][iPlotter]->etaPtBin().inBin(*jetRef, jec);
// Fill histograms if in desired pt/rapidity bin.
if (inBin)
binTagInfoPlotters[iJetLabel][iPlotter]->analyzeTag(baseTagInfos, jec, std::abs(jetWithFlavour.second.getFlavour()),weight);
binTagInfoPlotters[iJetLabel][iPlotter]->analyzeTag(baseTagInfos, jec, std::abs(jetWithFlavour.second.getPartonFlavour()),weight);
}
}
}
Expand Down Expand Up @@ -505,11 +526,11 @@ bool BTagPerformanceAnalyzerMC::getJetWithFlavour(edm::RefToBase<Jet> jetRef, c
if(!isNotPU) flavour=20;
}

jetWithFlavour.second = reco::JetFlavour(jetWithFlavour.first.p4(), math::XYZPoint (0,0,0), flavour);
jetWithFlavour.second = reco::JetFlavourInfo(flavour, flavour);

LogTrace("Info") << "Found jet with flavour "<<jetWithFlavour.second.getFlavour()<<endl;
LogTrace("Info") << jetWithFlavour.first.p()<<" , "<< jetWithFlavour.first.pt()<<" - "
<< jetWithFlavour.second.getLorentzVector().P()<<" , "<< jetWithFlavour.second.getLorentzVector().Pt()<<endl;
LogTrace("Info") << "Found jet with flavour "<<jetWithFlavour.second.getPartonFlavour()<<endl;
LogTrace("Info") << jetWithFlavour.first.p()<<" , "<< jetWithFlavour.first.pt()<<" - "<<endl;
//<< jetWithFlavour.second.getLorentzVector().P()<<" , "<< jetWithFlavour.second.getLorentzVector().Pt()<<endl;

return true;
}
Expand Down
10 changes: 7 additions & 3 deletions Validation/RecoB/plugins/BTagPerformanceAnalyzerMC.h
Expand Up @@ -8,14 +8,16 @@
#include "DQMOffline/RecoB/interface/JetTagPlotter.h"
#include "DQMOffline/RecoB/interface/TagCorrelationPlotter.h"
#include "DQMOffline/RecoB/interface/BaseTagInfoPlotter.h"
#include "SimDataFormats/JetMatching/interface/JetFlavourInfoMatching.h"
#include "SimDataFormats/JetMatching/interface/JetFlavourMatching.h"
#include "SimDataFormats/JetMatching/interface/JetFlavourInfo.h"
#include "SimDataFormats/JetMatching/interface/JetFlavour.h"
#include "DQMOffline/RecoB/interface/CorrectJet.h"
#include "DQMOffline/RecoB/interface/MatchJet.h"
#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
#include "DataFormats/JetReco/interface/GenJet.h"
#include "DataFormats/Common/interface/Association.h"

#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
/** \class BTagPerformanceAnalyzerMC
*
* Top level steering routine for b tag performance analysis.
Expand Down Expand Up @@ -44,7 +46,7 @@ class BTagPerformanceAnalyzerMC : public DQMEDAnalyzer {

EtaPtBin getEtaPtBin(const int& iEta, const int& iPt);

typedef std::pair<reco::Jet, reco::JetFlavour> JetWithFlavour;
typedef std::pair<reco::Jet, reco::JetFlavourInfo> JetWithFlavour;
typedef std::map<edm::RefToBase<reco::Jet>, unsigned int, JetRefCompare> FlavourMap;
typedef std::map<edm::RefToBase<reco::Jet>, reco::JetFlavour::Leptons, JetRefCompare> LeptonMap;

Expand All @@ -57,6 +59,7 @@ class BTagPerformanceAnalyzerMC : public DQMEDAnalyzer {
std::vector<std::string> tiDataFormatType;
AcceptJet jetSelector; // Decides if jet and parton satisfy kinematic cuts.
std::vector<double> etaRanges, ptRanges;
bool useOldFlavourTool;
std::string JECsource;
bool doJEC;

Expand Down Expand Up @@ -89,7 +92,8 @@ class BTagPerformanceAnalyzerMC : public DQMEDAnalyzer {
//add consumes
edm::EDGetTokenT<GenEventInfoProduct> genToken;
edm::EDGetTokenT<edm::Association<reco::GenJetCollection>> genJetsMatchedToken;
edm::EDGetTokenT<reco::JetFlavourMatchingCollection> jetToken;
edm::EDGetTokenT<reco::JetFlavourInfoMatchingCollection> jetToken;
edm::EDGetTokenT<reco::JetFlavourMatchingCollection> caloJetToken;
edm::EDGetTokenT<reco::SoftLeptonTagInfoCollection> slInfoToken;
std::vector< edm::EDGetTokenT<reco::JetTagCollection> > jetTagToken;
std::vector< std::pair<edm::EDGetTokenT<reco::JetTagCollection>, edm::EDGetTokenT<reco::JetTagCollection>> > tagCorrelationToken;
Expand Down

0 comments on commit 4e5ee01

Please sign in to comment.