Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:18:38

0001 #include <iostream>
0002 #include <vector>
0003 #include <sstream>
0004 #include <string>
0005 
0006 #include "TGaxis.h"
0007 #include "TString.h"
0008 #include "TF1.h"
0009 #include "TH1.h"
0010 #include "TH2.h"
0011 #include "TH3.h"
0012 #include "TMath.h"
0013 #include "TTree.h"
0014 #include "TChain.h"
0015 #include "TFile.h"
0016 #include "TCanvas.h"
0017 #include "TSystem.h"
0018 #include "TROOT.h"
0019 #include "TGraph.h"
0020 #include "TGraphErrors.h"
0021 #include "TGraphAsymmErrors.h"
0022 #include "TMultiGraph.h"
0023 #include "TCanvas.h"
0024 #include "TPad.h"
0025 #include "TLegend.h"
0026 #include "TLatex.h"
0027 #include "TLine.h"
0028 #include "TAxis.h"
0029 #include "TGraph.h"
0030 #include "TGraphErrors.h"
0031 #include "TLorentzVector.h"
0032 #include "TFitResult.h"
0033 #include "TFitResultPtr.h"
0034 #include "TMatrixDSym.h"
0035 #include "TMatrixD.h"
0036 #include "TArrow.h"
0037 
0038 void RiceStyle(){
0039 
0040 std::cout << "Welcome to Rice Heavy Ion group!! " << std::endl;
0041 
0042 }
0043 
0044 //make Canvas
0045 
0046 TCanvas* makeCanvas(const char* name, const char *title, bool doLogx = false, bool doLogy = false ){
0047     
0048     // Start with a canvas
0049     TCanvas *canvas = new TCanvas(name,title, 1, 1 ,600 ,600 );
0050     // General overall stuff
0051     canvas->SetFillColor      (0);
0052     canvas->SetBorderMode     (0);
0053     canvas->SetBorderSize     (10);
0054     // Set margins to reasonable defaults
0055     canvas->SetLeftMargin     (0.13);
0056     canvas->SetRightMargin    (0.10);
0057     canvas->SetTopMargin      (0.10);
0058     canvas->SetBottomMargin   (0.13);
0059     // Setup a frame which makes sense
0060     canvas->SetFrameFillStyle (0);
0061     canvas->SetFrameLineStyle (0);
0062     canvas->SetFrameBorderMode(0);
0063     canvas->SetFrameBorderSize(10);
0064     canvas->SetFrameFillStyle (0);
0065     canvas->SetFrameLineStyle (0);
0066     canvas->SetFrameBorderMode(0);
0067     canvas->SetFrameBorderSize(10);
0068 
0069     if( doLogy == true ) gPad->SetLogy(1);
0070     if( doLogx == true ) gPad->SetLogx(1);
0071     
0072     gPad->SetTicks();
0073 
0074     return canvas;
0075 }
0076 
0077 TCanvas* makeMultiCanvas(const char* name, 
0078                          const char* title,
0079                          int nRows,
0080                          int nColumns
0081 ){
0082 
0083     double ratio = nRows/nColumns;
0084 
0085     TCanvas* canvas = new TCanvas( name, title, 1, 1, 400*nRows, 400*nColumns );
0086     canvas->SetFillColor      (0);
0087     canvas->SetBorderMode     (0);
0088     canvas->SetBorderSize     (10);
0089     // Set margins to reasonable defaults
0090     canvas->SetLeftMargin     (0.30);
0091     canvas->SetRightMargin    (0.10);
0092     canvas->SetTopMargin      (0.10);
0093     canvas->SetBottomMargin   (0.30);
0094     // Setup a frame which makes sense
0095     canvas->SetFrameFillStyle (0);
0096     canvas->SetFrameLineStyle (0);
0097     canvas->SetFrameBorderMode(0);
0098     canvas->SetFrameBorderSize(10);
0099     canvas->SetFrameFillStyle (0);
0100     canvas->SetFrameLineStyle (0);
0101     canvas->SetFrameBorderMode(0);
0102     canvas->SetFrameBorderSize(10);
0103     
0104     canvas->Divide(nRows,nColumns,0.01,0.01);
0105 
0106     gPad->SetLeftMargin(0.3);
0107     gPad->SetBottomMargin(0.3);
0108     return canvas;
0109 
0110 }
0111 
0112 void saveCanvas(TCanvas* c, TString dir, TString filename)
0113 {
0114    TDatime* date = new TDatime();
0115    //c->Print(Form("../%s/%s_%d.eps",dir.Data(),filename.Data(),date->GetDate()));
0116    //c->Print(Form("../%s/%s_%d.gif",dir.Data(),filename.Data(),date->GetDate()));
0117    c->Print(Form("../%s/%s_%d.pdf",dir.Data(),filename.Data(),date->GetDate()));
0118    //c->Print(Form("../%s/%s_%d.C",dir.Data(),filename.Data(),date->GetDate()));
0119    c->Print(Form("../%s/%s_%d.png",dir.Data(),filename.Data(),date->GetDate()));
0120 }
0121 
0122 void initSubPad(TPad* pad, int i)
0123 {
0124   //printf("Pad: %p, index: %d\n",pad,i);
0125 
0126   pad->cd(i);
0127   TPad *tmpPad = (TPad*) pad->GetPad(i);
0128   tmpPad->SetLeftMargin  (0.20);
0129   tmpPad->SetTopMargin   (0.06);
0130   tmpPad->SetRightMargin (0.08);
0131   tmpPad->SetBottomMargin(0.15);
0132   return;
0133 }
0134 
0135 vector<TPad*> makeMultiPad(const int num){//we only have 4,6,8 options for now
0136 
0137     cout << "num: "<< num << endl;
0138     vector<TPad*> temp;
0139 
0140     TPad* pad[ num ];
0141 
0142     double setting1[] = {0.0, 0.35, 0.56, 1.0};
0143     double setting2[] = {0.0, 0.35, 0.40, 0.7, 1.0 };
0144     double setting3[] = {0.0, 0.35, 0.3, 0.533, 0.766, 1.0};
0145 
0146     if ( num == 4 ){
0147 
0148         pad[0] = new TPad("pad20", "pad20",setting1[0], setting1[1], setting1[2], setting1[3]);
0149         pad[1] = new TPad("pad21", "pad21",setting1[2], setting1[1], setting1[3], setting1[3]);
0150         pad[2] = new TPad("pad28", "pad28",setting1[0], setting1[0], setting1[2], setting1[1]);
0151         pad[3] = new TPad("pad29", "pad29",setting1[2], setting1[0], setting1[3], setting1[1]);
0152 
0153         for(int i = 0; i < num; i++){
0154 
0155             pad[i]->SetLeftMargin(0.0);
0156             pad[i]->SetRightMargin(0);
0157             pad[i]->SetTopMargin(0.0);
0158             pad[i]->SetBottomMargin(0);
0159             pad[i]->Draw();
0160             gPad->SetTicks();
0161 
0162         }
0163 
0164         pad[0]->SetLeftMargin(0.265);
0165         pad[2]->SetLeftMargin(0.265);
0166 
0167         pad[1]->SetRightMargin(0.05);
0168         pad[3]->SetRightMargin(0.05);
0169 
0170         pad[0]->SetTopMargin(0.02);
0171         pad[1]->SetTopMargin(0.02);
0172 
0173         pad[2]->SetBottomMargin(0.3);
0174         pad[3]->SetBottomMargin(0.3);
0175 
0176     }
0177     else if( num == 6 ){
0178 
0179         pad[0] = new TPad("pad10", "pad10",setting2[0], setting2[1], setting2[2], setting2[4]);
0180         pad[1] = new TPad("pad11", "pad11",setting2[2], setting2[1], setting2[3], setting2[4]);
0181         pad[2] = new TPad("pad12", "pad12",setting2[3], setting2[1], setting2[4], setting2[4]);
0182 
0183         pad[3] = new TPad("pad18", "pad18",  setting2[0], setting2[0], setting2[2],  setting2[1]);
0184         pad[4] = new TPad("pad19", "pad19",  setting2[2], setting2[0], setting2[3],  setting2[1]);
0185         pad[5] = new TPad("pad110", "pad110",setting2[3], setting2[0], setting2[4],  setting2[1]);
0186 
0187         for(int i = 0; i < num; i++){
0188 
0189             pad[i]->SetLeftMargin(0.0);
0190             pad[i]->SetRightMargin(0);
0191             pad[i]->SetTopMargin(0.0);
0192             pad[i]->SetBottomMargin(0);
0193             pad[i]->SetTicks();
0194             pad[i]->Draw();
0195 
0196         }
0197 
0198         pad[0]->SetLeftMargin(0.265);
0199         pad[3]->SetLeftMargin(0.265);
0200 
0201         pad[2]->SetRightMargin(0.05);
0202         pad[5]->SetRightMargin(0.05);
0203 
0204         pad[0]->SetTopMargin(0.02);
0205         pad[1]->SetTopMargin(0.02);
0206         pad[2]->SetTopMargin(0.02);
0207 
0208         pad[3]->SetBottomMargin(0.30);
0209         pad[4]->SetBottomMargin(0.30);
0210         pad[5]->SetBottomMargin(0.30);
0211 
0212     }
0213     else if( num == 8 ){
0214 
0215         pad[0] = new TPad("pad10", "pad10",setting3[0], setting3[1], setting3[2], setting3[5]);
0216         pad[1] = new TPad("pad11", "pad11",setting3[2], setting3[1], setting3[3], setting3[5]);     
0217         pad[2] = new TPad("pad12", "pad12",setting3[3], setting3[1], setting3[4], setting3[5]);
0218         pad[3] = new TPad("pad13", "pad13",setting3[4], setting3[1], setting3[5], setting3[5]);
0219 
0220         pad[4] = new TPad("pad18", "pad18",  setting3[0],  setting3[0], setting3[2], setting3[1]);
0221         pad[5] = new TPad("pad19", "pad19",  setting3[2],  setting3[0], setting3[3], setting3[1]);
0222         pad[6] = new TPad("pad110", "pad110",setting3[3],  setting3[0], setting3[4], setting3[1]);
0223         pad[7] = new TPad("pad111", "pad111",setting3[4],  setting3[0], setting3[5], setting3[1]);
0224 
0225         for( int i = 0; i < num; i++ ){
0226 
0227             pad[i]->SetLeftMargin(0.0);
0228             pad[i]->SetRightMargin(0);
0229             pad[i]->SetTopMargin(0.0);
0230             pad[i]->SetBottomMargin(0);
0231             pad[i]->SetTicks();
0232             pad[i]->Draw();     
0233         }
0234 
0235         pad[0]->SetLeftMargin(0.265);
0236         pad[4]->SetLeftMargin(0.265);
0237 
0238         pad[3]->SetRightMargin(0.05);
0239         pad[7]->SetRightMargin(0.05);
0240 
0241         pad[0]->SetTopMargin(0.05);
0242         pad[1]->SetTopMargin(0.05);
0243         pad[2]->SetTopMargin(0.05);
0244         pad[3]->SetTopMargin(0.05);
0245 
0246         pad[4]->SetBottomMargin(0.30);
0247         pad[5]->SetBottomMargin(0.30);
0248         pad[6]->SetBottomMargin(0.30);
0249         pad[7]->SetBottomMargin(0.30);
0250     }
0251 
0252     for( int i = 0; i < num; i++){
0253 
0254         temp.push_back( pad[i] );
0255     }
0256 
0257     return temp;
0258 }
0259 
0260 TH1D* makeHist(const char*name, const char*title, const char*xtit, const char*ytit, const int nBins, const double lower, const double higher, EColor color = kBlack ){
0261 
0262     TH1D* temp = new TH1D(name, title, nBins, lower, higher);
0263     
0264     temp->SetMarkerSize(1.0);
0265     temp->SetMarkerStyle(20);
0266     temp->SetMarkerColor(color);
0267     temp->SetLineColor(color);
0268     temp->SetStats(kFALSE);
0269 
0270     temp->GetXaxis()->SetTitle( xtit );
0271     temp->GetXaxis()->SetTitleSize(0.05);
0272     temp->GetXaxis()->SetTitleFont(42);
0273     temp->GetXaxis()->SetTitleOffset(1.25);
0274     temp->GetXaxis()->SetLabelSize(0.05);
0275     temp->GetXaxis()->SetLabelOffset(0.01);
0276     temp->GetXaxis()->SetLabelFont(42);
0277     temp->GetXaxis()->SetLabelColor(kBlack);
0278     temp->GetXaxis()->CenterTitle();
0279 
0280     temp->GetYaxis()->SetTitle( ytit );
0281     temp->GetYaxis()->SetTitleSize(0.05);
0282     temp->GetYaxis()->SetTitleFont(42);
0283     temp->GetYaxis()->SetTitleOffset(1.4);
0284     temp->GetYaxis()->SetLabelSize(0.05);
0285     temp->GetYaxis()->SetLabelOffset(0.01);
0286     temp->GetYaxis()->SetLabelFont(42);
0287     temp->GetYaxis()->SetLabelColor(kBlack);
0288     temp->GetYaxis()->CenterTitle();
0289 
0290     return temp;
0291 }
0292 
0293 TH1D* makeHistDifferentBins(const char*name, const char*title, const char*xtit, const char*ytit, const int nBins, double bins[], EColor color = kBlack ){
0294 
0295     TH1D* temp = new TH1D(name, title, nBins, bins);
0296     
0297     temp->SetMarkerSize(1.0);
0298     temp->SetMarkerStyle(20);
0299     temp->SetMarkerColor(color);
0300     temp->SetLineColor(color);
0301     temp->SetStats(kFALSE);
0302 
0303     temp->GetXaxis()->SetTitle( xtit );
0304     temp->GetXaxis()->SetTitleSize(0.05);
0305     temp->GetXaxis()->SetTitleFont(42);
0306     temp->GetXaxis()->SetTitleOffset(1.25);
0307     temp->GetXaxis()->SetLabelSize(0.05);
0308     temp->GetXaxis()->SetLabelOffset(0.01);
0309     temp->GetXaxis()->SetLabelFont(42);
0310     temp->GetXaxis()->SetLabelColor(kBlack);
0311     temp->GetXaxis()->CenterTitle();
0312 
0313     temp->GetYaxis()->SetTitle( ytit );
0314     temp->GetYaxis()->SetTitleSize(0.05);
0315     temp->GetYaxis()->SetTitleFont(42);
0316     temp->GetYaxis()->SetTitleOffset(1.4);
0317     temp->GetYaxis()->SetLabelSize(0.05);
0318     temp->GetYaxis()->SetLabelOffset(0.01);
0319     temp->GetYaxis()->SetLabelFont(42);
0320     temp->GetYaxis()->SetLabelColor(kBlack);
0321     temp->GetYaxis()->CenterTitle();
0322 
0323     return temp;
0324 }
0325 
0326 void fixedFontHist1D(TH1 * h, Float_t xoffset=1.5, Float_t yoffset=2.3)
0327 {
0328   h->SetLabelFont(43,"X");
0329   h->SetLabelFont(43,"Y");
0330   //h->SetLabelOffset(0.01);
0331   h->SetLabelSize(16);
0332   h->SetTitleFont(43);
0333   h->SetTitleSize(20);
0334   h->SetLabelSize(15,"Y");
0335   h->SetTitleFont(43,"Y");
0336   h->SetTitleSize(20,"Y");
0337   h->SetTitleOffset(xoffset,"X");
0338   h->SetTitleOffset(yoffset,"Y");
0339   h->GetXaxis()->CenterTitle();
0340   h->GetYaxis()->CenterTitle();
0341   
0342 }
0343 
0344 TH2D* make2DHist( const char*name, 
0345                   const char*title, 
0346                   const char*xtit, 
0347                   const char*ytit,
0348                   const int nxbins,
0349                   const double xlow, 
0350                   const double xhigh,
0351                   const int nybins,
0352                   const double ylow, 
0353                   const double yhigh
0354 ){
0355 
0356     TH2D* temp2D = new TH2D(name, title, nxbins, xlow, xhigh, nybins, ylow, yhigh);
0357 
0358     temp2D->SetMarkerSize(1.0);
0359     temp2D->SetMarkerStyle(20);
0360     temp2D->SetMarkerColor(kBlack);
0361     temp2D->SetLineColor(kBlack);
0362     temp2D->SetStats(kFALSE);
0363 
0364     temp2D->GetXaxis()->SetTitle( xtit );
0365     temp2D->GetXaxis()->SetTitleSize(0.04);
0366     temp2D->GetXaxis()->SetTitleFont(42);
0367     temp2D->GetXaxis()->SetTitleOffset(1.4);
0368     temp2D->GetXaxis()->SetLabelSize(0.04);
0369     temp2D->GetXaxis()->SetLabelOffset(0.01);
0370     temp2D->GetXaxis()->SetLabelFont(42);
0371     temp2D->GetXaxis()->SetLabelColor(kBlack);
0372 
0373     temp2D->GetYaxis()->SetTitle( ytit );
0374     temp2D->GetYaxis()->SetTitleSize(0.04);
0375     temp2D->GetYaxis()->SetTitleFont(42);
0376     temp2D->GetYaxis()->SetTitleOffset(1.7);
0377     temp2D->GetYaxis()->SetLabelSize(0.04);
0378     temp2D->GetYaxis()->SetLabelOffset(0.01);
0379     temp2D->GetYaxis()->SetLabelFont(42);
0380     temp2D->GetYaxis()->SetLabelColor(kBlack);
0381 
0382     return temp2D;
0383 
0384 }
0385 
0386 void fixedFontHist(TH2D * h, Float_t xoffset=0.9, Float_t yoffset=2.7)
0387 {
0388   h->SetLabelFont(43,"X");
0389   h->SetLabelFont(43,"Y");
0390   //h->SetLabelOffset(0.01);
0391   h->SetLabelSize(16);
0392   h->SetTitleFont(43);
0393   h->SetTitleSize(20);
0394   h->SetLabelSize(15,"Y");
0395   h->SetTitleFont(43,"Y");
0396   h->SetTitleSize(17,"Y");
0397   h->SetTitleOffset(xoffset,"X");
0398   h->SetTitleOffset(yoffset,"Y");
0399   h->GetXaxis()->CenterTitle();
0400   h->GetYaxis()->CenterTitle();
0401 }
0402 void make_dNdX( TH1D* hist ){
0403 
0404     for(int i=0;i<hist->GetNbinsX();i++){
0405         double value = hist->GetBinContent(i+1);
0406         double error = hist->GetBinError(i+1);
0407         double binwidth = hist->GetBinWidth(i+1);
0408 
0409         hist->SetBinContent(i+1, value / binwidth );
0410         hist->SetBinError(i+1, error / binwidth );
0411     }
0412 }
0413 
0414 double calColError(double Ea, double Eb, double Sa, double Sb){
0415 
0416     double temp = Ea/Eb;
0417     double temp2 = (Sa*Sa)/(Ea*Ea) + (Sb*Sb)/(Eb*Eb);
0418     double temp3 = (2.*Sa*Sa)/(Ea*Eb);
0419 
0420     return temp*(sqrt(TMath::Abs(temp2-temp3)) );
0421 }
0422 
0423 TH1D* make_systematicRatio(TH1D* hist1, TH1D* hist2){
0424 
0425     TH1D* hist_ratio = (TH1D*) hist1->Clone("hist_ratio");
0426 
0427     if( hist1->GetNbinsX() != hist2->GetNbinsX() ){
0428         std::cout << "Not compatible binning, abort!" << std::endl;
0429         return 0;
0430     }
0431 
0432     for(int ibin=0;ibin<hist1->GetNbinsX();ibin++){
0433         double value_a = hist1->GetBinContent(ibin+1);
0434         double error_a = hist1->GetBinError(ibin+1);
0435 
0436         double value_b = hist2->GetBinContent(ibin+1);
0437         double error_b = hist2->GetBinError(ibin+1);
0438 
0439         hist_ratio->SetBinContent(ibin+1, value_a / value_b );
0440         hist_ratio->SetBinError(ibin+1, calColError(value_a, value_b, error_a, error_b) );
0441     }
0442 
0443     return hist_ratio;
0444 }
0445 
0446 TLegend* makeLegend(){
0447 
0448     TLegend *w2 = new TLegend(0.65,0.15,0.90,0.45);
0449     w2->SetLineColor(kWhite);
0450     w2->SetFillColor(0);
0451     return w2;
0452 
0453 }
0454 
0455 TGraphAsymmErrors* makeEfficiency(TH1D* hist1, TH1D* hist2, const char*Draw = "cp", EColor color = kBlack  ){
0456 
0457     TGraphAsymmErrors* temp = new TGraphAsymmErrors();
0458     temp->Divide( hist1, hist2, Draw );
0459     temp->SetMarkerStyle(20);
0460     temp->SetMarkerColor(color);
0461     temp->SetLineColor(color);
0462 
0463     return temp;
0464 
0465 }
0466 
0467 TLatex* makeLatex(const char* txt,  double x, double y){
0468 
0469     TLatex* r = new TLatex(x, y, txt);
0470     r->SetTextSize(0.05);
0471     r->SetNDC();
0472     return r;
0473 
0474 }
0475 
0476 void drawBox(TH1D* hist1, double sys, bool doPercentage, double xe= 0.05){
0477 
0478     TBox* temp_box[100];
0479     int bins = hist1->GetNbinsX();
0480 
0481     for(int deta = 0; deta < bins; deta++){
0482 
0483         double value = hist1->GetBinContent(deta+1);
0484         double bincenter = hist1->GetBinCenter(deta+1);
0485         double sys_temp = 0.;
0486 
0487         if( doPercentage ) sys_temp = value*sys;
0488         else sys_temp = sys;
0489 
0490         temp_box[deta] = new TBox(bincenter-xe,value-sys_temp,bincenter+xe,value+sys_temp);
0491         temp_box[deta]->SetFillColorAlpha(kGray+2,0.4);
0492         temp_box[deta]->SetFillStyle(1001);
0493         temp_box[deta]->SetLineWidth(0);
0494         temp_box[deta]->Draw("same");
0495     }
0496 
0497 }
0498 
0499 void drawBoxRatio(TH1D* hist1, TH1D* hist2, double sys, bool doPercentage){
0500 
0501     TBox* temp_box[100];
0502     double xe = 0.08;
0503 
0504     int bins = hist1->GetNbinsX();
0505 
0506     for(int deta = 0; deta < bins; deta++){
0507 
0508         if(deta > 6) continue;
0509 
0510         double factor = hist2->GetBinContent(deta+1); 
0511         double value = hist1->GetBinContent(deta+1);
0512         double bincenter = hist1->GetBinCenter(deta+1);
0513 
0514         if( doPercentage ) sys = sqrt((value*0.045)*(value*0.045));
0515         else sys = sys;
0516 
0517         double sys_temp;
0518         sys_temp = sys;
0519     
0520         temp_box[deta] = new TBox(bincenter-xe,value-sys_temp,bincenter+xe,value+sys_temp);
0521         temp_box[deta]->SetFillColorAlpha(kGray+2,0.4);
0522         temp_box[deta]->SetFillStyle(1001);
0523         temp_box[deta]->SetLineWidth(0);
0524         temp_box[deta]->Draw("same");
0525 
0526     }
0527 
0528 }
0529 
0530 void drawBoxTGraphRatio(TGraphErrors* gr1, int bins, double sys, bool doPercentage){
0531 
0532     double xe[11];
0533     TBox* box1[11];
0534 
0535     for(int mult = 0; mult < bins; mult++){
0536 
0537         if( mult < 6 ){
0538 
0539             xe[mult] = 15*log(1.1*(mult+1));
0540             if(mult == 0) xe[mult] = 10;
0541         }
0542         if( mult ==  6) xe[mult] = 37;
0543         if( mult ==  7) xe[mult] = 50;
0544         if( mult ==  8) xe[mult] = 50;
0545         if( mult ==  9) xe[mult] = 63;
0546         if( mult ==  10) xe[mult] = 73;
0547         
0548         
0549         double x1;
0550         double value1;
0551         gr1->GetPoint(mult, x1, value1);
0552 
0553         double ye = sys;
0554         if( doPercentage ) ye = sqrt((value1*0.045)*(value1*0.045));
0555         else ye = sys;
0556 
0557         box1[mult] = new TBox(x1-xe[mult],value1-ye,x1+xe[mult],value1+ye);
0558         box1[mult]->SetFillColorAlpha(kGray+2,0.4);
0559         box1[mult]->SetFillStyle(1001);
0560         box1[mult]->SetLineWidth(0);
0561         box1[mult]->SetLineColor(kRed);
0562         box1[mult]->Draw("SAME");
0563 
0564     }
0565 
0566 }
0567 
0568 void drawBoxTGraph(TGraphErrors* gr1, int bins, double sys, bool doPercentage, bool doConstantWidth){
0569 
0570     double xe[100];
0571     TBox* box1[100];
0572 
0573     for(int mult = 0; mult < bins; mult++){
0574 
0575         if(!doConstantWidth){
0576             if( mult < 6 ){
0577 
0578                 xe[mult] = 15*log(1.1*(mult+1));
0579                 if(mult == 0) xe[mult] = 10;
0580             }
0581             if( mult ==  6) xe[mult] = 37;
0582             if( mult ==  7) xe[mult] = 50;
0583             if( mult ==  8) xe[mult] = 50;
0584             if( mult ==  9) xe[mult] = 63;
0585             if( mult ==  10) xe[mult] = 73;
0586         }
0587         else{ xe[mult] = 0.02;}
0588         
0589         
0590         double x1;
0591         double value1;
0592         gr1->GetPoint(mult, x1, value1);
0593 
0594         double ye = sys;
0595         if( doPercentage ) ye = value1 * sys;
0596         else ye = sys;
0597 
0598         box1[mult] = new TBox(x1-xe[mult],value1-ye,x1+xe[mult],value1+ye);
0599         box1[mult]->SetFillColorAlpha(kGray+2,0.4);
0600         box1[mult]->SetFillStyle(1001);
0601         box1[mult]->SetLineWidth(0);
0602         box1[mult]->SetLineColor(kBlack);
0603         box1[mult]->Draw("LSAME");
0604 
0605     }
0606 }
0607 
0608 void drawBoxTGraph_alt(TGraphErrors* gr1, int bins, double sys, bool doPercentage, bool doConstantWidth){
0609 
0610     double xe[100];
0611     TBox* box1[100];
0612 
0613     for(int mult = 0; mult < bins; mult++){
0614 
0615         if(!doConstantWidth){
0616             if( mult < 6 ){
0617 
0618                 xe[mult] = 15*log(1.1*(mult+1));
0619                 if(mult == 0) xe[mult] = 10;
0620             }
0621             if( mult ==  6) xe[mult] = 37;
0622             if( mult ==  7) xe[mult] = 50;
0623             if( mult ==  8) xe[mult] = 50;
0624             if( mult ==  9) xe[mult] = 63;
0625             if( mult ==  10) xe[mult] = 73;
0626         }
0627         else{ xe[mult] = 0.005;}
0628         
0629         
0630         double x1;
0631         double value1;
0632         gr1->GetPoint(mult, x1, value1);
0633 
0634         double ye = sys;
0635         if( doPercentage ) ye = value1 * sys;
0636         else ye = sys;
0637 
0638         box1[mult] = new TBox(x1-xe[mult],value1-ye,x1+xe[mult],value1+ye);
0639         box1[mult]->SetFillColorAlpha(kGray+2,0.4);
0640         box1[mult]->SetFillStyle(1001);
0641         box1[mult]->SetLineWidth(0);
0642         box1[mult]->SetLineColor(kRed);
0643         box1[mult]->Draw("SAME");
0644 
0645     }
0646 }
0647 
0648 
0649 void drawBoxTGraphDiff(TGraphErrors* gr1, TGraphErrors* gr2, int bins, double sys, bool doPercentage){
0650 
0651     double xe[11];
0652     TBox* box1[11];
0653     TBox* box2[11];
0654 
0655     for(int mult = 0; mult < bins; mult++){
0656 
0657         xe[mult] = 10*log(1.1*(mult+1));
0658         if(mult == 0) xe[mult] = 7;
0659 
0660         double x1;
0661         double value1;
0662         gr1->GetPoint(mult, x1, value1);
0663 
0664         double x2;
0665         double value2;
0666         gr2->GetPoint(mult, x2, value2);
0667 
0668         double value = value2 - value1;
0669 
0670         double ye = sys;
0671         if( doPercentage ) ye = sqrt((value*0.045)*(value*0.045)+sys*sys);
0672         else ye = sys;
0673 
0674         box1[mult] = new TBox(x1-xe[mult],value-ye,x1+xe[mult],value+ye);
0675         box1[mult]->SetFillColorAlpha(kGray+2,0.4);
0676         box1[mult]->SetFillStyle(1001);
0677         box1[mult]->SetLineWidth(0);
0678         box1[mult]->SetLineColor(kRed);
0679         box1[mult]->Draw("SAME");
0680 
0681     }
0682 
0683 }
0684