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 #include "AliRunLoader.h"
45 ClassImp(AliGenPythia)
47 AliGenPythia::AliGenPythia()
50 // Default Constructor
54 fDecayer = new AliDecayerPythia();
65 if (!AliPythiaRndm::GetPythiaRandom())
66 AliPythiaRndm::SetPythiaRandom(GetRandom());
69 AliGenPythia::AliGenPythia(Int_t npart)
72 // default charm production at 5. 5 TeV
74 // structure function GRVHO
77 fTitle= "Particle Generator using PYTHIA";
85 fDecayer = new AliDecayerPythia();
86 // Set random number generator
87 if (!AliPythiaRndm::GetPythiaRandom())
88 AliPythiaRndm::SetPythiaRandom(GetRandom());
91 fParticles = new TClonesArray("TParticle",1000);
99 SetJetReconstructionMode();
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;
110 SetPycellParameters();
114 AliGenPythia::AliGenPythia(const AliGenPythia & Pythia)
121 AliGenPythia::~AliGenPythia()
126 void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
127 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
129 // Set pycell parameters
130 fPycellEtaMax = etamax;
133 fPycellThreshold = thresh;
134 fPycellEtSeed = etseed;
135 fPycellMinEtJet = minet;
136 fPycellMaxRadius = r;
141 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
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;
150 void AliGenPythia::Init()
154 SetMC(AliPythia::Instance());
155 fPythia=(AliPythia*) fMCEvGen;
158 fParentWeight=1./Float_t(fNpart);
160 // Forward Paramters to the AliPythia object
161 fDecayer->SetForceDecay(fForceDecay);
165 fPythia->SetCKIN(3,fPtHardMin);
166 fPythia->SetCKIN(4,fPtHardMax);
167 fPythia->SetCKIN(7,fYHardMin);
168 fPythia->SetCKIN(8,fYHardMax);
170 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget);
172 if (fFragmentation) {
173 fPythia->SetMSTP(111,1);
175 fPythia->SetMSTP(111,0);
179 // initial state radiation
180 fPythia->SetMSTP(61,fGinit);
181 // final state radiation
182 fPythia->SetMSTP(71,fGfinal);
185 fPythia->SetMSTP(91,1);
186 fPythia->SetPARP(91,fPtKick);
188 fPythia->SetMSTP(91,0);
191 // fPythia->SetMSTJ(1,2);
193 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
195 // Parent and Children Selection
199 case kPyCharmUnforced:
200 case kPyCharmPbPbMNR:
203 fParentSelect[0] = 411;
204 fParentSelect[1] = 421;
205 fParentSelect[2] = 431;
206 fParentSelect[3] = 4122;
212 fParentSelect[0] = 421;
215 case kPyDPlusPbPbMNR:
218 fParentSelect[0] = 411;
222 case kPyBeautyPbPbMNR:
223 case kPyBeautypPbMNR:
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;
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;
246 fParentSelect[0] = 443;
256 // JetFinder for Trigger
258 // Configure detector (EMCAL like)
260 fPythia->SetPARU(51, fPycellEtaMax);
261 fPythia->SetMSTU(51, fPycellNEta);
262 fPythia->SetMSTU(52, fPycellNPhi);
264 // Configure Jet Finder
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);
272 // This counts the total number of calls to Pyevnt() per run.
287 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
291 fPythia->InitQuenching(0., 0.1, 6.e5, 0);
296 void AliGenPythia::Generate()
298 // Generate one event
300 fDecayer->ForceDecay();
302 Float_t polar[3] = {0,0,0};
303 Float_t origin[3] = {0,0,0};
305 // converts from mm/c to s
306 const Float_t kconv=0.001/2.999792458e8;
314 // Set collision vertex position
315 if (fVertexSmear == kPerEvent) Vertex();
321 // If quenching option has been selected switch off fragmentation first
324 fPythia->SetMSTJ(1, 0);
332 // Run quenching routine
335 // fPythia->Pylist(1);
337 // Switch fragmentation on
338 fPythia->SetMSTJ(1, 1);
340 // .. and perform fragmentation
342 // fPythia->Pylist(1);
347 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
348 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
352 fPythia->ImportParticles(fParticles,"All");
359 Int_t np = fParticles->GetEntriesFast();
360 if (np == 0 ) continue;
364 Int_t* pParent = new Int_t[np];
365 Int_t* pSelected = new Int_t[np];
366 Int_t* trackIt = new Int_t[np];
367 for (i=0; i< np; i++) {
373 Int_t nc = 0; // Total n. of selected particles
374 Int_t nParents = 0; // Selected parents
375 Int_t nTkbles = 0; // Trackable particles
376 if (fProcess != kPyMb && fProcess != kPyJets &&
377 fProcess != kPyDirectGamma &&
378 fProcess != kPyMbNonDiffr) {
380 for (i = 0; i<np; i++) {
381 TParticle* iparticle = (TParticle *) fParticles->At(i);
382 Int_t ks = iparticle->GetStatusCode();
383 kf = CheckPDGCode(iparticle->GetPdgCode());
384 // No initial state partons
385 if (ks==21) continue;
387 // Heavy Flavor Selection
393 if (kfl > 10) kfl/=100;
395 if (kfl > 10) kfl/=10;
396 if (kfl > 10) kfl/=10;
398 Int_t ipa = iparticle->GetFirstMother()-1;
402 TParticle * mother = (TParticle *) fParticles->At(ipa);
403 kfMo = TMath::Abs(mother->GetPdgCode());
405 // What to keep in Stack?
406 Bool_t flavorOK = kFALSE;
407 Bool_t selectOK = kFALSE;
409 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
411 if (kfl > fFlavorSelect) {
415 if (kfl == fFlavorSelect) flavorOK = kTRUE;
417 switch (fStackFillOpt) {
418 case kFlavorSelection:
421 case kParentSelection:
422 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
425 if (flavorOK && selectOK) {
427 // Heavy flavor hadron or quark
429 // Kinematic seletion on final state heavy flavor mesons
430 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
435 if (ParentSelected(kf)) ++nParents; // Update parent count
436 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
438 // Kinematic seletion on decay products
439 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
440 && !KinematicSelection(iparticle, 1))
446 // Select if mother was selected and is not tracked
448 if (pSelected[ipa] &&
449 !trackIt[ipa] && // mother will be tracked ?
450 kfMo != 5 && // mother is b-quark, don't store fragments
451 kfMo != 4 && // mother is c-quark, don't store fragments
452 kf != 92) // don't store string
455 // Semi-stable or de-selected: diselect decay products:
458 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
460 Int_t ipF = iparticle->GetFirstDaughter();
461 Int_t ipL = iparticle->GetLastDaughter();
462 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
464 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
465 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
468 if (pSelected[i] == -1) pSelected[i] = 0;
469 if (!pSelected[i]) continue;
470 // Count quarks only if you did not include fragmentation
471 if (fFragmentation && kf <= 10) continue;
473 // Decision on tracking
476 // Track final state particle
477 if (ks == 1) trackIt[i] = 1;
478 // Track semi-stable particles
479 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
480 // Track particles selected by process if undecayed.
481 if (fForceDecay == kNoDecay) {
482 if (ParentSelected(kf)) trackIt[i] = 1;
484 if (ParentSelected(kf)) trackIt[i] = 0;
486 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
490 } // particle selection loop
492 for (i = 0; i<np; i++) {
493 if (!pSelected[i]) continue;
494 TParticle * iparticle = (TParticle *) fParticles->At(i);
495 kf = CheckPDGCode(iparticle->GetPdgCode());
496 Int_t ks = iparticle->GetStatusCode();
497 p[0] = iparticle->Px();
498 p[1] = iparticle->Py();
499 p[2] = iparticle->Pz();
500 p[3] = iparticle->Energy();
502 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
503 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
504 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
506 Float_t tof = kconv*iparticle->T();
507 Int_t ipa = iparticle->GetFirstMother()-1;
508 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
510 PushTrack(fTrackIt*trackIt[i], iparent, kf,
511 p[0], p[1], p[2], p[3],
512 origin[0], origin[1], origin[2], tof,
513 polar[0], polar[1], polar[2],
514 kPPrimary, nt, 1., ks);
523 if (pParent) delete[] pParent;
524 if (pSelected) delete[] pSelected;
525 if (trackIt) delete[] trackIt;
528 switch (fCountMode) {
530 // printf(" Count all \n");
534 // printf(" Count parents \n");
537 case kCountTrackables:
538 // printf(" Count trackable \n");
542 if (jev >= fNpart || fNpart == -1) {
543 fKineBias=Float_t(fNpart)/Float_t(fTrials);
544 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
546 fQ += fPythia->GetVINT(51);
547 fX1 += fPythia->GetVINT(41);
548 fX2 += fPythia->GetVINT(42);
549 fTrialsRun += fTrials;
556 SetHighWaterMark(nt);
557 // adjust weight due to kinematic selection
560 fXsection=fPythia->GetPARI(1);
563 Int_t AliGenPythia::GenerateMB()
566 // Min Bias selection and other global selections
568 Int_t i, kf, nt, iparent;
571 Float_t polar[3] = {0,0,0};
572 Float_t origin[3] = {0,0,0};
573 // converts from mm/c to s
574 const Float_t kconv=0.001/2.999792458e8;
576 Int_t np = fParticles->GetEntriesFast();
577 Int_t* pParent = new Int_t[np];
578 for (i=0; i< np; i++) pParent[i] = -1;
579 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
580 TParticle* jet1 = (TParticle *) fParticles->At(6);
581 TParticle* jet2 = (TParticle *) fParticles->At(7);
582 if (!CheckTrigger(jet1, jet2)) return 0;
585 for (i = 0; i<np; i++) {
587 TParticle * iparticle = (TParticle *) fParticles->At(i);
588 kf = CheckPDGCode(iparticle->GetPdgCode());
589 Int_t ks = iparticle->GetStatusCode();
590 Int_t km = iparticle->GetFirstMother();
591 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
593 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
595 if (ks == 1) trackIt = 1;
596 Int_t ipa = iparticle->GetFirstMother()-1;
598 iparent = (ipa > -1) ? pParent[ipa] : -1;
601 // store track information
602 p[0] = iparticle->Px();
603 p[1] = iparticle->Py();
604 p[2] = iparticle->Pz();
605 p[3] = iparticle->Energy();
608 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
609 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
610 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
612 Float_t tof=kconv*iparticle->T();
614 PushTrack(fTrackIt*trackIt, iparent, kf,
615 p[0], p[1], p[2], p[3],
616 origin[0], origin[1], origin[2], tof,
617 polar[0], polar[1], polar[2],
618 kPPrimary, nt, 1., ks);
624 if (pParent) delete[] pParent;
626 printf("\n I've put %i particles on the stack \n",nc);
631 void AliGenPythia::FinishRun()
633 // Print x-section summary
638 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
639 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
644 void AliGenPythia::AdjustWeights()
646 // Adjust the weights after generation of all events
650 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
651 for (Int_t i=0; i<ntrack; i++) {
652 part= gAlice->GetMCApp()->Particle(i);
653 part->SetWeight(part->GetWeight()*fKineBias);
658 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
660 // Treat protons as inside nuclei with mass numbers a1 and a2
668 void AliGenPythia::MakeHeader()
670 // Builds the event header, to be called after each event
671 if (fHeader) delete fHeader;
672 fHeader = new AliGenPythiaEventHeader("Pythia");
675 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
678 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
681 fHeader->SetPrimaryVertex(fVertex);
683 // Jets that have triggered
684 if (fProcess == kPyJets)
688 GetJets(njet, ntrig, jets);
690 for (Int_t i = 0; i < ntrig; i++) {
691 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
695 if (gAlice) gAlice->SetGenEventHeader(fHeader);
699 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
701 // Check the kinematic trigger condition
704 eta[0] = jet1->Eta();
705 eta[1] = jet2->Eta();
707 phi[0] = jet1->Phi();
708 phi[1] = jet2->Phi();
710 pdg[0] = jet1->GetPdgCode();
711 pdg[1] = jet2->GetPdgCode();
712 Bool_t triggered = kFALSE;
714 if (fProcess == kPyJets) {
719 // Use Pythia clustering on parton level to determine jet axis
721 GetJets(njets, ntrig, jets);
723 if (ntrig) triggered = kTRUE;
728 if (pdg[0] == kGamma) {
732 //Check eta range first...
733 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
734 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
736 //Eta is okay, now check phi range
737 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
738 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
747 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
749 // Assignment operator
754 void AliGenPythia::LoadEvent(AliStack* stack, Int_t flag)
757 // Load event into Pythia Common Block
760 // AliRunLoader* rl = AliRunLoader::GetRunLoader();
761 Int_t npart = stack -> GetNprimary();
765 (fPythia->GetPyjets())->N = npart;
767 n0 = (fPythia->GetPyjets())->N;
768 (fPythia->GetPyjets())->N = n0 + npart;
772 for (Int_t part = 0; part < npart; part++) {
773 TParticle *MPart = stack->Particle(part);
775 Int_t kf = MPart->GetPdgCode();
776 Int_t ks = MPart->GetStatusCode();
778 Float_t px = MPart->Px();
779 Float_t py = MPart->Py();
780 Float_t pz = MPart->Pz();
781 Float_t e = MPart->Energy();
782 Float_t m = MPart->GetCalcMass();
785 (fPythia->GetPyjets())->P[0][part+n0] = px;
786 (fPythia->GetPyjets())->P[1][part+n0] = py;
787 (fPythia->GetPyjets())->P[2][part+n0] = pz;
788 (fPythia->GetPyjets())->P[3][part+n0] = e;
789 (fPythia->GetPyjets())->P[4][part+n0] = m;
791 (fPythia->GetPyjets())->K[1][part+n0] = kf;
792 (fPythia->GetPyjets())->K[0][part+n0] = ks;
796 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
799 // Calls the Pythia jet finding algorithm to find jets in the current event
804 Int_t n = fPythia->GetN();
808 fPythia->Pycell(njets);
810 for (i = 0; i < njets; i++) {
811 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
812 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
813 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
814 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
825 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
828 // Calls the Pythia clustering algorithm to find jets in the current event
830 Int_t n = fPythia->GetN();
833 if (fJetReconstruction == kCluster) {
835 // Configure cluster algorithm
837 fPythia->SetPARU(43, 2.);
838 fPythia->SetMSTU(41, 1);
840 // Call cluster algorithm
842 fPythia->Pyclus(nJets);
844 // Loading jets from common block
850 fPythia->Pycell(nJets);
854 for (i = 0; i < nJets; i++) {
855 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
856 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
857 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
858 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
859 Float_t pt = TMath::Sqrt(px * px + py * py);
860 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
861 Float_t theta = TMath::ATan2(pt,pz);
862 Float_t et = e * TMath::Sin(theta);
863 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
866 eta > fEtaMinJet && eta < fEtaMaxJet &&
867 phi > fPhiMinJet && phi < fPhiMaxJet &&
868 et > fEtMinJet && et < fEtMaxJet
871 jets[0][nJetsTrig] = px;
872 jets[1][nJetsTrig] = py;
873 jets[2][nJetsTrig] = pz;
874 jets[3][nJetsTrig] = e;
878 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
885 void AliGenPythia::Streamer(TBuffer &R__b)
887 // Stream an object of class AliGenPythia.
889 if (R__b.IsReading()) {
890 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
891 AliGenerator::Streamer(R__b);
892 R__b >> (Int_t&)fProcess;
893 R__b >> (Int_t&)fStrucFunc;
894 R__b >> (Int_t&)fForceDecay;
898 fParentSelect.Streamer(R__b);
899 fChildSelect.Streamer(R__b);
901 // (AliPythia::Instance())->Streamer(R__b);
904 // if (fDecayer) fDecayer->Streamer(R__b);
906 R__b.WriteVersion(AliGenPythia::IsA());
907 AliGenerator::Streamer(R__b);
908 R__b << (Int_t)fProcess;
909 R__b << (Int_t)fStrucFunc;
910 R__b << (Int_t)fForceDecay;
914 fParentSelect.Streamer(R__b);
915 fChildSelect.Streamer(R__b);
920 // fDecayer->Streamer(R__b);