ra4_stats  0341147a0dc35f80f4e12c6003afb76a38e2ed6e
dump_workspace.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 
4 #include "TFile.h"
5 #include "TIterator.h"
6 
7 #include "RooArgSet.h"
8 #include "RooRealVar.h"
9 
10 #include "RooStats/ModelConfig.h"
11 
12 using namespace std;
13 using namespace RooStats;
14 
15 int main(int argc, char *argv[]){
16  for(int iarg = 1; iarg < argc; ++iarg){
17  TFile file(argv[iarg], "read");
18  if(!file.IsOpen()) continue;
19  RooWorkspace *w = static_cast<RooWorkspace*>(file.Get("w"));
20  if(w == nullptr) continue;
21  w->Print();
22 
23  cout << fixed << setprecision(2);
24 
25  cout << "Constants:" << endl;
26  const RooArgSet &vars = w->allVars();
27  TIterator *iter_ptr = vars.createIterator();
28  for(; iter_ptr != nullptr && *(*iter_ptr) != nullptr; iter_ptr->Next()){
29  RooAbsArg *var = static_cast<RooAbsArg*>(*(*iter_ptr));
30  if(var == nullptr) continue;
31  if(!var->isConstant()) continue;
32  var->Print();
33  }
34 
35  cout << endl << "Fundamental variables:" << endl;
36  iter_ptr->Reset();
37  for(; iter_ptr != nullptr && *(*iter_ptr) != nullptr; iter_ptr->Next()){
38  RooAbsArg *var = static_cast<RooAbsArg*>(*(*iter_ptr));
39  if(var == nullptr) continue;
40  if(var->isConstant()) continue;
41  var->Print();
42  }
43 
44  cout << endl << "Yields: " << endl;
45  cout
46  << ' ' << setw(64) << "Name"
47  << ' ' << setw(12) << "Background"
48  << ' ' << setw(12) << "Signal"
49  << ' ' << setw(12) << "Total"
50  << ' ' << setw(12) << "Observed"
51  << endl;
52 
53  iter_ptr->Reset();
54  for(; iter_ptr != nullptr && *(*iter_ptr) != nullptr; iter_ptr->Next()){
55  RooAbsArg *var = static_cast<RooAbsArg*>(*(*iter_ptr));
56  if(var == nullptr) continue;
57  string nobs_name = var->GetName();
58  if(nobs_name.substr(0, 9) != "nobs_BLK_") continue;
59  string nbkg_name = nobs_name;
60  string nsig_name = nobs_name;
61  nbkg_name.replace(1, 3, "bkg");
62  nsig_name.replace(1, 3, "sig");
63  RooRealVar *nobs_arg = static_cast<RooRealVar*>(w->arg(nobs_name.c_str()));
64  RooRealVar *nbkg_arg = static_cast<RooRealVar*>(w->arg(nbkg_name.c_str()));
65  RooRealVar *nsig_arg = static_cast<RooRealVar*>(w->arg(nsig_name.c_str()));
66  if(nobs_arg==nullptr || nbkg_arg==nullptr || nsig_arg==nullptr) continue;
67  double nobs = nobs_arg->getVal();
68  double nbkg = nbkg_arg->getVal();
69  double nsig = nsig_arg->getVal();
70  cout
71  << ' ' << setw(64) << nobs_name.substr(5)
72  << ' ' << setw(12) << nbkg
73  << ' ' << setw(12) << nsig
74  << ' ' << setw(12) << nbkg+nsig
75  << ' ' << setw(12) << nobs
76  << endl;
77  }
78 
79  }
80 }
STL namespace.
int main(int argc, char *argv[])