Hi,
I need to fill a branch of histograms, using TTree->Draw(), but the histogram is stored empty.
TFile *ifile = new TFile("test1.root","READ");
TTree *treein = (TTree*)ifile->Get("mytree");
TFile *ofile = new TFile("test2.root","RECREATE");
TH1F *H = new TH1F("h","h",100,0,100);
TTree *treeout = new TTree("t","t");
treeout->Branch("hist","TH1F",H);
for (int i=0;i<treein->GetEntries();i++)
{
treein->GetEntry(i);
H = new TH1F(Form("h%i",i),"h",100,0,100);
treein->Draw(Form("var>>h%i",i));
treeout->Fill();
}
If I fill the histogram doing the usual Fill(), the TH1 is stored correctly… But I need to use Draw() in my macro.
I think the problem is when I do H = new TH1F
, but if I don’t do it still doesn’t work.
Any help is welcome!