Hello friends,

I am struggling for 3 days with this problem. I couldn’t find the explicit solution neither in the forum nor in the manuals and tutorials. There is no problem while I am trying to fill a histogram or a TTree with an int or double but I don’t know how to fill them with a vectors especially with a TLorentzVector in a loop. Everything is fine in the code till the filling part. Then I get;

*“Error in TRint::HandleTermInput(): cling::InvalidDerefException caught: Trying to access a pointer that points to an invalid memory address.”*

I don’t know is it just a simple pointer problem but I tried and couldn’t make it.

{

TFile* input = new TFile(“genie-nu_tau.root”);

TTree* t = (TTree*)input-> Get(“gst”);

t -> Print();

t->Scan(“Ei:pxi:pyi:pzi”);

t->SetBranchAddress(“Ei”, &Ei);

t->SetBranchAddress(“pxi”, &pxi);

t->SetBranchAddress(“pyi”, &pyi);

t->SetBranchAddress(“pzi”, &pzi);

Int_t nentries = (Int_t)t->GetEntries();

Double_t Ei;

Double_t pxi;

Double_t pyi;

Double_t pzi;

//construct TTree

TTree * pE = new TTree(“pE”, “lorentz tree”);

//have some variables that will be read from the TTree

int runNumber = 0, eventNumber = 0;

//branch the TTree

//arguments: branch name, address of var., var. name & type

pE->Branch(“runNumber”, &runNumber, “runNumber/I”);

pE->Branch(“eventNumber”, &eventNumber, “eventNumber/I”);

pE->Branch(“Theta”,&Theta, “Theta/D”);

pE-> Print();

//now let’s loop some events

for (Int_t i=0; i<nentries; i++) {

t->GetEntry(i);

runNumber = nentries;

TLorentzVector v1(pxi, pyi, pzi, Ei);

Double_t Phi = v1.Phi();

Double_Theta = v1.Theta();

Double_t Mag = v1.Mag();

pE->Fill();

cout << “Length of p (= Mass):” << Mag << endl;

cout << “Angle of phi (in rad):” << Phi << endl;

cout << “Angle of theta (in rad):” << Theta << endl;

}

pE->Print();

It reads couts without a problem but does not fill the values. I get same error when I tried to fill a histogram with the same way like;

//create one histogram

TH1F *hTheta = new TH1F(“hTheta”,“Theta”,1000,0,100);

for (Int_t i=0; i<nentries; i++) {

t->GetEntry(i);

runNumber = nentries;

TLorentzVector v1(pxi, pyi, pzi, Ei);

Double_t Phi = v1.Phi();

Double_t Theta = v1.Theta();

Double_t Mag = v1.Mag();

hTheta->Fill();

}

hTheta->Draw();

I saw some solutions which are using TClonesarrays or dictionary method but I couldn’t get the point.

Thank you.