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

**URL:** <https://root-forum.cern.ch/t/is-it-possible-to-redine-the-axis-and-bins-of-a-histogram-copied-using-clone/52695>\
**Category:** Newbie\
**Tags:** tree, hist, root\
**Created:** [December 8, 2022, 11:21am UTC](https://root-forum.cern.ch/t/is-it-possible-to-redine-the-axis-and-bins-of-a-histogram-copied-using-clone/52695 "2022-12-08T11:21:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [December 8, 2022, 11:21am UTC](https://root-forum.cern.ch/t/is-it-possible-to-redine-the-axis-and-bins-of-a-histogram-copied-using-clone/52695/1 "2022-12-08T11:21:15Z")

</div>

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 :

```auto
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.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [December 8, 2022, 11:33am UTC](https://root-forum.cern.ch/t/is-it-possible-to-redine-the-axis-and-bins-of-a-histogram-copied-using-clone/52695/2 "2022-12-08T11:33:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [December 8, 2022, 12:55pm UTC](https://root-forum.cern.ch/t/is-it-possible-to-redine-the-axis-and-bins-of-a-histogram-copied-using-clone/52695/3 "2022-12-08T12:55:04Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [December 8, 2022, 1:09pm UTC](https://root-forum.cern.ch/t/is-it-possible-to-redine-the-axis-and-bins-of-a-histogram-copied-using-clone/52695/4 "2022-12-08T13:09:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gini](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gini/32/29467_2.png) [@gini](https://root-forum.cern.ch/u/gini)\
**Post date:** [December 8, 2022, 1:23pm UTC](https://root-forum.cern.ch/t/is-it-possible-to-redine-the-axis-and-bins-of-a-histogram-copied-using-clone/52695/5 "2022-12-08T13:23:32Z")

</div>

That works. Thank you @Wile_E_Coyote .
