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.43 2001/10/21 18:35:56 hristov
19 Several pointers were set to zero in the default constructors to avoid memory management problems
21 Revision 1.42 2001/10/15 08:21:55 morsch
22 Vertex truncation settings moved to AliGenMC.
24 Revision 1.41 2001/10/08 08:45:42 morsch
25 Possibility of vertex cut added.
27 Revision 1.40 2001/09/25 11:30:23 morsch
28 Pass event vertex to header.
30 Revision 1.39 2001/07/27 17:09:36 morsch
31 Use local SetTrack, KeepTrack and SetHighWaterMark methods
32 to delegate either to local stack or to stack owned by AliRun.
33 (Piotr Skowronski, A.M.)
35 Revision 1.38 2001/07/13 10:58:54 morsch
36 - Some coded moved to AliGenMC
37 - Improved handling of secondary vertices.
39 Revision 1.37 2001/06/28 11:17:28 morsch
40 SetEventListRange setter added. Events in specified range are listed for
41 debugging. (Yuri Kharlov)
43 Revision 1.36 2001/03/30 07:05:49 morsch
44 Final print-out in finish run.
45 Write parton system for jet-production (preliminary solution).
47 Revision 1.35 2001/03/09 13:03:40 morsch
48 Process_t and Struc_Func_t moved to AliPythia.h
50 Revision 1.34 2001/02/14 15:50:40 hristov
51 The last particle in event marked using SetHighWaterMark
53 Revision 1.33 2001/01/30 09:23:12 hristov
54 Streamers removed (R.Brun)
56 Revision 1.32 2001/01/26 19:55:51 hristov
57 Major upgrade of AliRoot code
59 Revision 1.31 2001/01/17 10:54:31 hristov
60 Better protection against FPE
62 Revision 1.30 2000/12/18 08:55:35 morsch
63 Make AliPythia dependent generartors work with new scheme of random number generation
65 Revision 1.29 2000/12/04 11:22:03 morsch
66 Init of sRandom as in 1.15
68 Revision 1.28 2000/12/02 11:41:39 morsch
69 Use SetRandom() to initialize random number generator in constructor.
71 Revision 1.27 2000/11/30 20:29:02 morsch
72 Initialise static variable sRandom in constructor: sRandom = fRandom;
74 Revision 1.26 2000/11/30 07:12:50 alibrary
75 Introducing new Rndm and QA classes
77 Revision 1.25 2000/10/18 19:11:27 hristov
78 Division by zero fixed
80 Revision 1.24 2000/09/18 10:41:35 morsch
81 Add possibility to use nuclear structure functions from PDF library V8.
83 Revision 1.23 2000/09/14 14:05:40 morsch
86 Revision 1.22 2000/09/14 14:02:22 morsch
87 - Correct conversion from mm to cm when passing particle vertex to MC.
88 - Correct handling of fForceDecay == all.
90 Revision 1.21 2000/09/12 14:14:55 morsch
91 Call fDecayer->ForceDecay() at the beginning of Generate().
93 Revision 1.20 2000/09/06 14:29:33 morsch
94 Use AliPythia for event generation an AliDecayPythia for decays.
95 Correct handling of "nodecay" option
97 Revision 1.19 2000/07/11 18:24:56 fca
98 Coding convention corrections + few minor bug fixes
100 Revision 1.18 2000/06/30 12:40:34 morsch
101 Pythia takes care of vertex smearing. Correct conversion from Pythia units (mm) to
104 Revision 1.17 2000/06/09 20:34:07 morsch
105 All coding rule violations except RS3 corrected
107 Revision 1.16 2000/05/15 15:04:20 morsch
108 The full event is written for fNtrack = -1
109 Coding rule violations corrected.
111 Revision 1.15 2000/04/26 10:14:24 morsch
112 Particles array has one entry more than pythia particle list. Upper bound of
113 particle loop changed to np-1 (R. Guernane, AM)
115 Revision 1.14 2000/04/05 08:36:13 morsch
116 Check status code of particles in Pythia event
117 to avoid double counting as partonic state and final state particle.
119 Revision 1.13 1999/11/09 07:38:48 fca
120 Changes for compatibility with version 2.23 of ROOT
122 Revision 1.12 1999/11/03 17:43:20 fca
123 New version from G.Martinez & A.Morsch
125 Revision 1.11 1999/09/29 09:24:14 fca
126 Introduction of the Copyright and cvs Log
129 #include "AliGenPythia.h"
130 #include "AliGenPythiaEventHeader.h"
131 #include "AliDecayerPythia.h"
133 #include "AliPythia.h"
135 #include <TParticle.h>
138 ClassImp(AliGenPythia)
140 AliGenPythia::AliGenPythia()
143 // Default Constructor
146 fDecayer = new AliDecayerPythia();
150 AliGenPythia::AliGenPythia(Int_t npart)
153 // default charm production at 5. 5 TeV
155 // structure function GRVHO
165 fDecayer = new AliDecayerPythia();
166 // Set random number generator
170 // Produced particles
171 fParticles = new TClonesArray("TParticle",1000);
175 AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
180 AliGenPythia::~AliGenPythia()
185 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
187 // Set a range of event numbers, for which a table
188 // of generated particle will be printed
189 fDebugEventFirst = eventFirst;
190 fDebugEventLast = eventLast;
191 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
194 void AliGenPythia::Init()
197 SetMC(AliPythia::Instance());
198 fPythia=(AliPythia*) fgMCEvGen;
200 fParentWeight=1./Float_t(fNpart);
202 // Forward Paramters to the AliPythia object
203 fDecayer->SetForceDecay(fForceDecay);
207 fPythia->SetCKIN(3,fPtHardMin);
208 fPythia->SetCKIN(4,fPtHardMax);
209 if (fNucA1 > 0 && fNucA2 > 0) fPythia->SetNuclei(fNucA1, fNucA2);
210 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
212 // fPythia->Pylist(0);
213 // fPythia->Pystat(2);
214 // Parent and Children Selection
218 fParentSelect[0] = 411;
219 fParentSelect[1] = 421;
220 fParentSelect[2] = 431;
221 fParentSelect[3] = 4122;
224 case kPyCharmUnforced:
225 fParentSelect[0] = 411;
226 fParentSelect[1] = 421;
227 fParentSelect[2] = 431;
228 fParentSelect[3]= 4122;
232 fParentSelect[0]= 511;
233 fParentSelect[1]= 521;
234 fParentSelect[2]= 531;
235 fParentSelect[3]= 5122;
236 fParentSelect[4]= 5132;
237 fParentSelect[5]= 5232;
238 fParentSelect[6]= 5332;
241 case kPyBeautyUnforced:
242 fParentSelect[0] = 511;
243 fParentSelect[1] = 521;
244 fParentSelect[2] = 531;
245 fParentSelect[3] = 5122;
246 fParentSelect[4] = 5132;
247 fParentSelect[5] = 5232;
248 fParentSelect[6] = 5332;
253 fParentSelect[0] = 443;
263 void AliGenPythia::Generate()
265 // Generate one event
266 fDecayer->ForceDecay();
268 Float_t polar[3] = {0,0,0};
269 Float_t origin[3] = {0,0,0};
271 // converts from mm/c to s
272 const Float_t kconv=0.001/2.999792458e8;
279 // Set collision vertex position
280 if(fVertexSmear==kPerEvent) {
281 fPythia->SetMSTP(151,1);
283 fPythia->SetPARP(151+j, fOsigma[j]*10.);
285 } else if (fVertexSmear==kPerTrack) {
286 fPythia->SetMSTP(151,0);
292 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
293 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
296 fPythia->ImportParticles(fParticles,"All");
303 Int_t np = fParticles->GetEntriesFast();
304 if (np == 0 ) continue;
305 // Get event vertex and discard the event if the Z coord. is too big
306 TParticle *iparticle = (TParticle *) fParticles->At(0);
307 Float_t distz = iparticle->Vz()/10.;
308 if(TMath::Abs(distz)>fCutVertexZ*fOsigma[2]) continue;
310 fEventVertex[0] = iparticle->Vx()/10.+fOrigin.At(0);
311 fEventVertex[1] = iparticle->Vy()/10.+fOrigin.At(1);
312 fEventVertex[2] = iparticle->Vz()/10.+fOrigin.At(2);
314 Int_t* pParent = new Int_t[np];
315 Int_t* pSelected = new Int_t[np];
316 Int_t* trackIt = new Int_t[np];
317 for (i=0; i< np-1; i++) {
321 printf("\n **************************************************%d\n",np);
323 if (fProcess != kPyMb && fProcess != kPyJets && fProcess != kPyDirectGamma) {
324 for (i = 0; i<np-1; i++) {
325 iparticle = (TParticle *) fParticles->At(i);
326 Int_t ks = iparticle->GetStatusCode();
327 kf = CheckPDGCode(iparticle->GetPdgCode());
328 // No initial state partons
329 if (ks==21) continue;
331 // Heavy Flavor Selection
337 if (kfl > 10) kfl/=100;
339 if (kfl > 10) kfl/=10;
340 if (kfl > 10) kfl/=10;
342 Int_t ipa = iparticle->GetFirstMother()-1;
346 TParticle * mother = (TParticle *) fParticles->At(ipa);
347 kfMo = TMath::Abs(mother->GetPdgCode());
349 // printf("\n particle (all) %d %d %d", i, pSelected[i], kf);
350 if (kfl >= fFlavorSelect) {
352 // Heavy flavor hadron or quark
354 // Kinematic seletion on final state heavy flavor mesons
355 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
361 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
363 // Kinematic seletion on decay products
364 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
365 && !KinematicSelection(iparticle, 1))
372 // Select if mother was selected and is not tracked
374 if (pSelected[ipa] &&
375 !trackIt[ipa] && // mother will be tracked ?
376 kfMo != 5 && // mother is b-quark, don't store fragments
377 kfMo != 4 && // mother is c-quark, don't store fragments
378 kf != 92) // don't store string
381 // Semi-stable or de-selected: diselect decay products:
384 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
386 Int_t ipF = iparticle->GetFirstDaughter();
387 Int_t ipL = iparticle->GetLastDaughter();
388 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
390 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
391 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
394 if (pSelected[i] == -1) pSelected[i] = 0;
395 if (!pSelected[i]) continue;
397 // Decision on tracking
400 // Track final state particle
401 if (ks == 1) trackIt[i] = 1;
402 // Track semi-stable particles
403 if ((ks ==1) || (fDecayer->GetLifetime(kf)> 10e-15)) trackIt[i] = 1;
404 // Track particles selected by process if undecayed.
405 if (fForceDecay == kNoDecay) {
406 if (ParentSelected(kf)) trackIt[i] = 1;
408 if (ParentSelected(kf)) trackIt[i] = 0;
413 } // particle selection loop
415 for (i = 0; i<np-1; i++) {
416 if (!pSelected[i]) continue;
417 TParticle * iparticle = (TParticle *) fParticles->At(i);
418 kf = CheckPDGCode(iparticle->GetPdgCode());
419 p[0] = iparticle->Px();
420 p[1] = iparticle->Py();
421 p[2] = iparticle->Pz();
422 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
423 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
424 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
425 Float_t tof = kconv*iparticle->T();
426 Int_t ipa = iparticle->GetFirstMother()-1;
427 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
428 SetTrack(fTrackIt*trackIt[i] ,
429 iparent, kf, p, origin, polar, tof, kPPrimary, nt, 1.);
440 if (jev >= fNpart || fNpart == -1) {
441 fKineBias=Float_t(fNpart)/Float_t(fTrials);
442 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
447 SetHighWaterMark(nt);
448 // adjust weight due to kinematic selection
451 fXsection=fPythia->GetPARI(1);
454 Int_t AliGenPythia::GenerateMB()
456 Int_t i, kf, nt, iparent;
459 Float_t polar[3] = {0,0,0};
460 Float_t origin[3] = {0,0,0};
461 // converts from mm/c to s
462 const Float_t kconv=0.001/2.999792458e8;
464 Int_t np = fParticles->GetEntriesFast();
465 Int_t* pParent = new Int_t[np];
466 for (i=0; i< np-1; i++) pParent[i] = -1;
468 for (i = 0; i<np-1; i++) {
470 TParticle * iparticle = (TParticle *) fParticles->At(i);
471 kf = CheckPDGCode(iparticle->GetPdgCode());
472 Int_t ks = iparticle->GetStatusCode();
473 Int_t km = iparticle->GetFirstMother();
474 // printf("\n Particle: %d %d %d", i, kf, ks);
476 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
478 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
480 if (ks == 1) trackIt = 1;
481 Int_t ipa = iparticle->GetFirstMother()-1;
483 iparent = (ipa > -1) ? pParent[ipa] : -1;
486 // store track information
487 p[0] = iparticle->Px();
488 p[1] = iparticle->Py();
489 p[2] = iparticle->Pz();
490 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
491 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
492 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
493 Float_t tof=kconv*iparticle->T();
494 SetTrack(fTrackIt*trackIt, iparent, kf, p, origin, polar,
501 if (pParent) delete[] pParent;
503 printf("\n I've put %i particles on the stack \n",nc);
509 void AliGenPythia::FinishRun()
511 // Print x-section summary
515 void AliGenPythia::AdjustWeights()
517 // Adjust the weights after generation of all events
520 Int_t ntrack=gAlice->GetNtrack();
521 for (Int_t i=0; i<ntrack; i++) {
522 part= gAlice->Particle(i);
523 part->SetWeight(part->GetWeight()*fKineBias);
527 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
529 // Treat protons as inside nuclei with mass numbers a1 and a2
535 void AliGenPythia::MakeHeader()
537 // Builds the event header, to be called after each event
538 AliGenEventHeader* header = new AliGenPythiaEventHeader("Pythia");
539 ((AliGenPythiaEventHeader*) header)->SetProcessType(fPythia->GetMSTI(1));
540 header->SetPrimaryVertex(fEventVertex);
541 gAlice->SetGenEventHeader(header);
545 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
547 // Assignment operator
554 void AliGenPythia::Streamer(TBuffer &R__b)
556 // Stream an object of class AliGenPythia.
558 if (R__b.IsReading()) {
559 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
560 AliGenerator::Streamer(R__b);
561 R__b >> (Int_t&)fProcess;
562 R__b >> (Int_t&)fStrucFunc;
563 R__b >> (Int_t&)fForceDecay;
567 fParentSelect.Streamer(R__b);
568 fChildSelect.Streamer(R__b);
570 // (AliPythia::Instance())->Streamer(R__b);
573 // if (fDecayer) fDecayer->Streamer(R__b);
575 R__b.WriteVersion(AliGenPythia::IsA());
576 AliGenerator::Streamer(R__b);
577 R__b << (Int_t)fProcess;
578 R__b << (Int_t)fStrucFunc;
579 R__b << (Int_t)fForceDecay;
583 fParentSelect.Streamer(R__b);
584 fChildSelect.Streamer(R__b);
589 // fDecayer->Streamer(R__b);