Re: Adding a vector to a tree

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Thu, 18 Oct 2007 13:46:30 -0500


Use
{

    TFile *f = new TFile("peter.root", "recreate");     TTree * t1 = new TTree("nEmcPhotons", "EMC Photons");     vector<float> *E = new vector<float>;     t1->Branch("E", &E);
}

Also you need to make sure the dictionary for vector<float> is loaded (for example add #include <vector>).

Cheers,
Philippe.

> Hi Rooters,
>
> I want to add a vector to a root tree, and make it a branch of that tree.
> I found the example of adding an array to a tree like below:
>
> {
> TFile *f = new TFile("peter.root", "recreate");
> Int_t nPhot;
> Float_t E[500];
> TTree * t1 = new TTree("nEmcPhotons", "EMC Photons");
> t1->Branch("nPhot", &nPhot, "nPhot/I");
> t1->Branch("E", E, "E[nPhot]/F");
> }
>
>
> Now if I want to change E[500] array above to a vector:
> "vector<float> E",
> how do I change the t1->Branch("E", E, "E[nPhot]/F") line ?
>
> Namely, how do I write the 3rd argument of the "Branch()" method for
> a
> vector?
>
> Thanks for the help!
>
> Best,
> Bin
>
Received on Thu Oct 18 2007 - 20:46:47 CEST

This archive was generated by hypermail 2.2.0 : Fri Oct 19 2007 - 23:50:02 CEST