Hi Zhou,
You can do the following:
{
Float_t x1,y1,u1,v1;
Float_t x2,y2,u2,v2;
TFile *file1 = new TFile("file1.root");
TTree *t1 = (TTree*)file1->Get(name_of_tree1);
t1->SetBranchAddress("x1",&x1);
t1->SetBranchAddress("y1",&y1);
t1->SetBranchAddress("u1",&u1);
t1->SetBranchAddress("v1",&v1);
TFile *file2 = new TFile("file2.root");
TTree *t2 = (TTree*)file2->Get(name_of_tree2);
t2->SetBranchAddress("x2",&x2);
t2->SetBranchAddress("y2",&y2);
t2->SetBranchAddress("u2",&u2);
t2->SetBranchAddress("v2",&v2);
TFile *newfile = new TFile("newfile.root","recreate");
TTree *t = new TTree("t");
t->Branch("x1",&x1,32000);
t->Branch("y1",&y1,32000);
t->Branch("u1",&u1,32000);
t->Branch("v1",&v1,32000);
t->Branch("x2",&x2,32000);
t->Branch("y2",&y2,32000);
t->Branch("u2",&u2,32000);
t->Branch("v2",&v2,32000);
Int_t nentries = Int_t(t1->GetEntries());
for (Int_t i=0;i<nentries;i++) {
t1->GetEntry(i);
t2->GetEntry(i);
t->Fill();
}
t->Write();
}
On Tue, 9 May 2000, Zhou Zhang wrote:
> Hi rooters,
>
> I have two ntuples n1, n2 which have the float variable list
> (x1,y1,u1,v1) and (x2,y2,u2,v2) seperately. I need to get the data of
> (x1,y1) and (x2,y2) from these two ntuples and put them together into
> a new ntuple. I tried to use following piece of macro but failed:
>
> TBranch* bx1 = n1->GetBranch("x1");
> TLeaf* lx1 = bx1->GetLeaf("x1");
> Float_t fx1 = lx1->GetValue(0);//first entry
> the value of fx1 is not what I expected.
>
> who could tell me how to do it?
>
> Thanks a lot,
>
> zhou
>
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:24 MET