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.48 2001/12/20 11:44:28 morsch
19 Add kinematic bias for direct gamma production.
21 Revision 1.47 2001/12/19 14:45:00 morsch
22 Store number of trials in header.
24 Revision 1.46 2001/12/19 10:36:19 morsch
25 Add possibility if jet kinematic biasing.
27 Revision 1.45 2001/11/28 08:06:52 morsch
28 Use fMaxLifeTime parameter.
30 Revision 1.44 2001/11/27 13:13:07 morsch
31 Maximum lifetime for long-lived particles to be put on the stack is parameter.
32 It can be set via SetMaximumLifetime(..).
34 Revision 1.43 2001/10/21 18:35:56 hristov
35 Several pointers were set to zero in the default constructors to avoid memory management problems
37 Revision 1.42 2001/10/15 08:21:55 morsch
38 Vertex truncation settings moved to AliGenMC.
40 Revision 1.41 2001/10/08 08:45:42 morsch
41 Possibility of vertex cut added.
43 Revision 1.40 2001/09/25 11:30:23 morsch
44 Pass event vertex to header.
46 Revision 1.39 2001/07/27 17:09:36 morsch
47 Use local SetTrack, KeepTrack and SetHighWaterMark methods
48 to delegate either to local stack or to stack owned by AliRun.
49 (Piotr Skowronski, A.M.)
51 Revision 1.38 2001/07/13 10:58:54 morsch
52 - Some coded moved to AliGenMC
53 - Improved handling of secondary vertices.
55 Revision 1.37 2001/06/28 11:17:28 morsch
56 SetEventListRange setter added. Events in specified range are listed for
57 debugging. (Yuri Kharlov)
59 Revision 1.36 2001/03/30 07:05:49 morsch
60 Final print-out in finish run.
61 Write parton system for jet-production (preliminary solution).
63 Revision 1.35 2001/03/09 13:03:40 morsch
64 Process_t and Struc_Func_t moved to AliPythia.h
66 Revision 1.34 2001/02/14 15:50:40 hristov
67 The last particle in event marked using SetHighWaterMark
69 Revision 1.33 2001/01/30 09:23:12 hristov
70 Streamers removed (R.Brun)
72 Revision 1.32 2001/01/26 19:55:51 hristov
73 Major upgrade of AliRoot code
75 Revision 1.31 2001/01/17 10:54:31 hristov
76 Better protection against FPE
78 Revision 1.30 2000/12/18 08:55:35 morsch
79 Make AliPythia dependent generartors work with new scheme of random number generation
81 Revision 1.29 2000/12/04 11:22:03 morsch
82 Init of sRandom as in 1.15
84 Revision 1.28 2000/12/02 11:41:39 morsch
85 Use SetRandom() to initialize random number generator in constructor.
87 Revision 1.27 2000/11/30 20:29:02 morsch
88 Initialise static variable sRandom in constructor: sRandom = fRandom;
90 Revision 1.26 2000/11/30 07:12:50 alibrary
91 Introducing new Rndm and QA classes
93 Revision 1.25 2000/10/18 19:11:27 hristov
94 Division by zero fixed
96 Revision 1.24 2000/09/18 10:41:35 morsch
97 Add possibility to use nuclear structure functions from PDF library V8.
99 Revision 1.23 2000/09/14 14:05:40 morsch
102 Revision 1.22 2000/09/14 14:02:22 morsch
103 - Correct conversion from mm to cm when passing particle vertex to MC.
104 - Correct handling of fForceDecay == all.
106 Revision 1.21 2000/09/12 14:14:55 morsch
107 Call fDecayer->ForceDecay() at the beginning of Generate().
109 Revision 1.20 2000/09/06 14:29:33 morsch
110 Use AliPythia for event generation an AliDecayPythia for decays.
111 Correct handling of "nodecay" option
113 Revision 1.19 2000/07/11 18:24:56 fca
114 Coding convention corrections + few minor bug fixes
116 Revision 1.18 2000/06/30 12:40:34 morsch
117 Pythia takes care of vertex smearing. Correct conversion from Pythia units (mm) to
120 Revision 1.17 2000/06/09 20:34:07 morsch
121 All coding rule violations except RS3 corrected
123 Revision 1.16 2000/05/15 15:04:20 morsch
124 The full event is written for fNtrack = -1
125 Coding rule violations corrected.
127 Revision 1.15 2000/04/26 10:14:24 morsch
128 Particles array has one entry more than pythia particle list. Upper bound of
129 particle loop changed to np-1 (R. Guernane, AM)
131 Revision 1.14 2000/04/05 08:36:13 morsch
132 Check status code of particles in Pythia event
133 to avoid double counting as partonic state and final state particle.
135 Revision 1.13 1999/11/09 07:38:48 fca
136 Changes for compatibility with version 2.23 of ROOT
138 Revision 1.12 1999/11/03 17:43:20 fca
139 New version from G.Martinez & A.Morsch
141 Revision 1.11 1999/09/29 09:24:14 fca
142 Introduction of the Copyright and cvs Log
145 #include "AliGenPythia.h"
146 #include "AliGenPythiaEventHeader.h"
147 #include "AliDecayerPythia.h"
149 #include "AliPythia.h"
151 #include <TParticle.h>
154 ClassImp(AliGenPythia)
156 AliGenPythia::AliGenPythia()
159 // Default Constructor
162 fDecayer = new AliDecayerPythia();
168 AliGenPythia::AliGenPythia(Int_t npart)
171 // default charm production at 5. 5 TeV
173 // structure function GRVHO
176 fTitle= "Particle Generator using PYTHIA";
185 fDecayer = new AliDecayerPythia();
186 // Set random number generator
189 // Produced particles
190 fParticles = new TClonesArray("TParticle",1000);
197 AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
202 AliGenPythia::~AliGenPythia()
207 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
209 // Set a range of event numbers, for which a table
210 // of generated particle will be printed
211 fDebugEventFirst = eventFirst;
212 fDebugEventLast = eventLast;
213 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
216 void AliGenPythia::Init()
219 SetMC(AliPythia::Instance());
220 fPythia=(AliPythia*) fgMCEvGen;
222 fParentWeight=1./Float_t(fNpart);
224 // Forward Paramters to the AliPythia object
225 fDecayer->SetForceDecay(fForceDecay);
229 fPythia->SetCKIN(3,fPtHardMin);
230 fPythia->SetCKIN(4,fPtHardMax);
231 if (fNucA1 > 0 && fNucA2 > 0) fPythia->SetNuclei(fNucA1, fNucA2);
232 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
234 // fPythia->Pylist(0);
235 // fPythia->Pystat(2);
236 // Parent and Children Selection
240 fParentSelect[0] = 411;
241 fParentSelect[1] = 421;
242 fParentSelect[2] = 431;
243 fParentSelect[3] = 4122;
246 case kPyCharmUnforced:
247 fParentSelect[0] = 411;
248 fParentSelect[1] = 421;
249 fParentSelect[2] = 431;
250 fParentSelect[3] = 4122;
254 fParentSelect[0]= 511;
255 fParentSelect[1]= 521;
256 fParentSelect[2]= 531;
257 fParentSelect[3]= 5122;
258 fParentSelect[4]= 5132;
259 fParentSelect[5]= 5232;
260 fParentSelect[6]= 5332;
263 case kPyBeautyUnforced:
264 fParentSelect[0] = 511;
265 fParentSelect[1] = 521;
266 fParentSelect[2] = 531;
267 fParentSelect[3] = 5122;
268 fParentSelect[4] = 5132;
269 fParentSelect[5] = 5232;
270 fParentSelect[6] = 5332;
275 fParentSelect[0] = 443;
285 void AliGenPythia::Generate()
287 // Generate one event
288 fDecayer->ForceDecay();
290 Float_t polar[3] = {0,0,0};
291 Float_t origin[3] = {0,0,0};
293 // converts from mm/c to s
294 const Float_t kconv=0.001/2.999792458e8;
301 // Set collision vertex position
302 if(fVertexSmear==kPerEvent) {
303 fPythia->SetMSTP(151,1);
305 fPythia->SetPARP(151+j, fOsigma[j]*10.);
307 } else if (fVertexSmear==kPerTrack) {
308 fPythia->SetMSTP(151,0);
314 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
315 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
318 fPythia->ImportParticles(fParticles,"All");
325 Int_t np = fParticles->GetEntriesFast();
326 if (np == 0 ) continue;
327 // Get event vertex and discard the event if the Z coord. is too big
328 TParticle *iparticle = (TParticle *) fParticles->At(0);
329 Float_t distz = iparticle->Vz()/10.;
330 if(TMath::Abs(distz)>fCutVertexZ*fOsigma[2]) continue;
332 fEventVertex[0] = iparticle->Vx()/10.+fOrigin.At(0);
333 fEventVertex[1] = iparticle->Vy()/10.+fOrigin.At(1);
334 fEventVertex[2] = iparticle->Vz()/10.+fOrigin.At(2);
336 Int_t* pParent = new Int_t[np];
337 Int_t* pSelected = new Int_t[np];
338 Int_t* trackIt = new Int_t[np];
339 for (i=0; i< np-1; i++) {
343 printf("\n **************************************************%d\n",np);
345 if (fProcess != kPyMb && fProcess != kPyJets && fProcess != kPyDirectGamma) {
347 for (i = 0; i<np-1; i++) {
348 iparticle = (TParticle *) fParticles->At(i);
349 Int_t ks = iparticle->GetStatusCode();
350 kf = CheckPDGCode(iparticle->GetPdgCode());
351 // No initial state partons
352 if (ks==21) continue;
354 // Heavy Flavor Selection
360 if (kfl > 10) kfl/=100;
362 if (kfl > 10) kfl/=10;
363 if (kfl > 10) kfl/=10;
365 Int_t ipa = iparticle->GetFirstMother()-1;
369 TParticle * mother = (TParticle *) fParticles->At(ipa);
370 kfMo = TMath::Abs(mother->GetPdgCode());
372 // printf("\n particle (all) %d %d %d", i, pSelected[i], kf);
373 if (kfl >= fFlavorSelect) {
375 // Heavy flavor hadron or quark
377 // Kinematic seletion on final state heavy flavor mesons
378 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
384 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
386 // Kinematic seletion on decay products
387 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
388 && !KinematicSelection(iparticle, 1))
395 // Select if mother was selected and is not tracked
397 if (pSelected[ipa] &&
398 !trackIt[ipa] && // mother will be tracked ?
399 kfMo != 5 && // mother is b-quark, don't store fragments
400 kfMo != 4 && // mother is c-quark, don't store fragments
401 kf != 92) // don't store string
404 // Semi-stable or de-selected: diselect decay products:
407 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
409 Int_t ipF = iparticle->GetFirstDaughter();
410 Int_t ipL = iparticle->GetLastDaughter();
411 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
413 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
414 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
417 if (pSelected[i] == -1) pSelected[i] = 0;
418 if (!pSelected[i]) continue;
420 // Decision on tracking
423 // Track final state particle
424 if (ks == 1) trackIt[i] = 1;
425 // Track semi-stable particles
426 if ((ks ==1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
427 // Track particles selected by process if undecayed.
428 if (fForceDecay == kNoDecay) {
429 if (ParentSelected(kf)) trackIt[i] = 1;
431 if (ParentSelected(kf)) trackIt[i] = 0;
436 } // particle selection loop
438 for (i = 0; i<np-1; i++) {
439 if (!pSelected[i]) continue;
440 TParticle * iparticle = (TParticle *) fParticles->At(i);
441 kf = CheckPDGCode(iparticle->GetPdgCode());
442 p[0] = iparticle->Px();
443 p[1] = iparticle->Py();
444 p[2] = iparticle->Pz();
445 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
446 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
447 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
448 Float_t tof = kconv*iparticle->T();
449 Int_t ipa = iparticle->GetFirstMother()-1;
450 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
451 SetTrack(fTrackIt*trackIt[i] ,
452 iparent, kf, p, origin, polar, tof, kPPrimary, nt, 1.);
463 if (jev >= fNpart || fNpart == -1) {
464 fKineBias=Float_t(fNpart)/Float_t(fTrials);
465 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
471 SetHighWaterMark(nt);
472 // adjust weight due to kinematic selection
475 fXsection=fPythia->GetPARI(1);
478 Int_t AliGenPythia::GenerateMB()
480 Int_t i, kf, nt, iparent;
483 Float_t polar[3] = {0,0,0};
484 Float_t origin[3] = {0,0,0};
485 // converts from mm/c to s
486 const Float_t kconv=0.001/2.999792458e8;
488 Int_t np = fParticles->GetEntriesFast();
489 Int_t* pParent = new Int_t[np];
490 for (i=0; i< np-1; i++) pParent[i] = -1;
491 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
492 TParticle* jet1 = (TParticle *) fParticles->At(6);
493 TParticle* jet2 = (TParticle *) fParticles->At(7);
494 if (!CheckTrigger(jet1, jet2)) return 0;
497 for (i = 0; i<np-1; i++) {
499 TParticle * iparticle = (TParticle *) fParticles->At(i);
500 kf = CheckPDGCode(iparticle->GetPdgCode());
501 Int_t ks = iparticle->GetStatusCode();
502 Int_t km = iparticle->GetFirstMother();
503 // printf("\n Particle: %d %d %d", i, kf, ks);
505 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
507 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
509 if (ks == 1) trackIt = 1;
510 Int_t ipa = iparticle->GetFirstMother()-1;
512 iparent = (ipa > -1) ? pParent[ipa] : -1;
515 // store track information
516 p[0] = iparticle->Px();
517 p[1] = iparticle->Py();
518 p[2] = iparticle->Pz();
519 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
520 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
521 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
522 Float_t tof=kconv*iparticle->T();
523 SetTrack(fTrackIt*trackIt, iparent, kf, p, origin, polar,
530 if (pParent) delete[] pParent;
532 printf("\n I've put %i particles on the stack \n",nc);
537 void AliGenPythia::FinishRun()
539 // Print x-section summary
543 void AliGenPythia::AdjustWeights()
545 // Adjust the weights after generation of all events
548 Int_t ntrack=gAlice->GetNtrack();
549 for (Int_t i=0; i<ntrack; i++) {
550 part= gAlice->Particle(i);
551 part->SetWeight(part->GetWeight()*fKineBias);
555 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
557 // Treat protons as inside nuclei with mass numbers a1 and a2
563 void AliGenPythia::MakeHeader()
565 // Builds the event header, to be called after each event
566 AliGenEventHeader* header = new AliGenPythiaEventHeader("Pythia");
567 ((AliGenPythiaEventHeader*) header)->SetProcessType(fPythia->GetMSTI(1));
568 ((AliGenPythiaEventHeader*) header)->SetTrials(fTrials);
569 header->SetPrimaryVertex(fEventVertex);
570 gAlice->SetGenEventHeader(header);
574 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
576 // Check the kinematic trigger condition
579 eta[0] = jet1->Eta();
580 eta[1] = jet2->Eta();
582 phi[0] = jet1->Phi();
583 phi[1] = jet2->Phi();
585 pdg[0] = jet1->GetPdgCode();
586 pdg[1] = jet2->GetPdgCode();
587 Bool_t triggered = kFALSE;
589 if (fProcess == kPyJets) {
590 //Check eta range first...
591 if ((eta[0] < fEtaMaxJet && eta[0] > fEtaMinJet) ||
592 (eta[1] < fEtaMaxJet && eta[1] > fEtaMinJet))
594 //Eta is okay, now check phi range
595 if ((phi[0] < fPhiMaxJet && phi[0] > fPhiMinJet) ||
596 (phi[1] < fPhiMaxJet && phi[1] > fPhiMinJet))
604 if (pdg[0] == kGamma) {
608 //Check eta range first...
609 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
610 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
612 //Eta is okay, now check phi range
613 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
614 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
625 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
627 // Assignment operator
634 void AliGenPythia::Streamer(TBuffer &R__b)
636 // Stream an object of class AliGenPythia.
638 if (R__b.IsReading()) {
639 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
640 AliGenerator::Streamer(R__b);
641 R__b >> (Int_t&)fProcess;
642 R__b >> (Int_t&)fStrucFunc;
643 R__b >> (Int_t&)fForceDecay;
647 fParentSelect.Streamer(R__b);
648 fChildSelect.Streamer(R__b);
650 // (AliPythia::Instance())->Streamer(R__b);
653 // if (fDecayer) fDecayer->Streamer(R__b);
655 R__b.WriteVersion(AliGenPythia::IsA());
656 AliGenerator::Streamer(R__b);
657 R__b << (Int_t)fProcess;
658 R__b << (Int_t)fStrucFunc;
659 R__b << (Int_t)fForceDecay;
663 fParentSelect.Streamer(R__b);
664 fChildSelect.Streamer(R__b);
669 // fDecayer->Streamer(R__b);