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.56 2002/04/26 10:30:01 morsch
19 Option kPyBeautyPbMNR added. (N. Carrer).
21 Revision 1.55 2002/04/17 10:23:56 morsch
22 Coding Rule violations corrected.
24 Revision 1.54 2002/03/28 11:49:10 morsch
25 Pass status code in SetTrack.
27 Revision 1.53 2002/03/25 14:51:13 morsch
28 New stack-fill and count options introduced (N. Carrer).
30 Revision 1.51 2002/03/06 08:46:57 morsch
32 - delete dyn. alloc. arrays (N. Carrer)
34 Revision 1.50 2002/03/03 13:48:50 morsch
35 Option kPyCharmPbMNR added. Produce charm pairs in agreement with MNR
36 NLO calculations (Nicola Carrer).
38 Revision 1.49 2002/02/08 16:50:50 morsch
39 Add name and title in constructor.
41 Revision 1.48 2001/12/20 11:44:28 morsch
42 Add kinematic bias for direct gamma production.
44 Revision 1.47 2001/12/19 14:45:00 morsch
45 Store number of trials in header.
47 Revision 1.46 2001/12/19 10:36:19 morsch
48 Add possibility if jet kinematic biasing.
50 Revision 1.45 2001/11/28 08:06:52 morsch
51 Use fMaxLifeTime parameter.
53 Revision 1.44 2001/11/27 13:13:07 morsch
54 Maximum lifetime for long-lived particles to be put on the stack is parameter.
55 It can be set via SetMaximumLifetime(..).
57 Revision 1.43 2001/10/21 18:35:56 hristov
58 Several pointers were set to zero in the default constructors to avoid memory management problems
60 Revision 1.42 2001/10/15 08:21:55 morsch
61 Vertex truncation settings moved to AliGenMC.
63 Revision 1.41 2001/10/08 08:45:42 morsch
64 Possibility of vertex cut added.
66 Revision 1.40 2001/09/25 11:30:23 morsch
67 Pass event vertex to header.
69 Revision 1.39 2001/07/27 17:09:36 morsch
70 Use local SetTrack, KeepTrack and SetHighWaterMark methods
71 to delegate either to local stack or to stack owned by AliRun.
72 (Piotr Skowronski, A.M.)
74 Revision 1.38 2001/07/13 10:58:54 morsch
75 - Some coded moved to AliGenMC
76 - Improved handling of secondary vertices.
78 Revision 1.37 2001/06/28 11:17:28 morsch
79 SetEventListRange setter added. Events in specified range are listed for
80 debugging. (Yuri Kharlov)
82 Revision 1.36 2001/03/30 07:05:49 morsch
83 Final print-out in finish run.
84 Write parton system for jet-production (preliminary solution).
86 Revision 1.35 2001/03/09 13:03:40 morsch
87 Process_t and Struc_Func_t moved to AliPythia.h
89 Revision 1.34 2001/02/14 15:50:40 hristov
90 The last particle in event marked using SetHighWaterMark
92 Revision 1.33 2001/01/30 09:23:12 hristov
93 Streamers removed (R.Brun)
95 Revision 1.32 2001/01/26 19:55:51 hristov
96 Major upgrade of AliRoot code
98 Revision 1.31 2001/01/17 10:54:31 hristov
99 Better protection against FPE
101 Revision 1.30 2000/12/18 08:55:35 morsch
102 Make AliPythia dependent generartors work with new scheme of random number generation
104 Revision 1.29 2000/12/04 11:22:03 morsch
105 Init of sRandom as in 1.15
107 Revision 1.28 2000/12/02 11:41:39 morsch
108 Use SetRandom() to initialize random number generator in constructor.
110 Revision 1.27 2000/11/30 20:29:02 morsch
111 Initialise static variable sRandom in constructor: sRandom = fRandom;
113 Revision 1.26 2000/11/30 07:12:50 alibrary
114 Introducing new Rndm and QA classes
116 Revision 1.25 2000/10/18 19:11:27 hristov
117 Division by zero fixed
119 Revision 1.24 2000/09/18 10:41:35 morsch
120 Add possibility to use nuclear structure functions from PDF library V8.
122 Revision 1.23 2000/09/14 14:05:40 morsch
125 Revision 1.22 2000/09/14 14:02:22 morsch
126 - Correct conversion from mm to cm when passing particle vertex to MC.
127 - Correct handling of fForceDecay == all.
129 Revision 1.21 2000/09/12 14:14:55 morsch
130 Call fDecayer->ForceDecay() at the beginning of Generate().
132 Revision 1.20 2000/09/06 14:29:33 morsch
133 Use AliPythia for event generation an AliDecayPythia for decays.
134 Correct handling of "nodecay" option
136 Revision 1.19 2000/07/11 18:24:56 fca
137 Coding convention corrections + few minor bug fixes
139 Revision 1.18 2000/06/30 12:40:34 morsch
140 Pythia takes care of vertex smearing. Correct conversion from Pythia units (mm) to
143 Revision 1.17 2000/06/09 20:34:07 morsch
144 All coding rule violations except RS3 corrected
146 Revision 1.16 2000/05/15 15:04:20 morsch
147 The full event is written for fNtrack = -1
148 Coding rule violations corrected.
150 Revision 1.15 2000/04/26 10:14:24 morsch
151 Particles array has one entry more than pythia particle list. Upper bound of
152 particle loop changed to np-1 (R. Guernane, AM)
154 Revision 1.14 2000/04/05 08:36:13 morsch
155 Check status code of particles in Pythia event
156 to avoid double counting as partonic state and final state particle.
158 Revision 1.13 1999/11/09 07:38:48 fca
159 Changes for compatibility with version 2.23 of ROOT
161 Revision 1.12 1999/11/03 17:43:20 fca
162 New version from G.Martinez & A.Morsch
164 Revision 1.11 1999/09/29 09:24:14 fca
165 Introduction of the Copyright and cvs Log
169 // Generator using the TPythia interface (via AliPythia)
170 // to generate pp collisions.
171 // Using SetNuclei() also nuclear modifications to the structure functions
172 // can be taken into account. This makes, of course, only sense for the
173 // generation of the products of hard processes (heavy flavor, jets ...)
175 // andreas.morsch@cern.ch
179 #include "AliGenPythia.h"
180 #include "AliGenPythiaEventHeader.h"
181 #include "AliDecayerPythia.h"
183 #include "AliPythia.h"
185 #include <TParticle.h>
188 ClassImp(AliGenPythia)
190 AliGenPythia::AliGenPythia()
193 // Default Constructor
196 fDecayer = new AliDecayerPythia();
202 AliGenPythia::AliGenPythia(Int_t npart)
205 // default charm production at 5. 5 TeV
207 // structure function GRVHO
210 fTitle= "Particle Generator using PYTHIA";
219 fDecayer = new AliDecayerPythia();
220 // Set random number generator
223 // Produced particles
224 fParticles = new TClonesArray("TParticle",1000);
229 // Options determining what to keep in the stack (Heavy flavour generation)
230 fStackFillOpt = kFlavorSelection; // Keep particle with selected flavor
231 fFeedDownOpt = kTRUE; // allow feed down from higher family
232 // Fragmentation on/off
233 fFragmentation = kTRUE;
234 // Default counting mode
235 fCountMode = kCountAll;
238 AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
244 AliGenPythia::~AliGenPythia()
249 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
251 // Set a range of event numbers, for which a table
252 // of generated particle will be printed
253 fDebugEventFirst = eventFirst;
254 fDebugEventLast = eventLast;
255 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
258 void AliGenPythia::Init()
261 SetMC(AliPythia::Instance());
262 fPythia=(AliPythia*) fgMCEvGen;
264 fParentWeight=1./Float_t(fNpart);
266 // Forward Paramters to the AliPythia object
267 fDecayer->SetForceDecay(fForceDecay);
271 fPythia->SetCKIN(3,fPtHardMin);
272 fPythia->SetCKIN(4,fPtHardMax);
273 if (fNucA1 > 0 && fNucA2 > 0) fPythia->SetNuclei(fNucA1, fNucA2);
275 if (fFragmentation) {
276 fPythia->SetMSTP(111,1);
278 fPythia->SetMSTP(111,0);
281 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
283 // fPythia->Pylist(0);
284 // fPythia->Pystat(2);
285 // Parent and Children Selection
289 case kPyCharmUnforced:
291 fParentSelect[0] = 411;
292 fParentSelect[1] = 421;
293 fParentSelect[2] = 431;
294 fParentSelect[3] = 4122;
298 fParentSelect[0] = 421;
303 fParentSelect[0]= 511;
304 fParentSelect[1]= 521;
305 fParentSelect[2]= 531;
306 fParentSelect[3]= 5122;
307 fParentSelect[4]= 5132;
308 fParentSelect[5]= 5232;
309 fParentSelect[6]= 5332;
312 case kPyBeautyUnforced:
313 fParentSelect[0] = 511;
314 fParentSelect[1] = 521;
315 fParentSelect[2] = 531;
316 fParentSelect[3] = 5122;
317 fParentSelect[4] = 5132;
318 fParentSelect[5] = 5232;
319 fParentSelect[6] = 5332;
324 fParentSelect[0] = 443;
335 void AliGenPythia::Generate()
337 // Generate one event
338 fDecayer->ForceDecay();
340 Float_t polar[3] = {0,0,0};
341 Float_t origin[3] = {0,0,0};
343 // converts from mm/c to s
344 const Float_t kconv=0.001/2.999792458e8;
351 // Set collision vertex position
352 if(fVertexSmear==kPerEvent) {
353 fPythia->SetMSTP(151,1);
355 fPythia->SetPARP(151+j, fOsigma[j]*10.);
357 } else if (fVertexSmear==kPerTrack) {
358 fPythia->SetMSTP(151,0);
364 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
365 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
368 fPythia->ImportParticles(fParticles,"All");
375 Int_t np = fParticles->GetEntriesFast();
376 if (np == 0 ) continue;
377 // Get event vertex and discard the event if the Z coord. is too big
378 TParticle *iparticle = (TParticle *) fParticles->At(0);
379 Float_t distz = iparticle->Vz()/10.;
380 if(TMath::Abs(distz)>fCutVertexZ*fOsigma[2]) continue;
382 fEventVertex[0] = iparticle->Vx()/10.+fOrigin.At(0);
383 fEventVertex[1] = iparticle->Vy()/10.+fOrigin.At(1);
384 fEventVertex[2] = iparticle->Vz()/10.+fOrigin.At(2);
386 Int_t* pParent = new Int_t[np];
387 Int_t* pSelected = new Int_t[np];
388 Int_t* trackIt = new Int_t[np];
389 for (i=0; i< np; i++) {
394 // printf("\n **************************************************%d\n",np);
395 Int_t nc = 0; // Total n. of selected particles
396 Int_t nParents = 0; // Selected parents
397 Int_t nTkbles = 0; // Trackable particles
398 if (fProcess != kPyMb && fProcess != kPyJets && fProcess != kPyDirectGamma &&
399 fProcess != kPyMbNonDiffr) {
401 for (i = 0; i<np; i++) {
402 iparticle = (TParticle *) fParticles->At(i);
403 Int_t ks = iparticle->GetStatusCode();
404 kf = CheckPDGCode(iparticle->GetPdgCode());
405 // No initial state partons
406 if (ks==21) continue;
408 // Heavy Flavor Selection
414 if (kfl > 10) kfl/=100;
416 if (kfl > 10) kfl/=10;
417 if (kfl > 10) kfl/=10;
419 Int_t ipa = iparticle->GetFirstMother()-1;
423 TParticle * mother = (TParticle *) fParticles->At(ipa);
424 kfMo = TMath::Abs(mother->GetPdgCode());
426 // printf("\n particle (all) %d %d %d", i, pSelected[i], kf);
427 // What to keep in Stack?
428 Bool_t flavorOK = kFALSE;
429 Bool_t selectOK = kFALSE;
431 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
433 if (kfl > fFlavorSelect) {
437 if (kfl == fFlavorSelect) flavorOK = kTRUE;
439 switch (fStackFillOpt) {
440 case kFlavorSelection:
443 case kParentSelection:
444 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
447 if (flavorOK && selectOK) {
449 // Heavy flavor hadron or quark
451 // Kinematic seletion on final state heavy flavor mesons
452 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
457 if (ParentSelected(kf)) ++nParents; // Update parent count
458 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
460 // Kinematic seletion on decay products
461 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
462 && !KinematicSelection(iparticle, 1))
468 // Select if mother was selected and is not tracked
470 if (pSelected[ipa] &&
471 !trackIt[ipa] && // mother will be tracked ?
472 kfMo != 5 && // mother is b-quark, don't store fragments
473 kfMo != 4 && // mother is c-quark, don't store fragments
474 kf != 92) // don't store string
477 // Semi-stable or de-selected: diselect decay products:
480 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
482 Int_t ipF = iparticle->GetFirstDaughter();
483 Int_t ipL = iparticle->GetLastDaughter();
484 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
486 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
487 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
490 if (pSelected[i] == -1) pSelected[i] = 0;
491 if (!pSelected[i]) continue;
492 // Count quarks only if you did not include fragmentation
493 if (fFragmentation && kf <= 10) continue;
495 // Decision on tracking
498 // Track final state particle
499 if (ks == 1) trackIt[i] = 1;
500 // Track semi-stable particles
501 if ((ks ==1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
502 // Track particles selected by process if undecayed.
503 if (fForceDecay == kNoDecay) {
504 if (ParentSelected(kf)) trackIt[i] = 1;
506 if (ParentSelected(kf)) trackIt[i] = 0;
508 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
512 } // particle selection loop
514 for (i = 0; i<np; i++) {
515 if (!pSelected[i]) continue;
516 TParticle * iparticle = (TParticle *) fParticles->At(i);
517 kf = CheckPDGCode(iparticle->GetPdgCode());
518 Int_t ks = iparticle->GetStatusCode();
519 p[0] = iparticle->Px();
520 p[1] = iparticle->Py();
521 p[2] = iparticle->Pz();
522 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
523 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
524 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
525 Float_t tof = kconv*iparticle->T();
526 Int_t ipa = iparticle->GetFirstMother()-1;
527 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
528 SetTrack(fTrackIt*trackIt[i] ,
529 iparent, kf, p, origin, polar, tof, kPPrimary, nt, 1., ks);
538 if (pParent) delete[] pParent;
539 if (pSelected) delete[] pSelected;
540 if (trackIt) delete[] trackIt;
543 switch (fCountMode) {
545 // printf(" Count all \n");
549 // printf(" Count parents \n");
552 case kCountTrackables:
553 // printf(" Count trackable \n");
557 if (jev >= fNpart || fNpart == -1) {
558 fKineBias=Float_t(fNpart)/Float_t(fTrials);
559 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
565 SetHighWaterMark(nt);
566 // adjust weight due to kinematic selection
569 fXsection=fPythia->GetPARI(1);
572 Int_t AliGenPythia::GenerateMB()
575 // Min Bias selection and other global selections
577 Int_t i, kf, nt, iparent;
580 Float_t polar[3] = {0,0,0};
581 Float_t origin[3] = {0,0,0};
582 // converts from mm/c to s
583 const Float_t kconv=0.001/2.999792458e8;
585 Int_t np = fParticles->GetEntriesFast();
586 Int_t* pParent = new Int_t[np];
587 for (i=0; i< np; i++) pParent[i] = -1;
588 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
589 TParticle* jet1 = (TParticle *) fParticles->At(6);
590 TParticle* jet2 = (TParticle *) fParticles->At(7);
591 if (!CheckTrigger(jet1, jet2)) return 0;
594 for (i = 0; i<np; i++) {
596 TParticle * iparticle = (TParticle *) fParticles->At(i);
597 kf = CheckPDGCode(iparticle->GetPdgCode());
598 Int_t ks = iparticle->GetStatusCode();
599 Int_t km = iparticle->GetFirstMother();
600 // printf("\n Particle: %d %d %d", i, kf, ks);
602 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
604 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
606 if (ks == 1) trackIt = 1;
607 Int_t ipa = iparticle->GetFirstMother()-1;
609 iparent = (ipa > -1) ? pParent[ipa] : -1;
612 // store track information
613 p[0] = iparticle->Px();
614 p[1] = iparticle->Py();
615 p[2] = iparticle->Pz();
616 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
617 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
618 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
619 Float_t tof=kconv*iparticle->T();
620 SetTrack(fTrackIt*trackIt, iparent, kf, p, origin, polar,
621 tof, kPPrimary, nt, 1., ks);
627 if (pParent) delete[] pParent;
629 printf("\n I've put %i particles on the stack \n",nc);
634 void AliGenPythia::FinishRun()
636 // Print x-section summary
640 void AliGenPythia::AdjustWeights()
642 // Adjust the weights after generation of all events
645 Int_t ntrack=gAlice->GetNtrack();
646 for (Int_t i=0; i<ntrack; i++) {
647 part= gAlice->Particle(i);
648 part->SetWeight(part->GetWeight()*fKineBias);
652 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
654 // Treat protons as inside nuclei with mass numbers a1 and a2
660 void AliGenPythia::MakeHeader() const
662 // Builds the event header, to be called after each event
663 AliGenEventHeader* header = new AliGenPythiaEventHeader("Pythia");
664 ((AliGenPythiaEventHeader*) header)->SetProcessType(fPythia->GetMSTI(1));
665 ((AliGenPythiaEventHeader*) header)->SetTrials(fTrials);
666 header->SetPrimaryVertex(fEventVertex);
667 gAlice->SetGenEventHeader(header);
671 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2) const
673 // Check the kinematic trigger condition
676 eta[0] = jet1->Eta();
677 eta[1] = jet2->Eta();
679 phi[0] = jet1->Phi();
680 phi[1] = jet2->Phi();
682 pdg[0] = jet1->GetPdgCode();
683 pdg[1] = jet2->GetPdgCode();
684 Bool_t triggered = kFALSE;
686 if (fProcess == kPyJets) {
687 //Check eta range first...
688 if ((eta[0] < fEtaMaxJet && eta[0] > fEtaMinJet) ||
689 (eta[1] < fEtaMaxJet && eta[1] > fEtaMinJet))
691 //Eta is okay, now check phi range
692 if ((phi[0] < fPhiMaxJet && phi[0] > fPhiMinJet) ||
693 (phi[1] < fPhiMaxJet && phi[1] > fPhiMinJet))
701 if (pdg[0] == kGamma) {
705 //Check eta range first...
706 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
707 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
709 //Eta is okay, now check phi range
710 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
711 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
722 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
724 // Assignment operator
731 void AliGenPythia::Streamer(TBuffer &R__b)
733 // Stream an object of class AliGenPythia.
735 if (R__b.IsReading()) {
736 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
737 AliGenerator::Streamer(R__b);
738 R__b >> (Int_t&)fProcess;
739 R__b >> (Int_t&)fStrucFunc;
740 R__b >> (Int_t&)fForceDecay;
744 fParentSelect.Streamer(R__b);
745 fChildSelect.Streamer(R__b);
747 // (AliPythia::Instance())->Streamer(R__b);
750 // if (fDecayer) fDecayer->Streamer(R__b);
752 R__b.WriteVersion(AliGenPythia::IsA());
753 AliGenerator::Streamer(R__b);
754 R__b << (Int_t)fProcess;
755 R__b << (Int_t)fStrucFunc;
756 R__b << (Int_t)fForceDecay;
760 fParentSelect.Streamer(R__b);
761 fChildSelect.Streamer(R__b);
766 // fDecayer->Streamer(R__b);