plot_michel_final.C
Go to the documentation of this file.
1 // Macro to draw 2018 nue FHC analysis final MichelDecomp plot
2 #pragma once
3 
10 #include "CAFAna/Core/Spectrum.h"
18 #include "OscLib/IOscCalc.h"
19 
20 #include "TFile.h"
21 #include "TH1.h"
22 #include "THStack.h"
23 #include "TCanvas.h"
24 #include "TGaxis.h"
25 #include "TGraph.h"
26 #include "TLatex.h"
27 #include "TLegend.h"
28 #include "TLine.h"
29 #include "TSystem.h"
30 #include <fstream>
31 #include <iostream>
32 #include <iomanip>
33 #include <string>
34 #include <cstddef>
35 
36 using namespace ana;
37 
38 void SetAxis(TH1* h, bool visible, int color, int style = 1, bool scale = true);
39 double DerivePowScale(TH1* h);
40 void Legend(TH1* h_to_clone);
41 
43 
44  TFile* fdecomp = new TFile(("nue_dcmp.root"), "READ");
45  if(fdecomp->IsZombie()) {std::cout << "MC Decomp File not found"; return; }
46 
47  TH2F *da2D = (TH2F*)fdecomp->Get("nue_decomps/michelbenDCMP/TempData/hist");
48  TH2F *cc2D = (TH2F*)fdecomp->Get("nue_decomps/michelbenDCMP/TempNumu/hist");
49  TH2F *nc2D = (TH2F*)fdecomp->Get("nue_decomps/michelbenDCMP/TempNC/hist");
50  TH2F *ne2D = (TH2F*)fdecomp->Get("nue_decomps/michelbenDCMP/TempNue/hist");
51 
52  TH1D *potda = (TH1D*)(fdecomp->Get(("nue_decomps/michelbenDCMP/TempData/pot")))->Clone(UniqueName().c_str());
53  TH1D *potmc = (TH1D*)(fdecomp->Get(("nue_decomps/michelbenDCMP/TempNumu/pot")))->Clone(UniqueName().c_str());
54 
55  TH1D *da = (TH1D*)da2D->ProjectionY();
56  TH1D *cc = (TH1D*)cc2D->ProjectionY();
57  TH1D *nc = (TH1D*)nc2D->ProjectionY();
58  TH1D *ne = (TH1D*)ne2D->ProjectionY();
59 
60  da->Scale(0.001);
61  cc->Scale(0.001*potda->Integral()/potmc->Integral());
62  ne->Scale(0.001*potda->Integral()/potmc->Integral());
63  nc->Scale(0.001*potda->Integral()/potmc->Integral());
64 
65  THStack *st = new THStack(UniqueName().c_str(),"");
66  ne->SetLineColor(kMagenta);
67  ne->SetLineWidth(2);
68  ne->SetFillStyle(1001);
69 
70  st->Add(ne);
71  nc->SetLineColor(kAzure);
72  nc->SetLineWidth(2);
73  nc->SetFillStyle(1001);
74 
75  st->Add(nc);
76 
77  cc->SetLineColor(kGreen+2);
78  cc->SetLineWidth(2);
79  cc->SetFillStyle(1001);
80 
81  st->Add(cc);
82 
83  TCanvas* can = new TCanvas("c");
84 
85  std::vector <int> colors = {kMagenta,
86  kGreen+2,
87  kAzure,
88  kMagenta-2,
89  kGreen-3,
90  kRed};
91  std::vector<std::string> labels = {"#nu_{e} CC",
92  "#nu_{#mu} CC",
93  "NC",
94  "#bar{#nu_{e}} CC",
95  "#bar{#nu_{#mu}} CC"};
96 
97  da->GetXaxis()->SetTitle("Number of Michel Electrons");
98  da->GetXaxis()->CenterTitle();
99  da->GetYaxis()->SetTitle("10^{3} Events");
100 
101  da->GetYaxis()->CenterTitle();
102  da->SetMarkerStyle(kFullCircle);
103 
104  for (int i = 1; i <= 3; i++) da->SetBinError(i,da->GetBinContent(i)/1000);
105 
106  SetAxis(da, true, 5);
107 
108  da->Draw("E");
109  Legend(da);
110 
111  st->Draw("hist same");
112  da->Draw("same E1");
113  gPad->RedrawAxis();
114 
115  can->SaveAs("nue2018_michel_NME.pdf");
116  can->SaveAs("nue2018_michel_NME.png");
117  can->SaveAs("nue2018_michel_NME.eps");
118  can->SaveAs("nue2018_michel_NME.gif");
119 }
120 
121 void SetAxis(TH1* h, bool visible, int color, int style, bool scale) {
122  if(!visible){
123  h->SetTickLength(0.);
124  h->SetLabelSize(0.);
125  }
126  double norm = DerivePowScale(h);
127 }
128 
129 double DerivePowScale(TH1* h) {
130  return 3*(int(log10(h->GetMaximum())))/3;
131 }
132 
133 void Legend(TH1* h_to_clone){
134  std::vector <std::pair<int, TString>> entries = {{kBlack, "ND data"},
135  {kAzure, "NC"},
136  {kGreen+2, "#nu_{#mu} CC"},
137  {kMagenta, "#nu_{e} CC"},
138  };
139  TLegend* leg = new TLegend(.65, .5, .85, .8);
140  leg->SetFillStyle(0);
141  TH1* h = (TH1F*)h_to_clone->Clone();
142  leg->SetTextSize(0.75*h->GetXaxis()->GetTitleSize());
143  h->SetLineStyle(1);
144  h->SetLineColor(kBlack);
145  h->SetMarkerStyle(kFullCircle);
146  leg->AddEntry(h, entries[0].second, "lep");
147  for(int i = 1; i < (int) entries.size(); i++){
148  h->SetLineColor(entries[i].first);
149  if(i == 7) h->SetLineStyle(7); // Uncorr MC
150  else h->SetLineStyle(1);
151  if(i == 8){
152  h->SetMarkerColor(entries[i].first); // Ratio to Uncorr MC
153  h->SetMarkerStyle(kFullCircle);
154  leg->AddEntry(h->Clone(), entries[i].second, "lep");
155  continue;
156  }
157  if(i == 9) {
158  h->SetMarkerColor(entries[i].first);
159  h->SetMarkerStyle(kFullCircle);
160  leg->AddEntry(h->Clone(), entries[i].second, "lep");
161  continue;
162  }
163  leg->AddEntry(h->Clone(), entries[i].second, "l");
164  }
165  h->SetLineColor(kBlack);
166  leg->Draw();
167 
168 }
169 
170 
enum BeamMode kRed
void plot_michel_final()
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
void Legend(TH1 *h_to_clone)
void SetAxis(TH1 *h, bool visible, int color, int style=1, bool scale=true)
Double_t scale
Definition: plot.C:25
int colors[6]
Definition: tools.h:1
OStream cout
Definition: OStream.cxx:6
Float_t norm
T log10(T number)
Definition: d0nt_math.hpp:120
void cc()
Definition: test_ana.C:28
double DerivePowScale(TH1 *h)
enum BeamMode nc
enum BeamMode kGreen
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:29
const double potmc