CMS 3D CMS Logo

trackSplitPlot.h
Go to the documentation of this file.
1 #ifndef TRACKSPLITPLOT_H
2 #define 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 "TGaxis.h"
13 #include "TGraph2DErrors.h"
14 #include "TGraphErrors.h"
15 #include "TH1.h"
16 #include "TH1F.h"
17 #include "TH2F.h"
18 #include "TLegend.h"
19 #include "TLegendEntry.h"
20 #include "TList.h"
21 #include "TMath.h"
22 #include "TMultiGraph.h"
23 #include "TObject.h"
24 #include "TProfile.h"
25 #include "TROOT.h"
26 #include "TString.h"
27 #include "TStyle.h"
28 #include "TSystem.h"
29 #include "TText.h"
30 #include "TTree.h"
31 
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> T identity(T t) {return t;}
72 
73 //===================
74 //0. Track Split Plot
75 //===================
76 
77 TCanvas *trackSplitPlot(Int_t nFiles,TString *files,TString *names,TString xvar,TString yvar,
78  Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false,
79  TString saveas = "", ostream& summaryfile=devnull);
80 TCanvas *trackSplitPlot(Int_t nFiles,TString *files,TString *names,TString var,
81  Bool_t relative = false,Bool_t pull = false,TString saveas = "", ostream& summaryfile=devnull);
82 TCanvas *trackSplitPlot(TString file,TString xvar,TString yvar,Bool_t profile = false,
83  Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false,
84  TString saveas = "", ostream& summaryfile=devnull);
85 TCanvas *trackSplitPlot(TString file,TString var,
86  Bool_t relative = false,Bool_t pull = false,
87  TString saveas = "", ostream& summaryfile=devnull);
88 void placeholder(TString saveas = "",Bool_t wide = false);
89 void saveplot(TCanvas *c1,TString saveas);
90 void deleteCanvas(TObject *canvas);
91 void setupcolors();
92 void runNumberZoomed(Int_t nFiles,TString *files,TString *names,TString yvar,
93  Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false,
94  Int_t firstRun = -1,Int_t lastRun = -1,TString saveas = "");
95 
96 //==========================
97 //1. Misalignment Dependence
98 //==========================
99 
100 void misalignmentDependence(TCanvas *c1old,
101  Int_t nFiles,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar,
102  TF1 *function,Int_t parameter,TString parametername = "",TString functionname = "",
103  Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false,
104  TString saveas = "");
105 void misalignmentDependence(TCanvas *c1old,
106  Int_t nFiles,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar,
107  TF1 *function,Int_t nParameters,Int_t *parameters,TString *parameternames,TString functionname = "",
108  Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false,
109  TString saveas = "");
110 void misalignmentDependence(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar,
111  TF1 *function,Int_t parameter,TString parametername = "",TString functionname = "",
112  Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false,
113  TString saveas = "");
114 void misalignmentDependence(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar,
115  TF1 *function,Int_t nParameters,Int_t *parameters,TString *parameternames,TString functionname = "",
116  Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false,
117  TString saveas = "");
118 void misalignmentDependence(TCanvas *c1old,
119  Int_t nFiles,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar,
120  TString function,Int_t parameter,TString parametername = "",TString functionname = "",
121  Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false,
122  TString saveas = "");
123 void misalignmentDependence(TCanvas *c1old,
124  Int_t nFiles,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar,
125  TString function,Int_t nParameters,Int_t *parameters,TString *parameternames,TString functionname = "",
126  Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false,
127  TString saveas = "");
128 void misalignmentDependence(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar,
129  TString function,Int_t parameter,TString parametername = "",TString functionname = "",
130  Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false,
131  TString saveas = "");
132 void misalignmentDependence(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar,
133  TString function,Int_t nParameters,Int_t *parameters,TString *parameternames,TString functionname = "",
134  Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false,
135  TString saveas = "");
136 Bool_t misalignmentDependence(TCanvas *c1old,
137  Int_t nFiles,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar,
138  Bool_t drawfits = true,
139  Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false,
140  TString saveas = "");
141 Bool_t misalignmentDependence(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString xvar,TString yvar,
142  Bool_t drawfits = true,
143  Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false,
144  TString saveas = "");
145 Bool_t hasFit(TString misalignment,TString xvar,TString yvar,Bool_t relative = false,Bool_t resolution = false,Bool_t pull = false);
146 
147 
148 //=============
149 //2. Make Plots
150 //=============
151 
152 void makePlots(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString directory,Bool_t matrix[xsize][ysize]);
153 void makePlots(Int_t nFiles,TString *files,TString *names,TString directory, Bool_t matrix[xsize][ysize]);
154 void makePlots(TString file,TString misalignment,Double_t *values,Double_t *phases,TString directory,Bool_t matrix[xsize][ysize]);
155 void makePlots(TString file,TString directory,Bool_t matrix[xsize][ysize]);
156 void makePlots(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString directory,TString xvar,TString yvar);
157 void makePlots(Int_t nFiles,TString *files,TString *names,TString directory,TString xvar,TString yvar);
158 void makePlots(TString file,TString misalignment,Double_t *values,Double_t *phases,TString directory,
159  TString xvar,TString yvar);
160 void makePlots(TString file,TString directory,TString xvar,TString yvar);
161 void makePlots(Int_t nFiles,TString *files,TString *names,TString misalignment,Double_t *values,Double_t *phases,TString directory);
162 void makePlots(Int_t nFiles,TString *files,TString *names,TString directory);
163 void makePlots(TString file,TString misalignment,Double_t *values,Double_t *phases,TString directory);
164 void makePlots(TString file,TString directory);
165 
166 //=============
167 //3. Axis Label
168 //=============
169 
170 TString fancyname(TString variable);
171 TString units(TString variable,Char_t axis);
172 TString plainunits(TString variable,Char_t axis);
173 TString latexunits(TString variable,Char_t axis);
174 TString axislabel(TString variable, Char_t axis, Bool_t relative = false, Bool_t resolution = false, Bool_t pull = false);
175 TString latexlabel(TString variable, Char_t axis, Bool_t relative = false, Bool_t resolution = false, Bool_t pull = false);
176 void setAxisLabels(TH1 *p, PlotType type,TString xvar,TString yvar,Bool_t relative,Bool_t pull);
177 void setAxisLabels(TMultiGraph *p, PlotType type,TString xvar,TString yvar,Bool_t relative,Bool_t pull);
178 TString nPart(Int_t part,TString string,TString delimit = ";",Bool_t removerest = true);
179 
180 //==============
181 //4. Axis Limits
182 //==============
183 
184 Double_t findStatistic(Statistic what,Int_t nFiles,TString *files,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false);
185 Double_t findAverage(Int_t nFiles,TString *files,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false);
186 Double_t findMin(Int_t nFiles,TString *files,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false);
187 Double_t findMax(Int_t nFiles,TString *files,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false);
188 Double_t findRMS(Int_t nFiles,TString *files,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false);
189 Double_t findStatistic(Statistic what,TString file,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false);
190 Double_t findAverage(TString file,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false);
191 Double_t findMin(TString file,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false);
192 Double_t findMax(TString file,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false);
193 Double_t findRMS(TString file,TString var,Char_t axis,Bool_t relative = false,Bool_t pull = false);
194 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);
195 
196 //===============
197 //5. Place Legend
198 //===============
199 
200 Double_t placeLegend(TLegend *l, Double_t width, Double_t height, Double_t x1min, Double_t y1min, Double_t x2max, Double_t y2max);
201 Bool_t fitsHere(TLegend *l,Double_t x1, Double_t y1, Double_t x2, Double_t y2);
202 
203 #endif
TString yvariables[ysize]
const double Pi
type
Definition: HCALResponse.h:21
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)
T min(T a, T b)
Definition: MathUtil.h:58
void saveplot(TCanvas *c1, TString saveas)
TString nPart(Int_t part, TString string, TString delimit=";", Bool_t removerest=true)
std::vector< int > phases
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)