# How to find the pointer of current histogram created by 'TMatrixD::Draw()'?

**URL:** <https://root-forum.cern.ch/t/how-to-find-the-pointer-of-current-histogram-created-by-tmatrixd-draw/41177>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [August 27, 2020, 8:05am UTC](https://root-forum.cern.ch/t/how-to-find-the-pointer-of-current-histogram-created-by-tmatrixd-draw/41177 "2020-08-27T08:05:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhenhao](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/zhenhao/32/23177_2.png) [@Zhenhao](https://root-forum.cern.ch/u/Zhenhao)\
**Post date:** [August 27, 2020, 8:05am UTC](https://root-forum.cern.ch/t/how-to-find-the-pointer-of-current-histogram-created-by-tmatrixd-draw/41177/1 "2020-08-27T08:05:08Z")

</div>

Hi,

I put a 2D data in a `TMatrixD` Matrix and plot it using `TMatrixD::Draw()` method. Then I want to change the x and y ticks and tickslabel, and bining the data inside because the interval of x axis is not averaged.

How can I find the pointer of current histogram as if I use “`TH1F *hpx = new TH1F("hpx","This is the px distribution",100,-4,4);`”? Does there exist global environment variable like `gPad`?

If this is not a good way to play ROOT, I’m happy to change to the right way.🙂

Thank you very much!

---

<div class="post-metadata">

**Author:** ![StephanH](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@StephanH](https://root-forum.cern.ch/u/StephanH)\
**Post date:** [August 27, 2020, 9:25am UTC](https://root-forum.cern.ch/t/how-to-find-the-pointer-of-current-histogram-created-by-tmatrixd-draw/41177/2 "2020-08-27T09:25:31Z")

</div>

It’s indeed a bit ugly, but here’s one way:

```auto
matrix.Draw();
gPad->GetListOfPrimitives()->ls();
// For me, this prints:
// TFrame X1= 0.000000 Y1=0.000000 X2=3.000000 Y2=3.000000
// OBJ: TH2D	TMatrixDBase : 1 at: 0x7f95c249e800
auto histogram = static_cast<TH2D*>(gPad->GetPrimitive("TMatrixDBase"));

```

---

<div class="post-metadata">

**Author:** ![Zhenhao](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/zhenhao/32/23177_2.png) [@Zhenhao](https://root-forum.cern.ch/u/Zhenhao)\
**Post date:** [August 27, 2020, 9:39am UTC](https://root-forum.cern.ch/t/how-to-find-the-pointer-of-current-histogram-created-by-tmatrixd-draw/41177/3 "2020-08-27T09:39:28Z")

</div>

Thank you very much! It’s works well. I almost want to give up this way to work with my data.

Actually, I am confused about `Int_t TH2::Fill(Double_t x, Double_t y, Double_t w)` right now. My present understanding is: x and y form a cooridinate grid and w is actually the amplitude of each point?

---

<div class="post-metadata">

**Author:** ![StephanH](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@StephanH](https://root-forum.cern.ch/u/StephanH)\
**Post date:** [August 27, 2020, 9:48am UTC](https://root-forum.cern.ch/t/how-to-find-the-pointer-of-current-histogram-created-by-tmatrixd-draw/41177/4 "2020-08-27T09:48:30Z")

</div>

Yes,  
only exchange “amplitude” with “weight” to be more precise.  
The weight determines how much the content in the bin at the coordinate {x, y} is incremented when you fill.
