plot_nd_data_mc.C
Go to the documentation of this file.
4 #include "CAFAna/Core/Ratio.h"
6 #include "CAFAna/Core/Spectrum.h"
7 #include "CAFAna/Vars/Vars.h"
9 using namespace ana;
10 
12 
13 #include "nd_vars_and_cuts.h"
14 
15 #include "TCanvas.h"
16 #include "TFile.h"
17 #include "TH1.h"
18 #include "TLegend.h"
19 #include "TPad.h"
20 
21 void Legend(double x0, double y0, double x1, double y1)
22 {
23  // Doesn't handle log-y well
24  // TLegend* leg = AutoPlaceLegend(x1-x0, y1-y0);
25  TLegend* leg = new TLegend(x0, y0, x1, y1);
26  leg->SetFillStyle(0);
27 
28  TH1* dummy = new TH1F("", "", 1, 0, 1);
29  dummy->SetMarkerStyle(kFullCircle);
30 
31  leg->AddEntry(dummy->Clone(), "ND data", "lep");
32  dummy->SetLineColor(kGray+2);
33  dummy->SetMarkerColor(kGray+2);
34  // leg->AddEntry(dummy->Clone(), "ND data stagger", "lep");
35  dummy->SetLineColor(kTotalMCColor);
36  leg->AddEntry(dummy->Clone(), "Total MC", "l");
37  dummy->SetLineColor(kNCBackgroundColor);
38  leg->AddEntry(dummy->Clone(), "NC", "l");
39  dummy->SetLineColor(kBeamNueBackgroundColor);
40  leg->AddEntry(dummy->Clone(), "Beam #nu_{e} CC", "l");
41  dummy->SetLineColor(kNumuBackgroundColor);
42  leg->AddEntry(dummy->Clone(), "#nu_{#mu} CC", "l");
43 
44  leg->Draw();
45 }
46 
48 {
50  Spectrum* spectsStagger[kNumSels][kNumVars];
51  IPrediction* preds[kNumSels][kNumVars];
52 
54 
55  for(int selIdx = 0; selIdx < kNumSels; ++selIdx){
56  const char* selName = sels[selIdx].name.c_str();
57  for(int varIdx = 0; varIdx < kNumVars; ++varIdx){
58  const char* varName = defs[varIdx].name.c_str();
59 
60  spects[selIdx][varIdx] = LoadFromFile<Spectrum>(fname, TString::Format("%s/spect_%s", selName, varName).Data()).release();
61  spectsStagger[selIdx][varIdx] = LoadFromFile<Spectrum>(fname, TString::Format("%s/spect_%s_stagger", selName, varName).Data()).release();
62  preds[selIdx][varIdx] = LoadFromFile<IPrediction>(fname, TString::Format("%s/pred_%s", selName, varName).Data()).release();
63 
64  if(selIdx == 0 && varIdx == 0)
65  std::cout << "data, MC POT: "
66  << spects[selIdx][varIdx]->POT() << " "
67  << preds[selIdx][varIdx]->Predict(&noosc).POT() << std::endl;
68 
69 
70  if(defs[varIdx].name == "confuse" && selIdx == 1){
71  const double pot = spects[selIdx][varIdx]->POT();
72  TH1* hd = spects[selIdx][varIdx]->ToTH1(pot);
73  TH1* hm = preds[selIdx][varIdx]->Predict(&noosc).ToTH1(pot);
74  std::cout << "Neither, LID, LEM, both" << std::endl;
75  std::cout << "DATA: " << hd->GetBinContent(1) << " " << hd->GetBinContent(2) << " " << hd->GetBinContent(3) << " " << hd->GetBinContent(4) << " " << std::endl;
76  std::cout << "MC: " << hm->GetBinContent(1) << " " << hm->GetBinContent(2) << " " << hm->GetBinContent(3) << " " << hm->GetBinContent(4) << " " << std::endl;
77  }
78  } // end for varIdx
79  } // end for selIdx
80 
81  for(int selIdx = 0; selIdx < kNumSels; ++selIdx){
82  const std::string selName = sels[selIdx].name;
83  for(int varIdx = 0; varIdx < kNumVars; ++varIdx){
84  const std::string varName = defs[varIdx].name;
85 
86  new TCanvas;
87 
88  Spectrum* spect = spects[selIdx][varIdx];
89  Spectrum* spectStagger = spectsStagger[selIdx][varIdx];
90  IPrediction* pred = preds[selIdx][varIdx];
91 
92  TH1* h = DataMCComparisonComponents(*spect, pred, &noosc);
93  h->SetTitle("NO#nuA Near Detector");
94  h->GetXaxis()->CenterTitle();
95  h->GetYaxis()->CenterTitle();
96 
97  TH1* hstag = spectStagger->ToTH1(spect->POT());
98  hstag->SetMarkerStyle(kFullCircle);
99  hstag->SetMarkerColor(kGray+2);
100  hstag->SetLineColor(kGray+2);
101  // hstag->Draw("ep same");
102 
103  TH1* horig = spect->ToTH1(spect->POT());
104  horig->SetMarkerStyle(kFullCircle);
105  horig->Draw("ep same");
106 
107 
108  Legend(.6, .6, .85, .85);
109 
110  gPad->Print(("plots/"+selName+"_"+varName+"_lin.eps").c_str());
111 
112 
113  h = DataMCComparisonComponents(*spect, pred, &noosc);
114  h->SetTitle("NO#nuA Near Detector");
115  h->GetXaxis()->CenterTitle();
116  h->GetYaxis()->CenterTitle();
117 
118  hstag->Draw("ep same");
119  horig->Draw("ep same");
120 
121  gPad->SetLogy();
122 
123  Legend(.6, .6, .85, .85);
124 
125  gPad->Print(("plots/"+selName+"_"+varName+"_log.eps").c_str());
126 
127 
128  new TCanvas;
129 
130  DataMCRatio(*spect, pred, &noosc);
131 
132  gPad->Print(("plots/"+selName+"_"+varName+"_ratio.eps").c_str());
133 
134 
135  TCanvas* c = new TCanvas;
136 
137  TPad* p1 = new TPad("", "", 0, 0, 1, 1);
138  TPad* p2 = new TPad("", "", 0, 0, 1, 1);
139  p1->SetBottomMargin(.3);
140  p2->SetTopMargin(.7);
141  p1->SetFillStyle(0);
142  p2->SetFillStyle(0);
143  p1->Draw();
144  p2->Draw();
145 
146  p1->cd();
147  h = DataMCComparisonComponents(*spect, pred, &noosc);
148  h->SetTitle("NO#nuA Near Detector");
149  h->GetXaxis()->CenterTitle();
150  h->GetYaxis()->CenterTitle();
151  hstag->Draw("ep same");
152  horig->Draw("ep same");
153  Legend(.6, .6, .85, .85);
154 
155  p2->cd();
156  DataMCRatio(*spect, pred, &noosc, 0, 2.99);
157  Ratio ratioStagger(*spectStagger, pred->PredictUnoscillated());
158  TH1* hratio = ratioStagger.ToTH1();
159  hratio->SetLineColor(kGray+2);
160  // hratio->Draw("e same");
161 
162  c->cd();
163 
164  gPad->Print(("plots/"+selName+"_"+varName+"_lin_ratio.eps").c_str());
165 
166  p1->cd();
167  h = DataMCComparisonComponents(*spect, pred, &noosc);
168  h->SetTitle("NO#nuA Near Detector");
169  h->GetXaxis()->CenterTitle();
170  h->GetYaxis()->CenterTitle();
171  // hstag->Draw("ep same");
172  horig->Draw("ep same");
173  gPad->SetLogy();
174  Legend(.6, .6, .85, .85);
175  c->cd();
176  gPad->Print(("plots/"+selName+"_"+varName+"_log_ratio.eps").c_str());
177  } // end for varIdx
178  } // end for selIdx
179 }
const XML_Char * name
Definition: expat.h:151
Pass neutrinos through unchanged.
const int kNumVars
Definition: vars.h:14
Oscillation analysis framework, runs over CAF files outside of ART.
TH1D * ToTH1(Color_t col=kBlack, Style_t style=kSolid) const
Definition: Ratio.cxx:122
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:553
TH1 * DataMCComparisonComponents(const Spectrum &data, const IPrediction *mc, osc::IOscCalculator *calc)
Plot MC broken down into flavour components, overlayed with data.
Definition: Plots.cxx:113
void DataMCRatio(const Spectrum &data, const IPrediction *mc, osc::IOscCalculator *calc, double miny, double maxy)
Plot data/MC ratio for the given spectrum. Normalize MC to Data by POT.
Definition: Plots.cxx:166
Float_t x1[n_points_granero]
Definition: compare.C:5
void plot_nd_data_mc(std::string fname)
void Legend(double x0, double y0, double x1, double y1)
virtual Spectrum PredictUnoscillated() const
Definition: IPrediction.cxx:82
const Color_t kNumuBackgroundColor
Definition: Style.h:31
virtual Spectrum Predict(osc::IOscCalculator *calc) const =0
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:37
const Cut sels[kNumSels]
Definition: vars.h:44
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:263
Represent the ratio between two spectra.
Definition: Ratio.h:8
std::string name
Definition: NuePlotLists.h:12
OStream cout
Definition: OStream.cxx:6
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
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:17
void spects(osc::IOscCalculatorAdjustable *calc, IPrediction *predFHC, IPrediction *predRHC)
Definition: sensitivity.C:100
const Color_t kNCBackgroundColor
Definition: Style.h:22
TH1F * hd
Definition: Xdiff_gwt.C:57
h
Definition: demo3.py:41