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.52.4.4 2002/10/10 16:40:08 hristov
19 Updating VirtualMC to v3-09-02
21 Revision 1.62 2002/09/24 10:00:01 morsch
22 CheckTrigger() corrected.
24 Revision 1.61 2002/07/30 09:52:38 morsch
25 Call SetGammaPhiRange() and SetGammaEtaRange() in the constructor.
27 Revision 1.60 2002/07/19 14:49:03 morsch
30 Revision 1.59 2002/07/19 14:35:36 morsch
31 Count total number of trials. Print mean Q, x1, x2.
33 Revision 1.58 2002/07/17 10:04:09 morsch
34 SetYHard method added.
36 Revision 1.57 2002/05/22 13:22:53 morsch
37 Process kPyMbNonDiffr added.
39 Revision 1.56 2002/04/26 10:30:01 morsch
40 Option kPyBeautyPbMNR added. (N. Carrer).
42 Revision 1.55 2002/04/17 10:23:56 morsch
43 Coding Rule violations corrected.
45 Revision 1.54 2002/03/28 11:49:10 morsch
46 Pass status code in SetTrack.
48 Revision 1.53 2002/03/25 14:51:13 morsch
49 New stack-fill and count options introduced (N. Carrer).
51 Revision 1.51 2002/03/06 08:46:57 morsch
53 - delete dyn. alloc. arrays (N. Carrer)
55 Revision 1.50 2002/03/03 13:48:50 morsch
56 Option kPyCharmPbMNR added. Produce charm pairs in agreement with MNR
57 NLO calculations (Nicola Carrer).
59 Revision 1.49 2002/02/08 16:50:50 morsch
60 Add name and title in constructor.
62 Revision 1.48 2001/12/20 11:44:28 morsch
63 Add kinematic bias for direct gamma production.
65 Revision 1.47 2001/12/19 14:45:00 morsch
66 Store number of trials in header.
68 Revision 1.46 2001/12/19 10:36:19 morsch
69 Add possibility if jet kinematic biasing.
71 Revision 1.45 2001/11/28 08:06:52 morsch
72 Use fMaxLifeTime parameter.
74 Revision 1.44 2001/11/27 13:13:07 morsch
75 Maximum lifetime for long-lived particles to be put on the stack is parameter.
76 It can be set via SetMaximumLifetime(..).
78 Revision 1.43 2001/10/21 18:35:56 hristov
79 Several pointers were set to zero in the default constructors to avoid memory management problems
81 Revision 1.42 2001/10/15 08:21:55 morsch
82 Vertex truncation settings moved to AliGenMC.
84 Revision 1.41 2001/10/08 08:45:42 morsch
85 Possibility of vertex cut added.
87 Revision 1.40 2001/09/25 11:30:23 morsch
88 Pass event vertex to header.
90 Revision 1.39 2001/07/27 17:09:36 morsch
91 Use local SetTrack, KeepTrack and SetHighWaterMark methods
92 to delegate either to local stack or to stack owned by AliRun.
93 (Piotr Skowronski, A.M.)
95 Revision 1.38 2001/07/13 10:58:54 morsch
96 - Some coded moved to AliGenMC
97 - Improved handling of secondary vertices.
99 Revision 1.37 2001/06/28 11:17:28 morsch
100 SetEventListRange setter added. Events in specified range are listed for
101 debugging. (Yuri Kharlov)
103 Revision 1.36 2001/03/30 07:05:49 morsch
104 Final print-out in finish run.
105 Write parton system for jet-production (preliminary solution).
107 Revision 1.35 2001/03/09 13:03:40 morsch
108 Process_t and Struc_Func_t moved to AliPythia.h
110 Revision 1.34 2001/02/14 15:50:40 hristov
111 The last particle in event marked using SetHighWaterMark
113 Revision 1.33 2001/01/30 09:23:12 hristov
114 Streamers removed (R.Brun)
116 Revision 1.32 2001/01/26 19:55:51 hristov
117 Major upgrade of AliRoot code
119 Revision 1.31 2001/01/17 10:54:31 hristov
120 Better protection against FPE
122 Revision 1.30 2000/12/18 08:55:35 morsch
123 Make AliPythia dependent generartors work with new scheme of random number generation
125 Revision 1.29 2000/12/04 11:22:03 morsch
126 Init of sRandom as in 1.15
128 Revision 1.28 2000/12/02 11:41:39 morsch
129 Use SetRandom() to initialize random number generator in constructor.
131 Revision 1.27 2000/11/30 20:29:02 morsch
132 Initialise static variable sRandom in constructor: sRandom = fRandom;
134 Revision 1.26 2000/11/30 07:12:50 alibrary
135 Introducing new Rndm and QA classes
137 Revision 1.25 2000/10/18 19:11:27 hristov
138 Division by zero fixed
140 Revision 1.24 2000/09/18 10:41:35 morsch
141 Add possibility to use nuclear structure functions from PDF library V8.
143 Revision 1.23 2000/09/14 14:05:40 morsch
146 Revision 1.22 2000/09/14 14:02:22 morsch
147 - Correct conversion from mm to cm when passing particle vertex to MC.
148 - Correct handling of fForceDecay == all.
150 Revision 1.21 2000/09/12 14:14:55 morsch
151 Call fDecayer->ForceDecay() at the beginning of Generate().
153 Revision 1.20 2000/09/06 14:29:33 morsch
154 Use AliPythia for event generation an AliDecayPythia for decays.
155 Correct handling of "nodecay" option
157 Revision 1.19 2000/07/11 18:24:56 fca
158 Coding convention corrections + few minor bug fixes
160 Revision 1.18 2000/06/30 12:40:34 morsch
161 Pythia takes care of vertex smearing. Correct conversion from Pythia units (mm) to
164 Revision 1.17 2000/06/09 20:34:07 morsch
165 All coding rule violations except RS3 corrected
167 Revision 1.16 2000/05/15 15:04:20 morsch
168 The full event is written for fNtrack = -1
169 Coding rule violations corrected.
171 Revision 1.15 2000/04/26 10:14:24 morsch
172 Particles array has one entry more than pythia particle list. Upper bound of
173 particle loop changed to np-1 (R. Guernane, AM)
175 Revision 1.14 2000/04/05 08:36:13 morsch
176 Check status code of particles in Pythia event
177 to avoid double counting as partonic state and final state particle.
179 Revision 1.13 1999/11/09 07:38:48 fca
180 Changes for compatibility with version 2.23 of ROOT
182 Revision 1.12 1999/11/03 17:43:20 fca
183 New version from G.Martinez & A.Morsch
185 Revision 1.11 1999/09/29 09:24:14 fca
186 Introduction of the Copyright and cvs Log
190 // Generator using the TPythia interface (via AliPythia)
191 // to generate pp collisions.
192 // Using SetNuclei() also nuclear modifications to the structure functions
193 // can be taken into account. This makes, of course, only sense for the
194 // generation of the products of hard processes (heavy flavor, jets ...)
196 // andreas.morsch@cern.ch
200 #include "AliGenPythia.h"
201 #include "AliGenPythiaEventHeader.h"
202 #include "AliDecayerPythia.h"
204 #include "AliPythia.h"
206 #include <TParticle.h>
209 ClassImp(AliGenPythia)
211 AliGenPythia::AliGenPythia()
214 // Default Constructor
217 fDecayer = new AliDecayerPythia();
225 AliGenPythia::AliGenPythia(Int_t npart)
228 // default charm production at 5. 5 TeV
230 // structure function GRVHO
233 fTitle= "Particle Generator using PYTHIA";
243 fDecayer = new AliDecayerPythia();
244 // Set random number generator
247 // Produced particles
248 fParticles = new TClonesArray("TParticle",1000);
255 // Options determining what to keep in the stack (Heavy flavour generation)
256 fStackFillOpt = kFlavorSelection; // Keep particle with selected flavor
257 fFeedDownOpt = kTRUE; // allow feed down from higher family
258 // Fragmentation on/off
259 fFragmentation = kTRUE;
260 // Default counting mode
261 fCountMode = kCountAll;
264 AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
270 AliGenPythia::~AliGenPythia()
275 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
277 // Set a range of event numbers, for which a table
278 // of generated particle will be printed
279 fDebugEventFirst = eventFirst;
280 fDebugEventLast = eventLast;
281 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
284 void AliGenPythia::Init()
287 SetMC(AliPythia::Instance());
288 fPythia=(AliPythia*) fgMCEvGen;
290 fParentWeight=1./Float_t(fNpart);
292 // Forward Paramters to the AliPythia object
293 fDecayer->SetForceDecay(fForceDecay);
297 fPythia->SetCKIN(3,fPtHardMin);
298 fPythia->SetCKIN(4,fPtHardMax);
299 fPythia->SetCKIN(7,fYHardMin);
300 fPythia->SetCKIN(8,fYHardMax);
302 if (fNucA1 > 0 && fNucA2 > 0) fPythia->SetNuclei(fNucA1, fNucA2);
304 if (fFragmentation) {
305 fPythia->SetMSTP(111,1);
307 fPythia->SetMSTP(111,0);
310 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
312 // fPythia->Pylist(0);
313 // fPythia->Pystat(2);
314 // Parent and Children Selection
318 case kPyCharmUnforced:
320 fParentSelect[0] = 411;
321 fParentSelect[1] = 421;
322 fParentSelect[2] = 431;
323 fParentSelect[3] = 4122;
327 fParentSelect[0] = 421;
332 fParentSelect[0]= 511;
333 fParentSelect[1]= 521;
334 fParentSelect[2]= 531;
335 fParentSelect[3]= 5122;
336 fParentSelect[4]= 5132;
337 fParentSelect[5]= 5232;
338 fParentSelect[6]= 5332;
341 case kPyBeautyUnforced:
342 fParentSelect[0] = 511;
343 fParentSelect[1] = 521;
344 fParentSelect[2] = 531;
345 fParentSelect[3] = 5122;
346 fParentSelect[4] = 5132;
347 fParentSelect[5] = 5232;
348 fParentSelect[6] = 5332;
353 fParentSelect[0] = 443;
362 // This counts the total number of calls to Pyevnt() per run.
372 void AliGenPythia::Generate()
374 // Generate one event
375 fDecayer->ForceDecay();
377 Float_t polar[3] = {0,0,0};
378 Float_t origin[3] = {0,0,0};
380 // converts from mm/c to s
381 const Float_t kconv=0.001/2.999792458e8;
388 // Set collision vertex position
389 if(fVertexSmear==kPerEvent) {
390 fPythia->SetMSTP(151,1);
392 fPythia->SetPARP(151+j, fOsigma[j]*10.);
394 } else if (fVertexSmear==kPerTrack) {
395 fPythia->SetMSTP(151,0);
401 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
402 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
405 fPythia->ImportParticles(fParticles,"All");
412 Int_t np = fParticles->GetEntriesFast();
413 if (np == 0 ) continue;
414 // Get event vertex and discard the event if the Z coord. is too big
415 TParticle *iparticle = (TParticle *) fParticles->At(0);
416 Float_t distz = iparticle->Vz()/10.;
417 if(TMath::Abs(distz)>fCutVertexZ*fOsigma[2]) continue;
419 fEventVertex[0] = iparticle->Vx()/10.+fOrigin.At(0);
420 fEventVertex[1] = iparticle->Vy()/10.+fOrigin.At(1);
421 fEventVertex[2] = iparticle->Vz()/10.+fOrigin.At(2);
423 Int_t* pParent = new Int_t[np];
424 Int_t* pSelected = new Int_t[np];
425 Int_t* trackIt = new Int_t[np];
426 for (i=0; i< np; i++) {
432 Int_t nc = 0; // Total n. of selected particles
433 Int_t nParents = 0; // Selected parents
434 Int_t nTkbles = 0; // Trackable particles
435 if (fProcess != kPyMb && fProcess != kPyJets &&
436 fProcess != kPyDirectGamma &&
437 fProcess != kPyMbNonDiffr) {
439 for (i = 0; i<np; i++) {
440 iparticle = (TParticle *) fParticles->At(i);
441 Int_t ks = iparticle->GetStatusCode();
442 kf = CheckPDGCode(iparticle->GetPdgCode());
443 // No initial state partons
444 if (ks==21) continue;
446 // Heavy Flavor Selection
452 if (kfl > 10) kfl/=100;
454 if (kfl > 10) kfl/=10;
455 if (kfl > 10) kfl/=10;
457 Int_t ipa = iparticle->GetFirstMother()-1;
461 TParticle * mother = (TParticle *) fParticles->At(ipa);
462 kfMo = TMath::Abs(mother->GetPdgCode());
464 // What to keep in Stack?
465 Bool_t flavorOK = kFALSE;
466 Bool_t selectOK = kFALSE;
468 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
470 if (kfl > fFlavorSelect) {
474 if (kfl == fFlavorSelect) flavorOK = kTRUE;
476 switch (fStackFillOpt) {
477 case kFlavorSelection:
480 case kParentSelection:
481 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
484 if (flavorOK && selectOK) {
486 // Heavy flavor hadron or quark
488 // Kinematic seletion on final state heavy flavor mesons
489 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
494 if (ParentSelected(kf)) ++nParents; // Update parent count
495 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
497 // Kinematic seletion on decay products
498 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
499 && !KinematicSelection(iparticle, 1))
505 // Select if mother was selected and is not tracked
507 if (pSelected[ipa] &&
508 !trackIt[ipa] && // mother will be tracked ?
509 kfMo != 5 && // mother is b-quark, don't store fragments
510 kfMo != 4 && // mother is c-quark, don't store fragments
511 kf != 92) // don't store string
514 // Semi-stable or de-selected: diselect decay products:
517 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
519 Int_t ipF = iparticle->GetFirstDaughter();
520 Int_t ipL = iparticle->GetLastDaughter();
521 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
523 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
524 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
527 if (pSelected[i] == -1) pSelected[i] = 0;
528 if (!pSelected[i]) continue;
529 // Count quarks only if you did not include fragmentation
530 if (fFragmentation && kf <= 10) continue;
532 // Decision on tracking
535 // Track final state particle
536 if (ks == 1) trackIt[i] = 1;
537 // Track semi-stable particles
538 if ((ks ==1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
539 // Track particles selected by process if undecayed.
540 if (fForceDecay == kNoDecay) {
541 if (ParentSelected(kf)) trackIt[i] = 1;
543 if (ParentSelected(kf)) trackIt[i] = 0;
545 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
549 } // particle selection loop
551 for (i = 0; i<np; i++) {
552 if (!pSelected[i]) continue;
553 TParticle * iparticle = (TParticle *) fParticles->At(i);
554 kf = CheckPDGCode(iparticle->GetPdgCode());
555 Int_t ks = iparticle->GetStatusCode();
556 p[0] = iparticle->Px();
557 p[1] = iparticle->Py();
558 p[2] = iparticle->Pz();
559 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
560 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
561 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
562 Float_t tof = kconv*iparticle->T();
563 Int_t ipa = iparticle->GetFirstMother()-1;
564 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
565 SetTrack(fTrackIt*trackIt[i] ,
566 iparent, kf, p, origin, polar, tof, kPPrimary, nt, 1., ks);
575 if (pParent) delete[] pParent;
576 if (pSelected) delete[] pSelected;
577 if (trackIt) delete[] trackIt;
580 switch (fCountMode) {
582 // printf(" Count all \n");
586 // printf(" Count parents \n");
589 case kCountTrackables:
590 // printf(" Count trackable \n");
594 if (jev >= fNpart || fNpart == -1) {
595 fKineBias=Float_t(fNpart)/Float_t(fTrials);
596 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
598 fQ += fPythia->GetVINT(51);
599 fX1 += fPythia->GetVINT(41);
600 fX2 += fPythia->GetVINT(42);
601 fTrialsRun += fTrials;
608 SetHighWaterMark(nt);
609 // adjust weight due to kinematic selection
612 fXsection=fPythia->GetPARI(1);
615 Int_t AliGenPythia::GenerateMB()
618 // Min Bias selection and other global selections
620 Int_t i, kf, nt, iparent;
623 Float_t polar[3] = {0,0,0};
624 Float_t origin[3] = {0,0,0};
625 // converts from mm/c to s
626 const Float_t kconv=0.001/2.999792458e8;
628 Int_t np = fParticles->GetEntriesFast();
629 Int_t* pParent = new Int_t[np];
630 for (i=0; i< np; i++) pParent[i] = -1;
631 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
632 TParticle* jet1 = (TParticle *) fParticles->At(6);
633 TParticle* jet2 = (TParticle *) fParticles->At(7);
634 if (!CheckTrigger(jet1, jet2)) return 0;
637 for (i = 0; i<np; i++) {
639 TParticle * iparticle = (TParticle *) fParticles->At(i);
640 kf = CheckPDGCode(iparticle->GetPdgCode());
641 Int_t ks = iparticle->GetStatusCode();
642 Int_t km = iparticle->GetFirstMother();
643 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
645 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
647 if (ks == 1) trackIt = 1;
648 Int_t ipa = iparticle->GetFirstMother()-1;
650 iparent = (ipa > -1) ? pParent[ipa] : -1;
653 // store track information
654 p[0] = iparticle->Px();
655 p[1] = iparticle->Py();
656 p[2] = iparticle->Pz();
657 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
658 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
659 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
660 Float_t tof=kconv*iparticle->T();
661 SetTrack(fTrackIt*trackIt, iparent, kf, p, origin, polar,
662 tof, kPPrimary, nt, 1., ks);
668 if (pParent) delete[] pParent;
670 printf("\n I've put %i particles on the stack \n",nc);
675 void AliGenPythia::FinishRun()
677 // Print x-section summary
682 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
683 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
688 void AliGenPythia::AdjustWeights()
690 // Adjust the weights after generation of all events
693 Int_t ntrack=gAlice->GetNtrack();
694 for (Int_t i=0; i<ntrack; i++) {
695 part= gAlice->Particle(i);
696 part->SetWeight(part->GetWeight()*fKineBias);
700 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
702 // Treat protons as inside nuclei with mass numbers a1 and a2
708 void AliGenPythia::MakeHeader() const
710 // Builds the event header, to be called after each event
711 AliGenEventHeader* header = new AliGenPythiaEventHeader("Pythia");
712 ((AliGenPythiaEventHeader*) header)->SetProcessType(fPythia->GetMSTI(1));
713 ((AliGenPythiaEventHeader*) header)->SetTrials(fTrials);
714 header->SetPrimaryVertex(fEventVertex);
715 gAlice->SetGenEventHeader(header);
719 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2) const
721 // Check the kinematic trigger condition
724 eta[0] = jet1->Eta();
725 eta[1] = jet2->Eta();
727 phi[0] = jet1->Phi();
728 phi[1] = jet2->Phi();
730 pdg[0] = jet1->GetPdgCode();
731 pdg[1] = jet2->GetPdgCode();
732 Bool_t triggered = kFALSE;
734 if (fProcess == kPyJets) {
735 //Check eta range first...
737 ((eta[0] < fEtaMaxJet && eta[0] > fEtaMinJet) &&
738 (phi[0] < fPhiMaxJet && phi[0] > fPhiMinJet))
742 ((eta[1] < fEtaMaxJet && eta[1] > fEtaMinJet) &&
743 (phi[1] < fPhiMaxJet && phi[1] > fPhiMinJet))
751 if (pdg[0] == kGamma) {
755 //Check eta range first...
756 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
757 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
759 //Eta is okay, now check phi range
760 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
761 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
770 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
772 // Assignment operator
779 void AliGenPythia::Streamer(TBuffer &R__b)
781 // Stream an object of class AliGenPythia.
783 if (R__b.IsReading()) {
784 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
785 AliGenerator::Streamer(R__b);
786 R__b >> (Int_t&)fProcess;
787 R__b >> (Int_t&)fStrucFunc;
788 R__b >> (Int_t&)fForceDecay;
792 fParentSelect.Streamer(R__b);
793 fChildSelect.Streamer(R__b);
795 // (AliPythia::Instance())->Streamer(R__b);
798 // if (fDecayer) fDecayer->Streamer(R__b);
800 R__b.WriteVersion(AliGenPythia::IsA());
801 AliGenerator::Streamer(R__b);
802 R__b << (Int_t)fProcess;
803 R__b << (Int_t)fStrucFunc;
804 R__b << (Int_t)fForceDecay;
808 fParentSelect.Streamer(R__b);
809 fChildSelect.Streamer(R__b);
814 // fDecayer->Streamer(R__b);