Is it possible to redine the axis and bins of a histogram copied using clone()?

Hi,

I want to open a histogram from a root file. For fitting the histogram properly I want to change the axis of the histogram, so for this I copy the histogram into a new histogram using clone() function, but unfortunately I cant change the axis of the histogram. The following is the function I use :

void PSD_Constraint_187()
{

// DEFINING CANVAS
TCanvas *c1 = new TCanvas("c1","Without constraint",800,600);


gStyle->SetOptStat(2211);
gStyle->SetOptFit(1111);

TH2D*h1 = new TH2D("h1","176Os_With_Constraint",81.,49.5,130.5, 81., 79.5, 160.5);

TFile *file1=new TFile("RAW187OS_treeFF01_Hist.root");
TH2D *h11 = (TH2D*)file1->Get("Mass_TKE_Neutron");
h1 = (TH2D*)h11->Clone();
c1->cd();

TF2 *f1 = new TF2("f1","[0]*exp(-0.5*pow(((x-[1])/[2]),2)-0.5*pow(((y-[3])/[4]),2)) + [5]*(  exp(-0.5*pow(((x-([1]-[6]))/[7]),2)) * exp(-0.5*pow(((y-[8])/[9]),2))  + exp(-0.5*pow(((x-([1]+[6]))/[7]),2)) *exp(-0.5*pow(((y-[8])/[9]),2)) )");


   f1->SetFillColor(19);
   f1->SetFillStyle(0);
  
   f1->SetLineWidth(2);
  

   f1->SetParameter(0,150);
   f1->SetParLimits(0,100,1000);

   f1->SetParameter(1, 88);
   f1->SetParLimits(1,0,100);

   f1->SetParameter(2, 11.46);
   f1->SetParLimits(2,0,30);

   f1->SetParameter(3, 125.4);
   f1->SetParLimits(3,0,150);

   f1->SetParameter(4, 12.59);
   f1->SetParLimits(4,0,30);

   f1->SetParameter(5, 20);
   f1->SetParLimits(5,0,5000);

   f1->SetParameter(6,13);
   f1->SetParLimits(6,0,30);

   f1->SetParameter(7, 7);
   f1->SetParLimits(7,0,20);

   f1->SetParameter(8, 124);
   f1->SetParLimits(8,115,150);

   f1->SetParameter(9, 10);
   f1->SetParLimits(9,0,25);

   f1->SetLineColor(kRed);
   h1->Fit("f1");
   h1->Draw("colz");

}

Can someone tell me how to change the axis of the histogram ?

Thank you.

In general, you need to create your histogram with your preferred binning and then fill it with your (tree?) data.

I see, so it’s not possible to change the axis of a cloned histogram.

Also, I had another question regarding how can I store a 2D histogram with “COLW” in a root file ?

What I do now is in my Selector.C file, initially I define my histogram, in the process section I fill it and in the terminate section I write the histograms to a new root file. So when I do this for a 2D histogram I don’t get the color palette represtation which we get when we use “colz”

your_2D_histogram->SetOption("COLZ"); // set the default drawing option

That works. Thank you @Wile_E_Coyote .