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