star-travex
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VxEff.C
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <vector>
4 #include <map>
5 
6 #include "TFile.h"
7 #include "TCanvas.h"
8 #include "TH1.h"
9 #include "TLegend.h"
10 #include "TEfficiency.h"
11 #include "TStyle.h"
12 
13 #include "VxEff.h"
14 
15 
16 TCanvas gVtxEffCanvas("vtx_eff", "Vertex Finding Efficiencies, Std and TMVA ranking", 800, 800);
17 TLegend gVtxEffLegend(0.6, 0.30, 0.98, 0.50);
18 
19 const std::map<std::string, std::string> myDefaultVertexFiles = {
20  {"STD", "mytestout.root"},
21  {"TMVA", "mytestout.root"}
22 };
23 
24 const std::vector<Style_t> myMarkerStyles = {kFullCross, kFullTriangleDown, kFullCircle, kFullStar};
25 
26 
27 int VxEff(const std::vector<std::string> &vtx_file_keys, const std::vector<std::string> &vtx_file_names)
28 {
29  // Check user's input
30  if (vtx_file_keys.size() != vtx_file_names.size()) {
31  std::cout << "ERROR: Different number of keys and files" << std::endl;
32  return EXIT_FAILURE;
33  }
34 
35  if (vtx_file_keys.size() > 4) {
36  std::cout << "ERROR: Too many histograms to overlay on one plot. Specify at most four files" << std::endl;
37  return EXIT_FAILURE;
38  }
39 
40  std::map<std::string, std::string> myVertexFiles;
41 
42  auto fname = vtx_file_names.begin();
43 
44  for (auto key=vtx_file_keys.begin(); key!=vtx_file_keys.end(); ++key, ++fname)
45  {
46  myVertexFiles.insert( std::pair<std::string, std::string>(*key, *fname) );
47  }
48 
49  VxEff(myVertexFiles);
50 }
51 
52 
58 int VxEff(const std::map<std::string, std::string> & vtx_file_names)
59 {
60  // Check user's input
61  if (vtx_file_names.empty()) {
62  std::cout << "ERROR: No input files provided" << std::endl;
63  return EXIT_FAILURE;
64  }
65 
66  // Print out user's input
67  std::cout << "User provided files with histograms:\n";
68 
69  for (const auto& key2FileName : vtx_file_names) {
70  std::cout << "key => file: "
71  << key2FileName.first << " => " << key2FileName.second << "\n";
72  }
73 
74  std::cout << std::endl;
75 
76  TH1F *frame = gVtxEffCanvas.DrawFrame(0, 0, 40, 1.1);
77  frame->SetTitle("Vertex Finding Efficiency");
78  frame->SetYTitle("Efficiency/Impurity");
79  frame->SetXTitle("Vertex Track Multiplicity");
80 
81 
82  int file_indx = 0;
83 
84  for (const auto& key2FileName : vtx_file_names)
85  {
86  TFile file(key2FileName.second.c_str());
87 
88  TH1D *hMcRecMulT = (TH1D *) file.Get("McRecMulT");
89 
90  if (!hMcRecMulT) continue;
91 
92  TH1D *hMcRecMulAny = (TH1D*) file.Get("McRecMulAny");
93  TH1D *hMcRecMulGood = (TH1D*) file.Get("McRecMulGood");
94  TH1D *hMcRecMulBad = (TH1D*) file.Get("McRecMulBad");
95 
96  double T = hMcRecMulT->GetEntries();
97  double A = hMcRecMulAny->GetEntries();
98  double G = hMcRecMulGood->GetEntries();
99  double B = hMcRecMulBad->GetEntries();
100 
101  // For efficiency plots we create here the default marker is unscalable dot
102  // so, change it
103  gStyle->SetMarkerStyle(myMarkerStyles[file_indx++]);
104  gStyle->SetMarkerSize(1.5);
105 
106  // Plot the overall efficiency only from the first file
107  TEfficiency *eff_total = new TEfficiency(*hMcRecMulAny, *hMcRecMulT);
108  eff_total->SetMarkerColor(kBlack);
109  eff_total->Draw("same p");
110  gVtxEffLegend.AddEntry(eff_total, Form("%s Overall Efficiency = %4.2f", key2FileName.first.c_str(), A / T));
111 
112  TEfficiency *efficiency = new TEfficiency(*hMcRecMulGood, *hMcRecMulT);
113  efficiency->SetMarkerColor(kRed);
114  gVtxEffLegend.AddEntry(efficiency, Form("%s Max Rank Efficiency = %4.2f", key2FileName.first.c_str(), G / T));
115  efficiency->Draw("same p");
116 
117  TEfficiency *impurity = new TEfficiency(*hMcRecMulBad, *hMcRecMulT);
118  impurity->SetMarkerColor(kGreen);
119  gVtxEffLegend.AddEntry(impurity, Form("%s Impurity = %4.2f", key2FileName.first.c_str(), B / T));
120  impurity->Draw("same p");
121  }
122 
123  gVtxEffLegend.Draw();
124 
125  gVtxEffCanvas.SaveAs("vtx_eff.png");
126 }
const std::map< std::string, std::string > myDefaultVertexFiles
Definition: VxEff.C:19
int VxEff(const std::vector< std::string > &vtx_file_keys, const std::vector< std::string > &vtx_file_names)
Definition: VxEff.C:27
TCanvas gVtxEffCanvas("vtx_eff","Vertex Finding Efficiencies, Std and TMVA ranking", 800, 800)
TLegend gVtxEffLegend(0.6, 0.30, 0.98, 0.50)
const std::vector< Style_t > myMarkerStyles
Definition: VxEff.C:24