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;
156 printf("Pythia Init %p", fPythia);
159 fParentWeight=1./Float_t(fNpart);
161 // Forward Paramters to the AliPythia object
162 fDecayer->SetForceDecay(fForceDecay);
166 fPythia->SetCKIN(3,fPtHardMin);
167 fPythia->SetCKIN(4,fPtHardMax);
168 fPythia->SetCKIN(7,fYHardMin);
169 fPythia->SetCKIN(8,fYHardMax);
171 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget);
173 if (fFragmentation) {
174 fPythia->SetMSTP(111,1);
176 fPythia->SetMSTP(111,0);
180 // initial state radiation
181 fPythia->SetMSTP(61,fGinit);
182 // final state radiation
183 fPythia->SetMSTP(71,fGfinal);
186 fPythia->SetMSTP(91,1);
187 fPythia->SetPARP(91,fPtKick);
189 fPythia->SetMSTP(91,0);
192 // fPythia->SetMSTJ(1,2);
194 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
196 // Parent and Children Selection
200 case kPyCharmUnforced:
201 case kPyCharmPbPbMNR:
204 fParentSelect[0] = 411;
205 fParentSelect[1] = 421;
206 fParentSelect[2] = 431;
207 fParentSelect[3] = 4122;
213 fParentSelect[0] = 421;
217 case kPyBeautyPbPbMNR:
218 case kPyBeautypPbMNR:
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;
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;
241 fParentSelect[0] = 443;
251 // JetFinder for Trigger
253 // Configure detector (EMCAL like)
255 fPythia->SetPARU(51, fPycellEtaMax);
256 fPythia->SetMSTU(51, fPycellNEta);
257 fPythia->SetMSTU(52, fPycellNPhi);
259 // Configure Jet Finder
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);
267 // This counts the total number of calls to Pyevnt() per run.
282 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
286 void AliGenPythia::Generate()
288 // Generate one event
290 fDecayer->ForceDecay();
292 Float_t polar[3] = {0,0,0};
293 Float_t origin[3] = {0,0,0};
295 // converts from mm/c to s
296 const Float_t kconv=0.001/2.999792458e8;
303 // Set collision vertex position
304 if(fVertexSmear==kPerEvent) {
305 fPythia->SetMSTP(151,1);
307 fPythia->SetPARP(151+j, fOsigma[j]*10.);
309 } else if (fVertexSmear==kPerTrack) {
310 fPythia->SetMSTP(151,0);
316 fPythia->SetMSTJ(1, 0);
318 printf("Pythia pyevnt %p", fPythia);
323 fPythia->SetMSTJ(1, 1);
328 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
329 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
333 printf("Pythia import t %p %p ", fPythia, fParticles);
334 fPythia->ImportParticles(fParticles,"All");
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;
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);
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++) {
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) {
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;
376 // Heavy Flavor Selection
382 if (kfl > 10) kfl/=100;
384 if (kfl > 10) kfl/=10;
385 if (kfl > 10) kfl/=10;
387 Int_t ipa = iparticle->GetFirstMother()-1;
391 TParticle * mother = (TParticle *) fParticles->At(ipa);
392 kfMo = TMath::Abs(mother->GetPdgCode());
394 // What to keep in Stack?
395 Bool_t flavorOK = kFALSE;
396 Bool_t selectOK = kFALSE;
398 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
400 if (kfl > fFlavorSelect) {
404 if (kfl == fFlavorSelect) flavorOK = kTRUE;
406 switch (fStackFillOpt) {
407 case kFlavorSelection:
410 case kParentSelection:
411 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
414 if (flavorOK && selectOK) {
416 // Heavy flavor hadron or quark
418 // Kinematic seletion on final state heavy flavor mesons
419 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
424 if (ParentSelected(kf)) ++nParents; // Update parent count
425 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
427 // Kinematic seletion on decay products
428 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
429 && !KinematicSelection(iparticle, 1))
435 // Select if mother was selected and is not tracked
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
444 // Semi-stable or de-selected: diselect decay products:
447 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
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;
453 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
454 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
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;
462 // Decision on tracking
465 // Track final state particle
466 if (ks == 1) trackIt[i] = 1;
467 // Track semi-stable particles
468 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
469 // Track particles selected by process if undecayed.
470 if (fForceDecay == kNoDecay) {
471 if (ParentSelected(kf)) trackIt[i] = 1;
473 if (ParentSelected(kf)) trackIt[i] = 0;
475 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
479 } // particle selection loop
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();
489 p[3] = iparticle->Energy();
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;
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);
511 if (pParent) delete[] pParent;
512 if (pSelected) delete[] pSelected;
513 if (trackIt) delete[] trackIt;
516 switch (fCountMode) {
518 // printf(" Count all \n");
522 // printf(" Count parents \n");
525 case kCountTrackables:
526 // printf(" Count trackable \n");
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);
534 fQ += fPythia->GetVINT(51);
535 fX1 += fPythia->GetVINT(41);
536 fX2 += fPythia->GetVINT(42);
537 fTrialsRun += fTrials;
544 SetHighWaterMark(nt);
545 // adjust weight due to kinematic selection
548 fXsection=fPythia->GetPARI(1);
551 Int_t AliGenPythia::GenerateMB()
554 // Min Bias selection and other global selections
556 Int_t i, kf, nt, iparent;
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;
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;
573 for (i = 0; i<np; i++) {
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)) ||
581 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
583 if (ks == 1) trackIt = 1;
584 Int_t ipa = iparticle->GetFirstMother()-1;
586 iparent = (ipa > -1) ? pParent[ipa] : -1;
589 // store track information
590 p[0] = iparticle->Px();
591 p[1] = iparticle->Py();
592 p[2] = iparticle->Pz();
593 p[3] = iparticle->Energy();
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();
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);
610 if (pParent) delete[] pParent;
612 printf("\n I've put %i particles on the stack \n",nc);
617 void AliGenPythia::FinishRun()
619 // Print x-section summary
624 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
625 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
630 void AliGenPythia::AdjustWeights()
632 // Adjust the weights after generation of all events
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);
644 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
646 // Treat protons as inside nuclei with mass numbers a1 and a2
654 void AliGenPythia::MakeHeader()
656 // Builds the event header, to be called after each event
657 if (fHeader) delete fHeader;
658 fHeader = new AliGenPythiaEventHeader("Pythia");
661 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
664 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
667 fHeader->SetPrimaryVertex(fVertex);
669 // Jets that have triggered
670 if (fProcess == kPyJets)
674 GetJets(njet, ntrig, jets);
676 for (Int_t i = 0; i < ntrig; i++) {
677 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
681 if (gAlice) gAlice->SetGenEventHeader(fHeader);
685 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
687 // Check the kinematic trigger condition
690 eta[0] = jet1->Eta();
691 eta[1] = jet2->Eta();
693 phi[0] = jet1->Phi();
694 phi[1] = jet2->Phi();
696 pdg[0] = jet1->GetPdgCode();
697 pdg[1] = jet2->GetPdgCode();
698 Bool_t triggered = kFALSE;
700 if (fProcess == kPyJets) {
705 // Use Pythia clustering on parton level to determine jet axis
707 GetJets(njets, ntrig, jets);
709 if (ntrig) triggered = kTRUE;
714 if (pdg[0] == kGamma) {
718 //Check eta range first...
719 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
720 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
722 //Eta is okay, now check phi range
723 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
724 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
733 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
735 // Assignment operator
740 void AliGenPythia::LoadEvent()
743 // Load event into Pythia Common Block
746 AliRunLoader* rl = AliRunLoader::GetRunLoader();
747 Int_t npart = (rl->Stack())-> GetNprimary();
748 (fPythia->GetPyjets())->N = npart;
750 for (Int_t part = 0; part < npart; part++) {
751 TParticle *MPart = (rl->Stack())->Particle(part);
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();
758 Float_t m = MPart->GetCalcMass();
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;
767 (fPythia->GetPyjets())->K[1][part] = kf;
768 (fPythia->GetPyjets())->K[0][part] = ks;
772 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
775 // Calls the Pythia jet finding algorithm to find jets in the current event
780 Int_t n = fPythia->GetN();
784 fPythia->Pycell(njets);
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];
801 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
804 // Calls the Pythia clustering algorithm to find jets in the current event
806 Int_t n = fPythia->GetN();
809 if (fJetReconstruction == kCluster) {
811 // Configure cluster algorithm
813 fPythia->SetPARU(43, 2.);
814 fPythia->SetMSTU(41, 1);
816 // Call cluster algorithm
818 fPythia->Pyclus(nJets);
820 // Loading jets from common block
826 fPythia->Pycell(nJets);
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);
836 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
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.));
842 eta > fEtaMinJet && eta < fEtaMaxJet &&
843 phi > fPhiMinJet && phi < fPhiMaxJet &&
844 et > fEtMinJet && et < fEtMaxJet
847 jets[0][nJetsTrig] = px;
848 jets[1][nJetsTrig] = py;
849 jets[2][nJetsTrig] = pz;
850 jets[3][nJetsTrig] = e;
854 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
861 void AliGenPythia::Streamer(TBuffer &R__b)
863 // Stream an object of class AliGenPythia.
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;
874 fParentSelect.Streamer(R__b);
875 fChildSelect.Streamer(R__b);
877 // (AliPythia::Instance())->Streamer(R__b);
880 // if (fDecayer) fDecayer->Streamer(R__b);
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;
890 fParentSelect.Streamer(R__b);
891 fChildSelect.Streamer(R__b);
896 // fDecayer->Streamer(R__b);