// Author: I. Froehlich
// Written: 27.5.2007
// Revised: 

#ifndef _PDALITZDECAY_H_
#define _PDALITZDECAY_H_

#include "TF1.h"
#include "TF2.h"
#include "PChannelModel.h"
#include "PDynamicData.h"
#include "PKinematics.h"

class PDalitzDecay : public PChannelModel  {
  
 public:
    PDalitzDecay();
    PDalitzDecay(const Char_t *id, const Char_t *de, Int_t key);
    PDistribution *Clone(const char *delme=NULL) const;

    Bool_t Init(void);
    Bool_t SampleMass(void);
    Bool_t SampleMass(Double_t *mass, Int_t *didx=NULL);

    Bool_t GetWidth(Double_t mass, Double_t *width, Int_t didx=-1);

    using PDistribution::GetWeight;  
    Double_t GetWeight(Double_t *mass, Int_t *didx=NULL);
    Double_t GetWeight(void);
    int GetDepth(int i=0);

    Bool_t FreezeOut(void);

    virtual Double_t Eval(Double_t x, Double_t y = 0, Double_t z = 0, Double_t t = 0) const;
    virtual Double_t EvalPar(const Double_t *x, const Double_t *params);
    //TF1 wrapper

    void SetUseQED(int t) {
	useQED=t;
    };
    virtual void Print(const Option_t *delme=NULL) const ;  //Debug info
    Double_t draw_parent_mass;

 protected:
  
    PParticle *parent, *dilepton, *other;

    long double alpha;
    double mass_pi0;
    double mass_n;
    double mass_eta;
    double mass_p;
    double p1;

    double mass_e, mass_ee;
    
    double p2;
    double p3;
    double mass_x;   // mass of second (non dilepton) product
    double mass_parent;
    int flag;    // case flag
    int sw;      //0 for ee, 1 for mumu
    double ml;   // dilepton mass threshold

    int rejection_flag; //Case flag for the mass sampling

    int pi0, eta, eta_prime, w, Delta_0, Delta_plus, phi, S11_0, S11_plus; //PIDs
    int parent_id,dilepton_pid,other_pid;
    int dilepton_position;  //is dilepton particle 1 or 2?
    int others_position;
    double photon_br;  //PhotonBR

    int useQED; //use QED FF and not VMD
    int flatMD; // for test purposes sample a flat mass distribution

    PMesh *integral;                 //parent-mass dependent integral
    PChannelModel *formfactor_model; //form factor object


    //The following private methods are copied from PData
    //they are used here by the official wrapper funcions
    virtual double dGdM(const int &id, const double &m, const double &ecm);
    double FDalitz(const int &id, const double &m, double ecm);
    void sampleMD(const double &ecm, const int &id, 
		  double &m, const double &m1);
    double PhotonBR(const int &id);
 
    ClassDef(PDalitzDecay, 0)  // Dalitz decays "a -> dilepton/dimuon + b"
};

#endif


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