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

#ifndef _PANGULARDISTRIBUTION_H_
#define _PANGULARDISTRIBUTION_H_


#include "TF1.h"
#include "TF2.h"
#include "TGraph.h"
#include "TSpline.h"
#include "PDistribution.h"
#include "PKinematics.h"

#define MAX_ANG_NUM 10


class PAngularDistribution : public PDistribution  {
  
 public:
    PAngularDistribution();
    PAngularDistribution(const Char_t *id, const Char_t *de);
    
    PDistribution* Clone(const char *delme=NULL) const;
    
    Bool_t Init(void);
    Bool_t Prepare(void);
    Bool_t Finalize(void);
    Bool_t IsNotRejected(void);
    Bool_t CheckAbort(void);
    Bool_t SampleAngle(void);

    void SetAngleFunction(TF1 *f) {angles1=f;};
    void SetAngleFunction(TF2 *f) {angles2=f;};
    void SetAngleFunction(TGraph *f, Bool_t useSpline=kFALSE, 
                          Bool_t useSymmetry=kFALSE) {
	anglesg = f;
	spline  = useSpline;
	reflection_symmetry = useSymmetry;
	if (spline) g_spline = new TSpline3("", f);
    };

    void SetAngleFunction(TH1 *f) {anglesh = f;};

    void SetRotate(Bool_t t)  {rotate = t;};
    void NeverAbort(Bool_t t) {never_abort = t;}; //Avoid to re-sample the complete reaction chain
    void ForceRejectionMethod(Bool_t t) {always_reject = t;};

    void Print(const Option_t *delme=NULL) const;  //Debug info

    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

    virtual double SamplePolarAngle(double r = 0);
    Bool_t direct_sampling_possible, direct_sampling_done; //Try to use direct sampling and not rejection

 protected:
  
    TF1       *angles1;
    TF2       *angles2;
    TH1       *anglesh;
    TGraph    *anglesg;
    TSpline3  *g_spline;
    PParticle *reference;
    PParticle *base_reference;
    PParticle *primary;
    PParticle *parent;
    PParticle *align;
    PParticle *mass_reference, *daughter[MAX_ANG_NUM];
    PParticle *beam;
    PParticle *target;
    PParticle *ang_reference;
    int    n_daughters;
    Bool_t check_abort, never_abort, always_reject;
    Bool_t rotate;
    Bool_t align_is_daughter;
    Bool_t reflection_symmetry; //use symmetry around theta=90°
    Bool_t spline;

    PParticle primary_tmp, reference_tmp,
	ang_tmp;                          //for boosting and rotation
    Bool_t Rotate(Int_t);                 //Do temporary boosting and rotation
    Bool_t RotateBack(Int_t);             //Do temporary boosting and rotation

    Double_t q_value;

    Double_t weight_max;

    ClassDef(PAngularDistribution, 0) //Multi-purpose angular distributions

};

#endif


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