Hi Stephane,
In your function void Graph::Draw(), delete the line:
TH1F *plot = new TH1F();
The histogram object is automatically created by teh next instruction:
plot = (TH1F*)f->Get(Histoname);
Simply, do;
TH1F *plot = (TH1F*)f->Get(Histoname);
Rene Brun
Stephane Tourneur wrote:
>
> Dear Rooters,
>
> I have a problem with my root program that I don't manage to solve.
> To present it to you, I simplified my program in that way :
>
> -I have a file minigraph.C which builds a class named Graph :
>
> #include <iostream.h>
> #include <TFile.h>
> #include <TH1.h>
> #include <TCanvas.h>
> #include <TGClient.h>
> #include <TGWindow.h>
> #include <TObject.h>
>
> class Graph
> {
> public:
> char* Histoname;
> Graph(){};
> ~Graph(){};
> Graph(char name[20]){Histoname = name;};
> void Draw();
> };
>
> void Graph::Draw()
> {
> TFile *f = new TFile("SiliMon85983aa.root");
> TH1F *plot = new TH1F();
> plot = (TH1F*)f->Get(Histoname);
> plot->Draw();
> }
>
> -I have then a macro easybookgraphSOS.C :
>
> {
> gInterpreter->ProcessLine(".L minigraph.C+");
> Graph *h2[2];
> char scully[30];
> int layer = 0;
>
> sprintf(scully,"P%i",layer);
> h2[0]= new Graph(scully);
>
> sprintf(scully,"Z%i",layer);
> h2[1] = new Graph(scully);
> }
>
> Now, on the ROOT prompt, when I execute :
> root [0] .x easybookgraphSOS.C
> root [1] h2[0]->Draw();
> Instead of P0, the histo Z0 is drawn!
>
> BUT, strangely, if I use two different names of variables (instead of
> scully alone), that is to say if I replace easybookgraphSOS.C by :
>
> {
> gInterpreter->ProcessLine(".L minigraph.C+");
> Graph *h2[2];
> char scully[30];
> char mulder[30];
> int layer = 0;
>
> sprintf(scully,"P%i",layer);
> h2[0]= new Graph(scully);
>
> sprintf(mulder,"Z%i",layer);
> h2[1] = new Graph(mulder);
> }
>
> this time it works : h2[0]->Draw(); draws L0, and
> h2[1]->Draw(); draws Z0, as expected... What definitely proves that
> letting scully without mulder is a fundamental mistake!! (sorry for those
> who don't know anything about those famous TV heroes...)
>
> I must use one variable only because I have to book thousands of
> histograms in a similar way.
> Could anybody help me?
>
> Thanks a lot in advance.
>
> Stephane
> student at CDF/Fermilab for the UC Davis
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:40 MET