Getting the value of a TString applied to a TTree event

Hello there,

I am making use of the very nice GetEntries(const char* selection) in a cut optimisation tool I have developed, and I would like to know if I can evaluate the result of “const char* selection” as applied to a single event?

For example, right now I am doing things like:

Double_t numberpassingcut = myTree->GetEntries(“B_s_Energy2 - B_s_Momentum2 < 10*GeV”)

Where I don’t need to hard-code the string or have any knowledge of branch names within the tree.

Is there a way of applying a string to a single entry of a form similar to this? something like:

Double_t EsquaredMinusPsquared = myTree->GetEntryValue(Int_t entry, const char* formulaString)

where formulaString can be composed in a similar fashion to the selection string in GetEntries.

The reason I ask is because the only way I can think of doing it right now is by using SetBranchAddress which is less friendly than the nice string format used in GetEntries. If I want to change the formula in this case, I must assign a new set of branch addresses.

Thanks!

Conor

You can use TTree::Draw and specify the number of entries and the first entry to process, eg

Long64_t numberpassingcut = myTree->Draw("","B_s_Energy**2 - B_s_Momentum**2 < 10*GeV","goff",1,entry);
Rene

[quote=“brun”]You can use TTree::Draw and specify the number of entries and the first entry to process, eg

Long64_t numberpassingcut = myTree->Draw("","B_s_Energy**2 - B_s_Momentum**2 < 10*GeV","goff",1,entry);
Rene[/quote]

Sorry, Rene, this isn’t quite what I meant- I didn’t explain very well in my comparison. What I am trying to get is the value of an expression as applied to a given event- to use my string analogy, GetEntries is cutting on “B_s_Energy2 - B_s_Momentum2 < 10*GeV”; any event for which the outcome of the left side of the expression is less than 10GeV passes the cut.

What I am looking for is a way to evaluate the expression, rather than compare it, like this:

Double_t thisValue = myTree->GetEntryValue(Int_t entry, “B_s_Energy2 - B_s_Momentum2”)

so that thisValue becomes the evaluated expression when applied to this particular entry (9.7E06, 1.02E07 being two examples of ones that would increment or do nothing to numberpassingcut in my previous example).

I assumed that GetEntries is doing this somewhere as it needs to evaluate the expression on an event-by-event basis in order to see if it passes/fails. I cannot work out how it is doing this however.

Conor

You can use the class TTreeFormula or simply do

myTree->Draw("B_s_Energy**2 - B_s_Momentum**2 < 10*GeV","',"goff"); double *result = mytree->GetV1(); result[0] = result of expression for entry 0 result[1] = result of expression for entry 1 .. result[i] = result of expression for entry i
Rene

Thanks!

Could you provide an example of how to use TTreeFormula for this purpose? I’m having difficulty working out how to use it to evaluate to a Double_t in the documentation.

Conor

[code]TTree myTree = …;
TTreeFormula f(“formula”,"B_s_Energy2 - B_s_Momentum2 < 10
GeV",myTree);

for (Long64_t entry=0;entry<nentries;entry++) {
myTree->GetEntry(entry);
double result = f.EvalInstance(0);
}
[/code]
Rene

Thanks!

Conor