Std::vector to TVector

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

viewtopic.php?f=3&t=7953&start=0

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”
#include
void summaryplots()
{
TFile f1(“Run0012/C1.root”);
f1.cd();

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

vector *C1_ampl;
C1->SetBranchAddress(“ampl”,&C1_ampl);
C1->GetEntry(0);
vector C1_vect = *C1_ampl;

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

ampl_tv.Print();
}
[/code]

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,
Jean-François

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

Thank you, that resolved my problem.