Re: [ROOT] Histograms from TNtuple::Draw

From: Otto Schaile (Otto.Schaile@Physik.uni-muenchen.de)
Date: Tue Nov 14 2000 - 19:33:08 MET


Hi Miro,

just do:
 ntuple->Draw("var1:var2>>histv1v2")

and you ll get a hist with name "histv1v2"

often it is useful that yourself decide on the parameters
of the histogram, in this case you construct a hist yourself
and give its name to ntuple->Draw

TH2F * h2 = new TH2F("hv1v2", "var2 vs var1", 100,-2,2, 100, -2, 2) 
ntuple->Draw("var1:var2>>hv1v2")

Cheers
Otto

On Tue, 14 Nov 2000, Miroslav Helbich wrote:

> 
>  Hi,
> 
>   I have an NTuple and I want to do some fast analysis. When 
> I do ntuple->Draw("variable") it draws a nice histogram. How can I get a
> copy of it? In the following macro I use a trick with cloning histogram
> htemp created by TNtuple::Draw. However, this is not working for 2D
> histograms. What is wrong? Is there any way to get a histogram from
> TNtuple::DrawClone() ?
> 
> 				Regards,
> 
> 					Miro
> 
> I'm using version 25_03 for SuSe Linux
> 
> Macro:
> 
> {
> // first generate ntuple
> TNtuple *ntuple = new TNtuple("ntuple","ntuple","Ehit:yhit"); 
> Double_t Ehit,yhit;
> for (Int_t i=0;i<100;i++) {  
>   Ehit = gRandom->Gaus(10.,0.5); 
>   yhit= gRandom->Gaus(0.,0.7); 
>   ntuple->Fill(Ehit,yhit);
> }
> 
> // plots
>   TCanvas* c1 = new TCanvas("c1","c1",1);
>   c1->Divide(2,2);
> 
> // trick with 1D histograms
>   c1->cd(1);
>   ntuple->Draw("Ehit");
>   TH1F * myh1 =(TH1F *) htemp->Clone();
>   myh1->SetName("myh1");
>   c1->cd(2);
>   myh1->Draw(); // this works
> 
> // trick with 2D histograms - doesn't work!
>   c1->cd(3);
>   ntuple->Draw("Ehit:yhit");
>   TH2F *myh2 = (TH2F *) htemp->Clone();
>   myh2->SetName("myh2");
>   c1->cd(4);  
> myh2->Draw(); // it is empty!
> }
> 
> 

Dr. Otto Schaile            Sektion Physik, LMU Muenchen
Phone: +49 89 289 14070     Am Coulombwall 1, D-85748 Garching, Germany
GSM:   +49 171 4312031
FAX:   +49 89 289 14072     EMail: Otto.Schaile@Physik.Uni-Muenchen.DE



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:37 MET