Logo ROOT  
Reference Guide
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////////////////////////////////////////////////////////////////////////////////
12
13
14
15#include <string>
16#include <exception>
17#include <vector>
18
19#include <TROOT.h>
20
23#include "HFMsgService.h"
24#include "hist2workspaceCommandLineOptionsHelp.h"
25
26namespace RooStats {
27 namespace HistFactory {
28 void fastDriver(std::string const& input, HistoToWorkspaceFactoryFast::Configuration const& cfg) {
29
30 // Create the initial list of measurements and channels
31 std::vector< HistFactory::Measurement > measurement_list;
32 // std::vector< HistFactory::Channel > channel_list;
33
34 // Fill them using the XML parser
36 measurement_list = xmlParser.GetMeasurementsFromXML( input );
37
38 // At this point, we have all the information we need
39 // from the xml files.
40
41 // We will make the measurements 1-by-1
42 for(unsigned int i = 0; i < measurement_list.size(); ++i) {
43 HistFactory::Measurement measurement = measurement_list.at(i);
44 measurement.CollectHistograms();
45 MakeModelAndMeasurementFast(measurement, cfg);
46 }
47
48 return;
49
50 }
51 } // namespace RooStats
52} // namespace HistFactory
53
54/**
55 * \ingroup HistFactory
56 * main function of the hist2workspace executable.
57 * It creates RooFit models from an xml config and files with histograms.
58 * See MakeModelAndMeasurementFast(), for further instructions.
59 * \param[in] argc number of CLI arguments
60 * \param[in] argv pointer to arguments
61 *
62 * -h Help
63 * -v Switch HistFactory message stream to INFO level.
64 * -vv Switch HistFactory message stream to DEBUG level.
65 * -disable_binned_fit_optimization Disable the binned fit optimization used in HistFactory since ROOT 6.28.
66 */
67int main(int argc, char** argv) {
68
69 if( !(argc > 1) ) {
70 std::cerr << "need input file" << std::endl;
71 exit(1);
72 }
73
74 //Switch off ROOT histogram memory management
75 gROOT->SetMustClean(false);
77 cxcoutIHF << "hist2workspace is less verbose now. Use -v and -vv for more details." << std::endl;
81
82 std::string driverArg;
84
85 for (int i=1; i < argc; ++i) {
86 std::string input = argv[i];
87
88 if (input == "-h" || input == "--help"){
89 fprintf(stderr, kCommandLineOptionsHelp);
90 return 0;
91 }
92
93 if (input == "-v") {
96 continue;
97 }
98
99 if (input == "-vv") {
102 continue;
103 }
104
105 if(input == "-disable_binned_fit_optimization") {
106 cfg.binnedFitOptimization = false;
107 continue;
108 }
109
110 driverArg = argv[i];
111 }
112
113 try {
114 RooStats::HistFactory::fastDriver(driverArg, cfg);
115 }
116 catch(const std::string &str) {
117 std::cerr << "hist2workspace - Caught exception: " << str << std::endl ;
118 return 1;
119 }
120 catch( const std::exception& e ) {
121 std::cerr << "hist2workspace - Caught Exception: " << e.what() << std::endl;
122 return 1;
123 }
124 catch(...) {
125 std::cerr << "hist2workspace - Caught Exception" << std::endl;
126 return 1;
127 }
128
129
130 return 0;
131}
#define cxcoutIHF
Definition: HFMsgService.h:17
#define e(i)
Definition: RSha256.hxx:103
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
#define gROOT
Definition: TROOT.h:404
static RooMsgService & instance()
Return reference to singleton instance.
StreamConfig & getStream(Int_t id)
TODO Add documentation.
Definition: ConfigParser.h:28
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.
Definition: TDirectory.cxx:172
int main(int argc, char **argv)
main function of the hist2workspace executable.
RooWorkspace * MakeModelAndMeasurementFast(RooStats::HistFactory::Measurement &measurement, HistoToWorkspaceFactoryFast::Configuration const &cfg={})
@ HistFactory
Definition: RooGlobalFunc.h:65
void fastDriver(std::string const &input, HistoToWorkspaceFactoryFast::Configuration const &cfg)
Namespace for the RooStats classes.
Definition: Asimov.h:19
void addTopic(RooFit::MsgTopic newTopic)