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 **************************************************************************/
20 #include "AliGenerator.h"
21 #include "AliGenPythia.h"
23 #include "AliPythia.h"
24 #include <TDirectory.h>
28 #include <AliPythia.h>
29 #include <TParticle.h>
30 //#include <GParticle.h>
31 ClassImp(AliGenPythia)
33 AliGenPythia::AliGenPythia()
38 AliGenPythia::AliGenPythia(Int_t npart)
41 // default charm production at 5. 5 TeV
43 // structure function GRVHO
48 for (Int_t i=0; i<5; i++) fParentSelect[i]=fChildSelect[i]=0;
56 AliGenPythia::~AliGenPythia()
60 void AliGenPythia::Init()
62 SetMC(new AliPythia());
63 fPythia=(AliPythia*) fgMCEvGen;
65 fParentWeight=1./Float_t(fNpart);
67 // Forward Paramters to the AliPythia object
68 fPythia->DefineParticles();
69 fPythia->SetCKIN(3,fPtHardMin);
70 fPythia->SetCKIN(4,fPtHardMax);
71 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
72 fPythia->ForceDecay(fForceDecay);
75 // Parent and Children Selection
83 fParentSelect[3]=4122;
90 fParentSelect[3]=4122;
96 fParentSelect[3]=5122;
100 fParentSelect[1]=521;
101 fParentSelect[2]=531;
102 fParentSelect[3]=5122;
106 fParentSelect[0]=443;
116 case b_jpsi_dielectron:
117 case b_psip_dielectron:
131 void AliGenPythia::Generate()
134 Float_t polar[3] = {0,0,0};
135 Float_t origin[3]= {0,0,0};
136 Float_t origin_p[3]= {0,0,0};
137 Float_t origin0[3]= {0,0,0};
138 Float_t p[3], p_p[4], random[6];
139 static TClonesArray *particles;
140 // converts from mm/c to s
141 const Float_t kconv=0.001/2.999792458e8;
150 if(!particles) particles=new TClonesArray("TParticle",1000);
153 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
154 if(fVertexSmear==perEvent) {
157 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
158 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
159 fPythia->SetMSTP(151,0);
161 } else if (fVertexSmear==perTrack) {
162 fPythia->SetMSTP(151,0);
164 fPythia->SetPARP(151+j, fOsigma[j]*10.);
171 fPythia->ImportParticles(particles,"All");
172 Int_t np = particles->GetEntriesFast();
173 printf("\n **************************************************%d\n",np);
175 if (np == 0 ) continue;
176 if (fProcess != mb) {
177 for (Int_t i = 0; i<np; i++) {
178 TParticle * iparticle = (TParticle *) particles->At(i);
179 kf = CheckPDGCode(iparticle->GetPdgCode());
180 fChildWeight=(fPythia->GetBraPart(kf))*fParentWeight;
183 if (ParentSelected(TMath::Abs(kf))) {
184 if (KinematicSelection(iparticle)) {
187 // Store information concerning the hard scattering process
189 Float_t mass_p = fPythia->GetPARI(13);
190 Float_t pt_p = fPythia->GetPARI(17);
191 Float_t y_p = fPythia->GetPARI(37);
192 Float_t xmt_p = sqrt(pt_p*pt_p+mass_p*mass_p);
193 Float_t ty = Float_t(TMath::TanH(y_p));
196 p_p[2] = xmt_p*ty/sqrt(1.-ty*ty);
198 gAlice->SetTrack(0,-1,-1,
200 0,"Hard Scat.",nt_p,fParentWeight);
201 gAlice->KeepTrack(nt_p);
205 // store parent track information
206 p[0]=iparticle->Px();
207 p[1]=iparticle->Py();
208 p[2]=iparticle->Pz();
209 origin[0]=origin0[0]+iparticle->Vx()/10;
210 origin[1]=origin0[1]+iparticle->Vy()/10;
211 origin[2]=origin0[2]+iparticle->Vz()/10;
213 Int_t ifch=iparticle->GetFirstDaughter();
214 Int_t ilch=iparticle->GetLastDaughter();
215 if (ifch !=0 && ilch !=0) {
216 gAlice->SetTrack(0,nt_p,kf,
218 0,"Primary",nt,fParentWeight);
219 gAlice->KeepTrack(nt);
224 for (j=ifch; j<=ilch; j++)
227 (TParticle *) particles->At(j-1);
228 kf = CheckPDGCode(ichild->GetPdgCode());
231 if (ChildSelected(TMath::Abs(kf))) {
232 origin[0]=ichild->Vx();
233 origin[1]=ichild->Vy();
234 origin[2]=ichild->Vz();
238 Float_t tof=kconv*ichild->T();
239 gAlice->SetTrack(fTrackIt, iparent, kf,
241 tof,"Decay",nt,fChildWeight);
242 gAlice->KeepTrack(nt);
246 } // kinematic selection
250 for (Int_t i = 0; i<np; i++) {
251 TParticle * iparticle = (TParticle *) particles->At(i);
252 kf = CheckPDGCode(iparticle->GetPdgCode());
253 Int_t ks = iparticle->GetStatusCode();
254 if (ks==1 && kf!=0 && KinematicSelection(iparticle)) {
257 // store track information
258 p[0]=iparticle->Px();
259 p[1]=iparticle->Py();
260 p[2]=iparticle->Pz();
261 origin[0]=origin0[0]+iparticle->Vx()/10;
262 origin[1]=origin0[1]+iparticle->Vy()/10;
263 origin[2]=origin0[2]+iparticle->Vz()/10;
264 Float_t tof=kconv*iparticle->T();
265 gAlice->SetTrack(fTrackIt,-1,kf,p,origin,polar,
267 gAlice->KeepTrack(nt);
270 printf("\n I've put %i particles on the stack \n",nc);
275 fKineBias=Float_t(fNpart)/Float_t(fTrials);
276 printf("\n Trials: %i\n",fTrials);
281 // adjust weight due to kinematic selection
284 fXsection=fPythia->GetPARI(1);
287 Bool_t AliGenPythia::ParentSelected(Int_t ip)
289 for (Int_t i=0; i<5; i++)
291 if (fParentSelect[i]==ip) return kTRUE;
296 Bool_t AliGenPythia::ChildSelected(Int_t ip)
298 for (Int_t i=0; i<5; i++)
300 if (fChildSelect[i]==ip) return kTRUE;
305 Bool_t AliGenPythia::KinematicSelection(TParticle *particle)
307 Float_t px=particle->Px();
308 Float_t py=particle->Py();
309 Float_t pz=particle->Pz();
310 Float_t e=particle->Energy();
313 // transverse momentum cut
314 Float_t pt=TMath::Sqrt(px*px+py*py);
315 if (pt > fPtMax || pt < fPtMin)
317 // printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
322 Float_t p=TMath::Sqrt(px*px+py*py+pz*pz);
323 if (p > fPMax || p < fPMin)
325 // printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
331 Float_t theta = Float_t(TMath::ATan2(Double_t(pt),Double_t(pz)));
332 if (theta > fThetaMax || theta < fThetaMin)
334 // printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
340 Float_t y = 0.5*TMath::Log((e+pz)/(e-pz));
341 if (y > fYMax || y < fYMin)
343 // printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
349 Float_t phi=Float_t(TMath::ATan2(Double_t(py),Double_t(px)))+TMath::Pi();
350 if (phi > fPhiMax || phi < fPhiMin)
352 // printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
358 void AliGenPythia::AdjustWeights()
360 TClonesArray *PartArray = gAlice->Particles();
362 Int_t ntrack=gAlice->GetNtrack();
363 for (Int_t i=0; i<ntrack; i++) {
364 Part= (TParticle*) PartArray->UncheckedAt(i);
365 Part->SetWeight(Part->GetWeight()*fKineBias);
369 Int_t AliGenPythia::CheckPDGCode(Int_t pdgcode)
372 // If the particle is in a diffractive state, then take action accordigly
375 //rho_diff0 -- difficult to translate, return rho0
378 //pi_diffr+ -- change to pi+
381 //omega_di0 -- change to omega0
384 //phi_diff0 -- return phi0
387 //J/psi_di0 -- return J/psi
390 //n_diffr -- return neutron
393 //p_diffr+ -- return proton
396 //non diffractive state -- return code unchanged