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>
35 #include "AliDecayerPythia.h"
36 #include "AliGenPythia.h"
37 #include "AliHeader.h"
38 #include "AliGenPythiaEventHeader.h"
39 #include "AliPythia.h"
40 #include "AliPythiaRndm.h"
43 #include "AliRunLoader.h"
45 #include "PyquenCommon.h"
47 ClassImp(AliGenPythia)
50 AliGenPythia::AliGenPythia():
81 fDecayer(new AliDecayerPythia()),
89 fPhiMaxJet(2.* TMath::Pi()),
90 fJetReconstruction(kCell),
94 fPhiMaxGamma(2. * TMath::Pi()),
100 fPycellMinEtJet(10.),
101 fPycellMaxRadius(1.),
102 fStackFillOpt(kFlavorSelection),
104 fFragmentation(kTRUE),
111 fTriggerMultiplicity(0),
112 fTriggerMultiplicityEta(0),
113 fCountMode(kCountAll),
117 fFragPhotonInCalo(kFALSE),
119 fPhotonInCalo(kFALSE),
122 fCheckPHOSeta(kFALSE),
123 fFragPhotonOrPi0MinPt(0),
133 // Default Constructor
136 if (!AliPythiaRndm::GetPythiaRandom())
137 AliPythiaRndm::SetPythiaRandom(GetRandom());
140 AliGenPythia::AliGenPythia(Int_t npart)
151 fInteractionRate(0.),
165 fHadronisation(kTRUE),
167 fReadFromFile(kFALSE),
171 fDecayer(new AliDecayerPythia()),
172 fDebugEventFirst(-1),
179 fPhiMaxJet(2.* TMath::Pi()),
180 fJetReconstruction(kCell),
184 fPhiMaxGamma(2. * TMath::Pi()),
188 fPycellThreshold(0.),
190 fPycellMinEtJet(10.),
191 fPycellMaxRadius(1.),
192 fStackFillOpt(kFlavorSelection),
194 fFragmentation(kTRUE),
201 fTriggerMultiplicity(0),
202 fTriggerMultiplicityEta(0),
203 fCountMode(kCountAll),
207 fFragPhotonInCalo(kFALSE),
209 fPhotonInCalo(kFALSE),
212 fCheckPHOSeta(kFALSE),
213 fFragPhotonOrPi0MinPt(0),
222 // default charm production at 5. 5 TeV
224 // structure function GRVHO
228 fTitle= "Particle Generator using PYTHIA";
230 // Set random number generator
231 if (!AliPythiaRndm::GetPythiaRandom())
232 AliPythiaRndm::SetPythiaRandom(GetRandom());
236 AliGenPythia::~AliGenPythia()
239 if(fEventsTime) delete fEventsTime;
242 void AliGenPythia::SetInteractionRate(Float_t rate,Float_t timewindow)
244 // Generate pileup using user specified rate
245 fInteractionRate = rate;
246 fTimeWindow = timewindow;
250 void AliGenPythia::GeneratePileup()
252 // Generate sub events time for pileup
254 if(fInteractionRate == 0.) {
255 Warning("GeneratePileup","Zero interaction specified. Skipping pileup generation.\n");
259 Int_t npart = NumberParticles();
261 Warning("GeneratePileup","Negative number of particles. Skipping pileup generation.\n");
265 if(fEventsTime) delete fEventsTime;
266 fEventsTime = new TArrayF(npart);
267 TArrayF &array = *fEventsTime;
268 for(Int_t ipart = 0; ipart < npart; ipart++)
271 Float_t eventtime = 0.;
274 eventtime += (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
275 if(eventtime > fTimeWindow) break;
276 array.Set(array.GetSize()+1);
277 array[array.GetSize()-1] = eventtime;
283 eventtime -= (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
284 if(TMath::Abs(eventtime) > fTimeWindow) break;
285 array.Set(array.GetSize()+1);
286 array[array.GetSize()-1] = eventtime;
289 SetNumberParticles(fEventsTime->GetSize());
292 void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
293 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
295 // Set pycell parameters
296 fPycellEtaMax = etamax;
299 fPycellThreshold = thresh;
300 fPycellEtSeed = etseed;
301 fPycellMinEtJet = minet;
302 fPycellMaxRadius = r;
307 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
309 // Set a range of event numbers, for which a table
310 // of generated particle will be printed
311 fDebugEventFirst = eventFirst;
312 fDebugEventLast = eventLast;
313 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
316 void AliGenPythia::Init()
320 SetMC(AliPythia::Instance());
321 fPythia=(AliPythia*) fMCEvGen;
324 fParentWeight=1./Float_t(fNpart);
328 fPythia->SetCKIN(3,fPtHardMin);
329 fPythia->SetCKIN(4,fPtHardMax);
330 fPythia->SetCKIN(7,fYHardMin);
331 fPythia->SetCKIN(8,fYHardMax);
333 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget, fNucPdf);
335 if (fFragmentation) {
336 fPythia->SetMSTP(111,1);
338 fPythia->SetMSTP(111,0);
342 // initial state radiation
343 fPythia->SetMSTP(61,fGinit);
344 // final state radiation
345 fPythia->SetMSTP(71,fGfinal);
348 fPythia->SetMSTP(91,1);
349 fPythia->SetPARP(91,fPtKick);
350 fPythia->SetPARP(93, 4. * fPtKick);
352 fPythia->SetMSTP(91,0);
357 fRL = AliRunLoader::Open(fFileName, "Partons");
358 fRL->LoadKinematics();
364 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
365 // Forward Paramters to the AliPythia object
366 fDecayer->SetForceDecay(fForceDecay);
367 // Switch off Heavy Flavors on request
369 // Maximum number of quark flavours used in pdf
370 fPythia->SetMSTP(58, 3);
371 // Maximum number of flavors that can be used in showers
372 fPythia->SetMSTJ(45, 3);
373 // Switch off g->QQbar splitting in decay table
374 ((AliDecayerPythia*) fDecayer)->HeavyFlavourOff();
380 // Parent and Children Selection
383 case kPyOldUEQ2ordered:
384 case kPyOldUEQ2ordered2:
388 case kPyCharmUnforced:
389 case kPyCharmPbPbMNR:
392 case kPyCharmppMNRwmi:
393 fParentSelect[0] = 411;
394 fParentSelect[1] = 421;
395 fParentSelect[2] = 431;
396 fParentSelect[3] = 4122;
402 fParentSelect[0] = 421;
405 case kPyDPlusPbPbMNR:
408 fParentSelect[0] = 411;
411 case kPyDPlusStrangePbPbMNR:
412 case kPyDPlusStrangepPbMNR:
413 case kPyDPlusStrangeppMNR:
414 fParentSelect[0] = 431;
418 case kPyBeautyPbPbMNR:
419 case kPyBeautypPbMNR:
421 case kPyBeautyppMNRwmi:
422 fParentSelect[0]= 511;
423 fParentSelect[1]= 521;
424 fParentSelect[2]= 531;
425 fParentSelect[3]= 5122;
426 fParentSelect[4]= 5132;
427 fParentSelect[5]= 5232;
428 fParentSelect[6]= 5332;
431 case kPyBeautyUnforced:
432 fParentSelect[0] = 511;
433 fParentSelect[1] = 521;
434 fParentSelect[2] = 531;
435 fParentSelect[3] = 5122;
436 fParentSelect[4] = 5132;
437 fParentSelect[5] = 5232;
438 fParentSelect[6] = 5332;
443 fParentSelect[0] = 443;
459 // JetFinder for Trigger
461 // Configure detector (EMCAL like)
463 fPythia->SetPARU(51, fPycellEtaMax);
464 fPythia->SetMSTU(51, fPycellNEta);
465 fPythia->SetMSTU(52, fPycellNPhi);
467 // Configure Jet Finder
469 fPythia->SetPARU(58, fPycellThreshold);
470 fPythia->SetPARU(52, fPycellEtSeed);
471 fPythia->SetPARU(53, fPycellMinEtJet);
472 fPythia->SetPARU(54, fPycellMaxRadius);
473 fPythia->SetMSTU(54, 2);
475 // This counts the total number of calls to Pyevnt() per run.
490 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
494 fPythia->InitQuenching(0., 0.1, 0.6e6, 0);
496 fPythia->SetPARJ(200, 0.0);
499 // Nestor's change of the splittings
500 fPythia->SetPARJ(200, 0.8);
501 fPythia->SetMSTJ(41, 1); // QCD radiation only
502 fPythia->SetMSTJ(42, 2); // angular ordering
503 fPythia->SetMSTJ(44, 2); // option to run alpha_s
504 fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
505 fPythia->SetMSTJ(50, 0); // No coherence in first branching
506 fPythia->SetPARJ(82, 1.); // Cut off for parton showers
510 void AliGenPythia::Generate()
512 // Generate one event
513 if (!fPythia) fPythia=(AliPythia*) fMCEvGen;
514 fDecayer->ForceDecay();
516 Float_t polar[3] = {0,0,0};
517 Float_t origin[3] = {0,0,0};
519 // converts from mm/c to s
520 const Float_t kconv=0.001/2.999792458e8;
530 // Set collision vertex position
531 if (fVertexSmear == kPerEvent) Vertex();
540 // Switch hadronisation off
542 fPythia->SetMSTJ(1, 0);
544 // Either produce new event or read partons from file
546 if (!fReadFromFile) {
552 fNpartons = fPythia->GetN();
554 printf("Loading Event %d\n",AliRunLoader::GetRunLoader()->GetEventNumber());
555 fRL->GetEvent(AliRunLoader::GetRunLoader()->GetEventNumber());
557 LoadEvent(fRL->Stack(), 0 , 1);
562 // Run quenching routine
566 } else if (fQuench == 2){
567 fPythia->Pyquen(208., 0, 0.);
568 } else if (fQuench == 3) {
569 // Quenching is via multiplicative correction of the splittings
573 // Switch hadronisation on
575 if (fHadronisation) {
576 fPythia->SetMSTJ(1, 1);
578 // .. and perform hadronisation
579 // printf("Calling hadronisation %d\n", fPythia->GetN());
585 fPythia->ImportParticles(&fParticles,"All");
593 Int_t np = fParticles.GetEntriesFast();
595 if (np == 0) continue;
599 Int_t* pParent = new Int_t[np];
600 Int_t* pSelected = new Int_t[np];
601 Int_t* trackIt = new Int_t[np];
602 for (i = 0; i < np; i++) {
608 Int_t nc = 0; // Total n. of selected particles
609 Int_t nParents = 0; // Selected parents
610 Int_t nTkbles = 0; // Trackable particles
611 if (fProcess != kPyMbDefault &&
613 fProcess != kPyJets &&
614 fProcess != kPyDirectGamma &&
615 fProcess != kPyMbNonDiffr &&
616 fProcess != kPyMbMSEL1 &&
619 fProcess != kPyCharmppMNRwmi &&
620 fProcess != kPyBeautyppMNRwmi) {
622 for (i = 0; i < np; i++) {
623 TParticle* iparticle = (TParticle *) fParticles.At(i);
624 Int_t ks = iparticle->GetStatusCode();
625 kf = CheckPDGCode(iparticle->GetPdgCode());
626 // No initial state partons
627 if (ks==21) continue;
629 // Heavy Flavor Selection
636 if (kfl > 100000) kfl %= 100000;
637 if (kfl > 10000) kfl %= 10000;
639 if (kfl > 10) kfl/=100;
641 if (kfl > 10) kfl/=10;
642 Int_t ipa = iparticle->GetFirstMother()-1;
645 // Establish mother daughter relation between heavy quarks and mesons
647 if (kf >= fFlavorSelect && kf <= 6) {
648 Int_t idau = iparticle->GetFirstDaughter() - 1;
650 TParticle* daughter = (TParticle *) fParticles.At(idau);
651 Int_t pdgD = daughter->GetPdgCode();
652 if (pdgD == 91 || pdgD == 92) {
653 Int_t jmin = daughter->GetFirstDaughter() - 1;
654 Int_t jmax = daughter->GetLastDaughter() - 1;
655 for (Int_t jp = jmin; jp <= jmax; jp++)
656 ((TParticle *) fParticles.At(jp))->SetFirstMother(i+1);
657 } // is string or cluster
663 TParticle * mother = (TParticle *) fParticles.At(ipa);
664 kfMo = TMath::Abs(mother->GetPdgCode());
667 // What to keep in Stack?
668 Bool_t flavorOK = kFALSE;
669 Bool_t selectOK = kFALSE;
671 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
673 if (kfl > fFlavorSelect) {
677 if (kfl == fFlavorSelect) flavorOK = kTRUE;
679 switch (fStackFillOpt) {
680 case kFlavorSelection:
683 case kParentSelection:
684 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
687 if (flavorOK && selectOK) {
689 // Heavy flavor hadron or quark
691 // Kinematic seletion on final state heavy flavor mesons
692 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
697 if (ParentSelected(kf)) ++nParents; // Update parent count
698 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
700 // Kinematic seletion on decay products
701 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
702 && !KinematicSelection(iparticle, 1))
708 // Select if mother was selected and is not tracked
710 if (pSelected[ipa] &&
711 !trackIt[ipa] && // mother will be tracked ?
712 kfMo != 5 && // mother is b-quark, don't store fragments
713 kfMo != 4 && // mother is c-quark, don't store fragments
714 kf != 92) // don't store string
717 // Semi-stable or de-selected: diselect decay products:
720 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
722 Int_t ipF = iparticle->GetFirstDaughter();
723 Int_t ipL = iparticle->GetLastDaughter();
724 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
726 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
727 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
730 if (pSelected[i] == -1) pSelected[i] = 0;
731 if (!pSelected[i]) continue;
732 // Count quarks only if you did not include fragmentation
733 if (fFragmentation && kf <= 10) continue;
736 // Decision on tracking
739 // Track final state particle
740 if (ks == 1) trackIt[i] = 1;
741 // Track semi-stable particles
742 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
743 // Track particles selected by process if undecayed.
744 if (fForceDecay == kNoDecay) {
745 if (ParentSelected(kf)) trackIt[i] = 1;
747 if (ParentSelected(kf)) trackIt[i] = 0;
749 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
753 } // particle selection loop
755 for (i = 0; i<np; i++) {
756 if (!pSelected[i]) continue;
757 TParticle * iparticle = (TParticle *) fParticles.At(i);
758 kf = CheckPDGCode(iparticle->GetPdgCode());
759 Int_t ks = iparticle->GetStatusCode();
760 p[0] = iparticle->Px();
761 p[1] = iparticle->Py();
762 p[2] = iparticle->Pz();
763 p[3] = iparticle->Energy();
765 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
766 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
767 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
769 Float_t tof = kconv*iparticle->T();
770 Int_t ipa = iparticle->GetFirstMother()-1;
771 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
773 PushTrack(fTrackIt*trackIt[i], iparent, kf,
774 p[0], p[1], p[2], p[3],
775 origin[0], origin[1], origin[2], tof,
776 polar[0], polar[1], polar[2],
777 kPPrimary, nt, 1., ks);
794 switch (fCountMode) {
796 // printf(" Count all \n");
800 // printf(" Count parents \n");
803 case kCountTrackables:
804 // printf(" Count trackable \n");
808 if (jev >= fNpart || fNpart == -1) {
809 fKineBias=Float_t(fNpart)/Float_t(fTrials);
811 fQ += fPythia->GetVINT(51);
812 fX1 += fPythia->GetVINT(41);
813 fX2 += fPythia->GetVINT(42);
814 fTrialsRun += fTrials;
821 SetHighWaterMark(nt);
822 // adjust weight due to kinematic selection
825 fXsection=fPythia->GetPARI(1);
828 Int_t AliGenPythia::GenerateMB()
831 // Min Bias selection and other global selections
833 Int_t i, kf, nt, iparent;
836 Float_t polar[3] = {0,0,0};
837 Float_t origin[3] = {0,0,0};
838 // converts from mm/c to s
839 const Float_t kconv=0.001/2.999792458e8;
843 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
847 Int_t* pParent = new Int_t[np];
848 for (i=0; i< np; i++) pParent[i] = -1;
849 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
850 TParticle* jet1 = (TParticle *) fParticles.At(6);
851 TParticle* jet2 = (TParticle *) fParticles.At(7);
852 if (!CheckTrigger(jet1, jet2)) {
858 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
859 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
864 if (fFragPhotonInCalo) pdg = 22 ; // Photon
865 else if (fPi0InCalo) pdg = 111 ; // Pi0
867 for (i=0; i< np; i++) {
868 TParticle* iparticle = (TParticle *) fParticles.At(i);
869 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
870 iparticle->Pt() > fFragPhotonOrPi0MinPt){
871 Int_t imother = iparticle->GetFirstMother() - 1;
872 TParticle* pmother = (TParticle *) fParticles.At(imother);
874 (pdg == 22 && pmother->GetStatusCode() != 11))//No photon from hadron decay
876 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
877 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
878 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
879 (fCheckPHOS && IsInPHOS(phi,eta)) )
888 // Check for minimum multiplicity
889 if (fTriggerMultiplicity > 0) {
890 Int_t multiplicity = 0;
891 for (i = 0; i < np; i++) {
892 TParticle * iparticle = (TParticle *) fParticles.At(i);
894 Int_t statusCode = iparticle->GetStatusCode();
896 // Initial state particle
900 // skip quarks and gluons
901 Int_t pdgCode = TMath::Abs(iparticle->GetPdgCode());
902 if (pdgCode <= 10 || pdgCode == 21)
905 if (fTriggerMultiplicityEta > 0 && TMath::Abs(iparticle->Eta()) > fTriggerMultiplicityEta)
908 TParticlePDG* pdgPart = iparticle->GetPDG();
909 if (pdgPart && pdgPart->Charge() == 0)
915 if (multiplicity < fTriggerMultiplicity) {
920 Printf("Triggered on event with multiplicity of %d > %d", multiplicity, fTriggerMultiplicity);
923 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
924 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
930 for (i=0; i< np; i++) {
931 TParticle* iparticle = (TParticle *) fParticles.At(i);
932 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
933 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
935 if(iparticle->GetStatusCode() == 1
936 && iparticle->GetPdgCode() == pdg
937 && iparticle->Pt() > fPhotonMinPt
940 // first check if the photon is in PHOS phi
941 if(IsInPHOS(phi,eta)){
945 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
950 if(!okd && iphcand != -1) // execute rotation in phi
951 RotatePhi(iphcand,okd);
957 if (fTriggerParticle) {
958 Bool_t triggered = kFALSE;
959 for (i = 0; i < np; i++) {
960 TParticle * iparticle = (TParticle *) fParticles.At(i);
961 kf = CheckPDGCode(iparticle->GetPdgCode());
962 if (kf != fTriggerParticle) continue;
963 if (iparticle->Pt() == 0.) continue;
964 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
975 // Check if there is a ccbar or bbbar pair with at least one of the two
976 // in fYMin < y < fYMax
977 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi) {
979 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
982 for(i=0; i<np; i++) {
983 hvq = (TParticle*)fParticles.At(i);
984 pdgQ = hvq->GetPdgCode();
985 if(TMath::Abs(pdgQ) != fFlavorSelect) continue;
986 if(pdgQ>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
987 yQ = 0.5*TMath::Log((hvq->Energy()+hvq->Pz()+1.e-13)/
988 (hvq->Energy()-hvq->Pz()+1.e-13));
989 if(yQ>fYMin && yQ<fYMax) inYcut=kTRUE;
991 if (!theQ || !theQbar || !inYcut) {
997 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
998 if ( (fProcess == kPyW ||
1000 fProcess == kPyMbDefault ||
1001 fProcess == kPyMb ||
1002 fProcess == kPyMbNonDiffr)
1003 && (fCutOnChild == 1) ) {
1004 if ( !CheckKinematicsOnChild() ) {
1011 for (i = 0; i < np; i++) {
1013 TParticle * iparticle = (TParticle *) fParticles.At(i);
1014 kf = CheckPDGCode(iparticle->GetPdgCode());
1015 Int_t ks = iparticle->GetStatusCode();
1016 Int_t km = iparticle->GetFirstMother();
1017 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
1019 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
1021 if (ks == 1) trackIt = 1;
1022 Int_t ipa = iparticle->GetFirstMother()-1;
1024 iparent = (ipa > -1) ? pParent[ipa] : -1;
1027 // store track information
1028 p[0] = iparticle->Px();
1029 p[1] = iparticle->Py();
1030 p[2] = iparticle->Pz();
1031 p[3] = iparticle->Energy();
1034 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
1035 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
1036 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
1038 Float_t tof = fEventTime + kconv * iparticle->T();
1040 PushTrack(fTrackIt*trackIt, iparent, kf,
1041 p[0], p[1], p[2], p[3],
1042 origin[0], origin[1], origin[2], tof,
1043 polar[0], polar[1], polar[2],
1044 kPPrimary, nt, 1., ks);
1047 // Special Treatment to store color-flow
1049 if (ks == 3 || ks == 13 || ks == 14) {
1050 TParticle* particle = 0;
1052 particle = fStack->Particle(nt);
1054 particle = gAlice->Stack()->Particle(nt);
1056 particle->SetFirstDaughter(fPythia->GetK(2, i));
1057 particle->SetLastDaughter(fPythia->GetK(3, i));
1062 SetHighWaterMark(nt);
1064 } // select particle
1073 void AliGenPythia::FinishRun()
1075 // Print x-section summary
1084 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1085 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1088 void AliGenPythia::AdjustWeights() const
1090 // Adjust the weights after generation of all events
1094 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1095 for (Int_t i=0; i<ntrack; i++) {
1096 part= gAlice->GetMCApp()->Particle(i);
1097 part->SetWeight(part->GetWeight()*fKineBias);
1102 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2, Int_t pdfset)
1104 // Treat protons as inside nuclei with mass numbers a1 and a2
1108 fNucPdf = pdfset; // 0 EKS98 1 EPS08
1113 void AliGenPythia::MakeHeader()
1116 // Make header for the simulated event
1119 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1120 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(2);
1123 // Builds the event header, to be called after each event
1124 if (fHeader) delete fHeader;
1125 fHeader = new AliGenPythiaEventHeader("Pythia");
1128 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
1131 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1134 fHeader->SetPrimaryVertex(fVertex);
1137 // Number of primaries
1138 fHeader->SetNProduced(fNprimaries);
1140 // Jets that have triggered
1142 if (fProcess == kPyJets || fProcess == kPyDirectGamma)
1145 Float_t jets[4][10];
1146 GetJets(njet, ntrig, jets);
1149 for (Int_t i = 0; i < ntrig; i++) {
1150 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1155 // Copy relevant information from external header, if present.
1160 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1161 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1163 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1166 exHeader->TriggerJet(i, uqJet);
1167 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1171 // Store quenching parameters
1178 fPythia->GetQuenchingParameters(xp, yp, z);
1181 Double_t r1 = PARIMP.rb1;
1182 Double_t r2 = PARIMP.rb2;
1183 Double_t b = PARIMP.b1;
1184 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1185 Double_t phi = PARIMP.psib1;
1186 xp = r * TMath::Cos(phi);
1187 yp = r * TMath::Sin(phi);
1190 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1191 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1195 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetVINT(47));
1203 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
1205 // Check the kinematic trigger condition
1208 eta[0] = jet1->Eta();
1209 eta[1] = jet2->Eta();
1211 phi[0] = jet1->Phi();
1212 phi[1] = jet2->Phi();
1214 pdg[0] = jet1->GetPdgCode();
1215 pdg[1] = jet2->GetPdgCode();
1216 Bool_t triggered = kFALSE;
1218 if (fProcess == kPyJets) {
1221 Float_t jets[4][10];
1223 // Use Pythia clustering on parton level to determine jet axis
1225 GetJets(njets, ntrig, jets);
1227 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1232 if (pdg[0] == kGamma) {
1236 //Check eta range first...
1237 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1238 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1240 //Eta is okay, now check phi range
1241 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1242 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1253 Bool_t AliGenPythia::CheckKinematicsOnChild(){
1255 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1257 Bool_t checking = kFALSE;
1258 Int_t j, kcode, ks, km;
1259 Int_t nPartAcc = 0; //number of particles in the acceptance range
1260 Int_t numberOfAcceptedParticles = 1;
1261 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1262 Int_t npart = fParticles.GetEntriesFast();
1264 for (j = 0; j<npart; j++) {
1265 TParticle * jparticle = (TParticle *) fParticles.At(j);
1266 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1267 ks = jparticle->GetStatusCode();
1268 km = jparticle->GetFirstMother();
1270 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1273 if( numberOfAcceptedParticles <= nPartAcc){
1282 void AliGenPythia::LoadEvent(AliStack* stack, Int_t flag, Int_t reHadr)
1285 // Load event into Pythia Common Block
1288 Int_t npart = stack -> GetNprimary();
1292 (fPythia->GetPyjets())->N = npart;
1294 n0 = (fPythia->GetPyjets())->N;
1295 (fPythia->GetPyjets())->N = n0 + npart;
1299 for (Int_t part = 0; part < npart; part++) {
1300 TParticle *mPart = stack->Particle(part);
1302 Int_t kf = mPart->GetPdgCode();
1303 Int_t ks = mPart->GetStatusCode();
1304 Int_t idf = mPart->GetFirstDaughter();
1305 Int_t idl = mPart->GetLastDaughter();
1308 if (ks == 11 || ks == 12) {
1315 Float_t px = mPart->Px();
1316 Float_t py = mPart->Py();
1317 Float_t pz = mPart->Pz();
1318 Float_t e = mPart->Energy();
1319 Float_t m = mPart->GetCalcMass();
1322 (fPythia->GetPyjets())->P[0][part+n0] = px;
1323 (fPythia->GetPyjets())->P[1][part+n0] = py;
1324 (fPythia->GetPyjets())->P[2][part+n0] = pz;
1325 (fPythia->GetPyjets())->P[3][part+n0] = e;
1326 (fPythia->GetPyjets())->P[4][part+n0] = m;
1328 (fPythia->GetPyjets())->K[1][part+n0] = kf;
1329 (fPythia->GetPyjets())->K[0][part+n0] = ks;
1330 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
1331 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
1332 (fPythia->GetPyjets())->K[2][part+n0] = mPart->GetFirstMother() + 1;
1337 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1340 // Calls the Pythia jet finding algorithm to find jets in the current event
1345 Int_t n = fPythia->GetN();
1349 fPythia->Pycell(njets);
1351 for (i = 0; i < njets; i++) {
1352 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1353 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1354 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1355 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1366 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1369 // Calls the Pythia clustering algorithm to find jets in the current event
1371 Int_t n = fPythia->GetN();
1374 if (fJetReconstruction == kCluster) {
1376 // Configure cluster algorithm
1378 fPythia->SetPARU(43, 2.);
1379 fPythia->SetMSTU(41, 1);
1381 // Call cluster algorithm
1383 fPythia->Pyclus(nJets);
1385 // Loading jets from common block
1391 fPythia->Pycell(nJets);
1395 for (i = 0; i < nJets; i++) {
1396 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1397 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1398 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1399 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1400 Float_t pt = TMath::Sqrt(px * px + py * py);
1401 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1402 Float_t theta = TMath::ATan2(pt,pz);
1403 Float_t et = e * TMath::Sin(theta);
1404 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1406 eta > fEtaMinJet && eta < fEtaMaxJet &&
1407 phi > fPhiMinJet && phi < fPhiMaxJet &&
1408 et > fEtMinJet && et < fEtMaxJet
1411 jets[0][nJetsTrig] = px;
1412 jets[1][nJetsTrig] = py;
1413 jets[2][nJetsTrig] = pz;
1414 jets[3][nJetsTrig] = e;
1416 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1418 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1423 void AliGenPythia::GetSubEventTime()
1425 // Calculates time of the next subevent
1428 TArrayF &array = *fEventsTime;
1429 fEventTime = array[fCurSubEvent++];
1431 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1435 Bool_t AliGenPythia::IsInEMCAL(Float_t phi, Float_t eta)
1437 // Is particle in EMCAL acceptance?
1438 // phi in degrees, etamin=-etamax
1439 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1446 Bool_t AliGenPythia::IsInPHOS(Float_t phi, Float_t eta)
1448 // Is particle in PHOS acceptance?
1449 // Acceptance slightly larger considered.
1450 // phi in degrees, etamin=-etamax
1451 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1458 void AliGenPythia::RotatePhi(Int_t iphcand, Bool_t& okdd)
1460 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1461 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1462 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1463 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1465 //calculate deltaphi
1466 TParticle* ph = (TParticle *) fParticles.At(iphcand);
1467 Double_t phphi = ph->Phi();
1468 Double_t deltaphi = phiPHOS - phphi;
1472 //loop for all particles and produce the phi rotation
1473 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
1474 Double_t oldphi, newphi;
1475 Double_t newVx, newVy, R, Vz, time;
1476 Double_t newPx, newPy, pt, Pz, e;
1477 for(Int_t i=0; i< np; i++) {
1478 TParticle* iparticle = (TParticle *) fParticles.At(i);
1479 oldphi = iparticle->Phi();
1480 newphi = oldphi + deltaphi;
1481 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1482 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1485 newVx = R*TMath::Cos(newphi);
1486 newVy = R*TMath::Sin(newphi);
1487 Vz = iparticle->Vz(); // don't transform
1488 time = iparticle->T(); // don't transform
1490 pt = iparticle->Pt();
1491 newPx = pt*TMath::Cos(newphi);
1492 newPy = pt*TMath::Sin(newphi);
1493 Pz = iparticle->Pz(); // don't transform
1494 e = iparticle->Energy(); // don't transform
1497 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1498 iparticle->SetMomentum(newPx, newPy, Pz, e);
1500 } //end particle loop
1502 // now let's check that we put correctly the candidate photon in PHOS
1503 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1504 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1505 if(IsInPHOS(phi,eta))
1511 void AliGenPythia::Streamer(TBuffer &R__b)
1513 // Stream an object of class AliGenPythia.
1515 if (R__b.IsReading()) {
1516 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1517 AliGenerator::Streamer(R__b);
1518 R__b >> (Int_t&)fProcess;
1519 R__b >> (Int_t&)fStrucFunc;
1520 R__b >> (Int_t&)fForceDecay;
1524 fParentSelect.Streamer(R__b);
1525 fChildSelect.Streamer(R__b);
1527 // (AliPythia::Instance())->Streamer(R__b);
1530 // if (fDecayer) fDecayer->Streamer(R__b);
1532 R__b.WriteVersion(AliGenPythia::IsA());
1533 AliGenerator::Streamer(R__b);
1534 R__b << (Int_t)fProcess;
1535 R__b << (Int_t)fStrucFunc;
1536 R__b << (Int_t)fForceDecay;
1540 fParentSelect.Streamer(R__b);
1541 fChildSelect.Streamer(R__b);
1546 // fDecayer->Streamer(R__b);