Error in <TTree::SetBranchAddress>: Unable to determine type

I’m very new to ROOT, and I’m just starting on research work. I do have many years of experience with C++ though, among many other languages. So that’s my background.

I’m trying to extract some simple data from a D3PD, to make some graphs. I can get things to work in a root shell, but as soon as I move to compiling things everything breaks down. Here’s my code:

#include <root/TFile.h>
#include <root/TROOT.h>
#include <root/TKey.h>
#include <root/TTree.h>
#include <root/TTreePlayer.h>
#include <root/TEntryList.h>
#include <stdio.h>
#include <vector>

int
main()
{
    TFile* fh = TFile::Open("NTUP_HI.01611701._002987.root.2");

    TTree* tree = (TTree*)fh->Get("HeavyIonD3PD");

    std::vector<float>* sv0p_x = NULL;

    tree->SetBranchAddress(
        "antikt4HIItrEMFR_flavor_component_sv0p_x",
        &sv0p_x);

    return 0;
}

Here’s my Makefile:

a.out: run.cpp
	g++ `root-config --cflags` -D__USE_XOPEN2K8 -D_GNU_SOURCE run.cpp `root-config --libs` -lTreePlayer

And finally, here are the errors that result when I try to run the code:

[user@host ntup]$ make && ./a.out
g++ `root-config --cflags` -D__USE_XOPEN2K8 -D_GNU_SOURCE run.cpp `root-config --libs` -lTreePlayer
Warning in <TClass::TClass>: no dictionary for class AttributeListLayout is available
Warning in <TClass::TClass>: no dictionary for class pair<string,string> is available
Error in <TTree::SetBranchAddress>: Unable to determine the type given for the address for "antikt4HIItrEMFR_flavor_component_sv0p_x". The class expected (vector<float>) refers to an stl collection and do not have a compiled CollectionProxy.  Please generate the dictionary for this class (vector<float>)

I didn’t bother putting a GetEntry() call into the code I pasted. Given the failure SetBranchAddress() I just get a segfault when I try GetEntry().

Does anyone have any ideas about how to fix this “Unable to determine the type” error?

In your “main”, try to add the first line in form:
TApplication a(“a”, 0, 0); // just to make sure that the autoloading of ROOT libraries works

1 Like

Wow, that worked. Adding TApplication a(“a”, 0, 0) to the top of main() fixed everything.

What is that doing internally to make ROOT aware of how to handle std::vector?