Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:28:22

0001 #ifndef PLOTTHELPER_GENERAL_H
0002 #define PLOTTHELPER_GENERAL_H
0003 
0004 
0005   //__________________________________________________________________________________________________________
0006   //__________________________________________________________________________________________________________
0007   //__________________________________________________________________________________________________________
0008   TString ReturnDateStr(){
0009       TDatime today;
0010       int iDate           = today.GetDate();
0011       int iYear           = iDate/10000;
0012       int iMonth          = (iDate%10000)/100;
0013       int iDay            = iDate%100;
0014       return Form("%i_%02d_%02d",iYear, iMonth, iDay);
0015   }
0016 
0017 
0018   //__________________________________________________________________________________________________________
0019   // find bin with largest content
0020   //__________________________________________________________________________________________________________
0021   Double_t FindLargestBin1DHist(TH1* hist, Double_t minX = -10000, Double_t maxX = -10000 ){
0022     Double_t largestContent     = 0;
0023     if (!hist){
0024         std::cout << "histogram pointer was empty, skipping!" << std::endl;
0025         return 0.;
0026     }
0027     Int_t minBin = 1;
0028     Int_t maxBin = hist->GetNbinsX()+1;
0029     if (minX != -10000) minBin = hist->GetXaxis()->FindBin(minX);
0030     if (maxX != -10000) maxBin = hist->GetXaxis()->FindBin(maxX)+0.0001;
0031     for (Int_t i= minBin; i < maxBin; i++){
0032         if (largestContent < hist->GetBinContent(i)){
0033             largestContent = hist->GetBinContent(i);
0034         }
0035     }
0036     return largestContent;
0037   }
0038   //__________________________________________________________________________________________________________
0039   // find bin with smallest content
0040   //__________________________________________________________________________________________________________
0041   Double_t FindSmallestBin1DHist(TH1* hist, Double_t maxStart = 1e6 ){
0042     Double_t smallesContent     = maxStart;
0043     for (Int_t i= 0; i < hist->GetNbinsX(); i++){
0044       if (hist->GetBinContent(i) != 0 && smallesContent > hist->GetBinContent(i)){
0045         smallesContent = hist->GetBinContent(i);
0046       }
0047     }
0048     return smallesContent;
0049   }
0050 
0051   //__________________________________________________________________________________________________________
0052   // find bin last filled X bin
0053   //__________________________________________________________________________________________________________
0054   Double_t FindLastBinXAboveMin(TH1* hist, Double_t min = 1 ){
0055     int i = hist->GetNbinsX();
0056     while (i > 0 && hist->GetBinContent(i) < min) i--;
0057     if (i != 1)
0058       return hist->GetBinCenter(i+1);
0059     else 
0060       return hist->GetBinCenter(hist->GetNbinsX()-1);
0061   }
0062 
0063   //__________________________________________________________________________________________________________
0064   // find bin first filled X bin
0065   //__________________________________________________________________________________________________________
0066   Double_t FindFirstBinXAboveMin(TH1* hist, Double_t min = 1 ){
0067     int i = 1;
0068     while (i < hist->GetNbinsX() && hist->GetBinContent(i) < min) i++;
0069     if (i != hist->GetNbinsX()-1)
0070       return hist->GetBinCenter(i+1);
0071     else 
0072       return hist->GetBinCenter(1);
0073   }
0074   
0075   
0076   
0077   // ---------------------------- Function definiton --------------------------------------------------------------------------------------------
0078   // StyleSettingsBasics will make some standard settings for gStyle
0079   
0080   void StyleSettingsBasics( TString format = ""){
0081       //gStyle->SetOptTitle(kFALSE);
0082       gStyle->SetOptDate(0);   //show day and time
0083       gStyle->SetOptStat(0);  //show statistic
0084       gStyle->SetPalette(1,0);
0085       gStyle->SetFrameBorderMode(0);
0086       gStyle->SetFrameFillColor(0);
0087       gStyle->SetTitleFillColor(0);
0088       gStyle->SetTextSize(0.5);
0089       gStyle->SetLabelSize(0.03,"xyz");
0090       gStyle->SetLabelOffset(0.006,"xyz");
0091       gStyle->SetTitleFontSize(0.04);
0092       gStyle->SetTitleOffset(1,"y");
0093       gStyle->SetTitleOffset(0.7,"x");
0094       gStyle->SetCanvasColor(0);
0095       gStyle->SetPadTickX(1);
0096       gStyle->SetPadTickY(1);
0097       // gStyle->SetPadTickZ(1);
0098       gStyle->SetLineWidth(1);
0099       gStyle->SetPaintTextFormat(".3f");
0100       
0101       gStyle->SetPadTopMargin(0.03);
0102       gStyle->SetPadBottomMargin(0.09);
0103       gStyle->SetPadRightMargin(0.03);
0104       gStyle->SetPadLeftMargin(0.13);
0105 
0106 
0107       TGaxis::SetMaxDigits(4);
0108       gErrorIgnoreLevel=kError;
0109 
0110       if (format.CompareTo("eps") == 0 ||format.CompareTo("pdf") == 0  ) gStyle->SetLineScalePS(1);
0111   }
0112 
0113   //__________________________________________________________________________________________________________
0114   void SetPlotStyle() {
0115   //    const Int_t nRGBs = 7;
0116       const Int_t nRGBs = 5;
0117       const Int_t nCont = 255;
0118 
0119       Double_t stops[nRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
0120       Double_t red[nRGBs]   = { 0.00, 0.00, 0.87, 1.00, 0.51 };
0121       Double_t green[nRGBs] = { 0.31, 0.81, 1.00, 0.20, 0.00 };
0122       Double_t blue[nRGBs]  = { 0.51, 1., 0.12, 0.00, 0.00};
0123 
0124       TColor::CreateGradientColorTable(nRGBs, stops, red, green, blue, nCont);
0125       gStyle->SetNumberContours(nCont);
0126   }
0127 
0128   //__________________________________________________________________________________________________________
0129   void SetPlotStyleNConts(    Int_t nCont = 255) {
0130       const Int_t nRGBs = 5;
0131       Double_t stops[nRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
0132       Double_t red[nRGBs]   = { 0.00, 0.00, 0.87, 1.00, 0.51 };
0133       Double_t green[nRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
0134       Double_t blue[nRGBs]  = { 0.51, 1.00, 0.12, 0.00, 0.00 };
0135       TColor::CreateGradientColorTable(nRGBs, stops, red, green, blue, nCont);
0136       gStyle->SetNumberContours(nCont);
0137   }
0138   
0139   //__________________________________________________________________________________________________________  
0140   Color_t GetColorLayer(int l){
0141     Color_t colors[10] = {kBlack, kViolet+4, kBlue-3, kCyan+1, kGreen+1, kYellow-4, kOrange, kRed-4, kPink-5, kMagenta+2 };
0142     return colors[l%10];
0143   }
0144 
0145   //__________________________________________________________________________________________________________  
0146   Style_t GetLineStyleLayer(int l){
0147     Style_t styles[7] = {1, 3, 4, 6, 7, 10, 9};
0148     int bin = l/10;
0149     return styles[bin];
0150   }
0151   
0152   //__________________________________________________________________________________________________________
0153   void DrawCanvasSettings( TCanvas* c1,
0154                           Double_t leftMargin,
0155                           Double_t rightMargin,
0156                           Double_t topMargin,
0157                           Double_t bottomMargin){
0158 
0159       c1->SetTickx();
0160       c1->SetTicky();
0161       c1->SetGridx(0);
0162       c1->SetGridy(0);
0163       c1->SetLogy(0);
0164       c1->SetLeftMargin(leftMargin);
0165       c1->SetRightMargin(rightMargin);
0166       c1->SetTopMargin(topMargin);
0167       c1->SetBottomMargin(bottomMargin);
0168       c1->SetFillColor(0);
0169   }
0170 
0171   //__________________________________________________________________________________________________________
0172   TCanvas *GetAndSetCanvas( TString name,
0173                             Double_t leftmargin = 0.11,
0174                             Double_t bottommargin = 0.1,
0175                             Double_t x = 1400,
0176                             Double_t y = 1000){
0177 
0178       TCanvas *canvas =  new TCanvas(name,name,x,y);
0179       canvas->SetLeftMargin(leftmargin);
0180       canvas->SetRightMargin(0.015);
0181       canvas->SetTopMargin(0.03);
0182       canvas->SetBottomMargin(bottommargin);
0183       canvas->SetFillColor(0);
0184 
0185       return canvas;
0186 
0187   }
0188 
0189   //__________________________________________________________________________________________________________
0190   TLegend *GetAndSetLegend( Double_t positionX,
0191                           Double_t positionY,
0192                           Double_t entries,
0193                           Int_t Columns = 1,
0194                           TString header =""){
0195 
0196       if(header.CompareTo("") != 0) entries++;
0197       Double_t positionYPlus = 0.04*1.1*(Double_t)entries;
0198       TLegend *legend = new TLegend(positionX,positionY,positionX+(0.25*Columns),positionY+positionYPlus);
0199       legend->SetNColumns(Columns);
0200       legend->SetLineColor(0);
0201       legend->SetLineWidth(0);
0202       legend->SetFillColor(0);
0203       legend->SetFillStyle(0);
0204       legend->SetLineStyle(0);
0205       legend->SetTextSize(0.04);
0206       legend->SetTextFont(42);
0207       if(header.CompareTo("") != 0)legend->SetHeader(header);
0208       return legend;
0209   }
0210   
0211   //__________________________________________________________________________________________________________
0212   TLegend *GetAndSetLegend2(  Double_t positionX,
0213                               Double_t positionY,
0214                               Double_t positionXRight,
0215                               Double_t positionYUp,
0216                               Size_t textSize,
0217                               Int_t columns               = 1,
0218                               TString header              = "",
0219                               Font_t textFont             = 43,
0220                               Double_t margin             = 0
0221   ){
0222 
0223       TLegend *legend = new TLegend(positionX,positionY,positionXRight,positionYUp);
0224       legend->SetNColumns(columns);
0225       legend->SetLineColor(0);
0226       legend->SetLineWidth(0);
0227       legend->SetFillColor(0);
0228       legend->SetFillStyle(0);
0229       legend->SetLineStyle(0);
0230       legend->SetBorderSize(0);
0231       legend->SetTextFont(textFont);
0232       legend->SetTextSize(textSize);
0233       if (margin != 0) legend->SetMargin(margin);
0234       if (header.CompareTo("")!= 0) legend->SetHeader(header);
0235       return legend;
0236   }
0237 
0238   //__________________________________________________________________________________________________________
0239   void SetHistogramm( TH1 *hist,
0240                       TString xLabel,
0241                       TString yLabel,
0242                       Double_t rangeYlow  = -99.,
0243                       Double_t rangeYhigh = -99.,
0244                       Double_t xOffset    = 1.0,
0245                       Double_t yOffset    = 1.15,
0246                       Font_t font         = 42
0247   ){
0248 
0249       Double_t scale = 1./gPad->GetAbsHNDC();
0250       //hist->GetXaxis()->SetRangeUser(rangeX[0],rangeX[1]);
0251       if(rangeYlow != -99.) hist->GetYaxis()->SetRangeUser(rangeYlow,rangeYhigh);
0252       hist->SetTitle("");
0253       hist->SetXTitle(xLabel);
0254       hist->SetYTitle(yLabel);
0255       hist->GetYaxis()->SetDecimals();
0256       hist->GetYaxis()->SetTitleOffset(yOffset/scale);
0257       hist->GetXaxis()->SetTitleOffset(xOffset);
0258       hist->GetXaxis()->SetTitleSize(0.04*scale);
0259       hist->GetYaxis()->SetTitleSize(0.04*scale);
0260       hist->GetXaxis()->SetLabelSize(0.035*scale);
0261       hist->GetYaxis()->SetLabelSize(0.035*scale);
0262       hist->GetXaxis()->SetLabelFont(font);
0263       hist->GetYaxis()->SetLabelFont(font);
0264       hist->SetMarkerSize(1.);
0265       hist->SetMarkerStyle(20);
0266   }
0267 
0268   //__________________________________________________________________________________________________________
0269   void SetGraph( TGraph *graph,
0270                   TString xLabel,
0271                   TString yLabel,
0272                   Double_t rangeYlow = -99.,
0273                   Double_t rangeYhigh = -99.,
0274                   Double_t xOffset = 1.0,
0275                   Double_t yOffset = 1.15){
0276 
0277       Double_t scale = 1./gPad->GetAbsHNDC();
0278       //graph->GetXaxis()->SetRangeUser(rangeX[0],rangeX[1]);
0279       if(rangeYlow != -99.) graph->GetYaxis()->SetRangeUser(rangeYlow,rangeYhigh);
0280       graph->GetXaxis()->SetTitle(xLabel);
0281       graph->GetYaxis()->SetTitle(yLabel);
0282       graph->GetYaxis()->SetDecimals();
0283       graph->GetYaxis()->SetTitleOffset(yOffset/scale);
0284       graph->GetXaxis()->SetTitleOffset(xOffset);
0285       graph->GetXaxis()->SetTitleSize(0.04*scale);
0286       graph->GetYaxis()->SetTitleSize(0.04*scale);
0287       graph->GetXaxis()->SetLabelSize(0.035*scale);
0288       graph->GetYaxis()->SetLabelSize(0.035*scale);
0289       graph->GetXaxis()->SetLabelFont(42);
0290       graph->GetYaxis()->SetLabelFont(42);
0291       graph->SetMarkerSize(1.);
0292       graph->SetMarkerStyle(20);
0293   }
0294 
0295   //__________________________________________________________________________________________________________
0296   void SetMarkerDefaults(    TH1* histo1,
0297                               Style_t markerStyle,
0298                               Size_t markerSize,
0299                               Color_t markerColor,
0300                               Color_t lineColor,
0301                               Bool_t setFont = kTRUE) {
0302       histo1->SetMarkerStyle(markerStyle);
0303       histo1->SetMarkerSize(markerSize);
0304       histo1->SetMarkerColor(markerColor);
0305       histo1->SetLineColor(lineColor);
0306       if (setFont){
0307         histo1->GetYaxis()->SetLabelFont(42);
0308         histo1->GetXaxis()->SetLabelFont(42);
0309         histo1->GetYaxis()->SetTitleFont(62);
0310         histo1->GetXaxis()->SetTitleFont(62);
0311       }
0312   }
0313   //__________________________________________________________________________________________________________
0314   void SetMarkerDefaults(    TH1* histo1,
0315                               TString xtitle = "",
0316                               TString ytitle = "",
0317                               Style_t markerStyle = 20,
0318                               Size_t markerSize = 1,
0319                               Color_t markerColor = kBlack,
0320                               Color_t lineColor = kBlack,
0321                               double textsize = 0.045,
0322                               double labelsize = 0.045,
0323                               double xoffset = 1.,
0324                               double yoffset = 1. ) {
0325       histo1->SetTitle("");
0326       histo1->SetStats(0);
0327       histo1->SetMarkerStyle(markerStyle);
0328       histo1->SetMarkerSize(markerSize);
0329       histo1->SetMarkerColor(markerColor);
0330       histo1->SetLineColor(lineColor);
0331       histo1->GetYaxis()->SetLabelFont(42);
0332       histo1->GetXaxis()->SetLabelFont(42);
0333       histo1->GetYaxis()->SetLabelSize(labelsize);
0334       histo1->GetXaxis()->SetLabelSize(labelsize);
0335       histo1->GetYaxis()->SetTitleFont(62);
0336       histo1->GetXaxis()->SetTitleFont(62);
0337       histo1->GetYaxis()->SetTitleSize(textsize);
0338       histo1->GetXaxis()->SetTitleSize(textsize);
0339       if(!xtitle.EqualTo("")) histo1->GetXaxis()->SetTitle(xtitle);
0340       if(!ytitle.EqualTo("")) histo1->GetYaxis()->SetTitle(ytitle);
0341       histo1->GetXaxis()->SetTitleOffset(xoffset);
0342       histo1->GetYaxis()->SetTitleOffset(yoffset);
0343   }
0344   //__________________________________________________________________________________________________________
0345   void SetMarkerDefaultsProfile( TProfile* prof,
0346                                   Style_t markerStyle,
0347                                   Size_t markerSize,
0348                                   Color_t markerColor,
0349                                   Color_t lineColor ) {
0350       prof->SetMarkerStyle(markerStyle);
0351       prof->SetMarkerSize(markerSize);
0352       prof->SetMarkerColor(markerColor);
0353       prof->SetLineColor(lineColor);
0354       prof->GetYaxis()->SetLabelFont(42);
0355       prof->GetXaxis()->SetLabelFont(42);
0356       prof->GetYaxis()->SetTitleFont(62);
0357       prof->GetXaxis()->SetTitleFont(62);
0358   }
0359 
0360   //__________________________________________________________________________________________________________
0361   void SetLineDefaults(    TH1* histo1,
0362                               Int_t LineColor,
0363                               Int_t LineWidth,
0364                               Int_t LineStyle ) {
0365       histo1->SetLineColor(LineColor);
0366       histo1->SetMarkerColor(LineColor);
0367       histo1->SetLineWidth(LineWidth);
0368       histo1->SetLineStyle(LineStyle);
0369   }
0370 
0371   //__________________________________________________________________________________________________________
0372   void SetLineDefaultsTF1(  TF1*  Fit1,
0373                               Int_t LineColor,
0374                               Int_t LineWidth,
0375                               Int_t LineStyle ) {
0376       Fit1->SetLineColor(LineColor);
0377       Fit1->SetLineWidth(LineWidth);
0378       Fit1->SetLineStyle(LineStyle);
0379   }
0380   
0381 
0382     //__________________________________________________________________________________________________________
0383   void DefaultCancasSettings( TCanvas* c1,
0384                               Double_t leftMargin,
0385                               Double_t rightMargin,
0386                               Double_t topMargin,
0387                               Double_t bottomMargin){
0388       c1->SetTickx();
0389       c1->SetTicky();
0390       c1->SetGridx(0);
0391       c1->SetGridy(0);
0392       c1->SetLogy(0);
0393       c1->SetLeftMargin(leftMargin);
0394       c1->SetRightMargin(rightMargin);
0395       c1->SetTopMargin(topMargin);
0396       c1->SetBottomMargin(bottomMargin);
0397       c1->SetFillColor(0);
0398   }
0399 
0400   //__________________________________________________________________________________________________________
0401   void DefaultPadSettings( TPad* pad1,
0402                           Double_t leftMargin,
0403                           Double_t rightMargin,
0404                           Double_t topMargin,
0405                           Double_t bottomMargin){
0406       pad1->SetFillColor(0);
0407       pad1->GetFrame()->SetFillColor(0);
0408       pad1->SetBorderMode(0);
0409       pad1->SetLeftMargin(leftMargin);
0410       pad1->SetBottomMargin(bottomMargin);
0411       pad1->SetRightMargin(rightMargin);
0412       pad1->SetTopMargin(topMargin);
0413       pad1->SetTickx();
0414       pad1->SetTicky();
0415   }
0416 
0417   //__________________________________________________________________________________________________________
0418   void SetMarkerDefaultsTGraph(  TGraph* graph,
0419                                   Style_t markerStyle,
0420                                   Size_t markerSize,
0421                                   Color_t markerColor,
0422                                   Color_t lineColor,
0423                                   Width_t lineWidth       = 1,
0424                                   Style_t lineStyle       = 1,
0425                                   Bool_t boxes            = kFALSE,
0426                                   Color_t fillColor       = 0,
0427                                   Bool_t isHollow         = kFALSE
0428                                 ) {
0429       graph->SetMarkerStyle(markerStyle);
0430       graph->SetMarkerSize(markerSize);
0431       graph->SetMarkerColor(markerColor);
0432       graph->SetLineColor(lineColor);
0433       graph->SetLineWidth(lineWidth);
0434       graph->SetLineWidth(lineStyle);
0435       if (boxes){
0436           graph->SetFillColor(fillColor);
0437           if (fillColor!=0){
0438               if (!isHollow){
0439                   graph->SetFillStyle(1001);
0440               } else {
0441                   graph->SetFillStyle(0);
0442               }
0443           } else {
0444               graph->SetFillStyle(0);
0445           }
0446       }
0447   }
0448 
0449   //__________________________________________________________________________________________________________
0450   void SetMarkerDefaultsTGraphErr(   TGraphErrors* graph,
0451                                       Style_t markerStyle,
0452                                       Size_t markerSize,
0453                                       Color_t markerColor,
0454                                       Color_t lineColor,
0455                                       Width_t lineWidth       = 1,
0456                                       Bool_t boxes            = kFALSE,
0457                                       Color_t fillColor       = 0,
0458                                       Bool_t isHollow         = kFALSE) {
0459       graph->SetMarkerStyle(markerStyle);
0460       graph->SetMarkerSize(markerSize);
0461       graph->SetMarkerColor(markerColor);
0462       graph->SetLineColor(lineColor);
0463       graph->SetLineWidth(lineWidth);
0464       if (boxes){
0465           graph->SetFillColor(fillColor);
0466           if (fillColor!=0){
0467               if (!isHollow){
0468                   graph->SetFillStyle(1001);
0469               } else {
0470                   graph->SetFillStyle(0);
0471               }
0472           } else {
0473               graph->SetFillStyle(0);
0474           }
0475       }
0476   }
0477 
0478   //__________________________________________________________________________________________________________
0479   void SetMarkerDefaultsTGraphAsym(  TGraphAsymmErrors* graph,
0480                                       Style_t markerStyle,
0481                                       Size_t markerSize,
0482                                       Color_t markerColor,
0483                                       Color_t lineColor,
0484                                       Width_t lineWidth   =1,
0485                                       Bool_t boxes        = kFALSE,
0486                                       Color_t fillColor   = 0,
0487                                       Bool_t isHollow     = kFALSE
0488                                     ) {
0489       if (!graph) return;
0490       graph->SetMarkerStyle(markerStyle);
0491       graph->SetMarkerSize(markerSize);
0492       graph->SetMarkerColor(markerColor);
0493       graph->SetLineColor(lineColor);
0494       graph->SetLineWidth(lineWidth);
0495       if (boxes){
0496           graph->SetFillColor(fillColor);
0497           if (fillColor!=0){
0498               if (!isHollow){
0499                   graph->SetFillStyle(1001);
0500               } else {
0501                   graph->SetFillStyle(0);
0502               }
0503           } else {
0504               graph->SetFillStyle(0);
0505           }
0506       }
0507   }
0508 
0509   //__________________________________________________________________________________________________________
0510   void SetMarkerDefaultsTF1( TF1* fit1,
0511                               Style_t lineStyle,
0512                               Size_t lineWidth,
0513                               Color_t lineColor ) {
0514       if (!fit1) return;
0515       fit1->SetLineColor(lineColor);
0516       fit1->SetLineStyle(lineStyle);
0517       fit1->SetLineWidth(lineWidth);
0518   }
0519 
0520   //__________________________________________________________________________________________________________
0521   void SetStyleTLatex( TLatex* text,
0522                       Size_t textSize,
0523                       Width_t lineWidth,
0524                       Color_t textColor = 1,
0525                       Font_t textFont = 42,
0526                       Bool_t kNDC = kTRUE,
0527                       Short_t align = 11
0528                   ){
0529       if (kNDC) {text->SetNDC();}
0530       text->SetTextFont(textFont);
0531       text->SetTextColor(textColor);
0532       text->SetTextSize(textSize);
0533       text->SetLineWidth(lineWidth);
0534       text->SetTextAlign(align);
0535   }
0536 
0537   //__________________________________________________________________________________________________________
0538   void DrawLatex(const double  PosX = 0.5, const double  PosY = 0.5, TString text = "", const bool alignRight = false, const double TextSize = 0.044, const int font = 42, const double dDist = 0.05, const int color = 1){
0539 
0540       std::vector<TString> Latex;
0541       
0542       TObjArray *textStr = text.Tokenize(";");
0543       for(Int_t i = 0; i<textStr->GetEntries() ; i++){
0544           TObjString* tempObj     = (TObjString*) textStr->At(i);
0545           Latex.push_back( tempObj->GetString());
0546       }
0547       for(unsigned int i = 0; i < Latex.size(); ++i){
0548           TLatex l(PosX, PosY - i*dDist, Latex[i]);
0549           l.SetNDC();
0550           l.SetTextFont(font);
0551           l.SetTextColor(color);
0552           l.SetTextSize(TextSize);
0553           if(alignRight) l.SetTextAlign(31);
0554           l.DrawClone("same");
0555       }
0556   }
0557 
0558   //__________________________________________________________________________________________________________
0559   void SetStyleHisto( TH1* histo,
0560                       Width_t lineWidth,
0561                       Style_t lineStyle,
0562                       Color_t lineColor) {
0563       if (!histo) return;
0564       histo->SetLineWidth(lineWidth);
0565       histo->SetLineStyle(lineStyle);
0566       histo->SetLineColor(lineColor);
0567   }
0568 
0569   //__________________________________________________________________________________________________________
0570   void SetStyleFit(   TF1* fit,
0571                       Double_t xRangeStart,
0572                       Double_t xRangeEnd,
0573                       Width_t lineWidth,
0574                       Style_t lineStyle,
0575                       Color_t lineColor) {
0576       if (!fit) return;
0577       fit->SetRange(xRangeStart,xRangeEnd);
0578       fit->SetLineWidth(lineWidth);
0579       fit->SetLineStyle(lineStyle);
0580       fit->SetLineColor(lineColor);
0581   }
0582 
0583   //__________________________________________________________________________________________________________
0584   void SetStyleHistoTH2ForGraphs( TH2* histo,
0585                                   TString XTitle,
0586                                   TString YTitle,
0587                                   Size_t xLableSize,
0588                                   Size_t xTitleSize,
0589                                   Size_t yLableSize,
0590                                   Size_t yTitleSize,
0591                                   Float_t xTitleOffset    = 1,
0592                                   Float_t yTitleOffset    = 1,
0593                                   Int_t xNDivisions       = 510,
0594                                   Int_t yNDivisions       = 510,
0595                                   Font_t textFontLabel    = 42,
0596                                   Font_t textFontTitle    = 62
0597                                 ){
0598       histo->SetXTitle(XTitle);
0599       histo->SetYTitle(YTitle);
0600       histo->SetTitle("");
0601       histo->SetStats(0);
0602 
0603       histo->GetXaxis()->SetLabelFont(textFontLabel);
0604       histo->GetYaxis()->SetLabelFont(textFontLabel);
0605       histo->GetXaxis()->SetTitleFont(textFontTitle);
0606       histo->GetYaxis()->SetTitleFont(textFontTitle);
0607 
0608       histo->GetXaxis()->SetLabelSize(xLableSize);
0609       histo->GetXaxis()->SetTitleSize(xTitleSize);
0610       histo->GetXaxis()->SetTitleOffset(xTitleOffset);
0611       histo->GetXaxis()->SetNdivisions(xNDivisions,kTRUE);
0612 
0613       histo->GetYaxis()->SetDecimals();
0614       histo->GetYaxis()->SetLabelSize(yLableSize);
0615       histo->GetYaxis()->SetTitleSize(yTitleSize);
0616       histo->GetYaxis()->SetTitleOffset(yTitleOffset);
0617       histo->GetYaxis()->SetNdivisions(yNDivisions,kTRUE);
0618   }
0619 
0620   //__________________________________________________________________________________________________________
0621   void SetStyleHistoTH1ForGraphs( TH1* histo,
0622                                   TString XTitle,
0623                                   TString YTitle,
0624                                   Size_t xLableSize,
0625                                   Size_t xTitleSize,
0626                                   Size_t yLableSize,
0627                                   Size_t yTitleSize,
0628                                   Float_t xTitleOffset    = 1,
0629                                   Float_t yTitleOffset    = 1,
0630                                   Int_t xNDivisions       = 510,
0631                                   Int_t yNDivisions       = 510,
0632                                   Font_t textFontLabel    = 42,
0633                                   Font_t textFontTitle    = 62
0634                                 ){
0635       histo->SetXTitle(XTitle);
0636       histo->SetYTitle(YTitle);
0637       histo->SetTitle("");
0638 
0639       histo->GetYaxis()->SetLabelFont(textFontLabel);
0640       histo->GetXaxis()->SetLabelFont(textFontLabel);
0641       histo->GetYaxis()->SetTitleFont(textFontTitle);
0642       histo->GetXaxis()->SetTitleFont(textFontTitle);
0643 
0644       histo->GetXaxis()->SetLabelSize(xLableSize);
0645       histo->GetXaxis()->SetTitleSize(xTitleSize);
0646       histo->GetXaxis()->SetTitleOffset(xTitleOffset);
0647       histo->GetXaxis()->SetNdivisions(xNDivisions,kTRUE);
0648 
0649       histo->GetYaxis()->SetDecimals();
0650       histo->GetYaxis()->SetLabelSize(yLableSize);
0651       histo->GetYaxis()->SetTitleSize(yTitleSize);
0652       histo->GetYaxis()->SetTitleOffset(yTitleOffset);
0653       histo->GetYaxis()->SetNdivisions(yNDivisions,kTRUE);
0654   }
0655 
0656 //__________________________________________________________________________________________________________
0657 void SetStyleHistoTH3ForGraphs( TH3* histo,
0658                                 TString XTitle,
0659                                 TString YTitle,
0660                                 TString ZTitle,
0661                                 Size_t xLableSize,
0662                                 Size_t xTitleSize,
0663                                 Size_t yLableSize,
0664                                 Size_t yTitleSize,
0665                                 Size_t zLableSize,
0666                                 Size_t zTitleSize,
0667                                 Float_t xTitleOffset    = 1,
0668                                 Float_t yTitleOffset    = 1,
0669                                 Float_t zTitleOffset    = 1,
0670                                 Int_t xNDivisions       = 510,
0671                                 Int_t yNDivisions       = 510,
0672                                 Int_t zNDivisions       = 510,
0673                                 Font_t textFontLabel    = 42,
0674                                 Font_t textFontTitle    = 62
0675                               ){
0676   histo->SetXTitle(XTitle);
0677   histo->SetYTitle(YTitle);
0678   histo->SetZTitle(ZTitle);
0679   histo->SetTitle("");
0680 
0681   histo->GetXaxis()->SetLabelFont(textFontLabel);
0682   histo->GetYaxis()->SetLabelFont(textFontLabel);
0683   histo->GetZaxis()->SetLabelFont(textFontLabel);
0684   histo->GetXaxis()->SetTitleFont(textFontTitle);
0685   histo->GetYaxis()->SetTitleFont(textFontTitle);
0686   histo->GetZaxis()->SetTitleFont(textFontTitle);
0687 
0688   histo->GetXaxis()->SetDecimals();
0689   histo->GetXaxis()->SetLabelSize(xLableSize);
0690   histo->GetXaxis()->SetTitleSize(xTitleSize);
0691   histo->GetXaxis()->SetTitleOffset(xTitleOffset);
0692   histo->GetXaxis()->SetNdivisions(xNDivisions,kTRUE);
0693 
0694   histo->GetYaxis()->SetDecimals();
0695   histo->GetYaxis()->SetLabelSize(yLableSize);
0696   histo->GetYaxis()->SetTitleSize(yTitleSize);
0697   histo->GetYaxis()->SetTitleOffset(yTitleOffset);
0698   histo->GetYaxis()->SetNdivisions(yNDivisions,kTRUE);
0699   
0700   histo->GetZaxis()->SetDecimals();
0701   histo->GetZaxis()->SetLabelSize(zLableSize);
0702   histo->GetZaxis()->SetTitleSize(zTitleSize);
0703   histo->GetZaxis()->SetTitleOffset(zTitleOffset);
0704   histo->GetZaxis()->SetNdivisions(zNDivisions,kTRUE);
0705 }
0706 
0707   //__________________________________________________________________________________________________________
0708   void SetStyleTProfile( TH1* histo,
0709                          TString XTitle,
0710                          TString YTitle,
0711                          Size_t xLableSize,
0712                          Size_t xTitleSize,
0713                          Size_t yLableSize,
0714                          Size_t yTitleSize,
0715                          Float_t xTitleOffset    = 1,
0716                          Float_t yTitleOffset    = 1,
0717                          Int_t xNDivisions       = 510,
0718                          Int_t yNDivisions       = 510,
0719                          Font_t textFontLabel    = 42,
0720                          Font_t textFontTitle    = 62
0721                         ){
0722       histo->SetXTitle(XTitle);
0723       histo->SetYTitle(YTitle);
0724       histo->SetTitle("");
0725 
0726       histo->GetYaxis()->SetLabelFont(textFontLabel);
0727       histo->GetXaxis()->SetLabelFont(textFontLabel);
0728       histo->GetYaxis()->SetTitleFont(textFontTitle);
0729       histo->GetXaxis()->SetTitleFont(textFontTitle);
0730 
0731       histo->GetXaxis()->SetLabelSize(xLableSize);
0732       histo->GetXaxis()->SetTitleSize(xTitleSize);
0733       histo->GetXaxis()->SetTitleOffset(xTitleOffset);
0734       histo->GetXaxis()->SetNdivisions(xNDivisions,kTRUE);
0735 
0736       histo->GetYaxis()->SetDecimals();
0737       histo->GetYaxis()->SetLabelSize(yLableSize);
0738       histo->GetYaxis()->SetTitleSize(yTitleSize);
0739       histo->GetYaxis()->SetTitleOffset(yTitleOffset);
0740       histo->GetYaxis()->SetNdivisions(yNDivisions,kTRUE);
0741   }
0742   
0743   /* // DrawLines will draw the lines in the histogram for you
0744   * startX - starting point of drawing in x
0745   * endX - end point of drawing in x
0746   * startY -starting point of drawing in y
0747   * endY - end point of drawing in y
0748   * linew - line width
0749   */
0750   void DrawLines(Float_t startX, Float_t endX,
0751                   Float_t startY, Float_t endY,
0752                   Float_t linew, Float_t lineColor = 4, Style_t lineStyle = 1, Float_t opacity = 1.){
0753       TLine * l1 = new TLine (startX,startY,endX,endY);
0754       l1->SetLineColor(lineColor);
0755       l1->SetLineWidth(linew);
0756       l1->SetLineStyle(lineStyle);
0757       if (opacity != 1.)
0758           l1->SetLineColorAlpha(lineColor,opacity);
0759 
0760       l1->Draw("same");
0761   }
0762 
0763   //********************************************************************************************************************************
0764   //********************************************************************************************************************************
0765   //********************************************************************************************************************************
0766   TBox* CreateBox(Color_t colorBox, Double_t xStart, Double_t yStart, Double_t xEnd, Double_t yEnd, Style_t fillStyle = 1001 ) {
0767       TBox* box = new TBox(xStart ,yStart , xEnd, yEnd);
0768       box->SetLineColor(colorBox);
0769       box->SetFillColor(colorBox);
0770       box->SetFillStyle(fillStyle);
0771       return box;
0772   }
0773   
0774   //********************************************************************************************************************************
0775   //********************************************************************************************************************************
0776   //********************************************************************************************************************************
0777   void DrawCorrectBadChannelBox (short bctemp, double minX, double minY, double maxX, double maxY){
0778     if (bctemp != -64 && bctemp < 3){
0779       Color_t boxCol = kGray;
0780       if (bctemp == 1)
0781         boxCol = kGray+1;
0782       else if (bctemp == 0)
0783         boxCol = kGray+2;
0784       TBox* badChannelArea =  CreateBox(boxCol, minX, minY, maxX,maxY, 1001 );
0785       badChannelArea->Draw();
0786     }
0787   }
0788   //********************************************************************************************************************************
0789   //********************** Returns default labeling strings  ***********************************************************************
0790   //********************************************************************************************************************************    
0791   TString GetStringFromRunInfo(RunInfo currRunInfo, Int_t option = 1){
0792       if (option == 1){
0793           if (currRunInfo.species.Contains("cosmics")){
0794               return  Form("cosmics, Run %d, #it{V}_{#it{op}} = %1.1f V", currRunInfo.runNr, currRunInfo.vop  );
0795           } else if (currRunInfo.species.CompareTo("g") == 0){
0796               return  Form("LED, Run %d, #it{V}_{#it{op}} = %1.1f V", currRunInfo.runNr, currRunInfo.vop  );
0797           } else {
0798               TString beam = currRunInfo.species.Data();
0799               if (beam.CompareTo("Muon +") == 0) beam = "#mu^{+}";
0800               if (beam.CompareTo("Electron") == 0) beam = "e^{-}";              
0801               if (beam.CompareTo("Positron") == 0) beam = "e^{+}";              
0802               if (beam.CompareTo("Pion -") == 0) beam = "#pi^{-}";              
0803               if (beam.CompareTo("Hadron +") == 0) beam = "h^{+}";              
0804               return  Form("%s-beam, #it{E}_{#it{b}}= %.0f GeV, Run %d, #it{V}_{#it{op}} = %1.1f V", beam.Data(), currRunInfo.energy, currRunInfo.runNr, currRunInfo.vop  );
0805           }
0806       } else if (option == 2){
0807           if (currRunInfo.species.CompareTo("cosmics") == 0){
0808               return  "cosmics";
0809           } else if (currRunInfo.species.CompareTo("g") == 0){
0810               return  "LED";
0811           } else {
0812               TString beam = currRunInfo.species.Data();
0813               if (beam.CompareTo("Muon +") == 0) beam = "#mu^{+}";
0814               if (beam.CompareTo("Electron") == 0) beam = "e^{-}";              
0815               if (beam.CompareTo("Positron") == 0) beam = "e^{+}";              
0816               if (beam.CompareTo("Pion -") == 0) beam = "#pi^{-}";              
0817               if (beam.CompareTo("Hadron +") == 0) beam = "h^{+}";              
0818               return  Form("%s-beam, #it{E}_{#it{b}}= %.0f GeV", beam.Data(), currRunInfo.energy);
0819           }
0820       } else if (option == 3){
0821           return Form("Run %d, #it{V}_{#it{op}} = %1.1f V", currRunInfo.runNr, currRunInfo.vop  )   ;
0822       } else if (option == 4){
0823           if (currRunInfo.species.CompareTo("cosmics") == 0){
0824               return Form("cosmics, Run %d, #it{V}_{#it{op}} = %1.1f V, HG = %1d, LG = %1d", currRunInfo.runNr, currRunInfo.vop, currRunInfo.hgSet, currRunInfo.lgSet);
0825           } else if (currRunInfo.species.CompareTo("g") == 0){
0826               return Form("LED, Run %d, #it{V}_{#it{op}} = %1.1f V, HG = %1d, LG = %1d", currRunInfo.runNr, currRunInfo.vop, currRunInfo.hgSet, currRunInfo.lgSet);
0827           } else{
0828               TString beam = currRunInfo.species.Data();
0829               if (beam.CompareTo("Muon +") == 0) beam = "#mu^{+}";
0830               if (beam.CompareTo("Electron") == 0) beam = "e^{-}";              
0831               if (beam.CompareTo("Positron") == 0) beam = "e^{+}";              
0832               if (beam.CompareTo("Pion -") == 0) beam = "#pi^{-}";              
0833               if (beam.CompareTo("Hadron +") == 0) beam = "h^{+}";                            
0834               return Form("%s-beam, #it{E}_{#it{b}}= %.0f GeV, Run %d, #it{V}_{#it{op}} = %1.1f V, HG = %1d, LG = %1d", beam.Data(), currRunInfo.energy, currRunInfo.runNr, currRunInfo.vop, currRunInfo.hgSet, currRunInfo.lgSet);
0835           }
0836       } else if (option == 5){
0837           return Form("pedestal, Run %d, #it{V}_{#it{op}} = %1.1f V", currRunInfo.runNr, currRunInfo.vop  )   ;
0838       } else if (option == 6){
0839           if (currRunInfo.facility.CompareTo("")!=0 && currRunInfo.beamline.CompareTo("")!=0 && currRunInfo.year != -1 && currRunInfo.month != -1 && currRunInfo.readout.CompareTo("")!=0)
0840           return Form("%s-%s, %02d-%d, %s read-out", currRunInfo.facility.Data(), currRunInfo.beamline.Data(),   currRunInfo.month, currRunInfo.year, currRunInfo.readout.Data());
0841           else if (currRunInfo.facility.CompareTo("")!=0 && currRunInfo.beamline.CompareTo("")!=0 && currRunInfo.year != -1 && currRunInfo.month != -1 )
0842           return Form("%s-%s, %02d-%d", currRunInfo.facility.Data(), currRunInfo.beamline.Data(),   currRunInfo.month, currRunInfo.year);
0843       } else if (option == 7){
0844           if (currRunInfo.facility.CompareTo("")!=0 && currRunInfo.beamline.CompareTo("")!=0 && currRunInfo.year != -1 && currRunInfo.month != -1 )
0845           return Form("%s-%s, %02d-%d", currRunInfo.facility.Data(), currRunInfo.beamline.Data(), currRunInfo.month, currRunInfo.year);
0846       } else if (option == 8){
0847           if ( currRunInfo.readout.CompareTo("")!=0)
0848           return Form("%s read-out",  currRunInfo.readout.Data());
0849       } else if (option == 9){
0850           if (currRunInfo.facility.CompareTo("")!=0 && currRunInfo.beamline.CompareTo("")!=0 )
0851           return Form("%s-%s", currRunInfo.facility.Data(), currRunInfo.beamline.Data());
0852       } else if (option == 10){
0853           if ( currRunInfo.year != -1 && currRunInfo.month != -1 )
0854           return Form("%02d-%d", currRunInfo.month, currRunInfo.year);
0855       }
0856       
0857       return "";
0858   }
0859 
0860 //__________________________________________________________________________________________________________
0861   void ReturnCorrectValuesForCanvasScaling(   Int_t sizeX,
0862                                               Int_t sizeY,
0863                                               Int_t nCols,
0864                                               Int_t nRows,
0865                                               Double_t leftMargin,
0866                                               Double_t rightMargin,
0867                                               Double_t upperMargin,
0868                                               Double_t lowerMargin,
0869                                               Double_t* arrayBoundariesX,
0870                                               Double_t* arrayBoundariesY,
0871                                               Double_t* relativeMarginsX,
0872                                               Double_t* relativeMarginsY,
0873                                               int verbose = 1){
0874       Int_t realsizeX             = sizeX- (Int_t)(sizeX*leftMargin)- (Int_t)(sizeX*rightMargin);
0875       Int_t realsizeY             = sizeY- (Int_t)(sizeY*upperMargin)- (Int_t)(sizeY*lowerMargin);
0876 
0877       Int_t nPixelsLeftColumn     = (Int_t)(sizeX*leftMargin);
0878       Int_t nPixelsRightColumn    = (Int_t)(sizeX*rightMargin);
0879       Int_t nPixelsUpperColumn    = (Int_t)(sizeY*upperMargin);
0880       Int_t nPixelsLowerColumn    = (Int_t)(sizeY*lowerMargin);
0881 
0882       Int_t nPixelsSinglePlotX    = (Int_t) (realsizeX/nCols);
0883       Int_t nPixelsSinglePlotY    = (Int_t) (realsizeY/nRows);
0884       if(verbose > 0){
0885           std::cout << "Setup multi panel canvas"<< std::endl;
0886           std::cout << "X: "<< realsizeX << "\t" << nPixelsSinglePlotX << std::endl;
0887           std::cout << "Y: "<< realsizeY << "\t" << nPixelsSinglePlotY << std::endl;
0888           std::cout << "columns:"<< nPixelsLeftColumn << "\t" << nPixelsRightColumn  << "\t" << nPixelsLowerColumn << "\t" << nPixelsUpperColumn << std::endl;
0889       }
0890       Int_t pixel = 0;
0891       if(verbose > 1)std::cout << "boundaries X" << std::endl;
0892       for (Int_t i = 0; i < nCols+1; i++){
0893           if (i == 0){
0894               arrayBoundariesX[i] = 0.;
0895               pixel = pixel+nPixelsLeftColumn+nPixelsSinglePlotX;
0896           } else if (i == nCols){
0897               arrayBoundariesX[i] = 1.;
0898               pixel = pixel+nPixelsRightColumn;
0899           } else {
0900               arrayBoundariesX[i] = (Double_t)pixel/sizeX;
0901               pixel = pixel+nPixelsSinglePlotX;
0902           }
0903           if(verbose > 1)std::cout << "arrayBoundariesX: " << i << "\t" << arrayBoundariesX[i] << "\t" << pixel<<std::endl;
0904       }
0905 
0906       if(verbose > 1)std::cout << "boundaries Y" << std::endl;
0907       pixel = sizeY;
0908       for (Int_t i = 0; i < nRows+1; i++){
0909           if (i == 0){
0910               arrayBoundariesY[i] = 1.;
0911               pixel = pixel-nPixelsUpperColumn-nPixelsSinglePlotY;
0912           } else if (i == nRows){
0913               arrayBoundariesY[i] = 0.;
0914               pixel = pixel-nPixelsLowerColumn;
0915           } else {
0916               arrayBoundariesY[i] = (Double_t)pixel/sizeY;
0917               pixel = pixel-nPixelsSinglePlotY;
0918           }
0919           if(verbose > 1)std::cout << i << "\t" << arrayBoundariesY[i] <<"\t" << pixel<<std::endl;
0920       }
0921 
0922       relativeMarginsX[0]         = (Double_t)nPixelsLeftColumn/(nPixelsLeftColumn+nPixelsSinglePlotX);
0923       relativeMarginsX[1]         = 0;
0924       relativeMarginsX[2]         = (Double_t)nPixelsRightColumn/(nPixelsRightColumn+nPixelsSinglePlotX);;
0925 
0926       relativeMarginsY[0]         = (Double_t)nPixelsUpperColumn/(nPixelsUpperColumn+nPixelsSinglePlotY);
0927       relativeMarginsY[1]         = 0;
0928       relativeMarginsY[2]         = (Double_t)nPixelsLowerColumn/(nPixelsLowerColumn+nPixelsSinglePlotY);;
0929 
0930       return;
0931   }
0932 
0933   //__________________________________________________________________________________________________________
0934   void ReturnCorrectValuesTextSize(   TPad * pad,
0935                                       Double_t &textsizeLabels,
0936                                       Double_t &textsizeFac,
0937                                       Int_t textSizeLabelsPixel,
0938                                       Double_t dummyWUP){
0939       if(dummyWUP){}
0940 
0941       textsizeLabels = 0;
0942       textsizeFac = 0;
0943       if (pad->XtoPixel(pad->GetX2()) < pad->YtoPixel(pad->GetY1())){
0944           textsizeLabels = (Double_t)textSizeLabelsPixel/pad->XtoPixel(pad->GetX2()) ;
0945           textsizeFac = (Double_t)1./pad->XtoPixel(pad->GetX2()) ;
0946       } else {
0947           textsizeLabels = (Double_t)textSizeLabelsPixel/pad->YtoPixel(pad->GetY1());
0948           textsizeFac = (Double_t)1./pad->YtoPixel(pad->GetY1());
0949       }
0950       std::cout << textsizeLabels << std::endl;
0951       std::cout << textsizeFac << std::endl;
0952 
0953       return;
0954 
0955   }
0956 
0957   //********************************************************************************************************************************
0958   //******** CreateCanvasAndPadsFor8PannelTBPlot ***********************************************************************************
0959   //********************************************************************************************************************************
0960   void CreateCanvasAndPadsFor8PannelTBPlot(TCanvas* &canvas, TPad* pads[8],  Double_t* topRCornerX, Double_t* topRCornerY,  Double_t* relSize8P, Int_t textSizePixel = 30, Double_t marginLeft = 0.03, TString add = "", bool rightCorner = true, int debug = 0){
0961     Double_t arrayBoundX[5];
0962     Double_t arrayBoundY[3];
0963     Double_t relativeMarginsX[3];
0964     Double_t relativeMarginsY[3];
0965     ReturnCorrectValuesForCanvasScaling(2200,1200, 4, 2,marginLeft, 0.005, 0.005,0.05,arrayBoundX,arrayBoundY,relativeMarginsX,relativeMarginsY, debug);
0966 
0967     canvas = new TCanvas(Form("canvas8Panel%s", add.Data()),"",0,0,2200,1200);  // gives the page size
0968     canvas->cd();
0969 
0970     //*****************************************************************
0971     // Test beam geometry (beam coming from viewer)
0972     //===========================================================
0973     //||    8 (4)    ||    7 (5)   ||    6 (6)   ||    5 (7)   ||  row 0
0974     //===========================================================
0975     //||    1 (0)    ||    2 (1)   ||    3 (2)   ||    4 (3)   ||  row 1
0976     //===========================================================
0977     //    col 0     col 1       col 2     col  3
0978     // rebuild pad geom in similar way (numbering -1)
0979     //*****************************************************************
0980     
0981     pads[0] = new TPad(Form("pad8Pane%sl_0", add.Data()), "", arrayBoundX[0], arrayBoundY[2], arrayBoundX[1], arrayBoundY[1],-1, -1, -2);
0982     pads[1] = new TPad(Form("pad8Pane%sl_1", add.Data()), "", arrayBoundX[1], arrayBoundY[2], arrayBoundX[2], arrayBoundY[1],-1, -1, -2);
0983     pads[2] = new TPad(Form("pad8Pane%sl_2", add.Data()), "", arrayBoundX[2], arrayBoundY[2], arrayBoundX[3], arrayBoundY[1],-1, -1, -2);
0984     pads[3] = new TPad(Form("pad8Pane%sl_3", add.Data()), "", arrayBoundX[3], arrayBoundY[2], arrayBoundX[4], arrayBoundY[1],-1, -1, -2);
0985     pads[4] = new TPad(Form("pad8Pane%sl_4", add.Data()), "", arrayBoundX[0], arrayBoundY[1],arrayBoundX[1], arrayBoundY[0],-1, -1, -2);
0986     pads[5] = new TPad(Form("pad8Pane%sl_4", add.Data()), "", arrayBoundX[1], arrayBoundY[1],arrayBoundX[2], arrayBoundY[0],-1, -1, -2);
0987     pads[6] = new TPad(Form("pad8Pane%sl_4", add.Data()), "", arrayBoundX[2], arrayBoundY[1],arrayBoundX[3], arrayBoundY[0],-1, -1, -2);
0988     pads[7] = new TPad(Form("pad8Pane%sl_4", add.Data()), "", arrayBoundX[3], arrayBoundY[1],arrayBoundX[4], arrayBoundY[0],-1, -1, -2);
0989     
0990     DefaultPadSettings( pads[4], relativeMarginsX[0], relativeMarginsX[1], relativeMarginsY[0], relativeMarginsY[1]);
0991     DefaultPadSettings( pads[5], relativeMarginsX[1], relativeMarginsX[1], relativeMarginsY[0], relativeMarginsY[1]);
0992     DefaultPadSettings( pads[6], relativeMarginsX[1], relativeMarginsX[1], relativeMarginsY[0], relativeMarginsY[1]);
0993     DefaultPadSettings( pads[7], relativeMarginsX[1], relativeMarginsX[2], relativeMarginsY[0], relativeMarginsY[1]);
0994     DefaultPadSettings( pads[0], relativeMarginsX[0], relativeMarginsX[1], relativeMarginsY[1], relativeMarginsY[2]);
0995     DefaultPadSettings( pads[1], relativeMarginsX[1], relativeMarginsX[1], relativeMarginsY[1], relativeMarginsY[2]);
0996     DefaultPadSettings( pads[2], relativeMarginsX[1], relativeMarginsX[1], relativeMarginsY[1], relativeMarginsY[2]);
0997     DefaultPadSettings( pads[3], relativeMarginsX[1], relativeMarginsX[2], relativeMarginsY[1], relativeMarginsY[2]);
0998 
0999     topRCornerY[0]  = 1-relativeMarginsY[1];
1000     topRCornerY[1]  = 1-relativeMarginsY[1];
1001     topRCornerY[2]  = 1-relativeMarginsY[1];
1002     topRCornerY[3]  = 1-relativeMarginsY[1];
1003     topRCornerY[4]  = 1-relativeMarginsY[0];
1004     topRCornerY[5]  = 1-relativeMarginsY[0];
1005     topRCornerY[6]  = 1-relativeMarginsY[0];
1006     topRCornerY[7]  = 1-relativeMarginsY[0];      
1007     if (rightCorner){
1008       topRCornerX[0]  = 1-relativeMarginsX[1];
1009       topRCornerX[1]  = 1-relativeMarginsX[1];
1010       topRCornerX[2]  = 1-relativeMarginsX[1];
1011       topRCornerX[3]  = 1-relativeMarginsX[2];
1012       topRCornerX[4]  = 1-relativeMarginsX[1];
1013       topRCornerX[5]  = 1-relativeMarginsX[1];
1014       topRCornerX[6]  = 1-relativeMarginsX[1];
1015       topRCornerX[7]  = 1-relativeMarginsX[2];
1016     } else {
1017       topRCornerX[0]  = relativeMarginsX[0];
1018       topRCornerX[1]  = relativeMarginsX[1];
1019       topRCornerX[2]  = relativeMarginsX[1];
1020       topRCornerX[3]  = relativeMarginsX[1];
1021       topRCornerX[4]  = relativeMarginsX[0];
1022       topRCornerX[5]  = relativeMarginsX[1];
1023       topRCornerX[6]  = relativeMarginsX[1];
1024       topRCornerX[7]  = relativeMarginsX[1];
1025     }
1026     
1027     for (Int_t p = 0; p < 8; p++){
1028       if (pads[p]->XtoPixel(pads[p]->GetX2()) < pads[p]->YtoPixel(pads[p]->GetY1())){
1029         relSize8P[p]  = (Double_t)textSizePixel/pads[p]->XtoPixel(pads[p]->GetX2()) ;
1030       } else {
1031         relSize8P[p]  = (Double_t)textSizePixel/pads[p]->YtoPixel(pads[p]->GetY1());
1032       }
1033       if(debug > 1)std::cout << p << "\t" << topRCornerX[p]<< "\t" << topRCornerY[p] << "\t" << relSize8P[p] << std::endl;
1034     }
1035     return;
1036   }  
1037 
1038   //********************************************************************************************************************************
1039   //******** CreateCanvasAndPadsFor2PannelTBPlot ***********************************************************************************
1040   //********************************************************************************************************************************
1041   void CreateCanvasAndPadsFor2PannelTBPlot(TCanvas* &canvas, TPad* pads[2],  Double_t* topRCornerX, Double_t* topRCornerY,  Double_t* relSizeP, Int_t textSizePixel = 30, Double_t marginLeft = 0.03, TString add = "", bool rightCorner = true, int debug = 0){
1042     Double_t arrayBoundX[3];
1043     Double_t arrayBoundY[2];
1044     Double_t relativeMarginsX[3];
1045     Double_t relativeMarginsY[3];
1046     ReturnCorrectValuesForCanvasScaling(1200,600, 2, 1,marginLeft, 0.005, 0.015,0.1,arrayBoundX,arrayBoundY,relativeMarginsX,relativeMarginsY, 2);
1047 
1048     canvas = new TCanvas(Form("canvas2Panel%s", add.Data()),"",0,0,1200,600);  // gives the page size
1049     canvas->cd();
1050 
1051     //*****************************************************************
1052     // Test beam geometry (beam coming from viewer)
1053     //===========================================================
1054     //===========================================================
1055     //||    1 (0)    ||    2 (1)   ||  row 0
1056     //===========================================================
1057     //    col 0     col 1 
1058     // rebuild pad geom in similar way (numbering -1)
1059     //*****************************************************************
1060     
1061     std::cout << "0: " <<  arrayBoundX[0] << "\t" << arrayBoundY[0] << "\t" << arrayBoundX[1] << "\t" << arrayBoundY[1] << std::endl;
1062     std::cout << "1: " <<  arrayBoundX[1] << "\t" << arrayBoundY[0] << "\t" << arrayBoundX[2] << "\t" << arrayBoundY[1] << std::endl;
1063     
1064     pads[0] = new TPad(Form("pad2Pane%sl_0", add.Data()), "", arrayBoundX[0], arrayBoundY[1], arrayBoundX[1], arrayBoundY[0],-1, -1, -2);
1065     pads[1] = new TPad(Form("pad2Pane%sl_1", add.Data()), "", arrayBoundX[1], arrayBoundY[1], arrayBoundX[2], arrayBoundY[0],-1, -1, -2);
1066     
1067     
1068     DefaultPadSettings( pads[0], relativeMarginsX[0], relativeMarginsX[1], relativeMarginsY[0], relativeMarginsY[2]);
1069     DefaultPadSettings( pads[1], relativeMarginsX[1], relativeMarginsX[2], relativeMarginsY[0], relativeMarginsY[2]);
1070 
1071     topRCornerY[0]  = 1-relativeMarginsY[2];
1072     topRCornerY[1]  = 1-relativeMarginsY[2];
1073     if (rightCorner){
1074       topRCornerX[0]  = 1-relativeMarginsX[1];
1075       topRCornerX[1]  = 1-relativeMarginsX[2];
1076     } else {
1077       topRCornerX[0]  = relativeMarginsX[0];
1078       topRCornerX[1]  = relativeMarginsX[1];
1079     }
1080     
1081     for (Int_t p = 0; p < 2; p++){
1082       if (pads[p]->XtoPixel(pads[p]->GetX2()) < pads[p]->YtoPixel(pads[p]->GetY1())){
1083         relSizeP[p]  = (Double_t)textSizePixel/pads[p]->XtoPixel(pads[p]->GetX2()) ;
1084       } else {
1085         relSizeP[p]  = (Double_t)textSizePixel/pads[p]->YtoPixel(pads[p]->GetY1());
1086       }
1087       // if(debug > 1)
1088         std::cout << p << "\t" << topRCornerX[p]<< "\t" << topRCornerY[p] << "\t" << relSizeP[p] << std::endl;
1089     }
1090     return;
1091   }  
1092   
1093 #endif