]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVGEN/AliGenPythia.cxx
Added Vertex smearing and tracking flag by A.Morsch.
[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 <TMCParticle.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->ForceDecay(fForceDecay);
52     fPythia->SetCKIN(3,fPtHardMin);
53     fPythia->SetCKIN(4,fPtHardMax);    
54     fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
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     }
91
92     switch (fForceDecay) 
93     {
94     case semielectronic:
95     case dielectron:
96     case b_jpsi_dielectron:
97     case b_psip_dielectron:
98         fChildSelect[0]=11;     
99         break;
100     case semimuonic:
101     case dimuon:
102     case b_jpsi_dimuon:
103     case b_psip_dimuon:
104         fChildSelect[0]=13;
105         break;
106     }
107 }
108
109 void AliGenPythia::Generate()
110 {
111     AliMC* pMC = AliMC::GetMC();
112
113     Float_t polar[3] = {0,0,0};
114     Float_t origin[3]= {0,0,0};
115     Float_t origin0[3]= {0,0,0};
116     Float_t p[3], random[6];
117     
118     
119 //
120     printf("Generate event");
121     Int_t nt=0;
122     Int_t jev=0;
123     Int_t j;
124     
125     fTrials=0;
126     for (j=0;j<3;j++) origin0[j]=fOrigin[j];
127     if(fVertexSmear==perEvent) {
128         pMC->Rndm(random,6);
129         for (j=0;j<3;j++) {
130             origin0[j]+=fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
131                 TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
132             fPythia->SetMSTP(151,0);
133         }
134     } else if (fVertexSmear==perTrack) {
135         fPythia->SetMSTP(151,0);
136         for (j=0;j<3;j++) {
137             fPythia->SetPARP(151+j, fOsigma[j]*10.);
138         }
139     }
140     
141
142     while(1)
143     {
144         fPythia->PyEvnt();
145         fTrials++;
146         TObjArray* particles = fPythia->GetPrimaries() ;
147         Int_t np = particles->GetEntriesFast();
148         printf("\n **************************************************%d\n",np);
149         Int_t nc=0;
150         if (np == 0 ) continue;
151         for (Int_t i = 0; i<np; i++) {
152             TMCParticle *  iparticle = (TMCParticle *) particles->At(i);
153             Int_t kf = iparticle->GetKF();
154             fChildWeight=(fPythia->GetBraPart(kf))*fParentWeight;         
155 //
156 // Parent
157             if (ParentSelected(TMath::Abs(kf))) {
158                 
159                 if (KinematicSelection(iparticle)) {
160                     nc++;
161 //
162 // store parent track information
163                     p[0]=iparticle->GetPx();
164                     p[1]=iparticle->GetPy();
165                     p[2]=iparticle->GetPz();
166                     origin[0]=origin0[0]+iparticle->GetVx()/10;
167                     origin[1]=origin0[1]+iparticle->GetVy()/10;
168                     origin[2]=origin0[2]+iparticle->GetVz()/10;
169
170                     Int_t ifch=iparticle->GetFirstChild();
171                     Int_t ilch=iparticle->GetLastChild();       
172                     if (ifch !=0 && ilch !=0) {
173                         gAlice->SetTrack(0,-1,fPythia->GetGeantCode(kf),
174                                          p,origin,polar,
175                                          0,"Primary",nt,fParentWeight);
176                         Int_t iparent = nt;
177 //
178 // Children         
179
180                         for (Int_t j=ifch; j<=ilch; j++)
181                         {
182                             TMCParticle *  ichild = 
183                                 (TMCParticle *) particles->At(j-1);
184                             Int_t kf = ichild->GetKF();
185 //
186 // 
187                             if (ChildSelected(TMath::Abs(kf))) {
188                                 Int_t kg=fPythia->GetGeantCode(kf);
189                                 origin[0]=ichild->GetVx();
190                                 origin[1]=ichild->GetVy();
191                                 origin[2]=ichild->GetVz();              
192                                 p[0]=ichild->GetPx();
193                                 p[1]=ichild->GetPy();
194                                 p[2]=ichild->GetPz();
195                                 Float_t tof=ichild->GetTime();
196                                 gAlice->SetTrack(1, iparent, kg,
197                                                  p,origin,polar,
198                                                  tof,"Decay",nt,fChildWeight);
199                                 gAlice->KeepTrack(nt);
200                             } // select child
201                         } // child loop
202                     }
203                 } // kinematic selection
204             } // select particle 
205         } // particles
206         if (nc > 0) {
207             jev++;
208             if (jev >= fNpart) {
209                 fKineBias=Float_t(fNpart)/Float_t(fTrials);
210                 printf("\n Trials: %i\n",fTrials);
211                 break;
212             }
213         }
214     } // event loop
215 //  adjust weight due to kinematic selection
216     AdjustWeights();
217 //  get cross-section
218     fXsection=fPythia->GetPARI(1);
219 }
220
221 Bool_t AliGenPythia::ParentSelected(Int_t ip)
222 {
223     for (Int_t i=0; i<5; i++)
224     {
225         if (fParentSelect[i]==ip) return kTRUE;
226     }
227     return kFALSE;
228 }
229
230 Bool_t AliGenPythia::ChildSelected(Int_t ip)
231 {
232     for (Int_t i=0; i<5; i++)
233     {
234         if (fChildSelect[i]==ip) return kTRUE;
235     }
236     return kFALSE;
237 }
238
239 Bool_t AliGenPythia::KinematicSelection(TMCParticle *particle)
240 {
241     Float_t px=particle->GetPx();
242     Float_t py=particle->GetPy();
243     Float_t pz=particle->GetPz();
244     Float_t  e=particle->GetEnergy();
245
246 //
247 //  transverse momentum cut    
248     Float_t pt=TMath::Sqrt(px*px+py*py);
249     if (pt > fPtMax || pt < fPtMin) 
250     {
251 //      printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
252         return kFALSE;
253     }
254 //
255 // momentum cut
256     Float_t p=TMath::Sqrt(px*px+py*py+pz*pz);
257     if (p > fPMax || p < fPMin) 
258     {
259 //      printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
260         return kFALSE;
261     }
262     
263 //
264 // theta cut
265     Float_t  theta = Float_t(TMath::ATan2(Double_t(pt),Double_t(p)));
266     if (theta > fThetaMax || theta < fThetaMin) 
267     {
268 //      printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
269         return kFALSE;
270     }
271
272 //
273 // rapidity cut
274     Float_t y = 0.5*TMath::Log((e+pz)/(e-pz));
275     if (y > fYMax || y < fYMin)
276     {
277 //      printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
278         return kFALSE;
279     }
280
281 //
282 // phi cut
283     Float_t phi=Float_t(TMath::ATan2(Double_t(py),Double_t(px)))+TMath::Pi();
284     if (phi > fPhiMax || phi < fPhiMin)
285     {
286 //      printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
287         return kFALSE;
288     }
289
290     return kTRUE;
291 }
292 void AliGenPythia::AdjustWeights()
293 {
294     TClonesArray *PartArray = gAlice->Particles();
295     GParticle *Part;
296     Int_t ntrack=gAlice->GetNtrack();
297     for (Int_t i=0; i<ntrack; i++) {
298         Part= (GParticle*) PartArray->UncheckedAt(i);
299         Part->SetWgt(Part->GetWgt()*fKineBias);
300     }
301 }
302
303
304
305
306