# More 1D histogram in a 3D histogram

Hi all,
I have a problem.
I have, fox example, tree 1D histogram and I want to draw on a 3D histogram; in other words I want to put this tree 1D histogram on an other axis, so I can see the variation.
Is it possible?
Thanks
Ciccio

I am not sure to understand what you are asking for.
Do you want to plot the 3D histogram, let say with option “BOX”, and draw the 1D histograms on the walls (like projections) of the 3D plot ?
Can you explain a bit more ? Do you have some example ?

[quote=“couet”]I am not sure to understand what you are asking for.
Do you want to plot the 3D histogram, let say with option “BOX”, and draw the 1D histograms on the walls (like projections) of the 3D plot ?
Can you explain a bit more ? Do you have some example ?[/quote]

Hi,
I have 3 histogram (1D histogram like figure 3-13 of user’s guide chapter3) that represent the same thing in different point, for example the distribution of density in function of the position, I have h1 at x=0, h2 at x=10 and h3 at x=20, now I want to plot this 3 histogram, one behind the other, in a only histrogram (3D histogram like figure 3-7 “LEGO” of user’s guide chapter3)
Thank you
Ciccio

P.S.: And sorry for my English

You can plot on top of each other using the option SAME.
You can use THStack to plot all the histogram in one go.
You can also or fill a 2D histogram with the data in the 3 1D histograms and plot it as a LEGO.

[quote=“couet”]
You can also or fill a 2D histogram with the data in the 3 1D histograms and plot it as a LEGO.[/quote]

How do it?
Thanks
Ciccio

You get the content of each bins in the 1D histos and fill the 2D histogram with these values. Have a look at the TH1 and TH2 documentations all the needed geters and seters are provided.

It’s perfect!!!
Thank you very much, you have resolved an other problem.
Thanks
Ciccio

and if I saved the picture of the 1D histo on a .C file; can I get from the file the content of each bins?I suppose that I must open the file with the normal C++ I/O stream, and then how I get the information?

do a loop on all the bin of each 1D it will be simpler.

Hi,
when I have a .root file I use for open:

``````TFile *file = new TFile("file.root","read");
TH1F *h1  = (TH1F*) file->Get("h1");
h1.Draw();``````

but now I have .C file, and this method does not work

Why do you have a .C file now ? … What are you doing exactly ? It is not clear to me. Send an example.

because it is an other case.
I have a .C file because I have saved the picture of histo, from TBrowser, not in a .gif file but in a .C file (ROOT macros); now I want to use the information of the histo so I create the 2D histo.
a typical file .C is:

``````{
//=========Macro generated from canvas: c1/c1
//=========  (Thu Apr 12 10:42:32 2007) by ROOT version5.10/00
TCanvas *c1 = new TCanvas("c1", "c1",14,29,699,499);
c1->Range(-1.25,-1347.81,1.25,12130.3);
c1->SetBorderSize(2);
c1->SetFrameFillColor(0);

TH1 *h100 = new TH1F("h100","histo",100,-1,1);
h100->SetBinContent(25,3);
h100->SetBinContent(27,2);
h100->SetBinContent(28,1);
h100->SetBinContent(29,3);
h100->SetBinContent(30,4);
h100->SetBinContent(31,3);
h100->SetBinContent(32,3);
h100->SetBinContent(33,7);
h100->SetBinContent(34,8);
h100->SetBinContent(35,8);
h100->SetBinContent(36,17);
h100->SetBinContent(37,11);
h100->SetBinContent(38,17);
h100->SetBinContent(39,24);
h100->SetBinContent(40,33);
h100->SetBinContent(41,52);
h100->SetBinContent(42,87);
h100->SetEntries(57545);

TPaveStats *ptstats = new TPaveStats(0.78,0.835,0.98,0.995,"brNDC");
ptstats->SetName("stats");
ptstats->SetBorderSize(2);
ptstats->SetFillColor(19);
ptstats->SetTextAlign(12);
text->SetTextSize(0.0368);
text = ptstats->AddText("Entries = 57545  ");
ptstats->SetOptStat(1111);
ptstats->SetOptFit(0);
ptstats->Draw();
ptstats->SetParent(h100->GetListOfFunctions());
h100->Draw("");

TPaveText *pt = new TPaveText(0.01,0.943223,0.26339,0.995,"blNDC");
pt->SetName("title");
pt->SetBorderSize(2);
pt->SetFillColor(19);
pt->Draw();
c1->Modified();
c1->cd();
c1->SetSelected(c1);
}
``````

Once you have executed this macro the 1D histo h100 is created and you can use all the Getxxx() methods available in the TH1 doc to get the infos you need (bin content etc …)

since I want a program that make me all, how do I execute the macro from the program?

I am sorry but I do not understand why you are obliged to use .C file. It is much simpler to save the histos in a root files…

yes it’s true, but these are old files that my colleagues have given to me, in fact all new file are .root

So, make them all root files. You execute the macro, it creates the histo and you save the histo in a root file. That way you will have only root files.

it’s ok.
Thanks
Ciccio