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