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

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

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

#include "PF1.h"

//Standard ROOT ctors

PF1::PF1() :
    TF1() {
    projector = NULL;    
};

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

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

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

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

PF1::PF1(const PF1 &f1) :
    TF1(f1) {
    projector = NULL;
};

//Pluto ctor
PF1::PF1(const char *name, Double_t xmin, Double_t xmax) :
    TF1(name,"x", xmin, xmax) {
    SetTitle(name);
    projector = new PProjector();
    vf = makeStaticData()->GetBatchValue("_f"); 
    vx = makeStaticData()->GetBatchValue("_x"); 
}

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

Bool_t PF1::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 PF1::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 PF1::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 PF1::Add(TGraph *graph, const char *command) {
    if (!projector) {
	Warning("Add", "No PProjector, wrong ctor called?");
	return kFALSE;
    }
    return  projector->AddTGraph(graph, command);
};

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

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

    //Extension via batch script:
    *vx = x[0];

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



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