Error in Extracting Histogram from Root file

I want extract an histogram from a root file. I am using the following macro.

{ 
  TFile *f = new TFile("252.root"); 
  f->ls(); 
 TH1F * Px = (TH1F*)f->Get("Px"); 
  Px->Draw(); 
}

It is returning some error.

> error: redefinition of 'f'
TFile *f = new TFile("252.root"); 

Should I have to use the same name of the histogram here “Px” as declared in the root file.

Thank You

Some variable are define by some external include files parsed by cling. of many be you already define “f” in your rootlogon.C. Try to use an other variable name.

I tried using *myfile insted of *f. The following trace appeared.

TFile** 252.root
TFile* 252.root
KEY: TTree AMPT;1 AMPT DST Tree#0 0x00007fb68751207a in __GI___waitpid (pid=7957, stat_loc=stat_loc
entry=0x7ffe719d9b20, options=options
entry=0) at …/sysdeps/unix/sysv/linux/waitpid.c:29
1 0x00007fb68748afbb in do_system (line=) at …/sysdeps/posix/system.c:148
2 0x00007fb68808e1cd in TUnixSystem::StackTrace() () from /home/himanshu/root/lib/libCore.so
3 0x00007fb6837254c5 in cling::MultiplexInterpreterCallbacks::PrintStackTrace() () from /home/himanshu/root/lib/libCling.so
4 0x00007fb683724f88 in cling_runtime_internal_throwIfInvalidPointer () from /home/himanshu/root/lib/libCling.so
5 0x00007fb6888261de in ?? ()
6 0x00007ffe719dbf50 in ?? ()#7 0x00007fb683725a87 in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) [clone .part.253] [clone .constprop.361] () from /home/himanshu/root/lib/libCling.so
8 0x00007fb6837291bd in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /home/himanshu/root/lib/libCling.so
9 0x00007fb6837293c6 in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cling::Value*, cling::Transaction**, bool) () from /home/himanshu/root/lib/libCling.so
10 0x00007fb6837ace2e in cling::MetaProcessor::readInputFromFile(llvm::StringRef, cling::Value*, unsigned long, bool) () from /home/himanshu/root/lib/libCling.so
11 0x00007fb6836ea3da in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /home/himanshu/root/lib/libCling.so
12 0x00007fb6836dcb1d in TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) () from /home/himanshu/root/lib/libCling.so
13 0x00007fb687fb80fa in TApplication::ExecuteFile(char const*, int*, bool) () from /home/himanshu/root/lib/libCore.so
14 0x00007fb687fb9646 in TApplication::ProcessLine(char const*, bool, int*) () from /home/himanshu/root/lib/libCore.so
15 0x00007fb6883fb724 in TRint::ProcessLineNr(char const*, char const*, int*) () from /home/himanshu/root/lib/libRint.so
16 0x00007fb6883fba05 in TRint::HandleTermInput() () from /home/himanshu/root/lib/libRint.so
17 0x00007fb68808fcac in TUnixSystem::CheckDescriptors() () from /home/himanshu/root/lib/libCore.so
18 0x00007fb6880910ea in TUnixSystem::DispatchOneEvent(bool) () from /home/himanshu/root/lib/libCore.so
19 0x00007fb687f8e814 in TSystem::InnerLoop() () from /home/himanshu/root/lib/libCore.so
20 0x00007fb687f8d34f in TSystem::Run() () from /home/himanshu/root/lib/libCore.so
21 0x00007fb687fb5f4f in TApplication::Run(bool) () from /home/himanshu/root/lib/libCore.so
22 0x00007fb6883fcff7 in TRint::Run(bool) () from /home/himanshu/root/lib/libRint.so
23 0x0000000000400c1c in main ()
Error in TRint::HandleTermInput(): cling::InvalidDerefException caught: Trying to dereference null pointer or trying to call routine taking non-null arguments

Thank you

Is it possible to access this file ?

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