Re: TTree::Draw() with weights

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Nov 12 1998 - 13:15:09 MET


Christoph Ernst wrote:
> 
> Hello,
> 
> Is there a simple way to rescale the y-axis of a TH1 when you plot it from
> TTree::Draw()?
> For example I want to draw a pt spectrum via tree->Draw("pt"). But as
> 1/pt * dN/dpt  not just as  dN/dpt.
> Also, I would like to plot histos from a Tree where each entry has a
> specific weight w (something like dw/dx). In a loop I would simply say
> h1->Fill(x_i, w_i);.
> But I cannot figure out how to do this in the nice way of TTree::Draw().
> If TTree::Draw() can't do it, what do you think is the best alternative?
> 

Hi Christoph,
You can do all that in TTree::Draw in the following way:
   tree->Draw("pt>>hpt","pt*(xxx < yyy && ...)"
where (xxx < yyy && ...) is a selection expression involving one or
more Tree variables.
All events satisfying the selection will get the weight "pt"
The resulting histogram will be "hpt".
The second parameter of TTree::Draw is the "event-weight" expression.
If the result of the expression is null, the event is not histogrammed.
In the above example, if (xxx < yyy && ..) is false, the expression
is zero, otherwise it is 1.

Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:39 MET