Re: Error in drawing a histogram from ntuple file

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Sun, 13 Nov 2005 08:56:50 +0100 (MET)


see the file modified below and read comments

Rene Brun

void test()
{

//gROOT->Reset(); //==>never call this in a named macro (see u guide) gStyle->SetOptStat(0);
gBenchmark->Start("");
Float_t Et_had, Et_ptGT;

TFile *f = new TFile("correctionFactors_20154.root"); TNtuple *ntuple = (TNtuple*)f -> Get("ntuple"); TH1F *EtT_had = new TH1F("Et_had","Total hadronic Et",250,0.,500.);

Int_t Nentries = (Int_t)ntuple -> GetEntries(); //==>function returns Long64_t
cout << " Nentries = " << Nentries << endl;

ntuple -> SetBranchAddress("Et_had",&Et_had); ntuple -> SetBranchAddress("Et_ptGT",&Et_ptGT); for (Int_t i=0; i< Nentries; i++)

   {

     ntuple  -> GetEntry(i);
     // cout <<Et_had <<endl;
     EtT_had -> Fill(Et_had);

   }
TCanvas *test = new TCanvas("test","",2);

EtT_had -> Draw();
//f->Close(); //closing the file deletes the associated histograms gBenchmark->Show("");

}

On
Sun, 13 Nov 2005,
Raghunath Sahoo wrote:

>
> Dear All,
>
> I have a macro which reads a .root file which contains a ntuple.
> While plotting, it draws a canvas but doesn't plot the desired
> observable. The error message is:
>
> root [0] .x test.C
> Warning: conversion from 64bit to 32bit integer FILE:test.C LINE:13
> Nentries = 169
> : Real Time = 1.01 seconds Cpu Time = 0.96 seconds
> root [1] .q
>
> In line: 13, I have,
>
> Int_t Nentries = ntuple -> GetEntries();
>
> I am using root version 4.04/02 in Redhat linux 7.2 gcc: 2.96
>
> I could plot the branches in the ntuple thru TBrowser().
> And also, I could plot in root giving command lines.
>
> Any help is highly appreciated.
>
> Regards,
> Raghunath.
>
> NB: The macro is the following:
>
>
> void test()
> {
>
> gROOT->Reset();
> gStyle->SetOptStat(0);
> gBenchmark->Start("");
> Float_t Et_had, Et_ptGT;
>
> TFile *f = new TFile("correctionFactors_20154.root");
> TNtuple *ntuple = (TNtuple*)f -> Get("ntuple");
> TH1F *EtT_had = new TH1F("Et_had","Total hadronic Et",250,0.,500.);
>
> Int_t Nentries = ntuple -> GetEntries();
> cout << " Nentries = " << Nentries << endl;
>
> ntuple -> SetBranchAddress("Et_had",&Et_had);
> ntuple -> SetBranchAddress("Et_ptGT",&Et_ptGT);
> for (Int_t i=0; i< Nentries; i++)
> {
> ntuple -> GetEntry(i);
> // cout <<Et_had <<endl;
> EtT_had -> Fill(Et_had);
> }
> TCanvas *test = new TCanvas("test","",2);
>
> EtT_had -> Draw();
> f->Close();
> gBenchmark->Show("");
>
> }
>
>
> ********************************************************************
> * Raghunath Sahoo * Phone: +91-0674-2301172 *
> * Doctoral Scholar * 2301058 *
> * Institute Of Physics * Lab:- 230,H-303,359(Extn) *
> * Sachivalaya Marg * Fax: +91-0674-2300142 *
> * Bhubaneswar * URL: http://www.iopb.res.in/~raghu *
> * Orissa (India)-751005 * email: raghu_at_iopb.res.in *
> ********************************************************************
> * raghu_at_bnl.gov * raghu_at_mail.cern.ch *
> ********************************************************************
>
Received on Sun Nov 13 2005 - 08:56:58 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:13 MET