File indexing completed on 2024-11-06 06:06:08
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 moduleFilterFile =
0060 validation.count("moduleFilterFile") ? validation.get<std::string>("moduleFilterFile") : "";
0061 float maxBadLumiPixel = validation.count("maxBadLumiPixel") ? validation.get<float>("maxBadLumiPixel") : 0.5;
0062 float maxBadLumiStrip = validation.count("maxBadLumiStrip") ? validation.get<float>("maxBadLumiStrip") : 7.0;
0063 std::string rlabel = validation.count("customrighttitle") ? validation.get<std::string>("customrighttitle") : "";
0064 rlabel = merge_style.count("Rlabel") ? merge_style.get<std::string>("Rlabel") : rlabel;
0065 std::string cmslabel = merge_style.count("CMSlabel") ? merge_style.get<std::string>("CMSlabel") : "INTERNAL";
0066
0067 int minimum = validation.count("minimum") ? validation.get<int>("minimum") : 15;
0068
0069 bool useFit = validation.count("usefit") ? validation.get<bool>("usefit") : false;
0070 bool bigText = validation.count("bigtext") ? validation.get<bool>("bigtext") : false;
0071
0072 TkAlStyle::legendheader = validation.count("legendheader") ? validation.get<std::string>("legendheader") : "";
0073 TkAlStyle::legendoptions =
0074 validation.count("legendoptions") ? getVecTokenized(validation, "legendoptions", " ") : "mean rms";
0075 if (TkAlStyle::toStatus(cmslabel) == CUSTOM)
0076 TkAlStyle::set(CUSTOM, NONE, cmslabel, rlabel);
0077 else
0078 TkAlStyle::set(TkAlStyle::toStatus(cmslabel), NONE, "", rlabel);
0079
0080 std::vector<int> moduleids;
0081 if (validation.count("moduleid")) {
0082 for (const auto& childTree : validation.get_child("moduleid")) {
0083 moduleids.push_back(childTree.second.get_value<int>());
0084 }
0085 }
0086
0087
0088 TString filesAndLabels;
0089 std::vector<std::pair<std::string, pt::ptree>> alignmentsOrdered;
0090 for (const auto& childTree : alignments) {
0091 alignmentsOrdered.push_back(childTree);
0092 }
0093 std::sort(alignmentsOrdered.begin(),
0094 alignmentsOrdered.end(),
0095 [](const std::pair<std::string, pt::ptree>& left, const std::pair<std::string, pt::ptree>& right) {
0096 return left.second.get<int>("index") < right.second.get<int>("index");
0097 });
0098 for (const auto& childTree : alignmentsOrdered) {
0099 filesAndLabels +=
0100 childTree.second.get<std::string>("file") + "/DMR.root=" + childTree.second.get<std::string>("title") + "|" +
0101 childTree.second.get<std::string>("color") + "|" + childTree.second.get<std::string>("style") + " , ";
0102 }
0103 filesAndLabels.Remove(filesAndLabels.Length() - 3);
0104
0105
0106 CompareAlignments comparer(main_tree.get<std::string>("output"));
0107 if (TkAlStyle::toStatus(cmslabel) == CUSTOM)
0108 comparer.doComparison(filesAndLabels, "", cmslabel, rlabel, CUSTOM);
0109 else
0110 comparer.doComparison(filesAndLabels, "", "", rlabel, TkAlStyle::toStatus(cmslabel));
0111
0112
0113 gStyle->SetTitleH(0.07);
0114 gStyle->SetTitleW(1.00);
0115 gStyle->SetTitleFont(132);
0116
0117 PlotAlignmentValidation plotter(bigText);
0118
0119 for (const auto& childTree : alignmentsOrdered) {
0120 plotter.loadFileList((childTree.second.get<std::string>("file") + "/DMR.root").c_str(),
0121 childTree.second.get<std::string>("title"),
0122 childTree.second.get<int>("color"),
0123 childTree.second.get<int>("style"));
0124 }
0125
0126 plotter.setOutputDir(main_tree.get<std::string>("output"));
0127 plotter.useFitForDMRplots(useFit);
0128 plotter.setTreeBaseDir("TrackHitFilter");
0129 plotter.plotDMR(methods, minimum, curves, moduleFilterFile, maxBadLumiPixel, maxBadLumiStrip);
0130 plotter.plotSurfaceShapes("coarse");
0131 plotter.plotChi2((main_tree.get<std::string>("output") + "/" + "result.root").c_str());
0132
0133 for (const int& moduleid : moduleids) {
0134 plotter.residual_by_moduleID(moduleid);
0135 }
0136
0137 return EXIT_SUCCESS;
0138 }
0139
0140 #ifndef DOXYGEN_SHOULD_SKIP_THIS
0141 int main(int argc, char* argv[]) { return exceptions<merge>(argc, argv); }
0142 #endif