1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.25 2000/10/18 19:11:27 hristov
19 Division by zero fixed
21 Revision 1.24 2000/09/18 10:41:35 morsch
22 Add possibility to use nuclear structure functions from PDF library V8.
24 Revision 1.23 2000/09/14 14:05:40 morsch
27 Revision 1.22 2000/09/14 14:02:22 morsch
28 - Correct conversion from mm to cm when passing particle vertex to MC.
29 - Correct handling of fForceDecay == all.
31 Revision 1.21 2000/09/12 14:14:55 morsch
32 Call fDecayer->ForceDecay() at the beginning of Generate().
34 Revision 1.20 2000/09/06 14:29:33 morsch
35 Use AliPythia for event generation an AliDecayPythia for decays.
36 Correct handling of "nodecay" option
38 Revision 1.19 2000/07/11 18:24:56 fca
39 Coding convention corrections + few minor bug fixes
41 Revision 1.18 2000/06/30 12:40:34 morsch
42 Pythia takes care of vertex smearing. Correct conversion from Pythia units (mm) to
45 Revision 1.17 2000/06/09 20:34:07 morsch
46 All coding rule violations except RS3 corrected
48 Revision 1.16 2000/05/15 15:04:20 morsch
49 The full event is written for fNtrack = -1
50 Coding rule violations corrected.
52 Revision 1.15 2000/04/26 10:14:24 morsch
53 Particles array has one entry more than pythia particle list. Upper bound of
54 particle loop changed to np-1 (R. Guernane, AM)
56 Revision 1.14 2000/04/05 08:36:13 morsch
57 Check status code of particles in Pythia event
58 to avoid double counting as partonic state and final state particle.
60 Revision 1.13 1999/11/09 07:38:48 fca
61 Changes for compatibility with version 2.23 of ROOT
63 Revision 1.12 1999/11/03 17:43:20 fca
64 New version from G.Martinez & A.Morsch
66 Revision 1.11 1999/09/29 09:24:14 fca
67 Introduction of the Copyright and cvs Log
70 #include "AliGenPythia.h"
71 #include "AliDecayerPythia.h"
73 #include "AliPythia.h"
75 #include <TParticle.h>
78 ClassImp(AliGenPythia)
80 AliGenPythia::AliGenPythia()
83 // Default Constructor
84 fDecayer = new AliDecayerPythia();
87 AliGenPythia::AliGenPythia(Int_t npart)
90 // default charm production at 5. 5 TeV
92 // structure function GRVHO
99 for (Int_t i=0; i<5; i++) fParentSelect[i]=fChildSelect[i]=0;
105 fDecayer = new AliDecayerPythia();
108 AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
113 AliGenPythia::~AliGenPythia()
118 void AliGenPythia::Init()
121 SetMC(AliPythia::Instance());
122 fPythia=(AliPythia*) fgMCEvGen;
124 fParentWeight=1./Float_t(fNpart);
126 // Forward Paramters to the AliPythia object
127 // gSystem->Exec("ln -s $ALICE_ROOT/data/Decay.table fort.1");
128 // fPythia->Pyupda(2,1);
129 // gSystem->Exec("rm fort.1");
131 fDecayer->SetForceDecay(fForceDecay);
135 fPythia->SetCKIN(3,fPtHardMin);
136 fPythia->SetCKIN(4,fPtHardMax);
137 if (fNucA1 > 0 && fNucA2 > 0) fPythia->SetNuclei(fNucA1, fNucA2);
138 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
140 // fPythia->Pylist(0);
141 // fPythia->Pystat(2);
142 // Parent and Children Selection
147 fParentSelect[0]=411;
148 fParentSelect[1]=421;
149 fParentSelect[2]=431;
150 fParentSelect[3]=4122;
154 fParentSelect[0]=411;
155 fParentSelect[1]=421;
156 fParentSelect[2]=431;
157 fParentSelect[3]=4122;
160 fParentSelect[0]=511;
161 fParentSelect[1]=521;
162 fParentSelect[2]=531;
163 fParentSelect[3]=5122;
165 case beauty_unforced:
166 fParentSelect[0]=511;
167 fParentSelect[1]=521;
168 fParentSelect[2]=531;
169 fParentSelect[3]=5122;
173 fParentSelect[0]=443;
183 case b_jpsi_dielectron:
184 case b_psip_dielectron:
185 fChildSelect[0]=kElectron;
193 fChildSelect[0]=kMuonMinus;
196 fChildSelect[0]=kPiPlus;
197 fChildSelect[1]=kKPlus;
205 void AliGenPythia::Generate()
207 // Generate one event
208 fDecayer->ForceDecay();
210 Float_t polar[3] = {0,0,0};
211 Float_t origin[3]= {0,0,0};
212 Float_t originP[3]= {0,0,0};
213 Float_t origin0[3]= {0,0,0};
215 // Float_t random[6];
216 static TClonesArray *particles;
217 // converts from mm/c to s
218 const Float_t kconv=0.001/2.999792458e8;
227 if(!particles) particles=new TClonesArray("TParticle",1000);
230 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
231 if(fVertexSmear==kPerEvent) {
232 fPythia->SetMSTP(151,1);
234 fPythia->SetPARP(151+j, fOsigma[j]/10.);
236 } else if (fVertexSmear==kPerTrack) {
237 fPythia->SetMSTP(151,0);
243 // fPythia->Pylist(1);
245 fPythia->ImportParticles(particles,"All");
246 Int_t np = particles->GetEntriesFast();
247 printf("\n **************************************************%d\n",np);
249 if (np == 0 ) continue;
250 if (fProcess != mb) {
251 for (Int_t i = 0; i<np-1; i++) {
252 TParticle * iparticle = (TParticle *) particles->At(i);
253 Int_t ks = iparticle->GetStatusCode();
254 kf = CheckPDGCode(iparticle->GetPdgCode());
255 if (ks==21) continue;
257 fChildWeight=(fDecayer->GetPartialBranchingRatio(kf))*fParentWeight;
260 if (ParentSelected(TMath::Abs(kf))) {
261 if (KinematicSelection(iparticle)) {
264 // Store information concerning the hard scattering process
266 Float_t massP = fPythia->GetPARI(13);
267 Float_t ptP = fPythia->GetPARI(17);
268 Float_t yP = fPythia->GetPARI(37);
269 Float_t xmtP = sqrt(ptP*ptP+massP*massP);
270 Float_t ty = Float_t(TMath::TanH(yP));
273 pP[2] = xmtP*ty/sqrt(1.-ty*ty);
275 gAlice->SetTrack(0,-1,-1,
277 0,kPPrimary,ntP,fParentWeight);
278 // 0,"Hard Scat.",ntP,fParentWeight);
279 gAlice->KeepTrack(ntP);
283 // store parent track information
284 p[0]=iparticle->Px();
285 p[1]=iparticle->Py();
286 p[2]=iparticle->Pz();
287 origin[0]=origin0[0]+iparticle->Vx()/10.;
288 origin[1]=origin0[1]+iparticle->Vy()/10.;
289 origin[2]=origin0[2]+iparticle->Vz()/10.;
291 Int_t ifch=iparticle->GetFirstDaughter();
292 Int_t ilch=iparticle->GetLastDaughter();
294 if ((ifch !=0 && ilch !=0) || fForceDecay == nodecay) {
296 if (fForceDecay == nodecay) trackit = 1;
297 gAlice->SetTrack(trackit,ntP,kf,
299 0,kPPrimary,nt,fParentWeight);
300 gAlice->KeepTrack(nt);
304 if (fForceDecay != nodecay) {
305 for (j=ifch; j<=ilch; j++)
308 (TParticle *) particles->At(j-1);
309 kf = CheckPDGCode(ichild->GetPdgCode());
312 if (ChildSelected(TMath::Abs(kf))) {
313 origin[0]=origin0[0]+ichild->Vx()/10.;
314 origin[1]=origin0[1]+ichild->Vy()/10.;
315 origin[2]=origin0[2]+ichild->Vz()/10.;
319 Float_t tof=kconv*ichild->T();
320 gAlice->SetTrack(fTrackIt, iparent, kf,
322 tof,kPDecay,nt,fChildWeight);
323 gAlice->KeepTrack(nt);
328 } // kinematic selection
332 for (Int_t i = 0; i<np-1; i++) {
333 TParticle * iparticle = (TParticle *) particles->At(i);
334 kf = CheckPDGCode(iparticle->GetPdgCode());
335 Int_t ks = iparticle->GetStatusCode();
337 if (ks==1 && kf!=0 && KinematicSelection(iparticle)) {
340 // store track information
341 p[0]=iparticle->Px();
342 p[1]=iparticle->Py();
343 p[2]=iparticle->Pz();
344 origin[0]=origin0[0]+iparticle->Vx()/10.;
345 origin[1]=origin0[1]+iparticle->Vy()/10.;
346 origin[2]=origin0[2]+iparticle->Vz()/10.;
347 Float_t tof=kconv*iparticle->T();
348 gAlice->SetTrack(fTrackIt,-1,kf,p,origin,polar,
350 gAlice->KeepTrack(nt);
353 printf("\n I've put %i particles on the stack \n",nc);
357 if (jev >= fNpart || fNpart == -1) {
358 fKineBias=Float_t(fNpart)/Float_t(fTrials);
359 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
360 // Print x-section summary
366 // adjust weight due to kinematic selection
369 fXsection=fPythia->GetPARI(1);
372 Bool_t AliGenPythia::ParentSelected(Int_t ip)
374 // True if particle is in list of parent particles to be selected
375 for (Int_t i=0; i<5; i++)
377 if (fParentSelect[i]==ip) return kTRUE;
382 Bool_t AliGenPythia::ChildSelected(Int_t ip)
384 // True if particle is in list of decay products to be selected
385 if (fForceDecay == all) return kTRUE;
387 for (Int_t i=0; i<5; i++)
389 if (fChildSelect[i]==ip) return kTRUE;
394 Bool_t AliGenPythia::KinematicSelection(TParticle *particle)
396 // Perform kinematic selection
397 Float_t px=particle->Px();
398 Float_t py=particle->Py();
399 Float_t pz=particle->Pz();
400 Float_t e=particle->Energy();
403 // transverse momentum cut
404 Float_t pt=TMath::Sqrt(px*px+py*py);
405 if (pt > fPtMax || pt < fPtMin)
407 // printf("\n failed pt cut %f %f %f \n",pt,fPtMin,fPtMax);
412 Float_t p=TMath::Sqrt(px*px+py*py+pz*pz);
413 if (p > fPMax || p < fPMin)
415 // printf("\n failed p cut %f %f %f \n",p,fPMin,fPMax);
421 Float_t theta = Float_t(TMath::ATan2(Double_t(pt),Double_t(pz)));
422 if (theta > fThetaMax || theta < fThetaMin)
424 // printf("\n failed theta cut %f %f %f \n",theta,fThetaMin,fThetaMax);
434 Float_t y = 0.5*TMath::Log((e+pz)/(e-pz));
435 if (y > fYMax || y < fYMin)
437 // printf("\n failed y cut %f %f %f \n",y,fYMin,fYMax);
444 Float_t phi=Float_t(TMath::ATan2(Double_t(py),Double_t(px)));
445 if (phi > fPhiMax || phi < fPhiMin)
447 // printf("\n failed phi cut %f %f %f \n",phi,fPhiMin,fPhiMax);
453 void AliGenPythia::AdjustWeights()
455 // Adjust the weights after generation of all events
457 TClonesArray *partArray = gAlice->Particles();
459 Int_t ntrack=gAlice->GetNtrack();
460 for (Int_t i=0; i<ntrack; i++) {
461 part= (TParticle*) partArray->UncheckedAt(i);
462 part->SetWeight(part->GetWeight()*fKineBias);
466 Int_t AliGenPythia::CheckPDGCode(Int_t pdgcode)
469 // If the particle is in a diffractive state, then take action accordingly
474 //rho_diff0 -- difficult to translate, return rho0
477 //pi_diffr+ -- change to pi+
480 //omega_di0 -- change to omega0
483 //phi_diff0 -- return phi0
486 //J/psi_di0 -- return J/psi
489 //n_diffr -- return neutron
492 //p_diffr+ -- return proton
495 //non diffractive state -- return code unchanged
500 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
502 // Treat protons as inside nuclei with mass numbers a1 and a2
508 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
510 // Assignment operator
516 void AliGenPythia::Streamer(TBuffer &R__b)
518 // Stream an object of class AliGenPythia.
520 if (R__b.IsReading()) {
521 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
522 AliGenerator::Streamer(R__b);
523 R__b >> (Int_t&)fProcess;
524 R__b >> (Int_t&)fStrucFunc;
525 R__b >> (Int_t&)fForceDecay;
529 fParentSelect.Streamer(R__b);
530 fChildSelect.Streamer(R__b);
532 // (AliPythia::Instance())->Streamer(R__b);
535 // if (fDecayer) fDecayer->Streamer(R__b);
537 R__b.WriteVersion(AliGenPythia::IsA());
538 AliGenerator::Streamer(R__b);
539 R__b << (Int_t)fProcess;
540 R__b << (Int_t)fStrucFunc;
541 R__b << (Int_t)fForceDecay;
545 fParentSelect.Streamer(R__b);
546 fChildSelect.Streamer(R__b);
551 // fDecayer->Streamer(R__b);
559 #define pyrset pyrset_
560 #define pyrget pyrget_
563 #define pyrset PYRSET
564 #define pyrget PYRGET
568 Double_t pyr(Int_t*) {return sRandom->Rndm();}
569 void pyrset(Int_t*,Int_t*) {}
570 void pyrget(Int_t*,Int_t*) {}