Re: dynamical versus non dynamical for TH1F

From: Andriy Zatserklyaniy <zatserkl_at_gmail.com>
Date: Sat, 23 Jan 2010 15:23:15 -0600


Hi Mark,

In short: a recommended way is to create you histogram in heap

TH1F *myhisto=new TH1F(...)

Otherwise you have to specify what do you want to optimise: speed, memory usage, etc.

Well known drawback of

TH1F myhisto(...)

is that, according to C++ rules, the object myhisto will be destroyed after exiting of scope, e.g. when your macro will terminate (if you draw this histogram in macro, the plot will disappear from TCanvas).

Cheers,
Andrei.

On Sat, Jan 23, 2010 at 10:48 AM, Marc Escalier <escalier_at_lal.in2p3.fr>wrote:

> Hello,
>
> i'm using a basic root program (.C) that allows to make some histograms of
> variables of a given ntuple (a .root file)
>
> Up to now, i created the histogram dynamically with
> TH1F *myhisto=new TH1F(...)
>
> i was wondering what it the more optimal (in terms of memory, cpu usage, or
> any other criterious you know better than me) way to do ? :
>
> *this kind of dynamical allocation
>
> or
>
> *a non dynamical allocation
> (i mean :
> TH1F myhisto(...)
> )
>
> (just in case : i do always the same plots and there variables are always
> in the ntuple)
>
> thanks !
>
> (i'll reply in private to answers to prevent spamming you all)
>
>
Received on Sat Jan 23 2010 - 22:23:20 CET

This archive was generated by hypermail 2.2.0 : Sun Jan 24 2010 - 05:50:02 CET