部門 > ROOT > TTree

「部門/ROOT/TTree」の編集履歴(バックアップ)一覧に戻る

部門/ROOT/TTree - (2011/10/31 (月) 09:19:50) のソース

[[TTreeクラス>http://root.cern.ch/root/html/TTree.html]]について調べて書く予定。以下、t1をTTreeクラスのオブジェクトとする。
*メソッドいくつか
***イベント数を表示
#highlight(c++){{t1->GetEntries();}}
***イベント内容を表示
#highlight(c++){{t1->Show(整数);}}
中の整数がイベント番号で、0から始まる。
***Treeの構造を表示
#highlight(c++){{t1.Print();}}
同じ形のTreeをつくりたいときなどに便利。

*TTreeをつくる
[[ROOT User's Guide>http://root.cern.ch/drupal/content/users-guide]]([[邦訳>http://www.dw-sapporo.co.jp/technology/root_cint_dw_documents/]])のTreesの章に載っている。いちばん最初の例はなんだか複雑なものをつくっているので(XMLでやったほうがいいんじゃないのって感じがする)、p.199の”Example 1: A Tree with Simple Variables”というのがわかりやすい。引用すると、
#highlight(c++){{void tree1w() {

//create a tree file tree1.root - create the file, the Tree and a few branches
TFile f("tree1.root","recreate");
TTree t1("t1","a simple Tree with simple variables");
Float_t px, py, pz;
Int_t ev;

t1.Branch("px",&px,"px/F");
t1.Branch("py",&py,"py/F");
t1.Branch("pz",&pz,"pz/F");
t1.Branch("ev",&ev,"ev/I");

//fill the tree
for (Int_t i=0; i<10000; i++) {
gRandom->Rannor(px,py);
pz = px*px + py*py;
ev = i;
t1.Fill();
}
//save the Tree heade; the file will be automatically closed
//when going out of the function scope
t1.Write();
}
}}


#highlight(c++){{}}
#highlight(c++){{}}
#highlight(c++){{}}



*とりあえずブクマ
-http://root.cern.ch/root/roottalk/roottalk00/3004.html