RatioPlot Class Reference

#include <RatioPlot.h>

List of all members.

Public Member Functions

 RatioPlot (TString title, const TH1D *nom, const TH1D *dat, const TH1D *fit, const TH1D *bkg, bool rebin=false)
void AddOtherSpectrum (const TH1D *s)
void Draw ()
void SetSpectrumMax (double m)
void SetRatioMax (double m)

Protected Attributes

TString fTitle
NuMatrixSpectrum fNominal
NuMatrixSpectrum fData
NuMatrixSpectrum fFit
NuMatrixSpectrum fBackground
vector< NuMatrixSpectrumfOthers
double fSpectrumMax
double fRatioMax

Detailed Description

Definition at line 11 of file RatioPlot.h.


Constructor & Destructor Documentation

RatioPlot::RatioPlot ( TString  title,
const TH1D *  nom,
const TH1D *  dat,
const TH1D *  fit,
const TH1D *  bkg,
bool  rebin = false 
) [inline]

Definition at line 14 of file RatioPlot.h.

References NuMatrixSpectrum::BinWidthNormalize(), fBackground, fData, fFit, fNominal, fTitle, n, and NuMatrixSpectrum::RebinToArray().

00018     : fSpectrumMax(-1), fRatioMax(-1)
00019   {
00020     fTitle = title;
00021     if(nom) fNominal = NuMatrixSpectrum(*nom);
00022     if(dat) fData = NuMatrixSpectrum(*dat);
00023     if(fit) fFit = NuMatrixSpectrum(*fit);
00024     if(bkg) fBackground = NuMatrixSpectrum(*bkg);
00025 
00026     if(rebin){
00027       double edges[32];
00028       for(int n = 0; n <= 19; ++n) edges[n] = .5*n;
00029       for(int n = 0; n <= 10; ++n) edges[20+n] = 10+n;
00030       edges[31] = 200;
00031       fNominal.RebinToArray(31, edges);
00032       fData.RebinToArray(31, edges);
00033       fFit.RebinToArray(31, edges);
00034       fBackground.RebinToArray(31, edges);
00035 
00036       fNominal.BinWidthNormalize();
00037       fData.BinWidthNormalize();
00038       fFit.BinWidthNormalize();
00039       fBackground.BinWidthNormalize();
00040     }
00041   }


Member Function Documentation

void RatioPlot::AddOtherSpectrum ( const TH1D *  s  )  [inline]

Definition at line 43 of file RatioPlot.h.

References fOthers.

00043 {fOthers.push_back(NuMatrixSpectrum(*s));}

void RatioPlot::Draw (  )  [inline]

Definition at line 55 of file RatioPlot.h.

References copy(), NuMatrixSpectrum::Divide(), NuMatrix1D::Draw(), fBackground, fData, fFit, fill(), fNominal, fOthers, fRatioMax, fSpectrumMax, fTitle, NuMatrixSpectrum::GetXaxis(), NuMatrixSpectrum::GetYaxis(), n, NuMatrixSpectrum::RemoveErrors(), NuMatrixSpectrum::SetFillColor(), NuMatrixSpectrum::SetFillStyle(), NuMatrixSpectrum::SetLineColor(), NuMatrixSpectrum::SetTitle(), NuMatrixSpectrum::Spectrum(), and NuMatrix1D::Subtract().

00056   {
00057     TVirtualPad* pad = gPad;
00058 
00059     // Overdraw whatever's below us
00060     TPad* fill = new TPad("", "", 0, 0, 1, 1);
00061     fill->Draw();
00062 
00063     fNominal.SetLineColor(kRed);
00064     fFit.SetLineColor(kBlue);
00065 
00066     TPad* top = new TPad("", "", 0, 1-.66667/(1-gStyle->GetPadBottomMargin()), 1, 1);
00067     top->SetFillStyle(4000);
00068     top->Draw();
00069     TPad* bottom = new TPad("", "", 0, 0, 1, .33333/(1-gStyle->GetPadTopMargin()));
00070     bottom->SetBottomMargin(2*bottom->GetBottomMargin());
00071     bottom->SetFillStyle(4000);
00072     bottom->Draw();
00073 
00074     top->cd();
00075 
00076     fNominal.GetXaxis()->SetRangeUser(0, 19.99);
00077     fNominal.GetXaxis()->SetTitle("");
00078     fNominal.GetXaxis()->SetLabelSize(0);
00079     fNominal.Spectrum()->SetTitle(fTitle);
00080     fNominal.GetYaxis()->SetTitle("Events");
00081     double maxy = fSpectrumMax;
00082     if(maxy < 0){
00083       // Find maximum data bin, allow for poisson errors and then round up
00084       // to nearest multiple of 10.
00085       maxy = fData.Spectrum() ? fData.Spectrum()->GetBinContent(fData.Spectrum()->GetMaximumBin()) : 0;
00086       maxy += sqrt(maxy);
00087       const double maxynom = fNominal.Spectrum()->GetBinContent(fNominal.Spectrum()->GetMaximumBin());
00088       if(maxynom > maxy) maxy = maxynom;
00089       maxy = int(maxy/10+1)*10;
00090     }
00091     fNominal.GetYaxis()->SetRangeUser(0, maxy);
00092     fNominal.Draw("hist");
00093     fFit.Draw("hist same");
00094     for(unsigned int n = 0; n < fOthers.size(); ++n){
00095       fOthers[n].Draw("hist same");
00096     }
00097     if(fData.Spectrum()) fData.Draw("same ep");
00098 
00099     if(fBackground.Spectrum()){
00100       fBackground.SetFillColor(kBlack);
00101       fBackground.SetFillStyle(3004); // Crosshatching: ///
00102       fBackground.Draw("hist same");
00103     }
00104 
00105     TLegend* leg = new TLegend(.5, .5, .875, .875);
00106     leg->SetFillStyle(0);
00107     leg->AddEntry(fNominal.Spectrum(), "Unoscillated prediction", "l");
00108     if(fData.Spectrum()) leg->AddEntry(fData.Spectrum(), "FD Data", "lep");
00109     leg->AddEntry(fFit.Spectrum(), "Best fit", "l");
00110     if(fBackground.Spectrum())
00111       leg->AddEntry(fBackground.Spectrum(), "Background", "bf");
00112     leg->Draw();
00113 
00114     bottom->cd();
00115 
00116     NuMatrixSpectrum* fitCopy = new NuMatrixSpectrum(fFit);
00117     fitCopy->GetXaxis()->SetTitle("Energy (GeV)");
00118     fitCopy->GetYaxis()->SetTitle("Ratio to unoscillated");
00119     fitCopy->Divide(&fNominal);
00120     fitCopy->SetTitle("");
00121     fitCopy->Draw("hist");
00122     fitCopy->GetXaxis()->SetRangeUser(0, 19.99);
00123     if(fRatioMax < 0){
00124       fitCopy->GetYaxis()->SetRangeUser(0, 1.199);
00125     }
00126     else{
00127       fitCopy->GetYaxis()->SetRangeUser(0, fRatioMax);
00128     }
00129 
00130     for(unsigned int n = 0; n < fOthers.size(); ++n){
00131       NuMatrixSpectrum* copy = new NuMatrixSpectrum(fOthers[n]);
00132       copy->Divide(&fNominal);
00133       copy->Draw("same hist");
00134     }
00135 
00136     if(fData.Spectrum()){
00137       NuMatrixSpectrum* dataCopy = new NuMatrixSpectrum(fData);
00138       fBackground.RemoveErrors();
00139       dataCopy->Subtract(fBackground);
00140       NuMatrixSpectrum* nominalCopy = new NuMatrixSpectrum(fNominal);
00141       nominalCopy->Subtract(fBackground);
00142       nominalCopy->RemoveErrors();
00143       dataCopy->Divide(nominalCopy);
00144       dataCopy->Draw("same ep");
00145     }
00146 
00147     // The documentation for the text size calculation is a lie, but this seems
00148     // to work fine at this aspect ratio.
00149     const double factor = top->GetHNDC()/bottom->GetHNDC();
00150     TAxis* yax = fitCopy->GetYaxis();
00151     yax->SetTitleSize(factor*yax->GetTitleSize());
00152     yax->SetTitleOffset(yax->GetTitleOffset()/factor);
00153     yax->SetLabelSize(factor*yax->GetLabelSize());
00154 
00155     TAxis* xax = fitCopy->GetXaxis();
00156     xax->SetTitleSize(factor*xax->GetTitleSize());
00157     xax->SetLabelSize(factor*xax->GetLabelSize());
00158 
00159     pad->cd();
00160   }

void RatioPlot::SetRatioMax ( double  m  )  [inline]

Definition at line 163 of file RatioPlot.h.

References fRatioMax.

00163 {fRatioMax = m;}

void RatioPlot::SetSpectrumMax ( double  m  )  [inline]

Definition at line 162 of file RatioPlot.h.

References fSpectrumMax.

00162 {fSpectrumMax = m;}


Member Data Documentation

Definition at line 167 of file RatioPlot.h.

Referenced by Draw(), and RatioPlot().

Definition at line 167 of file RatioPlot.h.

Referenced by Draw(), and RatioPlot().

Definition at line 167 of file RatioPlot.h.

Referenced by Draw(), and RatioPlot().

Definition at line 167 of file RatioPlot.h.

Referenced by Draw(), and RatioPlot().

Definition at line 168 of file RatioPlot.h.

Referenced by AddOtherSpectrum(), and Draw().

double RatioPlot::fRatioMax [protected]

Definition at line 171 of file RatioPlot.h.

Referenced by Draw(), and SetRatioMax().

double RatioPlot::fSpectrumMax [protected]

Definition at line 170 of file RatioPlot.h.

Referenced by Draw(), and SetSpectrumMax().

TString RatioPlot::fTitle [protected]

Definition at line 165 of file RatioPlot.h.

Referenced by Draw(), and RatioPlot().


The documentation for this class was generated from the following file:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1