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