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