Hi Zhou,
Sorry for the typo in my previous mail. Please read the documentation
for TTree::Branch.
You should have :
t->Branch("evt",&evt,"evt",32000);
t->Branch("ntr",&ntr,"ntr",32000);
t->Branch("tid",&tid,"tid",32000);
instead of
t->Branch("evt",&evt,32000);
t->Branch("ntr",&ntr,32000);
t->Branch("tid",&tid,32000);
etc..
Rene
On Tue, 9 May 2000, Zhou Zhang wrote:
> Dear Rene,
>
> Indeed one of my ntpules has 29 variables. I used the example you give
> me replacing the x1,y1,u1,v1 with the all true variables to fetch the
> data from this ntuple. The code is as
> following:
>
> {
> Float_t
> evt,ntr,tid,arm,side,tx,ty,tz,tvx,tvy,tvz,nhit,hid,plane,cell,dist,width,hx,hy,hz,hvx,hvy,hvz,res,blind,out,rid,edge,time;
>
> TFile *file1 = new TFile("hit_asso_residual_800events.root");
> TTree *t1 = (TTree*)file1->Get("trackInfo");
> t1->SetBranchAddress("evt",&evt);
> t1->SetBranchAddress("ntr",&ntr);
> t1->SetBranchAddress("tid",&tid);
> t1->SetBranchAddress("arm",&arm);
> t1->SetBranchAddress("side",&side);
> t1->SetBranchAddress("tx",&tx);
> t1->SetBranchAddress("ty",&ty);
> t1->SetBranchAddress("tz",&tz);
> t1->SetBranchAddress("tvx",&tvx);
> t1->SetBranchAddress("tvy",&tvy);
> t1->SetBranchAddress("tvz",&tvz);
> t1->SetBranchAddress("nhit",&nhit);
> t1->SetBranchAddress("hid",&hid);
> t1->SetBranchAddress("plane",&plane);
> t1->SetBranchAddress("cell",&cell);
> t1->SetBranchAddress("dist",&dist);
> t1->SetBranchAddress("width",&width);
> t1->SetBranchAddress("hx",&hx);
> t1->SetBranchAddress("hy",&hy);
> t1->SetBranchAddress("hz",&hz);
> t1->SetBranchAddress("hvx",&hvx);
> t1->SetBranchAddress("hvy",&hvy);
> t1->SetBranchAddress("hvz",&hvz);
> t1->SetBranchAddress("res",&res);
> t1->SetBranchAddress("blind",&blind);
> t1->SetBranchAddress("out",&out);
> t1->SetBranchAddress("rid",&rid);
> t1->SetBranchAddress("edge",&edge);
> t1->SetBranchAddress("time",&time);
>
>
> TFile *newfile = new TFile("kk.root","recreate");
>
> TTree *t = new TTree("t","t");
>
> t->Branch("evt",&evt,32000);
> t->Branch("ntr",&ntr,32000);
> t->Branch("tid",&tid,32000);
> t->Branch("arm",&arm,32000);
> t->Branch("side",&side,32000);
> t->Branch("tx",&tx,32000);
> t->Branch("ty",&ty,32000);
> t->Branch("tz",&tz,32000);
> t->Branch("tvx",&tvx,32000);
> t->Branch("tvy",&tvy,32000);
> t->Branch("tvz",&tvz,32000);
> t->Branch("nhit",&nhit,32000);
> t->Branch("hid",&hid,32000);
> t->Branch("plane",&plane,32000);
> t->Branch("cell",&cell,32000);
> t->Branch("dist",&dist,32000);
> t->Branch("width",&width,32000);
> t->Branch("hx",&hx,32000);
> t->Branch("hy",&hy,32000);
> t->Branch("hz",&hz,32000);
> t->Branch("hvx",&hvx,32000);
> t->Branch("hvy",&hvy,32000);
> t->Branch("hvz",&hvz,32000);
> t->Branch("res",&res,32000);
> t->Branch("blind",&blind,32000);
> t->Branch("out",&out,32000);
> t->Branch("rid",&rid,32000);
> t->Branch("edge",&edge,32000);
> t->Branch("time",&time,32000);
>
> Int_t nentries = Int_t(t1->GetEntries());
> cout<<"n = "<<nentries<<endl;
>
> for (Int_t i=0;i<nentries;i++) {
> t1->GetEntry(i);
> t->Fill();
> }
> t->Write();
> }
>
>
> After running the macro I got the following output from the root when I
> opened the newfile:
>
> root [12] t.Print()
> ******************************************************************************
> *Tree :t : t
> *
> *Entries : 6223 : Total Size = 291 bytes File Size =
> 291 *
> * : : Tree compression factor = 1.00
> *
> ******************************************************************************
>
>
> What makes me confused is there is no branches as I expected.
>
> when I want to scan the variable "evt" in the tree using t->Scan("evt")
> I got an error message such as
> root [14] t.Scan("evt")
> *ERROR 26 :
> Unknown name : "evt"
>
> and the value of the variable is wrong.
>
> Could you please help me find what is wrong? The attachment is the root
> file containing the ntuple called trackInfo.
>
> Thanks a lot,
>
> zhou
>
>
>
>
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:24 MET