ra4_stats  0341147a0dc35f80f4e12c6003afb76a38e2ed6e
likelihood_fit.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 
4 #include <unistd.h>
5 #include <getopt.h>
6 
7 #include "TFile.h"
8 
9 #include "RooWorkspace.h"
10 #include "RooDataSet.h"
11 #include "RooProdPdf.h"
12 #include "RooNLLVar.h"
13 #include "RooMinuit.h"
14 #include "RooFitResult.h"
15 
16 using namespace std;
17 
18 namespace{
19  string file_path = "wspace_nosyst_nokappa_nor4_T1tttt_mGluino-1700_mLSP-100_xsecNom.root";
20 }
21 
22 void GetOptions(int argc, char *argv[]){
23  while(true){
24  static struct option long_options[] = {
25  {"file", required_argument, 0, 'f'},
26  {0, 0, 0, 0}
27  };
28 
29  char opt = -1;
30  int option_index;
31  opt = getopt_long(argc, argv, "f:", long_options, &option_index);
32 
33  if( opt == -1) break;
34 
35  string optname;
36  switch(opt){
37  case 'f':
38  file_path = optarg;
39  break;
40  case 0:
41  optname = long_options[option_index].name;
42  if(false){
43  }else{
44  printf("Bad option! Found option name %s\n", optname.c_str());
45  }
46  break;
47  default:
48  printf("Bad option! getopt_long returned character code 0%o\n", opt);
49  break;
50  }
51  }
52 }
53 int main(int argc, char *argv[]){
54  GetOptions(argc, argv);
55 
56  TFile in_file(file_path.c_str(), "read");
57  RooWorkspace *w = static_cast<RooWorkspace*>(in_file.Get("w"));
58  RooDataSet *data_obs = static_cast<RooDataSet*>(w->data("data_obs"));
59  RooProdPdf *model_b = static_cast<RooProdPdf*>(w->pdf("model_b"));
60 
61  RooNLLVar nll("nll", "nll", *model_b, *data_obs);
62  nll.Print();
63  RooMinuit minuit(nll);
64 
65  minuit.setPrintLevel(99999);
66  minuit.setVerbose(true);
67  minuit.setStrategy(2);
68  minuit.optimizeConst(true);
69  minuit.hesse();
70  minuit.migrad();
71 
72  nll.Print();
73 
74  minuit.save()->Print("v");
75 }
void GetOptions(int argc, char *argv[])
STL namespace.
int main(int argc, char *argv[])