Re: [ROOT] C++ Problem

From: Christian Holm Christensen (cholm@hehi03.nbi.dk)
Date: Mon Mar 10 2003 - 17:20:21 MET


Hi Guy, 

Guy Ron <ronguy@tauphy.tau.ac.il> wrote concerning
  [ROOT] C++ Problem [Mon, 10 Mar 2003 17:19:49 +0200] 
----------------------------------------------------------------------
> Dear Rooters,
> I'm running root on a linux machine (root version 3.05) and am trying to
> produce a simple histogram, the source code runs fine under CINT but once
> I compile it in C++ I can only access the entries in the tree but not draw
> them (neither the histogram nor directly through tree->Draw()).

You need an instance of the TApplication class (or a derived class
like TRint) - see mods below. 

> The source code I'm using is:

int main (int argc, char** argv) { 
    // Next line needed to get access to X server 
    TAppliction app("app", &argc, argv); 
    
    TH1F *hpx   = new TH1F("hpx","distribution",100,0,100);
 
    TFile* hfile = TFile::Open("bbtreefile.root");
    TTree* tree = (TTree*)hfile->Get("bbtree");
    hfile->Print();
 
    tree->Show(20);
    tree->Draw("inipp");
    cout << tree->GetEntries() << "\n";

    Event ev;
    tree->SetBranchAddress("mainE plane energy loss",&ev.zekind);

    for (Int_t i = 1; i < 10; i++) {
       cout << tree->GetEntry(nb) << "\n";
       cout << ev.zekind << "\n";
       hpx->Fill(ev.zekind);
    }
  
    hpx->Draw();

    // Next line needed for interactive manipulation of canvas, etc. 
    app.Run(); 
    hfile->Close();

    return 0;
} 
    
> Please HELP, I've been trying this for a few days now and am really
> falling behind on my work.

I think it's explained in the manual somewhere :-) 

Yours, 

 ___  |  Christian Holm Christensen 
  |_| |	 -------------------------------------------------------------
    | |	 Address: Sankt Hansgade 23, 1. th.  Phone:  (+45) 35 35 96 91
     _|	          DK-2200 Copenhagen N       Cell:   (+45) 24 61 85 91
    _|	          Denmark                    Office: (+45) 353  25 305
 ____|	 Email:   cholm@nbi.dk               Web:    www.nbi.dk/~cholm
 | |



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:10 MET