Hi Michele,
If you modify the graph, add a clone of this graph
to the multigraph. Instead of
multigraph->Add(graph);
do
multigraph->Add(graph->Clone());
To understand the problem with your copy constructor, I need your
code,
but also the version of Root
Rene Brun
On Sat, 14 Feb 2004,
Michele Zaffalon wrote:
> Dear ROOTers,
>
> I am trying to plot a graph given a TBranch *. So I derive
> a class from TGraph which I call zGraph, that accepts a
> TBranch * in the ctor of zGraph. I can then plot the
> zGraph using a TMultiGraph. The problem is that I cannot
> touch the zGraph anymore because it belongs to TMultiGraph
> and I want to be able to use the same zGraph for futher
> analysis and to keep the attributes.
> So I thought of using something like
>
> return new TGraph(*this); or
> return new zGraph(*this)
>
> in a method TGraph *zGraph::getGraph() or zGraph
> *zGraph::getGraph(). If I try to plot a few copies of the
> same graph (returned by zGraph::getGraph()), I obtain only
> one graph. I wonder: is the copy constructor of TGraph
> doing something strange or am I missing something about
> the way the graphs are plotted?
>
> Regards
>
> michele
>
> zGraph::getGraph() calls doGraph() and returns
>
> if (doGraph())
> return new TGraph(*this);
>
> Int_t zGraph::doGraph()
> {
> delete [] fX;
> delete [] fY;
> fNpoints = 0;
>
> if (!d_branch)
> {
> cerr << "branch = 0 in " << this->GetName() <<
> endl;
> return -1;
> }
>
> zData *data = new zData();
> d_branch->SetAddress(&data);
>
> fNpoints = (Int_t) d_branch->GetEntries();
> if (fNpoints <= 0)
> {
> cerr << "fNpoints <= 0 in " << d_branch->GetName()
> << endl;
> return -1;
> }
>
> fFunctions = new TList;
> fX = new Double_t[fNpoints];
> fY = new Double_t[fNpoints];
>
> Int_t idx = 0;
>
> while (d_branch->GetEntry(idx) > 0)
> {
> fX[idx] = data->getX();
> fY[idx] = data->getY();
> idx++;
> }
>
> delete data;
> return 0;
> }
>
>
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:05 MET