plot_muonid_dist.C
Go to the documentation of this file.
1 #include "CAFAna/Core/Spectrum.h"
3 
4 #include "TFile.h"
5 #include "TCanvas.h"
6 #include "TH1.h"
7 #include "TColor.h"
8 #include "TLegend.h"
9 
10 enum BeamMode{
13 }
14 
15 const vector<pair<string, Color_t > > int_mode_colors
16 {
17  {"numucc", kRed},
18  {"numubarcc", kBlue},
19  // {"select", kBlue},
20  // {"selsig", kGreen},
21  // {"bkgd", kViolet},
22  {"nueorbar", kGreen},
23  {"nc", kViolet},
24  {"otherbkgd", kOrange},
25  {"selectedVtxFailure", kGreen-5}
26 };
27 
28 map<string, string> int_mode_titles_fhc
29 {
30  {"numucc", "#nu_{#mu} CC"},
31  {"numubarcc", "#nu_{#mu} CC"},
32  // {"select", "Selection"},
33  // {"selsig", kGreen},
34  // {"bkgd", "All background"},
35  {"nueorbar", "#nu_e + #bar{#nu}_e"},
36  {"nc", "NC"},
37  {"otherbkgd", "Other Bkgd"},
38  {"selectedVtxFailure", "Vtx Fail"}
39 };
40 
41 const string weight = "xsecppfx";
42 
43 using ana::Spectrum;
44 
45 void plot_muonid_dist(string inputFilename, string mode_str, string outputFile = "muonid_dist.pdf")
46 {
47  BeamMode mode;
48  if (mode_str.tolower() == "fhc")
49  mode = kFHC;
50  else if (mode_str.tolower() == "rhc")
51  mode = kRHC;
52  else
53  throw std::runtime_error("Invalid beam mode, plesae give 'FHC' or 'RHC'");
54 
55  TFile * infile = TFile::Open(inputFilename.c_str());
56  TCanvas * c1 = new TCanvas("c1", "c1", 1600, 1200);
57  TLegend * leg = new TLegend();
58  bool firstplot = true;
59  for (pair<string, Color_t> int_mode : int_mode_colors)
60  {
61  TH1 * hist = Spectrum::LoadFrom(infile->GetDirectory(("cv/muonid_" + int_mode.first + "_" + weight).c_str()))->ToTH1(ana::kAna2020RHCPOT);
62  hist->SetName(("muonid_" + int_mode.first).c_str());
63  hist->SetTitle(";MuonID;Events / 12.5E20POT");
64  hist->SetLineColor(int_mode.second);
65  leg->AddEntry(hist, int_mode_titles[int_mode.first].c_str());
66  if (firstplot)
67  {
68  hist->Draw("hist");
69  firstplot = false;
70  }
71  else
72  hist->Draw("hist same");
73  }
74  leg->Draw();
75  c1->SaveAs(outputFile.c_str());
76  infile->Close();
77 }
enum BeamMode kOrange
enum BeamMode kRed
std::unique_ptr< T > LoadFrom(TDirectory *dir, const std::string &label)
Definition: LoadFromFile.h:17
const string weight
BeamMode
string infile
std::vector< float > Spectrum
Definition: Constants.h:728
const double kAna2020RHCPOT
Definition: Exposures.h:235
void plot_muonid_dist(string inputFilename, string mode_str, string outputFile="muonid_dist.pdf")
enum BeamMode kViolet
c1
Definition: demo5.py:24
enum BeamMode kGreen
enum BeamMode kBlue
map< string, string > int_mode_titles_fhc