]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PYTHIA6/AliGenPythia.cxx
If present, pass header to container.
[u/mrichter/AliRoot.git] / PYTHIA6 / AliGenPythia.cxx
CommitLineData
8d2cd130 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
7cdba479 16/* $Id$ */
8d2cd130 17
18//
19// Generator using the TPythia interface (via AliPythia)
20// to generate pp collisions.
21// Using SetNuclei() also nuclear modifications to the structure functions
22// can be taken into account. This makes, of course, only sense for the
23// generation of the products of hard processes (heavy flavor, jets ...)
24//
25// andreas.morsch@cern.ch
26//
27
28#include <TDatabasePDG.h>
29#include <TParticle.h>
30#include <TPDGCode.h>
31#include <TSystem.h>
32#include <TTree.h>
8d2cd130 33#include "AliConst.h"
34#include "AliDecayerPythia.h"
35#include "AliGenPythia.h"
5fa4b20b 36#include "AliHeader.h"
8d2cd130 37#include "AliGenPythiaEventHeader.h"
38#include "AliPythia.h"
7cdba479 39#include "AliPythiaRndm.h"
8d2cd130 40#include "AliRun.h"
7ea3ea5b 41#include "AliStack.h"
42#include "AliRunLoader.h"
5d12ce38 43#include "AliMC.h"
7c21f297 44#include "pyquenCommon.h"
8d2cd130 45
014a9521 46ClassImp(AliGenPythia)
8d2cd130 47
48AliGenPythia::AliGenPythia()
49 :AliGenMC()
50{
51// Default Constructor
52 fParticles = 0;
53 fPythia = 0;
e5c87a3d 54 fHeader = 0;
5fffd0fe 55 fReadFromFile = 0;
f913ec4f 56 fEventTime = 0.;
8ec89232 57 fInteractionRate = 0.;
9d7108a7 58 fTimeWindow = 0.;
59 fEventsTime = 0;
60 fCurSubEvent = 0;
8d2cd130 61 fDecayer = new AliDecayerPythia();
62 SetEventListRange();
63 SetJetPhiRange();
64 SetJetEtaRange();
65 SetJetEtRange();
66 SetGammaPhiRange();
67 SetGammaEtaRange();
68 SetPtKick();
7ea3ea5b 69 SetQuench();
5fa4b20b 70 SetHadronisation();
1d568bc2 71 fSetNuclei = kFALSE;
7cdba479 72 if (!AliPythiaRndm::GetPythiaRandom())
73 AliPythiaRndm::SetPythiaRandom(GetRandom());
8d2cd130 74}
75
76AliGenPythia::AliGenPythia(Int_t npart)
77 :AliGenMC(npart)
78{
79// default charm production at 5. 5 TeV
80// semimuonic decay
81// structure function GRVHO
82//
83 fName = "Pythia";
84 fTitle= "Particle Generator using PYTHIA";
85 fXsection = 0.;
5fffd0fe 86 fReadFromFile = 0;
f913ec4f 87 fEventTime = 0.;
8ec89232 88 fInteractionRate = 0.;
9d7108a7 89 fTimeWindow = 0.;
90 fEventsTime = 0;
91 fCurSubEvent = 0;
8d2cd130 92 SetProcess();
93 SetStrucFunc();
94 SetForceDecay();
95 SetPtHard();
96 SetYHard();
97 SetEnergyCMS();
98 fDecayer = new AliDecayerPythia();
99 // Set random number generator
7cdba479 100 if (!AliPythiaRndm::GetPythiaRandom())
101 AliPythiaRndm::SetPythiaRandom(GetRandom());
8d2cd130 102 fFlavorSelect = 0;
103 // Produced particles
104 fParticles = new TClonesArray("TParticle",1000);
e5c87a3d 105 fHeader = 0;
8d2cd130 106 SetEventListRange();
107 SetJetPhiRange();
108 SetJetEtaRange();
109 SetJetEtRange();
110 SetGammaPhiRange();
111 SetGammaEtaRange();
112 SetJetReconstructionMode();
7ea3ea5b 113 SetQuench();
5fa4b20b 114 SetHadronisation();
8d2cd130 115 SetPtKick();
116 // Options determining what to keep in the stack (Heavy flavour generation)
117 fStackFillOpt = kFlavorSelection; // Keep particle with selected flavor
118 fFeedDownOpt = kTRUE; // allow feed down from higher family
119 // Fragmentation on/off
120 fFragmentation = kTRUE;
121 // Default counting mode
122 fCountMode = kCountAll;
592f8307 123 // Pycel
124 SetPycellParameters();
1d568bc2 125 fSetNuclei = kFALSE;
8d2cd130 126}
127
128AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
f936b8ea 129 :AliGenMC(Pythia)
8d2cd130 130{
131// copy constructor
132 Pythia.Copy(*this);
133}
134
135AliGenPythia::~AliGenPythia()
136{
137// Destructor
9d7108a7 138 if(fEventsTime) delete fEventsTime;
139}
140
141void AliGenPythia::SetInteractionRate(Float_t rate,Float_t timewindow)
142{
143// Generate pileup using user specified rate
144 fInteractionRate = rate;
145 fTimeWindow = timewindow;
146 GeneratePileup();
147}
148
149void AliGenPythia::GeneratePileup()
150{
151// Generate sub events time for pileup
152 fEventsTime = 0;
153 if(fInteractionRate == 0.) {
154 Warning("GeneratePileup","Zero interaction specified. Skipping pileup generation.\n");
155 return;
156 }
157
158 Int_t npart = NumberParticles();
159 if(npart < 0) {
160 Warning("GeneratePileup","Negative number of particles. Skipping pileup generation.\n");
161 return;
162 }
163
164 if(fEventsTime) delete fEventsTime;
165 fEventsTime = new TArrayF(npart);
166 TArrayF &array = *fEventsTime;
167 for(Int_t ipart = 0; ipart < npart; ipart++)
168 array[ipart] = 0.;
169
170 Float_t eventtime = 0.;
171 while(1)
172 {
173 eventtime += (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
174 if(eventtime > fTimeWindow) break;
175 array.Set(array.GetSize()+1);
176 array[array.GetSize()-1] = eventtime;
177 }
178
179 eventtime = 0.;
180 while(1)
181 {
182 eventtime -= (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
183 if(TMath::Abs(eventtime) > fTimeWindow) break;
184 array.Set(array.GetSize()+1);
185 array[array.GetSize()-1] = eventtime;
186 }
187
188 SetNumberParticles(fEventsTime->GetSize());
8d2cd130 189}
190
592f8307 191void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
192 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
193{
194// Set pycell parameters
195 fPycellEtaMax = etamax;
196 fPycellNEta = neta;
197 fPycellNPhi = nphi;
198 fPycellThreshold = thresh;
199 fPycellEtSeed = etseed;
200 fPycellMinEtJet = minet;
201 fPycellMaxRadius = r;
202}
203
204
205
8d2cd130 206void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
207{
208 // Set a range of event numbers, for which a table
209 // of generated particle will be printed
210 fDebugEventFirst = eventFirst;
211 fDebugEventLast = eventLast;
212 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
213}
214
215void AliGenPythia::Init()
216{
217// Initialisation
218
219 SetMC(AliPythia::Instance());
b88f5cea 220 fPythia=(AliPythia*) fMCEvGen;
e2bddf81 221
8d2cd130 222//
223 fParentWeight=1./Float_t(fNpart);
224//
225// Forward Paramters to the AliPythia object
226 fDecayer->SetForceDecay(fForceDecay);
227 fDecayer->Init();
228
229
230 fPythia->SetCKIN(3,fPtHardMin);
231 fPythia->SetCKIN(4,fPtHardMax);
232 fPythia->SetCKIN(7,fYHardMin);
233 fPythia->SetCKIN(8,fYHardMax);
234
1a626d4e 235 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget);
8d2cd130 236 // Fragmentation?
237 if (fFragmentation) {
238 fPythia->SetMSTP(111,1);
239 } else {
240 fPythia->SetMSTP(111,0);
241 }
242
243
244// initial state radiation
245 fPythia->SetMSTP(61,fGinit);
246// final state radiation
247 fPythia->SetMSTP(71,fGfinal);
248// pt - kick
249 if (fPtKick > 0.) {
250 fPythia->SetMSTP(91,1);
251 fPythia->SetPARP(91,fPtKick);
252 } else {
253 fPythia->SetMSTP(91,0);
254 }
255
5fa4b20b 256
257 if (fReadFromFile) {
258 fRL = AliRunLoader::Open(fFileName, "Partons");
259 fRL->LoadKinematics();
260 fRL->LoadHeader();
261 } else {
262 fRL = 0x0;
263 }
264
265
8d2cd130 266 //
267 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
268
269// Parent and Children Selection
270 switch (fProcess)
271 {
272 case kPyCharm:
273 case kPyCharmUnforced:
adf4d898 274 case kPyCharmPbPbMNR:
aabc7187 275 case kPyCharmppMNR:
276 case kPyCharmpPbMNR:
8d2cd130 277 fParentSelect[0] = 411;
278 fParentSelect[1] = 421;
279 fParentSelect[2] = 431;
280 fParentSelect[3] = 4122;
281 fFlavorSelect = 4;
282 break;
adf4d898 283 case kPyD0PbPbMNR:
284 case kPyD0pPbMNR:
285 case kPyD0ppMNR:
8d2cd130 286 fParentSelect[0] = 421;
287 fFlavorSelect = 4;
288 break;
90d7b703 289 case kPyDPlusPbPbMNR:
290 case kPyDPluspPbMNR:
291 case kPyDPlusppMNR:
292 fParentSelect[0] = 411;
293 fFlavorSelect = 4;
294 break;
8d2cd130 295 case kPyBeauty:
adf4d898 296 case kPyBeautyPbPbMNR:
297 case kPyBeautypPbMNR:
298 case kPyBeautyppMNR:
8d2cd130 299 fParentSelect[0]= 511;
300 fParentSelect[1]= 521;
301 fParentSelect[2]= 531;
302 fParentSelect[3]= 5122;
303 fParentSelect[4]= 5132;
304 fParentSelect[5]= 5232;
305 fParentSelect[6]= 5332;
306 fFlavorSelect = 5;
307 break;
308 case kPyBeautyUnforced:
309 fParentSelect[0] = 511;
310 fParentSelect[1] = 521;
311 fParentSelect[2] = 531;
312 fParentSelect[3] = 5122;
313 fParentSelect[4] = 5132;
314 fParentSelect[5] = 5232;
315 fParentSelect[6] = 5332;
316 fFlavorSelect = 5;
317 break;
318 case kPyJpsiChi:
319 case kPyJpsi:
320 fParentSelect[0] = 443;
321 break;
322 case kPyMb:
323 case kPyMbNonDiffr:
324 case kPyJets:
325 case kPyDirectGamma:
326 break;
589380c6 327 case kPyW:
328 break;
8d2cd130 329 }
330//
592f8307 331//
332// JetFinder for Trigger
333//
334// Configure detector (EMCAL like)
335//
336 fPythia->SetPARU(51, fPycellEtaMax);
337 fPythia->SetMSTU(51, fPycellNEta);
338 fPythia->SetMSTU(52, fPycellNPhi);
339//
340// Configure Jet Finder
341//
342 fPythia->SetPARU(58, fPycellThreshold);
343 fPythia->SetPARU(52, fPycellEtSeed);
344 fPythia->SetPARU(53, fPycellMinEtJet);
345 fPythia->SetPARU(54, fPycellMaxRadius);
346 fPythia->SetMSTU(54, 2);
347//
8d2cd130 348// This counts the total number of calls to Pyevnt() per run.
349 fTrialsRun = 0;
350 fQ = 0.;
351 fX1 = 0.;
352 fX2 = 0.;
353 fNev = 0 ;
354//
1d568bc2 355//
356//
8d2cd130 357 AliGenMC::Init();
1d568bc2 358//
359//
360//
361 if (fSetNuclei) {
362 fDyBoost = 0;
363 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
364 }
32d6ef7d 365
366 if (fQuench) {
5fa4b20b 367 fPythia->InitQuenching(0., 0.1, 0.6e6, 0);
32d6ef7d 368 }
369
8d2cd130 370}
371
372void AliGenPythia::Generate()
373{
374// Generate one event
e5c87a3d 375
8d2cd130 376 fDecayer->ForceDecay();
377
378 Float_t polar[3] = {0,0,0};
379 Float_t origin[3] = {0,0,0};
a920faf9 380 Float_t p[4];
8d2cd130 381// converts from mm/c to s
382 const Float_t kconv=0.001/2.999792458e8;
383//
384 Int_t nt=0;
385 Int_t jev=0;
386 Int_t j, kf;
387 fTrials=0;
f913ec4f 388 fEventTime = 0.;
389
2590ccf9 390
8d2cd130 391
392 // Set collision vertex position
2590ccf9 393 if (fVertexSmear == kPerEvent) Vertex();
394
8d2cd130 395// event loop
396 while(1)
397 {
32d6ef7d 398//
5fa4b20b 399// Produce event
32d6ef7d 400//
32d6ef7d 401//
5fa4b20b 402// Switch hadronisation off
403//
404 fPythia->SetMSTJ(1, 0);
32d6ef7d 405//
5fa4b20b 406// Either produce new event or read partons from file
407//
408 if (!fReadFromFile) {
409 fPythia->Pyevnt();
410 fNpartons = fPythia->GetN();
411 } else {
412 printf("Loading Event %d\n",AliRunLoader::GetRunLoader()->GetEventNumber());
413 fRL->GetEvent(AliRunLoader::GetRunLoader()->GetEventNumber());
414 fPythia->SetN(0);
415 LoadEvent(fRL->Stack(), 0 , 1);
416 fPythia->Pyedit(21);
417 }
418
32d6ef7d 419//
420// Run quenching routine
421//
5fa4b20b 422 if (fQuench == 1) {
423 fPythia->Quench();
424 } else if (fQuench == 2){
425 fPythia->Pyquen(208., 0, 0.);
426 }
32d6ef7d 427//
5fa4b20b 428// Switch hadronisation on
32d6ef7d 429//
5fa4b20b 430 fPythia->SetMSTJ(1, 1);
431//
432// .. and perform hadronisation
433// printf("Calling hadronisation %d\n", fPythia->GetN());
434 fPythia->Pyexec();
8d2cd130 435 fTrials++;
8d2cd130 436 fPythia->ImportParticles(fParticles,"All");
1d568bc2 437 Boost();
8d2cd130 438//
439//
440//
441 Int_t i;
442
5fa4b20b 443
8d2cd130 444 Int_t np = fParticles->GetEntriesFast();
5fa4b20b 445
7c21f297 446 if (np == 0) continue;
8d2cd130 447//
2590ccf9 448
8d2cd130 449//
450 Int_t* pParent = new Int_t[np];
451 Int_t* pSelected = new Int_t[np];
452 Int_t* trackIt = new Int_t[np];
5fa4b20b 453 for (i = 0; i < np; i++) {
8d2cd130 454 pParent[i] = -1;
455 pSelected[i] = 0;
456 trackIt[i] = 0;
457 }
458
459 Int_t nc = 0; // Total n. of selected particles
460 Int_t nParents = 0; // Selected parents
461 Int_t nTkbles = 0; // Trackable particles
462 if (fProcess != kPyMb && fProcess != kPyJets &&
463 fProcess != kPyDirectGamma &&
589380c6 464 fProcess != kPyMbNonDiffr &&
465 fProcess != kPyW) {
8d2cd130 466
5fa4b20b 467 for (i = 0; i < np; i++) {
2590ccf9 468 TParticle* iparticle = (TParticle *) fParticles->At(i);
8d2cd130 469 Int_t ks = iparticle->GetStatusCode();
470 kf = CheckPDGCode(iparticle->GetPdgCode());
471// No initial state partons
472 if (ks==21) continue;
473//
474// Heavy Flavor Selection
475//
476 // quark ?
477 kf = TMath::Abs(kf);
478 Int_t kfl = kf;
9ff6c04c 479 // Resonance
f913ec4f 480
9ff6c04c 481 if (kfl > 100000) kfl %= 100000;
183a5ca9 482 if (kfl > 10000) kfl %= 10000;
8d2cd130 483 // meson ?
484 if (kfl > 10) kfl/=100;
485 // baryon
486 if (kfl > 10) kfl/=10;
8d2cd130 487 Int_t ipa = iparticle->GetFirstMother()-1;
488 Int_t kfMo = 0;
f913ec4f 489//
490// Establish mother daughter relation between heavy quarks and mesons
491//
492 if (kf >= fFlavorSelect && kf <= 6) {
493 Int_t idau = iparticle->GetFirstDaughter() - 1;
494 if (idau > -1) {
495 TParticle* daughter = (TParticle *) fParticles->At(idau);
496 Int_t pdgD = daughter->GetPdgCode();
497 if (pdgD == 91 || pdgD == 92) {
498 Int_t jmin = daughter->GetFirstDaughter() - 1;
499 Int_t jmax = daughter->GetLastDaughter() - 1;
500 for (Int_t j = jmin; j <= jmax; j++)
501 ((TParticle *) fParticles->At(j))->SetFirstMother(i+1);
502 } // is string or cluster
503 } // has daughter
504 } // heavy quark
8d2cd130 505
f913ec4f 506
8d2cd130 507 if (ipa > -1) {
508 TParticle * mother = (TParticle *) fParticles->At(ipa);
509 kfMo = TMath::Abs(mother->GetPdgCode());
510 }
f913ec4f 511
8d2cd130 512 // What to keep in Stack?
513 Bool_t flavorOK = kFALSE;
514 Bool_t selectOK = kFALSE;
515 if (fFeedDownOpt) {
32d6ef7d 516 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
8d2cd130 517 } else {
32d6ef7d 518 if (kfl > fFlavorSelect) {
519 nc = -1;
520 break;
521 }
522 if (kfl == fFlavorSelect) flavorOK = kTRUE;
8d2cd130 523 }
524 switch (fStackFillOpt) {
525 case kFlavorSelection:
32d6ef7d 526 selectOK = kTRUE;
527 break;
8d2cd130 528 case kParentSelection:
32d6ef7d 529 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
530 break;
8d2cd130 531 }
532 if (flavorOK && selectOK) {
533//
534// Heavy flavor hadron or quark
535//
536// Kinematic seletion on final state heavy flavor mesons
537 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
538 {
9ff6c04c 539 continue;
8d2cd130 540 }
541 pSelected[i] = 1;
542 if (ParentSelected(kf)) ++nParents; // Update parent count
543// printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
544 } else {
545// Kinematic seletion on decay products
546 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
9ff6c04c 547 && !KinematicSelection(iparticle, 1))
8d2cd130 548 {
9ff6c04c 549 continue;
8d2cd130 550 }
551//
552// Decay products
553// Select if mother was selected and is not tracked
554
555 if (pSelected[ipa] &&
556 !trackIt[ipa] && // mother will be tracked ?
557 kfMo != 5 && // mother is b-quark, don't store fragments
558 kfMo != 4 && // mother is c-quark, don't store fragments
559 kf != 92) // don't store string
560 {
561//
562// Semi-stable or de-selected: diselect decay products:
563//
564//
565 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
566 {
567 Int_t ipF = iparticle->GetFirstDaughter();
568 Int_t ipL = iparticle->GetLastDaughter();
569 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
570 }
571// printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
572 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
573 }
574 }
575 if (pSelected[i] == -1) pSelected[i] = 0;
576 if (!pSelected[i]) continue;
577 // Count quarks only if you did not include fragmentation
578 if (fFragmentation && kf <= 10) continue;
9ff6c04c 579
8d2cd130 580 nc++;
581// Decision on tracking
582 trackIt[i] = 0;
583//
584// Track final state particle
585 if (ks == 1) trackIt[i] = 1;
586// Track semi-stable particles
d25cfd65 587 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
8d2cd130 588// Track particles selected by process if undecayed.
589 if (fForceDecay == kNoDecay) {
590 if (ParentSelected(kf)) trackIt[i] = 1;
591 } else {
592 if (ParentSelected(kf)) trackIt[i] = 0;
593 }
594 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
595//
596//
597
598 } // particle selection loop
599 if (nc > 0) {
600 for (i = 0; i<np; i++) {
601 if (!pSelected[i]) continue;
602 TParticle * iparticle = (TParticle *) fParticles->At(i);
603 kf = CheckPDGCode(iparticle->GetPdgCode());
604 Int_t ks = iparticle->GetStatusCode();
605 p[0] = iparticle->Px();
606 p[1] = iparticle->Py();
607 p[2] = iparticle->Pz();
a920faf9 608 p[3] = iparticle->Energy();
609
2590ccf9 610 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
611 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
612 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
613
8d2cd130 614 Float_t tof = kconv*iparticle->T();
615 Int_t ipa = iparticle->GetFirstMother()-1;
616 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
a920faf9 617
618 PushTrack(fTrackIt*trackIt[i], iparent, kf,
619 p[0], p[1], p[2], p[3],
620 origin[0], origin[1], origin[2], tof,
621 polar[0], polar[1], polar[2],
622 kPPrimary, nt, 1., ks);
8d2cd130 623 pParent[i] = nt;
624 KeepTrack(nt);
642f15cf 625 } // PushTrack loop
8d2cd130 626 }
627 } else {
628 nc = GenerateMB();
629 } // mb ?
f913ec4f 630
631 GetSubEventTime();
8d2cd130 632
633 if (pParent) delete[] pParent;
634 if (pSelected) delete[] pSelected;
635 if (trackIt) delete[] trackIt;
636
637 if (nc > 0) {
638 switch (fCountMode) {
639 case kCountAll:
640 // printf(" Count all \n");
641 jev += nc;
642 break;
643 case kCountParents:
644 // printf(" Count parents \n");
645 jev += nParents;
646 break;
647 case kCountTrackables:
648 // printf(" Count trackable \n");
649 jev += nTkbles;
650 break;
651 }
652 if (jev >= fNpart || fNpart == -1) {
653 fKineBias=Float_t(fNpart)/Float_t(fTrials);
654 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
655
656 fQ += fPythia->GetVINT(51);
657 fX1 += fPythia->GetVINT(41);
658 fX2 += fPythia->GetVINT(42);
659 fTrialsRun += fTrials;
660 fNev++;
661 MakeHeader();
662 break;
663 }
664 }
665 } // event loop
666 SetHighWaterMark(nt);
667// adjust weight due to kinematic selection
b88f5cea 668// AdjustWeights();
8d2cd130 669// get cross-section
670 fXsection=fPythia->GetPARI(1);
671}
672
673Int_t AliGenPythia::GenerateMB()
674{
675//
676// Min Bias selection and other global selections
677//
678 Int_t i, kf, nt, iparent;
679 Int_t nc = 0;
bf950da8 680 Float_t p[4];
8d2cd130 681 Float_t polar[3] = {0,0,0};
682 Float_t origin[3] = {0,0,0};
683// converts from mm/c to s
684 const Float_t kconv=0.001/2.999792458e8;
685
5fa4b20b 686
687
688 Int_t np = (fHadronisation) ? fParticles->GetEntriesFast() : fNpartons;
689
690
8d2cd130 691 Int_t* pParent = new Int_t[np];
692 for (i=0; i< np; i++) pParent[i] = -1;
693 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
694 TParticle* jet1 = (TParticle *) fParticles->At(6);
695 TParticle* jet2 = (TParticle *) fParticles->At(7);
696 if (!CheckTrigger(jet1, jet2)) return 0;
697 }
698
f913ec4f 699 for (i = 0; i < np; i++) {
8d2cd130 700 Int_t trackIt = 0;
701 TParticle * iparticle = (TParticle *) fParticles->At(i);
702 kf = CheckPDGCode(iparticle->GetPdgCode());
703 Int_t ks = iparticle->GetStatusCode();
704 Int_t km = iparticle->GetFirstMother();
705 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
706 (ks != 1) ||
707 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
708 nc++;
709 if (ks == 1) trackIt = 1;
710 Int_t ipa = iparticle->GetFirstMother()-1;
711
712 iparent = (ipa > -1) ? pParent[ipa] : -1;
713
714//
715// store track information
716 p[0] = iparticle->Px();
717 p[1] = iparticle->Py();
718 p[2] = iparticle->Pz();
a920faf9 719 p[3] = iparticle->Energy();
1406f599 720
a920faf9 721
2590ccf9 722 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
723 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
724 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
725
f913ec4f 726 Float_t tof = fEventTime + kconv * iparticle->T();
a920faf9 727
728 PushTrack(fTrackIt*trackIt, iparent, kf,
729 p[0], p[1], p[2], p[3],
730 origin[0], origin[1], origin[2], tof,
731 polar[0], polar[1], polar[2],
732 kPPrimary, nt, 1., ks);
5fa4b20b 733 //
734 // Special Treatment to store color-flow
735 //
736 if (ks == 3 || ks == 13 || ks == 14) {
737 TParticle* particle = 0;
738 if (fStack) {
739 particle = fStack->Particle(nt);
740 } else {
741 particle = gAlice->Stack()->Particle(nt);
742 }
743 particle->SetFirstDaughter(fPythia->GetK(2, i));
744 particle->SetLastDaughter(fPythia->GetK(3, i));
745 }
746
8d2cd130 747 KeepTrack(nt);
748 pParent[i] = nt;
f913ec4f 749 SetHighWaterMark(nt);
750
8d2cd130 751 } // select particle
752 } // particle loop
753
754 if (pParent) delete[] pParent;
755
756 printf("\n I've put %i particles on the stack \n",nc);
f913ec4f 757 return 1;
8d2cd130 758}
759
760
761void AliGenPythia::FinishRun()
762{
763// Print x-section summary
764 fPythia->Pystat(1);
2779fc64 765
766 if (fNev > 0.) {
767 fQ /= fNev;
768 fX1 /= fNev;
769 fX2 /= fNev;
770 }
771
8d2cd130 772 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
773 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
8d2cd130 774}
775
776void AliGenPythia::AdjustWeights()
777{
778// Adjust the weights after generation of all events
779//
e2bddf81 780 if (gAlice) {
781 TParticle *part;
782 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
783 for (Int_t i=0; i<ntrack; i++) {
784 part= gAlice->GetMCApp()->Particle(i);
785 part->SetWeight(part->GetWeight()*fKineBias);
786 }
8d2cd130 787 }
788}
789
790void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
791{
792// Treat protons as inside nuclei with mass numbers a1 and a2
1d568bc2 793
1a626d4e 794 fAProjectile = a1;
795 fATarget = a2;
1d568bc2 796 fSetNuclei = kTRUE;
8d2cd130 797}
798
799
800void AliGenPythia::MakeHeader()
801{
183a5ca9 802 if (gAlice) {
803 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
f913ec4f 804 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(2);
183a5ca9 805 }
806
8d2cd130 807// Builds the event header, to be called after each event
e5c87a3d 808 if (fHeader) delete fHeader;
809 fHeader = new AliGenPythiaEventHeader("Pythia");
8d2cd130 810//
811// Event type
e5c87a3d 812 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
8d2cd130 813//
814// Number of trials
e5c87a3d 815 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
8d2cd130 816//
817// Event Vertex
d25cfd65 818 fHeader->SetPrimaryVertex(fVertex);
8d2cd130 819//
820// Jets that have triggered
f913ec4f 821
8d2cd130 822 if (fProcess == kPyJets)
823 {
824 Int_t ntrig, njet;
825 Float_t jets[4][10];
826 GetJets(njet, ntrig, jets);
9ff6c04c 827
8d2cd130 828
829 for (Int_t i = 0; i < ntrig; i++) {
e5c87a3d 830 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
8d2cd130 831 jets[3][i]);
832 }
833 }
5fa4b20b 834//
835// Copy relevant information from external header, if present.
836//
837 Float_t uqJet[4];
838
839 if (fRL) {
840 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
841 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
842 {
843 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
844
845
846 exHeader->TriggerJet(i, uqJet);
847 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
848 }
849 }
850//
851// Store quenching parameters
852//
853 if (fQuench){
854 Double_t z[4];
855 Double_t xp, yp;
7c21f297 856 if (fQuench == 1) {
857 // Pythia::Quench()
858 fPythia->GetQuenchingParameters(xp, yp, z);
859 } else {
860 // Pyquen
861 Double_t r1 = PARIMP.rb1;
862 Double_t r2 = PARIMP.rb2;
863 Double_t b = PARIMP.b1;
864 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
865 Double_t phi = PARIMP.psib1;
866 xp = r * TMath::Cos(phi);
867 yp = r * TMath::Sin(phi);
868
869 }
870 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
871 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
872 }
5fa4b20b 873
874//
cf57b268 875// Pass header
5fa4b20b 876//
cf57b268 877 AddHeader(fHeader);
8d2cd130 878}
cf57b268 879
880void AliGenPythia::AddHeader(AliGenEventHeader* header)
881{
882 // Add header to container or runloader
883 if (fContainer) {
884 fContainer->AddHeader(header);
885 } else {
886 AliRunLoader::GetRunLoader()->GetHeader()->SetGenEventHeader(header);
887 }
888}
889
8d2cd130 890
891Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
892{
893// Check the kinematic trigger condition
894//
895 Double_t eta[2];
896 eta[0] = jet1->Eta();
897 eta[1] = jet2->Eta();
898 Double_t phi[2];
899 phi[0] = jet1->Phi();
900 phi[1] = jet2->Phi();
901 Int_t pdg[2];
902 pdg[0] = jet1->GetPdgCode();
903 pdg[1] = jet2->GetPdgCode();
904 Bool_t triggered = kFALSE;
905
906 if (fProcess == kPyJets) {
907 Int_t njets = 0;
908 Int_t ntrig = 0;
909 Float_t jets[4][10];
910//
911// Use Pythia clustering on parton level to determine jet axis
912//
913 GetJets(njets, ntrig, jets);
914
915 if (ntrig) triggered = kTRUE;
916//
917 } else {
918 Int_t ij = 0;
919 Int_t ig = 1;
920 if (pdg[0] == kGamma) {
921 ij = 1;
922 ig = 0;
923 }
924 //Check eta range first...
925 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
926 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
927 {
928 //Eta is okay, now check phi range
929 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
930 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
931 {
932 triggered = kTRUE;
933 }
934 }
935 }
936 return triggered;
937}
938
939AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
940{
941// Assignment operator
014a9521 942 rhs.Copy(*this);
8d2cd130 943 return *this;
944}
945
5fa4b20b 946void AliGenPythia::LoadEvent(AliStack* stack, Int_t flag, Int_t reHadr)
8d2cd130 947{
948//
949// Load event into Pythia Common Block
950//
5fa4b20b 951
32d6ef7d 952 Int_t npart = stack -> GetNprimary();
953 Int_t n0 = 0;
954
955 if (!flag) {
956 (fPythia->GetPyjets())->N = npart;
957 } else {
958 n0 = (fPythia->GetPyjets())->N;
959 (fPythia->GetPyjets())->N = n0 + npart;
960 }
961
962
8d2cd130 963 for (Int_t part = 0; part < npart; part++) {
32d6ef7d 964 TParticle *MPart = stack->Particle(part);
965
5fa4b20b 966 Int_t kf = MPart->GetPdgCode();
967 Int_t ks = MPart->GetStatusCode();
968 Int_t idf = MPart->GetFirstDaughter();
969 Int_t idl = MPart->GetLastDaughter();
970
971 if (reHadr) {
972 if (ks == 11 || ks == 12) {
973 ks -= 10;
974 idf = -1;
975 idl = -1;
976 }
977 }
32d6ef7d 978
8d2cd130 979 Float_t px = MPart->Px();
980 Float_t py = MPart->Py();
981 Float_t pz = MPart->Pz();
982 Float_t e = MPart->Energy();
a920faf9 983 Float_t m = MPart->GetCalcMass();
8d2cd130 984
985
32d6ef7d 986 (fPythia->GetPyjets())->P[0][part+n0] = px;
987 (fPythia->GetPyjets())->P[1][part+n0] = py;
988 (fPythia->GetPyjets())->P[2][part+n0] = pz;
989 (fPythia->GetPyjets())->P[3][part+n0] = e;
990 (fPythia->GetPyjets())->P[4][part+n0] = m;
8d2cd130 991
32d6ef7d 992 (fPythia->GetPyjets())->K[1][part+n0] = kf;
993 (fPythia->GetPyjets())->K[0][part+n0] = ks;
5fa4b20b 994 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
995 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
996 (fPythia->GetPyjets())->K[2][part+n0] = MPart->GetFirstMother() + 1;
8d2cd130 997 }
998}
999
5fa4b20b 1000
014a9521 1001void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
8d2cd130 1002{
1003//
1004// Calls the Pythia jet finding algorithm to find jets in the current event
1005//
1006//
8d2cd130 1007//
1008// Save jets
1009 Int_t n = fPythia->GetN();
1010
1011//
1012// Run Jet Finder
1013 fPythia->Pycell(njets);
1014 Int_t i;
1015 for (i = 0; i < njets; i++) {
1016 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1017 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1018 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1019 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1020
1021 jets[0][i] = px;
1022 jets[1][i] = py;
1023 jets[2][i] = pz;
1024 jets[3][i] = e;
1025 }
1026}
1027
1028
1029
1030void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1031{
1032//
1033// Calls the Pythia clustering algorithm to find jets in the current event
1034//
1035 Int_t n = fPythia->GetN();
1036 nJets = 0;
1037 nJetsTrig = 0;
1038 if (fJetReconstruction == kCluster) {
1039//
1040// Configure cluster algorithm
1041//
1042 fPythia->SetPARU(43, 2.);
1043 fPythia->SetMSTU(41, 1);
1044//
1045// Call cluster algorithm
1046//
1047 fPythia->Pyclus(nJets);
1048//
1049// Loading jets from common block
1050//
1051 } else {
592f8307 1052
8d2cd130 1053//
1054// Run Jet Finder
1055 fPythia->Pycell(nJets);
1056 }
1057
1058 Int_t i;
1059 for (i = 0; i < nJets; i++) {
1060 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1061 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1062 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1063 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1064 Float_t pt = TMath::Sqrt(px * px + py * py);
a920faf9 1065 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
8d2cd130 1066 Float_t theta = TMath::ATan2(pt,pz);
1067 Float_t et = e * TMath::Sin(theta);
1068 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
8d2cd130 1069 if (
1070 eta > fEtaMinJet && eta < fEtaMaxJet &&
675eb105 1071 phi > fPhiMinJet && phi < fPhiMaxJet &&
8d2cd130 1072 et > fEtMinJet && et < fEtMaxJet
1073 )
1074 {
1075 jets[0][nJetsTrig] = px;
1076 jets[1][nJetsTrig] = py;
1077 jets[2][nJetsTrig] = pz;
1078 jets[3][nJetsTrig] = e;
1079 nJetsTrig++;
5fa4b20b 1080// printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
8d2cd130 1081 } else {
1082// printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1083 }
1084 }
1085}
1086
f913ec4f 1087void AliGenPythia::GetSubEventTime()
1088{
1089 // Calculates time of the next subevent
9d7108a7 1090 fEventTime = 0.;
1091 if (fEventsTime) {
1092 TArrayF &array = *fEventsTime;
1093 fEventTime = array[fCurSubEvent++];
1094 }
1095 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1096 return;
f913ec4f 1097}
8d2cd130 1098
1099#ifdef never
1100void AliGenPythia::Streamer(TBuffer &R__b)
1101{
1102 // Stream an object of class AliGenPythia.
1103
1104 if (R__b.IsReading()) {
1105 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1106 AliGenerator::Streamer(R__b);
1107 R__b >> (Int_t&)fProcess;
1108 R__b >> (Int_t&)fStrucFunc;
1109 R__b >> (Int_t&)fForceDecay;
1110 R__b >> fEnergyCMS;
1111 R__b >> fKineBias;
1112 R__b >> fTrials;
1113 fParentSelect.Streamer(R__b);
1114 fChildSelect.Streamer(R__b);
1115 R__b >> fXsection;
1116// (AliPythia::Instance())->Streamer(R__b);
1117 R__b >> fPtHardMin;
1118 R__b >> fPtHardMax;
1119// if (fDecayer) fDecayer->Streamer(R__b);
1120 } else {
1121 R__b.WriteVersion(AliGenPythia::IsA());
1122 AliGenerator::Streamer(R__b);
1123 R__b << (Int_t)fProcess;
1124 R__b << (Int_t)fStrucFunc;
1125 R__b << (Int_t)fForceDecay;
1126 R__b << fEnergyCMS;
1127 R__b << fKineBias;
1128 R__b << fTrials;
1129 fParentSelect.Streamer(R__b);
1130 fChildSelect.Streamer(R__b);
1131 R__b << fXsection;
1132// R__b << fPythia;
1133 R__b << fPtHardMin;
1134 R__b << fPtHardMax;
1135 // fDecayer->Streamer(R__b);
1136 }
1137}
1138#endif
1139
90d7b703 1140
589380c6 1141