粒子物理与核物理实验中的数据分析杨振伟第五讲:ROOT在数据分析中的应用(3)
粒子物理与核物理实验中的 数据分析 杨振伟 第五讲:ROOT在数据分 析中的应用(3)
上讲摘要ROOT的TTree类TTree *tree = new TTree("tree""mytree");tree->Branch("br1",&br1,"Br1/F");填充tree,将tree写入root文件tree->Fill;TFile *f = new TFile("fl.root","recreate") ;tree->WriteO;查看root文件中tree的信息TFile *f = new TFile("fl.root") ;f->1s(0 :TTree *tree = (TTree*)f->Get("tree") ;tree->ScanO,tree->Show(i),tree->PrintO处理tree格式相同的多个文件root文件:TChainTChain *chain = new TChainO;chain->Add("fl.root/tree") ;
上讲摘要 ◼ ROOT的TTree类 TTree *tree = new TTree(“tree”,”mytree”); tree->Branch(“br1”,&br1,”Br1/F”); ◼ 填充tree,将tree写入root文件 tree->Fill(); TFile *f = new TFile(“f1.root” , ”recreate”); tree->Write(); ◼ 查看root文件中tree的信息 TFile *f = new TFile(“f1.root”); f->ls(); TTree *tree = (TTree*)f->Get(“tree”); tree->Scan(),tree->Show(i),tree->Print() ◼ 处理tree格式相同的多个文件root文件: TChain TChain *chain = new TChain(); chain->Add(“f1.root/tree”);
本讲要点直方图的运算Add, Divide, ...ROOT中直方图拟合hl->Fit(;ROOT小结
本讲要点 ◼ 直方图的运算 Add,Divide,. ◼ ROOT中直方图拟合 h1->Fit(); ◼ ROOT小结
一维直方图之间的操作(1)图形归一化常用于比较两种分布,找root>Float t norm=1000:出区别。root>h1->Scale(norm/hl->IntegralO)Scale后BinContent之和root>h2->Scale(norm/h2->IntegralO)为normroot>hl->DrawO; h2->Draw(same")相加常用于相同实验的数据叠root>TH1F *h3=new TH1F(*hl);加,增加统计量root>h3->Add(h1,h2,a,b);a*h1+b*h2,一般a=b=1相减常用于从实验测量的分布root>TH1F *h3=new TH1F(*h1);中,扣除本底得到纯信号root>h3->Sumw20:的分布。root>h3->Add(h1,h2,a,-b):a*h1-b*h2,一般a=-b=1误差: =o+=n +n
一维直方图之间的操作(1) 相加 root>TH1F *h3=new TH1F(*h1); root>h3->Add(h1,h2,a,b); 常用于相同实验的数据叠 加,增加统计量。 a*h1+b*h2, 一般a=b=1 相减 root>TH1F *h3=new TH1F(*h1); root>h3->Sumw2(); root>h3->Add(h1,h2,a,-b); 常用于从实验测量的分布 中,扣除本底得到纯信号 的分布。 a*h1-b*h2, 一般a=-b=1 2 2 1 2 1 2 误差: = + = + n n 图形归一化 root>Float_t norm=1000; root>h1->Scale(norm/h1->Integral()); root>h2->Scale(norm/h2->Integral()); root>h1->Draw(); h2->Draw(“same”) ; 常用于比较两种分布,找 出区别。 Scale后BinContent之和 为norm
(2)一维直方图之间的运算相除常用于效率的计算。root>TH1F *h3=new TH1F(*hl);root>h3->Sumw20;na=root>h3->Divide(h1,h2,a,b):n2nn2nWroot>h3->Divide(hl,h2,a,b,“B"):n2n0=n2相乘常用于对分布进行诸root>TH1F *h3=new TH1F(*h1):如效率等的修正。root>h3->Sumw20:root>h3->Multiply(h1,h2,a,b);:=nn2nn
一维直方图之间的运算(2) 相除 root>TH1F *h3=new TH1F(*h1); root>h3->Sumw2(); root>h3->Divide(h1,h2,a,b); root>h3->Divide(h1,h2,a,b,“B”); 常用于效率的计算。 1 1 2 2 2 (1 ) n n n n n − = 相乘 root>TH1F *h3=new TH1F(*h1); root>h3->Sumw2(); root>h3->Multiply(h1,h2,a,b); 常用于对分布进行诸 如效率等的修正。 1 2 1 2 1 1 n n n n = + 1 2 1 2 n 1 1 n n n = +