Re: Filling histograms from ntuples

Thomas Kraemerkaemper (kraemerk@Physik.Uni-Dortmund.DE)
Mon, 8 Sep 1997 10:08:34 +0100 (NFD)


Rene,

thanks for your help. While trying out I detected, that leading blanks
of the histogram name are not ignored, e.g.

ntuple->Draw("some_quantity >>histogram");

works as expected, but

ntuple->Draw("some_quantity >> histogram");

does not: In the latter case a new histogram " histogram" is created,
instead of using the predefined histogram "histogram". I guess most
users will regard this as an unwanted feature: leading blanks in
object names should always be skipped.

Tsch"uss, Thomas Kr"amerk"amper.

>
> Thomas Kraemerkaemper wrote:
> >
> >
> > I'm still struggeling with this problem (perhaps I didn't understand
> > the ROOT memory/scope concepts; IMO there's a lack of documentation,
> > because I can't figure out that from the WWW pages):
> >
> > I would like to fill one predefined histogram with projections from
> > different TTrees from different files:
> >
> Thomas,
> Sorry for the delay. I am just back to CERN.
> I have slightly modified your macro to save the pointer to the directory
> containing your histogram and to set this directory before
> executing ntuple->Draw
> As you say, this should be better explained in the documentation.
> Rene
>
> {
> gROOT->Reset();
> Char_t mc_object_name[3];
> TTree *mc[3];
> TFile *mc_file[3];
> TH1F *mc_histo = new TH1F("mc_histo", "MC", 20, 0., 1.);
> TDirectory *homedir = gDirectory; //Save pointer to current directory
> mc_file[0] = new TFile("mc1.root");
> mc_file[1] = new TFile("mc2.root");
> mc_file[2] = new TFile("mc3.root");
> // Files contain TTrees h1 - h3.
> // I can't 'cd' to the files and use h1->Draw("some_quantity >>+ mc_histo").
>
> // Instead I've tried something like:
> for (Int_t i = 1; i < 2; i++)
> {
> sprintf(mc_object_name, "h%1i", i);
> mc[i] = (TTree *) mc_file[i]->Get(mc_object_name);
> homedir->cd(); //change directory
> mc[i]->Draw("some_quantity >>+mc_histo");
> }
>
> // And again I got not my histogram filled, but a newly created one:
> mc_histo->Draw();
> c1->Update();
> // Is empty...
> }
>