Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
71 changes: 42 additions & 29 deletions plugins/BTaggingExerciseII.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#include "TH2F.h"

#include <boost/algorithm/string.hpp>

//
// class declaration
//
Expand Down Expand Up @@ -94,7 +96,12 @@ BTaggingExerciseII::BTaggingExerciseII(const edm::ParameterSet& iConfig) :
bDiscr_flav = bDiscr + "_" + flav;
if( bDiscr.find("Counting") != std::string::npos ) // track counting discriminator can be both positive and negative and covers a wider range then other discriminators
bDiscriminatorsMap[bDiscr_flav] = fs->make<TH2F>(bDiscr_flav.c_str(), (bDiscr_flav + ";Jet p_{T} [GeV];b-tag discriminator").c_str(), 20, 0, 200, 11000, -15, 40);
else
else if ( bDiscr.find("probbb") != std::string::npos || bDiscr.find("probb") != std::string::npos ) {

Choose a reason for hiding this comment

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

Don't you create the same histogram twice with the OR, I think that a single part e.g.

bDiscr.find("probbb") != std::string::npos

Should suffice and avoid potential memory leaks

bDiscr_flav = std::string("pfDeepCSVJetTagsProbB") + "_" + flav;
if ( bDiscriminatorsMap.find(bDiscr_flav) == bDiscriminatorsMap.end() )
Copy link
Author

Choose a reason for hiding this comment

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

Well, doesn't this line check for the existence of the TH1 object before creating anew one?

bDiscriminatorsMap[bDiscr_flav] = fs->make<TH2F>(bDiscr_flav.c_str(), (bDiscr_flav + ";Jet p_{T} [GeV];b-tag discriminator").c_str(), 20, 0, 200, 4400, -11, 11);
}
else
bDiscriminatorsMap[bDiscr_flav] = fs->make<TH2F>(bDiscr_flav.c_str(), (bDiscr_flav + ";Jet p_{T} [GeV];b-tag discriminator").c_str(), 20, 0, 200, 4400, -11, 11);
}
}
Expand All @@ -103,9 +110,9 @@ BTaggingExerciseII::BTaggingExerciseII(const edm::ParameterSet& iConfig) :

BTaggingExerciseII::~BTaggingExerciseII()
{
// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)

// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)

}

Expand All @@ -115,7 +122,7 @@ BTaggingExerciseII::~BTaggingExerciseII()
//

// ------------ method called for each event ------------
void
void
BTaggingExerciseII::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
// define a jet handle
Expand All @@ -131,7 +138,7 @@ BTaggingExerciseII::analyze(const edm::Event& iEvent, const edm::EventSetup& iSe
// fill discriminator histograms
for( const std::string &bDiscr : bDiscriminators_ )
{
if( jet->pt()<30. || std::abs(jet->eta())>2.4 ) continue; // skip jets with low pT or outside the tracker acceptance
if( jet->pt()<20. || std::abs(jet->eta())>2.5 ) continue; // skip jets with low pT or outside the tracker acceptance

if( flavor==5 ) // b jet
bDiscr_flav = bDiscr + "_b";
Expand All @@ -140,55 +147,61 @@ BTaggingExerciseII::analyze(const edm::Event& iEvent, const edm::EventSetup& iSe
else // light-flavor jet
bDiscr_flav = bDiscr + "_udsg";

bDiscriminatorsMap[bDiscr_flav]->Fill( jet->pt(), jet->bDiscriminator(bDiscr) );
if ( bDiscr.find("probbb") != std::string::npos ) continue; //// We will sum the DeepCSV::probbb and DeepCSV::probb together
if ( bDiscr.find("probb") != std::string::npos ) {
boost::replace_all(bDiscr_flav, bDiscr, "pfDeepCSVJetTagsProbB") ;
bDiscriminatorsMap[bDiscr_flav]->Fill( jet->pt(), jet->bDiscriminator("pfDeepCSVJetTags:probb") + jet->bDiscriminator("pfDeepCSVJetTags:probbb") );
}
else bDiscriminatorsMap[bDiscr_flav]->Fill( jet->pt(), jet->bDiscriminator(bDiscr) );

}
}
}


// ------------ method called once each job just before starting event loop ------------
void
void
BTaggingExerciseII::beginJob()
{
}

// ------------ method called once each job just after ending the event loop ------------
void
void
BTaggingExerciseII::endJob()
{
}

// ------------ method called when starting to processes a run ------------
/*
void
BTaggingExerciseII::beginRun(edm::Run const&, edm::EventSetup const&)
{
}
*/
void
BTaggingExerciseII::beginRun(edm::Run const&, edm::EventSetup const&)
{
}
*/

// ------------ method called when ending the processing of a run ------------
/*
void
BTaggingExerciseII::endRun(edm::Run const&, edm::EventSetup const&)
{
}
*/
void
BTaggingExerciseII::endRun(edm::Run const&, edm::EventSetup const&)
{
}
*/

// ------------ method called when starting to processes a luminosity block ------------
/*
void
BTaggingExerciseII::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
{
}
*/
void
BTaggingExerciseII::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
{
}
*/

// ------------ method called when ending the processing of a luminosity block ------------
/*
void
BTaggingExerciseII::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
{
}
*/
void
BTaggingExerciseII::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
{
}
*/

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void
Expand Down
1 change: 1 addition & 0 deletions plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<use name="FWCore/ParameterSet"/>
<use name="PhysicsTools/UtilAlgos"/>
<use name="FWCore/ServiceRegistry"/>
<use name="boost"/>
<flags EDM_PLUGIN="1"/>
84 changes: 78 additions & 6 deletions test/runBTaggingExerciseII_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
## Input files
process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring(
# /TTJets_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/RunIIFall15MiniAODv2-PU25nsData2015v1_76X_mcRun2_asymptotic_v12-v1/MINIAODSIM
'root://cmseos.fnal.gov//store/user/cmsdas/2017/short_exercises/BTagging/PUMoriond17_80X_mcRun2_asymptotic_2016_TrancheIV_v6-v1/50000/0806AB92-99BE-E611-9ECD-0025905A6138.root'
'/store/mc/RunIISummer17MiniAOD/BulkGravTohhTohbbhbb_narrow_M-3000_13TeV-madgraph/MINIAODSIM/92X_upgrade2017_realistic_v10-v2/90000/06BC74E3-989A-E711-AE10-549F35AF447B.root'
)
)

Expand Down Expand Up @@ -91,7 +90,11 @@
'pfSimpleSecondaryVertexHighPurBJetTags',
'pfCombinedSecondaryVertexV2BJetTags',
'pfCombinedInclusiveSecondaryVertexV2BJetTags',
'pfCombinedMVAV2BJetTags'
'pfCombinedMVAV2BJetTags',
'pfDeepCSVJetTags:probudsg',
'pfDeepCSVJetTags:probb',
'pfDeepCSVJetTags:probc',
'pfDeepCSVJetTags:probbb',
]

from PhysicsTools.PatAlgos.tools.jetTools import *
Expand All @@ -103,9 +106,24 @@
btagDiscriminators = bTagDiscriminators
)

updateJetCollection(
process,
labelName='FatPF',
jetSource=cms.InputTag('slimmedJetsAK8'),
jetCorrections = ('AK8PFPuppi', ['L2Relative', 'L3Absolute'], 'None'),
btagDiscriminators = bTagDiscriminators,
)

updateJetCollection(
process,
labelName='SoftDropSubjetsPF',
jetSource=cms.InputTag('slimmedJetsAK8PFPuppiSoftDropPacked:SubJets'),
jetCorrections = ('AK4PFPuppi', ['L2Relative', 'L3Absolute'], 'None'),
btagDiscriminators = bTagDiscriminators,
)

## Initialize analyzer
process.bTaggingExerciseII = cms.EDAnalyzer('BTaggingExerciseII',
process.bTaggingExerciseIIAK4Jets = cms.EDAnalyzer('BTaggingExerciseII',
jets = cms.InputTag('selectedUpdatedPatJets'), # input jet collection name
bDiscriminators = cms.vstring( # list of b-tag discriminators to access
'pfTrackCountingHighEffBJetTags',
Expand All @@ -116,9 +134,63 @@
'pfSimpleSecondaryVertexHighPurBJetTags',
'pfCombinedSecondaryVertexV2BJetTags',
'pfCombinedInclusiveSecondaryVertexV2BJetTags',
'pfCombinedMVABJetTags'
'pfCombinedMVAV2BJetTags',
'pfDeepCSVJetTags:probudsg',
'pfDeepCSVJetTags:probb',
'pfDeepCSVJetTags:probc',
'pfDeepCSVJetTags:probbb',
)
)

process.bTaggingExerciseIIAK8Jets = cms.EDAnalyzer('BTaggingExerciseII',
jets = cms.InputTag('selectedUpdatedPatJetsFatPF'), # input jet collection name
bDiscriminators = cms.vstring( # list of b-tag discriminators to access
'pfTrackCountingHighEffBJetTags',
'pfTrackCountingHighPurBJetTags',
'pfJetProbabilityBJetTags',
'pfJetBProbabilityBJetTags',
'pfSimpleSecondaryVertexHighEffBJetTags',
'pfSimpleSecondaryVertexHighPurBJetTags',
'pfCombinedSecondaryVertexV2BJetTags',
'pfCombinedInclusiveSecondaryVertexV2BJetTags',
'pfCombinedMVAV2BJetTags',
'pfDeepCSVJetTags:probudsg',
'pfDeepCSVJetTags:probb',
'pfDeepCSVJetTags:probc',
'pfDeepCSVJetTags:probbb',
)
)

process.bTaggingExerciseIISubJets = cms.EDAnalyzer('BTaggingExerciseII',
jets = cms.InputTag('selectedUpdatedPatJetsSoftDropSubjetsPF'), # input jet collection name
bDiscriminators = cms.vstring( # list of b-tag discriminators to access
'pfTrackCountingHighEffBJetTags',
'pfTrackCountingHighPurBJetTags',
'pfJetProbabilityBJetTags',
'pfJetBProbabilityBJetTags',
'pfSimpleSecondaryVertexHighEffBJetTags',
'pfSimpleSecondaryVertexHighPurBJetTags',
'pfCombinedSecondaryVertexV2BJetTags',
'pfCombinedInclusiveSecondaryVertexV2BJetTags',
'pfCombinedMVAV2BJetTags',
'pfDeepCSVJetTags:probudsg',
'pfDeepCSVJetTags:probb',
'pfDeepCSVJetTags:probc',
'pfDeepCSVJetTags:probbb',
)
)

process.task = cms.Task()
for mod in process.producers_().itervalues():
process.task.add(mod)
for mod in process.filters_().itervalues():
process.task.add(mod)

## Let it run
process.p = cms.Path(process.bTaggingExerciseII)
process.p = cms.Path(
process.bTaggingExerciseIIAK4Jets
* process.bTaggingExerciseIIAK8Jets
* process.bTaggingExerciseIISubJets
,process.task )

open('dump.py', 'w').write(process.dumpPython())