New code from Piergiorgio added
[u/mrichter/AliRoot.git] / ZDC / AliGenZDC.cxx
CommitLineData
68ca986e 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$
c0ceba4c 18Revision 1.1 2000/07/10 13:58:01 fca
19New version of ZDC from E.Scomparin & C.Oppedisano
20
68ca986e 21Revision 1.7 2000/01/19 17:17:40 fca
22
23Revision 1.6 1999/09/29 09:24:35 fca
24Introduction of the Copyright and cvs Log
25
26*/
27#include <TRandom.h>
28#include <TLorentzVector.h>
29#include <TVector3.h>
30
31#include "AliGenZDC.h"
32#include "AliConst.h"
33#include "AliPDG.h"
34#include "AliRun.h"
35
36ClassImp(AliGenZDC)
37
38//_____________________________________________________________________________
39AliGenZDC::AliGenZDC()
40 :AliGenerator()
41{
42 //
43 // Default constructor
44 //
45 fIpart = 0;
46}
47
48//_____________________________________________________________________________
49AliGenZDC::AliGenZDC(Int_t npart)
50 :AliGenerator(npart)
51{
52 //
53 // Standard constructor
54 //
55 fName = "AliGenZDC";
56 fTitle = "Generation of Test Particles for ZDCs";
57 fIpart = kNeutron;
58 fCosx = 0.;
59 fCosy = 0.;
60 fCosz = 1.;
61 fPseudoRapidity = 0.;
62 fFermiflag = 1;
63 // LHC values for beam divergence and crossing angle
64 fBeamDiv = 0.000032;
65 fBeamCrossAngle = 0.0001;
66 fBeamCrossPlane = 2;
67}
68
69//_____________________________________________________________________________
70void AliGenZDC::Init()
71{
72 printf(" Initializing AliGenZDC\n");
73 printf(" Fermi flag = %d, Beam Divergence = %f, Crossing Angle "
74 "= %f, Crossing Plane = %d\n\n", fFermiflag, fBeamDiv, fBeamCrossAngle,
75 fBeamCrossPlane);
76 //Initialize Fermi momentum distributions for Pb-Pb
77 FermiTwoGaussian(207.,82.,fPp,fProbintp,fProbintn);
78}
79
80//_____________________________________________________________________________
81void AliGenZDC::Generate()
82{
83 //
84 // Generate one trigger (n or p)
85 //
c0ceba4c 86 Int_t i;
87
68ca986e 88 Double_t mass, pLab[3], balp0, balp[3], ddp[3], dddp0, dddp[3];
89 Float_t ptot = fPMin;
90 Int_t nt;
91
92 if(fPseudoRapidity==0.){
93 pLab[0] = ptot*fCosx;
94 pLab[1] = ptot*fCosy;
95 pLab[2] = ptot*fCosz;
96 }
97 else{
98 Float_t scang = 2*TMath::ATan(TMath::Exp(-(fPseudoRapidity)));
99 pLab[0] = -ptot*TMath::Sin(scang);
100 pLab[1] = 0.;
101 pLab[2] = ptot*TMath::Cos(scang);
102 }
c0ceba4c 103 for(i=0; i<=2; i++){
68ca986e 104 fP[i] = pLab[i];
105 }
106
107 // Beam divergence and crossing angle
108 if(fBeamDiv!=0.) {BeamDivCross(0,fBeamDiv,fBeamCrossAngle,fBeamCrossPlane,pLab);}
109 if(fBeamCrossAngle!=0.) {BeamDivCross(1,fBeamDiv,fBeamCrossAngle,fBeamCrossPlane,pLab);}
110
111 // If required apply the Fermi momentum
112 if(fFermiflag==1){
113 if((fIpart==kProton) || (fIpart==kNeutron)){
114 ExtractFermi(fIpart,fPp,fProbintp,fProbintn,ddp);
115 }
116 if(fIpart==kProton) {mass = 0.93956563;}
117 if(fIpart==kNeutron) {mass = 0.93827231;}
118// printf(" pLABx = %f pLABy = %f pLABz = %f \n",pLab[0],pLab[1],pLab[2]);
c0ceba4c 119 for(i=0; i<=2; i++){
68ca986e 120 balp[i] = -pLab[i];
121 }
122 balp0 = TMath::Sqrt(pLab[0]*pLab[0]+pLab[1]*pLab[1]+pLab[2]*pLab[2]+mass*mass);
c0ceba4c 123 for(i=0; i<=2; i++){
68ca986e 124 dddp[i] = ddp[i];
125 }
126 dddp0 = TMath::Sqrt(dddp[0]*dddp[0]+dddp[1]*dddp[1]+dddp[2]*dddp[2]+mass*mass);
127
128 TVector3 b(balp[0]/balp0, balp[1]/balp0, balp[2]/balp0);
129 TLorentzVector pFermi(dddp[0], dddp[1], dddp[2], dddp0);
130
131// printf(" pmu -> pLABx = %f pLABy = %f pLABz = %f E = %f\n",
132// balp[0],balp[1],balp[2],balp0);
133// printf(" Beta -> bx = %f by = %f bz = %f\n", b[0], b[1], b[2]);
134// printf(" pFermi -> px = %f, py = %f, pz = %f\n", pFermi[0], pFermi[1], pFermi[2]);
135
136 pFermi.Boost(b);
137
138// printf(" Boosted momentum -> px = %f, py = %f, pz = %f\n",
139// pFermi[0], pFermi[1], pFermi[2]);
c0ceba4c 140 for(i=0; i<=2; i++){
68ca986e 141 fBoostP[i] = pFermi[i];
142 }
143
144 }
145
146 Float_t polar[3] = {0,0,0};
147 gAlice->SetTrack(fTrackIt,-1,fIpart,fBoostP,fOrigin.GetArray(),polar,0,
148 "Primary",nt);
149}
150
151//_____________________________________________________________________________
152void AliGenZDC::FermiTwoGaussian(Double_t A, Float_t Z, Double_t* fPp, Double_t*
153 fProbintp, Double_t* fProbintn)
154{
155//
156// Momenta distributions according to the "double-gaussian"
157// distribution (Ilinov) - equal for protons and neutrons
158//
159// printf(" Initialization of Fermi momenta distribution\n");
160 fProbintp[0] = 0;
161 fProbintn[0] = 0;
162 Double_t sig1 = 0.113;
163 Double_t sig2 = 0.250;
164 Double_t alfa = 0.18*(TMath::Power((A/12.),(Float_t)1/3));
165 Double_t xk = (2*k2PI)/((1.+alfa)*(TMath::Power(k2PI,1.5)));
166
167 for(Int_t i=1; i<=200; i++){
168 Double_t p = i*0.005;
169 fPp[i] = p;
170// printf(" fPp[%d] = %f\n",i,fPp[i]);
171 Double_t e1 = (p*p)/(2.*sig1*sig1);
172 Double_t e2 = (p*p)/(2.*sig2*sig2);
173 Double_t f1 = TMath::Exp(-(e1));
174 Double_t f2 = TMath::Exp(-(e2));
175 Double_t probp = xk*p*p*(f1/(TMath::Power(sig1,3.))+
176 alfa*f2/(TMath::Power(sig2,3.)))*0.005;
177// printf(" probp = %f\n",probp);
178 fProbintp[i] = fProbintp[i-1] + probp;
179 fProbintn[i] = fProbintp[i];
180// printf(" fProbintp[%d] = %f, fProbintp[%d] = %f\n",i,fProbintp[i],i,fProbintn[i]);
181 }
182}
183//_____________________________________________________________________________
184void AliGenZDC::ExtractFermi(Int_t id, Double_t* fPp, Double_t* fProbintp,
185 Double_t* fProbintn, Double_t* ddp)
186{
187//
188// Compute Fermi momentum for spectator nucleons
189//
190 Int_t i;
191 Float_t xx = gRandom->Rndm();
192 if(id==kProton){
193 for(i=0; i<=200; i++){
194 if((xx>=fProbintp[i-1]) && (xx<fProbintp[i])) break;
195 }
196 }
197 else if(id==kNeutron){
198 for(i=0; i<=200; i++){
199 if((xx>=fProbintn[i-1]) && (xx<fProbintn[i])) break;
200 }
201 }
202 Float_t pext = fPp[i]+0.001;
203 Float_t phi = k2PI*(gRandom->Rndm());
204 Float_t cost = (1.-2.*(gRandom->Rndm()));
205 Float_t tet = TMath::ACos(cost);
206 ddp[0] = pext*TMath::Sin(tet)*TMath::Cos(phi);
207 ddp[1] = pext*TMath::Sin(tet)*TMath::Sin(phi);
208 ddp[2] = pext*cost;
209}
210
211//_____________________________________________________________________________
212void AliGenZDC::BeamDivCross(Int_t icross, Float_t fBeamDiv, Float_t fBeamCrossAngle,
213 Int_t fBeamCrossPlane, Double_t* pLab)
214{
215 Double_t tetpart, fipart, tetdiv, fidiv, angleSum[2], tetsum, fisum, dplab[3];
216 Double_t rvec;
c0ceba4c 217
218 Int_t i;
68ca986e 219
220 Double_t pmq = 0.;
c0ceba4c 221 for(i=0; i<=2; i++){
68ca986e 222 dplab[i] = pLab[i];
223 pmq = pmq+pLab[i]*pLab[i];
224 }
225 Double_t pmod = TMath::Sqrt(pmq);
226// printf(" pmod = %f\n",pmod);
227
228// printf(" icross = %d, fBeamDiv = %f\n",icross,fBeamDiv);
229 if(icross==0){
230 rvec = gRandom->Gaus(0.0,1.0);
231 tetdiv = fBeamDiv * TMath::Abs(rvec);
232 fidiv = (gRandom->Rndm())*k2PI;
233 }
234 else if(icross==1){
235 if(fBeamCrossPlane==0.){
236 tetdiv = 0.;
237 fidiv = 0.;
238 }
239 else if(fBeamCrossPlane==1.){
240 tetdiv = fBeamCrossAngle;
241 fidiv = 0.;
242 }
243 else if(fBeamCrossPlane==2.){
244 tetdiv = fBeamCrossAngle;
245 fidiv = k2PI/4.;
246 }
247 }
248// printf(" tetdiv = %f, fidiv = %f\n",tetdiv,fidiv);
249 tetpart = TMath::ATan(TMath::Sqrt(dplab[0]*dplab[0]+dplab[1]*dplab[1])/dplab[2]);
250 if(dplab[1]!=0. || dplab[0]!=0.){
251 fipart = TMath::ATan2(dplab[1],dplab[0]);
252 }
253 else{
254 fipart = 0.;
255 }
256 if(fipart<0.) {fipart = fipart+k2PI;}
257// printf(" tetpart = %f, fipart = %f\n",tetpart,fipart);
258 tetdiv = tetdiv*kRaddeg;
259 fidiv = fidiv*kRaddeg;
260 tetpart = tetpart*kRaddeg;
261 fipart = fipart*kRaddeg;
262 AddAngle(tetpart,fipart,tetdiv,fidiv,angleSum);
263 tetsum = angleSum[0];
264 fisum = angleSum[1];
265// printf(" tetsum = %f, fisum = %f\n",tetsum,fisum);
266 tetsum = tetsum*kDegrad;
267 fisum = fisum*kDegrad;
268 pLab[0] = pmod*TMath::Sin(tetsum)*TMath::Cos(fisum);
269 pLab[1] = pmod*TMath::Sin(tetsum)*TMath::Sin(fisum);
270 pLab[2] = pmod*TMath::Cos(tetsum);
271// printf(" pLab[0] = %f pLab[1] = %f pLab[2] = %f \n\n",
272// pLab[0],pLab[1],pLab[2]);
c0ceba4c 273 for(i=0; i<=2; i++){
68ca986e 274 fDivP[i] = pLab[i];
275 }
276}
277
278//_____________________________________________________________________________
279void AliGenZDC::AddAngle(Double_t theta1, Double_t phi1, Double_t theta2,
280 Double_t phi2, Double_t* angleSum)
281{
282 Double_t temp, conv, cx, cy, cz, ct1, st1, ct2, st2, cp1, sp1, cp2, sp2;
283 Double_t rtetsum, tetsum, fisum;
284
285 temp = -1.;
286 conv = 180./TMath::ACos(temp);
287
288 ct1 = TMath::Cos(theta1/conv);
289 st1 = TMath::Sin(theta1/conv);
290 cp1 = TMath::Cos(phi1/conv);
291 sp1 = TMath::Sin(phi1/conv);
292 ct2 = TMath::Cos(theta2/conv);
293 st2 = TMath::Sin(theta2/conv);
294 cp2 = TMath::Cos(phi2/conv);
295 sp2 = TMath::Sin(phi2/conv);
296 cx = ct1*cp1*st2*cp2+st1*cp1*ct2-sp1*st2*sp2;
297 cy = ct1*sp1*st2*cp2+st1*sp1*ct2+cp1*st2*sp2;
298 cz = ct1*ct2-st1*st2*cp2;
299
300 rtetsum = TMath::ACos(cz);
301 tetsum = conv*rtetsum;
302 if(tetsum==0. || tetsum==180.){
303 fisum = 0.;
304 return;
305 }
306 temp = cx/TMath::Sin(rtetsum);
307 if(temp>1.) temp=1.;
308 if(temp<-1.) temp=-1.;
309 fisum = conv*TMath::ACos(temp);
310 if(cy<0) {fisum = 360.-fisum;}
311// printf(" AddAngle -> tetsum = %f, fisum = %f\n",tetsum, fisum);
312 angleSum[0] = tetsum;
313 angleSum[1] = fisum;
314}
315