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