Hi Rooters,
I am trying to fill a TTree with an std::vector of a vector. I am not sure about the syntax to use on the Branch method. Could you please have a look in the attached code and tell me from where the problem comes.
—> sorry I cannot attach the file … I will try to put the codes below :
[code]–> in the .hh
Int_t Nsampler;
Int_t n_hits[200];
std::vector <Float_t> x0[200],xp0[200],y0[200],yp0[200];
std::vector <Float_t> E0[200],z0[200],x[200],xp[200],y[200];
std::vector <Float_t> yp[200],E[200],z[200],weight[200];
std::vector <Int_t> part[200],nev[200], pID[200],theID[200],track_id[200];
–> in the .cc
SamplerTree->Branch(“Nsampler”,&Nsampler,“Nsampler/I”);
SamplerTree->Branch(“n_hits”,&n_hits,“h_hits/I”);
SamplerTree->Branch(“x”,x,“std::vector<Float_t> x[Nsampler]/F”);
SamplerTree->Branch(“x0”,x0,“std::vector<Float_t> x0[Nsampler]”);
SamplerTree->Branch(“xp0”,xp0,“std::vector<Float_t> xp0[Nsampler]”);
SamplerTree->Branch(“y0”,y0,“std::vector<Float_t> y0[Nsampler]”);
SamplerTree->Branch(“yp0”,yp0,“std::vector<Float_t> yp0[Nsampler]”);
SamplerTree->Branch(“E0”,E0,“std::vector<Float_t> E0[Nsampler]”);
SamplerTree->Branch(“z0”,z0,“std::vector<Float_t> z0[Nsampler]”);
SamplerTree->Branch(“xp”,xp,“std::vector<Float_t> xp[Nsampler]”);
SamplerTree->Branch(“y”,y,“std::vector<Float_t> y[Nsampler]”);
SamplerTree->Branch(“yp”,yp,“std::vector<Float_t> yp[Nsampler]”);
SamplerTree->Branch(“E”,E,“std::vector<Float_t> E[Nsampler]”);
SamplerTree->Branch(“z”,z,“std::vector<Float_t> z[Nsampler]”);
SamplerTree->Branch(“part”,part,“std::vector<Int_t> part[Nsampler]”);
SamplerTree->Branch(“nev”,nev,“std::vector<Int_t> nev[Nsampler]”);
SamplerTree->Branch(“pID”,pID,“std::vector<Int_t> pID[Nsampler]”);
SamplerTree->Branch(“tID”,track_id,“std::vector<Int_t> tID[Nsampler]”);
for (G4int ks=0; ks<nSamplers; ks++)
{
n_hits[ks]=0;
x0[ks].clear();
xp0[ks].clear();
y0[ks].clear();
yp0[ks].clear();
E0[ks].clear();
z0[ks].clear();
x[ks].clear();
xp[ks].clear();
y[ks].clear();
yp[ks].clear();
E[ks].clear();
z[ks].clear();
weight[ks].clear();
part[ks].clear();
nev[ks].clear();
pID[ks].clear();
track_id[ks].clear();
}
for (G4int i=0; i<hc->entries(); i++)
{
G4int ksampler = names[(*hc)[i]->GetName()];
name=(*hc)[i]->GetName();
n_hits[ksampler]++;
x0[ksampler].push_back((*hc)[i]->GetInitX() / micrometer);
xp0[ksampler].push_back((*hc)[i]->GetInitXPrime());
y0[ksampler].push_back((*hc)[i]->GetInitY() / micrometer);
yp0[ksampler].push_back((*hc)[i]->GetInitYPrime());
E0[ksampler].push_back((*hc)[i]->GetInitMom() / GeV);
z0[ksampler].push_back((*hc)[i]->GetInitZ() / m);
x[ksampler].push_back((*hc)[i]->GetX()/ micrometer);
xp[ksampler].push_back((*hc)[i]->GetXPrime());
y[ksampler].push_back((*hc)[i]->GetY() / micrometer);
yp[ksampler].push_back((*hc)[i]->GetYPrime());
E[ksampler].push_back((*hc)[i]->GetMom() / GeV);
z[ksampler].push_back((*hc)[i]->GetZ() / m);
weight[ksampler].push_back((*hc)[i]->GetWeight());
part[ksampler].push_back((*hc)[i]->GetPDGtype());
nev[ksampler].push_back((*hc)[i]->GetEventNo());
pID[ksampler].push_back((*hc)[i]->GetParentID());
track_id[ksampler].push_back((*hc)[i]->GetTrackID());
Nsampler=nSamplers;
sTree->Fill();
}
[/code]
thanks a lot,
Hayg