All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Plots.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <vector>
5 
6 #include "Rtypes.h"
7 
8 class TLegend;
9 class TGraph;
10 class TGraphAsymmErrors;
11 class TH1;
12 class TH2;
13 class THStack;
14 
15 namespace osc
16 {
17  template<class T> class _IOscCalc;
19 }
20 
21 namespace ana
22 {
23  class IPrediction;
24  class ISyst;
25  class Spectrum;
26  class SystShifts;
27 
28  /// Overlay MC spectrum with data spectrum
29  ///
30  /// \return The first histogram drawn so you can alter axis labels etc
31  TH1* DataMCComparison(const Spectrum& data, const Spectrum& mc);
32 
33  /// Overlay MC spectrum with data spectrum, area normalized
34  ///
35  /// \return The first histogram drawn so you can alter axis labels etc
36  TH1* DataMCComparisonAreaNormalized(const Spectrum& data, const Spectrum& mc);
37 
38  /// \brief Plot MC broken down into flavour components, overlayed with data
39  ///
40  /// \return The first histogram drawn so you can alter axis labels etc
41  TH1* DataMCComparisonComponents(const Spectrum& data,
42  const IPrediction* mc,
43  osc::IOscCalc* calc);
44 
45  TH1* GetMCSystTotal(const IPrediction* mc,
46  osc::IOscCalc* calc,
47  const SystShifts& shift,
48  std::string hist_name,
49  double pot,
50  bool force1D=false);
51 
52  TH1* GetMCTotal(const IPrediction* mc,
53  osc::IOscCalc* calc,
54  std::string hist_name,
55  double pot,
56  bool force1D=false);
57 
58 
59  /// A vector of histograms for the MC components. Easier to manipulate elsewhere
60  /// Not ideal as returned pointers probably won't get deleted... but very useful...
61  std::vector<TH1*> GetMCComponents(const IPrediction* mc,
62  osc::IOscCalc* calc,
63  std::string hist_name,
64  double pot,
65  bool force1D = false);
66 
67  std::vector<TH1*> GetMCSystComponents(const IPrediction* mc,
68  osc::IOscCalc* calc,
69  const SystShifts& shift,
70  std::string hist_name,
71  double pot,
72  bool force1D=false);
73 
74 
75  std::vector<TH1*> GetMCTotalForSystShifts(const IPrediction* mc,
76  osc::IOscCalc* calc,
77  const ISyst* syst,
78  std::string hist_base_name,
79  double pot,
80  bool force1D = false);
81 
82  /// Plot data/MC ratio for the given spectrum. Normalize MC to Data by area
83  void DataMCAreaNormalizedRatio(const Spectrum& data, const Spectrum& mc,
84  double miny = 0, double maxy = 3);
85 
86  /// Plot data/MC ratio for the given spectrum. Normalize MC to Data by area
87  void DataMCAreaNormalizedRatio(const Spectrum& data,
88  const IPrediction* mc,
89  osc::IOscCalc* calc,
90  double miny = 0, double maxy = 3);
91 
92  /// Plot data/MC ratio for the given spectrum. Normalize MC to Data by POT
93  void DataMCRatio(const Spectrum& data, const Spectrum& mc,
94  double miny = 0, double maxy = 3);
95 
96  /// Plot data/MC ratio for the given spectrum. Normalize MC to Data by POT
97  void DataMCRatio(const Spectrum& data,
98  const IPrediction* mc,
99  osc::IOscCalc* calc,
100  double miny = 0, double maxy = 3);
101 
102  /// Plot data/expected, compared with fit/expected
103  void RatioPlot(const Spectrum& data,
104  const Spectrum& expected,
105  const Spectrum& fit,
106  double miny = 0, double maxy = 1.2);
107 
108  /// \brief Plot prediction with +/-1sigma error band
109  ///
110  /// When multiple systematics are used, the errors are the quadrature sum
111  ///
112  /// \param pred The prediction. Must be able to generate shifted spectra
113  /// \param systs List of systematics to include in error band
114  /// \param calc Oscillation parameters
115  /// \param pot POT to evaluate prediction at
116  /// \param col Color of the prediction, default kRed
117  /// \param errCol Color of the shading, default col-7 (kRed-7 is light red)
118  /// \param headroom Fraction of maximum bin for headroom, default 30%
119  void PlotWithSystErrorBand(IPrediction* pred,
120  const std::vector<const ISyst*>& systs,
121  osc::IOscCalc* calc,
122  double pot,
123  int col = -1, int errCol = -1,
124  float headroom = 1.3,
125  bool newaxis = true);
126 
127  /// \brief Plot prediction with error band
128  ///
129  /// When multiple systematics are used, the errors are the quadrature sum
130  ///
131  /// \param nominal Nominal spectrum
132  /// \param upShifts Vector of spectra which have + shifts
133  /// \param downShifts Vector of spectra which have - shifts, same order as +
134  /// \param pot POT to scale spectra to
135  /// \param col Color of the prediction, default kRed
136  /// \param errCol Color of the shading, default col-7(kRed-7 is light red)
137  /// \param headroom Fraction of maximum bin for headroom, default 30%
138  void PlotWithSystErrorBand(const Spectrum& nominal,
139  const std::vector<Spectrum>& upShifts,
140  const std::vector<Spectrum>& downShifts,
141  double pot,
142  int col = -1, int errCol = -1,
143  float headroom = 1.3, bool newaxis=true);
144 
145  /// Can call like ToTHStack({{h1, kRed}, {h2, kBlue}}, pot)
146  THStack* ToTHStack(const std::vector<std::pair<Spectrum, Color_t>>& s,
147  double pot);
148 
149 
150  /// \brief Create a legend, maximizing distance from all histograms
151  ///
152  /// \param dx Width of the legend, fraction of pad width
153  /// \param dy Height of the legend, fraction of pad height
154  /// \param yPin, height in NDC (frac) to pin center of legend, i.e only move x
155  TLegend* AutoPlaceLegend(double dx, double dy, double yPin = -1);
156 
157  /// \brief Make a simple plot of relative size of different errors
158  ///
159  /// \param systs Map from error label to size in percent
160  /// \param statErr Percentage statistical error. Optional.
161  /// \param bkgdOrSig Label axis for background or signal. Default (false) = bkgd
162  void CountingExperimentErrorBarChart(const std::map<std::string, double>& systs, double statErr = 0, bool bkgdOrSig = false, bool shortchart=false);
163 
164  /// Calculate statistical errors appropriate for small Poisson numbers
165  TGraphAsymmErrors* GraphWithPoissonErrors(const TH1* h, bool noErrorsXaxis = false, bool drawEmptyBins = true);
166 
167  /// Gives a TGraph with the area between two histograms. Do Draw("f") to draw
168  /// this area. By default it has a lighter version of the colour of hmin
169  TGraph* ShadeBetweenHistograms(TH1* hmin, TH1* hmax);
170 
171  /// Calculate profile with error bars corresponding to specified quantiles of a 2D distribution (by default, 68% coverage)
172  TGraphAsymmErrors * ProfileQuantile(const TH2 * hist, const std::string & axis_name, const std::string & graph_name="", const std::pair<double, double> & quantile_divisions={0.159, 0.841});
173 }
THStack * ToTHStack(const std::vector< std::pair< Spectrum, Color_t >> &s, double pot)
Can call like ToTHStack({{h1, kRed}, {h2, kBlue}}, pot)
Definition: Plots.cxx:469
void DataMCRatio(const Spectrum &data, const IPrediction *mc, osc::IOscCalc *calc, double miny, double maxy)
Plot data/MC ratio for the given spectrum. Normalize MC to Data by POT.
Definition: Plots.cxx:299
TH1 * DataMCComparison(const Spectrum &data, const Spectrum &mc)
Definition: Plots.cxx:32
void PlotWithSystErrorBand(IPrediction *pred, const std::vector< const ISyst * > &systs, osc::IOscCalc *calc, double pot, int col, int errCol, float headroom, bool newaxis)
Plot prediction with +/-1sigma error band.
Definition: Plots.cxx:377
TGraphAsymmErrors * GraphWithPoissonErrors(const TH1 *h, bool noErrorsXaxis, bool drawEmptyBins)
Calculate statistical errors appropriate for small Poisson numbers.
Definition: Plots.cxx:678
process_name opflashCryoW ana
shift
Definition: fcl_checks.sh:26
_IOscCalc< double > IOscCalc
Definition: Plots.h:17
TGraphAsymmErrors * ProfileQuantile(const TH2 *hist, const std::string &axisName, const std::string &graphName, const std::pair< double, double > &quantileDivisions)
Calculate profile with error bars corresponding to specified quantiles of a 2D distribution (by defau...
Definition: Plots.cxx:728
std::vector< TH1 * > GetMCTotalForSystShifts(const IPrediction *mc, osc::IOscCalc *calc, const ISyst *syst, std::string hist_base_name, double pot, bool force1D)
Definition: Plots.cxx:278
while getopts h
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
void RatioPlot(const Spectrum &data, const Spectrum &expected, const Spectrum &fit, double miny, double maxy)
Plot data/expected, compared with fit/expected.
Definition: Plots.cxx:348
TH1 * DataMCComparisonAreaNormalized(const Spectrum &data, const Spectrum &mc)
Definition: Plots.cxx:62
TGraph * ShadeBetweenHistograms(TH1 *hmin, TH1 *hmax)
Definition: Plots.cxx:704
TH1 * GetMCTotal(const IPrediction *mc, osc::IOscCalc *calc, std::string hist_name, double pot, bool force1D)
Definition: Plots.cxx:158
std::vector< TH1 * > GetMCSystComponents(const IPrediction *mc, osc::IOscCalc *calc, const SystShifts &shift, std::string hist_name, double pot, bool force1D)
Definition: Plots.cxx:176
void CountingExperimentErrorBarChart(const std::map< std::string, double > &systs, double statErr=0, bool bkgdOrSig=false, bool shortchart=false)
Make a simple plot of relative size of different errors.
void DataMCAreaNormalizedRatio(const Spectrum &data, const IPrediction *mc, osc::IOscCalc *calc, double miny, double maxy)
Plot data/MC ratio for the given spectrum. Normalize MC to Data by area.
Definition: Plots.cxx:328
TH1 * DataMCComparisonComponents(const Spectrum &data, const IPrediction *mc, osc::IOscCalc *calc)
Plot MC broken down into flavour components, overlayed with data.
Definition: Plots.cxx:94
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
std::vector< TH1 * > GetMCComponents(const IPrediction *mc, osc::IOscCalc *calc, std::string hist_name, double pot, bool force1D)
Definition: Plots.cxx:167
TH1 * GetMCSystTotal(const IPrediction *mc, osc::IOscCalc *calc, const SystShifts &shift, std::string hist_name, double pot, bool force1D)
Definition: Plots.cxx:146
TLegend * AutoPlaceLegend(double dx, double dy, double yPin)
Create a legend, maximizing distance from all histograms.
Definition: Plots.cxx:510