CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GeometryComparisonPlotter.cc
Go to the documentation of this file.
2 
3 /***********************************************************************************/
4 /* GEOMETRY COMPARISON PLOTTER */
5 /* See the talk of 15 January 2015 for short documentation and the example script. */
6 /* This code is highly commented if need be to upgrade it. */
7 /* Any further question is to be asked to Patrick Connor (patrick.connor@desy.de). */
8 /* Thanks a million <3 */
9 /***********************************************************************************/
10 
11 // NOTE: look for "TO DO" as a keyword to now what should be upgraded in later versions....
12 
13 
14 // modes
15 #define TALKATIVE // get some comments while processing
16 //#define DEBUG // get a lot of comments while processing + canvases -> resource-consuming!
17 
18 // MACROS
19 #define INSIDE_VECTOR(vector) \
20  cout << #vector << "={"; for (unsigned int i = 0 ; i < vector.size()-1 ; i++) cout << vector[i] << ","; cout << vector.back() << "}";
21 #define CHECK_MAP_CONTENT(m,type) \
22  for (map<TString,type>::iterator it = m.begin() ; it != m.end() ; it++) \
23  cout << __FILE__ << ":" << __LINE__ << ":Info: " << #m << "[" << it->first << "]=" << it->second << endl;
24 
25 // CONSTRUCTOR AND DESTRUCTOR
27  TString output_directory) :
28  _output_directory(output_directory + TString(output_directory.EndsWith("/") ? "" : "/")),
29  _output_filename("comparison.root"),
30  _print_option("pdf"),
31  _print(true), // print the graphs in a file (e.g. pdf)
32  _legend(true), // print the graphs in a file (e.g. pdf)
33  _write(true), // write the graphs in a root file
34  _batchMode(
35 #ifdef DEBUG
36  false // false = display canvases (very time- and resource-consuming)
37 #else
38  true // true = no canvases
39 #endif
40  ),
41  _1dModule(true), // cut on 1d modules
42  _2dModule(true), // cut on 2d modules
43  _levelCut (DEFAULT_LEVEL), // module level (see branch of same name)
44  _grid_x(0), // by default no display the grid in the canvases
45  _grid_y(0), // by default no display the grid in the canvases
46  _window_width(DEFAULT_WINDOW_WIDTH),
47  _window_height(DEFAULT_WINDOW_HEIGHT)
48 {
49 #ifdef TALKATIVE
50  cout << ">>> TALKATIVE MODE ACTIVATED <<<" << endl;
51 #endif
52 #ifdef DEBUG
53  cout << ">>> DEBUG MODE ACTIVATED <<<" << endl;
54  cout << __FILE__ << ":"<< __LINE__ << ":Info: inside constructor of GeometryComparisonPlotter utility"<< endl;
55 #endif
56 
57  //_sublevel_names = {"PXB", "PXF", "TIB", "TID", "TOB", "TEC"}; // C++11
58  _sublevel_names[0] = TString("PXB");
59  _sublevel_names[1] = TString("PXF");
60  _sublevel_names[2] = TString("TIB");
61  _sublevel_names[3] = TString("TID");
62  _sublevel_names[4] = TString("TOB");
63  _sublevel_names[5] = TString("TEC");
64  // TO DO: handle other structures
65 
66  // read tree
67  tree_file = new TFile(tree_file_name, "UPDATE");
68  data = (TTree*) tree_file->Get("alignTree");
69  // int branches
70  data->SetBranchAddress("id" ,&branch_i["id"]);
71  data->SetBranchAddress("mid" ,&branch_i["mid"]);
72  data->SetBranchAddress("level" ,&branch_i["level"]);
73  data->SetBranchAddress("mlevel" ,&branch_i["mlevel"]);
74  data->SetBranchAddress("sublevel" ,&branch_i["sublevel"]);
75  data->SetBranchAddress("useDetId" ,&branch_i["useDetId"]);
76  data->SetBranchAddress("detDim" ,&branch_i["detDim"]);
77  // float branches
78  data->SetBranchAddress("x" ,&branch_f["x"]);
79  data->SetBranchAddress("y" ,&branch_f["y"]);
80  data->SetBranchAddress("z" ,&branch_f["z"]);
81  data->SetBranchAddress("alpha" ,&branch_f["alpha"]);
82  data->SetBranchAddress("beta" ,&branch_f["beta"]);
83  data->SetBranchAddress("gamma" ,&branch_f["gamma"]);
84  data->SetBranchAddress("phi" ,&branch_f["phi"]);
85  data->SetBranchAddress("eta" ,&branch_f["eta"]);
86  data->SetBranchAddress("r" ,&branch_f["r"]);
87  data->SetBranchAddress("dx" ,&branch_f["dx"]);
88  data->SetBranchAddress("dy" ,&branch_f["dy"]);
89  data->SetBranchAddress("dz" ,&branch_f["dz"]);
90  data->SetBranchAddress("dphi" ,&branch_f["dphi"]);
91  data->SetBranchAddress("dr" ,&branch_f["dr"]);
92  data->SetBranchAddress("dalpha" ,&branch_f["dalpha"]);
93  data->SetBranchAddress("dbeta" ,&branch_f["dbeta"]);
94  data->SetBranchAddress("dgamma" ,&branch_f["dgamma"]);
95  if (data->GetBranch("rdphi") == 0x0) // in the case of rdphi branch not existing, it is created from r and dphi branches
96  {
97 #ifdef TALKATIVE
98  cout << __FILE__ << ":" << __LINE__ << ":Info: computing the rdphi branch from r and dphi branches (assuming they exist...)" << endl;
99 #endif
100  TBranch * br_rdphi = data->Branch("rdphi", &branch_f["rdphi"], "rdphi/F");
101  for (unsigned int ientry = 0 ; ientry < data->GetEntries() ; ientry++)
102  {
103  data->GetEntry(ientry);
104  branch_f["rdphi"] = branch_f["r"]*branch_f["dphi"];
105  br_rdphi->Fill();
106  }
107  }
108  else
109  data->SetBranchAddress("rdphi",&branch_f["rdphi"]);
110 
111 #ifdef DEBUG
112  cout << __FILE__ << ":" << __LINE__ << ":Info: branch addresses set" << endl;
113 #endif
114 
115  // style
116  gROOT->Reset();
117 
118  data->SetMarkerSize(0.5);
119  data->SetMarkerStyle(6);
120 
121  gStyle->SetOptStat("emr");
122  gStyle->SetTitleAlign(22);
123  gStyle->SetTitleX(0.5);
124  gStyle->SetTitleY(0.97);
125  gStyle->SetTitleFont(62);
126  //gStyle->SetOptTitle(0);
127 
128  gStyle->SetTextFont(132);
129  gStyle->SetTextSize(0.08);
130  gStyle->SetLabelFont(132,"x");
131  gStyle->SetLabelFont(132,"y");
132  gStyle->SetLabelFont(132,"z");
133  gStyle->SetTitleSize(0.08,"x");
134  gStyle->SetTitleSize(0.08,"y");
135  gStyle->SetTitleSize(0.08,"z");
136  gStyle->SetLabelSize(0.08,"x");
137  gStyle->SetLabelSize(0.08,"y");
138  gStyle->SetLabelSize(0.08,"z");
139 
140  gStyle->SetMarkerStyle(8);
141  gStyle->SetHistLineWidth(2);
142  gStyle->SetLineStyleString(2,"[12 12]"); // postscript dashes
143 
144  gStyle->SetFrameBorderMode(0);
145  gStyle->SetCanvasBorderMode(0);
146  gStyle->SetPadBorderMode(0);
147  gStyle->SetPadColor(0);
148  gStyle->SetCanvasColor(0);
149  gStyle->SetTitleColor(1);
150  gStyle->SetStatColor(0);
151  gStyle->SetStatBorderSize(1);
152  gStyle->SetFrameFillColor(0);
153 
154  gStyle->SetPadTickX(1);
155  gStyle->SetPadTickY(1);
156 
157  gStyle->SetPadTopMargin(0.1);
158  gStyle->SetPadRightMargin(0.05);
159  gStyle->SetPadBottomMargin(0.16);
160  gStyle->SetPadLeftMargin(0.18);
161 
162 #ifdef DEBUG
163  cout << __FILE__ << ":" << __LINE__ << ":Info: end of constructor" << endl;
164 #endif
165 }
166 
168 {
169 #ifdef DEBUG
170  cout << __FILE__ << ":" << __LINE__ << ":Info: in destructor of the GeometryComparisonPlotter utility" << endl;
171 #endif
172  tree_file->Close();
173 #ifdef DEBUG
174  cout << __FILE__ << ":" << __LINE__ << ":Info: ending." << endl;
175 #endif
176 }
177 
178 // MAIN METHOD
179 void GeometryComparisonPlotter::MakePlots (vector<TString> x, // axes to combine to plot
180  vector<TString> y) // every combination (except the ones such that x=y) will be perfomed
181 {
183  // (we use a macro to avoid copy/paste)
184 #define CHECK_BRANCHES(branchname_vector) \
185  for (unsigned int i = 0 ; i < branchname_vector.size() ; i++) \
186  { \
187  if (branch_f.find(branchname_vector[i]) == branch_f.end()) \
188  { \
189  cout << __FILE__ << ":" << __LINE__ << ":Error: The branch " << branchname_vector[i] << " is not recognised." << endl; \
190  return; \
191  } \
192  }
193  CHECK_BRANCHES(x);
194  CHECK_BRANCHES(y);
195 
196  const unsigned int nentries = data->GetEntries();
197 
198 #ifdef TALKATIVE
199  cout << __FILE__ << ":" << __LINE__ << ":Info: "; INSIDE_VECTOR(x); cout << endl
200  << __FILE__ << ":" << __LINE__ << ":Info: "; INSIDE_VECTOR(y); cout << endl;
201 #endif
202 
204  // the max and min of the graphs are computed from the tree if they have not been manually input yet
205  // (we use a macro to avoid copy/paste)
206 #define LIMITS(axes_vector) \
207  for (unsigned int i = 0 ; i < axes_vector.size() ; i++) \
208  { \
209  if ( _SF.find(axes_vector[i]) == _SF.end()) _SF[axes_vector[i]] = 1.; \
210  if (_min.find(axes_vector[i]) == _min.end()) _min[axes_vector[i]] = _SF[axes_vector[i]]*data->GetMinimum(axes_vector[i]); \
211  if (_max.find(axes_vector[i]) == _max.end()) _max[axes_vector[i]] = _SF[axes_vector[i]]*data->GetMaximum(axes_vector[i]); \
212  }
213  LIMITS(x);
214  LIMITS(y);
215 
216 #ifdef TALKATIVE
217  CHECK_MAP_CONTENT(_min,float);
218  CHECK_MAP_CONTENT(_max,float);
219  CHECK_MAP_CONTENT(_SF ,float);
220 #endif
221 
223  // the idea is to produce at the end a table of 7 TMultiGraphs:
224  // - 0=Tracker, with color code for the different sublevels
225  // - 1..6=different sublevels, with color code for z < or > 0
226  // (convention: the six first (resp. last) correspond to z>0 (resp. z<0))
227  // This means that 2*6 TGraphs will be filled during the loop on the TTree,
228  // and will be arranged differently with different color codes in the TMultiGraphs
229 #ifndef NB_SUBLEVELS
230 #define NB_SUBLEVELS 6
231 #endif
232 #define NB_Z_SLICES 2
233  TGraph * graphs[x.size()][y.size()][NB_SUBLEVELS*NB_Z_SLICES];
234  long int ipoint[x.size()][y.size()][NB_SUBLEVELS*NB_Z_SLICES];
235  for (unsigned int ix = 0 ; ix < x.size() ; ix++)
236  {
237  for (unsigned int iy = 0 ; iy < y.size() ; iy++)
238  {
239  //if (x[ix] == y[iy]) continue; // do not plot graphs like (r,r) or (phi,phi)
240  for (unsigned int igraph = 0 ; igraph < NB_SUBLEVELS*NB_Z_SLICES ; igraph++)
241  {
242  // declaring
243  ipoint[ix][iy][igraph] = 0; // the purpose of an index for every graph is to avoid thousands of points at the origin of each
244  graphs[ix][iy][igraph] = new TGraph ();
245 #define COLOR_CODE(icolor) int(icolor/4)+icolor+1
246  graphs[ix][iy][igraph]->SetMarkerColor(COLOR_CODE(igraph));
247  graphs[ix][iy][igraph]->SetMarkerStyle(6);
248  // pimping
249  graphs[ix][iy][igraph]->SetName (x[ix]+y[iy]+_sublevel_names[igraph%NB_SUBLEVELS]+TString(igraph>=NB_SUBLEVELS ? "n" : "p" ));
250  graphs[ix][iy][igraph]->SetTitle( _sublevel_names[igraph%NB_SUBLEVELS]+TString(igraph>=NB_SUBLEVELS ? " at z<0": " at z>=0")
251  + TString (";") + LateXstyle(x[ix]) + " /" + _units[x[ix]]
252  + TString (";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]);
253  graphs[ix][iy][igraph]->SetMarkerStyle(6);
254  }
255  }
256  }
257 #ifdef DEBUG
258  cout << __FILE__ << ":" << __LINE__ << ":Info: Creation of the TGraph[" << x.size() << "][" << y.size() << "][" << NB_SUBLEVELS*NB_Z_SLICES << "] ended." << endl;
259 #endif
260 
262 #ifdef DEBUG
263  cout << __FILE__ << ":" << __LINE__ << ":Info: Looping on the TTree" << endl;
264 #endif
265 #ifdef TALKATIVE
266  unsigned int progress = 0;
267  cout << __FILE__ << ":" << __LINE__ << ":Info: 0%" << endl;
268 #endif
269  for (unsigned int ientry = 0 ; ientry < nentries ; ientry++)
270  {
271 #ifdef TALKATIVE
272  if (10*ientry/nentries != progress)
273  {
274  progress = 10*ientry/nentries;
275  cout << __FILE__ << ":" << __LINE__ << ":Info: " << 10*progress << "%" << endl;
276  }
277 #endif
278  // load current tree entry
279  data->GetEntry(ientry);
280 
281  // CUTS on entry
282  if (branch_i["level"] != _levelCut) continue;
283  if (!_1dModule && branch_i["detDim"] == 1) continue;
284  if (!_2dModule && branch_i["detDim"] == 2) continue;
285 
286  // loop on the different couples of variables to plot in a graph
287  for (unsigned int ix = 0 ; ix < x.size() ; ix++)
288  {
289  // CUTS on x[ix]
290  if (_SF[x[ix]]*branch_f[x[ix]] > _max[x[ix]] || _SF[x[ix]]*branch_f[x[ix]] < _min[x[ix]])
291  {
292 //#ifdef DEBUG
293 // cout << "branch_f[x[ix]]=" << branch_f[x[ix]] << endl;
294 //#endif
295  continue;
296  }
297 
298  for (unsigned int iy = 0 ; iy < y.size() ; iy++)
299  {
300  // CUTS on y[iy]
301  //if (x[ix] == y[iy]) continue; // TO DO: handle display when such a case occurs
302  if (branch_i["sublevel"] < 1 || branch_i["sublevel"] > NB_SUBLEVELS) continue;
303  if (_SF[y[iy]]*branch_f[y[iy]] > _max[y[iy]] || _SF[y[iy]]*branch_f[y[iy]] < _min[y[iy]])
304  {
305 //#ifdef DEBUG
306 // cout << "branch_f[y[iy]]=" << branch_f[y[iy]] << endl;
307 //#endif
308  continue;
309  }
310 
311  // FILLING GRAPH
312  const short int igraph = (branch_i["sublevel"]-1) + (branch_f["z"]>=0?0:NB_SUBLEVELS);
313  graphs[ix][iy][igraph]->SetPoint(ipoint[ix][iy][igraph],
314  _SF[x[ix]]*branch_f[x[ix]],
315  _SF[y[iy]]*branch_f[y[iy]]);
316  ipoint[ix][iy][igraph]++;
317  }
318  }
319  }
320 #ifdef TALKATIVE
321  cout << __FILE__ << ":" << __LINE__ << ":Info: 100%\tLoop ended" << endl;
322 #endif
323 
325  gROOT->SetBatch(_batchMode); // if true, then equivalent to "root -b", i.e. no canvas
326  if (_write)
327  { // opening the file to write the graphs
328  output = new TFile(_output_directory+TString(_output_filename), "UPDATE"); // possibly existing file will be updated, otherwise created
329  if (output->IsZombie())
330  {
331  cout << __FILE__ << ":" << __LINE__ << ":Error: Opening of " << _output_directory+TString(_output_filename) << " failed" << endl;
332  exit(-1);
333  }
334 #ifdef TALKATIVE
335  cout << __FILE__ << ":"<< __LINE__ << ":Info: output file is " << _output_directory+TString(_output_filename) << endl;
336 #endif
337  }
338  // declaring TMultiGraphs and TCanvas
339  TMultiGraph * mgraphs[x.size()][y.size()][1+NB_SUBLEVELS]; // the 0th is for global plots, the 1..6th for sublevel plots
340  TCanvas * c[x.size()][y.size()][1+NB_SUBLEVELS],
341  * c_global[1+NB_SUBLEVELS];
342  canvas_index++; // this static index is a safety used in case the MakePlots method is used several times to avoid overloading
343  for (unsigned int ic = 0 ; ic <= NB_SUBLEVELS ; ic++)
344  {
345  c_global[ic] = new TCanvas (TString::Format("global_%s_%d", ic==0?"tracker":_sublevel_names[ic-1].Data(),
346  canvas_index),
347  TString::Format("Global overview of the %s variables", ic==0?"tracker":_sublevel_names[ic-1].Data()),
350  c_global[ic]->Divide(x.size(),y.size());
351  }
352 #define INDEX_IN_GLOBAL_CANVAS(i1,i2) 1 + i1 + i2*x.size()
353  // creating TLegend
354  TLegend * legend = MakeLegend(.1,.92,.9,1.);
355  if (_write) legend->Write();
356  // running on the TGraphs to produce the TMultiGraph and draw/print them
357  for (unsigned int ix = 0 ; ix < x.size() ; ix++)
358  {
359 #ifdef DEBUG
360  cout << __FILE__ << ":" << __LINE__ << ":Info: x[" << ix << "]="<< x[ix] << endl;
361 #endif
362 // // left and right margin for drawing
363 // double left_margin_factor = 1.,
364 // right_margin_factor = 1.;
365 // if (_min[x[ix]] > 0) left_margin_factor = 0.9;
366 // else if (_min[x[ix]] < 0) left_margin_factor = 1.1;
367 // if (_max[x[ix]] > 0) right_margin_factor = 1.1;
368 // else if (_max[x[ix]] < 0) right_margin_factor = 0.9;
369 //#ifdef DEBUG
370 // cout << __FILE__ << ":" << __LINE__ << ":Info: left_margin_factor=" << left_margin_factor
371 // << " and right_margin_factor=" << right_margin_factor << endl;
372 //#endif
373  // looping on Y axes
374  for (unsigned int iy = 0 ; iy < y.size() ; iy++)
375  {
376 // // lower and upper margin for drawing
377 // double lower_margin_factor = 1.,
378 // upper_margin_factor = 1.;
379 // if (_min[y[iy]] > 0) lower_margin_factor = 0.9;
380 // else if (_min[y[iy]] < 0) lower_margin_factor = 1.1;
381 // if (_max[y[iy]] > 0) upper_margin_factor = 1.1;
382 // else if (_max[y[iy]] < 0) upper_margin_factor = 0.9;
383 //#ifdef DEBUG
384 // cout << __FILE__ << ":" << __LINE__ << ":Info: lower_margin_factor=" << lower_margin_factor
385 // << " and upper_margin_factor=" << upper_margin_factor << endl;
386 //#endif
387 
388 
389 #ifdef DEBUG
390  cout << __FILE__ << ":" << __LINE__ << ":Info: x[" << ix << "]=" << x[ix]
391  << " and y[" << iy << "]=" << y[iy]
392  << "\t-> creating TMultiGraph" << endl;
393 #endif
394  mgraphs[ix][iy][0] = new TMultiGraph (TString::Format("mgr_%s_vs_%s_tracker_%d", x[ix].Data(),
395  y[iy].Data(),
396  canvas_index), // name
397  //LateXstyle(x[ix]) + TString(" vs. ") + LateXstyle(y[iy]) + TString(" for Tracker") // graph title
398  TString (";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] // x axis title
399  + TString (";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); // y axis title
400 
402  // fixing ranges and filling TMultiGraph
403  // for (unsigned short int jgraph = NB_SUBLEVELS*NB_Z_SLICES-1 ; jgraph >= 0 ; --jgraph)
404  for (unsigned short int jgraph = 0 ; jgraph < NB_SUBLEVELS*NB_Z_SLICES ; jgraph++)
405  {
406  unsigned short int igraph = NB_SUBLEVELS*NB_Z_SLICES - jgraph - 1; // reverse counting for humane readability (one of the sublevel takes much more place than the others)
407 //#ifdef DEBUG
408 // cout << __FILE__ << ":" << __LINE__ << ":Info: setting X-axis range of " << graphs[ix][iy][jgraph]->GetName() << endl;
409 //#endif
410 // graphs[ix][iy][jgraph]->GetXaxis()->SetLimits ( left_margin_factor*_min[x[ix]],
411 // right_margin_factor*_max[x[ix]]); // for X axis, use SetLimits
412 //#ifdef DEBUG
413 // cout << __FILE__ << ":" << __LINE__ << ":Info: setting Y-axis range of " << graphs[ix][iy][jgraph]->GetName() << endl;
414 //#endif
415 // graphs[ix][iy][jgraph]->GetYaxis()->SetRangeUser(lower_margin_factor*_min[y[iy]],
416 // upper_margin_factor*_max[y[iy]]); // for Y axis, use SetRangeUser
417 // // moreover, for the ranges to be effective in TMultiGraph, the option AP should be given for the first graph and
418 // // only P for the others (assuming all stacked graphs have received the same x- and y-ranges)
419 
420 #ifdef DEBUG
421  cout << __FILE__ << ":" << __LINE__ << ":Info: writing TGraph to file" << endl;
422 #endif
423  // write into root file
424  if (_write) graphs[ix][iy][igraph]->Write();
425  if (graphs[ix][iy][igraph]->GetN() == 0)
426  {
427 #ifdef TALKATIVE
428  cout << __FILE__ << ":" << __LINE__ << ":Info: " << graphs[ix][iy][igraph]->GetName() << " is empty." << endl;
429 #endif
430  continue;
431  }
432 #ifdef DEBUG
433  cout << __FILE__ << ":" << __LINE__ << ":Info: cloning, coloring and adding TGraph "
434  << _sublevel_names[igraph%NB_SUBLEVELS]
435  << (igraph >= NB_SUBLEVELS ? "(z<0)" : "(z>0)")
436  << " to global TMultiGraph" << endl;
437 #endif
438  // clone to prevent any injure on the graph
439  TGraph * gr = (TGraph *) graphs[ix][iy][igraph]->Clone();
440  // color
441  gr->SetMarkerColor(COLOR_CODE(igraph%NB_SUBLEVELS));
442  mgraphs[ix][iy][0]->Add(gr, "P");//, (mgraphs[ix][iy][0]->GetListOfGraphs()==0?"AP":"P"));
443  }
444 
446  for (unsigned int isublevel = 1 ; isublevel <= NB_SUBLEVELS ; isublevel++)
447  {
448 #ifdef DEBUG
449  cout << __FILE__ << ":" << __LINE__ << ":Info: cloning, coloring and adding TGraph "
450  << _sublevel_names[isublevel-1] << " to sublevel TMultiGraph" << endl;
451 #endif
452  mgraphs[ix][iy][isublevel] = new TMultiGraph (TString::Format("%s_vs_%s_%s_%d", x[ix].Data(),
453  y[iy].Data(),
454  _sublevel_names[isublevel-1].Data(),
455  canvas_index), // name
456  //LateXstyle(x[ix]) + TString(" vs. ") + LateXstyle(y[iy]) + TString(" for ") +
457  _sublevel_names[isublevel-1] // graph title
458  + TString (";") + LateXstyle(x[ix]) + " /" + _units[x[ix]] // x axis title
459  + TString (";") + LateXstyle(y[iy]) + " /" + _units[y[iy]]); // y axis title
460  graphs[ix][iy][ isublevel-1]->SetMarkerColor(kBlack);
461  graphs[ix][iy][NB_SUBLEVELS+isublevel-1]->SetMarkerColor(kRed);
462  if (graphs[ix][iy][ isublevel-1]->GetN() > 0) mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][ isublevel-1], "P"); //(mgraphs[ix][iy][isublevel-1]->GetListOfGraphs()==0?"AP":"P")); // z>0
463 #ifdef TALKATIVE
464  else cout << __FILE__ << ":" << __LINE__ << ":Info: graphs[ix][iy][isublevel-1]=" << graphs[ix][iy][isublevel-1]->GetName() << " is empty -> not added into " << mgraphs[ix][iy][isublevel]->GetName() << endl;
465 #endif
466  if (graphs[ix][iy][NB_SUBLEVELS+isublevel-1]->GetN() > 0) mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][NB_SUBLEVELS+isublevel-1], "P"); //(mgraphs[ix][iy][isublevel-1]->GetListOfGraphs()==0?"AP":"P")); // z<0
467 #ifdef TALKATIVE
468  else cout << __FILE__ << ":" << __LINE__ << ":Info: graphs[ix][iy][NB_SUBLEVEL+isublevel-1]=" << graphs[ix][iy][NB_Z_SLICES+isublevel-1]->GetName() << " is empty -> not added into " << mgraphs[ix][iy][isublevel]->GetName() << endl;
469 #endif
470 #if NB_Z_SLICES!=2
471  cout << __FILE__ << ":" << __LINE__ << ":Error: color code incomplete for Z slices..." << endl;
472 #endif
473  }
474 
475  // fixing ranges, saving, and drawing of TMultiGraph (tracker AND sublevels, i.e. 1+NB_SUBLEVELS objects)
476  // the individual canvases are saved, but the global are just drawn and will be saved later
477  for (unsigned short int imgr = 0 ; imgr <= NB_SUBLEVELS ; imgr++)
478  {
479 #ifdef DEBUG
480  cout << __FILE__ << ":" << __LINE__ << ":Info: treating individual canvases." << endl;
481 #endif
482  // drawing into individual canvas and printing it (including a legend for the tracker canvas)
483  c[ix][iy][imgr] = new TCanvas (TString::Format("c_%s_vs_%s_%s_%d", x[ix].Data(),
484  y[iy].Data(),
485  imgr==0?"tracker":_sublevel_names[imgr-1].Data(),
486  canvas_index),
487  TString::Format("%s vs. %s at %s level", x[ix].Data(),
488  y[iy].Data(),
489  imgr==0?"tracker":_sublevel_names[imgr-1].Data()),
492  c[ix][iy][imgr]->SetGrid(_grid_x,_grid_y); // grid
493  if (mgraphs[ix][iy][imgr]->GetListOfGraphs() != 0) mgraphs[ix][iy][imgr]->Draw("A");
494  if (imgr == 0 && _legend) legend->Draw(); // only for the tracker
495  if (_print) c[ix][iy][imgr]->Print(_output_directory + mgraphs[ix][iy][imgr]->GetName() + ExtensionFromPrintOption(_print_option), _print_option);
496 
497 // // setting ranges
498 //#ifdef DEBUG
499 // cout << __FILE__ << ":" << __LINE__ << ":Info: setting X-axis range of " << mgraphs[ix][iy][imgr]->GetName() << endl;
500 //#endif
501 // mgraphs[ix][iy][imgr]->GetXaxis()->SetLimits ( left_margin_factor*_min[x[ix]],
502 // right_margin_factor*_max[x[ix]]); // for X axis, use SetLimits
503 //#ifdef DEBUG
504 // cout << __FILE__ << ":" << __LINE__ << ":Info: setting Y-axis range of " << graphs[ix][iy][imgr]->GetName() << endl;
505 //#endif
506 // mgraphs[ix][iy][imgr]->GetYaxis()->SetRangeUser(lower_margin_factor*_min[y[iy]],
507 // upper_margin_factor*_max[y[iy]]); // for Y axis, use SetRangeUser
508 
509  // writing into root file
510  if (_write) mgraphs[ix][iy][imgr]->Write();
511 
512  // drawing into global canvas
513  c_global[imgr]->cd(INDEX_IN_GLOBAL_CANVAS(ix,iy));
514  c_global[imgr]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix,iy))->SetFillStyle(4000); // make the pad transparent
515  c_global[imgr]->GetPad(INDEX_IN_GLOBAL_CANVAS(ix,iy))->SetGrid(_grid_x,_grid_y); // grid
516  if (mgraphs[ix][iy][imgr]->GetListOfGraphs() != 0) mgraphs[ix][iy][imgr]->Draw("A");
517  // printing will be performed after customisation (e.g. legend or title) just after the loops on ix and iy
518  }
519  } // end of loop on y
520  } // end of loop on x
521 
522  // CUSTOMISATION
523  gStyle->SetOptTitle(0); // otherwise, the title is repeated in every pad of the global canvases
524  // -> instead, we will write it in the upper part in a TPaveText or in a TLegend
525  for (unsigned int ic = 0 ; ic <= NB_SUBLEVELS ; ic++)
526  {
527  c_global[ic]->Draw();
528 
529  // setting legend to tracker canvases
530  if (!_legend) break;
531  TCanvas * c_temp = (TCanvas *) c_global[ic]->Clone(c_global[ic]->GetTitle() + TString("_sub"));
532  c_temp->Draw();
533  c_global[ic] = new TCanvas (c_temp->GetName() + TString("_final"), c_temp->GetTitle(), c_temp->GetWindowWidth(), c_temp->GetWindowHeight());
534  c_global[ic]->Draw();
535  TPad * p_up = new TPad (TString("legend_") + c_temp->GetName(), "",
536  0., 0.9, 1., 1., // relative position
537  -1, 0, 0), // display options
538  * p_down = new TPad (TString("main_") + c_temp->GetName(), "",
539  0., 0., 1., 0.9,
540  -1, 0, 0);
541  // in the lower part, draw the plots
542  p_down->Draw();
543  p_down->cd();
544  c_temp->DrawClonePad();
545  c_global[ic]->cd();
546  // in the upper part, pimp the canvas :p
547  p_up->Draw();
548  p_up->cd();
549  if (ic == 0) // tracker
550  {
551  TLegend * global_legend = MakeLegend(.05,.1,.95,.8);//, "brNDC");
552  global_legend->Draw();
553  }
554  else // sublevels
555  {
556  TPaveText * pt = new TPaveText(.05,.1,.95,.8, "NB");
557  pt->SetFillColor(0);
558  pt->AddText(_sublevel_names[ic-1]);
559  pt->Draw();
560  }
561  // printing
562  if (_print) c_global[ic]->Print(_output_directory + c_global[ic]->GetName() + ExtensionFromPrintOption(_print_option), _print_option);
563  if (_write) c_global[ic]->Write();
564  }
565 
566  // printing global canvases
567  if (_write) output->Close();
568 #ifdef TALKATIVE
569  cout << __FILE__ << ":" << __LINE__ << ":Info: End of MakePlots method" << endl;
570 #endif
571 
572 }
573 
574 // OPTION METHODS
575 void GeometryComparisonPlotter::SetPrint (const bool kPrint) { _print = kPrint ; }
576 void GeometryComparisonPlotter::SetLegend (const bool kLegend) { _legend = kLegend ; }
577 void GeometryComparisonPlotter::SetWrite (const bool kWrite) { _write = kWrite ; }
578 void GeometryComparisonPlotter::Set1dModule (const bool k1dModule) { _1dModule = k1dModule ; }
579 void GeometryComparisonPlotter::Set2dModule (const bool k2dModule) { _2dModule = k2dModule ; }
580 void GeometryComparisonPlotter::SetLevelCut (const int kLevelCut) { _levelCut = kLevelCut ; }
581 void GeometryComparisonPlotter::SetBatchMode (const bool kBatchMode) { _batchMode = kBatchMode ; }
582 void GeometryComparisonPlotter::SetGrid (const int kGridX,
583  const int kGridY) { _grid_x = kGridX ;
584  _grid_y = kGridY ; }
585 void GeometryComparisonPlotter::SetBranchMax (const TString branchname,
586  const float max) { _max[branchname] = max ; }
587 void GeometryComparisonPlotter::SetBranchMin (const TString branchname,
588  const float min) { _min[branchname] = min ; }
589 void GeometryComparisonPlotter::SetBranchSF (const TString branchname,
590  const float SF) { _SF[branchname] = SF ; }
591 void GeometryComparisonPlotter::SetBranchUnits (const TString branchname,
592  const TString units) { _units[branchname] = units ; }
593 void GeometryComparisonPlotter::SetPrintOption (const Option_t * print_option) { _print_option = print_option ; }
594 void GeometryComparisonPlotter::SetCanvasSize (const int window_width,
595  const int window_height) { _window_width = window_width ;
596  _window_height = window_height ; }
599  + TString(name.EndsWith("/") ? "" : "/") ; }
600 
601 // PRIVATE METHODS
603 {
604  word.ToLower();
605  if (word.BeginsWith("d")) word.ReplaceAll("d", "#Delta");
606  if (word == TString("rdphi")) word = "r#Delta#phi"; // TO DO: find something less ad hoc...
607  else if (word.EndsWith("phi")) word.ReplaceAll("phi", "#phi");
608  else if (word.EndsWith("alpha")) word.ReplaceAll("alpha", "#alpha");
609  else if (word.EndsWith("beta")) word.ReplaceAll("beta" , "#beta");
610  else if (word.EndsWith("gamma")) word.ReplaceAll("gamma", "#gamma");
611  else if (word.EndsWith("eta")) word.ReplaceAll("eta", "#eta");
612  return word;
613 }
614 
616 {
617  if (print_option.Contains("pdf" )) return TString(".pdf" );
618  else if (print_option.Contains("eps" )) return TString(".eps" );
619  else if (print_option.Contains("ps" )) return TString(".ps" );
620  else if (print_option.Contains("svg" )) return TString(".svg" );
621  else if (print_option.Contains("tex" )) return TString(".tex" );
622  else if (print_option.Contains("gif" )) return TString(".gif" );
623  else if (print_option.Contains("xpm" )) return TString(".xpm" );
624  else if (print_option.Contains("png" )) return TString(".png" );
625  else if (print_option.Contains("jpg" )) return TString(".jpg" );
626  else if (print_option.Contains("tiff")) return TString(".tiff");
627  else if (print_option.Contains("cxx" )) return TString(".cxx" );
628  else if (print_option.Contains("xml" )) return TString(".xml" );
629  else if (print_option.Contains("root")) return TString(".root");
630  else
631  {
632  cout << __FILE__ << ":" << __LINE__ << ":Warning: unknown format. Returning .pdf, but possibly wrong..." << endl;
633  return TString(".pdf");
634  }
635 }
636 
638  double y1,
639  double x2,
640  double y2,
641  const TString title)
642 {
643  TLegend * legend = new TLegend (x1, y1, x2, y2, title.Data(), "NBNDC");
644  legend->SetNColumns(NB_SUBLEVELS);
645  legend->SetFillColor(0);
646  legend->SetLineColor(0); // redundant with option
647  legend->SetLineWidth(0); // redundant with option
648  for (unsigned int isublevel = 0 ; isublevel < NB_SUBLEVELS ; isublevel++)
649  {
650  TGraph * g = new TGraph (0);
651  g->SetMarkerColor(COLOR_CODE(isublevel));
652  g->SetFillColor(COLOR_CODE(isublevel));
653  g->SetMarkerStyle(kFullSquare);
654  g->SetMarkerSize(10);
655  legend->AddEntry(g,_sublevel_names[isublevel], "p");
656  }
657  return legend;
658 }
list graphs
Definition: cuy.py:960
#define DEBUG
void SetCanvasSize(const int window_width=3508, const int window_height=2480)
void MakePlots(const vector< TString >, const vector< TString >)
void SetGrid(const int, const int)
#define DEFAULT_LEVEL
#define LIMITS(axes_vector)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
#define INDEX_IN_GLOBAL_CANVAS(i1, i2)
void SetBranchMax(const TString, const float)
else
Definition: XrdSource.cc:104
void SetBranchUnits(const TString, const TString)
#define DEFAULT_WINDOW_WIDTH
TLegend * MakeLegend(double x1, double y1, double x2, double y2, const TString title="")
void SetOutputDirectoryName(const TString)
void SetPrintOption(const Option_t *)
T min(T a, T b)
Definition: MathUtil.h:58
#define CHECK_MAP_CONTENT(m, type)
#define NB_Z_SLICES
map< TString, TString > _units
GeometryComparisonPlotter(TString tree_file_name, TString outputDirname="output/")
void SetBranchSF(const TString, const float)
TString units(TString variable, Char_t axis)
#define CHECK_BRANCHES(branchname_vector)
tuple cout
Definition: gather_cfg.py:121
#define NB_SUBLEVELS
volatile std::atomic< bool > shutdown_flag false
Definition: DDAxes.h:10
#define DEFAULT_WINDOW_HEIGHT
#define COLOR_CODE(icolor)
void SetBranchMin(const TString, const float)
#define INSIDE_VECTOR(vector)