# Problem in adding histogram

**URL:** <https://root-forum.cern.ch/t/problem-in-adding-histogram/57907>\
**Category:** Newbie\
**Tags:** hist, root\
**Created:** [January 19, 2024, 2:52pm UTC](https://root-forum.cern.ch/t/problem-in-adding-histogram/57907 "2024-01-19T14:52:20Z")\
**Posts on this page:** 3\
**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:** [January 19, 2024, 2:52pm UTC](https://root-forum.cern.ch/t/problem-in-adding-histogram/57907/1 "2024-01-19T14:52:20Z")

</div>

Hi,

I want to add 3 histogarms (which are generated from a function). Unfortunately i get the following error :

```auto
Info in <TH1D::Add>: Attempt to add histograms with different number of bins - trying to use TH1::Merge
Error in <Merge>: Cannot merge histograms - limits are inconsistent:
 first: h1 (92, 44.000000, 136.000000), second: Func (100, 44.000000, 136.000000)"

```

here I attach my macro:  
[check1.C](https://root-forum.cern.ch/uploads/short-url/K30R5hb8v9XBojmPTVOklkQfLR.C) (1.7 KB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 19, 2024, 3:14pm UTC](https://root-forum.cern.ch/t/problem-in-adding-histogram/57907/2 "2024-01-19T15:14:19Z")

</div>

h1 has 92 bins instead of 100. Replace:

```auto
   TH1D*h1 = new TH1D("h1","h1",92,44,136);

```

by

```auto
   auto h1 = new TH1D("h1","h1",100,44,136);

```

---

<div class="post-metadata">

**Author:** ![Dilicus](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dilicus/32/14338_2.png) [@Dilicus](https://root-forum.cern.ch/u/Dilicus)\
**Post date:** [January 19, 2024, 3:24pm UTC](https://root-forum.cern.ch/t/problem-in-adding-histogram/57907/3 "2024-01-19T15:24:29Z")

</div>

Or in the case you want to use 92 bins, you have to use set the number of point of your function to 92 with SetNpx()

```auto
f12_A1_i->SetNpx(92);

```

Then when you will use GetHistogram, the returned histogram will have 92 bins.
