How to extract TH3F data

Hi everyone!

I’m new here and I need to extract data from a TH3F histogram that shows the deposited energy in a particular geometry. I get the output from a dose simulation in GATE 7 and I use the hadd command to compress all histograms into one but I want to analyse the behavior of the deposited energy (Edep) in x,y,z directions separately.

I tried the MakeClass but I believe it only works for TTrees and NTuples and also saw the TProfile method but I’m not quite sure how to use it… Is there a way to read the ROOT file, extract the data and store it in arrays using PyROOT?

Once you have attached your file with TFile:

TFile *f = new TFile("file.root")

you can then get the TH3F with:

TH3F *h = (TH3F*)f->Get("myth3"");

Then you can use on h all the getters described in the reference guide:
https://root.cern/doc/master/classTH1.html

Hi couet,

Thank you for the answer! however ROOT is returning Null and I can’t use the getters on h for that matter.

root [0] TFile *f = new TFile("resultwaterboneEdep.root")
(TFile *) 0x28260d0
root [1] TH3F *h = (TH3F*)f -> Get("myth3")
(TH3F *) nullptr

And here is the error:

#0  0x00007fcac90544ca in __GI___waitpid (pid=20903, stat_loc=stat_loc
entry=0x7ffcff847ec0, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
#1  0x00007fcac8fcdfbb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2  0x00007fcac9bbe064 in TUnixSystem::StackTrace() () from /home/bianca/Documentos/root/lib/libCore.so
#3  0x00007fcac599c235 in cling::MultiplexInterpreterCallbacks::PrintStackTrace() () from /home/bianca/Documentos/root/lib/libCling.so
#4  0x00007fcac599bbd8 in cling_runtime_internal_throwIfInvalidPointer () from /home/bianca/Documentos/root/lib/libCling.so
#5  0x00007fcaaea3106d in ?? ()
#6  0x00007fcaaea31000 in ?? ()
#7  0x00000000040173e0 in ?? ()
#8  0x0000000000000016 in ?? ()
#9  0x00007fcac900c98c in __GI___libc_free (mem=<optimized out>) at malloc.c:2966
#10 0x00007fcac599d7cf in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) () from /home/bianca/Documentos/root/lib/libCling.so
#11 0x00007fcac599f22d in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /home/bianca/Documentos/root/lib/libCling.so
#12 0x00007fcac599f4e0 in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**) () from /home/bianca/Documentos/root/lib/libCling.so
#13 0x00007fcac5a2871e in cling::MetaProcessor::process(char const*, cling::Interpreter::CompilationResult&, cling::Value*) () from /home/bianca/Documentos/root/lib/libCling.so
#14 0x00007fcac592f486 in HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) () from /home/bianca/Documentos/root/lib/libCling.so
#15 0x00007fcac594046a in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /home/bianca/Documentos/root/lib/libCling.so
#16 0x00007fcac9af13d6 in TApplication::ProcessLine(char const*, bool, int*) () from /home/bianca/Documentos/root/lib/libCore.so
#17 0x00007fcac9f285ee in TRint::ProcessLineNr(char const*, char const*, int*) () from /home/bianca/Documentos/root/lib/libRint.so
#18 0x00007fcac9f28975 in TRint::HandleTermInput() () from /home/bianca/Documentos/root/lib/libRint.so
#19 0x00007fcac9bbfbbc in TUnixSystem::CheckDescriptors() () from /home/bianca/Documentos/root/lib/libCore.so
#20 0x00007fcac9bc0ffa in TUnixSystem::DispatchOneEvent(bool) () from /home/bianca/Documentos/root/lib/libCore.so
#21 0x00007fcac9ac71c4 in TSystem::InnerLoop() () from /home/bianca/Documentos/root/lib/libCore.so
#22 0x00007fcac9ac5cff in TSystem::Run() () from /home/bianca/Documentos/root/lib/libCore.so
#23 0x00007fcac9aee90f in TApplication::Run(bool) () from /home/bianca/Documentos/root/lib/libCore.so
#24 0x00007fcac9f2a057 in TRint::Run(bool) () from /home/bianca/Documentos/root/lib/libRint.so
#25 0x00000000004010dc in main ()
Error in <HandleInterpreterException>: Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.
ROOT_prompt_4:1:1: warning: null passed to a callee that requires a non-null argument [-Wnonnull]

Using f -> Map() I get:

root [5] f->Map()
20170515/165147  At:100  N=144       TFile         
20170515/165147  At:244  N=284132    TH3F           CX = 10.96
20170515/165147  At:284376  N=136       KeysList      
20170515/165147  At:284512  N=3281      StreamerInfo   CX =  3.18
20170515/165147  At:287793  N=68        FreeSegments  
20170515/165147  At:287861  N=1         END

So obviously there is a TH3F histogram… :confused:

Try to execute: f->ls()

Sure, there it is…

root [1] f->ls()
TFile**		resultwaterboneEdep.root	
 TFile*		resultwaterboneEdep.root	
  KEY: TH3F	histo;1	3D distribution actorwater-Edep.root
TH3F *h; f->GetObject("histo", h);
if (!h) std::cout << "Requested object was NOT found!" << std::endl;

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.