Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:08

0001 // name of analyzer
0002 static const char *directory = "analyzeBJetTags";
0003 
0004 static const char *algos[] = { "TC", "SSV", "CSV", 0 };
0005 
0006 static const char *algoNames[] = {
0007     "Track Counting (high efficiency)",
0008     "Simple Secondary Vertex",
0009     "Combined Secondary Vertex",
0010     0
0011 };
0012 
0013 static const char *flavours[] = { "b", "c", "udsg", 0 };
0014 
0015 void patBJetTags_efficiencies()
0016 {
0017     // define proper canvas style
0018     setNiceStyle();
0019     gStyle->SetOptStat(0);
0020 
0021     // open file
0022     TFile* file = new TFile("analyzePatBJetTags.root");
0023 
0024     TH1 *total = (TH1*)file->Get(Form("%s/flavours", directory));
0025     unsigned int j = 0;
0026     for(const char **algo = algos; *algo; algo++, j++) {
0027         TLegend *legend[3] = { 0, 0, 0 };
0028 
0029         // draw canvas with efficiencies
0030         TCanvas *canv;
0031         canv = new TCanvas(*algo, Form("%s efficiencies", algoNames[j]), 800, 300);
0032         canv->Divide(3, 1);
0033 
0034         TH1 *effVsCutB = 0;
0035         unsigned int i = 0;
0036         for(const char **flavour = flavours; *flavour; flavour++, i++) {
0037             TH1 *h = (TH1*)file->Get(Form("%s/discr%s_%s", directory, *algo, *flavour));
0038             TH1 *discrShape = (TH1*)h->Clone(Form("%s_discrShape", h->GetName()));
0039             discrShape->Scale(1.0 / discrShape->Integral());
0040             discrShape->SetMaximum(discrShape->GetMaximum() * 5);
0041             TH1 *effVsCut = computeEffVsCut(h, total->GetBinContent(4 - i));
0042             TH1 *effVsBEff = 0;
0043 
0044             if (flavour == flavours)    // b-jets
0045                 effVsCutB = effVsCut;
0046             else
0047                 effVsBEff = computeEffVsBEff(effVsCut, effVsCutB);
0048 
0049             discrShape->SetTitle("discriminator shape");
0050             effVsCut->SetTitle("efficiency versus discriminator cut");
0051             if (effVsBEff)
0052                 effVsBEff->SetTitle("mistag versus b efficiency");
0053 
0054             setHistStyle(discrShape);
0055             setHistStyle(effVsCut);
0056             setHistStyle(effVsBEff);
0057 
0058             canv->cd(1);
0059             gPad->SetLogy(1);
0060             gPad->SetGridy(1);
0061             discrShape->SetLineColor(i + 1);
0062             discrShape->SetMarkerColor(i + 1);
0063             discrShape->Draw(i > 0 ? "same" : "");
0064             if (!legend[0])
0065                 legend[0] = new TLegend(0.5, 0.7, 0.78, 0.88);
0066             legend[0]->AddEntry(discrShape, *flavour);
0067 
0068             canv->cd(2);
0069             gPad->SetLogy(1);
0070             gPad->SetGridy(1);
0071             effVsCut->SetLineColor(i + 1);
0072             effVsCut->SetMarkerColor(i + 1);
0073             effVsCut->Draw(i > 0 ? "same" : "");
0074             if (!legend[1])
0075                 legend[1] = new TLegend(0.3, 0.4, 0.58, 0.58);
0076             legend[1]->AddEntry(effVsCut, *flavour);
0077 
0078             if (!effVsBEff)
0079                 continue;
0080             canv->cd(3);
0081             gPad->SetLogy(1);
0082             gPad->SetGridx(1);
0083             gPad->SetGridy(1);
0084             effVsBEff->SetLineColor(i + 1);
0085             effVsBEff->SetMarkerColor(i + 1);
0086             effVsBEff->Draw(i > 1 ? "same" : "");
0087             if (!legend[2])
0088                 legend[2] = new TLegend(0.12, 0.7, 0.40, 0.88);
0089             legend[2]->AddEntry(effVsBEff, *flavour);
0090         }
0091 
0092         canv->cd(1);
0093         legend[0]->Draw();
0094 
0095         canv->cd(2);
0096         legend[1]->Draw();
0097 
0098         canv->cd(3);
0099         legend[2]->Draw();
0100     }
0101 }
0102 
0103 TH1 *computeEffVsCut(TH1 *discrShape, double total)
0104 {
0105     TH1 *h = discrShape->Clone(Form("%s_effVsCut", discrShape->GetName()));
0106     h->Sumw2();
0107     h->SetMaximum(1.5);
0108     h->SetMinimum(1e-3);
0109 
0110     unsigned int n = h->GetNbinsX();
0111     for(unsigned int bin = 1; bin <= n; bin++) {
0112         double efficiency = h->Integral(bin, n + 1) / total;
0113         double error = sqrt(efficiency * (1 - efficiency) / total);
0114         h->SetBinContent(bin, efficiency);
0115         h->SetBinError(bin, error);
0116     }
0117 
0118     return h;
0119 }
0120 
0121 TH1 *computeEffVsBEff(TH1 *effVsCut, TH1 *effVsCutB)
0122 {
0123     TH1 *h = new TH1F(Form("%s_effVsBEff", effVsCut->GetName()), "effVsBEff",
0124                       100, 0, 1);
0125     h->SetMaximum(1.5);
0126     h->SetMinimum(1e-3);
0127 
0128     unsigned int n = effVsCut->GetNbinsX();
0129     for(unsigned int bin = 1; bin <= n; bin++) {
0130         double eff = effVsCut->GetBinContent(bin);
0131         double error = effVsCut->GetBinError(bin);
0132         double effB = effVsCutB->GetBinContent(bin);
0133 
0134         h->SetBinContent(h->FindBin(effB), eff);
0135         h->SetBinError(h->FindBin(effB), error);
0136         // FIXME: The error in effB is not propagated
0137     }
0138 
0139     return h;
0140 }
0141 
0142 void setAxisStyle(TH1 *hist) {
0143     // --------------------------------------------------
0144     // define proper axsis style for a given histogram
0145     // --------------------------------------------------
0146     hist->GetXaxis()->SetTitleSize( 0.06);
0147     hist->GetXaxis()->SetTitleColor( 1);
0148     hist->GetXaxis()->SetTitleOffset( 0.8);
0149     hist->GetXaxis()->SetTitleFont( 62);
0150     hist->GetXaxis()->SetLabelSize( 0.05);
0151     hist->GetXaxis()->SetLabelFont( 62);
0152     hist->GetXaxis()->CenterTitle();
0153     hist->GetXaxis()->SetNdivisions( 505);
0154 
0155     hist->GetYaxis()->SetTitleSize( 0.07);
0156     hist->GetYaxis()->SetTitleColor( 1);
0157     hist->GetYaxis()->SetTitleOffset( 0.5);
0158     hist->GetYaxis()->SetTitleFont( 62);
0159     hist->GetYaxis()->SetLabelSize( 0.05);
0160     hist->GetYaxis()->SetLabelFont( 62);
0161 }
0162 
0163 void setHistStyle(TH1 *hist)
0164 {
0165     if (!hist)
0166         return;
0167 
0168     // --------------------------------------------------
0169     // define proper histogram style
0170     // --------------------------------------------------
0171     setAxisStyle(hist);
0172     hist->GetXaxis()->SetTitle(hist->GetTitle());
0173     hist->SetTitle();
0174     hist->SetLineColor(4.);
0175     hist->SetLineWidth(2.);
0176     hist->SetMarkerSize(0.75);
0177     hist->SetMarkerColor(4.);
0178     hist->SetMarkerStyle(20.);
0179 }
0180 
0181 void setNiceStyle() 
0182 {
0183     gROOT->SetStyle("Plain");
0184 
0185     // --------------------------------------------------
0186     // define proper canvas style
0187     // --------------------------------------------------
0188     TStyle *MyStyle = new TStyle ("MyStyle", "My style for nicer plots");
0189     
0190     Float_t xoff = MyStyle->GetLabelOffset("X"),
0191             yoff = MyStyle->GetLabelOffset("Y"),
0192             zoff = MyStyle->GetLabelOffset("Z");
0193 
0194     MyStyle->SetCanvasBorderMode ( 0 );
0195     MyStyle->SetPadBorderMode    ( 0 );
0196     MyStyle->SetPadColor         ( 0 );
0197     MyStyle->SetCanvasColor      ( 0 );
0198     MyStyle->SetTitleColor       ( 0 );
0199     MyStyle->SetStatColor        ( 0 );
0200     MyStyle->SetTitleBorderSize  ( 0 );
0201     MyStyle->SetTitleFillColor   ( 0 );
0202     MyStyle->SetTitleH        ( 0.07 );
0203     MyStyle->SetTitleW        ( 1.00 );
0204     MyStyle->SetTitleFont     (  132 );
0205 
0206     MyStyle->SetLabelOffset (1.5*xoff, "X");
0207     MyStyle->SetLabelOffset (1.5*yoff, "Y");
0208     MyStyle->SetLabelOffset (1.5*zoff, "Z");
0209 
0210     MyStyle->SetTitleOffset (0.9,      "X");
0211     MyStyle->SetTitleOffset (0.9,      "Y");
0212     MyStyle->SetTitleOffset (0.9,      "Z");
0213 
0214     MyStyle->SetTitleSize   (0.045,    "X");
0215     MyStyle->SetTitleSize   (0.045,    "Y");
0216     MyStyle->SetTitleSize   (0.045,    "Z");
0217 
0218     MyStyle->SetLabelFont   (132,      "X");
0219     MyStyle->SetLabelFont   (132,      "Y");
0220     MyStyle->SetLabelFont   (132,      "Z");
0221 
0222     MyStyle->SetPalette(1);
0223 
0224     MyStyle->cd();
0225 }