Skip to content

Commit

Permalink
Merge pull request #18986 from natalia-korneeva/HEP17-btaghlt-validation
Browse files Browse the repository at this point in the history
Adding plots for the hltbtag HEP17 validation
  • Loading branch information
cmsbuild committed Jul 4, 2017
2 parents a405400 + fbc36d8 commit 88e61f1
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
4 changes: 4 additions & 0 deletions HLTriggerOffline/Btag/interface/HLTBTagHarvestingAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class HLTBTagHarvestingAnalyzer : public DQMEDHarvester {
TH1F calculateEfficiency1D( DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter, TH1 & num, TH1 & den, std::string name );
bool GetNumDenumerators(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter, std::string num, std::string den,TH1 * & ptrnum,TH1* & ptrden,int type);
void mistagrate( DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter, TH1F* num, TH1F* den, std::string effName );
void modulesrate( DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter, TH1F* num, TH1F* den, std::string effName );

private:
// ----------member data ---------------------------
Expand All @@ -48,6 +49,9 @@ class HLTBTagHarvestingAnalyzer : public DQMEDHarvester {
// Histogram handler
std::map<std::string, MonitorElement *> H1_;

enum HCALSpecials {HEP17, HEP18, HEM17};
std::map<HLTBTagHarvestingAnalyzer::HCALSpecials,std::string> HCALSpecialsNames;

};


Expand Down
5 changes: 5 additions & 0 deletions HLTriggerOffline/Btag/interface/HLTBTagPerformanceAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class HLTBTagPerformanceAnalyzer : public DQMEDAnalyzer {

typedef std::map<edm::RefToBase<reco::Jet>, float, JetRefCompare> JetTagMap;

enum HCALSpecials {HEP17, HEP18, HEM17};

// variables from python configuration
edm::EDGetTokenT<edm::TriggerResults> hlTriggerResults_;
std::vector<std::string> hltPathNames_;
Expand All @@ -84,7 +86,9 @@ class HLTBTagPerformanceAnalyzer : public DQMEDAnalyzer {

// Histogram handler
std::vector< std::map<std::string, MonitorElement *> > H1_;
std::vector< std::map<std::string, std::map<HCALSpecials, MonitorElement *> > > H1mod_;
std::vector< std::map<std::string, MonitorElement *> > H2_;
std::vector< std::map<std::string, std::map<HCALSpecials, MonitorElement *> > > H2mod_;
std::vector< std::map<std::string, MonitorElement *> > H2Eta_;
std::vector< std::map<std::string, MonitorElement *> > H2Phi_;

Expand All @@ -94,6 +98,7 @@ class HLTBTagPerformanceAnalyzer : public DQMEDAnalyzer {
std::vector<std::string> JetTagCollection_Label;
std::string hlTriggerResults_Label;
std::string hltConfigProvider_Label;
std::map<HLTBTagPerformanceAnalyzer::HCALSpecials,std::string> HCALSpecialsNames;

};

Expand Down
76 changes: 76 additions & 0 deletions HLTriggerOffline/Btag/src/HLTBTagHarvestingAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ HLTBTagHarvestingAnalyzer::HLTBTagHarvestingAnalyzer(const edm::ParameterSet& iC
m_mcLabels = mc.getParameterNamesForType<std::vector<unsigned int> >();
m_histoName = iConfig.getParameter<std::vector<std::string> >("histoName");
m_minTag = iConfig.getParameter<double>("minTag");

HCALSpecialsNames[HEP17] = "HEP17";
HCALSpecialsNames[HEP18] = "HEP18";
HCALSpecialsNames[HEM17] = "HEM17";
}

HLTBTagHarvestingAnalyzer::~HLTBTagHarvestingAnalyzer()
Expand All @@ -27,11 +31,14 @@ HLTBTagHarvestingAnalyzer::dqmEndJob(DQMStore::IBooker & ibooker, DQMStore::IGet
{
dqmFolder_hist = Form("HLT/BTag/Discriminator/%s",hltPathNames_[ind].c_str());
std::string effDir = Form("HLT/BTag/Discriminator/%s/efficiency",hltPathNames_[ind].c_str());
std::string relationsDir = Form("HLT/BTag/Discriminator/%s/HEP17_HEM17",hltPathNames_[ind].c_str());
ibooker.setCurrentFolder(effDir);
TH1 *den =NULL;
TH1 *num =NULL;
std::map<TString,TH1F> effics;
std::map<TString,bool> efficsOK;
std::map<std::string,std::map<HCALSpecials,TH1F> > efficsmod;
std::map<std::string,std::map<HCALSpecials,bool> > efficsmodOK;
for (unsigned int i = 0; i < m_mcLabels.size(); ++i)
{
bool isOK=false;
Expand All @@ -45,6 +52,18 @@ HLTBTagHarvestingAnalyzer::dqmEndJob(DQMStore::IBooker & ibooker, DQMStore::IGet
effics[flavour]=calculateEfficiency1D(ibooker,igetter,*num,*den,(label+"_efficiency_vs_disc").Data());
efficsOK[flavour]=isOK;
}
//for modules (HEP17 etc.)
for (auto j: HCALSpecialsNames){
ibooker.setCurrentFolder(dqmFolder_hist+"/"+j.second+"/efficiency");
isOK=GetNumDenumerators(ibooker,igetter,(TString(dqmFolder_hist)+"/"+j.second+"/"+label).Data(),(TString(dqmFolder_hist)+"/"+j.second+"/"+label).Data(),num,den,0);
if (isOK){

//do the 'b-tag efficiency vs discr' plot
efficsmod[flavour.Data()][j.first]=calculateEfficiency1D(ibooker,igetter,*num,*den,(label+"_efficiency_vs_disc").Data());
efficsmodOK[flavour.Data()][j.first]=isOK;
}
}
ibooker.setCurrentFolder(effDir);
label= m_histoName.at(ind)+std::string("___");
std::string labelEta = label.Data();
std::string labelPhi = label.Data();
Expand All @@ -69,12 +88,37 @@ HLTBTagHarvestingAnalyzer::dqmEndJob(DQMStore::IBooker & ibooker, DQMStore::IGet
//do the 'b-tag efficiency vs Phi' plot
TH1F eff=calculateEfficiency1D(ibooker,igetter,*num,*den,labelPhi+"_efficiency_vs_phi");
}

///save efficiency_vs_disc_HEP17 / efficiency_vs_disc_HEM17 plots
ibooker.setCurrentFolder(relationsDir);
if (efficsmodOK[flavour.Data()][HEP17] && efficsmodOK[flavour.Data()][HEM17])
modulesrate(ibooker,igetter,&efficsmod[flavour.Data()][HEP17], &efficsmod[flavour.Data()][HEM17], m_histoName.at(ind)+"_"+flavour.Data()+"_HEP17_HEM17_effs_vs_disc_rate" );
ibooker.setCurrentFolder(effDir);

} /// for mc labels

///save mistagrate vs b-eff plots
if (efficsOK["b"] && efficsOK["c"]) mistagrate(ibooker,igetter,&effics["b"], &effics["c"], m_histoName.at(ind)+"_b_c_mistagrate" );
if (efficsOK["b"] && efficsOK["light"]) mistagrate(ibooker,igetter,&effics["b"], &effics["light"], m_histoName.at(ind)+"_b_light_mistagrate" );
if (efficsOK["b"] && efficsOK["g"]) mistagrate(ibooker,igetter,&effics["b"], &effics["g"], m_histoName.at(ind)+"_b_g_mistagrate" );

///save mistagrate vs b-eff plots for modules (HEP17 etc.)
for (auto j: HCALSpecialsNames){
ibooker.setCurrentFolder(dqmFolder_hist+"/"+j.second+"/efficiency");
if (efficsmodOK["b"][j.first] && efficsmodOK["c"][j.first]) mistagrate(ibooker,igetter,&efficsmod["b"][j.first], &efficsmod["c"][j.first], m_histoName.at(ind)+"_b_c_mistagrate" );
if (efficsmodOK["b"][j.first] && efficsmodOK["light"][j.first]) mistagrate(ibooker,igetter,&efficsmod["b"][j.first], &efficsmod["light"][j.first], m_histoName.at(ind)+"_b_light_mistagrate" );
if (efficsmodOK["b"][j.first] && efficsmodOK["g"][j.first]) mistagrate(ibooker,igetter,&efficsmod["b"][j.first], &efficsmod["g"][j.first], m_histoName.at(ind)+"_b_g_mistagrate" );
}

///save mistagrate_HEP17 / mistagrate_HEM17 plots
ibooker.setCurrentFolder(relationsDir);
bool isOK=false;
isOK=GetNumDenumerators(ibooker,igetter,dqmFolder_hist+"/HEP17/efficiency/"+m_histoName.at(ind)+"_b_c_mistagrate",dqmFolder_hist+"/HEM17/efficiency/"+m_histoName.at(ind)+"_b_c_mistagrate",num,den,3);
if (isOK) modulesrate(ibooker,igetter,(TH1F*)num, (TH1F*)den, m_histoName.at(ind)+"_HEP17_HEM17_b_c_mistagrate" );
isOK=GetNumDenumerators(ibooker,igetter,dqmFolder_hist+"/HEP17/efficiency/"+m_histoName.at(ind)+"_b_light_mistagrate",dqmFolder_hist+"/HEM17/efficiency/"+m_histoName.at(ind)+"_b_light_mistagrate",num,den,3);
if (isOK) modulesrate(ibooker,igetter,(TH1F*)num, (TH1F*)den, m_histoName.at(ind)+"_HEP17_HEM17_b_light_mistagrate" );
isOK=GetNumDenumerators(ibooker,igetter,dqmFolder_hist+"/HEP17/efficiency/"+m_histoName.at(ind)+"_b_g_mistagrate",dqmFolder_hist+"/HEM17/efficiency/"+m_histoName.at(ind)+"_b_g_mistagrate",num,den,3);
if (isOK) modulesrate(ibooker,igetter,(TH1F*)num, (TH1F*)den, m_histoName.at(ind)+"_HEP17_HEM17_b_g_mistagrate" );
} /// for triggers
}

Expand All @@ -86,6 +130,7 @@ bool HLTBTagHarvestingAnalyzer::GetNumDenumerators(DQMStore::IBooker& ibooker, D
type =0 for eff_vs_discriminator
type =1 for eff_vs_pT
type =2 for eff_vs_eta or eff_vs_phi
type =3 for HEP17 / HEM17 mistagrate relation
*/
MonitorElement *denME = NULL;
MonitorElement *numME = NULL;
Expand Down Expand Up @@ -163,6 +208,12 @@ bool HLTBTagHarvestingAnalyzer::GetNumDenumerators(DQMStore::IBooker& ibooker, D
delete cutg_num;
delete cutg_den;
}

if (type==3) //mistagrate HEP17 / HEM17 relation: fill "ptrnum" with HEP17 mistagrate and "ptrden" with HEM17 mistagrate
{
ptrden=denME->getTH1();
ptrnum=numME->getTH1();
}
return true;
}

Expand Down Expand Up @@ -201,6 +252,31 @@ void HLTBTagHarvestingAnalyzer::mistagrate(DQMStore::IBooker& ibooker, DQMStore:
return;
}

void HLTBTagHarvestingAnalyzer::modulesrate(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter, TH1F* num, TH1F* den, std::string effName ){
//do the eff_vs_disc_HEP17 / eff_vs_disc_HEM17 plot
TH1F* eff=new TH1F(*num);
//eff = new TH1F(effName.c_str(),effName.c_str(),100,0,1);
eff->Divide(den);
eff->SetTitle(effName.c_str());
eff->SetXTitle(num->GetXaxis()->GetTitle());
eff->SetYTitle("");
eff->SetOption("E");
eff->SetLineColor(2);
eff->SetLineWidth(2);
eff->SetMarkerStyle(20);
eff->SetMarkerSize(0.8);
eff->GetYaxis()->SetRangeUser(0.001,2.001);
//eff->GetXaxis()->SetRangeUser(-0.001,1.001);
eff->SetStats(kFALSE);

MonitorElement *me;
me = ibooker.book1D(effName.c_str(),eff);
me->setEfficiencyFlag();

delete eff;
return;
}

TH1F HLTBTagHarvestingAnalyzer::calculateEfficiency1D(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter, TH1 & num , TH1 & den, std::string effName ){
//calculate the efficiency as num/den ratio
TH1F eff;
Expand Down
42 changes: 42 additions & 0 deletions HLTriggerOffline/Btag/src/HLTBTagPerformanceAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ HLTBTagPerformanceAnalyzer::HLTBTagPerformanceAnalyzer(const edm::ParameterSet&
m_mcMatching = m_mcPartons_Label != "none" ;

m_mcRadius=0.3;

HCALSpecialsNames[HEP17] = "HEP17";
HCALSpecialsNames[HEP18] = "HEP18";
HCALSpecialsNames[HEM17] = "HEM17";
}


Expand Down Expand Up @@ -139,8 +143,17 @@ void HLTBTagPerformanceAnalyzer::analyze(const edm::Event& iEvent, const edm::Ev
}

for (auto & BtagJT: JetTag) {
std::map<HCALSpecials, bool> inmodule;
inmodule[HEP17]=(BtagJT.first->phi() >= -0.87) && (BtagJT.first->phi() < -0.52) && (BtagJT.first->eta() > 1.3);
inmodule[HEP18]=(BtagJT.first->phi() >= -0.52) && (BtagJT.first->phi() < -0.17) && (BtagJT.first->eta() > 1.3);
inmodule[HEM17]=(BtagJT.first->phi() >= -0.87) && (BtagJT.first->phi() < -0.52) && (BtagJT.first->eta() < -1.3);

//fill 1D btag plot for 'all'
H1_.at(ind)[JetTagCollection_Label[ind]] -> Fill(std::fmax(0.0,BtagJT.second));
for (auto i: HCALSpecialsNames){
if (inmodule[i.first])
H1mod_.at(ind)[JetTagCollection_Label[ind]][i.first] -> Fill(std::fmax(0.0,BtagJT.second));
}
if (MCOK) {
int m = closestJet(BtagJT.first, *h_mcPartons, m_mcRadius);
unsigned int flavour = (m != -1) ? abs((*h_mcPartons)[m].second.getFlavour()) : 0;
Expand All @@ -152,12 +165,20 @@ void HLTBTagPerformanceAnalyzer::analyze(const edm::Event& iEvent, const edm::Ev
TString label=JetTagCollection_Label[ind] + "__";
label+=flavour_str;
H1_.at(ind)[label.Data()]->Fill(std::fmax(0.0,BtagJT.second)); //fill 1D btag plot for 'b,c,uds'
for (auto j: HCALSpecialsNames){
if (inmodule[j.first])
H1mod_.at(ind)[label.Data()][j.first]->Fill(std::fmax(0.0,BtagJT.second)); //fill 1D btag plot for 'b,c,uds' in modules (HEP17 etc.)
}
label=JetTagCollection_Label[ind] + "___";
label+=flavour_str;
std::string labelEta = label.Data();
std::string labelPhi = label.Data();
label+=TString("_disc_pT");
H2_.at(ind)[label.Data()]->Fill(std::fmax(0.0,BtagJT.second),BtagJT.first->pt()); //fill 2D btag, jetPt plot for 'b,c,uds'
for (auto j: HCALSpecialsNames){
if (inmodule[j.first])
H2mod_.at(ind)[label.Data()][j.first]->Fill(std::fmax(0.0,BtagJT.second),BtagJT.first->pt());
}
labelEta+="_disc_eta";
H2Eta_.at(ind)[labelEta]->Fill(std::fmax(0.0,BtagJT.second),BtagJT.first->eta()); //fill 2D btag, jetEta plot for 'b,c,uds'
labelPhi+="_disc_phi";
Expand Down Expand Up @@ -185,6 +206,8 @@ void HLTBTagPerformanceAnalyzer::bookHistograms(DQMStore::IBooker & ibooker, edm
dqmFolder = Form("HLT/BTag/Discriminator/%s",hltPathNames_[ind].c_str());
H1_.push_back(std::map<std::string, MonitorElement *>());
H2_.push_back(std::map<std::string, MonitorElement *>());
H1mod_.push_back(std::map<std::string, std::map<HCALSpecials, MonitorElement *> > ());
H2mod_.push_back(std::map<std::string, std::map<HCALSpecials, MonitorElement *> > ());
H2Eta_.push_back(std::map<std::string, MonitorElement *>());
H2Phi_.push_back(std::map<std::string, MonitorElement *>());
ibooker.setCurrentFolder(dqmFolder);
Expand All @@ -193,6 +216,12 @@ void HLTBTagPerformanceAnalyzer::bookHistograms(DQMStore::IBooker & ibooker, edm
if ( JetTagCollection_Label[ind] != "" && JetTagCollection_Label[ind] != "NULL" ) {
H1_.back()[JetTagCollection_Label[ind]] = ibooker.book1D(JetTagCollection_Label[ind] + "_all", (JetTagCollection_Label[ind]+ "_all").c_str(), btagBins, btagL, btagU );
H1_.back()[JetTagCollection_Label[ind]] -> setAxisTitle(JetTagCollection_Label[ind] +"discriminant",1);
for (auto i: HCALSpecialsNames){
ibooker.setCurrentFolder(dqmFolder+"/"+i.second);
H1mod_.back()[JetTagCollection_Label[ind]][i.first] = ibooker.book1D(JetTagCollection_Label[ind] + "_all", (JetTagCollection_Label[ind]+ "_all").c_str(), btagBins, btagL, btagU );
H1mod_.back()[JetTagCollection_Label[ind]][i.first] -> setAxisTitle(JetTagCollection_Label[ind] +"discriminant",1);
}
ibooker.setCurrentFolder(dqmFolder);
}
int nBinsPt=60;
double pTmin=30;
Expand All @@ -217,6 +246,12 @@ void HLTBTagPerformanceAnalyzer::bookHistograms(DQMStore::IBooker & ibooker, edm
//book 1D btag plot for 'b,c,light,g'
H1_.back()[label.Data()] = ibooker.book1D(label.Data(), Form("%s %s",JetTagCollection_Label[ind].c_str(),flavour.Data()), btagBins, btagL, btagU );
H1_.back()[label.Data()]->setAxisTitle("disc",1);
for (auto j: HCALSpecialsNames){
ibooker.setCurrentFolder(dqmFolder+"/"+j.second);
H1mod_.back()[label.Data()][j.first] = ibooker.book1D(label.Data(), Form("%s %s",JetTagCollection_Label[ind].c_str(),flavour.Data()), btagBins, btagL, btagU );
H1mod_.back()[label.Data()][j.first]->setAxisTitle("disc",1);
}
ibooker.setCurrentFolder(dqmFolder);
label=JetTagCollection_Label[ind]+"___";
labelEta=label;
labelPhi=label;
Expand All @@ -228,6 +263,13 @@ void HLTBTagPerformanceAnalyzer::bookHistograms(DQMStore::IBooker & ibooker, edm
H2_.back()[label.Data()] = ibooker.book2D( label.Data(), label.Data(), btagBins, btagL, btagU, nBinsPt, pTmin, pTMax );
H2_.back()[label.Data()]->setAxisTitle("pT",2);
H2_.back()[label.Data()]->setAxisTitle("disc",1);
for (auto j: HCALSpecialsNames){
ibooker.setCurrentFolder(dqmFolder+"/"+j.second);
H2mod_.back()[label.Data()][j.first] = ibooker.book2D( label.Data(), label.Data(), btagBins, btagL, btagU, nBinsPt, pTmin, pTMax );
H2mod_.back()[label.Data()][j.first]->setAxisTitle("pT",2);
H2mod_.back()[label.Data()][j.first]->setAxisTitle("disc",1);
}
ibooker.setCurrentFolder(dqmFolder);
H2Eta_.back()[labelEta] = ibooker.book2D( labelEta, labelEta, btagBins, btagL, btagU, nBinsEta, etamin, etaMax );
H2Eta_.back()[labelEta]->setAxisTitle("eta",2);
H2Eta_.back()[labelEta]->setAxisTitle("disc",1);
Expand Down

0 comments on commit 88e61f1

Please sign in to comment.