]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVGEN/AliGenPythia.cxx
Do not delete subtasks when AliRunDigitizer is deleted. Owner should delete them...
[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$
5f42cc16 18Revision 1.56 2002/04/26 10:30:01 morsch
19Option kPyBeautyPbMNR added. (N. Carrer).
20
c0acde67 21Revision 1.55 2002/04/17 10:23:56 morsch
22Coding Rule violations corrected.
23
6d4dd317 24Revision 1.54 2002/03/28 11:49:10 morsch
25Pass status code in SetTrack.
26
5ec84200 27Revision 1.53 2002/03/25 14:51:13 morsch
28New stack-fill and count options introduced (N. Carrer).
29
0d7c70a0 30Revision 1.51 2002/03/06 08:46:57 morsch
31- Loop until np-1
32- delete dyn. alloc. arrays (N. Carrer)
33
b9817493 34Revision 1.50 2002/03/03 13:48:50 morsch
35Option kPyCharmPbMNR added. Produce charm pairs in agreement with MNR
36NLO calculations (Nicola Carrer).
37
fbd1348b 38Revision 1.49 2002/02/08 16:50:50 morsch
39Add name and title in constructor.
40
8b31bfac 41Revision 1.48 2001/12/20 11:44:28 morsch
42Add kinematic bias for direct gamma production.
43
b2bb450d 44Revision 1.47 2001/12/19 14:45:00 morsch
45Store number of trials in header.
46
fd8fb861 47Revision 1.46 2001/12/19 10:36:19 morsch
48Add possibility if jet kinematic biasing.
49
988b118b 50Revision 1.45 2001/11/28 08:06:52 morsch
51Use fMaxLifeTime parameter.
52
8cdfd303 53Revision 1.44 2001/11/27 13:13:07 morsch
54Maximum lifetime for long-lived particles to be put on the stack is parameter.
55It can be set via SetMaximumLifetime(..).
56
47fc6bd5 57Revision 1.43 2001/10/21 18:35:56 hristov
58Several pointers were set to zero in the default constructors to avoid memory management problems
59
2685bf00 60Revision 1.42 2001/10/15 08:21:55 morsch
61Vertex truncation settings moved to AliGenMC.
62
4c07486d 63Revision 1.41 2001/10/08 08:45:42 morsch
64Possibility of vertex cut added.
65
a0b2b296 66Revision 1.40 2001/09/25 11:30:23 morsch
67Pass event vertex to header.
68
c5d36e84 69Revision 1.39 2001/07/27 17:09:36 morsch
70Use local SetTrack, KeepTrack and SetHighWaterMark methods
71to delegate either to local stack or to stack owned by AliRun.
72(Piotr Skowronski, A.M.)
73
a99cf51f 74Revision 1.38 2001/07/13 10:58:54 morsch
75- Some coded moved to AliGenMC
76- Improved handling of secondary vertices.
77
fff02fee 78Revision 1.37 2001/06/28 11:17:28 morsch
79SetEventListRange setter added. Events in specified range are listed for
80debugging. (Yuri Kharlov)
81
11dfaf8d 82Revision 1.36 2001/03/30 07:05:49 morsch
83Final print-out in finish run.
84Write parton system for jet-production (preliminary solution).
85
9be6226f 86Revision 1.35 2001/03/09 13:03:40 morsch
87Process_t and Struc_Func_t moved to AliPythia.h
88
f1a48a38 89Revision 1.34 2001/02/14 15:50:40 hristov
90The last particle in event marked using SetHighWaterMark
91
28adac24 92Revision 1.33 2001/01/30 09:23:12 hristov
93Streamers removed (R.Brun)
94
a8a6107b 95Revision 1.32 2001/01/26 19:55:51 hristov
96Major upgrade of AliRoot code
97
2ab0c725 98Revision 1.31 2001/01/17 10:54:31 hristov
99Better protection against FPE
100
0f9e52a3 101Revision 1.30 2000/12/18 08:55:35 morsch
102Make AliPythia dependent generartors work with new scheme of random number generation
103
3356c022 104Revision 1.29 2000/12/04 11:22:03 morsch
105Init of sRandom as in 1.15
106
097ec7c1 107Revision 1.28 2000/12/02 11:41:39 morsch
108Use SetRandom() to initialize random number generator in constructor.
109
1ed25e11 110Revision 1.27 2000/11/30 20:29:02 morsch
111Initialise static variable sRandom in constructor: sRandom = fRandom;
112
ad1df918 113Revision 1.26 2000/11/30 07:12:50 alibrary
114Introducing new Rndm and QA classes
115
65fb704d 116Revision 1.25 2000/10/18 19:11:27 hristov
117Division by zero fixed
118
919c2096 119Revision 1.24 2000/09/18 10:41:35 morsch
120Add possibility to use nuclear structure functions from PDF library V8.
121
811826d8 122Revision 1.23 2000/09/14 14:05:40 morsch
123dito
124
819f84ad 125Revision 1.22 2000/09/14 14:02:22 morsch
126- Correct conversion from mm to cm when passing particle vertex to MC.
127- Correct handling of fForceDecay == all.
128
4451ef92 129Revision 1.21 2000/09/12 14:14:55 morsch
130Call fDecayer->ForceDecay() at the beginning of Generate().
131
00d6ce7d 132Revision 1.20 2000/09/06 14:29:33 morsch
133Use AliPythia for event generation an AliDecayPythia for decays.
134Correct handling of "nodecay" option
135
18edb254 136Revision 1.19 2000/07/11 18:24:56 fca
137Coding convention corrections + few minor bug fixes
138
aee8290b 139Revision 1.18 2000/06/30 12:40:34 morsch
140Pythia takes care of vertex smearing. Correct conversion from Pythia units (mm) to
141Geant units (cm).
142
1512e357 143Revision 1.17 2000/06/09 20:34:07 morsch
144All coding rule violations except RS3 corrected
145
f87cfe57 146Revision 1.16 2000/05/15 15:04:20 morsch
147The full event is written for fNtrack = -1
148Coding rule violations corrected.
149
5ddeb374 150Revision 1.15 2000/04/26 10:14:24 morsch
151Particles array has one entry more than pythia particle list. Upper bound of
152particle loop changed to np-1 (R. Guernane, AM)
153
2a0e6f5b 154Revision 1.14 2000/04/05 08:36:13 morsch
155Check status code of particles in Pythia event
156to avoid double counting as partonic state and final state particle.
157
23211d3e 158Revision 1.13 1999/11/09 07:38:48 fca
159Changes for compatibility with version 2.23 of ROOT
160
084c1b4a 161Revision 1.12 1999/11/03 17:43:20 fca
162New version from G.Martinez & A.Morsch
163
886b6f73 164Revision 1.11 1999/09/29 09:24:14 fca
165Introduction of the Copyright and cvs Log
4c039060 166*/
167
6d4dd317 168//
169// Generator using the TPythia interface (via AliPythia)
170// to generate pp collisions.
171// Using SetNuclei() also nuclear modifications to the structure functions
172// can be taken into account. This makes, of course, only sense for the
173// generation of the products of hard processes (heavy flavor, jets ...)
174//
175// andreas.morsch@cern.ch
176//
177
178
fe4da5cc 179#include "AliGenPythia.h"
fff02fee 180#include "AliGenPythiaEventHeader.h"
18edb254 181#include "AliDecayerPythia.h"
fe4da5cc 182#include "AliRun.h"
183#include "AliPythia.h"
18edb254 184#include "AliPDG.h"
1578254f 185#include <TParticle.h>
18edb254 186#include <TSystem.h>
f87cfe57 187
fe4da5cc 188 ClassImp(AliGenPythia)
189
190AliGenPythia::AliGenPythia()
fff02fee 191 :AliGenMC()
fe4da5cc 192{
18edb254 193// Default Constructor
2685bf00 194 fParticles = 0;
195 fPythia = 0;
988b118b 196 fDecayer = new AliDecayerPythia();
11dfaf8d 197 SetEventListRange();
988b118b 198 SetJetPhiRange();
199 SetJetEtaRange();
fe4da5cc 200}
201
202AliGenPythia::AliGenPythia(Int_t npart)
fff02fee 203 :AliGenMC(npart)
fe4da5cc 204{
205// default charm production at 5. 5 TeV
206// semimuonic decay
207// structure function GRVHO
208//
8b31bfac 209 fName = "Pythia";
210 fTitle= "Particle Generator using PYTHIA";
fe4da5cc 211 fXsection = 0.;
811826d8 212 fNucA1=0;
213 fNucA2=0;
fe4da5cc 214 SetProcess();
215 SetStrucFunc();
886b6f73 216 SetForceDecay();
fe4da5cc 217 SetPtHard();
218 SetEnergyCMS();
18edb254 219 fDecayer = new AliDecayerPythia();
1ed25e11 220 // Set random number generator
097ec7c1 221 sRandom=fRandom;
fff02fee 222 fFlavorSelect = 0;
223 // Produced particles
224 fParticles = new TClonesArray("TParticle",1000);
c5d36e84 225 fEventVertex.Set(3);
988b118b 226 SetEventListRange();
227 SetJetPhiRange();
228 SetJetEtaRange();
719b6b8a 229 // Options determining what to keep in the stack (Heavy flavour generation)
230 fStackFillOpt = kFlavorSelection; // Keep particle with selected flavor
231 fFeedDownOpt = kTRUE; // allow feed down from higher family
232 // Fragmentation on/off
233 fFragmentation = kTRUE;
234 // Default counting mode
235 fCountMode = kCountAll;
fe4da5cc 236}
237
f87cfe57 238AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
239{
240// copy constructor
6d4dd317 241 Pythia.Copy(*this);
f87cfe57 242}
243
fe4da5cc 244AliGenPythia::~AliGenPythia()
245{
5ddeb374 246// Destructor
fe4da5cc 247}
248
11dfaf8d 249void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
250{
251 // Set a range of event numbers, for which a table
252 // of generated particle will be printed
253 fDebugEventFirst = eventFirst;
254 fDebugEventLast = eventLast;
255 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
256}
257
fe4da5cc 258void AliGenPythia::Init()
259{
5ddeb374 260// Initialisation
18edb254 261 SetMC(AliPythia::Instance());
fe4da5cc 262 fPythia=(AliPythia*) fgMCEvGen;
263//
264 fParentWeight=1./Float_t(fNpart);
265//
266// Forward Paramters to the AliPythia object
00d6ce7d 267 fDecayer->SetForceDecay(fForceDecay);
18edb254 268 fDecayer->Init();
00d6ce7d 269
18edb254 270
fe4da5cc 271 fPythia->SetCKIN(3,fPtHardMin);
272 fPythia->SetCKIN(4,fPtHardMax);
811826d8 273 if (fNucA1 > 0 && fNucA2 > 0) fPythia->SetNuclei(fNucA1, fNucA2);
719b6b8a 274 // Fragmentation?
275 if (fFragmentation) {
276 fPythia->SetMSTP(111,1);
277 } else {
278 fPythia->SetMSTP(111,0);
279 }
280
fe4da5cc 281 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
18edb254 282
283 // fPythia->Pylist(0);
284 // fPythia->Pystat(2);
fe4da5cc 285// Parent and Children Selection
286 switch (fProcess)
287 {
f1a48a38 288 case kPyCharm:
f1a48a38 289 case kPyCharmUnforced:
fbd1348b 290 case kPyCharmPbMNR:
b2bb450d 291 fParentSelect[0] = 411;
292 fParentSelect[1] = 421;
293 fParentSelect[2] = 431;
294 fParentSelect[3] = 4122;
8b31bfac 295 fFlavorSelect = 4;
fe4da5cc 296 break;
719b6b8a 297 case kPyD0PbMNR:
298 fParentSelect[0] = 421;
5f42cc16 299 fFlavorSelect = 4;
719b6b8a 300 break;
f1a48a38 301 case kPyBeauty:
c0acde67 302 case kPyBeautyPbMNR:
fff02fee 303 fParentSelect[0]= 511;
304 fParentSelect[1]= 521;
305 fParentSelect[2]= 531;
306 fParentSelect[3]= 5122;
307 fParentSelect[4]= 5132;
308 fParentSelect[5]= 5232;
309 fParentSelect[6]= 5332;
310 fFlavorSelect = 5;
fe4da5cc 311 break;
f1a48a38 312 case kPyBeautyUnforced:
fff02fee 313 fParentSelect[0] = 511;
314 fParentSelect[1] = 521;
315 fParentSelect[2] = 531;
316 fParentSelect[3] = 5122;
317 fParentSelect[4] = 5132;
318 fParentSelect[5] = 5232;
319 fParentSelect[6] = 5332;
320 fFlavorSelect = 5;
fe4da5cc 321 break;
f1a48a38 322 case kPyJpsiChi:
323 case kPyJpsi:
fff02fee 324 fParentSelect[0] = 443;
fe4da5cc 325 break;
f1a48a38 326 case kPyMb:
5f42cc16 327 case kPyMbNonDiffr:
f1a48a38 328 case kPyJets:
329 case kPyDirectGamma:
5be1fe76 330 break;
fe4da5cc 331 }
fff02fee 332 AliGenMC::Init();
fe4da5cc 333}
334
335void AliGenPythia::Generate()
336{
5ddeb374 337// Generate one event
00d6ce7d 338 fDecayer->ForceDecay();
a0b2b296 339
9be6226f 340 Float_t polar[3] = {0,0,0};
341 Float_t origin[3] = {0,0,0};
fff02fee 342 Float_t p[3];
5be1fe76 343// converts from mm/c to s
344 const Float_t kconv=0.001/2.999792458e8;
fe4da5cc 345//
fe4da5cc 346 Int_t nt=0;
347 Int_t jev=0;
7921755b 348 Int_t j, kf;
fe4da5cc 349 fTrials=0;
fff02fee 350
fd8fb861 351 // Set collision vertex position
aee8290b 352 if(fVertexSmear==kPerEvent) {
1512e357 353 fPythia->SetMSTP(151,1);
fe4da5cc 354 for (j=0;j<3;j++) {
fff02fee 355 fPythia->SetPARP(151+j, fOsigma[j]*10.);
fe4da5cc 356 }
aee8290b 357 } else if (fVertexSmear==kPerTrack) {
fe4da5cc 358 fPythia->SetMSTP(151,0);
fe4da5cc 359 }
fff02fee 360// event loop
fe4da5cc 361 while(1)
362 {
084c1b4a 363 fPythia->Pyevnt();
11dfaf8d 364 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
365 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
fe4da5cc 366 fTrials++;
47fc6bd5 367
fff02fee 368 fPythia->ImportParticles(fParticles,"All");
369
370//
371//
372//
373 Int_t i;
374
375 Int_t np = fParticles->GetEntriesFast();
a0b2b296 376 if (np == 0 ) continue;
377// Get event vertex and discard the event if the Z coord. is too big
4c07486d 378 TParticle *iparticle = (TParticle *) fParticles->At(0);
379 Float_t distz = iparticle->Vz()/10.;
380 if(TMath::Abs(distz)>fCutVertexZ*fOsigma[2]) continue;
a0b2b296 381//
4c07486d 382 fEventVertex[0] = iparticle->Vx()/10.+fOrigin.At(0);
383 fEventVertex[1] = iparticle->Vy()/10.+fOrigin.At(1);
384 fEventVertex[2] = iparticle->Vz()/10.+fOrigin.At(2);
a0b2b296 385//
fff02fee 386 Int_t* pParent = new Int_t[np];
387 Int_t* pSelected = new Int_t[np];
388 Int_t* trackIt = new Int_t[np];
b9817493 389 for (i=0; i< np; i++) {
fff02fee 390 pParent[i] = -1;
391 pSelected[i] = 0;
719b6b8a 392 trackIt[i] = 0;
fff02fee 393 }
719b6b8a 394 // printf("\n **************************************************%d\n",np);
395 Int_t nc = 0; // Total n. of selected particles
396 Int_t nParents = 0; // Selected parents
397 Int_t nTkbles = 0; // Trackable particles
5f42cc16 398 if (fProcess != kPyMb && fProcess != kPyJets && fProcess != kPyDirectGamma &&
399 fProcess != kPyMbNonDiffr) {
fd8fb861 400
b9817493 401 for (i = 0; i<np; i++) {
c5d36e84 402 iparticle = (TParticle *) fParticles->At(i);
23211d3e 403 Int_t ks = iparticle->GetStatusCode();
a8228d85 404 kf = CheckPDGCode(iparticle->GetPdgCode());
fff02fee 405// No initial state partons
2a0e6f5b 406 if (ks==21) continue;
fe4da5cc 407//
fff02fee 408// Heavy Flavor Selection
5be1fe76 409//
fff02fee 410 // quark ?
411 kf = TMath::Abs(kf);
412 Int_t kfl = kf;
413 // meson ?
414 if (kfl > 10) kfl/=100;
415 // baryon
416 if (kfl > 10) kfl/=10;
417 if (kfl > 10) kfl/=10;
418
419 Int_t ipa = iparticle->GetFirstMother()-1;
420 Int_t kfMo = 0;
421
422 if (ipa > -1) {
423 TParticle * mother = (TParticle *) fParticles->At(ipa);
424 kfMo = TMath::Abs(mother->GetPdgCode());
425 }
426// printf("\n particle (all) %d %d %d", i, pSelected[i], kf);
719b6b8a 427 // What to keep in Stack?
428 Bool_t flavorOK = kFALSE;
429 Bool_t selectOK = kFALSE;
430 if (fFeedDownOpt) {
431 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
432 } else {
433 if (kfl > fFlavorSelect) {
434 nc = -1;
435 break;
436 }
437 if (kfl == fFlavorSelect) flavorOK = kTRUE;
438 }
439 switch (fStackFillOpt) {
440 case kFlavorSelection:
441 selectOK = kTRUE;
442 break;
443 case kParentSelection:
444 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
445 break;
446 }
447 if (flavorOK && selectOK) {
5be1fe76 448//
fff02fee 449// Heavy flavor hadron or quark
fe4da5cc 450//
fff02fee 451// Kinematic seletion on final state heavy flavor mesons
452 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
453 {
719b6b8a 454 continue;
fff02fee 455 }
456 pSelected[i] = 1;
719b6b8a 457 if (ParentSelected(kf)) ++nParents; // Update parent count
fff02fee 458// printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
459 } else {
460// Kinematic seletion on decay products
461 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
462 && !KinematicSelection(iparticle, 1))
463 {
719b6b8a 464 continue;
fff02fee 465 }
fe4da5cc 466//
fff02fee 467// Decay products
468// Select if mother was selected and is not tracked
469
470 if (pSelected[ipa] &&
471 !trackIt[ipa] && // mother will be tracked ?
472 kfMo != 5 && // mother is b-quark, don't store fragments
473 kfMo != 4 && // mother is c-quark, don't store fragments
474 kf != 92) // don't store string
475 {
fe4da5cc 476//
fff02fee 477// Semi-stable or de-selected: diselect decay products:
fe4da5cc 478//
5be1fe76 479//
47fc6bd5 480 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
fff02fee 481 {
482 Int_t ipF = iparticle->GetFirstDaughter();
483 Int_t ipL = iparticle->GetLastDaughter();
484 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
485 }
486// printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
487 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
488 }
489 }
490 if (pSelected[i] == -1) pSelected[i] = 0;
491 if (!pSelected[i]) continue;
719b6b8a 492 // Count quarks only if you did not include fragmentation
493 if (fFragmentation && kf <= 10) continue;
fff02fee 494 nc++;
495// Decision on tracking
496 trackIt[i] = 0;
497//
498// Track final state particle
499 if (ks == 1) trackIt[i] = 1;
500// Track semi-stable particles
8cdfd303 501 if ((ks ==1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
fff02fee 502// Track particles selected by process if undecayed.
503 if (fForceDecay == kNoDecay) {
504 if (ParentSelected(kf)) trackIt[i] = 1;
505 } else {
506 if (ParentSelected(kf)) trackIt[i] = 0;
507 }
719b6b8a 508 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
fff02fee 509//
510//
511
512 } // particle selection loop
719b6b8a 513 if (nc > 0) {
b9817493 514 for (i = 0; i<np; i++) {
fff02fee 515 if (!pSelected[i]) continue;
516 TParticle * iparticle = (TParticle *) fParticles->At(i);
517 kf = CheckPDGCode(iparticle->GetPdgCode());
5ec84200 518 Int_t ks = iparticle->GetStatusCode();
a0b2b296 519 p[0] = iparticle->Px();
520 p[1] = iparticle->Py();
521 p[2] = iparticle->Pz();
522 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
523 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
524 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
525 Float_t tof = kconv*iparticle->T();
526 Int_t ipa = iparticle->GetFirstMother()-1;
fff02fee 527 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
a99cf51f 528 SetTrack(fTrackIt*trackIt[i] ,
5ec84200 529 iparent, kf, p, origin, polar, tof, kPPrimary, nt, 1., ks);
fff02fee 530 pParent[i] = nt;
a99cf51f 531 KeepTrack(nt);
fff02fee 532 } // SetTrack loop
533 }
534 } else {
535 nc = GenerateMB();
5be1fe76 536 } // mb ?
fff02fee 537
b9817493 538 if (pParent) delete[] pParent;
539 if (pSelected) delete[] pSelected;
540 if (trackIt) delete[] trackIt;
541
fe4da5cc 542 if (nc > 0) {
719b6b8a 543 switch (fCountMode) {
544 case kCountAll:
545 // printf(" Count all \n");
546 jev += nc;
547 break;
548 case kCountParents:
549 // printf(" Count parents \n");
550 jev += nParents;
551 break;
552 case kCountTrackables:
553 // printf(" Count trackable \n");
554 jev += nTkbles;
555 break;
556 }
5ddeb374 557 if (jev >= fNpart || fNpart == -1) {
fe4da5cc 558 fKineBias=Float_t(fNpart)/Float_t(fTrials);
23211d3e 559 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
fd8fb861 560 MakeHeader();
fe4da5cc 561 break;
562 }
563 }
564 } // event loop
a99cf51f 565 SetHighWaterMark(nt);
fe4da5cc 566// adjust weight due to kinematic selection
567 AdjustWeights();
568// get cross-section
569 fXsection=fPythia->GetPARI(1);
570}
571
fff02fee 572Int_t AliGenPythia::GenerateMB()
fe4da5cc 573{
5ec84200 574//
575// Min Bias selection and other global selections
576//
fff02fee 577 Int_t i, kf, nt, iparent;
578 Int_t nc = 0;
579 Float_t p[3];
580 Float_t polar[3] = {0,0,0};
581 Float_t origin[3] = {0,0,0};
fff02fee 582// converts from mm/c to s
583 const Float_t kconv=0.001/2.999792458e8;
4451ef92 584
fff02fee 585 Int_t np = fParticles->GetEntriesFast();
586 Int_t* pParent = new Int_t[np];
b9817493 587 for (i=0; i< np; i++) pParent[i] = -1;
b2bb450d 588 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
988b118b 589 TParticle* jet1 = (TParticle *) fParticles->At(6);
590 TParticle* jet2 = (TParticle *) fParticles->At(7);
591 if (!CheckTrigger(jet1, jet2)) return 0;
592 }
593
b9817493 594 for (i = 0; i<np; i++) {
fff02fee 595 Int_t trackIt = 0;
596 TParticle * iparticle = (TParticle *) fParticles->At(i);
597 kf = CheckPDGCode(iparticle->GetPdgCode());
598 Int_t ks = iparticle->GetStatusCode();
599 Int_t km = iparticle->GetFirstMother();
600// printf("\n Particle: %d %d %d", i, kf, ks);
601
602 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
603 (ks != 1) ||
604 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
605 nc++;
606 if (ks == 1) trackIt = 1;
607 Int_t ipa = iparticle->GetFirstMother()-1;
fe4da5cc 608
fff02fee 609 iparent = (ipa > -1) ? pParent[ipa] : -1;
fe4da5cc 610
611//
fff02fee 612// store track information
a0b2b296 613 p[0] = iparticle->Px();
614 p[1] = iparticle->Py();
615 p[2] = iparticle->Pz();
616 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
617 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
618 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
fff02fee 619 Float_t tof=kconv*iparticle->T();
a99cf51f 620 SetTrack(fTrackIt*trackIt, iparent, kf, p, origin, polar,
5ec84200 621 tof, kPPrimary, nt, 1., ks);
a99cf51f 622 KeepTrack(nt);
fff02fee 623 pParent[i] = nt;
624 } // select particle
625 } // particle loop
626
627 if (pParent) delete[] pParent;
fe4da5cc 628
fff02fee 629 printf("\n I've put %i particles on the stack \n",nc);
fff02fee 630 return nc;
631}
fe4da5cc 632
fe4da5cc 633
fff02fee 634void AliGenPythia::FinishRun()
635{
636// Print x-section summary
637 fPythia->Pystat(1);
fe4da5cc 638}
fff02fee 639
fe4da5cc 640void AliGenPythia::AdjustWeights()
641{
5ddeb374 642// Adjust the weights after generation of all events
643//
5ddeb374 644 TParticle *part;
fe4da5cc 645 Int_t ntrack=gAlice->GetNtrack();
646 for (Int_t i=0; i<ntrack; i++) {
2ab0c725 647 part= gAlice->Particle(i);
5ddeb374 648 part->SetWeight(part->GetWeight()*fKineBias);
fe4da5cc 649 }
650}
811826d8 651
652void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
653{
654// Treat protons as inside nuclei with mass numbers a1 and a2
655 fNucA1 = a1;
656 fNucA2 = a2;
657}
fff02fee 658
659
6d4dd317 660void AliGenPythia::MakeHeader() const
fff02fee 661{
662// Builds the event header, to be called after each event
663 AliGenEventHeader* header = new AliGenPythiaEventHeader("Pythia");
c5d36e84 664 ((AliGenPythiaEventHeader*) header)->SetProcessType(fPythia->GetMSTI(1));
fd8fb861 665 ((AliGenPythiaEventHeader*) header)->SetTrials(fTrials);
c5d36e84 666 header->SetPrimaryVertex(fEventVertex);
667 gAlice->SetGenEventHeader(header);
fff02fee 668}
811826d8 669
988b118b 670
5ec84200 671Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2) const
988b118b 672{
673// Check the kinematic trigger condition
674//
b2bb450d 675 Double_t eta[2];
676 eta[0] = jet1->Eta();
677 eta[1] = jet2->Eta();
678 Double_t phi[2];
679 phi[0] = jet1->Phi();
680 phi[1] = jet2->Phi();
681 Int_t pdg[2];
682 pdg[0] = jet1->GetPdgCode();
683 pdg[1] = jet2->GetPdgCode();
988b118b 684 Bool_t triggered = kFALSE;
b2bb450d 685
686 if (fProcess == kPyJets) {
687 //Check eta range first...
688 if ((eta[0] < fEtaMaxJet && eta[0] > fEtaMinJet) ||
689 (eta[1] < fEtaMaxJet && eta[1] > fEtaMinJet))
690 {
691 //Eta is okay, now check phi range
692 if ((phi[0] < fPhiMaxJet && phi[0] > fPhiMinJet) ||
693 (phi[1] < fPhiMaxJet && phi[1] > fPhiMinJet))
694 {
695 triggered = kTRUE;
696 }
697 }
698 } else {
699 Int_t ij = 0;
700 Int_t ig = 1;
701 if (pdg[0] == kGamma) {
702 ij = 1;
703 ig = 0;
704 }
705 //Check eta range first...
706 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
707 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
708 {
709 //Eta is okay, now check phi range
710 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
711 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
712 {
713 triggered = kTRUE;
714 }
715 }
988b118b 716 }
b2bb450d 717
718
988b118b 719 return triggered;
720}
811826d8 721
f87cfe57 722AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
723{
724// Assignment operator
725 return *this;
726}
fe4da5cc 727
728
811826d8 729
a8a6107b 730#ifdef never
18edb254 731void AliGenPythia::Streamer(TBuffer &R__b)
732{
733 // Stream an object of class AliGenPythia.
734
735 if (R__b.IsReading()) {
736 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
737 AliGenerator::Streamer(R__b);
738 R__b >> (Int_t&)fProcess;
739 R__b >> (Int_t&)fStrucFunc;
740 R__b >> (Int_t&)fForceDecay;
741 R__b >> fEnergyCMS;
742 R__b >> fKineBias;
743 R__b >> fTrials;
744 fParentSelect.Streamer(R__b);
745 fChildSelect.Streamer(R__b);
746 R__b >> fXsection;
747// (AliPythia::Instance())->Streamer(R__b);
748 R__b >> fPtHardMin;
749 R__b >> fPtHardMax;
750// if (fDecayer) fDecayer->Streamer(R__b);
751 } else {
752 R__b.WriteVersion(AliGenPythia::IsA());
753 AliGenerator::Streamer(R__b);
754 R__b << (Int_t)fProcess;
755 R__b << (Int_t)fStrucFunc;
756 R__b << (Int_t)fForceDecay;
757 R__b << fEnergyCMS;
758 R__b << fKineBias;
759 R__b << fTrials;
760 fParentSelect.Streamer(R__b);
761 fChildSelect.Streamer(R__b);
762 R__b << fXsection;
763// R__b << fPythia;
764 R__b << fPtHardMin;
765 R__b << fPtHardMax;
766 // fDecayer->Streamer(R__b);
767 }
768}
a8a6107b 769#endif
18edb254 770