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