Kalanand's May 2008 Log

   April 2008   
May 2008
SuMoTuWeThFrSa
    123
45678910
11121314151617
18192021222324
25262728293031
   June 2008   

May 1st

Two plots on the same canvas sharing common axis

Here is my attempt to plot two histograms on different pads of a canvas that share the same x-axis. A minor nuisance is that the y-axis labels kind of overlap, although this is fixable with some tweaks :( PlotTwo.C
void PlotTwo() {


   TCanvas *c1 = new TCanvas("c1","multipads",900,700);
   gStyle->SetPadBorderMode(0);
   gStyle->SetOptStat(0);
   gStyle->SetOptTitle(0);

   c1->Divide(2,2,0,0);

   TH1F *h1 = new TH1F("h1","test1",20,-3,3);
   h1->SetMarkerStyle(21);
   h1->Sumw2();
   TH1F *h2 = (TH1F*)h1->Clone("h2");
   TH1F *h3 = (TH1F*)h1->Clone("h3");


   TH1F *h4 = (TH1F*)h1->Clone("h4");
   h1->FillRandom("gaus",500); h1->SetMaximum(80);
   h2->FillRandom("gaus",300); h2->SetMaximum(80);
   h3->FillRandom("gaus",900); h3->SetMaximum(130);


   h4->FillRandom("gaus",500); h4->SetMaximum(130);
   
   c1->cd(1);
   gPad->SetBottomMargin(0);
   gPad->SetRightMargin(0);
   gPad->SetTickx();
   h1->GetYaxis()->SetTitle("Number of events");


   h1->Draw();
   
   c1->cd(2);
   gPad->SetLeftMargin(0);
   gPad->SetBottomMargin(0);
   gPad->SetTickx();
   gPad->SetTicky();
   h2->GetYaxis()->SetLabelOffset(0.01);

   h2->Draw();

   
   c1->cd(3);
   gPad->SetTopMargin(0);
   gPad->SetRightMargin(0);
   gPad->SetGridx();
   gPad->SetGridy();
   h3->Draw();

   c1->cd(4);
   gPad->SetLeftMargin(0);


   gPad->SetTopMargin(0);
   gPad->SetTicky();
   gPad->SetGridx();
   gPad->SetGridy();
   h4->GetXaxis()->SetTitle("X title");
   h4->Draw();
}      

Revisited on May 5

A similar question was raised in ROOT forum. The following python code accomplishes similar task as above.
#!/usr/bin/python
import sys, os, ROOT
"""
This is for plotting two histograms with differing y-ranges and the same x-range.  
"""
# general style (taken from my rootlogon.C)
ROOT.gROOT.SetStyle("Plain")
ROOT.gStyle.SetPadTickX(1)
ROOT.gStyle.SetPadTickY(1)
ROOT.gStyle.SetPadTopMargin(0.05)
ROOT.gStyle.SetPadRightMargin(0.05)
ROOT.gStyle.SetPadBottomMargin(0.16)
ROOT.gStyle.SetPadLeftMargin(0.12)
ROOT.gStyle.SetPadBorderMode(0)
ROOT.gStyle.SetOptStat(0)
ROOT.gStyle.SetOptTitle(0)

# create two functions to draw
file = ROOT.TFile( sys.argv[1] )
tree = file.Get("fTree")
minRun = tree.GetMinimum("fRunNumber") - 10
maxRun = tree.GetMaximum("fRunNumber") + 10

# create a canvas and divide it
c1 = ROOT.TCanvas("paddy","paddy",700,700)
c1.Divide(1,2,0,0)

# Histogram for the reset rate in Hz
h1 = ROOT.TH2F("h1","h1",10000,minRun,maxRun,10000,7200,7450)
h1.SetMarkerStyle(24)
h1.SetMarkerSize(0.4)
h1.GetYaxis().SetTitle("Baseline Value (ADC)")

# Histogram for the Nitrogen Level
h2 = ROOT.TH2F("h2","h2",10000,minRun,maxRun,10000,72,98)
h2.SetMarkerStyle(24)
h2.SetMarkerSize(0.4)
h2.GetXaxis().SetTitle("Run Number")
h2.GetYaxis().SetTitle("LN_{2} Level (%)")

#top canvas
c1.cd(1)
ROOT.gPad.SetBottomMargin(0.001)
ROOT.gPad.SetTopMargin(0.01)
ROOT.gPad.SetRightMargin(0.01)
tree.Draw("baselineValueMean:fRunNumber>>h1","","goff")
h1.Draw()

# bottom canvas
c1.cd(2)
ROOT.gPad.SetTopMargin(0.001)
ROOT.gPad.SetRightMargin(0.01)
tree.Draw("fDetLnLevelAtBeginRun:fRunNumber>>h2","","goff")
h2.Draw()

# update the canvas
c1.Update()
raw_input('press enter')

May 6th

My twiki registration

Finally I registered and created a CERN twiki account. Here is the welcome message for future reference.
 
Subject: TWiki - Registration for KalanandMishra (kalanand.mishra@cern.ch)
Date: 	Tue, 06 May 2008 20:05:04 +0000
From: 	TWiki Support 
To: 	Kalanand Mishra 

Thank you for registering in the TWiki collaboration platform. Please save this e-mail for future reference.

Read https://twiki.cern.ch/twiki/bin/view/TWiki/WelcomeGuest to get a quick overview of this collaboration platform. To learn more, study the TWikiTutorial, which is accessible from the same link.

Your personal TWiki topic is located at https://twiki.cern.ch/twiki/bin/view/Main/KalanandMishra. You can customize it as you like:

	* Some people turn it into a personal portal with favorite links, what they work on, what help they'd like, etc.
	* Some add schedule information and vacation notice.
	* How about attaching your photo?

Submitted content:

	* FirstName: Kalanand
	* LastName: Mishra
	* LoginName: kalanand.mishra@cern.ch
	* Email: kalanand.mishra@cern.ch
	* OrganisationName: Fermilab
	* OrganisationURL: 
	* Country: USA
	* Comment: 


Note:
	1 If you got this e-mail by mistake: Somebody (Kalanand Mishra) registered at the TWiki site using your mail address kalanand.mishra@cern.ch. Contact twiki.support@cern.ch if this is in error.
	2 You can change your password at via https://twiki.cern.ch/twiki/bin/view/TWiki/ChangePassword
	3 If you haven't set a password yet or you want to reset it, go to: https://twiki.cern.ch/twiki/bin/view/TWiki/ResetPassword

Go to April's log


Last modified: Tue Nov 4 11:07:59 CST 2008