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():
85 fDecayer(new AliDecayerPythia()),
93 fPhiMaxJet(2.* TMath::Pi()),
94 fJetReconstruction(kCell),
98 fPhiMaxGamma(2. * TMath::Pi()),
102 fPycellThreshold(0.),
104 fPycellMinEtJet(10.),
105 fPycellMaxRadius(1.),
106 fStackFillOpt(kFlavorSelection),
108 fFragmentation(kTRUE),
115 fTriggerMultiplicity(0),
116 fTriggerMultiplicityEta(0),
117 fCountMode(kCountAll),
121 fFragPhotonInCalo(kFALSE),
123 fPhotonInCalo(kFALSE),
126 fCheckPHOSeta(kFALSE),
127 fFragPhotonOrPi0MinPt(0),
137 // Default Constructor
140 if (!AliPythiaRndm::GetPythiaRandom())
141 AliPythiaRndm::SetPythiaRandom(GetRandom());
144 AliGenPythia::AliGenPythia(Int_t npart)
155 fInteractionRate(0.),
169 fHadronisation(kTRUE),
171 fReadFromFile(kFALSE),
177 fDecayer(new AliDecayerPythia()),
178 fDebugEventFirst(-1),
185 fPhiMaxJet(2.* TMath::Pi()),
186 fJetReconstruction(kCell),
190 fPhiMaxGamma(2. * TMath::Pi()),
194 fPycellThreshold(0.),
196 fPycellMinEtJet(10.),
197 fPycellMaxRadius(1.),
198 fStackFillOpt(kFlavorSelection),
200 fFragmentation(kTRUE),
207 fTriggerMultiplicity(0),
208 fTriggerMultiplicityEta(0),
209 fCountMode(kCountAll),
213 fFragPhotonInCalo(kFALSE),
215 fPhotonInCalo(kFALSE),
218 fCheckPHOSeta(kFALSE),
219 fFragPhotonOrPi0MinPt(0),
228 // default charm production at 5. 5 TeV
230 // structure function GRVHO
234 fTitle= "Particle Generator using PYTHIA";
236 // Set random number generator
237 if (!AliPythiaRndm::GetPythiaRandom())
238 AliPythiaRndm::SetPythiaRandom(GetRandom());
242 AliGenPythia::~AliGenPythia()
245 if(fEventsTime) delete fEventsTime;
248 void AliGenPythia::SetInteractionRate(Float_t rate,Float_t timewindow)
250 // Generate pileup using user specified rate
251 fInteractionRate = rate;
252 fTimeWindow = timewindow;
256 void AliGenPythia::GeneratePileup()
258 // Generate sub events time for pileup
260 if(fInteractionRate == 0.) {
261 Warning("GeneratePileup","Zero interaction specified. Skipping pileup generation.\n");
265 Int_t npart = NumberParticles();
267 Warning("GeneratePileup","Negative number of particles. Skipping pileup generation.\n");
271 if(fEventsTime) delete fEventsTime;
272 fEventsTime = new TArrayF(npart);
273 TArrayF &array = *fEventsTime;
274 for(Int_t ipart = 0; ipart < npart; ipart++)
277 Float_t eventtime = 0.;
280 eventtime += (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
281 if(eventtime > fTimeWindow) break;
282 array.Set(array.GetSize()+1);
283 array[array.GetSize()-1] = eventtime;
289 eventtime -= (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
290 if(TMath::Abs(eventtime) > fTimeWindow) break;
291 array.Set(array.GetSize()+1);
292 array[array.GetSize()-1] = eventtime;
295 SetNumberParticles(fEventsTime->GetSize());
298 void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
299 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
301 // Set pycell parameters
302 fPycellEtaMax = etamax;
305 fPycellThreshold = thresh;
306 fPycellEtSeed = etseed;
307 fPycellMinEtJet = minet;
308 fPycellMaxRadius = r;
313 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
315 // Set a range of event numbers, for which a table
316 // of generated particle will be printed
317 fDebugEventFirst = eventFirst;
318 fDebugEventLast = eventLast;
319 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
322 void AliGenPythia::Init()
326 SetMC(AliPythia::Instance());
327 fPythia=(AliPythia*) fMCEvGen;
330 fParentWeight=1./Float_t(fNpart);
334 fPythia->SetCKIN(3,fPtHardMin);
335 fPythia->SetCKIN(4,fPtHardMax);
336 fPythia->SetCKIN(7,fYHardMin);
337 fPythia->SetCKIN(8,fYHardMax);
339 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget, fNucPdf);
341 if (fFragmentation) {
342 fPythia->SetMSTP(111,1);
344 fPythia->SetMSTP(111,0);
348 // initial state radiation
349 fPythia->SetMSTP(61,fGinit);
350 // final state radiation
351 fPythia->SetMSTP(71,fGfinal);
354 fPythia->SetMSTP(91,1);
355 fPythia->SetPARP(91,fPtKick);
356 fPythia->SetPARP(93, 4. * fPtKick);
358 fPythia->SetMSTP(91,0);
363 fRL = AliRunLoader::Open(fFileName, "Partons");
364 fRL->LoadKinematics();
370 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
371 // Forward Paramters to the AliPythia object
372 fDecayer->SetForceDecay(fForceDecay);
373 // Switch off Heavy Flavors on request
375 // Maximum number of quark flavours used in pdf
376 fPythia->SetMSTP(58, 3);
377 // Maximum number of flavors that can be used in showers
378 fPythia->SetMSTJ(45, 3);
379 // Switch off g->QQbar splitting in decay table
380 ((AliDecayerPythia*) fDecayer)->HeavyFlavourOff();
386 // Parent and Children Selection
389 case kPyOldUEQ2ordered:
390 case kPyOldUEQ2ordered2:
394 case kPyCharmUnforced:
395 case kPyCharmPbPbMNR:
398 case kPyCharmppMNRwmi:
399 fParentSelect[0] = 411;
400 fParentSelect[1] = 421;
401 fParentSelect[2] = 431;
402 fParentSelect[3] = 4122;
403 fParentSelect[4] = 4232;
404 fParentSelect[5] = 4132;
405 fParentSelect[6] = 4332;
411 fParentSelect[0] = 421;
414 case kPyDPlusPbPbMNR:
417 fParentSelect[0] = 411;
420 case kPyDPlusStrangePbPbMNR:
421 case kPyDPlusStrangepPbMNR:
422 case kPyDPlusStrangeppMNR:
423 fParentSelect[0] = 431;
427 case kPyBeautyPbPbMNR:
428 case kPyBeautypPbMNR:
430 case kPyBeautyppMNRwmi:
431 fParentSelect[0]= 511;
432 fParentSelect[1]= 521;
433 fParentSelect[2]= 531;
434 fParentSelect[3]= 5122;
435 fParentSelect[4]= 5132;
436 fParentSelect[5]= 5232;
437 fParentSelect[6]= 5332;
440 case kPyBeautyUnforced:
441 fParentSelect[0] = 511;
442 fParentSelect[1] = 521;
443 fParentSelect[2] = 531;
444 fParentSelect[3] = 5122;
445 fParentSelect[4] = 5132;
446 fParentSelect[5] = 5232;
447 fParentSelect[6] = 5332;
452 fParentSelect[0] = 443;
456 case kPyMbWithDirectPhoton:
469 // JetFinder for Trigger
471 // Configure detector (EMCAL like)
473 fPythia->SetPARU(51, fPycellEtaMax);
474 fPythia->SetMSTU(51, fPycellNEta);
475 fPythia->SetMSTU(52, fPycellNPhi);
477 // Configure Jet Finder
479 fPythia->SetPARU(58, fPycellThreshold);
480 fPythia->SetPARU(52, fPycellEtSeed);
481 fPythia->SetPARU(53, fPycellMinEtJet);
482 fPythia->SetPARU(54, fPycellMaxRadius);
483 fPythia->SetMSTU(54, 2);
485 // This counts the total number of calls to Pyevnt() per run.
500 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
503 fPythia->SetPARJ(200, 0.0);
504 fPythia->SetPARJ(199, 0.0);
505 fPythia->SetPARJ(198, 0.0);
506 fPythia->SetPARJ(197, 0.0);
509 fPythia->InitQuenching(0., 0.1, 0.6e6, 0);
513 // Nestor's change of the splittings
514 fPythia->SetPARJ(200, 0.8);
515 fPythia->SetMSTJ(41, 1); // QCD radiation only
516 fPythia->SetMSTJ(42, 2); // angular ordering
517 fPythia->SetMSTJ(44, 2); // option to run alpha_s
518 fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
519 fPythia->SetMSTJ(50, 0); // No coherence in first branching
520 fPythia->SetPARJ(82, 1.); // Cut off for parton showers
521 } else if (fQuench == 4) {
522 // Armesto-Cunqueiro-Salgado change of the splittings.
523 AliFastGlauber* glauber = AliFastGlauber::Instance();
525 //read and store transverse almonds corresponding to differnt
527 glauber->SetCentralityClass(0.,0.1);
528 fPythia->SetPARJ(200, 1.);
529 fPythia->SetPARJ(198, fQhat);
530 fPythia->SetPARJ(199, fLength);
532 fPythia->SetMSTJ(41, 1); // QCD radiation only
533 fPythia->SetMSTJ(42, 2); // angular ordering
534 fPythia->SetMSTJ(44, 2); // option to run alpha_s
535 //fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
536 //fPythia->SetMSTJ(50, 0); // No coherence in first branching
537 fPythia->SetPARJ(82, 1.); // Cut off for parton showers
538 // MSTJ(41) must NOT be 11 or 12, as then FSR may go through PYPTFS
539 // (kt-ordered cascade) in which medium effects have not been introduced.
543 void AliGenPythia::Generate()
545 // Generate one event
546 if (!fPythia) fPythia=(AliPythia*) fMCEvGen;
547 fDecayer->ForceDecay();
549 Float_t polar[3] = {0,0,0};
550 Float_t origin[3] = {0,0,0};
552 // converts from mm/c to s
553 const Float_t kconv=0.001/2.999792458e8;
563 // Set collision vertex position
564 if (fVertexSmear == kPerEvent) Vertex();
573 // Switch hadronisation off
575 fPythia->SetMSTJ(1, 0);
579 // Quenching comes through medium-modified splitting functions.
580 AliFastGlauber::Instance()->GetRandomBHard(bimp);
581 fPythia->SetPARJ(197,bimp);
584 // Either produce new event or read partons from file
586 if (!fReadFromFile) {
592 fNpartons = fPythia->GetN();
594 printf("Loading Event %d\n",AliRunLoader::Instance()->GetEventNumber());
595 fRL->GetEvent(AliRunLoader::Instance()->GetEventNumber());
597 LoadEvent(fRL->Stack(), 0 , 1);
602 // Run quenching routine
606 } else if (fQuench == 2){
607 fPythia->Pyquen(208., 0, 0.);
608 } else if (fQuench == 3) {
609 // Quenching is via multiplicative correction of the splittings
613 // Switch hadronisation on
615 if (fHadronisation) {
616 fPythia->SetMSTJ(1, 1);
618 // .. and perform hadronisation
619 // printf("Calling hadronisation %d\n", fPythia->GetN());
623 fPythia->ImportParticles(&fParticles,"All");
631 Int_t np = fParticles.GetEntriesFast();
633 if (np == 0) continue;
637 Int_t* pParent = new Int_t[np];
638 Int_t* pSelected = new Int_t[np];
639 Int_t* trackIt = new Int_t[np];
640 for (i = 0; i < np; i++) {
646 Int_t nc = 0; // Total n. of selected particles
647 Int_t nParents = 0; // Selected parents
648 Int_t nTkbles = 0; // Trackable particles
649 if (fProcess != kPyMbDefault &&
651 fProcess != kPyMbWithDirectPhoton &&
652 fProcess != kPyJets &&
653 fProcess != kPyDirectGamma &&
654 fProcess != kPyMbNonDiffr &&
655 fProcess != kPyMbMSEL1 &&
658 fProcess != kPyCharmppMNRwmi &&
659 fProcess != kPyBeautyppMNRwmi) {
661 for (i = 0; i < np; i++) {
662 TParticle* iparticle = (TParticle *) fParticles.At(i);
663 Int_t ks = iparticle->GetStatusCode();
664 kf = CheckPDGCode(iparticle->GetPdgCode());
665 // No initial state partons
666 if (ks==21) continue;
668 // Heavy Flavor Selection
675 if (kfl > 100000) kfl %= 100000;
676 if (kfl > 10000) kfl %= 10000;
678 if (kfl > 10) kfl/=100;
680 if (kfl > 10) kfl/=10;
681 Int_t ipa = iparticle->GetFirstMother()-1;
684 // Establish mother daughter relation between heavy quarks and mesons
686 if (kf >= fFlavorSelect && kf <= 6) {
687 Int_t idau = iparticle->GetFirstDaughter() - 1;
689 TParticle* daughter = (TParticle *) fParticles.At(idau);
690 Int_t pdgD = daughter->GetPdgCode();
691 if (pdgD == 91 || pdgD == 92) {
692 Int_t jmin = daughter->GetFirstDaughter() - 1;
693 Int_t jmax = daughter->GetLastDaughter() - 1;
694 for (Int_t jp = jmin; jp <= jmax; jp++)
695 ((TParticle *) fParticles.At(jp))->SetFirstMother(i+1);
696 } // is string or cluster
702 TParticle * mother = (TParticle *) fParticles.At(ipa);
703 kfMo = TMath::Abs(mother->GetPdgCode());
706 // What to keep in Stack?
707 Bool_t flavorOK = kFALSE;
708 Bool_t selectOK = kFALSE;
710 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
712 if (kfl > fFlavorSelect) {
716 if (kfl == fFlavorSelect) flavorOK = kTRUE;
718 switch (fStackFillOpt) {
719 case kFlavorSelection:
722 case kParentSelection:
723 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
726 if (flavorOK && selectOK) {
728 // Heavy flavor hadron or quark
730 // Kinematic seletion on final state heavy flavor mesons
731 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
736 if (ParentSelected(kf)) ++nParents; // Update parent count
737 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
739 // Kinematic seletion on decay products
740 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
741 && !KinematicSelection(iparticle, 1))
747 // Select if mother was selected and is not tracked
749 if (pSelected[ipa] &&
750 !trackIt[ipa] && // mother will be tracked ?
751 kfMo != 5 && // mother is b-quark, don't store fragments
752 kfMo != 4 && // mother is c-quark, don't store fragments
753 kf != 92) // don't store string
756 // Semi-stable or de-selected: diselect decay products:
759 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
761 Int_t ipF = iparticle->GetFirstDaughter();
762 Int_t ipL = iparticle->GetLastDaughter();
763 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
765 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
766 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
769 if (pSelected[i] == -1) pSelected[i] = 0;
770 if (!pSelected[i]) continue;
771 // Count quarks only if you did not include fragmentation
772 if (fFragmentation && kf <= 10) continue;
775 // Decision on tracking
778 // Track final state particle
779 if (ks == 1) trackIt[i] = 1;
780 // Track semi-stable particles
781 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
782 // Track particles selected by process if undecayed.
783 if (fForceDecay == kNoDecay) {
784 if (ParentSelected(kf)) trackIt[i] = 1;
786 if (ParentSelected(kf)) trackIt[i] = 0;
788 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
792 } // particle selection loop
794 for (i = 0; i<np; i++) {
795 if (!pSelected[i]) continue;
796 TParticle * iparticle = (TParticle *) fParticles.At(i);
797 kf = CheckPDGCode(iparticle->GetPdgCode());
798 Int_t ks = iparticle->GetStatusCode();
799 p[0] = iparticle->Px();
800 p[1] = iparticle->Py();
801 p[2] = iparticle->Pz();
802 p[3] = iparticle->Energy();
804 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
805 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
806 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
808 Float_t tof = kconv*iparticle->T();
809 Int_t ipa = iparticle->GetFirstMother()-1;
810 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
812 PushTrack(fTrackIt*trackIt[i], iparent, kf,
813 p[0], p[1], p[2], p[3],
814 origin[0], origin[1], origin[2], tof,
815 polar[0], polar[1], polar[2],
816 kPPrimary, nt, 1., ks);
833 switch (fCountMode) {
835 // printf(" Count all \n");
839 // printf(" Count parents \n");
842 case kCountTrackables:
843 // printf(" Count trackable \n");
847 if (jev >= fNpart || fNpart == -1) {
848 fKineBias=Float_t(fNpart)/Float_t(fTrials);
850 fQ += fPythia->GetVINT(51);
851 fX1 += fPythia->GetVINT(41);
852 fX2 += fPythia->GetVINT(42);
853 fTrialsRun += fTrials;
860 SetHighWaterMark(nt);
861 // adjust weight due to kinematic selection
864 fXsection=fPythia->GetPARI(1);
867 Int_t AliGenPythia::GenerateMB()
870 // Min Bias selection and other global selections
872 Int_t i, kf, nt, iparent;
875 Float_t polar[3] = {0,0,0};
876 Float_t origin[3] = {0,0,0};
877 // converts from mm/c to s
878 const Float_t kconv=0.001/2.999792458e8;
882 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
886 Int_t* pParent = new Int_t[np];
887 for (i=0; i< np; i++) pParent[i] = -1;
888 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
889 TParticle* jet1 = (TParticle *) fParticles.At(6);
890 TParticle* jet2 = (TParticle *) fParticles.At(7);
891 if (!CheckTrigger(jet1, jet2)) {
897 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
898 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
903 if (fFragPhotonInCalo) pdg = 22 ; // Photon
904 else if (fPi0InCalo) pdg = 111 ; // Pi0
906 for (i=0; i< np; i++) {
907 TParticle* iparticle = (TParticle *) fParticles.At(i);
908 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
909 iparticle->Pt() > fFragPhotonOrPi0MinPt){
910 Int_t imother = iparticle->GetFirstMother() - 1;
911 TParticle* pmother = (TParticle *) fParticles.At(imother);
913 (pdg == 22 && pmother->GetStatusCode() != 11)) //No photon from hadron decay
915 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
916 Float_t eta =TMath::Abs(iparticle->Eta()); //in calos etamin=-etamax
917 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
918 (fCheckPHOS && IsInPHOS(phi,eta)) )
927 // Check for minimum multiplicity
928 if (fTriggerMultiplicity > 0) {
929 Int_t multiplicity = 0;
930 for (i = 0; i < np; i++) {
931 TParticle * iparticle = (TParticle *) fParticles.At(i);
933 Int_t statusCode = iparticle->GetStatusCode();
935 // Initial state particle
939 // skip quarks and gluons
940 Int_t pdgCode = TMath::Abs(iparticle->GetPdgCode());
941 if (pdgCode <= 10 || pdgCode == 21)
944 if (fTriggerMultiplicityEta > 0 && TMath::Abs(iparticle->Eta()) > fTriggerMultiplicityEta)
947 TParticlePDG* pdgPart = iparticle->GetPDG();
948 if (pdgPart && pdgPart->Charge() == 0)
954 if (multiplicity < fTriggerMultiplicity) {
959 Printf("Triggered on event with multiplicity of %d > %d", multiplicity, fTriggerMultiplicity);
962 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
963 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
969 for (i=0; i< np; i++) {
970 TParticle* iparticle = (TParticle *) fParticles.At(i);
971 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
972 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
974 if(iparticle->GetStatusCode() == 1
975 && iparticle->GetPdgCode() == pdg
976 && iparticle->Pt() > fPhotonMinPt
979 // first check if the photon is in PHOS phi
980 if(IsInPHOS(phi,eta)){
984 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
989 if(!okd && iphcand != -1) // execute rotation in phi
990 RotatePhi(iphcand,okd);
996 if (fTriggerParticle) {
997 Bool_t triggered = kFALSE;
998 for (i = 0; i < np; i++) {
999 TParticle * iparticle = (TParticle *) fParticles.At(i);
1000 kf = CheckPDGCode(iparticle->GetPdgCode());
1001 if (kf != fTriggerParticle) continue;
1002 if (iparticle->Pt() == 0.) continue;
1003 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
1014 // Check if there is a ccbar or bbbar pair with at least one of the two
1015 // in fYMin < y < fYMax
1016 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi) {
1017 TParticle *partCheck;
1019 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
1020 Bool_t theChild=kFALSE;
1022 Int_t pdg,mpdg,mpdgUpperFamily;
1023 for(i=0; i<np; i++) {
1024 partCheck = (TParticle*)fParticles.At(i);
1025 pdg = partCheck->GetPdgCode();
1026 if(TMath::Abs(pdg) == fFlavorSelect) { // quark
1027 if(pdg>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
1028 y = 0.5*TMath::Log((partCheck->Energy()+partCheck->Pz()+1.e-13)/
1029 (partCheck->Energy()-partCheck->Pz()+1.e-13));
1030 if(y>fYMin && y<fYMax) inYcut=kTRUE;
1032 if(fCutOnChild && TMath::Abs(pdg) == fPdgCodeParticleforAcceptanceCut) {
1033 Int_t mi = partCheck->GetFirstMother() - 1;
1035 mother = (TParticle*)fParticles.At(mi);
1036 mpdg=TMath::Abs(mother->GetPdgCode());
1037 mpdgUpperFamily=(mpdg>1000 ? mpdg+1000 : mpdg+100); // keep e from c from b
1038 if ( ParentSelected(mpdg) ||
1039 (fFlavorSelect==5 && ParentSelected(mpdgUpperFamily))) {
1040 if (KinematicSelection(partCheck,1)) {
1046 if (!theQ || !theQbar || !inYcut) { // one of the c/b conditions not satisfied
1050 if (fCutOnChild && !theChild) { // one of the child conditions not satisfied
1057 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
1058 if ( (fProcess == kPyW ||
1060 fProcess == kPyMbDefault ||
1061 fProcess == kPyMb ||
1062 fProcess == kPyMbWithDirectPhoton ||
1063 fProcess == kPyMbNonDiffr)
1064 && (fCutOnChild == 1) ) {
1065 if ( !CheckKinematicsOnChild() ) {
1072 for (i = 0; i < np; i++) {
1074 TParticle * iparticle = (TParticle *) fParticles.At(i);
1075 kf = CheckPDGCode(iparticle->GetPdgCode());
1076 Int_t ks = iparticle->GetStatusCode();
1077 Int_t km = iparticle->GetFirstMother();
1078 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
1080 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
1082 if (ks == 1) trackIt = 1;
1083 Int_t ipa = iparticle->GetFirstMother()-1;
1085 iparent = (ipa > -1) ? pParent[ipa] : -1;
1088 // store track information
1089 p[0] = iparticle->Px();
1090 p[1] = iparticle->Py();
1091 p[2] = iparticle->Pz();
1092 p[3] = iparticle->Energy();
1095 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
1096 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
1097 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
1099 Float_t tof = fEventTime + kconv * iparticle->T();
1101 PushTrack(fTrackIt*trackIt, iparent, kf,
1102 p[0], p[1], p[2], p[3],
1103 origin[0], origin[1], origin[2], tof,
1104 polar[0], polar[1], polar[2],
1105 kPPrimary, nt, 1., ks);
1109 SetHighWaterMark(nt);
1111 } // select particle
1120 void AliGenPythia::FinishRun()
1122 // Print x-section summary
1131 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1132 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1135 void AliGenPythia::AdjustWeights() const
1137 // Adjust the weights after generation of all events
1141 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1142 for (Int_t i=0; i<ntrack; i++) {
1143 part= gAlice->GetMCApp()->Particle(i);
1144 part->SetWeight(part->GetWeight()*fKineBias);
1149 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2, Int_t pdfset)
1151 // Treat protons as inside nuclei with mass numbers a1 and a2
1155 fNucPdf = pdfset; // 0 EKS98 1 EPS08
1160 void AliGenPythia::MakeHeader()
1163 // Make header for the simulated event
1166 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1167 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(2);
1170 // Builds the event header, to be called after each event
1171 if (fHeader) delete fHeader;
1172 fHeader = new AliGenPythiaEventHeader("Pythia");
1175 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
1178 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1181 fHeader->SetPrimaryVertex(fVertex);
1184 // Number of primaries
1185 fHeader->SetNProduced(fNprimaries);
1187 // Jets that have triggered
1189 if (fProcess == kPyJets || fProcess == kPyDirectGamma)
1192 Float_t jets[4][10];
1193 GetJets(njet, ntrig, jets);
1196 for (Int_t i = 0; i < ntrig; i++) {
1197 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1202 // Copy relevant information from external header, if present.
1207 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1208 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1210 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1213 exHeader->TriggerJet(i, uqJet);
1214 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1218 // Store quenching parameters
1225 fPythia->GetQuenchingParameters(xp, yp, z);
1226 } else if (fQuench == 2){
1228 Double_t r1 = PARIMP.rb1;
1229 Double_t r2 = PARIMP.rb2;
1230 Double_t b = PARIMP.b1;
1231 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1232 Double_t phi = PARIMP.psib1;
1233 xp = r * TMath::Cos(phi);
1234 yp = r * TMath::Sin(phi);
1236 } else if (fQuench == 4) {
1240 AliFastGlauber::Instance()->GetSavedXY(xy);
1241 AliFastGlauber::Instance()->GetSavedI0I1(i0i1);
1244 ((AliGenPythiaEventHeader*) fHeader)->SetInMediumLength(2. * i0i1[1] / i0i1[0]);
1247 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1248 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1252 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetVINT(47));
1260 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
1262 // Check the kinematic trigger condition
1265 eta[0] = jet1->Eta();
1266 eta[1] = jet2->Eta();
1268 phi[0] = jet1->Phi();
1269 phi[1] = jet2->Phi();
1271 pdg[0] = jet1->GetPdgCode();
1272 pdg[1] = jet2->GetPdgCode();
1273 Bool_t triggered = kFALSE;
1275 if (fProcess == kPyJets) {
1278 Float_t jets[4][10];
1280 // Use Pythia clustering on parton level to determine jet axis
1282 GetJets(njets, ntrig, jets);
1284 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1289 if (pdg[0] == kGamma) {
1293 //Check eta range first...
1294 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1295 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1297 //Eta is okay, now check phi range
1298 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1299 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1310 Bool_t AliGenPythia::CheckKinematicsOnChild(){
1312 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1314 Bool_t checking = kFALSE;
1315 Int_t j, kcode, ks, km;
1316 Int_t nPartAcc = 0; //number of particles in the acceptance range
1317 Int_t numberOfAcceptedParticles = 1;
1318 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1319 Int_t npart = fParticles.GetEntriesFast();
1321 for (j = 0; j<npart; j++) {
1322 TParticle * jparticle = (TParticle *) fParticles.At(j);
1323 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1324 ks = jparticle->GetStatusCode();
1325 km = jparticle->GetFirstMother();
1327 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1330 if( numberOfAcceptedParticles <= nPartAcc){
1339 void AliGenPythia::LoadEvent(AliStack* stack, Int_t flag, Int_t reHadr)
1342 // Load event into Pythia Common Block
1345 Int_t npart = stack -> GetNprimary();
1349 (fPythia->GetPyjets())->N = npart;
1351 n0 = (fPythia->GetPyjets())->N;
1352 (fPythia->GetPyjets())->N = n0 + npart;
1356 for (Int_t part = 0; part < npart; part++) {
1357 TParticle *mPart = stack->Particle(part);
1359 Int_t kf = mPart->GetPdgCode();
1360 Int_t ks = mPart->GetStatusCode();
1361 Int_t idf = mPart->GetFirstDaughter();
1362 Int_t idl = mPart->GetLastDaughter();
1365 if (ks == 11 || ks == 12) {
1372 Float_t px = mPart->Px();
1373 Float_t py = mPart->Py();
1374 Float_t pz = mPart->Pz();
1375 Float_t e = mPart->Energy();
1376 Float_t m = mPart->GetCalcMass();
1379 (fPythia->GetPyjets())->P[0][part+n0] = px;
1380 (fPythia->GetPyjets())->P[1][part+n0] = py;
1381 (fPythia->GetPyjets())->P[2][part+n0] = pz;
1382 (fPythia->GetPyjets())->P[3][part+n0] = e;
1383 (fPythia->GetPyjets())->P[4][part+n0] = m;
1385 (fPythia->GetPyjets())->K[1][part+n0] = kf;
1386 (fPythia->GetPyjets())->K[0][part+n0] = ks;
1387 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
1388 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
1389 (fPythia->GetPyjets())->K[2][part+n0] = mPart->GetFirstMother() + 1;
1393 void AliGenPythia::LoadEvent(TObjArray* stack, Int_t flag, Int_t reHadr)
1396 // Load event into Pythia Common Block
1399 Int_t npart = stack -> GetEntries();
1403 (fPythia->GetPyjets())->N = npart;
1405 n0 = (fPythia->GetPyjets())->N;
1406 (fPythia->GetPyjets())->N = n0 + npart;
1410 for (Int_t part = 0; part < npart; part++) {
1411 TParticle *mPart = dynamic_cast<TParticle *>(stack->At(part));
1412 Int_t kf = mPart->GetPdgCode();
1413 Int_t ks = mPart->GetStatusCode();
1414 Int_t idf = mPart->GetFirstDaughter();
1415 Int_t idl = mPart->GetLastDaughter();
1418 if (ks == 11 || ks == 12) {
1425 Float_t px = mPart->Px();
1426 Float_t py = mPart->Py();
1427 Float_t pz = mPart->Pz();
1428 Float_t e = mPart->Energy();
1429 Float_t m = mPart->GetCalcMass();
1432 (fPythia->GetPyjets())->P[0][part+n0] = px;
1433 (fPythia->GetPyjets())->P[1][part+n0] = py;
1434 (fPythia->GetPyjets())->P[2][part+n0] = pz;
1435 (fPythia->GetPyjets())->P[3][part+n0] = e;
1436 (fPythia->GetPyjets())->P[4][part+n0] = m;
1438 (fPythia->GetPyjets())->K[1][part+n0] = kf;
1439 (fPythia->GetPyjets())->K[0][part+n0] = ks;
1440 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
1441 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
1442 (fPythia->GetPyjets())->K[2][part+n0] = mPart->GetFirstMother() + 1;
1447 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1450 // Calls the Pythia jet finding algorithm to find jets in the current event
1455 Int_t n = fPythia->GetN();
1459 fPythia->Pycell(njets);
1461 for (i = 0; i < njets; i++) {
1462 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1463 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1464 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1465 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1476 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1479 // Calls the Pythia clustering algorithm to find jets in the current event
1481 Int_t n = fPythia->GetN();
1484 if (fJetReconstruction == kCluster) {
1486 // Configure cluster algorithm
1488 fPythia->SetPARU(43, 2.);
1489 fPythia->SetMSTU(41, 1);
1491 // Call cluster algorithm
1493 fPythia->Pyclus(nJets);
1495 // Loading jets from common block
1501 fPythia->Pycell(nJets);
1505 for (i = 0; i < nJets; i++) {
1506 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1507 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1508 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1509 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1510 Float_t pt = TMath::Sqrt(px * px + py * py);
1511 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1512 Float_t theta = TMath::ATan2(pt,pz);
1513 Float_t et = e * TMath::Sin(theta);
1514 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1516 eta > fEtaMinJet && eta < fEtaMaxJet &&
1517 phi > fPhiMinJet && phi < fPhiMaxJet &&
1518 et > fEtMinJet && et < fEtMaxJet
1521 jets[0][nJetsTrig] = px;
1522 jets[1][nJetsTrig] = py;
1523 jets[2][nJetsTrig] = pz;
1524 jets[3][nJetsTrig] = e;
1526 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1528 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1533 void AliGenPythia::GetSubEventTime()
1535 // Calculates time of the next subevent
1538 TArrayF &array = *fEventsTime;
1539 fEventTime = array[fCurSubEvent++];
1541 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1545 Bool_t AliGenPythia::IsInEMCAL(Float_t phi, Float_t eta)
1547 // Is particle in EMCAL acceptance?
1548 // phi in degrees, etamin=-etamax
1549 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1556 Bool_t AliGenPythia::IsInPHOS(Float_t phi, Float_t eta)
1558 // Is particle in PHOS acceptance?
1559 // Acceptance slightly larger considered.
1560 // phi in degrees, etamin=-etamax
1561 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1568 void AliGenPythia::RotatePhi(Int_t iphcand, Bool_t& okdd)
1570 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1571 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1572 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1573 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1575 //calculate deltaphi
1576 TParticle* ph = (TParticle *) fParticles.At(iphcand);
1577 Double_t phphi = ph->Phi();
1578 Double_t deltaphi = phiPHOS - phphi;
1582 //loop for all particles and produce the phi rotation
1583 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
1584 Double_t oldphi, newphi;
1585 Double_t newVx, newVy, R, Vz, time;
1586 Double_t newPx, newPy, pt, Pz, e;
1587 for(Int_t i=0; i< np; i++) {
1588 TParticle* iparticle = (TParticle *) fParticles.At(i);
1589 oldphi = iparticle->Phi();
1590 newphi = oldphi + deltaphi;
1591 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1592 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1595 newVx = R*TMath::Cos(newphi);
1596 newVy = R*TMath::Sin(newphi);
1597 Vz = iparticle->Vz(); // don't transform
1598 time = iparticle->T(); // don't transform
1600 pt = iparticle->Pt();
1601 newPx = pt*TMath::Cos(newphi);
1602 newPy = pt*TMath::Sin(newphi);
1603 Pz = iparticle->Pz(); // don't transform
1604 e = iparticle->Energy(); // don't transform
1607 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1608 iparticle->SetMomentum(newPx, newPy, Pz, e);
1610 } //end particle loop
1612 // now let's check that we put correctly the candidate photon in PHOS
1613 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1614 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1615 if(IsInPHOS(phi,eta))
1621 void AliGenPythia::Streamer(TBuffer &R__b)
1623 // Stream an object of class AliGenPythia.
1625 if (R__b.IsReading()) {
1626 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1627 AliGenerator::Streamer(R__b);
1628 R__b >> (Int_t&)fProcess;
1629 R__b >> (Int_t&)fStrucFunc;
1630 R__b >> (Int_t&)fForceDecay;
1634 fParentSelect.Streamer(R__b);
1635 fChildSelect.Streamer(R__b);
1637 // (AliPythia::Instance())->Streamer(R__b);
1640 // if (fDecayer) fDecayer->Streamer(R__b);
1642 R__b.WriteVersion(AliGenPythia::IsA());
1643 AliGenerator::Streamer(R__b);
1644 R__b << (Int_t)fProcess;
1645 R__b << (Int_t)fStrucFunc;
1646 R__b << (Int_t)fForceDecay;
1650 fParentSelect.Streamer(R__b);
1651 fChildSelect.Streamer(R__b);
1656 // fDecayer->Streamer(R__b);