// Author: Romain Holzmann
// Written: 28.04.00
// Revised: 14.08.00 MK
// Revised: 05.09.05 RH
// Revised: 28.03.06 RH
// Revised: 02.02.07 RH
// Revised: 21.02.07 RH
// PFireball Class Header

#ifndef _PFireball_H_
#define _PFireball_H_

#include "PF2.h"
#include "TH2F.h"
#include "PParticle.h"
#include "PChannel.h"
#include "PChannelModel.h"
#include "PFunction.h"
#include "PAdaptiveMeshN.h"

class PFireball: public PParticle {

 protected:

    int prodId;    // product id
    float T1;      // temperature of component 1 (in GeV)
    float T2;      // temperature of component 2 (in GeV)
    float frac;    // fraction of component 1  (0 < frac < 1) 
    float blast;   // radial blast velocity  (0 < blast < 1)
    float power1;  // power of p**n term in p**n exp(-E/T) sampling at 0 deg
    float power2;  // power of p**n term at 90 deg
    float A2;      // polar anisotropy (dN/dOmega = 1 + A2*cost**2 + A4*cost**4)
    float A4;      // 
    float v1;      // directed flow parameter at mid-rapidity
    float v2;      // elliptic flow (squeeze out) at mid-rapidity
    float Ap;      // projectile mass
    float At;      // target mass
    float prob;    // particle production probability per participant nucleon
    float bmin;    // min impact parameter 
    float bmax;    // max impact parameter
    float meanN;   // mean multiplicity 
    int   nProd;   // number of product particles
    bool  flag;    //! if set, sample impact parameter first, then Poisson Npart
    float mt_fac;  //! mt scaling of mass distribution
    double sig;    //! sigma of gaussian dNdy distribution
    TF1  *rapidity_function; //!Function of dNdy distribution

    int spect;     //! if set to 0 participant, if set to 1 target-like spectator,
    //  if set to 2 projectile-like spectator

    PF2 *fE;       //! energy sampling function (true Boltzmann) x BW(M)
    TF1 *fE_1d;    //!
    PF2 *fE1;      //! energy sampling function with E*sqrt(p) x BW(M)
    TF1 *fE1_1d;   //!
    PF2 *fE2;      //! energy sampling function with E*p**3 x BW(M)
    TF1 *fE2_1d;   //!
    PF2 *fE3;      //! energy sampling function with p**n x W(Theta)
    TF1 *fA;       //! polar angle sampling function
    TF1 *fMt;      //! mt sampling function
    TH2F *fHisto;  //! dN2/dEdTheta sampling histogram
    bool trueThermal; //! thermal sampling flag
    Int_t npx, npy; //! Granularity for all 2-dim histograms

    PParticle **part; //! array of particle pointers
    bool quasistable; //! long-lived or stable particle flag

    PChannelModel *model;  //! Primary model for emitted particle prodId
    int didx_old;          //! cache for didx
    int sample_option;     //! option for a rotation in the E-M-plane

    int mesh_option;     //! option to use the adaptive mesh
    PFunction *pfE;      //!Envelope for thermal channel model E
    PAdaptiveMeshN *afE; //!Mesh for  thermal channel model E

    Float_t y0;          // mid-rapidity of source 

 public:
    PFireball(const char *particle, float AGeV, float t1, float t2=0.0, float f=1.0,
	      float b=0.0, float a2=0.0, float a4=0.0, float w1=0.0, float w2=0.0, int sp=0);

    void setTemperature(float t1, float t2, float f, int id=0) {
	T1 = t1; 
	T2 = t2; 
	frac = f;
	updateFunctions(id);
	if (mt_fac > 0.) 
	    mt_fac = mtIntegral(makeStaticData()->GetParticleMass(prodId),T1);
    }

    //Rapidity sampling:
    void setSigma(double s) {
	SetSigma(s);
    } 
    void SetSigma(double s) {
	sig = s;
    } 
    void SetRapidityDistribution(TF1 *f) {
	rapidity_function = f;
    };

    void setBlast(float b, int id=0) {
	blast = b;
	updateFunctions(id);
    }
    void setAnisotropy(float a2, float a4, int id=0) {
	A2 = a2;
	A4 = a4; 
	updateFunctions(id);
    }
    void setFlow(float a, float b) {
	v1 = a; 
	v2 = b;
    }

    Double_t AvApart(Double_t ap, Double_t at, Double_t bn, Double_t bx);
    Double_t AvApart(Double_t ap, Double_t at) {
	return (ap*pow(at,0.667) + at*pow(ap,0.667))
	    /pow((pow(ap,0.333)+pow(at,0.333)),2);  // average Apart
    }
    void setRandomB(float ap, float at, float p=0., float bn=0., float bx=20.) {
	Ap = ap; 
	At = at; 
	prob = p; 
	flag = 1; 
	bmin = bn; 
	bmax = bx;
	if (prob <= 0.) 
	    prob = meanN/AvApart(Ap, At);
	meanN = prob*AvApart(Ap, At, bmin, bmax);
	if (bmax > 1.14*(pow((double)Ap,(double)0.333) + pow((double)At,(double)0.333))+2.)
	    bmax = 1.14*(pow((double)Ap,(double)0.333) + pow((double)At,(double)0.333)+2.);
	if (bmin > bmax) {
	    float temp = bmin; 
	    bmin = bmax; 
	    bmax = temp;
	}
    }
    void setMeanN(float mN) {
	if (mN >= 0.) meanN = mN;
    }
    void setSpectator(int sp){
	spect=sp;
    }

    bool IsRandomB() {return flag;}
    bool IsRandomN() {return meanN>0. ? 1 : 0;}

    int getParticleId() {return prodId;}
    float getT1()       {return T1;}
    float getT2()       {return T1;}
    float getFrac()     {return frac;}
    float getBlast()    {return blast;}
    float getA2()       {return A2;}
    float getA4()       {return A4;}
    float getV1()       {return v1;}
    float getV2()       {return v2;}
    int  getSpectator() {return spect;}
    PF2 *getFuncE()     {return fE;}
    PF2 *getFuncE1()    {return fE1;}
    PF2 *getFuncE2()    {return fE2;}
    PF2 *getFuncE3()    {return fE3;}
    TF1 *getFuncA()     {return fA;}
    TF1 *getFuncMt()    {return fMt;}
    void setHisto(TH2F *pH) {
	fHisto = pH;
	A2 = A4 = 0.;
    }
    TH2F *getHisto() {return fHisto;}

    void SetNpx(Int_t my_npx);
    void SetNpy(Int_t my_npy);
    void SetEpsilon(Double_t e);

    void RotateSamplingPlane(void) {
	sample_option = 1;
	updateFunctions();
    }
    void UseMesh(void) {
	mesh_option = 1;
    }


    void sampleECM(Double_t &E, Double_t &M, int didx);
  
    void sampleECM1(Double_t &E, Double_t &M, int didx) {
	if (fE1) {
	    if (didx != didx_old) {
		didx_old = didx; //prevent random initialization each time
		if (didx < 0) 
		    fE1->SetParameter(5, -1.1);
		else
		    fE1->SetParameter(5, (double) didx);
	    }
	    fE1->GetRandom2(E, M);
	} else if (fE1_1d) {
	    E = fE1_1d->GetRandom();
	} else {
	    Error("sampleECM1", "fE1 not found");
	}
    }

    void sampleECM2(Double_t &E, Double_t &M, int didx) {
	if (fE2) {
	    if (didx != didx_old) {
		didx_old = didx; //prevent random initialization each time
		if (didx<0) 
		    fE2->SetParameter(5, -1.1);
		else
		    fE2->SetParameter(5, (double) didx);
	    }
	    fE2->GetRandom2(E, M);
	} else if (fE2_1d) {
	    E = fE2_1d->GetRandom();
	} else {
	    Error("sampleECM2", "fE2 not found");
	}
    }
  
    void sampleECM3(Double_t &E, Double_t &Theta) {
	fE3->GetRandom2(E, Theta);
    }

    double sampleThetaCM() {return fA->GetRandom();}
    double sampleMt()      {return fMt->GetRandom();}
    void samplePartCM(double &px, double &py, double &pz, double &E, int didx);
    float sampleB() const ;
    int sampleNProd();
    int sampleNProd(float b);
    int getLastNProd() {return nProd;}
    int IsFireball()   {return 1;}

    PChannel *makeChannel(Int_t nMax, Float_t nAverage=0.);
 
    void setTrueThermal(Bool_t flag=kTRUE) {
	trueThermal = flag;
    } 
    void setMtScaling() {
	mt_fac = mtIntegral(makeStaticData()->GetParticleMass(prodId),T1);
    }
    float mtScale(double m) {
	return mt_fac>0. ? mtIntegral(m,T1)/mt_fac : 1.;
    }
    virtual void Print(const Option_t *delme="") const;
    void printAverages() const ;
    virtual ~PFireball() {
	delete fE;
	delete fE_1d;
	delete fE1;
	delete fE1_1d;
	delete fE2;
	delete fE2_1d;
	delete fA;
	delete fMt;
    }
    float mtIntegral(double mass, float temperature);

    void SetW(double w=1.) {
	if (*(makeStaticData()->GetBatchValue("_system_weight_version"))) {
	    Info("SetW", "Use old weighting method (pure chain based)");
	}
	*(makeStaticData()->GetBatchValue("_system_weight_version")) = 0.;      
	PParticle::SetW(w);
    };

 protected:
    void updateFunctions(int id = 0);
    void setToMidrapidity(float AGeV);
    float Npar(float ap, float at, float b);
    float NparSmeared(float ap, float at, float b) const ;

    ClassDef(PFireball, 1) // Pluto Fireball Class

};
#endif // _PFireball_H_


 PFireball.h:1
 PFireball.h:2
 PFireball.h:3
 PFireball.h:4
 PFireball.h:5
 PFireball.h:6
 PFireball.h:7
 PFireball.h:8
 PFireball.h:9
 PFireball.h:10
 PFireball.h:11
 PFireball.h:12
 PFireball.h:13
 PFireball.h:14
 PFireball.h:15
 PFireball.h:16
 PFireball.h:17
 PFireball.h:18
 PFireball.h:19
 PFireball.h:20
 PFireball.h:21
 PFireball.h:22
 PFireball.h:23
 PFireball.h:24
 PFireball.h:25
 PFireball.h:26
 PFireball.h:27
 PFireball.h:28
 PFireball.h:29
 PFireball.h:30
 PFireball.h:31
 PFireball.h:32
 PFireball.h:33
 PFireball.h:34
 PFireball.h:35
 PFireball.h:36
 PFireball.h:37
 PFireball.h:38
 PFireball.h:39
 PFireball.h:40
 PFireball.h:41
 PFireball.h:42
 PFireball.h:43
 PFireball.h:44
 PFireball.h:45
 PFireball.h:46
 PFireball.h:47
 PFireball.h:48
 PFireball.h:49
 PFireball.h:50
 PFireball.h:51
 PFireball.h:52
 PFireball.h:53
 PFireball.h:54
 PFireball.h:55
 PFireball.h:56
 PFireball.h:57
 PFireball.h:58
 PFireball.h:59
 PFireball.h:60
 PFireball.h:61
 PFireball.h:62
 PFireball.h:63
 PFireball.h:64
 PFireball.h:65
 PFireball.h:66
 PFireball.h:67
 PFireball.h:68
 PFireball.h:69
 PFireball.h:70
 PFireball.h:71
 PFireball.h:72
 PFireball.h:73
 PFireball.h:74
 PFireball.h:75
 PFireball.h:76
 PFireball.h:77
 PFireball.h:78
 PFireball.h:79
 PFireball.h:80
 PFireball.h:81
 PFireball.h:82
 PFireball.h:83
 PFireball.h:84
 PFireball.h:85
 PFireball.h:86
 PFireball.h:87
 PFireball.h:88
 PFireball.h:89
 PFireball.h:90
 PFireball.h:91
 PFireball.h:92
 PFireball.h:93
 PFireball.h:94
 PFireball.h:95
 PFireball.h:96
 PFireball.h:97
 PFireball.h:98
 PFireball.h:99
 PFireball.h:100
 PFireball.h:101
 PFireball.h:102
 PFireball.h:103
 PFireball.h:104
 PFireball.h:105
 PFireball.h:106
 PFireball.h:107
 PFireball.h:108
 PFireball.h:109
 PFireball.h:110
 PFireball.h:111
 PFireball.h:112
 PFireball.h:113
 PFireball.h:114
 PFireball.h:115
 PFireball.h:116
 PFireball.h:117
 PFireball.h:118
 PFireball.h:119
 PFireball.h:120
 PFireball.h:121
 PFireball.h:122
 PFireball.h:123
 PFireball.h:124
 PFireball.h:125
 PFireball.h:126
 PFireball.h:127
 PFireball.h:128
 PFireball.h:129
 PFireball.h:130
 PFireball.h:131
 PFireball.h:132
 PFireball.h:133
 PFireball.h:134
 PFireball.h:135
 PFireball.h:136
 PFireball.h:137
 PFireball.h:138
 PFireball.h:139
 PFireball.h:140
 PFireball.h:141
 PFireball.h:142
 PFireball.h:143
 PFireball.h:144
 PFireball.h:145
 PFireball.h:146
 PFireball.h:147
 PFireball.h:148
 PFireball.h:149
 PFireball.h:150
 PFireball.h:151
 PFireball.h:152
 PFireball.h:153
 PFireball.h:154
 PFireball.h:155
 PFireball.h:156
 PFireball.h:157
 PFireball.h:158
 PFireball.h:159
 PFireball.h:160
 PFireball.h:161
 PFireball.h:162
 PFireball.h:163
 PFireball.h:164
 PFireball.h:165
 PFireball.h:166
 PFireball.h:167
 PFireball.h:168
 PFireball.h:169
 PFireball.h:170
 PFireball.h:171
 PFireball.h:172
 PFireball.h:173
 PFireball.h:174
 PFireball.h:175
 PFireball.h:176
 PFireball.h:177
 PFireball.h:178
 PFireball.h:179
 PFireball.h:180
 PFireball.h:181
 PFireball.h:182
 PFireball.h:183
 PFireball.h:184
 PFireball.h:185
 PFireball.h:186
 PFireball.h:187
 PFireball.h:188
 PFireball.h:189
 PFireball.h:190
 PFireball.h:191
 PFireball.h:192
 PFireball.h:193
 PFireball.h:194
 PFireball.h:195
 PFireball.h:196
 PFireball.h:197
 PFireball.h:198
 PFireball.h:199
 PFireball.h:200
 PFireball.h:201
 PFireball.h:202
 PFireball.h:203
 PFireball.h:204
 PFireball.h:205
 PFireball.h:206
 PFireball.h:207
 PFireball.h:208
 PFireball.h:209
 PFireball.h:210
 PFireball.h:211
 PFireball.h:212
 PFireball.h:213
 PFireball.h:214
 PFireball.h:215
 PFireball.h:216
 PFireball.h:217
 PFireball.h:218
 PFireball.h:219
 PFireball.h:220
 PFireball.h:221
 PFireball.h:222
 PFireball.h:223
 PFireball.h:224
 PFireball.h:225
 PFireball.h:226
 PFireball.h:227
 PFireball.h:228
 PFireball.h:229
 PFireball.h:230
 PFireball.h:231
 PFireball.h:232
 PFireball.h:233
 PFireball.h:234
 PFireball.h:235
 PFireball.h:236
 PFireball.h:237
 PFireball.h:238
 PFireball.h:239
 PFireball.h:240
 PFireball.h:241
 PFireball.h:242
 PFireball.h:243
 PFireball.h:244
 PFireball.h:245
 PFireball.h:246
 PFireball.h:247
 PFireball.h:248
 PFireball.h:249
 PFireball.h:250
 PFireball.h:251
 PFireball.h:252
 PFireball.h:253
 PFireball.h:254
 PFireball.h:255
 PFireball.h:256
 PFireball.h:257
 PFireball.h:258
 PFireball.h:259
 PFireball.h:260
 PFireball.h:261
 PFireball.h:262
 PFireball.h:263
 PFireball.h:264
 PFireball.h:265
 PFireball.h:266
 PFireball.h:267
 PFireball.h:268
 PFireball.h:269
 PFireball.h:270
 PFireball.h:271
 PFireball.h:272
 PFireball.h:273
 PFireball.h:274
 PFireball.h:275
 PFireball.h:276