File indexing completed on 2024-04-06 11:56:53
0001 #include <cstdlib>
0002 #include <string>
0003 #include <iostream>
0004 #include <numeric>
0005 #include <functional>
0006
0007 #include "exceptions.h"
0008 #include "toolbox.h"
0009 #include "Options.h"
0010
0011 #include "boost/filesystem.hpp"
0012 #include "boost/property_tree/ptree.hpp"
0013 #include "boost/property_tree/json_parser.hpp"
0014 #include "boost/optional.hpp"
0015
0016 #include "TString.h"
0017
0018 #include "Alignment/OfflineValidation/interface/CompareAlignments.h"
0019 #include "Alignment/OfflineValidation/interface/PlotAlignmentValidation.h"
0020 #include "Alignment/OfflineValidation/interface/TkAlStyle.h"
0021
0022 using namespace std;
0023 using namespace AllInOneConfig;
0024
0025 namespace pt = boost::property_tree;
0026
0027 std::string getVecTokenized(pt::ptree& tree, const std::string& name, const std::string& token) {
0028 std::string s;
0029
0030 for (const auto& childTree : tree.get_child(name)) {
0031 s += childTree.second.get_value<std::string>() + token;
0032 }
0033
0034 return s.substr(0, s.size() - token.size());
0035 }
0036
0037 int merge(int argc, char* argv[]) {
0038
0039 Options options;
0040 options.helper(argc, argv);
0041 options.parser(argc, argv);
0042
0043
0044 pt::ptree main_tree;
0045 pt::read_json(options.config, main_tree);
0046
0047 pt::ptree alignments = main_tree.get_child("alignments");
0048 pt::ptree validation = main_tree.get_child("validation");
0049 pt::ptree global_style;
0050 pt::ptree merge_style;
0051 global_style = main_tree.count("style") ? main_tree.get_child("style") : global_style;
0052 merge_style = global_style.count("DMR") && global_style.get_child("DMR").count("merge")
0053 ? global_style.get_child("DMR").get_child("merge")
0054 : global_style;
0055
0056
0057 std::string methods = validation.count("methods") ? getVecTokenized(validation, "methods", ",") : "median,rmsNorm";
0058 std::string curves = validation.count("curves") ? getVecTokenized(validation, "curves", ",") : "plain";
0059 std::string rlabel = validation.count("customrighttitle") ? validation.get<std::string>("customrighttitle") : "";
0060 rlabel = merge_style.count("Rlabel") ? merge_style.get<std::string>("Rlabel") : rlabel;
0061 std::string cmslabel = merge_style.count("CMSlabel") ? merge_style.get<std::string>("CMSlabel") : "INTERNAL";
0062
0063 int minimum = validation.count("minimum") ? validation.get<int>("minimum") : 15;
0064
0065 bool useFit = validation.count("usefit") ? validation.get<bool>("usefit") : false;
0066 bool bigText = validation.count("bigtext") ? validation.get<bool>("bigtext") : false;
0067
0068 TkAlStyle::legendheader = validation.count("legendheader") ? validation.get<std::string>("legendheader") : "";
0069 TkAlStyle::legendoptions =
0070 validation.count("legendoptions") ? getVecTokenized(validation, "legendoptions", " ") : "mean rms";
0071 if (TkAlStyle::toStatus(cmslabel) == CUSTOM)
0072 TkAlStyle::set(CUSTOM, NONE, cmslabel, rlabel);
0073 else
0074 TkAlStyle::set(TkAlStyle::toStatus(cmslabel), NONE, "", rlabel);
0075
0076 std::vector<int> moduleids;
0077 if (validation.count("moduleid")) {
0078 for (const auto& childTree : validation.get_child("moduleid")) {
0079 moduleids.push_back(childTree.second.get_value<int>());
0080 }
0081 }
0082
0083
0084 TString filesAndLabels;
0085 std::vector<std::pair<std::string, pt::ptree>> alignmentsOrdered;
0086 for (const auto& childTree : alignments) {
0087 alignmentsOrdered.push_back(childTree);
0088 }
0089 std::sort(alignmentsOrdered.begin(),
0090 alignmentsOrdered.end(),
0091 [](const std::pair<std::string, pt::ptree>& left, const std::pair<std::string, pt::ptree>& right) {
0092 return left.second.get<int>("index") < right.second.get<int>("index");
0093 });
0094 for (const auto& childTree : alignmentsOrdered) {
0095 filesAndLabels +=
0096 childTree.second.get<std::string>("file") + "/DMR.root=" + childTree.second.get<std::string>("title") + "|" +
0097 childTree.second.get<std::string>("color") + "|" + childTree.second.get<std::string>("style") + " , ";
0098 }
0099 filesAndLabels.Remove(filesAndLabels.Length() - 3);
0100
0101
0102 CompareAlignments comparer(main_tree.get<std::string>("output"));
0103 if (TkAlStyle::toStatus(cmslabel) == CUSTOM)
0104 comparer.doComparison(filesAndLabels, "", cmslabel, rlabel, CUSTOM);
0105 else
0106 comparer.doComparison(filesAndLabels, "", "", rlabel, TkAlStyle::toStatus(cmslabel));
0107
0108
0109 gStyle->SetTitleH(0.07);
0110 gStyle->SetTitleW(1.00);
0111 gStyle->SetTitleFont(132);
0112
0113 PlotAlignmentValidation plotter(bigText);
0114
0115 for (const auto& childTree : alignmentsOrdered) {
0116 plotter.loadFileList((childTree.second.get<std::string>("file") + "/DMR.root").c_str(),
0117 childTree.second.get<std::string>("title"),
0118 childTree.second.get<int>("color"),
0119 childTree.second.get<int>("style"));
0120 }
0121
0122 plotter.setOutputDir(main_tree.get<std::string>("output"));
0123 plotter.useFitForDMRplots(useFit);
0124 plotter.setTreeBaseDir("TrackHitFilter");
0125 plotter.plotDMR(methods, minimum, curves);
0126 plotter.plotSurfaceShapes("coarse");
0127 plotter.plotChi2((main_tree.get<std::string>("output") + "/" + "result.root").c_str());
0128
0129 for (const int& moduleid : moduleids) {
0130 plotter.residual_by_moduleID(moduleid);
0131 }
0132
0133 return EXIT_SUCCESS;
0134 }
0135
0136 #ifndef DOXYGEN_SHOULD_SKIP_THIS
0137 int main(int argc, char* argv[]) { return exceptions<merge>(argc, argv); }
0138 #endif