この文書の現在のバージョンと選択したバージョンの差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン 次のリビジョン 両方とも次のリビジョン | ||
ja:root:ttree [2015/04/01 07:30] kota |
ja:root:ttree [2016/06/20 05:47] kota [元treeから条件を満たすイベントの、必要なbranchだけを抽出したtreeを作る] |
||
---|---|---|---|
ライン 51: | ライン 51: | ||
TChainで結びつけられたTreeの全エントリにつけられた通し番号(entry)を引数にとり、 | TChainで結びつけられたTreeの全エントリにつけられた通し番号(entry)を引数にとり、 | ||
そのentryが含まれるTreeをCurrent Treeとし、 | そのentryが含まれるTreeをCurrent Treeとし、 | ||
- | Current Tree内でのEntry Numberを返り値とする関数。 | + | Current Tree内でのEntry Numberを返り値とする関数。\\ |
+ | Errorがあると-1~-4の値を返すので、 if( localEntry < 0 ) でError判定ができる。 | ||
+ | |||
+ | ==== 元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> |