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;
157 fParentWeight=1./Float_t(fNpart);
159 // Forward Paramters to the AliPythia object
160 fDecayer->SetForceDecay(fForceDecay);
164 fPythia->SetCKIN(3,fPtHardMin);
165 fPythia->SetCKIN(4,fPtHardMax);
166 fPythia->SetCKIN(7,fYHardMin);
167 fPythia->SetCKIN(8,fYHardMax);
169 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget);
171 if (fFragmentation) {
172 fPythia->SetMSTP(111,1);
174 fPythia->SetMSTP(111,0);
178 // initial state radiation
179 fPythia->SetMSTP(61,fGinit);
180 // final state radiation
181 fPythia->SetMSTP(71,fGfinal);
184 fPythia->SetMSTP(91,1);
185 fPythia->SetPARP(91,fPtKick);
187 fPythia->SetMSTP(91,0);
190 // fPythia->SetMSTJ(1,2);
192 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
194 // Parent and Children Selection
198 case kPyCharmUnforced:
199 case kPyCharmPbPbMNR:
202 fParentSelect[0] = 411;
203 fParentSelect[1] = 421;
204 fParentSelect[2] = 431;
205 fParentSelect[3] = 4122;
211 fParentSelect[0] = 421;
215 case kPyBeautyPbPbMNR:
216 case kPyBeautypPbMNR:
218 fParentSelect[0]= 511;
219 fParentSelect[1]= 521;
220 fParentSelect[2]= 531;
221 fParentSelect[3]= 5122;
222 fParentSelect[4]= 5132;
223 fParentSelect[5]= 5232;
224 fParentSelect[6]= 5332;
227 case kPyBeautyUnforced:
228 fParentSelect[0] = 511;
229 fParentSelect[1] = 521;
230 fParentSelect[2] = 531;
231 fParentSelect[3] = 5122;
232 fParentSelect[4] = 5132;
233 fParentSelect[5] = 5232;
234 fParentSelect[6] = 5332;
239 fParentSelect[0] = 443;
249 // JetFinder for Trigger
251 // Configure detector (EMCAL like)
253 fPythia->SetPARU(51, fPycellEtaMax);
254 fPythia->SetMSTU(51, fPycellNEta);
255 fPythia->SetMSTU(52, fPycellNPhi);
257 // Configure Jet Finder
259 fPythia->SetPARU(58, fPycellThreshold);
260 fPythia->SetPARU(52, fPycellEtSeed);
261 fPythia->SetPARU(53, fPycellMinEtJet);
262 fPythia->SetPARU(54, fPycellMaxRadius);
263 fPythia->SetMSTU(54, 2);
265 // This counts the total number of calls to Pyevnt() per run.
280 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
284 void AliGenPythia::Generate()
286 // Generate one event
288 fDecayer->ForceDecay();
290 Float_t polar[3] = {0,0,0};
291 Float_t origin[3] = {0,0,0};
293 // converts from mm/c to s
294 const Float_t kconv=0.001/2.999792458e8;
301 // Set collision vertex position
302 if(fVertexSmear==kPerEvent) {
303 fPythia->SetMSTP(151,1);
305 fPythia->SetPARP(151+j, fOsigma[j]*10.);
307 } else if (fVertexSmear==kPerTrack) {
308 fPythia->SetMSTP(151,0);
314 fPythia->SetMSTJ(1, 0);
321 fPythia->SetMSTJ(1, 1);
326 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
327 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
330 fPythia->ImportParticles(fParticles,"All");
338 Int_t np = fParticles->GetEntriesFast();
339 if (np == 0 ) continue;
340 // Get event vertex and discard the event if the Z coord. is too big
341 TParticle *iparticle = (TParticle *) fParticles->At(0);
342 Float_t distz = iparticle->Vz()/10.;
343 if(TMath::Abs(distz)>fCutVertexZ*fOsigma[2]) continue;
345 fVertex[0] = iparticle->Vx()/10.+fOrigin.At(0);
346 fVertex[1] = iparticle->Vy()/10.+fOrigin.At(1);
347 fVertex[2] = iparticle->Vz()/10.+fOrigin.At(2);
349 Int_t* pParent = new Int_t[np];
350 Int_t* pSelected = new Int_t[np];
351 Int_t* trackIt = new Int_t[np];
352 for (i=0; i< np; i++) {
358 Int_t nc = 0; // Total n. of selected particles
359 Int_t nParents = 0; // Selected parents
360 Int_t nTkbles = 0; // Trackable particles
361 if (fProcess != kPyMb && fProcess != kPyJets &&
362 fProcess != kPyDirectGamma &&
363 fProcess != kPyMbNonDiffr) {
365 for (i = 0; i<np; i++) {
366 iparticle = (TParticle *) fParticles->At(i);
367 Int_t ks = iparticle->GetStatusCode();
368 kf = CheckPDGCode(iparticle->GetPdgCode());
369 // No initial state partons
370 if (ks==21) continue;
372 // Heavy Flavor Selection
378 if (kfl > 10) kfl/=100;
380 if (kfl > 10) kfl/=10;
381 if (kfl > 10) kfl/=10;
383 Int_t ipa = iparticle->GetFirstMother()-1;
387 TParticle * mother = (TParticle *) fParticles->At(ipa);
388 kfMo = TMath::Abs(mother->GetPdgCode());
390 // What to keep in Stack?
391 Bool_t flavorOK = kFALSE;
392 Bool_t selectOK = kFALSE;
394 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
396 if (kfl > fFlavorSelect) {
400 if (kfl == fFlavorSelect) flavorOK = kTRUE;
402 switch (fStackFillOpt) {
403 case kFlavorSelection:
406 case kParentSelection:
407 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
410 if (flavorOK && selectOK) {
412 // Heavy flavor hadron or quark
414 // Kinematic seletion on final state heavy flavor mesons
415 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
420 if (ParentSelected(kf)) ++nParents; // Update parent count
421 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
423 // Kinematic seletion on decay products
424 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
425 && !KinematicSelection(iparticle, 1))
431 // Select if mother was selected and is not tracked
433 if (pSelected[ipa] &&
434 !trackIt[ipa] && // mother will be tracked ?
435 kfMo != 5 && // mother is b-quark, don't store fragments
436 kfMo != 4 && // mother is c-quark, don't store fragments
437 kf != 92) // don't store string
440 // Semi-stable or de-selected: diselect decay products:
443 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
445 Int_t ipF = iparticle->GetFirstDaughter();
446 Int_t ipL = iparticle->GetLastDaughter();
447 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
449 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
450 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
453 if (pSelected[i] == -1) pSelected[i] = 0;
454 if (!pSelected[i]) continue;
455 // Count quarks only if you did not include fragmentation
456 if (fFragmentation && kf <= 10) continue;
458 // Decision on tracking
461 // Track final state particle
462 if (ks == 1) trackIt[i] = 1;
463 // Track semi-stable particles
464 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
465 // Track particles selected by process if undecayed.
466 if (fForceDecay == kNoDecay) {
467 if (ParentSelected(kf)) trackIt[i] = 1;
469 if (ParentSelected(kf)) trackIt[i] = 0;
471 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
475 } // particle selection loop
477 for (i = 0; i<np; i++) {
478 if (!pSelected[i]) continue;
479 TParticle * iparticle = (TParticle *) fParticles->At(i);
480 kf = CheckPDGCode(iparticle->GetPdgCode());
481 Int_t ks = iparticle->GetStatusCode();
482 p[0] = iparticle->Px();
483 p[1] = iparticle->Py();
484 p[2] = iparticle->Pz();
485 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
486 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
487 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
488 Float_t tof = kconv*iparticle->T();
489 Int_t ipa = iparticle->GetFirstMother()-1;
490 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
491 PushTrack(fTrackIt*trackIt[i] ,
492 iparent, kf, p, origin, polar, tof, kPPrimary, nt, 1., ks);
501 if (pParent) delete[] pParent;
502 if (pSelected) delete[] pSelected;
503 if (trackIt) delete[] trackIt;
506 switch (fCountMode) {
508 // printf(" Count all \n");
512 // printf(" Count parents \n");
515 case kCountTrackables:
516 // printf(" Count trackable \n");
520 if (jev >= fNpart || fNpart == -1) {
521 fKineBias=Float_t(fNpart)/Float_t(fTrials);
522 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
524 fQ += fPythia->GetVINT(51);
525 fX1 += fPythia->GetVINT(41);
526 fX2 += fPythia->GetVINT(42);
527 fTrialsRun += fTrials;
534 SetHighWaterMark(nt);
535 // adjust weight due to kinematic selection
538 fXsection=fPythia->GetPARI(1);
541 Int_t AliGenPythia::GenerateMB()
544 // Min Bias selection and other global selections
546 Int_t i, kf, nt, iparent;
549 Float_t polar[3] = {0,0,0};
550 Float_t origin[3] = {0,0,0};
551 // converts from mm/c to s
552 const Float_t kconv=0.001/2.999792458e8;
554 Int_t np = fParticles->GetEntriesFast();
555 Int_t* pParent = new Int_t[np];
556 for (i=0; i< np; i++) pParent[i] = -1;
557 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
558 TParticle* jet1 = (TParticle *) fParticles->At(6);
559 TParticle* jet2 = (TParticle *) fParticles->At(7);
560 if (!CheckTrigger(jet1, jet2)) return 0;
563 for (i = 0; i<np; i++) {
565 TParticle * iparticle = (TParticle *) fParticles->At(i);
566 kf = CheckPDGCode(iparticle->GetPdgCode());
567 Int_t ks = iparticle->GetStatusCode();
568 Int_t km = iparticle->GetFirstMother();
569 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
571 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
573 if (ks == 1) trackIt = 1;
574 Int_t ipa = iparticle->GetFirstMother()-1;
576 iparent = (ipa > -1) ? pParent[ipa] : -1;
579 // store track information
580 p[0] = iparticle->Px();
581 p[1] = iparticle->Py();
582 p[2] = iparticle->Pz();
583 origin[0] = fOrigin[0]+iparticle->Vx()/10.;
584 origin[1] = fOrigin[1]+iparticle->Vy()/10.;
585 origin[2] = fOrigin[2]+iparticle->Vz()/10.;
586 Float_t tof=kconv*iparticle->T();
587 PushTrack(fTrackIt*trackIt, iparent, kf, p, origin, polar,
588 tof, kPPrimary, nt, 1., ks);
594 if (pParent) delete[] pParent;
596 printf("\n I've put %i particles on the stack \n",nc);
601 void AliGenPythia::FinishRun()
603 // Print x-section summary
608 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
609 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
614 void AliGenPythia::AdjustWeights()
616 // Adjust the weights after generation of all events
619 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
620 for (Int_t i=0; i<ntrack; i++) {
621 part= gAlice->GetMCApp()->Particle(i);
622 part->SetWeight(part->GetWeight()*fKineBias);
626 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
628 // Treat protons as inside nuclei with mass numbers a1 and a2
636 void AliGenPythia::MakeHeader()
638 // Builds the event header, to be called after each event
639 if (fHeader) delete fHeader;
640 fHeader = new AliGenPythiaEventHeader("Pythia");
643 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
646 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
649 fHeader->SetPrimaryVertex(fVertex);
651 // Jets that have triggered
652 if (fProcess == kPyJets)
656 GetJets(njet, ntrig, jets);
658 for (Int_t i = 0; i < ntrig; i++) {
659 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
663 gAlice->SetGenEventHeader(fHeader);
667 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
669 // Check the kinematic trigger condition
672 eta[0] = jet1->Eta();
673 eta[1] = jet2->Eta();
675 phi[0] = jet1->Phi();
676 phi[1] = jet2->Phi();
678 pdg[0] = jet1->GetPdgCode();
679 pdg[1] = jet2->GetPdgCode();
680 Bool_t triggered = kFALSE;
682 if (fProcess == kPyJets) {
687 // Use Pythia clustering on parton level to determine jet axis
689 GetJets(njets, ntrig, jets);
691 if (ntrig) triggered = kTRUE;
696 if (pdg[0] == kGamma) {
700 //Check eta range first...
701 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
702 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
704 //Eta is okay, now check phi range
705 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
706 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
715 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
717 // Assignment operator
722 void AliGenPythia::LoadEvent()
725 // Load event into Pythia Common Block
728 AliRunLoader* rl = AliRunLoader::GetRunLoader();
729 Int_t npart = (rl->Stack())-> GetNprimary();
730 (fPythia->GetPyjets())->N = npart;
732 for (Int_t part = 0; part < npart; part++) {
733 TParticle *MPart = (rl->Stack())->Particle(part);
734 Int_t kf = MPart->GetPdgCode();
735 Int_t ks = MPart->GetStatusCode();
736 Float_t px = MPart->Px();
737 Float_t py = MPart->Py();
738 Float_t pz = MPart->Pz();
739 Float_t e = MPart->Energy();
740 Float_t p = TMath::Sqrt(px * px + py * py + pz * pz);
741 Float_t m = TMath::Sqrt(e * e - p * p);
744 (fPythia->GetPyjets())->P[0][part] = px;
745 (fPythia->GetPyjets())->P[1][part] = py;
746 (fPythia->GetPyjets())->P[2][part] = pz;
747 (fPythia->GetPyjets())->P[3][part] = e;
748 (fPythia->GetPyjets())->P[4][part] = m;
750 (fPythia->GetPyjets())->K[1][part] = kf;
751 (fPythia->GetPyjets())->K[0][part] = ks;
755 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
758 // Calls the Pythia jet finding algorithm to find jets in the current event
763 Int_t n = fPythia->GetN();
767 fPythia->Pycell(njets);
769 for (i = 0; i < njets; i++) {
770 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
771 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
772 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
773 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
784 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
787 // Calls the Pythia clustering algorithm to find jets in the current event
789 Int_t n = fPythia->GetN();
792 if (fJetReconstruction == kCluster) {
794 // Configure cluster algorithm
796 fPythia->SetPARU(43, 2.);
797 fPythia->SetMSTU(41, 1);
799 // Call cluster algorithm
801 fPythia->Pyclus(nJets);
803 // Loading jets from common block
809 fPythia->Pycell(nJets);
813 for (i = 0; i < nJets; i++) {
814 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
815 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
816 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
817 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
818 Float_t pt = TMath::Sqrt(px * px + py * py);
819 Float_t phi = TMath::ATan2(py,px);
820 Float_t theta = TMath::ATan2(pt,pz);
821 Float_t et = e * TMath::Sin(theta);
822 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
825 eta > fEtaMinJet && eta < fEtaMaxJet &&
826 phi > fPhiMinJet && phi < fPhiMaxJet &&
827 et > fEtMinJet && et < fEtMaxJet
830 jets[0][nJetsTrig] = px;
831 jets[1][nJetsTrig] = py;
832 jets[2][nJetsTrig] = pz;
833 jets[3][nJetsTrig] = e;
837 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
844 void AliGenPythia::Streamer(TBuffer &R__b)
846 // Stream an object of class AliGenPythia.
848 if (R__b.IsReading()) {
849 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
850 AliGenerator::Streamer(R__b);
851 R__b >> (Int_t&)fProcess;
852 R__b >> (Int_t&)fStrucFunc;
853 R__b >> (Int_t&)fForceDecay;
857 fParentSelect.Streamer(R__b);
858 fChildSelect.Streamer(R__b);
860 // (AliPythia::Instance())->Streamer(R__b);
863 // if (fDecayer) fDecayer->Streamer(R__b);
865 R__b.WriteVersion(AliGenPythia::IsA());
866 AliGenerator::Streamer(R__b);
867 R__b << (Int_t)fProcess;
868 R__b << (Int_t)fStrucFunc;
869 R__b << (Int_t)fForceDecay;
873 fParentSelect.Streamer(R__b);
874 fChildSelect.Streamer(R__b);
879 // fDecayer->Streamer(R__b);