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);
115 cxcoutIHF << "hist2workspace is less verbose now. Use -v and -vv for more details." << std::endl;
119
120 std::string driverArg;
122
123 for (int i=1; i < argc; ++i) {
124 std::string input = argv[i];
125
126 if (input == "-h" || input == "--help"){
127 fprintf(stderr, kCommandLineOptionsHelp);
128 return 0;
129 }
130
131 if (input == "-v") {
134 continue;
135 }
136
137 if (input == "-vv") {
140 continue;
141 }
142
143 if(input == "-disable_binned_fit_optimization") {
144 cfg.binnedFitOptimization = false;
145 continue;
146 }
147
148 driverArg = argv[i];
149 }
150
151 RooStats::HistFactory::fastDriver(driverArg, cfg);
152
153 return 0;
154}
#define cxcoutIHF
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
#define gROOT
Definition TROOT.h:417
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...
void CollectHistograms()
The most common way to add histograms to channels is to have them stored in ROOT files and to give Hi...
static constexpr const char kCommandLineOptionsHelp[]
int main()
Definition main.cpp:18
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:67
void addTopic(RooFit::MsgTopic newTopic)