Remove ZDC and FMD by default
[u/mrichter/AliRoot.git] / EVGEN / AliGenPythia.cxx
CommitLineData
4c039060 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/*
17$Log$
23211d3e 18Revision 1.13 1999/11/09 07:38:48 fca
19Changes for compatibility with version 2.23 of ROOT
20
084c1b4a 21Revision 1.12 1999/11/03 17:43:20 fca
22New version from G.Martinez & A.Morsch
23
886b6f73 24Revision 1.11 1999/09/29 09:24:14 fca
25Introduction of the Copyright and cvs Log
4c039060 26*/
27
fe4da5cc 28#include "AliGenerator.h"
29#include "AliGenPythia.h"
fe4da5cc 30#include "AliRun.h"
31#include "AliPythia.h"
32#include <TDirectory.h>
33#include <TFile.h>
34#include <TTree.h>
35#include <stdlib.h>
36#include <AliPythia.h>
1578254f 37#include <TParticle.h>
38//#include <GParticle.h>
fe4da5cc 39 ClassImp(AliGenPythia)
40
41AliGenPythia::AliGenPythia()
42 :AliGenerator()
43{
44}
45
46AliGenPythia::AliGenPythia(Int_t npart)
47 :AliGenerator(npart)
48{
49// default charm production at 5. 5 TeV
50// semimuonic decay
51// structure function GRVHO
52//
53 fXsection = 0.;
54 fParentSelect.Set(5);
55 fChildSelect.Set(5);
56 for (Int_t i=0; i<5; i++) fParentSelect[i]=fChildSelect[i]=0;
57 SetProcess();
58 SetStrucFunc();
886b6f73 59 SetForceDecay();
fe4da5cc 60 SetPtHard();
61 SetEnergyCMS();
62}
63
64AliGenPythia::~AliGenPythia()
65{
66}
67
68void AliGenPythia::Init()
69{
70 SetMC(new AliPythia());
71 fPythia=(AliPythia*) fgMCEvGen;
72//
73 fParentWeight=1./Float_t(fNpart);
74//
75// Forward Paramters to the AliPythia object
76 fPythia->DefineParticles();
fe4da5cc 77 fPythia->SetCKIN(3,fPtHardMin);
78 fPythia->SetCKIN(4,fPtHardMax);
79 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
5be1fe76 80 fPythia->ForceDecay(fForceDecay);
084c1b4a 81 fPythia->Lulist(0);
82 fPythia->Pystat(2);
fe4da5cc 83// Parent and Children Selection
84 switch (fProcess)
85 {
86 case charm:
87
88 fParentSelect[0]=411;
89 fParentSelect[1]=421;
90 fParentSelect[2]=431;
91 fParentSelect[3]=4122;
92 break;
93 case charm_unforced:
94
95 fParentSelect[0]=411;
96 fParentSelect[1]=421;
97 fParentSelect[2]=431;
98 fParentSelect[3]=4122;
99 break;
100 case beauty:
101 fParentSelect[0]=511;
102 fParentSelect[1]=521;
103 fParentSelect[2]=531;
104 fParentSelect[3]=5122;
105 break;
106 case beauty_unforced:
107 fParentSelect[0]=511;
108 fParentSelect[1]=521;
109 fParentSelect[2]=531;
110 fParentSelect[3]=5122;
111 break;
112 case jpsi_chi:
113 case jpsi:
114 fParentSelect[0]=443;
115 break;
5be1fe76 116 case mb:
117 break;
fe4da5cc 118 }
119
120 switch (fForceDecay)
121 {
122 case semielectronic:
123 case dielectron:
124 case b_jpsi_dielectron:
125 case b_psip_dielectron:
126 fChildSelect[0]=11;
127 break;
128 case semimuonic:
129 case dimuon:
130 case b_jpsi_dimuon:
131 case b_psip_dimuon:
5be1fe76 132 case pitomu:
133 case katomu:
fe4da5cc 134 fChildSelect[0]=13;
135 break;
886b6f73 136 case all:
137 case nodecay:
138 break;
fe4da5cc 139 }
140}
141
142void AliGenPythia::Generate()
143{
fe4da5cc 144
5be1fe76 145 Float_t polar[3] = {0,0,0};
146 Float_t origin[3]= {0,0,0};
147 Float_t origin_p[3]= {0,0,0};
148 Float_t origin0[3]= {0,0,0};
149 Float_t p[3], p_p[4], random[6];
09fd3ea2 150 static TClonesArray *particles;
5be1fe76 151// converts from mm/c to s
152 const Float_t kconv=0.001/2.999792458e8;
fe4da5cc 153
154
155//
fe4da5cc 156 Int_t nt=0;
5be1fe76 157 Int_t nt_p=0;
fe4da5cc 158 Int_t jev=0;
7921755b 159 Int_t j, kf;
09fd3ea2 160
161 if(!particles) particles=new TClonesArray("TParticle",1000);
fe4da5cc 162
163 fTrials=0;
164 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
165 if(fVertexSmear==perEvent) {
cfce8870 166 gMC->Rndm(random,6);
fe4da5cc 167 for (j=0;j<3;j++) {
168 origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
169 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
170 fPythia->SetMSTP(151,0);
171 }
172 } else if (fVertexSmear==perTrack) {
173 fPythia->SetMSTP(151,0);
174 for (j=0;j<3;j++) {
175 fPythia->SetPARP(151+j, fOsigma[j]*10.);
176 }
177 }
fe4da5cc 178 while(1)
179 {
084c1b4a 180 fPythia->Pyevnt();
fe4da5cc 181 fTrials++;
f1092809 182 fPythia->ImportParticles(particles,"All");
fe4da5cc 183 Int_t np = particles->GetEntriesFast();
184 printf("\n **************************************************%d\n",np);
185 Int_t nc=0;
186 if (np == 0 ) continue;
5be1fe76 187 if (fProcess != mb) {
188 for (Int_t i = 0; i<np; i++) {
1578254f 189 TParticle * iparticle = (TParticle *) particles->At(i);
23211d3e 190 Int_t ks = iparticle->GetStatusCode();
191 if (ks==21) continue;
a8228d85 192 kf = CheckPDGCode(iparticle->GetPdgCode());
5be1fe76 193 fChildWeight=(fPythia->GetBraPart(kf))*fParentWeight;
fe4da5cc 194//
195// Parent
5be1fe76 196 if (ParentSelected(TMath::Abs(kf))) {
197 if (KinematicSelection(iparticle)) {
198 if (nc==0) {
199//
200// Store information concerning the hard scattering process
201//
202 Float_t mass_p = fPythia->GetPARI(13);
203 Float_t pt_p = fPythia->GetPARI(17);
204 Float_t y_p = fPythia->GetPARI(37);
205 Float_t xmt_p = sqrt(pt_p*pt_p+mass_p*mass_p);
206 Float_t ty = Float_t(TMath::TanH(y_p));
207 p_p[0] = pt_p;
208 p_p[1] = 0;
209 p_p[2] = xmt_p*ty/sqrt(1.-ty*ty);
210 p_p[3] = mass_p;
211 gAlice->SetTrack(0,-1,-1,
212 p_p,origin_p,polar,
213 0,"Hard Scat.",nt_p,fParentWeight);
214 gAlice->KeepTrack(nt_p);
215 }
216 nc++;
fe4da5cc 217//
218// store parent track information
1578254f 219 p[0]=iparticle->Px();
220 p[1]=iparticle->Py();
221 p[2]=iparticle->Pz();
222 origin[0]=origin0[0]+iparticle->Vx()/10;
223 origin[1]=origin0[1]+iparticle->Vy()/10;
224 origin[2]=origin0[2]+iparticle->Vz()/10;
fe4da5cc 225
1578254f 226 Int_t ifch=iparticle->GetFirstDaughter();
227 Int_t ilch=iparticle->GetLastDaughter();
5be1fe76 228 if (ifch !=0 && ilch !=0) {
1578254f 229 gAlice->SetTrack(0,nt_p,kf,
5be1fe76 230 p,origin,polar,
231 0,"Primary",nt,fParentWeight);
232 gAlice->KeepTrack(nt);
233 Int_t iparent = nt;
fe4da5cc 234//
235// Children
236
7921755b 237 for (j=ifch; j<=ilch; j++)
5be1fe76 238 {
1578254f 239 TParticle * ichild =
240 (TParticle *) particles->At(j-1);
a8228d85 241 kf = CheckPDGCode(ichild->GetPdgCode());
fe4da5cc 242//
243//
5be1fe76 244 if (ChildSelected(TMath::Abs(kf))) {
1578254f 245 origin[0]=ichild->Vx();
246 origin[1]=ichild->Vy();
247 origin[2]=ichild->Vz();
248 p[0]=ichild->Px();
249 p[1]=ichild->Py();
250 p[2]=ichild->Pz();
251 Float_t tof=kconv*ichild->T();
252 gAlice->SetTrack(fTrackIt, iparent, kf,
5be1fe76 253 p,origin,polar,
254 tof,"Decay",nt,fChildWeight);
255 gAlice->KeepTrack(nt);
256 } // select child
257 } // child loop
258 }
259 } // kinematic selection
260 } // select particle
261 } // particle loop
262 } else {
263 for (Int_t i = 0; i<np; i++) {
1578254f 264 TParticle * iparticle = (TParticle *) particles->At(i);
a8228d85 265 kf = CheckPDGCode(iparticle->GetPdgCode());
1578254f 266 Int_t ks = iparticle->GetStatusCode();
267 if (ks==1 && kf!=0 && KinematicSelection(iparticle)) {
5be1fe76 268 nc++;
269//
270// store track information
1578254f 271 p[0]=iparticle->Px();
272 p[1]=iparticle->Py();
273 p[2]=iparticle->Pz();
274 origin[0]=origin0[0]+iparticle->Vx()/10;
275 origin[1]=origin0[1]+iparticle->Vy()/10;
276 origin[2]=origin0[2]+iparticle->Vz()/10;
277 Float_t tof=kconv*iparticle->T();
278 gAlice->SetTrack(fTrackIt,-1,kf,p,origin,polar,
5be1fe76 279 tof,"Primary",nt);
280 gAlice->KeepTrack(nt);
281 } // select particle
282 } // particle loop
283 printf("\n I've put %i particles on the stack \n",nc);
284 } // mb ?
fe4da5cc 285 if (nc > 0) {
5be1fe76 286 jev+=nc;
fe4da5cc 287 if (jev >= fNpart) {
288 fKineBias=Float_t(fNpart)/Float_t(fTrials);
23211d3e 289 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
fe4da5cc 290 break;
291 }
292 }
293 } // event loop
294// adjust weight due to kinematic selection
295 AdjustWeights();
296// get cross-section
297 fXsection=fPythia->GetPARI(1);
298}
299
300Bool_t AliGenPythia::ParentSelected(Int_t ip)
301{
302 for (Int_t i=0; i<5; i++)
303 {
304 if (fParentSelect[i]==ip) return kTRUE;
305 }
306 return kFALSE;
307}
308
309Bool_t AliGenPythia::ChildSelected(Int_t ip)
310{
311 for (Int_t i=0; i<5; i++)
312 {
313 if (fChildSelect[i]==ip) return kTRUE;
314 }
315 return kFALSE;
316}
317
1578254f 318Bool_t AliGenPythia::KinematicSelection(TParticle *particle)
fe4da5cc 319{
1578254f 320 Float_t px=particle->Px();
321 Float_t py=particle->Py();
322 Float_t pz=particle->Pz();
323 Float_t e=particle->Energy();
fe4da5cc 324
325//
326// transverse momentum cut
327 Float_t pt=TMath::Sqrt(px*px+py*py);
328 if (pt > fPtMax || pt < fPtMin)
329 {
330// printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
331 return kFALSE;
332 }
333//
334// momentum cut
335 Float_t p=TMath::Sqrt(px*px+py*py+pz*pz);
336 if (p > fPMax || p < fPMin)
337 {
338// printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
339 return kFALSE;
340 }
341
342//
343// theta cut
5be1fe76 344 Float_t theta = Float_t(TMath::ATan2(Double_t(pt),Double_t(pz)));
fe4da5cc 345 if (theta > fThetaMax || theta < fThetaMin)
346 {
347// printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
348 return kFALSE;
349 }
350
351//
352// rapidity cut
353 Float_t y = 0.5*TMath::Log((e+pz)/(e-pz));
354 if (y > fYMax || y < fYMin)
355 {
356// printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
357 return kFALSE;
358 }
359
360//
361// phi cut
362 Float_t phi=Float_t(TMath::ATan2(Double_t(py),Double_t(px)))+TMath::Pi();
363 if (phi > fPhiMax || phi < fPhiMin)
364 {
365// printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
366 return kFALSE;
367 }
368
369 return kTRUE;
370}
371void AliGenPythia::AdjustWeights()
372{
373 TClonesArray *PartArray = gAlice->Particles();
1578254f 374 TParticle *Part;
fe4da5cc 375 Int_t ntrack=gAlice->GetNtrack();
376 for (Int_t i=0; i<ntrack; i++) {
1578254f 377 Part= (TParticle*) PartArray->UncheckedAt(i);
378 Part->SetWeight(Part->GetWeight()*fKineBias);
fe4da5cc 379 }
380}
381
a8228d85 382Int_t AliGenPythia::CheckPDGCode(Int_t pdgcode)
383{
384//
23211d3e 385// If the particle is in a diffractive state, then take action accordingly
a8228d85 386 switch (pdgcode) {
387 case 110:
388 //rho_diff0 -- difficult to translate, return rho0
389 return 113;
390 case 210:
391 //pi_diffr+ -- change to pi+
392 return 211;
393 case 220:
394 //omega_di0 -- change to omega0
395 return 223;
396 case 330:
397 //phi_diff0 -- return phi0
398 return 333;
399 case 440:
400 //J/psi_di0 -- return J/psi
401 return 443;
402 case 2110:
403 //n_diffr -- return neutron
404 return 2112;
405 case 2210:
406 //p_diffr+ -- return proton
407 return 2212;
408 }
409 //non diffractive state -- return code unchanged
410 return pdgcode;
411}
412
fe4da5cc 413
414
415
416
5be1fe76 417
418
419
420