PlotNus18Sideband.C
Go to the documentation of this file.
1 #ifdef __CINT__
3 {
4  std::cout << "Sorry, you must run in compiled mode" << std::endl;
5 }
6 #else
7 
10 #include "CAFAna/Core/Spectrum.h"
12 #include "OscLib/OscCalcSterile.h"
13 
15 
16 #include "TH1.h"
17 #include "THStack.h"
18 #include "TCanvas.h"
19 #include "TColor.h"
20 #include "TLegend.h"
21 
22 #include <utility>
23 
24 using namespace ana;
25 
27 
28  TH1::AddDirectory(0);
29 
30  // Read in the data objects
31  // IPrediction* pred_genie_e = LoadFromFile<PredictionNoExtrap>(inFile.c_str(), "pred_genie").release();
32  // Spectrum* spec_data_e = LoadFromFile<Spectrum>(inFile.c_str(), "spec_data").release();
33  // Spectrum* spec_cos_e = LoadFromFile<Spectrum>(inFile.c_str(), "spec_cos").release();
34 
35  IPrediction* pred_genie_e = LoadFromFile<PredictionNoExtrap>(inFile.c_str(), "pred_genie_e").release();
36  Spectrum* spec_data_e = LoadFromFile<Spectrum>(inFile.c_str(), "spec_data_e").release();
37  Spectrum* spec_cos_e = LoadFromFile<Spectrum>(inFile.c_str(), "spec_cos_e").release();
38 
39  IPrediction* pred_genie_cvn = LoadFromFile<PredictionNoExtrap>(inFile.c_str(), "pred_genie_cvn").release();
40  Spectrum* spec_data_cvn = LoadFromFile<Spectrum>(inFile.c_str(), "spec_data_cvn").release();
41  Spectrum* spec_cos_cvn = LoadFromFile<Spectrum>(inFile.c_str(), "spec_cos_cvn").release();
42 
43  IPrediction* pred_genie_nhits = LoadFromFile<PredictionNoExtrap>(inFile.c_str(), "pred_genie_nhits").release();
44  Spectrum* spec_data_nhits = LoadFromFile<Spectrum>(inFile.c_str(), "spec_data_nhits").release();
45  Spectrum* spec_cos_nhits = LoadFromFile<Spectrum>(inFile.c_str(), "spec_cos_nhits").release();
46 
47  // Set up output
48  std::string fileName = inFile.substr(0, inFile.find(".root"));
49  std::string saveName = fileName + "_ana.root";
50  TFile* outFile = new TFile(saveName.c_str(), "RECREATE");
51  TCanvas* canv = new TCanvas("canv","",800,600);
52 
53  // Set up oscillation calculator that uses default 3 flavor parameters
55  SetAngles(calc);
56 
57  TH1* hDataE = spec_data_e->ToTH1(spec_data_e->POT());
58  TH1* hSigE = pred_genie_e->PredictComponent(calc, Flavors::kAll, Current::kNC, Sign::kBoth).ToTH1(spec_data_e->POT());
59  TH1* hBeamBgE = pred_genie_e->PredictComponent(calc, Flavors::kAll, Current::kCC, Sign::kBoth).ToTH1(spec_data_e->POT());
60  TH1* hCosE = spec_cos_e->ToTH1(spec_data_e->Livetime(), kLivetime);
61 
62  TH1* hDataCVN = spec_data_cvn->ToTH1(spec_data_cvn->POT());
63  TH1* hSigCVN = pred_genie_cvn->PredictComponent(calc, Flavors::kAll, Current::kNC, Sign::kBoth).ToTH1(spec_data_cvn->POT());
64  TH1* hBeamBgCVN = pred_genie_cvn->PredictComponent(calc, Flavors::kAll, Current::kCC, Sign::kBoth).ToTH1(spec_data_cvn->POT());
65  TH1* hCosCVN = spec_cos_cvn->ToTH1(spec_data_cvn->Livetime(), kLivetime);
66 
67  TH1* hDataNHits = spec_data_nhits->ToTH1(spec_data_nhits->POT());
68  TH1* hSigNHits = pred_genie_nhits->PredictComponent(calc, Flavors::kAll, Current::kNC, Sign::kBoth).ToTH1(spec_data_nhits->POT());
69  TH1* hBeamBgNHits = pred_genie_nhits->PredictComponent(calc, Flavors::kAll, Current::kCC, Sign::kBoth).ToTH1(spec_data_nhits->POT());
70  TH1* hCosNHits = spec_cos_nhits->ToTH1(spec_data_nhits->Livetime(), kLivetime);
71 
72  // Plot everything!
73  TLegend* leg = new TLegend(0.5,0.6,0.88,0.88);
74 
75  // energy
76  std::cout << "Energy:" << std::endl;
77  std::cout << " Data: " << hDataE->Integral() << std::endl;
78  std::cout << " NC: " << hSigE->Integral() << std::endl;
79  std::cout << " Beam background: " << hBeamBgE->Integral() << std::endl;
80  std::cout << " Cosmics: " << hCosE->Integral() << std::endl;
81 
82  hDataE->SetMarkerStyle(8);
83  hDataE->SetMarkerSize(1);
84  hDataE->SetMarkerColor(1);
85  hDataE->SetLineColor(1);
86  hSigE->SetLineColor(kAzure+2);
87  hBeamBgE->SetLineColor(kGreen+2);
88  hCosE->SetLineColor(kOrange+2);
89 
90  leg->Clear();
91  leg->AddEntry(hDataE, "Data", "p");
92  leg->AddEntry(hSigE, "Signal", "l");
93  leg->AddEntry(hBeamBgE, "Beam background", "l");
94  leg->AddEntry(hCosE, "Cosmic background", "l");
95 
96  THStack* stackE = new THStack("stackE", "");
97  stackE->Add(hCosE);
98  stackE->Add(hBeamBgE);
99  stackE->Add(hSigE);
100 
101  canv->cd();
102  canv->Clear();
103  hDataE->Draw();
104  stackE->Draw("hist nostack same");
105  leg->Draw();
106  outFile->cd();
107  canv->Write("SidebandDataMCEnergy");
108 
109  canv->cd();
110  canv->Clear();
111  hSigE->SetFillColor(kAzure+2);
112  hBeamBgE->SetFillColor(kGreen+2);
113  hCosE->SetFillColor(kOrange+2);
114  stackE->SetMaximum(200);
115  stackE->Draw("hist");
116  stackE->GetXaxis()->SetTitle("Energy Deposited (GeV)");
117  hDataE->Draw("same");
118  leg->Draw();
119  outFile->cd();
120  canv->Write("SidebandDataMCEnergyStack");
121 
122  // cvn
123  hDataCVN->SetMarkerStyle(8);
124  hDataCVN->SetMarkerSize(1);
125  hDataCVN->SetMarkerColor(1);
126  hDataCVN->SetLineColor(1);
127  hSigCVN->SetLineColor(kAzure+2);
128  hBeamBgCVN->SetLineColor(kGreen+2);
129  hCosCVN->SetLineColor(kOrange+2);
130 
131  leg->Clear();
132  leg->AddEntry(hDataCVN, "Data", "p");
133  leg->AddEntry(hSigCVN, "Signal", "l");
134  leg->AddEntry(hBeamBgCVN, "Beam background", "l");
135  leg->AddEntry(hCosCVN, "Cosmic background", "l");
136 
137  THStack* stackCVN = new THStack("stackCVN", "");
138  stackCVN->Add(hCosCVN);
139  stackCVN->Add(hBeamBgCVN);
140  stackCVN->Add(hSigCVN);
141 
142  canv->cd();
143  canv->Clear();
144  hDataCVN->Draw();
145  stackCVN->Draw("hist nostack same");
146  leg->Draw();
147  outFile->cd();
148  canv->Write("SidebandDataMCCVN");
149 
150  canv->cd();
151  canv->Clear();
152  hSigCVN->SetFillColor(kAzure+2);
153  hBeamBgCVN->SetFillColor(kGreen+2);
154  hCosCVN->SetFillColor(kOrange+2);
155  stackCVN->SetMaximum(60);
156  stackCVN->Draw("hist");
157  stackCVN->GetXaxis()->SetTitle("CVNnc Identifier");
158  hDataCVN->Draw("same");
159  leg->Draw();
160  outFile->cd();
161  canv->Write("SidebandDataMCCVNncStack");
162 
163  // nhits
164  hDataNHits->SetMarkerStyle(8);
165  hDataNHits->SetMarkerSize(1);
166  hDataNHits->SetMarkerColor(1);
167  hDataNHits->SetLineColor(1);
168  hSigNHits->SetLineColor(kAzure+2);
169  hBeamBgNHits->SetLineColor(kGreen+2);
170  hCosNHits->SetLineColor(kOrange+2);
171 
172  leg->Clear();
173  leg->AddEntry(hDataNHits, "Data", "p");
174  leg->AddEntry(hSigNHits, "Signal", "l");
175  leg->AddEntry(hBeamBgNHits, "Beam background", "l");
176  leg->AddEntry(hCosNHits, "Cosmic background", "l");
177 
178  THStack* stackNHits = new THStack("stackNHits", "");
179  stackNHits->Add(hCosNHits);
180  stackNHits->Add(hBeamBgNHits);
181  stackNHits->Add(hSigNHits);
182 
183  canv->cd();
184  canv->Clear();
185  hDataNHits->Draw();
186  stackNHits->Draw("hist nostack same");
187  leg->Draw();
188  outFile->cd();
189  canv->Write("SidebandDataMCNHits");
190 
191  canv->cd();
192  canv->Clear();
193  hSigNHits->SetFillColor(kAzure+2);
194  hBeamBgNHits->SetFillColor(kGreen+2);
195  hCosNHits->SetFillColor(kOrange+2);
196  stackNHits->SetMaximum(60);
197  stackNHits->Draw("hist");
198  stackNHits->GetXaxis()->SetTitle("Number of Hits");
199  hDataNHits->Draw("same");
200  leg->Draw();
201  outFile->cd();
202  canv->Write("SidebandDataMCNHitsStack");
203 
204  outFile->Close();
205  delete canv;
206  delete outFile;
207 
208  return;
209 
210 }
211 
212 #endif
fileName
Definition: plotROC.py:78
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
virtual Spectrum PredictComponent(osc::IOscCalc *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const =0
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:209
TCanvas * canv
Adapt the PMNS_Sterile calculator to standard interface.
osc::OscCalcDumb calc
void SetAngles(osc::OscCalcSterile *calc)
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:33
ifstream inFile
Definition: AnaPlotMaker.h:34
Charged-current interactions.
Definition: IPrediction.h:39
osc::OscCalcSterile * DefaultSterileCalc(int nflavors)
Create a sterile calculator with default assumptions for all parameters.
Definition: Calcs.cxx:97
TFile * outFile
Definition: PlotXSec.C:135
void PlotNus18Sideband(std::string inFile)
double POT() const
Definition: Spectrum.h:231
OStream cout
Definition: OStream.cxx:6
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
Neutral-current interactions.
Definition: IPrediction.h:40
Both neutrinos and antineutrinos.
Definition: IPrediction.h:52
Standard interface to all prediction techniques.
Definition: IPrediction.h:57
All neutrinos, any flavor.
Definition: IPrediction.h:26
double Livetime() const
Seconds. For informational purposes only. No calculations use this.
Definition: Spectrum.h:234