八千里路云和月

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

按名称寻找 TF1 

TF1 *ffitold = (TF1*)gROOT->GetListOfFunctions()->FindObject(FunName);

直接将自定义的类写入 tree

fitdata *fd = new fitdata(0, 4000);

TTree *tr = new TTree("tree","waveform fit analysis");
tr->Branch("fd", &fd, 64000, 1);

g++ 编译同时出图

1 int main(int argc, char *argv[])
2 {
3    TApplication the_app("app", &argc, argv);
4    ...
5    the_app.Run();
6    return 0;
7 }

设置字体


 

颜色和标志的编号


root 中的数据长度


 

TString 初始化

1 TString m("foobarbaz");
2 TString option="IESN";
3 TString file = dir+“/spectrum/TSpectrum.root”;    //dir是TString类型

TString Format()

1 TString filename = Form("%s.root", jobname);
2 TString workarea = Form("%s/proof", tutdir.Data());
3 cmd = Form("kill -9 %d", pid);

写一个简单的 tree

  • branch 为普通变量
1 TTree t1("t1","a simple Tree with simple variables");
2 Double_t random;
3 t1.Branch("random",&random,"random/D");
4 random = gRandom->Rndm();
5 t1.Fill();
  • branch 为固定长度数组,注意这里的 10 需要是的数字,而不是某个 const 的值
1 Float_t f[10];
2 tree->Branch("fBranch",f,"f[10]/F");
  • branch 为可变长度数组,可以设置最大长度
1 Int_t nPhot;
2 Float_t E[500];
3 TTree* nEmcPhotons = new TTree("nEmcPhotons","EMC Photons");
4 nEmcPhotons->Branch("nPhot",&nPhot,"nPhot/I");
5 nEmcPhotons->Branch("E",E,"E[nPhot]/F");

tree 的数据简写


读一个 tree

1 TTree* htx = (TTree*)fin->Get("htx");
2 
3   Int_t nevt;
4   Double_t datay[size];
5   Double_t dty[size];
6   htx->SetBranchAddress("nevt", &nevt);
7   htx->SetBranchAddress("datay", datay);
8   htx->SetBranchAddress("dty", dty);

tree Draw 方法

1 t->Draw(“data:dt”, “nevt == 0”, “L”);
2 
3 tree.Draw("sqrt(x)>>hsqrt","y>0")
4 TH1F *hsqrt = (TH1F*)gDirectory->Get("hsqrt");

TRandom 类

1 TH1D* h1 = new TH1D("h1", "", 200, 0, 200);
2 for(Int_t i = 0; i < 100000; i++){
3   h1->Fill(gRandom->Gaus(100, 10));
4   h1->Fill(200*gRandom->Rndm(1));
5 }
6 
7 h1->Draw();

TFile Close 函数

Tfile 类对象可以用 cd() 方法进入,需要用 Close() 方法关闭,如果在这之前有根据 file 里的内容做出的图像,会随着 Close() 方法而失效。 这种情况不会报错。如果 delete 了对象,并试图调用,则会报错。


 

TFit 中为拟合参数设置范围限制

1 TF1 *ffit = new TF1(FunName,langaufun,fitrange[0],fitrange[1],4);   
2 ffit->SetParameters(startvalues);   
3 ffit->SetParNames("Width","MP","Area","GSigma");   
4 
5 for (i=0; i<4; i++) {
6       ffit->SetParLimits(i, parlimitslo[i], parlimitshi[i]);   
7 }   
8 
9 his->Fit(FunName,"RB0");   // fit within specified range, use ParLimits, do not plot

TLegend 类

1 TLgend *len = new TLgend(0.7, 0.65, 0.86, 0.88);
2 len->AddEntry(h1, "24#mus", "l");
3 len->AddEntry(h2, "26#mus", "l");
4 len->AddEntry(h3, "28#mus", "l");
5 len->Draw();

TLatex 类

1 TLatex *text = new TLatex(0.2, 200, Form("#tau_{p}=\d#mus", taup));
2 text->SetTextFont(22);
3 text->SetTextSize(0.06);
4 text->Draw()

 

posted on 2022-02-11 10:49  hanX3  阅读(102)  评论(0编辑  收藏  举报