-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNicePlots.C
271 lines (268 loc) · 6.57 KB
/
NicePlots.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#include "TLegend.h"
#include "THStack.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TGraph.h"
#include "TGraphErrors.h"
#include "TLatex.h"
#include "TMarker.h"
#include <limits.h>
#include <queue>
#include <iostream>
namespace {
short colors[7]={kRed,kBlue,kGreen+2,kMagenta+3,kOrange+4,kCyan+1,kMagenta-7};
short styles[7]={kFullCircle,kOpenSquare,kFullTriangleUp,kFullDiamond,kFullCross,kFullStar,kOpenCircle};
/* const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";*/
}
using namespace std;
template<class T>
T* zeroArray(int n,T* type){
T* r = new T[n];
for (int i = 0; i < n; ++i)
{
r[i] = 0;
}
return r;
}
float* zeroArray(int n){
float* r = new float[n];
for (int i = 0; i < n; ++i)
{
r[i] = 0;
}
return r;
}
template<class T>
T* clone(T* a,int SIZE){
T* r = new T[SIZE];
for (int i = 0; i < SIZE; ++i)
{
r[i] = a[i];
}
return r;
}
/*template<class T>
queue<T> clone(queue<T> *q){
queue<T> r;
while(!q->empty()){
r.push(q->front());
}
}*/
void makeBins(float* bins, int min, int nBins, float width){
for(int i=0; i<=nBins;++i){
bins[i] = min + width*i;
}
}
float* makeBins(float min, float max, float width, int* nBins){ //nBins can't be NULL
*nBins =(int)((max-min+.5)/width);
float *bins= new float[*nBins];
for(int i=0; i<= *nBins;++i){
bins[i] = min + width*i;
}
return bins;
}
void makeMarkerNice(TH1F** h, int n){
for (int i = 1; i < n; ++i)
{
(*h)->SetMarkerStyle(styles[i-1]);
(*h)->SetMarkerColor(colors[i-1]);
h++;
}
}
void makeMarkerNice(TGraph** h, int n){
for (int i = 1; i < n; ++i)
{
(*h)->SetMarkerStyle(styles[i-1]);
(*h)->SetMarkerColor(colors[i-1]);
h++;
}
}
void makeMarkerNice(TGraphErrors** h, int n){
for (int i = 1; i < n; ++i)
{
(*h)->SetMarkerStyle(styles[i-1]);
(*h)->SetMarkerColor(colors[i-1]);
h++;
}
}
/*void gNice(){
gStyle->SetOptStat(0);
gStyle->SetErrorX(0);
}*/
void fixOffset(TH1* plot){
plot->GetYaxis()->SetTitleOffset(1);
plot->GetXaxis()->SetTitleOffset(1);
}
void makeLineColors(TH1F** h, int n){
for (int i = 1; i < n; ++i)
{
(*h)->SetLineColor(colors[i-1]);
h++;
}
}
void makeDifferent(TH1* h, int i){
h->SetLineColor(colors[i]);
h->SetMarkerStyle(styles[i]);
h->SetMarkerColor(colors[i]);
}
void makeDifferent(TGraph* h, int i){
h->SetLineColor(colors[i]);
h->SetMarkerStyle(styles[i]);
h->SetMarkerColor(colors[i]);
}
void makeDifferent(queue<TH1F*> hQ){
int i=0;
while(!hQ.empty()){
hQ.front()->SetLineColor(colors[i]);
hQ.front()->SetMarkerStyle(styles[i]);
hQ.front()->SetMarkerColor(colors[i]);
hQ.pop();
i++;
}
}
void makeDifferent(TH1F** h, int SIZE){
for (int i = 0; i < SIZE; ++i)
{
h[i]->SetLineColor(colors[i]);
h[i]->SetMarkerStyle(styles[i]);
h[i]->SetMarkerColor(colors[i]);
}
}
void makeLegendPoint(TLegend* tl, TH1F** h, int n, std::string *titles){
for (int i = 0; i < n; ++i)
{
tl->AddEntry((*h++),titles++->c_str(),"p");
}
}
void makeLegendLine(TLegend* tl, TH1F** h, int n, std::string *titles){
for (int i = 0; i < n; ++i)
{
tl->AddEntry((*h++),titles++->c_str(),"l");
}
}
void makeNiceHist(TH1* h){
h->SetMarkerStyle(kFullCircle);
}
void axisTitles(TH1* h,std::string x, std::string y){
h->GetYaxis()->SetTitle(y.c_str());
h->GetXaxis()->SetTitle(x.c_str());
}
void axisTitles(TGraph* h,std::string x, std::string y){
h->GetYaxis()->SetTitle(y.c_str());
h->GetXaxis()->SetTitle(x.c_str());
}
void axisTitles(THStack* h,std::string x, std::string y){
h->GetYaxis()->SetTitle(y.c_str());
h->GetXaxis()->SetTitle(x.c_str());
}
/*void smallBorders(){
gPad->SetBottomMargin(.1);
gPad->SetTopMargin(.1);
}*/
void axisTitleSize(TH1F* h,float s){
h->GetYaxis()->SetTitleSize(s);
h->GetXaxis()->SetTitleSize(s);
}
void axisTitleSize(TH2F* h,float s){
h->GetYaxis()->SetTitleSize(s);
h->GetXaxis()->SetTitleSize(s);
}
void axisLabelSize(TH1F* h,float s){
h->GetYaxis()->SetLabelSize(s);
h->GetXaxis()->SetLabelSize(s);
}
template<class T>
void axisTitleOffset(T* h, float s){
h->GetYaxis()->SetTitleOffset(s);
h->GetXaxis()->SetTitleOffset(s);
}
void myMarkerText(Double_t x,Double_t y,Int_t color,Int_t mstyle, const char *text,Float_t msize,Double_t tsize)
{
// Double_t tsize=0.032;
TMarker *marker = new TMarker(x-(0.4*tsize),y,8);
marker->SetMarkerColor(color); marker->SetNDC();
marker->SetMarkerStyle(mstyle);
marker->SetMarkerSize(msize);
marker->Draw();
TLatex l; l.SetTextAlign(12); l.SetTextSize(tsize);
l.SetNDC();
l.DrawLatex(x,y,text);
}
void doubleZero(TGraph *h, float y, float x){
h->GetYaxis()->SetRangeUser(0,y);
h->GetXaxis()->SetRangeUser(0,x);
}
void doubleZero(TH1F *h, float y, float x){
h->GetYaxis()->SetRangeUser(0,y);
h->GetXaxis()->SetRangeUser(0,x);
}
void printHist(TH1F *h){
cout<<h->GetName()<<":\n";
for (int i = 0; i < h->GetNbinsX(); ++i)
{
cout<<"Bin"<<i<<":"<<h->GetBinContent(i)<<'\n';
}
}
inline string getNextPlotName(int* plotcount){
string r= "plot"+to_string(*plotcount);
*plotcount = *plotcount+1;
return r;
}
void normalizeTotal(TH1F** hlist,int SIZE){
float sum=0;
for (int i = 0; i < SIZE; ++i)
{
sum+=hlist[i]->Integral();
}
for (int i = 0; i < SIZE; ++i)
{
hlist[i]->Scale(1/sum);
}
}
void normalizeBins(TH1F** hlist, int SIZE){ // note that this does not propagate the error
for (int i = 1; i <= hlist[0]->GetNbinsX(); ++i)
{
double sum=0;
for (int j = 0; j < SIZE; ++j)
{
sum+=hlist[j]->GetBinContent(i);
}
if(sum==0)continue;
//cout<<"Sum"<<i<<":"<<sum<<'\n';
for (int j = 0; j < SIZE; ++j)
{
hlist[j]->SetBinContent(i,hlist[j]->GetBinContent(i)/sum);
}
}
}
THStack* getStack(TH1F** hlist, int SIZE){
string thisName = string(hlist[0]->GetName())+"Stack";
THStack *r = new THStack(thisName.c_str(),hlist[0]->GetTitle());
for (int i = 0; i < SIZE; ++i)
{
r->Add(hlist[i],"");
}
return r;
}
THStack* getStack(TH1F** hlist, int SIZE,string options){
string thisName = string(hlist[0]->GetName())+"Stack";
THStack *r = new THStack(thisName.c_str(),hlist[0]->GetTitle());
for (int i = 0; i < SIZE; ++i)
{
r->Add(hlist[i],options.c_str());
}
return r;
}
THStack* getStack(TH1F** hlist, int SIZE,string options,string xTitle, string yTitle){ //must be drawn before it can be editted
string thisName = string(hlist[0]->GetName())+"Stack";
THStack *r = new THStack(thisName.c_str(),hlist[0]->GetTitle());
for (int i = 0; i < SIZE; ++i)
{
r->Add(hlist[i],options.c_str());
}
return r;
}