This code, when typed line-by-line into the interpreter, works fine:
TFile* tf = new TFile("/apps/HallB/workspace/data/eppi0eta.root", "READ");
TTree* tt = tf->Get("tt");
TVector3 Rtgt;
TBranch* b_Rtgt = tt->GetBranch("Rtgt");
b_Rtgt->SetAddress(&Rtgt);
b_Rtgt->GetEntry(0);
But when wrapped into a macro and executed, it segfaults. I can get the macro to work if I use this code instead:
TFile* tf = new TFile("/apps/HallB/workspace/data/eppi0eta.root", "READ");
TTree* tt = tf->Get("tt");
TVector3* Rtgt = new TVector3();
TBranch* b_Rtgt = tt->GetBranch("Rtgt");
b_Rtgt->SetAddress(&Rtgt);
b_Rtgt->GetEntry(0);
This problem does not occur for me when I use TLorentzVectors. I have yet to see any hard and fast rules for what should be passed to TBranch::SetAddress() – I can cite examples of addresses of stack-allocated variables, pointers, and references to pointers all being passed to TBranch::SetAddress(). How should I be using it, and why does it behave differently for different objects?