Store and communicate event specific quenching parameters.
[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>
33
34#include "AliConst.h"
35#include "AliDecayerPythia.h"
36#include "AliGenPythia.h"
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"
8d2cd130 44
014a9521 45ClassImp(AliGenPythia)
8d2cd130 46
47AliGenPythia::AliGenPythia()
48 :AliGenMC()
49{
50// Default Constructor
51 fParticles = 0;
52 fPythia = 0;
e5c87a3d 53 fHeader = 0;
8d2cd130 54 fDecayer = new AliDecayerPythia();
55 SetEventListRange();
56 SetJetPhiRange();
57 SetJetEtaRange();
58 SetJetEtRange();
59 SetGammaPhiRange();
60 SetGammaEtaRange();
61 SetPtKick();
7ea3ea5b 62 SetQuench();
63
1d568bc2 64 fSetNuclei = kFALSE;
7cdba479 65 if (!AliPythiaRndm::GetPythiaRandom())
66 AliPythiaRndm::SetPythiaRandom(GetRandom());
8d2cd130 67}
68
69AliGenPythia::AliGenPythia(Int_t npart)
70 :AliGenMC(npart)
71{
72// default charm production at 5. 5 TeV
73// semimuonic decay
74// structure function GRVHO
75//
76 fName = "Pythia";
77 fTitle= "Particle Generator using PYTHIA";
78 fXsection = 0.;
8d2cd130 79 SetProcess();
80 SetStrucFunc();
81 SetForceDecay();
82 SetPtHard();
83 SetYHard();
84 SetEnergyCMS();
85 fDecayer = new AliDecayerPythia();
86 // Set random number generator
7cdba479 87 if (!AliPythiaRndm::GetPythiaRandom())
88 AliPythiaRndm::SetPythiaRandom(GetRandom());
8d2cd130 89 fFlavorSelect = 0;
90 // Produced particles
91 fParticles = new TClonesArray("TParticle",1000);
e5c87a3d 92 fHeader = 0;
8d2cd130 93 SetEventListRange();
94 SetJetPhiRange();
95 SetJetEtaRange();
96 SetJetEtRange();
97 SetGammaPhiRange();
98 SetGammaEtaRange();
99 SetJetReconstructionMode();
7ea3ea5b 100 SetQuench();
8d2cd130 101 SetPtKick();
102 // Options determining what to keep in the stack (Heavy flavour generation)
103 fStackFillOpt = kFlavorSelection; // Keep particle with selected flavor
104 fFeedDownOpt = kTRUE; // allow feed down from higher family
105 // Fragmentation on/off
106 fFragmentation = kTRUE;
107 // Default counting mode
108 fCountMode = kCountAll;
592f8307 109 // Pycel
110 SetPycellParameters();
1d568bc2 111 fSetNuclei = kFALSE;
8d2cd130 112}
113
114AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
f936b8ea 115 :AliGenMC(Pythia)
8d2cd130 116{
117// copy constructor
118 Pythia.Copy(*this);
119}
120
121AliGenPythia::~AliGenPythia()
122{
123// Destructor
124}
125
592f8307 126void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
127 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
128{
129// Set pycell parameters
130 fPycellEtaMax = etamax;
131 fPycellNEta = neta;
132 fPycellNPhi = nphi;
133 fPycellThreshold = thresh;
134 fPycellEtSeed = etseed;
135 fPycellMinEtJet = minet;
136 fPycellMaxRadius = r;
137}
138
139
140
8d2cd130 141void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
142{
143 // Set a range of event numbers, for which a table
144 // of generated particle will be printed
145 fDebugEventFirst = eventFirst;
146 fDebugEventLast = eventLast;
147 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
148}
149
150void AliGenPythia::Init()
151{
152// Initialisation
153
154 SetMC(AliPythia::Instance());
b88f5cea 155 fPythia=(AliPythia*) fMCEvGen;
e2bddf81 156
8d2cd130 157//
158 fParentWeight=1./Float_t(fNpart);
159//
160// Forward Paramters to the AliPythia object
161 fDecayer->SetForceDecay(fForceDecay);
162 fDecayer->Init();
163
164
165 fPythia->SetCKIN(3,fPtHardMin);
166 fPythia->SetCKIN(4,fPtHardMax);
167 fPythia->SetCKIN(7,fYHardMin);
168 fPythia->SetCKIN(8,fYHardMax);
169
1a626d4e 170 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget);
8d2cd130 171 // Fragmentation?
172 if (fFragmentation) {
173 fPythia->SetMSTP(111,1);
174 } else {
175 fPythia->SetMSTP(111,0);
176 }
177
178
179// initial state radiation
180 fPythia->SetMSTP(61,fGinit);
181// final state radiation
182 fPythia->SetMSTP(71,fGfinal);
183// pt - kick
184 if (fPtKick > 0.) {
185 fPythia->SetMSTP(91,1);
186 fPythia->SetPARP(91,fPtKick);
187 } else {
188 fPythia->SetMSTP(91,0);
189 }
190
191 // fPythia->SetMSTJ(1,2);
192 //
193 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
194
195// Parent and Children Selection
196 switch (fProcess)
197 {
198 case kPyCharm:
199 case kPyCharmUnforced:
adf4d898 200 case kPyCharmPbPbMNR:
aabc7187 201 case kPyCharmppMNR:
202 case kPyCharmpPbMNR:
8d2cd130 203 fParentSelect[0] = 411;
204 fParentSelect[1] = 421;
205 fParentSelect[2] = 431;
206 fParentSelect[3] = 4122;
207 fFlavorSelect = 4;
208 break;
adf4d898 209 case kPyD0PbPbMNR:
210 case kPyD0pPbMNR:
211 case kPyD0ppMNR:
8d2cd130 212 fParentSelect[0] = 421;
213 fFlavorSelect = 4;
214 break;
90d7b703 215 case kPyDPlusPbPbMNR:
216 case kPyDPluspPbMNR:
217 case kPyDPlusppMNR:
218 fParentSelect[0] = 411;
219 fFlavorSelect = 4;
220 break;
8d2cd130 221 case kPyBeauty:
adf4d898 222 case kPyBeautyPbPbMNR:
223 case kPyBeautypPbMNR:
224 case kPyBeautyppMNR:
8d2cd130 225 fParentSelect[0]= 511;
226 fParentSelect[1]= 521;
227 fParentSelect[2]= 531;
228 fParentSelect[3]= 5122;
229 fParentSelect[4]= 5132;
230 fParentSelect[5]= 5232;
231 fParentSelect[6]= 5332;
232 fFlavorSelect = 5;
233 break;
234 case kPyBeautyUnforced:
235 fParentSelect[0] = 511;
236 fParentSelect[1] = 521;
237 fParentSelect[2] = 531;
238 fParentSelect[3] = 5122;
239 fParentSelect[4] = 5132;
240 fParentSelect[5] = 5232;
241 fParentSelect[6] = 5332;
242 fFlavorSelect = 5;
243 break;
244 case kPyJpsiChi:
245 case kPyJpsi:
246 fParentSelect[0] = 443;
247 break;
248 case kPyMb:
249 case kPyMbNonDiffr:
250 case kPyJets:
251 case kPyDirectGamma:
252 break;
253 }
254//
592f8307 255//
256// JetFinder for Trigger
257//
258// Configure detector (EMCAL like)
259//
260 fPythia->SetPARU(51, fPycellEtaMax);
261 fPythia->SetMSTU(51, fPycellNEta);
262 fPythia->SetMSTU(52, fPycellNPhi);
263//
264// Configure Jet Finder
265//
266 fPythia->SetPARU(58, fPycellThreshold);
267 fPythia->SetPARU(52, fPycellEtSeed);
268 fPythia->SetPARU(53, fPycellMinEtJet);
269 fPythia->SetPARU(54, fPycellMaxRadius);
270 fPythia->SetMSTU(54, 2);
271//
8d2cd130 272// This counts the total number of calls to Pyevnt() per run.
273 fTrialsRun = 0;
274 fQ = 0.;
275 fX1 = 0.;
276 fX2 = 0.;
277 fNev = 0 ;
278//
1d568bc2 279//
280//
8d2cd130 281 AliGenMC::Init();
1d568bc2 282//
283//
284//
285 if (fSetNuclei) {
286 fDyBoost = 0;
287 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
288 }
32d6ef7d 289
290 if (fQuench) {
86b6ad68 291 fPythia->InitQuenching(0., 0.1, 6.e5, 0);
32d6ef7d 292 }
293
8d2cd130 294}
295
296void AliGenPythia::Generate()
297{
298// Generate one event
e5c87a3d 299
8d2cd130 300 fDecayer->ForceDecay();
301
302 Float_t polar[3] = {0,0,0};
303 Float_t origin[3] = {0,0,0};
a920faf9 304 Float_t p[4];
8d2cd130 305// converts from mm/c to s
306 const Float_t kconv=0.001/2.999792458e8;
307//
308 Int_t nt=0;
309 Int_t jev=0;
310 Int_t j, kf;
311 fTrials=0;
2590ccf9 312
8d2cd130 313
314 // Set collision vertex position
2590ccf9 315 if (fVertexSmear == kPerEvent) Vertex();
316
8d2cd130 317// event loop
318 while(1)
319 {
32d6ef7d 320//
321// If quenching option has been selected switch off fragmentation first
322//
7ea3ea5b 323 if (fQuench) {
324 fPythia->SetMSTJ(1, 0);
325 }
32d6ef7d 326//
327// Produce event
328//
8d2cd130 329 fPythia->Pyevnt();
7ea3ea5b 330 if (fQuench) {
32d6ef7d 331//
332// Run quenching routine
333//
b6bbf811 334 if (fQuench == 1) {
335 fPythia->Quench();
336 } else {
337 fPythia->Pyquen(208., 0, 0.);
338 }
339
32d6ef7d 340//
341// Switch fragmentation on
7ea3ea5b 342 fPythia->SetMSTJ(1, 1);
32d6ef7d 343//
344// .. and perform fragmentation
7ea3ea5b 345 fPythia->Pyexec();
346 }
347
e2bddf81 348 if (gAlice) {
349 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
350 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
351 }
7ea3ea5b 352
8d2cd130 353 fTrials++;
8d2cd130 354 fPythia->ImportParticles(fParticles,"All");
1d568bc2 355 Boost();
8d2cd130 356//
357//
358//
359 Int_t i;
360
361 Int_t np = fParticles->GetEntriesFast();
362 if (np == 0 ) continue;
8d2cd130 363//
2590ccf9 364
8d2cd130 365//
366 Int_t* pParent = new Int_t[np];
367 Int_t* pSelected = new Int_t[np];
368 Int_t* trackIt = new Int_t[np];
369 for (i=0; i< np; i++) {
370 pParent[i] = -1;
371 pSelected[i] = 0;
372 trackIt[i] = 0;
373 }
374
375 Int_t nc = 0; // Total n. of selected particles
376 Int_t nParents = 0; // Selected parents
377 Int_t nTkbles = 0; // Trackable particles
378 if (fProcess != kPyMb && fProcess != kPyJets &&
379 fProcess != kPyDirectGamma &&
380 fProcess != kPyMbNonDiffr) {
381
382 for (i = 0; i<np; i++) {
2590ccf9 383 TParticle* iparticle = (TParticle *) fParticles->At(i);
8d2cd130 384 Int_t ks = iparticle->GetStatusCode();
385 kf = CheckPDGCode(iparticle->GetPdgCode());
386// No initial state partons
387 if (ks==21) continue;
388//
389// Heavy Flavor Selection
390//
391 // quark ?
392 kf = TMath::Abs(kf);
393 Int_t kfl = kf;
394 // meson ?
395 if (kfl > 10) kfl/=100;
396 // baryon
397 if (kfl > 10) kfl/=10;
398 if (kfl > 10) kfl/=10;
399
400 Int_t ipa = iparticle->GetFirstMother()-1;
401 Int_t kfMo = 0;
402
403 if (ipa > -1) {
404 TParticle * mother = (TParticle *) fParticles->At(ipa);
405 kfMo = TMath::Abs(mother->GetPdgCode());
406 }
407 // What to keep in Stack?
408 Bool_t flavorOK = kFALSE;
409 Bool_t selectOK = kFALSE;
410 if (fFeedDownOpt) {
32d6ef7d 411 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
8d2cd130 412 } else {
32d6ef7d 413 if (kfl > fFlavorSelect) {
414 nc = -1;
415 break;
416 }
417 if (kfl == fFlavorSelect) flavorOK = kTRUE;
8d2cd130 418 }
419 switch (fStackFillOpt) {
420 case kFlavorSelection:
32d6ef7d 421 selectOK = kTRUE;
422 break;
8d2cd130 423 case kParentSelection:
32d6ef7d 424 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
425 break;
8d2cd130 426 }
427 if (flavorOK && selectOK) {
428//
429// Heavy flavor hadron or quark
430//
431// Kinematic seletion on final state heavy flavor mesons
432 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
433 {
434 continue;
435 }
436 pSelected[i] = 1;
437 if (ParentSelected(kf)) ++nParents; // Update parent count
438// printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
439 } else {
440// Kinematic seletion on decay products
441 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
442 && !KinematicSelection(iparticle, 1))
443 {
444 continue;
445 }
446//
447// Decay products
448// Select if mother was selected and is not tracked
449
450 if (pSelected[ipa] &&
451 !trackIt[ipa] && // mother will be tracked ?
452 kfMo != 5 && // mother is b-quark, don't store fragments
453 kfMo != 4 && // mother is c-quark, don't store fragments
454 kf != 92) // don't store string
455 {
456//
457// Semi-stable or de-selected: diselect decay products:
458//
459//
460 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
461 {
462 Int_t ipF = iparticle->GetFirstDaughter();
463 Int_t ipL = iparticle->GetLastDaughter();
464 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
465 }
466// printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
467 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
468 }
469 }
470 if (pSelected[i] == -1) pSelected[i] = 0;
471 if (!pSelected[i]) continue;
472 // Count quarks only if you did not include fragmentation
473 if (fFragmentation && kf <= 10) continue;
474 nc++;
475// Decision on tracking
476 trackIt[i] = 0;
477//
478// Track final state particle
479 if (ks == 1) trackIt[i] = 1;
480// Track semi-stable particles
d25cfd65 481 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
8d2cd130 482// Track particles selected by process if undecayed.
483 if (fForceDecay == kNoDecay) {
484 if (ParentSelected(kf)) trackIt[i] = 1;
485 } else {
486 if (ParentSelected(kf)) trackIt[i] = 0;
487 }
488 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
489//
490//
491
492 } // particle selection loop
493 if (nc > 0) {
494 for (i = 0; i<np; i++) {
495 if (!pSelected[i]) continue;
496 TParticle * iparticle = (TParticle *) fParticles->At(i);
497 kf = CheckPDGCode(iparticle->GetPdgCode());
498 Int_t ks = iparticle->GetStatusCode();
499 p[0] = iparticle->Px();
500 p[1] = iparticle->Py();
501 p[2] = iparticle->Pz();
a920faf9 502 p[3] = iparticle->Energy();
503
2590ccf9 504 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
505 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
506 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
507
8d2cd130 508 Float_t tof = kconv*iparticle->T();
509 Int_t ipa = iparticle->GetFirstMother()-1;
510 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
a920faf9 511
512 PushTrack(fTrackIt*trackIt[i], iparent, kf,
513 p[0], p[1], p[2], p[3],
514 origin[0], origin[1], origin[2], tof,
515 polar[0], polar[1], polar[2],
516 kPPrimary, nt, 1., ks);
8d2cd130 517 pParent[i] = nt;
518 KeepTrack(nt);
642f15cf 519 } // PushTrack loop
8d2cd130 520 }
521 } else {
522 nc = GenerateMB();
523 } // mb ?
524
525 if (pParent) delete[] pParent;
526 if (pSelected) delete[] pSelected;
527 if (trackIt) delete[] trackIt;
528
529 if (nc > 0) {
530 switch (fCountMode) {
531 case kCountAll:
532 // printf(" Count all \n");
533 jev += nc;
534 break;
535 case kCountParents:
536 // printf(" Count parents \n");
537 jev += nParents;
538 break;
539 case kCountTrackables:
540 // printf(" Count trackable \n");
541 jev += nTkbles;
542 break;
543 }
544 if (jev >= fNpart || fNpart == -1) {
545 fKineBias=Float_t(fNpart)/Float_t(fTrials);
546 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
547
548 fQ += fPythia->GetVINT(51);
549 fX1 += fPythia->GetVINT(41);
550 fX2 += fPythia->GetVINT(42);
551 fTrialsRun += fTrials;
552 fNev++;
553 MakeHeader();
554 break;
555 }
556 }
557 } // event loop
558 SetHighWaterMark(nt);
559// adjust weight due to kinematic selection
b88f5cea 560// AdjustWeights();
8d2cd130 561// get cross-section
562 fXsection=fPythia->GetPARI(1);
563}
564
565Int_t AliGenPythia::GenerateMB()
566{
567//
568// Min Bias selection and other global selections
569//
570 Int_t i, kf, nt, iparent;
571 Int_t nc = 0;
bf950da8 572 Float_t p[4];
8d2cd130 573 Float_t polar[3] = {0,0,0};
574 Float_t origin[3] = {0,0,0};
575// converts from mm/c to s
576 const Float_t kconv=0.001/2.999792458e8;
577
578 Int_t np = fParticles->GetEntriesFast();
579 Int_t* pParent = new Int_t[np];
580 for (i=0; i< np; i++) pParent[i] = -1;
581 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
582 TParticle* jet1 = (TParticle *) fParticles->At(6);
583 TParticle* jet2 = (TParticle *) fParticles->At(7);
584 if (!CheckTrigger(jet1, jet2)) return 0;
585 }
586
587 for (i = 0; i<np; i++) {
588 Int_t trackIt = 0;
589 TParticle * iparticle = (TParticle *) fParticles->At(i);
590 kf = CheckPDGCode(iparticle->GetPdgCode());
591 Int_t ks = iparticle->GetStatusCode();
592 Int_t km = iparticle->GetFirstMother();
593 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
594 (ks != 1) ||
595 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
596 nc++;
597 if (ks == 1) trackIt = 1;
598 Int_t ipa = iparticle->GetFirstMother()-1;
599
600 iparent = (ipa > -1) ? pParent[ipa] : -1;
601
602//
603// store track information
604 p[0] = iparticle->Px();
605 p[1] = iparticle->Py();
606 p[2] = iparticle->Pz();
a920faf9 607 p[3] = iparticle->Energy();
1406f599 608
a920faf9 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();
a920faf9 615
616 PushTrack(fTrackIt*trackIt, iparent, kf,
617 p[0], p[1], p[2], p[3],
618 origin[0], origin[1], origin[2], tof,
619 polar[0], polar[1], polar[2],
620 kPPrimary, nt, 1., ks);
8d2cd130 621 KeepTrack(nt);
622 pParent[i] = nt;
623 } // select particle
624 } // particle loop
625
626 if (pParent) delete[] pParent;
627
628 printf("\n I've put %i particles on the stack \n",nc);
629 return nc;
630}
631
632
633void AliGenPythia::FinishRun()
634{
635// Print x-section summary
636 fPythia->Pystat(1);
637 fQ /= fNev;
638 fX1 /= fNev;
639 fX2 /= fNev;
640 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
641 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
642
643
644}
645
646void AliGenPythia::AdjustWeights()
647{
648// Adjust the weights after generation of all events
649//
e2bddf81 650 if (gAlice) {
651 TParticle *part;
652 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
653 for (Int_t i=0; i<ntrack; i++) {
654 part= gAlice->GetMCApp()->Particle(i);
655 part->SetWeight(part->GetWeight()*fKineBias);
656 }
8d2cd130 657 }
658}
659
660void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
661{
662// Treat protons as inside nuclei with mass numbers a1 and a2
1d568bc2 663
1a626d4e 664 fAProjectile = a1;
665 fATarget = a2;
1d568bc2 666 fSetNuclei = kTRUE;
8d2cd130 667}
668
669
670void AliGenPythia::MakeHeader()
671{
672// Builds the event header, to be called after each event
e5c87a3d 673 if (fHeader) delete fHeader;
674 fHeader = new AliGenPythiaEventHeader("Pythia");
8d2cd130 675//
676// Event type
e5c87a3d 677 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
8d2cd130 678//
679// Number of trials
e5c87a3d 680 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
8d2cd130 681//
682// Event Vertex
d25cfd65 683 fHeader->SetPrimaryVertex(fVertex);
8d2cd130 684//
685// Jets that have triggered
686 if (fProcess == kPyJets)
687 {
688 Int_t ntrig, njet;
689 Float_t jets[4][10];
690 GetJets(njet, ntrig, jets);
691
692 for (Int_t i = 0; i < ntrig; i++) {
e5c87a3d 693 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
8d2cd130 694 jets[3][i]);
695 }
696 }
e2bddf81 697 if (gAlice) gAlice->SetGenEventHeader(fHeader);
8d2cd130 698}
699
700
701Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
702{
703// Check the kinematic trigger condition
704//
705 Double_t eta[2];
706 eta[0] = jet1->Eta();
707 eta[1] = jet2->Eta();
708 Double_t phi[2];
709 phi[0] = jet1->Phi();
710 phi[1] = jet2->Phi();
711 Int_t pdg[2];
712 pdg[0] = jet1->GetPdgCode();
713 pdg[1] = jet2->GetPdgCode();
714 Bool_t triggered = kFALSE;
715
716 if (fProcess == kPyJets) {
717 Int_t njets = 0;
718 Int_t ntrig = 0;
719 Float_t jets[4][10];
720//
721// Use Pythia clustering on parton level to determine jet axis
722//
723 GetJets(njets, ntrig, jets);
724
725 if (ntrig) triggered = kTRUE;
726//
727 } else {
728 Int_t ij = 0;
729 Int_t ig = 1;
730 if (pdg[0] == kGamma) {
731 ij = 1;
732 ig = 0;
733 }
734 //Check eta range first...
735 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
736 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
737 {
738 //Eta is okay, now check phi range
739 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
740 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
741 {
742 triggered = kTRUE;
743 }
744 }
745 }
746 return triggered;
747}
748
749AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
750{
751// Assignment operator
014a9521 752 rhs.Copy(*this);
8d2cd130 753 return *this;
754}
755
32d6ef7d 756void AliGenPythia::LoadEvent(AliStack* stack, Int_t flag)
8d2cd130 757{
758//
759// Load event into Pythia Common Block
760//
761
32d6ef7d 762// AliRunLoader* rl = AliRunLoader::GetRunLoader();
763 Int_t npart = stack -> GetNprimary();
764 Int_t n0 = 0;
765
766 if (!flag) {
767 (fPythia->GetPyjets())->N = npart;
768 } else {
769 n0 = (fPythia->GetPyjets())->N;
770 (fPythia->GetPyjets())->N = n0 + npart;
771 }
772
773
8d2cd130 774 for (Int_t part = 0; part < npart; part++) {
32d6ef7d 775 TParticle *MPart = stack->Particle(part);
776
8d2cd130 777 Int_t kf = MPart->GetPdgCode();
778 Int_t ks = MPart->GetStatusCode();
32d6ef7d 779
8d2cd130 780 Float_t px = MPart->Px();
781 Float_t py = MPart->Py();
782 Float_t pz = MPart->Pz();
783 Float_t e = MPart->Energy();
a920faf9 784 Float_t m = MPart->GetCalcMass();
8d2cd130 785
786
32d6ef7d 787 (fPythia->GetPyjets())->P[0][part+n0] = px;
788 (fPythia->GetPyjets())->P[1][part+n0] = py;
789 (fPythia->GetPyjets())->P[2][part+n0] = pz;
790 (fPythia->GetPyjets())->P[3][part+n0] = e;
791 (fPythia->GetPyjets())->P[4][part+n0] = m;
8d2cd130 792
32d6ef7d 793 (fPythia->GetPyjets())->K[1][part+n0] = kf;
794 (fPythia->GetPyjets())->K[0][part+n0] = ks;
8d2cd130 795 }
796}
797
014a9521 798void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
8d2cd130 799{
800//
801// Calls the Pythia jet finding algorithm to find jets in the current event
802//
803//
8d2cd130 804//
805// Save jets
806 Int_t n = fPythia->GetN();
807
808//
809// Run Jet Finder
810 fPythia->Pycell(njets);
811 Int_t i;
812 for (i = 0; i < njets; i++) {
813 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
814 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
815 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
816 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
817
818 jets[0][i] = px;
819 jets[1][i] = py;
820 jets[2][i] = pz;
821 jets[3][i] = e;
822 }
823}
824
825
826
827void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
828{
829//
830// Calls the Pythia clustering algorithm to find jets in the current event
831//
832 Int_t n = fPythia->GetN();
833 nJets = 0;
834 nJetsTrig = 0;
835 if (fJetReconstruction == kCluster) {
836//
837// Configure cluster algorithm
838//
839 fPythia->SetPARU(43, 2.);
840 fPythia->SetMSTU(41, 1);
841//
842// Call cluster algorithm
843//
844 fPythia->Pyclus(nJets);
845//
846// Loading jets from common block
847//
848 } else {
592f8307 849
8d2cd130 850//
851// Run Jet Finder
852 fPythia->Pycell(nJets);
853 }
854
855 Int_t i;
856 for (i = 0; i < nJets; i++) {
857 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
858 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
859 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
860 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
861 Float_t pt = TMath::Sqrt(px * px + py * py);
a920faf9 862 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
8d2cd130 863 Float_t theta = TMath::ATan2(pt,pz);
864 Float_t et = e * TMath::Sin(theta);
865 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
866
867 if (
868 eta > fEtaMinJet && eta < fEtaMaxJet &&
675eb105 869 phi > fPhiMinJet && phi < fPhiMaxJet &&
8d2cd130 870 et > fEtMinJet && et < fEtMaxJet
871 )
872 {
873 jets[0][nJetsTrig] = px;
874 jets[1][nJetsTrig] = py;
875 jets[2][nJetsTrig] = pz;
876 jets[3][nJetsTrig] = e;
877 nJetsTrig++;
878
879 } else {
880// printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
881 }
882 }
883}
884
885
886#ifdef never
887void AliGenPythia::Streamer(TBuffer &R__b)
888{
889 // Stream an object of class AliGenPythia.
890
891 if (R__b.IsReading()) {
892 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
893 AliGenerator::Streamer(R__b);
894 R__b >> (Int_t&)fProcess;
895 R__b >> (Int_t&)fStrucFunc;
896 R__b >> (Int_t&)fForceDecay;
897 R__b >> fEnergyCMS;
898 R__b >> fKineBias;
899 R__b >> fTrials;
900 fParentSelect.Streamer(R__b);
901 fChildSelect.Streamer(R__b);
902 R__b >> fXsection;
903// (AliPythia::Instance())->Streamer(R__b);
904 R__b >> fPtHardMin;
905 R__b >> fPtHardMax;
906// if (fDecayer) fDecayer->Streamer(R__b);
907 } else {
908 R__b.WriteVersion(AliGenPythia::IsA());
909 AliGenerator::Streamer(R__b);
910 R__b << (Int_t)fProcess;
911 R__b << (Int_t)fStrucFunc;
912 R__b << (Int_t)fForceDecay;
913 R__b << fEnergyCMS;
914 R__b << fKineBias;
915 R__b << fTrials;
916 fParentSelect.Streamer(R__b);
917 fChildSelect.Streamer(R__b);
918 R__b << fXsection;
919// R__b << fPythia;
920 R__b << fPtHardMin;
921 R__b << fPtHardMax;
922 // fDecayer->Streamer(R__b);
923 }
924}
925#endif
926
90d7b703 927