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