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