ProtoDUNEFitUtils.h
Go to the documentation of this file.
1 #ifndef PROTODUNEFITUTILS_h
2 #define PROTODUNEFITUTILS_h
3 
4 #include <iostream>
5 #include <vector>
6 #include <string>
7 
8 #include <TString.h>
9 #include <TTree.h>
10 #include <TH2.h>
11 #include <TH1.h>
12 #include <TCanvas.h>
13 
14 #include <RooArgSet.h>
15 #include <RooArgList.h>
16 #include <RooWorkspace.h>
17 #include <RooFitResult.h>
18 #include <RooPlot.h>
19 
20 namespace protoana{
21  namespace ProtoDUNEFitUtils{
22 
23  // Get vector with all systematic histograms from file
24  std::vector<TH1*> GetSystHistograms(std::string name);
25 
26  // Get histogram with MC statistical uncertainty
27  TH1* GetStatsSystHistogram(TH1* nominal);
28 
29  // Get systematic histograms
30  TH1* GetSystematicHistoFromNominal(TH1* nominal, TH1* syst, TString name);
31 
32  // Check if histogram has one or multiple bins
33  bool IsSingleBinHisto(TH1* histo);
34 
35  // Get fit covariance matrix
36  TH2* GetFitCovariance(RooFitResult* result);
37 
38  // Get fit correlation matrix
39  TH2* GetFitCorrelationMatrix(RooFitResult* result);
40 
41  // Save/access workspace
42  void SaveSnapshot(RooWorkspace* ws, TString snapshotname);
43  bool LoadSnapshot(RooWorkspace* ws, TString snapshotname);
44  void SaveWorkspace(RooWorkspace* ws, TString outFileName);
45 
46  // Set interpolation code
47  void SetInterpolationCode(RooWorkspace* ws, int code);
48 
49  // Remove empty bins from RooPlot
50  void RemoveEmptyBins(RooPlot* frame);
51 
52  // Calculate chi2 comparing the data and MC distributions
53  double GetDataMCChi2(RooWorkspace *work, TString channelname, RooAbsData* data=NULL);
54 
55  // Vector of plots with data and pdfs
56  std::vector<TCanvas*> PlotDatasetsAndPdfs(
57  RooWorkspace *work, TString name, TString error, TString plottodraw,
58  std::vector<TString> binnames, std::vector<double> recobins,
59  std::vector<TString> incidentBinNames,
60  std::vector<TString> sidebandBinNames, std::vector<double> sidebandBins,
61  TString measurement="PDFit",
62  bool doNegativeReco=false,RooAbsData* data=NULL,
63  RooFitResult* result=NULL);
64 
65  std::vector<TH1 *> PlotXSecs(
66  RooWorkspace * work, std::string name, /*std::string error,*/
67  std::vector<TString> binnames, std::vector<double> recobins,
68  std::vector<TString> incidentBinNames, RooAbsData * data = 0x0,
69  RooFitResult * result = 0x0);
70 
71  // Vector of plots for the NLL
72  std::vector<TCanvas*> PlotNLL(RooWorkspace *work, TString name, RooFitResult* result, bool plotPLL=false);
73 
74  // Plot the nuisance parameters impact on POI
75  std::vector<TCanvas*> PlotNuisanceParametersImpact(RooWorkspace *work, RooFitResult* result, TString snapshotload, std::vector<std::string> SystsToConsider);
76 
77  // Plot pull mean and sigma of all the POI
78  TCanvas* PlotParametersPull(TTree* tree, RooWorkspace* ws);
79 
80  // Plot nuisance parameters pulls
81  TCanvas* PlotNuisanceParametersPull(TTree* tree, RooWorkspace* ws);
82 
83  // Plot nuisance parameters
84  TCanvas* PlotNuisanceParameters(TTree* tree, RooWorkspace* ws);
85 
86  // Plot the average number of events from all toys. If fit the data the fit results will be shown
87  TCanvas* PlotAverageResultsFromToys(TTree* tree, RooWorkspace* ws, TString channelname, TString catname, RooArgList * PreFit_POI = 0x0);
88 
89  // Take list of poi
90  RooArgList GetPostfitPOIList(RooArgList paramsfit, bool print=false);
91 
92  // Make all nuisance parameters in workspace constant. One exception is the exceptPar
93  void MakeNuisanceParamsConstant(RooWorkspace* ws, TString exceptPar);
94 
95  // Reset all parameters
96  void ResetValues(RooWorkspace* ws, const RooArgList& parList);
97 
98  // Reset all parameters to their nominal
99  void ResetValuesToNominal(RooWorkspace* ws, const RooArgSet& parSet);
100 
101  // Reset error for all parameters
102  void ResetError(RooWorkspace* ws, const RooArgList& parList);
103 
104  // Reset all values and errors
105  void ResetAllValuesAndErrors(RooWorkspace* ws);
106 
107  // Get argon number density
108  double GetArgonNumberDensity(double argon_density=1.3973, double argon_molecularmass=39.948);
109  // @87K
110 
111  }
112 }
113 
114 #endif
static QCString name
Definition: declinfo.cpp:673
std::vector< TCanvas * > PlotDatasetsAndPdfs(RooWorkspace *work, TString name, TString error, TString plottodraw, std::vector< TString > binnames, std::vector< double > recobins, std::vector< TString > incidentBinNames, std::vector< TString > sidebandBinNames, std::vector< double > sidebandBins, TString measurement="PDFit", bool doNegativeReco=false, RooAbsData *data=NULL, RooFitResult *result=NULL)
RooArgList GetPostfitPOIList(RooArgList paramsfit, bool print=false)
void ResetValues(RooWorkspace *ws, const RooArgList &parList)
void SetInterpolationCode(RooWorkspace *ws, int code)
static QCString result
void SaveWorkspace(RooWorkspace *ws, TString outFileName)
TH1 * GetStatsSystHistogram(TH1 *nominal)
std::string string
Definition: nybbler.cc:12
error
Definition: include.cc:26
bool LoadSnapshot(RooWorkspace *ws, TString snapshotname)
void MakeNuisanceParamsConstant(RooWorkspace *ws, TString exceptPar)
std::vector< TH1 * > PlotXSecs(RooWorkspace *work, std::string name, std::vector< TString > binnames, std::vector< double > recobins, std::vector< TString > incidentBinNames, RooAbsData *data=0x0, RooFitResult *result=0x0)
TH1 * GetSystematicHistoFromNominal(TH1 *nominal, TH1 *syst, TString name)
void RemoveEmptyBins(RooPlot *frame)
std::vector< TCanvas * > PlotNuisanceParametersImpact(RooWorkspace *work, RooFitResult *result, TString snapshotload, std::vector< std::string > SystsToConsider)
TH2 * GetFitCovariance(RooFitResult *result)
TCanvas * PlotParametersPull(TTree *tree, RooWorkspace *ws)
double GetDataMCChi2(RooWorkspace *work, TString channelname, RooAbsData *data=NULL)
CodeOutputInterface * code
double GetArgonNumberDensity(double argon_density=1.3973, double argon_molecularmass=39.948)
void ResetValuesToNominal(RooWorkspace *ws, const RooArgSet &parSet)
TCanvas * PlotNuisanceParameters(TTree *tree, RooWorkspace *ws)
std::vector< TCanvas * > PlotNLL(RooWorkspace *work, TString name, RooFitResult *result, bool plotPLL=false)
TH2 * GetFitCorrelationMatrix(RooFitResult *result)
void SaveSnapshot(RooWorkspace *ws, TString snapshotname)
void ResetError(RooWorkspace *ws, const RooArgList &parList)
TCanvas * PlotAverageResultsFromToys(TTree *tree, RooWorkspace *ws, TString channelname, TString catname, RooArgList *PreFit_POI=0x0)
TCanvas * PlotNuisanceParametersPull(TTree *tree, RooWorkspace *ws)
std::vector< TH1 * > GetSystHistograms(std::string name)
void ResetAllValuesAndErrors(RooWorkspace *ws)