]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVGEN/AliGenPythia.cxx
Possibility to store and retrieve primary vertex position added.
[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$
a99cf51f 18Revision 1.38 2001/07/13 10:58:54 morsch
19- Some coded moved to AliGenMC
20- Improved handling of secondary vertices.
21
fff02fee 22Revision 1.37 2001/06/28 11:17:28 morsch
23SetEventListRange setter added. Events in specified range are listed for
24debugging. (Yuri Kharlov)
25
11dfaf8d 26Revision 1.36 2001/03/30 07:05:49 morsch
27Final print-out in finish run.
28Write parton system for jet-production (preliminary solution).
29
9be6226f 30Revision 1.35 2001/03/09 13:03:40 morsch
31Process_t and Struc_Func_t moved to AliPythia.h
32
f1a48a38 33Revision 1.34 2001/02/14 15:50:40 hristov
34The last particle in event marked using SetHighWaterMark
35
28adac24 36Revision 1.33 2001/01/30 09:23:12 hristov
37Streamers removed (R.Brun)
38
a8a6107b 39Revision 1.32 2001/01/26 19:55:51 hristov
40Major upgrade of AliRoot code
41
2ab0c725 42Revision 1.31 2001/01/17 10:54:31 hristov
43Better protection against FPE
44
0f9e52a3 45Revision 1.30 2000/12/18 08:55:35 morsch
46Make AliPythia dependent generartors work with new scheme of random number generation
47
3356c022 48Revision 1.29 2000/12/04 11:22:03 morsch
49Init of sRandom as in 1.15
50
097ec7c1 51Revision 1.28 2000/12/02 11:41:39 morsch
52Use SetRandom() to initialize random number generator in constructor.
53
1ed25e11 54Revision 1.27 2000/11/30 20:29:02 morsch
55Initialise static variable sRandom in constructor: sRandom = fRandom;
56
ad1df918 57Revision 1.26 2000/11/30 07:12:50 alibrary
58Introducing new Rndm and QA classes
59
65fb704d 60Revision 1.25 2000/10/18 19:11:27 hristov
61Division by zero fixed
62
919c2096 63Revision 1.24 2000/09/18 10:41:35 morsch
64Add possibility to use nuclear structure functions from PDF library V8.
65
811826d8 66Revision 1.23 2000/09/14 14:05:40 morsch
67dito
68
819f84ad 69Revision 1.22 2000/09/14 14:02:22 morsch
70- Correct conversion from mm to cm when passing particle vertex to MC.
71- Correct handling of fForceDecay == all.
72
4451ef92 73Revision 1.21 2000/09/12 14:14:55 morsch
74Call fDecayer->ForceDecay() at the beginning of Generate().
75
00d6ce7d 76Revision 1.20 2000/09/06 14:29:33 morsch
77Use AliPythia for event generation an AliDecayPythia for decays.
78Correct handling of "nodecay" option
79
18edb254 80Revision 1.19 2000/07/11 18:24:56 fca
81Coding convention corrections + few minor bug fixes
82
aee8290b 83Revision 1.18 2000/06/30 12:40:34 morsch
84Pythia takes care of vertex smearing. Correct conversion from Pythia units (mm) to
85Geant units (cm).
86
1512e357 87Revision 1.17 2000/06/09 20:34:07 morsch
88All coding rule violations except RS3 corrected
89
f87cfe57 90Revision 1.16 2000/05/15 15:04:20 morsch
91The full event is written for fNtrack = -1
92Coding rule violations corrected.
93
5ddeb374 94Revision 1.15 2000/04/26 10:14:24 morsch
95Particles array has one entry more than pythia particle list. Upper bound of
96particle loop changed to np-1 (R. Guernane, AM)
97
2a0e6f5b 98Revision 1.14 2000/04/05 08:36:13 morsch
99Check status code of particles in Pythia event
100to avoid double counting as partonic state and final state particle.
101
23211d3e 102Revision 1.13 1999/11/09 07:38:48 fca
103Changes for compatibility with version 2.23 of ROOT
104
084c1b4a 105Revision 1.12 1999/11/03 17:43:20 fca
106New version from G.Martinez & A.Morsch
107
886b6f73 108Revision 1.11 1999/09/29 09:24:14 fca
109Introduction of the Copyright and cvs Log
4c039060 110*/
111
fe4da5cc 112#include "AliGenPythia.h"
fff02fee 113#include "AliGenPythiaEventHeader.h"
18edb254 114#include "AliDecayerPythia.h"
fe4da5cc 115#include "AliRun.h"
116#include "AliPythia.h"
18edb254 117#include "AliPDG.h"
1578254f 118#include <TParticle.h>
18edb254 119#include <TSystem.h>
f87cfe57 120
fe4da5cc 121 ClassImp(AliGenPythia)
122
123AliGenPythia::AliGenPythia()
fff02fee 124 :AliGenMC()
fe4da5cc 125{
18edb254 126// Default Constructor
127 fDecayer = new AliDecayerPythia();
11dfaf8d 128 SetEventListRange();
fe4da5cc 129}
130
131AliGenPythia::AliGenPythia(Int_t npart)
fff02fee 132 :AliGenMC(npart)
fe4da5cc 133{
134// default charm production at 5. 5 TeV
135// semimuonic decay
136// structure function GRVHO
137//
138 fXsection = 0.;
811826d8 139 fNucA1=0;
140 fNucA2=0;
fe4da5cc 141 SetProcess();
142 SetStrucFunc();
886b6f73 143 SetForceDecay();
fe4da5cc 144 SetPtHard();
145 SetEnergyCMS();
18edb254 146 fDecayer = new AliDecayerPythia();
1ed25e11 147 // Set random number generator
097ec7c1 148 sRandom=fRandom;
11dfaf8d 149 SetEventListRange();
fff02fee 150 fFlavorSelect = 0;
151 // Produced particles
152 fParticles = new TClonesArray("TParticle",1000);
fe4da5cc 153}
154
f87cfe57 155AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
156{
157// copy constructor
158}
159
fe4da5cc 160AliGenPythia::~AliGenPythia()
161{
5ddeb374 162// Destructor
fe4da5cc 163}
164
11dfaf8d 165void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
166{
167 // Set a range of event numbers, for which a table
168 // of generated particle will be printed
169 fDebugEventFirst = eventFirst;
170 fDebugEventLast = eventLast;
171 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
172}
173
fe4da5cc 174void AliGenPythia::Init()
175{
5ddeb374 176// Initialisation
18edb254 177 SetMC(AliPythia::Instance());
fe4da5cc 178 fPythia=(AliPythia*) fgMCEvGen;
179//
180 fParentWeight=1./Float_t(fNpart);
181//
182// Forward Paramters to the AliPythia object
00d6ce7d 183 fDecayer->SetForceDecay(fForceDecay);
18edb254 184 fDecayer->Init();
00d6ce7d 185
18edb254 186
fe4da5cc 187 fPythia->SetCKIN(3,fPtHardMin);
188 fPythia->SetCKIN(4,fPtHardMax);
811826d8 189 if (fNucA1 > 0 && fNucA2 > 0) fPythia->SetNuclei(fNucA1, fNucA2);
fe4da5cc 190 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
18edb254 191
192 // fPythia->Pylist(0);
193 // fPythia->Pystat(2);
fe4da5cc 194// Parent and Children Selection
195 switch (fProcess)
196 {
f1a48a38 197 case kPyCharm:
fff02fee 198 fParentSelect[0] = 411;
199 fParentSelect[1] = 421;
200 fParentSelect[2] = 431;
201 fParentSelect[3] = 4122;
202 fFlavorSelect = 4;
fe4da5cc 203 break;
f1a48a38 204 case kPyCharmUnforced:
fff02fee 205 fParentSelect[0] = 411;
206 fParentSelect[1] = 421;
207 fParentSelect[2] = 431;
208 fParentSelect[3]= 4122;
209 fFlavorSelect = 4;
fe4da5cc 210 break;
f1a48a38 211 case kPyBeauty:
fff02fee 212 fParentSelect[0]= 511;
213 fParentSelect[1]= 521;
214 fParentSelect[2]= 531;
215 fParentSelect[3]= 5122;
216 fParentSelect[4]= 5132;
217 fParentSelect[5]= 5232;
218 fParentSelect[6]= 5332;
219 fFlavorSelect = 5;
fe4da5cc 220 break;
f1a48a38 221 case kPyBeautyUnforced:
fff02fee 222 fParentSelect[0] = 511;
223 fParentSelect[1] = 521;
224 fParentSelect[2] = 531;
225 fParentSelect[3] = 5122;
226 fParentSelect[4] = 5132;
227 fParentSelect[5] = 5232;
228 fParentSelect[6] = 5332;
229 fFlavorSelect = 5;
fe4da5cc 230 break;
f1a48a38 231 case kPyJpsiChi:
232 case kPyJpsi:
fff02fee 233 fParentSelect[0] = 443;
fe4da5cc 234 break;
f1a48a38 235 case kPyMb:
236 case kPyJets:
237 case kPyDirectGamma:
5be1fe76 238 break;
fe4da5cc 239 }
fff02fee 240 AliGenMC::Init();
fe4da5cc 241}
242
243void AliGenPythia::Generate()
244{
5ddeb374 245// Generate one event
00d6ce7d 246 fDecayer->ForceDecay();
fe4da5cc 247
9be6226f 248 Float_t polar[3] = {0,0,0};
249 Float_t origin[3] = {0,0,0};
9be6226f 250 Float_t origin0[3] = {0,0,0};
fff02fee 251 Float_t p[3];
5be1fe76 252// converts from mm/c to s
253 const Float_t kconv=0.001/2.999792458e8;
fe4da5cc 254//
fe4da5cc 255 Int_t nt=0;
256 Int_t jev=0;
7921755b 257 Int_t j, kf;
fe4da5cc 258 fTrials=0;
fff02fee 259
260// Set collision vertex position
fe4da5cc 261 for (j=0;j<3;j++) origin0[j]=fOrigin[j];
aee8290b 262 if(fVertexSmear==kPerEvent) {
1512e357 263 fPythia->SetMSTP(151,1);
fe4da5cc 264 for (j=0;j<3;j++) {
fff02fee 265 fPythia->SetPARP(151+j, fOsigma[j]*10.);
fe4da5cc 266 }
aee8290b 267 } else if (fVertexSmear==kPerTrack) {
fe4da5cc 268 fPythia->SetMSTP(151,0);
fe4da5cc 269 }
fff02fee 270// event loop
fe4da5cc 271 while(1)
272 {
084c1b4a 273 fPythia->Pyevnt();
11dfaf8d 274 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
275 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
fe4da5cc 276 fTrials++;
fff02fee 277 fPythia->ImportParticles(fParticles,"All");
278
279//
280//
281//
282 Int_t i;
283
284 Int_t np = fParticles->GetEntriesFast();
285 Int_t* pParent = new Int_t[np];
286 Int_t* pSelected = new Int_t[np];
287 Int_t* trackIt = new Int_t[np];
288 for (i=0; i< np-1; i++) {
289 pParent[i] = -1;
290 pSelected[i] = 0;
291 }
fe4da5cc 292 printf("\n **************************************************%d\n",np);
fff02fee 293 Int_t nc = 0;
fe4da5cc 294 if (np == 0 ) continue;
f1a48a38 295 if (fProcess != kPyMb && fProcess != kPyJets && fProcess != kPyDirectGamma) {
fff02fee 296 for (i = 0; i<np-1; i++) {
297 TParticle * iparticle = (TParticle *) fParticles->At(i);
23211d3e 298 Int_t ks = iparticle->GetStatusCode();
a8228d85 299 kf = CheckPDGCode(iparticle->GetPdgCode());
fff02fee 300// No initial state partons
2a0e6f5b 301 if (ks==21) continue;
fe4da5cc 302//
fff02fee 303// Heavy Flavor Selection
5be1fe76 304//
fff02fee 305 // quark ?
306 kf = TMath::Abs(kf);
307 Int_t kfl = kf;
308 // meson ?
309 if (kfl > 10) kfl/=100;
310 // baryon
311 if (kfl > 10) kfl/=10;
312 if (kfl > 10) kfl/=10;
313
314 Int_t ipa = iparticle->GetFirstMother()-1;
315 Int_t kfMo = 0;
316
317 if (ipa > -1) {
318 TParticle * mother = (TParticle *) fParticles->At(ipa);
319 kfMo = TMath::Abs(mother->GetPdgCode());
320 }
321// printf("\n particle (all) %d %d %d", i, pSelected[i], kf);
322 if (kfl >= fFlavorSelect) {
5be1fe76 323//
fff02fee 324// Heavy flavor hadron or quark
fe4da5cc 325//
fff02fee 326// Kinematic seletion on final state heavy flavor mesons
327 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
328 {
329 nc = -1;
330 break;
331 }
332 pSelected[i] = 1;
333// printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
334 } else {
335// Kinematic seletion on decay products
336 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
337 && !KinematicSelection(iparticle, 1))
338 {
339 nc = -1;
340 break;
341 }
fe4da5cc 342//
fff02fee 343// Decay products
344// Select if mother was selected and is not tracked
345
346 if (pSelected[ipa] &&
347 !trackIt[ipa] && // mother will be tracked ?
348 kfMo != 5 && // mother is b-quark, don't store fragments
349 kfMo != 4 && // mother is c-quark, don't store fragments
350 kf != 92) // don't store string
351 {
fe4da5cc 352//
fff02fee 353// Semi-stable or de-selected: diselect decay products:
fe4da5cc 354//
5be1fe76 355//
fff02fee 356 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > 10e-15)
357 {
358 Int_t ipF = iparticle->GetFirstDaughter();
359 Int_t ipL = iparticle->GetLastDaughter();
360 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
361 }
362// printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
363 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
364 }
365 }
366 if (pSelected[i] == -1) pSelected[i] = 0;
367 if (!pSelected[i]) continue;
368 nc++;
369// Decision on tracking
370 trackIt[i] = 0;
371//
372// Track final state particle
373 if (ks == 1) trackIt[i] = 1;
374// Track semi-stable particles
375 if ((ks ==1) || (fDecayer->GetLifetime(kf)> 10e-15)) trackIt[i] = 1;
376// Track particles selected by process if undecayed.
377 if (fForceDecay == kNoDecay) {
378 if (ParentSelected(kf)) trackIt[i] = 1;
379 } else {
380 if (ParentSelected(kf)) trackIt[i] = 0;
381 }
382//
383//
384
385 } // particle selection loop
386 if (nc > -1) {
387 for (i = 0; i<np-1; i++) {
388 if (!pSelected[i]) continue;
389 TParticle * iparticle = (TParticle *) fParticles->At(i);
390 kf = CheckPDGCode(iparticle->GetPdgCode());
9be6226f 391 p[0]=iparticle->Px();
392 p[1]=iparticle->Py();
393 p[2]=iparticle->Pz();
394 origin[0]=origin0[0]+iparticle->Vx()/10.;
395 origin[1]=origin0[1]+iparticle->Vy()/10.;
396 origin[2]=origin0[2]+iparticle->Vz()/10.;
397 Float_t tof=kconv*iparticle->T();
fff02fee 398 Int_t ipa = iparticle->GetFirstMother()-1;
399 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
400// printf("\n SetTrack %d %d %d %d", i, iparent, kf, trackIt[i]);
a99cf51f 401 SetTrack(fTrackIt*trackIt[i] ,
fff02fee 402 iparent, kf, p, origin, polar, tof, kPPrimary, nt, 1.);
403 pParent[i] = nt;
a99cf51f 404 KeepTrack(nt);
fff02fee 405 } // SetTrack loop
406 }
407 } else {
408 nc = GenerateMB();
5be1fe76 409 } // mb ?
fff02fee 410
fe4da5cc 411 if (nc > 0) {
5be1fe76 412 jev+=nc;
5ddeb374 413 if (jev >= fNpart || fNpart == -1) {
fe4da5cc 414 fKineBias=Float_t(fNpart)/Float_t(fTrials);
23211d3e 415 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
fe4da5cc 416 break;
417 }
418 }
419 } // event loop
a99cf51f 420 SetHighWaterMark(nt);
fe4da5cc 421// adjust weight due to kinematic selection
422 AdjustWeights();
423// get cross-section
424 fXsection=fPythia->GetPARI(1);
425}
426
fff02fee 427Int_t AliGenPythia::GenerateMB()
fe4da5cc 428{
fff02fee 429 Int_t i, kf, nt, iparent;
430 Int_t nc = 0;
431 Float_t p[3];
432 Float_t polar[3] = {0,0,0};
433 Float_t origin[3] = {0,0,0};
434 Float_t origin0[3] = {0,0,0};
435// converts from mm/c to s
436 const Float_t kconv=0.001/2.999792458e8;
4451ef92 437
fff02fee 438 Int_t np = fParticles->GetEntriesFast();
439 Int_t* pParent = new Int_t[np];
440 for (i=0; i< np-1; i++) pParent[i] = -1;
441
442 for (i = 0; i<np-1; i++) {
443 Int_t trackIt = 0;
444 TParticle * iparticle = (TParticle *) fParticles->At(i);
445 kf = CheckPDGCode(iparticle->GetPdgCode());
446 Int_t ks = iparticle->GetStatusCode();
447 Int_t km = iparticle->GetFirstMother();
448// printf("\n Particle: %d %d %d", i, kf, ks);
449
450 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
451 (ks != 1) ||
452 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
453 nc++;
454 if (ks == 1) trackIt = 1;
455 Int_t ipa = iparticle->GetFirstMother()-1;
fe4da5cc 456
fff02fee 457 iparent = (ipa > -1) ? pParent[ipa] : -1;
fe4da5cc 458
459//
fff02fee 460// store track information
461 p[0]=iparticle->Px();
462 p[1]=iparticle->Py();
463 p[2]=iparticle->Pz();
464 origin[0]=origin0[0]+iparticle->Vx()/10.;
465 origin[1]=origin0[1]+iparticle->Vy()/10.;
466 origin[2]=origin0[2]+iparticle->Vz()/10.;
467 Float_t tof=kconv*iparticle->T();
a99cf51f 468 SetTrack(fTrackIt*trackIt, iparent, kf, p, origin, polar,
fff02fee 469 tof, kPPrimary, nt);
a99cf51f 470 KeepTrack(nt);
fff02fee 471 pParent[i] = nt;
472 } // select particle
473 } // particle loop
474
475 if (pParent) delete[] pParent;
fe4da5cc 476
fff02fee 477 printf("\n I've put %i particles on the stack \n",nc);
478 MakeHeader();
479 return nc;
480}
fe4da5cc 481
fe4da5cc 482
fff02fee 483void AliGenPythia::FinishRun()
484{
485// Print x-section summary
486 fPythia->Pystat(1);
fe4da5cc 487}
fff02fee 488
fe4da5cc 489void AliGenPythia::AdjustWeights()
490{
5ddeb374 491// Adjust the weights after generation of all events
492//
5ddeb374 493 TParticle *part;
fe4da5cc 494 Int_t ntrack=gAlice->GetNtrack();
495 for (Int_t i=0; i<ntrack; i++) {
2ab0c725 496 part= gAlice->Particle(i);
5ddeb374 497 part->SetWeight(part->GetWeight()*fKineBias);
fe4da5cc 498 }
499}
811826d8 500
501void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
502{
503// Treat protons as inside nuclei with mass numbers a1 and a2
504 fNucA1 = a1;
505 fNucA2 = a2;
506}
fff02fee 507
508
509void AliGenPythia::MakeHeader()
510{
511// Builds the event header, to be called after each event
512 AliGenEventHeader* header = new AliGenPythiaEventHeader("Pythia");
513 ((AliGenPythiaEventHeader*) header)->SetProcessType(fPythia->GetMSTI(1));
514 gAlice->SetGenEventHeader(header);
515}
811826d8 516
517
f87cfe57 518AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
519{
520// Assignment operator
521 return *this;
522}
fe4da5cc 523
524
811826d8 525
a8a6107b 526#ifdef never
18edb254 527void AliGenPythia::Streamer(TBuffer &R__b)
528{
529 // Stream an object of class AliGenPythia.
530
531 if (R__b.IsReading()) {
532 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
533 AliGenerator::Streamer(R__b);
534 R__b >> (Int_t&)fProcess;
535 R__b >> (Int_t&)fStrucFunc;
536 R__b >> (Int_t&)fForceDecay;
537 R__b >> fEnergyCMS;
538 R__b >> fKineBias;
539 R__b >> fTrials;
540 fParentSelect.Streamer(R__b);
541 fChildSelect.Streamer(R__b);
542 R__b >> fXsection;
543// (AliPythia::Instance())->Streamer(R__b);
544 R__b >> fPtHardMin;
545 R__b >> fPtHardMax;
546// if (fDecayer) fDecayer->Streamer(R__b);
547 } else {
548 R__b.WriteVersion(AliGenPythia::IsA());
549 AliGenerator::Streamer(R__b);
550 R__b << (Int_t)fProcess;
551 R__b << (Int_t)fStrucFunc;
552 R__b << (Int_t)fForceDecay;
553 R__b << fEnergyCMS;
554 R__b << fKineBias;
555 R__b << fTrials;
556 fParentSelect.Streamer(R__b);
557 fChildSelect.Streamer(R__b);
558 R__b << fXsection;
559// R__b << fPythia;
560 R__b << fPtHardMin;
561 R__b << fPtHardMax;
562 // fDecayer->Streamer(R__b);
563 }
564}
a8a6107b 565#endif
18edb254 566