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.55 2002/04/17 10:23:56 morsch
19 Coding Rule violations corrected.
21 Revision 1.54 2002/03/28 11:49:10 morsch
22 Pass status code in SetTrack.
24 Revision 1.53 2002/03/25 14:51:13 morsch
25 New stack-fill and count options introduced (N. Carrer).
27 Revision 1.51 2002/03/06 08:46:57 morsch
29 - delete dyn. alloc. arrays (N. Carrer)
31 Revision 1.50 2002/03/03 13:48:50 morsch
32 Option kPyCharmPbMNR added. Produce charm pairs in agreement with MNR
33 NLO calculations (Nicola Carrer).
35 Revision 1.49 2002/02/08 16:50:50 morsch
36 Add name and title in constructor.
38 Revision 1.48 2001/12/20 11:44:28 morsch
39 Add kinematic bias for direct gamma production.
41 Revision 1.47 2001/12/19 14:45:00 morsch
42 Store number of trials in header.
44 Revision 1.46 2001/12/19 10:36:19 morsch
45 Add possibility if jet kinematic biasing.
47 Revision 1.45 2001/11/28 08:06:52 morsch
48 Use fMaxLifeTime parameter.
50 Revision 1.44 2001/11/27 13:13:07 morsch
51 Maximum lifetime for long-lived particles to be put on the stack is parameter.
52 It can be set via SetMaximumLifetime(..).
54 Revision 1.43 2001/10/21 18:35:56 hristov
55 Several pointers were set to zero in the default constructors to avoid memory management problems
57 Revision 1.42 2001/10/15 08:21:55 morsch
58 Vertex truncation settings moved to AliGenMC.
60 Revision 1.41 2001/10/08 08:45:42 morsch
61 Possibility of vertex cut added.
63 Revision 1.40 2001/09/25 11:30:23 morsch
64 Pass event vertex to header.
66 Revision 1.39 2001/07/27 17:09:36 morsch
67 Use local SetTrack, KeepTrack and SetHighWaterMark methods
68 to delegate either to local stack or to stack owned by AliRun.
69 (Piotr Skowronski, A.M.)
71 Revision 1.38 2001/07/13 10:58:54 morsch
72 - Some coded moved to AliGenMC
73 - Improved handling of secondary vertices.
75 Revision 1.37 2001/06/28 11:17:28 morsch
76 SetEventListRange setter added. Events in specified range are listed for
77 debugging. (Yuri Kharlov)
79 Revision 1.36 2001/03/30 07:05:49 morsch
80 Final print-out in finish run.
81 Write parton system for jet-production (preliminary solution).
83 Revision 1.35 2001/03/09 13:03:40 morsch
84 Process_t and Struc_Func_t moved to AliPythia.h
86 Revision 1.34 2001/02/14 15:50:40 hristov
87 The last particle in event marked using SetHighWaterMark
89 Revision 1.33 2001/01/30 09:23:12 hristov
90 Streamers removed (R.Brun)
92 Revision 1.32 2001/01/26 19:55:51 hristov
93 Major upgrade of AliRoot code
95 Revision 1.31 2001/01/17 10:54:31 hristov
96 Better protection against FPE
98 Revision 1.30 2000/12/18 08:55:35 morsch
99 Make AliPythia dependent generartors work with new scheme of random number generation
101 Revision 1.29 2000/12/04 11:22:03 morsch
102 Init of sRandom as in 1.15
104 Revision 1.28 2000/12/02 11:41:39 morsch
105 Use SetRandom() to initialize random number generator in constructor.
107 Revision 1.27 2000/11/30 20:29:02 morsch
108 Initialise static variable sRandom in constructor: sRandom = fRandom;
110 Revision 1.26 2000/11/30 07:12:50 alibrary
111 Introducing new Rndm and QA classes
113 Revision 1.25 2000/10/18 19:11:27 hristov
114 Division by zero fixed
116 Revision 1.24 2000/09/18 10:41:35 morsch
117 Add possibility to use nuclear structure functions from PDF library V8.
119 Revision 1.23 2000/09/14 14:05:40 morsch
122 Revision 1.22 2000/09/14 14:02:22 morsch
123 - Correct conversion from mm to cm when passing particle vertex to MC.
124 - Correct handling of fForceDecay == all.
126 Revision 1.21 2000/09/12 14:14:55 morsch
127 Call fDecayer->ForceDecay() at the beginning of Generate().
129 Revision 1.20 2000/09/06 14:29:33 morsch
130 Use AliPythia for event generation an AliDecayPythia for decays.
131 Correct handling of "nodecay" option
133 Revision 1.19 2000/07/11 18:24:56 fca
134 Coding convention corrections + few minor bug fixes
136 Revision 1.18 2000/06/30 12:40:34 morsch
137 Pythia takes care of vertex smearing. Correct conversion from Pythia units (mm) to
140 Revision 1.17 2000/06/09 20:34:07 morsch
141 All coding rule violations except RS3 corrected
143 Revision 1.16 2000/05/15 15:04:20 morsch
144 The full event is written for fNtrack = -1
145 Coding rule violations corrected.
147 Revision 1.15 2000/04/26 10:14:24 morsch
148 Particles array has one entry more than pythia particle list. Upper bound of
149 particle loop changed to np-1 (R. Guernane, AM)
151 Revision 1.14 2000/04/05 08:36:13 morsch
152 Check status code of particles in Pythia event
153 to avoid double counting as partonic state and final state particle.
155 Revision 1.13 1999/11/09 07:38:48 fca
156 Changes for compatibility with version 2.23 of ROOT
158 Revision 1.12 1999/11/03 17:43:20 fca
159 New version from G.Martinez & A.Morsch
161 Revision 1.11 1999/09/29 09:24:14 fca
162 Introduction of the Copyright and cvs Log
166 // Generator using the TPythia interface (via AliPythia)
167 // to generate pp collisions.
168 // Using SetNuclei() also nuclear modifications to the structure functions
169 // can be taken into account. This makes, of course, only sense for the
170 // generation of the products of hard processes (heavy flavor, jets ...)
172 // andreas.morsch@cern.ch
176 #include "AliGenPythia.h"
177 #include "AliGenPythiaEventHeader.h"
178 #include "AliDecayerPythia.h"
180 #include "AliPythia.h"
182 #include <TParticle.h>
185 ClassImp(AliGenPythia)
187 AliGenPythia::AliGenPythia()
190 // Default Constructor
193 fDecayer = new AliDecayerPythia();
199 AliGenPythia::AliGenPythia(Int_t npart)
202 // default charm production at 5. 5 TeV
204 // structure function GRVHO
207 fTitle= "Particle Generator using PYTHIA";
216 fDecayer = new AliDecayerPythia();
217 // Set random number generator
220 // Produced particles
221 fParticles = new TClonesArray("TParticle",1000);
226 // Options determining what to keep in the stack (Heavy flavour generation)
227 fStackFillOpt = kFlavorSelection; // Keep particle with selected flavor
228 fFeedDownOpt = kTRUE; // allow feed down from higher family
229 // Fragmentation on/off
230 fFragmentation = kTRUE;
231 // Default counting mode
232 fCountMode = kCountAll;
235 AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
241 AliGenPythia::~AliGenPythia()
246 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
248 // Set a range of event numbers, for which a table
249 // of generated particle will be printed
250 fDebugEventFirst = eventFirst;
251 fDebugEventLast = eventLast;
252 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
255 void AliGenPythia::Init()
258 SetMC(AliPythia::Instance());
259 fPythia=(AliPythia*) fgMCEvGen;
261 fParentWeight=1./Float_t(fNpart);
263 // Forward Paramters to the AliPythia object
264 fDecayer->SetForceDecay(fForceDecay);
268 fPythia->SetCKIN(3,fPtHardMin);
269 fPythia->SetCKIN(4,fPtHardMax);
270 if (fNucA1 > 0 && fNucA2 > 0) fPythia->SetNuclei(fNucA1, fNucA2);
272 if (fFragmentation) {
273 fPythia->SetMSTP(111,1);
275 fPythia->SetMSTP(111,0);
278 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
280 // fPythia->Pylist(0);
281 // fPythia->Pystat(2);
282 // Parent and Children Selection
286 case kPyCharmUnforced:
288 fParentSelect[0] = 411;
289 fParentSelect[1] = 421;
290 fParentSelect[2] = 431;
291 fParentSelect[3] = 4122;
295 fParentSelect[0] = 421;
300 fParentSelect[0]= 511;
301 fParentSelect[1]= 521;
302 fParentSelect[2]= 531;
303 fParentSelect[3]= 5122;
304 fParentSelect[4]= 5132;
305 fParentSelect[5]= 5232;
306 fParentSelect[6]= 5332;
309 case kPyBeautyUnforced:
310 fParentSelect[0] = 511;
311 fParentSelect[1] = 521;
312 fParentSelect[2] = 531;
313 fParentSelect[3] = 5122;
314 fParentSelect[4] = 5132;
315 fParentSelect[5] = 5232;
316 fParentSelect[6] = 5332;
321 fParentSelect[0] = 443;
331 void AliGenPythia::Generate()
333 // Generate one event
334 fDecayer->ForceDecay();
336 Float_t polar[3] = {0,0,0};
337 Float_t origin[3] = {0,0,0};
339 // converts from mm/c to s
340 const Float_t kconv=0.001/2.999792458e8;
347 // Set collision vertex position
348 if(fVertexSmear==kPerEvent) {
349 fPythia->SetMSTP(151,1);
351 fPythia->SetPARP(151+j, fOsigma[j]*10.);
353 } else if (fVertexSmear==kPerTrack) {
354 fPythia->SetMSTP(151,0);
360 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
361 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
364 fPythia->ImportParticles(fParticles,"All");
371 Int_t np = fParticles->GetEntriesFast();
372 if (np == 0 ) continue;
373 // Get event vertex and discard the event if the Z coord. is too big
374 TParticle *iparticle = (TParticle *) fParticles->At(0);
375 Float_t distz = iparticle->Vz()/10.;
376 if(TMath::Abs(distz)>fCutVertexZ*fOsigma[2]) continue;
378 fEventVertex[0] = iparticle->Vx()/10.+fOrigin.At(0);
379 fEventVertex[1] = iparticle->Vy()/10.+fOrigin.At(1);
380 fEventVertex[2] = iparticle->Vz()/10.+fOrigin.At(2);
382 Int_t* pParent = new Int_t[np];
383 Int_t* pSelected = new Int_t[np];
384 Int_t* trackIt = new Int_t[np];
385 for (i=0; i< np; i++) {
390 // printf("\n **************************************************%d\n",np);
391 Int_t nc = 0; // Total n. of selected particles
392 Int_t nParents = 0; // Selected parents
393 Int_t nTkbles = 0; // Trackable particles
394 if (fProcess != kPyMb && fProcess != kPyJets && fProcess != kPyDirectGamma) {
396 for (i = 0; i<np; i++) {
397 iparticle = (TParticle *) fParticles->At(i);
398 Int_t ks = iparticle->GetStatusCode();
399 kf = CheckPDGCode(iparticle->GetPdgCode());
400 // No initial state partons
401 if (ks==21) continue;
403 // Heavy Flavor Selection
409 if (kfl > 10) kfl/=100;
411 if (kfl > 10) kfl/=10;
412 if (kfl > 10) kfl/=10;
414 Int_t ipa = iparticle->GetFirstMother()-1;
418 TParticle * mother = (TParticle *) fParticles->At(ipa);
419 kfMo = TMath::Abs(mother->GetPdgCode());
421 // printf("\n particle (all) %d %d %d", i, pSelected[i], kf);
422 // What to keep in Stack?
423 Bool_t flavorOK = kFALSE;
424 Bool_t selectOK = kFALSE;
426 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
428 if (kfl > fFlavorSelect) {
432 if (kfl == fFlavorSelect) flavorOK = kTRUE;
434 switch (fStackFillOpt) {
435 case kFlavorSelection:
438 case kParentSelection:
439 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
442 if (flavorOK && selectOK) {
444 // Heavy flavor hadron or quark
446 // Kinematic seletion on final state heavy flavor mesons
447 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
452 if (ParentSelected(kf)) ++nParents; // Update parent count
453 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
455 // Kinematic seletion on decay products
456 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
457 && !KinematicSelection(iparticle, 1))
463 // Select if mother was selected and is not tracked
465 if (pSelected[ipa] &&
466 !trackIt[ipa] && // mother will be tracked ?
467 kfMo != 5 && // mother is b-quark, don't store fragments
468 kfMo != 4 && // mother is c-quark, don't store fragments
469 kf != 92) // don't store string
472 // Semi-stable or de-selected: diselect decay products:
475 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
477 Int_t ipF = iparticle->GetFirstDaughter();
478 Int_t ipL = iparticle->GetLastDaughter();
479 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
481 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
482 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
485 if (pSelected[i] == -1) pSelected[i] = 0;
486 if (!pSelected[i]) continue;
487 // Count quarks only if you did not include fragmentation
488 if (fFragmentation && kf <= 10) continue;
490 // Decision on tracking
493 // Track final state particle
494 if (ks == 1) trackIt[i] = 1;
495 // Track semi-stable particles
496 if ((ks ==1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
497 // Track particles selected by process if undecayed.
498 if (fForceDecay == kNoDecay) {
499 if (ParentSelected(kf)) trackIt[i] = 1;
501 if (ParentSelected(kf)) trackIt[i] = 0;
503 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
507 } // particle selection loop
509 for (i = 0; i<np; i++) {
510 if (!pSelected[i]) continue;
511 TParticle * iparticle = (TParticle *) fParticles->At(i);
512 kf = CheckPDGCode(iparticle->GetPdgCode());
513 Int_t ks = iparticle->GetStatusCode();
514 p[0] = iparticle->Px();
515 p[1] = iparticle->Py();
516 p[2] = iparticle->Pz();
517 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
518 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
519 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
520 Float_t tof = kconv*iparticle->T();
521 Int_t ipa = iparticle->GetFirstMother()-1;
522 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
523 SetTrack(fTrackIt*trackIt[i] ,
524 iparent, kf, p, origin, polar, tof, kPPrimary, nt, 1., ks);
533 if (pParent) delete[] pParent;
534 if (pSelected) delete[] pSelected;
535 if (trackIt) delete[] trackIt;
538 switch (fCountMode) {
540 // printf(" Count all \n");
544 // printf(" Count parents \n");
547 case kCountTrackables:
548 // printf(" Count trackable \n");
552 if (jev >= fNpart || fNpart == -1) {
553 fKineBias=Float_t(fNpart)/Float_t(fTrials);
554 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
560 SetHighWaterMark(nt);
561 // adjust weight due to kinematic selection
564 fXsection=fPythia->GetPARI(1);
567 Int_t AliGenPythia::GenerateMB()
570 // Min Bias selection and other global selections
572 Int_t i, kf, nt, iparent;
575 Float_t polar[3] = {0,0,0};
576 Float_t origin[3] = {0,0,0};
577 // converts from mm/c to s
578 const Float_t kconv=0.001/2.999792458e8;
580 Int_t np = fParticles->GetEntriesFast();
581 Int_t* pParent = new Int_t[np];
582 for (i=0; i< np; i++) pParent[i] = -1;
583 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
584 TParticle* jet1 = (TParticle *) fParticles->At(6);
585 TParticle* jet2 = (TParticle *) fParticles->At(7);
586 if (!CheckTrigger(jet1, jet2)) return 0;
589 for (i = 0; i<np; i++) {
591 TParticle * iparticle = (TParticle *) fParticles->At(i);
592 kf = CheckPDGCode(iparticle->GetPdgCode());
593 Int_t ks = iparticle->GetStatusCode();
594 Int_t km = iparticle->GetFirstMother();
595 // printf("\n Particle: %d %d %d", i, kf, ks);
597 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
599 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
601 if (ks == 1) trackIt = 1;
602 Int_t ipa = iparticle->GetFirstMother()-1;
604 iparent = (ipa > -1) ? pParent[ipa] : -1;
607 // store track information
608 p[0] = iparticle->Px();
609 p[1] = iparticle->Py();
610 p[2] = iparticle->Pz();
611 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
612 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
613 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
614 Float_t tof=kconv*iparticle->T();
615 SetTrack(fTrackIt*trackIt, iparent, kf, p, origin, polar,
616 tof, kPPrimary, nt, 1., ks);
622 if (pParent) delete[] pParent;
624 printf("\n I've put %i particles on the stack \n",nc);
629 void AliGenPythia::FinishRun()
631 // Print x-section summary
635 void AliGenPythia::AdjustWeights()
637 // Adjust the weights after generation of all events
640 Int_t ntrack=gAlice->GetNtrack();
641 for (Int_t i=0; i<ntrack; i++) {
642 part= gAlice->Particle(i);
643 part->SetWeight(part->GetWeight()*fKineBias);
647 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
649 // Treat protons as inside nuclei with mass numbers a1 and a2
655 void AliGenPythia::MakeHeader() const
657 // Builds the event header, to be called after each event
658 AliGenEventHeader* header = new AliGenPythiaEventHeader("Pythia");
659 ((AliGenPythiaEventHeader*) header)->SetProcessType(fPythia->GetMSTI(1));
660 ((AliGenPythiaEventHeader*) header)->SetTrials(fTrials);
661 header->SetPrimaryVertex(fEventVertex);
662 gAlice->SetGenEventHeader(header);
666 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2) const
668 // Check the kinematic trigger condition
671 eta[0] = jet1->Eta();
672 eta[1] = jet2->Eta();
674 phi[0] = jet1->Phi();
675 phi[1] = jet2->Phi();
677 pdg[0] = jet1->GetPdgCode();
678 pdg[1] = jet2->GetPdgCode();
679 Bool_t triggered = kFALSE;
681 if (fProcess == kPyJets) {
682 //Check eta range first...
683 if ((eta[0] < fEtaMaxJet && eta[0] > fEtaMinJet) ||
684 (eta[1] < fEtaMaxJet && eta[1] > fEtaMinJet))
686 //Eta is okay, now check phi range
687 if ((phi[0] < fPhiMaxJet && phi[0] > fPhiMinJet) ||
688 (phi[1] < fPhiMaxJet && phi[1] > fPhiMinJet))
696 if (pdg[0] == kGamma) {
700 //Check eta range first...
701 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
702 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
704 //Eta is okay, now check phi range
705 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
706 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
717 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
719 // Assignment operator
726 void AliGenPythia::Streamer(TBuffer &R__b)
728 // Stream an object of class AliGenPythia.
730 if (R__b.IsReading()) {
731 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
732 AliGenerator::Streamer(R__b);
733 R__b >> (Int_t&)fProcess;
734 R__b >> (Int_t&)fStrucFunc;
735 R__b >> (Int_t&)fForceDecay;
739 fParentSelect.Streamer(R__b);
740 fChildSelect.Streamer(R__b);
742 // (AliPythia::Instance())->Streamer(R__b);
745 // if (fDecayer) fDecayer->Streamer(R__b);
747 R__b.WriteVersion(AliGenPythia::IsA());
748 AliGenerator::Streamer(R__b);
749 R__b << (Int_t)fProcess;
750 R__b << (Int_t)fStrucFunc;
751 R__b << (Int_t)fForceDecay;
755 fParentSelect.Streamer(R__b);
756 fChildSelect.Streamer(R__b);
761 // fDecayer->Streamer(R__b);