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.35 2001/03/09 13:03:40 morsch
19 Process_t and Struc_Func_t moved to AliPythia.h
21 Revision 1.34 2001/02/14 15:50:40 hristov
22 The last particle in event marked using SetHighWaterMark
24 Revision 1.33 2001/01/30 09:23:12 hristov
25 Streamers removed (R.Brun)
27 Revision 1.32 2001/01/26 19:55:51 hristov
28 Major upgrade of AliRoot code
30 Revision 1.31 2001/01/17 10:54:31 hristov
31 Better protection against FPE
33 Revision 1.30 2000/12/18 08:55:35 morsch
34 Make AliPythia dependent generartors work with new scheme of random number generation
36 Revision 1.29 2000/12/04 11:22:03 morsch
37 Init of sRandom as in 1.15
39 Revision 1.28 2000/12/02 11:41:39 morsch
40 Use SetRandom() to initialize random number generator in constructor.
42 Revision 1.27 2000/11/30 20:29:02 morsch
43 Initialise static variable sRandom in constructor: sRandom = fRandom;
45 Revision 1.26 2000/11/30 07:12:50 alibrary
46 Introducing new Rndm and QA classes
48 Revision 1.25 2000/10/18 19:11:27 hristov
49 Division by zero fixed
51 Revision 1.24 2000/09/18 10:41:35 morsch
52 Add possibility to use nuclear structure functions from PDF library V8.
54 Revision 1.23 2000/09/14 14:05:40 morsch
57 Revision 1.22 2000/09/14 14:02:22 morsch
58 - Correct conversion from mm to cm when passing particle vertex to MC.
59 - Correct handling of fForceDecay == all.
61 Revision 1.21 2000/09/12 14:14:55 morsch
62 Call fDecayer->ForceDecay() at the beginning of Generate().
64 Revision 1.20 2000/09/06 14:29:33 morsch
65 Use AliPythia for event generation an AliDecayPythia for decays.
66 Correct handling of "nodecay" option
68 Revision 1.19 2000/07/11 18:24:56 fca
69 Coding convention corrections + few minor bug fixes
71 Revision 1.18 2000/06/30 12:40:34 morsch
72 Pythia takes care of vertex smearing. Correct conversion from Pythia units (mm) to
75 Revision 1.17 2000/06/09 20:34:07 morsch
76 All coding rule violations except RS3 corrected
78 Revision 1.16 2000/05/15 15:04:20 morsch
79 The full event is written for fNtrack = -1
80 Coding rule violations corrected.
82 Revision 1.15 2000/04/26 10:14:24 morsch
83 Particles array has one entry more than pythia particle list. Upper bound of
84 particle loop changed to np-1 (R. Guernane, AM)
86 Revision 1.14 2000/04/05 08:36:13 morsch
87 Check status code of particles in Pythia event
88 to avoid double counting as partonic state and final state particle.
90 Revision 1.13 1999/11/09 07:38:48 fca
91 Changes for compatibility with version 2.23 of ROOT
93 Revision 1.12 1999/11/03 17:43:20 fca
94 New version from G.Martinez & A.Morsch
96 Revision 1.11 1999/09/29 09:24:14 fca
97 Introduction of the Copyright and cvs Log
100 #include "AliGenPythia.h"
101 #include "AliDecayerPythia.h"
103 #include "AliPythia.h"
105 #include <TParticle.h>
108 ClassImp(AliGenPythia)
110 AliGenPythia::AliGenPythia()
113 // Default Constructor
114 fDecayer = new AliDecayerPythia();
117 AliGenPythia::AliGenPythia(Int_t npart)
120 // default charm production at 5. 5 TeV
122 // structure function GRVHO
127 fParentSelect.Set(5);
129 for (Int_t i=0; i<5; i++) fParentSelect[i]=fChildSelect[i]=0;
135 fDecayer = new AliDecayerPythia();
136 // Set random number generator
140 AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
145 AliGenPythia::~AliGenPythia()
150 void AliGenPythia::Init()
153 SetMC(AliPythia::Instance());
154 fPythia=(AliPythia*) fgMCEvGen;
156 fParentWeight=1./Float_t(fNpart);
158 // Forward Paramters to the AliPythia object
159 // gSystem->Exec("ln -s $ALICE_ROOT/data/Decay.table fort.1");
160 // fPythia->Pyupda(2,1);
161 // gSystem->Exec("rm fort.1");
163 fDecayer->SetForceDecay(fForceDecay);
167 fPythia->SetCKIN(3,fPtHardMin);
168 fPythia->SetCKIN(4,fPtHardMax);
169 if (fNucA1 > 0 && fNucA2 > 0) fPythia->SetNuclei(fNucA1, fNucA2);
170 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
172 // fPythia->Pylist(0);
173 // fPythia->Pystat(2);
174 // Parent and Children Selection
178 fParentSelect[0]=411;
179 fParentSelect[1]=421;
180 fParentSelect[2]=431;
181 fParentSelect[3]=4122;
183 case kPyCharmUnforced:
184 fParentSelect[0]=411;
185 fParentSelect[1]=421;
186 fParentSelect[2]=431;
187 fParentSelect[3]=4122;
190 fParentSelect[0]=511;
191 fParentSelect[1]=521;
192 fParentSelect[2]=531;
193 fParentSelect[3]=5122;
195 case kPyBeautyUnforced:
196 fParentSelect[0]=511;
197 fParentSelect[1]=521;
198 fParentSelect[2]=531;
199 fParentSelect[3]=5122;
203 fParentSelect[0]=443;
213 case kSemiElectronic:
215 case kBJpsiDiElectron:
216 case kBPsiPrimeDiElectron:
217 fChildSelect[0]=kElectron;
222 case kBPsiPrimeDiMuon:
225 fChildSelect[0]=kMuonMinus;
228 fChildSelect[0]=kPiPlus;
229 fChildSelect[1]=kKPlus;
237 void AliGenPythia::Generate()
239 // Generate one event
240 fDecayer->ForceDecay();
242 Float_t polar[3] = {0,0,0};
243 Float_t origin[3] = {0,0,0};
244 Float_t originP[3] = {0,0,0};
245 Float_t origin0[3] = {0,0,0};
247 // Float_t random[6];
248 static TClonesArray *particles;
249 // converts from mm/c to s
250 const Float_t kconv=0.001/2.999792458e8;
259 if(!particles) particles=new TClonesArray("TParticle",1000);
262 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
263 if(fVertexSmear==kPerEvent) {
264 fPythia->SetMSTP(151,1);
266 fPythia->SetPARP(151+j, fOsigma[j]/10.);
268 } else if (fVertexSmear==kPerTrack) {
269 fPythia->SetMSTP(151,0);
275 // fPythia->Pylist(1);
277 fPythia->ImportParticles(particles,"All");
278 Int_t np = particles->GetEntriesFast();
279 printf("\n **************************************************%d\n",np);
281 if (np == 0 ) continue;
282 if (fProcess != kPyMb && fProcess != kPyJets && fProcess != kPyDirectGamma) {
283 for (Int_t i = 0; i<np-1; i++) {
284 TParticle * iparticle = (TParticle *) particles->At(i);
285 Int_t ks = iparticle->GetStatusCode();
286 kf = CheckPDGCode(iparticle->GetPdgCode());
287 if (ks==21) continue;
289 fChildWeight=(fDecayer->GetPartialBranchingRatio(kf))*fParentWeight;
292 if (ParentSelected(TMath::Abs(kf))) {
293 if (KinematicSelection(iparticle)) {
296 // Store information concerning the hard scattering process
298 Float_t massP = fPythia->GetPARI(13);
299 Float_t ptP = fPythia->GetPARI(17);
300 Float_t yP = fPythia->GetPARI(37);
301 Float_t xmtP = sqrt(ptP*ptP+massP*massP);
302 Float_t ty = Float_t(TMath::TanH(yP));
305 pP[2] = xmtP*ty/sqrt(1.-ty*ty);
307 gAlice->SetTrack(0,-1,-1,
309 0,kPPrimary,ntP,fParentWeight);
310 // 0,"Hard Scat.",ntP,fParentWeight);
311 gAlice->KeepTrack(ntP);
315 // store parent track information
316 p[0]=iparticle->Px();
317 p[1]=iparticle->Py();
318 p[2]=iparticle->Pz();
319 origin[0]=origin0[0]+iparticle->Vx()/10.;
320 origin[1]=origin0[1]+iparticle->Vy()/10.;
321 origin[2]=origin0[2]+iparticle->Vz()/10.;
323 Int_t ifch=iparticle->GetFirstDaughter();
324 Int_t ilch=iparticle->GetLastDaughter();
326 if ((ifch !=0 && ilch !=0) || fForceDecay == kNoDecay) {
328 if (fForceDecay == kNoDecay) trackit = 1;
329 gAlice->SetTrack(trackit,ntP,kf,
331 0,kPPrimary,nt,fParentWeight);
332 gAlice->KeepTrack(nt);
336 if (fForceDecay != kNoDecay) {
337 for (j=ifch; j<=ilch; j++)
340 (TParticle *) particles->At(j-1);
341 kf = CheckPDGCode(ichild->GetPdgCode());
344 if (ChildSelected(TMath::Abs(kf))) {
345 origin[0]=origin0[0]+ichild->Vx()/10.;
346 origin[1]=origin0[1]+ichild->Vy()/10.;
347 origin[2]=origin0[2]+ichild->Vz()/10.;
351 Float_t tof=kconv*ichild->T();
352 gAlice->SetTrack(fTrackIt, iparent, kf,
354 tof,kPDecay,nt,fChildWeight);
355 gAlice->KeepTrack(nt);
360 } // kinematic selection
364 for (Int_t i = 0; i<np-1; i++) {
365 TParticle * iparticle = (TParticle *) particles->At(i);
366 kf = CheckPDGCode(iparticle->GetPdgCode());
367 Int_t ks = iparticle->GetStatusCode();
368 Int_t km = iparticle->GetFirstMother();
369 // printf("\n process %d %d\n", ks,km);
371 if ((ks==1 && kf!=0 && KinematicSelection(iparticle)) ||
372 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
375 // store track information
376 p[0]=iparticle->Px();
377 p[1]=iparticle->Py();
378 p[2]=iparticle->Pz();
379 origin[0]=origin0[0]+iparticle->Vx()/10.;
380 origin[1]=origin0[1]+iparticle->Vy()/10.;
381 origin[2]=origin0[2]+iparticle->Vz()/10.;
382 Float_t tof=kconv*iparticle->T();
383 gAlice->SetTrack(fTrackIt,-1,kf,p,origin,polar,
385 gAlice->KeepTrack(nt);
388 printf("\n I've put %i particles on the stack \n",nc);
392 if (jev >= fNpart || fNpart == -1) {
393 fKineBias=Float_t(fNpart)/Float_t(fTrials);
394 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
399 gAlice->SetHighWaterMark(nt);
400 // adjust weight due to kinematic selection
403 fXsection=fPythia->GetPARI(1);
406 void AliGenPythia::FinishRun()
408 // Print x-section summary
412 Bool_t AliGenPythia::ParentSelected(Int_t ip)
414 // True if particle is in list of parent particles to be selected
415 for (Int_t i=0; i<5; i++)
417 if (fParentSelect[i]==ip) return kTRUE;
422 Bool_t AliGenPythia::ChildSelected(Int_t ip)
424 // True if particle is in list of decay products to be selected
425 if (fForceDecay == kAll) return kTRUE;
427 for (Int_t i=0; i<5; i++)
429 if (fChildSelect[i]==ip) return kTRUE;
434 Bool_t AliGenPythia::KinematicSelection(TParticle *particle)
436 // Perform kinematic selection
437 Float_t px=particle->Px();
438 Float_t py=particle->Py();
439 Float_t pz=particle->Pz();
440 Float_t e=particle->Energy();
443 // transverse momentum cut
444 Float_t pt=TMath::Sqrt(px*px+py*py);
445 if (pt > fPtMax || pt < fPtMin)
447 // printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
452 Float_t p=TMath::Sqrt(px*px+py*py+pz*pz);
453 if (p > fPMax || p < fPMin)
455 // printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
461 Float_t theta = Float_t(TMath::ATan2(Double_t(pt),Double_t(pz)));
462 if (theta > fThetaMax || theta < fThetaMin)
464 // printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
470 if ( (e-pz)<=0 || (e+pz)<=0 ) {
474 Float_t y = 0.5*TMath::Log((e+pz)/(e-pz));
475 if (y > fYMax || y < fYMin)
477 // printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
484 Float_t phi=Float_t(TMath::ATan2(Double_t(py),Double_t(px)));
485 if (phi > fPhiMax || phi < fPhiMin)
487 // printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
493 void AliGenPythia::AdjustWeights()
495 // Adjust the weights after generation of all events
498 Int_t ntrack=gAlice->GetNtrack();
499 for (Int_t i=0; i<ntrack; i++) {
500 part= gAlice->Particle(i);
501 part->SetWeight(part->GetWeight()*fKineBias);
505 Int_t AliGenPythia::CheckPDGCode(Int_t pdgcode)
508 // If the particle is in a diffractive state, then take action accordingly
513 //rho_diff0 -- difficult to translate, return rho0
516 //pi_diffr+ -- change to pi+
519 //omega_di0 -- change to omega0
522 //phi_diff0 -- return phi0
525 //J/psi_di0 -- return J/psi
528 //n_diffr -- return neutron
531 //p_diffr+ -- return proton
534 //non diffractive state -- return code unchanged
539 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
541 // Treat protons as inside nuclei with mass numbers a1 and a2
547 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
549 // Assignment operator
556 void AliGenPythia::Streamer(TBuffer &R__b)
558 // Stream an object of class AliGenPythia.
560 if (R__b.IsReading()) {
561 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
562 AliGenerator::Streamer(R__b);
563 R__b >> (Int_t&)fProcess;
564 R__b >> (Int_t&)fStrucFunc;
565 R__b >> (Int_t&)fForceDecay;
569 fParentSelect.Streamer(R__b);
570 fChildSelect.Streamer(R__b);
572 // (AliPythia::Instance())->Streamer(R__b);
575 // if (fDecayer) fDecayer->Streamer(R__b);
577 R__b.WriteVersion(AliGenPythia::IsA());
578 AliGenerator::Streamer(R__b);
579 R__b << (Int_t)fProcess;
580 R__b << (Int_t)fStrucFunc;
581 R__b << (Int_t)fForceDecay;
585 fParentSelect.Streamer(R__b);
586 fChildSelect.Streamer(R__b);
591 // fDecayer->Streamer(R__b);