1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
19 // Generator using the TPythia interface (via AliPythia)
20 // to generate pp collisions.
21 // Using SetNuclei() also nuclear modifications to the structure functions
22 // can be taken into account. This makes, of course, only sense for the
23 // generation of the products of hard processes (heavy flavor, jets ...)
25 // andreas.morsch@cern.ch
28 #include <TClonesArray.h>
29 #include <TDatabasePDG.h>
30 #include <TParticle.h>
35 #include "AliDecayerPythia.h"
36 #include "AliGenPythia.h"
37 #include "AliHeader.h"
38 #include "AliGenPythiaEventHeader.h"
39 #include "AliPythia.h"
40 #include "AliPythiaRndm.h"
43 #include "AliRunLoader.h"
45 #include "PyquenCommon.h"
47 ClassImp(AliGenPythia)
50 AliGenPythia::AliGenPythia():
81 fDecayer(new AliDecayerPythia()),
89 fPhiMaxJet(2.* TMath::Pi()),
90 fJetReconstruction(kCell),
94 fPhiMaxGamma(2. * TMath::Pi()),
100 fPycellMinEtJet(10.),
101 fPycellMaxRadius(1.),
102 fStackFillOpt(kFlavorSelection),
104 fFragmentation(kTRUE),
111 fTriggerMultiplicity(0),
112 fTriggerMultiplicityEta(0),
113 fCountMode(kCountAll),
117 fFragPhotonInCalo(kFALSE),
119 fPhotonInCalo(kFALSE),
122 fCheckPHOSeta(kFALSE),
123 fFragPhotonOrPi0MinPt(0),
133 // Default Constructor
136 if (!AliPythiaRndm::GetPythiaRandom())
137 AliPythiaRndm::SetPythiaRandom(GetRandom());
140 AliGenPythia::AliGenPythia(Int_t npart)
151 fInteractionRate(0.),
165 fHadronisation(kTRUE),
167 fReadFromFile(kFALSE),
171 fDecayer(new AliDecayerPythia()),
172 fDebugEventFirst(-1),
179 fPhiMaxJet(2.* TMath::Pi()),
180 fJetReconstruction(kCell),
184 fPhiMaxGamma(2. * TMath::Pi()),
188 fPycellThreshold(0.),
190 fPycellMinEtJet(10.),
191 fPycellMaxRadius(1.),
192 fStackFillOpt(kFlavorSelection),
194 fFragmentation(kTRUE),
201 fTriggerMultiplicity(0),
202 fTriggerMultiplicityEta(0),
203 fCountMode(kCountAll),
207 fFragPhotonInCalo(kFALSE),
209 fPhotonInCalo(kFALSE),
212 fCheckPHOSeta(kFALSE),
213 fFragPhotonOrPi0MinPt(0),
222 // default charm production at 5. 5 TeV
224 // structure function GRVHO
228 fTitle= "Particle Generator using PYTHIA";
230 // Set random number generator
231 if (!AliPythiaRndm::GetPythiaRandom())
232 AliPythiaRndm::SetPythiaRandom(GetRandom());
236 AliGenPythia::~AliGenPythia()
239 if(fEventsTime) delete fEventsTime;
242 void AliGenPythia::SetInteractionRate(Float_t rate,Float_t timewindow)
244 // Generate pileup using user specified rate
245 fInteractionRate = rate;
246 fTimeWindow = timewindow;
250 void AliGenPythia::GeneratePileup()
252 // Generate sub events time for pileup
254 if(fInteractionRate == 0.) {
255 Warning("GeneratePileup","Zero interaction specified. Skipping pileup generation.\n");
259 Int_t npart = NumberParticles();
261 Warning("GeneratePileup","Negative number of particles. Skipping pileup generation.\n");
265 if(fEventsTime) delete fEventsTime;
266 fEventsTime = new TArrayF(npart);
267 TArrayF &array = *fEventsTime;
268 for(Int_t ipart = 0; ipart < npart; ipart++)
271 Float_t eventtime = 0.;
274 eventtime += (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
275 if(eventtime > fTimeWindow) break;
276 array.Set(array.GetSize()+1);
277 array[array.GetSize()-1] = eventtime;
283 eventtime -= (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
284 if(TMath::Abs(eventtime) > fTimeWindow) break;
285 array.Set(array.GetSize()+1);
286 array[array.GetSize()-1] = eventtime;
289 SetNumberParticles(fEventsTime->GetSize());
292 void AliGenPythia::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
293 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
295 // Set pycell parameters
296 fPycellEtaMax = etamax;
299 fPycellThreshold = thresh;
300 fPycellEtSeed = etseed;
301 fPycellMinEtJet = minet;
302 fPycellMaxRadius = r;
307 void AliGenPythia::SetEventListRange(Int_t eventFirst, Int_t eventLast)
309 // Set a range of event numbers, for which a table
310 // of generated particle will be printed
311 fDebugEventFirst = eventFirst;
312 fDebugEventLast = eventLast;
313 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
316 void AliGenPythia::Init()
320 SetMC(AliPythia::Instance());
321 fPythia=(AliPythia*) fMCEvGen;
324 fParentWeight=1./Float_t(fNpart);
328 fPythia->SetCKIN(3,fPtHardMin);
329 fPythia->SetCKIN(4,fPtHardMax);
330 fPythia->SetCKIN(7,fYHardMin);
331 fPythia->SetCKIN(8,fYHardMax);
333 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget, fNucPdf);
335 if (fFragmentation) {
336 fPythia->SetMSTP(111,1);
338 fPythia->SetMSTP(111,0);
342 // initial state radiation
343 fPythia->SetMSTP(61,fGinit);
344 // final state radiation
345 fPythia->SetMSTP(71,fGfinal);
348 fPythia->SetMSTP(91,1);
349 fPythia->SetPARP(91,fPtKick);
350 fPythia->SetPARP(93, 4. * fPtKick);
352 fPythia->SetMSTP(91,0);
357 fRL = AliRunLoader::Open(fFileName, "Partons");
358 fRL->LoadKinematics();
364 fPythia->ProcInit(fProcess,fEnergyCMS,fStrucFunc);
365 // Forward Paramters to the AliPythia object
366 fDecayer->SetForceDecay(fForceDecay);
367 // Switch off Heavy Flavors on request
369 // Maximum number of quark flavours used in pdf
370 fPythia->SetMSTP(58, 3);
371 // Maximum number of flavors that can be used in showers
372 fPythia->SetMSTJ(45, 3);
373 // Switch off g->QQbar splitting in decay table
374 ((AliDecayerPythia*) fDecayer)->HeavyFlavourOff();
380 // Parent and Children Selection
383 case kPyOldUEQ2ordered:
384 case kPyOldUEQ2ordered2:
388 case kPyCharmUnforced:
389 case kPyCharmPbPbMNR:
392 case kPyCharmppMNRwmi:
393 fParentSelect[0] = 411;
394 fParentSelect[1] = 421;
395 fParentSelect[2] = 431;
396 fParentSelect[3] = 4122;
397 fParentSelect[4] = 4232;
398 fParentSelect[5] = 4132;
399 fParentSelect[6] = 4332;
405 fParentSelect[0] = 421;
408 case kPyDPlusPbPbMNR:
411 fParentSelect[0] = 411;
414 case kPyDPlusStrangePbPbMNR:
415 case kPyDPlusStrangepPbMNR:
416 case kPyDPlusStrangeppMNR:
417 fParentSelect[0] = 431;
421 case kPyBeautyPbPbMNR:
422 case kPyBeautypPbMNR:
424 case kPyBeautyppMNRwmi:
425 fParentSelect[0]= 511;
426 fParentSelect[1]= 521;
427 fParentSelect[2]= 531;
428 fParentSelect[3]= 5122;
429 fParentSelect[4]= 5132;
430 fParentSelect[5]= 5232;
431 fParentSelect[6]= 5332;
434 case kPyBeautyUnforced:
435 fParentSelect[0] = 511;
436 fParentSelect[1] = 521;
437 fParentSelect[2] = 531;
438 fParentSelect[3] = 5122;
439 fParentSelect[4] = 5132;
440 fParentSelect[5] = 5232;
441 fParentSelect[6] = 5332;
446 fParentSelect[0] = 443;
450 case kPyMbWithDirectPhoton:
463 // JetFinder for Trigger
465 // Configure detector (EMCAL like)
467 fPythia->SetPARU(51, fPycellEtaMax);
468 fPythia->SetMSTU(51, fPycellNEta);
469 fPythia->SetMSTU(52, fPycellNPhi);
471 // Configure Jet Finder
473 fPythia->SetPARU(58, fPycellThreshold);
474 fPythia->SetPARU(52, fPycellEtSeed);
475 fPythia->SetPARU(53, fPycellMinEtJet);
476 fPythia->SetPARU(54, fPycellMaxRadius);
477 fPythia->SetMSTU(54, 2);
479 // This counts the total number of calls to Pyevnt() per run.
494 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
498 fPythia->InitQuenching(0., 0.1, 0.6e6, 0);
500 fPythia->SetPARJ(200, 0.0);
503 // Nestor's change of the splittings
504 fPythia->SetPARJ(200, 0.8);
505 fPythia->SetMSTJ(41, 1); // QCD radiation only
506 fPythia->SetMSTJ(42, 2); // angular ordering
507 fPythia->SetMSTJ(44, 2); // option to run alpha_s
508 fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
509 fPythia->SetMSTJ(50, 0); // No coherence in first branching
510 fPythia->SetPARJ(82, 1.); // Cut off for parton showers
514 void AliGenPythia::Generate()
516 // Generate one event
517 if (!fPythia) fPythia=(AliPythia*) fMCEvGen;
518 fDecayer->ForceDecay();
520 Float_t polar[3] = {0,0,0};
521 Float_t origin[3] = {0,0,0};
523 // converts from mm/c to s
524 const Float_t kconv=0.001/2.999792458e8;
534 // Set collision vertex position
535 if (fVertexSmear == kPerEvent) Vertex();
544 // Switch hadronisation off
546 fPythia->SetMSTJ(1, 0);
548 // Either produce new event or read partons from file
550 if (!fReadFromFile) {
556 fNpartons = fPythia->GetN();
558 printf("Loading Event %d\n",AliRunLoader::GetRunLoader()->GetEventNumber());
559 fRL->GetEvent(AliRunLoader::GetRunLoader()->GetEventNumber());
561 LoadEvent(fRL->Stack(), 0 , 1);
566 // Run quenching routine
570 } else if (fQuench == 2){
571 fPythia->Pyquen(208., 0, 0.);
572 } else if (fQuench == 3) {
573 // Quenching is via multiplicative correction of the splittings
577 // Switch hadronisation on
579 if (fHadronisation) {
580 fPythia->SetMSTJ(1, 1);
582 // .. and perform hadronisation
583 // printf("Calling hadronisation %d\n", fPythia->GetN());
587 fPythia->ImportParticles(&fParticles,"All");
595 Int_t np = fParticles.GetEntriesFast();
597 if (np == 0) continue;
601 Int_t* pParent = new Int_t[np];
602 Int_t* pSelected = new Int_t[np];
603 Int_t* trackIt = new Int_t[np];
604 for (i = 0; i < np; i++) {
610 Int_t nc = 0; // Total n. of selected particles
611 Int_t nParents = 0; // Selected parents
612 Int_t nTkbles = 0; // Trackable particles
613 if (fProcess != kPyMbDefault &&
615 fProcess != kPyMbWithDirectPhoton &&
616 fProcess != kPyJets &&
617 fProcess != kPyDirectGamma &&
618 fProcess != kPyMbNonDiffr &&
619 fProcess != kPyMbMSEL1 &&
622 fProcess != kPyCharmppMNRwmi &&
623 fProcess != kPyBeautyppMNRwmi) {
625 for (i = 0; i < np; i++) {
626 TParticle* iparticle = (TParticle *) fParticles.At(i);
627 Int_t ks = iparticle->GetStatusCode();
628 kf = CheckPDGCode(iparticle->GetPdgCode());
629 // No initial state partons
630 if (ks==21) continue;
632 // Heavy Flavor Selection
639 if (kfl > 100000) kfl %= 100000;
640 if (kfl > 10000) kfl %= 10000;
642 if (kfl > 10) kfl/=100;
644 if (kfl > 10) kfl/=10;
645 Int_t ipa = iparticle->GetFirstMother()-1;
648 // Establish mother daughter relation between heavy quarks and mesons
650 if (kf >= fFlavorSelect && kf <= 6) {
651 Int_t idau = iparticle->GetFirstDaughter() - 1;
653 TParticle* daughter = (TParticle *) fParticles.At(idau);
654 Int_t pdgD = daughter->GetPdgCode();
655 if (pdgD == 91 || pdgD == 92) {
656 Int_t jmin = daughter->GetFirstDaughter() - 1;
657 Int_t jmax = daughter->GetLastDaughter() - 1;
658 for (Int_t jp = jmin; jp <= jmax; jp++)
659 ((TParticle *) fParticles.At(jp))->SetFirstMother(i+1);
660 } // is string or cluster
666 TParticle * mother = (TParticle *) fParticles.At(ipa);
667 kfMo = TMath::Abs(mother->GetPdgCode());
670 // What to keep in Stack?
671 Bool_t flavorOK = kFALSE;
672 Bool_t selectOK = kFALSE;
674 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
676 if (kfl > fFlavorSelect) {
680 if (kfl == fFlavorSelect) flavorOK = kTRUE;
682 switch (fStackFillOpt) {
683 case kFlavorSelection:
686 case kParentSelection:
687 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
690 if (flavorOK && selectOK) {
692 // Heavy flavor hadron or quark
694 // Kinematic seletion on final state heavy flavor mesons
695 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
700 if (ParentSelected(kf)) ++nParents; // Update parent count
701 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
703 // Kinematic seletion on decay products
704 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
705 && !KinematicSelection(iparticle, 1))
711 // Select if mother was selected and is not tracked
713 if (pSelected[ipa] &&
714 !trackIt[ipa] && // mother will be tracked ?
715 kfMo != 5 && // mother is b-quark, don't store fragments
716 kfMo != 4 && // mother is c-quark, don't store fragments
717 kf != 92) // don't store string
720 // Semi-stable or de-selected: diselect decay products:
723 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
725 Int_t ipF = iparticle->GetFirstDaughter();
726 Int_t ipL = iparticle->GetLastDaughter();
727 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
729 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
730 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
733 if (pSelected[i] == -1) pSelected[i] = 0;
734 if (!pSelected[i]) continue;
735 // Count quarks only if you did not include fragmentation
736 if (fFragmentation && kf <= 10) continue;
739 // Decision on tracking
742 // Track final state particle
743 if (ks == 1) trackIt[i] = 1;
744 // Track semi-stable particles
745 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
746 // Track particles selected by process if undecayed.
747 if (fForceDecay == kNoDecay) {
748 if (ParentSelected(kf)) trackIt[i] = 1;
750 if (ParentSelected(kf)) trackIt[i] = 0;
752 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
756 } // particle selection loop
758 for (i = 0; i<np; i++) {
759 if (!pSelected[i]) continue;
760 TParticle * iparticle = (TParticle *) fParticles.At(i);
761 kf = CheckPDGCode(iparticle->GetPdgCode());
762 Int_t ks = iparticle->GetStatusCode();
763 p[0] = iparticle->Px();
764 p[1] = iparticle->Py();
765 p[2] = iparticle->Pz();
766 p[3] = iparticle->Energy();
768 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
769 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
770 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
772 Float_t tof = kconv*iparticle->T();
773 Int_t ipa = iparticle->GetFirstMother()-1;
774 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
776 PushTrack(fTrackIt*trackIt[i], iparent, kf,
777 p[0], p[1], p[2], p[3],
778 origin[0], origin[1], origin[2], tof,
779 polar[0], polar[1], polar[2],
780 kPPrimary, nt, 1., ks);
797 switch (fCountMode) {
799 // printf(" Count all \n");
803 // printf(" Count parents \n");
806 case kCountTrackables:
807 // printf(" Count trackable \n");
811 if (jev >= fNpart || fNpart == -1) {
812 fKineBias=Float_t(fNpart)/Float_t(fTrials);
814 fQ += fPythia->GetVINT(51);
815 fX1 += fPythia->GetVINT(41);
816 fX2 += fPythia->GetVINT(42);
817 fTrialsRun += fTrials;
824 SetHighWaterMark(nt);
825 // adjust weight due to kinematic selection
828 fXsection=fPythia->GetPARI(1);
831 Int_t AliGenPythia::GenerateMB()
834 // Min Bias selection and other global selections
836 Int_t i, kf, nt, iparent;
839 Float_t polar[3] = {0,0,0};
840 Float_t origin[3] = {0,0,0};
841 // converts from mm/c to s
842 const Float_t kconv=0.001/2.999792458e8;
846 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
850 Int_t* pParent = new Int_t[np];
851 for (i=0; i< np; i++) pParent[i] = -1;
852 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
853 TParticle* jet1 = (TParticle *) fParticles.At(6);
854 TParticle* jet2 = (TParticle *) fParticles.At(7);
855 if (!CheckTrigger(jet1, jet2)) {
861 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
862 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
867 if (fFragPhotonInCalo) pdg = 22 ; // Photon
868 else if (fPi0InCalo) pdg = 111 ; // Pi0
870 for (i=0; i< np; i++) {
871 TParticle* iparticle = (TParticle *) fParticles.At(i);
872 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
873 iparticle->Pt() > fFragPhotonOrPi0MinPt){
874 Int_t imother = iparticle->GetFirstMother() - 1;
875 TParticle* pmother = (TParticle *) fParticles.At(imother);
877 (pdg == 22 && pmother->GetStatusCode() != 11)) //No photon from hadron decay
879 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
880 Float_t eta =TMath::Abs(iparticle->Eta()); //in calos etamin=-etamax
881 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
882 (fCheckPHOS && IsInPHOS(phi,eta)) )
891 // Check for minimum multiplicity
892 if (fTriggerMultiplicity > 0) {
893 Int_t multiplicity = 0;
894 for (i = 0; i < np; i++) {
895 TParticle * iparticle = (TParticle *) fParticles.At(i);
897 Int_t statusCode = iparticle->GetStatusCode();
899 // Initial state particle
903 // skip quarks and gluons
904 Int_t pdgCode = TMath::Abs(iparticle->GetPdgCode());
905 if (pdgCode <= 10 || pdgCode == 21)
908 if (fTriggerMultiplicityEta > 0 && TMath::Abs(iparticle->Eta()) > fTriggerMultiplicityEta)
911 TParticlePDG* pdgPart = iparticle->GetPDG();
912 if (pdgPart && pdgPart->Charge() == 0)
918 if (multiplicity < fTriggerMultiplicity) {
923 Printf("Triggered on event with multiplicity of %d > %d", multiplicity, fTriggerMultiplicity);
926 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
927 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
933 for (i=0; i< np; i++) {
934 TParticle* iparticle = (TParticle *) fParticles.At(i);
935 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
936 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
938 if(iparticle->GetStatusCode() == 1
939 && iparticle->GetPdgCode() == pdg
940 && iparticle->Pt() > fPhotonMinPt
943 // first check if the photon is in PHOS phi
944 if(IsInPHOS(phi,eta)){
948 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
953 if(!okd && iphcand != -1) // execute rotation in phi
954 RotatePhi(iphcand,okd);
960 if (fTriggerParticle) {
961 Bool_t triggered = kFALSE;
962 for (i = 0; i < np; i++) {
963 TParticle * iparticle = (TParticle *) fParticles.At(i);
964 kf = CheckPDGCode(iparticle->GetPdgCode());
965 if (kf != fTriggerParticle) continue;
966 if (iparticle->Pt() == 0.) continue;
967 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
978 // Check if there is a ccbar or bbbar pair with at least one of the two
979 // in fYMin < y < fYMax
980 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi) {
981 TParticle *partCheck;
983 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
984 Bool_t theChild=kFALSE;
986 Int_t pdg,mpdg,mpdgUpperFamily;
987 for(i=0; i<np; i++) {
988 partCheck = (TParticle*)fParticles.At(i);
989 pdg = partCheck->GetPdgCode();
990 if(TMath::Abs(pdg) == fFlavorSelect) { // quark
991 if(pdg>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
992 y = 0.5*TMath::Log((partCheck->Energy()+partCheck->Pz()+1.e-13)/
993 (partCheck->Energy()-partCheck->Pz()+1.e-13));
994 if(y>fYMin && y<fYMax) inYcut=kTRUE;
996 if(fCutOnChild && TMath::Abs(pdg) == fPdgCodeParticleforAcceptanceCut) {
997 Int_t mi = partCheck->GetFirstMother() - 1;
999 mother = (TParticle*)fParticles.At(mi);
1000 mpdg=TMath::Abs(mother->GetPdgCode());
1001 mpdgUpperFamily=(mpdg>1000 ? mpdg-1000 : mpdg-100); // keep e from c from b
1002 if ( ParentSelected(mpdg) ||
1003 (fFlavorSelect==5 && ParentSelected(mpdgUpperFamily))) {
1004 if (KinematicSelection(partCheck,1)) {
1010 if (!theQ || !theQbar || !inYcut) { // one of the c/b conditions not satisfied
1014 if (fCutOnChild && !theChild) { // one of the child conditions not satisfied
1021 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
1022 if ( (fProcess == kPyW ||
1024 fProcess == kPyMbDefault ||
1025 fProcess == kPyMb ||
1026 fProcess == kPyMbWithDirectPhoton ||
1027 fProcess == kPyMbNonDiffr)
1028 && (fCutOnChild == 1) ) {
1029 if ( !CheckKinematicsOnChild() ) {
1036 for (i = 0; i < np; i++) {
1038 TParticle * iparticle = (TParticle *) fParticles.At(i);
1039 kf = CheckPDGCode(iparticle->GetPdgCode());
1040 Int_t ks = iparticle->GetStatusCode();
1041 Int_t km = iparticle->GetFirstMother();
1042 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
1044 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
1046 if (ks == 1) trackIt = 1;
1047 Int_t ipa = iparticle->GetFirstMother()-1;
1049 iparent = (ipa > -1) ? pParent[ipa] : -1;
1052 // store track information
1053 p[0] = iparticle->Px();
1054 p[1] = iparticle->Py();
1055 p[2] = iparticle->Pz();
1056 p[3] = iparticle->Energy();
1059 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
1060 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
1061 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
1063 Float_t tof = fEventTime + kconv * iparticle->T();
1065 PushTrack(fTrackIt*trackIt, iparent, kf,
1066 p[0], p[1], p[2], p[3],
1067 origin[0], origin[1], origin[2], tof,
1068 polar[0], polar[1], polar[2],
1069 kPPrimary, nt, 1., ks);
1073 SetHighWaterMark(nt);
1075 } // select particle
1084 void AliGenPythia::FinishRun()
1086 // Print x-section summary
1095 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1096 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1099 void AliGenPythia::AdjustWeights() const
1101 // Adjust the weights after generation of all events
1105 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1106 for (Int_t i=0; i<ntrack; i++) {
1107 part= gAlice->GetMCApp()->Particle(i);
1108 part->SetWeight(part->GetWeight()*fKineBias);
1113 void AliGenPythia::SetNuclei(Int_t a1, Int_t a2, Int_t pdfset)
1115 // Treat protons as inside nuclei with mass numbers a1 and a2
1119 fNucPdf = pdfset; // 0 EKS98 1 EPS08
1124 void AliGenPythia::MakeHeader()
1127 // Make header for the simulated event
1130 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1131 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->Pylist(2);
1134 // Builds the event header, to be called after each event
1135 if (fHeader) delete fHeader;
1136 fHeader = new AliGenPythiaEventHeader("Pythia");
1139 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->GetMSTI(1));
1142 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1145 fHeader->SetPrimaryVertex(fVertex);
1148 // Number of primaries
1149 fHeader->SetNProduced(fNprimaries);
1151 // Jets that have triggered
1153 if (fProcess == kPyJets || fProcess == kPyDirectGamma)
1156 Float_t jets[4][10];
1157 GetJets(njet, ntrig, jets);
1160 for (Int_t i = 0; i < ntrig; i++) {
1161 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1166 // Copy relevant information from external header, if present.
1171 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1172 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1174 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1177 exHeader->TriggerJet(i, uqJet);
1178 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1182 // Store quenching parameters
1189 fPythia->GetQuenchingParameters(xp, yp, z);
1192 Double_t r1 = PARIMP.rb1;
1193 Double_t r2 = PARIMP.rb2;
1194 Double_t b = PARIMP.b1;
1195 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1196 Double_t phi = PARIMP.psib1;
1197 xp = r * TMath::Cos(phi);
1198 yp = r * TMath::Sin(phi);
1201 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1202 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1206 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetVINT(47));
1214 Bool_t AliGenPythia::CheckTrigger(TParticle* jet1, TParticle* jet2)
1216 // Check the kinematic trigger condition
1219 eta[0] = jet1->Eta();
1220 eta[1] = jet2->Eta();
1222 phi[0] = jet1->Phi();
1223 phi[1] = jet2->Phi();
1225 pdg[0] = jet1->GetPdgCode();
1226 pdg[1] = jet2->GetPdgCode();
1227 Bool_t triggered = kFALSE;
1229 if (fProcess == kPyJets) {
1232 Float_t jets[4][10];
1234 // Use Pythia clustering on parton level to determine jet axis
1236 GetJets(njets, ntrig, jets);
1238 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1243 if (pdg[0] == kGamma) {
1247 //Check eta range first...
1248 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1249 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1251 //Eta is okay, now check phi range
1252 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1253 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1264 Bool_t AliGenPythia::CheckKinematicsOnChild(){
1266 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1268 Bool_t checking = kFALSE;
1269 Int_t j, kcode, ks, km;
1270 Int_t nPartAcc = 0; //number of particles in the acceptance range
1271 Int_t numberOfAcceptedParticles = 1;
1272 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1273 Int_t npart = fParticles.GetEntriesFast();
1275 for (j = 0; j<npart; j++) {
1276 TParticle * jparticle = (TParticle *) fParticles.At(j);
1277 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1278 ks = jparticle->GetStatusCode();
1279 km = jparticle->GetFirstMother();
1281 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1284 if( numberOfAcceptedParticles <= nPartAcc){
1293 void AliGenPythia::LoadEvent(AliStack* stack, Int_t flag, Int_t reHadr)
1296 // Load event into Pythia Common Block
1299 Int_t npart = stack -> GetNprimary();
1303 (fPythia->GetPyjets())->N = npart;
1305 n0 = (fPythia->GetPyjets())->N;
1306 (fPythia->GetPyjets())->N = n0 + npart;
1310 for (Int_t part = 0; part < npart; part++) {
1311 TParticle *mPart = stack->Particle(part);
1313 Int_t kf = mPart->GetPdgCode();
1314 Int_t ks = mPart->GetStatusCode();
1315 Int_t idf = mPart->GetFirstDaughter();
1316 Int_t idl = mPart->GetLastDaughter();
1319 if (ks == 11 || ks == 12) {
1326 Float_t px = mPart->Px();
1327 Float_t py = mPart->Py();
1328 Float_t pz = mPart->Pz();
1329 Float_t e = mPart->Energy();
1330 Float_t m = mPart->GetCalcMass();
1333 (fPythia->GetPyjets())->P[0][part+n0] = px;
1334 (fPythia->GetPyjets())->P[1][part+n0] = py;
1335 (fPythia->GetPyjets())->P[2][part+n0] = pz;
1336 (fPythia->GetPyjets())->P[3][part+n0] = e;
1337 (fPythia->GetPyjets())->P[4][part+n0] = m;
1339 (fPythia->GetPyjets())->K[1][part+n0] = kf;
1340 (fPythia->GetPyjets())->K[0][part+n0] = ks;
1341 (fPythia->GetPyjets())->K[3][part+n0] = idf + 1;
1342 (fPythia->GetPyjets())->K[4][part+n0] = idl + 1;
1343 (fPythia->GetPyjets())->K[2][part+n0] = mPart->GetFirstMother() + 1;
1348 void AliGenPythia::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1351 // Calls the Pythia jet finding algorithm to find jets in the current event
1356 Int_t n = fPythia->GetN();
1360 fPythia->Pycell(njets);
1362 for (i = 0; i < njets; i++) {
1363 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1364 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1365 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1366 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1377 void AliGenPythia::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1380 // Calls the Pythia clustering algorithm to find jets in the current event
1382 Int_t n = fPythia->GetN();
1385 if (fJetReconstruction == kCluster) {
1387 // Configure cluster algorithm
1389 fPythia->SetPARU(43, 2.);
1390 fPythia->SetMSTU(41, 1);
1392 // Call cluster algorithm
1394 fPythia->Pyclus(nJets);
1396 // Loading jets from common block
1402 fPythia->Pycell(nJets);
1406 for (i = 0; i < nJets; i++) {
1407 Float_t px = (fPythia->GetPyjets())->P[0][n+i];
1408 Float_t py = (fPythia->GetPyjets())->P[1][n+i];
1409 Float_t pz = (fPythia->GetPyjets())->P[2][n+i];
1410 Float_t e = (fPythia->GetPyjets())->P[3][n+i];
1411 Float_t pt = TMath::Sqrt(px * px + py * py);
1412 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1413 Float_t theta = TMath::ATan2(pt,pz);
1414 Float_t et = e * TMath::Sin(theta);
1415 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1417 eta > fEtaMinJet && eta < fEtaMaxJet &&
1418 phi > fPhiMinJet && phi < fPhiMaxJet &&
1419 et > fEtMinJet && et < fEtMaxJet
1422 jets[0][nJetsTrig] = px;
1423 jets[1][nJetsTrig] = py;
1424 jets[2][nJetsTrig] = pz;
1425 jets[3][nJetsTrig] = e;
1427 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1429 // printf("\n........-Jet #%d: %10.3f %10.3f %10.3f %10.3f \n", i, pt, et, eta, phi * kRaddeg);
1434 void AliGenPythia::GetSubEventTime()
1436 // Calculates time of the next subevent
1439 TArrayF &array = *fEventsTime;
1440 fEventTime = array[fCurSubEvent++];
1442 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1446 Bool_t AliGenPythia::IsInEMCAL(Float_t phi, Float_t eta)
1448 // Is particle in EMCAL acceptance?
1449 // phi in degrees, etamin=-etamax
1450 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1457 Bool_t AliGenPythia::IsInPHOS(Float_t phi, Float_t eta)
1459 // Is particle in PHOS acceptance?
1460 // Acceptance slightly larger considered.
1461 // phi in degrees, etamin=-etamax
1462 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1469 void AliGenPythia::RotatePhi(Int_t iphcand, Bool_t& okdd)
1471 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1472 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1473 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1474 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1476 //calculate deltaphi
1477 TParticle* ph = (TParticle *) fParticles.At(iphcand);
1478 Double_t phphi = ph->Phi();
1479 Double_t deltaphi = phiPHOS - phphi;
1483 //loop for all particles and produce the phi rotation
1484 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
1485 Double_t oldphi, newphi;
1486 Double_t newVx, newVy, R, Vz, time;
1487 Double_t newPx, newPy, pt, Pz, e;
1488 for(Int_t i=0; i< np; i++) {
1489 TParticle* iparticle = (TParticle *) fParticles.At(i);
1490 oldphi = iparticle->Phi();
1491 newphi = oldphi + deltaphi;
1492 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1493 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1496 newVx = R*TMath::Cos(newphi);
1497 newVy = R*TMath::Sin(newphi);
1498 Vz = iparticle->Vz(); // don't transform
1499 time = iparticle->T(); // don't transform
1501 pt = iparticle->Pt();
1502 newPx = pt*TMath::Cos(newphi);
1503 newPy = pt*TMath::Sin(newphi);
1504 Pz = iparticle->Pz(); // don't transform
1505 e = iparticle->Energy(); // don't transform
1508 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1509 iparticle->SetMomentum(newPx, newPy, Pz, e);
1511 } //end particle loop
1513 // now let's check that we put correctly the candidate photon in PHOS
1514 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1515 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1516 if(IsInPHOS(phi,eta))
1522 void AliGenPythia::Streamer(TBuffer &R__b)
1524 // Stream an object of class AliGenPythia.
1526 if (R__b.IsReading()) {
1527 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1528 AliGenerator::Streamer(R__b);
1529 R__b >> (Int_t&)fProcess;
1530 R__b >> (Int_t&)fStrucFunc;
1531 R__b >> (Int_t&)fForceDecay;
1535 fParentSelect.Streamer(R__b);
1536 fChildSelect.Streamer(R__b);
1538 // (AliPythia::Instance())->Streamer(R__b);
1541 // if (fDecayer) fDecayer->Streamer(R__b);
1543 R__b.WriteVersion(AliGenPythia::IsA());
1544 AliGenerator::Streamer(R__b);
1545 R__b << (Int_t)fProcess;
1546 R__b << (Int_t)fStrucFunc;
1547 R__b << (Int_t)fForceDecay;
1551 fParentSelect.Streamer(R__b);
1552 fChildSelect.Streamer(R__b);
1557 // fDecayer->Streamer(R__b);