Bug corrected.
[u/mrichter/AliRoot.git] / EVGEN / AliGenGrayParticles.cxx
CommitLineData
930c0bb5 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
17$Log$
116cbefd 18Revision 1.5 2003/01/07 14:11:43 morsch
19Comminication with gray particle model and collision geometry added.
20
8b87aa60 21Revision 1.4 2003/01/06 10:09:57 morsch
22Use AliGrayParticleModel.
23
c27c8b4d 24Revision 1.3 2002/12/02 10:02:40 morsch
25Corrections introduced by F. Silker:
26- SetBetaSource
27- Particle type according to charge.
28
ca33591a 29Revision 1.2 2002/10/14 14:55:35 hristov
30Merging the VirtualMC branch to the main development branch (HEAD)
31
b9d0a01d 32Revision 1.1.2.1 2002/10/10 16:40:08 hristov
33Updating VirtualMC to v3-09-02
34
35Revision 1.1 2002/10/08 13:53:17 morsch
36Gray particle generator, first commit.
37
930c0bb5 38*/
39
40/*
41 Generator for gray nucluons in pA interactions.
42 Source is modelled by a relativistic Maxwell distributions.
43 Original code by Ferenc Sikler <sikler@rmki.kfki.hu>
44 */
116cbefd 45
46#include <TDatabasePDG.h>
47#include <TPDGCode.h>
48
49#include "AliCollisionGeometry.h"
930c0bb5 50#include "AliGenGrayParticles.h"
c27c8b4d 51#include "AliGrayParticleModel.h"
930c0bb5 52
53 ClassImp(AliGenGrayParticles)
54
55 AliGenGrayParticles::AliGenGrayParticles():AliGenerator(-1)
56{
57// Default constructor
8b87aa60 58 fGrayParticleModel = 0;
59 fCollisionGeometry = 0;
930c0bb5 60}
61
62AliGenGrayParticles::AliGenGrayParticles(Int_t npart)
63 :AliGenerator(npart)
64{
65// Constructor
66 fName = "GrayParticles";
67 fTitle = "Generator for gray particles in pA collisions";
68 SetPmax();
69 SetTarget();
70 SetNominalCmsEnergy();
ca33591a 71 SetCharge();
930c0bb5 72 SetTemperature();
ca33591a 73 SetBetaSource();
8b87aa60 74 fGrayParticleModel = new AliGrayParticleModel();
75 fCollisionGeometry = 0;
930c0bb5 76}
77
78//____________________________________________________________
79AliGenGrayParticles::~AliGenGrayParticles()
80{
81// Destructor
8b87aa60 82 delete fGrayParticleModel;
930c0bb5 83}
84
85
86void AliGenGrayParticles::Init()
87{
88 //
89 // Initialization
90 //
91 Float_t kMass = TDatabasePDG::Instance()->GetParticle(kProton)->Mass();
92 fMomentum = fCMS/2. * fZTarget / fATarget;
93 fBeta = fMomentum / TMath::Sqrt(kMass * kMass + fMomentum * fMomentum);
94}
95
96
97void AliGenGrayParticles::Generate()
98{
99 //
100 // Generate one event
101 //
8b87aa60 102 //
103 // Communication with Gray Particle Model
104 //
105 Int_t np, nn;
106
107 Float_t b = fCollisionGeometry->ImpactParameter();
108 printf("AliGenGrayParticles: Impact parameter from Collision Geometry %f \n", b);
109
110 fGrayParticleModel->GetNumberOfGrayNucleons(fCollisionGeometry, np, nn);
111
112 //
930c0bb5 113 Float_t p[3];
114 Float_t origin[3] = {0., 0., 0.};
115 Float_t polar [3] = {0., 0., 0.};
116 Int_t nt, i;
8b87aa60 117 for(i = 0;i < fNpart; i++) {
ca33591a 118 Int_t kf;
119 if(fCharge==1) kf = kProton;
120 else kf = kNeutron;
121 GenerateSlow(fCharge, fTemperature, fBetaSource, p);
930c0bb5 122
123 SetTrack(fTrackIt, -1, kf, p, origin, polar,
124 0., kPNoProcess, nt, 1.);
125
126 KeepTrack(nt);
127 }
128}
129
130
131
132
133void AliGenGrayParticles::GenerateSlow(Int_t charge, Double_t T, Double_t beta, Float_t* q)
134/*
135 Emit a slow nucleon with "temperature" T [GeV],
136 from a source moving with velocity beta
137 Three-momentum [GeV/c] is given back in q[3]
138*/
139
140{
141 Double_t m, pmax, p, f, theta, phi;
142
143 TDatabasePDG * pdg = TDatabasePDG::Instance();
144 const Double_t kMassProton = pdg->GetParticle(kProton) ->Mass();
145 const Double_t kMassNeutron = pdg->GetParticle(kNeutron)->Mass();
146
147 /* Select nucleon type */
148 if(charge == 0) m = kMassNeutron;
149 else m = kMassProton;
150
151 /* Momentum at maximum of Maxwell-distribution */
152
153 pmax = TMath::Sqrt(2*T*(T+sqrt(T*T+m*m)));
154
155 /* Try until proper momentum */
156 /* for lack of primitive function of the Maxwell-distribution */
157 /* a brute force trial-accept loop, normalized at pmax */
158
159 do
160 {
161 p = Rndm() * fPmax;
162 f = Maxwell(m, p, T) / Maxwell(m , pmax, T);
163 }
164 while(f < Rndm());
165
166 /* Spherical symmetric emission */
167 theta = TMath::ACos(2. * Rndm() - 1.);
168 phi = 2. * TMath::Pi() * Rndm();
169
170 /* Determine momentum components in system of the moving source */
171 q[0] = p * TMath::Sin(theta) * TMath::Cos(phi);
172 q[1] = p * TMath::Sin(theta) * TMath::Sin(phi);
173 q[2] = p * TMath::Cos(theta);
174
175 /* Transform to system of the target nucleus */
176 /* beta is passed as negative, because the gray nucleons are slowed down */
177 Lorentz(m, -beta, q);
178
179 /* Transform to laboratory system */
180 Lorentz(m, fBeta, q);
181}
182
183Double_t AliGenGrayParticles::Maxwell(Double_t m, Double_t p, Double_t T)
184{
185/* Relativistic Maxwell-distribution */
186 Double_t ekin;
187 ekin = TMath::Sqrt(p*p+m*m)-m;
188 return (p*p * exp(-ekin/T));
189}
190
191
192void AliGenGrayParticles::Lorentz(Double_t m, Double_t beta, Float_t* q)
193{
194/* Lorentz transform in the direction of q[2] */
195
196 Double_t gamma = 1/sqrt(1-beta*beta);
197 Double_t energy = sqrt(m*m + q[0]*q[0] + q[1]*q[1] + q[2]*q[2]);
198 q[2] = gamma * (q[2] + beta*energy);
199}
200
201
202
203
204
205
206