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