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():
82 fDecayer(new AliDecayerPythia()),
90 fPhiMaxJet(2.* TMath::Pi()),
91 fJetReconstruction(kCell),
95 fPhiMaxGamma(2. * TMath::Pi()),
101 fPycellMinEtJet(10.),
102 fPycellMaxRadius(1.),
103 fStackFillOpt(kFlavorSelection),
105 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
135 if (!AliPythiaRndm::GetPythiaRandom())
136 AliPythiaRndm::SetPythiaRandom(GetRandom());
139 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),
200 fTriggerMultiplicity(0),
201 fTriggerMultiplicityEta(0),
202 fCountMode(kCountAll),
206 fFragPhotonInCalo(kFALSE),
208 fPhotonInCalo(kFALSE),
211 fCheckPHOSeta(kFALSE),
212 fFragPhotonOrPi0MinPt(0),
221 // default charm production at 5. 5 TeV
223 // structure function GRVHO
226 fTitle= "Particle Generator using PYTHIA";
228 // Set random number generator
229 if (!AliPythiaRndm::GetPythiaRandom())
230 AliPythiaRndm::SetPythiaRandom(GetRandom());
231 fParticles = new TClonesArray("TParticle",1000);
235 AliGenPythia::~AliGenPythia()
238 if(fEventsTime) delete fEventsTime;
241 void AliGenPythia::SetInteractionRate(Float_t rate,Float_t timewindow)
243 // Generate pileup using user specified rate
244 fInteractionRate = rate;
245 fTimeWindow = timewindow;
249 void AliGenPythia::GeneratePileup()
251 // Generate sub events time for pileup
253 if(fInteractionRate == 0.) {
254 Warning("GeneratePileup","Zero interaction specified. Skipping pileup generation.\n");
258 Int_t npart = NumberParticles();
260 Warning("GeneratePileup","Negative number of particles. Skipping pileup generation.\n");
264 if(fEventsTime) delete fEventsTime;
265 fEventsTime = new TArrayF(npart);
266 TArrayF &array = *fEventsTime;
267 for(Int_t ipart = 0; ipart < npart; ipart++)
270 Float_t eventtime = 0.;
273 eventtime += (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
274 if(eventtime > fTimeWindow) break;
275 array.Set(array.GetSize()+1);
276 array[array.GetSize()-1] = eventtime;
282 eventtime -= (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
283 if(TMath::Abs(eventtime) > fTimeWindow) break;
284 array.Set(array.GetSize()+1);
285 array[array.GetSize()-1] = eventtime;
288 SetNumberParticles(fEventsTime->GetSize());
291 void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
292 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
294 // Set pycell parameters
295 fPycellEtaMax = etamax;
298 fPycellThreshold = thresh;
299 fPycellEtSeed = etseed;
300 fPycellMinEtJet = minet;
301 fPycellMaxRadius = r;
306 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
308 // Set a range of event numbers, for which a table
309 // of generated particle will be printed
310 fDebugEventFirst = eventFirst;
311 fDebugEventLast = eventLast;
312 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
315 void AliGenPythia::Init()
319 SetMC(AliPythia::Instance());
320 fPythia=(AliPythia*) fMCEvGen;
323 fParentWeight=1./Float_t(fNpart);
327 fPythia->SetCKIN(3,fPtHardMin);
328 fPythia->SetCKIN(4,fPtHardMax);
329 fPythia->SetCKIN(7,fYHardMin);
330 fPythia->SetCKIN(8,fYHardMax);
332 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget);
334 if (fFragmentation) {
335 fPythia->SetMSTP(111,1);
337 fPythia->SetMSTP(111,0);
341 // initial state radiation
342 fPythia->SetMSTP(61,fGinit);
343 // final state radiation
344 fPythia->SetMSTP(71,fGfinal);
347 fPythia->SetMSTP(91,1);
348 fPythia->SetPARP(91,fPtKick);
349 fPythia->SetPARP(93, 4. * fPtKick);
351 fPythia->SetMSTP(91,0);
356 fRL = AliRunLoader::Open(fFileName, "Partons");
357 fRL->LoadKinematics();
363 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
364 // Forward Paramters to the AliPythia object
365 fDecayer->SetForceDecay(fForceDecay);
366 // Switch off Heavy Flavors on request
368 // Maximum number of quark flavours used in pdf
369 fPythia->SetMSTP(58, 3);
370 // Maximum number of flavors that can be used in showers
371 fPythia->SetMSTJ(45, 3);
372 // Switch off g->QQbar splitting in decay table
373 ((AliDecayerPythia*) fDecayer)->HeavyFlavourOff();
379 // Parent and Children Selection
382 case kPyOldUEQ2ordered:
383 case kPyOldUEQ2ordered2:
387 case kPyCharmUnforced:
388 case kPyCharmPbPbMNR:
391 case kPyCharmppMNRwmi:
392 fParentSelect[0] = 411;
393 fParentSelect[1] = 421;
394 fParentSelect[2] = 431;
395 fParentSelect[3] = 4122;
401 fParentSelect[0] = 421;
404 case kPyDPlusPbPbMNR:
407 fParentSelect[0] = 411;
410 case kPyDPlusStrangePbPbMNR:
411 case kPyDPlusStrangepPbMNR:
412 case kPyDPlusStrangeppMNR:
413 fParentSelect[0] = 431;
417 case kPyBeautyPbPbMNR:
418 case kPyBeautypPbMNR:
420 case kPyBeautyppMNRwmi:
421 fParentSelect[0]= 511;
422 fParentSelect[1]= 521;
423 fParentSelect[2]= 531;
424 fParentSelect[3]= 5122;
425 fParentSelect[4]= 5132;
426 fParentSelect[5]= 5232;
427 fParentSelect[6]= 5332;
430 case kPyBeautyUnforced:
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;
442 fParentSelect[0] = 443;
458 // JetFinder for Trigger
460 // Configure detector (EMCAL like)
462 fPythia->SetPARU(51, fPycellEtaMax);
463 fPythia->SetMSTU(51, fPycellNEta);
464 fPythia->SetMSTU(52, fPycellNPhi);
466 // Configure Jet Finder
468 fPythia->SetPARU(58, fPycellThreshold);
469 fPythia->SetPARU(52, fPycellEtSeed);
470 fPythia->SetPARU(53, fPycellMinEtJet);
471 fPythia->SetPARU(54, fPycellMaxRadius);
472 fPythia->SetMSTU(54, 2);
474 // This counts the total number of calls to Pyevnt() per run.
489 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
493 fPythia->InitQuenching(0., 0.1, 0.6e6, 0);
495 fPythia->SetPARJ(200, 0.0);
498 // Nestor's change of the splittings
499 fPythia->SetPARJ(200, 0.8);
500 fPythia->SetMSTJ(41, 1); // QCD radiation only
501 fPythia->SetMSTJ(42, 2); // angular ordering
502 fPythia->SetMSTJ(44, 2); // option to run alpha_s
503 fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
504 fPythia->SetMSTJ(50, 0); // No coherence in first branching
505 fPythia->SetPARJ(82, 1.); // Cut off for parton showers
509 void AliGenPythia::Generate()
511 // Generate one event
513 fDecayer->ForceDecay();
515 Float_t polar[3] = {0,0,0};
516 Float_t origin[3] = {0,0,0};
518 // converts from mm/c to s
519 const Float_t kconv=0.001/2.999792458e8;
529 // Set collision vertex position
530 if (fVertexSmear == kPerEvent) Vertex();
539 // Switch hadronisation off
541 fPythia->SetMSTJ(1, 0);
543 // Either produce new event or read partons from file
545 if (!fReadFromFile) {
551 fNpartons = fPythia->GetN();
553 printf("Loading Event %d\n",AliRunLoader::GetRunLoader()->GetEventNumber());
554 fRL->GetEvent(AliRunLoader::GetRunLoader()->GetEventNumber());
556 LoadEvent(fRL->Stack(), 0 , 1);
561 // Run quenching routine
565 } else if (fQuench == 2){
566 fPythia->Pyquen(208., 0, 0.);
567 } else if (fQuench == 3) {
568 // Quenching is via multiplicative correction of the splittings
572 // Switch hadronisation on
574 fPythia->SetMSTJ(1, 1);
576 // .. and perform hadronisation
577 // printf("Calling hadronisation %d\n", fPythia->GetN());
580 fPythia->ImportParticles(fParticles,"All");
588 Int_t np = fParticles->GetEntriesFast();
590 if (np == 0) continue;
594 Int_t* pParent = new Int_t[np];
595 Int_t* pSelected = new Int_t[np];
596 Int_t* trackIt = new Int_t[np];
597 for (i = 0; i < np; i++) {
603 Int_t nc = 0; // Total n. of selected particles
604 Int_t nParents = 0; // Selected parents
605 Int_t nTkbles = 0; // Trackable particles
606 if (fProcess != kPyMbDefault &&
608 fProcess != kPyJets &&
609 fProcess != kPyDirectGamma &&
610 fProcess != kPyMbNonDiffr &&
611 fProcess != kPyMbMSEL1 &&
614 fProcess != kPyCharmppMNRwmi &&
615 fProcess != kPyBeautyppMNRwmi) {
617 for (i = 0; i < np; i++) {
618 TParticle* iparticle = (TParticle *) fParticles->At(i);
619 Int_t ks = iparticle->GetStatusCode();
620 kf = CheckPDGCode(iparticle->GetPdgCode());
621 // No initial state partons
622 if (ks==21) continue;
624 // Heavy Flavor Selection
631 if (kfl > 100000) kfl %= 100000;
632 if (kfl > 10000) kfl %= 10000;
634 if (kfl > 10) kfl/=100;
636 if (kfl > 10) kfl/=10;
637 Int_t ipa = iparticle->GetFirstMother()-1;
640 // Establish mother daughter relation between heavy quarks and mesons
642 if (kf >= fFlavorSelect && kf <= 6) {
643 Int_t idau = iparticle->GetFirstDaughter() - 1;
645 TParticle* daughter = (TParticle *) fParticles->At(idau);
646 Int_t pdgD = daughter->GetPdgCode();
647 if (pdgD == 91 || pdgD == 92) {
648 Int_t jmin = daughter->GetFirstDaughter() - 1;
649 Int_t jmax = daughter->GetLastDaughter() - 1;
650 for (Int_t j = jmin; j <= jmax; j++)
651 ((TParticle *) fParticles->At(j))->SetFirstMother(i+1);
652 } // is string or cluster
658 TParticle * mother = (TParticle *) fParticles->At(ipa);
659 kfMo = TMath::Abs(mother->GetPdgCode());
662 // What to keep in Stack?
663 Bool_t flavorOK = kFALSE;
664 Bool_t selectOK = kFALSE;
666 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
668 if (kfl > fFlavorSelect) {
672 if (kfl == fFlavorSelect) flavorOK = kTRUE;
674 switch (fStackFillOpt) {
675 case kFlavorSelection:
678 case kParentSelection:
679 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
682 if (flavorOK && selectOK) {
684 // Heavy flavor hadron or quark
686 // Kinematic seletion on final state heavy flavor mesons
687 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
692 if (ParentSelected(kf)) ++nParents; // Update parent count
693 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
695 // Kinematic seletion on decay products
696 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
697 && !KinematicSelection(iparticle, 1))
703 // Select if mother was selected and is not tracked
705 if (pSelected[ipa] &&
706 !trackIt[ipa] && // mother will be tracked ?
707 kfMo != 5 && // mother is b-quark, don't store fragments
708 kfMo != 4 && // mother is c-quark, don't store fragments
709 kf != 92) // don't store string
712 // Semi-stable or de-selected: diselect decay products:
715 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
717 Int_t ipF = iparticle->GetFirstDaughter();
718 Int_t ipL = iparticle->GetLastDaughter();
719 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
721 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
722 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
725 if (pSelected[i] == -1) pSelected[i] = 0;
726 if (!pSelected[i]) continue;
727 // Count quarks only if you did not include fragmentation
728 if (fFragmentation && kf <= 10) continue;
731 // Decision on tracking
734 // Track final state particle
735 if (ks == 1) trackIt[i] = 1;
736 // Track semi-stable particles
737 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
738 // Track particles selected by process if undecayed.
739 if (fForceDecay == kNoDecay) {
740 if (ParentSelected(kf)) trackIt[i] = 1;
742 if (ParentSelected(kf)) trackIt[i] = 0;
744 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
748 } // particle selection loop
750 for (i = 0; i<np; i++) {
751 if (!pSelected[i]) continue;
752 TParticle * iparticle = (TParticle *) fParticles->At(i);
753 kf = CheckPDGCode(iparticle->GetPdgCode());
754 Int_t ks = iparticle->GetStatusCode();
755 p[0] = iparticle->Px();
756 p[1] = iparticle->Py();
757 p[2] = iparticle->Pz();
758 p[3] = iparticle->Energy();
760 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
761 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
762 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
764 Float_t tof = kconv*iparticle->T();
765 Int_t ipa = iparticle->GetFirstMother()-1;
766 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
768 PushTrack(fTrackIt*trackIt[i], iparent, kf,
769 p[0], p[1], p[2], p[3],
770 origin[0], origin[1], origin[2], tof,
771 polar[0], polar[1], polar[2],
772 kPPrimary, nt, 1., ks);
789 switch (fCountMode) {
791 // printf(" Count all \n");
795 // printf(" Count parents \n");
798 case kCountTrackables:
799 // printf(" Count trackable \n");
803 if (jev >= fNpart || fNpart == -1) {
804 fKineBias=Float_t(fNpart)/Float_t(fTrials);
806 fQ += fPythia->GetVINT(51);
807 fX1 += fPythia->GetVINT(41);
808 fX2 += fPythia->GetVINT(42);
809 fTrialsRun += fTrials;
816 SetHighWaterMark(nt);
817 // adjust weight due to kinematic selection
820 fXsection=fPythia->GetPARI(1);
823 Int_t AliGenPythia::GenerateMB()
826 // Min Bias selection and other global selections
828 Int_t i, kf, nt, iparent;
831 Float_t polar[3] = {0,0,0};
832 Float_t origin[3] = {0,0,0};
833 // converts from mm/c to s
834 const Float_t kconv=0.001/2.999792458e8;
838 Int_t np = (fHadronisation) ? fParticles->GetEntriesFast() : fNpartons;
842 Int_t* pParent = new Int_t[np];
843 for (i=0; i< np; i++) pParent[i] = -1;
844 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
845 TParticle* jet1 = (TParticle *) fParticles->At(6);
846 TParticle* jet2 = (TParticle *) fParticles->At(7);
847 if (!CheckTrigger(jet1, jet2)) {
853 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
854 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
859 if (fFragPhotonInCalo) pdg = 22 ; // Photon
860 else if (fPi0InCalo) pdg = 111 ; // Pi0
862 for (i=0; i< np; i++) {
863 TParticle* iparticle = (TParticle *) fParticles->At(i);
864 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
865 iparticle->Pt() > fFragPhotonOrPi0MinPt){
866 Int_t imother = iparticle->GetFirstMother() - 1;
867 TParticle* pmother = (TParticle *) fParticles->At(imother);
869 (pdg == 22 && pmother->GetStatusCode() != 11))//No photon from hadron decay
871 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
872 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
873 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
874 (fCheckPHOS && IsInPHOS(phi,eta)) )
883 // Check for minimum multiplicity
884 if (fTriggerMultiplicity > 0) {
885 Int_t multiplicity = 0;
886 for (i = 0; i < np; i++) {
887 TParticle * iparticle = (TParticle *) fParticles->At(i);
889 Int_t statusCode = iparticle->GetStatusCode();
891 // Initial state particle
895 // skip quarks and gluons
896 Int_t pdgCode = TMath::Abs(iparticle->GetPdgCode());
897 if (pdgCode <= 10 || pdgCode == 21)
900 if (fTriggerMultiplicityEta > 0 && TMath::Abs(iparticle->Eta()) > fTriggerMultiplicityEta)
903 TParticlePDG* pdgPart = iparticle->GetPDG();
904 if (pdgPart && pdgPart->Charge() == 0)
910 if (multiplicity < fTriggerMultiplicity) {
915 Printf("Triggered on event with multiplicity of %d > %d", multiplicity, fTriggerMultiplicity);
918 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
919 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
925 for (i=0; i< np; i++) {
926 TParticle* iparticle = (TParticle *) fParticles->At(i);
927 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
928 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
930 if(iparticle->GetStatusCode() == 1
931 && iparticle->GetPdgCode() == pdg
932 && iparticle->Pt() > fPhotonMinPt
935 // first check if the photon is in PHOS phi
936 if(IsInPHOS(phi,eta)){
940 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
945 if(!okd && iphcand != -1) // execute rotation in phi
946 RotatePhi(iphcand,okd);
952 if (fTriggerParticle) {
953 Bool_t triggered = kFALSE;
954 for (i = 0; i < np; i++) {
955 TParticle * iparticle = (TParticle *) fParticles->At(i);
956 kf = CheckPDGCode(iparticle->GetPdgCode());
957 if (kf != fTriggerParticle) continue;
958 if (iparticle->Pt() == 0.) continue;
959 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
970 // Check if there is a ccbar or bbbar pair with at least one of the two
971 // in fYMin < y < fYMax
972 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi) {
974 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
977 for(i=0; i<np; i++) {
978 hvq = (TParticle*)fParticles->At(i);
979 pdgQ = hvq->GetPdgCode();
980 if(TMath::Abs(pdgQ) != fFlavorSelect) continue;
981 if(pdgQ>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
982 yQ = 0.5*TMath::Log((hvq->Energy()+hvq->Pz()+1.e-13)/
983 (hvq->Energy()-hvq->Pz()+1.e-13));
984 if(yQ>fYMin && yQ<fYMax) inYcut=kTRUE;
986 if (!theQ || !theQbar || !inYcut) {
992 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
993 if ( (fProcess == kPyW ||
995 fProcess == kPyMbDefault ||
997 fProcess == kPyMbNonDiffr)
998 && (fCutOnChild == 1) ) {
999 if ( !CheckKinematicsOnChild() ) {
1006 for (i = 0; i < np; i++) {
1008 TParticle * iparticle = (TParticle *) fParticles->At(i);
1009 kf = CheckPDGCode(iparticle->GetPdgCode());
1010 Int_t ks = iparticle->GetStatusCode();
1011 Int_t km = iparticle->GetFirstMother();
1012 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
1014 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
1016 if (ks == 1) trackIt = 1;
1017 Int_t ipa = iparticle->GetFirstMother()-1;
1019 iparent = (ipa > -1) ? pParent[ipa] : -1;
1022 // store track information
1023 p[0] = iparticle->Px();
1024 p[1] = iparticle->Py();
1025 p[2] = iparticle->Pz();
1026 p[3] = iparticle->Energy();
1029 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
1030 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
1031 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
1033 Float_t tof = fEventTime + kconv * iparticle->T();
1035 PushTrack(fTrackIt*trackIt, iparent, kf,
1036 p[0], p[1], p[2], p[3],
1037 origin[0], origin[1], origin[2], tof,
1038 polar[0], polar[1], polar[2],
1039 kPPrimary, nt, 1., ks);
1042 // Special Treatment to store color-flow
1044 if (ks == 3 || ks == 13 || ks == 14) {
1045 TParticle* particle = 0;
1047 particle = fStack->Particle(nt);
1049 particle = gAlice->Stack()->Particle(nt);
1051 particle->SetFirstDaughter(fPythia->GetK(2, i));
1052 particle->SetLastDaughter(fPythia->GetK(3, i));
1057 SetHighWaterMark(nt);
1059 } // select particle
1068 void AliGenPythia::FinishRun()
1070 // Print x-section summary
1079 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1080 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1083 void AliGenPythia::AdjustWeights() const
1085 // Adjust the weights after generation of all events
1089 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1090 for (Int_t i=0; i<ntrack; i++) {
1091 part= gAlice->GetMCApp()->Particle(i);
1092 part->SetWeight(part->GetWeight()*fKineBias);
1097 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
1099 // Treat protons as inside nuclei with mass numbers a1 and a2
1107 void AliGenPythia::MakeHeader()
1110 // Make header for the simulated event
1113 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1114 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(2);
1117 // Builds the event header, to be called after each event
1118 if (fHeader) delete fHeader;
1119 fHeader = new AliGenPythiaEventHeader("Pythia");
1122 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
1125 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1128 fHeader->SetPrimaryVertex(fVertex);
1131 // Number of primaries
1132 fHeader->SetNProduced(fNprimaries);
1134 // Jets that have triggered
1136 if (fProcess == kPyJets)
1139 Float_t jets[4][10];
1140 GetJets(njet, ntrig, jets);
1143 for (Int_t i = 0; i < ntrig; i++) {
1144 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1149 // Copy relevant information from external header, if present.
1154 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1155 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1157 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1160 exHeader->TriggerJet(i, uqJet);
1161 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1165 // Store quenching parameters
1172 fPythia->GetQuenchingParameters(xp, yp, z);
1175 Double_t r1 = PARIMP.rb1;
1176 Double_t r2 = PARIMP.rb2;
1177 Double_t b = PARIMP.b1;
1178 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1179 Double_t phi = PARIMP.psib1;
1180 xp = r * TMath::Cos(phi);
1181 yp = r * TMath::Sin(phi);
1184 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1185 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1189 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetVINT(47));
1197 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
1199 // Check the kinematic trigger condition
1202 eta[0] = jet1->Eta();
1203 eta[1] = jet2->Eta();
1205 phi[0] = jet1->Phi();
1206 phi[1] = jet2->Phi();
1208 pdg[0] = jet1->GetPdgCode();
1209 pdg[1] = jet2->GetPdgCode();
1210 Bool_t triggered = kFALSE;
1212 if (fProcess == kPyJets) {
1215 Float_t jets[4][10];
1217 // Use Pythia clustering on parton level to determine jet axis
1219 GetJets(njets, ntrig, jets);
1221 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1226 if (pdg[0] == kGamma) {
1230 //Check eta range first...
1231 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1232 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1234 //Eta is okay, now check phi range
1235 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1236 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1247 Bool_t AliGenPythia::CheckKinematicsOnChild(){
1249 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1251 Bool_t checking = kFALSE;
1252 Int_t j, kcode, ks, km;
1253 Int_t nPartAcc = 0; //number of particles in the acceptance range
1254 Int_t numberOfAcceptedParticles = 1;
1255 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1256 Int_t npart = fParticles->GetEntriesFast();
1258 for (j = 0; j<npart; j++) {
1259 TParticle * jparticle = (TParticle *) fParticles->At(j);
1260 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1261 ks = jparticle->GetStatusCode();
1262 km = jparticle->GetFirstMother();
1264 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1267 if( numberOfAcceptedParticles <= nPartAcc){
1276 void AliGenPythia::LoadEvent(AliStack* stack, Int_t flag, Int_t reHadr)
1279 // Load event into Pythia Common Block
1282 Int_t npart = stack -> GetNprimary();
1286 (fPythia->GetPyjets())->N = npart;
1288 n0 = (fPythia->GetPyjets())->N;
1289 (fPythia->GetPyjets())->N = n0 + npart;
1293 for (Int_t part = 0; part < npart; part++) {
1294 TParticle *mPart = stack->Particle(part);
1296 Int_t kf = mPart->GetPdgCode();
1297 Int_t ks = mPart->GetStatusCode();
1298 Int_t idf = mPart->GetFirstDaughter();
1299 Int_t idl = mPart->GetLastDaughter();
1302 if (ks == 11 || ks == 12) {
1309 Float_t px = mPart->Px();
1310 Float_t py = mPart->Py();
1311 Float_t pz = mPart->Pz();
1312 Float_t e = mPart->Energy();
1313 Float_t m = mPart->GetCalcMass();
1316 (fPythia->GetPyjets())->P[0][part+n0] = px;
1317 (fPythia->GetPyjets())->P[1][part+n0] = py;
1318 (fPythia->GetPyjets())->P[2][part+n0] = pz;
1319 (fPythia->GetPyjets())->P[3][part+n0] = e;
1320 (fPythia->GetPyjets())->P[4][part+n0] = m;
1322 (fPythia->GetPyjets())->K[1][part+n0] = kf;
1323 (fPythia->GetPyjets())->K[0][part+n0] = ks;
1324 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
1325 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
1326 (fPythia->GetPyjets())->K[2][part+n0] = mPart->GetFirstMother() + 1;
1331 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1334 // Calls the Pythia jet finding algorithm to find jets in the current event
1339 Int_t n = fPythia->GetN();
1343 fPythia->Pycell(njets);
1345 for (i = 0; i < njets; i++) {
1346 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1347 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1348 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1349 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1360 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1363 // Calls the Pythia clustering algorithm to find jets in the current event
1365 Int_t n = fPythia->GetN();
1368 if (fJetReconstruction == kCluster) {
1370 // Configure cluster algorithm
1372 fPythia->SetPARU(43, 2.);
1373 fPythia->SetMSTU(41, 1);
1375 // Call cluster algorithm
1377 fPythia->Pyclus(nJets);
1379 // Loading jets from common block
1385 fPythia->Pycell(nJets);
1389 for (i = 0; i < nJets; i++) {
1390 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1391 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1392 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1393 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1394 Float_t pt = TMath::Sqrt(px * px + py * py);
1395 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1396 Float_t theta = TMath::ATan2(pt,pz);
1397 Float_t et = e * TMath::Sin(theta);
1398 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1400 eta > fEtaMinJet && eta < fEtaMaxJet &&
1401 phi > fPhiMinJet && phi < fPhiMaxJet &&
1402 et > fEtMinJet && et < fEtMaxJet
1405 jets[0][nJetsTrig] = px;
1406 jets[1][nJetsTrig] = py;
1407 jets[2][nJetsTrig] = pz;
1408 jets[3][nJetsTrig] = e;
1410 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1412 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1417 void AliGenPythia::GetSubEventTime()
1419 // Calculates time of the next subevent
1422 TArrayF &array = *fEventsTime;
1423 fEventTime = array[fCurSubEvent++];
1425 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1429 Bool_t AliGenPythia::IsInEMCAL(Float_t phi, Float_t eta)
1431 // Is particle in EMCAL acceptance?
1432 // phi in degrees, etamin=-etamax
1433 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1440 Bool_t AliGenPythia::IsInPHOS(Float_t phi, Float_t eta)
1442 // Is particle in PHOS acceptance?
1443 // Acceptance slightly larger considered.
1444 // phi in degrees, etamin=-etamax
1445 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1452 void AliGenPythia::RotatePhi(Int_t iphcand, Bool_t& okdd)
1454 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1455 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1456 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1457 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1459 //calculate deltaphi
1460 TParticle* ph = (TParticle *) fParticles->At(iphcand);
1461 Double_t phphi = ph->Phi();
1462 Double_t deltaphi = phiPHOS - phphi;
1466 //loop for all particles and produce the phi rotation
1467 Int_t np = (fHadronisation) ? fParticles->GetEntriesFast() : fNpartons;
1468 Double_t oldphi, newphi;
1469 Double_t newVx, newVy, R, Vz, time;
1470 Double_t newPx, newPy, pt, Pz, e;
1471 for(Int_t i=0; i< np; i++) {
1472 TParticle* iparticle = (TParticle *) fParticles->At(i);
1473 oldphi = iparticle->Phi();
1474 newphi = oldphi + deltaphi;
1475 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1476 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1479 newVx = R*TMath::Cos(newphi);
1480 newVy = R*TMath::Sin(newphi);
1481 Vz = iparticle->Vz(); // don't transform
1482 time = iparticle->T(); // don't transform
1484 pt = iparticle->Pt();
1485 newPx = pt*TMath::Cos(newphi);
1486 newPy = pt*TMath::Sin(newphi);
1487 Pz = iparticle->Pz(); // don't transform
1488 e = iparticle->Energy(); // don't transform
1491 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1492 iparticle->SetMomentum(newPx, newPy, Pz, e);
1494 } //end particle loop
1496 // now let's check that we put correctly the candidate photon in PHOS
1497 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1498 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1499 if(IsInPHOS(phi,eta))
1505 void AliGenPythia::Streamer(TBuffer &R__b)
1507 // Stream an object of class AliGenPythia.
1509 if (R__b.IsReading()) {
1510 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1511 AliGenerator::Streamer(R__b);
1512 R__b >> (Int_t&)fProcess;
1513 R__b >> (Int_t&)fStrucFunc;
1514 R__b >> (Int_t&)fForceDecay;
1518 fParentSelect.Streamer(R__b);
1519 fChildSelect.Streamer(R__b);
1521 // (AliPythia::Instance())->Streamer(R__b);
1524 // if (fDecayer) fDecayer->Streamer(R__b);
1526 R__b.WriteVersion(AliGenPythia::IsA());
1527 AliGenerator::Streamer(R__b);
1528 R__b << (Int_t)fProcess;
1529 R__b << (Int_t)fStrucFunc;
1530 R__b << (Int_t)fForceDecay;
1534 fParentSelect.Streamer(R__b);
1535 fChildSelect.Streamer(R__b);
1540 // fDecayer->Streamer(R__b);