Hi John,
You do not call the right Branch constructor for your second Tree:
Replace the lines:
h11->Branch("Cal_e",&aCal_e);
h11->Branch("Cal_et",&aCal_et);
h11->Branch("Cal_empz",&aCal_empz);
h11->Branch("Cal_pt",&aCal_pt);
by
h11->Branch("Cal_e",&aCal_e,"Cal_e/F");
h11->Branch("Cal_et",&aCal_et,"Cal_et/F");
h11->Branch("Cal_empz",&aCal_empz,"Cal_empz/F");
h11->Branch("Cal_pt",&aCal_pt,"Cal_pt/F");
Rene Brun
John H Loizides wrote:
>
> Can Someone help me please I am trying to create a new root file from an
> existing root file with some cuts imposed on the TTree. My code is below
> with no cuts so it sould create the same root file. But does not seem to
> fill the TTree with anything.
>
> main()
> {
>
> TFile *f =
> (TFile*)gROOT->GetListOfFiles()->FindObject("97NCBACKq400.root");
> if (!f) {
> f = new TFile("97NCBACKq400.root");
> }
> TTree *h1 = (TTree*)gDirectory->Get("h1");
>
> Float_t Cal_e;
> Float_t Cal_et;
> Float_t Cal_empz;
> Float_t Cal_pt;
>
> Float_t aCal_e;
> Float_t aCal_et;
> Float_t aCal_empz;
> Float_t aCal_pt;
>
> h1->SetBranchAddress("Cal_e",&Cal_e);
> h1->SetBranchAddress("Cal_et",&Cal_et);
> h1->SetBranchAddress("Cal_empz",&Cal_empz);
> h1->SetBranchAddress("Cal_pt",&Cal_pt);
>
> TFile *outfile = new TFile("S3.root","RECREATE");
>
> TTree *h11 = new TTree("T","A new Tree");
>
> h11->Branch("Cal_e",&aCal_e);
> h11->Branch("Cal_et",&aCal_et);
> h11->Branch("Cal_empz",&aCal_empz);
> h11->Branch("Cal_pt",&aCal_pt);
> Int_t nentries = h1->GetEntries();
>
> for (Int_t i=0; i<nentries;i++)
> {
> h1->GetEntry(i);
>
> h11->Fill();
>
> }//for i
>
> h11->Write();
> outfile->Write();
>
> outfile->Close();
>
> }//main
>
> Thanks
>
> John Loizides
>
> 4th Year Student UCL Physics
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:39 MET