Hello kind Root helpers,
I am having a great deal of problem with filling a branch of a tree with a vector of floats. In a header file i have initialised some variables from a tree a which to read from (this was actually generated by MakeClass in root), such as:
vector *el_E;
TBranch *b_el_E;
el_E = 0;
fChain->SetBranchAddress(“el_E”, &el_E, &b_el_E);
(With a whole host of other variables there as well).
So with that all set up, i want to read from one Tree (fChain) some of these varialbes, check they meet some criteria and store the entries from those which do in another smaller Tree (Loose), so:
TTree* Loose = new TTree("Loose","Loose");
Loose->Branch("el_n", &el_n);
Loose->Branch("el_E",&el_E,"el_E/F");
Loose->Branch("el_eta", &el_eta,"el_eta/F");
e.t.c.....
So i loop through the Tree i am reading from gettin each entry and checking which entries meet my criteria:
if (fChain == 0) return;
cout << "Entries in the tree: " << fChain->GetEntries() << endl;
Long64_t nentries = 0;
if (m_events<0 ) nentries = fChain->GetEntries();
else nentries = m_events;
for (Long64_t i_event = 0; i_event < nentries; ++i_event) {
Long64_t event_tree = LoadTree(i_event);
if (event_tree < 0) break;
fChain->GetEntry(i_event);
ResetCounters();
Then i fill my Loose tree based on this:
if(lomu>0 && loel>0){
cout << “Filling Tree\n”;
Loose->Fill();
}
MY PROBLEM
So my problem, is that by using the above method, the tree is created in the output ROOT file with all the correct branches correct, but the branches of vector are filled with 0’s even though oddly the branches of type Int or vector are all filled correctly with non zeros.
WHAT I HAVE TRIED PREVIOUSLY
So i have run into various problems along the way, the first is that if i define a branch like this:
Loose->Branch(“el_pt”, &el_pt); (as instructed by ROOT tutorials)
I will get an error whereby ROOT says it does not recognise:
Error in TTree::Branch: The pointer specified for el_pt is not of a class known to ROOT
However the odd thing is it does recgonise vector and vector just not floats…? So i can create a branch with vectors of integers of doubles without explicitly passing the “I” or “D” e.t.c So i cunningly decided i can recast my variables as a vectors of doubles instead of floats, this results in no problems of ROOT not recognising the pointer but causes segmentation faults when trying to use these varaibles in checking my criteria. Also, it results in the branches storing only 0’s or stupendously high values (i guess the size in bytes of a double or something).
Thanks for taking the time to help me with this problem.