Problem with SetBranchAddress

Dear all,

I am having the following problem when reading a tree: I would like to change the name of a branch:

TFile *myfile = new TFile(pathData + dataFile,"READ");
TTree *data_Weighted = (TTree*) myfile->Get("data_Weighted");
Double_t varX, varY;
data_Weighted->SetBranchAddress("Low_s31_s23_DTF", &varX);
data_Weighted->SetBranchAddress("High_s31_s23_DTF", &varY);

The true names of the branch data_Weighted are Low_s31_s23_DTF and High_s31_s23_DTF and I need to manipulate them (do TCuts, Draw(), etc…) as varX and varY. The output I have is:

Error in <TTreeFormula::Compile>:  Bad numerical expression : "varY"
Info in <TSelectorDraw::AbortProcess>: Variable compilation failed: {varY:varX ,flgBkgSubs == 1}

I cannot do any type of operation with varX or varY. However, if I replace varX by Low_s31_s23_DTF, it works… The root file works well, I can not it send because is too big.
Thanks for your help.


1 Like

Hi @Diego,
indeed, as @couet suggests, the way to set new names for your branches is via TTree::SetAlias.

That use of SetBranchAddress is just telling TTree to read the values of "Low_s31_s23_DTF" and "High_s31_s23_DTF" into C++ variables varX and varY, but it’s not creating new branches or aliases or anything of the sort.


Perfect! It works. Thanks!