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;
216 case kPyBeautyPbPbMNR:
217 case kPyBeautypPbMNR:
219 fParentSelect[0]= 511;
220 fParentSelect[1]= 521;
221 fParentSelect[2]= 531;
222 fParentSelect[3]= 5122;
223 fParentSelect[4]= 5132;
224 fParentSelect[5]= 5232;
225 fParentSelect[6]= 5332;
228 case kPyBeautyUnforced:
229 fParentSelect[0] = 511;
230 fParentSelect[1] = 521;
231 fParentSelect[2] = 531;
232 fParentSelect[3] = 5122;
233 fParentSelect[4] = 5132;
234 fParentSelect[5] = 5232;
235 fParentSelect[6] = 5332;
240 fParentSelect[0] = 443;
250 // JetFinder for Trigger
252 // Configure detector (EMCAL like)
254 fPythia->SetPARU(51, fPycellEtaMax);
255 fPythia->SetMSTU(51, fPycellNEta);
256 fPythia->SetMSTU(52, fPycellNPhi);
258 // Configure Jet Finder
260 fPythia->SetPARU(58, fPycellThreshold);
261 fPythia->SetPARU(52, fPycellEtSeed);
262 fPythia->SetPARU(53, fPycellMinEtJet);
263 fPythia->SetPARU(54, fPycellMaxRadius);
264 fPythia->SetMSTU(54, 2);
266 // This counts the total number of calls to Pyevnt() per run.
281 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
285 fPythia->InitQuenching(0., 0.05, 1.45, 8., 1);
290 void AliGenPythia::Generate()
292 // Generate one event
294 fDecayer->ForceDecay();
296 Float_t polar[3] = {0,0,0};
297 Float_t origin[3] = {0,0,0};
299 // converts from mm/c to s
300 const Float_t kconv=0.001/2.999792458e8;
308 // Set collision vertex position
309 if (fVertexSmear == kPerEvent) Vertex();
315 // If quenching option has been selected switch off fragmentation first
318 fPythia->SetMSTJ(1, 0);
326 // Run quenching routine
329 // fPythia->Pylist(1);
331 // Switch fragmentation on
332 fPythia->SetMSTJ(1, 1);
334 // .. and perform fragmentation
336 // fPythia->Pylist(1);
341 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
342 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
346 fPythia->ImportParticles(fParticles,"All");
353 Int_t np = fParticles->GetEntriesFast();
354 if (np == 0 ) continue;
358 Int_t* pParent = new Int_t[np];
359 Int_t* pSelected = new Int_t[np];
360 Int_t* trackIt = new Int_t[np];
361 for (i=0; i< np; i++) {
367 Int_t nc = 0; // Total n. of selected particles
368 Int_t nParents = 0; // Selected parents
369 Int_t nTkbles = 0; // Trackable particles
370 if (fProcess != kPyMb && fProcess != kPyJets &&
371 fProcess != kPyDirectGamma &&
372 fProcess != kPyMbNonDiffr) {
374 for (i = 0; i<np; i++) {
375 TParticle* iparticle = (TParticle *) fParticles->At(i);
376 Int_t ks = iparticle->GetStatusCode();
377 kf = CheckPDGCode(iparticle->GetPdgCode());
378 // No initial state partons
379 if (ks==21) continue;
381 // Heavy Flavor Selection
387 if (kfl > 10) kfl/=100;
389 if (kfl > 10) kfl/=10;
390 if (kfl > 10) kfl/=10;
392 Int_t ipa = iparticle->GetFirstMother()-1;
396 TParticle * mother = (TParticle *) fParticles->At(ipa);
397 kfMo = TMath::Abs(mother->GetPdgCode());
399 // What to keep in Stack?
400 Bool_t flavorOK = kFALSE;
401 Bool_t selectOK = kFALSE;
403 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
405 if (kfl > fFlavorSelect) {
409 if (kfl == fFlavorSelect) flavorOK = kTRUE;
411 switch (fStackFillOpt) {
412 case kFlavorSelection:
415 case kParentSelection:
416 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
419 if (flavorOK && selectOK) {
421 // Heavy flavor hadron or quark
423 // Kinematic seletion on final state heavy flavor mesons
424 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
429 if (ParentSelected(kf)) ++nParents; // Update parent count
430 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
432 // Kinematic seletion on decay products
433 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
434 && !KinematicSelection(iparticle, 1))
440 // Select if mother was selected and is not tracked
442 if (pSelected[ipa] &&
443 !trackIt[ipa] && // mother will be tracked ?
444 kfMo != 5 && // mother is b-quark, don't store fragments
445 kfMo != 4 && // mother is c-quark, don't store fragments
446 kf != 92) // don't store string
449 // Semi-stable or de-selected: diselect decay products:
452 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
454 Int_t ipF = iparticle->GetFirstDaughter();
455 Int_t ipL = iparticle->GetLastDaughter();
456 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
458 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
459 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
462 if (pSelected[i] == -1) pSelected[i] = 0;
463 if (!pSelected[i]) continue;
464 // Count quarks only if you did not include fragmentation
465 if (fFragmentation && kf <= 10) continue;
467 // Decision on tracking
470 // Track final state particle
471 if (ks == 1) trackIt[i] = 1;
472 // Track semi-stable particles
473 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
474 // Track particles selected by process if undecayed.
475 if (fForceDecay == kNoDecay) {
476 if (ParentSelected(kf)) trackIt[i] = 1;
478 if (ParentSelected(kf)) trackIt[i] = 0;
480 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
484 } // particle selection loop
486 for (i = 0; i<np; i++) {
487 if (!pSelected[i]) continue;
488 TParticle * iparticle = (TParticle *) fParticles->At(i);
489 kf = CheckPDGCode(iparticle->GetPdgCode());
490 Int_t ks = iparticle->GetStatusCode();
491 p[0] = iparticle->Px();
492 p[1] = iparticle->Py();
493 p[2] = iparticle->Pz();
494 p[3] = iparticle->Energy();
496 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
497 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
498 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
500 Float_t tof = kconv*iparticle->T();
501 Int_t ipa = iparticle->GetFirstMother()-1;
502 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
504 PushTrack(fTrackIt*trackIt[i], iparent, kf,
505 p[0], p[1], p[2], p[3],
506 origin[0], origin[1], origin[2], tof,
507 polar[0], polar[1], polar[2],
508 kPPrimary, nt, 1., ks);
517 if (pParent) delete[] pParent;
518 if (pSelected) delete[] pSelected;
519 if (trackIt) delete[] trackIt;
522 switch (fCountMode) {
524 // printf(" Count all \n");
528 // printf(" Count parents \n");
531 case kCountTrackables:
532 // printf(" Count trackable \n");
536 if (jev >= fNpart || fNpart == -1) {
537 fKineBias=Float_t(fNpart)/Float_t(fTrials);
538 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
540 fQ += fPythia->GetVINT(51);
541 fX1 += fPythia->GetVINT(41);
542 fX2 += fPythia->GetVINT(42);
543 fTrialsRun += fTrials;
550 SetHighWaterMark(nt);
551 // adjust weight due to kinematic selection
554 fXsection=fPythia->GetPARI(1);
557 Int_t AliGenPythia::GenerateMB()
560 // Min Bias selection and other global selections
562 Int_t i, kf, nt, iparent;
565 Float_t polar[3] = {0,0,0};
566 Float_t origin[3] = {0,0,0};
567 // converts from mm/c to s
568 const Float_t kconv=0.001/2.999792458e8;
570 Int_t np = fParticles->GetEntriesFast();
571 Int_t* pParent = new Int_t[np];
572 for (i=0; i< np; i++) pParent[i] = -1;
573 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
574 TParticle* jet1 = (TParticle *) fParticles->At(6);
575 TParticle* jet2 = (TParticle *) fParticles->At(7);
576 if (!CheckTrigger(jet1, jet2)) return 0;
579 for (i = 0; i<np; i++) {
581 TParticle * iparticle = (TParticle *) fParticles->At(i);
582 kf = CheckPDGCode(iparticle->GetPdgCode());
583 Int_t ks = iparticle->GetStatusCode();
584 Int_t km = iparticle->GetFirstMother();
585 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
587 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
589 if (ks == 1) trackIt = 1;
590 Int_t ipa = iparticle->GetFirstMother()-1;
592 iparent = (ipa > -1) ? pParent[ipa] : -1;
595 // store track information
596 p[0] = iparticle->Px();
597 p[1] = iparticle->Py();
598 p[2] = iparticle->Pz();
599 p[3] = iparticle->Energy();
602 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
603 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
604 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
606 Float_t tof=kconv*iparticle->T();
608 PushTrack(fTrackIt*trackIt, iparent, kf,
609 p[0], p[1], p[2], p[3],
610 origin[0], origin[1], origin[2], tof,
611 polar[0], polar[1], polar[2],
612 kPPrimary, nt, 1., ks);
618 if (pParent) delete[] pParent;
620 printf("\n I've put %i particles on the stack \n",nc);
625 void AliGenPythia::FinishRun()
627 // Print x-section summary
632 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
633 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
638 void AliGenPythia::AdjustWeights()
640 // Adjust the weights after generation of all events
644 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
645 for (Int_t i=0; i<ntrack; i++) {
646 part= gAlice->GetMCApp()->Particle(i);
647 part->SetWeight(part->GetWeight()*fKineBias);
652 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
654 // Treat protons as inside nuclei with mass numbers a1 and a2
662 void AliGenPythia::MakeHeader()
664 // Builds the event header, to be called after each event
665 if (fHeader) delete fHeader;
666 fHeader = new AliGenPythiaEventHeader("Pythia");
669 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
672 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
675 fHeader->SetPrimaryVertex(fVertex);
677 // Jets that have triggered
678 if (fProcess == kPyJets)
682 GetJets(njet, ntrig, jets);
684 for (Int_t i = 0; i < ntrig; i++) {
685 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
689 if (gAlice) gAlice->SetGenEventHeader(fHeader);
693 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
695 // Check the kinematic trigger condition
698 eta[0] = jet1->Eta();
699 eta[1] = jet2->Eta();
701 phi[0] = jet1->Phi();
702 phi[1] = jet2->Phi();
704 pdg[0] = jet1->GetPdgCode();
705 pdg[1] = jet2->GetPdgCode();
706 Bool_t triggered = kFALSE;
708 if (fProcess == kPyJets) {
713 // Use Pythia clustering on parton level to determine jet axis
715 GetJets(njets, ntrig, jets);
717 if (ntrig) triggered = kTRUE;
722 if (pdg[0] == kGamma) {
726 //Check eta range first...
727 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
728 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
730 //Eta is okay, now check phi range
731 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
732 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
741 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
743 // Assignment operator
748 void AliGenPythia::LoadEvent(AliStack* stack, Int_t flag)
751 // Load event into Pythia Common Block
754 // AliRunLoader* rl = AliRunLoader::GetRunLoader();
755 Int_t npart = stack -> GetNprimary();
759 (fPythia->GetPyjets())->N = npart;
761 n0 = (fPythia->GetPyjets())->N;
762 (fPythia->GetPyjets())->N = n0 + npart;
766 for (Int_t part = 0; part < npart; part++) {
767 TParticle *MPart = stack->Particle(part);
769 Int_t kf = MPart->GetPdgCode();
770 Int_t ks = MPart->GetStatusCode();
772 Float_t px = MPart->Px();
773 Float_t py = MPart->Py();
774 Float_t pz = MPart->Pz();
775 Float_t e = MPart->Energy();
776 Float_t m = MPart->GetCalcMass();
779 (fPythia->GetPyjets())->P[0][part+n0] = px;
780 (fPythia->GetPyjets())->P[1][part+n0] = py;
781 (fPythia->GetPyjets())->P[2][part+n0] = pz;
782 (fPythia->GetPyjets())->P[3][part+n0] = e;
783 (fPythia->GetPyjets())->P[4][part+n0] = m;
785 (fPythia->GetPyjets())->K[1][part+n0] = kf;
786 (fPythia->GetPyjets())->K[0][part+n0] = ks;
790 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
793 // Calls the Pythia jet finding algorithm to find jets in the current event
798 Int_t n = fPythia->GetN();
802 fPythia->Pycell(njets);
804 for (i = 0; i < njets; i++) {
805 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
806 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
807 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
808 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
819 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
822 // Calls the Pythia clustering algorithm to find jets in the current event
824 Int_t n = fPythia->GetN();
827 if (fJetReconstruction == kCluster) {
829 // Configure cluster algorithm
831 fPythia->SetPARU(43, 2.);
832 fPythia->SetMSTU(41, 1);
834 // Call cluster algorithm
836 fPythia->Pyclus(nJets);
838 // Loading jets from common block
844 fPythia->Pycell(nJets);
848 for (i = 0; i < nJets; i++) {
849 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
850 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
851 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
852 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
853 Float_t pt = TMath::Sqrt(px * px + py * py);
854 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
855 Float_t theta = TMath::ATan2(pt,pz);
856 Float_t et = e * TMath::Sin(theta);
857 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
860 eta > fEtaMinJet && eta < fEtaMaxJet &&
861 phi > fPhiMinJet && phi < fPhiMaxJet &&
862 et > fEtMinJet && et < fEtMaxJet
865 jets[0][nJetsTrig] = px;
866 jets[1][nJetsTrig] = py;
867 jets[2][nJetsTrig] = pz;
868 jets[3][nJetsTrig] = e;
872 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
879 void AliGenPythia::Streamer(TBuffer &R__b)
881 // Stream an object of class AliGenPythia.
883 if (R__b.IsReading()) {
884 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
885 AliGenerator::Streamer(R__b);
886 R__b >> (Int_t&)fProcess;
887 R__b >> (Int_t&)fStrucFunc;
888 R__b >> (Int_t&)fForceDecay;
892 fParentSelect.Streamer(R__b);
893 fChildSelect.Streamer(R__b);
895 // (AliPythia::Instance())->Streamer(R__b);
898 // if (fDecayer) fDecayer->Streamer(R__b);
900 R__b.WriteVersion(AliGenPythia::IsA());
901 AliGenerator::Streamer(R__b);
902 R__b << (Int_t)fProcess;
903 R__b << (Int_t)fStrucFunc;
904 R__b << (Int_t)fForceDecay;
908 fParentSelect.Streamer(R__b);
909 fChildSelect.Streamer(R__b);
914 // fDecayer->Streamer(R__b);