Hello, I am trying to make a simple ratio plot out of root files, which of each includes a TH1D.
My root environment is set up with
source external/root/bin/thisroot.sh
when the source file is derived from the ROOT 6.08/06 binary distribution for ubuntu64.
The two root files, which contain the TH1D histograms are located in
$HOME/CI8TeV/fastNLO/000/JESJERPDF/
with name of qcd.root and newqcd.root
Both root file contain
TFile** newqcd.root
TFile* newqcd.root
KEY: TH1D nlo_0.500_0.500_000;1
KEY: TH1D nlo_0.500_1.000_000;1
KEY: TH1D nlo_1.000_0.500_000;1
KEY: TH1D nlo_1.000_1.000_000;1
KEY: TH1D nlo_1.000_2.000_000;1
KEY: TH1D nlo_2.000_1.000_000;1
KEY: TH1D nlo_2.000_2.000_000;1
(same for qcd.root)
I attempt to get a ratio plot of
nlo_0.500_0.500_000;1
I have pyROOT script named ratioplot1.py in the same directory
Below is the script that I run with command python ratioplot1.py
from ROOT import *
def ratio():
life = TFile('/home/CI8TeV/fastNLO/CT10/000/JESJERPDF/qcd.root')
death = TFile('/home/CI8TeV/fastNLO/CT10/000/JESJERPDF/newqcd.root')
h1 = TH1D( 'h1', 'h1', 20, 500, 2500)
h2 = TH1D( 'h2', 'h2', 20, 500, 2500)
h1 = life.Get('nl0_0.500_0.500_000').Clone('h1')
h2 = death.Get('nlo_0.500_0.500_000').Clone('h1')
c = TCanvas('c', 'canvas', 800, 800)
hratio = h1.Clone('hratio')
hratio.Divide('h2')
c.cd()
hratio.Draw('ep')
c.Update()
c.SaveAs('.png')
ratio()
However, it gives an error message of
Traceback (most recent call last):
File “ratioplot1.py”, line 21, in
ratio()
File “ratioplot1.py”, line 9, in ratio
h1 = life.Get(‘nl0_0.500_0.500_000’).Clone(‘h1’)
ReferenceError: attempt to access a null-pointer
I also have C macro named ratioplo1.C in the same directory that I run with
root ratioplot1.C
The script basically has same argument but with C language
void ratioplot1(){
TFile* life = new TFile("/home/chad/CI8TeV/fastNLO/CT10/000/JESJERPDF/newqcd.root");
TFile* death = new TFile("/home/chad/CI8TeV/fastNLO/CT10/000/JESJERPDF/qcd.root");
TH1D *h1 = (TH1D*)life->Get("nl0_0.500_0.500_000")->Clone("h1");
TH1D *h2 = (TH1D*)death->Get("nlo_0.500_0.500_000")->Clone("h2");
// Define the Canvas
TCanvas *c = new TCanvas("c", "canvas", 800, 800);
TH1D *hratio = (TH1D*)hratio->Get(h1)->Clone("hratio");
hratio->Divide("h2");
c->cd();
hratio->Draw("ep");
c->Update();
c->SaveAs(".png");
It gives me a different error message.
root [0]
Processing ratioplot1.C…
In file included from input_line_8:1:
/home/chad/CI8TeV/fastNLO/CT10/000/JESJERPDF/ratioplot1.C:22:36: error: no
member named ‘Get’ in ‘TH1D’
TH1D hratio = (TH1D)hratio->Get(h1)->Clone(“hratio”);
~~~~~~ ^
/home/chad/CI8TeV/fastNLO/CT10/000/JESJERPDF/ratioplot1.C:23:12: error: no
matching member function for call to ‘Divide’
hratio->Divide(“h2”);/home/chad/external/root/etc/../include/TH1.h:212:21: note: candidate function not viable: no known conversion from 'const char [3]' to 'TF1 *' for 1st argument virtual Bool_t Divide(TF1 *f1, Double_t c1=1); ^ /home/chad/external/root/etc/../include/TH1.h:213:21: note: candidate function not viable: no known conversion from 'const char [3]' to 'const TH1 *' for 1st argument virtual Bool_t Divide(const TH1 *h1); ^ /home/chad/external/root/etc/../include/TH1.h:214:21: note: candidate function not viable: requires at least 2 arguments, but 1 was provided virtual Bool_t Divide(const TH1 *h1, const TH1 *h2, Double_t c1=1, ... ^
Could I get to know what are the sources of problem for both the pyROOT and C files that I have?
Thank you so much.