KaliVeda
Toolkit for HIC analysis
mdweight.cpp
1 //Created by KVClassFactory on Thu May 7 11:02:24 2015
2 //Author: John Frankland,,,
3 
4 #include "MicroStat/mdweight.h"
5 #include "TMath.h"
6 #include "KVNucleusEvent.h"
7 #include "TRandom.h"
8 
10 
11 namespace MicroStat {
12 
13 
19 
21  {
22  // energy distribution of particle in gas
23  // arg[0] = energy/available energy
24  // par[0] = number of particles in gas
25  // par[1] = mass ratio = massTot/(massTot-mPart)
26  Double_t e = arg[0];
27  Double_t N = par[0];
28  Double_t massRat = par[1];
29 
30  Double_t val = 0.;
31  if ((e > 0) && (e * massRat < 1) && (N > 2)) {
32  val = TMath::Sqrt(e) * TMath::Power(1. - massRat * e, (3.*N - 8.) / 2.);
33  }
34  return val;
35  }
36 
37 
38 
42 
44  {
45  // find/create energy distribution for given number of particles
46  // N and mass ratio R.
47 
48  TString fn = Form("fKE_N%d_R%f", N, R);
49  TF1* f = (TF1*)fKEDist.FindObject(fn);
50  if (!f) {
51  f = new TF1("mdweight::SPKEDist", mdweight::edist, 0, 1, 2);
52  f->SetRange(0, 1.);
53  f->SetParameters((Double_t)N, R);
54  f->SetNpx(100);
55  f->SetName(fn);
56  fKEDist.Add(f);
57  }
58  return f;
59  }
60 
61 
62 
69 
70  double CosThetaDist(double* x, double* par)
71  {
72  // parameterise angular distribution as function of ratio between
73  // P(cos theta=+/-1) and P(cos theta=0)
74  // par[0] = a = P(cos theta=+/-1)
75  // par[1] = b = P(cos theta=0)
76  // x = cosTheta
77  if (abs(par[0] - par[1]) < 1.e-6) return par[1];
78 
79  double a = par[0];
80  double b = par[1];
81  double cosTheta = x[0];
82  double alpha = TMath::Pi() * cosTheta;
83  return (a - b) / 2.*(1. - TMath::Cos(alpha)) + b;
84  }
85 
86 
87 
89 
91  : fCosTheta("CosTheta", CosThetaDist, -1, 1, 2)
92  {
93  fKEDist.SetOwner();
95  log10twelve = TMath::Log(1e+12);
96  eDisp = 0.0;
97  massTot = 0.0;
98  massTot0 = 0.0;
99  px = 0.0;
100  py = 0.0;
101  pz = 0.0;
102  SetAnisotropy(1, 1);
103  }
104 
105 
106 
109 
111  {
112  // Destructor
113  }
114 
115 
116 
120 
122  {
123  // Set available energy, E, and calculate statistical weight
124  // for this event
125 
126  if (E <= 0) {
127  setAvailableEnergy(0.);
128  setWeight(0.);
129  return;
130  }
132  Double_t N = e->GetMult();
133  Double_t logmass_sum, mass_sum;
134  logmass_sum = mass_sum = 0.;
135  for (auto& n : EventIterator(e)) {
136  Double_t m = n.GetMass();
137  logmass_sum += TMath::Log(m);
138  mass_sum += m;
139  }
140  A = (3 * (N - 1) / 2.) * log2pi - TMath::LnGamma(3 * (N - 1) / 2.)
141  + 1.5 * (logmass_sum - TMath::Log(mass_sum));
142  B = (3 * N - 5) / 2.;
143 
145  setWeight(w);
146  }
147 
148 
149 
153 
155  {
156  // Call before generating an event with StatWeight::GenerateEvent
157  // using the given partition and available energy
158 
159  massTot0 = 0;
160 
161  for (auto& e : EventIterator(partition)) massTot0 += e.GetMass();
162 
164  }
165 
166 
167 
171 
173  {
174  // Called by StatWeight::GenerateEvent before generating another
175  // event using the same partition as the last
177  massTot = massTot0;
178  px = py = pz = 0.0;
179  }
180 
181 
182 
188 
190  {
191  // Called by StatWeight::GenerateEvent when adding a particle to the event
192  // N is the number of particles still to add including this one
193  //
194  // The algorithm was written by Daniel Cussol (LPC Caen, France).
195 
196  Double_t mPart = part->GetMass();
197  Double_t rR = mPart / massTot;
198  Double_t ratio;
199  if (rR < 1.) ratio = 1. / (1. - rR);
200  else ratio = 1.;
201  Double_t ec = 0.; // kinetic energy of particle
202  Double_t ppx, ppy, ppz; // components of particle momentum
203  ppx = ppy = ppz = 0;
204  if (N >= 2) {
205  Double_t p = 0.; //momentum to give particle
206  if (N > 2) {
207  // draw random KE from 1-particle distribution for given N & ratio
208  ec = eDisp * getKEdist(N, ratio)->GetRandom();
209  p = sqrt(2.*mPart * ec);
210  }
211  else {
212  // last 2 particles: share remaining available energy
213  p = sqrt(2.*(massTot - mPart) * mPart * eDisp / massTot);
214  ec = p * p / 2. / mPart;
215  }
216  Double_t ct = fCosTheta.GetRandom(-1, 1); //1. - 2.*gRandom->Rndm();
217  Double_t st = TMath::Sqrt(1. - ct * ct);
218  Double_t phi = gRandom->Rndm() * 2.*TMath::Pi();
219  ppz = ct * p;
220  ppx = st * TMath::Cos(phi) * p;
221  ppy = st * TMath::Sin(phi) * p;
222  ppx += px * rR;
223  ppy += py * rR;
224  ppz += pz * rR;
225  }
226  else if (N == 1) {
227  ppx = px;
228  ppy = py;
229  ppz = pz;
230  ec = 0;
231  }
232  part->SetMomentum(ppx, ppy, ppz);
233 
234  eDisp -= ec * ratio;
235  massTot -= mPart;
236  px -= ppx;
237  py -= ppy;
238  pz -= ppz;
239  }
240 
241 
242 }/* namespace MicroStat */
243 
int Int_t
#define f(i)
#define e(i)
double Double_t
#define N
winID w
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
Class for iterating over nuclei in events accessed through base pointer/reference.
Abstract base class container for multi-particle events.
Definition: KVEvent.h:67
Description of properties and kinematics of atomic nuclei.
Definition: KVNucleus.h:123
void SetMomentum(const TVector3 *v)
Definition: KVParticle.h:545
Double_t GetMass() const
Definition: KVParticle.h:577
void Add(TObject *obj) override
TObject * FindObject(const char *name) const override
void SetOwner(Bool_t enable=kTRUE) override
void setAvailableEnergy(Double_t e)
Definition: StatWeight.h:34
Double_t GetAvailableEnergy() const
Definition: StatWeight.h:48
void setWeight(Double_t w)
Definition: StatWeight.h:30
Calculate molecular dynamics ensemble weights for events .
Definition: mdweight.h:20
void resetGenerateEvent()
Definition: mdweight.cpp:172
Double_t log10twelve
Definition: mdweight.h:22
void initGenerateEvent(KVEvent *partition)
Definition: mdweight.cpp:154
virtual void SetWeight(KVEvent *e, Double_t E)
Definition: mdweight.cpp:121
Double_t eDisp
Definition: mdweight.h:23
TF1 * getKEdist(Int_t, Double_t)
function used to draw random CosTheta values
Definition: mdweight.cpp:43
Double_t massTot
Definition: mdweight.h:23
static Double_t edist(Double_t *, Double_t *)
Definition: mdweight.cpp:20
Double_t massTot0
Definition: mdweight.h:23
virtual ~mdweight()
Destructor.
Definition: mdweight.cpp:110
virtual void nextparticleGenerateEvent(Int_t, KVNucleus *)
Definition: mdweight.cpp:189
void SetAnisotropy(double a, double b)
Definition: mdweight.h:38
KVHashList fKEDist
Definition: mdweight.h:24
Double_t log2pi
Definition: mdweight.h:22
virtual Double_t GetRandom(Double_t xmin, Double_t xmax, TRandom *rng=nullptr, Option_t *opt=nullptr)
Double_t Rndm() override
Expr< UnaryOp< Sqrt< T >, SMatrix< T, D, D2, R >, T >, T, D, D2, R > sqrt(const SMatrix< T, D, D2, R > &rhs)
RVec< PromoteType< T > > abs(const RVec< T > &v)
Double_t x[n]
const Int_t n
double CosThetaDist(double *x, double *par)
Definition: mdweight.cpp:70
Double_t Exp(Double_t x)
Double_t Power(Double_t x, Double_t y)
constexpr Double_t E()
Double_t Log(Double_t x)
Double_t Sqrt(Double_t x)
Double_t Cos(Double_t)
constexpr Double_t Pi()
constexpr Double_t R()
Double_t LnGamma(Double_t z)
Double_t Sin(Double_t)
constexpr Double_t TwoPi()
TMarker m
TArc a
ClassImp(TPyArg)