Re: 2D histogram projection from a TTree

Rene Brun (Rene.Brun@cern.ch)
Thu, 02 Jul 1998 09:01:53 +0200


Alberto Baldisseri wrote:
>
> Hi rooters,
>
> I have problems to do a 2D histogram projection from a tree in batch. I
> compile an execute
> the following code :
>
> //
> // Test TTree projections
> // from an n/tuple to an 2D histogram
> //
> #include <stdio.h>
> #include <iostream.h>
> #include <stdlib.h>
> #include "TROOT.h"
> #include "TFile.h"
> #include "TH1.h"
> #include "TH2.h"
> #include "TF1.h"
> #include "TTree.h"
> #include "TProfile.h"
> int main()
> {
> TROOT test("test","Test of 2D project");
> TFile *ntufp = new TFile("gene_ntu.root"); // Open n/tuple file
> TTree *tgassi = (TTree *) test.FindObject("tgassi");
> tgassi->Print();
> tgassi->Draw("ch[1]:ch[0]>>hmy");
> //tgassi->Draw("ch[1]:ch[0]>>hmy","","goff");
> ntufp->ls();
> TH2F *hmy = (TH2F *) test.FindObject("hmy");
> printf("\nhmy = %x\n",hmy);
> hmy->Print();
> }
>
> I got a segmentation fault because the hmy pointer is NULL, thats mean
> the TH2F histogram
> hmy is not created. This code work with the 1D histogram. By the way,
> the 2D projections works
> well in a root macro interactively. I do something wrong ?
> I am using root version 2.00/08 for Linux Redhat5.0 and egcs2.90.27.
>

Your code above cannot compile. You should at least replace
FindObject by Get.
Please send me the real code you try to execute.

Rene Brun