Getting brach problem

Hello,
I’m trying to get data from branch, but when running the macro I get

Error in <TTree::SetBranchAddress>: The pointer type given "vector<float>" does not correspond to the type needed "Float_t" (5) by the branch: Energy
Error in <TTree::SetBranchAddress>: The pointer type given "vector<Long64_t>" does not correspond to the type needed "Long64_t" (16) by the branch: Timestamp

 *** Break *** segmentation violation

it looks like that it doesn’t want the vector, but the branch is vectorial branch, indeed I’ve Energy[0], Energy[1], etc. in the root file

anaprin.cpp (3.6 KB)
run1024_coinc.root (1.2 MB)

Hi,

May you try with this code?

// file: test.cxx
// to run: root test.cxx
void test()
{

   Long64_t        Timestamp[8];
   Short_t         Channel[8];
   Float_t         Energy[8];
   Int_t           Multiplicity;
   Int_t           Flag[8];
   TTree * tree;
   auto f = new TFile("run1024_coinc.root");
      f->GetObject("T_coinc",tree);
   tree->SetBranchAddress("Timestamp", Timestamp);
   tree->SetBranchAddress("Channel", Channel);
   tree->SetBranchAddress("Energy", Energy);
   tree->SetBranchAddress("Multiplicity", &Multiplicity);
   tree->SetBranchAddress("Flag", Flag);
   Long64_t nentries = tree->GetEntriesFast();
   for (Long64_t jentry=0; jentry<nentries;jentry++)
   {
      tree->GetEntry(jentry);
      	std::cout << "New entry: " << jentry << std::endl;
      for( auto ts : Timestamp )
      	std::cout << "   new TS: " << ts << std::endl;
   
   }
}

TTree provides a function that creates the minimal code to iterate over that given TTree,

root [2] T_coinc->MakeClass("test")

I hope that helps

Best,
Alvaro

Thank you @atd

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