CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 moduleFilterFile =
60  validation.count("moduleFilterFile") ? validation.get<std::string>("moduleFilterFile") : "";
61  float maxBadLumiPixel = validation.count("maxBadLumiPixel") ? validation.get<float>("maxBadLumiPixel") : 0.5;
62  float maxBadLumiStrip = validation.count("maxBadLumiStrip") ? validation.get<float>("maxBadLumiStrip") : 7.0;
63  std::string rlabel = validation.count("customrighttitle") ? validation.get<std::string>("customrighttitle") : "";
64  rlabel = merge_style.count("Rlabel") ? merge_style.get<std::string>("Rlabel") : rlabel;
65  std::string cmslabel = merge_style.count("CMSlabel") ? merge_style.get<std::string>("CMSlabel") : "INTERNAL";
66 
67  int minimum = validation.count("minimum") ? validation.get<int>("minimum") : 15;
68 
69  bool useFit = validation.count("usefit") ? validation.get<bool>("usefit") : false;
70  bool bigText = validation.count("bigtext") ? validation.get<bool>("bigtext") : false;
71 
72  TkAlStyle::legendheader = validation.count("legendheader") ? validation.get<std::string>("legendheader") : "";
74  validation.count("legendoptions") ? getVecTokenized(validation, "legendoptions", " ") : "mean rms";
75  if (TkAlStyle::toStatus(cmslabel) == CUSTOM)
76  TkAlStyle::set(CUSTOM, NONE, cmslabel, rlabel);
77  else
78  TkAlStyle::set(TkAlStyle::toStatus(cmslabel), NONE, "", rlabel);
79 
80  std::vector<int> moduleids;
81  if (validation.count("moduleid")) {
82  for (const auto& childTree : validation.get_child("moduleid")) {
83  moduleids.push_back(childTree.second.get_value<int>());
84  }
85  }
86 
87  //Set configuration string for CompareAlignments class in user defined order
88  TString filesAndLabels;
89  std::vector<std::pair<std::string, pt::ptree>> alignmentsOrdered;
90  for (const auto& childTree : alignments) {
91  alignmentsOrdered.push_back(childTree);
92  }
93  std::sort(alignmentsOrdered.begin(),
94  alignmentsOrdered.end(),
95  [](const std::pair<std::string, pt::ptree>& left, const std::pair<std::string, pt::ptree>& right) {
96  return left.second.get<int>("index") < right.second.get<int>("index");
97  });
98  for (const auto& childTree : alignmentsOrdered) {
99  filesAndLabels +=
100  childTree.second.get<std::string>("file") + "/DMR.root=" + childTree.second.get<std::string>("title") + "|" +
101  childTree.second.get<std::string>("color") + "|" + childTree.second.get<std::string>("style") + " , ";
102  }
103  filesAndLabels.Remove(filesAndLabels.Length() - 3);
104 
105  //Do file comparisons
106  CompareAlignments comparer(main_tree.get<std::string>("output"));
107  if (TkAlStyle::toStatus(cmslabel) == CUSTOM)
108  comparer.doComparison(filesAndLabels, "", cmslabel, rlabel, CUSTOM);
109  else
110  comparer.doComparison(filesAndLabels, "", "", rlabel, TkAlStyle::toStatus(cmslabel));
111 
112  //Create plots in user defined order
113  gStyle->SetTitleH(0.07);
114  gStyle->SetTitleW(1.00);
115  gStyle->SetTitleFont(132);
116 
118 
119  for (const auto& childTree : alignmentsOrdered) {
120  plotter.loadFileList((childTree.second.get<std::string>("file") + "/DMR.root").c_str(),
121  childTree.second.get<std::string>("title"),
122  childTree.second.get<int>("color"),
123  childTree.second.get<int>("style"));
124  }
125 
126  plotter.setOutputDir(main_tree.get<std::string>("output"));
127  plotter.useFitForDMRplots(useFit);
128  plotter.setTreeBaseDir("TrackHitFilter");
129  plotter.plotDMR(methods, minimum, curves, moduleFilterFile, maxBadLumiPixel, maxBadLumiStrip);
130  plotter.plotSurfaceShapes("coarse");
131  plotter.plotChi2((main_tree.get<std::string>("output") + "/" + "result.root").c_str());
132 
133  for (const int& moduleid : moduleids) {
134  plotter.residual_by_moduleID(moduleid);
135  }
136 
137  return EXIT_SUCCESS;
138 }
139 
140 #ifndef DOXYGEN_SHOULD_SKIP_THIS
141 int main(int argc, char* argv[]) { return exceptions<merge>(argc, argv); }
142 #endif
int main(int argc, char *argv[])
Definition: DMRmerge.cc:141
static void set(const PublicationStatus status, const Era era=NONE, const TString customTitle="", const TString customRightTitle="")
Definition: TkAlStyle.cc:275
static TString legendheader
Definition: TkAlStyle.h:101
int merge(int argc, char *argv[])
Definition: DMRmerge.cc:37
static TString legendoptions
Definition: TkAlStyle.h:102
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:83