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

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.:slight_smile:

Thank you very much!

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

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"));
1 Like

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?

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.