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),
110 fTriggerMultiplicity(0),
111 fTriggerMultiplicityEta(0),
112 fCountMode(kCountAll),
116 fFragPhotonInCalo(kFALSE),
118 fPhotonInCalo(kFALSE),
121 fCheckPHOSeta(kFALSE),
122 fFragPhotonOrPi0MinPt(0),
132 // Default Constructor
135 if (!AliPythiaRndm::GetPythiaRandom())
136 AliPythiaRndm::SetPythiaRandom(GetRandom());
139 AliGenPythia::AliGenPythia(Int_t npart)
150 fInteractionRate(0.),
164 fHadronisation(kTRUE),
166 fReadFromFile(kFALSE),
170 fDecayer(new AliDecayerPythia()),
171 fDebugEventFirst(-1),
178 fPhiMaxJet(2.* TMath::Pi()),
179 fJetReconstruction(kCell),
183 fPhiMaxGamma(2. * TMath::Pi()),
187 fPycellThreshold(0.),
189 fPycellMinEtJet(10.),
190 fPycellMaxRadius(1.),
191 fStackFillOpt(kFlavorSelection),
193 fFragmentation(kTRUE),
199 fTriggerMultiplicity(0),
200 fTriggerMultiplicityEta(0),
201 fCountMode(kCountAll),
205 fFragPhotonInCalo(kFALSE),
207 fPhotonInCalo(kFALSE),
210 fCheckPHOSeta(kFALSE),
211 fFragPhotonOrPi0MinPt(0),
220 // default charm production at 5. 5 TeV
222 // structure function GRVHO
226 fTitle= "Particle Generator using PYTHIA";
228 // Set random number generator
229 if (!AliPythiaRndm::GetPythiaRandom())
230 AliPythiaRndm::SetPythiaRandom(GetRandom());
234 AliGenPythia::~AliGenPythia()
237 if(fEventsTime) delete fEventsTime;
240 void AliGenPythia::SetInteractionRate(Float_t rate,Float_t timewindow)
242 // Generate pileup using user specified rate
243 fInteractionRate = rate;
244 fTimeWindow = timewindow;
248 void AliGenPythia::GeneratePileup()
250 // Generate sub events time for pileup
252 if(fInteractionRate == 0.) {
253 Warning("GeneratePileup","Zero interaction specified. Skipping pileup generation.\n");
257 Int_t npart = NumberParticles();
259 Warning("GeneratePileup","Negative number of particles. Skipping pileup generation.\n");
263 if(fEventsTime) delete fEventsTime;
264 fEventsTime = new TArrayF(npart);
265 TArrayF &array = *fEventsTime;
266 for(Int_t ipart = 0; ipart < npart; ipart++)
269 Float_t eventtime = 0.;
272 eventtime += (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
273 if(eventtime > fTimeWindow) break;
274 array.Set(array.GetSize()+1);
275 array[array.GetSize()-1] = eventtime;
281 eventtime -= (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
282 if(TMath::Abs(eventtime) > fTimeWindow) break;
283 array.Set(array.GetSize()+1);
284 array[array.GetSize()-1] = eventtime;
287 SetNumberParticles(fEventsTime->GetSize());
290 void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
291 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
293 // Set pycell parameters
294 fPycellEtaMax = etamax;
297 fPycellThreshold = thresh;
298 fPycellEtSeed = etseed;
299 fPycellMinEtJet = minet;
300 fPycellMaxRadius = r;
305 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
307 // Set a range of event numbers, for which a table
308 // of generated particle will be printed
309 fDebugEventFirst = eventFirst;
310 fDebugEventLast = eventLast;
311 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
314 void AliGenPythia::Init()
318 SetMC(AliPythia::Instance());
319 fPythia=(AliPythia*) fMCEvGen;
322 fParentWeight=1./Float_t(fNpart);
326 fPythia->SetCKIN(3,fPtHardMin);
327 fPythia->SetCKIN(4,fPtHardMax);
328 fPythia->SetCKIN(7,fYHardMin);
329 fPythia->SetCKIN(8,fYHardMax);
331 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget);
333 if (fFragmentation) {
334 fPythia->SetMSTP(111,1);
336 fPythia->SetMSTP(111,0);
340 // initial state radiation
341 fPythia->SetMSTP(61,fGinit);
342 // final state radiation
343 fPythia->SetMSTP(71,fGfinal);
346 fPythia->SetMSTP(91,1);
347 fPythia->SetPARP(91,fPtKick);
348 fPythia->SetPARP(93, 4. * fPtKick);
350 fPythia->SetMSTP(91,0);
355 fRL = AliRunLoader::Open(fFileName, "Partons");
356 fRL->LoadKinematics();
362 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
363 // Forward Paramters to the AliPythia object
364 fDecayer->SetForceDecay(fForceDecay);
365 // Switch off Heavy Flavors on request
367 // Maximum number of quark flavours used in pdf
368 fPythia->SetMSTP(58, 3);
369 // Maximum number of flavors that can be used in showers
370 fPythia->SetMSTJ(45, 3);
371 // Switch off g->QQbar splitting in decay table
372 ((AliDecayerPythia*) fDecayer)->HeavyFlavourOff();
378 // Parent and Children Selection
381 case kPyOldUEQ2ordered:
382 case kPyOldUEQ2ordered2:
386 case kPyCharmUnforced:
387 case kPyCharmPbPbMNR:
390 case kPyCharmppMNRwmi:
391 fParentSelect[0] = 411;
392 fParentSelect[1] = 421;
393 fParentSelect[2] = 431;
394 fParentSelect[3] = 4122;
400 fParentSelect[0] = 421;
403 case kPyDPlusPbPbMNR:
406 fParentSelect[0] = 411;
409 case kPyDPlusStrangePbPbMNR:
410 case kPyDPlusStrangepPbMNR:
411 case kPyDPlusStrangeppMNR:
412 fParentSelect[0] = 431;
416 case kPyBeautyPbPbMNR:
417 case kPyBeautypPbMNR:
419 case kPyBeautyppMNRwmi:
420 fParentSelect[0]= 511;
421 fParentSelect[1]= 521;
422 fParentSelect[2]= 531;
423 fParentSelect[3]= 5122;
424 fParentSelect[4]= 5132;
425 fParentSelect[5]= 5232;
426 fParentSelect[6]= 5332;
429 case kPyBeautyUnforced:
430 fParentSelect[0] = 511;
431 fParentSelect[1] = 521;
432 fParentSelect[2] = 531;
433 fParentSelect[3] = 5122;
434 fParentSelect[4] = 5132;
435 fParentSelect[5] = 5232;
436 fParentSelect[6] = 5332;
441 fParentSelect[0] = 443;
457 // JetFinder for Trigger
459 // Configure detector (EMCAL like)
461 fPythia->SetPARU(51, fPycellEtaMax);
462 fPythia->SetMSTU(51, fPycellNEta);
463 fPythia->SetMSTU(52, fPycellNPhi);
465 // Configure Jet Finder
467 fPythia->SetPARU(58, fPycellThreshold);
468 fPythia->SetPARU(52, fPycellEtSeed);
469 fPythia->SetPARU(53, fPycellMinEtJet);
470 fPythia->SetPARU(54, fPycellMaxRadius);
471 fPythia->SetMSTU(54, 2);
473 // This counts the total number of calls to Pyevnt() per run.
488 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
492 fPythia->InitQuenching(0., 0.1, 0.6e6, 0);
494 fPythia->SetPARJ(200, 0.0);
497 // Nestor's change of the splittings
498 fPythia->SetPARJ(200, 0.8);
499 fPythia->SetMSTJ(41, 1); // QCD radiation only
500 fPythia->SetMSTJ(42, 2); // angular ordering
501 fPythia->SetMSTJ(44, 2); // option to run alpha_s
502 fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
503 fPythia->SetMSTJ(50, 0); // No coherence in first branching
504 fPythia->SetPARJ(82, 1.); // Cut off for parton showers
508 void AliGenPythia::Generate()
510 // Generate one event
512 fDecayer->ForceDecay();
514 Float_t polar[3] = {0,0,0};
515 Float_t origin[3] = {0,0,0};
517 // converts from mm/c to s
518 const Float_t kconv=0.001/2.999792458e8;
528 // Set collision vertex position
529 if (fVertexSmear == kPerEvent) Vertex();
538 // Switch hadronisation off
540 fPythia->SetMSTJ(1, 0);
542 // Either produce new event or read partons from file
544 if (!fReadFromFile) {
550 fNpartons = fPythia->GetN();
552 printf("Loading Event %d\n",AliRunLoader::GetRunLoader()->GetEventNumber());
553 fRL->GetEvent(AliRunLoader::GetRunLoader()->GetEventNumber());
555 LoadEvent(fRL->Stack(), 0 , 1);
560 // Run quenching routine
564 } else if (fQuench == 2){
565 fPythia->Pyquen(208., 0, 0.);
566 } else if (fQuench == 3) {
567 // Quenching is via multiplicative correction of the splittings
571 // Switch hadronisation on
573 fPythia->SetMSTJ(1, 1);
575 // .. and perform hadronisation
576 // printf("Calling hadronisation %d\n", fPythia->GetN());
579 fPythia->ImportParticles(&fParticles,"All");
587 Int_t np = fParticles.GetEntriesFast();
589 if (np == 0) continue;
593 Int_t* pParent = new Int_t[np];
594 Int_t* pSelected = new Int_t[np];
595 Int_t* trackIt = new Int_t[np];
596 for (i = 0; i < np; i++) {
602 Int_t nc = 0; // Total n. of selected particles
603 Int_t nParents = 0; // Selected parents
604 Int_t nTkbles = 0; // Trackable particles
605 if (fProcess != kPyMbDefault &&
607 fProcess != kPyJets &&
608 fProcess != kPyDirectGamma &&
609 fProcess != kPyMbNonDiffr &&
610 fProcess != kPyMbMSEL1 &&
613 fProcess != kPyCharmppMNRwmi &&
614 fProcess != kPyBeautyppMNRwmi) {
616 for (i = 0; i < np; i++) {
617 TParticle* iparticle = (TParticle *) fParticles.At(i);
618 Int_t ks = iparticle->GetStatusCode();
619 kf = CheckPDGCode(iparticle->GetPdgCode());
620 // No initial state partons
621 if (ks==21) continue;
623 // Heavy Flavor Selection
630 if (kfl > 100000) kfl %= 100000;
631 if (kfl > 10000) kfl %= 10000;
633 if (kfl > 10) kfl/=100;
635 if (kfl > 10) kfl/=10;
636 Int_t ipa = iparticle->GetFirstMother()-1;
639 // Establish mother daughter relation between heavy quarks and mesons
641 if (kf >= fFlavorSelect && kf <= 6) {
642 Int_t idau = iparticle->GetFirstDaughter() - 1;
644 TParticle* daughter = (TParticle *) fParticles.At(idau);
645 Int_t pdgD = daughter->GetPdgCode();
646 if (pdgD == 91 || pdgD == 92) {
647 Int_t jmin = daughter->GetFirstDaughter() - 1;
648 Int_t jmax = daughter->GetLastDaughter() - 1;
649 for (Int_t jp = jmin; jp <= jmax; jp++)
650 ((TParticle *) fParticles.At(jp))->SetFirstMother(i+1);
651 } // is string or cluster
657 TParticle * mother = (TParticle *) fParticles.At(ipa);
658 kfMo = TMath::Abs(mother->GetPdgCode());
661 // What to keep in Stack?
662 Bool_t flavorOK = kFALSE;
663 Bool_t selectOK = kFALSE;
665 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
667 if (kfl > fFlavorSelect) {
671 if (kfl == fFlavorSelect) flavorOK = kTRUE;
673 switch (fStackFillOpt) {
674 case kFlavorSelection:
677 case kParentSelection:
678 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
681 if (flavorOK && selectOK) {
683 // Heavy flavor hadron or quark
685 // Kinematic seletion on final state heavy flavor mesons
686 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
691 if (ParentSelected(kf)) ++nParents; // Update parent count
692 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
694 // Kinematic seletion on decay products
695 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
696 && !KinematicSelection(iparticle, 1))
702 // Select if mother was selected and is not tracked
704 if (pSelected[ipa] &&
705 !trackIt[ipa] && // mother will be tracked ?
706 kfMo != 5 && // mother is b-quark, don't store fragments
707 kfMo != 4 && // mother is c-quark, don't store fragments
708 kf != 92) // don't store string
711 // Semi-stable or de-selected: diselect decay products:
714 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
716 Int_t ipF = iparticle->GetFirstDaughter();
717 Int_t ipL = iparticle->GetLastDaughter();
718 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
720 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
721 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
724 if (pSelected[i] == -1) pSelected[i] = 0;
725 if (!pSelected[i]) continue;
726 // Count quarks only if you did not include fragmentation
727 if (fFragmentation && kf <= 10) continue;
730 // Decision on tracking
733 // Track final state particle
734 if (ks == 1) trackIt[i] = 1;
735 // Track semi-stable particles
736 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
737 // Track particles selected by process if undecayed.
738 if (fForceDecay == kNoDecay) {
739 if (ParentSelected(kf)) trackIt[i] = 1;
741 if (ParentSelected(kf)) trackIt[i] = 0;
743 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
747 } // particle selection loop
749 for (i = 0; i<np; i++) {
750 if (!pSelected[i]) continue;
751 TParticle * iparticle = (TParticle *) fParticles.At(i);
752 kf = CheckPDGCode(iparticle->GetPdgCode());
753 Int_t ks = iparticle->GetStatusCode();
754 p[0] = iparticle->Px();
755 p[1] = iparticle->Py();
756 p[2] = iparticle->Pz();
757 p[3] = iparticle->Energy();
759 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
760 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
761 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
763 Float_t tof = kconv*iparticle->T();
764 Int_t ipa = iparticle->GetFirstMother()-1;
765 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
767 PushTrack(fTrackIt*trackIt[i], iparent, kf,
768 p[0], p[1], p[2], p[3],
769 origin[0], origin[1], origin[2], tof,
770 polar[0], polar[1], polar[2],
771 kPPrimary, nt, 1., ks);
788 switch (fCountMode) {
790 // printf(" Count all \n");
794 // printf(" Count parents \n");
797 case kCountTrackables:
798 // printf(" Count trackable \n");
802 if (jev >= fNpart || fNpart == -1) {
803 fKineBias=Float_t(fNpart)/Float_t(fTrials);
805 fQ += fPythia->GetVINT(51);
806 fX1 += fPythia->GetVINT(41);
807 fX2 += fPythia->GetVINT(42);
808 fTrialsRun += fTrials;
815 SetHighWaterMark(nt);
816 // adjust weight due to kinematic selection
819 fXsection=fPythia->GetPARI(1);
822 Int_t AliGenPythia::GenerateMB()
825 // Min Bias selection and other global selections
827 Int_t i, kf, nt, iparent;
830 Float_t polar[3] = {0,0,0};
831 Float_t origin[3] = {0,0,0};
832 // converts from mm/c to s
833 const Float_t kconv=0.001/2.999792458e8;
837 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
841 Int_t* pParent = new Int_t[np];
842 for (i=0; i< np; i++) pParent[i] = -1;
843 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
844 TParticle* jet1 = (TParticle *) fParticles.At(6);
845 TParticle* jet2 = (TParticle *) fParticles.At(7);
846 if (!CheckTrigger(jet1, jet2)) {
852 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
853 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
858 if (fFragPhotonInCalo) pdg = 22 ; // Photon
859 else if (fPi0InCalo) pdg = 111 ; // Pi0
861 for (i=0; i< np; i++) {
862 TParticle* iparticle = (TParticle *) fParticles.At(i);
863 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
864 iparticle->Pt() > fFragPhotonOrPi0MinPt){
865 Int_t imother = iparticle->GetFirstMother() - 1;
866 TParticle* pmother = (TParticle *) fParticles.At(imother);
868 (pdg == 22 && pmother->GetStatusCode() != 11))//No photon from hadron decay
870 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
871 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
872 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
873 (fCheckPHOS && IsInPHOS(phi,eta)) )
882 // Check for minimum multiplicity
883 if (fTriggerMultiplicity > 0) {
884 Int_t multiplicity = 0;
885 for (i = 0; i < np; i++) {
886 TParticle * iparticle = (TParticle *) fParticles.At(i);
888 Int_t statusCode = iparticle->GetStatusCode();
890 // Initial state particle
894 // skip quarks and gluons
895 Int_t pdgCode = TMath::Abs(iparticle->GetPdgCode());
896 if (pdgCode <= 10 || pdgCode == 21)
899 if (fTriggerMultiplicityEta > 0 && TMath::Abs(iparticle->Eta()) > fTriggerMultiplicityEta)
902 TParticlePDG* pdgPart = iparticle->GetPDG();
903 if (pdgPart && pdgPart->Charge() == 0)
909 if (multiplicity < fTriggerMultiplicity) {
914 Printf("Triggered on event with multiplicity of %d > %d", multiplicity, fTriggerMultiplicity);
917 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
918 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
924 for (i=0; i< np; i++) {
925 TParticle* iparticle = (TParticle *) fParticles.At(i);
926 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
927 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
929 if(iparticle->GetStatusCode() == 1
930 && iparticle->GetPdgCode() == pdg
931 && iparticle->Pt() > fPhotonMinPt
934 // first check if the photon is in PHOS phi
935 if(IsInPHOS(phi,eta)){
939 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
944 if(!okd && iphcand != -1) // execute rotation in phi
945 RotatePhi(iphcand,okd);
951 if (fTriggerParticle) {
952 Bool_t triggered = kFALSE;
953 for (i = 0; i < np; i++) {
954 TParticle * iparticle = (TParticle *) fParticles.At(i);
955 kf = CheckPDGCode(iparticle->GetPdgCode());
956 if (kf != fTriggerParticle) continue;
957 if (iparticle->Pt() == 0.) continue;
958 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
969 // Check if there is a ccbar or bbbar pair with at least one of the two
970 // in fYMin < y < fYMax
971 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi) {
973 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
976 for(i=0; i<np; i++) {
977 hvq = (TParticle*)fParticles.At(i);
978 pdgQ = hvq->GetPdgCode();
979 if(TMath::Abs(pdgQ) != fFlavorSelect) continue;
980 if(pdgQ>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
981 yQ = 0.5*TMath::Log((hvq->Energy()+hvq->Pz()+1.e-13)/
982 (hvq->Energy()-hvq->Pz()+1.e-13));
983 if(yQ>fYMin && yQ<fYMax) inYcut=kTRUE;
985 if (!theQ || !theQbar || !inYcut) {
991 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
992 if ( (fProcess == kPyW ||
994 fProcess == kPyMbDefault ||
996 fProcess == kPyMbNonDiffr)
997 && (fCutOnChild == 1) ) {
998 if ( !CheckKinematicsOnChild() ) {
1005 for (i = 0; i < np; i++) {
1007 TParticle * iparticle = (TParticle *) fParticles.At(i);
1008 kf = CheckPDGCode(iparticle->GetPdgCode());
1009 Int_t ks = iparticle->GetStatusCode();
1010 Int_t km = iparticle->GetFirstMother();
1011 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
1013 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
1015 if (ks == 1) trackIt = 1;
1016 Int_t ipa = iparticle->GetFirstMother()-1;
1018 iparent = (ipa > -1) ? pParent[ipa] : -1;
1021 // store track information
1022 p[0] = iparticle->Px();
1023 p[1] = iparticle->Py();
1024 p[2] = iparticle->Pz();
1025 p[3] = iparticle->Energy();
1028 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
1029 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
1030 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
1032 Float_t tof = fEventTime + kconv * iparticle->T();
1034 PushTrack(fTrackIt*trackIt, iparent, kf,
1035 p[0], p[1], p[2], p[3],
1036 origin[0], origin[1], origin[2], tof,
1037 polar[0], polar[1], polar[2],
1038 kPPrimary, nt, 1., ks);
1041 // Special Treatment to store color-flow
1043 if (ks == 3 || ks == 13 || ks == 14) {
1044 TParticle* particle = 0;
1046 particle = fStack->Particle(nt);
1048 particle = gAlice->Stack()->Particle(nt);
1050 particle->SetFirstDaughter(fPythia->GetK(2, i));
1051 particle->SetLastDaughter(fPythia->GetK(3, i));
1056 SetHighWaterMark(nt);
1058 } // select particle
1067 void AliGenPythia::FinishRun()
1069 // Print x-section summary
1078 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1079 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1082 void AliGenPythia::AdjustWeights() const
1084 // Adjust the weights after generation of all events
1088 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1089 for (Int_t i=0; i<ntrack; i++) {
1090 part= gAlice->GetMCApp()->Particle(i);
1091 part->SetWeight(part->GetWeight()*fKineBias);
1096 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2)
1098 // Treat protons as inside nuclei with mass numbers a1 and a2
1106 void AliGenPythia::MakeHeader()
1109 // Make header for the simulated event
1112 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1113 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(2);
1116 // Builds the event header, to be called after each event
1117 if (fHeader) delete fHeader;
1118 fHeader = new AliGenPythiaEventHeader("Pythia");
1121 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
1124 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1127 fHeader->SetPrimaryVertex(fVertex);
1130 // Number of primaries
1131 fHeader->SetNProduced(fNprimaries);
1133 // Jets that have triggered
1135 if (fProcess == kPyJets)
1138 Float_t jets[4][10];
1139 GetJets(njet, ntrig, jets);
1142 for (Int_t i = 0; i < ntrig; i++) {
1143 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1148 // Copy relevant information from external header, if present.
1153 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1154 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1156 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1159 exHeader->TriggerJet(i, uqJet);
1160 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1164 // Store quenching parameters
1171 fPythia->GetQuenchingParameters(xp, yp, z);
1174 Double_t r1 = PARIMP.rb1;
1175 Double_t r2 = PARIMP.rb2;
1176 Double_t b = PARIMP.b1;
1177 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1178 Double_t phi = PARIMP.psib1;
1179 xp = r * TMath::Cos(phi);
1180 yp = r * TMath::Sin(phi);
1183 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1184 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1188 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetVINT(47));
1196 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
1198 // Check the kinematic trigger condition
1201 eta[0] = jet1->Eta();
1202 eta[1] = jet2->Eta();
1204 phi[0] = jet1->Phi();
1205 phi[1] = jet2->Phi();
1207 pdg[0] = jet1->GetPdgCode();
1208 pdg[1] = jet2->GetPdgCode();
1209 Bool_t triggered = kFALSE;
1211 if (fProcess == kPyJets) {
1214 Float_t jets[4][10];
1216 // Use Pythia clustering on parton level to determine jet axis
1218 GetJets(njets, ntrig, jets);
1220 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1225 if (pdg[0] == kGamma) {
1229 //Check eta range first...
1230 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1231 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1233 //Eta is okay, now check phi range
1234 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1235 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1246 Bool_t AliGenPythia::CheckKinematicsOnChild(){
1248 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1250 Bool_t checking = kFALSE;
1251 Int_t j, kcode, ks, km;
1252 Int_t nPartAcc = 0; //number of particles in the acceptance range
1253 Int_t numberOfAcceptedParticles = 1;
1254 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1255 Int_t npart = fParticles.GetEntriesFast();
1257 for (j = 0; j<npart; j++) {
1258 TParticle * jparticle = (TParticle *) fParticles.At(j);
1259 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1260 ks = jparticle->GetStatusCode();
1261 km = jparticle->GetFirstMother();
1263 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1266 if( numberOfAcceptedParticles <= nPartAcc){
1275 void AliGenPythia::LoadEvent(AliStack* stack, Int_t flag, Int_t reHadr)
1278 // Load event into Pythia Common Block
1281 Int_t npart = stack -> GetNprimary();
1285 (fPythia->GetPyjets())->N = npart;
1287 n0 = (fPythia->GetPyjets())->N;
1288 (fPythia->GetPyjets())->N = n0 + npart;
1292 for (Int_t part = 0; part < npart; part++) {
1293 TParticle *mPart = stack->Particle(part);
1295 Int_t kf = mPart->GetPdgCode();
1296 Int_t ks = mPart->GetStatusCode();
1297 Int_t idf = mPart->GetFirstDaughter();
1298 Int_t idl = mPart->GetLastDaughter();
1301 if (ks == 11 || ks == 12) {
1308 Float_t px = mPart->Px();
1309 Float_t py = mPart->Py();
1310 Float_t pz = mPart->Pz();
1311 Float_t e = mPart->Energy();
1312 Float_t m = mPart->GetCalcMass();
1315 (fPythia->GetPyjets())->P[0][part+n0] = px;
1316 (fPythia->GetPyjets())->P[1][part+n0] = py;
1317 (fPythia->GetPyjets())->P[2][part+n0] = pz;
1318 (fPythia->GetPyjets())->P[3][part+n0] = e;
1319 (fPythia->GetPyjets())->P[4][part+n0] = m;
1321 (fPythia->GetPyjets())->K[1][part+n0] = kf;
1322 (fPythia->GetPyjets())->K[0][part+n0] = ks;
1323 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
1324 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
1325 (fPythia->GetPyjets())->K[2][part+n0] = mPart->GetFirstMother() + 1;
1330 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1333 // Calls the Pythia jet finding algorithm to find jets in the current event
1338 Int_t n = fPythia->GetN();
1342 fPythia->Pycell(njets);
1344 for (i = 0; i < njets; i++) {
1345 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1346 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1347 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1348 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1359 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1362 // Calls the Pythia clustering algorithm to find jets in the current event
1364 Int_t n = fPythia->GetN();
1367 if (fJetReconstruction == kCluster) {
1369 // Configure cluster algorithm
1371 fPythia->SetPARU(43, 2.);
1372 fPythia->SetMSTU(41, 1);
1374 // Call cluster algorithm
1376 fPythia->Pyclus(nJets);
1378 // Loading jets from common block
1384 fPythia->Pycell(nJets);
1388 for (i = 0; i < nJets; i++) {
1389 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1390 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1391 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1392 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1393 Float_t pt = TMath::Sqrt(px * px + py * py);
1394 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1395 Float_t theta = TMath::ATan2(pt,pz);
1396 Float_t et = e * TMath::Sin(theta);
1397 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1399 eta > fEtaMinJet && eta < fEtaMaxJet &&
1400 phi > fPhiMinJet && phi < fPhiMaxJet &&
1401 et > fEtMinJet && et < fEtMaxJet
1404 jets[0][nJetsTrig] = px;
1405 jets[1][nJetsTrig] = py;
1406 jets[2][nJetsTrig] = pz;
1407 jets[3][nJetsTrig] = e;
1409 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1411 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1416 void AliGenPythia::GetSubEventTime()
1418 // Calculates time of the next subevent
1421 TArrayF &array = *fEventsTime;
1422 fEventTime = array[fCurSubEvent++];
1424 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1428 Bool_t AliGenPythia::IsInEMCAL(Float_t phi, Float_t eta)
1430 // Is particle in EMCAL acceptance?
1431 // phi in degrees, etamin=-etamax
1432 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1439 Bool_t AliGenPythia::IsInPHOS(Float_t phi, Float_t eta)
1441 // Is particle in PHOS acceptance?
1442 // Acceptance slightly larger considered.
1443 // phi in degrees, etamin=-etamax
1444 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1451 void AliGenPythia::RotatePhi(Int_t iphcand, Bool_t& okdd)
1453 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1454 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1455 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1456 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1458 //calculate deltaphi
1459 TParticle* ph = (TParticle *) fParticles.At(iphcand);
1460 Double_t phphi = ph->Phi();
1461 Double_t deltaphi = phiPHOS - phphi;
1465 //loop for all particles and produce the phi rotation
1466 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
1467 Double_t oldphi, newphi;
1468 Double_t newVx, newVy, R, Vz, time;
1469 Double_t newPx, newPy, pt, Pz, e;
1470 for(Int_t i=0; i< np; i++) {
1471 TParticle* iparticle = (TParticle *) fParticles.At(i);
1472 oldphi = iparticle->Phi();
1473 newphi = oldphi + deltaphi;
1474 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1475 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1478 newVx = R*TMath::Cos(newphi);
1479 newVy = R*TMath::Sin(newphi);
1480 Vz = iparticle->Vz(); // don't transform
1481 time = iparticle->T(); // don't transform
1483 pt = iparticle->Pt();
1484 newPx = pt*TMath::Cos(newphi);
1485 newPy = pt*TMath::Sin(newphi);
1486 Pz = iparticle->Pz(); // don't transform
1487 e = iparticle->Energy(); // don't transform
1490 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1491 iparticle->SetMomentum(newPx, newPy, Pz, e);
1493 } //end particle loop
1495 // now let's check that we put correctly the candidate photon in PHOS
1496 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1497 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1498 if(IsInPHOS(phi,eta))
1504 void AliGenPythia::Streamer(TBuffer &R__b)
1506 // Stream an object of class AliGenPythia.
1508 if (R__b.IsReading()) {
1509 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1510 AliGenerator::Streamer(R__b);
1511 R__b >> (Int_t&)fProcess;
1512 R__b >> (Int_t&)fStrucFunc;
1513 R__b >> (Int_t&)fForceDecay;
1517 fParentSelect.Streamer(R__b);
1518 fChildSelect.Streamer(R__b);
1520 // (AliPythia::Instance())->Streamer(R__b);
1523 // if (fDecayer) fDecayer->Streamer(R__b);
1525 R__b.WriteVersion(AliGenPythia::IsA());
1526 AliGenerator::Streamer(R__b);
1527 R__b << (Int_t)fProcess;
1528 R__b << (Int_t)fStrucFunc;
1529 R__b << (Int_t)fForceDecay;
1533 fParentSelect.Streamer(R__b);
1534 fChildSelect.Streamer(R__b);
1539 // fDecayer->Streamer(R__b);