Hi,
>> first of all, you should use pointers to histograms: >> >> class MyClass : public TObject { >> private: >> TH1D *hist;
Not a ROOT reason, but a C++ one. Suppose you have a TH1D hist, not a pointer, and you create an object of type MyClass:
the compiler invokes the default constructor TH1D::TH1D() for hist, and then you revert all that did later, setting up hist properly (name, binning,...), so it becomes usable. That's a waste of CPU, and you might have to watch out with renaming histograms (ROOT doesn't notice that they're renamed, and doesn't update its list of known histograms - which can be searched by name).
Or you need to initialize hist as part of the initialization list of the
constructor of your class, i.e.
MyClass::MyClass(const char* name):
hist(name, Form("a hist in MyClass named %s", name), 100, 0., 1.)
{...}
Often you don't know yet the binning, the name, etc at the time the
constructor is called.
That's why I always prefer the pointer member, and a simple MyClass::MyClass(const char* name): hist(0) {...}
creating hist = new TH1D(...) when everything is known.
That's the generic advice. Without knowing your use case and code I cannot tell whether having a TH1D member makes sense or not in your application.
Cheers, Axel. Received on Wed Jun 21 2006 - 16:38:02 MEST
This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:59 MET