/////////////////////////////////////////////////////////////////////
//
// Input:  the mass q (not squared - see SECONDARY_MODELS)
// Output: the form factor FF squared
//
// This class can be used in 2 modes:
//
// i)  either one has to set the vector meson mass,
//     the the following equation is used:
//       FF = m_V^2 / (m_V^2 - q^2)
//
// ii) or one can use a self-defined equation using the 
//     PBatch syntax
//     in this case the batch variables "_q" and "_q2"
//     are the dilepton mass (resp. squared)
//     The equation has to calculate _ff2, the form factor
//     squared. Example:
//
//     AddEquation("_ff2 = 0.17918225/( (0.4225- _q2)*(0.4225- _q2) + 0.000676)");
//
//     reproduces the Pluto build-in VMD function of Landsberg.
//
//
//                                  Author:  I. Froehlich
/////////////////////////////////////////////////////////////////////


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

#include "PSimpleVMDFF.h"


ClassImp(PSimpleVMDFF)

PSimpleVMDFF::PSimpleVMDFF() {
};

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

    dilepton = dilepton2 = parent = NULL;

    vector_meson_mass2 = -1;
    batch = NULL;
};

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

Bool_t PSimpleVMDFF::AddEquation(const char *command) {
    if (!batch) batch = new PBatch();

    vq   = makeStaticData()->GetBatchValue("_q"); 
    vq2  = makeStaticData()->GetBatchValue("_q2"); 
    vff2 = makeStaticData()->GetBatchValue("_ff2"); 

    return batch->AddCommand(command);
}

Bool_t PSimpleVMDFF::Init(void) {

    dilepton = GetParticle("dilepton");
    if (!dilepton) {
	dilepton = GetParticle("dimuon");
    }
    if (!dilepton) {
	ep = GetParticle("e+");
	em = GetParticle("e-");
    }
    if (!dilepton && !(ep && em) ) {
	Error("Init", "No dilepton found");
	return kFALSE;
    }

    //double Dalitz?
    dilepton2 = GetParticle("dilepton");
    if (!dilepton2) {
	dilepton2 = GetParticle("dimuon");
    }

    parent = GetParticle("parent");
    if (!parent)  {
	    Error("Init", "No parent found");
	    return kFALSE;
    }

    if (vector_meson_mass2<0 && !batch) {
	Error("Init", "Vector meson mass OR eqn. must be initialized");
	return kFALSE;
    } 

    return kTRUE;    
};


Double_t PSimpleVMDFF::GetWeight(void) {

    Double_t q = 0;
    if (dilepton)
	q = dilepton->M();
    else {
	TLorentzVector dil = (*(TLorentzVector*)ep)+(*(TLorentzVector*)em);
	q = dil.M();
    }
	
    Double_t pmass = parent->M();
    Double_t ff = GetWeight(q, pmass);

    if (dilepton2) {
	Double_t q = dilepton2->M();
	ff *= GetWeight(q,pmass);
    }

    return ff;
};

Double_t PSimpleVMDFF::GetWeight(Double_t *mass, Int_t *) {
    Double_t q2 = mass[0]*mass[0];

    if (batch) {	
	*vq  = mass[0];
	*vq2 = q2;
	batch->Execute();
	return *vff2;
    }

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