Re: Superimposing histograms

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Fri, 24 Aug 2007 12:57:38 +0200


Use a THStack object. It will compute automatically the scale for all histograms in the stack, eg

   THStack *hs = new THStack("hs","example");    hs->Add(h0phiL1);
   hs->Add(hophiL2):
   etc

  hs->Draw("nostack");

see examples in $ROOTSYS/tutorials/hist/hsdtack.C and: http://root.cern.ch/root/html/THStack.html

Rene Brun

Daniel Andrade Leon wrote:
> Hi Rooters,
>
> When I try to superimpose histograms, the first drawn histogram fixes the Y range and the next histogram ( "same" ) sometimes don't display the complete range. The solution could be to draw in the opposite order, but with a lot of histograms this is a very long work. And by changing the order with color filled histograms I obviously can't see all the line.
> I'm trying to solve this problem by setting the axis range, but it doesn't work.
> Please help me with some idea.
>
> Tkank you very much
>
>
> Daniel
>
>
>
>
> {
> gROOT->Reset();
>
> TFile *f0 = new TFile("/space2/andrade/run/ejercicios/Ideal_histos.root");
> TH1F *h0phiL1 = (TH1F *)f0->Get("h0phiL1");
>
> TFile *f1 = new TFile("/space2/andrade/run/ejercicios/Misaligned_histos.root");
> TH1F *h1phiL1 = (TH1F *)f1->Get("h1phiL1");
>
> TCanvas *cIM = new TCanvas("cIM", "Ideal & Misaligned Geometries");
>
> gPad->SetLogy(0);
>
> h1phiL1->SetLineColor(36);
> h1phiL1->SetFillColor(33);
>
> Double_t scale_h0phiL1 = 1/h0phiL1->Integral();
> h0phiL1->Scale(scale_h0phiL1);
>
> Double_t scale_h1phiL1 = 1/h1phiL1->Integral();
> h1phiL1->Scale(scale_h1phiL1);
>
> Double_t maxh0phiL1=0.0;
> Double_t maxh1phiL1=0.0;
> maxh0phiL1=h0phiL1->GetMaximum();
> maxh1phiL1=h1phiL1->GetMaximum();
> if(maxh0phiL1>maxh1phiL1){
> h1phiL1->GetYaxis()->SetRange(0,1.1*maxh0phiL1);
> }
> else{
> h1phiL1->GetYaxis()->SetRange(0,1.1*maxh1phiL1);
> }
>
> h1phiL1->Draw();
> h0phiL1->Draw("same");
>
> }
>
Received on Fri Aug 24 2007 - 12:57:44 CEST

This archive was generated by hypermail 2.2.0 : Sat Aug 25 2007 - 05:50:02 CEST