Reading a vector of double from a TTree in a root file


I encountered some troubles when using the following command in my script to read a vector of double Jet_pt from a TTree in an external root file.

void MyMacro() {

std::vector *Jet_pt;

TFile f(“file_name.root”);
lfv = (TH1F*) f->Get(“lfv”);
lfv -> SetBranchAddress (“Jet_pt”, &Jet_pt"); //This is where the excution stopped with segmentation fault


lfv is a TTree with a branch called “Jet_pt” which is a vector of double and its name coincided with the variable declared in my script.

Would you guys mind help me investigate the issue?

Many thanks for the help

Initialize your variables!

std::vector<Double_t> *Jet_pt = nullptr;

Or, as an alternative, create a vector with new.

By the way, this line:[quote=“Heng_Fai_Chang, post:1, topic:24358”]
TTree* lfv = (TH1F*) f->Get(“lfv”);
is very wrong. This does not even compile.

1 Like

Hi behrenhoff

Many thanks! The issue of segmentation fault was fixed after adding the initialization.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.