DESY Hbb Analysis Framework
plotscomp_config.h
Go to the documentation of this file.
1 #ifndef Analysis_Tools_plotscomp_config_h_
2 #define Analysis_Tools_plotscomp_config_h_
3 
4 #include "boost/program_options.hpp"
5 #include "boost/algorithm/string.hpp"
6 #include <string>
7 #include <iostream>
8 #include <fstream>
9 #include <vector>
10 
11 int plotscomp_config(int argc, char * argv[]);
12 
13 //std::string cfg_;
14 
15 // if file, give up to 4 histograms
16 std::vector<std::string> files_;
17 std::vector<std::string> histos_;
18 std::vector<std::string> titles_;
19 
20 std::string file_;
21 std::string hist1_;
22 std::string hist2_;
23 
24 std::string hist_;
25 std::string file1_;
26 std::string file2_;
27 
28 std::string title_;
29 std::string legend1_;
30 std::string legend2_;
31 
32 std::string outplot_;
33 
34 float min_,max_;
35 
36 float scale_;
37 
38 bool logx_;
39 bool logy_;
40 bool app_;
41 
42 
43 
44 int plotscomp_config(int argc, char * argv[])
45 {
46  app_ = true;
47  logx_ = false;
48  logy_ = false;
49  try
50  {
51  namespace po = boost::program_options;
52  po::options_description desc("Options");
53  desc.add_options()
54  ("help,h" , "Show help messages")
55  ("bkg,b" , "Run in the background")
56  ("logx" , "x-axis in log scale")
57  ("logy" , "y-axis in log scale")
58  ("files" , po::value<std::vector<std::string> >(&files_)->multitoken(),"list of files")
59  ("histos" , po::value<std::vector<std::string> >(&histos_)->multitoken(),"list of histograms")
60  ("titles" , po::value<std::vector<std::string> >(&titles_)->multitoken(),"titles of histograms")
61  ("title,t" , po::value <std::string> (&title_) -> default_value("") , "Title of the histogram")
62  ("legend1" , po::value <std::string> (&legend1_)-> default_value("histo 1") , "Legend of the histogram 1")
63  ("legend2" , po::value <std::string> (&legend2_)-> default_value("histo 2") , "Legend of the histogram 2")
64  ("scale,s" , po::value <float> (&scale_) -> default_value(1) , "Scale factor for the 2nd histogram")
65  ("min" , po::value <float> (&min_) -> default_value(-1) , "Min value histogram range")
66  ("max" , po::value <float> (&max_) -> default_value(-2) , "Max value histogram range")
67  ("file,f" , po::value <std::string> (&file_) -> default_value("") , "File with up to 2 histograms to compare")
68  ("hist1" , po::value <std::string> (&hist1_ ) -> default_value("") , "1st histogram name in file")
69  ("hist2" , po::value <std::string> (&hist2_ ) -> default_value("") , "2nd histogram name in file")
70  ("hist,h" , po::value <std::string> (&hist_) -> default_value("") , "Histogram name common to the different files")
71  ("file1" , po::value <std::string> (&file1_) -> default_value("") , "1st file with 1 histogram to compare")
72  ("file2" , po::value <std::string> (&file2_) -> default_value("") , "2nd file with 1 histogram to compare")
73  ("output" , po::value <std::string> (&outplot_)-> default_value("") , "name of the output plot");
74 
75 // ("config,c",po::value<std::string>(&cfg_),"Configuration file name");
76 
77 // po::options_description config("Configuration");
78 // config.add_options()
79 // ("file",po::value <std::string> (&file_) ->default_value(""),"File with up to 2 histograms to compare")
80 // ("hist",po::value <std::string> (&hist_) ->default_value(""),"Histogram name common to the different files");
81 
82  po::variables_map vm;
83  try
84  {
85  po::store(po::parse_command_line(argc, argv, desc), vm); // can throw
86  // --help option
87 
88  if ( vm.count("help") )
89  {
90  std::cout << "PlotsCompare macro" << std::endl
91  << desc << std::endl;
92 // << config << std::endl;
93  return 1;
94  }
95  if ( vm.count("logx") ) logx_ = true;
96  if ( vm.count("logy") ) logy_ = true;
97  if ( vm.count("bkg") ) app_ = false;
98 
99  po::notify(vm);
100 
101 // std::ifstream cfg_s(cfg_.c_str());
102 // po::store(po::parse_config_file(cfg_s, config), vm); // can throw
103 // if ( vm.count("config") )
104 // {
105 //
106 // }
107  po::notify(vm);
108  }
109  catch(po::error& e)
110  {
111  std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
112  std::cerr << desc << std::endl;
113  return -1;
114  }
115 
116  }
117  catch(std::exception& e)
118  {
119  std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
120  return -1;
121  }
122 
123  return 0;
124 }
125 
126 
127 #endif
std::vector< std::string > titles_
std::vector< std::string > histos_
std::string hist1_
std::string file1_
float min_
std::string file2_
std::string legend2_
std::string title_
std::string legend1_
std::string outplot_
std::string file_
std::string hist_
float max_
bool app_
int plotscomp_config(int argc, char *argv[])
float scale_
std::string hist2_
bool logx_
std::vector< std::string > files_
bool logy_