]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVGEN/AliGenPythia.cxx
Introduced PDG code everywhere and use of TParticlePDG.
[u/mrichter/AliRoot.git] / EVGEN / AliGenPythia.cxx
1 #include "AliGenerator.h"
2 #include "AliGenPythia.h"
3 #include "TGeant3.h"
4 #include "AliRun.h"
5 #include "AliPythia.h"
6 #include <TDirectory.h>
7 #include <TFile.h>
8 #include <TTree.h>
9 #include <stdlib.h>
10 #include <AliPythia.h>
11 #include <TParticle.h>
12 //#include <GParticle.h>
13  ClassImp(AliGenPythia)
14
15 AliGenPythia::AliGenPythia()
16                  :AliGenerator()
17 {
18 }
19
20 AliGenPythia::AliGenPythia(Int_t npart)
21                  :AliGenerator(npart)
22 {
23 // default charm production at 5. 5 TeV
24 // semimuonic decay
25 // structure function GRVHO
26 //
27     fXsection  = 0.;
28     fParentSelect.Set(5);
29     fChildSelect.Set(5);
30     for (Int_t i=0; i<5; i++) fParentSelect[i]=fChildSelect[i]=0;
31     SetProcess();
32     SetStrucFunc();
33     ForceDecay();
34     SetPtHard();
35     SetEnergyCMS();
36 }
37
38 AliGenPythia::~AliGenPythia()
39 {
40 }
41
42 void AliGenPythia::Init()
43 {
44     SetMC(new AliPythia());
45     fPythia=(AliPythia*) fgMCEvGen;
46 //
47     fParentWeight=1./Float_t(fNpart);
48 //
49 //  Forward Paramters to the AliPythia object
50     fPythia->DefineParticles();
51     fPythia->SetCKIN(3,fPtHardMin);
52     fPythia->SetCKIN(4,fPtHardMax);    
53     fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
54     fPythia->ForceDecay(fForceDecay);
55     fPythia->LuList(0);
56     fPythia->PyStat(2);
57 //  Parent and Children Selection
58     switch (fProcess) 
59     {
60     case charm:
61
62         fParentSelect[0]=411;
63         fParentSelect[1]=421;
64         fParentSelect[2]=431;
65         fParentSelect[3]=4122;  
66         break;
67     case charm_unforced:
68
69         fParentSelect[0]=411;
70         fParentSelect[1]=421;
71         fParentSelect[2]=431;
72         fParentSelect[3]=4122;  
73         break;
74     case beauty:
75         fParentSelect[0]=511;
76         fParentSelect[1]=521;
77         fParentSelect[2]=531;
78         fParentSelect[3]=5122;  
79         break;
80     case beauty_unforced:
81         fParentSelect[0]=511;
82         fParentSelect[1]=521;
83         fParentSelect[2]=531;
84         fParentSelect[3]=5122;  
85         break;
86     case jpsi_chi:
87     case jpsi:
88         fParentSelect[0]=443;
89         break;
90     case mb:
91         break;
92     }
93
94     switch (fForceDecay) 
95     {
96     case semielectronic:
97     case dielectron:
98     case b_jpsi_dielectron:
99     case b_psip_dielectron:
100         fChildSelect[0]=11;     
101         break;
102     case semimuonic:
103     case dimuon:
104     case b_jpsi_dimuon:
105     case b_psip_dimuon:
106     case pitomu:
107     case katomu:
108         fChildSelect[0]=13;
109         break;
110     }
111 }
112
113 void AliGenPythia::Generate()
114 {
115     AliMC* pMC = AliMC::GetMC();
116
117     Float_t polar[3] =   {0,0,0};
118     Float_t origin[3]=   {0,0,0};
119     Float_t origin_p[3]= {0,0,0};
120     Float_t origin0[3]=  {0,0,0};
121     Float_t p[3], p_p[4], random[6];
122 //  converts from mm/c to s
123     const Float_t kconv=0.001/2.999792458e8;
124     
125     
126 //
127     Int_t nt=0;
128     Int_t nt_p=0;
129     Int_t jev=0;
130     Int_t j;
131     
132     fTrials=0;
133     for (j=0;j<3;j++) origin0[j]=fOrigin[j];
134     if(fVertexSmear==perEvent) {
135         pMC->Rndm(random,6);
136         for (j=0;j<3;j++) {
137             origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
138                 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
139             fPythia->SetMSTP(151,0);
140         }
141     } else if (fVertexSmear==perTrack) {
142         fPythia->SetMSTP(151,0);
143         for (j=0;j<3;j++) {
144             fPythia->SetPARP(151+j, fOsigma[j]*10.);
145         }
146     }
147     while(1)
148     {
149         fPythia->PyEvnt();
150         fTrials++;
151         TObjArray* particles = fPythia->ImportParticles();
152         Int_t np = particles->GetEntriesFast();
153         printf("\n **************************************************%d\n",np);
154         Int_t nc=0;
155         if (np == 0 ) continue;
156         if (fProcess != mb) {
157             for (Int_t i = 0; i<np; i++) {
158                 TParticle *  iparticle = (TParticle *) particles->At(i);
159                 Int_t kf = iparticle->GetPdgCode();
160                 fChildWeight=(fPythia->GetBraPart(kf))*fParentWeight;     
161 //
162 // Parent
163                 if (ParentSelected(TMath::Abs(kf))) {
164                     if (KinematicSelection(iparticle)) {
165                         if (nc==0) {
166 //
167 // Store information concerning the hard scattering process
168 //
169                             Float_t mass_p = fPythia->GetPARI(13);
170                             Float_t   pt_p = fPythia->GetPARI(17);
171                             Float_t    y_p = fPythia->GetPARI(37);
172                             Float_t  xmt_p = sqrt(pt_p*pt_p+mass_p*mass_p);
173                             Float_t     ty = Float_t(TMath::TanH(y_p));
174                             p_p[0] = pt_p;
175                             p_p[1] = 0;
176                             p_p[2] = xmt_p*ty/sqrt(1.-ty*ty);
177                             p_p[3] = mass_p;
178                             gAlice->SetTrack(0,-1,-1,
179                                              p_p,origin_p,polar,
180                                              0,"Hard Scat.",nt_p,fParentWeight);
181                             gAlice->KeepTrack(nt_p);
182                         }
183                         nc++;
184 //
185 // store parent track information
186                         p[0]=iparticle->Px();
187                         p[1]=iparticle->Py();
188                         p[2]=iparticle->Pz();
189                         origin[0]=origin0[0]+iparticle->Vx()/10;
190                         origin[1]=origin0[1]+iparticle->Vy()/10;
191                         origin[2]=origin0[2]+iparticle->Vz()/10;
192
193                         Int_t ifch=iparticle->GetFirstDaughter();
194                         Int_t ilch=iparticle->GetLastDaughter();        
195                         if (ifch !=0 && ilch !=0) {
196                             gAlice->SetTrack(0,nt_p,kf,
197                                              p,origin,polar,
198                                              0,"Primary",nt,fParentWeight);
199                             gAlice->KeepTrack(nt);
200                             Int_t iparent = nt;
201 //
202 // Children         
203
204                             for (Int_t j=ifch; j<=ilch; j++)
205                             {
206                                 TParticle *  ichild = 
207                                     (TParticle *) particles->At(j-1);
208                                 Int_t kf = ichild->GetPdgCode();
209 //
210 // 
211                                 if (ChildSelected(TMath::Abs(kf))) {
212                                     origin[0]=ichild->Vx();
213                                     origin[1]=ichild->Vy();
214                                     origin[2]=ichild->Vz();             
215                                     p[0]=ichild->Px();
216                                     p[1]=ichild->Py();
217                                     p[2]=ichild->Pz();
218                                     Float_t tof=kconv*ichild->T();
219                                     gAlice->SetTrack(fTrackIt, iparent, kf,
220                                                      p,origin,polar,
221                                                      tof,"Decay",nt,fChildWeight);
222                                     gAlice->KeepTrack(nt);
223                                 } // select child
224                             } // child loop
225                         }
226                     } // kinematic selection
227                 } // select particle
228             } // particle loop
229         } else {
230             for (Int_t i = 0; i<np; i++) {
231                 TParticle *  iparticle = (TParticle *) particles->At(i);
232                 Int_t kf = iparticle->GetPdgCode();
233                 Int_t ks = iparticle->GetStatusCode();
234                 if (ks==1 && kf!=0 && KinematicSelection(iparticle)) {
235                         nc++;
236 //
237 // store track information
238                         p[0]=iparticle->Px();
239                         p[1]=iparticle->Py();
240                         p[2]=iparticle->Pz();
241                         origin[0]=origin0[0]+iparticle->Vx()/10;
242                         origin[1]=origin0[1]+iparticle->Vy()/10;
243                         origin[2]=origin0[2]+iparticle->Vz()/10;
244                         Float_t tof=kconv*iparticle->T();
245                         gAlice->SetTrack(fTrackIt,-1,kf,p,origin,polar,
246                                          tof,"Primary",nt);
247                         gAlice->KeepTrack(nt);
248                 } // select particle
249             } // particle loop 
250             printf("\n I've put %i particles on the stack \n",nc);
251         } // mb ?
252         if (nc > 0) {
253             jev+=nc;
254             if (jev >= fNpart) {
255                 fKineBias=Float_t(fNpart)/Float_t(fTrials);
256                 printf("\n Trials: %i\n",fTrials);
257                 break;
258             }
259         }
260     } // event loop
261 //  adjust weight due to kinematic selection
262     AdjustWeights();
263 //  get cross-section
264     fXsection=fPythia->GetPARI(1);
265 }
266
267 Bool_t AliGenPythia::ParentSelected(Int_t ip)
268 {
269     for (Int_t i=0; i<5; i++)
270     {
271         if (fParentSelect[i]==ip) return kTRUE;
272     }
273     return kFALSE;
274 }
275
276 Bool_t AliGenPythia::ChildSelected(Int_t ip)
277 {
278     for (Int_t i=0; i<5; i++)
279     {
280         if (fChildSelect[i]==ip) return kTRUE;
281     }
282     return kFALSE;
283 }
284
285 Bool_t AliGenPythia::KinematicSelection(TParticle *particle)
286 {
287     Float_t px=particle->Px();
288     Float_t py=particle->Py();
289     Float_t pz=particle->Pz();
290     Float_t  e=particle->Energy();
291
292 //
293 //  transverse momentum cut    
294     Float_t pt=TMath::Sqrt(px*px+py*py);
295     if (pt > fPtMax || pt < fPtMin) 
296     {
297 //      printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
298         return kFALSE;
299     }
300 //
301 // momentum cut
302     Float_t p=TMath::Sqrt(px*px+py*py+pz*pz);
303     if (p > fPMax || p < fPMin) 
304     {
305 //      printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
306         return kFALSE;
307     }
308     
309 //
310 // theta cut
311     Float_t  theta = Float_t(TMath::ATan2(Double_t(pt),Double_t(pz)));
312     if (theta > fThetaMax || theta < fThetaMin) 
313     {
314 //      printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
315         return kFALSE;
316     }
317
318 //
319 // rapidity cut
320     Float_t y = 0.5*TMath::Log((e+pz)/(e-pz));
321     if (y > fYMax || y < fYMin)
322     {
323 //      printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
324         return kFALSE;
325     }
326
327 //
328 // phi cut
329     Float_t phi=Float_t(TMath::ATan2(Double_t(py),Double_t(px)))+TMath::Pi();
330     if (phi > fPhiMax || phi < fPhiMin)
331     {
332 //      printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
333         return kFALSE;
334     }
335
336     return kTRUE;
337 }
338 void AliGenPythia::AdjustWeights()
339 {
340     TClonesArray *PartArray = gAlice->Particles();
341     TParticle *Part;
342     Int_t ntrack=gAlice->GetNtrack();
343     for (Int_t i=0; i<ntrack; i++) {
344         Part= (TParticle*) PartArray->UncheckedAt(i);
345         Part->SetWeight(Part->GetWeight()*fKineBias);
346     }
347 }
348
349
350
351
352
353
354
355
356