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