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.37 2001/06/28 11:17:28 morsch
19 SetEventListRange setter added. Events in specified range are listed for
20 debugging. (Yuri Kharlov)
22 Revision 1.36 2001/03/30 07:05:49 morsch
23 Final print-out in finish run.
24 Write parton system for jet-production (preliminary solution).
26 Revision 1.35 2001/03/09 13:03:40 morsch
27 Process_t and Struc_Func_t moved to AliPythia.h
29 Revision 1.34 2001/02/14 15:50:40 hristov
30 The last particle in event marked using SetHighWaterMark
32 Revision 1.33 2001/01/30 09:23:12 hristov
33 Streamers removed (R.Brun)
35 Revision 1.32 2001/01/26 19:55:51 hristov
36 Major upgrade of AliRoot code
38 Revision 1.31 2001/01/17 10:54:31 hristov
39 Better protection against FPE
41 Revision 1.30 2000/12/18 08:55:35 morsch
42 Make AliPythia dependent generartors work with new scheme of random number generation
44 Revision 1.29 2000/12/04 11:22:03 morsch
45 Init of sRandom as in 1.15
47 Revision 1.28 2000/12/02 11:41:39 morsch
48 Use SetRandom() to initialize random number generator in constructor.
50 Revision 1.27 2000/11/30 20:29:02 morsch
51 Initialise static variable sRandom in constructor: sRandom = fRandom;
53 Revision 1.26 2000/11/30 07:12:50 alibrary
54 Introducing new Rndm and QA classes
56 Revision 1.25 2000/10/18 19:11:27 hristov
57 Division by zero fixed
59 Revision 1.24 2000/09/18 10:41:35 morsch
60 Add possibility to use nuclear structure functions from PDF library V8.
62 Revision 1.23 2000/09/14 14:05:40 morsch
65 Revision 1.22 2000/09/14 14:02:22 morsch
66 - Correct conversion from mm to cm when passing particle vertex to MC.
67 - Correct handling of fForceDecay == all.
69 Revision 1.21 2000/09/12 14:14:55 morsch
70 Call fDecayer->ForceDecay() at the beginning of Generate().
72 Revision 1.20 2000/09/06 14:29:33 morsch
73 Use AliPythia for event generation an AliDecayPythia for decays.
74 Correct handling of "nodecay" option
76 Revision 1.19 2000/07/11 18:24:56 fca
77 Coding convention corrections + few minor bug fixes
79 Revision 1.18 2000/06/30 12:40:34 morsch
80 Pythia takes care of vertex smearing. Correct conversion from Pythia units (mm) to
83 Revision 1.17 2000/06/09 20:34:07 morsch
84 All coding rule violations except RS3 corrected
86 Revision 1.16 2000/05/15 15:04:20 morsch
87 The full event is written for fNtrack = -1
88 Coding rule violations corrected.
90 Revision 1.15 2000/04/26 10:14:24 morsch
91 Particles array has one entry more than pythia particle list. Upper bound of
92 particle loop changed to np-1 (R. Guernane, AM)
94 Revision 1.14 2000/04/05 08:36:13 morsch
95 Check status code of particles in Pythia event
96 to avoid double counting as partonic state and final state particle.
98 Revision 1.13 1999/11/09 07:38:48 fca
99 Changes for compatibility with version 2.23 of ROOT
101 Revision 1.12 1999/11/03 17:43:20 fca
102 New version from G.Martinez & A.Morsch
104 Revision 1.11 1999/09/29 09:24:14 fca
105 Introduction of the Copyright and cvs Log
108 #include "AliGenPythia.h"
109 #include "AliGenPythiaEventHeader.h"
110 #include "AliDecayerPythia.h"
112 #include "AliPythia.h"
114 #include <TParticle.h>
117 ClassImp(AliGenPythia)
119 AliGenPythia::AliGenPythia()
122 // Default Constructor
123 fDecayer = new AliDecayerPythia();
127 AliGenPythia::AliGenPythia(Int_t npart)
130 // default charm production at 5. 5 TeV
132 // structure function GRVHO
142 fDecayer = new AliDecayerPythia();
143 // Set random number generator
147 // Produced particles
148 fParticles = new TClonesArray("TParticle",1000);
151 AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
156 AliGenPythia::~AliGenPythia()
161 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
163 // Set a range of event numbers, for which a table
164 // of generated particle will be printed
165 fDebugEventFirst = eventFirst;
166 fDebugEventLast = eventLast;
167 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
170 void AliGenPythia::Init()
173 SetMC(AliPythia::Instance());
174 fPythia=(AliPythia*) fgMCEvGen;
176 fParentWeight=1./Float_t(fNpart);
178 // Forward Paramters to the AliPythia object
179 fDecayer->SetForceDecay(fForceDecay);
183 fPythia->SetCKIN(3,fPtHardMin);
184 fPythia->SetCKIN(4,fPtHardMax);
185 if (fNucA1 > 0 && fNucA2 > 0) fPythia->SetNuclei(fNucA1, fNucA2);
186 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
188 // fPythia->Pylist(0);
189 // fPythia->Pystat(2);
190 // Parent and Children Selection
194 fParentSelect[0] = 411;
195 fParentSelect[1] = 421;
196 fParentSelect[2] = 431;
197 fParentSelect[3] = 4122;
200 case kPyCharmUnforced:
201 fParentSelect[0] = 411;
202 fParentSelect[1] = 421;
203 fParentSelect[2] = 431;
204 fParentSelect[3]= 4122;
208 fParentSelect[0]= 511;
209 fParentSelect[1]= 521;
210 fParentSelect[2]= 531;
211 fParentSelect[3]= 5122;
212 fParentSelect[4]= 5132;
213 fParentSelect[5]= 5232;
214 fParentSelect[6]= 5332;
217 case kPyBeautyUnforced:
218 fParentSelect[0] = 511;
219 fParentSelect[1] = 521;
220 fParentSelect[2] = 531;
221 fParentSelect[3] = 5122;
222 fParentSelect[4] = 5132;
223 fParentSelect[5] = 5232;
224 fParentSelect[6] = 5332;
229 fParentSelect[0] = 443;
239 void AliGenPythia::Generate()
241 // Generate one event
242 fDecayer->ForceDecay();
244 Float_t polar[3] = {0,0,0};
245 Float_t origin[3] = {0,0,0};
246 Float_t origin0[3] = {0,0,0};
248 // converts from mm/c to s
249 const Float_t kconv=0.001/2.999792458e8;
256 // Set collision vertex position
257 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
258 if(fVertexSmear==kPerEvent) {
259 fPythia->SetMSTP(151,1);
261 fPythia->SetPARP(151+j, fOsigma[j]*10.);
263 } else if (fVertexSmear==kPerTrack) {
264 fPythia->SetMSTP(151,0);
270 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
271 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
273 fPythia->ImportParticles(fParticles,"All");
280 Int_t np = fParticles->GetEntriesFast();
281 Int_t* pParent = new Int_t[np];
282 Int_t* pSelected = new Int_t[np];
283 Int_t* trackIt = new Int_t[np];
284 for (i=0; i< np-1; i++) {
288 printf("\n **************************************************%d\n",np);
290 if (np == 0 ) continue;
291 if (fProcess != kPyMb && fProcess != kPyJets && fProcess != kPyDirectGamma) {
292 for (i = 0; i<np-1; i++) {
293 TParticle * iparticle = (TParticle *) fParticles->At(i);
294 Int_t ks = iparticle->GetStatusCode();
295 kf = CheckPDGCode(iparticle->GetPdgCode());
296 // No initial state partons
297 if (ks==21) continue;
299 // Heavy Flavor Selection
305 if (kfl > 10) kfl/=100;
307 if (kfl > 10) kfl/=10;
308 if (kfl > 10) kfl/=10;
310 Int_t ipa = iparticle->GetFirstMother()-1;
314 TParticle * mother = (TParticle *) fParticles->At(ipa);
315 kfMo = TMath::Abs(mother->GetPdgCode());
317 // printf("\n particle (all) %d %d %d", i, pSelected[i], kf);
318 if (kfl >= fFlavorSelect) {
320 // Heavy flavor hadron or quark
322 // Kinematic seletion on final state heavy flavor mesons
323 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
329 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
331 // Kinematic seletion on decay products
332 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
333 && !KinematicSelection(iparticle, 1))
340 // Select if mother was selected and is not tracked
342 if (pSelected[ipa] &&
343 !trackIt[ipa] && // mother will be tracked ?
344 kfMo != 5 && // mother is b-quark, don't store fragments
345 kfMo != 4 && // mother is c-quark, don't store fragments
346 kf != 92) // don't store string
349 // Semi-stable or de-selected: diselect decay products:
352 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > 10e-15)
354 Int_t ipF = iparticle->GetFirstDaughter();
355 Int_t ipL = iparticle->GetLastDaughter();
356 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
358 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
359 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
362 if (pSelected[i] == -1) pSelected[i] = 0;
363 if (!pSelected[i]) continue;
365 // Decision on tracking
368 // Track final state particle
369 if (ks == 1) trackIt[i] = 1;
370 // Track semi-stable particles
371 if ((ks ==1) || (fDecayer->GetLifetime(kf)> 10e-15)) trackIt[i] = 1;
372 // Track particles selected by process if undecayed.
373 if (fForceDecay == kNoDecay) {
374 if (ParentSelected(kf)) trackIt[i] = 1;
376 if (ParentSelected(kf)) trackIt[i] = 0;
381 } // particle selection loop
383 for (i = 0; i<np-1; i++) {
384 if (!pSelected[i]) continue;
385 TParticle * iparticle = (TParticle *) fParticles->At(i);
386 kf = CheckPDGCode(iparticle->GetPdgCode());
387 p[0]=iparticle->Px();
388 p[1]=iparticle->Py();
389 p[2]=iparticle->Pz();
390 origin[0]=origin0[0]+iparticle->Vx()/10.;
391 origin[1]=origin0[1]+iparticle->Vy()/10.;
392 origin[2]=origin0[2]+iparticle->Vz()/10.;
393 Float_t tof=kconv*iparticle->T();
394 Int_t ipa = iparticle->GetFirstMother()-1;
395 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
396 // printf("\n SetTrack %d %d %d %d", i, iparent, kf, trackIt[i]);
397 gAlice->SetTrack(fTrackIt*trackIt[i] ,
398 iparent, kf, p, origin, polar, tof, kPPrimary, nt, 1.);
400 gAlice->KeepTrack(nt);
409 if (jev >= fNpart || fNpart == -1) {
410 fKineBias=Float_t(fNpart)/Float_t(fTrials);
411 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
416 gAlice->SetHighWaterMark(nt);
417 // adjust weight due to kinematic selection
420 fXsection=fPythia->GetPARI(1);
423 Int_t AliGenPythia::GenerateMB()
425 Int_t i, kf, nt, iparent;
428 Float_t polar[3] = {0,0,0};
429 Float_t origin[3] = {0,0,0};
430 Float_t origin0[3] = {0,0,0};
431 // converts from mm/c to s
432 const Float_t kconv=0.001/2.999792458e8;
434 Int_t np = fParticles->GetEntriesFast();
435 Int_t* pParent = new Int_t[np];
436 for (i=0; i< np-1; i++) pParent[i] = -1;
438 for (i = 0; i<np-1; i++) {
440 TParticle * iparticle = (TParticle *) fParticles->At(i);
441 kf = CheckPDGCode(iparticle->GetPdgCode());
442 Int_t ks = iparticle->GetStatusCode();
443 Int_t km = iparticle->GetFirstMother();
444 // printf("\n Particle: %d %d %d", i, kf, ks);
446 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
448 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
450 if (ks == 1) trackIt = 1;
451 Int_t ipa = iparticle->GetFirstMother()-1;
453 iparent = (ipa > -1) ? pParent[ipa] : -1;
456 // store track information
457 p[0]=iparticle->Px();
458 p[1]=iparticle->Py();
459 p[2]=iparticle->Pz();
460 origin[0]=origin0[0]+iparticle->Vx()/10.;
461 origin[1]=origin0[1]+iparticle->Vy()/10.;
462 origin[2]=origin0[2]+iparticle->Vz()/10.;
463 Float_t tof=kconv*iparticle->T();
464 gAlice->SetTrack(fTrackIt*trackIt, iparent, kf, p, origin, polar,
466 gAlice->KeepTrack(nt);
471 if (pParent) delete[] pParent;
473 printf("\n I've put %i particles on the stack \n",nc);
479 void AliGenPythia::FinishRun()
481 // Print x-section summary
485 void AliGenPythia::AdjustWeights()
487 // Adjust the weights after generation of all events
490 Int_t ntrack=gAlice->GetNtrack();
491 for (Int_t i=0; i<ntrack; i++) {
492 part= gAlice->Particle(i);
493 part->SetWeight(part->GetWeight()*fKineBias);
497 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
499 // Treat protons as inside nuclei with mass numbers a1 and a2
505 void AliGenPythia::MakeHeader()
507 // Builds the event header, to be called after each event
508 AliGenEventHeader* header = new AliGenPythiaEventHeader("Pythia");
509 ((AliGenPythiaEventHeader*) header)->SetProcessType(fPythia->GetMSTI(1));
510 gAlice->SetGenEventHeader(header);
514 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
516 // Assignment operator
523 void AliGenPythia::Streamer(TBuffer &R__b)
525 // Stream an object of class AliGenPythia.
527 if (R__b.IsReading()) {
528 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
529 AliGenerator::Streamer(R__b);
530 R__b >> (Int_t&)fProcess;
531 R__b >> (Int_t&)fStrucFunc;
532 R__b >> (Int_t&)fForceDecay;
536 fParentSelect.Streamer(R__b);
537 fChildSelect.Streamer(R__b);
539 // (AliPythia::Instance())->Streamer(R__b);
542 // if (fDecayer) fDecayer->Streamer(R__b);
544 R__b.WriteVersion(AliGenPythia::IsA());
545 AliGenerator::Streamer(R__b);
546 R__b << (Int_t)fProcess;
547 R__b << (Int_t)fStrucFunc;
548 R__b << (Int_t)fForceDecay;
552 fParentSelect.Streamer(R__b);
553 fChildSelect.Streamer(R__b);
558 // fDecayer->Streamer(R__b);