1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.50 2002/03/03 13:48:50 morsch
19 Option kPyCharmPbMNR added. Produce charm pairs in agreement with MNR
20 NLO calculations (Nicola Carrer).
22 Revision 1.49 2002/02/08 16:50:50 morsch
23 Add name and title in constructor.
25 Revision 1.48 2001/12/20 11:44:28 morsch
26 Add kinematic bias for direct gamma production.
28 Revision 1.47 2001/12/19 14:45:00 morsch
29 Store number of trials in header.
31 Revision 1.46 2001/12/19 10:36:19 morsch
32 Add possibility if jet kinematic biasing.
34 Revision 1.45 2001/11/28 08:06:52 morsch
35 Use fMaxLifeTime parameter.
37 Revision 1.44 2001/11/27 13:13:07 morsch
38 Maximum lifetime for long-lived particles to be put on the stack is parameter.
39 It can be set via SetMaximumLifetime(..).
41 Revision 1.43 2001/10/21 18:35:56 hristov
42 Several pointers were set to zero in the default constructors to avoid memory management problems
44 Revision 1.42 2001/10/15 08:21:55 morsch
45 Vertex truncation settings moved to AliGenMC.
47 Revision 1.41 2001/10/08 08:45:42 morsch
48 Possibility of vertex cut added.
50 Revision 1.40 2001/09/25 11:30:23 morsch
51 Pass event vertex to header.
53 Revision 1.39 2001/07/27 17:09:36 morsch
54 Use local SetTrack, KeepTrack and SetHighWaterMark methods
55 to delegate either to local stack or to stack owned by AliRun.
56 (Piotr Skowronski, A.M.)
58 Revision 1.38 2001/07/13 10:58:54 morsch
59 - Some coded moved to AliGenMC
60 - Improved handling of secondary vertices.
62 Revision 1.37 2001/06/28 11:17:28 morsch
63 SetEventListRange setter added. Events in specified range are listed for
64 debugging. (Yuri Kharlov)
66 Revision 1.36 2001/03/30 07:05:49 morsch
67 Final print-out in finish run.
68 Write parton system for jet-production (preliminary solution).
70 Revision 1.35 2001/03/09 13:03:40 morsch
71 Process_t and Struc_Func_t moved to AliPythia.h
73 Revision 1.34 2001/02/14 15:50:40 hristov
74 The last particle in event marked using SetHighWaterMark
76 Revision 1.33 2001/01/30 09:23:12 hristov
77 Streamers removed (R.Brun)
79 Revision 1.32 2001/01/26 19:55:51 hristov
80 Major upgrade of AliRoot code
82 Revision 1.31 2001/01/17 10:54:31 hristov
83 Better protection against FPE
85 Revision 1.30 2000/12/18 08:55:35 morsch
86 Make AliPythia dependent generartors work with new scheme of random number generation
88 Revision 1.29 2000/12/04 11:22:03 morsch
89 Init of sRandom as in 1.15
91 Revision 1.28 2000/12/02 11:41:39 morsch
92 Use SetRandom() to initialize random number generator in constructor.
94 Revision 1.27 2000/11/30 20:29:02 morsch
95 Initialise static variable sRandom in constructor: sRandom = fRandom;
97 Revision 1.26 2000/11/30 07:12:50 alibrary
98 Introducing new Rndm and QA classes
100 Revision 1.25 2000/10/18 19:11:27 hristov
101 Division by zero fixed
103 Revision 1.24 2000/09/18 10:41:35 morsch
104 Add possibility to use nuclear structure functions from PDF library V8.
106 Revision 1.23 2000/09/14 14:05:40 morsch
109 Revision 1.22 2000/09/14 14:02:22 morsch
110 - Correct conversion from mm to cm when passing particle vertex to MC.
111 - Correct handling of fForceDecay == all.
113 Revision 1.21 2000/09/12 14:14:55 morsch
114 Call fDecayer->ForceDecay() at the beginning of Generate().
116 Revision 1.20 2000/09/06 14:29:33 morsch
117 Use AliPythia for event generation an AliDecayPythia for decays.
118 Correct handling of "nodecay" option
120 Revision 1.19 2000/07/11 18:24:56 fca
121 Coding convention corrections + few minor bug fixes
123 Revision 1.18 2000/06/30 12:40:34 morsch
124 Pythia takes care of vertex smearing. Correct conversion from Pythia units (mm) to
127 Revision 1.17 2000/06/09 20:34:07 morsch
128 All coding rule violations except RS3 corrected
130 Revision 1.16 2000/05/15 15:04:20 morsch
131 The full event is written for fNtrack = -1
132 Coding rule violations corrected.
134 Revision 1.15 2000/04/26 10:14:24 morsch
135 Particles array has one entry more than pythia particle list. Upper bound of
136 particle loop changed to np-1 (R. Guernane, AM)
138 Revision 1.14 2000/04/05 08:36:13 morsch
139 Check status code of particles in Pythia event
140 to avoid double counting as partonic state and final state particle.
142 Revision 1.13 1999/11/09 07:38:48 fca
143 Changes for compatibility with version 2.23 of ROOT
145 Revision 1.12 1999/11/03 17:43:20 fca
146 New version from G.Martinez & A.Morsch
148 Revision 1.11 1999/09/29 09:24:14 fca
149 Introduction of the Copyright and cvs Log
152 #include "AliGenPythia.h"
153 #include "AliGenPythiaEventHeader.h"
154 #include "AliDecayerPythia.h"
156 #include "AliPythia.h"
158 #include <TParticle.h>
161 ClassImp(AliGenPythia)
163 AliGenPythia::AliGenPythia()
166 // Default Constructor
169 fDecayer = new AliDecayerPythia();
175 AliGenPythia::AliGenPythia(Int_t npart)
178 // default charm production at 5. 5 TeV
180 // structure function GRVHO
183 fTitle= "Particle Generator using PYTHIA";
192 fDecayer = new AliDecayerPythia();
193 // Set random number generator
196 // Produced particles
197 fParticles = new TClonesArray("TParticle",1000);
204 AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
209 AliGenPythia::~AliGenPythia()
214 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
216 // Set a range of event numbers, for which a table
217 // of generated particle will be printed
218 fDebugEventFirst = eventFirst;
219 fDebugEventLast = eventLast;
220 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
223 void AliGenPythia::Init()
226 SetMC(AliPythia::Instance());
227 fPythia=(AliPythia*) fgMCEvGen;
229 fParentWeight=1./Float_t(fNpart);
231 // Forward Paramters to the AliPythia object
232 fDecayer->SetForceDecay(fForceDecay);
236 fPythia->SetCKIN(3,fPtHardMin);
237 fPythia->SetCKIN(4,fPtHardMax);
238 if (fNucA1 > 0 && fNucA2 > 0) fPythia->SetNuclei(fNucA1, fNucA2);
239 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
241 // fPythia->Pylist(0);
242 // fPythia->Pystat(2);
243 // Parent and Children Selection
247 case kPyCharmUnforced:
249 fParentSelect[0] = 411;
250 fParentSelect[1] = 421;
251 fParentSelect[2] = 431;
252 fParentSelect[3] = 4122;
256 fParentSelect[0]= 511;
257 fParentSelect[1]= 521;
258 fParentSelect[2]= 531;
259 fParentSelect[3]= 5122;
260 fParentSelect[4]= 5132;
261 fParentSelect[5]= 5232;
262 fParentSelect[6]= 5332;
265 case kPyBeautyUnforced:
266 fParentSelect[0] = 511;
267 fParentSelect[1] = 521;
268 fParentSelect[2] = 531;
269 fParentSelect[3] = 5122;
270 fParentSelect[4] = 5132;
271 fParentSelect[5] = 5232;
272 fParentSelect[6] = 5332;
277 fParentSelect[0] = 443;
287 void AliGenPythia::Generate()
289 // Generate one event
290 fDecayer->ForceDecay();
292 Float_t polar[3] = {0,0,0};
293 Float_t origin[3] = {0,0,0};
295 // converts from mm/c to s
296 const Float_t kconv=0.001/2.999792458e8;
303 // Set collision vertex position
304 if(fVertexSmear==kPerEvent) {
305 fPythia->SetMSTP(151,1);
307 fPythia->SetPARP(151+j, fOsigma[j]*10.);
309 } else if (fVertexSmear==kPerTrack) {
310 fPythia->SetMSTP(151,0);
316 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
317 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
320 fPythia->ImportParticles(fParticles,"All");
327 Int_t np = fParticles->GetEntriesFast();
328 if (np == 0 ) continue;
329 // Get event vertex and discard the event if the Z coord. is too big
330 TParticle *iparticle = (TParticle *) fParticles->At(0);
331 Float_t distz = iparticle->Vz()/10.;
332 if(TMath::Abs(distz)>fCutVertexZ*fOsigma[2]) continue;
334 fEventVertex[0] = iparticle->Vx()/10.+fOrigin.At(0);
335 fEventVertex[1] = iparticle->Vy()/10.+fOrigin.At(1);
336 fEventVertex[2] = iparticle->Vz()/10.+fOrigin.At(2);
338 Int_t* pParent = new Int_t[np];
339 Int_t* pSelected = new Int_t[np];
340 Int_t* trackIt = new Int_t[np];
341 for (i=0; i< np; i++) {
345 printf("\n **************************************************%d\n",np);
347 if (fProcess != kPyMb && fProcess != kPyJets && fProcess != kPyDirectGamma) {
349 for (i = 0; i<np; i++) {
350 iparticle = (TParticle *) fParticles->At(i);
351 Int_t ks = iparticle->GetStatusCode();
352 kf = CheckPDGCode(iparticle->GetPdgCode());
353 // No initial state partons
354 if (ks==21) continue;
356 // Heavy Flavor Selection
362 if (kfl > 10) kfl/=100;
364 if (kfl > 10) kfl/=10;
365 if (kfl > 10) kfl/=10;
367 Int_t ipa = iparticle->GetFirstMother()-1;
371 TParticle * mother = (TParticle *) fParticles->At(ipa);
372 kfMo = TMath::Abs(mother->GetPdgCode());
374 // printf("\n particle (all) %d %d %d", i, pSelected[i], kf);
375 if (kfl >= fFlavorSelect) {
377 // Heavy flavor hadron or quark
379 // Kinematic seletion on final state heavy flavor mesons
380 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
386 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
388 // Kinematic seletion on decay products
389 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
390 && !KinematicSelection(iparticle, 1))
397 // Select if mother was selected and is not tracked
399 if (pSelected[ipa] &&
400 !trackIt[ipa] && // mother will be tracked ?
401 kfMo != 5 && // mother is b-quark, don't store fragments
402 kfMo != 4 && // mother is c-quark, don't store fragments
403 kf != 92) // don't store string
406 // Semi-stable or de-selected: diselect decay products:
409 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
411 Int_t ipF = iparticle->GetFirstDaughter();
412 Int_t ipL = iparticle->GetLastDaughter();
413 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
415 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
416 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
419 if (pSelected[i] == -1) pSelected[i] = 0;
420 if (!pSelected[i]) continue;
422 // Decision on tracking
425 // Track final state particle
426 if (ks == 1) trackIt[i] = 1;
427 // Track semi-stable particles
428 if ((ks ==1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
429 // Track particles selected by process if undecayed.
430 if (fForceDecay == kNoDecay) {
431 if (ParentSelected(kf)) trackIt[i] = 1;
433 if (ParentSelected(kf)) trackIt[i] = 0;
438 } // particle selection loop
440 for (i = 0; i<np; i++) {
441 if (!pSelected[i]) continue;
442 TParticle * iparticle = (TParticle *) fParticles->At(i);
443 kf = CheckPDGCode(iparticle->GetPdgCode());
444 p[0] = iparticle->Px();
445 p[1] = iparticle->Py();
446 p[2] = iparticle->Pz();
447 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
448 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
449 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
450 Float_t tof = kconv*iparticle->T();
451 Int_t ipa = iparticle->GetFirstMother()-1;
452 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
453 SetTrack(fTrackIt*trackIt[i] ,
454 iparent, kf, p, origin, polar, tof, kPPrimary, nt, 1.);
463 if (pParent) delete[] pParent;
464 if (pSelected) delete[] pSelected;
465 if (trackIt) delete[] trackIt;
469 if (jev >= fNpart || fNpart == -1) {
470 fKineBias=Float_t(fNpart)/Float_t(fTrials);
471 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
477 SetHighWaterMark(nt);
478 // adjust weight due to kinematic selection
481 fXsection=fPythia->GetPARI(1);
484 Int_t AliGenPythia::GenerateMB()
486 Int_t i, kf, nt, iparent;
489 Float_t polar[3] = {0,0,0};
490 Float_t origin[3] = {0,0,0};
491 // converts from mm/c to s
492 const Float_t kconv=0.001/2.999792458e8;
494 Int_t np = fParticles->GetEntriesFast();
495 Int_t* pParent = new Int_t[np];
496 for (i=0; i< np; i++) pParent[i] = -1;
497 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
498 TParticle* jet1 = (TParticle *) fParticles->At(6);
499 TParticle* jet2 = (TParticle *) fParticles->At(7);
500 if (!CheckTrigger(jet1, jet2)) return 0;
503 for (i = 0; i<np; i++) {
505 TParticle * iparticle = (TParticle *) fParticles->At(i);
506 kf = CheckPDGCode(iparticle->GetPdgCode());
507 Int_t ks = iparticle->GetStatusCode();
508 Int_t km = iparticle->GetFirstMother();
509 // printf("\n Particle: %d %d %d", i, kf, ks);
511 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
513 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
515 if (ks == 1) trackIt = 1;
516 Int_t ipa = iparticle->GetFirstMother()-1;
518 iparent = (ipa > -1) ? pParent[ipa] : -1;
521 // store track information
522 p[0] = iparticle->Px();
523 p[1] = iparticle->Py();
524 p[2] = iparticle->Pz();
525 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
526 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
527 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
528 Float_t tof=kconv*iparticle->T();
529 SetTrack(fTrackIt*trackIt, iparent, kf, p, origin, polar,
536 if (pParent) delete[] pParent;
538 printf("\n I've put %i particles on the stack \n",nc);
543 void AliGenPythia::FinishRun()
545 // Print x-section summary
549 void AliGenPythia::AdjustWeights()
551 // Adjust the weights after generation of all events
554 Int_t ntrack=gAlice->GetNtrack();
555 for (Int_t i=0; i<ntrack; i++) {
556 part= gAlice->Particle(i);
557 part->SetWeight(part->GetWeight()*fKineBias);
561 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
563 // Treat protons as inside nuclei with mass numbers a1 and a2
569 void AliGenPythia::MakeHeader()
571 // Builds the event header, to be called after each event
572 AliGenEventHeader* header = new AliGenPythiaEventHeader("Pythia");
573 ((AliGenPythiaEventHeader*) header)->SetProcessType(fPythia->GetMSTI(1));
574 ((AliGenPythiaEventHeader*) header)->SetTrials(fTrials);
575 header->SetPrimaryVertex(fEventVertex);
576 gAlice->SetGenEventHeader(header);
580 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
582 // Check the kinematic trigger condition
585 eta[0] = jet1->Eta();
586 eta[1] = jet2->Eta();
588 phi[0] = jet1->Phi();
589 phi[1] = jet2->Phi();
591 pdg[0] = jet1->GetPdgCode();
592 pdg[1] = jet2->GetPdgCode();
593 Bool_t triggered = kFALSE;
595 if (fProcess == kPyJets) {
596 //Check eta range first...
597 if ((eta[0] < fEtaMaxJet && eta[0] > fEtaMinJet) ||
598 (eta[1] < fEtaMaxJet && eta[1] > fEtaMinJet))
600 //Eta is okay, now check phi range
601 if ((phi[0] < fPhiMaxJet && phi[0] > fPhiMinJet) ||
602 (phi[1] < fPhiMaxJet && phi[1] > fPhiMinJet))
610 if (pdg[0] == kGamma) {
614 //Check eta range first...
615 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
616 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
618 //Eta is okay, now check phi range
619 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
620 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
631 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
633 // Assignment operator
640 void AliGenPythia::Streamer(TBuffer &R__b)
642 // Stream an object of class AliGenPythia.
644 if (R__b.IsReading()) {
645 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
646 AliGenerator::Streamer(R__b);
647 R__b >> (Int_t&)fProcess;
648 R__b >> (Int_t&)fStrucFunc;
649 R__b >> (Int_t&)fForceDecay;
653 fParentSelect.Streamer(R__b);
654 fChildSelect.Streamer(R__b);
656 // (AliPythia::Instance())->Streamer(R__b);
659 // if (fDecayer) fDecayer->Streamer(R__b);
661 R__b.WriteVersion(AliGenPythia::IsA());
662 AliGenerator::Streamer(R__b);
663 R__b << (Int_t)fProcess;
664 R__b << (Int_t)fStrucFunc;
665 R__b << (Int_t)fForceDecay;
669 fParentSelect.Streamer(R__b);
670 fChildSelect.Streamer(R__b);
675 // fDecayer->Streamer(R__b);