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():
88 fDecayer(new AliDecayerPythia()),
96 fPhiMaxJet(2.* TMath::Pi()),
97 fJetReconstruction(kCell),
101 fPhiMaxGamma(2. * TMath::Pi()),
105 fPycellThreshold(0.),
107 fPycellMinEtJet(10.),
108 fPycellMaxRadius(1.),
109 fStackFillOpt(kFlavorSelection),
111 fFragmentation(kTRUE),
118 fTriggerMultiplicity(0),
119 fTriggerMultiplicityEta(0),
120 fTriggerMultiplicityPtMin(0),
121 fCountMode(kCountAll),
125 fFragPhotonInCalo(kFALSE),
127 fPhotonInCalo(kFALSE),
131 fCheckPHOSeta(kFALSE),
132 fFragPhotonOrPi0MinPt(0),
143 // Default Constructor
145 if (!AliPythiaRndm::GetPythiaRandom())
146 AliPythiaRndm::SetPythiaRandom(GetRandom());
149 AliGenPythia::AliGenPythia(Int_t npart)
161 fInteractionRate(0.),
175 fHadronisation(kTRUE),
176 fPatchOmegaDalitz(0),
178 fReadFromFile(kFALSE),
185 fDecayer(new AliDecayerPythia()),
186 fDebugEventFirst(-1),
193 fPhiMaxJet(2.* TMath::Pi()),
194 fJetReconstruction(kCell),
198 fPhiMaxGamma(2. * TMath::Pi()),
202 fPycellThreshold(0.),
204 fPycellMinEtJet(10.),
205 fPycellMaxRadius(1.),
206 fStackFillOpt(kFlavorSelection),
208 fFragmentation(kTRUE),
215 fTriggerMultiplicity(0),
216 fTriggerMultiplicityEta(0),
217 fTriggerMultiplicityPtMin(0),
218 fCountMode(kCountAll),
222 fFragPhotonInCalo(kFALSE),
224 fPhotonInCalo(kFALSE),
228 fCheckPHOSeta(kFALSE),
229 fFragPhotonOrPi0MinPt(0),
239 // default charm production at 5. 5 TeV
241 // structure function GRVHO
245 fTitle= "Particle Generator using PYTHIA";
247 // Set random number generator
248 if (!AliPythiaRndm::GetPythiaRandom())
249 AliPythiaRndm::SetPythiaRandom(GetRandom());
252 AliGenPythia::~AliGenPythia()
255 if(fEventsTime) delete fEventsTime;
258 void AliGenPythia::SetInteractionRate(Float_t rate,Float_t timewindow)
260 // Generate pileup using user specified rate
261 fInteractionRate = rate;
262 fTimeWindow = timewindow;
266 void AliGenPythia::GeneratePileup()
268 // Generate sub events time for pileup
270 if(fInteractionRate == 0.) {
271 Warning("GeneratePileup","Zero interaction specified. Skipping pileup generation.\n");
275 Int_t npart = NumberParticles();
277 Warning("GeneratePileup","Negative number of particles. Skipping pileup generation.\n");
281 if(fEventsTime) delete fEventsTime;
282 fEventsTime = new TArrayF(npart);
283 TArrayF &array = *fEventsTime;
284 for(Int_t ipart = 0; ipart < npart; ipart++)
287 Float_t eventtime = 0.;
290 eventtime += (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
291 if(eventtime > fTimeWindow) break;
292 array.Set(array.GetSize()+1);
293 array[array.GetSize()-1] = eventtime;
299 eventtime -= (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
300 if(TMath::Abs(eventtime) > fTimeWindow) break;
301 array.Set(array.GetSize()+1);
302 array[array.GetSize()-1] = eventtime;
305 SetNumberParticles(fEventsTime->GetSize());
308 void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
309 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
311 // Set pycell parameters
312 fPycellEtaMax = etamax;
315 fPycellThreshold = thresh;
316 fPycellEtSeed = etseed;
317 fPycellMinEtJet = minet;
318 fPycellMaxRadius = r;
323 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
325 // Set a range of event numbers, for which a table
326 // of generated particle will be printed
327 fDebugEventFirst = eventFirst;
328 fDebugEventLast = eventLast;
329 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
332 void AliGenPythia::Init()
336 SetMC(AliPythia::Instance());
337 fPythia=(AliPythia*) fMCEvGen;
340 fParentWeight=1./Float_t(fNpart);
344 fPythia->SetCKIN(3,fPtHardMin);
345 fPythia->SetCKIN(4,fPtHardMax);
346 fPythia->SetCKIN(7,fYHardMin);
347 fPythia->SetCKIN(8,fYHardMax);
349 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget, fNucPdf);
351 if (fFragmentation) {
352 fPythia->SetMSTP(111,1);
354 fPythia->SetMSTP(111,0);
358 // initial state radiation
359 fPythia->SetMSTP(61,fGinit);
360 // final state radiation
361 fPythia->SetMSTP(71,fGfinal);
364 fPythia->SetMSTP(91,1);
365 fPythia->SetPARP(91,fPtKick);
366 fPythia->SetPARP(93, 4. * fPtKick);
368 fPythia->SetMSTP(91,0);
373 fRL = AliRunLoader::Open(fkFileName, "Partons");
374 fRL->LoadKinematics();
380 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc, fItune);
381 // Forward Paramters to the AliPythia object
382 fDecayer->SetForceDecay(fForceDecay);
383 // Switch off Heavy Flavors on request
385 // Maximum number of quark flavours used in pdf
386 fPythia->SetMSTP(58, 3);
387 // Maximum number of flavors that can be used in showers
388 fPythia->SetMSTJ(45, 3);
389 // Switch off g->QQbar splitting in decay table
390 ((AliDecayerPythia*) fDecayer)->HeavyFlavourOff();
396 // Parent and Children Selection
399 case kPyOldUEQ2ordered:
400 case kPyOldUEQ2ordered2:
404 case kPyCharmUnforced:
405 case kPyCharmPbPbMNR:
408 case kPyCharmppMNRwmi:
409 fParentSelect[0] = 411;
410 fParentSelect[1] = 421;
411 fParentSelect[2] = 431;
412 fParentSelect[3] = 4122;
413 fParentSelect[4] = 4232;
414 fParentSelect[5] = 4132;
415 fParentSelect[6] = 4332;
421 fParentSelect[0] = 421;
424 case kPyDPlusPbPbMNR:
427 fParentSelect[0] = 411;
430 case kPyDPlusStrangePbPbMNR:
431 case kPyDPlusStrangepPbMNR:
432 case kPyDPlusStrangeppMNR:
433 fParentSelect[0] = 431;
436 case kPyLambdacppMNR:
437 fParentSelect[0] = 4122;
442 case kPyBeautyPbPbMNR:
443 case kPyBeautypPbMNR:
445 case kPyBeautyppMNRwmi:
446 fParentSelect[0]= 511;
447 fParentSelect[1]= 521;
448 fParentSelect[2]= 531;
449 fParentSelect[3]= 5122;
450 fParentSelect[4]= 5132;
451 fParentSelect[5]= 5232;
452 fParentSelect[6]= 5332;
455 case kPyBeautyUnforced:
456 fParentSelect[0] = 511;
457 fParentSelect[1] = 521;
458 fParentSelect[2] = 531;
459 fParentSelect[3] = 5122;
460 fParentSelect[4] = 5132;
461 fParentSelect[5] = 5232;
462 fParentSelect[6] = 5332;
467 fParentSelect[0] = 443;
470 case kPyMbAtlasTuneMC09:
472 case kPyMbWithDirectPhoton:
485 // JetFinder for Trigger
487 // Configure detector (EMCAL like)
489 fPythia->SetPARU(51, fPycellEtaMax);
490 fPythia->SetMSTU(51, fPycellNEta);
491 fPythia->SetMSTU(52, fPycellNPhi);
493 // Configure Jet Finder
495 fPythia->SetPARU(58, fPycellThreshold);
496 fPythia->SetPARU(52, fPycellEtSeed);
497 fPythia->SetPARU(53, fPycellMinEtJet);
498 fPythia->SetPARU(54, fPycellMaxRadius);
499 fPythia->SetMSTU(54, 2);
501 // This counts the total number of calls to Pyevnt() per run.
516 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
519 fPythia->SetPARJ(200, 0.0);
520 fPythia->SetPARJ(199, 0.0);
521 fPythia->SetPARJ(198, 0.0);
522 fPythia->SetPARJ(197, 0.0);
525 fPythia->InitQuenching(0., 0.1, 0.6e6, 0);
529 // Nestor's change of the splittings
530 fPythia->SetPARJ(200, 0.8);
531 fPythia->SetMSTJ(41, 1); // QCD radiation only
532 fPythia->SetMSTJ(42, 2); // angular ordering
533 fPythia->SetMSTJ(44, 2); // option to run alpha_s
534 fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
535 fPythia->SetMSTJ(50, 0); // No coherence in first branching
536 fPythia->SetPARJ(82, 1.); // Cut off for parton showers
537 } else if (fQuench == 4) {
538 // Armesto-Cunqueiro-Salgado change of the splittings.
539 AliFastGlauber* glauber = AliFastGlauber::Instance();
541 //read and store transverse almonds corresponding to differnt
543 glauber->SetCentralityClass(0.,0.1);
544 fPythia->SetPARJ(200, 1.);
545 fPythia->SetPARJ(198, fQhat);
546 fPythia->SetPARJ(199, fLength);
547 fPythia->SetMSTJ(42, 2); // angular ordering
548 fPythia->SetMSTJ(44, 2); // option to run alpha_s
549 fPythia->SetPARJ(82, 1.); // Cut off for parton showers
553 void AliGenPythia::Generate()
555 // Generate one event
556 if (!fPythia) fPythia=(AliPythia*) fMCEvGen;
557 fDecayer->ForceDecay();
559 Float_t polar[3] = {0,0,0};
560 Float_t origin[3] = {0,0,0};
562 // converts from mm/c to s
563 const Float_t kconv=0.001/2.999792458e8;
573 // Set collision vertex position
574 if (fVertexSmear == kPerEvent) Vertex();
583 // Switch hadronisation off
585 fPythia->SetMSTJ(1, 0);
589 // Quenching comes through medium-modified splitting functions.
590 AliFastGlauber::Instance()->GetRandomBHard(bimp);
591 fPythia->SetPARJ(197, bimp);
596 // Either produce new event or read partons from file
598 if (!fReadFromFile) {
604 fNpartons = fPythia->GetN();
606 printf("Loading Event %d\n",AliRunLoader::Instance()->GetEventNumber());
607 fRL->GetEvent(AliRunLoader::Instance()->GetEventNumber());
609 LoadEvent(fRL->Stack(), 0 , 1);
614 // Run quenching routine
618 } else if (fQuench == 2){
619 fPythia->Pyquen(208., 0, 0.);
620 } else if (fQuench == 3) {
621 // Quenching is via multiplicative correction of the splittings
625 // Switch hadronisation on
627 if (fHadronisation) {
628 fPythia->SetMSTJ(1, 1);
630 // .. and perform hadronisation
631 // printf("Calling hadronisation %d\n", fPythia->GetN());
633 if (fPatchOmegaDalitz) {
634 fPythia->SetMDCY(fPythia->Pycomp(111) ,1, 0);
636 fPythia->DalitzDecays();
637 fPythia->SetMDCY(fPythia->Pycomp(111) ,1, 1);
642 fPythia->ImportParticles(&fParticles,"All");
644 if (TMath::Abs(fDyBoost) > 1.e-4) Boost();
645 if(TMath::Abs(fXingAngleY) > 1.e-10) BeamCrossAngle();
653 Int_t np = fParticles.GetEntriesFast();
655 if (np == 0) continue;
659 Int_t* pParent = new Int_t[np];
660 Int_t* pSelected = new Int_t[np];
661 Int_t* trackIt = new Int_t[np];
662 for (i = 0; i < np; i++) {
668 Int_t nc = 0; // Total n. of selected particles
669 Int_t nParents = 0; // Selected parents
670 Int_t nTkbles = 0; // Trackable particles
671 if (fProcess != kPyMbDefault &&
673 fProcess != kPyMbAtlasTuneMC09 &&
674 fProcess != kPyMbWithDirectPhoton &&
675 fProcess != kPyJets &&
676 fProcess != kPyDirectGamma &&
677 fProcess != kPyMbNonDiffr &&
678 fProcess != kPyMbMSEL1 &&
681 fProcess != kPyCharmppMNRwmi &&
682 fProcess != kPyBeautyppMNRwmi &&
683 fProcess != kPyBeautyJets) {
685 for (i = 0; i < np; i++) {
686 TParticle* iparticle = (TParticle *) fParticles.At(i);
687 Int_t ks = iparticle->GetStatusCode();
688 kf = CheckPDGCode(iparticle->GetPdgCode());
689 // No initial state partons
690 if (ks==21) continue;
692 // Heavy Flavor Selection
699 if (kfl > 100000) kfl %= 100000;
700 if (kfl > 10000) kfl %= 10000;
702 if (kfl > 10) kfl/=100;
704 if (kfl > 10) kfl/=10;
705 Int_t ipa = iparticle->GetFirstMother()-1;
708 // Establish mother daughter relation between heavy quarks and mesons
710 if (kf >= fFlavorSelect && kf <= 6) {
711 Int_t idau = iparticle->GetFirstDaughter() - 1;
713 TParticle* daughter = (TParticle *) fParticles.At(idau);
714 Int_t pdgD = daughter->GetPdgCode();
715 if (pdgD == 91 || pdgD == 92) {
716 Int_t jmin = daughter->GetFirstDaughter() - 1;
717 Int_t jmax = daughter->GetLastDaughter() - 1;
718 for (Int_t jp = jmin; jp <= jmax; jp++)
719 ((TParticle *) fParticles.At(jp))->SetFirstMother(i+1);
720 } // is string or cluster
726 TParticle * mother = (TParticle *) fParticles.At(ipa);
727 kfMo = TMath::Abs(mother->GetPdgCode());
730 // What to keep in Stack?
731 Bool_t flavorOK = kFALSE;
732 Bool_t selectOK = kFALSE;
734 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
736 if (kfl > fFlavorSelect) {
740 if (kfl == fFlavorSelect) flavorOK = kTRUE;
742 switch (fStackFillOpt) {
743 case kFlavorSelection:
746 case kParentSelection:
747 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
750 if (flavorOK && selectOK) {
752 // Heavy flavor hadron or quark
754 // Kinematic seletion on final state heavy flavor mesons
755 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
760 if (ParentSelected(kf)) ++nParents; // Update parent count
761 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
763 // Kinematic seletion on decay products
764 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
765 && !KinematicSelection(iparticle, 1))
771 // Select if mother was selected and is not tracked
773 if (pSelected[ipa] &&
774 !trackIt[ipa] && // mother will be tracked ?
775 kfMo != 5 && // mother is b-quark, don't store fragments
776 kfMo != 4 && // mother is c-quark, don't store fragments
777 kf != 92) // don't store string
780 // Semi-stable or de-selected: diselect decay products:
783 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
785 Int_t ipF = iparticle->GetFirstDaughter();
786 Int_t ipL = iparticle->GetLastDaughter();
787 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
789 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
790 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
793 if (pSelected[i] == -1) pSelected[i] = 0;
794 if (!pSelected[i]) continue;
795 // Count quarks only if you did not include fragmentation
796 if (fFragmentation && kf <= 10) continue;
799 // Decision on tracking
802 // Track final state particle
803 if (ks == 1) trackIt[i] = 1;
804 // Track semi-stable particles
805 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
806 // Track particles selected by process if undecayed.
807 if (fForceDecay == kNoDecay) {
808 if (ParentSelected(kf)) trackIt[i] = 1;
810 if (ParentSelected(kf)) trackIt[i] = 0;
812 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
816 } // particle selection loop
818 for (i = 0; i<np; i++) {
819 if (!pSelected[i]) continue;
820 TParticle * iparticle = (TParticle *) fParticles.At(i);
821 kf = CheckPDGCode(iparticle->GetPdgCode());
822 Int_t ks = iparticle->GetStatusCode();
823 p[0] = iparticle->Px();
824 p[1] = iparticle->Py();
825 p[2] = iparticle->Pz();
826 p[3] = iparticle->Energy();
828 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
829 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
830 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
832 Float_t tof = kconv*iparticle->T();
833 Int_t ipa = iparticle->GetFirstMother()-1;
834 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
836 PushTrack(fTrackIt*trackIt[i], iparent, kf,
837 p[0], p[1], p[2], p[3],
838 origin[0], origin[1], origin[2], tof,
839 polar[0], polar[1], polar[2],
840 kPPrimary, nt, 1., ks);
857 switch (fCountMode) {
859 // printf(" Count all \n");
863 // printf(" Count parents \n");
866 case kCountTrackables:
867 // printf(" Count trackable \n");
871 if (jev >= fNpart || fNpart == -1) {
872 fKineBias=Float_t(fNpart)/Float_t(fTrials);
874 fQ += fPythia->GetVINT(51);
875 fX1 += fPythia->GetVINT(41);
876 fX2 += fPythia->GetVINT(42);
877 fTrialsRun += fTrials;
884 SetHighWaterMark(nt);
885 // adjust weight due to kinematic selection
888 fXsection=fPythia->GetPARI(1);
891 Int_t AliGenPythia::GenerateMB()
894 // Min Bias selection and other global selections
896 Int_t i, kf, nt, iparent;
899 Float_t polar[3] = {0,0,0};
900 Float_t origin[3] = {0,0,0};
901 // converts from mm/c to s
902 const Float_t kconv=0.001/2.999792458e8;
906 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
910 Int_t* pParent = new Int_t[np];
911 for (i=0; i< np; i++) pParent[i] = -1;
912 if (fProcess == kPyJets || fProcess == kPyDirectGamma || fProcess == kPyBeautyJets || fProcess == kPyBeautyppMNRwmi) {
913 TParticle* jet1 = (TParticle *) fParticles.At(6);
914 TParticle* jet2 = (TParticle *) fParticles.At(7);
915 if (!CheckTrigger(jet1, jet2)) {
921 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
922 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
927 if (fFragPhotonInCalo) pdg = 22 ; // Photon
928 else if (fPi0InCalo) pdg = 111 ; // Pi0
930 for (i=0; i< np; i++) {
931 TParticle* iparticle = (TParticle *) fParticles.At(i);
932 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
933 iparticle->Pt() > fFragPhotonOrPi0MinPt){
934 Int_t imother = iparticle->GetFirstMother() - 1;
935 TParticle* pmother = (TParticle *) fParticles.At(imother);
937 (pdg == 22 && pmother->GetStatusCode() != 11)) //No photon from hadron decay
939 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
940 Float_t eta =TMath::Abs(iparticle->Eta()); //in calos etamin=-etamax
941 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
942 (fCheckPHOS && IsInPHOS(phi,eta)) )
951 // Select beauty jets with electron in EMCAL
952 if (fProcess == kPyBeautyJets && fEleInEMCAL) {
956 Int_t pdg = 11; //electron
961 for (i=0; i< np; i++) {
962 TParticle* iparticle = (TParticle *) fParticles.At(i);
963 if(iparticle->GetStatusCode()==1 && TMath::Abs(iparticle->GetPdgCode())==pdg &&
964 iparticle->Pt() > fElectronMinPt){
965 pt = iparticle->Pt();
966 phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
967 eta =TMath::Abs(iparticle->Eta()); //in calos etamin=-etamax
968 if(IsInEMCAL(phi,eta))
974 AliDebug(5,Form("Found an electron jet (pt,eta,phi) = (%f,%f,%f)",pt,eta,phi));
976 // Check for minimum multiplicity
977 if (fTriggerMultiplicity > 0) {
978 Int_t multiplicity = 0;
979 for (i = 0; i < np; i++) {
980 TParticle * iparticle = (TParticle *) fParticles.At(i);
982 Int_t statusCode = iparticle->GetStatusCode();
984 // Initial state particle
988 if (fTriggerMultiplicityEta > 0 && TMath::Abs(iparticle->Eta()) > fTriggerMultiplicityEta)
991 if (iparticle->Pt() < fTriggerMultiplicityPtMin)
994 TParticlePDG* pdgPart = iparticle->GetPDG();
995 if (pdgPart && pdgPart->Charge() == 0)
1001 if (multiplicity < fTriggerMultiplicity) {
1005 Printf("Triggered on event with multiplicity of %d >= %d", multiplicity, fTriggerMultiplicity);
1008 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
1009 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
1011 Bool_t okd = kFALSE;
1015 for (i=0; i< np; i++) {
1016 TParticle* iparticle = (TParticle *) fParticles.At(i);
1017 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
1018 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
1020 if(iparticle->GetStatusCode() == 1
1021 && iparticle->GetPdgCode() == pdg
1022 && iparticle->Pt() > fPhotonMinPt
1025 // first check if the photon is in PHOS phi
1026 if(IsInPHOS(phi,eta)){
1030 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
1035 if(!okd && iphcand != -1) // execute rotation in phi
1036 RotatePhi(iphcand,okd);
1042 if (fTriggerParticle) {
1043 Bool_t triggered = kFALSE;
1044 for (i = 0; i < np; i++) {
1045 TParticle * iparticle = (TParticle *) fParticles.At(i);
1046 kf = CheckPDGCode(iparticle->GetPdgCode());
1047 if (kf != fTriggerParticle) continue;
1048 if (iparticle->Pt() == 0.) continue;
1049 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
1060 // Check if there is a ccbar or bbbar pair with at least one of the two
1061 // in fYMin < y < fYMax
1063 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi || fProcess == kPyBeautyJets) {
1064 TParticle *partCheck;
1066 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
1067 Bool_t theChild=kFALSE;
1069 Int_t pdg,mpdg,mpdgUpperFamily;
1070 for(i=0; i<np; i++) {
1071 partCheck = (TParticle*)fParticles.At(i);
1072 pdg = partCheck->GetPdgCode();
1073 if(TMath::Abs(pdg) == fFlavorSelect) { // quark
1074 if(pdg>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
1075 y = 0.5*TMath::Log((partCheck->Energy()+partCheck->Pz()+1.e-13)/
1076 (partCheck->Energy()-partCheck->Pz()+1.e-13));
1077 if(y>fYMin && y<fYMax) inYcut=kTRUE;
1079 if(fCutOnChild && TMath::Abs(pdg) == fPdgCodeParticleforAcceptanceCut) {
1080 Int_t mi = partCheck->GetFirstMother() - 1;
1082 mother = (TParticle*)fParticles.At(mi);
1083 mpdg=TMath::Abs(mother->GetPdgCode());
1084 mpdgUpperFamily=(mpdg>1000 ? mpdg+1000 : mpdg+100); // keep e from c from b
1085 if ( ParentSelected(mpdg) ||
1086 (fFlavorSelect==5 && ParentSelected(mpdgUpperFamily))) {
1087 if (KinematicSelection(partCheck,1)) {
1093 if (!theQ || !theQbar || !inYcut) { // one of the c/b conditions not satisfied
1097 if (fCutOnChild && !theChild) { // one of the child conditions not satisfied
1104 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
1105 if ( (fProcess == kPyW ||
1107 fProcess == kPyMbDefault ||
1108 fProcess == kPyMb ||
1109 fProcess == kPyMbAtlasTuneMC09 ||
1110 fProcess == kPyMbWithDirectPhoton ||
1111 fProcess == kPyMbNonDiffr)
1112 && (fCutOnChild == 1) ) {
1113 if ( !CheckKinematicsOnChild() ) {
1120 for (i = 0; i < np; i++) {
1122 TParticle * iparticle = (TParticle *) fParticles.At(i);
1123 kf = CheckPDGCode(iparticle->GetPdgCode());
1124 Int_t ks = iparticle->GetStatusCode();
1125 Int_t km = iparticle->GetFirstMother();
1126 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
1128 ((fProcess == kPyJets || fProcess == kPyBeautyJets) && ks == 21 && km == 0 && i>1)) {
1130 if (ks == 1) trackIt = 1;
1131 Int_t ipa = iparticle->GetFirstMother()-1;
1133 iparent = (ipa > -1) ? pParent[ipa] : -1;
1136 // store track information
1137 p[0] = iparticle->Px();
1138 p[1] = iparticle->Py();
1139 p[2] = iparticle->Pz();
1140 p[3] = iparticle->Energy();
1143 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
1144 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
1145 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
1147 Float_t tof = fEventTime + kconv * iparticle->T();
1149 PushTrack(fTrackIt*trackIt, iparent, kf,
1150 p[0], p[1], p[2], p[3],
1151 origin[0], origin[1], origin[2], tof,
1152 polar[0], polar[1], polar[2],
1153 kPPrimary, nt, 1., ks);
1157 SetHighWaterMark(nt);
1159 } // select particle
1168 void AliGenPythia::FinishRun()
1170 // Print x-section summary
1179 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1180 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1183 void AliGenPythia::AdjustWeights() const
1185 // Adjust the weights after generation of all events
1189 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1190 for (Int_t i=0; i<ntrack; i++) {
1191 part= gAlice->GetMCApp()->Particle(i);
1192 part->SetWeight(part->GetWeight()*fKineBias);
1197 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2, Int_t pdfset)
1199 // Treat protons as inside nuclei with mass numbers a1 and a2
1203 fNucPdf = pdfset; // 0 EKS98 1 EPS08
1208 void AliGenPythia::MakeHeader()
1211 // Make header for the simulated event
1214 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1215 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(2);
1218 // Builds the event header, to be called after each event
1219 if (fHeader) delete fHeader;
1220 fHeader = new AliGenPythiaEventHeader("Pythia");
1223 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
1226 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1229 fHeader->SetPrimaryVertex(fVertex);
1230 fHeader->SetInteractionTime(fEventTime);
1232 // Number of primaries
1233 fHeader->SetNProduced(fNprimaries);
1235 // Jets that have triggered
1237 //Need to store jets for b-jet studies too!
1238 if (fProcess == kPyJets || fProcess == kPyDirectGamma || fProcess == kPyBeautyJets || fProcess == kPyBeautyppMNRwmi)
1241 Float_t jets[4][10];
1242 GetJets(njet, ntrig, jets);
1245 for (Int_t i = 0; i < ntrig; i++) {
1246 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1251 // Copy relevant information from external header, if present.
1256 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1257 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1259 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1262 exHeader->TriggerJet(i, uqJet);
1263 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1267 // Store quenching parameters
1270 Double_t z[4] = {0.};
1276 fPythia->GetQuenchingParameters(xp, yp, z);
1277 } else if (fQuench == 2){
1279 Double_t r1 = PARIMP.rb1;
1280 Double_t r2 = PARIMP.rb2;
1281 Double_t b = PARIMP.b1;
1282 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1283 Double_t phi = PARIMP.psib1;
1284 xp = r * TMath::Cos(phi);
1285 yp = r * TMath::Sin(phi);
1287 } else if (fQuench == 4) {
1291 AliFastGlauber::Instance()->GetSavedXY(xy);
1292 AliFastGlauber::Instance()->GetSavedI0I1(i0i1);
1295 ((AliGenPythiaEventHeader*) fHeader)->SetImpactParameter(fImpact);
1298 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1299 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1303 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetVINT(47));
1311 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
1313 // Check the kinematic trigger condition
1316 eta[0] = jet1->Eta();
1317 eta[1] = jet2->Eta();
1319 phi[0] = jet1->Phi();
1320 phi[1] = jet2->Phi();
1322 pdg[0] = jet1->GetPdgCode();
1323 pdg[1] = jet2->GetPdgCode();
1324 Bool_t triggered = kFALSE;
1326 if (fProcess == kPyJets || fProcess == kPyBeautyJets || fProcess == kPyBeautyppMNRwmi) {
1329 Float_t jets[4][10];
1331 // Use Pythia clustering on parton level to determine jet axis
1333 GetJets(njets, ntrig, jets);
1335 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1340 if (pdg[0] == kGamma) {
1344 //Check eta range first...
1345 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1346 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1348 //Eta is okay, now check phi range
1349 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1350 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1361 Bool_t AliGenPythia::CheckKinematicsOnChild(){
1363 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1365 Bool_t checking = kFALSE;
1366 Int_t j, kcode, ks, km;
1367 Int_t nPartAcc = 0; //number of particles in the acceptance range
1368 Int_t numberOfAcceptedParticles = 1;
1369 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1370 Int_t npart = fParticles.GetEntriesFast();
1372 for (j = 0; j<npart; j++) {
1373 TParticle * jparticle = (TParticle *) fParticles.At(j);
1374 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1375 ks = jparticle->GetStatusCode();
1376 km = jparticle->GetFirstMother();
1378 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1381 if( numberOfAcceptedParticles <= nPartAcc){
1390 void AliGenPythia::LoadEvent(AliStack* stack, Int_t flag, Int_t reHadr)
1393 // Load event into Pythia Common Block
1396 Int_t npart = stack -> GetNprimary();
1400 (fPythia->GetPyjets())->N = npart;
1402 n0 = (fPythia->GetPyjets())->N;
1403 (fPythia->GetPyjets())->N = n0 + npart;
1407 for (Int_t part = 0; part < npart; part++) {
1408 TParticle *mPart = stack->Particle(part);
1410 Int_t kf = mPart->GetPdgCode();
1411 Int_t ks = mPart->GetStatusCode();
1412 Int_t idf = mPart->GetFirstDaughter();
1413 Int_t idl = mPart->GetLastDaughter();
1416 if (ks == 11 || ks == 12) {
1423 Float_t px = mPart->Px();
1424 Float_t py = mPart->Py();
1425 Float_t pz = mPart->Pz();
1426 Float_t e = mPart->Energy();
1427 Float_t m = mPart->GetCalcMass();
1430 (fPythia->GetPyjets())->P[0][part+n0] = px;
1431 (fPythia->GetPyjets())->P[1][part+n0] = py;
1432 (fPythia->GetPyjets())->P[2][part+n0] = pz;
1433 (fPythia->GetPyjets())->P[3][part+n0] = e;
1434 (fPythia->GetPyjets())->P[4][part+n0] = m;
1436 (fPythia->GetPyjets())->K[1][part+n0] = kf;
1437 (fPythia->GetPyjets())->K[0][part+n0] = ks;
1438 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
1439 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
1440 (fPythia->GetPyjets())->K[2][part+n0] = mPart->GetFirstMother() + 1;
1444 void AliGenPythia::LoadEvent(TObjArray* stack, Int_t flag, Int_t reHadr)
1447 // Load event into Pythia Common Block
1450 Int_t npart = stack -> GetEntries();
1454 (fPythia->GetPyjets())->N = npart;
1456 n0 = (fPythia->GetPyjets())->N;
1457 (fPythia->GetPyjets())->N = n0 + npart;
1461 for (Int_t part = 0; part < npart; part++) {
1462 TParticle *mPart = dynamic_cast<TParticle *>(stack->At(part));
1463 Int_t kf = mPart->GetPdgCode();
1464 Int_t ks = mPart->GetStatusCode();
1465 Int_t idf = mPart->GetFirstDaughter();
1466 Int_t idl = mPart->GetLastDaughter();
1469 if (ks == 11 || ks == 12) {
1476 Float_t px = mPart->Px();
1477 Float_t py = mPart->Py();
1478 Float_t pz = mPart->Pz();
1479 Float_t e = mPart->Energy();
1480 Float_t m = mPart->GetCalcMass();
1483 (fPythia->GetPyjets())->P[0][part+n0] = px;
1484 (fPythia->GetPyjets())->P[1][part+n0] = py;
1485 (fPythia->GetPyjets())->P[2][part+n0] = pz;
1486 (fPythia->GetPyjets())->P[3][part+n0] = e;
1487 (fPythia->GetPyjets())->P[4][part+n0] = m;
1489 (fPythia->GetPyjets())->K[1][part+n0] = kf;
1490 (fPythia->GetPyjets())->K[0][part+n0] = ks;
1491 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
1492 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
1493 (fPythia->GetPyjets())->K[2][part+n0] = mPart->GetFirstMother() + 1;
1498 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1501 // Calls the Pythia jet finding algorithm to find jets in the current event
1506 Int_t n = fPythia->GetN();
1510 fPythia->Pycell(njets);
1512 for (i = 0; i < njets; i++) {
1513 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1514 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1515 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1516 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1527 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1530 // Calls the Pythia clustering algorithm to find jets in the current event
1532 Int_t n = fPythia->GetN();
1535 if (fJetReconstruction == kCluster) {
1537 // Configure cluster algorithm
1539 fPythia->SetPARU(43, 2.);
1540 fPythia->SetMSTU(41, 1);
1542 // Call cluster algorithm
1544 fPythia->Pyclus(nJets);
1546 // Loading jets from common block
1552 fPythia->Pycell(nJets);
1556 for (i = 0; i < nJets; i++) {
1557 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1558 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1559 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1560 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1561 Float_t pt = TMath::Sqrt(px * px + py * py);
1562 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1563 Float_t theta = TMath::ATan2(pt,pz);
1564 Float_t et = e * TMath::Sin(theta);
1565 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1567 eta > fEtaMinJet && eta < fEtaMaxJet &&
1568 phi > fPhiMinJet && phi < fPhiMaxJet &&
1569 et > fEtMinJet && et < fEtMaxJet
1572 jets[0][nJetsTrig] = px;
1573 jets[1][nJetsTrig] = py;
1574 jets[2][nJetsTrig] = pz;
1575 jets[3][nJetsTrig] = e;
1577 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1579 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1584 void AliGenPythia::GetSubEventTime()
1586 // Calculates time of the next subevent
1589 TArrayF &array = *fEventsTime;
1590 fEventTime = array[fCurSubEvent++];
1592 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1596 Bool_t AliGenPythia::IsInEMCAL(Float_t phi, Float_t eta)
1598 // Is particle in EMCAL acceptance?
1599 // phi in degrees, etamin=-etamax
1600 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1607 Bool_t AliGenPythia::IsInPHOS(Float_t phi, Float_t eta)
1609 // Is particle in PHOS acceptance?
1610 // Acceptance slightly larger considered.
1611 // phi in degrees, etamin=-etamax
1612 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1619 void AliGenPythia::RotatePhi(Int_t iphcand, Bool_t& okdd)
1621 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1622 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1623 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1624 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1626 //calculate deltaphi
1627 TParticle* ph = (TParticle *) fParticles.At(iphcand);
1628 Double_t phphi = ph->Phi();
1629 Double_t deltaphi = phiPHOS - phphi;
1633 //loop for all particles and produce the phi rotation
1634 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
1635 Double_t oldphi, newphi;
1636 Double_t newVx, newVy, r, vZ, time;
1637 Double_t newPx, newPy, pt, pz, e;
1638 for(Int_t i=0; i< np; i++) {
1639 TParticle* iparticle = (TParticle *) fParticles.At(i);
1640 oldphi = iparticle->Phi();
1641 newphi = oldphi + deltaphi;
1642 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1643 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1646 newVx = r * TMath::Cos(newphi);
1647 newVy = r * TMath::Sin(newphi);
1648 vZ = iparticle->Vz(); // don't transform
1649 time = iparticle->T(); // don't transform
1651 pt = iparticle->Pt();
1652 newPx = pt * TMath::Cos(newphi);
1653 newPy = pt * TMath::Sin(newphi);
1654 pz = iparticle->Pz(); // don't transform
1655 e = iparticle->Energy(); // don't transform
1658 iparticle->SetProductionVertex(newVx, newVy, vZ, time);
1659 iparticle->SetMomentum(newPx, newPy, pz, e);
1661 } //end particle loop
1663 // now let's check that we put correctly the candidate photon in PHOS
1664 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1665 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1666 if(IsInPHOS(phi,eta))