Re: Questions on TTreeFormula

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Tue, 25 Mar 2008 08:04:52 +0100


see TTree::SetAlias

For example, you can define the following alias   tree.SetAlias("rng","sin(pi*rndm)*sqrt(-2*log(rndm))")

This will create the tree alias named "rng". The value of the rng variable will be a gaussian random number with mean=0 and sigma=1. See the effect doing

  tree.Draw("rndm")
  tree.Draw("rng")
  tree.Draw("myvar+0.1*rng")

If you want to create an alias returning a random gaussian number with mean = -1.5 and sigma=2.5, do
  tree.SetAlias("rng2","-1.5+2.5*sin(pi*rndm)*sqrt(-2*log(rndm))")   tree.Draw("myvar+rng2")

above "rndm" is a special keyword known by TFormula. It calls the current random number generator pointed by gRandom (currently the Mersenne Twister algorithm in TRandom3).

Note that using TTree::SetAlias you can define an alias formula referencing any combination of variables in the Tree.

Rene Brun

Tom Roberts wrote:
> Questions on TTreeFormula:
>
> 1) What functions are permitted? Specifically: are there any
> random-numbers? I would specifically like GaussRan(mean,sigma).
> (I want to add a measurement resolution in, but am in a place
> where C++ is hard but can type an expression into a TTreeFormula).
>
> 2) Is it possible for me to define new functions? If so, how?
>
> 3) What is the relationship between TFormula and TTreeFormula? yes,
> I know the latter inherits from the former, but what is the
> relationship for evaluation? This might make (4) below moot.
>
> 4) Is it possible for me to define new variables? specifically,
> I would like to define something like "Ptot=sqrt(Px*Px+Py*Py+Pz*Pz)"
> where Px,Py,Pz are float-s in the TTree. It should be evaluated
> before the TTreeFormula is evaluated (as the formula might use Ptot).
>
> This might be implementable as a friend, but that's complicated, and
> I don't really want to create a whole new TFile for a transient
> thing like this; it would also require a scan of the original
> TTree to fill the friend.
>
> 4a) If it is possible to define a new function, is it possible to
> define one without an argument or parens? this would let me do (4)
> in C++.
>
> If neither (4) nor (4a) is possible, I may implement (4) as a text
> macro that expands defined variable names before creating the
> TTreeFormula.
>
>
> Tom Roberts
>
Received on Tue Mar 25 2008 - 08:04:58 CET

This archive was generated by hypermail 2.2.0 : Tue Mar 25 2008 - 17:50:01 CET