Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:53

0001 // Plot fraction of good & bad tracks surviving as function of chi2 cut.
0002 // Does so for subset of tracks with nSkip skipped layers (or if nSkip=-1 for all tracks).
0003 
0004 void chi2dof_cut(int nSkip) {
0005   //=== Optimise chi2 cut applied to fitted tracks.
0006 
0007   // In unnamed scripts, variables not forgotten at end, so must delete them before rerunning script, so ...
0008   gROOT->Reset("a");
0009   gStyle->SetOptTitle(0);
0010   gStyle->SetOptStat("");
0011   //gStyle->SetOptStat("emr");
0012   //  gStyle->SetOptStat("euom");
0013   gStyle->SetStatFontSize(0.035);
0014   gStyle->SetHistFillColor(kBlue);
0015   gStyle->SetHistFillStyle(1001);
0016   gStyle->SetMarkerSize(1.2);
0017 
0018   gStyle->SetStatFormat("5.3f");
0019   gStyle->SetStatFontSize(0.04);
0020   gStyle->SetOptFit(0111);
0021   gStyle->SetStatW(0.30);
0022   gStyle->SetStatH(0.02);
0023   gStyle->SetStatX(0.9);
0024   gStyle->SetStatY(0.9);
0025   gStyle->SetPadLeftMargin(0.20);
0026   gStyle->SetTitleYOffset(1.6);
0027   gStyle->SetTitleSize(0.05, "XYZ");
0028 
0029   gStyle->SetLabelSize(.04, "x");
0030   gStyle->SetLabelSize(.04, "y");
0031 
0032   gStyle->SetCanvasDefH(600);
0033   gStyle->SetCanvasDefW(600);
0034 
0035   TCanvas d1("d1");
0036 
0037   TH1F* hisMatchTot;
0038   TH1F* hisUnmatchTot;
0039   TH1F* hisMatch;
0040   TH1F* hisUnmatch;
0041 
0042   //TFile file1("out_ttbar_ultimate_20180831_182908/Hist.root");
0043   //TFile file1("out_ttbar_ultimate_offall_20180831_183257/Hist.root");
0044   TFile file1("Hist.root");
0045 
0046   TLegend leg(0.25, 0.15, 0.55, 0.30);
0047   file1.GetObject("TMTrackProducer/KF4ParamsComb/FitChi2DofMatched_KF4ParamsComb", hisMatchTot);
0048   file1.GetObject("TMTrackProducer/KF4ParamsComb/FitChi2DofUnmatched_KF4ParamsComb", hisUnmatchTot);
0049   if (nSkip == 0) {
0050     file1.GetObject("TMTrackProducer/KF4ParamsComb/KalmanChi2DofSkipLay0Matched_KF4ParamsComb", hisMatch);
0051     file1.GetObject("TMTrackProducer/KF4ParamsComb/KalmanChi2DofSkipLay0Unmatched_KF4ParamsComb", hisUnmatch);
0052   } else if (nSkip == 1) {
0053     file1.GetObject("TMTrackProducer/KF4ParamsComb/KalmanChi2DofSkipLay1Matched_KF4ParamsComb", hisMatch);
0054     file1.GetObject("TMTrackProducer/KF4ParamsComb/KalmanChi2DofSkipLay1Unmatched_KF4ParamsComb", hisUnmatch);
0055   } else if (nSkip == 2) {
0056     file1.GetObject("TMTrackProducer/KF4ParamsComb/KalmanChi2DofSkipLay2Matched_KF4ParamsComb", hisMatch);
0057     file1.GetObject("TMTrackProducer/KF4ParamsComb/KalmanChi2DofSkipLay2Unmatched_KF4ParamsComb", hisUnmatch);
0058   } else if (nSkip == -1) {
0059     file1.GetObject("TMTrackProducer/KF4ParamsComb/FitChi2DofMatched_KF4ParamsComb", hisMatch);
0060     file1.GetObject("TMTrackProducer/KF4ParamsComb/FitChi2DofUnmatched_KF4ParamsComb", hisUnmatch);
0061   }
0062   //file1.GetObject("TMTrackProducer/KF4ParamsComb/FitBeamChi2DofMatched_KF4ParamsComb", hisMatch);
0063   //file1.GetObject("TMTrackProducer/KF4ParamsComb/FitBeamChi2DofUnmatched_KF4ParamsComb", hisUnmatch);
0064 
0065   TH1* hisMatchCum = hisMatch->GetCumulative(false);
0066   TH1* hisUnmatchCum = hisUnmatch->GetCumulative(false);
0067   unsigned int nBins = hisMatchCum->GetNbinsX();
0068 
0069   // TH1::GetCumulative() ignores overflow bins, so add them by hand.
0070   float overMatch = hisMatchCum->GetBinContent(nBins + 1);
0071   float overUnmatch = hisUnmatchCum->GetBinContent(nBins + 1);
0072   float lastMatch = hisMatchCum->GetBinContent(nBins);
0073   float lastUnmatch = hisUnmatchCum->GetBinContent(nBins);
0074   hisMatchCum->SetBinContent(nBins, lastMatch + overMatch);
0075   hisUnmatchCum->SetBinContent(nBins, lastUnmatch + overUnmatch);
0076 
0077   hisMatchCum->Scale(1. / hisMatchTot->GetEntries());
0078   hisUnmatchCum->Scale(1. / hisUnmatchTot->GetEntries());
0079   hisMatchCum->SetMarkerStyle(20);
0080   hisUnmatchCum->SetMarkerStyle(24);
0081   hisMatchCum->SetAxisRange(0.9, 35, "X");  // dangerous. don't make lower cut too big.
0082   hisMatchCum->SetTitle("; chi2/dof; efficiency loss");
0083   d1.SetLogx(1);
0084   d1.SetLogy(1);
0085   float ymax = max(hisMatchCum->GetMaximum(), hisUnmatchCum->GetMaximum());
0086   hisMatchCum->SetMaximum(2 * ymax);
0087   hisMatchCum->SetMarkerStyle(20);
0088   hisMatchCum->Draw("P");
0089   leg.AddEntry(hisMatchCum, "match", "P");
0090   hisUnmatchCum->SetMarkerStyle(24);
0091   hisUnmatchCum->Draw("P SAME");
0092   leg.AddEntry(hisUnmatchCum, "unmatch", "P");
0093   leg.Draw();
0094 
0095   d1.Update();
0096   cin.get();
0097 
0098   TGraph graph_killed(nBins);
0099   graph_killed.SetTitle("; Good tracks killed; Fake tracks killed");
0100   for (unsigned int i = 1; i <= nBins + 1; i++) {
0101     float fracMatch = hisMatchCum->GetBinContent(i);
0102     float fracUnmatch = hisUnmatchCum->GetBinContent(i);
0103     graph_killed.SetPoint(i - 1, fracMatch, fracUnmatch);
0104   }
0105   graph_killed.Draw("AP");
0106 
0107   d1.Update();
0108   d1.Print("plot.pdf");
0109   cin.get();
0110 
0111   file1.Close();
0112 }