CMS 3D CMS Logo

PVmerge.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 #include "TASImage.h"
18 
20 #include "Alignment/OfflineValidation/macros/FitPVResiduals.C"
22 
23 using namespace std;
24 using namespace AllInOneConfig;
25 
26 namespace pt = boost::property_tree;
27 
28 int merge(int argc, char* argv[]) {
29  // parse the command line
30 
32  options.helper(argc, argv);
33  options.parser(argc, argv);
34 
35  //Read in AllInOne json config
36  pt::ptree main_tree;
37  pt::read_json(options.config, main_tree);
38 
39  pt::ptree alignments = main_tree.get_child("alignments");
40  pt::ptree validation = main_tree.get_child("validation");
41  pt::ptree global_style;
42  pt::ptree merge_style;
43  global_style = main_tree.count("style") ? main_tree.get_child("style") : global_style;
44  merge_style = global_style.count("PV") && global_style.get_child("PV").count("merge")
45  ? global_style.get_child("PV").get_child("merge")
46  : global_style;
47 
48  //Read all configure variables and set default for missing keys
49  bool doMaps = validation.count("doMaps") ? validation.get<bool>("doMaps") : false;
50  bool stdResiduals = validation.count("stdResiduals") ? validation.get<bool>("stdResiduals") : true;
51  bool autoLimits = validation.count("autoLimits") ? validation.get<bool>("autoLimits") : false;
52 
53  float m_dxyPhiMax = validation.count("m_dxyPhiMax") ? validation.get<float>("m_dxyPhiMax") : 40;
54  float m_dzPhiMax = validation.count("m_dzPhiMax") ? validation.get<float>("m_dzPhiMax") : 40;
55  float m_dxyEtaMax = validation.count("m_dxyEtaMax") ? validation.get<float>("m_dxyEtaMax") : 40;
56  float m_dzEtaMax = validation.count("m_dzEtaMax") ? validation.get<float>("m_dzEtaMax") : 40;
57  float m_dxyPhiNormMax = validation.count("m_dxyPhiNormMax") ? validation.get<float>("m_dxyPhiNormMax") : 0.5;
58  float m_dzPhiNormMax = validation.count("m_dzPhiNormMax") ? validation.get<float>("m_dzPhiNormMax") : 0.5;
59  float m_dxyEtaNormMax = validation.count("m_dxyEtaNormMax") ? validation.get<float>("m_dxyEtaNormMax") : 0.5;
60  float m_dzEtaNormMax = validation.count("m_dzEtaNormMax") ? validation.get<float>("m_dzEtaNormMax") : 0.5;
61  float w_dxyPhiMax = validation.count("w_dxyPhiMax") ? validation.get<float>("w_dxyPhiMax") : 150;
62  float w_dzPhiMax = validation.count("w_dzPhiMax") ? validation.get<float>("w_dzPhiMax") : 150;
63  float w_dxyEtaMax = validation.count("w_dxyEtaMax") ? validation.get<float>("w_dxyEtaMax") : 150;
64  float w_dzEtaMax = validation.count("w_dzEtaMax") ? validation.get<float>("w_dzEtaMax") : 1000;
65  float w_dxyPhiNormMax = validation.count("w_dxyPhiNormMax") ? validation.get<float>("w_dxyPhiNormMax") : 1.8;
66  float w_dzPhiNormMax = validation.count("w_dzPhiNormMax") ? validation.get<float>("w_dzPhiNormMax") : 1.8;
67  float w_dxyEtaNormMax = validation.count("w_dxyEtaNormMax") ? validation.get<float>("w_dxyEtaNormMax") : 1.8;
68  float w_dzEtaNormMax = validation.count("w_dzEtaNormMax") ? validation.get<float>("w_dzEtaNormMax") : 1.8;
69  int iov = validation.count("IOV") ? validation.get<int>("IOV") : 1;
70  std::string rlabel = validation.count("customrighttitle") ? validation.get<std::string>("customrighttitle") : "";
71  rlabel = merge_style.count("Rlabel") ? merge_style.get<std::string>("Rlabel") : rlabel;
72  std::string cmslabel = merge_style.count("CMSlabel") ? merge_style.get<std::string>("CMSlabel") : "INTERNAL";
73  if (TkAlStyle::toStatus(cmslabel) == CUSTOM)
74  TkAlStyle::set(CUSTOM, NONE, cmslabel, rlabel);
75  else
76  TkAlStyle::set(TkAlStyle::toStatus(cmslabel), NONE, "", rlabel);
77 
78  //Create plots
79  // initialize the plot y-axis ranges
80  thePlotLimits->init(m_dxyPhiMax, // mean of dxy vs Phi
81  m_dzPhiMax, // mean of dz vs Phi
82  m_dxyEtaMax, // mean of dxy vs Eta
83  m_dzEtaMax, // mean of dz vs Eta
84  m_dxyPhiNormMax, // mean of dxy vs Phi (norm)
85  m_dzPhiNormMax, // mean of dz vs Phi (norm)
86  m_dxyEtaNormMax, // mean of dxy vs Eta (norm)
87  m_dzEtaNormMax, // mean of dz vs Eta (norm)
88  w_dxyPhiMax, // width of dxy vs Phi
89  w_dzPhiMax, // width of dz vs Phi
90  w_dxyEtaMax, // width of dxy vs Eta
91  w_dzEtaMax, // width of dz vs Eta
92  w_dxyPhiNormMax, // width of dxy vs Phi (norm)
93  w_dzPhiNormMax, // width of dz vs Phi (norm)
94  w_dxyEtaNormMax, // width of dxy vs Eta (norm)
95  w_dzEtaNormMax // width of dz vs Eta (norm)
96  );
97 
98  //Load file list in user defined order
99  std::vector<std::pair<std::string, pt::ptree>> alignmentsOrdered;
100  for (const auto& childTree : alignments) {
101  alignmentsOrdered.push_back(childTree);
102  }
103  std::sort(alignmentsOrdered.begin(),
104  alignmentsOrdered.end(),
105  [](const std::pair<std::string, pt::ptree>& left, const std::pair<std::string, pt::ptree>& right) {
106  return left.second.get<int>("index") < right.second.get<int>("index");
107  });
108  for (const auto& childTree : alignmentsOrdered) {
109  if (childTree.second.get<bool>("isMC")) {
110  loadFileList(
111  (childTree.second.get<string>("file") + Form("/PVValidation_%s_%d.root", childTree.first.c_str(), 1)).c_str(),
112  "PVValidation",
113  childTree.second.get<string>("title"),
114  childTree.second.get<int>("color"),
115  childTree.second.get<int>("style"));
116  } else {
117  loadFileList(
118  (childTree.second.get<string>("file") + Form("/PVValidation_%s_%d.root", childTree.first.c_str(), iov))
119  .c_str(),
120  "PVValidation",
121  childTree.second.get<string>("title"),
122  childTree.second.get<int>("color"),
123  childTree.second.get<int>("style"));
124  }
125  }
126 
127  //And finally fit
128  FitPVResiduals("", stdResiduals, doMaps, "", autoLimits, cmslabel, rlabel);
129 
130  return EXIT_SUCCESS;
131 }
132 
133 #ifndef DOXYGEN_SHOULD_SKIP_THIS
134 int main(int argc, char* argv[]) { return exceptions<merge>(argc, argv); }
135 #endif
static void set(const PublicationStatus status, const Era era=NONE, const TString customTitle="", const TString customRightTitle="")
Definition: TkAlStyle.cc:240
int merge(int argc, char *argv[])
Definition: PVmerge.cc:28
int main(int argc, char *argv[])
Definition: PVmerge.cc:134
Definition: TkAlStyle.h:43
static PublicationStatus toStatus(std::string _status)
Definition: TkAlStyle.cc:48