Hi everyone,
I’m working with TTree and TBranch and I am having some troubles enabling and disabling branches status. Everything is ok if you are working with primitive types or std::vector in a ROOT file, each branch could be enabled or disabled anytime and works correctly, but I have experimented some cases where branches containing TLorentzVector objects are not re-enabled successfully.
I have created a quick script that shows this behaviour. The first case, it is the simplest workflow, it opens a tree and test if at entry 0 of “value” branch (Type: TLorentzVector) has a “1” as a value of its Y component. The case 2, shows that if you disables and re-enables the branches without get an entry, it also works. And finally, the third case, it is similar to case 2 but after disable all branches, it get an entry. In this last case, I have not been able to get the TLorentzVector after the first GetEntry.
I have attached the macro described (TLorentzTree.C) and a ROOT file (Tree_TLorentz.root). I am using ROOT 5.34.30.
Here it is also the macro:
void PrintTLorentz(TTree* tree)
{
TLeaf* leaf = tree->GetLeaf("value");
TLorentzVector* lorentz = (*(TLorentzVector**)leaf->GetBranch()->GetAddress());
if (lorentz->Y() == 1)
{
std::cout << "Alright." << std::endl;
}
else
{
std::cout << "Wrong, TLorentzVector is not loaded." << std::endl;
}
}
void Case1()
{
TFile file("Tree_TLorentz.root");
TTree* tree = (TTree*)file.Get("tree");
tree->GetEntry(0);
PrintTLorentz(tree);
}
void Case2()
{
TFile file("Tree_TLorentz.root");
TTree* tree = (TTree*)file.Get("tree");
tree->SetBranchStatus("*", kFALSE);
tree->SetBranchStatus("*", kTRUE);
tree->GetEntry(0);
PrintTLorentz(tree);
}
void Case3()
{
TFile file("Tree_TLorentz.root");
TTree* tree = (TTree*)file.Get("tree");
tree->SetBranchStatus("*", kFALSE);
tree->GetEntry(0);
tree->SetBranchStatus("*", kTRUE);
tree->GetEntry(0);
PrintTLorentz(tree);
}
void TLorentzTree()
{
Case1();
Case2();
Case3();
}
Greetings and thanks in advance,
Javier Delgado.
TLorentzTree.C (937 Bytes)
Tree_TLorentz.root (7.9 KB)