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