File indexing completed on 2024-04-06 11:56:53
0001 #include <cstdlib>
0002 #include <iostream>
0003 #include <vector>
0004
0005 #include "TString.h"
0006
0007 #include "exceptions.h"
0008 #include "toolbox.h"
0009 #include "Options.h"
0010
0011 #include "boost/regex.hpp"
0012 #include "boost/filesystem.hpp"
0013 #include "boost/algorithm/string.hpp"
0014 #include "boost/container/vector.hpp"
0015 #include "boost/property_tree/ptree.hpp"
0016 #include "boost/property_tree/json_parser.hpp"
0017
0018 #include "Alignment/OfflineValidation/interface/GeometryComparisonPlotter.h"
0019 #include "Alignment/OfflineValidation/scripts/visualizationTracker.C"
0020 #include "Alignment/OfflineValidation/macros/makeArrowPlots.C"
0021
0022
0023 #include "TObject.h"
0024
0025 using namespace std;
0026 using namespace AllInOneConfig;
0027
0028 namespace pt = boost::property_tree;
0029 namespace fs = boost::filesystem;
0030 namespace bc = boost::container;
0031
0032 void comparisonScript(pt::ptree GCPoptions,
0033 TString inFile,
0034 TString outDir = "outputDir/",
0035 TString alignmentName = "Alignment",
0036 TString referenceName = "Ideal") {
0037
0038 fs::create_directories(outDir.Data());
0039
0040 TString modulesToPlot = "all";
0041 TString transDir = outDir + "/Translations";
0042 TString rotDir = outDir + "/Rotations";
0043 fs::create_directories(transDir.Data());
0044 fs::create_directories(rotDir.Data());
0045
0046 bool plotOnlyGlobal = GCPoptions.count("plotOnlyGlobal") ? GCPoptions.get<bool>("plotOnlyGlobal") : false;
0047 bool plotPng = GCPoptions.count("plotPng") ? GCPoptions.get<bool>("plotPng") : false;
0048 bool makeProfilePlots = GCPoptions.count("makeProfilePlots") ? GCPoptions.get<bool>("makeProfilePlots") : true;
0049
0050
0051 GeometryComparisonPlotter* trans = new GeometryComparisonPlotter(
0052 inFile, transDir, modulesToPlot, alignmentName, referenceName, plotOnlyGlobal, makeProfilePlots, 0);
0053
0054
0055
0056 vector<TString> x{"r", "phi", "z"};
0057 vector<TString> y{"dr", "dz", "rdphi", "dx", "dy"};
0058 vector<TString> xmean{"x", "y", "z", "r"};
0059
0060 trans->SetBranchUnits("x", "cm");
0061 trans->SetBranchUnits("y", "cm");
0062 trans->SetBranchUnits("z", "cm");
0063 trans->SetBranchUnits("r", "cm");
0064 trans->SetBranchUnits("phi", "rad");
0065 trans->SetBranchUnits("dx", "#mum");
0066 trans->SetBranchUnits("dy", "#mum");
0067 trans->SetBranchUnits("dz", "#mum");
0068 trans->SetBranchUnits("dr", "#mum");
0069 trans->SetBranchUnits("rdphi", "#mum rad");
0070
0071 trans->SetBranchSF("dx", 10000);
0072 trans->SetBranchSF("dy", 10000);
0073 trans->SetBranchSF("dz", 10000);
0074 trans->SetBranchSF("dr", 10000);
0075 trans->SetBranchSF("rdphi", 10000);
0076
0077 trans->SetGrid(1, 1);
0078 trans->MakePlots(x, y, GCPoptions);
0079
0080
0081 if (plotPng) {
0082 trans->SetPrintOption("png");
0083 trans->MakePlots(x, y, GCPoptions);
0084 }
0085
0086 trans->MakeTables(xmean, y, GCPoptions);
0087
0088
0089 GeometryComparisonPlotter* rot = new GeometryComparisonPlotter(
0090 inFile, rotDir, modulesToPlot, alignmentName, referenceName, plotOnlyGlobal, makeProfilePlots, 2);
0091
0092
0093
0094 vector<TString> b{"dalpha", "dbeta", "dgamma"};
0095
0096 rot->SetBranchUnits("z", "cm");
0097 rot->SetBranchUnits("r", "cm");
0098 rot->SetBranchUnits("phi", "rad");
0099 rot->SetBranchUnits("dalpha", "mrad");
0100 rot->SetBranchUnits("dbeta", "mrad");
0101 rot->SetBranchUnits("dgamma", "mrad");
0102
0103 rot->SetBranchSF("dalpha", 1000);
0104 rot->SetBranchSF("dbeta", 1000);
0105 rot->SetBranchSF("dgamma", 1000);
0106
0107 rot->SetGrid(1, 1);
0108 rot->SetPrintOption("pdf");
0109 rot->MakePlots(x, b, GCPoptions);
0110 if (plotPng) {
0111 rot->SetPrintOption("png");
0112 rot->MakePlots(x, b, GCPoptions);
0113 }
0114
0115 delete trans;
0116 delete rot;
0117 }
0118
0119 void vizualizationScript(TString inFile, TString outDir, TString alignmentName, TString referenceName) {
0120 TString outputFileName = outDir + "/Visualization";
0121 fs::create_directories(outputFileName.Data());
0122
0123 std::string line1 = alignmentName.Data();
0124 std::string line2 = referenceName.Data();
0125
0126 int subdetector1 = 1;
0127 int subdetector2 = 2;
0128
0129 int sclftr = 50;
0130
0131 int sclfrt = 1;
0132
0133 float sclfmodulesizex = 1;
0134 float sclfmodulesizey = 1;
0135 float sclfmodulesizez = 1;
0136
0137 float piperadius = 2.25;
0138
0139 float pipexcoord = 0;
0140 float pipeycoord = 0;
0141
0142 float linexcoord = 0;
0143 float lineycoord = 0;
0144 runVisualizer(inFile,
0145 outputFileName.Data(),
0146 line1,
0147 line2,
0148 subdetector1,
0149 subdetector2,
0150 sclftr,
0151 sclfrt,
0152 sclfmodulesizex,
0153 sclfmodulesizey,
0154 sclfmodulesizez,
0155 piperadius,
0156 pipexcoord,
0157 pipeycoord,
0158 linexcoord,
0159 lineycoord);
0160 }
0161
0162 int GCP(int argc, char* argv[]) {
0163
0164
0165
0166
0167
0168
0169
0170
0171 Options options;
0172 options.helper(argc, argv);
0173 options.parser(argc, argv);
0174
0175 std::cout << " ----- GCP validation plots -----" << std::endl;
0176 std::cout << " --- Digesting configuration" << std::endl;
0177
0178 pt::ptree main_tree;
0179 pt::read_json(options.config, main_tree);
0180
0181 pt::ptree alignments = main_tree.get_child("alignments");
0182 pt::ptree validation = main_tree.get_child("validation");
0183
0184 pt::ptree GCPoptions = validation.get_child("GCP");
0185
0186
0187 bool doUnitTest = GCPoptions.count("doUnitTest") ? GCPoptions.get<bool>("doUnitTest") : false;
0188
0189
0190 bool useDefaultRange = GCPoptions.count("useDefaultRange") ? GCPoptions.get<bool>("useDefaultRange") : false;
0191 if (useDefaultRange) {
0192
0193 pt::ptree default_range;
0194 bc::vector<fs::path> possible_base_paths;
0195 boost::split(possible_base_paths, std::getenv("CMSSW_SEARCH_PATH"), boost::is_any_of(":"));
0196 fs::path default_range_path = "";
0197 fs::path default_range_file = "Alignment/OfflineValidation/data/GCP/GCP_defaultRange.json";
0198 for (const fs::path& path : possible_base_paths) {
0199 if (fs::exists(path / default_range_file)) {
0200 default_range_path = path / default_range_file;
0201 }
0202 }
0203 assert((fs::exists(default_range_path)) &&
0204 "Check if 'Alignment/OfflineValidation/test/GCP_defaultRange.json' exists");
0205 pt::read_json(default_range_path.c_str(), default_range);
0206
0207 for (pair<string, pt::ptree> it : default_range) {
0208 if (GCPoptions.count(it.first) < 1) {
0209 GCPoptions.put(it.first, it.second.data());
0210 }
0211 }
0212 }
0213
0214 pt::ptree comAl = alignments.get_child("comp");
0215 pt::ptree refAl = alignments.get_child("ref");
0216
0217
0218 TString inFile = main_tree.get<std::string>("output") + "/GCPtree.root";
0219 TString outDir = main_tree.get<std::string>("output");
0220 TString modulesToPlot = "all";
0221 TString alignmentName = comAl.get<std::string>("title");
0222 TString referenceName = refAl.get<std::string>("title");
0223
0224 std::cout << " --- Running comparison script" << std::endl;
0225
0226 comparisonScript(GCPoptions, inFile, outDir, alignmentName, referenceName);
0227
0228 if (!doUnitTest) {
0229 std::cout << " --- Running visualization script" << std::endl;
0230
0231 vizualizationScript(inFile, outDir, alignmentName, referenceName);
0232 } else {
0233 std::cout << " --- Skipping visualization script for unit test purpose" << std::endl;
0234 }
0235
0236 std::cout << " --- Running arrow plot script" << std::endl;
0237
0238 TString arrowDir = outDir + "/ArrowPlots";
0239 makeArrowPlots(inFile.Data(), arrowDir.Data());
0240
0241 std::cout << " --- Finished running GCP.cpp" << std::endl;
0242 return EXIT_SUCCESS;
0243 }
0244
0245 #ifndef DOXYGEN_SHOULD_SKIP_THIS
0246 int main(int argc, char* argv[]) { return exceptions<GCP>(argc, argv); }
0247 #endif