Re: Pointer to histogram
Rene Brun (Rene.Brun@cern.ch)
Tue, 07 Apr 1998 19:13:48 +0200
Tadeusz Pytlos wrote:
>
> Hello Rooters,
> I can't understand how to operate on histograms.
> I just want to receive h14=h4, but I solved it
> in quite unelegant way. Would you tell me what is wrong in my macro?
> I reckon that operating togeher on objects and pointers
> causes a complicating notation. I wish there was no pointers at all
> or there were hidden pointers, but I understand that there are many
> benefits of pointers...
> Best wishes,
> Tadeusz
>
> {
> //////////////////////////////////////////////////////////
> // This file has been automatically generated
> // (Mon Nov 24 12:46:19 1997 by ROOT version 1.03/07)
> // from TTree kas/BASKET
> // found on file: dst00459.root
> //////////////////////////////////////////////////////////
>
> //Reset ROOT and connect tree file
> gROOT->Reset();
> TFile hfile("dep.root");
> page = new TCanvas("page","Example",0,0,500,700);
> page->SetFillColor(10);
> page->Divide(1,1);
>
> TH1F *h44 = new TH1F("h44","Example",100,0,50);
> TH1F *h14 = new TH1F("h14","Example",100,0,50);
> // Of course there h4 is the same.
>
> // It's correct
> // h44->Add(h4,h4);
> // h14->Add(h44,h4,1,-1);
> // There are nice figures
>
> // It's wrong
> h44=(*h4)+(*h4);
> h14=(*h4);
> // There is nothing ...
>
>
The statement h44 = (*h4) + (*h4) is wrong. h44 has been defined
as a pointer to a TH1F. It must be an object, not a pointer.
Do:
TH1F result = (*h4) + (*h4)
Rene Brun