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.1, 1., 8., 0);
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
330 // Switch fragmentation on
331 fPythia->SetMSTJ(1, 1);
333 // .. and perform fragmentation
339 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
340 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(1);
344 fPythia->ImportParticles(fParticles,"All");
351 Int_t np = fParticles->GetEntriesFast();
352 if (np == 0 ) continue;
356 Int_t* pParent = new Int_t[np];
357 Int_t* pSelected = new Int_t[np];
358 Int_t* trackIt = new Int_t[np];
359 for (i=0; i< np; i++) {
365 Int_t nc = 0; // Total n. of selected particles
366 Int_t nParents = 0; // Selected parents
367 Int_t nTkbles = 0; // Trackable particles
368 if (fProcess != kPyMb && fProcess != kPyJets &&
369 fProcess != kPyDirectGamma &&
370 fProcess != kPyMbNonDiffr) {
372 for (i = 0; i<np; i++) {
373 TParticle* iparticle = (TParticle *) fParticles->At(i);
374 Int_t ks = iparticle->GetStatusCode();
375 kf = CheckPDGCode(iparticle->GetPdgCode());
376 // No initial state partons
377 if (ks==21) continue;
379 // Heavy Flavor Selection
385 if (kfl > 10) kfl/=100;
387 if (kfl > 10) kfl/=10;
388 if (kfl > 10) kfl/=10;
390 Int_t ipa = iparticle->GetFirstMother()-1;
394 TParticle * mother = (TParticle *) fParticles->At(ipa);
395 kfMo = TMath::Abs(mother->GetPdgCode());
397 // What to keep in Stack?
398 Bool_t flavorOK = kFALSE;
399 Bool_t selectOK = kFALSE;
401 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
403 if (kfl > fFlavorSelect) {
407 if (kfl == fFlavorSelect) flavorOK = kTRUE;
409 switch (fStackFillOpt) {
410 case kFlavorSelection:
413 case kParentSelection:
414 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
417 if (flavorOK && selectOK) {
419 // Heavy flavor hadron or quark
421 // Kinematic seletion on final state heavy flavor mesons
422 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
427 if (ParentSelected(kf)) ++nParents; // Update parent count
428 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
430 // Kinematic seletion on decay products
431 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
432 && !KinematicSelection(iparticle, 1))
438 // Select if mother was selected and is not tracked
440 if (pSelected[ipa] &&
441 !trackIt[ipa] && // mother will be tracked ?
442 kfMo != 5 && // mother is b-quark, don't store fragments
443 kfMo != 4 && // mother is c-quark, don't store fragments
444 kf != 92) // don't store string
447 // Semi-stable or de-selected: diselect decay products:
450 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
452 Int_t ipF = iparticle->GetFirstDaughter();
453 Int_t ipL = iparticle->GetLastDaughter();
454 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
456 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
457 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
460 if (pSelected[i] == -1) pSelected[i] = 0;
461 if (!pSelected[i]) continue;
462 // Count quarks only if you did not include fragmentation
463 if (fFragmentation && kf <= 10) continue;
465 // Decision on tracking
468 // Track final state particle
469 if (ks == 1) trackIt[i] = 1;
470 // Track semi-stable particles
471 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
472 // Track particles selected by process if undecayed.
473 if (fForceDecay == kNoDecay) {
474 if (ParentSelected(kf)) trackIt[i] = 1;
476 if (ParentSelected(kf)) trackIt[i] = 0;
478 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
482 } // particle selection loop
484 for (i = 0; i<np; i++) {
485 if (!pSelected[i]) continue;
486 TParticle * iparticle = (TParticle *) fParticles->At(i);
487 kf = CheckPDGCode(iparticle->GetPdgCode());
488 Int_t ks = iparticle->GetStatusCode();
489 p[0] = iparticle->Px();
490 p[1] = iparticle->Py();
491 p[2] = iparticle->Pz();
492 p[3] = iparticle->Energy();
494 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
495 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
496 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
498 Float_t tof = kconv*iparticle->T();
499 Int_t ipa = iparticle->GetFirstMother()-1;
500 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
502 PushTrack(fTrackIt*trackIt[i], iparent, kf,
503 p[0], p[1], p[2], p[3],
504 origin[0], origin[1], origin[2], tof,
505 polar[0], polar[1], polar[2],
506 kPPrimary, nt, 1., ks);
515 if (pParent) delete[] pParent;
516 if (pSelected) delete[] pSelected;
517 if (trackIt) delete[] trackIt;
520 switch (fCountMode) {
522 // printf(" Count all \n");
526 // printf(" Count parents \n");
529 case kCountTrackables:
530 // printf(" Count trackable \n");
534 if (jev >= fNpart || fNpart == -1) {
535 fKineBias=Float_t(fNpart)/Float_t(fTrials);
536 printf("\n Trials: %i %i %i\n",fTrials, fNpart, jev);
538 fQ += fPythia->GetVINT(51);
539 fX1 += fPythia->GetVINT(41);
540 fX2 += fPythia->GetVINT(42);
541 fTrialsRun += fTrials;
548 SetHighWaterMark(nt);
549 // adjust weight due to kinematic selection
552 fXsection=fPythia->GetPARI(1);
555 Int_t AliGenPythia::GenerateMB()
558 // Min Bias selection and other global selections
560 Int_t i, kf, nt, iparent;
563 Float_t polar[3] = {0,0,0};
564 Float_t origin[3] = {0,0,0};
565 // converts from mm/c to s
566 const Float_t kconv=0.001/2.999792458e8;
568 Int_t np = fParticles->GetEntriesFast();
569 Int_t* pParent = new Int_t[np];
570 for (i=0; i< np; i++) pParent[i] = -1;
571 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
572 TParticle* jet1 = (TParticle *) fParticles->At(6);
573 TParticle* jet2 = (TParticle *) fParticles->At(7);
574 if (!CheckTrigger(jet1, jet2)) return 0;
577 for (i = 0; i<np; i++) {
579 TParticle * iparticle = (TParticle *) fParticles->At(i);
580 kf = CheckPDGCode(iparticle->GetPdgCode());
581 Int_t ks = iparticle->GetStatusCode();
582 Int_t km = iparticle->GetFirstMother();
583 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
585 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
587 if (ks == 1) trackIt = 1;
588 Int_t ipa = iparticle->GetFirstMother()-1;
590 iparent = (ipa > -1) ? pParent[ipa] : -1;
593 // store track information
594 p[0] = iparticle->Px();
595 p[1] = iparticle->Py();
596 p[2] = iparticle->Pz();
597 p[3] = iparticle->Energy();
599 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
600 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
601 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
603 Float_t tof=kconv*iparticle->T();
605 PushTrack(fTrackIt*trackIt, iparent, kf,
606 p[0], p[1], p[2], p[3],
607 origin[0], origin[1], origin[2], tof,
608 polar[0], polar[1], polar[2],
609 kPPrimary, nt, 1., ks);
615 if (pParent) delete[] pParent;
617 printf("\n I've put %i particles on the stack \n",nc);
622 void AliGenPythia::FinishRun()
624 // Print x-section summary
629 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
630 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
635 void AliGenPythia::AdjustWeights()
637 // Adjust the weights after generation of all events
641 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
642 for (Int_t i=0; i<ntrack; i++) {
643 part= gAlice->GetMCApp()->Particle(i);
644 part->SetWeight(part->GetWeight()*fKineBias);
649 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
651 // Treat protons as inside nuclei with mass numbers a1 and a2
659 void AliGenPythia::MakeHeader()
661 // Builds the event header, to be called after each event
662 if (fHeader) delete fHeader;
663 fHeader = new AliGenPythiaEventHeader("Pythia");
666 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
669 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
672 fHeader->SetPrimaryVertex(fVertex);
674 // Jets that have triggered
675 if (fProcess == kPyJets)
679 GetJets(njet, ntrig, jets);
681 for (Int_t i = 0; i < ntrig; i++) {
682 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
686 if (gAlice) gAlice->SetGenEventHeader(fHeader);
690 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
692 // Check the kinematic trigger condition
695 eta[0] = jet1->Eta();
696 eta[1] = jet2->Eta();
698 phi[0] = jet1->Phi();
699 phi[1] = jet2->Phi();
701 pdg[0] = jet1->GetPdgCode();
702 pdg[1] = jet2->GetPdgCode();
703 Bool_t triggered = kFALSE;
705 if (fProcess == kPyJets) {
710 // Use Pythia clustering on parton level to determine jet axis
712 GetJets(njets, ntrig, jets);
714 if (ntrig) triggered = kTRUE;
719 if (pdg[0] == kGamma) {
723 //Check eta range first...
724 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
725 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
727 //Eta is okay, now check phi range
728 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
729 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
738 AliGenPythia& AliGenPythia::operator=(const AliGenPythia& rhs)
740 // Assignment operator
745 void AliGenPythia::LoadEvent(AliStack* stack, Int_t flag)
748 // Load event into Pythia Common Block
751 // AliRunLoader* rl = AliRunLoader::GetRunLoader();
752 Int_t npart = stack -> GetNprimary();
756 (fPythia->GetPyjets())->N = npart;
758 n0 = (fPythia->GetPyjets())->N;
759 (fPythia->GetPyjets())->N = n0 + npart;
763 for (Int_t part = 0; part < npart; part++) {
764 TParticle *MPart = stack->Particle(part);
766 Int_t kf = MPart->GetPdgCode();
767 Int_t ks = MPart->GetStatusCode();
769 Float_t px = MPart->Px();
770 Float_t py = MPart->Py();
771 Float_t pz = MPart->Pz();
772 Float_t e = MPart->Energy();
773 Float_t m = MPart->GetCalcMass();
776 (fPythia->GetPyjets())->P[0][part+n0] = px;
777 (fPythia->GetPyjets())->P[1][part+n0] = py;
778 (fPythia->GetPyjets())->P[2][part+n0] = pz;
779 (fPythia->GetPyjets())->P[3][part+n0] = e;
780 (fPythia->GetPyjets())->P[4][part+n0] = m;
782 (fPythia->GetPyjets())->K[1][part+n0] = kf;
783 (fPythia->GetPyjets())->K[0][part+n0] = ks;
787 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
790 // Calls the Pythia jet finding algorithm to find jets in the current event
795 Int_t n = fPythia->GetN();
799 fPythia->Pycell(njets);
801 for (i = 0; i < njets; i++) {
802 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
803 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
804 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
805 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
816 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
819 // Calls the Pythia clustering algorithm to find jets in the current event
821 Int_t n = fPythia->GetN();
824 if (fJetReconstruction == kCluster) {
826 // Configure cluster algorithm
828 fPythia->SetPARU(43, 2.);
829 fPythia->SetMSTU(41, 1);
831 // Call cluster algorithm
833 fPythia->Pyclus(nJets);
835 // Loading jets from common block
841 fPythia->Pycell(nJets);
845 for (i = 0; i < nJets; i++) {
846 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
847 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
848 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
849 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
850 Float_t pt = TMath::Sqrt(px * px + py * py);
851 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
852 Float_t theta = TMath::ATan2(pt,pz);
853 Float_t et = e * TMath::Sin(theta);
854 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
857 eta > fEtaMinJet && eta < fEtaMaxJet &&
858 phi > fPhiMinJet && phi < fPhiMaxJet &&
859 et > fEtMinJet && et < fEtMaxJet
862 jets[0][nJetsTrig] = px;
863 jets[1][nJetsTrig] = py;
864 jets[2][nJetsTrig] = pz;
865 jets[3][nJetsTrig] = e;
869 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
876 void AliGenPythia::Streamer(TBuffer &R__b)
878 // Stream an object of class AliGenPythia.
880 if (R__b.IsReading()) {
881 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
882 AliGenerator::Streamer(R__b);
883 R__b >> (Int_t&)fProcess;
884 R__b >> (Int_t&)fStrucFunc;
885 R__b >> (Int_t&)fForceDecay;
889 fParentSelect.Streamer(R__b);
890 fChildSelect.Streamer(R__b);
892 // (AliPythia::Instance())->Streamer(R__b);
895 // if (fDecayer) fDecayer->Streamer(R__b);
897 R__b.WriteVersion(AliGenPythia::IsA());
898 AliGenerator::Streamer(R__b);
899 R__b << (Int_t)fProcess;
900 R__b << (Int_t)fStrucFunc;
901 R__b << (Int_t)fForceDecay;
905 fParentSelect.Streamer(R__b);
906 fChildSelect.Streamer(R__b);
911 // fDecayer->Streamer(R__b);