Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-07 08:09:19

0001 /* Header file with useful functions for plotting */
0002 
0003 /*------------------------------------------*/
0004 /*------------Create Histogram--------------*/
0005 /*------------------------------------------*/
0006 /**
0007  *\ The creation of this histogram includes a method for setting the bins to a logarithmic scale along with the axes
0008  **/
0009 /*------------------------------------------*/
0010 TH2F* make_TH2D_xylog( int x_nbins, int x_min, int x_max, int y_nbins, int y_min, int y_max )
0011 {
0012   TH2F* hnew = new TH2F("hnew", "", x_nbins, x_min, x_max, y_nbins, y_min, y_max );
0013   TAxis *xaxis = hnew->GetXaxis();
0014   TAxis *yaxis = hnew->GetYaxis();
0015   int xbins = xaxis->GetNbins();
0016   int ybins = yaxis->GetNbins();
0017 
0018   Axis_t xmin = xaxis->GetXmin();
0019   Axis_t xmax = xaxis->GetXmax();
0020   Axis_t xwidth = (xmax - xmin ) / xbins;
0021   Axis_t *new_xbins = new Axis_t[xbins + 1];
0022 
0023   Axis_t ymin = yaxis->GetXmin();
0024   Axis_t ymax = yaxis->GetXmax();
0025   Axis_t ywidth = (ymax - ymin) / ybins;
0026   Axis_t *new_ybins = new Axis_t[ybins + 1];
0027 
0028   for( int i =0; i <= xbins; i++)
0029     {
0030       new_xbins[i] = TMath::Power( 10, xmin + i*xwidth);
0031     }
0032   xaxis->Set(xbins, new_xbins);
0033 
0034   for( int i =0; i <= ybins; i++)
0035     {
0036       new_ybins[i] = TMath::Power( 10, ymin + i*ywidth);
0037     }
0038   yaxis->Set(ybins, new_ybins);
0039 
0040   return hnew;
0041 }