Re: [ROOT] Problem with Tree.Draw

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon May 21 2001 - 15:03:33 MEST


Hi Christian,

Thanks for sending this example. I have now fixed the problem.
It was a side-effect of another change introduced in 3.01
The fix is in CVS.

Rene Brun

cstrato@EUnet.at wrote:
> 
> Dear Rene
> 
> Thank you for your help. Since I am loading the macro first, the macro
> call mechanism may not be the reason for the problem.
> Therefore, I am sending you a demo code which also shows this behavior.
> I apologize that the code is pretty long because I am creating a library
> first.
> 
> The steps are the following:
> 1, load macro
> 2, initialize library
> 3, fill tree
> 4, draw tree
> 
> This is the output from root:
> root [0] .L macro4Test.C
> root [1] Init()
> root [2] FillTree("/opt/rootdata/test.txt")
> TestClass::TestClass
> New file [test.root] is created
> TestClass::FFillTree
> ~TestClass::TestClass
> root [3] DrawTree("/opt/rootcode/test.root","fX")
> <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
> root [4] DrawTree("/opt/rootcode/test.root","log10(fX)")
> Error: No symbol fX in current scope  FILE:macro4Test.C LINE:42
> *** Interpreter error recovered ***
> Error: class,struct,union or type (unknown) not defined  FILE:macro4Test.C
> LINE:42
> Error: No symbol fX in current scope  FILE:macro4Test.C LINE:42
> *** Interpreter error recovered ***
> Error: class,struct,union or type (unknown) not defined  FILE:macro4Test.C
> LINE:42
> Error: No symbol fX in current scope  FILE:macro4Test.C LINE:42
> *** Interpreter error recovered ***
> Error: class,struct,union or type (unknown) not defined  FILE:macro4Test.C
> LINE:42
> ....
> etc
> ....
> 
> All necessary files are listed below, and the file "test.txt", which
> contains
> hundred lines with x and y values, is attached.
> 
> Thank you in advance for your help.
> 
> Best regards
> Christian
> ----------------------------------
> C.h.r.i.s.t.i.a.n  S.t.r.a.t.o.w.a
> V.i.e.n.n.a,  A.u.s.t.r.i.a
> 
> //==================================================================
> // macro4Test.C
> //==================================================================
> #ifndef __CINT__
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <iostream.h>
> #include <iomanip.h>
> #include <math.h>
> 
> #include "TFile.h"
> #include "TTree.h"
> #include "TBranch.h"
> #include "Test.h"
> 
> #endif
> 
> //----------------------------------------------------------------------//
> void Init()
> {
>    gSystem->Load("/opt/rootcode/Test.so");
> }//Init
> 
> //----------------------------------------------------------------------//
> void FillTree(const char *vData)
> {
> 
>    TestClass *vTestClass = new TestClass("TestClass","class
> title","test.root");
> 
>    vTestClass->FFillTree(vData);
> 
>    delete vTestClass;
> }//FillTree
> 
> //----------------------------------------------------------------------//
> void DrawTree(const char *vRootFile,const char *varexp)
> {
>    TFile *fFile = new TFile(vRootFile,"READ");
> 
>    TTree *vTree = (TTree*)fFile->Get("vTree");
>    TTest *vTest = 0;
>    vTree->SetBranchAddress("vBranch",&vTest);
> 
>    vTree->Draw(varexp);
> }//DrawTree
> 
> ///////////////////////////
> // To run it in root:
> //     > .L macro4Test.C
> //     > Init()            //only once per root session
> //     > FillTree("/opt/rootdata/test.txt")
> //     > DrawTree("/opt/rootcode/test.root","fX")
> //     > DrawTree("/opt/rootcode/test.root","log10(fX)")
> //     > DrawTree("/opt/rootcode/test.root","fX:fY")
> //     > DrawTree("/opt/rootcode/test.root","sqrt(fX):sqrt(fY)")
> //
> ///////////////////////////
> 
> //==================================================================
> // Test.h
> //==================================================================
> #ifndef __Test__
> #define __Test__
> 
> #include <iostream.h>
> #include "TObject.h"
> #include "TNamed.h"
> #include "TFile.h"
> #include "TString.h"
> 
> class TestClass: public TNamed {
> 
>    private:
>       TFile        *fFile;   //!
> 
>    public :
> 
>       TestClass();
>       TestClass(const char *vName,const char *vTitle,const char
> *vFileName);
>       ~TestClass();
> 
>       void FFillTree(const char *vText);
> 
>       ClassDef(TestClass,1) //TestClass
> };
> 
> class TTest: public TObject {
> 
>    private:
>       Float_t       fX;
>       Float_t       fY;
> 
>    public :
>       TTest();
>       ~TTest();
> 
>       void FSetX(Float_t vX) {fX = vX;}
>       void FSetY(Float_t vY) {fY = vY;}
> 
>       Float_t FGetX() const {return fX;}
>       Float_t FGetY() const {return fY;}
> 
>       ClassDef(TTest,1) //Test
> };
> 
> #endif
> 
> //==================================================================
> // Test.cxx
> //==================================================================
> #include <stdio.h>
> #include <stdlib.h>
> #include <iostream.h>
> #include <fstream.h>
> #include <math.h>
> 
> #include "Test.h"
> #include "TTree.h"
> #include "TSystem.h"
> #include "TBranch.h"
> 
> ClassImp(TestClass);
> ClassImp(TTest);
> 
> //----------------------------------------------------------------------//
> TestClass::TestClass(): TNamed()
> {
>    cout << "TestClass::TestClass" << endl;
>    fFile = 0;
> }
> 
> //----------------------------------------------------------------------//
> TestClass::TestClass(const char *vName,const char *vTitle,const char
> *vFileName):
>            TNamed(vName,vTitle)
> {
>    cout << "TestClass::TestClass" << endl;
> 
>    fFile = new TFile(vFileName,"RECREATE");
>    cout << "New file [" << vFileName << "] is created" << endl;
> }//Constructor
> 
> //----------------------------------------------------------------------//
> TestClass::~TestClass()
> {
>    cout << "~TestClass::TestClass" << endl;
> 
>    delete fFile;
>    fFile = 0;
> }//Destructor
> 
> //----------------------------------------------------------------------//
> void TestClass::FFillTree(const char *vText)
> {
>    cout << "TestClass::FFillTree" << endl;
> 
>    Float_t vX, vY;
> 
>    ifstream vInput(vText, ios::in);
> 
>    TTree *vTree = new TTree("vTree","data from test.txt");
> //   TTest *vTest = new TTest();
>    TTest *vTest = 0;
>    TBranch *vBranch = vTree->Branch("vBranch","TTest",&vTest,64000,1);
> 
>    Int_t nlines = 0;
>    while (nlines < 100) {
>       vInput >> vX >> vY;
>       if (!vInput.good()) break;
>       vTest->FSetX(vX);
>       vTest->FSetY(vY);
> 
>       vTree->Fill();
>       nlines++;
>    }
> 
>    fFile->Write();
> 
>    vInput.close();
> //   delete vTest;
> }//FFillTree
> 
> //----------------------------------------------------------------------//
> TTest::TTest(): TObject()
> {
> //*-*-*-*-*-*-*-*-*Default TTest constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
> //                 ========================
>    fX = 0;
>    fY = 0;
> }//Constructor
> 
> //----------------------------------------------------------------------//
> TTest::~TTest()
> {
> //*-*-*-*-*-*-*-*-*TTest destructor *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
> //                 ===============
> }//Destructor
> 
> //==================================================================
> // TestLinkDef.h
> //==================================================================
> #ifdef __CINT__
> 
> #pragma link off all globals;
> #pragma link off all classes;
> #pragma link off all functions;
> 
> #pragma link C++ class TestClass+;
> #pragma link C++ class TTest+;
> 
> #endif
> 
> //==================================================================
> // MakeFile4Test
> //==================================================================
> # Makefile for class Test.
> # shell: gmake -f Makefile4Test
> 
> ARCH          = linuxppcegcs
> 
> CXX           =
> ObjSuf        = o
> SrcSuf        = cxx
> ExeSuf        =
> DllSuf        = so
> OutPutOpt     = -o
> 
> ROOTCFLAGS   := $(shell root-config --cflags)
> ROOTLIBS     := $(shell root-config --libs)
> ROOTGLIBS    := $(shell root-config --glibs)
> 
> ifeq ($(ARCH),linuxegcs)
> # Linux with egcs (>= RedHat 5.2)
> CXX           = g++
> CXXFLAGS      = -O -Wall -fPIC
> LD            = g++
> LDFLAGS       = -O
> SOFLAGS       = -shared
> endif
> 
> ifeq ($(ARCH),linuxppcegcs)
> # MkLinux with egcs/glibc
> CXX           = g++
> CXXFLAGS      = -O -Wall -fPIC
> LD            = g++
> LDFLAGS       = -O
> SOFLAGS       = -shared -Wl,-soname,
> endif
> 
> CXXFLAGS     += $(ROOTCFLAGS)
> LIBS          = $(ROOTLIBS) $(SYSLIBS)
> GLIBS         = $(ROOTGLIBS) $(SYSLIBS)
> 
> #------------------------------------------------------------------------------
> 
> TESTO       = Test.$(ObjSuf) TestDict.$(ObjSuf)
> TESTS       = Test.$(SrcSuf) TestDict.$(SrcSuf)
> TESTSO      = Test.$(DllSuf)
> 
> OBJS          = $(TESTO)
> PROGRAMS      = $(TESTSO)
> 
> #------------------------------------------------------------------------------
> 
> .SUFFIXES: .$(SrcSuf) .$(ObjSuf) .$(DllSuf)
> 
> all:            $(PROGRAMS)
> 
> $(TESTSO):    $(TESTO)
>                 $(LD) $(SOFLAGS) $(LDFLAGS) $^ $(OutPutOpt) $@
> 
> clean:
>   @rm -f $(OBJS) core
> 
> .SUFFIXES: .$(SrcSuf)
> 
> ###
> 
> Test.$(ObjSuf): Test.h
> TestDict.$(SrcSuf): Test.h TestLinkDef.h
>  @echo "Generating dictionary TestDict..."
>  @rootcint -f TestDict.$(SrcSuf) -c Test.h TestLinkDef.h
> 
> .$(SrcSuf).$(ObjSuf):
>  $(CXX) $(CXXFLAGS) -c $<
> 
> Rene Brun wrote:
> 
> > Hi Christian,
> >
> > The first problem is not connected with Trees. It seems that there is
> > a problem with the CINT macro call mechanism when an argument
> > is a string with a ")". This is under investigation.
> > Instead of doing  .x DrawTree.C("...
> >    do
> > .L DrawTree.C, then
> >   DrawTree(""...
> >
> > If this does not solve your problem, please send me a short macro
> > that I can use to to debug.
> >
> > About your second problem. I am aware of some combinations
> > of viewing angles that give problems. This happens if you make more
> > than one complete turn with the picture upside down.
> >
> >  Rene Brun
> >
> > On Sat, 19 May 2001 cstrato@EUnet.at wrote:
> >
> > >
> > > Dear Rooters
> > >
> > > I have the following function in a macro to draw a tree:
> > > void DrawTee(const char *vTreeName,const char *varexp)
> > > {
> > >    gSystem->Load("/opt/rootcode/Mylib.so");
> > >
> > >    TFile *fFile = new TFile("/opt/rootcode/test.root","READ");
> > >    TTree *vTree = (TTree*)fFile->Get(vTreeName);
> > > //   MyClass *vClass = 0;
> > > //   vTree->SetBranchAddress("vBranch",&vClass);
> > >
> > >    vTree->Draw(varexp);
> > > }
> > >
> > > >From root I call this function:
> > > root [1] DrawTree("vTree","fX")
> > > This works fine, however, when I call:
> > > root [2] DrawTree("vTree","sqrt(fX)")
> > > I get the following error message printed 13 times:
> > > Error: No symbol fX in current scope  FILE:macro4draw.C LINE:17
> > > *** Interpreter error recovered ***
> > > Error: class,struct,union or type (unknown) not defined
> > > FILE:macro4draw.C LINE:17
> > >
> > > Interestingly, the histogram is always drawn correctly, when
> > > I use different functions.
> > >
> > > I do understand why the error appears, since fX is a private member
> > > of class MyClass and cannot be accessed directly, but then this error
> > > should also appear in the case: DrawTree("vTree","fX").
> > >
> > > What can I do to avoid the error messages?
> > >
> > > Thank you in advance for your help.
> > > My system: PowerBook LinuxPPC 2000, root 3.01/02
> > >
> > > P.S.: When I rotate a 3-dim histogram interactively with the mouse in
> > > such a way,
> > > that I turn it upside-down often, then finally the vertical axis is no
> > > longer
> > > drawn correctly, and also the content is drawn partly outside of the
> > > box.
> > >
> > > P.P.S.: The function Tree->AddFriend() is really very helpful!
> > >
> > > Best regards
> > > Christian
> > > ----------------------------------
> > > C.h.r.i.s.t.i.a.n  S.t.r.a.t.o.w.a
> > > V.i.e.n.n.a,  A.u.s.t.r.i.a
> > >
> > >
> > >
> 
>   --------------------------------------------------------------------------------
> 
>                      Name: test.txt
>    test.txt          Type: Plain Text (text/plain)
>                  Encoding: 7bit
>               Description: Unknown Document



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:46 MET