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