lasagna lasagna - 18 days ago 6
C++ Question

How does LoadTree work in root?

I have written the following code to read in some trees (this is just the bare bones, it is under development):

~~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();

}


And I am getting the following error message:
readtest.C:51:20: error: use of undeclared identifier 'LoadTree'
Long64_t ientry = LoadTree(i);

From googling I have come to understand that I need to have:
some_class::LoadTree but I am not at all sure which class and how to do this...

I just want a way to loop over all events, and make my histos!

please please help!
-lasagna

Answer

Instead of

Long64_t ientry = LoadTree(i);

use

Long64_t ientry = compchain->LoadTree(i);

or

Long64_t ientry = chchain->LoadTree(i);

(it depends for which of your objects - compchain or chchain - you want use LoadTree() method - I guess that for compchain.)

Comments