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