Hi, Do: TFile f(input); TCut runcut=cut1 && cut2 && cut3; TTree *all = (TTree*)f.Get("all"); TFile fout(output,"RECREATE"); TH1F *pointetah = new TH1F("pointetah","emc point eta",80,-1,1); all->Draw("pointeta>>pointetah",runcut); fout.Write(); The problem is that all->Draw("pointeta>>pointetah",runcut); looks for an histogram named 'pointetah' in the current ROOT directory and if it does not find one, create one with that name. In your script, you create histrograms which are stored in the current directory at the time (gROOT) and then open the input file, which becomes the current directory. all->Draw does not find the histograms in this new current directory and thus creates some new ones (and display them properly). Later when you call Write on the histogram pointers, the first histograms (that were held in gROOT and are still empty) are saved in the file. Cheers, Philippe. -----Original Message----- From: owner-roottalk@pcroot.cern.ch [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Weijiang Dong Sent: Monday, July 21, 2003 7:59 PM To: roottalk@pcroot.cern.ch Subject: [ROOT] TNtuple::Draw("sth>>hist") and hist->Write() didn't work Hi, I have a root file which contains a Ntuple. I want to draw some of the variables in the Ntuple into a few histograms and save the histograms into a new root file. I have a macro to do this. When the macro ran, root didn't complain anything. But later when I open the new root file, the histogram keys were visible, but they were all empty. Need your help! btw, when I do it step by step, I can see the histrograms were correctly plotted on the canvas, but none of them were correctly wrote into the new root file. here is my macro(xbadrun.C): xbadrun(const char* input, const char* output) { TH1F *pointetah = new TH1F("pointetah","emc point eta",80,-1,1); TH1F *pointphih = new TH1F("pointphih","emc point phi",240,-TMath::Pi(),TMath::Pi()); TH2F *pointetaphih = new TH2F("pointetaphih","emc point eta and phi",80,-1,1,240,-TMath::Pi(),TMath::Pi()); TFile f(input); TCut cut1="RunId!=4033025"; TCut cut2="RunId!=4034002"; TCut cut3="RunId!=4034005"; TCut runcut=cut1 && cut2 && cut3; all->Draw("pointeta>>pointetah",runcut); all->Draw("pointphi>>pointphih",runcut); all->Draw("pointeta:pointphi>>pointetaphih",runcut); TFile fout(output,"RECREATE"); fout.cd(); pointetah->Write(); pointphih->Write(); pointetaphih->Write(); fout.Close(); f.Close(); } Thanks. Weijiang
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:13 MET