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 fCountMode(kCountAll),
115 fFragPhotonInCalo(kFALSE),
117 fPhotonInCalo(kFALSE),
120 fCheckPHOSeta(kFALSE),
121 fFragPhotonOrPi0MinPt(0),
131 // Default Constructor
133 if (!AliPythiaRndm::GetPythiaRandom())
134 AliPythiaRndm::SetPythiaRandom(GetRandom());
137 AliGenPythia::AliGenPythia(Int_t npart)
149 fInteractionRate(0.),
163 fHadronisation(kTRUE),
165 fReadFromFile(kFALSE),
169 fDecayer(new AliDecayerPythia()),
170 fDebugEventFirst(-1),
177 fPhiMaxJet(2.* TMath::Pi()),
178 fJetReconstruction(kCell),
182 fPhiMaxGamma(2. * TMath::Pi()),
186 fPycellThreshold(0.),
188 fPycellMinEtJet(10.),
189 fPycellMaxRadius(1.),
190 fStackFillOpt(kFlavorSelection),
192 fFragmentation(kTRUE),
198 fCountMode(kCountAll),
202 fFragPhotonInCalo(kFALSE),
204 fPhotonInCalo(kFALSE),
207 fCheckPHOSeta(kFALSE),
208 fFragPhotonOrPi0MinPt(0),
217 // default charm production at 5. 5 TeV
219 // structure function GRVHO
222 fTitle= "Particle Generator using PYTHIA";
224 // Set random number generator
225 if (!AliPythiaRndm::GetPythiaRandom())
226 AliPythiaRndm::SetPythiaRandom(GetRandom());
227 fParticles = new TClonesArray("TParticle",1000);
231 AliGenPythia::~AliGenPythia()
234 if(fEventsTime) delete fEventsTime;
237 void AliGenPythia::SetInteractionRate(Float_t rate,Float_t timewindow)
239 // Generate pileup using user specified rate
240 fInteractionRate = rate;
241 fTimeWindow = timewindow;
245 void AliGenPythia::GeneratePileup()
247 // Generate sub events time for pileup
249 if(fInteractionRate == 0.) {
250 Warning("GeneratePileup","Zero interaction specified. Skipping pileup generation.\n");
254 Int_t npart = NumberParticles();
256 Warning("GeneratePileup","Negative number of particles. Skipping pileup generation.\n");
260 if(fEventsTime) delete fEventsTime;
261 fEventsTime = new TArrayF(npart);
262 TArrayF &array = *fEventsTime;
263 for(Int_t ipart = 0; ipart < npart; ipart++)
266 Float_t eventtime = 0.;
269 eventtime += (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
270 if(eventtime > fTimeWindow) break;
271 array.Set(array.GetSize()+1);
272 array[array.GetSize()-1] = eventtime;
278 eventtime -= (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
279 if(TMath::Abs(eventtime) > fTimeWindow) break;
280 array.Set(array.GetSize()+1);
281 array[array.GetSize()-1] = eventtime;
284 SetNumberParticles(fEventsTime->GetSize());
287 void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
288 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
290 // Set pycell parameters
291 fPycellEtaMax = etamax;
294 fPycellThreshold = thresh;
295 fPycellEtSeed = etseed;
296 fPycellMinEtJet = minet;
297 fPycellMaxRadius = r;
302 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
304 // Set a range of event numbers, for which a table
305 // of generated particle will be printed
306 fDebugEventFirst = eventFirst;
307 fDebugEventLast = eventLast;
308 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
311 void AliGenPythia::Init()
315 SetMC(AliPythia::Instance());
316 fPythia=(AliPythia*) fMCEvGen;
319 fParentWeight=1./Float_t(fNpart);
323 fPythia->SetCKIN(3,fPtHardMin);
324 fPythia->SetCKIN(4,fPtHardMax);
325 fPythia->SetCKIN(7,fYHardMin);
326 fPythia->SetCKIN(8,fYHardMax);
328 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget);
330 if (fFragmentation) {
331 fPythia->SetMSTP(111,1);
333 fPythia->SetMSTP(111,0);
337 // initial state radiation
338 fPythia->SetMSTP(61,fGinit);
339 // final state radiation
340 fPythia->SetMSTP(71,fGfinal);
343 fPythia->SetMSTP(91,1);
344 fPythia->SetPARP(91,fPtKick);
345 fPythia->SetPARP(93, 4. * fPtKick);
347 fPythia->SetMSTP(91,0);
352 fRL = AliRunLoader::Open(fFileName, "Partons");
353 fRL->LoadKinematics();
359 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
360 // Forward Paramters to the AliPythia object
361 fDecayer->SetForceDecay(fForceDecay);
362 // Switch off Heavy Flavors on request
364 // Maximum number of quark flavours used in pdf
365 fPythia->SetMSTP(58, 3);
366 // Maximum number of flavors that can be used in showers
367 fPythia->SetMSTJ(45, 3);
368 // Switch off g->QQbar splitting in decay table
369 ((AliDecayerPythia*) fDecayer)->HeavyFlavourOff();
375 // Parent and Children Selection
378 case kPyOldUEQ2ordered:
379 case kPyOldUEQ2ordered2:
383 case kPyCharmUnforced:
384 case kPyCharmPbPbMNR:
387 case kPyCharmppMNRwmi:
388 fParentSelect[0] = 411;
389 fParentSelect[1] = 421;
390 fParentSelect[2] = 431;
391 fParentSelect[3] = 4122;
397 fParentSelect[0] = 421;
400 case kPyDPlusPbPbMNR:
403 fParentSelect[0] = 411;
406 case kPyDPlusStrangePbPbMNR:
407 case kPyDPlusStrangepPbMNR:
408 case kPyDPlusStrangeppMNR:
409 fParentSelect[0] = 431;
413 case kPyBeautyPbPbMNR:
414 case kPyBeautypPbMNR:
416 case kPyBeautyppMNRwmi:
417 fParentSelect[0]= 511;
418 fParentSelect[1]= 521;
419 fParentSelect[2]= 531;
420 fParentSelect[3]= 5122;
421 fParentSelect[4]= 5132;
422 fParentSelect[5]= 5232;
423 fParentSelect[6]= 5332;
426 case kPyBeautyUnforced:
427 fParentSelect[0] = 511;
428 fParentSelect[1] = 521;
429 fParentSelect[2] = 531;
430 fParentSelect[3] = 5122;
431 fParentSelect[4] = 5132;
432 fParentSelect[5] = 5232;
433 fParentSelect[6] = 5332;
438 fParentSelect[0] = 443;
454 // JetFinder for Trigger
456 // Configure detector (EMCAL like)
458 fPythia->SetPARU(51, fPycellEtaMax);
459 fPythia->SetMSTU(51, fPycellNEta);
460 fPythia->SetMSTU(52, fPycellNPhi);
462 // Configure Jet Finder
464 fPythia->SetPARU(58, fPycellThreshold);
465 fPythia->SetPARU(52, fPycellEtSeed);
466 fPythia->SetPARU(53, fPycellMinEtJet);
467 fPythia->SetPARU(54, fPycellMaxRadius);
468 fPythia->SetMSTU(54, 2);
470 // This counts the total number of calls to Pyevnt() per run.
485 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
489 fPythia->InitQuenching(0., 0.1, 0.6e6, 0);
491 fPythia->SetPARJ(200, 0.0);
494 // Nestor's change of the splittings
495 fPythia->SetPARJ(200, 0.8);
496 fPythia->SetMSTJ(41, 1); // QCD radiation only
497 fPythia->SetMSTJ(42, 2); // angular ordering
498 fPythia->SetMSTJ(44, 2); // option to run alpha_s
499 fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
500 fPythia->SetMSTJ(50, 0); // No coherence in first branching
501 fPythia->SetPARJ(82, 1.); // Cut off for parton showers
505 void AliGenPythia::Generate()
507 // Generate one event
509 fDecayer->ForceDecay();
511 Float_t polar[3] = {0,0,0};
512 Float_t origin[3] = {0,0,0};
514 // converts from mm/c to s
515 const Float_t kconv=0.001/2.999792458e8;
525 // Set collision vertex position
526 if (fVertexSmear == kPerEvent) Vertex();
535 // Switch hadronisation off
537 fPythia->SetMSTJ(1, 0);
539 // Either produce new event or read partons from file
541 if (!fReadFromFile) {
547 fNpartons = fPythia->GetN();
549 printf("Loading Event %d\n",AliRunLoader::GetRunLoader()->GetEventNumber());
550 fRL->GetEvent(AliRunLoader::GetRunLoader()->GetEventNumber());
552 LoadEvent(fRL->Stack(), 0 , 1);
557 // Run quenching routine
561 } else if (fQuench == 2){
562 fPythia->Pyquen(208., 0, 0.);
563 } else if (fQuench == 3) {
564 // Quenching is via multiplicative correction of the splittings
568 // Switch hadronisation on
570 fPythia->SetMSTJ(1, 1);
572 // .. and perform hadronisation
573 // printf("Calling hadronisation %d\n", fPythia->GetN());
576 fPythia->ImportParticles(fParticles,"All");
584 Int_t np = fParticles->GetEntriesFast();
586 if (np == 0) continue;
590 Int_t* pParent = new Int_t[np];
591 Int_t* pSelected = new Int_t[np];
592 Int_t* trackIt = new Int_t[np];
593 for (i = 0; i < np; i++) {
599 Int_t nc = 0; // Total n. of selected particles
600 Int_t nParents = 0; // Selected parents
601 Int_t nTkbles = 0; // Trackable particles
602 if (fProcess != kPyMbDefault &&
604 fProcess != kPyJets &&
605 fProcess != kPyDirectGamma &&
606 fProcess != kPyMbNonDiffr &&
607 fProcess != kPyMbMSEL1 &&
610 fProcess != kPyCharmppMNRwmi &&
611 fProcess != kPyBeautyppMNRwmi) {
613 for (i = 0; i < np; i++) {
614 TParticle* iparticle = (TParticle *) fParticles->At(i);
615 Int_t ks = iparticle->GetStatusCode();
616 kf = CheckPDGCode(iparticle->GetPdgCode());
617 // No initial state partons
618 if (ks==21) continue;
620 // Heavy Flavor Selection
627 if (kfl > 100000) kfl %= 100000;
628 if (kfl > 10000) kfl %= 10000;
630 if (kfl > 10) kfl/=100;
632 if (kfl > 10) kfl/=10;
633 Int_t ipa = iparticle->GetFirstMother()-1;
636 // Establish mother daughter relation between heavy quarks and mesons
638 if (kf >= fFlavorSelect && kf <= 6) {
639 Int_t idau = iparticle->GetFirstDaughter() - 1;
641 TParticle* daughter = (TParticle *) fParticles->At(idau);
642 Int_t pdgD = daughter->GetPdgCode();
643 if (pdgD == 91 || pdgD == 92) {
644 Int_t jmin = daughter->GetFirstDaughter() - 1;
645 Int_t jmax = daughter->GetLastDaughter() - 1;
646 for (Int_t j = jmin; j <= jmax; j++)
647 ((TParticle *) fParticles->At(j))->SetFirstMother(i+1);
648 } // is string or cluster
654 TParticle * mother = (TParticle *) fParticles->At(ipa);
655 kfMo = TMath::Abs(mother->GetPdgCode());
658 // What to keep in Stack?
659 Bool_t flavorOK = kFALSE;
660 Bool_t selectOK = kFALSE;
662 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
664 if (kfl > fFlavorSelect) {
668 if (kfl == fFlavorSelect) flavorOK = kTRUE;
670 switch (fStackFillOpt) {
671 case kFlavorSelection:
674 case kParentSelection:
675 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
678 if (flavorOK && selectOK) {
680 // Heavy flavor hadron or quark
682 // Kinematic seletion on final state heavy flavor mesons
683 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
688 if (ParentSelected(kf)) ++nParents; // Update parent count
689 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
691 // Kinematic seletion on decay products
692 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
693 && !KinematicSelection(iparticle, 1))
699 // Select if mother was selected and is not tracked
701 if (pSelected[ipa] &&
702 !trackIt[ipa] && // mother will be tracked ?
703 kfMo != 5 && // mother is b-quark, don't store fragments
704 kfMo != 4 && // mother is c-quark, don't store fragments
705 kf != 92) // don't store string
708 // Semi-stable or de-selected: diselect decay products:
711 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
713 Int_t ipF = iparticle->GetFirstDaughter();
714 Int_t ipL = iparticle->GetLastDaughter();
715 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
717 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
718 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
721 if (pSelected[i] == -1) pSelected[i] = 0;
722 if (!pSelected[i]) continue;
723 // Count quarks only if you did not include fragmentation
724 if (fFragmentation && kf <= 10) continue;
727 // Decision on tracking
730 // Track final state particle
731 if (ks == 1) trackIt[i] = 1;
732 // Track semi-stable particles
733 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
734 // Track particles selected by process if undecayed.
735 if (fForceDecay == kNoDecay) {
736 if (ParentSelected(kf)) trackIt[i] = 1;
738 if (ParentSelected(kf)) trackIt[i] = 0;
740 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
744 } // particle selection loop
746 for (i = 0; i<np; i++) {
747 if (!pSelected[i]) continue;
748 TParticle * iparticle = (TParticle *) fParticles->At(i);
749 kf = CheckPDGCode(iparticle->GetPdgCode());
750 Int_t ks = iparticle->GetStatusCode();
751 p[0] = iparticle->Px();
752 p[1] = iparticle->Py();
753 p[2] = iparticle->Pz();
754 p[3] = iparticle->Energy();
756 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
757 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
758 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
760 Float_t tof = kconv*iparticle->T();
761 Int_t ipa = iparticle->GetFirstMother()-1;
762 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
764 PushTrack(fTrackIt*trackIt[i], iparent, kf,
765 p[0], p[1], p[2], p[3],
766 origin[0], origin[1], origin[2], tof,
767 polar[0], polar[1], polar[2],
768 kPPrimary, nt, 1., ks);
785 switch (fCountMode) {
787 // printf(" Count all \n");
791 // printf(" Count parents \n");
794 case kCountTrackables:
795 // printf(" Count trackable \n");
799 if (jev >= fNpart || fNpart == -1) {
800 fKineBias=Float_t(fNpart)/Float_t(fTrials);
802 fQ += fPythia->GetVINT(51);
803 fX1 += fPythia->GetVINT(41);
804 fX2 += fPythia->GetVINT(42);
805 fTrialsRun += fTrials;
812 SetHighWaterMark(nt);
813 // adjust weight due to kinematic selection
816 fXsection=fPythia->GetPARI(1);
819 Int_t AliGenPythia::GenerateMB()
822 // Min Bias selection and other global selections
824 Int_t i, kf, nt, iparent;
827 Float_t polar[3] = {0,0,0};
828 Float_t origin[3] = {0,0,0};
829 // converts from mm/c to s
830 const Float_t kconv=0.001/2.999792458e8;
834 Int_t np = (fHadronisation) ? fParticles->GetEntriesFast() : fNpartons;
838 Int_t* pParent = new Int_t[np];
839 for (i=0; i< np; i++) pParent[i] = -1;
840 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
841 TParticle* jet1 = (TParticle *) fParticles->At(6);
842 TParticle* jet2 = (TParticle *) fParticles->At(7);
843 if (!CheckTrigger(jet1, jet2)) {
849 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
850 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
855 if (fFragPhotonInCalo) pdg = 22 ; // Photon
856 else if (fPi0InCalo) pdg = 111 ; // Pi0
858 for (i=0; i< np; i++) {
859 TParticle* iparticle = (TParticle *) fParticles->At(i);
860 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
861 iparticle->Pt() > fFragPhotonOrPi0MinPt){
862 Int_t imother = iparticle->GetFirstMother() - 1;
863 TParticle* pmother = (TParticle *) fParticles->At(imother);
865 (pdg == 22 && pmother->GetStatusCode() != 11))//No photon from hadron decay
867 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
868 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
869 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
870 (fCheckPHOS && IsInPHOS(phi,eta)) )
880 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
881 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
887 for (i=0; i< np; i++) {
888 TParticle* iparticle = (TParticle *) fParticles->At(i);
889 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
890 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
892 if(iparticle->GetStatusCode() == 1
893 && iparticle->GetPdgCode() == pdg
894 && iparticle->Pt() > fPhotonMinPt
897 // first check if the photon is in PHOS phi
898 if(IsInPHOS(phi,eta)){
902 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
907 if(!okd && iphcand != -1) // execute rotation in phi
908 RotatePhi(iphcand,okd);
914 if (fTriggerParticle) {
915 Bool_t triggered = kFALSE;
916 for (i = 0; i < np; i++) {
917 TParticle * iparticle = (TParticle *) fParticles->At(i);
918 kf = CheckPDGCode(iparticle->GetPdgCode());
919 if (kf != fTriggerParticle) continue;
920 if (iparticle->Pt() == 0.) continue;
921 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
932 // Check if there is a ccbar or bbbar pair with at least one of the two
933 // in fYMin < y < fYMax
934 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi) {
936 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
939 for(i=0; i<np; i++) {
940 hvq = (TParticle*)fParticles->At(i);
941 pdgQ = hvq->GetPdgCode();
942 if(TMath::Abs(pdgQ) != fFlavorSelect) continue;
943 if(pdgQ>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
944 yQ = 0.5*TMath::Log((hvq->Energy()+hvq->Pz()+1.e-13)/
945 (hvq->Energy()-hvq->Pz()+1.e-13));
946 if(yQ>fYMin && yQ<fYMax) inYcut=kTRUE;
948 if (!theQ || !theQbar || !inYcut) {
954 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
955 if ( (fProcess == kPyW ||
957 fProcess == kPyMbDefault ||
959 fProcess == kPyMbNonDiffr)
960 && (fCutOnChild == 1) ) {
961 if ( !CheckKinematicsOnChild() ) {
968 for (i = 0; i < np; i++) {
970 TParticle * iparticle = (TParticle *) fParticles->At(i);
971 kf = CheckPDGCode(iparticle->GetPdgCode());
972 Int_t ks = iparticle->GetStatusCode();
973 Int_t km = iparticle->GetFirstMother();
974 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
976 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
978 if (ks == 1) trackIt = 1;
979 Int_t ipa = iparticle->GetFirstMother()-1;
981 iparent = (ipa > -1) ? pParent[ipa] : -1;
984 // store track information
985 p[0] = iparticle->Px();
986 p[1] = iparticle->Py();
987 p[2] = iparticle->Pz();
988 p[3] = iparticle->Energy();
991 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
992 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
993 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
995 Float_t tof = fEventTime + kconv * iparticle->T();
997 PushTrack(fTrackIt*trackIt, iparent, kf,
998 p[0], p[1], p[2], p[3],
999 origin[0], origin[1], origin[2], tof,
1000 polar[0], polar[1], polar[2],
1001 kPPrimary, nt, 1., ks);
1004 // Special Treatment to store color-flow
1006 if (ks == 3 || ks == 13 || ks == 14) {
1007 TParticle* particle = 0;
1009 particle = fStack->Particle(nt);
1011 particle = gAlice->Stack()->Particle(nt);
1013 particle->SetFirstDaughter(fPythia->GetK(2, i));
1014 particle->SetLastDaughter(fPythia->GetK(3, i));
1019 SetHighWaterMark(nt);
1021 } // select particle
1030 void AliGenPythia::FinishRun()
1032 // Print x-section summary
1041 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1042 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1045 void AliGenPythia::AdjustWeights() const
1047 // Adjust the weights after generation of all events
1051 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1052 for (Int_t i=0; i<ntrack; i++) {
1053 part= gAlice->GetMCApp()->Particle(i);
1054 part->SetWeight(part->GetWeight()*fKineBias);
1059 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
1061 // Treat protons as inside nuclei with mass numbers a1 and a2
1069 void AliGenPythia::MakeHeader()
1072 // Make header for the simulated event
1075 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1076 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(2);
1079 // Builds the event header, to be called after each event
1080 if (fHeader) delete fHeader;
1081 fHeader = new AliGenPythiaEventHeader("Pythia");
1084 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
1087 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1090 fHeader->SetPrimaryVertex(fVertex);
1093 // Number of primaries
1094 fHeader->SetNProduced(fNprimaries);
1096 // Jets that have triggered
1098 if (fProcess == kPyJets)
1101 Float_t jets[4][10];
1102 GetJets(njet, ntrig, jets);
1105 for (Int_t i = 0; i < ntrig; i++) {
1106 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1111 // Copy relevant information from external header, if present.
1116 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1117 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1119 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1122 exHeader->TriggerJet(i, uqJet);
1123 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1127 // Store quenching parameters
1134 fPythia->GetQuenchingParameters(xp, yp, z);
1137 Double_t r1 = PARIMP.rb1;
1138 Double_t r2 = PARIMP.rb2;
1139 Double_t b = PARIMP.b1;
1140 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1141 Double_t phi = PARIMP.psib1;
1142 xp = r * TMath::Cos(phi);
1143 yp = r * TMath::Sin(phi);
1146 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1147 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1151 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetVINT(47));
1159 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
1161 // Check the kinematic trigger condition
1164 eta[0] = jet1->Eta();
1165 eta[1] = jet2->Eta();
1167 phi[0] = jet1->Phi();
1168 phi[1] = jet2->Phi();
1170 pdg[0] = jet1->GetPdgCode();
1171 pdg[1] = jet2->GetPdgCode();
1172 Bool_t triggered = kFALSE;
1174 if (fProcess == kPyJets) {
1177 Float_t jets[4][10];
1179 // Use Pythia clustering on parton level to determine jet axis
1181 GetJets(njets, ntrig, jets);
1183 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1188 if (pdg[0] == kGamma) {
1192 //Check eta range first...
1193 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1194 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1196 //Eta is okay, now check phi range
1197 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1198 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1209 Bool_t AliGenPythia::CheckKinematicsOnChild(){
1211 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1213 Bool_t checking = kFALSE;
1214 Int_t j, kcode, ks, km;
1215 Int_t nPartAcc = 0; //number of particles in the acceptance range
1216 Int_t numberOfAcceptedParticles = 1;
1217 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1218 Int_t npart = fParticles->GetEntriesFast();
1220 for (j = 0; j<npart; j++) {
1221 TParticle * jparticle = (TParticle *) fParticles->At(j);
1222 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1223 ks = jparticle->GetStatusCode();
1224 km = jparticle->GetFirstMother();
1226 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1229 if( numberOfAcceptedParticles <= nPartAcc){
1238 void AliGenPythia::LoadEvent(AliStack* stack, Int_t flag, Int_t reHadr)
1241 // Load event into Pythia Common Block
1244 Int_t npart = stack -> GetNprimary();
1248 (fPythia->GetPyjets())->N = npart;
1250 n0 = (fPythia->GetPyjets())->N;
1251 (fPythia->GetPyjets())->N = n0 + npart;
1255 for (Int_t part = 0; part < npart; part++) {
1256 TParticle *mPart = stack->Particle(part);
1258 Int_t kf = mPart->GetPdgCode();
1259 Int_t ks = mPart->GetStatusCode();
1260 Int_t idf = mPart->GetFirstDaughter();
1261 Int_t idl = mPart->GetLastDaughter();
1264 if (ks == 11 || ks == 12) {
1271 Float_t px = mPart->Px();
1272 Float_t py = mPart->Py();
1273 Float_t pz = mPart->Pz();
1274 Float_t e = mPart->Energy();
1275 Float_t m = mPart->GetCalcMass();
1278 (fPythia->GetPyjets())->P[0][part+n0] = px;
1279 (fPythia->GetPyjets())->P[1][part+n0] = py;
1280 (fPythia->GetPyjets())->P[2][part+n0] = pz;
1281 (fPythia->GetPyjets())->P[3][part+n0] = e;
1282 (fPythia->GetPyjets())->P[4][part+n0] = m;
1284 (fPythia->GetPyjets())->K[1][part+n0] = kf;
1285 (fPythia->GetPyjets())->K[0][part+n0] = ks;
1286 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
1287 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
1288 (fPythia->GetPyjets())->K[2][part+n0] = mPart->GetFirstMother() + 1;
1293 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1296 // Calls the Pythia jet finding algorithm to find jets in the current event
1301 Int_t n = fPythia->GetN();
1305 fPythia->Pycell(njets);
1307 for (i = 0; i < njets; i++) {
1308 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1309 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1310 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1311 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1322 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1325 // Calls the Pythia clustering algorithm to find jets in the current event
1327 Int_t n = fPythia->GetN();
1330 if (fJetReconstruction == kCluster) {
1332 // Configure cluster algorithm
1334 fPythia->SetPARU(43, 2.);
1335 fPythia->SetMSTU(41, 1);
1337 // Call cluster algorithm
1339 fPythia->Pyclus(nJets);
1341 // Loading jets from common block
1347 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];
1356 Float_t pt = TMath::Sqrt(px * px + py * py);
1357 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1358 Float_t theta = TMath::ATan2(pt,pz);
1359 Float_t et = e * TMath::Sin(theta);
1360 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1362 eta > fEtaMinJet && eta < fEtaMaxJet &&
1363 phi > fPhiMinJet && phi < fPhiMaxJet &&
1364 et > fEtMinJet && et < fEtMaxJet
1367 jets[0][nJetsTrig] = px;
1368 jets[1][nJetsTrig] = py;
1369 jets[2][nJetsTrig] = pz;
1370 jets[3][nJetsTrig] = e;
1372 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1374 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1379 void AliGenPythia::GetSubEventTime()
1381 // Calculates time of the next subevent
1384 TArrayF &array = *fEventsTime;
1385 fEventTime = array[fCurSubEvent++];
1387 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1391 Bool_t AliGenPythia::IsInEMCAL(Float_t phi, Float_t eta)
1393 // Is particle in EMCAL acceptance?
1394 // phi in degrees, etamin=-etamax
1395 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1402 Bool_t AliGenPythia::IsInPHOS(Float_t phi, Float_t eta)
1404 // Is particle in PHOS acceptance?
1405 // Acceptance slightly larger considered.
1406 // phi in degrees, etamin=-etamax
1407 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1414 void AliGenPythia::RotatePhi(Int_t iphcand, Bool_t& okdd)
1416 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1417 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1418 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1419 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1421 //calculate deltaphi
1422 TParticle* ph = (TParticle *) fParticles->At(iphcand);
1423 Double_t phphi = ph->Phi();
1424 Double_t deltaphi = phiPHOS - phphi;
1428 //loop for all particles and produce the phi rotation
1429 Int_t np = (fHadronisation) ? fParticles->GetEntriesFast() : fNpartons;
1430 Double_t oldphi, newphi;
1431 Double_t newVx, newVy, R, Vz, time;
1432 Double_t newPx, newPy, pt, Pz, e;
1433 for(Int_t i=0; i< np; i++) {
1434 TParticle* iparticle = (TParticle *) fParticles->At(i);
1435 oldphi = iparticle->Phi();
1436 newphi = oldphi + deltaphi;
1437 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1438 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1441 newVx = R*TMath::Cos(newphi);
1442 newVy = R*TMath::Sin(newphi);
1443 Vz = iparticle->Vz(); // don't transform
1444 time = iparticle->T(); // don't transform
1446 pt = iparticle->Pt();
1447 newPx = pt*TMath::Cos(newphi);
1448 newPy = pt*TMath::Sin(newphi);
1449 Pz = iparticle->Pz(); // don't transform
1450 e = iparticle->Energy(); // don't transform
1453 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1454 iparticle->SetMomentum(newPx, newPy, Pz, e);
1456 } //end particle loop
1458 // now let's check that we put correctly the candidate photon in PHOS
1459 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1460 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1461 if(IsInPHOS(phi,eta))
1467 void AliGenPythia::Streamer(TBuffer &R__b)
1469 // Stream an object of class AliGenPythia.
1471 if (R__b.IsReading()) {
1472 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1473 AliGenerator::Streamer(R__b);
1474 R__b >> (Int_t&)fProcess;
1475 R__b >> (Int_t&)fStrucFunc;
1476 R__b >> (Int_t&)fForceDecay;
1480 fParentSelect.Streamer(R__b);
1481 fChildSelect.Streamer(R__b);
1483 // (AliPythia::Instance())->Streamer(R__b);
1486 // if (fDecayer) fDecayer->Streamer(R__b);
1488 R__b.WriteVersion(AliGenPythia::IsA());
1489 AliGenerator::Streamer(R__b);
1490 R__b << (Int_t)fProcess;
1491 R__b << (Int_t)fStrucFunc;
1492 R__b << (Int_t)fForceDecay;
1496 fParentSelect.Streamer(R__b);
1497 fChildSelect.Streamer(R__b);
1502 // fDecayer->Streamer(R__b);