Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist2workspace.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Author: Kyle Cranmer, George Lewis
3/*************************************************************************
4 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#include <string>
12#include <exception>
13#include <vector>
14
15#include <TROOT.h>
16
19#include "HFMsgService.h"
20
21// When updating the docs for the hist2workspace executable, please recreate
22// the Python file with the get_argparse() function (code below), and run the
23// following argparse2help.py invocations:
24//
25// 1. To generate the string in the kCommandLineOptionsHelp variable
26//
27// python cmake/scripts/argparse2help.py hist2workspace-argparse.py hist2workspaceCommandLineOptionsHelp.h
28//
29// 2. Recreate the man file that should be put in roofit/man/man1/:
30//
31// python cmake/scripts/argparse2help.py hist2workspace-argparse.py hist2workspace.1
32//
33// The content of hist2workspace-argparse.py is:
34//
35// ```Python
36// import argparse
37//
38//
39// def get_argparse():
40// DESCRIPTION = "hist2workspace is a utility to create RooFit/RooStats workspace from histograms"
41// parser = argparse.ArgumentParser(prog="hist2workspace", description=DESCRIPTION)
42// parser.add_argument("-v", help="switch HistFactory message stream to INFO level", action="store_true")
43// parser.add_argument("-vv", help="switch HistFactory message stream to DEBUG level", action="store_true")
44// parser.add_argument(
45// "-disable_binned_fit_optimization",
46// help="disable the binned fit optimization used in HistFactory since ROOT 6.28",
47// action="store_true",
48// )
49// return parser
50// ```
51
52constexpr static const char kCommandLineOptionsHelp[] = R"RAW(
53usage: hist2workspace [-h] [-v] [-vv] [-disable_binned_fit_optimization]
54
55hist2workspace is a utility to create RooFit/RooStats workspace from histograms
56
57OPTIONS:
58 -h, --help show this help message and exit
59 -v switch HistFactory message stream to INFO level
60 -vv switch HistFactory message stream to DEBUG level
61 -disable_binned_fit_optimization disable the binned fit optimization used in HistFactory since ROOT 6.28
62)RAW";
63
64
65namespace RooStats {
66 namespace HistFactory {
67 void fastDriver(std::string const& input, HistoToWorkspaceFactoryFast::Configuration const& cfg) {
68
69 // Create the initial list of measurements and channels
70 std::vector< HistFactory::Measurement > measurement_list;
71 // std::vector< HistFactory::Channel > channel_list;
72
73 // Fill them using the XML parser
75 measurement_list = xmlParser.GetMeasurementsFromXML( input );
76
77 // At this point, we have all the information we need
78 // from the xml files.
79
80 // We will make the measurements 1-by-1
81 for(unsigned int i = 0; i < measurement_list.size(); ++i) {
82 HistFactory::Measurement measurement = measurement_list.at(i);
83 measurement.CollectHistograms();
84 MakeModelAndMeasurementFast(measurement, cfg);
85 }
86
87 return;
88
89 }
90 } // namespace RooStats
91} // namespace HistFactory
92
93/**
94 * \ingroup HistFactory
95 * main function of the hist2workspace executable.
96 * It creates RooFit models from an xml config and files with histograms.
97 * See MakeModelAndMeasurementFast(), for further instructions.
98 * \param[in] argc number of CLI arguments
99 * \param[in] argv pointer to arguments
100 *
101 * -h Help
102 * -v Switch HistFactory message stream to INFO level.
103 * -vv Switch HistFactory message stream to DEBUG level.
104 * -disable_binned_fit_optimization Disable the binned fit optimization used in HistFactory since ROOT 6.28.
105 */
106int main(int argc, char** argv) {
107
108 if( !(argc > 1) ) {
109 std::cerr << "need input file" << std::endl;
110 exit(1);
111 }
112
113 //Switch off ROOT histogram memory management
114 gROOT->SetMustClean(false);
116 cxcoutIHF << "hist2workspace is less verbose now. Use -v and -vv for more details." << std::endl;
120
121 std::string driverArg;
123
124 for (int i=1; i < argc; ++i) {
125 std::string input = argv[i];
126
127 if (input == "-h" || input == "--help"){
128 fprintf(stderr, kCommandLineOptionsHelp);
129 return 0;
130 }
131
132 if (input == "-v") {
135 continue;
136 }
137
138 if (input == "-vv") {
141 continue;
142 }
143
144 if(input == "-disable_binned_fit_optimization") {
145 cfg.binnedFitOptimization = false;
146 continue;
147 }
148
149 driverArg = argv[i];
150 }
151
152 RooStats::HistFactory::fastDriver(driverArg, cfg);
153
154 return 0;
155}
#define cxcoutIHF
int main()
Definition Prototype.cxx:12
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
#define gROOT
Definition TROOT.h:406
static RooMsgService & instance()
Return reference to singleton instance.
StreamConfig & getStream(Int_t id)
std::vector< RooStats::HistFactory::Measurement > GetMeasurementsFromXML(std::string input)
The "main" method.
The RooStats::HistFactory::Measurement class can be used to construct a model by combining multiple R...
Definition Measurement.h:31
void CollectHistograms()
The most common way to add histograms to channels is to have them stored in ROOT files and to give Hi...
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add objects like histograms, TGraph2D, etc in memory.
static constexpr const char kCommandLineOptionsHelp[]
void fastDriver(std::string const &input, HistoToWorkspaceFactoryFast::Configuration const &cfg)
RooFit::OwningPtr< RooWorkspace > MakeModelAndMeasurementFast(RooStats::HistFactory::Measurement &measurement, HistoToWorkspaceFactoryFast::Configuration const &cfg={})
Namespace for the RooStats classes.
Definition CodegenImpl.h:58
void addTopic(RooFit::MsgTopic newTopic)