# TProfile From a TH2D Histogram

**URL:** <https://root-forum.cern.ch/t/tprofile-from-a-th2d-histogram/32825>\
**Category:** Newbie\
**Created:** [February 20, 2019, 4:23pm UTC](https://root-forum.cern.ch/t/tprofile-from-a-th2d-histogram/32825 "2019-02-20T16:23:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maximus12108](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/e47c2d/32.png) [@Maximus12108](https://root-forum.cern.ch/u/Maximus12108)\
**Post date:** [February 20, 2019, 4:23pm UTC](https://root-forum.cern.ch/t/tprofile-from-a-th2d-histogram/32825/1 "2019-02-20T16:23:22Z")

</div>

Hi,  
I have a 2D-Histogram and a TProfile that I have declared:

```auto
 Double_t x[] = {1., 2., 3., 5., 7., 9., 13., 19., 27., 37., 52., 74., 105., 155.};
//define histogram and profile
TProfile *prof = new TProfile("prof", "prof", (sizeof(x) / sizeof(Double_t) - 1), x);
TH2F *h1 = new TH2F("h1","hist",100,0.,10.,100,0.,11.);

```

After some retrieving of data, I fill the histogram and TProfile.

```auto
for(Int_t i =0; i<NumEntries; ++i){
  k->GetEntry(i);
  Double_t total = c+d+e+ff+g;

//checking results using console output
  
 cout << a << "\t" << "0" << "\t" << g << "\t" <<c << "\t" << d << "\t" << e << "\t" << ff << "\t" << "total: " << total << endl;
   h1->Fill(a,total);
   prof->Fill(a*a,total);
}

```

However I don’t think I have done this correctly. Shouldn’t the TProfile depend on my histogram? Whereas the way I have created it they exist independently. The effect this has is that I do not have any error bars on my TPofile y-axis when it is drawn?

Could someone point me in the right direction?

Thanks.

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [February 21, 2019, 9:17am UTC](https://root-forum.cern.ch/t/tprofile-from-a-th2d-histogram/32825/2 "2019-02-21T09:17:53Z")

</div>

Hi

The Profile is independent of the histogram, ably you are using dependent data.

I don’t know why you don’t have error bars, maybe too few entries?  
When the bin entry is 1 no error is displayed

Lorenzo

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [February 21, 2019, 9:44am UTC](https://root-forum.cern.ch/t/tprofile-from-a-th2d-histogram/32825/3 "2019-02-21T09:44:14Z")

</div>

Hi,  
may be you mix up the 2 cases:

1. Construct and fill a TProfile as you did (independent of a TH2)

2. Construct and fill a TH2  
then apply TProfile \*prof = TH2::ProfileX(… ) to get a profile  
of your TH2 i.e. the means of Y vs X including errors  
Cheers  
Otto
