PrintCosmicBackground.C
Go to the documentation of this file.
1 #include "../../Analysis/Exposures.h"
2 
4 
5  TH1::SetDefaultSumw2();
6 
7  // Out file
8  TFile fout("nus18_cosmic_background.root", "recreate");
9 
10  // Set livetimes for each period
11  std::map<std::string,float> livetime;
12  livetime["1"] = ana::kSecondAnaPeriod1Livetime;
13  livetime["2"] = ana::kSecondAnaPeriod2Livetime;
14  livetime["3"] = ana::kSecondAnaPeriod3Livetime
16  livetime["4"] = ana::kAna2018Period4Livetime;
17  livetime["5"] = ana::kAna2017Period5Livetime;
18  livetime["6"] = ana::kAna2018Period6Livetime;
19  livetime["7"] = ana::kAna2018Period7Livetime;
20 
21  // Set the runs for each polarity
22  std::vector<std::string> fhcPeriods = {"1", "2", "3", "5"};
23  std::vector<std::string> rhcPeriods = {"4", "6", "7"};
24 
25  // Base dir
26  TString dir = "/pnfs/nova/scratch/users/wallbank/nc_sterile_rhc/CosBackgrounds/";
27 
28  // Output
29  std::map<std::string, TH1*> hnumi, hcos, hnumilive, hcoslive;
30  std::map<std::string, float> cosev, numiev;
31 
32  // Look through each period separately
33  for (std::map<std::string,float>::const_iterator pIt = livetime.begin(); pIt != livetime.end(); ++pIt) {
34 
35  const std::string p = pIt->first;
36  std::cout << "Period " << p << ": " << std::endl;
37 
38  TFile pFile(dir+"p"+p+"/p"+p+"_cosmic_hists.root", "read");
39 
40  hnumi[p] = (TH1*)pFile.Get("NuminusE");
41  hcos[p] = (TH1*)pFile.Get("CosnusE");
42  hnumilive[p] = (TH1*)pFile.Get("livetimenumi");
43  hcoslive[p] = (TH1*)pFile.Get("livetimecos");
44  hnumi[p] ->SetDirectory(0);
45  hcos[p] ->SetDirectory(0);
46  hnumilive[p]->SetDirectory(0);
47  hcoslive[p] ->SetDirectory(0);
48 
49  cosev[p] = hcos[p] ->Integral()*pIt->second/hcoslive[p]->GetBinContent(1);
50  numiev[p] = hnumi[p]->Integral()*pIt->second/hnumilive[p]->GetBinContent(1);
51 
52  std::cout << "All: cos: " << cosev[p] << " +- " << cosev[p]/sqrt(hcos[p]->Integral()) << std::endl;
53  std::cout << "All: numi: " << numiev[p] << " +- " << numiev[p]/sqrt(hnumi[p]->Integral()) << std::endl;
54 
55  }
56 
57  // FHC
58  TH1* hfhcnumi = (TH1*)hnumi[*fhcPeriods.begin()]->Clone("fhcnumi");
59  TH1* hfhccos = (TH1*)hcos[*fhcPeriods.begin()]->Clone("fhccos");
60  hfhcnumi->Reset();
61  hfhccos->Reset();
62 
63  for (std::vector<std::string>::const_iterator pIt = fhcPeriods.begin(); pIt != fhcPeriods.end(); ++pIt) {
64 
65  TH1* houtnumi = (TH1*)hnumi[*pIt]->Clone(TString("houtnumi")+TString(*pIt));
66  TH1* houtcos = (TH1*)hcos[*pIt]->Clone(TString("houtcos")+TString(*pIt));
67 
68  houtnumi->Scale((numiev[*pIt])/houtnumi->Integral());
69  houtcos->Scale((cosev[*pIt])/houtcos->Integral());
70 
71  fout.cd();
72  houtnumi->Write(TString("numiall")+TString(*pIt));
73  houtcos->Write(TString("cosall")+TString(*pIt));
74 
75  hfhcnumi->Add(houtnumi);
76  hfhccos->Add(houtcos);
77 
78  }
79 
80  std::stringstream sfhcnumi, sfhccos;
81  sfhcnumi << hfhcnumi->Integral() << " #pm " << hfhcnumi->Integral()/sqrt(hfhcnumi->Integral()) << " events";
82  sfhccos << hfhccos->Integral() << " #pm " << hfhccos->Integral()/sqrt(hfhccos->Integral()) << " events";
83 
84  std::cout << "FHC: Total NuMI: " << sfhcnumi.str() << std::endl;
85  std::cout << "FHC: Total Cos: " << sfhccos.str() << std::endl;
86 
87  TCanvas* cfhc = new TCanvas();
88  hfhccos->SetMarkerStyle(kFullCircle);
89  hfhccos->SetMarkerColor(kBlack);
90  hfhcnumi->SetMarkerStyle(kFullCircle);
91  hfhcnumi->SetMarkerColor(kRed+2);
92  hfhcnumi->SetLineColor(kRed+2);
93  hfhcnumi->Draw();
94  hfhccos->Draw("same");
95 
96  TLegend *leg = new TLegend(0.5, 0.65, 0.8, 0.85);
97  leg->SetBorderSize(0);
98  leg->SetFillColor(kWhite);
99  leg->SetFillStyle(0);
100  leg->SetTextFont(42);
101  leg->SetTextSize(0.037);
102  leg->AddEntry(hfhcnumi, "NuMI Out-of-Time Data", "pe");
103  leg->AddEntry(hfhccos, "Cosmic Trigger Data", "pe");
104  leg->Draw();
105 
106  TLatex* tex = new TLatex();
107  tex->SetNDC();
108  tex->SetTextFont(42);
109  tex->SetTextSize(0.037);
110  tex->SetTextAlign(11);
111  tex->SetTextColor(kRed+2);
112  tex->DrawLatex(0.5, 0.5, sfhcnumi.str().c_str());
113  tex->SetTextColor(kBlack);
114  tex->DrawLatex(0.5, 0.5 - 1*0.055, sfhccos.str().c_str());
115 
116  fout.cd();
117  cfhc->Write("fhc");
118 
119  // CenterTitles(houtcos5);
120  // Preliminary();
121 
122  // RHC
123  TH1* hrhcnumi = (TH1*)hnumi[*rhcPeriods.begin()]->Clone("rhcnumi");
124  TH1* hrhccos = (TH1*)hcos[*rhcPeriods.begin()]->Clone("rhccos");
125  hrhcnumi->Reset();
126  hrhccos->Reset();
127 
128  for (std::vector<std::string>::const_iterator pIt = rhcPeriods.begin(); pIt != rhcPeriods.end(); ++pIt) {
129 
130  TH1* houtnumi = (TH1*)hnumi[*pIt]->Clone(TString("houtnumi")+TString(*pIt));
131  TH1* houtcos = (TH1*)hcos[*pIt]->Clone(TString("houtcos")+TString(*pIt));
132 
133  houtnumi->Scale((numiev[*pIt])/houtnumi->Integral());
134  houtcos->Scale((cosev[*pIt])/houtcos->Integral());
135 
136  fout.cd();
137  houtnumi->Write(TString("numiall")+TString(*pIt));
138  houtcos->Write(TString("cosall")+TString(*pIt));
139 
140  hrhcnumi->Add(houtnumi);
141  hrhccos->Add(houtcos);
142 
143  }
144 
145  std::stringstream srhcnumi, srhccos;
146  srhcnumi << hrhcnumi->Integral() << " #pm " << hrhcnumi->Integral()/sqrt(hrhcnumi->Integral()) << " events";
147  srhccos << hrhccos->Integral() << " #pm " << hrhccos->Integral()/sqrt(hrhccos->Integral()) << " events";
148 
149  std::cout << "RHC: Total NuMI: " << srhcnumi.str() << std::endl;
150  std::cout << "RHC: Total Cos: " << srhccos.str() << std::endl;
151 
152  TCanvas* crhc = new TCanvas();
153  // hrhccos->SetMarkerStyle(kFullCircle);
154  // hrhccos->SetMarkerColor(kBlack);
155  // hrhccos->Draw();
156  hrhcnumi->SetMarkerStyle(kFullCircle);
157  hrhcnumi->SetMarkerColor(kRed+2);
158  hrhcnumi->SetLineColor(kRed+2);
159  hrhcnumi->Draw();
160 
161  leg = new TLegend(0.5, 0.65, 0.8, 0.85);
162  leg->SetBorderSize(0);
163  leg->SetFillColor(kWhite);
164  leg->SetFillStyle(0);
165  leg->SetTextFont(42);
166  leg->SetTextSize(0.037);
167  leg->AddEntry(hrhcnumi, "NuMI Out-of-Time Data", "pe");
168  // leg->AddEntry(hrhccos, "Cosmic Trigger Data", "pe");
169  leg->Draw();
170 
171  tex = new TLatex();
172  tex->SetNDC();
173  tex->SetTextFont(42);
174  tex->SetTextSize(0.037);
175  tex->SetTextAlign(11);
176  tex->SetTextColor(kRed+2);
177 
178  tex->DrawLatex(0.5, 0.5, srhcnumi.str().c_str());
179  tex->SetTextColor(kBlack);
180  tex->DrawLatex(0.5, 0.5 - 1*0.055, srhccos.str().c_str());
181 
182  // CenterTitles(houtcos5);
183  // Preliminary();
184 
185  fout.cd();
186  crhc->Write("rhc");
187 
188 }
enum BeamMode kRed
double Integral(const Spectrum &s, const double pot, int cvnregion)
const char * p
Definition: xmltok.h:285
T sqrt(T number)
Definition: d0nt_math.hpp:156
const double kSecondAnaPeriod3Livetime
Definition: Exposures.h:104
void PrintNus18CosBkgd()
const double kAna2017Epoch3eLivetime
Definition: Exposures.h:197
const double kAna2017Period5Livetime
Definition: Exposures.h:198
OStream cout
Definition: OStream.cxx:6
const double kSecondAnaPeriod1Livetime
Definition: Exposures.h:99
TDirectory * dir
Definition: macro.C:5
double livetime
Definition: saveFDMCHists.C:21
TLatex * tex
Definition: f2_nu.C:499
const double kSecondAnaPeriod2Livetime
Definition: Exposures.h:100
enum BeamMode string