MCToyGenerationAndFit.h
Go to the documentation of this file.
1 #ifndef MCToyGenerationAndFit_h
2 #define MCToyGenerationAndFit_h
3 
4 #include <iostream>
5 #include <vector>
6 #include <fstream>
7 #include <string>
8 
9 // ROOT
10 #include "TTree.h"
11 #include "TString.h"
12 
13 #include "RooAbsData.h"
14 #include "RooWorkspace.h"
15 #include "RooMCStudy.h"
16 #include "RooFitResult.h"
17 #include "RooMultiVarGaussian.h"
18 #include "RooArgList.h"
19 #include "RooArgSet.h"
20 
21 #include "RooStats/HypoTestResult.h"
22 
23 namespace protoana{
24 
26 
27  public:
28 
30  MCToyGenerationAndFit(std::string minimizer, int fitstrategy, bool minoserror, double cl = 0.95);
32 
33  // Generate a toy MC. Choose to generate either the expected events from data or MC
34  RooAbsData* GenerateToyMC(RooWorkspace* ws, bool datanorm=true);
35 
36  // Generate and fit a number of nexp toys. Results will be written in a ttree
37  TTree* GenerateAndFit(RooWorkspace* ws, int nexp);
38 
39  // Add comment
40  RooFitResult * GenerateAndFitOneToy(RooWorkspace* ws);
41 
42  // Fit the data
43  RooFitResult* FitData(RooWorkspace* ws, bool isWeighted=false);
44 
45  // Fit Asimov dataset
46  RooFitResult* FitAsimovData(RooWorkspace* w);
47 
48  // Fit MC toy dataset
49  RooFitResult* FitToyData(RooWorkspace* w, RooAbsData* obsdata);
50 
51  // Fit toys from a list of workspaces
52  TTree* FitToyMCFromWorkspace(std::vector<RooWorkspace*> wsvec, bool fitdata);
53 
54  // Write Roofitresult to a tree
55  TTree* RooFitResultToTTree(RooWorkspace* ws, RooFitResult* res);
56 
57  // Write the fit results stored in RooMCStudy to a ttree
58  TTree* RooMCStudyToTTree(RooMCStudy* mc);
59 
60  // Write a RooDataSet into a ttree
61  TTree* RooDataSetToTTree(RooAbsData* data, TString treename);
62 
63  // Get chi2 between the fit models and a dataset.
64  RooArgSet* GetChi2Set(RooWorkspace *work, RooAbsData* data);
65 
66  // Generate tree with chi2 fit results
67  TTree* GenerateChi2Tree(RooWorkspace* ws, int nexp, int seed);
68 
69  //HypoTestResult* GetHypothesisTest(RooWorkspace* ws, Int_t Ntoys, Int_t calctype, Int_t stattype);
70 
71  // Option to change the minimiser - default is Minuit2
72  void SetMinimiser(std::string min) {_minimizer = TString(min.c_str());}
73 
74  // Change algorithm - default is migrad
75  void SetAlgorithm(std::string min) {_algorithm = TString(min.c_str());}
76 
77  // Option to change fit strategy - default is 1
79 
80  // Option to enable Minos error analysis - default is off
81  void EnableMinosError() {_minoserror = true;}
82 
83  // Option to set CL - default is 95%
84  void SetConfLevel(double cl) {_conflevel = cl;}
85 
86  protected:
87 
88  // Minimiser
89  TString _minimizer;
90 
91  // Algorithm
92  TString _algorithm;
93 
94  // Fit strategy
96 
97  // Flag to enable minos error analysis
99 
100  // Confidence level
101  double _conflevel;
102 
103  };
104 
105 }
106 
107 #endif
TTree * RooMCStudyToTTree(RooMCStudy *mc)
RooFitResult * FitData(RooWorkspace *ws, bool isWeighted=false)
std::string string
Definition: nybbler.cc:12
static constexpr double fs
Definition: Units.h:100
QAsciiDict< Entry > cl
TTree * RooDataSetToTTree(RooAbsData *data, TString treename)
RooFitResult * FitAsimovData(RooWorkspace *w)
TTree * GenerateChi2Tree(RooWorkspace *ws, int nexp, int seed)
RooArgSet * GetChi2Set(RooWorkspace *work, RooAbsData *data)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
TTree * FitToyMCFromWorkspace(std::vector< RooWorkspace * > wsvec, bool fitdata)
TTree * GenerateAndFit(RooWorkspace *ws, int nexp)
RooAbsData * GenerateToyMC(RooWorkspace *ws, bool datanorm=true)
TTree * RooFitResultToTTree(RooWorkspace *ws, RooFitResult *res)
RooFitResult * GenerateAndFitOneToy(RooWorkspace *ws)
RooFitResult * FitToyData(RooWorkspace *w, RooAbsData *obsdata)