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);
95 SetJetReconstructionMode();
97 // Options determining what to keep in the stack (Heavy flavour generation)
98 fStackFillOpt = kFlavorSelection; // Keep particle with selected flavor
99 fFeedDownOpt = kTRUE; // allow feed down from higher family
100 // Fragmentation on/off
101 fFragmentation = kTRUE;
102 // Default counting mode
103 fCountMode = kCountAll;
105 SetPycellParameters();
109 AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
115 AliGenPythia::~AliGenPythia()
120 void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
121 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
123 // Set pycell parameters
124 fPycellEtaMax = etamax;
127 fPycellThreshold = thresh;
128 fPycellEtSeed = etseed;
129 fPycellMinEtJet = minet;
130 fPycellMaxRadius = r;
135 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
137 // Set a range of event numbers, for which a table
138 // of generated particle will be printed
139 fDebugEventFirst = eventFirst;
140 fDebugEventLast = eventLast;
141 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
144 void AliGenPythia::Init()
148 SetMC(AliPythia::Instance());
149 fPythia=(AliPythia*) fgMCEvGen;
151 fParentWeight=1./Float_t(fNpart);
153 // Forward Paramters to the AliPythia object
154 fDecayer->SetForceDecay(fForceDecay);
158 fPythia->SetCKIN(3,fPtHardMin);
159 fPythia->SetCKIN(4,fPtHardMax);
160 fPythia->SetCKIN(7,fYHardMin);
161 fPythia->SetCKIN(8,fYHardMax);
163 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget);
165 if (fFragmentation) {
166 fPythia->SetMSTP(111,1);
168 fPythia->SetMSTP(111,0);
172 // initial state radiation
173 fPythia->SetMSTP(61,fGinit);
174 // final state radiation
175 fPythia->SetMSTP(71,fGfinal);
178 fPythia->SetMSTP(91,1);
179 fPythia->SetPARP(91,fPtKick);
181 fPythia->SetMSTP(91,0);
184 // fPythia->SetMSTJ(1,2);
186 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
188 // Parent and Children Selection
192 case kPyCharmUnforced:
193 case kPyCharmPbPbMNR:
196 fParentSelect[0] = 411;
197 fParentSelect[1] = 421;
198 fParentSelect[2] = 431;
199 fParentSelect[3] = 4122;
205 fParentSelect[0] = 421;
209 case kPyBeautyPbPbMNR:
210 case kPyBeautypPbMNR:
212 fParentSelect[0]= 511;
213 fParentSelect[1]= 521;
214 fParentSelect[2]= 531;
215 fParentSelect[3]= 5122;
216 fParentSelect[4]= 5132;
217 fParentSelect[5]= 5232;
218 fParentSelect[6]= 5332;
221 case kPyBeautyUnforced:
222 fParentSelect[0] = 511;
223 fParentSelect[1] = 521;
224 fParentSelect[2] = 531;
225 fParentSelect[3] = 5122;
226 fParentSelect[4] = 5132;
227 fParentSelect[5] = 5232;
228 fParentSelect[6] = 5332;
233 fParentSelect[0] = 443;
243 // JetFinder for Trigger
245 // Configure detector (EMCAL like)
247 fPythia->SetPARU(51, fPycellEtaMax);
248 fPythia->SetMSTU(51, fPycellNEta);
249 fPythia->SetMSTU(52, fPycellNPhi);
251 // Configure Jet Finder
253 fPythia->SetPARU(58, fPycellThreshold);
254 fPythia->SetPARU(52, fPycellEtSeed);
255 fPythia->SetPARU(53, fPycellMinEtJet);
256 fPythia->SetPARU(54, fPycellMaxRadius);
257 fPythia->SetMSTU(54, 2);
259 // This counts the total number of calls to Pyevnt() per run.
274 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
278 void AliGenPythia::Generate()
280 // Generate one event
282 fDecayer->ForceDecay();
284 Float_t polar[3] = {0,0,0};
285 Float_t origin[3] = {0,0,0};
287 // converts from mm/c to s
288 const Float_t kconv=0.001/2.999792458e8;
295 // Set collision vertex position
296 if(fVertexSmear==kPerEvent) {
297 fPythia->SetMSTP(151,1);
299 fPythia->SetPARP(151+j, fOsigma[j]*10.);
301 } else if (fVertexSmear==kPerTrack) {
302 fPythia->SetMSTP(151,0);
308 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
309 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
312 fPythia->ImportParticles(fParticles,"All");
320 Int_t np = fParticles->GetEntriesFast();
321 if (np == 0 ) continue;
322 // Get event vertex and discard the event if the Z coord. is too big
323 TParticle *iparticle = (TParticle *) fParticles->At(0);
324 Float_t distz = iparticle->Vz()/10.;
325 if(TMath::Abs(distz)>fCutVertexZ*fOsigma[2]) continue;
327 fEventVertex[0] = iparticle->Vx()/10.+fOrigin.At(0);
328 fEventVertex[1] = iparticle->Vy()/10.+fOrigin.At(1);
329 fEventVertex[2] = iparticle->Vz()/10.+fOrigin.At(2);
331 Int_t* pParent = new Int_t[np];
332 Int_t* pSelected = new Int_t[np];
333 Int_t* trackIt = new Int_t[np];
334 for (i=0; i< np; i++) {
340 Int_t nc = 0; // Total n. of selected particles
341 Int_t nParents = 0; // Selected parents
342 Int_t nTkbles = 0; // Trackable particles
343 if (fProcess != kPyMb && fProcess != kPyJets &&
344 fProcess != kPyDirectGamma &&
345 fProcess != kPyMbNonDiffr) {
347 for (i = 0; i<np; i++) {
348 iparticle = (TParticle *) fParticles->At(i);
349 Int_t ks = iparticle->GetStatusCode();
350 kf = CheckPDGCode(iparticle->GetPdgCode());
351 // No initial state partons
352 if (ks==21) continue;
354 // Heavy Flavor Selection
360 if (kfl > 10) kfl/=100;
362 if (kfl > 10) kfl/=10;
363 if (kfl > 10) kfl/=10;
365 Int_t ipa = iparticle->GetFirstMother()-1;
369 TParticle * mother = (TParticle *) fParticles->At(ipa);
370 kfMo = TMath::Abs(mother->GetPdgCode());
372 // What to keep in Stack?
373 Bool_t flavorOK = kFALSE;
374 Bool_t selectOK = kFALSE;
376 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
378 if (kfl > fFlavorSelect) {
382 if (kfl == fFlavorSelect) flavorOK = kTRUE;
384 switch (fStackFillOpt) {
385 case kFlavorSelection:
388 case kParentSelection:
389 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
392 if (flavorOK && selectOK) {
394 // Heavy flavor hadron or quark
396 // Kinematic seletion on final state heavy flavor mesons
397 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
402 if (ParentSelected(kf)) ++nParents; // Update parent count
403 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
405 // Kinematic seletion on decay products
406 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
407 && !KinematicSelection(iparticle, 1))
413 // Select if mother was selected and is not tracked
415 if (pSelected[ipa] &&
416 !trackIt[ipa] && // mother will be tracked ?
417 kfMo != 5 && // mother is b-quark, don't store fragments
418 kfMo != 4 && // mother is c-quark, don't store fragments
419 kf != 92) // don't store string
422 // Semi-stable or de-selected: diselect decay products:
425 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
427 Int_t ipF = iparticle->GetFirstDaughter();
428 Int_t ipL = iparticle->GetLastDaughter();
429 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
431 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
432 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
435 if (pSelected[i] == -1) pSelected[i] = 0;
436 if (!pSelected[i]) continue;
437 // Count quarks only if you did not include fragmentation
438 if (fFragmentation && kf <= 10) continue;
440 // Decision on tracking
443 // Track final state particle
444 if (ks == 1) trackIt[i] = 1;
445 // Track semi-stable particles
446 if ((ks ==1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
447 // Track particles selected by process if undecayed.
448 if (fForceDecay == kNoDecay) {
449 if (ParentSelected(kf)) trackIt[i] = 1;
451 if (ParentSelected(kf)) trackIt[i] = 0;
453 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
457 } // particle selection loop
459 for (i = 0; i<np; i++) {
460 if (!pSelected[i]) continue;
461 TParticle * iparticle = (TParticle *) fParticles->At(i);
462 kf = CheckPDGCode(iparticle->GetPdgCode());
463 Int_t ks = iparticle->GetStatusCode();
464 p[0] = iparticle->Px();
465 p[1] = iparticle->Py();
466 p[2] = iparticle->Pz();
467 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
468 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
469 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
470 Float_t tof = kconv*iparticle->T();
471 Int_t ipa = iparticle->GetFirstMother()-1;
472 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
473 SetTrack(fTrackIt*trackIt[i] ,
474 iparent, kf, p, origin, polar, tof, kPPrimary, nt, 1., ks);
483 if (pParent) delete[] pParent;
484 if (pSelected) delete[] pSelected;
485 if (trackIt) delete[] trackIt;
488 switch (fCountMode) {
490 // printf(" Count all \n");
494 // printf(" Count parents \n");
497 case kCountTrackables:
498 // printf(" Count trackable \n");
502 if (jev >= fNpart || fNpart == -1) {
503 fKineBias=Float_t(fNpart)/Float_t(fTrials);
504 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
506 fQ += fPythia->GetVINT(51);
507 fX1 += fPythia->GetVINT(41);
508 fX2 += fPythia->GetVINT(42);
509 fTrialsRun += fTrials;
516 SetHighWaterMark(nt);
517 // adjust weight due to kinematic selection
520 fXsection=fPythia->GetPARI(1);
523 Int_t AliGenPythia::GenerateMB()
526 // Min Bias selection and other global selections
528 Int_t i, kf, nt, iparent;
531 Float_t polar[3] = {0,0,0};
532 Float_t origin[3] = {0,0,0};
533 // converts from mm/c to s
534 const Float_t kconv=0.001/2.999792458e8;
536 Int_t np = fParticles->GetEntriesFast();
537 Int_t* pParent = new Int_t[np];
538 for (i=0; i< np; i++) pParent[i] = -1;
539 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
540 TParticle* jet1 = (TParticle *) fParticles->At(6);
541 TParticle* jet2 = (TParticle *) fParticles->At(7);
542 if (!CheckTrigger(jet1, jet2)) return 0;
545 for (i = 0; i<np; i++) {
547 TParticle * iparticle = (TParticle *) fParticles->At(i);
548 kf = CheckPDGCode(iparticle->GetPdgCode());
549 Int_t ks = iparticle->GetStatusCode();
550 Int_t km = iparticle->GetFirstMother();
551 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
553 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
555 if (ks == 1) trackIt = 1;
556 Int_t ipa = iparticle->GetFirstMother()-1;
558 iparent = (ipa > -1) ? pParent[ipa] : -1;
561 // store track information
562 p[0] = iparticle->Px();
563 p[1] = iparticle->Py();
564 p[2] = iparticle->Pz();
565 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
566 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
567 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
568 Float_t tof=kconv*iparticle->T();
569 SetTrack(fTrackIt*trackIt, iparent, kf, p, origin, polar,
570 tof, kPPrimary, nt, 1., ks);
576 if (pParent) delete[] pParent;
578 printf("\n I've put %i particles on the stack \n",nc);
583 void AliGenPythia::FinishRun()
585 // Print x-section summary
590 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
591 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
596 void AliGenPythia::AdjustWeights()
598 // Adjust the weights after generation of all events
601 Int_t ntrack=gAlice->GetNtrack();
602 for (Int_t i=0; i<ntrack; i++) {
603 part= gAlice->Particle(i);
604 part->SetWeight(part->GetWeight()*fKineBias);
608 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
610 // Treat protons as inside nuclei with mass numbers a1 and a2
618 void AliGenPythia::MakeHeader()
620 // Builds the event header, to be called after each event
621 if (fHeader) delete fHeader;
622 fHeader = new AliGenPythiaEventHeader("Pythia");
625 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
628 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
631 fHeader->SetPrimaryVertex(fEventVertex);
633 // Jets that have triggered
634 if (fProcess == kPyJets)
638 GetJets(njet, ntrig, jets);
640 for (Int_t i = 0; i < ntrig; i++) {
641 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
645 gAlice->SetGenEventHeader(fHeader);
649 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
651 // Check the kinematic trigger condition
654 eta[0] = jet1->Eta();
655 eta[1] = jet2->Eta();
657 phi[0] = jet1->Phi();
658 phi[1] = jet2->Phi();
660 pdg[0] = jet1->GetPdgCode();
661 pdg[1] = jet2->GetPdgCode();
662 Bool_t triggered = kFALSE;
664 if (fProcess == kPyJets) {
669 // Use Pythia clustering on parton level to determine jet axis
671 GetJets(njets, ntrig, jets);
673 if (ntrig) triggered = kTRUE;
678 if (pdg[0] == kGamma) {
682 //Check eta range first...
683 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
684 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
686 //Eta is okay, now check phi range
687 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
688 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
697 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
699 // Assignment operator
703 void AliGenPythia::LoadEvent()
706 // Load event into Pythia Common Block
710 Int_t npart = (Int_t) (gAlice->TreeK())->GetEntries();
711 (fPythia->GetPyjets())->N = npart;
713 for (Int_t part = 0; part < npart; part++) {
714 TParticle *MPart = gAlice->Particle(part);
715 Int_t kf = MPart->GetPdgCode();
716 Int_t ks = MPart->GetStatusCode();
717 Float_t px = MPart->Px();
718 Float_t py = MPart->Py();
719 Float_t pz = MPart->Pz();
720 Float_t e = MPart->Energy();
721 Float_t p = TMath::Sqrt(px * px + py * py + pz * pz);
722 Float_t m = TMath::Sqrt(e * e - p * p);
725 (fPythia->GetPyjets())->P[0][part] = px;
726 (fPythia->GetPyjets())->P[1][part] = py;
727 (fPythia->GetPyjets())->P[2][part] = pz;
728 (fPythia->GetPyjets())->P[3][part] = e;
729 (fPythia->GetPyjets())->P[4][part] = m;
731 (fPythia->GetPyjets())->K[1][part] = kf;
732 (fPythia->GetPyjets())->K[0][part] = ks;
736 void AliGenPythia::RecJetsUA1(Float_t eCellMin, Float_t eCellSeed, Float_t eMin, Float_t rMax,
737 Int_t& njets, Float_t jets [4][50])
740 // Calls the Pythia jet finding algorithm to find jets in the current event
745 Int_t n = fPythia->GetN();
749 fPythia->Pycell(njets);
751 for (i = 0; i < njets; i++) {
752 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
753 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
754 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
755 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
766 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
769 // Calls the Pythia clustering algorithm to find jets in the current event
771 Int_t n = fPythia->GetN();
774 if (fJetReconstruction == kCluster) {
776 // Configure cluster algorithm
778 fPythia->SetPARU(43, 2.);
779 fPythia->SetMSTU(41, 1);
781 // Call cluster algorithm
783 fPythia->Pyclus(nJets);
785 // Loading jets from common block
791 fPythia->Pycell(nJets);
795 for (i = 0; i < nJets; i++) {
796 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
797 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
798 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
799 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
800 Float_t pt = TMath::Sqrt(px * px + py * py);
801 Float_t phi = TMath::ATan2(py,px);
802 Float_t theta = TMath::ATan2(pt,pz);
803 Float_t et = e * TMath::Sin(theta);
804 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
807 eta > fEtaMinJet && eta < fEtaMaxJet &&
808 phi > fPhiMinJet && phi < fPhiMaxJet &&
809 et > fEtMinJet && et < fEtMaxJet
812 jets[0][nJetsTrig] = px;
813 jets[1][nJetsTrig] = py;
814 jets[2][nJetsTrig] = pz;
815 jets[3][nJetsTrig] = e;
819 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
826 void AliGenPythia::Streamer(TBuffer &R__b)
828 // Stream an object of class AliGenPythia.
830 if (R__b.IsReading()) {
831 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
832 AliGenerator::Streamer(R__b);
833 R__b >> (Int_t&)fProcess;
834 R__b >> (Int_t&)fStrucFunc;
835 R__b >> (Int_t&)fForceDecay;
839 fParentSelect.Streamer(R__b);
840 fChildSelect.Streamer(R__b);
842 // (AliPythia::Instance())->Streamer(R__b);
845 // if (fDecayer) fDecayer->Streamer(R__b);
847 R__b.WriteVersion(AliGenPythia::IsA());
848 AliGenerator::Streamer(R__b);
849 R__b << (Int_t)fProcess;
850 R__b << (Int_t)fStrucFunc;
851 R__b << (Int_t)fForceDecay;
855 fParentSelect.Streamer(R__b);
856 fChildSelect.Streamer(R__b);
861 // fDecayer->Streamer(R__b);