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