Home | News | Documentation | Download

Ambiguous results when extracting 1D from 2D

Dear All
I need an help to crosscheck my code when extracting 1D plot from 2D histogram (attached picture).
The results from depth 10mm is higher than 130mm which if refer to 2D histogram the depth at 130mm must be higher.
here the code which I use:

TH1D* total10 = Lattotaldoseproton->ProjectionX("total10", Lattotaldoseproton->GetYaxis()->FindBin(10), Lattotaldoseproton->GetNbinsX());

TH1D* total130 = Lattotaldoseproton->ProjectionX("total130", Lattotaldoseproton->GetYaxis()->FindBin(130), Lattotaldoseproton->GetNbinsX());



	TLegend *leg = new TLegend();    
	leg->AddEntry(total10,"Depth 10mm");
	leg->AddEntry(total130,"Depth 130mm");

Thank you so much for your reply, but actually it not answer the question yet.
I have try the code in that discussion
TH1D* total10 = Lattotaldoseproton->ProjectionX(“total10”, 10, 10);
TH1D* total130 = Lattotaldoseproton->ProjectionX(“total130”, 130, 130);
but it still not give the true result, as we can see in 2D plot at depth130 the value is much higher than depth10

The 130 in ProjectionX is the bin number, not the axis value. What is the Y-axis of Lattotaldoseproton?

Thank you so much for your kind answer, axel.
Could you please suggest how to take the Y axis value instead of bin number?
Y-axis is the depth, and X-axis is lateral, its actually lateral dose profile in 30x30x30 phantom.

That’s TAxis::FindFixBin:

auto yaxis = Lattotaldoseproton->GetYaxis();
auto bin130 = yaxis->FindFixBin(130);
TH1D* total130 = Lattotaldoseproton->ProjectionX(“total130”, bin130, bin130);

Dear Axel,
Thank you so much for your helps, it work well and solved my problem/