2016-11-15 7 views
2

나는 (이 개발되고,이 그냥 맨손으로 뼈입니다) 어떤 나무에서 읽을 수있는 다음과 같은 코드를 작성했습니다 :LoadTree는 루트에서 어떻게 작동합니까?

~~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하지만 어떤 클래스인지 그리고 어떻게해야하는지 모르겠습니다 ...

나는 모든 이벤트를 반복하는 방법을 원합니다. 내 히스 토스를 만들어라!

답변

1

대신

Long64_t ientry = LoadTree(i); 

사용

Long64_t ientry = compchain->LoadTree(i); 

또는

Long64_t ientry = chchain->LoadTree(i); 

(가 따라 달라집니다 오브젝트하는 - compchain 또는 chchain - 당신이 LoadTree() 메서드를 사용합니다 - 나는 compchain에 대한 것 같아요.)

+0

작품, 고맙습니다 !!! – lasagna

+0

또 다른 문제가 있습니다 ... 코드가 실행되고 있지만 실제로 항목을 얻지 못했습니다 ... 대신 읽기가 동일한 작은 번호를 보여줍니다 * 10^-321 ... 그래서 어떤 이유로 항목이 없습니다 실제로로드됩니다. 나는 무엇을해야합니까? – lasagna