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