1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
19 // Generator using the TPythia interface (via AliPythia)
20 // to generate pp collisions.
21 // Using SetNuclei() also nuclear modifications to the structure functions
22 // can be taken into account. This makes, of course, only sense for the
23 // generation of the products of hard processes (heavy flavor, jets ...)
25 // andreas.morsch@cern.ch
28 #include <TClonesArray.h>
29 #include <TDatabasePDG.h>
30 #include <TParticle.h>
32 #include <TObjArray.h>
36 #include "AliDecayerPythia.h"
37 #include "AliGenPythia.h"
38 #include "AliHeader.h"
39 #include "AliGenPythiaEventHeader.h"
40 #include "AliPythia.h"
41 #include "AliPythiaRndm.h"
44 #include "AliRunLoader.h"
46 #include "PyquenCommon.h"
48 ClassImp(AliGenPythia)
51 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),
112 fTriggerMultiplicity(0),
113 fTriggerMultiplicityEta(0),
114 fCountMode(kCountAll),
118 fFragPhotonInCalo(kFALSE),
120 fPhotonInCalo(kFALSE),
123 fCheckPHOSeta(kFALSE),
124 fFragPhotonOrPi0MinPt(0),
134 // Default Constructor
137 if (!AliPythiaRndm::GetPythiaRandom())
138 AliPythiaRndm::SetPythiaRandom(GetRandom());
141 AliGenPythia::AliGenPythia(Int_t npart)
152 fInteractionRate(0.),
166 fHadronisation(kTRUE),
168 fReadFromFile(kFALSE),
172 fDecayer(new AliDecayerPythia()),
173 fDebugEventFirst(-1),
180 fPhiMaxJet(2.* TMath::Pi()),
181 fJetReconstruction(kCell),
185 fPhiMaxGamma(2. * TMath::Pi()),
189 fPycellThreshold(0.),
191 fPycellMinEtJet(10.),
192 fPycellMaxRadius(1.),
193 fStackFillOpt(kFlavorSelection),
195 fFragmentation(kTRUE),
202 fTriggerMultiplicity(0),
203 fTriggerMultiplicityEta(0),
204 fCountMode(kCountAll),
208 fFragPhotonInCalo(kFALSE),
210 fPhotonInCalo(kFALSE),
213 fCheckPHOSeta(kFALSE),
214 fFragPhotonOrPi0MinPt(0),
223 // default charm production at 5. 5 TeV
225 // structure function GRVHO
229 fTitle= "Particle Generator using PYTHIA";
231 // Set random number generator
232 if (!AliPythiaRndm::GetPythiaRandom())
233 AliPythiaRndm::SetPythiaRandom(GetRandom());
237 AliGenPythia::~AliGenPythia()
240 if(fEventsTime) delete fEventsTime;
243 void AliGenPythia::SetInteractionRate(Float_t rate,Float_t timewindow)
245 // Generate pileup using user specified rate
246 fInteractionRate = rate;
247 fTimeWindow = timewindow;
251 void AliGenPythia::GeneratePileup()
253 // Generate sub events time for pileup
255 if(fInteractionRate == 0.) {
256 Warning("GeneratePileup","Zero interaction specified. Skipping pileup generation.\n");
260 Int_t npart = NumberParticles();
262 Warning("GeneratePileup","Negative number of particles. Skipping pileup generation.\n");
266 if(fEventsTime) delete fEventsTime;
267 fEventsTime = new TArrayF(npart);
268 TArrayF &array = *fEventsTime;
269 for(Int_t ipart = 0; ipart < npart; ipart++)
272 Float_t eventtime = 0.;
275 eventtime += (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
276 if(eventtime > fTimeWindow) break;
277 array.Set(array.GetSize()+1);
278 array[array.GetSize()-1] = eventtime;
284 eventtime -= (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
285 if(TMath::Abs(eventtime) > fTimeWindow) break;
286 array.Set(array.GetSize()+1);
287 array[array.GetSize()-1] = eventtime;
290 SetNumberParticles(fEventsTime->GetSize());
293 void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
294 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
296 // Set pycell parameters
297 fPycellEtaMax = etamax;
300 fPycellThreshold = thresh;
301 fPycellEtSeed = etseed;
302 fPycellMinEtJet = minet;
303 fPycellMaxRadius = r;
308 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
310 // Set a range of event numbers, for which a table
311 // of generated particle will be printed
312 fDebugEventFirst = eventFirst;
313 fDebugEventLast = eventLast;
314 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
317 void AliGenPythia::Init()
321 SetMC(AliPythia::Instance());
322 fPythia=(AliPythia*) fMCEvGen;
325 fParentWeight=1./Float_t(fNpart);
329 fPythia->SetCKIN(3,fPtHardMin);
330 fPythia->SetCKIN(4,fPtHardMax);
331 fPythia->SetCKIN(7,fYHardMin);
332 fPythia->SetCKIN(8,fYHardMax);
334 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget, fNucPdf);
336 if (fFragmentation) {
337 fPythia->SetMSTP(111,1);
339 fPythia->SetMSTP(111,0);
343 // initial state radiation
344 fPythia->SetMSTP(61,fGinit);
345 // final state radiation
346 fPythia->SetMSTP(71,fGfinal);
349 fPythia->SetMSTP(91,1);
350 fPythia->SetPARP(91,fPtKick);
351 fPythia->SetPARP(93, 4. * fPtKick);
353 fPythia->SetMSTP(91,0);
358 fRL = AliRunLoader::Open(fFileName, "Partons");
359 fRL->LoadKinematics();
365 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
366 // Forward Paramters to the AliPythia object
367 fDecayer->SetForceDecay(fForceDecay);
368 // Switch off Heavy Flavors on request
370 // Maximum number of quark flavours used in pdf
371 fPythia->SetMSTP(58, 3);
372 // Maximum number of flavors that can be used in showers
373 fPythia->SetMSTJ(45, 3);
374 // Switch off g->QQbar splitting in decay table
375 ((AliDecayerPythia*) fDecayer)->HeavyFlavourOff();
381 // Parent and Children Selection
384 case kPyOldUEQ2ordered:
385 case kPyOldUEQ2ordered2:
389 case kPyCharmUnforced:
390 case kPyCharmPbPbMNR:
393 case kPyCharmppMNRwmi:
394 fParentSelect[0] = 411;
395 fParentSelect[1] = 421;
396 fParentSelect[2] = 431;
397 fParentSelect[3] = 4122;
398 fParentSelect[4] = 4232;
399 fParentSelect[5] = 4132;
400 fParentSelect[6] = 4332;
406 fParentSelect[0] = 421;
409 case kPyDPlusPbPbMNR:
412 fParentSelect[0] = 411;
415 case kPyDPlusStrangePbPbMNR:
416 case kPyDPlusStrangepPbMNR:
417 case kPyDPlusStrangeppMNR:
418 fParentSelect[0] = 431;
422 case kPyBeautyPbPbMNR:
423 case kPyBeautypPbMNR:
425 case kPyBeautyppMNRwmi:
426 fParentSelect[0]= 511;
427 fParentSelect[1]= 521;
428 fParentSelect[2]= 531;
429 fParentSelect[3]= 5122;
430 fParentSelect[4]= 5132;
431 fParentSelect[5]= 5232;
432 fParentSelect[6]= 5332;
435 case kPyBeautyUnforced:
436 fParentSelect[0] = 511;
437 fParentSelect[1] = 521;
438 fParentSelect[2] = 531;
439 fParentSelect[3] = 5122;
440 fParentSelect[4] = 5132;
441 fParentSelect[5] = 5232;
442 fParentSelect[6] = 5332;
447 fParentSelect[0] = 443;
451 case kPyMbWithDirectPhoton:
464 // JetFinder for Trigger
466 // Configure detector (EMCAL like)
468 fPythia->SetPARU(51, fPycellEtaMax);
469 fPythia->SetMSTU(51, fPycellNEta);
470 fPythia->SetMSTU(52, fPycellNPhi);
472 // Configure Jet Finder
474 fPythia->SetPARU(58, fPycellThreshold);
475 fPythia->SetPARU(52, fPycellEtSeed);
476 fPythia->SetPARU(53, fPycellMinEtJet);
477 fPythia->SetPARU(54, fPycellMaxRadius);
478 fPythia->SetMSTU(54, 2);
480 // This counts the total number of calls to Pyevnt() per run.
495 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
499 fPythia->InitQuenching(0., 0.1, 0.6e6, 0);
501 fPythia->SetPARJ(200, 0.0);
504 // Nestor's change of the splittings
505 fPythia->SetPARJ(200, 0.8);
506 fPythia->SetMSTJ(41, 1); // QCD radiation only
507 fPythia->SetMSTJ(42, 2); // angular ordering
508 fPythia->SetMSTJ(44, 2); // option to run alpha_s
509 fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
510 fPythia->SetMSTJ(50, 0); // No coherence in first branching
511 fPythia->SetPARJ(82, 1.); // Cut off for parton showers
515 void AliGenPythia::Generate()
517 // Generate one event
518 if (!fPythia) fPythia=(AliPythia*) fMCEvGen;
519 fDecayer->ForceDecay();
521 Float_t polar[3] = {0,0,0};
522 Float_t origin[3] = {0,0,0};
524 // converts from mm/c to s
525 const Float_t kconv=0.001/2.999792458e8;
535 // Set collision vertex position
536 if (fVertexSmear == kPerEvent) Vertex();
545 // Switch hadronisation off
547 fPythia->SetMSTJ(1, 0);
549 // Either produce new event or read partons from file
551 if (!fReadFromFile) {
557 fNpartons = fPythia->GetN();
559 printf("Loading Event %d\n",AliRunLoader::Instance()->GetEventNumber());
560 fRL->GetEvent(AliRunLoader::Instance()->GetEventNumber());
562 LoadEvent(fRL->Stack(), 0 , 1);
567 // Run quenching routine
571 } else if (fQuench == 2){
572 fPythia->Pyquen(208., 0, 0.);
573 } else if (fQuench == 3) {
574 // Quenching is via multiplicative correction of the splittings
578 // Switch hadronisation on
580 if (fHadronisation) {
581 fPythia->SetMSTJ(1, 1);
583 // .. and perform hadronisation
584 // printf("Calling hadronisation %d\n", fPythia->GetN());
588 fPythia->ImportParticles(&fParticles,"All");
596 Int_t np = fParticles.GetEntriesFast();
598 if (np == 0) continue;
602 Int_t* pParent = new Int_t[np];
603 Int_t* pSelected = new Int_t[np];
604 Int_t* trackIt = new Int_t[np];
605 for (i = 0; i < np; i++) {
611 Int_t nc = 0; // Total n. of selected particles
612 Int_t nParents = 0; // Selected parents
613 Int_t nTkbles = 0; // Trackable particles
614 if (fProcess != kPyMbDefault &&
616 fProcess != kPyMbWithDirectPhoton &&
617 fProcess != kPyJets &&
618 fProcess != kPyDirectGamma &&
619 fProcess != kPyMbNonDiffr &&
620 fProcess != kPyMbMSEL1 &&
623 fProcess != kPyCharmppMNRwmi &&
624 fProcess != kPyBeautyppMNRwmi) {
626 for (i = 0; i < np; i++) {
627 TParticle* iparticle = (TParticle *) fParticles.At(i);
628 Int_t ks = iparticle->GetStatusCode();
629 kf = CheckPDGCode(iparticle->GetPdgCode());
630 // No initial state partons
631 if (ks==21) continue;
633 // Heavy Flavor Selection
640 if (kfl > 100000) kfl %= 100000;
641 if (kfl > 10000) kfl %= 10000;
643 if (kfl > 10) kfl/=100;
645 if (kfl > 10) kfl/=10;
646 Int_t ipa = iparticle->GetFirstMother()-1;
649 // Establish mother daughter relation between heavy quarks and mesons
651 if (kf >= fFlavorSelect && kf <= 6) {
652 Int_t idau = iparticle->GetFirstDaughter() - 1;
654 TParticle* daughter = (TParticle *) fParticles.At(idau);
655 Int_t pdgD = daughter->GetPdgCode();
656 if (pdgD == 91 || pdgD == 92) {
657 Int_t jmin = daughter->GetFirstDaughter() - 1;
658 Int_t jmax = daughter->GetLastDaughter() - 1;
659 for (Int_t jp = jmin; jp <= jmax; jp++)
660 ((TParticle *) fParticles.At(jp))->SetFirstMother(i+1);
661 } // is string or cluster
667 TParticle * mother = (TParticle *) fParticles.At(ipa);
668 kfMo = TMath::Abs(mother->GetPdgCode());
671 // What to keep in Stack?
672 Bool_t flavorOK = kFALSE;
673 Bool_t selectOK = kFALSE;
675 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
677 if (kfl > fFlavorSelect) {
681 if (kfl == fFlavorSelect) flavorOK = kTRUE;
683 switch (fStackFillOpt) {
684 case kFlavorSelection:
687 case kParentSelection:
688 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
691 if (flavorOK && selectOK) {
693 // Heavy flavor hadron or quark
695 // Kinematic seletion on final state heavy flavor mesons
696 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
701 if (ParentSelected(kf)) ++nParents; // Update parent count
702 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
704 // Kinematic seletion on decay products
705 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
706 && !KinematicSelection(iparticle, 1))
712 // Select if mother was selected and is not tracked
714 if (pSelected[ipa] &&
715 !trackIt[ipa] && // mother will be tracked ?
716 kfMo != 5 && // mother is b-quark, don't store fragments
717 kfMo != 4 && // mother is c-quark, don't store fragments
718 kf != 92) // don't store string
721 // Semi-stable or de-selected: diselect decay products:
724 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
726 Int_t ipF = iparticle->GetFirstDaughter();
727 Int_t ipL = iparticle->GetLastDaughter();
728 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
730 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
731 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
734 if (pSelected[i] == -1) pSelected[i] = 0;
735 if (!pSelected[i]) continue;
736 // Count quarks only if you did not include fragmentation
737 if (fFragmentation && kf <= 10) continue;
740 // Decision on tracking
743 // Track final state particle
744 if (ks == 1) trackIt[i] = 1;
745 // Track semi-stable particles
746 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
747 // Track particles selected by process if undecayed.
748 if (fForceDecay == kNoDecay) {
749 if (ParentSelected(kf)) trackIt[i] = 1;
751 if (ParentSelected(kf)) trackIt[i] = 0;
753 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
757 } // particle selection loop
759 for (i = 0; i<np; i++) {
760 if (!pSelected[i]) continue;
761 TParticle * iparticle = (TParticle *) fParticles.At(i);
762 kf = CheckPDGCode(iparticle->GetPdgCode());
763 Int_t ks = iparticle->GetStatusCode();
764 p[0] = iparticle->Px();
765 p[1] = iparticle->Py();
766 p[2] = iparticle->Pz();
767 p[3] = iparticle->Energy();
769 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
770 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
771 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
773 Float_t tof = kconv*iparticle->T();
774 Int_t ipa = iparticle->GetFirstMother()-1;
775 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
777 PushTrack(fTrackIt*trackIt[i], iparent, kf,
778 p[0], p[1], p[2], p[3],
779 origin[0], origin[1], origin[2], tof,
780 polar[0], polar[1], polar[2],
781 kPPrimary, nt, 1., ks);
798 switch (fCountMode) {
800 // printf(" Count all \n");
804 // printf(" Count parents \n");
807 case kCountTrackables:
808 // printf(" Count trackable \n");
812 if (jev >= fNpart || fNpart == -1) {
813 fKineBias=Float_t(fNpart)/Float_t(fTrials);
815 fQ += fPythia->GetVINT(51);
816 fX1 += fPythia->GetVINT(41);
817 fX2 += fPythia->GetVINT(42);
818 fTrialsRun += fTrials;
825 SetHighWaterMark(nt);
826 // adjust weight due to kinematic selection
829 fXsection=fPythia->GetPARI(1);
832 Int_t AliGenPythia::GenerateMB()
835 // Min Bias selection and other global selections
837 Int_t i, kf, nt, iparent;
840 Float_t polar[3] = {0,0,0};
841 Float_t origin[3] = {0,0,0};
842 // converts from mm/c to s
843 const Float_t kconv=0.001/2.999792458e8;
847 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
851 Int_t* pParent = new Int_t[np];
852 for (i=0; i< np; i++) pParent[i] = -1;
853 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
854 TParticle* jet1 = (TParticle *) fParticles.At(6);
855 TParticle* jet2 = (TParticle *) fParticles.At(7);
856 if (!CheckTrigger(jet1, jet2)) {
862 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
863 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
868 if (fFragPhotonInCalo) pdg = 22 ; // Photon
869 else if (fPi0InCalo) pdg = 111 ; // Pi0
871 for (i=0; i< np; i++) {
872 TParticle* iparticle = (TParticle *) fParticles.At(i);
873 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
874 iparticle->Pt() > fFragPhotonOrPi0MinPt){
875 Int_t imother = iparticle->GetFirstMother() - 1;
876 TParticle* pmother = (TParticle *) fParticles.At(imother);
878 (pdg == 22 && pmother->GetStatusCode() != 11)) //No photon from hadron decay
880 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
881 Float_t eta =TMath::Abs(iparticle->Eta()); //in calos etamin=-etamax
882 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
883 (fCheckPHOS && IsInPHOS(phi,eta)) )
892 // Check for minimum multiplicity
893 if (fTriggerMultiplicity > 0) {
894 Int_t multiplicity = 0;
895 for (i = 0; i < np; i++) {
896 TParticle * iparticle = (TParticle *) fParticles.At(i);
898 Int_t statusCode = iparticle->GetStatusCode();
900 // Initial state particle
904 // skip quarks and gluons
905 Int_t pdgCode = TMath::Abs(iparticle->GetPdgCode());
906 if (pdgCode <= 10 || pdgCode == 21)
909 if (fTriggerMultiplicityEta > 0 && TMath::Abs(iparticle->Eta()) > fTriggerMultiplicityEta)
912 TParticlePDG* pdgPart = iparticle->GetPDG();
913 if (pdgPart && pdgPart->Charge() == 0)
919 if (multiplicity < fTriggerMultiplicity) {
924 Printf("Triggered on event with multiplicity of %d > %d", multiplicity, fTriggerMultiplicity);
927 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
928 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
934 for (i=0; i< np; i++) {
935 TParticle* iparticle = (TParticle *) fParticles.At(i);
936 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
937 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
939 if(iparticle->GetStatusCode() == 1
940 && iparticle->GetPdgCode() == pdg
941 && iparticle->Pt() > fPhotonMinPt
944 // first check if the photon is in PHOS phi
945 if(IsInPHOS(phi,eta)){
949 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
954 if(!okd && iphcand != -1) // execute rotation in phi
955 RotatePhi(iphcand,okd);
961 if (fTriggerParticle) {
962 Bool_t triggered = kFALSE;
963 for (i = 0; i < np; i++) {
964 TParticle * iparticle = (TParticle *) fParticles.At(i);
965 kf = CheckPDGCode(iparticle->GetPdgCode());
966 if (kf != fTriggerParticle) continue;
967 if (iparticle->Pt() == 0.) continue;
968 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
979 // Check if there is a ccbar or bbbar pair with at least one of the two
980 // in fYMin < y < fYMax
981 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi) {
982 TParticle *partCheck;
984 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
985 Bool_t theChild=kFALSE;
987 Int_t pdg,mpdg,mpdgUpperFamily;
988 for(i=0; i<np; i++) {
989 partCheck = (TParticle*)fParticles.At(i);
990 pdg = partCheck->GetPdgCode();
991 if(TMath::Abs(pdg) == fFlavorSelect) { // quark
992 if(pdg>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
993 y = 0.5*TMath::Log((partCheck->Energy()+partCheck->Pz()+1.e-13)/
994 (partCheck->Energy()-partCheck->Pz()+1.e-13));
995 if(y>fYMin && y<fYMax) inYcut=kTRUE;
997 if(fCutOnChild && TMath::Abs(pdg) == fPdgCodeParticleforAcceptanceCut) {
998 Int_t mi = partCheck->GetFirstMother() - 1;
1000 mother = (TParticle*)fParticles.At(mi);
1001 mpdg=TMath::Abs(mother->GetPdgCode());
1002 mpdgUpperFamily=(mpdg>1000 ? mpdg+1000 : mpdg+100); // keep e from c from b
1003 if ( ParentSelected(mpdg) ||
1004 (fFlavorSelect==5 && ParentSelected(mpdgUpperFamily))) {
1005 if (KinematicSelection(partCheck,1)) {
1011 if (!theQ || !theQbar || !inYcut) { // one of the c/b conditions not satisfied
1015 if (fCutOnChild && !theChild) { // one of the child conditions not satisfied
1022 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
1023 if ( (fProcess == kPyW ||
1025 fProcess == kPyMbDefault ||
1026 fProcess == kPyMb ||
1027 fProcess == kPyMbWithDirectPhoton ||
1028 fProcess == kPyMbNonDiffr)
1029 && (fCutOnChild == 1) ) {
1030 if ( !CheckKinematicsOnChild() ) {
1037 for (i = 0; i < np; i++) {
1039 TParticle * iparticle = (TParticle *) fParticles.At(i);
1040 kf = CheckPDGCode(iparticle->GetPdgCode());
1041 Int_t ks = iparticle->GetStatusCode();
1042 Int_t km = iparticle->GetFirstMother();
1043 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
1045 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
1047 if (ks == 1) trackIt = 1;
1048 Int_t ipa = iparticle->GetFirstMother()-1;
1050 iparent = (ipa > -1) ? pParent[ipa] : -1;
1053 // store track information
1054 p[0] = iparticle->Px();
1055 p[1] = iparticle->Py();
1056 p[2] = iparticle->Pz();
1057 p[3] = iparticle->Energy();
1060 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
1061 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
1062 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
1064 Float_t tof = fEventTime + kconv * iparticle->T();
1066 PushTrack(fTrackIt*trackIt, iparent, kf,
1067 p[0], p[1], p[2], p[3],
1068 origin[0], origin[1], origin[2], tof,
1069 polar[0], polar[1], polar[2],
1070 kPPrimary, nt, 1., ks);
1074 SetHighWaterMark(nt);
1076 } // select particle
1085 void AliGenPythia::FinishRun()
1087 // Print x-section summary
1096 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1097 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1100 void AliGenPythia::AdjustWeights() const
1102 // Adjust the weights after generation of all events
1106 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1107 for (Int_t i=0; i<ntrack; i++) {
1108 part= gAlice->GetMCApp()->Particle(i);
1109 part->SetWeight(part->GetWeight()*fKineBias);
1114 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2, Int_t pdfset)
1116 // Treat protons as inside nuclei with mass numbers a1 and a2
1120 fNucPdf = pdfset; // 0 EKS98 1 EPS08
1125 void AliGenPythia::MakeHeader()
1128 // Make header for the simulated event
1131 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1132 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(2);
1135 // Builds the event header, to be called after each event
1136 if (fHeader) delete fHeader;
1137 fHeader = new AliGenPythiaEventHeader("Pythia");
1140 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
1143 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1146 fHeader->SetPrimaryVertex(fVertex);
1149 // Number of primaries
1150 fHeader->SetNProduced(fNprimaries);
1152 // Jets that have triggered
1154 if (fProcess == kPyJets || fProcess == kPyDirectGamma)
1157 Float_t jets[4][10];
1158 GetJets(njet, ntrig, jets);
1161 for (Int_t i = 0; i < ntrig; i++) {
1162 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1167 // Copy relevant information from external header, if present.
1172 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1173 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1175 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1178 exHeader->TriggerJet(i, uqJet);
1179 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1183 // Store quenching parameters
1190 fPythia->GetQuenchingParameters(xp, yp, z);
1193 Double_t r1 = PARIMP.rb1;
1194 Double_t r2 = PARIMP.rb2;
1195 Double_t b = PARIMP.b1;
1196 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1197 Double_t phi = PARIMP.psib1;
1198 xp = r * TMath::Cos(phi);
1199 yp = r * TMath::Sin(phi);
1202 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1203 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1207 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetVINT(47));
1215 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
1217 // Check the kinematic trigger condition
1220 eta[0] = jet1->Eta();
1221 eta[1] = jet2->Eta();
1223 phi[0] = jet1->Phi();
1224 phi[1] = jet2->Phi();
1226 pdg[0] = jet1->GetPdgCode();
1227 pdg[1] = jet2->GetPdgCode();
1228 Bool_t triggered = kFALSE;
1230 if (fProcess == kPyJets) {
1233 Float_t jets[4][10];
1235 // Use Pythia clustering on parton level to determine jet axis
1237 GetJets(njets, ntrig, jets);
1239 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1244 if (pdg[0] == kGamma) {
1248 //Check eta range first...
1249 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1250 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1252 //Eta is okay, now check phi range
1253 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1254 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1265 Bool_t AliGenPythia::CheckKinematicsOnChild(){
1267 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1269 Bool_t checking = kFALSE;
1270 Int_t j, kcode, ks, km;
1271 Int_t nPartAcc = 0; //number of particles in the acceptance range
1272 Int_t numberOfAcceptedParticles = 1;
1273 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1274 Int_t npart = fParticles.GetEntriesFast();
1276 for (j = 0; j<npart; j++) {
1277 TParticle * jparticle = (TParticle *) fParticles.At(j);
1278 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1279 ks = jparticle->GetStatusCode();
1280 km = jparticle->GetFirstMother();
1282 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1285 if( numberOfAcceptedParticles <= nPartAcc){
1294 void AliGenPythia::LoadEvent(AliStack* stack, Int_t flag, Int_t reHadr)
1297 // Load event into Pythia Common Block
1300 Int_t npart = stack -> GetNprimary();
1304 (fPythia->GetPyjets())->N = npart;
1306 n0 = (fPythia->GetPyjets())->N;
1307 (fPythia->GetPyjets())->N = n0 + npart;
1311 for (Int_t part = 0; part < npart; part++) {
1312 TParticle *mPart = stack->Particle(part);
1314 Int_t kf = mPart->GetPdgCode();
1315 Int_t ks = mPart->GetStatusCode();
1316 Int_t idf = mPart->GetFirstDaughter();
1317 Int_t idl = mPart->GetLastDaughter();
1320 if (ks == 11 || ks == 12) {
1327 Float_t px = mPart->Px();
1328 Float_t py = mPart->Py();
1329 Float_t pz = mPart->Pz();
1330 Float_t e = mPart->Energy();
1331 Float_t m = mPart->GetCalcMass();
1334 (fPythia->GetPyjets())->P[0][part+n0] = px;
1335 (fPythia->GetPyjets())->P[1][part+n0] = py;
1336 (fPythia->GetPyjets())->P[2][part+n0] = pz;
1337 (fPythia->GetPyjets())->P[3][part+n0] = e;
1338 (fPythia->GetPyjets())->P[4][part+n0] = m;
1340 (fPythia->GetPyjets())->K[1][part+n0] = kf;
1341 (fPythia->GetPyjets())->K[0][part+n0] = ks;
1342 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
1343 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
1344 (fPythia->GetPyjets())->K[2][part+n0] = mPart->GetFirstMother() + 1;
1348 void AliGenPythia::LoadEvent(TObjArray* stack, Int_t flag, Int_t reHadr)
1351 // Load event into Pythia Common Block
1354 Int_t npart = stack -> GetEntries();
1358 (fPythia->GetPyjets())->N = npart;
1360 n0 = (fPythia->GetPyjets())->N;
1361 (fPythia->GetPyjets())->N = n0 + npart;
1365 for (Int_t part = 0; part < npart; part++) {
1366 TParticle *mPart = dynamic_cast<TParticle *>(stack->At(part));
1367 Int_t kf = mPart->GetPdgCode();
1368 Int_t ks = mPart->GetStatusCode();
1369 Int_t idf = mPart->GetFirstDaughter();
1370 Int_t idl = mPart->GetLastDaughter();
1373 if (ks == 11 || ks == 12) {
1380 Float_t px = mPart->Px();
1381 Float_t py = mPart->Py();
1382 Float_t pz = mPart->Pz();
1383 Float_t e = mPart->Energy();
1384 Float_t m = mPart->GetCalcMass();
1387 (fPythia->GetPyjets())->P[0][part+n0] = px;
1388 (fPythia->GetPyjets())->P[1][part+n0] = py;
1389 (fPythia->GetPyjets())->P[2][part+n0] = pz;
1390 (fPythia->GetPyjets())->P[3][part+n0] = e;
1391 (fPythia->GetPyjets())->P[4][part+n0] = m;
1393 (fPythia->GetPyjets())->K[1][part+n0] = kf;
1394 (fPythia->GetPyjets())->K[0][part+n0] = ks;
1395 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
1396 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
1397 (fPythia->GetPyjets())->K[2][part+n0] = mPart->GetFirstMother() + 1;
1402 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1405 // Calls the Pythia jet finding algorithm to find jets in the current event
1410 Int_t n = fPythia->GetN();
1414 fPythia->Pycell(njets);
1416 for (i = 0; i < njets; i++) {
1417 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1418 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1419 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1420 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1431 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1434 // Calls the Pythia clustering algorithm to find jets in the current event
1436 Int_t n = fPythia->GetN();
1439 if (fJetReconstruction == kCluster) {
1441 // Configure cluster algorithm
1443 fPythia->SetPARU(43, 2.);
1444 fPythia->SetMSTU(41, 1);
1446 // Call cluster algorithm
1448 fPythia->Pyclus(nJets);
1450 // Loading jets from common block
1456 fPythia->Pycell(nJets);
1460 for (i = 0; i < nJets; i++) {
1461 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1462 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1463 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1464 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1465 Float_t pt = TMath::Sqrt(px * px + py * py);
1466 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1467 Float_t theta = TMath::ATan2(pt,pz);
1468 Float_t et = e * TMath::Sin(theta);
1469 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1471 eta > fEtaMinJet && eta < fEtaMaxJet &&
1472 phi > fPhiMinJet && phi < fPhiMaxJet &&
1473 et > fEtMinJet && et < fEtMaxJet
1476 jets[0][nJetsTrig] = px;
1477 jets[1][nJetsTrig] = py;
1478 jets[2][nJetsTrig] = pz;
1479 jets[3][nJetsTrig] = e;
1481 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1483 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1488 void AliGenPythia::GetSubEventTime()
1490 // Calculates time of the next subevent
1493 TArrayF &array = *fEventsTime;
1494 fEventTime = array[fCurSubEvent++];
1496 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1500 Bool_t AliGenPythia::IsInEMCAL(Float_t phi, Float_t eta)
1502 // Is particle in EMCAL acceptance?
1503 // phi in degrees, etamin=-etamax
1504 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1511 Bool_t AliGenPythia::IsInPHOS(Float_t phi, Float_t eta)
1513 // Is particle in PHOS acceptance?
1514 // Acceptance slightly larger considered.
1515 // phi in degrees, etamin=-etamax
1516 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1523 void AliGenPythia::RotatePhi(Int_t iphcand, Bool_t& okdd)
1525 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1526 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1527 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1528 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1530 //calculate deltaphi
1531 TParticle* ph = (TParticle *) fParticles.At(iphcand);
1532 Double_t phphi = ph->Phi();
1533 Double_t deltaphi = phiPHOS - phphi;
1537 //loop for all particles and produce the phi rotation
1538 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
1539 Double_t oldphi, newphi;
1540 Double_t newVx, newVy, R, Vz, time;
1541 Double_t newPx, newPy, pt, Pz, e;
1542 for(Int_t i=0; i< np; i++) {
1543 TParticle* iparticle = (TParticle *) fParticles.At(i);
1544 oldphi = iparticle->Phi();
1545 newphi = oldphi + deltaphi;
1546 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1547 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1550 newVx = R*TMath::Cos(newphi);
1551 newVy = R*TMath::Sin(newphi);
1552 Vz = iparticle->Vz(); // don't transform
1553 time = iparticle->T(); // don't transform
1555 pt = iparticle->Pt();
1556 newPx = pt*TMath::Cos(newphi);
1557 newPy = pt*TMath::Sin(newphi);
1558 Pz = iparticle->Pz(); // don't transform
1559 e = iparticle->Energy(); // don't transform
1562 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1563 iparticle->SetMomentum(newPx, newPy, Pz, e);
1565 } //end particle loop
1567 // now let's check that we put correctly the candidate photon in PHOS
1568 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1569 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1570 if(IsInPHOS(phi,eta))
1576 void AliGenPythia::Streamer(TBuffer &R__b)
1578 // Stream an object of class AliGenPythia.
1580 if (R__b.IsReading()) {
1581 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1582 AliGenerator::Streamer(R__b);
1583 R__b >> (Int_t&)fProcess;
1584 R__b >> (Int_t&)fStrucFunc;
1585 R__b >> (Int_t&)fForceDecay;
1589 fParentSelect.Streamer(R__b);
1590 fChildSelect.Streamer(R__b);
1592 // (AliPythia::Instance())->Streamer(R__b);
1595 // if (fDecayer) fDecayer->Streamer(R__b);
1597 R__b.WriteVersion(AliGenPythia::IsA());
1598 AliGenerator::Streamer(R__b);
1599 R__b << (Int_t)fProcess;
1600 R__b << (Int_t)fStrucFunc;
1601 R__b << (Int_t)fForceDecay;
1605 fParentSelect.Streamer(R__b);
1606 fChildSelect.Streamer(R__b);
1611 // fDecayer->Streamer(R__b);