Show BinContent for All Bins in one Canvas

ROOT Version: 6.18/02

Hi, I’m new in this forum.
I would like to graph on a TH1 the bin content of all the bins from a different TH2

TH2F *My_Th2 = new TH2F("My_Th2", "My_Th2", nbins, -10, 260, 1000, 0, 100);
TH1F *My_Th1 = new TH1F("My_Th1", "My_Th1", 110, -10, 100);

for (Int_t n = 1; n < nbins; n++){
      for (Int_t i = 1; i < 1001; i++){
	 	Double_t bincont = My_Th2 -> GetBinContent(n,i);
		if (bincont > 0){
			My_Th1 -> Fill(bincont);
      }
}

My_Th1 -> Draw();

Thank you in advance.

D.M.

It seems to me that you are interested in TH2::ProjectionX and TH2::ProjectionY, e.g.:

${ROOTSYS}/tutorials/hist/h2proj.C

Thank you so much! I feel this could help me a lot.

But what if I would need to distinguish the contents of My_Th2 bins in the projections?

Thans again!
D.M.

No idea what you mean.

Both TH2::ProjectionX and TH2::ProjectionY methods offer “firstbin” and “lastbin” parameters plus the “option” parameter which can be a TCutG graphical cut.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.