CMS 3D CMS Logo

DMRmerge.cc
Go to the documentation of this file.
1 #include <cstdlib>
2 #include <string>
3 #include <iostream>
4 #include <numeric>
5 #include <functional>
6 
7 #include "exceptions.h"
8 #include "toolbox.h"
9 #include "Options.h"
10 
11 #include "boost/filesystem.hpp"
12 #include "boost/property_tree/ptree.hpp"
13 #include "boost/property_tree/json_parser.hpp"
14 #include "boost/optional.hpp"
15 
16 #include "TString.h"
17 
21 
22 using namespace std;
23 using namespace AllInOneConfig;
24 
25 namespace pt = boost::property_tree;
26 
28  std::string s;
29 
30  for (const auto& childTree : tree.get_child(name)) {
31  s += childTree.second.get_value<std::string>() + token;
32  }
33 
34  return s.substr(0, s.size() - token.size());
35 }
36 
37 int merge(int argc, char* argv[]) {
38  // parse the command line
40  options.helper(argc, argv);
41  options.parser(argc, argv);
42 
43  //Read in AllInOne json config
44  pt::ptree main_tree;
45  pt::read_json(options.config, main_tree);
46 
47  pt::ptree alignments = main_tree.get_child("alignments");
48  pt::ptree validation = main_tree.get_child("validation");
49  pt::ptree global_style;
50  pt::ptree merge_style;
51  global_style = main_tree.count("style") ? main_tree.get_child("style") : global_style;
52  merge_style = global_style.count("DMR") && global_style.get_child("DMR").count("merge")
53  ? global_style.get_child("DMR").get_child("merge")
54  : global_style;
55 
56  //Read all configure variables and set default for missing keys
57  std::string methods = validation.count("methods") ? getVecTokenized(validation, "methods", ",") : "median,rmsNorm";
58  std::string curves = validation.count("curves") ? getVecTokenized(validation, "curves", ",") : "plain";
59  std::string rlabel = validation.count("customrighttitle") ? validation.get<std::string>("customrighttitle") : "";
60  rlabel = merge_style.count("Rlabel") ? merge_style.get<std::string>("Rlabel") : rlabel;
61  std::string cmslabel = merge_style.count("CMSlabel") ? merge_style.get<std::string>("CMSlabel") : "INTERNAL";
62 
63  int minimum = validation.count("minimum") ? validation.get<int>("minimum") : 15;
64 
65  bool useFit = validation.count("usefit") ? validation.get<bool>("usefit") : false;
66  bool bigText = validation.count("bigtext") ? validation.get<bool>("bigtext") : false;
67 
68  TkAlStyle::legendheader = validation.count("legendheader") ? validation.get<std::string>("legendheader") : "";
70  validation.count("legendoptions") ? getVecTokenized(validation, "legendoptions", " ") : "mean rms";
71  if (TkAlStyle::toStatus(cmslabel) == CUSTOM)
72  TkAlStyle::set(CUSTOM, NONE, cmslabel, rlabel);
73  else
74  TkAlStyle::set(TkAlStyle::toStatus(cmslabel), NONE, "", rlabel);
75 
76  std::vector<int> moduleids;
77  if (validation.count("moduleid")) {
78  for (const auto& childTree : validation.get_child("moduleid")) {
79  moduleids.push_back(childTree.second.get_value<int>());
80  }
81  }
82 
83  //Set configuration string for CompareAlignments class in user defined order
84  TString filesAndLabels;
85  std::vector<std::pair<std::string, pt::ptree>> alignmentsOrdered;
86  for (const auto& childTree : alignments) {
87  alignmentsOrdered.push_back(childTree);
88  }
89  std::sort(alignmentsOrdered.begin(),
90  alignmentsOrdered.end(),
91  [](const std::pair<std::string, pt::ptree>& left, const std::pair<std::string, pt::ptree>& right) {
92  return left.second.get<int>("index") < right.second.get<int>("index");
93  });
94  for (const auto& childTree : alignmentsOrdered) {
95  filesAndLabels +=
96  childTree.second.get<std::string>("file") + "/DMR.root=" + childTree.second.get<std::string>("title") + "|" +
97  childTree.second.get<std::string>("color") + "|" + childTree.second.get<std::string>("style") + " , ";
98  }
99  filesAndLabels.Remove(filesAndLabels.Length() - 3);
100 
101  //Do file comparisons
102  CompareAlignments comparer(main_tree.get<std::string>("output"));
103  if (TkAlStyle::toStatus(cmslabel) == CUSTOM)
104  comparer.doComparison(filesAndLabels, "", cmslabel, rlabel, CUSTOM);
105  else
106  comparer.doComparison(filesAndLabels, "", "", rlabel, TkAlStyle::toStatus(cmslabel));
107 
108  //Create plots in user defined order
109  gStyle->SetTitleH(0.07);
110  gStyle->SetTitleW(1.00);
111  gStyle->SetTitleFont(132);
112 
114 
115  for (const auto& childTree : alignmentsOrdered) {
116  plotter.loadFileList((childTree.second.get<std::string>("file") + "/DMR.root").c_str(),
117  childTree.second.get<std::string>("title"),
118  childTree.second.get<int>("color"),
119  childTree.second.get<int>("style"));
120  }
121 
122  plotter.setOutputDir(main_tree.get<std::string>("output"));
123  plotter.useFitForDMRplots(useFit);
124  plotter.setTreeBaseDir("TrackHitFilter");
125  plotter.plotDMR(methods, minimum, curves);
126  plotter.plotSurfaceShapes("coarse");
127  plotter.plotChi2((main_tree.get<std::string>("output") + "/" + "result.root").c_str());
128 
129  for (const int& moduleid : moduleids) {
130  plotter.residual_by_moduleID(moduleid);
131  }
132 
133  return EXIT_SUCCESS;
134 }
135 
136 #ifndef DOXYGEN_SHOULD_SKIP_THIS
137 int main(int argc, char* argv[]) { return exceptions<merge>(argc, argv); }
138 #endif
int main(int argc, char *argv[])
Definition: DMRmerge.cc:137
static void set(const PublicationStatus status, const Era era=NONE, const TString customTitle="", const TString customRightTitle="")
Definition: TkAlStyle.cc:240
static TString legendheader
Definition: TkAlStyle.h:91
int merge(int argc, char *argv[])
Definition: DMRmerge.cc:37
static TString legendoptions
Definition: TkAlStyle.h:92
Class PlotAlignmentValidation Class used as the last step for Offline Track Validation tool...
std::string getVecTokenized(pt::ptree &tree, const std::string &name, const std::string &token)
Definition: DMRmerge.cc:27
void doComparison(TString namesandlabels, TString legendheader="", TString lefttitle="", TString righttitle="", PublicationStatus status=INTERNAL, bool bigtext=false)
Definition: tree.py:1
Definition: TkAlStyle.h:43
static PublicationStatus toStatus(std::string _status)
Definition: TkAlStyle.cc:48