Hello guys,
I have a tree with a branch called “reference_frame.lab.p0” and a second one called “a”. This first variable is a lorentzvector and the second a double.
When I draw an histogram using this branch I am calling the following command (this is an illustration of my problem):
t->Draw("TMath::Sqrt(reference_frame.lab.p0.P()*reference_frame.lab.p0.P()-reference_frame.lab.p0.E()*reference_frame.lab.p0.E())")
This formula seems to be processed using TTreeFormula.
Basically I am looking for a way to properly catch “reference_frame.lab.p0” and replace it by an other one and do not replace wrong part of the string like “a”… which occurs everywhere
Do you have any suggestion ?
For the moment I wrote this :
TList *l = (TList*) tree->GetListOfBranches();
std::cout << varexp_expanded << std::endl;
for(int i = 0, N = l->GetSize(); i < N; i++) {
TString branchname = l->At(i)->GetName();
int j = 0;
int index = 0;
//std::cout << "branch:" << branchname << std::endl;
while((index = varexp_expanded.Index(branchname, (Ssiz_t) index)) != -1) {
//if(index == 5) std::cout << branchname << std::endl;
TString substr1 = varexp_expanded(index-1,branchname.Length()+1).String();
TString substr2 = varexp_expanded(index-2,branchname.Length()+2).String();
std::cout << "input: " << varexp_expanded << std::endl;
std::cout << "index: " << index<< std::endl;
std::cout << "substring: " << substr1 << std::endl;
if(!substr1.BeginsWith(".") && !substr2.BeginsWith("::")) {
TString replacement = (TString) tree->GetName() + ".";
varexp_expanded.Replace(index, 0, replacement);
index += replacement.Length();
}
index += branchname.Length();
j++;
if(j>10) gSystem->Abort();
}
}
std::cout << varexp_expanded << std::endl;
std::cout << std::endl;