/////////////////////////////////////////////////////////////////////
//
// A wrapper to use root-functions as Pluto-models
//
// Can be used for simple models
// or to use the PAdaptiveMeshN algorithm
//
// Works also in batch mode via AddEquation
// input: _x, output: _f
//
//                                  Author:  I. Froehlich
/////////////////////////////////////////////////////////////////////


using namespace std;
#include <sstream>
#include <iostream>
#include <iomanip>

#include "PFunction.h"


ClassImp(PFunction)

PFunction::PFunction() {
};

PFunction::PFunction(const Char_t *id, const Char_t *de, Int_t key) : PChannelModel (id, de,key) {

    tf1 = NULL;
    tf2 = NULL;
    tf3 = NULL;
    constant = 0;
    batch    = NULL;
};

PDistribution *PFunction::Clone(const char *) const {
    return new PFunction((const PFunction &)* this);
};

Bool_t PFunction::Init(void) {
    return kTRUE;    
};

Bool_t PFunction::AddEquation(const char *command) {

    if (!batch) batch = new PBatch();
    
    vx = makeStaticData()->GetBatchValue("_x"); 
    vf = makeStaticData()->GetBatchValue("_f"); 

    return batch->AddCommand(command);
};

Double_t PFunction::GetWeight(Double_t *mass, Int_t *) {

    if (batch) {	
	*vx = mass[0];
	batch->Execute();
	return *vf;
    }

    if (tf1) return tf1->Eval(mass[0]);
    if (tf2) return tf2->Eval(mass[0],mass[1]);
    if (tf2) return tf3->Eval(mass[0],mass[1],mass[2]);

    return constant;  
};


Bool_t PFunction::SampleMass(Double_t *mass, Int_t *) {

    if (tf1) {
	mass[0] = tf1->GetRandom();
	return kTRUE;
    } else if (batch) {
	mass[0] = GetRandom();
    }

    return kFALSE;
};
 PFunction.cc:1
 PFunction.cc:2
 PFunction.cc:3
 PFunction.cc:4
 PFunction.cc:5
 PFunction.cc:6
 PFunction.cc:7
 PFunction.cc:8
 PFunction.cc:9
 PFunction.cc:10
 PFunction.cc:11
 PFunction.cc:12
 PFunction.cc:13
 PFunction.cc:14
 PFunction.cc:15
 PFunction.cc:16
 PFunction.cc:17
 PFunction.cc:18
 PFunction.cc:19
 PFunction.cc:20
 PFunction.cc:21
 PFunction.cc:22
 PFunction.cc:23
 PFunction.cc:24
 PFunction.cc:25
 PFunction.cc:26
 PFunction.cc:27
 PFunction.cc:28
 PFunction.cc:29
 PFunction.cc:30
 PFunction.cc:31
 PFunction.cc:32
 PFunction.cc:33
 PFunction.cc:34
 PFunction.cc:35
 PFunction.cc:36
 PFunction.cc:37
 PFunction.cc:38
 PFunction.cc:39
 PFunction.cc:40
 PFunction.cc:41
 PFunction.cc:42
 PFunction.cc:43
 PFunction.cc:44
 PFunction.cc:45
 PFunction.cc:46
 PFunction.cc:47
 PFunction.cc:48
 PFunction.cc:49
 PFunction.cc:50
 PFunction.cc:51
 PFunction.cc:52
 PFunction.cc:53
 PFunction.cc:54
 PFunction.cc:55
 PFunction.cc:56
 PFunction.cc:57
 PFunction.cc:58
 PFunction.cc:59
 PFunction.cc:60
 PFunction.cc:61
 PFunction.cc:62
 PFunction.cc:63
 PFunction.cc:64
 PFunction.cc:65
 PFunction.cc:66
 PFunction.cc:67
 PFunction.cc:68
 PFunction.cc:69
 PFunction.cc:70
 PFunction.cc:71
 PFunction.cc:72
 PFunction.cc:73
 PFunction.cc:74
 PFunction.cc:75
 PFunction.cc:76
 PFunction.cc:77
 PFunction.cc:78
 PFunction.cc:79
 PFunction.cc:80
 PFunction.cc:81