Hi all,
I’m a new Rooter and I’ve a little problem, if any of you could help me …
Let’s have a look at this short code:
Class.h
[code]#ifndef Classe
#define Classe
#include “TH1F.h”
class Classe
{
public:
Classe();
TH1F *h1;
TH1F *h2;
TH1F *h3;
ClassDef(Classe,1)
};
#endif[/code]
Class.cxx
[code]#include “Class.h”
Classe::Classe()
{
h1 = new TH1F(“h1”,“The first”,100,0,100);
h2 = new TH1F(“h2”,“The second”,100,0,100);
h3 = new TH1F(“h3”,“The third”,100,0,100);
}
[/code]
Script.C
[code]{
gSystem->CompileMacro(“Class.cxx”,“gfk”);
TFile *file = new TFile(“puppa.root”,“RECREATE”);
TTree *tree = new TTree(“tree”,“My tree”);
Classe *pointer = new Classe();
tree->Branch(“ramo”,“Classe”,&pointer,8000,99);
for(Int_t i=0;i<30;i++)
if(i<10)
pointer->h1->Fill(i);
else if(i<20)
pointer->h2->Fill(i);
else if(i<30)
pointer->h3->Fill(i);
tree->Fill();
file->Write();
}[/code]
The problem is that when I execute the script and I look at the Root file, in the branch created, histos have only one entry which is 0!!! The right ones are in the top directory of the rootfile!
I also tried objects instead of pointers and the result was worse: no histos at all in the tree (again the right ones are in the top dir)!!!
I think that the problem might be the adress passed in the TTree::Branch method or the way I fill the tree.
How can I solve my problem???
Thanks a lot!
Bye…