normalizing histograms

From: Richard Dubois (richard@SLAC.stanford.edu)
Date: Tue Jul 01 1997 - 22:12:51 MEST


I am using 2 PAW ntuples h2root-ed. I want to overplot variables from
each file, normalized by entries. I can now sort out (see attachment) how
to normalize them when I have explicitly defined the histograms.

 I am curious to know if I can also do it in the 'interactive' mode,
using the h10 TTree object, viz:

 TFile f("file1.root");
 TFile g("file2.root");

 f.cd();
 h10.Draw("momentum");
 g.cd();
 h10.Draw("momentum","","same");

 Can I get pointers to these two histograms so I can normalize them
as per Rene's solution (in the attachment)?

Thanks,

Richard
-- 
Richard Dubois
SLD, Stanford Linear Accelerator Center
Richard@slac.stanford.edu
http://www.slac.stanford.edu/~richard/
415-926-3824
415-926-2923 (FAX)


attached mail follows:


Richard Dubois wrote: > > Hi Rene, > > In a quick search I didn't find an address to send root questions... > > I want to do an overlay of two plots, normalized by the number of > entries for each. I haven't been able to figure out how to do the > normalization. How do I do it? > Hi Richard, We have two lists roottalk and rootdev. To suscribe see http://root.cern.ch roottalk is a general discussion list (we have about 300 people now) rootdev is the Root developers. Send mail to rootdev@hpsalo.cern.ch for bug reports (if any). Now the answer to your question. Suppose you have a Root file containing two histograms h1 and h2 You can do: Root > float norm1 = 1/h1.GetEntries() Root > float norm2 = 1/h2.GetEntries() Root > TH1F hnorm1 = norm1*(*h1) Root > TH1F hnorm2 = norm2*(*h2) Root > hnorm1.Draw(); Root > hnorm2.Draw("same") Note that if h1 and h2 are two TH1F objects (not pointers) created with TH1F h1(...) TH2F h2(..) you should replace the statement above TH1F hnorm1 = norm1*(*h1) by TH1F hnorm1 = norm1*h1 (*h1) dereferences the pointer (normal C++). Rene



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:19 MET