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.24 2000/09/18 10:41:35 morsch
19 Add possibility to use nuclear structure functions from PDF library V8.
21 Revision 1.23 2000/09/14 14:05:40 morsch
24 Revision 1.22 2000/09/14 14:02:22 morsch
25 - Correct conversion from mm to cm when passing particle vertex to MC.
26 - Correct handling of fForceDecay == all.
28 Revision 1.21 2000/09/12 14:14:55 morsch
29 Call fDecayer->ForceDecay() at the beginning of Generate().
31 Revision 1.20 2000/09/06 14:29:33 morsch
32 Use AliPythia for event generation an AliDecayPythia for decays.
33 Correct handling of "nodecay" option
35 Revision 1.19 2000/07/11 18:24:56 fca
36 Coding convention corrections + few minor bug fixes
38 Revision 1.18 2000/06/30 12:40:34 morsch
39 Pythia takes care of vertex smearing. Correct conversion from Pythia units (mm) to
42 Revision 1.17 2000/06/09 20:34:07 morsch
43 All coding rule violations except RS3 corrected
45 Revision 1.16 2000/05/15 15:04:20 morsch
46 The full event is written for fNtrack = -1
47 Coding rule violations corrected.
49 Revision 1.15 2000/04/26 10:14:24 morsch
50 Particles array has one entry more than pythia particle list. Upper bound of
51 particle loop changed to np-1 (R. Guernane, AM)
53 Revision 1.14 2000/04/05 08:36:13 morsch
54 Check status code of particles in Pythia event
55 to avoid double counting as partonic state and final state particle.
57 Revision 1.13 1999/11/09 07:38:48 fca
58 Changes for compatibility with version 2.23 of ROOT
60 Revision 1.12 1999/11/03 17:43:20 fca
61 New version from G.Martinez & A.Morsch
63 Revision 1.11 1999/09/29 09:24:14 fca
64 Introduction of the Copyright and cvs Log
67 #include "AliGenPythia.h"
68 #include "AliDecayerPythia.h"
70 #include "AliPythia.h"
72 #include <TParticle.h>
75 ClassImp(AliGenPythia)
77 AliGenPythia::AliGenPythia()
80 // Default Constructor
81 fDecayer = new AliDecayerPythia();
84 AliGenPythia::AliGenPythia(Int_t npart)
87 // default charm production at 5. 5 TeV
89 // structure function GRVHO
96 for (Int_t i=0; i<5; i++) fParentSelect[i]=fChildSelect[i]=0;
102 fDecayer = new AliDecayerPythia();
105 AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
110 AliGenPythia::~AliGenPythia()
115 void AliGenPythia::Init()
118 SetMC(AliPythia::Instance());
119 fPythia=(AliPythia*) fgMCEvGen;
121 fParentWeight=1./Float_t(fNpart);
123 // Forward Paramters to the AliPythia object
124 // gSystem->Exec("ln -s $ALICE_ROOT/data/Decay.table fort.1");
125 // fPythia->Pyupda(2,1);
126 // gSystem->Exec("rm fort.1");
128 fDecayer->SetForceDecay(fForceDecay);
132 fPythia->SetCKIN(3,fPtHardMin);
133 fPythia->SetCKIN(4,fPtHardMax);
134 if (fNucA1 > 0 && fNucA2 > 0) fPythia->SetNuclei(fNucA1, fNucA2);
135 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
137 // fPythia->Pylist(0);
138 // fPythia->Pystat(2);
139 // Parent and Children Selection
144 fParentSelect[0]=411;
145 fParentSelect[1]=421;
146 fParentSelect[2]=431;
147 fParentSelect[3]=4122;
151 fParentSelect[0]=411;
152 fParentSelect[1]=421;
153 fParentSelect[2]=431;
154 fParentSelect[3]=4122;
157 fParentSelect[0]=511;
158 fParentSelect[1]=521;
159 fParentSelect[2]=531;
160 fParentSelect[3]=5122;
162 case beauty_unforced:
163 fParentSelect[0]=511;
164 fParentSelect[1]=521;
165 fParentSelect[2]=531;
166 fParentSelect[3]=5122;
170 fParentSelect[0]=443;
180 case b_jpsi_dielectron:
181 case b_psip_dielectron:
182 fChildSelect[0]=kElectron;
190 fChildSelect[0]=kMuonMinus;
193 fChildSelect[0]=kPiPlus;
194 fChildSelect[1]=kKPlus;
202 void AliGenPythia::Generate()
204 // Generate one event
205 fDecayer->ForceDecay();
207 Float_t polar[3] = {0,0,0};
208 Float_t origin[3]= {0,0,0};
209 Float_t originP[3]= {0,0,0};
210 Float_t origin0[3]= {0,0,0};
212 // Float_t random[6];
213 static TClonesArray *particles;
214 // converts from mm/c to s
215 const Float_t kconv=0.001/2.999792458e8;
224 if(!particles) particles=new TClonesArray("TParticle",1000);
227 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
228 if(fVertexSmear==kPerEvent) {
229 fPythia->SetMSTP(151,1);
231 fPythia->SetPARP(151+j, fOsigma[j]/10.);
233 } else if (fVertexSmear==kPerTrack) {
234 fPythia->SetMSTP(151,0);
240 // fPythia->Pylist(1);
242 fPythia->ImportParticles(particles,"All");
243 Int_t np = particles->GetEntriesFast();
244 printf("\n **************************************************%d\n",np);
246 if (np == 0 ) continue;
247 if (fProcess != mb) {
248 for (Int_t i = 0; i<np-1; i++) {
249 TParticle * iparticle = (TParticle *) particles->At(i);
250 Int_t ks = iparticle->GetStatusCode();
251 kf = CheckPDGCode(iparticle->GetPdgCode());
252 if (ks==21) continue;
254 fChildWeight=(fDecayer->GetPartialBranchingRatio(kf))*fParentWeight;
257 if (ParentSelected(TMath::Abs(kf))) {
258 if (KinematicSelection(iparticle)) {
261 // Store information concerning the hard scattering process
263 Float_t massP = fPythia->GetPARI(13);
264 Float_t ptP = fPythia->GetPARI(17);
265 Float_t yP = fPythia->GetPARI(37);
266 Float_t xmtP = sqrt(ptP*ptP+massP*massP);
267 Float_t ty = Float_t(TMath::TanH(yP));
270 pP[2] = xmtP*ty/sqrt(1.-ty*ty);
272 gAlice->SetTrack(0,-1,-1,
274 0,"Hard Scat.",ntP,fParentWeight);
275 gAlice->KeepTrack(ntP);
279 // store parent track information
280 p[0]=iparticle->Px();
281 p[1]=iparticle->Py();
282 p[2]=iparticle->Pz();
283 origin[0]=origin0[0]+iparticle->Vx()/10.;
284 origin[1]=origin0[1]+iparticle->Vy()/10.;
285 origin[2]=origin0[2]+iparticle->Vz()/10.;
287 Int_t ifch=iparticle->GetFirstDaughter();
288 Int_t ilch=iparticle->GetLastDaughter();
290 if ((ifch !=0 && ilch !=0) || fForceDecay == nodecay) {
292 if (fForceDecay == nodecay) trackit = 1;
293 gAlice->SetTrack(trackit,ntP,kf,
295 0,"Primary",nt,fParentWeight);
296 gAlice->KeepTrack(nt);
300 if (fForceDecay != nodecay) {
301 for (j=ifch; j<=ilch; j++)
304 (TParticle *) particles->At(j-1);
305 kf = CheckPDGCode(ichild->GetPdgCode());
308 if (ChildSelected(TMath::Abs(kf))) {
309 origin[0]=origin0[0]+ichild->Vx()/10.;
310 origin[1]=origin0[1]+ichild->Vy()/10.;
311 origin[2]=origin0[2]+ichild->Vz()/10.;
315 Float_t tof=kconv*ichild->T();
316 gAlice->SetTrack(fTrackIt, iparent, kf,
318 tof,"Decay",nt,fChildWeight);
319 gAlice->KeepTrack(nt);
324 } // kinematic selection
328 for (Int_t i = 0; i<np-1; i++) {
329 TParticle * iparticle = (TParticle *) particles->At(i);
330 kf = CheckPDGCode(iparticle->GetPdgCode());
331 Int_t ks = iparticle->GetStatusCode();
333 if (ks==1 && kf!=0 && KinematicSelection(iparticle)) {
336 // store track information
337 p[0]=iparticle->Px();
338 p[1]=iparticle->Py();
339 p[2]=iparticle->Pz();
340 origin[0]=origin0[0]+iparticle->Vx()/10.;
341 origin[1]=origin0[1]+iparticle->Vy()/10.;
342 origin[2]=origin0[2]+iparticle->Vz()/10.;
343 Float_t tof=kconv*iparticle->T();
344 gAlice->SetTrack(fTrackIt,-1,kf,p,origin,polar,
346 gAlice->KeepTrack(nt);
349 printf("\n I've put %i particles on the stack \n",nc);
353 if (jev >= fNpart || fNpart == -1) {
354 fKineBias=Float_t(fNpart)/Float_t(fTrials);
355 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
356 // Print x-section summary
362 // adjust weight due to kinematic selection
365 fXsection=fPythia->GetPARI(1);
368 Bool_t AliGenPythia::ParentSelected(Int_t ip)
370 // True if particle is in list of parent particles to be selected
371 for (Int_t i=0; i<5; i++)
373 if (fParentSelect[i]==ip) return kTRUE;
378 Bool_t AliGenPythia::ChildSelected(Int_t ip)
380 // True if particle is in list of decay products to be selected
381 if (fForceDecay == all) return kTRUE;
383 for (Int_t i=0; i<5; i++)
385 if (fChildSelect[i]==ip) return kTRUE;
390 Bool_t AliGenPythia::KinematicSelection(TParticle *particle)
392 // Perform kinematic selection
393 Float_t px=particle->Px();
394 Float_t py=particle->Py();
395 Float_t pz=particle->Pz();
396 Float_t e=particle->Energy();
399 // transverse momentum cut
400 Float_t pt=TMath::Sqrt(px*px+py*py);
401 if (pt > fPtMax || pt < fPtMin)
403 // printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
408 Float_t p=TMath::Sqrt(px*px+py*py+pz*pz);
409 if (p > fPMax || p < fPMin)
411 // printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
417 Float_t theta = Float_t(TMath::ATan2(Double_t(pt),Double_t(pz)));
418 if (theta > fThetaMax || theta < fThetaMin)
420 // printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
430 Float_t y = 0.5*TMath::Log((e+pz)/(e-pz));
431 if (y > fYMax || y < fYMin)
433 // printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
440 Float_t phi=Float_t(TMath::ATan2(Double_t(py),Double_t(px)));
441 if (phi > fPhiMax || phi < fPhiMin)
443 // printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
449 void AliGenPythia::AdjustWeights()
451 // Adjust the weights after generation of all events
453 TClonesArray *partArray = gAlice->Particles();
455 Int_t ntrack=gAlice->GetNtrack();
456 for (Int_t i=0; i<ntrack; i++) {
457 part= (TParticle*) partArray->UncheckedAt(i);
458 part->SetWeight(part->GetWeight()*fKineBias);
462 Int_t AliGenPythia::CheckPDGCode(Int_t pdgcode)
465 // If the particle is in a diffractive state, then take action accordingly
470 //rho_diff0 -- difficult to translate, return rho0
473 //pi_diffr+ -- change to pi+
476 //omega_di0 -- change to omega0
479 //phi_diff0 -- return phi0
482 //J/psi_di0 -- return J/psi
485 //n_diffr -- return neutron
488 //p_diffr+ -- return proton
491 //non diffractive state -- return code unchanged
496 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
498 // Treat protons as inside nuclei with mass numbers a1 and a2
504 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
506 // Assignment operator
512 void AliGenPythia::Streamer(TBuffer &R__b)
514 // Stream an object of class AliGenPythia.
516 if (R__b.IsReading()) {
517 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
518 AliGenerator::Streamer(R__b);
519 R__b >> (Int_t&)fProcess;
520 R__b >> (Int_t&)fStrucFunc;
521 R__b >> (Int_t&)fForceDecay;
525 fParentSelect.Streamer(R__b);
526 fChildSelect.Streamer(R__b);
528 // (AliPythia::Instance())->Streamer(R__b);
531 // if (fDecayer) fDecayer->Streamer(R__b);
533 R__b.WriteVersion(AliGenPythia::IsA());
534 AliGenerator::Streamer(R__b);
535 R__b << (Int_t)fProcess;
536 R__b << (Int_t)fStrucFunc;
537 R__b << (Int_t)fForceDecay;
541 fParentSelect.Streamer(R__b);
542 fChildSelect.Streamer(R__b);
547 // fDecayer->Streamer(R__b);