Re: Filling histograms from ntuples

Rene Brun (Rene.Brun@cern.ch)
Thu, 04 Sep 1997 15:55:10 +0200


Thomas Kraemerkaemper wrote:
>
> ROOTers,
>
> I've some problem with filling predefined histograms from ntuples
> (projecting ntuples into histograms):
>
> my_ntuple->Draw("some_quantity >> my_histo", "some_selection")
>
> seems to use ONLY selfdefined temporary histograms. When I tried to
> instantiate the histogram before it is used in the command above,
> nothing happens (I can't Draw() the histogram afterwards: canvas stays
> empty). I would like to use predefined histograms to get a special
> binning.
>

This should work, unless you are changing directory between the creation
of your histogram and the invokation of ntuple->Draw.
This works:
TH1F *myhist = new TH1F("myhist","title",100,-5,5);
ntuple->Draw("some_quantity>>myhist");

This will not work
TH1F *myhist = new TH1F("myhist","title",100,-5,5);
TFile f("myfile.root");
ntuple->Draw("some_quantity>>myhist");

> Also the command
>
> my_ntuple->Project("my_histo", "some_quantity", "some_selection")
>
> does not work in that way, albeit there is some indication from the
> (at this point vague) documentation that it should.
>

Same symptom as above.

> And another question: Should Project() work like ntuple/project in
> Paw, e.g. the projection is only _added_ to the histogram contents (no
> reset)?
>
> I've tried with 1.03/01 for AIX 4.1 and 1.02/00 for Solaris 2.4.

TTree::Project is only a shortcut to TTree::Draw.
By default, Project replaces the contents of the specified histogram.
In both TTree::Draw and TTree::Project, you can use the following
undocumented feature in version 1.02 to use the "+" character in front
of the histogram name.
For example
ntuple_>Draw("px>>myhist","py<0");
ntuple->Draw("px>>+myhist","py>0"); //add to existing bin contents

Rene Brun