meanWeight_plot.C
Go to the documentation of this file.
1 #include "CAFAna/Core/Spectrum.h"
2 
3 #include "TCanvas.h"
4 #include "TH2.h"
5 #include "TH1.h"
6 #include "TLegend.h"
7 #include "TGraph.h"
8 #include "TFile.h"
9 #include "TStyle.h"
10 
11 #include <iostream>
12 #include <algorithm>
13 #include <vector>
14 #include <string>
15 
16 //#include "Utilities/plotting.h"
17 
18 
19 using namespace ana;
20 
22 {
23 
24  std::string mode = "g4";
25 
26 
28 
29  if(mode == "nofid_g4" || mode == "g4" ){
30  x_title = "Piplus universe mean weight";
31  }
32  else if(mode == "nofid_ppfx" || mode == "ppfx" ){
33  x_title = "PPFX universe mean weight";
34  }
35 
36 
38 
39  if(mode == "nofid_g4" || mode == "g4" ){
40  title = "GEANT4";
41  }
42  else if(mode == "nofid_ppfx" || mode == "ppfx" ){
43  title = "PPFX";
44  }
45 
46 
47 
48  //std::string inName = mode + "_meanWeights.root";
49  std::string inName = "meanWeights.root";
50 
51 
52  //TFile inFile(inName.c_str());
53  TFile *inFile = new TFile(inName.c_str(), "READ");
54 
55 
56  std::string outDir = "./plots/mean_weights/";
57 
58 
59  gStyle->SetOptStat(2200);
60  gStyle->SetStatX(0.8);
61  gStyle->SetStatY(0.8);
62 
63 
64  TH1F *hMeans = new TH1F("hMeans", title.c_str(), 40, 0.2, 1.8);
65  TH1F *hRMSs = new TH1F("hRMSs", title.c_str(), 40, 0.2, 1.8);
66 
67  for(uint i=0; i < 100; ++i){
68 
69  std::string spec_dir = "dir_Univ_" + std::to_string(i);
70  const std::unique_ptr<Spectrum> & sWeights = Spectrum::LoadFrom(inFile, spec_dir.c_str() );
71 
72 
73  const double pot = sWeights->POT();
74  //const double pot = 8.09e20;
75 
76 
77  TH1D *hWeights = (TH1D*) sWeights->ToTH1(pot);
78  hWeights->StatOverflows(kFALSE);
79 
80  std::string plot_title = "univ_" + std::to_string(i);
81 
82  TCanvas *canv = new TCanvas("canv", "canv", 800, 600);
83  hWeights->GetYaxis()->SetTitle("Events");
84  hWeights->GetXaxis()->SetTitle(x_title.c_str());
85  hWeights->SetTitle( plot_title.c_str() );
86 
87  hWeights->Draw("hist");
88 
89  int nEntries = hWeights->GetEntries();
90  std::cout << nEntries << std::endl;
91 
92  canv->SaveAs( (outDir + plot_title + ".png").c_str() );
93 
94  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95 
96 
97  std::string spec_overflow_dir = "dir_Univ_overflow_" + std::to_string(i);
98  const std::unique_ptr<Spectrum> & sWeights_overflow = Spectrum::LoadFrom(inFile, spec_overflow_dir.c_str() );
99 
100  TH1D *hWeights_overflow = (TH1D*) sWeights_overflow->ToTH1(pot);
101  //hWeights_overflow->StatOverflows(kTRUE); No longer want this as we move weight == 1 to -5
102 
103 
104  std::string plot_overflow_title = "univ_" + std::to_string(i) + "_overflow";
105 
106  TCanvas *canv_overflow = new TCanvas("canv_overflow", "canv_overflow", 800, 600);
107  hWeights_overflow->GetYaxis()->SetTitle("Events");
108  hWeights_overflow->GetXaxis()->SetTitle(x_title.c_str());
109  hWeights_overflow->SetTitle( plot_overflow_title.c_str() );
110 
111  hWeights_overflow->Draw("hist");
112 
113  double mean = hWeights_overflow->GetMean();
114  hMeans->Fill(mean);
115  hMeans->GetXaxis()->SetTitle(x_title.c_str());
116  hMeans->GetYaxis()->SetTitle("nUniv");
117 
118  double rms = hWeights_overflow->GetRMS();
119  hRMSs->Fill(rms);
120  hRMSs->GetXaxis()->SetTitle(x_title.c_str());
121  hRMSs->GetYaxis()->SetTitle("nUniv");
122 
123  canv_overflow->SaveAs( (outDir + plot_overflow_title + ".png").c_str() );
124 
125  /*
126  if(mean > 1.2){
127  std::cout << "********************" << std::endl;
128  std::cout << "********************" << std::endl;
129  std::cout << "********************" << std::endl;
130  std::cout << "********************" << std::endl;
131  std::cout << "********************" << std::endl;
132  std::cout << i << std::endl;
133  }
134  */
135 
136  }
137 
138  TCanvas *canv_mean = new TCanvas("canv_mean", "canv_mean", 800, 600);
139  hMeans->Draw("hist");
140  canv_mean->SaveAs( (outDir + mode + "_mean.png").c_str() );
141 
142  TCanvas *canv_rms = new TCanvas("canv_rms", "canv_rms", 800, 600);
143  hRMSs->Draw("hist");
144  canv_rms->SaveAs( (outDir + mode + "_rms.png").c_str() );
145 
146 }
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
TCanvas * canv
std::string outDir
ifstream inFile
Definition: AnaPlotMaker.h:34
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Spectrum.cxx:535
void meanWeight_plot()
#define pot
OStream cout
Definition: OStream.cxx:6
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
enum BeamMode string
unsigned int uint