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

Boosted objects and 94X version #5

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions plugins/BTaggingExerciseI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ BTaggingExerciseI::~BTaggingExerciseI()
void
BTaggingExerciseI::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
// define a jet handle
edm::Handle<std::vector<pat::Jet> > jets;
// get jets from the event
iEvent.getByToken(jets_, jets);

// loop over jets
for( auto jet = jets->begin(); jet != jets->end(); ++jet )
{
// fill discriminator histograms
for( const std::string &bDiscr : bDiscriminators_ ){
if(bDiscr != "pfDeepCSVJetTags")
bDiscriminatorsMap[bDiscr]->Fill( jet->bDiscriminator(bDiscr) );
if(bDiscr == "pfDeepCSVJetTags")
bDiscriminatorsMap[bDiscr]->Fill(jet->bDiscriminator("pfDeepCSVJetTags:probb") + jet->bDiscriminator("pfDeepCSVJetTags:probbb") );
}
}

}

Expand Down
154 changes: 115 additions & 39 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 All @@ -59,13 +61,15 @@ class BTaggingExerciseII : public edm::EDAnalyzer {
//virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;

// ----------member data ---------------------------
const edm::EDGetTokenT<std::vector<pat::Jet> > jets_;
// const edm::EDGetTokenT<std::vector<pat::Jet> > jets_;
const edm::EDGetTokenT<std::vector<pat::Jet> > jetsak8_;
const std::vector<std::string> bDiscriminators_;

edm::Service<TFileService> fs;

// declare a map of b-tag discriminator histograms
std::map<std::string, TH2F *> bDiscriminatorsMap;
std::map<std::string, TH2F *> bDiscriminatorsMap_sjBDiscMin;
};

//
Expand All @@ -81,7 +85,8 @@ class BTaggingExerciseII : public edm::EDAnalyzer {
//
BTaggingExerciseII::BTaggingExerciseII(const edm::ParameterSet& iConfig) :

jets_(consumes<std::vector<pat::Jet> >(iConfig.getParameter<edm::InputTag>("jets"))),
// jets_(consumes<std::vector<pat::Jet> >(iConfig.getParameter<edm::InputTag>("jets"))),
jetsak8_(consumes<std::vector<pat::Jet> >(iConfig.getParameter<edm::InputTag>("jetsak8"))),
bDiscriminators_(iConfig.getParameter<std::vector<std::string> >("bDiscriminators"))

{
Expand All @@ -93,19 +98,38 @@ 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
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);
}
bDiscriminatorsMap[bDiscr_flav] = fs->make<TH2F>(bDiscr_flav.c_str(), (bDiscr_flav + ";Jet p_{T} [GeV];b-tag discriminator").c_str(), 100, 0, 1000, 11000, -15, 40);
else if ( bDiscr.find("probbb") != std::string::npos || bDiscr.find("probb") != std::string::npos ) {
bDiscr_flav = std::string("pfDeepCSVJetTagsProbB") + "_" + flav;
if ( bDiscriminatorsMap.find(bDiscr_flav) == bDiscriminatorsMap.end() )
bDiscriminatorsMap[bDiscr_flav] = fs->make<TH2F>(bDiscr_flav.c_str(), (bDiscr_flav + ";Jet p_{T} [GeV];b-tag discriminator").c_str(), 100, 0, 1000, 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(), 100, 0, 1000, 4400, -11, 11);

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_sjBDiscMin[bDiscr_flav] = fs->make<TH2F>(bDiscr_flav.c_str(), (bDiscr_flav + ";Jet p_{T} [GeV];b-tag discriminator").c_str(), 100, 0, 1000, 11000, -15, 40);
else if ( bDiscr.find("probbb") != std::string::npos || bDiscr.find("probb") != std::string::npos ) {
bDiscr_flav = std::string("pfDeepCSVJetTagsProbb") + "_" + flav ;
if ( bDiscriminatorsMap_sjBDiscMin.find(bDiscr_flav) == bDiscriminatorsMap_sjBDiscMin.end() )
bDiscriminatorsMap_sjBDiscMin[bDiscr_flav] = fs->make<TH2F>(bDiscr_flav.c_str(), (bDiscr_flav + ";Jet p_{T} [GeV];b-tag discriminator").c_str(), 100, 0, 1000, 4400, -11, 11);
}
else
bDiscriminatorsMap_sjBDiscMin[bDiscr_flav] = fs->make<TH2F>(bDiscr_flav.c_str(), (bDiscr_flav + ";Jet p_{T} [GeV];b-tag discriminator").c_str(), 100, 0, 1000, 4400, -11, 11);
}

}
}




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,80 +139,132 @@ BTaggingExerciseII::~BTaggingExerciseII()
//

// ------------ method called for each event ------------
void
void
BTaggingExerciseII::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
// define a jet handle
edm::Handle<std::vector<pat::Jet> > jets;
// edm::Handle<std::vector<pat::Jet> > jets;
// get jets from the event
iEvent.getByToken(jets_, jets);
//iEvent.getByToken(jets_, jets);

// define a jet handle
edm::Handle<std::vector<pat::Jet> > h_jetsak8;
// get jets from the event
iEvent.getByToken(jetsak8_, h_jetsak8);

std::string bDiscr_flav = "";
//loop over AK8 jets
for( auto jetak8 = h_jetsak8->begin(); jetak8 != h_jetsak8->end(); ++jetak8 ){
if(jetak8->mass() < 80 && jetak8->mass() > 160) continue;
if(jetak8->pt() < 750 && jetak8->pt() > 1150) continue;
if(std::abs(jetak8->eta()) > 1.5 ) continue;
std::vector<edm::Ptr<pat::Jet> > const& jets = jetak8->subjets("SoftDropPuppi") ;
// loop over jets
for( auto jet = jets->begin(); jet != jets->end(); ++jet )
int n = jets.size();
//for( auto jet = jets.begin(); jet != jets.end(); ++jet )
for(int i=0 ; i < n ; i++)
{
int flavor = std::abs( jet->hadronFlavour() );
int flavor = std::abs( jets.at(i)->hadronFlavour() );
// 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( flavor==5 ) // b jet
bDiscr_flav = bDiscr + "_b";
else if( flavor==4 ) // c jets
bDiscr_flav = bDiscr + "_c";
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( jets.at(i)->pt(), jets.at(i)->bDiscriminator("pfDeepCSVJetTags:probb") + jets.at(i)->bDiscriminator("pfDeepCSVJetTags:probbb") );
}
else bDiscriminatorsMap[bDiscr_flav]->Fill( jets.at(i)->pt(), jets.at(i)->bDiscriminator(bDiscr) );

}
}
if (n<2) continue;
int flavor0 = std::abs( jets.at(0)->hadronFlavour() );
int flavor1 = std::abs( jets.at(1)->hadronFlavour() );
double bdisc_0 = jets.at(0)->bDiscriminator("pfDeepCSVJetTags:probb") + jets.at(0)->bDiscriminator("pfDeepCSVJetTags:probbb");
double bdisc_1 = jets.at(1)->bDiscriminator("pfDeepCSVJetTags:probb") + jets.at(1)->bDiscriminator("pfDeepCSVJetTags:probbb");
// fill discriminator histograms

for( const std::string &bDiscr : bDiscriminators_ )
{

if( flavor0==5 && flavor1==5 ) // b jet
bDiscr_flav = bDiscr + "_b";
else if( flavor0==4 && flavor1==4 ) // c jets
bDiscr_flav = bDiscr + "_c";
else // light-flavor jet

bDiscr_flav = bDiscr + "_udsg";

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") ;

if ( bdisc_0 < bdisc_1)
bDiscriminatorsMap_sjBDiscMin[bDiscr_flav]->Fill(jets.at(0)->pt(), bdisc_0 );
else
bDiscriminatorsMap_sjBDiscMin[bDiscr_flav]->Fill(jets.at(1)->pt(), bdisc_1 );
}
// else bDiscriminatorsMap_sjBDiscMin[bDiscr_flav]->Fill( jets.at(i)->pt(), jets.at(i)->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"/>
Loading