How can i open cernstaff.root file?

Hi experts!
I’m just studying root tutorials histogram “hbars.C” example.

The example asked me to open first the file cernstaff.root in tutorials/tree directory.

Then it shows below

hyungjoe@hyungjoe-MINIPC:~$ cd $ROOTSYS/tutorials/tree
hyungjoe@hyungjoe-MINIPC:~/root/tutorials/tree$ root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.22/06                        https://root.cern |
  | (c) 1995-2020, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Nov 27 2020, 15:14:08                 |
  | From tags/v6-22-06@v6-22-06                                      |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] .x cernstaff.root
Error in <TApplication::ExecuteFile>: macro cernstaff.root not found in path .:/home/hyungjoe/root/macros
root [1] TBrowser b("cernstaff.root");
root [2] Error in <TApplication::ExecuteFile>: macro cernbuild.C not found in path /home/hyungjoe/root/tutorials/tree/cernstaff.C
Error in <TFile::TFile>: file cernstaff.root does not exist
#0  0x00007f04dfa02dba in __GI___wait4 (pid=72158, stat_loc=stat_loc
entry=0x7ffd741c2888, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:27
#1  0x00007f04dfa02d7b in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
entry=0x7ffd741c2888, options=options
entry=0) at waitpid.c:38
#2  0x00007f04df9720e7 in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:172
#3  0x00007f04e0027d7e in TUnixSystem::StackTrace() () from /home/hyungjoe/root/lib/libCore.so.6.22
#4  0x00007f04dc27b890 in cling::MultiplexInterpreterCallbacks::PrintStackTrace() () from /home/hyungjoe/root/lib/libCling.so
#5  0x00007f04dc27b1d2 in cling_runtime_internal_throwIfInvalidPointer () from /home/hyungjoe/root/lib/libCling.so
#6  0x00007f04cbbcc47d in ?? ()
#7  0x00007f04000002ee in ?? ()
#8  0x00007f04df86db59 in _dlerror_run (operate=0x0, args=0x7ffd741c5490) at dlerror.c:170
#9  0x00007f04df86d53a in __dlsym (handle=<optimized out>, name=0x5562f2ce3410 "\377\377\377\377\377\377\377\377") at dlsym.c:72
#10 0x00007f04de7adc5c in llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(char const*) () from /home/hyungjoe/root/lib/libCling.so
#11 0x00007f04dc2fcf45 in llvm::orc::LambdaResolver<cling::IncrementalJIT::addModule(std::shared_ptr<llvm::Module> const&)::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)#1}, cling::IncrementalJIT::addModule(std::shared_ptr<llvm::Module> const&)::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)#2}>::findSymbolInLogicalDylib(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /home/hyungjoe/root/lib/libCling.so
#12 0x0000000000000016 in ?? ()
#13 0x0000000000000000 in ?? ()
Error in <HandleInterpreterException>: Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.
In file included from input_line_51:1:
/home/hyungjoe/root/tutorials/tree/cernstaff.C:24:4: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
   T->Draw("Nation:Division>>hN","","text");
 
___
_Please read [tips for efficient and successful posting](https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292) and [posting code](https://root-forum.cern.ch/t/posting-code-read-this-first/28293)_

In this case am i copy and paste the cernstaff.root, cernbuild.C to /home/hyungjoe/root/macros ?

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


The macros hbars.C creates the file cernstaff.root if it does not exist by executing cernbuild.C in the tree directory. You need to execute hbars.C in a folder with write access.

You miss-understand. .x is used to execute a macro, a .C file. To open a . root file you should use TFile.

Maybe I don’t understand . But I am not trying to execute hbars.C, I am trying to follow the code in hbars.C. And the first step is to open cernstaff.root, I don’t know how to open it.

As done in hbars.C

   TFile * f = TFile::Open("cernstaff.root");

But the file cernstaff.root should exist in the directory where you run root. If needed, the macro cernbuild.C creates it. It needs cernstaff.dat to create it.

I try it but nothing happening. I’m just following the example.

hyungjoe@hyungjoe-MINIPC:~/root/tutorials/tree$ ls
basic2.C           clonesA_Event.h         h1analysisTreeReader.h  ntuple1.C               tree0.C
basic.C            copytree2.C             h1chain.C               parallelcoord.C         tree1.C
basic.dat          copytree3.C             hsimpleProxy.C          parallelcoordtrans.C    tree2a.C
bill.C             copytree.C              hsimpleProxyDriver.C    printSizes.C            tree2.C
cernbuild.C        drawsparse.C            hsimpleReader.C         run_h1analysis.C        tree3.C
cernstaff.C        h1analysis.C            htest.C                 simpleAnalysis.txt      tree4.C
cernstaff.dat      h1analysis.h            hvector.C               spider.C                tree.C
cernstaff.root     h1analysisProxy.C       index.md                staff.C                 treefriend.C
circular.C         h1analysisProxyCut.C    JetEvent.cxx            tcl.C                   treegetval.C
clonesA_Event.C    h1analysisProxy.h       JetEvent.h              temperature.C           tv3.C
clonesA_Event.cxx  h1analysisTreeReader.C  jets.C                  temperature_Prague.dat  tvdemo.C
hyungjoe@hyungjoe-MINIPC:~/root/tutorials/tree$ root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.22/06                        https://root.cern |
  | (c) 1995-2020, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Nov 27 2020, 15:14:08                 |
  | From tags/v6-22-06@v6-22-06                                      |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] TFile * f = TFile::Open("cernstaff.root");
root [1] TCanvas *hbars() {
root (cont'ed, cancel with .@) [2]   TString filedir = gROOT->GetTutorialDir();
root (cont'ed, cancel with .@) [3]   filedir += TString("/tree/");
root (cont'ed, cancel with .@) [4]   TString filename = "cernstaff.root";
root (cont'ed, cancel with .@) [5]   bool fileNotFound = gSystem->AccessPathName(filename); 
root (cont'ed, cancel with .@) [6]   if (fileNotFound) {
root (cont'ed, cancel with .@) [7]      TString macroName = filedir + "cernbuild.C";
root (cont'ed, cancel with .@) [8]      if (!gInterpreter->IsLoaded(macroName)) gInterpreter->LoadMacro(macroName);
root (cont'ed, cancel with .@) [9]      gROOT->ProcessLineFast("cernbuild()");
root (cont'ed, cancel with .@) [10]   }
root (cont'ed, cancel with .@) [11]   TFile * f = TFile::Open(filename);
root (cont'ed, cancel with .@) [12]   if (!f) {
root (cont'ed, cancel with .@) [13]      Error("hbars","file cernstaff.root not found");
root (cont'ed, cancel with .@) [14]      return 0;
root (cont'ed, cancel with .@) [15]   }
root (cont'ed, cancel with .@) [16]   TTree *T = (TTree*)f->Get("T");
root (cont'ed, cancel with .@) [17]   if (!T) {
root (cont'ed, cancel with .@) [18]      Error("hbars","Tree T is not present in file %s",f->GetName() );
root (cont'ed, cancel with .@) [19]      return 0;
root (cont'ed, cancel with .@) [20]   }
root (cont'ed, cancel with .@) [21]   T->SetFillColor(45);
root (cont'ed, cancel with .@) [22]   TCanvas *c1 = new TCanvas("c1","histograms with bars",700,800);
root (cont'ed, cancel with .@) [23]   c1->SetFillColor(42);
root (cont'ed, cancel with .@) [24]   c1->Divide(1,2);
root (cont'ed, cancel with .@) [25]
root (cont'ed, cancel with .@) [25]   c1->cd(1); gPad->SetGrid(); gPad->SetLogx(); gPad->SetFrameFillColor(33);
root (cont'ed, cancel with .@) [26]   T->Draw("Nation","","hbar2");
root (cont'ed, cancel with .@) [27]
root (cont'ed, cancel with .@) [27]   c1->cd(2); gPad->SetGrid(); gPad->SetFrameFillColor(33);
root (cont'ed, cancel with .@) [28]   T->Draw("Division>>hDiv","","goff");
root (cont'ed, cancel with .@) [29]   TH1F *hDiv   = (TH1F*)gDirectory->Get("hDiv");
root (cont'ed, cancel with .@) [30]   hDiv->SetStats(0);
root (cont'ed, cancel with .@) [31]   TH1F *hDivFR = (TH1F*)hDiv->Clone("hDivFR");
root (cont'ed, cancel with .@) [32]   T->Draw("Division>>hDivFR","Nation==\"FR\"","goff");
root (cont'ed, cancel with .@) [33]   hDiv->SetBarWidth(0.45);
root (cont'ed, cancel with .@) [34]   hDiv->SetBarOffset(0.1);
root (cont'ed, cancel with .@) [35]   hDiv->SetFillColor(49);
root (cont'ed, cancel with .@) [36]   TH1 *h1 = hDiv->DrawCopy("bar2");
root (cont'ed, cancel with .@) [37]   hDivFR->SetBarWidth(0.4);
root (cont'ed, cancel with .@) [38]   hDivFR->SetBarOffset(0.55);
root (cont'ed, cancel with .@) [39]   hDivFR->SetFillColor(50);
root (cont'ed, cancel with .@) [40]   TH1 *h2 = hDivFR->DrawCopy("bar2,same");
root (cont'ed, cancel with .@) [41]
root (cont'ed, cancel with .@) [41]   TLegend *legend = new TLegend(0.55,0.65,0.76,0.82);
root (cont'ed, cancel with .@) [42]   legend->AddEntry(h1,"All nations","f");
root (cont'ed, cancel with .@) [43]   legend->AddEntry(h2,"French only","f");
root (cont'ed, cancel with .@) [44]   legend->Draw();
root (cont'ed, cancel with .@) [45]
root (cont'ed, cancel with .@) [45]   c1->cd();
root (cont'ed, cancel with .@) [46]   delete f;
root (cont'ed, cancel with .@) [47]   return c1;
root (cont'ed, cancel with .@) [48]}
root [49]

I can’t see any spectrum. Also canvas.

That’s not the right way to execute hbars.C.
do the following:

cd $ROOTSYS/tutorials/hist
cp ../tree/cernstaff.root .
root hbars.C

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