0

I am reading a root file whose structure looks like:

$ root -l Residual_Position_iter_99_R1869.root
.lroot [0] 
Attaching file Residual_Position_iter_99_R1869.root as _file0...
s
Warning in <TClass::TClass>: no dictionary for class TF1Parameters is available
root [1] .ls
TFile**     Residual_Position_iter_99_R1869.root    
 TFile*     Residual_Position_iter_99_R1869.root    
  KEY: TH1F Pos_g3xcl_100;1 
  KEY: TH1F Pos_g3ycl_100;1 
  KEY: TH1F Pos_g2xcl_100;1 
  KEY: TH1F Pos_g2ycl_100;1 
  KEY: TH1F Pos_g1xcl_100;1 
  KEY: TH1F residual_g1xcl_100;1    
  KEY: TH1F residual_g1ycl_100;1    
  KEY: TH1F residual_g2xcl_100;1    
  KEY: TH1F residual_g2ycl_100;1    
  KEY: TH1F residual_g3xcl_100;1    
  KEY: TH1F residual_g3ycl_100;1    

To read this I wrote a macro :

import ROOT
from ROOT import TFile, TH1F, TObject


ROOT.gROOT.SetBatch(True)  # This will prevent histogram to show

c=ROOT.TCanvas("c","c",800,600)

f1=ROOT.TFile("Residual_Position_iter_99_R1869.root","READ")
h1x=f1.Get("Pos_g1xcl_100");       c.cd();        h1x.Draw()
c.Print("plots/residual.pdf")

This code is working fine. But its fine only for branches of like Pos*. But if I replace

h1x=f1.Get("Pos_g1xcl_100"); 

with

h1x=f1.Get("residual_g1xcl_100"); 

then I am getting the segmentation fault[1]. The difference between Pos_g1xcl_100 & residual_g1xcl_100 is that one is simple histogram while later one is histogram along with its fit.

[1]

TClass::TClass:0: RuntimeWarning: no dictionary for class TF1Parameters is available TStreamerInfo::BuildOld:0: RuntimeWarning: Cannot convert TF1::fParErrors from type:vector to type:Double_t*, skip element TStreamerInfo::BuildOld:0: RuntimeWarning: Cannot convert TF1::fParMin from type:vector to type:Double_t*, skip element TStreamerInfo::BuildOld:0: RuntimeWarning: Cannot convert TF1::fParMax from type:vector to type:Double_t*, skip element TStreamerInfo::BuildOld:0: RuntimeWarning: Cannot convert TF1::fSave from type:vector to type:Double_t*, skip element TStreamerInfo::BuildOld:0: RuntimeWarning: Cannot convert TF1::fParams from type:TF1Parameters* to type:Double_t*, skip element

* Break * segmentation violation

ramkrishna
  • 632
  • 1
  • 7
  • 24
  • can you try adding `from ROOT import TF1` and maybe `from ROOT import TF1Parameters`? – pseyfert Aug 21 '16 at 01:07
  • No, by adding TF1 it did not work, same error. I also tried to add TF1Parameters but then it was giving us import error. – ramkrishna Aug 22 '16 at 09:04
  • 1
    reading histograms with fit function with your macro works for me. importing TF1Parameters doesn't result in an import error for me. do you use the same root version for opening the file as was used for creating them? (which version(s) are you using?) – pseyfert Aug 22 '16 at 09:52
  • In my laptop, it worked that has root 6.06.06. Yes, I think you are right its because of a different version of roots. – ramkrishna Aug 22 '16 at 16:23
  • But, If I work on Lxplus (i don't know if you know about this, this is cern cluster), there I am getting the above error with root 5.34. And with root 6 on lxplus I am getting error: Traceback (most recent call last): File "Plot_TrackerAlign_Lin.py", line 3, in import ROOT File "/afs/cern.ch/sw/lcg/app/releases/ROOT/6.06.06/x86_64-slc6-gcc49-opt/root/lib/ROOT.py", line 24, in import cppyy File "/afs/cern.ch/sw/lcg/app/releases/ROOT/6.06.06/x86_64-slc6-gcc49-opt/root/lib/cppyy.py", line 60, in import libPyROOT as _backend ImportError: lib.... – ramkrishna Aug 22 '16 at 16:26
  • 1
    almost sounds to me like a bug except, root 6.06.06 on lxplus seems to work for me with `/afs/cern.ch/user/p/pseyfert/public/test.root` (and root 5.34.36 only warns about being unable to convert the fit function, and then doesn't draw it, but no segfault). My `$PYTHONPATH` is `/afs/cern.ch/sw/lcg/app/releases/ROOT/6.06.06/x86_64-slc6-gcc49-opt/root/lib:/afs/cern.ch/lhcb/software/releases/LBSCRIPTS/LBSCRIPTS_v8r6p7/InstallArea/python` do you have anything more/less which may cause problems (especially in the beginning; the experiment specific end part hopefully doesn't matter). – pseyfert Aug 23 '16 at 05:58
  • I think the problem is related to the gcc & root versions. Now, I tried it after setting CMSSW environment of 8X, then it worked. Thank you pseyfert. – ramkrishna Aug 23 '16 at 10:01

0 Answers0