CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
GeometryComparisonPlotter Class Reference

#include <GeometryComparisonPlotter.h>

Public Member Functions

 GeometryComparisonPlotter (TString tree_file_name, TString outputDirname="output/")
 
void MakePlots (const vector< TString >, const vector< TString >)
 
void Set1dModule (const bool)
 
void Set2dModule (const bool)
 
void SetBatchMode (const bool)
 
void SetBranchMax (const TString, const float)
 
void SetBranchMin (const TString, const float)
 
void SetBranchSF (const TString, const float)
 
void SetBranchUnits (const TString, const TString)
 
void SetCanvasSize (const int window_width=3508, const int window_height=2480)
 
void SetGrid (const int, const int)
 
void SetLegend (const bool)
 
void SetLevelCut (const int)
 
void SetOutputDirectoryName (const TString)
 
void SetOutputFileName (const TString)
 
void SetPrint (const bool)
 
void SetPrintOption (const Option_t *)
 
void SetWrite (const bool)
 
 ~GeometryComparisonPlotter ()
 

Static Public Attributes

static int canvas_index
 

Private Member Functions

TString ExtensionFromPrintOption (TString)
 
TString LateXstyle (TString)
 
TLegend * MakeLegend (double x1, double y1, double x2, double y2, const TString title="")
 

Private Attributes

bool _1dModule
 
bool _2dModule
 
bool _batchMode
 
int _grid_x
 
int _grid_y
 
bool _legend
 
int _levelCut
 
map< TString, float > _max
 
map< TString, float > _min
 
TString _output_directory
 
TString _output_filename
 
bool _print
 
TString _print_option
 
map< TString, float > _SF
 
TString _sublevel_names [6]
 
map< TString, TString > _units
 
int _window_height
 
int _window_width
 
bool _write
 
map< TString, float > branch_f
 
map< TString, int > branch_i
 
TTree * data
 
TFile * output
 
TFile * tree_file
 

Detailed Description

Definition at line 22 of file GeometryComparisonPlotter.h.

Constructor & Destructor Documentation

GeometryComparisonPlotter::GeometryComparisonPlotter ( TString  tree_file_name,
TString  outputDirname = "output/" 
)

Definition at line 26 of file GeometryComparisonPlotter.cc.

References _sublevel_names, branch_f, branch_i, gather_cfg::cout, data, and tree_file.

27  :
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
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 }
#define DEBUG
#define DEFAULT_LEVEL
#define DEFAULT_WINDOW_WIDTH
tuple cout
Definition: gather_cfg.py:121
#define DEFAULT_WINDOW_HEIGHT
GeometryComparisonPlotter::~GeometryComparisonPlotter ( )

Definition at line 167 of file GeometryComparisonPlotter.cc.

References gather_cfg::cout, and tree_file.

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 }
tuple cout
Definition: gather_cfg.py:121

Member Function Documentation

TString GeometryComparisonPlotter::ExtensionFromPrintOption ( TString  print_option)
private

Definition at line 615 of file GeometryComparisonPlotter.cc.

References gather_cfg::cout.

Referenced by MakePlots().

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 }
tuple cout
Definition: gather_cfg.py:121
TString GeometryComparisonPlotter::LateXstyle ( TString  word)
private

Definition at line 602 of file GeometryComparisonPlotter.cc.

Referenced by MakePlots().

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 }
TLegend * GeometryComparisonPlotter::MakeLegend ( double  x1,
double  y1,
double  x2,
double  y2,
const TString  title = "" 
)
private

Definition at line 637 of file GeometryComparisonPlotter.cc.

References _sublevel_names, COLOR_CODE, g, and NB_SUBLEVELS.

Referenced by MakePlots().

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 }
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 NB_SUBLEVELS
#define COLOR_CODE(icolor)
void GeometryComparisonPlotter::MakePlots ( const vector< TString >  x,
const vector< TString >  y 
)

-1) check that only existing branches are called

0) min and max values

1) declare TGraphs

2) loop on the TTree data

3) merge TGraph objects into TMultiGraph objects, then draw, print and write (according to the options _batchMode, _print and _write respectively)

TRACKER

SUBLEVELS (1..6)

Definition at line 179 of file GeometryComparisonPlotter.cc.

References _1dModule, _2dModule, _batchMode, _grid_x, _grid_y, _legend, _levelCut, _max, _min, _output_directory, _output_filename, _print, _print_option, _SF, _sublevel_names, _units, _window_height, _window_width, _write, branch_f, branch_i, EnergyCorrector::c, canvas_index, CHECK_BRANCHES, CHECK_MAP_CONTENT, COLOR_CODE, gather_cfg::cout, data, cmsRelvalreport::exit, ExtensionFromPrintOption(), cuy::graphs, INDEX_IN_GLOBAL_CANVAS, INSIDE_VECTOR, plotBeamSpotDB::ipoint, LateXstyle(), LIMITS, MakeLegend(), NB_SUBLEVELS, NB_Z_SLICES, output, and EnergyCorrector::pt.

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 }
list graphs
Definition: cuy.py:960
#define LIMITS(axes_vector)
#define INDEX_IN_GLOBAL_CANVAS(i1, i2)
TLegend * MakeLegend(double x1, double y1, double x2, double y2, const TString title="")
#define CHECK_MAP_CONTENT(m, type)
#define NB_Z_SLICES
map< TString, TString > _units
#define CHECK_BRANCHES(branchname_vector)
tuple cout
Definition: gather_cfg.py:121
#define NB_SUBLEVELS
Definition: DDAxes.h:10
#define COLOR_CODE(icolor)
#define INSIDE_VECTOR(vector)
void GeometryComparisonPlotter::Set1dModule ( const bool  k1dModule)

Definition at line 578 of file GeometryComparisonPlotter.cc.

References _1dModule.

578 { _1dModule = k1dModule ; }
void GeometryComparisonPlotter::Set2dModule ( const bool  k2dModule)

Definition at line 579 of file GeometryComparisonPlotter.cc.

References _2dModule.

579 { _2dModule = k2dModule ; }
void GeometryComparisonPlotter::SetBatchMode ( const bool  kBatchMode)

Definition at line 581 of file GeometryComparisonPlotter.cc.

References _batchMode.

581 { _batchMode = kBatchMode ; }
void GeometryComparisonPlotter::SetBranchMax ( const TString  branchname,
const float  max 
)

Definition at line 585 of file GeometryComparisonPlotter.cc.

References _max, and bookConverter::max.

586  { _max[branchname] = max ; }
void GeometryComparisonPlotter::SetBranchMin ( const TString  branchname,
const float  min 
)

Definition at line 587 of file GeometryComparisonPlotter.cc.

References _min, and min().

588  { _min[branchname] = min ; }
T min(T a, T b)
Definition: MathUtil.h:58
void GeometryComparisonPlotter::SetBranchSF ( const TString  branchname,
const float  SF 
)

Definition at line 589 of file GeometryComparisonPlotter.cc.

References _SF.

590  { _SF[branchname] = SF ; }
void GeometryComparisonPlotter::SetBranchUnits ( const TString  branchname,
const TString  units 
)

Definition at line 591 of file GeometryComparisonPlotter.cc.

References _units, and units().

592  { _units[branchname] = units ; }
map< TString, TString > _units
TString units(TString variable, Char_t axis)
void GeometryComparisonPlotter::SetCanvasSize ( const int  window_width = 3508,
const int  window_height = 2480 
)

Definition at line 594 of file GeometryComparisonPlotter.cc.

References _window_height, and _window_width.

595  { _window_width = window_width ;
596  _window_height = window_height ; }
void GeometryComparisonPlotter::SetGrid ( const int  kGridX,
const int  kGridY 
)
void GeometryComparisonPlotter::SetLegend ( const bool  kLegend)

Definition at line 576 of file GeometryComparisonPlotter.cc.

References _legend.

576 { _legend = kLegend ; }
void GeometryComparisonPlotter::SetLevelCut ( const int  kLevelCut)

Definition at line 580 of file GeometryComparisonPlotter.cc.

References _levelCut.

580 { _levelCut = kLevelCut ; }
void GeometryComparisonPlotter::SetOutputDirectoryName ( const TString  name)

Definition at line 598 of file GeometryComparisonPlotter.cc.

References _output_directory.

599  + TString(name.EndsWith("/") ? "" : "/") ; }
void GeometryComparisonPlotter::SetOutputFileName ( const TString  name)
void GeometryComparisonPlotter::SetPrint ( const bool  kPrint)

Definition at line 575 of file GeometryComparisonPlotter.cc.

References _print.

575 { _print = kPrint ; }
void GeometryComparisonPlotter::SetPrintOption ( const Option_t *  print_option)

Definition at line 593 of file GeometryComparisonPlotter.cc.

References _print_option.

593 { _print_option = print_option ; }
void GeometryComparisonPlotter::SetWrite ( const bool  kWrite)

Definition at line 577 of file GeometryComparisonPlotter.cc.

References _write.

577 { _write = kWrite ; }

Member Data Documentation

bool GeometryComparisonPlotter::_1dModule
private

Definition at line 32 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and Set1dModule().

bool GeometryComparisonPlotter::_2dModule
private

Definition at line 32 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and Set2dModule().

bool GeometryComparisonPlotter::_batchMode
private

Definition at line 32 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and SetBatchMode().

int GeometryComparisonPlotter::_grid_x
private

Definition at line 38 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and SetGrid().

int GeometryComparisonPlotter::_grid_y
private

Definition at line 38 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and SetGrid().

bool GeometryComparisonPlotter::_legend
private

Definition at line 32 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and SetLegend().

int GeometryComparisonPlotter::_levelCut
private

Definition at line 38 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and SetLevelCut().

map<TString, float> GeometryComparisonPlotter::_max
private
map<TString, float> GeometryComparisonPlotter::_min
private
TString GeometryComparisonPlotter::_output_directory
private

Definition at line 28 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and SetOutputDirectoryName().

TString GeometryComparisonPlotter::_output_filename
private

Definition at line 28 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and SetOutputFileName().

bool GeometryComparisonPlotter::_print
private

Definition at line 32 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and SetPrint().

TString GeometryComparisonPlotter::_print_option
private

Definition at line 28 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and SetPrintOption().

map<TString, float> GeometryComparisonPlotter::_SF
private

Definition at line 46 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and SetBranchSF().

TString GeometryComparisonPlotter::_sublevel_names[6]
private

Definition at line 28 of file GeometryComparisonPlotter.h.

Referenced by GeometryComparisonPlotter(), MakeLegend(), and MakePlots().

map<TString, TString> GeometryComparisonPlotter::_units
private

Definition at line 48 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and SetBranchUnits().

int GeometryComparisonPlotter::_window_height
private

Definition at line 38 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and SetCanvasSize().

int GeometryComparisonPlotter::_window_width
private

Definition at line 38 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and SetCanvasSize().

bool GeometryComparisonPlotter::_write
private

Definition at line 32 of file GeometryComparisonPlotter.h.

Referenced by MakePlots(), and SetWrite().

map<TString, float> GeometryComparisonPlotter::branch_f
private

Definition at line 46 of file GeometryComparisonPlotter.h.

Referenced by GeometryComparisonPlotter(), and MakePlots().

map<TString, int> GeometryComparisonPlotter::branch_i
private

Definition at line 45 of file GeometryComparisonPlotter.h.

Referenced by GeometryComparisonPlotter(), and MakePlots().

int GeometryComparisonPlotter::canvas_index
static

Definition at line 66 of file GeometryComparisonPlotter.h.

Referenced by MakePlots().

TTree* GeometryComparisonPlotter::data
private
TFile* GeometryComparisonPlotter::output
private

Definition at line 52 of file GeometryComparisonPlotter.h.

Referenced by MakePlots().

TFile* GeometryComparisonPlotter::tree_file
private