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


I’m completely new to ROOT (and Programming either) so maybe this is a dumb question.

First of all, that’s what I’m using ROOT for at the moment: I want to read in a TTree, which I didn’t made, and which has many branches, but I need only a few of them. I’m trying to plot the data from one branch into a histogram. (Later I want to compare the same branch of two TTrees in a histogram, but for the beginning I tried it with one branch from one tree).

My code looks like

#include <TTree.h>
#include <TFile.h>
#include <TH1F.h>

void func1(){

TFile *fs = new TFile(“file.root”);
TTree *ts = (TTree *)fs->Get(“treename”);
Float_t V;
ts->SetBranchAddress(“name of the branch”,&V);

This error occurs at the last line:
Error in TTree::SetBranchAddress: The pointer type given “Float_t” (5) does not correspond to the type needed “vector< float>” by the branch

It appears, when I try to run it with Root (root file.cxx). So I understand that as “Hey you want the data from the branch and you are trying to put them in a float but that will not work”.
I’ve got no idea how to change that code, so that it will work. I’ve made this code with the Users Guide from Root as a help.

So I hope there’s somebody who can help me with that.
Greetings :slight_smile:

std::vector<float> *V = 0;
ts->SetBranchAddress("name of the branch", &V);
// ...
delete V; // after the "ts" no longer uses / needs it

Yes, It worked :slight_smile:
Now I’ve got a new problem, that I can’t fill the Histogram, but I try to fix it.

Thank you!

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