// **************************************************************** // invexp.C // **************************************************************** // Some helper functions for producing a TTree string expression // for several kinematic variables out of (4-)vector components // // If a TTree contains the branches Part0px, ... , Part0e, Part1px, ... , Part1e // the function m("Part0+Part1") gives "sqrt((Part0e+Part1e)^2-(Part0px+Part1px)^2-(Part0py+Part1py)^2-(Part0pz+Part1pz)^2)" // as result. Works with + and - sign and arbitrary number of particles. // // USAGE: .L invexp.C+ // fnc(TString expr, TString suff) // // - expr : formula without suffixes, e.g. "p0+p2-p3-p4"; // if 1st character is a '*', suffixes used as prefixes, e.g. p("*p0+p1") results in "sqrt((pxp0+pxp1)^2+(pyp0+pyp1)^2+(pzp0+pzp1)^2)" // - suff : list with suffixes; default : "e px py pz" // // Implemented functions are: // - m() : invariant mass // - m2() : invariant mass squared // - p() : momentum // - pt() : transvers momentum // - pz() : z-component of momentum // - tht() : polar angle in radians // - thtd() : polar angle in degrees // - ctht() : cosine of polar angle // - dalitz() : expr = list of 3 particles, e.g. "p0 p1 p2" -> returns 'm2("p0+p1"):m2("p0+p2")' // // **************************************************************** // K.Goetzen, GSI, 10/2015 // **************************************************************** #include "TObjString.h" #include "TString.h" #include "TObjArray.h" #include typedef std::vector StrVec; int SplitString(TString s, TString delim, StrVec &toks) { toks.clear(); TObjArray *tok = s.Tokenize(delim); int N = tok->GetEntries(); for (int i=0;iAt(i))->String()).Strip(TString::kBoth); toks.push_back(token); } return toks.size(); } // --------------------------------- // prepares the TString arrays // --------------------------------- bool prepare(TString pts, TString exts, StrVec &c, StrVec &vars) { bool invord = false; if (pts.BeginsWith("*")) invord=true; pts.ReplaceAll("*",""); SplitString(exts," ",c); if (invord) { pts.ReplaceAll("-","- "); pts.ReplaceAll("+","+ "); } else { pts.ReplaceAll("-"," -"); pts.ReplaceAll("+"," +"); } SplitString(pts," ",vars); return invord; } // --------------------------------- // makes the formula out of the vector components // --------------------------------- TString makefml(TString pts, TString exts, int ncmp=4, TString last="-") { StrVec c,vars; bool invord = prepare(pts, exts, c, vars); TString r=""; for (int i=0;i