plot_pid.C
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////
2 //
3 // Script to plot data/mc comparisons for prong CVN with
4 // different cuts.
5 //
6 //////////////////////////////////////////////////////////
7 
8 #include <sstream>
9 #include <iomanip>
10 #include <fstream>
11 
12 #include "TCanvas.h"
13 #include "TH1.h"
14 #include "TF1.h"
15 #include "TFile.h"
16 #include "TLegend.h"
17 #include "TLegendEntry.h"
18 #include "TArrayD.h"
19 #include "TAxis.h"
20 #include "TLatex.h"
21 #include "TStyle.h"
22 #include "THStack.h"
23 
24 #include "CAFAna/Core/Cut.h"
26 #include "CAFAna/Cuts/NueCutsFirstAna.h"
28 #include "CAFAna/Analysis/Plots.h"
29 #include "CAFAna/Analysis/Style.h"
31 #include "CAFAna/Core/Spectrum.h"
32 #include "CAFAna/Cuts/SpillCuts.h"
33 #include "CAFAna/Vars/Vars.h"
35 
37 
39 
40 using namespace ana;
41 
42 void HCtag(TString tag,double pot)
43 {
44 
45  std::stringstream out;
46  out << std::setprecision(3);
47  out << pot;
48 
49  std::string potstr = out.str();
50  std::string coef = out.str().substr(0,4);
51  std::string power = out.str().substr(6,2);
52  potstr = coef+"x10^{"+power+"}";
53 
54  TLatex* tex = new TLatex(.625, .85, "#scale[0.8]{"+potstr+" POT-equiv "+tag+"}");
55  //if ( tag == "FHC") tex->SetTextColor(kPink+3);
56  //if ( tag == "RHC") tex->SetTextColor(kAzure+3);
57  tex->SetNDC();
58  tex->SetTextSize(0.043);
59  tex->SetTextFont(42);
60  tex->SetTextAlign(12);
61  tex->Draw();
62 }
63 
65  std::stringstream out;
66  out << std::setprecision(3);
67  out << value;
68  return out.str();
69 }
70 
72 {
73  TLatex* prelim = new TLatex(.9, .95, "NOvA Preliminary");
74  prelim->SetTextColor(kAzure);
75  prelim->SetNDC();
76  prelim->SetTextSize(2/30.);
77  prelim->SetTextAlign(32);
78  prelim->Draw();
79 }
80 
81 void plot_pid(const std::string inFile,bool isFHC = 1){
82 
83  const std::string cStr = isFHC ? "FHC" : "RHC";
84 
85  Spectrum* spects[kNSels][kNPlots];
86 
87  for(unsigned int i = 0;i < kNSels;++i){
88  for(unsigned int j = 0;j < kNPlots;++j){
89  spects[i][j] = LoadFromFile<Spectrum>(inFile,(sels[i].suffix+"_"
90  +plots[j].suffix).c_str()).release();
91  }
92  }
93 
94  // Get spectra from file
95 
96  TFile fout(("plot_pid_output_"+cStr+".root").c_str(),"RECREATE");
97 
98  for ( unsigned int i = 0 ; i < kNSels ; ++i ){
99  for ( unsigned int j = 0 ; j < 5 ; ++j ){
100 
101  std::string theSuffix = sels[i].suffix+"_"+plots[j].suffix;
102  TCanvas *c = new TCanvas(theSuffix.c_str(),theSuffix.c_str());
103  TH1* h[kNPlots];
104 
105  h[j] = spects[i][j]->ToTH1(spects[i][j]->POT());
106 
107  THStack *hs = new THStack("hs","");
108  for ( int k = j+5;k < kNPlots;k = k+5 ){
109  h[k] = spects[i][k]->ToTH1(spects[i][j]->POT());
110  hs->Add(h[k]);
111  }
112 
113  h[j]->SetMarkerStyle(kFullCircle);
114  h[j+5]->SetLineColor(PDGcolor["Electron"]);
115  h[j+10]->SetLineColor(PDGcolor["Muon"]);
116  h[j+15]->SetLineColor(PDGcolor["Gamma"]);
117  h[j+20]->SetLineColor(PDGcolor["Pion"]);
118  h[j+25]->SetLineColor(PDGcolor["Proton"]);
119 
120  for(int k = j+5;k < kNPlots;k = k+5) FillWithDimColor(h[k]);
121 
122  hs->Draw("hist");
123  h[j]->Draw("ep same");
124 
125  hs->GetYaxis()->SetTitle(("Prongs / "+ToString(h[i]->GetBinWidth(1))+" PID").c_str());
126  hs->GetXaxis()->SetTitle(plots[j].label.c_str());
127  hs->GetXaxis()->CenterTitle();
128  hs->GetYaxis()->CenterTitle();
129 
130  HCtag(cStr,spects[i][j]->POT());
131  Preliminary();
132 
133  hs->SetMaximum(1.05*h[j]->GetMaximum());
134 
135  gPad->Modified();
136  gPad->RedrawAxis();
137  gPad->Update();
138 
139  TLegend *l = new TLegend(0.35,0.5,0.7,0.8);
140  l->AddEntry(h[j],"Data","lpe");
141  l->AddEntry(h[j+25],"True Proton","f");
142  l->AddEntry(h[j+20],"True Pion","f");
143  l->AddEntry(h[j+15],"True Photon","f");
144  l->AddEntry(h[j+10],"True Muon","f");
145  l->AddEntry(h[j+5],"True Electron","f");
146  l->Draw("same");
147 
148  fout.cd();
149  c->Write();
150  c->Print(("pidPlot_"+cStr+"_"+sels[i].suffix+"_"+plots[j].suffix+".root").c_str());
151  c->Print(("pidPlot_"+cStr+"_"+sels[i].suffix+"_"+plots[j].suffix+".pdf").c_str());
152  gPad->SetLogy();
153  c->Print(("pidPlot_"+cStr+"_"+sels[i].suffix+"_"+plots[j].suffix+"_log.pdf").c_str());
154  }
155  }
156 }
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
TH1D * ToTH1(double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Histogram made from this Spectrum, scaled to some exposure.
Definition: Spectrum.cxx:148
const unsigned int kNSels
const unsigned int kNPlots
void plot_pid(const std::string inFile, bool isFHC=1)
Definition: plot_pid.C:81
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const char * label
ifstream inFile
Definition: AnaPlotMaker.h:34
void Preliminary()
Definition: plot_pid.C:71
const XML_Char int const XML_Char * value
Definition: expat.h:331
std::map< std::string, Color_t > PDGcolor
Definition: make_pid.h:76
const Cut sels[kNumSels]
Definition: vars.h:44
const std::vector< Plot > plots
#define pot
const double j
Definition: BetheBloch.cxx:29
TLatex * prelim
Definition: Xsec_final.C:133
static bool isFHC
std::vector< double > POT
std::string ToString(double value)
Definition: plot_pid.C:64
TLatex * tex
Definition: f2_nu.C:499
void HCtag(TString tag, double pot)
Definition: plot_pid.C:42
void FillWithDimColor(TH1 *h, bool usealpha, float dim)
enum BeamMode string