Std::vector to TVector

I am trying to create a TVector from an std::vector. I have found the following older post:


but I find that this does not work. Rather, it works when I do .x mymacro.C in root, but not when I do .x mymacro.C+ (compiling). When compiling I get a segmentation fault (but no useful error messages).

My context is that I have a file with a tree with a single branch. The branch holds std::vectors, and I wish to perform some mathematical operations that are much easier with a TVector. Here is the code I am trying to use (based on the RootTalk post linked above):

[code]#include “TVector.h”
#include “TFile.h”
#include “TTree.h”
void summaryplots()
TFile f1(“Run0012/C1.root”);;

TTree* C1 = (TTree*)gDirectory->Get(“C1”);

vector *C1_ampl;
vector C1_vect = *C1_ampl;

TVectorD ampl_tv(C1_vect.size(),&C1_vect[0]);


As mentioned, it works when I just .x mymacro.C, but not with .x mymacro.C+. This indicates that it should be possible to add an #include line, or fix a -> vs . problem, but it is not obvious at all, since the only error message is a segmentation violation.

Thank you for any help,

#include “TFile.h”
#include “TTree.h”
#include “TDirectory.h”
#include “TVectorD.h”
// …
vector *C1_ampl = 0;
// …

Thank you, that resolved my problem.