Trouble with Tree, Double_t vs. Double

I’ve been trying to read in a root tree to a std::vector and keep getting the same error (below):
Error in <TTree::SetBranchAddress>: The pointer type given "vector<double>" does not correspond to the type needed "Double_t" (8) by the branch: xMwpc4Muon

The code that I am using is below. Please note that I changed every instance of Double_t to double in the code that produces the tree and still get the error. I have also tried changing the std::vector to std::vector<double_t>. Any help is greatly appreciated.

#include "TFile.h"
#include "TTreeReader.h"
#include "TTreeReaderValue.h"
#include <string>
#include <iostream>
#include <sstream>
#include <vector>

void xReadTree()
  TFile f1("trackInformation.root");
  TTree *t1 = (TTree*)f1.Get("tracks;1");

  std::vector<double> *muons = 0;
  t1->SetBranchAddress("xMwpc4Muon", &muons);

  int n = (int) t1->GetEntries();
  std::cout << "Tree Entries: " << n << std::endl;
  for(int i=0; i<n; ++i){
    int ntrk = muons->size();
    for(int j=0; j<ntrk; ++j){
      double v = (*muons)[j];

from the error message, it would seem what you need is a plain Double_t muon; not a std::vector<double> *muons;
(so, a scalar, not a collection.)

The error states that the branch is not a vector<double>, but just a double (or Double_t, which should be equivalent). You should change muons from a pointer to vector<double> to just a double.

Oh that makes sense… Thanks for the help

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