CMS 3D CMS Logo

trackSplitPlot.h
Go to the documentation of this file.
1 #ifndef ALIGNMENT_OFFLINEVALIDATION_TRACKSPLITPLOT_H
2 #define ALIGNMENT_OFFLINEVALIDATION_TRACKSPLITPLOT_H
3 
4 #include <fstream>
5 #include <iostream>
6 #include <sstream>
7 #include <cmath>
8 #include "TCanvas.h"
9 #include "TClass.h"
10 #include "TColor.h"
11 #include "TFile.h"
12 #include "TF1.h"
13 #include "TGaxis.h"
14 #include "TGraph2DErrors.h"
15 #include "TGraphErrors.h"
16 #include "TH1.h"
17 #include "TH1F.h"
18 #include "TH2F.h"
19 #include "TLegend.h"
20 #include "TLegendEntry.h"
21 #include "TList.h"
22 #include "TMath.h"
23 #include "TMultiGraph.h"
24 #include "TObject.h"
25 #include "TProfile.h"
26 #include "TROOT.h"
27 #include "TString.h"
28 #include "TStyle.h"
29 #include "TSystem.h"
30 #include "TText.h"
31 #include "TTree.h"
32 
35 
36 const Double_t pi = TMath::Pi();
37 vector<Color_t> colors;
38 vector<Style_t> styles;
39 bool colorsset = false;
40 Int_t minrun = -1;
41 Int_t maxrun = -1;
42 const Int_t xsize = 8;
43 const Int_t ysize = 9;
44 Int_t legendGrid = 100;
45 Double_t margin = .1;
46 Double_t increaseby = .1;
47 
48 TString xvariables[xsize] = {"", "pt", "eta", "phi", "dz", "dxy", "theta", "qoverpt"};
49 TString yvariables[ysize] = {"pt", "pt", "eta", "phi", "dz", "dxy", "theta", "qoverpt", ""};
50 Bool_t relativearray[ysize] = {true, false, false, false, false, false, false, false, false};
51 
52 TList *stufftodelete = new TList();
53 
54 TString subdetector = "PIXEL";
55 double outliercut = 0.99; //use the middle 99% of tracks to find the mean and RMS
56  //(a few tracks are fit badly and skew them otherwise)
57 
58 /***********************************
59 Table Of Contents
60 0. Track Split Plot
61 1. Misalignment Dependence
62 2. Make Plots
63 3. Axis Label
64 4. Axis Limits
65 5. Place Legend
66 ***********************************/
67 
68 #include "trackSplitPlot.h"
69 
70 ofstream devnull("/dev/null");
71 template <typename T>
73  return t;
74 }
75 
76 //===================
77 //0. Track Split Plot
78 //===================
79 
80 TCanvas *trackSplitPlot(Int_t nFiles,
81  TString *files,
82  TString *names,
83  TString xvar,
84  TString yvar,
85  Bool_t relative = false,
86  Bool_t resolution = false,
87  Bool_t pull = false,
88  TString saveas = "",
89  ostream &summaryfile = devnull);
90 TCanvas *trackSplitPlot(Int_t nFiles,
91  TString *files,
92  TString *names,
93  TString var,
94  Bool_t relative = false,
95  Bool_t pull = false,
96  TString saveas = "",
97  ostream &summaryfile = devnull);
98 TCanvas *trackSplitPlot(TString file,
99  TString xvar,
100  TString yvar,
101  Bool_t profile = false,
102  Bool_t relative = false,
103  Bool_t resolution = false,
104  Bool_t pull = false,
105  TString saveas = "",
106  ostream &summaryfile = devnull);
107 TCanvas *trackSplitPlot(TString file,
108  TString var,
109  Bool_t relative = false,
110  Bool_t pull = false,
111  TString saveas = "",
112  ostream &summaryfile = devnull);
113 void placeholder(TString saveas = "", Bool_t wide = false);
114 void saveplot(TCanvas *c1, TString saveas);
115 void deleteCanvas(TObject *canvas);
116 void setupcolors();
117 void runNumberZoomed(Int_t nFiles,
118  TString *files,
119  TString *names,
120  TString yvar,
121  Bool_t relative = false,
122  Bool_t resolution = false,
123  Bool_t pull = false,
124  Int_t firstRun = -1,
125  Int_t lastRun = -1,
126  TString saveas = "");
127 
128 //==========================
129 //1. Misalignment Dependence
130 //==========================
131 
132 void misalignmentDependence(TCanvas *c1old,
133  Int_t nFiles,
134  TString *names,
135  TString misalignment,
136  Double_t *values,
137  Double_t *phases,
138  TString xvar,
139  TString yvar,
140  TF1 *function,
141  Int_t parameter,
142  TString parametername = "",
143  TString functionname = "",
144  Bool_t relative = false,
145  Bool_t resolution = false,
146  Bool_t pull = false,
147  TString saveas = "");
148 void misalignmentDependence(TCanvas *c1old,
149  Int_t nFiles,
150  TString *names,
151  TString misalignment,
152  Double_t *values,
153  Double_t *phases,
154  TString xvar,
155  TString yvar,
156  TF1 *function,
157  Int_t nParameters,
158  Int_t *parameters,
159  TString *parameternames,
160  TString functionname = "",
161  Bool_t relative = false,
162  Bool_t resolution = false,
163  Bool_t pull = false,
164  TString saveas = "");
165 void misalignmentDependence(Int_t nFiles,
166  TString *files,
167  TString *names,
168  TString misalignment,
169  Double_t *values,
170  Double_t *phases,
171  TString xvar,
172  TString yvar,
173  TF1 *function,
174  Int_t parameter,
175  TString parametername = "",
176  TString functionname = "",
177  Bool_t relative = false,
178  Bool_t resolution = false,
179  Bool_t pull = false,
180  TString saveas = "");
181 void misalignmentDependence(Int_t nFiles,
182  TString *files,
183  TString *names,
184  TString misalignment,
185  Double_t *values,
186  Double_t *phases,
187  TString xvar,
188  TString yvar,
189  TF1 *function,
190  Int_t nParameters,
191  Int_t *parameters,
192  TString *parameternames,
193  TString functionname = "",
194  Bool_t relative = false,
195  Bool_t resolution = false,
196  Bool_t pull = false,
197  TString saveas = "");
198 void misalignmentDependence(TCanvas *c1old,
199  Int_t nFiles,
200  TString *names,
201  TString misalignment,
202  Double_t *values,
203  Double_t *phases,
204  TString xvar,
205  TString yvar,
206  TString function,
207  Int_t parameter,
208  TString parametername = "",
209  TString functionname = "",
210  Bool_t relative = false,
211  Bool_t resolution = false,
212  Bool_t pull = false,
213  TString saveas = "");
214 void misalignmentDependence(TCanvas *c1old,
215  Int_t nFiles,
216  TString *names,
217  TString misalignment,
218  Double_t *values,
219  Double_t *phases,
220  TString xvar,
221  TString yvar,
222  TString function,
223  Int_t nParameters,
224  Int_t *parameters,
225  TString *parameternames,
226  TString functionname = "",
227  Bool_t relative = false,
228  Bool_t resolution = false,
229  Bool_t pull = false,
230  TString saveas = "");
231 void misalignmentDependence(Int_t nFiles,
232  TString *files,
233  TString *names,
234  TString misalignment,
235  Double_t *values,
236  Double_t *phases,
237  TString xvar,
238  TString yvar,
239  TString function,
240  Int_t parameter,
241  TString parametername = "",
242  TString functionname = "",
243  Bool_t relative = false,
244  Bool_t resolution = false,
245  Bool_t pull = false,
246  TString saveas = "");
247 void misalignmentDependence(Int_t nFiles,
248  TString *files,
249  TString *names,
250  TString misalignment,
251  Double_t *values,
252  Double_t *phases,
253  TString xvar,
254  TString yvar,
255  TString function,
256  Int_t nParameters,
257  Int_t *parameters,
258  TString *parameternames,
259  TString functionname = "",
260  Bool_t relative = false,
261  Bool_t resolution = false,
262  Bool_t pull = false,
263  TString saveas = "");
264 Bool_t misalignmentDependence(TCanvas *c1old,
265  Int_t nFiles,
266  TString *names,
267  TString misalignment,
268  Double_t *values,
269  Double_t *phases,
270  TString xvar,
271  TString yvar,
272  Bool_t drawfits = true,
273  Bool_t relative = false,
274  Bool_t resolution = false,
275  Bool_t pull = false,
276  TString saveas = "");
277 Bool_t misalignmentDependence(Int_t nFiles,
278  TString *files,
279  TString *names,
280  TString misalignment,
281  Double_t *values,
282  Double_t *phases,
283  TString xvar,
284  TString yvar,
285  Bool_t drawfits = true,
286  Bool_t relative = false,
287  Bool_t resolution = false,
288  Bool_t pull = false,
289  TString saveas = "");
290 Bool_t hasFit(TString misalignment,
291  TString xvar,
292  TString yvar,
293  Bool_t relative = false,
294  Bool_t resolution = false,
295  Bool_t pull = false);
296 
297 //=============
298 //2. Make Plots
299 //=============
300 
301 void makePlots(Int_t nFiles,
302  TString *files,
303  TString *names,
304  TString misalignment,
305  Double_t *values,
306  Double_t *phases,
307  TString directory,
308  Bool_t matrix[xsize][ysize]);
309 void makePlots(Int_t nFiles, TString *files, TString *names, TString directory, Bool_t matrix[xsize][ysize]);
310 void makePlots(TString file,
311  TString misalignment,
312  Double_t *values,
313  Double_t *phases,
314  TString directory,
315  Bool_t matrix[xsize][ysize]);
316 void makePlots(TString file, TString directory, Bool_t matrix[xsize][ysize]);
317 void makePlots(Int_t nFiles,
318  TString *files,
319  TString *names,
320  TString misalignment,
321  Double_t *values,
322  Double_t *phases,
323  TString directory,
324  TString xvar,
325  TString yvar);
326 void makePlots(Int_t nFiles, TString *files, TString *names, TString directory, TString xvar, TString yvar);
327 void makePlots(TString file,
328  TString misalignment,
329  Double_t *values,
330  Double_t *phases,
331  TString directory,
332  TString xvar,
333  TString yvar);
334 void makePlots(TString file, TString directory, TString xvar, TString yvar);
335 void makePlots(Int_t nFiles,
336  TString *files,
337  TString *names,
338  TString misalignment,
339  Double_t *values,
340  Double_t *phases,
341  TString directory);
342 void makePlots(Int_t nFiles, TString *files, TString *names, TString directory);
343 void makePlots(TString file, TString misalignment, Double_t *values, Double_t *phases, TString directory);
344 void makePlots(TString file, TString directory);
345 
346 //=============
347 //3. Axis Label
348 //=============
349 
350 TString fancyname(TString variable);
351 TString units(TString variable, Char_t axis);
352 TString plainunits(TString variable, Char_t axis);
353 TString latexunits(TString variable, Char_t axis);
354 TString axislabel(
355  TString variable, Char_t axis, Bool_t relative = false, Bool_t resolution = false, Bool_t pull = false);
356 TString latexlabel(
357  TString variable, Char_t axis, Bool_t relative = false, Bool_t resolution = false, Bool_t pull = false);
358 void setAxisLabels(TH1 *p, PlotType type, TString xvar, TString yvar, Bool_t relative, Bool_t pull);
359 void setAxisLabels(TMultiGraph *p, PlotType type, TString xvar, TString yvar, Bool_t relative, Bool_t pull);
360 TString nPart(Int_t part, TString string, TString delimit = ";", Bool_t removerest = true);
361 
362 //==============
363 //4. Axis Limits
364 //==============
365 
366 Double_t findStatistic(Statistic what,
367  Int_t nFiles,
368  TString *files,
369  TString var,
370  Char_t axis,
371  Bool_t relative = false,
372  Bool_t pull = false);
373 Double_t findAverage(
374  Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
375 Double_t findMin(Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
376 Double_t findMax(Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
377 Double_t findRMS(Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
378 Double_t findStatistic(
379  Statistic what, TString file, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
380 Double_t findAverage(TString file, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
381 Double_t findMin(TString file, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
382 Double_t findMax(TString file, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
383 Double_t findRMS(TString file, TString var, Char_t axis, Bool_t relative = false, Bool_t pull = false);
384 void axislimits(Int_t nFiles,
385  TString *files,
386  TString var,
387  Char_t axis,
388  Bool_t relative,
389  Bool_t pull,
390  Double_t &min,
391  Double_t &max,
392  Double_t &bins);
393 
394 //===============
395 //5. Place Legend
396 //===============
397 
398 Double_t placeLegend(
399  TLegend *l, Double_t width, Double_t height, Double_t x1min, Double_t y1min, Double_t x2max, Double_t y2max);
400 Bool_t fitsHere(TLegend *l, Double_t x1, Double_t y1, Double_t x2, Double_t y2);
401 
402 #endif
TString yvariables[ysize]
const double Pi
TList * stufftodelete
Double_t increaseby
TString xvariables[xsize]
double outliercut
Double_t findStatistic(Statistic what, Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative=false, Bool_t pull=false)
void axislimits(Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative, Bool_t pull, Double_t &min, Double_t &max, Double_t &bins)
vector< Style_t > styles
TString latexunits(TString variable, Char_t axis)
TString subdetector
PlotType
Double_t findRMS(Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative=false, Bool_t pull=false)
void deleteCanvas(TObject *canvas)
Int_t maxrun
const Int_t ysize
const std::string names[nVars_]
TString fancyname(TString variable)
const Double_t pi
ofstream devnull("/dev/null")
void setAxisLabels(TH1 *p, PlotType type, TString xvar, TString yvar, Bool_t relative, Bool_t pull)
vector< Color_t > colors
void placeholder(TString saveas="", Bool_t wide=false)
void runNumberZoomed(Int_t nFiles, TString *files, TString *names, TString yvar, Bool_t relative=false, Bool_t resolution=false, Bool_t pull=false, Int_t firstRun=-1, Int_t lastRun=-1, TString saveas="")
Int_t minrun
Double_t margin
TCanvas * trackSplitPlot(Int_t nFiles, TString *files, TString *names, TString xvar, TString yvar, Bool_t relative=false, Bool_t resolution=false, Bool_t pull=false, TString saveas="", ostream &summaryfile=devnull)
T identity(T t)
void saveplot(TCanvas *c1, TString saveas)
TString nPart(Int_t part, TString string, TString delimit=";", Bool_t removerest=true)
Double_t findMin(Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative=false, Bool_t pull=false)
part
Definition: HCALResponse.h:20
Statistic
Bool_t hasFit(TString misalignment, TString xvar, TString yvar, Bool_t relative=false, Bool_t resolution=false, Bool_t pull=false)
TString units(TString variable, Char_t axis)
Bool_t relativearray[ysize]
bool colorsset
Bool_t fitsHere(TLegend *l, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
def canvas(sub, attr)
Definition: svgfig.py:482
firstRun
Definition: dataset.py:940
const Int_t xsize
Double_t placeLegend(TLegend *l, Double_t width, Double_t height, Double_t x1min, Double_t y1min, Double_t x2max, Double_t y2max)
long double T
Double_t findMax(Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative=false, Bool_t pull=false)
void setupcolors()
void makePlots(Int_t nFiles, TString *files, TString *names, TString misalignment, Double_t *values, Double_t *phases, TString directory, Bool_t matrix[xsize][ysize])
Int_t legendGrid
TString axislabel(TString variable, Char_t axis, Bool_t relative=false, Bool_t resolution=false, Bool_t pull=false)
Double_t findAverage(Int_t nFiles, TString *files, TString var, Char_t axis, Bool_t relative=false, Bool_t pull=false)
TString latexlabel(TString variable, Char_t axis, Bool_t relative=false, Bool_t resolution=false, Bool_t pull=false)
void misalignmentDependence(TCanvas *c1old, Int_t nFiles, TString *names, TString misalignment, Double_t *values, Double_t *phases, TString xvar, TString yvar, TF1 *function, Int_t parameter, TString parametername="", TString functionname="", Bool_t relative=false, Bool_t resolution=false, Bool_t pull=false, TString saveas="")
TString plainunits(TString variable, Char_t axis)