この文書の現在のバージョンと選択したバージョンの差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン 次のリビジョン 両方とも次のリビジョン | ||
ja:root:ttree [2016/06/20 05:36] kota [元treeから条件を満たすイベントの、必要なbranchだけを抽出したtreeを作る] |
ja:root:ttree [2016/06/20 05:47] kota [元treeから条件を満たすイベントの、必要なbranchだけを抽出したtreeを作る] |
||
---|---|---|---|
ライン 63: | ライン 63: | ||
を用いることで、必要なbranchだけを取り出してくることができる。 | を用いることで、必要なbranchだけを取り出してくることができる。 | ||
- | + | こんな感じで使う: | |
- | TChain* chain = new TChain("T"); | + | <code c_mac> |
+ | TChain* chain = new TChain("T");//上の話はTChainでも同じ | ||
chain->Add(....); | chain->Add(....); | ||
- | std::string branchname[] = {"brA","br2","br3",...}; | + | |
+ | std::string branchname[] = {"brA","br2","br3",...};//抜き出すbranchをリストアップ | ||
const Int_t nBranch = sizeof(branchname)/sizeof(branchname[0]); | const Int_t nBranch = sizeof(branchname)/sizeof(branchname[0]); | ||
- | chain->SetBranchStatus("*",0); | + | chain->SetBranchStatus("*",0);//一旦全てのbranchをdeactiveに |
for(Int_t iBranch = 0 ; iBranch < nBranch ; ++iBranch) | for(Int_t iBranch = 0 ; iBranch < nBranch ; ++iBranch) | ||
- | chain->SetBranchStatus(branchname[iBranch].c_str(),1); | + | chain->SetBranchStatus(branchname[iBranch].c_str(),1);//リストされたbranchだけをactiveにしていく |
- | TFile* ofile = new TFile(Form("data/CosmicNCC%d.root",RunNo),"RECREATE"); | + | TFile* ofile = new TFile("file.root","RECREATE"); |
- | TTree* newtree = chain->CopyTree("(DetectorBit&0x4)>0"); | + | TTree* newtree = chain->CopyTree("(SelectBit&0x4)>0");// とある変数"SelectBit"の0x4 Bitが立っていることを要求 |
ofile->cd(); | ofile->cd(); | ||
newtree->Write(); | newtree->Write(); | ||
ofile->Close(); | ofile->Close(); | ||
+ | </code> |