When the macro is interpreted, CINT knows about the symbols gr1 and gr2 because they refer to pad names (one of the CINT C++ extensions). The commands specified in TPad::AddExec must be valid CINT commands. In case, one wants to refer to a global variable (say your gr1 and gr2), one can make use of a special list supported by gROOT, called ListOfSpecials. You simply add your objects, in the example below the 3 TGraph objects, to this list. In the zoompad function, you then have to get a pointer to these objects, searching by name. See the code below Rene Brun void zoom3() { gROOT->Reset(); TCanvas *c1 = new TCanvas("c1","TCanvas",250,200,990,720); pad1 = new TPad("pad1","Window N1",0.02,0.66,0.98,0.96,18); pad2 = new TPad("pad2","Window N2",0.02,0.34,0.98,0.64,18); pad3 = new TPad("pad3","Window N3",0.02,0.02,0.98,0.32,18); pad1->SetGrid(); pad1->SetBottomMargin(0.19); pad2->SetGrid(); pad2->SetBottomMargin(0.19); pad3->SetGrid(); pad3->SetBottomMargin(0.19); pad1->Draw(); pad2->Draw(); pad3->Draw(); pad1->cd(); Float_t x[100], y[100]; Int_t n = 20; for (Int_t i=0;i<n;i++) { x[i] = i*0.1; y[i] = 10*sin(x[i]+0.2); } gr1 = new TGraph(n,x,y); gr1->SetName("gr1"); gROOT->GetListOfSpecials()->Add(gr1); gr1->Draw("AC*"); gPad->AddExec("ex","zoompad(\"gr1\",\"gr2\")"); gPad->AddExec("ex","zoompad(\"gr1\",\"gr3\")"); pad2->cd(); Float_t x[100], y[100]; Int_t n = 20; for (Int_t i=0;i<n;i++) { x[i] = i*0.1; y[i] = 10*cos(x[i]+0.2); } gr2 = new TGraph(n,x,y); gr2->SetName("gr2"); gROOT->GetListOfSpecials()->Add(gr2); gr2->Draw("AC*"); pad3->cd(); Float_t x[100], y[100]; Int_t n = 20; for (Int_t i=0;i<n;i++) { x[i] = i*0.1; y[i] = x[i]; } gr3 = new TGraph(n,x,y); gr3->SetName("gr3"); gROOT->GetListOfSpecials()->Add(gr3); gr3->Draw("AC*"); c1->Update(); } void zoompad(const char *ngr1, const char *ngr2) { int event = gPad->GetEvent(); if (event != 11) return; TObject *select = gPad->GetSelected(); if (!select) return; TGraph *tgr1 = (TGraph*)gROOT->GetListOfSpecials()->FindObject(ngr1); TGraph *tgr2 = (TGraph*)gROOT->GetListOfSpecials()->FindObject(ngr2); TAxis *axis1 = tgr1->GetXaxis(); Int_t binmin = axis1->GetFirst(); Int_t binmax = axis1->GetLast(); Float_t xmin = axis1->GetBinLowEdge(binmin); Float_t xmax = axis1->GetBinLowEdge(binmax); TAxis *axis2 = tgr2->GetXaxis(); Int_t newmin = axis2->FindBin(xmin); Int_t newmax = axis2->FindBin(xmax); axis2->SetRange(newmin,newmax); if (gr2){ pad2->Modified(); pad2->Update(); } if(gr3){ pad3->Modified(); pad3->Update(); } } On Mon, 6 Mar 2000, Yongzhao Zhou wrote: > Hi, Rooters, > A macro names threezoom which make three TGraph pictures zooming in > syn can work well on interpreted mode of root 2.23/12 of AIX4.3 as > > void threezoom() > { > gROOT->Reset(); > > TCanvas *c1 = new TCanvas("c1","TCanvas",250,200,990,720); > > pad1 = new TPad("pad1","Window N1",0.02,0.66,0.98,0.96,18); > pad2 = new TPad("pad2","Window N2",0.02,0.34,0.98,0.64,18); > pad3 = new TPad("pad3","Window N3",0.02,0.02,0.98,0.32,18); > > pad1->SetGrid(); > pad1->SetBottomMargin(0.19); > > pad2->SetGrid(); > pad2->SetBottomMargin(0.19); > > pad3->SetGrid(); > pad3->SetBottomMargin(0.19); > > pad1->Draw(); > pad2->Draw(); > pad3->Draw(); > > pad1->cd(); > > Float_t x[100], y[100]; > Int_t n = 20; > for (Int_t i=0;i<n;i++) { > x[i] = i*0.1; > y[i] = 10*sin(x[i]+0.2); > } > gr1 = new TGraph(n,x,y); > gr1->Draw("AC*"); > > gPad->AddExec("ex","zoompad(gr1,gr2)"); > gPad->AddExec("ex","zoompad(gr1,gr3)"); > > pad2->cd(); > > Float_t x[100], y[100]; > Int_t n = 20; > for (Int_t i=0;i<n;i++) { > x[i] = i*0.1; > y[i] = 10*cos(x[i]+0.2); > } > gr2 = new TGraph(n,x,y); > > gr2->Draw("AC*"); > > pad3->cd(); > > Float_t x[100], y[100]; > Int_t n = 20; > for (Int_t i=0;i<n;i++) { > x[i] = i*0.1; > y[i] = x[i]; > } > gr3 = new TGraph(n,x,y); > gr3->Draw("AC*"); > > c1->Update(); > } > > > void zoompad(TGraph *tgr1, TGraph *tgr2) > { > int event = gPad->GetEvent(); > if (event != 11) return; > TObject *select = gPad->GetSelected(); > if (!select) return; > TAxis *axis1 = tgr1->GetXaxis(); > Int_t binmin = axis1->GetFirst(); > Int_t binmax = axis1->GetLast(); > Float_t xmin = axis1->GetBinLowEdge(binmin); > Float_t xmax = axis1->GetBinLowEdge(binmax); > TAxis *axis2 = tgr2->GetXaxis(); > Int_t newmin = axis2->FindBin(xmin); > Int_t newmax = axis2->FindBin(xmax); > axis2->SetRange(newmin,newmax); > > if (gr2){ > pad2->Modified(); > pad2->Update(); > } > if(gr3){ > pad3->Modified(); > pad3->Update(); > } > } > > But there aer always error messages if the same codes (sure, some statements > sould be changed) works on compiled mode on same system: > > *** Interpreter error recovered *** > Error: No symbol gr1 in current scope FILE:/tmp/oeaPlnizS_cint LINE:1 > Error: No symbol gr3 in current scope FILE:/tmp/oeaPlnizS_cint LINE:1 > > Does it means that function AddExec just can work under interpreted mode > and can not work under compiled mode? > Thanks for any help. > Best, > ZYZ > > ------ > Yongzhao Zhou, KLOE, LNF, INFN, Italy > Tel:39-06-94032696 Fax:39-06-94032427 >
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:21 MET