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

以前のリビジョンの文書です



Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/inc/parser/handler.php on line 1458

Warning: Declaration of syntax_plugin_note::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/lib/plugins/note/syntax.php on line 79

Warning: Declaration of syntax_plugin_note::render($mode, &$renderer, $indata) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/lib/plugins/note/syntax.php on line 101

Warning: preg_match(): Compilation failed: invalid range in character class at offset 3120 in /mnt/hep_web/hep_web/member/n-kota/dokuwiki/inc/parser/lexer.php on line 118
A PCRE internal error occured. This might be caused by a faulty plugin

====== TTree ====== ---- ==== 読み込むBranchを限定する ==== === 方法1 --- SetBranchStatus === デフォルトではGetEntryすると、SetBranchAddressで指定されていないBranchまでも読みにいく(らしい)。 treeに多数のBranchが入っていて、その一部だけを使う場合、これは非常に無駄になる。 Branchを読み込む・読み込まないを指定するメソッドが、SetBranchStatus である。 <code c_mac> tree->SetBranchStatus("*",0); //まず全体を読み込まない様に指定 tree->SetBranchStatus("Detector.nHit",1); //次いで、使用するものを順次読み込む設定に変えていく tree->SetBranchStatus("Detector.hits.*",1);//クラス化されているものはワイルドカードで指定したりもできる </code> このとき、先に0番目のEntryをGetEntryしてやらなければならないらしい。http://root.cern.ch/root/roottalk/roottalk03/4900.html 理由は不明。 具体的には以下のようにする。 <code c_mac> tree->SetBranchAddress("hoge",&hoge); tree->SetBranchAddress("hogehoge.",&hogehoge); ・ ・ ・ tree->GetEntry(0); tree->SetBranchStatus("*",0); tree->SetBranchStatus("Detector.nHit",1); tree->SetBranchStatus("Detector.hits.*",1); ・ ・ ・ 以下 event loop </code> === 方法2 --- TBranch::GetEntry=== TBranch のGetEntryを用いることで、Branch毎に読み込むことができる。\\ ただし、TChainを用いている時、気をつけなければならないことが1つ。\\ TBranch::GetEntryは、引数として”当該イベントが含まれているTree内でのEntry Number”を取らなくてはならない。\\ 具体的には次のようにする。 <code c> TChain *chain = ...; Long64_t localEntry = chain->LoadTree(entry); branch->GetEntry(localEntry); </code> Long64_t TChain::LoadTree(Long64_t entry)は TChainで結びつけられたTreeの全エントリにつけられた通し番号(entry)を引数にとり、 そのentryが含まれるTreeをCurrent Treeとし、 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だけを取り出してくることができる。 TChain* chain = new TChain("T"); chain->Add(....); std::string branchname[] = {"brA","br2","br3",...}; const Int_t nBranch = sizeof(branchname)/sizeof(branchname[0]); chain->SetBranchStatus("*",0); for(Int_t iBranch = 0 ; iBranch < nBranch ; ++iBranch) chain->SetBranchStatus(branchname[iBranch].c_str(),1); TFile* ofile = new TFile(Form("data/CosmicNCC%d.root",RunNo),"RECREATE"); TTree* newtree = chain->CopyTree("(DetectorBit&0x4)>0"); ofile->cd(); newtree->Write(); ofile->Close();

ja/root/ttree.1466400987.txt.gz · 最終更新: 2016/06/20 05:36 by kota