我正在读取一个结构如下的根文件:
$ 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
为了阅读这个我写了一个宏:
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")
这段代码工作正常。但它只适用于像Pos*的分支。但如果我更换
h1x=f1.Get("Pos_g1xcl_100");
和
h1x=f1.Get("residual_g1xcl_100");
然后我得到分段错误[1]。Pos_g1xcl_100 和residual_g1xcl_100 之间的区别在于一个是简单的直方图,而后一个是直方图及其拟合。
[1]
TClass::TClass:0: RuntimeWarning: TF1Parameters 类没有可用的字典 TStreamerInfo::BuildOld:0: RuntimeWarning: 无法将 TF1::fParErrors 从 type:vector 转换为 type:Double_t*,跳过元素 TStreamerInfo::BuildOld:0: RuntimeWarning:无法将 TF1::fParMin 从 type:vector 转换为 type:Double_t*,跳过元素 TStreamerInfo::BuildOld:0:RuntimeWarning:无法将 TF1::fParMax 从 type:vector 转换为 type:Double_t*,跳过元素 TStreamerInfo:: BuildOld:0: RuntimeWarning: 无法将 TF1::fSave 从 type:vector 转换为 type:Double_t*,跳过元素 TStreamerInfo::BuildOld:0: RuntimeWarning: Cannot convert TF1::fParams from type:TF1Parameters* to type:Double_t*,跳过元素
* 打破 *分割违规