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