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_dxyPtMax = validation.count("m_dxyPtMax") ? validation.get<float>("m_dxyPtMax") : 40;
58  float m_dzPtMax = validation.count("m_dzPtMax") ? validation.get<float>("m_dzPtMax") : 40;
59  float m_dxyPhiNormMax = validation.count("m_dxyPhiNormMax") ? validation.get<float>("m_dxyPhiNormMax") : 0.5;
60  float m_dzPhiNormMax = validation.count("m_dzPhiNormMax") ? validation.get<float>("m_dzPhiNormMax") : 0.5;
61  float m_dxyEtaNormMax = validation.count("m_dxyEtaNormMax") ? validation.get<float>("m_dxyEtaNormMax") : 0.5;
62  float m_dzEtaNormMax = validation.count("m_dzEtaNormMax") ? validation.get<float>("m_dzEtaNormMax") : 0.5;
63  float m_dxyPtNormMax = validation.count("m_dxyPtNormMax") ? validation.get<float>("m_dxyPtNormMax") : 0.5;
64  float m_dzPtNormMax = validation.count("m_dzPtNormMax") ? validation.get<float>("m_dzPtNormMax") : 0.5;
65  float w_dxyPhiMax = validation.count("w_dxyPhiMax") ? validation.get<float>("w_dxyPhiMax") : 150;
66  float w_dzPhiMax = validation.count("w_dzPhiMax") ? validation.get<float>("w_dzPhiMax") : 150;
67  float w_dxyEtaMax = validation.count("w_dxyEtaMax") ? validation.get<float>("w_dxyEtaMax") : 150;
68  float w_dzEtaMax = validation.count("w_dzEtaMax") ? validation.get<float>("w_dzEtaMax") : 1000;
69  float w_dxyPtMax = validation.count("w_dxyPtMax") ? validation.get<float>("w_dxyPtMax") : 150;
70  float w_dzPtMax = validation.count("w_dzPtMax") ? validation.get<float>("w_dzPtMax") : 150;
71  float w_dxyPhiNormMax = validation.count("w_dxyPhiNormMax") ? validation.get<float>("w_dxyPhiNormMax") : 1.8;
72  float w_dzPhiNormMax = validation.count("w_dzPhiNormMax") ? validation.get<float>("w_dzPhiNormMax") : 1.8;
73  float w_dxyEtaNormMax = validation.count("w_dxyEtaNormMax") ? validation.get<float>("w_dxyEtaNormMax") : 1.8;
74  float w_dzEtaNormMax = validation.count("w_dzEtaNormMax") ? validation.get<float>("w_dzEtaNormMax") : 1.8;
75  float w_dxyPtNormMax = validation.count("w_dxyPtNormMax") ? validation.get<float>("w_dxyPtNormMax") : 1.8;
76  float w_dzPtNormMax = validation.count("w_dzPtNormMax") ? validation.get<float>("w_dzPtNormMax") : 1.8;
77  int iov = validation.count("IOV") ? validation.get<int>("IOV") : 1;
78  std::string rlabel = validation.count("customrighttitle") ? validation.get<std::string>("customrighttitle") : "";
79  rlabel = merge_style.count("Rlabel") ? merge_style.get<std::string>("Rlabel") : rlabel;
80  std::string cmslabel = merge_style.count("CMSlabel") ? merge_style.get<std::string>("CMSlabel") : "INTERNAL";
81  if (TkAlStyle::toStatus(cmslabel) == CUSTOM)
82  TkAlStyle::set(CUSTOM, NONE, cmslabel, rlabel);
83  else
84  TkAlStyle::set(TkAlStyle::toStatus(cmslabel), NONE, "", rlabel);
85 
86  //Create plots
87  // initialize the plot y-axis ranges
88  thePlotLimits->init(m_dxyPhiMax, // mean of dxy vs Phi
89  m_dzPhiMax, // mean of dz vs Phi
90  m_dxyEtaMax, // mean of dxy vs Eta
91  m_dzEtaMax, // mean of dz vs Eta
92  m_dxyPtMax, // mean of dxy vs Pt
93  m_dzPtMax, // mean of dz vs Pt
94  m_dxyPhiNormMax, // mean of dxy vs Phi (norm)
95  m_dzPhiNormMax, // mean of dz vs Phi (norm)
96  m_dxyEtaNormMax, // mean of dxy vs Eta (norm)
97  m_dzEtaNormMax, // mean of dz vs Eta (norm)
98  m_dxyPtNormMax, // mean of dxy vs Pt (norm)
99  m_dzPtNormMax, // mean of dz vs Pt (norm)
100  w_dxyPhiMax, // width of dxy vs Phi
101  w_dzPhiMax, // width of dz vs Phi
102  w_dxyEtaMax, // width of dxy vs Eta
103  w_dzEtaMax, // width of dz vs Eta
104  w_dxyPtMax, // width of dxy vs Pt
105  w_dzPtMax, // width of dz vs Pt
106  w_dxyPhiNormMax, // width of dxy vs Phi (norm)
107  w_dzPhiNormMax, // width of dz vs Phi (norm)
108  w_dxyEtaNormMax, // width of dxy vs Eta (norm)
109  w_dzEtaNormMax, // width of dz vs Eta (norm)
110  w_dxyPtNormMax, // width of dxy vs Pt (norm)
111  w_dzPtNormMax // width of dz vs Pt (norm)
112  );
113 
114  //Load file list in user defined order
115  std::vector<std::pair<std::string, pt::ptree>> alignmentsOrdered;
116  for (const auto& childTree : alignments) {
117  alignmentsOrdered.push_back(childTree);
118  }
119  std::sort(alignmentsOrdered.begin(),
120  alignmentsOrdered.end(),
121  [](const std::pair<std::string, pt::ptree>& left, const std::pair<std::string, pt::ptree>& right) {
122  return left.second.get<int>("index") < right.second.get<int>("index");
123  });
124  for (const auto& childTree : alignmentsOrdered) {
125  if (childTree.second.get<bool>("isMC")) {
126  loadFileList(
127  (childTree.second.get<string>("file") + Form("/PVValidation_%s_%d.root", childTree.first.c_str(), 1)).c_str(),
128  "PVValidation",
129  childTree.second.get<string>("title"),
130  childTree.second.get<int>("color"),
131  childTree.second.get<int>("style"));
132  } else {
133  loadFileList(
134  (childTree.second.get<string>("file") + Form("/PVValidation_%s_%d.root", childTree.first.c_str(), iov))
135  .c_str(),
136  "PVValidation",
137  childTree.second.get<string>("title"),
138  childTree.second.get<int>("color"),
139  childTree.second.get<int>("style"));
140  }
141  }
142 
143  //And finally fit
144  FitPVResiduals("", stdResiduals, doMaps, "", autoLimits, cmslabel, rlabel);
145 
146  return EXIT_SUCCESS;
147 }
148 
149 #ifndef DOXYGEN_SHOULD_SKIP_THIS
150 int main(int argc, char* argv[]) { return exceptions<merge>(argc, argv); }
151 #endif
static void set(const PublicationStatus status, const Era era=NONE, const TString customTitle="", const TString customRightTitle="")
Definition: TkAlStyle.cc:275
int merge(int argc, char *argv[])
Definition: PVmerge.cc:28
int main(int argc, char *argv[])
Definition: PVmerge.cc:150
Definition: TkAlStyle.h:43
static PublicationStatus toStatus(std::string _status)
Definition: TkAlStyle.cc:83