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. >
>>>> 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
>>> >>>>>> 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.
>>>>> 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
>>>> 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 - 15:26:21 CEST
This archive was generated by hypermail 2.2.0 : Wed Mar 30 2011 - 17:50:01 CEST