Re: TF3::GetHistogram() seg violation

From: Olivier Couet <Olivier.Couet_at_cern.ch>
Date: Wed, 30 Mar 2011 14:55:28 +0000


Hi Serhiy,

Just for completeness let me point also this page: http://root.cern.ch/root/html/THistPainter.html#HP27 The example there shows clearly that only the iso-surfaces on which the function is 0 are painted.
May be it should be made even clearer on this page.

Cheers,
Olivier

On 3/30/11 4:50 PM, "Serhiy Senyukov" <Serhiy.Senyukov_at_cern.ch> wrote:

>Hi Lorenzo,
>
>Thank you for the explanation. Now I see how it works.
>I found the correct way to visualize my function without going to
>histograms.
>Actually what I needed was the equipotential surface.
>
>Thank you all for the fruitful discussion.
>Regards,
>Serhiy.
>
>> -----Original Message-----
>> From: Lorenzo Moneta
>> Sent: Wednesday, March 30, 2011 4:17 PM
>> To: Serhiy Senyukov
>> Cc: Olivier Couet; roottalk (Mailing list discussing all aspects of the
>> ROOT system.)
>> Subject: Re: [ROOT] TF3::GetHistogram() seg violation
>>
>> Hi Serhiy,
>>
>> Currently the TF3 is drawing in a different way (by showing the
>> contours when f(x,y,z)=0)) and does not need to have the contained
>> histogram filled with the values.
>> Probably we will have to revise this and at some point we should put
>> the code to fill the histogram inside the TF3
>>
>> Regards
>>
>> Lorenzo
>>
>>
>>
>> On Mar 30, 2011, at 3:38 PM, Serhiy Senyukov wrote:
>>
>> > Hi Lorenzo,
>> >
>> > Thank you for your answer.
>> > Indeed such a brute-force way should work.
>> > However, I do not understand why this operation cannot be done inside
>> GetHistogram(). What is the meaning of this method as it is implemented
>> now? Moreover its behavior is not coherent to the 1D and 2D cases.
>> >
>> > Regards,
>> > Serhiy.
>> >
>> >> -----Original Message-----
>> >> From: Lorenzo Moneta
>> >> Sent: Wednesday, March 30, 2011 3:26 PM
>> >> To: Serhiy Senyukov
>> >> Cc: Olivier Couet; roottalk (Mailing list discussing all aspects of
>> the
>> >> ROOT system.)
>> >> Subject: Re: [ROOT] TF3::GetHistogram() seg violation
>> >>
>> >> Hi,
>> >>
>> >> To fill a 3D histogram from a TF3 function you can do something like
>> >> this
>> >>
>> >> {
>> >>
>> >>
>> >> TF3 * f3 = new TF3("f3","x*x+y*y+z");
>> >> f3->Draw();
>> >> gPad->Update(); // this forces the creation of the histogram
>> >> TH3 * h3=(TH3*) f3->GetHistogram();
>> >>
>> >> double xv[3];
>> >> f3->InitArgs(xv, f3->GetParameters());
>> >> for (int i=1;i<=h3->GetNbinsX();i++) {
>> >> xv[0] = h3->GetXaxis()->GetBinCenter(i);
>> >> for (int j=1;j<=h3->GetNbinsY();j++) {
>> >> xv[1] = h3->GetYaxis()->GetBinCenter(j);
>> >> for (int k=1;k<=h3->GetNbinsZ();k++) {
>> >> xv[2] = h3->GetZaxis()->GetBinCenter(k);
>> >> int bin = h3->GetBin(i,j,k);
>> >> h3->SetBinContent(bin,f3->EvalPar(xv,f3->GetParameters())
>> >> );
>> >> }
>> >> }
>> >> }
>> >>
>> >> h3->Draw("ISO");
>> >> }
>> >>
>> >>
>> >> Lorenzo
>> >>
>> >>
>> >> On Mar 30, 2011, at 2:58 PM, Serhiy Senyukov wrote:
>> >>
>> >>> Thank you for your suggestion Oliver. However it is not the thing I
>> >> would like to do.
>> >>> What I really need is to translate 3D function into reasonable
>> >> histogram. Final goal is to visualize the original 3D function.
>> >>>
>> >>>> -----Original Message-----
>> >>>> From: Olivier Couet
>> >>>> Sent: Wednesday, March 30, 2011 2:44 PM
>> >>>> To: Serhiy Senyukov
>> >>>> Cc: Olivier Couet; roottalk (Mailing list discussing all aspects
>> of
>> >> the
>> >>>> ROOT system.)
>> >>>> Subject: RE: [ROOT] TF3::GetHistogram() seg violation
>> >>>>
>> >>>>
>> >>>>
>> >>>> I think the TH3 ib that case is only used to draw the frame and
>> >> remains
>> >>>> empty. You should try to do something like that:
>> >>>>
>> >>>> {
>> >>>> TH3D *earth = new TH3D("earth", "earth", 100, -1., 1., 100, -1.,
>> >>>> 1.,100, -1., 1.);
>> >>>> double phi=0., cos_theta=0., theta=0.;
>> >>>> for(int i=0; i<100; i++){
>> >>>> phi=gRandom->Uniform(0., 6.28);
>> >>>> cos_theta=gRandom->Uniform(0., 1.);
>> >>>> theta=acos(cos_theta);
>> >>>> earth->Fill(cos(phi)*sin(theta), sin(phi)*sin(theta),
>> >>>> cos_theta);
>> >>>> }
>> >>>> TCanvas *c1 = new TCanvas("c1", "c1",1);
>> >>>> earth->SetMarkerStyle(4);
>> >>>>
>> >>>> earth->Draw("box");
>> >>>> }
>> >>>>
>> >>>>
>> >>>>
>> >>>> Org: CERN - European Laboratory for Particle Physics.
>> >>>> Mail: 1211 Geneve 23 - Switzerland Mailbox:
>> >>>> J25910
>> >>>> E-Mail: Olivier.Couet_at_cern.ch Phone:
>> >> +41
>> >>>> 22 7676522
>> >>>> WWW: http://cern.ch/Olivier.Couet/ Fax:
>> >> +41
>> >>>> 22 7670300
>> >>>>
>> >>>> On Wed, 30 Mar 2011, Serhiy Senyukov wrote:
>> >>>>
>> >>>>>> As you see I get 100 .
>> >>>>>> I am using the trunk
>> >>>>> [Serhiy Senyukov] As far as I can see from your code you are
>> >> getting
>> >>>> 100 evaluating the function itself. Contrary I get zero by asking
>> >> the
>> >>>> bin content of the histogram derived from the function.
>> >>>>>
>> >>>>>>>> I do not see what you describe here.
>> >>>>>>> [Serhiy Senyukov] Ok. I have found the reason for the first
>> >> issue.
>> >>>>>> There
>> >>>>>>> were parameters missing in the declaration of the 3D function.
>> >>>> However
>> >>>>>>> the bin content of the produced histogram is always zero.
>> >>>>>>>
>> >>>>>>> Regards,
>> >>>>>>> Serhiy.
>> >>>>>>>
>> >>>>>>>> root [0] .x ser.C
>> >>>>>>>> Processing ser.C...
>> >>>>>>>> Test function3 test = 100
>> >>>>>>>> Info in <TCanvas::MakeDefCanvas>: created default TCanvas
>> with
>> >>>> name
>> >>>>>> c1
>> >>>>>>>>
>> >>>>>>>> The macro is:
>> >>>>>>>>
>> >>>>>>>> Double_t test(Double_t *x, Double_t *par)
>> >>>>>>>> {
>> >>>>>>>> return 100;
>> >>>>>>>> }
>> >>>>>>>>
>> >>>>>>>> void ser(Int_t nPoints=5){
>> >>>>>>>> TF3* test_f3=new TF3("test_f3",test,0,10,0,10,0,10,2);
>> >>>>>>>> test_f3->SetParameters(1,2);
>> >>>>>>>> test_f3->SetNpx(nPoints);
>> >>>>>>>> test_f3->SetNpy(nPoints);
>> >>>>>>>> test_f3->SetNpz(nPoints);
>> >>>>>>>>
>> >>>>>>>> cout<<"Test function3 test = "<<test_f3->Eval(5,5,5)<<endl;
>> >>>>>>>>
>> >>>>>>>> test_f3->Draw();
>> >>>>>>>> TH3F* test3_hist=(TH3F*)test_f3->GetHistogram();
>> >>>>>>>> }
>> >>>>>
>> >>>>>
>> >>>
>> >
>
Received on Wed Mar 30 2011 - 16:55:38 CEST

This archive was generated by hypermail 2.2.0 : Wed Mar 30 2011 - 23:50:01 CEST