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