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