Re: [ROOT] Superimposing 2D plots from ntuples

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Nov 02 2000 - 08:38:37 MET


Hi Robert,
You tried to follow an example showing how to superimpose
two ONE dimensional histograms using two different
vertical scales.
With TWO-dimensional histograms, the x and y axis are part
of the histogram definition & binning. One could think of the
equivalent example by forcing two different Z scales.
I do not think that this is your intention.
I have modified your script to do what I believe you want to do.

Rene Brun


 TFile *f1 = new TFile("et0.root");
   TNtuple *ntuple1 = (TTree*)f1->Get("et0");

TFile *f2 = new TFile("et4.root");
   TNtuple *ntuple2 = (TTree*)f2->Get("et4");

 ntuple1->Draw("Xmean:time>>et0x_july", "run_number < 481", "goff");
 ntuple2->Draw("Xmean:time>>et4x_july", "run_number < 481", "goff");

// make first plot
 et0x_july->SetMarkerColor(4);
 et0x_july->GetXaxis()->SetTitle("Unix Time (sec)");
 et0x_july->GetYaxis()->SetTitle("X ISR Mean (mm)");
 et0x_july->GetYaxis()->CenterTitle();
 et0x_july->SetTitle("July XMean (ISR) vs Time");
 et0x_july->Draw("p");


// draw 2nd plot 
   et4x_july->SetMarkerColor(2);
   et4x_july->Draw("same");

==================================================================


Robert Lee wrote:
Hello all,

   I would like to combine two 2D plots (made from variables 
which were stored in two separate ntuples) with the same X axes
and different Y axes on the same pad.  I tried to follow the
examples I found in earlier posts, but with no luck.  

   When running the portion of the macro below, I only 
get the first plot displayed.  The second axis is generated,
but the scale is not even close to right.  I get no errors
reported as well.

// ************************************ //

 TFile *f1 = new TFile("et0.root");
   TNtuple *ntuple1 = (TTree*)f1->Get("et0");

TFile *f2 = new TFile("et4.root");
   TNtuple *ntuple2 = (TTree*)f2->Get("et4");

 ntuple1->Draw("Xmean:time>>et0x_july", "run_number < 481");
 ntuple2->Draw("Xmean:time>>et4x_july", "run_number < 481");

// make first plot
 et0x_july->SetMarkerColor(4);
 et0x_july->GetXaxis()->SetTitle("Unix Time (sec)");
 et0x_july->GetYaxis()->SetTitle("X ISR Mean (mm)");
 et0x_july->GetYaxis()->CenterTitle();
 et0x_july->SetTitle("July XMean (ISR) vs Time");
 et0x_july->Draw("p");
 myCanvas->Update();

// scale 2nd plot correctly
   Float_t rightmax = 1.1*et4x_july->GetMaximum();
   Float_t scale = gPad->GetUymax()/rightmax;
   et4x_july->Scale(scale);

// draw 2nd plot 
   et4x_july->SetMarkerColor(2);
   et4x_july->Draw("same");

// Draw second axis
   TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),
         gPad->GetUxmax(), gPad->GetUymax(),0,rightmax,510,"+L");

   axis->Draw();



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