1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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 ...)
25 // andreas.morsch@cern.ch
28 #include <TDatabasePDG.h>
29 #include <TParticle.h>
35 #include "AliDecayerPythia.h"
36 #include "AliGenPythia.h"
37 #include "AliGenPythiaEventHeader.h"
38 #include "AliPythia.h"
39 #include "AliPythiaRndm.h"
42 ClassImp(AliGenPythia)
44 AliGenPythia::AliGenPythia()
47 // Default Constructor
51 fDecayer = new AliDecayerPythia();
60 if (!AliPythiaRndm::GetPythiaRandom())
61 AliPythiaRndm::SetPythiaRandom(GetRandom());
64 AliGenPythia::AliGenPythia(Int_t npart)
67 // default charm production at 5. 5 TeV
69 // structure function GRVHO
72 fTitle= "Particle Generator using PYTHIA";
80 fDecayer = new AliDecayerPythia();
81 // Set random number generator
82 if (!AliPythiaRndm::GetPythiaRandom())
83 AliPythiaRndm::SetPythiaRandom(GetRandom());
86 fParticles = new TClonesArray("TParticle",1000);
94 SetJetReconstructionMode();
96 // Options determining what to keep in the stack (Heavy flavour generation)
97 fStackFillOpt = kFlavorSelection; // Keep particle with selected flavor
98 fFeedDownOpt = kTRUE; // allow feed down from higher family
99 // Fragmentation on/off
100 fFragmentation = kTRUE;
101 // Default counting mode
102 fCountMode = kCountAll;
104 SetPycellParameters();
108 AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
114 AliGenPythia::~AliGenPythia()
119 void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
120 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
122 // Set pycell parameters
123 fPycellEtaMax = etamax;
126 fPycellThreshold = thresh;
127 fPycellEtSeed = etseed;
128 fPycellMinEtJet = minet;
129 fPycellMaxRadius = r;
134 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
136 // Set a range of event numbers, for which a table
137 // of generated particle will be printed
138 fDebugEventFirst = eventFirst;
139 fDebugEventLast = eventLast;
140 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
143 void AliGenPythia::Init()
147 SetMC(AliPythia::Instance());
148 fPythia=(AliPythia*) fMCEvGen;
150 fParentWeight=1./Float_t(fNpart);
152 // Forward Paramters to the AliPythia object
153 fDecayer->SetForceDecay(fForceDecay);
157 fPythia->SetCKIN(3,fPtHardMin);
158 fPythia->SetCKIN(4,fPtHardMax);
159 fPythia->SetCKIN(7,fYHardMin);
160 fPythia->SetCKIN(8,fYHardMax);
162 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget);
164 if (fFragmentation) {
165 fPythia->SetMSTP(111,1);
167 fPythia->SetMSTP(111,0);
171 // initial state radiation
172 fPythia->SetMSTP(61,fGinit);
173 // final state radiation
174 fPythia->SetMSTP(71,fGfinal);
177 fPythia->SetMSTP(91,1);
178 fPythia->SetPARP(91,fPtKick);
180 fPythia->SetMSTP(91,0);
183 // fPythia->SetMSTJ(1,2);
185 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
187 // Parent and Children Selection
191 case kPyCharmUnforced:
192 case kPyCharmPbPbMNR:
195 fParentSelect[0] = 411;
196 fParentSelect[1] = 421;
197 fParentSelect[2] = 431;
198 fParentSelect[3] = 4122;
204 fParentSelect[0] = 421;
208 case kPyBeautyPbPbMNR:
209 case kPyBeautypPbMNR:
211 fParentSelect[0]= 511;
212 fParentSelect[1]= 521;
213 fParentSelect[2]= 531;
214 fParentSelect[3]= 5122;
215 fParentSelect[4]= 5132;
216 fParentSelect[5]= 5232;
217 fParentSelect[6]= 5332;
220 case kPyBeautyUnforced:
221 fParentSelect[0] = 511;
222 fParentSelect[1] = 521;
223 fParentSelect[2] = 531;
224 fParentSelect[3] = 5122;
225 fParentSelect[4] = 5132;
226 fParentSelect[5] = 5232;
227 fParentSelect[6] = 5332;
232 fParentSelect[0] = 443;
242 // JetFinder for Trigger
244 // Configure detector (EMCAL like)
246 fPythia->SetPARU(51, fPycellEtaMax);
247 fPythia->SetMSTU(51, fPycellNEta);
248 fPythia->SetMSTU(52, fPycellNPhi);
250 // Configure Jet Finder
252 fPythia->SetPARU(58, fPycellThreshold);
253 fPythia->SetPARU(52, fPycellEtSeed);
254 fPythia->SetPARU(53, fPycellMinEtJet);
255 fPythia->SetPARU(54, fPycellMaxRadius);
256 fPythia->SetMSTU(54, 2);
258 // This counts the total number of calls to Pyevnt() per run.
273 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
277 void AliGenPythia::Generate()
279 // Generate one event
281 fDecayer->ForceDecay();
283 Float_t polar[3] = {0,0,0};
284 Float_t origin[3] = {0,0,0};
286 // converts from mm/c to s
287 const Float_t kconv=0.001/2.999792458e8;
294 // Set collision vertex position
295 if(fVertexSmear==kPerEvent) {
296 fPythia->SetMSTP(151,1);
298 fPythia->SetPARP(151+j, fOsigma[j]*10.);
300 } else if (fVertexSmear==kPerTrack) {
301 fPythia->SetMSTP(151,0);
307 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
308 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
311 fPythia->ImportParticles(fParticles,"All");
319 Int_t np = fParticles->GetEntriesFast();
320 if (np == 0 ) continue;
321 // Get event vertex and discard the event if the Z coord. is too big
322 TParticle *iparticle = (TParticle *) fParticles->At(0);
323 Float_t distz = iparticle->Vz()/10.;
324 if(TMath::Abs(distz)>fCutVertexZ*fOsigma[2]) continue;
326 fVertex[0] = iparticle->Vx()/10.+fOrigin.At(0);
327 fVertex[1] = iparticle->Vy()/10.+fOrigin.At(1);
328 fVertex[2] = iparticle->Vz()/10.+fOrigin.At(2);
330 Int_t* pParent = new Int_t[np];
331 Int_t* pSelected = new Int_t[np];
332 Int_t* trackIt = new Int_t[np];
333 for (i=0; i< np; i++) {
339 Int_t nc = 0; // Total n. of selected particles
340 Int_t nParents = 0; // Selected parents
341 Int_t nTkbles = 0; // Trackable particles
342 if (fProcess != kPyMb && fProcess != kPyJets &&
343 fProcess != kPyDirectGamma &&
344 fProcess != kPyMbNonDiffr) {
346 for (i = 0; i<np; i++) {
347 iparticle = (TParticle *) fParticles->At(i);
348 Int_t ks = iparticle->GetStatusCode();
349 kf = CheckPDGCode(iparticle->GetPdgCode());
350 // No initial state partons
351 if (ks==21) continue;
353 // Heavy Flavor Selection
359 if (kfl > 10) kfl/=100;
361 if (kfl > 10) kfl/=10;
362 if (kfl > 10) kfl/=10;
364 Int_t ipa = iparticle->GetFirstMother()-1;
368 TParticle * mother = (TParticle *) fParticles->At(ipa);
369 kfMo = TMath::Abs(mother->GetPdgCode());
371 // What to keep in Stack?
372 Bool_t flavorOK = kFALSE;
373 Bool_t selectOK = kFALSE;
375 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
377 if (kfl > fFlavorSelect) {
381 if (kfl == fFlavorSelect) flavorOK = kTRUE;
383 switch (fStackFillOpt) {
384 case kFlavorSelection:
387 case kParentSelection:
388 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
391 if (flavorOK && selectOK) {
393 // Heavy flavor hadron or quark
395 // Kinematic seletion on final state heavy flavor mesons
396 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
401 if (ParentSelected(kf)) ++nParents; // Update parent count
402 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
404 // Kinematic seletion on decay products
405 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
406 && !KinematicSelection(iparticle, 1))
412 // Select if mother was selected and is not tracked
414 if (pSelected[ipa] &&
415 !trackIt[ipa] && // mother will be tracked ?
416 kfMo != 5 && // mother is b-quark, don't store fragments
417 kfMo != 4 && // mother is c-quark, don't store fragments
418 kf != 92) // don't store string
421 // Semi-stable or de-selected: diselect decay products:
424 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
426 Int_t ipF = iparticle->GetFirstDaughter();
427 Int_t ipL = iparticle->GetLastDaughter();
428 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
430 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
431 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
434 if (pSelected[i] == -1) pSelected[i] = 0;
435 if (!pSelected[i]) continue;
436 // Count quarks only if you did not include fragmentation
437 if (fFragmentation && kf <= 10) continue;
439 // Decision on tracking
442 // Track final state particle
443 if (ks == 1) trackIt[i] = 1;
444 // Track semi-stable particles
445 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
446 // Track particles selected by process if undecayed.
447 if (fForceDecay == kNoDecay) {
448 if (ParentSelected(kf)) trackIt[i] = 1;
450 if (ParentSelected(kf)) trackIt[i] = 0;
452 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
456 } // particle selection loop
458 for (i = 0; i<np; i++) {
459 if (!pSelected[i]) continue;
460 TParticle * iparticle = (TParticle *) fParticles->At(i);
461 kf = CheckPDGCode(iparticle->GetPdgCode());
462 Int_t ks = iparticle->GetStatusCode();
463 p[0] = iparticle->Px();
464 p[1] = iparticle->Py();
465 p[2] = iparticle->Pz();
466 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
467 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
468 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
469 Float_t tof = kconv*iparticle->T();
470 Int_t ipa = iparticle->GetFirstMother()-1;
471 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
472 PushTrack(fTrackIt*trackIt[i] ,
473 iparent, kf, p, origin, polar, tof, kPPrimary, nt, 1., ks);
482 if (pParent) delete[] pParent;
483 if (pSelected) delete[] pSelected;
484 if (trackIt) delete[] trackIt;
487 switch (fCountMode) {
489 // printf(" Count all \n");
493 // printf(" Count parents \n");
496 case kCountTrackables:
497 // printf(" Count trackable \n");
501 if (jev >= fNpart || fNpart == -1) {
502 fKineBias=Float_t(fNpart)/Float_t(fTrials);
503 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
505 fQ += fPythia->GetVINT(51);
506 fX1 += fPythia->GetVINT(41);
507 fX2 += fPythia->GetVINT(42);
508 fTrialsRun += fTrials;
515 SetHighWaterMark(nt);
516 // adjust weight due to kinematic selection
519 fXsection=fPythia->GetPARI(1);
522 Int_t AliGenPythia::GenerateMB()
525 // Min Bias selection and other global selections
527 Int_t i, kf, nt, iparent;
530 Float_t polar[3] = {0,0,0};
531 Float_t origin[3] = {0,0,0};
532 // converts from mm/c to s
533 const Float_t kconv=0.001/2.999792458e8;
535 Int_t np = fParticles->GetEntriesFast();
536 Int_t* pParent = new Int_t[np];
537 for (i=0; i< np; i++) pParent[i] = -1;
538 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
539 TParticle* jet1 = (TParticle *) fParticles->At(6);
540 TParticle* jet2 = (TParticle *) fParticles->At(7);
541 if (!CheckTrigger(jet1, jet2)) return 0;
544 for (i = 0; i<np; i++) {
546 TParticle * iparticle = (TParticle *) fParticles->At(i);
547 kf = CheckPDGCode(iparticle->GetPdgCode());
548 Int_t ks = iparticle->GetStatusCode();
549 Int_t km = iparticle->GetFirstMother();
550 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
552 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
554 if (ks == 1) trackIt = 1;
555 Int_t ipa = iparticle->GetFirstMother()-1;
557 iparent = (ipa > -1) ? pParent[ipa] : -1;
560 // store track information
561 p[0] = iparticle->Px();
562 p[1] = iparticle->Py();
563 p[2] = iparticle->Pz();
564 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
565 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
566 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
567 Float_t tof=kconv*iparticle->T();
568 PushTrack(fTrackIt*trackIt, iparent, kf, p, origin, polar,
569 tof, kPPrimary, nt, 1., ks);
575 if (pParent) delete[] pParent;
577 printf("\n I've put %i particles on the stack \n",nc);
582 void AliGenPythia::FinishRun()
584 // Print x-section summary
589 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
590 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
595 void AliGenPythia::AdjustWeights()
597 // Adjust the weights after generation of all events
600 Int_t ntrack=gAlice->GetNtrack();
601 for (Int_t i=0; i<ntrack; i++) {
602 part= gAlice->Particle(i);
603 part->SetWeight(part->GetWeight()*fKineBias);
607 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
609 // Treat protons as inside nuclei with mass numbers a1 and a2
617 void AliGenPythia::MakeHeader()
619 // Builds the event header, to be called after each event
620 if (fHeader) delete fHeader;
621 fHeader = new AliGenPythiaEventHeader("Pythia");
624 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
627 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
630 fHeader->SetPrimaryVertex(fVertex);
632 // Jets that have triggered
633 if (fProcess == kPyJets)
637 GetJets(njet, ntrig, jets);
639 for (Int_t i = 0; i < ntrig; i++) {
640 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
644 gAlice->SetGenEventHeader(fHeader);
648 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
650 // Check the kinematic trigger condition
653 eta[0] = jet1->Eta();
654 eta[1] = jet2->Eta();
656 phi[0] = jet1->Phi();
657 phi[1] = jet2->Phi();
659 pdg[0] = jet1->GetPdgCode();
660 pdg[1] = jet2->GetPdgCode();
661 Bool_t triggered = kFALSE;
663 if (fProcess == kPyJets) {
668 // Use Pythia clustering on parton level to determine jet axis
670 GetJets(njets, ntrig, jets);
672 if (ntrig) triggered = kTRUE;
677 if (pdg[0] == kGamma) {
681 //Check eta range first...
682 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
683 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
685 //Eta is okay, now check phi range
686 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
687 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
696 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
698 // Assignment operator
702 void AliGenPythia::LoadEvent()
705 // Load event into Pythia Common Block
709 Int_t npart = (Int_t) (gAlice->TreeK())->GetEntries();
710 (fPythia->GetPyjets())->N = npart;
712 for (Int_t part = 0; part < npart; part++) {
713 TParticle *MPart = gAlice->Particle(part);
714 Int_t kf = MPart->GetPdgCode();
715 Int_t ks = MPart->GetStatusCode();
716 Float_t px = MPart->Px();
717 Float_t py = MPart->Py();
718 Float_t pz = MPart->Pz();
719 Float_t e = MPart->Energy();
720 Float_t p = TMath::Sqrt(px * px + py * py + pz * pz);
721 Float_t m = TMath::Sqrt(e * e - p * p);
724 (fPythia->GetPyjets())->P[0][part] = px;
725 (fPythia->GetPyjets())->P[1][part] = py;
726 (fPythia->GetPyjets())->P[2][part] = pz;
727 (fPythia->GetPyjets())->P[3][part] = e;
728 (fPythia->GetPyjets())->P[4][part] = m;
730 (fPythia->GetPyjets())->K[1][part] = kf;
731 (fPythia->GetPyjets())->K[0][part] = ks;
735 void AliGenPythia::RecJetsUA1(Float_t eCellMin, Float_t eCellSeed, Float_t eMin, Float_t rMax,
736 Int_t& njets, Float_t jets [4][50])
739 // Calls the Pythia jet finding algorithm to find jets in the current event
744 Int_t n = fPythia->GetN();
748 fPythia->Pycell(njets);
750 for (i = 0; i < njets; i++) {
751 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
752 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
753 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
754 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
765 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
768 // Calls the Pythia clustering algorithm to find jets in the current event
770 Int_t n = fPythia->GetN();
773 if (fJetReconstruction == kCluster) {
775 // Configure cluster algorithm
777 fPythia->SetPARU(43, 2.);
778 fPythia->SetMSTU(41, 1);
780 // Call cluster algorithm
782 fPythia->Pyclus(nJets);
784 // Loading jets from common block
790 fPythia->Pycell(nJets);
794 for (i = 0; i < nJets; i++) {
795 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
796 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
797 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
798 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
799 Float_t pt = TMath::Sqrt(px * px + py * py);
800 Float_t phi = TMath::ATan2(py,px);
801 Float_t theta = TMath::ATan2(pt,pz);
802 Float_t et = e * TMath::Sin(theta);
803 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
806 eta > fEtaMinJet && eta < fEtaMaxJet &&
807 phi > fPhiMinJet && phi < fPhiMaxJet &&
808 et > fEtMinJet && et < fEtMaxJet
811 jets[0][nJetsTrig] = px;
812 jets[1][nJetsTrig] = py;
813 jets[2][nJetsTrig] = pz;
814 jets[3][nJetsTrig] = e;
818 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
825 void AliGenPythia::Streamer(TBuffer &R__b)
827 // Stream an object of class AliGenPythia.
829 if (R__b.IsReading()) {
830 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
831 AliGenerator::Streamer(R__b);
832 R__b >> (Int_t&)fProcess;
833 R__b >> (Int_t&)fStrucFunc;
834 R__b >> (Int_t&)fForceDecay;
838 fParentSelect.Streamer(R__b);
839 fChildSelect.Streamer(R__b);
841 // (AliPythia::Instance())->Streamer(R__b);
844 // if (fDecayer) fDecayer->Streamer(R__b);
846 R__b.WriteVersion(AliGenPythia::IsA());
847 AliGenerator::Streamer(R__b);
848 R__b << (Int_t)fProcess;
849 R__b << (Int_t)fStrucFunc;
850 R__b << (Int_t)fForceDecay;
854 fParentSelect.Streamer(R__b);
855 fChildSelect.Streamer(R__b);
860 // fDecayer->Streamer(R__b);