4c039060 |
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$ |
5ddeb374 |
18 | Revision 1.15 2000/04/26 10:14:24 morsch |
19 | Particles array has one entry more than pythia particle list. Upper bound of |
20 | particle loop changed to np-1 (R. Guernane, AM) |
21 | |
2a0e6f5b |
22 | Revision 1.14 2000/04/05 08:36:13 morsch |
23 | Check status code of particles in Pythia event |
24 | to avoid double counting as partonic state and final state particle. |
25 | |
23211d3e |
26 | Revision 1.13 1999/11/09 07:38:48 fca |
27 | Changes for compatibility with version 2.23 of ROOT |
28 | |
084c1b4a |
29 | Revision 1.12 1999/11/03 17:43:20 fca |
30 | New version from G.Martinez & A.Morsch |
31 | |
886b6f73 |
32 | Revision 1.11 1999/09/29 09:24:14 fca |
33 | Introduction of the Copyright and cvs Log |
4c039060 |
34 | */ |
35 | |
fe4da5cc |
36 | #include "AliGenerator.h" |
37 | #include "AliGenPythia.h" |
fe4da5cc |
38 | #include "AliRun.h" |
39 | #include "AliPythia.h" |
40 | #include <TDirectory.h> |
41 | #include <TFile.h> |
42 | #include <TTree.h> |
43 | #include <stdlib.h> |
44 | #include <AliPythia.h> |
1578254f |
45 | #include <TParticle.h> |
46 | //#include <GParticle.h> |
fe4da5cc |
47 | ClassImp(AliGenPythia) |
48 | |
49 | AliGenPythia::AliGenPythia() |
50 | :AliGenerator() |
51 | { |
5ddeb374 |
52 | // Constructor |
fe4da5cc |
53 | } |
54 | |
55 | AliGenPythia::AliGenPythia(Int_t npart) |
56 | :AliGenerator(npart) |
57 | { |
58 | // default charm production at 5. 5 TeV |
59 | // semimuonic decay |
60 | // structure function GRVHO |
61 | // |
62 | fXsection = 0.; |
63 | fParentSelect.Set(5); |
64 | fChildSelect.Set(5); |
65 | for (Int_t i=0; i<5; i++) fParentSelect[i]=fChildSelect[i]=0; |
66 | SetProcess(); |
67 | SetStrucFunc(); |
886b6f73 |
68 | SetForceDecay(); |
fe4da5cc |
69 | SetPtHard(); |
70 | SetEnergyCMS(); |
71 | } |
72 | |
73 | AliGenPythia::~AliGenPythia() |
74 | { |
5ddeb374 |
75 | // Destructor |
fe4da5cc |
76 | } |
77 | |
78 | void AliGenPythia::Init() |
79 | { |
5ddeb374 |
80 | // Initialisation |
fe4da5cc |
81 | SetMC(new AliPythia()); |
82 | fPythia=(AliPythia*) fgMCEvGen; |
83 | // |
84 | fParentWeight=1./Float_t(fNpart); |
85 | // |
86 | // Forward Paramters to the AliPythia object |
87 | fPythia->DefineParticles(); |
fe4da5cc |
88 | fPythia->SetCKIN(3,fPtHardMin); |
89 | fPythia->SetCKIN(4,fPtHardMax); |
90 | fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc); |
5be1fe76 |
91 | fPythia->ForceDecay(fForceDecay); |
084c1b4a |
92 | fPythia->Lulist(0); |
93 | fPythia->Pystat(2); |
fe4da5cc |
94 | // Parent and Children Selection |
95 | switch (fProcess) |
96 | { |
97 | case charm: |
98 | |
99 | fParentSelect[0]=411; |
100 | fParentSelect[1]=421; |
101 | fParentSelect[2]=431; |
102 | fParentSelect[3]=4122; |
103 | break; |
104 | case charm_unforced: |
105 | |
106 | fParentSelect[0]=411; |
107 | fParentSelect[1]=421; |
108 | fParentSelect[2]=431; |
109 | fParentSelect[3]=4122; |
110 | break; |
111 | case beauty: |
112 | fParentSelect[0]=511; |
113 | fParentSelect[1]=521; |
114 | fParentSelect[2]=531; |
115 | fParentSelect[3]=5122; |
116 | break; |
117 | case beauty_unforced: |
118 | fParentSelect[0]=511; |
119 | fParentSelect[1]=521; |
120 | fParentSelect[2]=531; |
121 | fParentSelect[3]=5122; |
122 | break; |
123 | case jpsi_chi: |
124 | case jpsi: |
125 | fParentSelect[0]=443; |
126 | break; |
5be1fe76 |
127 | case mb: |
128 | break; |
fe4da5cc |
129 | } |
130 | |
131 | switch (fForceDecay) |
132 | { |
133 | case semielectronic: |
134 | case dielectron: |
135 | case b_jpsi_dielectron: |
136 | case b_psip_dielectron: |
137 | fChildSelect[0]=11; |
138 | break; |
139 | case semimuonic: |
140 | case dimuon: |
141 | case b_jpsi_dimuon: |
142 | case b_psip_dimuon: |
5be1fe76 |
143 | case pitomu: |
144 | case katomu: |
fe4da5cc |
145 | fChildSelect[0]=13; |
146 | break; |
886b6f73 |
147 | case all: |
148 | case nodecay: |
149 | break; |
fe4da5cc |
150 | } |
151 | } |
152 | |
153 | void AliGenPythia::Generate() |
154 | { |
5ddeb374 |
155 | // Generate one event |
fe4da5cc |
156 | |
5be1fe76 |
157 | Float_t polar[3] = {0,0,0}; |
158 | Float_t origin[3]= {0,0,0}; |
5ddeb374 |
159 | Float_t originP[3]= {0,0,0}; |
5be1fe76 |
160 | Float_t origin0[3]= {0,0,0}; |
5ddeb374 |
161 | Float_t p[3], pP[4], random[6]; |
09fd3ea2 |
162 | static TClonesArray *particles; |
5be1fe76 |
163 | // converts from mm/c to s |
164 | const Float_t kconv=0.001/2.999792458e8; |
fe4da5cc |
165 | |
166 | |
167 | // |
fe4da5cc |
168 | Int_t nt=0; |
5ddeb374 |
169 | Int_t ntP=0; |
fe4da5cc |
170 | Int_t jev=0; |
7921755b |
171 | Int_t j, kf; |
09fd3ea2 |
172 | |
173 | if(!particles) particles=new TClonesArray("TParticle",1000); |
fe4da5cc |
174 | |
175 | fTrials=0; |
176 | for (j=0;j<3;j++) origin0[j]=fOrigin[j]; |
177 | if(fVertexSmear==perEvent) { |
cfce8870 |
178 | gMC->Rndm(random,6); |
fe4da5cc |
179 | for (j=0;j<3;j++) { |
180 | origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())* |
181 | TMath::Sqrt(-2*TMath::Log(random[2*j+1])); |
182 | fPythia->SetMSTP(151,0); |
183 | } |
184 | } else if (fVertexSmear==perTrack) { |
185 | fPythia->SetMSTP(151,0); |
186 | for (j=0;j<3;j++) { |
187 | fPythia->SetPARP(151+j, fOsigma[j]*10.); |
188 | } |
189 | } |
fe4da5cc |
190 | while(1) |
191 | { |
084c1b4a |
192 | fPythia->Pyevnt(); |
2a0e6f5b |
193 | fPythia->Lulist(1); |
fe4da5cc |
194 | fTrials++; |
f1092809 |
195 | fPythia->ImportParticles(particles,"All"); |
fe4da5cc |
196 | Int_t np = particles->GetEntriesFast(); |
197 | printf("\n **************************************************%d\n",np); |
198 | Int_t nc=0; |
199 | if (np == 0 ) continue; |
5be1fe76 |
200 | if (fProcess != mb) { |
2a0e6f5b |
201 | for (Int_t i = 0; i<np-1; i++) { |
1578254f |
202 | TParticle * iparticle = (TParticle *) particles->At(i); |
23211d3e |
203 | Int_t ks = iparticle->GetStatusCode(); |
a8228d85 |
204 | kf = CheckPDGCode(iparticle->GetPdgCode()); |
2a0e6f5b |
205 | if (ks==21) continue; |
206 | |
5be1fe76 |
207 | fChildWeight=(fPythia->GetBraPart(kf))*fParentWeight; |
fe4da5cc |
208 | // |
209 | // Parent |
5be1fe76 |
210 | if (ParentSelected(TMath::Abs(kf))) { |
211 | if (KinematicSelection(iparticle)) { |
212 | if (nc==0) { |
213 | // |
214 | // Store information concerning the hard scattering process |
215 | // |
5ddeb374 |
216 | Float_t massP = fPythia->GetPARI(13); |
217 | Float_t ptP = fPythia->GetPARI(17); |
218 | Float_t yP = fPythia->GetPARI(37); |
219 | Float_t xmtP = sqrt(ptP*ptP+massP*massP); |
220 | Float_t ty = Float_t(TMath::TanH(yP)); |
221 | pP[0] = ptP; |
222 | pP[1] = 0; |
223 | pP[2] = xmtP*ty/sqrt(1.-ty*ty); |
224 | pP[3] = massP; |
5be1fe76 |
225 | gAlice->SetTrack(0,-1,-1, |
5ddeb374 |
226 | pP,originP,polar, |
227 | 0,"Hard Scat.",ntP,fParentWeight); |
228 | gAlice->KeepTrack(ntP); |
5be1fe76 |
229 | } |
230 | nc++; |
fe4da5cc |
231 | // |
232 | // store parent track information |
1578254f |
233 | p[0]=iparticle->Px(); |
234 | p[1]=iparticle->Py(); |
235 | p[2]=iparticle->Pz(); |
236 | origin[0]=origin0[0]+iparticle->Vx()/10; |
237 | origin[1]=origin0[1]+iparticle->Vy()/10; |
238 | origin[2]=origin0[2]+iparticle->Vz()/10; |
fe4da5cc |
239 | |
1578254f |
240 | Int_t ifch=iparticle->GetFirstDaughter(); |
241 | Int_t ilch=iparticle->GetLastDaughter(); |
5be1fe76 |
242 | if (ifch !=0 && ilch !=0) { |
5ddeb374 |
243 | gAlice->SetTrack(0,ntP,kf, |
5be1fe76 |
244 | p,origin,polar, |
245 | 0,"Primary",nt,fParentWeight); |
246 | gAlice->KeepTrack(nt); |
247 | Int_t iparent = nt; |
fe4da5cc |
248 | // |
249 | // Children |
250 | |
7921755b |
251 | for (j=ifch; j<=ilch; j++) |
5be1fe76 |
252 | { |
1578254f |
253 | TParticle * ichild = |
254 | (TParticle *) particles->At(j-1); |
a8228d85 |
255 | kf = CheckPDGCode(ichild->GetPdgCode()); |
fe4da5cc |
256 | // |
257 | // |
5be1fe76 |
258 | if (ChildSelected(TMath::Abs(kf))) { |
1578254f |
259 | origin[0]=ichild->Vx(); |
260 | origin[1]=ichild->Vy(); |
261 | origin[2]=ichild->Vz(); |
262 | p[0]=ichild->Px(); |
263 | p[1]=ichild->Py(); |
264 | p[2]=ichild->Pz(); |
265 | Float_t tof=kconv*ichild->T(); |
266 | gAlice->SetTrack(fTrackIt, iparent, kf, |
5be1fe76 |
267 | p,origin,polar, |
268 | tof,"Decay",nt,fChildWeight); |
269 | gAlice->KeepTrack(nt); |
270 | } // select child |
271 | } // child loop |
272 | } |
273 | } // kinematic selection |
274 | } // select particle |
275 | } // particle loop |
276 | } else { |
2a0e6f5b |
277 | for (Int_t i = 0; i<np-1; i++) { |
1578254f |
278 | TParticle * iparticle = (TParticle *) particles->At(i); |
a8228d85 |
279 | kf = CheckPDGCode(iparticle->GetPdgCode()); |
1578254f |
280 | Int_t ks = iparticle->GetStatusCode(); |
2a0e6f5b |
281 | |
1578254f |
282 | if (ks==1 && kf!=0 && KinematicSelection(iparticle)) { |
5be1fe76 |
283 | nc++; |
284 | // |
285 | // store track information |
1578254f |
286 | p[0]=iparticle->Px(); |
287 | p[1]=iparticle->Py(); |
288 | p[2]=iparticle->Pz(); |
289 | origin[0]=origin0[0]+iparticle->Vx()/10; |
290 | origin[1]=origin0[1]+iparticle->Vy()/10; |
291 | origin[2]=origin0[2]+iparticle->Vz()/10; |
292 | Float_t tof=kconv*iparticle->T(); |
293 | gAlice->SetTrack(fTrackIt,-1,kf,p,origin,polar, |
5be1fe76 |
294 | tof,"Primary",nt); |
295 | gAlice->KeepTrack(nt); |
296 | } // select particle |
297 | } // particle loop |
298 | printf("\n I've put %i particles on the stack \n",nc); |
299 | } // mb ? |
fe4da5cc |
300 | if (nc > 0) { |
5be1fe76 |
301 | jev+=nc; |
5ddeb374 |
302 | if (jev >= fNpart || fNpart == -1) { |
fe4da5cc |
303 | fKineBias=Float_t(fNpart)/Float_t(fTrials); |
23211d3e |
304 | printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev); |
fe4da5cc |
305 | break; |
306 | } |
307 | } |
308 | } // event loop |
309 | // adjust weight due to kinematic selection |
310 | AdjustWeights(); |
311 | // get cross-section |
312 | fXsection=fPythia->GetPARI(1); |
313 | } |
314 | |
315 | Bool_t AliGenPythia::ParentSelected(Int_t ip) |
316 | { |
5ddeb374 |
317 | // True if particle is in list of parent particles to be selected |
fe4da5cc |
318 | for (Int_t i=0; i<5; i++) |
319 | { |
320 | if (fParentSelect[i]==ip) return kTRUE; |
321 | } |
322 | return kFALSE; |
323 | } |
324 | |
325 | Bool_t AliGenPythia::ChildSelected(Int_t ip) |
326 | { |
5ddeb374 |
327 | // True if particle is in list of decay products to be selected |
fe4da5cc |
328 | for (Int_t i=0; i<5; i++) |
329 | { |
330 | if (fChildSelect[i]==ip) return kTRUE; |
331 | } |
332 | return kFALSE; |
333 | } |
334 | |
1578254f |
335 | Bool_t AliGenPythia::KinematicSelection(TParticle *particle) |
fe4da5cc |
336 | { |
5ddeb374 |
337 | // Perform kinematic selection |
1578254f |
338 | Float_t px=particle->Px(); |
339 | Float_t py=particle->Py(); |
340 | Float_t pz=particle->Pz(); |
341 | Float_t e=particle->Energy(); |
fe4da5cc |
342 | |
343 | // |
344 | // transverse momentum cut |
345 | Float_t pt=TMath::Sqrt(px*px+py*py); |
346 | if (pt > fPtMax || pt < fPtMin) |
347 | { |
348 | // printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax); |
349 | return kFALSE; |
350 | } |
351 | // |
352 | // momentum cut |
353 | Float_t p=TMath::Sqrt(px*px+py*py+pz*pz); |
354 | if (p > fPMax || p < fPMin) |
355 | { |
356 | // printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax); |
357 | return kFALSE; |
358 | } |
359 | |
360 | // |
361 | // theta cut |
5be1fe76 |
362 | Float_t theta = Float_t(TMath::ATan2(Double_t(pt),Double_t(pz))); |
fe4da5cc |
363 | if (theta > fThetaMax || theta < fThetaMin) |
364 | { |
365 | // printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax); |
366 | return kFALSE; |
367 | } |
368 | |
369 | // |
370 | // rapidity cut |
371 | Float_t y = 0.5*TMath::Log((e+pz)/(e-pz)); |
372 | if (y > fYMax || y < fYMin) |
373 | { |
374 | // printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax); |
375 | return kFALSE; |
376 | } |
377 | |
378 | // |
379 | // phi cut |
380 | Float_t phi=Float_t(TMath::ATan2(Double_t(py),Double_t(px)))+TMath::Pi(); |
381 | if (phi > fPhiMax || phi < fPhiMin) |
382 | { |
383 | // printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax); |
384 | return kFALSE; |
385 | } |
386 | |
387 | return kTRUE; |
388 | } |
389 | void AliGenPythia::AdjustWeights() |
390 | { |
5ddeb374 |
391 | // Adjust the weights after generation of all events |
392 | // |
393 | TClonesArray *partArray = gAlice->Particles(); |
394 | TParticle *part; |
fe4da5cc |
395 | Int_t ntrack=gAlice->GetNtrack(); |
396 | for (Int_t i=0; i<ntrack; i++) { |
5ddeb374 |
397 | part= (TParticle*) partArray->UncheckedAt(i); |
398 | part->SetWeight(part->GetWeight()*fKineBias); |
fe4da5cc |
399 | } |
400 | } |
401 | |
a8228d85 |
402 | Int_t AliGenPythia::CheckPDGCode(Int_t pdgcode) |
403 | { |
404 | // |
23211d3e |
405 | // If the particle is in a diffractive state, then take action accordingly |
a8228d85 |
406 | switch (pdgcode) { |
407 | case 110: |
408 | //rho_diff0 -- difficult to translate, return rho0 |
409 | return 113; |
410 | case 210: |
411 | //pi_diffr+ -- change to pi+ |
412 | return 211; |
413 | case 220: |
414 | //omega_di0 -- change to omega0 |
415 | return 223; |
416 | case 330: |
417 | //phi_diff0 -- return phi0 |
418 | return 333; |
419 | case 440: |
420 | //J/psi_di0 -- return J/psi |
421 | return 443; |
422 | case 2110: |
423 | //n_diffr -- return neutron |
424 | return 2112; |
425 | case 2210: |
426 | //p_diffr+ -- return proton |
427 | return 2212; |
428 | } |
429 | //non diffractive state -- return code unchanged |
430 | return pdgcode; |
431 | } |
432 | |
fe4da5cc |
433 | |
434 | |
435 | |
436 | |
5be1fe76 |
437 | |
438 | |
439 | |
440 | |