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

#ifndef _PHADRONDECAYM1_H_
#define _PHADRONDECAYM1_H_

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

class PHadronDecayM1 : public PHadronDecay  {
   
 public:

    PHadronDecayM1();
    PHadronDecayM1(const Char_t *id, const Char_t *de, Int_t key);
    PDistribution *Clone(const char*delme=NULL) const;

    Bool_t Init(void);
    Bool_t Prepare(void);
    void   SubPrint(Int_t opt) const;
    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);

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

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

    Bool_t CheckAbort(void) {
	return abort;
    };

    Bool_t IsNotRejected(void) {
	return !abort;
    };

 protected:

    int unstable_id, stable_id;
    int unstable_position, stable_position;
    Double_t unstable_mass, unstable_ml; //Unstable mass pole, threshold
    Double_t unstable_dynamic_mass;      //sampled unstable mass
    Double_t stable_mass;
    bool sampleM1(const double &ecm);
    Double_t scale;
    double BWWeight(const int &i1, const double &m, 
		    const double &m1, const double &m2, int didx_local1=-1, 
		    int i2=0, int didx_local2=-1);
    double maxBWWeight(const int &i1, const double &m, const double &lower,
		       const double &upper, double &max1, const double &m2, int didx_local1=-1, 
		       int i2=0, int didx_local2=-1);

    PParticle *parent, *daughter1, *daughter2;
    PChannelModel *model1, *model2;
    int didx1, didx2, didx_unstable;

    Bool_t abort;

    ClassDef(PHadronDecayM1, 0)  // Hadron decay in 1 unstable and 1 stable product
};

#endif


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