Hi Harufumi,
There are several problems in your script. In particular where is
the variable h in ProjectioXY defined?
Below, you will find a modified version of your program using
two files py.C and pym.C
file pym.C
=========
{
gROOT->Reset();
gROOT->ProcessLine(".L py.C");
TExec *ex_proj = new TExec("ex_proj", "ProjectionXY()");
TFile f("hsimple.root");
TH2F *h = (TH2F*)gDirectory->Get("hpxpy");
h->GetListOfFunctions()->Add(ex_proj);
h1_px = 0; h1_py = 0;
TCanvas c1("c1");
c1.Divide(2,2);
c1.cd(1);
h->Draw("colz");
}
file py.C
=========
void ProjectionXY() {
TH2F *h = (TH2F*)gDirectory->Get("hpxpy");
TAxis *xaxis = h->GetXaxis();
TAxis *yaxis = h->GetYaxis();
Int_t ixmin = xaxis->GetFirst();
Int_t ixmax = xaxis->GetLast();
Int_t iymin = yaxis->GetFirst();
Int_t iymax = yaxis->GetLast();
static TH1D *h1_px=0, *h1_py=0;
if (h1_px) delete h1_px; if (h1_py) delete h1_py;
// Projection to X axis
TCanvas *c1 = gPad->GetCanvas();
c1->cd(2);
h1_px = (TH1D*)h->ProjectionX("h1_px",iymin, iymax);
h1_px->GetXaxis()->SetRange(ixmin, ixmax);
h1_px->Draw();
gPad->Modified();
// Projection to Y axis
c1->cd(3);
h1_py = (TH1D*)h->ProjectionY("h1_py",ixmin, ixmax);
h1_py->GetXaxis()->SetRange(iymin, iymax);
h1_py->Draw();
gPad->Modified();
}
Rene Brun
On Tue, 4 Dec 2001, Harufumi Tsuchiya wrote:
> Dear ROOTers,
>
> Now, I try to execute my original function via TExex.
> But, I do not succeed in doing this.
>
> My procedure is like this
>
> I modified cexec.C in
> http://root.cern.ch/cgi-bin/print_hit_bold.pl/root/roottalk/roottalk01/2830.html?cexec#first_hit for my aim.
> In my program, cproject() in cexec.C was renamed to ProjectionXY().
>
> ProjectionXY() is like this.
>
> void ProjectionXY() {
> TAxis *xaxis = h->GetXaxis();
> TAxis *yaxis = h->GetYaxis();
> Int_t ixmin = xaxis->GetFirst();
> Int_t ixmax = xaxis->GetLast();
> Int_t iymin = yaxis->GetFirst();
> Int_t iymax = yaxis->GetLast();
> if (h1_px) delete h1_px; if (h1_py) delete h1_py;
> // Projection to X axis
> pad[1]->cd();
> h1_px = (TH1F*)h->ProjectionX("h1_px",iymin, iymax);
> h1_px->GetXaxis()->SetRange(ixmin, ixmax);
> h1_px->Draw();
> gPad->Modified();
> // Projection to Y axis
> pad[2]->cd();
> h1_py = (TH1F*)h->ProjectionY("h1_py",ixmin, ixmax);
> h1_py->GetYaxis()->SetRange(iymin, iymax);
> h1_py->Draw();
> gPad->Modified();
> }
>
> I divied canvas into 4 sections and colar map produced via
> h->Draw("colz") is displayed at pad[0].
> I would like to display each projection of h along x and y axis
> at pad[1] and pad[2], respectively.
> h is already filled via TH2F::Fill() before calling ProjectionXY.
> ProjectionXY is defined like above in my main program and used like this.
>
> :
> :
> TExec *ex_proj = new TExec("ex_proj", "ProjectionXY()");
> h->GetListOfFunctions()->Add(ex_proj);
> h1_px = 0; h1_py = 0;
> pad[0]->cd();
> h->Draw("colz");
> :
> :
>
> I compiled my program via g++ successfully and run.
> But, I got error message below.
>
> Error: Function ProjectionXY() is not defined in current scope FILE:/var/tmp/tmp.1.Wa1kvA_cint LINE:1
> Possible candidates are...
> filename line:size busy function type and name
> *** Interpreter error recovered ***
>
> Only color map was drawn at pad[0] and no histogram appeared at other pads.
> I zoomed the this map on canvas and also got the same error mesasge above.
> (Zooming itsef could be done successfully.)
>
> What is wrong ?
>
> Please tell me correct way.
>
> I use ROOT version 3.02.04 on FreeBSD 4.3 and version of g++ is 2.95.3.
>
> Harufumi Tsuchiya
>
>
>
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:10 MET