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 <TClonesArray.h>
29 #include <TDatabasePDG.h>
30 #include <TParticle.h>
32 #include <TObjArray.h>
36 #include "AliDecayerPythia.h"
37 #include "AliGenPythia.h"
38 #include "AliFastGlauber.h"
39 #include "AliHeader.h"
40 #include "AliGenPythiaEventHeader.h"
41 #include "AliPythia.h"
42 #include "AliPythiaRndm.h"
45 #include "AliRunLoader.h"
47 #include "PyquenCommon.h"
49 ClassImp(AliGenPythia)
52 AliGenPythia::AliGenPythia():
87 fDecayer(new AliDecayerPythia()),
95 fPhiMaxJet(2.* TMath::Pi()),
96 fJetReconstruction(kCell),
100 fPhiMaxGamma(2. * TMath::Pi()),
104 fPycellThreshold(0.),
106 fPycellMinEtJet(10.),
107 fPycellMaxRadius(1.),
108 fStackFillOpt(kFlavorSelection),
110 fFragmentation(kTRUE),
117 fTriggerMultiplicity(0),
118 fTriggerMultiplicityEta(0),
119 fCountMode(kCountAll),
123 fFragPhotonInCalo(kFALSE),
125 fPhotonInCalo(kFALSE),
129 fCheckPHOSeta(kFALSE),
130 fFragPhotonOrPi0MinPt(0),
141 // Default Constructor
144 if (!AliPythiaRndm::GetPythiaRandom())
145 AliPythiaRndm::SetPythiaRandom(GetRandom());
148 AliGenPythia::AliGenPythia(Int_t npart)
160 fInteractionRate(0.),
174 fHadronisation(kTRUE),
176 fReadFromFile(kFALSE),
183 fDecayer(new AliDecayerPythia()),
184 fDebugEventFirst(-1),
191 fPhiMaxJet(2.* TMath::Pi()),
192 fJetReconstruction(kCell),
196 fPhiMaxGamma(2. * TMath::Pi()),
200 fPycellThreshold(0.),
202 fPycellMinEtJet(10.),
203 fPycellMaxRadius(1.),
204 fStackFillOpt(kFlavorSelection),
206 fFragmentation(kTRUE),
213 fTriggerMultiplicity(0),
214 fTriggerMultiplicityEta(0),
215 fCountMode(kCountAll),
219 fFragPhotonInCalo(kFALSE),
221 fPhotonInCalo(kFALSE),
225 fCheckPHOSeta(kFALSE),
226 fFragPhotonOrPi0MinPt(0),
236 // default charm production at 5. 5 TeV
238 // structure function GRVHO
242 fTitle= "Particle Generator using PYTHIA";
244 // Set random number generator
245 if (!AliPythiaRndm::GetPythiaRandom())
246 AliPythiaRndm::SetPythiaRandom(GetRandom());
250 AliGenPythia::~AliGenPythia()
253 if(fEventsTime) delete fEventsTime;
256 void AliGenPythia::SetInteractionRate(Float_t rate,Float_t timewindow)
258 // Generate pileup using user specified rate
259 fInteractionRate = rate;
260 fTimeWindow = timewindow;
264 void AliGenPythia::GeneratePileup()
266 // Generate sub events time for pileup
268 if(fInteractionRate == 0.) {
269 Warning("GeneratePileup","Zero interaction specified. Skipping pileup generation.\n");
273 Int_t npart = NumberParticles();
275 Warning("GeneratePileup","Negative number of particles. Skipping pileup generation.\n");
279 if(fEventsTime) delete fEventsTime;
280 fEventsTime = new TArrayF(npart);
281 TArrayF &array = *fEventsTime;
282 for(Int_t ipart = 0; ipart < npart; ipart++)
285 Float_t eventtime = 0.;
288 eventtime += (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
289 if(eventtime > fTimeWindow) break;
290 array.Set(array.GetSize()+1);
291 array[array.GetSize()-1] = eventtime;
297 eventtime -= (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
298 if(TMath::Abs(eventtime) > fTimeWindow) break;
299 array.Set(array.GetSize()+1);
300 array[array.GetSize()-1] = eventtime;
303 SetNumberParticles(fEventsTime->GetSize());
306 void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
307 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
309 // Set pycell parameters
310 fPycellEtaMax = etamax;
313 fPycellThreshold = thresh;
314 fPycellEtSeed = etseed;
315 fPycellMinEtJet = minet;
316 fPycellMaxRadius = r;
321 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
323 // Set a range of event numbers, for which a table
324 // of generated particle will be printed
325 fDebugEventFirst = eventFirst;
326 fDebugEventLast = eventLast;
327 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
330 void AliGenPythia::Init()
334 SetMC(AliPythia::Instance());
335 fPythia=(AliPythia*) fMCEvGen;
338 fParentWeight=1./Float_t(fNpart);
342 fPythia->SetCKIN(3,fPtHardMin);
343 fPythia->SetCKIN(4,fPtHardMax);
344 fPythia->SetCKIN(7,fYHardMin);
345 fPythia->SetCKIN(8,fYHardMax);
347 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget, fNucPdf);
349 if (fFragmentation) {
350 fPythia->SetMSTP(111,1);
352 fPythia->SetMSTP(111,0);
356 // initial state radiation
357 fPythia->SetMSTP(61,fGinit);
358 // final state radiation
359 fPythia->SetMSTP(71,fGfinal);
362 fPythia->SetMSTP(91,1);
363 fPythia->SetPARP(91,fPtKick);
364 fPythia->SetPARP(93, 4. * fPtKick);
366 fPythia->SetMSTP(91,0);
371 fRL = AliRunLoader::Open(fFileName, "Partons");
372 fRL->LoadKinematics();
378 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc, fItune);
379 // Forward Paramters to the AliPythia object
380 fDecayer->SetForceDecay(fForceDecay);
381 // Switch off Heavy Flavors on request
383 // Maximum number of quark flavours used in pdf
384 fPythia->SetMSTP(58, 3);
385 // Maximum number of flavors that can be used in showers
386 fPythia->SetMSTJ(45, 3);
387 // Switch off g->QQbar splitting in decay table
388 ((AliDecayerPythia*) fDecayer)->HeavyFlavourOff();
394 // Parent and Children Selection
397 case kPyOldUEQ2ordered:
398 case kPyOldUEQ2ordered2:
402 case kPyCharmUnforced:
403 case kPyCharmPbPbMNR:
406 case kPyCharmppMNRwmi:
407 fParentSelect[0] = 411;
408 fParentSelect[1] = 421;
409 fParentSelect[2] = 431;
410 fParentSelect[3] = 4122;
411 fParentSelect[4] = 4232;
412 fParentSelect[5] = 4132;
413 fParentSelect[6] = 4332;
419 fParentSelect[0] = 421;
422 case kPyDPlusPbPbMNR:
425 fParentSelect[0] = 411;
428 case kPyDPlusStrangePbPbMNR:
429 case kPyDPlusStrangepPbMNR:
430 case kPyDPlusStrangeppMNR:
431 fParentSelect[0] = 431;
436 case kPyBeautyPbPbMNR:
437 case kPyBeautypPbMNR:
439 case kPyBeautyppMNRwmi:
440 fParentSelect[0]= 511;
441 fParentSelect[1]= 521;
442 fParentSelect[2]= 531;
443 fParentSelect[3]= 5122;
444 fParentSelect[4]= 5132;
445 fParentSelect[5]= 5232;
446 fParentSelect[6]= 5332;
449 case kPyBeautyUnforced:
450 fParentSelect[0] = 511;
451 fParentSelect[1] = 521;
452 fParentSelect[2] = 531;
453 fParentSelect[3] = 5122;
454 fParentSelect[4] = 5132;
455 fParentSelect[5] = 5232;
456 fParentSelect[6] = 5332;
461 fParentSelect[0] = 443;
465 case kPyMbWithDirectPhoton:
478 // JetFinder for Trigger
480 // Configure detector (EMCAL like)
482 fPythia->SetPARU(51, fPycellEtaMax);
483 fPythia->SetMSTU(51, fPycellNEta);
484 fPythia->SetMSTU(52, fPycellNPhi);
486 // Configure Jet Finder
488 fPythia->SetPARU(58, fPycellThreshold);
489 fPythia->SetPARU(52, fPycellEtSeed);
490 fPythia->SetPARU(53, fPycellMinEtJet);
491 fPythia->SetPARU(54, fPycellMaxRadius);
492 fPythia->SetMSTU(54, 2);
494 // This counts the total number of calls to Pyevnt() per run.
509 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
512 fPythia->SetPARJ(200, 0.0);
513 fPythia->SetPARJ(199, 0.0);
514 fPythia->SetPARJ(198, 0.0);
515 fPythia->SetPARJ(197, 0.0);
518 fPythia->InitQuenching(0., 0.1, 0.6e6, 0);
522 // Nestor's change of the splittings
523 fPythia->SetPARJ(200, 0.8);
524 fPythia->SetMSTJ(41, 1); // QCD radiation only
525 fPythia->SetMSTJ(42, 2); // angular ordering
526 fPythia->SetMSTJ(44, 2); // option to run alpha_s
527 fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
528 fPythia->SetMSTJ(50, 0); // No coherence in first branching
529 fPythia->SetPARJ(82, 1.); // Cut off for parton showers
530 } else if (fQuench == 4) {
531 // Armesto-Cunqueiro-Salgado change of the splittings.
532 AliFastGlauber* glauber = AliFastGlauber::Instance();
534 //read and store transverse almonds corresponding to differnt
536 glauber->SetCentralityClass(0.,0.1);
537 fPythia->SetPARJ(200, 1.);
538 fPythia->SetPARJ(198, fQhat);
539 fPythia->SetPARJ(199, fLength);
540 fPythia->SetMSTJ(42, 2); // angular ordering
541 fPythia->SetMSTJ(44, 2); // option to run alpha_s
542 fPythia->SetPARJ(82, 1.); // Cut off for parton showers
546 void AliGenPythia::Generate()
548 // Generate one event
549 if (!fPythia) fPythia=(AliPythia*) fMCEvGen;
550 fDecayer->ForceDecay();
552 Float_t polar[3] = {0,0,0};
553 Float_t origin[3] = {0,0,0};
555 // converts from mm/c to s
556 const Float_t kconv=0.001/2.999792458e8;
566 // Set collision vertex position
567 if (fVertexSmear == kPerEvent) Vertex();
576 // Switch hadronisation off
578 fPythia->SetMSTJ(1, 0);
582 // Quenching comes through medium-modified splitting functions.
583 AliFastGlauber::Instance()->GetRandomBHard(bimp);
584 fPythia->SetPARJ(197, bimp);
588 // Either produce new event or read partons from file
590 if (!fReadFromFile) {
596 fNpartons = fPythia->GetN();
598 printf("Loading Event %d\n",AliRunLoader::Instance()->GetEventNumber());
599 fRL->GetEvent(AliRunLoader::Instance()->GetEventNumber());
601 LoadEvent(fRL->Stack(), 0 , 1);
606 // Run quenching routine
610 } else if (fQuench == 2){
611 fPythia->Pyquen(208., 0, 0.);
612 } else if (fQuench == 3) {
613 // Quenching is via multiplicative correction of the splittings
617 // Switch hadronisation on
619 if (fHadronisation) {
620 fPythia->SetMSTJ(1, 1);
622 // .. and perform hadronisation
623 // printf("Calling hadronisation %d\n", fPythia->GetN());
627 fPythia->ImportParticles(&fParticles,"All");
635 Int_t np = fParticles.GetEntriesFast();
637 if (np == 0) continue;
641 Int_t* pParent = new Int_t[np];
642 Int_t* pSelected = new Int_t[np];
643 Int_t* trackIt = new Int_t[np];
644 for (i = 0; i < np; i++) {
650 Int_t nc = 0; // Total n. of selected particles
651 Int_t nParents = 0; // Selected parents
652 Int_t nTkbles = 0; // Trackable particles
653 if (fProcess != kPyMbDefault &&
655 fProcess != kPyMbWithDirectPhoton &&
656 fProcess != kPyJets &&
657 fProcess != kPyDirectGamma &&
658 fProcess != kPyMbNonDiffr &&
659 fProcess != kPyMbMSEL1 &&
662 fProcess != kPyCharmppMNRwmi &&
663 fProcess != kPyBeautyppMNRwmi &&
664 fProcess != kPyBeautyJets) {
666 for (i = 0; i < np; i++) {
667 TParticle* iparticle = (TParticle *) fParticles.At(i);
668 Int_t ks = iparticle->GetStatusCode();
669 kf = CheckPDGCode(iparticle->GetPdgCode());
670 // No initial state partons
671 if (ks==21) continue;
673 // Heavy Flavor Selection
680 if (kfl > 100000) kfl %= 100000;
681 if (kfl > 10000) kfl %= 10000;
683 if (kfl > 10) kfl/=100;
685 if (kfl > 10) kfl/=10;
686 Int_t ipa = iparticle->GetFirstMother()-1;
689 // Establish mother daughter relation between heavy quarks and mesons
691 if (kf >= fFlavorSelect && kf <= 6) {
692 Int_t idau = iparticle->GetFirstDaughter() - 1;
694 TParticle* daughter = (TParticle *) fParticles.At(idau);
695 Int_t pdgD = daughter->GetPdgCode();
696 if (pdgD == 91 || pdgD == 92) {
697 Int_t jmin = daughter->GetFirstDaughter() - 1;
698 Int_t jmax = daughter->GetLastDaughter() - 1;
699 for (Int_t jp = jmin; jp <= jmax; jp++)
700 ((TParticle *) fParticles.At(jp))->SetFirstMother(i+1);
701 } // is string or cluster
707 TParticle * mother = (TParticle *) fParticles.At(ipa);
708 kfMo = TMath::Abs(mother->GetPdgCode());
711 // What to keep in Stack?
712 Bool_t flavorOK = kFALSE;
713 Bool_t selectOK = kFALSE;
715 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
717 if (kfl > fFlavorSelect) {
721 if (kfl == fFlavorSelect) flavorOK = kTRUE;
723 switch (fStackFillOpt) {
724 case kFlavorSelection:
727 case kParentSelection:
728 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
731 if (flavorOK && selectOK) {
733 // Heavy flavor hadron or quark
735 // Kinematic seletion on final state heavy flavor mesons
736 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
741 if (ParentSelected(kf)) ++nParents; // Update parent count
742 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
744 // Kinematic seletion on decay products
745 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
746 && !KinematicSelection(iparticle, 1))
752 // Select if mother was selected and is not tracked
754 if (pSelected[ipa] &&
755 !trackIt[ipa] && // mother will be tracked ?
756 kfMo != 5 && // mother is b-quark, don't store fragments
757 kfMo != 4 && // mother is c-quark, don't store fragments
758 kf != 92) // don't store string
761 // Semi-stable or de-selected: diselect decay products:
764 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
766 Int_t ipF = iparticle->GetFirstDaughter();
767 Int_t ipL = iparticle->GetLastDaughter();
768 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
770 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
771 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
774 if (pSelected[i] == -1) pSelected[i] = 0;
775 if (!pSelected[i]) continue;
776 // Count quarks only if you did not include fragmentation
777 if (fFragmentation && kf <= 10) continue;
780 // Decision on tracking
783 // Track final state particle
784 if (ks == 1) trackIt[i] = 1;
785 // Track semi-stable particles
786 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
787 // Track particles selected by process if undecayed.
788 if (fForceDecay == kNoDecay) {
789 if (ParentSelected(kf)) trackIt[i] = 1;
791 if (ParentSelected(kf)) trackIt[i] = 0;
793 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
797 } // particle selection loop
799 for (i = 0; i<np; i++) {
800 if (!pSelected[i]) continue;
801 TParticle * iparticle = (TParticle *) fParticles.At(i);
802 kf = CheckPDGCode(iparticle->GetPdgCode());
803 Int_t ks = iparticle->GetStatusCode();
804 p[0] = iparticle->Px();
805 p[1] = iparticle->Py();
806 p[2] = iparticle->Pz();
807 p[3] = iparticle->Energy();
809 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
810 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
811 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
813 Float_t tof = kconv*iparticle->T();
814 Int_t ipa = iparticle->GetFirstMother()-1;
815 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
817 PushTrack(fTrackIt*trackIt[i], iparent, kf,
818 p[0], p[1], p[2], p[3],
819 origin[0], origin[1], origin[2], tof,
820 polar[0], polar[1], polar[2],
821 kPPrimary, nt, 1., ks);
838 switch (fCountMode) {
840 // printf(" Count all \n");
844 // printf(" Count parents \n");
847 case kCountTrackables:
848 // printf(" Count trackable \n");
852 if (jev >= fNpart || fNpart == -1) {
853 fKineBias=Float_t(fNpart)/Float_t(fTrials);
855 fQ += fPythia->GetVINT(51);
856 fX1 += fPythia->GetVINT(41);
857 fX2 += fPythia->GetVINT(42);
858 fTrialsRun += fTrials;
865 SetHighWaterMark(nt);
866 // adjust weight due to kinematic selection
869 fXsection=fPythia->GetPARI(1);
872 Int_t AliGenPythia::GenerateMB()
875 // Min Bias selection and other global selections
877 Int_t i, kf, nt, iparent;
880 Float_t polar[3] = {0,0,0};
881 Float_t origin[3] = {0,0,0};
882 // converts from mm/c to s
883 const Float_t kconv=0.001/2.999792458e8;
887 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
891 Int_t* pParent = new Int_t[np];
892 for (i=0; i< np; i++) pParent[i] = -1;
893 if (fProcess == kPyJets || fProcess == kPyDirectGamma || fProcess == kPyBeautyJets || fProcess == kPyBeautyppMNRwmi) {
894 TParticle* jet1 = (TParticle *) fParticles.At(6);
895 TParticle* jet2 = (TParticle *) fParticles.At(7);
896 if (!CheckTrigger(jet1, jet2)) {
902 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
903 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
908 if (fFragPhotonInCalo) pdg = 22 ; // Photon
909 else if (fPi0InCalo) pdg = 111 ; // Pi0
911 for (i=0; i< np; i++) {
912 TParticle* iparticle = (TParticle *) fParticles.At(i);
913 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
914 iparticle->Pt() > fFragPhotonOrPi0MinPt){
915 Int_t imother = iparticle->GetFirstMother() - 1;
916 TParticle* pmother = (TParticle *) fParticles.At(imother);
918 (pdg == 22 && pmother->GetStatusCode() != 11)) //No photon from hadron decay
920 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
921 Float_t eta =TMath::Abs(iparticle->Eta()); //in calos etamin=-etamax
922 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
923 (fCheckPHOS && IsInPHOS(phi,eta)) )
932 // Select beauty jets with electron in EMCAL
933 if (fProcess == kPyBeautyJets && fEleInEMCAL) {
937 Int_t pdg = 11; //electron
942 for (i=0; i< np; i++) {
943 TParticle* iparticle = (TParticle *) fParticles.At(i);
944 if(iparticle->GetStatusCode()==1 && TMath::Abs(iparticle->GetPdgCode())==pdg &&
945 iparticle->Pt() > fElectronMinPt){
946 pt = iparticle->Pt();
947 phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
948 eta =TMath::Abs(iparticle->Eta()); //in calos etamin=-etamax
949 if(IsInEMCAL(phi,eta))
955 AliDebug(5,Form("Found an electron jet (pt,eta,phi) = (%f,%f,%f)",pt,eta,phi));
958 // Check for minimum multiplicity
959 if (fTriggerMultiplicity > 0) {
960 Int_t multiplicity = 0;
961 for (i = 0; i < np; i++) {
962 TParticle * iparticle = (TParticle *) fParticles.At(i);
964 Int_t statusCode = iparticle->GetStatusCode();
966 // Initial state particle
970 if (fTriggerMultiplicityEta > 0 && TMath::Abs(iparticle->Eta()) > fTriggerMultiplicityEta)
973 TParticlePDG* pdgPart = iparticle->GetPDG();
974 if (pdgPart && pdgPart->Charge() == 0)
980 if (multiplicity < fTriggerMultiplicity) {
985 Printf("Triggered on event with multiplicity of %d > %d", multiplicity, fTriggerMultiplicity);
988 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
989 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
995 for (i=0; i< np; i++) {
996 TParticle* iparticle = (TParticle *) fParticles.At(i);
997 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
998 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
1000 if(iparticle->GetStatusCode() == 1
1001 && iparticle->GetPdgCode() == pdg
1002 && iparticle->Pt() > fPhotonMinPt
1005 // first check if the photon is in PHOS phi
1006 if(IsInPHOS(phi,eta)){
1010 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
1015 if(!okd && iphcand != -1) // execute rotation in phi
1016 RotatePhi(iphcand,okd);
1022 if (fTriggerParticle) {
1023 Bool_t triggered = kFALSE;
1024 for (i = 0; i < np; i++) {
1025 TParticle * iparticle = (TParticle *) fParticles.At(i);
1026 kf = CheckPDGCode(iparticle->GetPdgCode());
1027 if (kf != fTriggerParticle) continue;
1028 if (iparticle->Pt() == 0.) continue;
1029 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
1040 // Check if there is a ccbar or bbbar pair with at least one of the two
1041 // in fYMin < y < fYMax
1043 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi || fProcess == kPyBeautyJets) {
1044 TParticle *partCheck;
1046 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
1047 Bool_t theChild=kFALSE;
1049 Int_t pdg,mpdg,mpdgUpperFamily;
1050 for(i=0; i<np; i++) {
1051 partCheck = (TParticle*)fParticles.At(i);
1052 pdg = partCheck->GetPdgCode();
1053 if(TMath::Abs(pdg) == fFlavorSelect) { // quark
1054 if(pdg>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
1055 y = 0.5*TMath::Log((partCheck->Energy()+partCheck->Pz()+1.e-13)/
1056 (partCheck->Energy()-partCheck->Pz()+1.e-13));
1057 if(y>fYMin && y<fYMax) inYcut=kTRUE;
1059 if(fCutOnChild && TMath::Abs(pdg) == fPdgCodeParticleforAcceptanceCut) {
1060 Int_t mi = partCheck->GetFirstMother() - 1;
1062 mother = (TParticle*)fParticles.At(mi);
1063 mpdg=TMath::Abs(mother->GetPdgCode());
1064 mpdgUpperFamily=(mpdg>1000 ? mpdg+1000 : mpdg+100); // keep e from c from b
1065 if ( ParentSelected(mpdg) ||
1066 (fFlavorSelect==5 && ParentSelected(mpdgUpperFamily))) {
1067 if (KinematicSelection(partCheck,1)) {
1073 if (!theQ || !theQbar || !inYcut) { // one of the c/b conditions not satisfied
1077 if (fCutOnChild && !theChild) { // one of the child conditions not satisfied
1084 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
1085 if ( (fProcess == kPyW ||
1087 fProcess == kPyMbDefault ||
1088 fProcess == kPyMb ||
1089 fProcess == kPyMbWithDirectPhoton ||
1090 fProcess == kPyMbNonDiffr)
1091 && (fCutOnChild == 1) ) {
1092 if ( !CheckKinematicsOnChild() ) {
1099 for (i = 0; i < np; i++) {
1101 TParticle * iparticle = (TParticle *) fParticles.At(i);
1102 kf = CheckPDGCode(iparticle->GetPdgCode());
1103 Int_t ks = iparticle->GetStatusCode();
1104 Int_t km = iparticle->GetFirstMother();
1105 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
1107 ((fProcess == kPyJets || fProcess == kPyBeautyJets) && ks == 21 && km == 0 && i>1)) {
1109 if (ks == 1) trackIt = 1;
1110 Int_t ipa = iparticle->GetFirstMother()-1;
1112 iparent = (ipa > -1) ? pParent[ipa] : -1;
1115 // store track information
1116 p[0] = iparticle->Px();
1117 p[1] = iparticle->Py();
1118 p[2] = iparticle->Pz();
1119 p[3] = iparticle->Energy();
1122 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
1123 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
1124 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
1126 Float_t tof = fEventTime + kconv * iparticle->T();
1128 PushTrack(fTrackIt*trackIt, iparent, kf,
1129 p[0], p[1], p[2], p[3],
1130 origin[0], origin[1], origin[2], tof,
1131 polar[0], polar[1], polar[2],
1132 kPPrimary, nt, 1., ks);
1136 SetHighWaterMark(nt);
1138 } // select particle
1147 void AliGenPythia::FinishRun()
1149 // Print x-section summary
1158 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1159 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1162 void AliGenPythia::AdjustWeights() const
1164 // Adjust the weights after generation of all events
1168 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1169 for (Int_t i=0; i<ntrack; i++) {
1170 part= gAlice->GetMCApp()->Particle(i);
1171 part->SetWeight(part->GetWeight()*fKineBias);
1176 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2, Int_t pdfset)
1178 // Treat protons as inside nuclei with mass numbers a1 and a2
1182 fNucPdf = pdfset; // 0 EKS98 1 EPS08
1187 void AliGenPythia::MakeHeader()
1190 // Make header for the simulated event
1193 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1194 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(2);
1197 // Builds the event header, to be called after each event
1198 if (fHeader) delete fHeader;
1199 fHeader = new AliGenPythiaEventHeader("Pythia");
1202 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
1205 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1208 fHeader->SetPrimaryVertex(fVertex);
1211 // Number of primaries
1212 fHeader->SetNProduced(fNprimaries);
1214 // Jets that have triggered
1216 //Need to store jets for b-jet studies too!
1217 if (fProcess == kPyJets || fProcess == kPyDirectGamma || fProcess == kPyBeautyJets || fProcess == kPyBeautyppMNRwmi)
1220 Float_t jets[4][10];
1221 GetJets(njet, ntrig, jets);
1224 for (Int_t i = 0; i < ntrig; i++) {
1225 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1230 // Copy relevant information from external header, if present.
1235 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1236 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1238 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1241 exHeader->TriggerJet(i, uqJet);
1242 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1246 // Store quenching parameters
1253 fPythia->GetQuenchingParameters(xp, yp, z);
1254 } else if (fQuench == 2){
1256 Double_t r1 = PARIMP.rb1;
1257 Double_t r2 = PARIMP.rb2;
1258 Double_t b = PARIMP.b1;
1259 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1260 Double_t phi = PARIMP.psib1;
1261 xp = r * TMath::Cos(phi);
1262 yp = r * TMath::Sin(phi);
1264 } else if (fQuench == 4) {
1268 AliFastGlauber::Instance()->GetSavedXY(xy);
1269 AliFastGlauber::Instance()->GetSavedI0I1(i0i1);
1272 ((AliGenPythiaEventHeader*) fHeader)->SetImpactParameter(fImpact);
1275 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1276 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1280 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetVINT(47));
1288 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
1290 // Check the kinematic trigger condition
1293 eta[0] = jet1->Eta();
1294 eta[1] = jet2->Eta();
1296 phi[0] = jet1->Phi();
1297 phi[1] = jet2->Phi();
1299 pdg[0] = jet1->GetPdgCode();
1300 pdg[1] = jet2->GetPdgCode();
1301 Bool_t triggered = kFALSE;
1303 if (fProcess == kPyJets || fProcess == kPyBeautyJets || fProcess == kPyBeautyppMNRwmi) {
1306 Float_t jets[4][10];
1308 // Use Pythia clustering on parton level to determine jet axis
1310 GetJets(njets, ntrig, jets);
1312 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1317 if (pdg[0] == kGamma) {
1321 //Check eta range first...
1322 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1323 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1325 //Eta is okay, now check phi range
1326 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1327 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1338 Bool_t AliGenPythia::CheckKinematicsOnChild(){
1340 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1342 Bool_t checking = kFALSE;
1343 Int_t j, kcode, ks, km;
1344 Int_t nPartAcc = 0; //number of particles in the acceptance range
1345 Int_t numberOfAcceptedParticles = 1;
1346 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1347 Int_t npart = fParticles.GetEntriesFast();
1349 for (j = 0; j<npart; j++) {
1350 TParticle * jparticle = (TParticle *) fParticles.At(j);
1351 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1352 ks = jparticle->GetStatusCode();
1353 km = jparticle->GetFirstMother();
1355 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1358 if( numberOfAcceptedParticles <= nPartAcc){
1367 void AliGenPythia::LoadEvent(AliStack* stack, Int_t flag, Int_t reHadr)
1370 // Load event into Pythia Common Block
1373 Int_t npart = stack -> GetNprimary();
1377 (fPythia->GetPyjets())->N = npart;
1379 n0 = (fPythia->GetPyjets())->N;
1380 (fPythia->GetPyjets())->N = n0 + npart;
1384 for (Int_t part = 0; part < npart; part++) {
1385 TParticle *mPart = stack->Particle(part);
1387 Int_t kf = mPart->GetPdgCode();
1388 Int_t ks = mPart->GetStatusCode();
1389 Int_t idf = mPart->GetFirstDaughter();
1390 Int_t idl = mPart->GetLastDaughter();
1393 if (ks == 11 || ks == 12) {
1400 Float_t px = mPart->Px();
1401 Float_t py = mPart->Py();
1402 Float_t pz = mPart->Pz();
1403 Float_t e = mPart->Energy();
1404 Float_t m = mPart->GetCalcMass();
1407 (fPythia->GetPyjets())->P[0][part+n0] = px;
1408 (fPythia->GetPyjets())->P[1][part+n0] = py;
1409 (fPythia->GetPyjets())->P[2][part+n0] = pz;
1410 (fPythia->GetPyjets())->P[3][part+n0] = e;
1411 (fPythia->GetPyjets())->P[4][part+n0] = m;
1413 (fPythia->GetPyjets())->K[1][part+n0] = kf;
1414 (fPythia->GetPyjets())->K[0][part+n0] = ks;
1415 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
1416 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
1417 (fPythia->GetPyjets())->K[2][part+n0] = mPart->GetFirstMother() + 1;
1421 void AliGenPythia::LoadEvent(TObjArray* stack, Int_t flag, Int_t reHadr)
1424 // Load event into Pythia Common Block
1427 Int_t npart = stack -> GetEntries();
1431 (fPythia->GetPyjets())->N = npart;
1433 n0 = (fPythia->GetPyjets())->N;
1434 (fPythia->GetPyjets())->N = n0 + npart;
1438 for (Int_t part = 0; part < npart; part++) {
1439 TParticle *mPart = dynamic_cast<TParticle *>(stack->At(part));
1440 Int_t kf = mPart->GetPdgCode();
1441 Int_t ks = mPart->GetStatusCode();
1442 Int_t idf = mPart->GetFirstDaughter();
1443 Int_t idl = mPart->GetLastDaughter();
1446 if (ks == 11 || ks == 12) {
1453 Float_t px = mPart->Px();
1454 Float_t py = mPart->Py();
1455 Float_t pz = mPart->Pz();
1456 Float_t e = mPart->Energy();
1457 Float_t m = mPart->GetCalcMass();
1460 (fPythia->GetPyjets())->P[0][part+n0] = px;
1461 (fPythia->GetPyjets())->P[1][part+n0] = py;
1462 (fPythia->GetPyjets())->P[2][part+n0] = pz;
1463 (fPythia->GetPyjets())->P[3][part+n0] = e;
1464 (fPythia->GetPyjets())->P[4][part+n0] = m;
1466 (fPythia->GetPyjets())->K[1][part+n0] = kf;
1467 (fPythia->GetPyjets())->K[0][part+n0] = ks;
1468 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
1469 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
1470 (fPythia->GetPyjets())->K[2][part+n0] = mPart->GetFirstMother() + 1;
1475 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1478 // Calls the Pythia jet finding algorithm to find jets in the current event
1483 Int_t n = fPythia->GetN();
1487 fPythia->Pycell(njets);
1489 for (i = 0; i < njets; i++) {
1490 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1491 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1492 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1493 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1504 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1507 // Calls the Pythia clustering algorithm to find jets in the current event
1509 Int_t n = fPythia->GetN();
1512 if (fJetReconstruction == kCluster) {
1514 // Configure cluster algorithm
1516 fPythia->SetPARU(43, 2.);
1517 fPythia->SetMSTU(41, 1);
1519 // Call cluster algorithm
1521 fPythia->Pyclus(nJets);
1523 // Loading jets from common block
1529 fPythia->Pycell(nJets);
1533 for (i = 0; i < nJets; i++) {
1534 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1535 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1536 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1537 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1538 Float_t pt = TMath::Sqrt(px * px + py * py);
1539 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1540 Float_t theta = TMath::ATan2(pt,pz);
1541 Float_t et = e * TMath::Sin(theta);
1542 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1544 eta > fEtaMinJet && eta < fEtaMaxJet &&
1545 phi > fPhiMinJet && phi < fPhiMaxJet &&
1546 et > fEtMinJet && et < fEtMaxJet
1549 jets[0][nJetsTrig] = px;
1550 jets[1][nJetsTrig] = py;
1551 jets[2][nJetsTrig] = pz;
1552 jets[3][nJetsTrig] = e;
1554 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1556 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1561 void AliGenPythia::GetSubEventTime()
1563 // Calculates time of the next subevent
1566 TArrayF &array = *fEventsTime;
1567 fEventTime = array[fCurSubEvent++];
1569 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1573 Bool_t AliGenPythia::IsInEMCAL(Float_t phi, Float_t eta)
1575 // Is particle in EMCAL acceptance?
1576 // phi in degrees, etamin=-etamax
1577 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1584 Bool_t AliGenPythia::IsInPHOS(Float_t phi, Float_t eta)
1586 // Is particle in PHOS acceptance?
1587 // Acceptance slightly larger considered.
1588 // phi in degrees, etamin=-etamax
1589 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1596 void AliGenPythia::RotatePhi(Int_t iphcand, Bool_t& okdd)
1598 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1599 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1600 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1601 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1603 //calculate deltaphi
1604 TParticle* ph = (TParticle *) fParticles.At(iphcand);
1605 Double_t phphi = ph->Phi();
1606 Double_t deltaphi = phiPHOS - phphi;
1610 //loop for all particles and produce the phi rotation
1611 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
1612 Double_t oldphi, newphi;
1613 Double_t newVx, newVy, R, Vz, time;
1614 Double_t newPx, newPy, pt, Pz, e;
1615 for(Int_t i=0; i< np; i++) {
1616 TParticle* iparticle = (TParticle *) fParticles.At(i);
1617 oldphi = iparticle->Phi();
1618 newphi = oldphi + deltaphi;
1619 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1620 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1623 newVx = R*TMath::Cos(newphi);
1624 newVy = R*TMath::Sin(newphi);
1625 Vz = iparticle->Vz(); // don't transform
1626 time = iparticle->T(); // don't transform
1628 pt = iparticle->Pt();
1629 newPx = pt*TMath::Cos(newphi);
1630 newPy = pt*TMath::Sin(newphi);
1631 Pz = iparticle->Pz(); // don't transform
1632 e = iparticle->Energy(); // don't transform
1635 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1636 iparticle->SetMomentum(newPx, newPy, Pz, e);
1638 } //end particle loop
1640 // now let's check that we put correctly the candidate photon in PHOS
1641 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1642 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1643 if(IsInPHOS(phi,eta))
1649 void AliGenPythia::Streamer(TBuffer &R__b)
1651 // Stream an object of class AliGenPythia.
1653 if (R__b.IsReading()) {
1654 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1655 AliGenerator::Streamer(R__b);
1656 R__b >> (Int_t&)fProcess;
1657 R__b >> (Int_t&)fStrucFunc;
1658 R__b >> (Int_t&)fForceDecay;
1662 fParentSelect.Streamer(R__b);
1663 fChildSelect.Streamer(R__b);
1665 // (AliPythia::Instance())->Streamer(R__b);
1668 // if (fDecayer) fDecayer->Streamer(R__b);
1670 R__b.WriteVersion(AliGenPythia::IsA());
1671 AliGenerator::Streamer(R__b);
1672 R__b << (Int_t)fProcess;
1673 R__b << (Int_t)fStrucFunc;
1674 R__b << (Int_t)fForceDecay;
1678 fParentSelect.Streamer(R__b);
1679 fChildSelect.Streamer(R__b);
1684 // fDecayer->Streamer(R__b);