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.