14 #include "CAFAna/Core/Binning.h" 29 #include "TMultiGraph.h" 34 #include "TPaveText.h" 40 double getFractionalError(
double const mean0,
double const meanErr0,
double const mean1,
double const meanErr1)
42 double fractionalError = 0.;
44 double numerator = mean1 - mean0;
45 double denominator = mean0;
46 double numeratorVar = meanErr0*meanErr0 + meanErr1*meanErr1;
47 double denominatorVar = meanErr0*meanErr0;
49 std::cout << numerator <<
" " << denominator <<
" " << numeratorVar <<
" " << denominatorVar <<
std::endl;
51 return std::sqrt((numerator/denominator)*(numerator/denominator)*(numeratorVar/(numerator*numerator)+denominatorVar/(denominator*denominator)))*100.;
56 std::pair<double,double> largeMean;
57 std::pair<double,double> smallMean;
61 largeMean = {mean0, meanErr0};
62 smallMean = {mean1, meanErr1};
66 largeMean = {mean1, meanErr1};
67 smallMean = {mean0, meanErr0};
70 double largeMeanShifted = largeMean.first - 2.*largeMean.second;
71 double smallMeanShifted = smallMean.first + 2.*smallMean.second;
73 return (largeMeanShifted <= smallMeanShifted ?
"True" :
"False");
77 unsigned int color1 = 1,
unsigned int color2 = 2) {
79 std::cout <<
"\n\n\nMAKING THE PLOTS...\n\n\n";
81 std::ofstream f_MeansFile;
82 f_MeansFile.open(s_OutDir+
"meansFile_"+s_OutName+
".csv");
84 TFile f_In(s_InFile.c_str());
88 unsigned int nSpec = 41;
90 for(
unsigned int S = 0;
S <= nSpec; ++
S) {
91 for(
unsigned int Q = 0; Q <=
nQuant; ++Q) {
93 sprintf(s_DirName,
"dir_Var%d_Q%d_DataSet0",
S,Q);
95 sprintf(s_DirName,
"dir_Var%d_Q%d_DataSet1",
S,Q);
98 TCanvas *
c =
new TCanvas(
"c",
"c", 1000, 800);
99 TPad *
p1 =
new TPad(
"p1",
"p1", 0, 0, 1, 1);
100 TPad *
p2 =
new TPad(
"p2",
"p2", 0, 0, 1, 1);
105 gStyle->SetOptStat(0);
107 TH1 *h0 = spec0->ToTH1(spec1->POT());
108 TH1 *
h1 = spec1->ToTH1(spec1->POT());
111 h0->SetLineColor(color1);
114 h1->SetLineColor(color2);
116 h0->GetXaxis()->SetTitle(
"");
117 h0->GetXaxis()->SetLabelSize(0);
118 h1->GetXaxis()->SetTitle(
"");
119 h1->GetXaxis()->SetLabelSize(0);
125 Ratio rat(*spec1, *spec0);
126 std::cout <<
"DIVINING " << spec1->GetLabels()[0] <<
" BY " << spec0->GetLabels()[0] <<
std::endl;
128 TH1* hRat = rat.
ToTH1();
129 hRat->SetAxisRange(0.9,1.1,
"Y");
132 double x[2] = {hRat->GetXaxis()->GetXmin(), hRat->GetXaxis()->GetXmax()};
133 double y[2] = {1.0, 1.0};
134 TGraph* l_Xaxis =
new TGraph(2, x, y);
135 l_Xaxis->SetLineColor(kGray);
136 l_Xaxis->SetLineWidth(3);
137 l_Xaxis->SetLineStyle(2);
138 l_Xaxis->Draw(
"L SAME");
140 sprintf (s_FileName,
"Var%d_Q%d_%s.pdf",
S, Q+1, s_OutName.c_str());
141 c->Print((s_OutDir+(
std::string)s_FileName).c_str());
143 std::cout <<
"\n\nMeans for:\t" << hRat->GetXaxis()->GetTitle() <<
" for quant " << Q+1 <<
"\n" 144 <<
"old data: \t" << h0->GetMean() <<
" +/- " << h0->GetMeanError() <<
"\n" 145 <<
"keepup data:\t" << h1->GetMean() <<
" +/- " << h1->GetMeanError() <<
"\n\n";
147 f_MeansFile << s_FileName <<
"=" << hRat->GetXaxis()->GetTitle() <<
" for quant " << Q+1 <<
"=" 148 << h0->GetMean() <<
"=" << h0->GetMeanError() <<
"=" 149 << h1->GetMean() <<
"=" << h1->GetMeanError() <<
"=" 150 << (h1->GetMean()-h0->GetMean())/h0->GetMean()*100. <<
"=" 151 <<
getFractionalError (h0->GetMean(), h0->GetMeanError(), h1->GetMean(), h1->GetMeanError()) <<
"=" 161 std::cout <<
"\n\n\nFINISHED MAKING PLOTS!\n\n\n";
Cuts and Vars for the 2020 FD DiF Study.
TH1D * ToTH1(Color_t col=kBlack, Style_t style=kSolid) const
void SplitCanvas(double ysplit, TPad *&p1, TPad *&p2)
Split the current pad into two vertically stacked pieces, suitable for ratio plots and so on...
void Plotting_Data2DataComp(std::string s_InFile="", std::string s_OutDir="", std::string s_OutName="", unsigned int color1=1, unsigned int color2=2)
double getFractionalError(double const mean0, double const meanErr0, double const mean1, double const meanErr1)
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
Represent the ratio between two spectra.
std::string is2SigmaBandsTouching(double const mean0, double const meanErr0, double const mean1, double const meanErr1)