我已经编写了以下代码来阅读一些树(这只是简单的骨头,它正在开发中):
~~included headers here
using namespace std;
void reconstruction::readtest(){
TFile *file = TFile::Open("file.root");
TTree* comp_tree = (TTree*)file->Get("_compress_tree");
TTree* compch_tree = (TTree*)file->Get("_compress_ch");
TChain* compchain = new TChain("_compress_tree");
compchain->Add("file.root");
TChain* chchain = new TChain("_compress_ch");
chchain->Add("file.root");
TH2D *hist = new TH2D("hist","hist",100,0,0.05,100,0,60);
Double_t _compression, _compressionU, _compressionV, _compressionY, _ch_compression;
Int_t _ch;
comp_tree->SetBranchAddress("_compression",&_compression);
comp_tree->SetBranchAddress("_compressionU",&_compressionU);
comp_tree->SetBranchAddress("_compressionV",&_compressionV);
comp_tree->SetBranchAddress("_compressionY",&_compressionY);
compch_tree->SetBranchAddress("_ch_compression",&_ch_compression);
compch_tree->SetBranchAddress("_ch",&_ch);
TH1D *comp = new TH1D("comp","_compression",100,0,0.05);
TH1D *comp_ch = new TH1D("comp_ch","channel compression",100,0,0.02);
Long64_t nentries = compchain->GetEntries();
for (int i=0; i<2 ; i++) {
Long64_t ientry = LoadTree(i);
if (ientry <0 ) break;
compchain->GetEntry(i);
cout << "compression = " << _compression << endl;
cout << "compression_ch = " << _ch_compression << endl;
comp->Fill(_compression);
comp_ch->Fill(_ch_compression);
}
cout << "entries = " << nentries << endl;
TCanvas *cans = new TCanvas("cans","xxx",800,400);
cans->Divide(2,1);
cans->cd(1);
comp_ch->Draw();
cans->cd(2);
comp->Draw();
}
我收到以下错误消息:
readtest.C:51:20: error: use of undeclared identifier 'LoadTree'
Long64_t ientry = LoadTree(i);
从谷歌搜索我已经明白我需要:
some_class::LoadTree
但我完全不确定哪个班级以及如何做到这一点......
我只是想要一种循环遍历所有事件的方法,并制作我的histos!
答案 0 :(得分:1)
而不是
Long64_t ientry = LoadTree(i);
使用
Long64_t ientry = compchain->LoadTree(i);
或
Long64_t ientry = chchain->LoadTree(i);
(取决于你的哪个对象 - compchain
或chchain
- 你想要使用LoadTree()方法 - 我想这是compchain
。)