ROOT Tip: Creating New and Complicated Variables

Date December 12, 2007

When presented with a ROOT file, we are often annoyed that the simple variables are present, but the hard-to-compute ones are not. For instance, as might be popular in my experiment, BaBar, perhaps the reconstructed B momentum and the center-of-mass (CM) energy are provided, but not the energy-substituted mass (mES). In this tip, I’ll show you how to define new complicated variables, give them a simple-to-remember string name, and draw them.

Let’s say that the B momentum (in the CM frame) variable is called “pBCM”, and that the CM collider energy is called “SQRTs”. You want to define “mES”, which is mathematically given by: mES = SQRT( (SQRTs/2.0)^2 – pBCM^2 ) You obviously don’t want to have to type this every time. Let’s define a TFormula for this new variable:

TFormula mES("mES","TMath::Sqrt( TMath::Power( SQRTs/2.0, 2.0 ) - TMath::Power( pBCM, 2.0 ) )");

Now you can make this new variable globally accessible to all ROOT commands that parse equations, like TTree::Draw(), as follows:

gROOT->GetListOfFunctions()->Add(&mES);

Now it’s a cinch to use this formula in your Draw() method:

myTree->Draw("mES");

You can easily imagine defining even more complicated variables, like conditional ones where a variable is drawn in certain ways for values of another variable in your ROOT tree. The possibilities are fairly endless.

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CAPTCHA Image CAPTCHA Audio
Refresh Image