plot_nue_data_mc.C
Go to the documentation of this file.
1 #ifdef __CINT__
3 #else
4 
8 #include "CAFAna/Core/Ratio.h"
10 #include "CAFAna/Core/Spectrum.h"
11 #include "CAFAna/Vars/Vars.h"
12 #include "CAFAna/Analysis/Style.h"
13 using namespace ana;
14 
15 #include "OscLib/func/IOscCalculator.h"
16 
17 #include "TCanvas.h"
18 #include "TFile.h"
19 #include "TH1.h"
20 #include "TLegend.h"
21 #include "TPad.h"
22 
23 void Legend(double x0, double y0, double x1, double y1)
24 {
25  // Doesn't handle log-y well
26  // TLegend* leg = AutoPlaceLegend(x1-x0, y1-y0);
27  TLegend* leg = new TLegend(x0, y0, x1, y1);
28  leg->SetFillStyle(0);
29 
30  TH1* dummy = new TH1F("", "", 1, 0, 1);
31  dummy->SetMarkerStyle(kFullCircle);
32 
33  leg->AddEntry(dummy->Clone(), "ND data", "lep");
34  dummy->SetLineColor(kGray+2);
35  dummy->SetMarkerColor(kGray+2);
36  // leg->AddEntry(dummy->Clone(), "ND data stagger", "lep");
37  dummy->SetLineColor(kTotalMCColor);
38  leg->AddEntry(dummy->Clone(), "Total MC", "l");
39  dummy->SetLineColor(kNCBackgroundColor);
40  leg->AddEntry(dummy->Clone(), "NC", "l");
41  dummy->SetLineColor(kBeamNueBackgroundColor);
42  leg->AddEntry(dummy->Clone(), "Beam #nu_{e} CC", "l");
43  dummy->SetLineColor(kNumuBackgroundColor);
44  leg->AddEntry(dummy->Clone(), "#nu_{#mu} CC", "l");
45 
46  leg->Draw();
47 }
48 
50 {
51  struct HistDef
52  {
54  };
55 
56  // TODO definitely share. Merge macros?
57  const int kNumVars = 52;
58  const HistDef defs[kNumVars] = {
59  "lem",
60  "lem_zoom",
61  "nhits",
62  "lem_pidexp",
63  "lem_meany",
64  "lem_qfrac",
65  "lem_ediff",
66  "lem_enrich",
67  "calE",
68  "nvtx",
69  "vtxx",
70  "vtxy",
71  "vtxz",
72 
73  "nshw",
74  "shwstartx",
75  "shwstarty",
76  "shwstartz",
77  "shwstopx",
78  "shwstopy",
79  "shwstopz",
80  "longprong",
81  "e_per_hit",
82  "shw_nhit",
83  "shw_len",
84  "shw_width",
85  "shw_gap",
86  "shw_efrac",
87 
88  "shw_e",
89  "had_e",
90 
91  "ptp",
92  "costheta",
93  "hits_per_plane",
94  "pi0mass",
95 
96  "lid",
97  "lid_zoom",
98 
99  "mulll",
100  "elll",
101  "emulll",
102  "eglll",
103  "eplll",
104  "enlll",
105  "epilll",
106  "epi0lll",
107 
108  "mullt",
109  "ellt",
110  "emullt",
111  "egllt",
112  "epllt",
113  "enllt",
114  "epillt",
115  "epi0llt",
116 
117  "confuse"
118  };
119 
120  const int kNumSels = 4;
121  const std::string selNames[kNumSels] = {"nocut", "presel", "lem", "lid"};
122 
123  Spectrum* spects[kNumSels][kNumVars];
124  Spectrum* spectsStagger[kNumSels][kNumVars];
125  IPrediction* preds[kNumSels][kNumVars];
126 
128 
129  for(int selIdx = 0; selIdx < kNumSels; ++selIdx){
130  const char* selName = selNames[selIdx].c_str();
131  for(int varIdx = 0; varIdx < kNumVars; ++varIdx){
132  const char* varName = defs[varIdx].name.c_str();
133 
134  spects[selIdx][varIdx] = LoadFromFile<Spectrum>(fname, TString::Format("%s/spect_%s", selName, varName).Data()).release();
135  spectsStagger[selIdx][varIdx] = LoadFromFile<Spectrum>(fname, TString::Format("%s/spect_%s_stagger", selName, varName).Data()).release();
136  preds[selIdx][varIdx] = LoadFromFile<IPrediction>(fname, TString::Format("%s/pred_%s", selName, varName).Data()).release();
137 
138  if(selIdx == 0 && varIdx == 0)
139  std::cout << "data, MC POT: "
140  << spects[selIdx][varIdx]->POT() << " "
141  << preds[selIdx][varIdx]->Predict(&noosc).POT() << std::endl;
142 
143 
144  if(defs[varIdx].name == "confuse" && selIdx == 1){
145  const double pot = spects[selIdx][varIdx]->POT();
146  TH1* hd = spects[selIdx][varIdx]->ToTH1(pot);
147  TH1* hm = preds[selIdx][varIdx]->Predict(&noosc).ToTH1(pot);
148  std::cout << "Neither, LID, LEM, both" << std::endl;
149  std::cout << "DATA: " << hd->GetBinContent(1) << " " << hd->GetBinContent(2) << " " << hd->GetBinContent(3) << " " << hd->GetBinContent(4) << " " << std::endl;
150  std::cout << "MC: " << hm->GetBinContent(1) << " " << hm->GetBinContent(2) << " " << hm->GetBinContent(3) << " " << hm->GetBinContent(4) << " " << std::endl;
151  }
152  } // end for varIdx
153  } // end for selIdx
154 
155  for(int selIdx = 0; selIdx < kNumSels; ++selIdx){
156  const std::string selName = selNames[selIdx];
157  for(int varIdx = 0; varIdx < kNumVars; ++varIdx){
158  const std::string varName = defs[varIdx].name;
159 
160  new TCanvas;
161 
162  Spectrum* spect = spects[selIdx][varIdx];
163  Spectrum* spectStagger = spectsStagger[selIdx][varIdx];
164  IPrediction* pred = preds[selIdx][varIdx];
165 
166  TH1* h = DataMCComparisonComponents(*spect, pred, &noosc);
167  h->SetTitle("NO#nuA Near Detector");
168  h->GetXaxis()->CenterTitle();
169  h->GetYaxis()->CenterTitle();
170 
171  TH1* hstag = spectStagger->ToTH1(spect->POT());
172  hstag->SetMarkerStyle(kFullCircle);
173  hstag->SetMarkerColor(kGray+2);
174  hstag->SetLineColor(kGray+2);
175  // hstag->Draw("ep same");
176 
177  TH1* horig = spect->ToTH1(spect->POT());
178  horig->SetMarkerStyle(kFullCircle);
179  horig->Draw("ep same");
180 
181 
182  Legend(.6, .6, .85, .85);
183 
184  gPad->Print(("plots/"+selName+"_"+varName+"_lin.eps").c_str());
185 
186 
187  h = DataMCComparisonComponents(*spect, pred, &noosc);
188  h->SetTitle("NO#nuA Near Detector");
189  h->GetXaxis()->CenterTitle();
190  h->GetYaxis()->CenterTitle();
191 
192  hstag->Draw("ep same");
193  horig->Draw("ep same");
194 
195  gPad->SetLogy();
196 
197  Legend(.6, .6, .85, .85);
198 
199  gPad->Print(("plots/"+selName+"_"+varName+"_log.eps").c_str());
200 
201 
202  new TCanvas;
203 
204  DataMCRatio(*spect, pred, &noosc);
205 
206  gPad->Print(("plots/"+selName+"_"+varName+"_ratio.eps").c_str());
207 
208 
209  TCanvas* c = new TCanvas;
210 
211  TPad* p1 = new TPad("", "", 0, 0, 1, 1);
212  TPad* p2 = new TPad("", "", 0, 0, 1, 1);
213  p1->SetBottomMargin(.3);
214  p2->SetTopMargin(.7);
215  p1->SetFillStyle(0);
216  p2->SetFillStyle(0);
217  p1->Draw();
218  p2->Draw();
219 
220  p1->cd();
221  h = DataMCComparisonComponents(*spect, pred, &noosc);
222  h->SetTitle("NO#nuA Near Detector");
223  h->GetXaxis()->CenterTitle();
224  h->GetYaxis()->CenterTitle();
225  hstag->Draw("ep same");
226  horig->Draw("ep same");
227  Legend(.6, .6, .85, .85);
228 
229  p2->cd();
230  DataMCRatio(*spect, pred, &noosc, 0, 2.99);
231  Ratio ratioStagger(*spectStagger, pred->PredictUnoscillated());
232  TH1* hratio = ratioStagger.ToTH1();
233  hratio->SetLineColor(kGray+2);
234  // hratio->Draw("e same");
235 
236  c->cd();
237 
238  gPad->Print(("plots/"+selName+"_"+varName+"_lin_ratio.eps").c_str());
239 
240  p1->cd();
241  h = DataMCComparisonComponents(*spect, pred, &noosc);
242  h->SetTitle("NO#nuA Near Detector");
243  h->GetXaxis()->CenterTitle();
244  h->GetYaxis()->CenterTitle();
245  // hstag->Draw("ep same");
246  horig->Draw("ep same");
247  gPad->SetLogy();
248  Legend(.6, .6, .85, .85);
249  c->cd();
250  gPad->Print(("plots/"+selName+"_"+varName+"_log_ratio.eps").c_str());
251  } // end for varIdx
252  } // end for selIdx
253 }
254 
255 #endif
void Legend(double x0, double y0, double x1, double y1)
const XML_Char * name
Definition: expat.h:151
Pass neutrinos through unchanged.
Definition: IOscCalc.h:45
void DataMCRatio(const Spectrum &data, const IPrediction *mc, osc::IOscCalc *calc, double miny, double maxy)
Plot data/MC ratio for the given spectrum. Normalize MC to Data by POT.
Definition: Plots.cxx:167
const int kNumVars
Definition: vars.h:14
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
TH1D * ToTH1(Color_t col=kBlack, Style_t style=kSolid) const
Definition: Ratio.cxx:67
Float_t y1[n_points_granero]
Definition: compare.C:5
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
virtual Spectrum Predict(osc::IOscCalc *calc) const =0
Float_t x1[n_points_granero]
Definition: compare.C:5
std::string name
Definition: NuePlotLists.h:12
virtual Spectrum PredictUnoscillated() const
Definition: IPrediction.cxx:33
const Color_t kNumuBackgroundColor
Definition: Style.h:30
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const Color_t kBeamNueBackgroundColor
Definition: Style.h:24
#define pot
const HistDef defs[kNumVars]
Definition: vars.h:15
const int kNumSels
Definition: vars.h:43
osc::NoOscillations noosc
Definition: NueSystFuncs.h:44
double POT() const
Definition: Spectrum.h:227
Represent the ratio between two spectra.
Definition: Ratio.h:8
OStream cout
Definition: OStream.cxx:6
TH1 * DataMCComparisonComponents(const Spectrum &data, const IPrediction *mc, osc::IOscCalc *calc)
Plot MC broken down into flavour components, overlayed with data.
Definition: Plots.cxx:114
void plot_nd_data_mc(std::string fname)
Standard interface to all prediction techniques.
Definition: IPrediction.h:57
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
const Color_t kTotalMCColor
Definition: Style.h:16
const std::string selNames[kNumSels]
Definition: vars.h:46
const Color_t kNCBackgroundColor
Definition: Style.h:22
TH1F * hd
Definition: Xdiff_gwt.C:57
enum BeamMode string