File indexing completed on 2024-04-06 12:26:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <sstream>
0014 #include <iomanip>
0015
0016 TString getPitchString(TH1 *histo, int prec = 5);
0017
0018
0019 TLegend * getLegend(float x1=0.48, float y1=0.81, float x2=0.98, float y2=0.995);
0020 void setStyle(TH1 *histo);
0021 void setStyle(TH2 *histo);
0022
0023
0024 void setStyle(TH1 *histo) {
0025 histo->GetXaxis()->SetTitleFont(gStyle->GetTitleFont());
0026 histo->GetXaxis()->SetTitleSize(gStyle->GetTitleFontSize());
0027 histo->GetXaxis()->SetLabelFont(gStyle->GetLabelFont());
0028 histo->GetXaxis()->SetLabelSize(gStyle->GetLabelSize());
0029
0030 histo->GetYaxis()->SetTitleFont(gStyle->GetTitleFont());
0031 histo->GetYaxis()->SetTitleSize(gStyle->GetTitleFontSize());
0032 histo->GetYaxis()->SetLabelFont(gStyle->GetLabelFont());
0033 histo->GetYaxis()->SetLabelSize(gStyle->GetLabelSize());
0034 }
0035
0036 void setStyle(TH2 *histo) {
0037 histo->GetXaxis()->SetTitleFont(gStyle->GetTitleFont());
0038 histo->GetXaxis()->SetTitleSize(gStyle->GetTitleFontSize());
0039 histo->GetXaxis()->SetLabelFont(gStyle->GetLabelFont());
0040 histo->GetXaxis()->SetLabelSize(gStyle->GetLabelSize());
0041
0042 histo->GetYaxis()->SetTitleFont(gStyle->GetTitleFont());
0043 histo->GetYaxis()->SetTitleSize(gStyle->GetTitleFontSize());
0044 histo->GetYaxis()->SetLabelFont(gStyle->GetLabelFont());
0045 histo->GetYaxis()->SetLabelSize(gStyle->GetLabelSize());
0046 }
0047
0048 void plotAndProfileX (TH2* h2, float min, float max, bool profile=false) {
0049 setStyle(h2);
0050 gPad->SetGrid(1,1);
0051 gStyle->SetGridColor(15);
0052 h2->GetYaxis()->SetRangeUser(min,max);
0053 h2->Draw();
0054 if (profile) {
0055 TProfile* prof = h2->ProfileX();
0056 prof->SetMarkerColor(2);
0057 prof->SetLineColor(2);
0058 prof->Draw("same");
0059 }
0060 TLine * l = new TLine(h2->GetXaxis()->GetXmin(),0,h2->GetXaxis()->GetXmax(),0);
0061 l->SetLineColor(3);
0062 l->Draw();
0063 }
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 void plotAndProfileXSpread (TH2* h2, float min, float max, bool profile=false, float ymin=-5., float ymax=5.) {
0079 setStyle(h2);
0080 gPad->SetGrid(1,1);
0081 gStyle->SetGridColor(15);
0082 gStyle->SetOptStat(0);
0083
0084
0085
0086
0087 h2->SetMarkerColor(2);
0088 h2->SetLineColor(2);
0089 h2->GetYaxis()->SetTitleOffset(1.4);
0090 h2->GetXaxis()->SetRangeUser(min,max);
0091 h2->GetYaxis()->SetRangeUser(ymin,ymax);
0092 h2->DrawCopy("box");
0093 if (profile) {
0094 TProfile* prof = h2->ProfileX("profile",-1,-1,"s");
0095 prof->SetMarkerStyle(20);
0096 prof->SetMarkerSize(1.2);
0097 prof->SetMarkerColor(1);
0098 prof->SetLineColor(1);
0099 prof->SetLineWidth(2);
0100 prof->DrawCopy("same e1");
0101 }
0102 TLine * l = new TLine(h2->GetXaxis()->GetXmin(),0,h2->GetXaxis()->GetXmax(),0);
0103 l->SetLineColor(3);
0104 l->Draw();
0105 }
0106
0107
0108
0109
0110
0111
0112
0113 void drawGFit(TH1 * h1, float nsigmas, float min, float max){
0114 float minfit = h1->GetMean() - h1->GetRMS();
0115 float maxfit = h1->GetMean() + h1->GetRMS();
0116 drawGFit(h1, min, max, minfit, maxfit);
0117 gPad->Draw();
0118 }
0119
0120 void drawGFit(TH1 * h1, float min, float max){
0121 drawGFit(h1, min, max, min, max);
0122 gPad->Draw();
0123 }
0124
0125
0126 void drawGFit(TH1 * h1, float min, float max, float minfit, float maxfit) {
0127 setStyle(h1);
0128 static int i = 0;
0129 i++;
0130 gPad->SetGrid(1,1);
0131 gStyle->SetGridColor(15);
0132 h1->GetXaxis()->SetRangeUser(min,max);
0133 TF1* g1 = new TF1(TString("g")+i,"gaus",minfit,maxfit);
0134 g1->SetLineColor(2);
0135 g1->SetLineWidth(2);
0136 h1->Fit(g1,"R");
0137 h1->Draw();
0138
0139
0140
0141 }
0142
0143
0144
0145
0146
0147
0148
0149 TCanvas * newCanvas(TString name="", TString title="",
0150 Int_t xdiv=0, Int_t ydiv=0, Int_t form = 1, Int_t w=-1){
0151 static int i = 1;
0152 if (name == "") {
0153 name = TString("Canvas ") + i;
0154 i++;
0155 }
0156 if (title == "") title = name;
0157 if (w<0) {
0158 TCanvas * c = new TCanvas(name,title, form);
0159 } else {
0160 TCanvas * c = new TCanvas(name,title,form,w);
0161 }
0162 if (xdiv*ydiv!=0) c->Divide(xdiv,ydiv);
0163 c->cd(1);
0164 return c;
0165 }
0166
0167
0168 TCanvas * newCanvas(Int_t xdiv, Int_t ydiv, Int_t form = 1) {
0169 return newCanvas("","",xdiv,ydiv,form);
0170 }
0171
0172
0173 TCanvas * newCanvas(Int_t form = 1)
0174 {
0175 return newCanvas(0,0,form);
0176 }
0177
0178 TCanvas * newCanvas(TString name, Int_t xdiv, Int_t ydiv, Int_t form,
0179 Int_t w) {
0180 return newCanvas(name, name,xdiv,ydiv,form,w);
0181 }
0182
0183 TCanvas * newCanvas(TString name, Int_t form, Int_t w=-1)
0184 {
0185 return newCanvas(name, name, 0,0,form,w);
0186 }
0187
0188
0189
0190
0191
0192
0193 void printCanvasesPS(TString name){
0194 TPostScript * ps = new TPostScript(name,112);
0195 TIter iter(gROOT->GetListOfCanvases());
0196 TCanvas *c;
0197 while( (c = (TCanvas *)iter()) )
0198 {
0199 c->cd();
0200 cout << "Printing " << c->GetName() << endl;
0201 ps->NewPage();
0202 c->Draw();
0203 }
0204 cout << " File " << name << " was created" << endl;
0205 ps->Close();
0206 }
0207
0208 void printCanvasesEps(){
0209 TIter iter(gROOT->GetListOfCanvases());
0210 TCanvas *c;
0211 while( (c = (TCanvas *)iter()) ) {
0212 c->Print(0,".eps");
0213 }
0214 }
0215
0216 void printCanvasesEps2() {
0217 gROOT->GetListOfCanvases()->Print(".eps");
0218 }
0219
0220 void printCanvases(TString type=".eps"){
0221 TIter iter(gROOT->GetListOfCanvases());
0222 TCanvas *c;
0223 while( (c = (TCanvas *)iter()) ) {
0224 c->cd();
0225 c->Print(0,type);
0226 }
0227 }
0228
0229
0230
0231
0232
0233
0234 TStyle * getStyle(TString name="myStyle")
0235 {
0236 TStyle *theStyle;
0237 if ( name == "myStyle" ) {
0238 theStyle = new TStyle("myStyle", "myStyle");
0239
0240 theStyle->SetPadBorderMode(0);
0241 theStyle->SetCanvasBorderMode(0);
0242 theStyle->SetPadColor(0);
0243 theStyle->SetCanvasColor(0);
0244 theStyle->SetMarkerStyle(8);
0245 theStyle->SetMarkerSize(0.7);
0246 theStyle->SetStatH(0.3);
0247 theStyle->SetStatW(0.15);
0248
0249
0250 theStyle->SetTitleBorderSize(1);
0251 theStyle->SetPalette(1);
0252
0253 } else if( name == "tdr" ) {
0254 theStyle = new TStyle("tdrStyle","Style for P-TDR");
0255
0256
0257 theStyle->SetCanvasBorderMode(0);
0258 theStyle->SetCanvasColor(kWhite);
0259 theStyle->SetCanvasDefH(600);
0260 theStyle->SetCanvasDefW(600);
0261 theStyle->SetCanvasDefX(0);
0262 theStyle->SetCanvasDefY(0);
0263
0264
0265 theStyle->SetPadBorderMode(0);
0266
0267 theStyle->SetPadColor(kWhite);
0268 theStyle->SetPadGridX(true);
0269 theStyle->SetPadGridY(true);
0270 theStyle->SetGridColor(0);
0271 theStyle->SetGridStyle(3);
0272 theStyle->SetGridWidth(1);
0273
0274
0275 theStyle->SetFrameBorderMode(0);
0276 theStyle->SetFrameBorderSize(1);
0277 theStyle->SetFrameFillColor(0);
0278 theStyle->SetFrameFillStyle(0);
0279 theStyle->SetFrameLineColor(1);
0280 theStyle->SetFrameLineStyle(1);
0281 theStyle->SetFrameLineWidth(1);
0282
0283
0284
0285
0286 theStyle->SetHistLineColor(1);
0287 theStyle->SetHistLineStyle(0);
0288 theStyle->SetHistLineWidth(1);
0289
0290
0291
0292 theStyle->SetEndErrorSize(2);
0293
0294 theStyle->SetErrorX(0.);
0295
0296 theStyle->SetMarkerStyle(20);
0297
0298
0299 theStyle->SetOptFit(1);
0300 theStyle->SetFitFormat("5.4g");
0301 theStyle->SetFuncColor(2);
0302 theStyle->SetFuncStyle(1);
0303 theStyle->SetFuncWidth(1);
0304
0305
0306 theStyle->SetOptDate(0);
0307
0308
0309
0310
0311 theStyle->SetOptFile(0);
0312
0313 theStyle->SetOptStat(10);
0314 theStyle->SetStatColor(kWhite);
0315 theStyle->SetStatFont(42);
0316 theStyle->SetStatFontSize(0.07);
0317 theStyle->SetStatTextColor(1);
0318 theStyle->SetStatFormat("6.4g");
0319 theStyle->SetStatBorderSize(1);
0320 theStyle->SetStatH(0.3);
0321 theStyle->SetStatW(0.2);
0322
0323
0324
0325
0326
0327 theStyle->SetPadTopMargin(0.05);
0328 theStyle->SetPadBottomMargin(0.13);
0329 theStyle->SetPadLeftMargin(0.16);
0330 theStyle->SetPadRightMargin(0.02);
0331
0332
0333
0334 theStyle->SetOptTitle(0);
0335 theStyle->SetTitleFont(42);
0336 theStyle->SetTitleColor(1);
0337 theStyle->SetTitleTextColor(1);
0338 theStyle->SetTitleFillColor(10);
0339 theStyle->SetTitleFontSize(0.05);
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349 theStyle->SetTitleColor(1, "XYZ");
0350 theStyle->SetTitleFont(42, "XYZ");
0351 theStyle->SetTitleSize(0.06, "XYZ");
0352
0353
0354 theStyle->SetTitleXOffset(0.9);
0355 theStyle->SetTitleYOffset(1.25);
0356
0357
0358
0359
0360 theStyle->SetLabelColor(1, "XYZ");
0361 theStyle->SetLabelFont(42, "XYZ");
0362 theStyle->SetLabelOffset(0.007, "XYZ");
0363 theStyle->SetLabelSize(0.045, "XYZ");
0364
0365
0366
0367 theStyle->SetAxisColor(1, "XYZ");
0368 theStyle->SetStripDecimals(kTRUE);
0369 theStyle->SetTickLength(0.03, "XYZ");
0370 theStyle->SetNdivisions(510, "XYZ");
0371 theStyle->SetPadTickX(1);
0372 theStyle->SetPadTickY(1);
0373
0374
0375 theStyle->SetOptLogx(0);
0376 theStyle->SetOptLogy(0);
0377 theStyle->SetOptLogz(0);
0378
0379
0380 theStyle->SetPaperSize(20.,20.);
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397 } else {
0398
0399 theStyle = gStyle;
0400 }
0401 return theStyle;
0402 }