Hi,
Is there a way to clone an empty histogram (i.e. clone only its dimensions) as there’s a way to clone an empty TTree (CloneTree(0))?
I’d like to avoid the overhead of cloning a histogram and then resetting it.
Thanks,
N.
Hi,
Is there a way to clone an empty histogram (i.e. clone only its dimensions) as there’s a way to clone an empty TTree (CloneTree(0))?
I’d like to avoid the overhead of cloning a histogram and then resetting it.
Thanks,
N.
[quote=“Nir”]Hi,
Is there a way to clone an empty histogram (i.e. clone only its dimensions) as there’s a way to clone an empty TTree (CloneTree(0))?
I’d like to avoid the overhead of cloning a histogram and then resetting it.
Thanks,
N.[/quote]
Strange question, can you, please, give more details? Why do you need to clone the “void”, if you can simply create the histogram with required dimensions?
Hi,
I can see the point but no, the only interface we offer is Clone() + Reset(). Maybe you can Clone() before filling the original histogram?
Cheers, Axel.
tpochep: Yes, I was asking if there already was a function which created an empty histogram according to the given dimensions of a given histogram. This is a pretty common operation for efficiency studies.
I ended up doing this:
TH1F* cloneDims1d(TH2F* hist)
{
if (hist == NULL) return NULL;
TH1F* cloneHist = new TH1F(Form("%s_clone", hist->GetName()),
hist->GetTitle(),
hist->GetNbinsX(),
hist->GetXaxis()->GetXbins()->GetArray());
return cloneHist;
}
But it would be quite nice if there was a build-in function that did it - especially for higher dimension hists.
N.
[quote=“Nir”]
I ended up doing this:
TH1F* cloneDims1d(TH2F* hist)
{
if (hist == NULL) return NULL;
TH1F* cloneHist = new TH1F(Form("%s_clone", hist->GetName()),
hist->GetTitle(),
hist->GetNbinsX(),
hist->GetXaxis()->GetXbins()->GetArray());
return cloneHist;
}
But it would be quite nice if there was a build-in function that did it - especially for higher dimension hists.
N.[/quote]
Hmm. What you can do, is just copy taxis. Like this:
.....
TH1F * h1 = .... //hist to copy dimensions from.
....
TH1F h2 = ...;
Now:
h1->GetXaxis()->Copy(*h2.GetXaxis());
And you’ll have both number of bins and range from h1 in h2. Is it what you want?