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