Discussion:
persistence of a histogram across macros
Adrian Sevcenco
2014-10-17 09:29:46 UTC
Permalink
Hi! I try to do the following:
read some histograms from some root files in a macro
and then in the main macro that plot the histograms in various way
to access them ...

something like (logical structure):

setup_histos.C
void setup_histos()
{
//get histos from files
histo1 Get from file

}

analysis.C

void analysis ()
{
LoadMacro setup_histos.C
setup_histos();

histo{1..n}->Draw();
}

the thing is that even if the pointers are available
the pointed info is not .. how can access the histograms
that were setup in the first macro?

Thanks a lot!
Adrian
Redmer Alexander Bertens
2014-10-17 09:33:44 UTC
Permalink
hi adrian,
if i'm not mistaken the file in which the histograms are stored also
owns the stored histograms by default. so as soon as the file closes
(goes out of scope) you'll lose the histograms event though you'll still
have the pointers.
what you could do is in the first macro clone the histograms (via
TObject::Clone) and let your pointers point to the cloned histo's.
hope it helps,
redmer
Post by Adrian Sevcenco
read some histograms from some root files in a macro
and then in the main macro that plot the histograms in various way
to access them ...
setup_histos.C
void setup_histos()
{
//get histos from files
histo1 Get from file
}
analysis.C
void analysis ()
{
LoadMacro setup_histos.C
setup_histos();
histo{1..n}->Draw();
}
the thing is that even if the pointers are available
the pointed info is not .. how can access the histograms
that were setup in the first macro?
Thanks a lot!
Adrian
Jochen Kerdels
2014-10-17 09:53:01 UTC
Permalink
Hi,

if Redmer is correct, you could also use hist->SetDirectory(0); to remove the connection between the histogram and the file (instead of cloning).

Cheers,
Jochen
Post by Redmer Alexander Bertens
hi adrian,
if i'm not mistaken the file in which the histograms are stored also owns the stored histograms by default. so as soon as the file closes (goes out of scope) you'll lose the histograms event though you'll still have the pointers.
what you could do is in the first macro clone the histograms (via TObject::Clone) and let your pointers point to the cloned histo's.
hope it helps,
redmer
Post by Adrian Sevcenco
read some histograms from some root files in a macro
and then in the main macro that plot the histograms in various way
to access them ...
setup_histos.C
void setup_histos()
{
//get histos from files
histo1 Get from file
}
analysis.C
void analysis ()
{
LoadMacro setup_histos.C
setup_histos();
histo{1..n}->Draw();
}
the thing is that even if the pointers are available
the pointed info is not .. how can access the histograms
that were setup in the first macro?
Thanks a lot!
Adrian
--
Jochen Kerdels

Tel.: +49 2331 987-4187

Lehrgebiet Mensch-Computer-Interaktion
Prof. Dr. Gabriele Peters

FernUniversität in Hagen
Fakultät für Mathematik und Informatik
Lehrgebiet Mensch-Computer-Interaktion
Universitätsstr. 1
D-58097 Hagen
Germany
Loading...