LoadTree 如何在 root 中工作?

How does LoadTree work in root?

我写了以下代码来读取一些树(这只是骨架,正在开发中):

~~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 但我完全不确定哪个 class 以及如何做到这一点...

我只是想要一种循环遍历所有事件并创建历史记录的方法!

而不是

Long64_t ientry = LoadTree(i);

使用

Long64_t ientry = compchain->LoadTree(i);

Long64_t ientry = chchain->LoadTree(i);

(这取决于您的哪个对象 - compchainchchain - 你想使用 LoadTree() 方法 - 我猜是 compchain。)