CMS 3D CMS Logo

Functions
GCP.cc File Reference
#include <cstdlib>
#include <iostream>
#include <vector>
#include "TString.h"
#include "exceptions.h"
#include "toolbox.h"
#include "Options.h"
#include "boost/regex.hpp"
#include "boost/filesystem.hpp"
#include "boost/algorithm/string.hpp"
#include "boost/container/vector.hpp"
#include "boost/property_tree/ptree.hpp"
#include "boost/property_tree/json_parser.hpp"
#include "Alignment/OfflineValidation/interface/GeometryComparisonPlotter.h"
#include "Alignment/OfflineValidation/scripts/visualizationTracker.C"
#include "Alignment/OfflineValidation/macros/makeArrowPlots.C"
#include "TObject.h"

Go to the source code of this file.

Functions

void comparisonScript (pt::ptree GCPoptions, TString inFile, TString outDir="outputDir/", TString alignmentName="Alignment", TString referenceName="Ideal")
 
int GCP (int argc, char *argv[])
 
int main (int argc, char *argv[])
 
void vizualizationScript (TString inFile, TString outDir, TString alignmentName, TString referenceName)
 

Function Documentation

◆ comparisonScript()

void comparisonScript ( pt::ptree  GCPoptions,
TString  inFile,
TString  outDir = "outputDir/",
TString  alignmentName = "Alignment",
TString  referenceName = "Ideal" 
)

Definition at line 32 of file GCP.cc.

References b, testHGCalDigi_cfg::inFile, visualization-live-secondInstance_cfg::outDir, makeMuonMisalignmentScenario::rot, x, and y.

Referenced by GCP().

36  {
37  // the output directory is created if it does not exist
38  fs::create_directories(outDir.Data());
39 
40  TString modulesToPlot = "all";
41  TString transDir = outDir + "/Translations";
42  TString rotDir = outDir + "/Rotations";
43  fs::create_directories(transDir.Data());
44  fs::create_directories(rotDir.Data());
45 
46  bool plotOnlyGlobal = GCPoptions.count("plotOnlyGlobal") ? GCPoptions.get<bool>("plotOnlyGlobal") : false;
47  bool plotPng = GCPoptions.count("plotPng") ? GCPoptions.get<bool>("plotPng") : false;
48  bool makeProfilePlots = GCPoptions.count("makeProfilePlots") ? GCPoptions.get<bool>("makeProfilePlots") : true;
49 
50  // Plot Translations
52  inFile, transDir, modulesToPlot, alignmentName, referenceName, plotOnlyGlobal, makeProfilePlots, 0);
53  // x and y contain the couples to plot
54  // -> every combination possible will be performed
55  // /!\ always give units (otherwise, unexpected bug from root...)
56  vector<TString> x{"r", "phi", "z"};
57  vector<TString> y{"dr", "dz", "rdphi", "dx", "dy"};
58  vector<TString> xmean{"x", "y", "z", "r"};
59 
60  trans->SetBranchUnits("x", "cm");
61  trans->SetBranchUnits("y", "cm");
62  trans->SetBranchUnits("z", "cm"); //trans->SetBranchMax("z", 100); trans->SetBranchMin("z", -100);
63  trans->SetBranchUnits("r", "cm");
64  trans->SetBranchUnits("phi", "rad");
65  trans->SetBranchUnits("dx", "#mum"); //trans->SetBranchMax("dx", 10); trans->SetBranchMin("dx", -10);
66  trans->SetBranchUnits("dy", "#mum"); //trans->SetBranchMax("dy", 10); trans->SetBranchMin("dy", -10);
67  trans->SetBranchUnits("dz", "#mum");
68  trans->SetBranchUnits("dr", "#mum");
69  trans->SetBranchUnits("rdphi", "#mum rad");
70 
71  trans->SetBranchSF("dx", 10000);
72  trans->SetBranchSF("dy", 10000);
73  trans->SetBranchSF("dz", 10000);
74  trans->SetBranchSF("dr", 10000);
75  trans->SetBranchSF("rdphi", 10000);
76 
77  trans->SetGrid(1, 1);
78  trans->MakePlots(x, y, GCPoptions); // default output is pdf, but png gives a nicer result, so we use it as well
79  // remark: what takes the more time is the creation of the output files,
80  // not the looping on the tree (because the code is perfect, of course :p)
81  if (plotPng) {
82  trans->SetPrintOption("png");
83  trans->MakePlots(x, y, GCPoptions);
84  }
85 
86  trans->MakeTables(xmean, y, GCPoptions);
87 
88  // Plot Rotations
90  inFile, rotDir, modulesToPlot, alignmentName, referenceName, plotOnlyGlobal, makeProfilePlots, 2);
91  // x and y contain the couples to plot
92  // -> every combination possible will be performed
93  // /!\ always give units (otherwise, unexpected bug from root...)
94  vector<TString> b{"dalpha", "dbeta", "dgamma"};
95 
96  rot->SetBranchUnits("z", "cm");
97  rot->SetBranchUnits("r", "cm");
98  rot->SetBranchUnits("phi", "rad");
99  rot->SetBranchUnits("dalpha", "mrad");
100  rot->SetBranchUnits("dbeta", "mrad");
101  rot->SetBranchUnits("dgamma", "mrad");
102 
103  rot->SetBranchSF("dalpha", 1000);
104  rot->SetBranchSF("dbeta", 1000);
105  rot->SetBranchSF("dgamma", 1000);
106 
107  rot->SetGrid(1, 1);
108  rot->SetPrintOption("pdf");
109  rot->MakePlots(x, b, GCPoptions);
110  if (plotPng) {
111  rot->SetPrintOption("png");
112  rot->MakePlots(x, b, GCPoptions);
113  }
114 
115  delete trans;
116  delete rot;
117 }
double b
Definition: hdecay.h:118
float x

◆ GCP()

int GCP ( int  argc,
char *  argv[] 
)

Definition at line 162 of file GCP.cc.

References dir2webdir::argc, GCPpyPlots::argv, cms::cuda::assert(), comparisonScript(), gather_cfg::cout, testHGCalDigi_cfg::inFile, AlcaSiPixelAliHarvester0T_cff::options, visualization-live-secondInstance_cfg::outDir, castor_dqm_sourceclient_file_cfg::path, submitPVValidationJobs::split(), AlCaHLTBitMon_QueryRunRegistry::string, and vizualizationScript().

162  {
163  /*
164  TObject* printer = new TObject();
165  printer->Info("GCPvalidation", "Hello!");
166  // Hack to push through messages even without -v running
167  // Very ugly coding, to run with std::cout -> run with -v option (GCP cfg.json -v)
168  */
169 
170  // parse the command line
172  options.helper(argc, argv);
173  options.parser(argc, argv);
174 
175  std::cout << " ----- GCP validation plots -----" << std::endl;
176  std::cout << " --- Digesting configuration" << std::endl;
177 
178  pt::ptree main_tree;
179  pt::read_json(options.config, main_tree);
180 
181  pt::ptree alignments = main_tree.get_child("alignments");
182  pt::ptree validation = main_tree.get_child("validation");
183 
184  pt::ptree GCPoptions = validation.get_child("GCP");
185 
186  // Disable some of the features for unit tests
187  bool doUnitTest = GCPoptions.count("doUnitTest") ? GCPoptions.get<bool>("doUnitTest") : false;
188 
189  // If useDefaultRange, update ranges if not defined in GCPoptions
190  bool useDefaultRange = GCPoptions.count("useDefaultRange") ? GCPoptions.get<bool>("useDefaultRange") : false;
191  if (useDefaultRange) {
192  // Read default ranges
193  pt::ptree default_range;
194  bc::vector<fs::path> possible_base_paths;
195  boost::split(possible_base_paths, std::getenv("CMSSW_SEARCH_PATH"), boost::is_any_of(":"));
196  fs::path default_range_path = "";
197  fs::path default_range_file = "Alignment/OfflineValidation/data/GCP/GCP_defaultRange.json";
198  for (const fs::path& path : possible_base_paths) {
199  if (fs::exists(path / default_range_file)) {
200  default_range_path = path / default_range_file;
201  }
202  }
203  assert((fs::exists(default_range_path)) &&
204  "Check if 'Alignment/OfflineValidation/test/GCP_defaultRange.json' exists");
205  pt::read_json(default_range_path.c_str(), default_range);
206 
207  for (pair<string, pt::ptree> it : default_range) {
208  if (GCPoptions.count(it.first) < 1) {
209  GCPoptions.put(it.first, it.second.data());
210  }
211  }
212  }
213 
214  pt::ptree comAl = alignments.get_child("comp");
215  pt::ptree refAl = alignments.get_child("ref");
216 
217  // Read the options
218  TString inFile = main_tree.get<std::string>("output") + "/GCPtree.root";
219  TString outDir = main_tree.get<std::string>("output");
220  TString modulesToPlot = "all";
221  TString alignmentName = comAl.get<std::string>("title");
222  TString referenceName = refAl.get<std::string>("title");
223 
224  std::cout << " --- Running comparison script" << std::endl;
225  // Compare script
226  comparisonScript(GCPoptions, inFile, outDir, alignmentName, referenceName);
227 
228  if (!doUnitTest) {
229  std::cout << " --- Running visualization script" << std::endl;
230  // Visualization script
231  vizualizationScript(inFile, outDir, alignmentName, referenceName);
232  } else {
233  std::cout << " --- Skipping visualization script for unit test purpose" << std::endl;
234  }
235 
236  std::cout << " --- Running arrow plot script" << std::endl;
237  // Arrow plot
238  TString arrowDir = outDir + "/ArrowPlots";
239  makeArrowPlots(inFile.Data(), arrowDir.Data());
240 
241  std::cout << " --- Finished running GCP.cpp" << std::endl;
242  return EXIT_SUCCESS;
243 }
void comparisonScript(pt::ptree GCPoptions, TString inFile, TString outDir="outputDir/", TString alignmentName="Alignment", TString referenceName="Ideal")
Definition: GCP.cc:32
assert(be >=bs)
void vizualizationScript(TString inFile, TString outDir, TString alignmentName, TString referenceName)
Definition: GCP.cc:119

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 246 of file GCP.cc.

References dir2webdir::argc, and GCPpyPlots::argv.

246 { return exceptions<GCP>(argc, argv); }

◆ vizualizationScript()

void vizualizationScript ( TString  inFile,
TString  outDir,
TString  alignmentName,
TString  referenceName 
)

Definition at line 119 of file GCP.cc.

References testHGCalDigi_cfg::inFile, visualization-live-secondInstance_cfg::outDir, makeListRunsInFiles::outputFileName, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by GCP().

119  {
120  TString outputFileName = outDir + "/Visualization";
121  fs::create_directories(outputFileName.Data());
122  //title
123  std::string line1 = alignmentName.Data();
124  std::string line2 = referenceName.Data();
125  //set subdetectors to see
126  int subdetector1 = 1;
127  int subdetector2 = 2;
128  //translation scale factor
129  int sclftr = 50;
130  //rotation scale factor
131  int sclfrt = 1;
132  //module size scale factor
133  float sclfmodulesizex = 1;
134  float sclfmodulesizey = 1;
135  float sclfmodulesizez = 1;
136  //beam pipe radius
137  float piperadius = 2.25;
138  //beam pipe xy coordinates
139  float pipexcoord = 0;
140  float pipeycoord = 0;
141  //beam line xy coordinates
142  float linexcoord = 0;
143  float lineycoord = 0;
144  runVisualizer(inFile,
145  outputFileName.Data(),
146  line1,
147  line2,
148  subdetector1,
149  subdetector2,
150  sclftr,
151  sclfrt,
152  sclfmodulesizex,
153  sclfmodulesizey,
154  sclfmodulesizez,
155  piperadius,
156  pipexcoord,
157  pipeycoord,
158  linexcoord,
159  lineycoord);
160 }