Deprecated: Array and string offset access syntax with curly braces is deprecated in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/inc/init.php on line 542
ja:root:ttree [GiriWiki]

ユーザ用ツール

サイト用ツール


ja:root:ttree

差分

この文書の現在のバージョンと選択したバージョンの差分を表示します。

この比較画面にリンクする

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
ja:root:ttree [2016/06/20 05:24]
kota [読み込むBranchを限定する]
ja:root:ttree [2017/08/19 09:27] (現在)
kota [読み込むBranchを限定する]
ライン 6: ライン 6:
  
 === 方法1 --- SetBranchStatus ​ === === 方法1 --- SetBranchStatus ​ ===
-デフォルトではGetEntryすると、SetBranchAddressで指定されていないBranchまでも読みにいく(らし。 +デフォルトではGetEntryすると、SetBranchAddressで指定されていないBranchまでも読みにいく。\\ 
-treeに多数のBranchが入っていて、その一部だけを使う場合、これは非常に無駄になる+うかすべてのbranchのデータをメモリに乗せるが、SetBranchAddressすると 
 +そのbranchに対応するメモリのポインタが指定した変数に割り当てられる 
 + 
 +treeに多数のBranchが入っていて、その一部だけを使う場合、毎回全branchをメモリ乗せるのは無駄。
 Branchを読み込む・読み込まないを指定するメソッドが、SetBranchStatus である。 Branchを読み込む・読み込まないを指定するメソッドが、SetBranchStatus である。
  
ライン 16: ライン 19:
 </​code>​ </​code>​
  
-このとき、先に0番目のEntryをGetEntryしてやらなければならないらしい。http://​root.cern.ch/​root/​roottalk/​roottalk03/​4900.html+このとき、先にGetEntryを呼んでやらなくてはならないらしい。http://​root.cern.ch/​root/​roottalk/​roottalk03/​4900.html 
 +(GetEntryの前にSetBranchAddressを呼んでやっておく必要があるっぽい)
  
-理由は不明+理由はあまりよくわからない
 具体的には以下のようにする。 具体的には以下のようにする。
 <code c_mac> <code c_mac>
ライン 56: ライン 60:
 ==== 元treeから条件を満たすイベントの、必要なbranchだけを抽出したtreeを作る ==== ==== 元treeから条件を満たすイベントの、必要なbranchだけを抽出したtreeを作る ====
  
 +
 +  TTree* TTree::​CopyTree(const char *selection, Option_t *option="",​ Long64_t nentries=kMaxEntries,​ Long64_t firstentry=0)
 +を用いる。
 +さらに
 +  void TTree::​SetBranchStatus (const char *bname, Bool_t status=1, UInt_t *found=0)
 +を用いることで、必要なbranchだけを取り出してくることができる。
 +
 +こんな感じで使う:
 +<code c_mac>
 +  TChain* chain = new TChain("​T"​);//​上の話はTChainでも同じ
 +  chain->​Add(....);​
 +  ​
 +  std::string branchname[] = {"​brA","​br2","​br3",​...};//​抜き出すbranchをリストアップ
 +  const Int_t nBranch = sizeof(branchname)/​sizeof(branchname[0]);​
 +  chain->​SetBranchStatus("​*",​0);//​一旦全てのbranchをdeactiveに
 +  for(Int_t iBranch = 0 ; iBranch < nBranch ; ++iBranch)
 +    chain->​SetBranchStatus(branchname[iBranch].c_str(),​1);//​リストされたbranchだけをactiveにしていく
 +
 +  TFile* ofile = new TFile("​file.root","​RECREATE"​);​
 +  TTree* newtree = chain->​CopyTree("​(SelectBit&​0x4)>​0"​);//​ とある変数"​SelectBit"​の0x4 Bitが立っていることを要求
 +
 +  ofile->​cd();​
 +  newtree->​Write();​
 +  ofile->​Close();​
 +</​code>​
ja/root/ttree.1466400284.txt.gz · 最終更新: 2016/06/20 05:24 by kota