[ROOT] CINT/pointers in ROOT/TGraphErrors

From: Shawn Kwang (skwang@wam.umd.edu)
Date: Thu Aug 02 2001 - 19:09:29 MEST


Roottalk members,

First here is the code in question:
==================================================================
...

void regx(TH2F *h8877, char *hname, int colorint, int pflag, TGraphErrors
	*mean1, TGraphErrors *sigma1, char *name1, char *name2)
{

<snip>

  TGraphErrors *grmean = new TGraphErrors(nhitbins,x,y,ex,ey);

  TGraphErrors *grsigma = new TGraphErrors(nhitbins,x,sigmay,ex,errey);

  //copy graphs to passed variables
  *mean1 =  *grmean;		<-----Problem???
  mean1->SetName(name1);
  *sigma1 = *grsigma;		<-----Problem???
  sigma1->SetName(name2);

}

{ main function (not actually main(), but another function which runs
everything)
<snip>

TGraphErrors *recomean = new TGraphErrors();
TGraphErrors *recosigma = new TGraphErrors();
regx(pt_genrec,"pt_genrec",4,1,recomean,recosigma,"Mean Pt with Fit",
	"Sigma Pt");

<snip>

TCanvas *c11=new TCanvas("c11","Mean Pt of PMCS  and RECO electrons");
recomean->Draw("AP");
recomean->GetHistogram()->SetXTitle("Pt of Generated Electrons");
		^--Line 771

...
}
=================================================================

When I compile this program using KCC and ROOT header files, the program
runs fine.  When I try to run the program as a ROOT macro it crashes at
the GetHistogram() line.

Here is the error ROOT gives:
Error in <TGraphErrors::PaintGraph>: illegal number of points (0)
Error: illegal pointer to class object GetHistogram() 0x0 134
FILE:/home/skwang/CAPR/CAPR.C LINE:771
*** Interpreter error recovered ***


I suspect the problem is where I have inserted the two "Problem" arrows.  
I am trying to copy the pointers of the two TGraphErrors grmean and
grsigma to the ones I pass to the function, mean1 and sigma1.  The reason
I am doing it this way is because the function regx is run fives times on
five different histograms, thereby producing ten TGraphErrors.  From what
I can tell the pointers mean1 and sigma1 are not being assigned correctly,
and do not point to grmean and grsigma respectively.  This means that
recomean and recosigma (in the main function) are effectively empty and
when I try to access their histograms, the program crashes.

What I want is how to assign the pointers mean1 and sigma1 to the
TGraphErrors that are created by grmean and grsigma.  I tried using
Clone() but that gives the same error.

i.e. mean1 = (TGraphErrors*)grmean->Clone();

I suspect the problem is with my understanding of pointers in C++ and how
Root handles them.  Finally, if there is a better way to do what I do
above please let me know.

Thanks in advance,
Shawn Kwang

--
					skwang@wam.umd.edu
					skwang@glue.umd.edu



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