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():
86 fDecayer(new AliDecayerPythia()),
94 fPhiMaxJet(2.* TMath::Pi()),
95 fJetReconstruction(kCell),
99 fPhiMaxGamma(2. * TMath::Pi()),
103 fPycellThreshold(0.),
105 fPycellMinEtJet(10.),
106 fPycellMaxRadius(1.),
107 fStackFillOpt(kFlavorSelection),
109 fFragmentation(kTRUE),
116 fTriggerMultiplicity(0),
117 fTriggerMultiplicityEta(0),
118 fCountMode(kCountAll),
122 fFragPhotonInCalo(kFALSE),
124 fPhotonInCalo(kFALSE),
128 fCheckPHOSeta(kFALSE),
129 fFragPhotonOrPi0MinPt(0),
140 // Default Constructor
143 if (!AliPythiaRndm::GetPythiaRandom())
144 AliPythiaRndm::SetPythiaRandom(GetRandom());
147 AliGenPythia::AliGenPythia(Int_t npart)
158 fInteractionRate(0.),
172 fHadronisation(kTRUE),
174 fReadFromFile(kFALSE),
181 fDecayer(new AliDecayerPythia()),
182 fDebugEventFirst(-1),
189 fPhiMaxJet(2.* TMath::Pi()),
190 fJetReconstruction(kCell),
194 fPhiMaxGamma(2. * TMath::Pi()),
198 fPycellThreshold(0.),
200 fPycellMinEtJet(10.),
201 fPycellMaxRadius(1.),
202 fStackFillOpt(kFlavorSelection),
204 fFragmentation(kTRUE),
211 fTriggerMultiplicity(0),
212 fTriggerMultiplicityEta(0),
213 fCountMode(kCountAll),
217 fFragPhotonInCalo(kFALSE),
219 fPhotonInCalo(kFALSE),
223 fCheckPHOSeta(kFALSE),
224 fFragPhotonOrPi0MinPt(0),
234 // default charm production at 5. 5 TeV
236 // structure function GRVHO
240 fTitle= "Particle Generator using PYTHIA";
242 // Set random number generator
243 if (!AliPythiaRndm::GetPythiaRandom())
244 AliPythiaRndm::SetPythiaRandom(GetRandom());
248 AliGenPythia::~AliGenPythia()
251 if(fEventsTime) delete fEventsTime;
254 void AliGenPythia::SetInteractionRate(Float_t rate,Float_t timewindow)
256 // Generate pileup using user specified rate
257 fInteractionRate = rate;
258 fTimeWindow = timewindow;
262 void AliGenPythia::GeneratePileup()
264 // Generate sub events time for pileup
266 if(fInteractionRate == 0.) {
267 Warning("GeneratePileup","Zero interaction specified. Skipping pileup generation.\n");
271 Int_t npart = NumberParticles();
273 Warning("GeneratePileup","Negative number of particles. Skipping pileup generation.\n");
277 if(fEventsTime) delete fEventsTime;
278 fEventsTime = new TArrayF(npart);
279 TArrayF &array = *fEventsTime;
280 for(Int_t ipart = 0; ipart < npart; ipart++)
283 Float_t eventtime = 0.;
286 eventtime += (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
287 if(eventtime > fTimeWindow) break;
288 array.Set(array.GetSize()+1);
289 array[array.GetSize()-1] = eventtime;
295 eventtime -= (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
296 if(TMath::Abs(eventtime) > fTimeWindow) break;
297 array.Set(array.GetSize()+1);
298 array[array.GetSize()-1] = eventtime;
301 SetNumberParticles(fEventsTime->GetSize());
304 void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
305 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
307 // Set pycell parameters
308 fPycellEtaMax = etamax;
311 fPycellThreshold = thresh;
312 fPycellEtSeed = etseed;
313 fPycellMinEtJet = minet;
314 fPycellMaxRadius = r;
319 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
321 // Set a range of event numbers, for which a table
322 // of generated particle will be printed
323 fDebugEventFirst = eventFirst;
324 fDebugEventLast = eventLast;
325 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
328 void AliGenPythia::Init()
332 SetMC(AliPythia::Instance());
333 fPythia=(AliPythia*) fMCEvGen;
336 fParentWeight=1./Float_t(fNpart);
340 fPythia->SetCKIN(3,fPtHardMin);
341 fPythia->SetCKIN(4,fPtHardMax);
342 fPythia->SetCKIN(7,fYHardMin);
343 fPythia->SetCKIN(8,fYHardMax);
345 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget, fNucPdf);
347 if (fFragmentation) {
348 fPythia->SetMSTP(111,1);
350 fPythia->SetMSTP(111,0);
354 // initial state radiation
355 fPythia->SetMSTP(61,fGinit);
356 // final state radiation
357 fPythia->SetMSTP(71,fGfinal);
360 fPythia->SetMSTP(91,1);
361 fPythia->SetPARP(91,fPtKick);
362 fPythia->SetPARP(93, 4. * fPtKick);
364 fPythia->SetMSTP(91,0);
369 fRL = AliRunLoader::Open(fFileName, "Partons");
370 fRL->LoadKinematics();
376 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
377 // Forward Paramters to the AliPythia object
378 fDecayer->SetForceDecay(fForceDecay);
379 // Switch off Heavy Flavors on request
381 // Maximum number of quark flavours used in pdf
382 fPythia->SetMSTP(58, 3);
383 // Maximum number of flavors that can be used in showers
384 fPythia->SetMSTJ(45, 3);
385 // Switch off g->QQbar splitting in decay table
386 ((AliDecayerPythia*) fDecayer)->HeavyFlavourOff();
392 // Parent and Children Selection
395 case kPyOldUEQ2ordered:
396 case kPyOldUEQ2ordered2:
400 case kPyCharmUnforced:
401 case kPyCharmPbPbMNR:
404 case kPyCharmppMNRwmi:
405 fParentSelect[0] = 411;
406 fParentSelect[1] = 421;
407 fParentSelect[2] = 431;
408 fParentSelect[3] = 4122;
409 fParentSelect[4] = 4232;
410 fParentSelect[5] = 4132;
411 fParentSelect[6] = 4332;
417 fParentSelect[0] = 421;
420 case kPyDPlusPbPbMNR:
423 fParentSelect[0] = 411;
426 case kPyDPlusStrangePbPbMNR:
427 case kPyDPlusStrangepPbMNR:
428 case kPyDPlusStrangeppMNR:
429 fParentSelect[0] = 431;
434 case kPyBeautyPbPbMNR:
435 case kPyBeautypPbMNR:
437 case kPyBeautyppMNRwmi:
438 fParentSelect[0]= 511;
439 fParentSelect[1]= 521;
440 fParentSelect[2]= 531;
441 fParentSelect[3]= 5122;
442 fParentSelect[4]= 5132;
443 fParentSelect[5]= 5232;
444 fParentSelect[6]= 5332;
447 case kPyBeautyUnforced:
448 fParentSelect[0] = 511;
449 fParentSelect[1] = 521;
450 fParentSelect[2] = 531;
451 fParentSelect[3] = 5122;
452 fParentSelect[4] = 5132;
453 fParentSelect[5] = 5232;
454 fParentSelect[6] = 5332;
459 fParentSelect[0] = 443;
463 case kPyMbWithDirectPhoton:
476 // JetFinder for Trigger
478 // Configure detector (EMCAL like)
480 fPythia->SetPARU(51, fPycellEtaMax);
481 fPythia->SetMSTU(51, fPycellNEta);
482 fPythia->SetMSTU(52, fPycellNPhi);
484 // Configure Jet Finder
486 fPythia->SetPARU(58, fPycellThreshold);
487 fPythia->SetPARU(52, fPycellEtSeed);
488 fPythia->SetPARU(53, fPycellMinEtJet);
489 fPythia->SetPARU(54, fPycellMaxRadius);
490 fPythia->SetMSTU(54, 2);
492 // This counts the total number of calls to Pyevnt() per run.
507 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
510 fPythia->SetPARJ(200, 0.0);
511 fPythia->SetPARJ(199, 0.0);
512 fPythia->SetPARJ(198, 0.0);
513 fPythia->SetPARJ(197, 0.0);
516 fPythia->InitQuenching(0., 0.1, 0.6e6, 0);
520 // Nestor's change of the splittings
521 fPythia->SetPARJ(200, 0.8);
522 fPythia->SetMSTJ(41, 1); // QCD radiation only
523 fPythia->SetMSTJ(42, 2); // angular ordering
524 fPythia->SetMSTJ(44, 2); // option to run alpha_s
525 fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
526 fPythia->SetMSTJ(50, 0); // No coherence in first branching
527 fPythia->SetPARJ(82, 1.); // Cut off for parton showers
528 } else if (fQuench == 4) {
529 // Armesto-Cunqueiro-Salgado change of the splittings.
530 AliFastGlauber* glauber = AliFastGlauber::Instance();
532 //read and store transverse almonds corresponding to differnt
534 glauber->SetCentralityClass(0.,0.1);
535 fPythia->SetPARJ(200, 1.);
536 fPythia->SetPARJ(198, fQhat);
537 fPythia->SetPARJ(199, fLength);
538 fPythia->SetMSTJ(42, 2); // angular ordering
539 fPythia->SetMSTJ(44, 2); // option to run alpha_s
540 fPythia->SetPARJ(82, 1.); // Cut off for parton showers
544 void AliGenPythia::Generate()
546 // Generate one event
547 if (!fPythia) fPythia=(AliPythia*) fMCEvGen;
548 fDecayer->ForceDecay();
550 Float_t polar[3] = {0,0,0};
551 Float_t origin[3] = {0,0,0};
553 // converts from mm/c to s
554 const Float_t kconv=0.001/2.999792458e8;
564 // Set collision vertex position
565 if (fVertexSmear == kPerEvent) Vertex();
574 // Switch hadronisation off
576 fPythia->SetMSTJ(1, 0);
580 // Quenching comes through medium-modified splitting functions.
581 AliFastGlauber::Instance()->GetRandomBHard(bimp);
582 fPythia->SetPARJ(197, bimp);
586 // Either produce new event or read partons from file
588 if (!fReadFromFile) {
594 fNpartons = fPythia->GetN();
596 printf("Loading Event %d\n",AliRunLoader::Instance()->GetEventNumber());
597 fRL->GetEvent(AliRunLoader::Instance()->GetEventNumber());
599 LoadEvent(fRL->Stack(), 0 , 1);
604 // Run quenching routine
608 } else if (fQuench == 2){
609 fPythia->Pyquen(208., 0, 0.);
610 } else if (fQuench == 3) {
611 // Quenching is via multiplicative correction of the splittings
615 // Switch hadronisation on
617 if (fHadronisation) {
618 fPythia->SetMSTJ(1, 1);
620 // .. and perform hadronisation
621 // printf("Calling hadronisation %d\n", fPythia->GetN());
625 fPythia->ImportParticles(&fParticles,"All");
633 Int_t np = fParticles.GetEntriesFast();
635 if (np == 0) continue;
639 Int_t* pParent = new Int_t[np];
640 Int_t* pSelected = new Int_t[np];
641 Int_t* trackIt = new Int_t[np];
642 for (i = 0; i < np; i++) {
648 Int_t nc = 0; // Total n. of selected particles
649 Int_t nParents = 0; // Selected parents
650 Int_t nTkbles = 0; // Trackable particles
651 if (fProcess != kPyMbDefault &&
653 fProcess != kPyMbWithDirectPhoton &&
654 fProcess != kPyJets &&
655 fProcess != kPyDirectGamma &&
656 fProcess != kPyMbNonDiffr &&
657 fProcess != kPyMbMSEL1 &&
660 fProcess != kPyCharmppMNRwmi &&
661 fProcess != kPyBeautyppMNRwmi &&
662 fProcess != kPyBeautyJets) {
664 for (i = 0; i < np; i++) {
665 TParticle* iparticle = (TParticle *) fParticles.At(i);
666 Int_t ks = iparticle->GetStatusCode();
667 kf = CheckPDGCode(iparticle->GetPdgCode());
668 // No initial state partons
669 if (ks==21) continue;
671 // Heavy Flavor Selection
678 if (kfl > 100000) kfl %= 100000;
679 if (kfl > 10000) kfl %= 10000;
681 if (kfl > 10) kfl/=100;
683 if (kfl > 10) kfl/=10;
684 Int_t ipa = iparticle->GetFirstMother()-1;
687 // Establish mother daughter relation between heavy quarks and mesons
689 if (kf >= fFlavorSelect && kf <= 6) {
690 Int_t idau = iparticle->GetFirstDaughter() - 1;
692 TParticle* daughter = (TParticle *) fParticles.At(idau);
693 Int_t pdgD = daughter->GetPdgCode();
694 if (pdgD == 91 || pdgD == 92) {
695 Int_t jmin = daughter->GetFirstDaughter() - 1;
696 Int_t jmax = daughter->GetLastDaughter() - 1;
697 for (Int_t jp = jmin; jp <= jmax; jp++)
698 ((TParticle *) fParticles.At(jp))->SetFirstMother(i+1);
699 } // is string or cluster
705 TParticle * mother = (TParticle *) fParticles.At(ipa);
706 kfMo = TMath::Abs(mother->GetPdgCode());
709 // What to keep in Stack?
710 Bool_t flavorOK = kFALSE;
711 Bool_t selectOK = kFALSE;
713 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
715 if (kfl > fFlavorSelect) {
719 if (kfl == fFlavorSelect) flavorOK = kTRUE;
721 switch (fStackFillOpt) {
722 case kFlavorSelection:
725 case kParentSelection:
726 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
729 if (flavorOK && selectOK) {
731 // Heavy flavor hadron or quark
733 // Kinematic seletion on final state heavy flavor mesons
734 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
739 if (ParentSelected(kf)) ++nParents; // Update parent count
740 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
742 // Kinematic seletion on decay products
743 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
744 && !KinematicSelection(iparticle, 1))
750 // Select if mother was selected and is not tracked
752 if (pSelected[ipa] &&
753 !trackIt[ipa] && // mother will be tracked ?
754 kfMo != 5 && // mother is b-quark, don't store fragments
755 kfMo != 4 && // mother is c-quark, don't store fragments
756 kf != 92) // don't store string
759 // Semi-stable or de-selected: diselect decay products:
762 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
764 Int_t ipF = iparticle->GetFirstDaughter();
765 Int_t ipL = iparticle->GetLastDaughter();
766 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
768 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
769 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
772 if (pSelected[i] == -1) pSelected[i] = 0;
773 if (!pSelected[i]) continue;
774 // Count quarks only if you did not include fragmentation
775 if (fFragmentation && kf <= 10) continue;
778 // Decision on tracking
781 // Track final state particle
782 if (ks == 1) trackIt[i] = 1;
783 // Track semi-stable particles
784 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
785 // Track particles selected by process if undecayed.
786 if (fForceDecay == kNoDecay) {
787 if (ParentSelected(kf)) trackIt[i] = 1;
789 if (ParentSelected(kf)) trackIt[i] = 0;
791 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
795 } // particle selection loop
797 for (i = 0; i<np; i++) {
798 if (!pSelected[i]) continue;
799 TParticle * iparticle = (TParticle *) fParticles.At(i);
800 kf = CheckPDGCode(iparticle->GetPdgCode());
801 Int_t ks = iparticle->GetStatusCode();
802 p[0] = iparticle->Px();
803 p[1] = iparticle->Py();
804 p[2] = iparticle->Pz();
805 p[3] = iparticle->Energy();
807 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
808 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
809 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
811 Float_t tof = kconv*iparticle->T();
812 Int_t ipa = iparticle->GetFirstMother()-1;
813 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
815 PushTrack(fTrackIt*trackIt[i], iparent, kf,
816 p[0], p[1], p[2], p[3],
817 origin[0], origin[1], origin[2], tof,
818 polar[0], polar[1], polar[2],
819 kPPrimary, nt, 1., ks);
836 switch (fCountMode) {
838 // printf(" Count all \n");
842 // printf(" Count parents \n");
845 case kCountTrackables:
846 // printf(" Count trackable \n");
850 if (jev >= fNpart || fNpart == -1) {
851 fKineBias=Float_t(fNpart)/Float_t(fTrials);
853 fQ += fPythia->GetVINT(51);
854 fX1 += fPythia->GetVINT(41);
855 fX2 += fPythia->GetVINT(42);
856 fTrialsRun += fTrials;
863 SetHighWaterMark(nt);
864 // adjust weight due to kinematic selection
867 fXsection=fPythia->GetPARI(1);
870 Int_t AliGenPythia::GenerateMB()
873 // Min Bias selection and other global selections
875 Int_t i, kf, nt, iparent;
878 Float_t polar[3] = {0,0,0};
879 Float_t origin[3] = {0,0,0};
880 // converts from mm/c to s
881 const Float_t kconv=0.001/2.999792458e8;
885 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
889 Int_t* pParent = new Int_t[np];
890 for (i=0; i< np; i++) pParent[i] = -1;
892 //TO BE CHECKED: Should we require this for Beauty Jets?
894 if (fProcess == kPyJets || fProcess == kPyDirectGamma || fProcess == kPyBeautyJets) {
895 TParticle* jet1 = (TParticle *) fParticles.At(6);
896 TParticle* jet2 = (TParticle *) fParticles.At(7);
897 if (!CheckTrigger(jet1, jet2)) {
903 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
904 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
909 if (fFragPhotonInCalo) pdg = 22 ; // Photon
910 else if (fPi0InCalo) pdg = 111 ; // Pi0
912 for (i=0; i< np; i++) {
913 TParticle* iparticle = (TParticle *) fParticles.At(i);
914 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
915 iparticle->Pt() > fFragPhotonOrPi0MinPt){
916 Int_t imother = iparticle->GetFirstMother() - 1;
917 TParticle* pmother = (TParticle *) fParticles.At(imother);
919 (pdg == 22 && pmother->GetStatusCode() != 11)) //No photon from hadron decay
921 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
922 Float_t eta =TMath::Abs(iparticle->Eta()); //in calos etamin=-etamax
923 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
924 (fCheckPHOS && IsInPHOS(phi,eta)) )
933 // Select beauty jets with electron in EMCAL
934 if (fProcess == kPyBeautyJets && fEleInEMCAL) {
938 Int_t pdg = 11; //electron
943 for (i=0; i< np; i++) {
944 TParticle* iparticle = (TParticle *) fParticles.At(i);
945 if(iparticle->GetStatusCode()==1 && TMath::Abs(iparticle->GetPdgCode())==pdg &&
946 iparticle->Pt() > fElectronMinPt){
947 pt = iparticle->Pt();
948 phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
949 eta =TMath::Abs(iparticle->Eta()); //in calos etamin=-etamax
950 if(IsInEMCAL(phi,eta))
956 AliDebug(5,Form("Found an electron jet (pt,eta,phi) = (%f,%f,%f)",pt,eta,phi));
959 // Check for minimum multiplicity
960 if (fTriggerMultiplicity > 0) {
961 Int_t multiplicity = 0;
962 for (i = 0; i < np; i++) {
963 TParticle * iparticle = (TParticle *) fParticles.At(i);
965 Int_t statusCode = iparticle->GetStatusCode();
967 // Initial state particle
971 // skip quarks and gluons
972 Int_t pdgCode = TMath::Abs(iparticle->GetPdgCode());
973 if (pdgCode <= 10 || pdgCode == 21)
976 if (fTriggerMultiplicityEta > 0 && TMath::Abs(iparticle->Eta()) > fTriggerMultiplicityEta)
979 TParticlePDG* pdgPart = iparticle->GetPDG();
980 if (pdgPart && pdgPart->Charge() == 0)
986 if (multiplicity < fTriggerMultiplicity) {
991 Printf("Triggered on event with multiplicity of %d > %d", multiplicity, fTriggerMultiplicity);
994 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
995 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
1001 for (i=0; i< np; i++) {
1002 TParticle* iparticle = (TParticle *) fParticles.At(i);
1003 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
1004 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
1006 if(iparticle->GetStatusCode() == 1
1007 && iparticle->GetPdgCode() == pdg
1008 && iparticle->Pt() > fPhotonMinPt
1011 // first check if the photon is in PHOS phi
1012 if(IsInPHOS(phi,eta)){
1016 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
1021 if(!okd && iphcand != -1) // execute rotation in phi
1022 RotatePhi(iphcand,okd);
1028 if (fTriggerParticle) {
1029 Bool_t triggered = kFALSE;
1030 for (i = 0; i < np; i++) {
1031 TParticle * iparticle = (TParticle *) fParticles.At(i);
1032 kf = CheckPDGCode(iparticle->GetPdgCode());
1033 if (kf != fTriggerParticle) continue;
1034 if (iparticle->Pt() == 0.) continue;
1035 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
1046 // Check if there is a ccbar or bbbar pair with at least one of the two
1047 // in fYMin < y < fYMax
1049 // TO BE CHECKED: Should we require this for beauty jets?
1051 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi || fProcess == kPyBeautyJets) {
1052 TParticle *partCheck;
1054 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
1055 Bool_t theChild=kFALSE;
1057 Int_t pdg,mpdg,mpdgUpperFamily;
1058 for(i=0; i<np; i++) {
1059 partCheck = (TParticle*)fParticles.At(i);
1060 pdg = partCheck->GetPdgCode();
1061 if(TMath::Abs(pdg) == fFlavorSelect) { // quark
1062 if(pdg>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
1063 y = 0.5*TMath::Log((partCheck->Energy()+partCheck->Pz()+1.e-13)/
1064 (partCheck->Energy()-partCheck->Pz()+1.e-13));
1065 if(y>fYMin && y<fYMax) inYcut=kTRUE;
1067 if(fCutOnChild && TMath::Abs(pdg) == fPdgCodeParticleforAcceptanceCut) {
1068 Int_t mi = partCheck->GetFirstMother() - 1;
1070 mother = (TParticle*)fParticles.At(mi);
1071 mpdg=TMath::Abs(mother->GetPdgCode());
1072 mpdgUpperFamily=(mpdg>1000 ? mpdg+1000 : mpdg+100); // keep e from c from b
1073 if ( ParentSelected(mpdg) ||
1074 (fFlavorSelect==5 && ParentSelected(mpdgUpperFamily))) {
1075 if (KinematicSelection(partCheck,1)) {
1081 if (!theQ || !theQbar || !inYcut) { // one of the c/b conditions not satisfied
1085 if (fCutOnChild && !theChild) { // one of the child conditions not satisfied
1092 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
1093 if ( (fProcess == kPyW ||
1095 fProcess == kPyMbDefault ||
1096 fProcess == kPyMb ||
1097 fProcess == kPyMbWithDirectPhoton ||
1098 fProcess == kPyMbNonDiffr)
1099 && (fCutOnChild == 1) ) {
1100 if ( !CheckKinematicsOnChild() ) {
1107 for (i = 0; i < np; i++) {
1109 TParticle * iparticle = (TParticle *) fParticles.At(i);
1110 kf = CheckPDGCode(iparticle->GetPdgCode());
1111 Int_t ks = iparticle->GetStatusCode();
1112 Int_t km = iparticle->GetFirstMother();
1113 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
1116 //TO BE CHECKED: Should we require this for beauty jets?
1118 ((fProcess == kPyJets || fProcess == kPyBeautyJets) && ks == 21 && km == 0 && i>1)) {
1120 if (ks == 1) trackIt = 1;
1121 Int_t ipa = iparticle->GetFirstMother()-1;
1123 iparent = (ipa > -1) ? pParent[ipa] : -1;
1126 // store track information
1127 p[0] = iparticle->Px();
1128 p[1] = iparticle->Py();
1129 p[2] = iparticle->Pz();
1130 p[3] = iparticle->Energy();
1133 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
1134 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
1135 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
1137 Float_t tof = fEventTime + kconv * iparticle->T();
1139 PushTrack(fTrackIt*trackIt, iparent, kf,
1140 p[0], p[1], p[2], p[3],
1141 origin[0], origin[1], origin[2], tof,
1142 polar[0], polar[1], polar[2],
1143 kPPrimary, nt, 1., ks);
1147 SetHighWaterMark(nt);
1149 } // select particle
1158 void AliGenPythia::FinishRun()
1160 // Print x-section summary
1169 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1170 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1173 void AliGenPythia::AdjustWeights() const
1175 // Adjust the weights after generation of all events
1179 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1180 for (Int_t i=0; i<ntrack; i++) {
1181 part= gAlice->GetMCApp()->Particle(i);
1182 part->SetWeight(part->GetWeight()*fKineBias);
1187 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2, Int_t pdfset)
1189 // Treat protons as inside nuclei with mass numbers a1 and a2
1193 fNucPdf = pdfset; // 0 EKS98 1 EPS08
1198 void AliGenPythia::MakeHeader()
1201 // Make header for the simulated event
1204 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1205 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(2);
1208 // Builds the event header, to be called after each event
1209 if (fHeader) delete fHeader;
1210 fHeader = new AliGenPythiaEventHeader("Pythia");
1213 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
1216 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1219 fHeader->SetPrimaryVertex(fVertex);
1222 // Number of primaries
1223 fHeader->SetNProduced(fNprimaries);
1225 // Jets that have triggered
1227 //Need to store jets for b-jet studies too!
1228 if (fProcess == kPyJets || fProcess == kPyDirectGamma || fProcess == kPyBeautyJets)
1231 Float_t jets[4][10];
1232 GetJets(njet, ntrig, jets);
1235 for (Int_t i = 0; i < ntrig; i++) {
1236 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1241 // Copy relevant information from external header, if present.
1246 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1247 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1249 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1252 exHeader->TriggerJet(i, uqJet);
1253 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1257 // Store quenching parameters
1264 fPythia->GetQuenchingParameters(xp, yp, z);
1265 } else if (fQuench == 2){
1267 Double_t r1 = PARIMP.rb1;
1268 Double_t r2 = PARIMP.rb2;
1269 Double_t b = PARIMP.b1;
1270 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1271 Double_t phi = PARIMP.psib1;
1272 xp = r * TMath::Cos(phi);
1273 yp = r * TMath::Sin(phi);
1275 } else if (fQuench == 4) {
1279 AliFastGlauber::Instance()->GetSavedXY(xy);
1280 AliFastGlauber::Instance()->GetSavedI0I1(i0i1);
1283 ((AliGenPythiaEventHeader*) fHeader)->SetImpactParameter(fImpact);
1286 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1287 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1291 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetVINT(47));
1299 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
1301 // Check the kinematic trigger condition
1304 eta[0] = jet1->Eta();
1305 eta[1] = jet2->Eta();
1307 phi[0] = jet1->Phi();
1308 phi[1] = jet2->Phi();
1310 pdg[0] = jet1->GetPdgCode();
1311 pdg[1] = jet2->GetPdgCode();
1312 Bool_t triggered = kFALSE;
1315 //TO BE CHECKED: If we call this method for kPyBeautyJets, we need it here
1317 if (fProcess == kPyJets || fProcess == kPyBeautyJets) {
1320 Float_t jets[4][10];
1322 // Use Pythia clustering on parton level to determine jet axis
1324 GetJets(njets, ntrig, jets);
1326 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1331 if (pdg[0] == kGamma) {
1335 //Check eta range first...
1336 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1337 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1339 //Eta is okay, now check phi range
1340 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1341 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1352 Bool_t AliGenPythia::CheckKinematicsOnChild(){
1354 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1356 Bool_t checking = kFALSE;
1357 Int_t j, kcode, ks, km;
1358 Int_t nPartAcc = 0; //number of particles in the acceptance range
1359 Int_t numberOfAcceptedParticles = 1;
1360 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1361 Int_t npart = fParticles.GetEntriesFast();
1363 for (j = 0; j<npart; j++) {
1364 TParticle * jparticle = (TParticle *) fParticles.At(j);
1365 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1366 ks = jparticle->GetStatusCode();
1367 km = jparticle->GetFirstMother();
1369 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1372 if( numberOfAcceptedParticles <= nPartAcc){
1381 void AliGenPythia::LoadEvent(AliStack* stack, Int_t flag, Int_t reHadr)
1384 // Load event into Pythia Common Block
1387 Int_t npart = stack -> GetNprimary();
1391 (fPythia->GetPyjets())->N = npart;
1393 n0 = (fPythia->GetPyjets())->N;
1394 (fPythia->GetPyjets())->N = n0 + npart;
1398 for (Int_t part = 0; part < npart; part++) {
1399 TParticle *mPart = stack->Particle(part);
1401 Int_t kf = mPart->GetPdgCode();
1402 Int_t ks = mPart->GetStatusCode();
1403 Int_t idf = mPart->GetFirstDaughter();
1404 Int_t idl = mPart->GetLastDaughter();
1407 if (ks == 11 || ks == 12) {
1414 Float_t px = mPart->Px();
1415 Float_t py = mPart->Py();
1416 Float_t pz = mPart->Pz();
1417 Float_t e = mPart->Energy();
1418 Float_t m = mPart->GetCalcMass();
1421 (fPythia->GetPyjets())->P[0][part+n0] = px;
1422 (fPythia->GetPyjets())->P[1][part+n0] = py;
1423 (fPythia->GetPyjets())->P[2][part+n0] = pz;
1424 (fPythia->GetPyjets())->P[3][part+n0] = e;
1425 (fPythia->GetPyjets())->P[4][part+n0] = m;
1427 (fPythia->GetPyjets())->K[1][part+n0] = kf;
1428 (fPythia->GetPyjets())->K[0][part+n0] = ks;
1429 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
1430 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
1431 (fPythia->GetPyjets())->K[2][part+n0] = mPart->GetFirstMother() + 1;
1435 void AliGenPythia::LoadEvent(TObjArray* stack, Int_t flag, Int_t reHadr)
1438 // Load event into Pythia Common Block
1441 Int_t npart = stack -> GetEntries();
1445 (fPythia->GetPyjets())->N = npart;
1447 n0 = (fPythia->GetPyjets())->N;
1448 (fPythia->GetPyjets())->N = n0 + npart;
1452 for (Int_t part = 0; part < npart; part++) {
1453 TParticle *mPart = dynamic_cast<TParticle *>(stack->At(part));
1454 Int_t kf = mPart->GetPdgCode();
1455 Int_t ks = mPart->GetStatusCode();
1456 Int_t idf = mPart->GetFirstDaughter();
1457 Int_t idl = mPart->GetLastDaughter();
1460 if (ks == 11 || ks == 12) {
1467 Float_t px = mPart->Px();
1468 Float_t py = mPart->Py();
1469 Float_t pz = mPart->Pz();
1470 Float_t e = mPart->Energy();
1471 Float_t m = mPart->GetCalcMass();
1474 (fPythia->GetPyjets())->P[0][part+n0] = px;
1475 (fPythia->GetPyjets())->P[1][part+n0] = py;
1476 (fPythia->GetPyjets())->P[2][part+n0] = pz;
1477 (fPythia->GetPyjets())->P[3][part+n0] = e;
1478 (fPythia->GetPyjets())->P[4][part+n0] = m;
1480 (fPythia->GetPyjets())->K[1][part+n0] = kf;
1481 (fPythia->GetPyjets())->K[0][part+n0] = ks;
1482 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
1483 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
1484 (fPythia->GetPyjets())->K[2][part+n0] = mPart->GetFirstMother() + 1;
1489 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1492 // Calls the Pythia jet finding algorithm to find jets in the current event
1497 Int_t n = fPythia->GetN();
1501 fPythia->Pycell(njets);
1503 for (i = 0; i < njets; i++) {
1504 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1505 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1506 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1507 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1518 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1521 // Calls the Pythia clustering algorithm to find jets in the current event
1523 Int_t n = fPythia->GetN();
1526 if (fJetReconstruction == kCluster) {
1528 // Configure cluster algorithm
1530 fPythia->SetPARU(43, 2.);
1531 fPythia->SetMSTU(41, 1);
1533 // Call cluster algorithm
1535 fPythia->Pyclus(nJets);
1537 // Loading jets from common block
1543 fPythia->Pycell(nJets);
1547 for (i = 0; i < nJets; i++) {
1548 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1549 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1550 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1551 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1552 Float_t pt = TMath::Sqrt(px * px + py * py);
1553 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1554 Float_t theta = TMath::ATan2(pt,pz);
1555 Float_t et = e * TMath::Sin(theta);
1556 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1558 eta > fEtaMinJet && eta < fEtaMaxJet &&
1559 phi > fPhiMinJet && phi < fPhiMaxJet &&
1560 et > fEtMinJet && et < fEtMaxJet
1563 jets[0][nJetsTrig] = px;
1564 jets[1][nJetsTrig] = py;
1565 jets[2][nJetsTrig] = pz;
1566 jets[3][nJetsTrig] = e;
1568 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1570 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1575 void AliGenPythia::GetSubEventTime()
1577 // Calculates time of the next subevent
1580 TArrayF &array = *fEventsTime;
1581 fEventTime = array[fCurSubEvent++];
1583 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1587 Bool_t AliGenPythia::IsInEMCAL(Float_t phi, Float_t eta)
1589 // Is particle in EMCAL acceptance?
1590 // phi in degrees, etamin=-etamax
1591 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1598 Bool_t AliGenPythia::IsInPHOS(Float_t phi, Float_t eta)
1600 // Is particle in PHOS acceptance?
1601 // Acceptance slightly larger considered.
1602 // phi in degrees, etamin=-etamax
1603 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1610 void AliGenPythia::RotatePhi(Int_t iphcand, Bool_t& okdd)
1612 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1613 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1614 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1615 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1617 //calculate deltaphi
1618 TParticle* ph = (TParticle *) fParticles.At(iphcand);
1619 Double_t phphi = ph->Phi();
1620 Double_t deltaphi = phiPHOS - phphi;
1624 //loop for all particles and produce the phi rotation
1625 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
1626 Double_t oldphi, newphi;
1627 Double_t newVx, newVy, R, Vz, time;
1628 Double_t newPx, newPy, pt, Pz, e;
1629 for(Int_t i=0; i< np; i++) {
1630 TParticle* iparticle = (TParticle *) fParticles.At(i);
1631 oldphi = iparticle->Phi();
1632 newphi = oldphi + deltaphi;
1633 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1634 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1637 newVx = R*TMath::Cos(newphi);
1638 newVy = R*TMath::Sin(newphi);
1639 Vz = iparticle->Vz(); // don't transform
1640 time = iparticle->T(); // don't transform
1642 pt = iparticle->Pt();
1643 newPx = pt*TMath::Cos(newphi);
1644 newPy = pt*TMath::Sin(newphi);
1645 Pz = iparticle->Pz(); // don't transform
1646 e = iparticle->Energy(); // don't transform
1649 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1650 iparticle->SetMomentum(newPx, newPy, Pz, e);
1652 } //end particle loop
1654 // now let's check that we put correctly the candidate photon in PHOS
1655 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1656 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1657 if(IsInPHOS(phi,eta))
1663 void AliGenPythia::Streamer(TBuffer &R__b)
1665 // Stream an object of class AliGenPythia.
1667 if (R__b.IsReading()) {
1668 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1669 AliGenerator::Streamer(R__b);
1670 R__b >> (Int_t&)fProcess;
1671 R__b >> (Int_t&)fStrucFunc;
1672 R__b >> (Int_t&)fForceDecay;
1676 fParentSelect.Streamer(R__b);
1677 fChildSelect.Streamer(R__b);
1679 // (AliPythia::Instance())->Streamer(R__b);
1682 // if (fDecayer) fDecayer->Streamer(R__b);
1684 R__b.WriteVersion(AliGenPythia::IsA());
1685 AliGenerator::Streamer(R__b);
1686 R__b << (Int_t)fProcess;
1687 R__b << (Int_t)fStrucFunc;
1688 R__b << (Int_t)fForceDecay;
1692 fParentSelect.Streamer(R__b);
1693 fChildSelect.Streamer(R__b);
1698 // fDecayer->Streamer(R__b);