The multi Root file causing crashes

_ROOT Version:6.15/01
_Platform:CENTOS 7
Compiler: Not Provided

Hello I tried to plot histogram by reading 2 root files. However, the program crashes. I do not understand why.

Here is the following code:

  TFile* f = new TFile("totalN.root","READ");
  TFile* f1 = new TFile("totalN_2mm.root","READ");
  TTree *EverythingN;
  f->GetObject("EverythingN", EverythingN);
  f1->GetObject("EverythingN1", EverythingN);
//////////////////////////reasonID == -1 /////////////////////
  Double_t w = 800;
  Double_t h = 1000;
  Double_t hscale = 2000000.;
  Double_t hscale_10 = 10000000.;
  TCanvas * c1 = new TCanvas("c1", "c1", w, h);
  c1->SetWindowSize(w + (w - c1->GetWw()), h + (h - c1->GetWh()));
 const Int_t nbins = 100;
   Double_t xmin = 1e-5;
   Double_t xmax = 10.;
   Double_t logxmin = log10(xmin);
   Double_t logxmax = log10(xmax);
   Double_t binwidth = (logxmax-logxmin)/nbins;
   Double_t xbins[nbins+1];
   xbins[0] = xmin;
   for (Int_t i=1;i<=nbins;i++) {
      xbins[i] = xmin + TMath::Power(10,logxmin+i*binwidth);
TH1F *energy0 = new TH1F("Energy_original", "Neutron energy spectrum from orginal, reason ID==-1",nbins,xbins);
EverythingN->Draw("log10((energyK/1000.))>>Energy_original", "reasonID==-1","H*");
TH1F *energy1 = new TH1F("Energy_2mm", "Neutron energy spectrum from 2mm reduction, reason ID==-1",nbins,xbins);
EverythingN1->Draw("log10((energyK/1000.))>>Energy_2mm", "reasonID==-1","H*");

After that, I have following error message

root [0] 
Processing plotNtuple_Esep.C...
#0  0x00007f5c1cd9717c in waitpid () from /usr/lib64/
#1  0x00007f5c1cd14e52 in do_system () from /usr/lib64/
#2  0x00007f5c1de32f4d in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x10ab960) at /home/dslee/root_cern/root-6.14.04/root/core/unix/src/TUnixSystem.cxx:2119
#3  TUnixSystem::StackTrace (this=0x10ab960) at /home/dslee/root_cern/root-6.14.04/root/core/unix/src/TUnixSystem.cxx:2413
#4  0x00007f5c18a020f5 in cling::MultiplexInterpreterCallbacks::PrintStackTrace() () from /home/dslee/root_cern/root-6.14.04/root-build/lib/
#5  0x00007f5c18a01afb in cling_runtime_internal_throwIfInvalidPointer () from /home/dslee/root_cern/root-6.14.04/root-build/lib/
#6  0x00007f5c1e542985 in ?? ()
#7  0x00007ffc8dabf160 in ?? ()
#8  0x00007f5c1dd81080 in TArrayF::Set (this=0x7ffc8dabf180, this
entry=0x31deef0, n=17978224) at /home/dslee/root_cern/root-6.14.04/root/core/cont/src/TArrayF.cxx:115
#9  0x00007f5c0dbe681c in TH1F::TH1F (this=0x31deb20, name=<optimized out>, title=<optimized out>, nbins=<optimized out>, xbins=<optimized out>) at /home/dslee/root_cern/root-6.14.04/root/hist/hist/src/TH1.cxx:9381
#10 0x0000000001c20ce0 in ?? ()
#11 0x0000000000000000 in ?? ()
terminate called after throwing an instance of 'cling::InvalidDerefException'
  what():  Trying to dereference null pointer or trying to call routine taking non-null arguments

Could someone help me with this?

Thank you

  TTree *EverythingN, *EverythingN1;
  f->GetObject("EverythingN", EverythingN);
  f1->GetObject("EverythingN", EverythingN1);

Thank you so much I searched for class reference in GetObject but could not find.

Thank you

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