////////////////////////////////////////////////////////
//  
// Adapted TF1
//
////////////////////////////////////////////////////////

#include <math.h>
#include <iostream>
#include "PUtils.h"
using namespace std;

#ifdef WIN32
#pragma optimize("",off)
#endif

#include "PF3.h"

//Standard ROOT ctors

PF3::PF3() :
    TF3() {
    projector = NULL;    
};

PF3::PF3(const char *name, const char *formula, Double_t xmin, Double_t xmax, Double_t, Double_t, Double_t, Double_t) :
    TF3(name, formula, xmin, xmax) {
    projector = NULL;
};

#if 0
PF3::PF3(const char *name, void *fcn, Double_t xmin, Double_t xmax, Double_t, Double_t, Double_t, Double_t, Int_t npar) :
    TF3(name, fcn, xmin, xmax, npar) {
    projector = NULL;
};
#endif

PF3::PF3(const char *name, Double_t (*fcn)(Double_t *, Double_t *), 
	 Double_t xmin, Double_t xmax, Double_t, Double_t, Double_t, Double_t, Int_t npar) :
    TF3(name, fcn, xmin, xmax, npar) {
    projector = NULL;
};

PF3::PF3(const char *name, ROOT::Math::ParamFunctor f, Double_t xmin, Double_t xmax, Double_t, Double_t, Double_t, Double_t, Int_t npar) :
    TF3(name, f, xmin, xmax, npar) {
    projector = NULL;
};  

PF3::PF3(const PF3 &f3) :
    TF3(f3) {
    projector = NULL;
};

//Pluto ctor
PF3::PF3(const char *name, Double_t xmin, Double_t xmax, Double_t, Double_t, Double_t, Double_t) :
    TF3(name,"x+y+z", xmin, xmax) {
    SetTitle(name);
    projector = new PProjector();
    vf = makeStaticData()->GetBatchValue("_f"); 
    vx = makeStaticData()->GetBatchValue("_x"); 
    vy = makeStaticData()->GetBatchValue("_y"); 
    vz = makeStaticData()->GetBatchValue("_z"); 
}

Bool_t PF3::Add(char *command) {
    if (!projector) {
	Warning("Add", "No PProjector, wrong ctor called?");
	return kFALSE;
    }
    return projector->AddCommand(command);
};

Bool_t PF3::Add(TH1 *histo, const char *command) {
    if (!projector) {
	Warning("Add", "No PProjector, wrong ctor called?");
	return kFALSE;
    }
    return  projector->AddHistogram(histo, command, 0);
};

Bool_t PF3::Add(TH2 *histo, const char *command) {
    if (!projector) {
	Warning("Add", "No PProjector, wrong ctor called?");
	return kFALSE;
    }
    return  projector->AddHistogram(histo, command, 0);
};

Bool_t PF3::Add(TH3 *histo, const char *command) {
    if (!projector) {
	Warning("Add", "No PProjector, wrong ctor called?");
	return kFALSE;
    }
    return  projector->AddHistogram(histo, command, 0);
};

Bool_t PF3::Add(TGraph *graph, const char *command) {
    if (!projector) {
	Warning("Add", "No PProjector, wrong ctor called?");
	return kFALSE;
    }
    return  projector->AddTGraph(graph, command);
};

Bool_t PF3::Add(TGraph2D *graph, const char *command) {
    if (!projector) {
	Warning("Add", "No PProjector, wrong ctor called?");
	return kFALSE;
    }
    return  projector->AddTGraph2D(graph, command);
};

Double_t PF3::EvalPar(const Double_t *x, const Double_t *params) {
    if (!projector) return TF3::EvalPar(x, params);

    //Extension via batch script:
    *vx = x[0];
    *vy = x[1];
    *vz = x[2];

    Int_t num=0;
    if (projector->Modify(NULL, NULL, &num, 0))
	return  *vf;
    return 0;
}



ClassImp(PF3)
 PF3.cc:1
 PF3.cc:2
 PF3.cc:3
 PF3.cc:4
 PF3.cc:5
 PF3.cc:6
 PF3.cc:7
 PF3.cc:8
 PF3.cc:9
 PF3.cc:10
 PF3.cc:11
 PF3.cc:12
 PF3.cc:13
 PF3.cc:14
 PF3.cc:15
 PF3.cc:16
 PF3.cc:17
 PF3.cc:18
 PF3.cc:19
 PF3.cc:20
 PF3.cc:21
 PF3.cc:22
 PF3.cc:23
 PF3.cc:24
 PF3.cc:25
 PF3.cc:26
 PF3.cc:27
 PF3.cc:28
 PF3.cc:29
 PF3.cc:30
 PF3.cc:31
 PF3.cc:32
 PF3.cc:33
 PF3.cc:34
 PF3.cc:35
 PF3.cc:36
 PF3.cc:37
 PF3.cc:38
 PF3.cc:39
 PF3.cc:40
 PF3.cc:41
 PF3.cc:42
 PF3.cc:43
 PF3.cc:44
 PF3.cc:45
 PF3.cc:46
 PF3.cc:47
 PF3.cc:48
 PF3.cc:49
 PF3.cc:50
 PF3.cc:51
 PF3.cc:52
 PF3.cc:53
 PF3.cc:54
 PF3.cc:55
 PF3.cc:56
 PF3.cc:57
 PF3.cc:58
 PF3.cc:59
 PF3.cc:60
 PF3.cc:61
 PF3.cc:62
 PF3.cc:63
 PF3.cc:64
 PF3.cc:65
 PF3.cc:66
 PF3.cc:67
 PF3.cc:68
 PF3.cc:69
 PF3.cc:70
 PF3.cc:71
 PF3.cc:72
 PF3.cc:73
 PF3.cc:74
 PF3.cc:75
 PF3.cc:76
 PF3.cc:77
 PF3.cc:78
 PF3.cc:79
 PF3.cc:80
 PF3.cc:81
 PF3.cc:82
 PF3.cc:83
 PF3.cc:84
 PF3.cc:85
 PF3.cc:86
 PF3.cc:87
 PF3.cc:88
 PF3.cc:89
 PF3.cc:90
 PF3.cc:91
 PF3.cc:92
 PF3.cc:93
 PF3.cc:94
 PF3.cc:95
 PF3.cc:96
 PF3.cc:97
 PF3.cc:98
 PF3.cc:99
 PF3.cc:100
 PF3.cc:101
 PF3.cc:102
 PF3.cc:103
 PF3.cc:104
 PF3.cc:105
 PF3.cc:106
 PF3.cc:107
 PF3.cc:108
 PF3.cc:109
 PF3.cc:110
 PF3.cc:111
 PF3.cc:112
 PF3.cc:113
 PF3.cc:114
 PF3.cc:115
 PF3.cc:116
 PF3.cc:117
 PF3.cc:118
 PF3.cc:119
 PF3.cc:120
 PF3.cc:121
 PF3.cc:122
 PF3.cc:123
 PF3.cc:124
 PF3.cc:125
 PF3.cc:126
 PF3.cc:127
 PF3.cc:128