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 "AliGenPythiaPlus.h"
37 #include "AliHeader.h"
38 #include "AliGenPythiaEventHeader.h"
39 #include "AliPythiaBase.h"
40 #include "AliPythiaRndm.h"
43 #include "AliRunLoader.h"
45 #include "PyquenCommon.h"
47 ClassImp(AliGenPythiaPlus)
50 AliGenPythiaPlus::AliGenPythiaPlus():
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 fCountMode(kCountAll),
114 fFragPhotonInCalo(kFALSE),
116 fPhotonInCalo(kFALSE),
119 fCheckPHOSeta(kFALSE),
120 fFragPhotonOrPi0MinPt(0),
130 // Default Constructor
133 if (!AliPythiaRndm::GetPythiaRandom())
134 AliPythiaRndm::SetPythiaRandom(GetRandom());
137 AliGenPythiaPlus::AliGenPythiaPlus(AliPythiaBase* pythia)
149 fInteractionRate(0.),
162 fHadronisation(kTRUE),
164 fReadFromFile(kFALSE),
168 fDecayer(new AliDecayerPythia()),
169 fDebugEventFirst(-1),
176 fPhiMaxJet(2.* TMath::Pi()),
177 fJetReconstruction(kCell),
181 fPhiMaxGamma(2. * TMath::Pi()),
185 fPycellThreshold(0.),
187 fPycellMinEtJet(10.),
188 fPycellMaxRadius(1.),
189 fStackFillOpt(kFlavorSelection),
191 fFragmentation(kTRUE),
197 fCountMode(kCountAll),
201 fFragPhotonInCalo(kFALSE),
203 fPhotonInCalo(kFALSE),
206 fCheckPHOSeta(kFALSE),
207 fFragPhotonOrPi0MinPt(0),
216 // default charm production at 5. 5 TeV
218 // structure function GRVHO
222 fTitle= "Particle Generator using PYTHIA";
224 // Set random number generator
225 if (!AliPythiaRndm::GetPythiaRandom())
226 AliPythiaRndm::SetPythiaRandom(GetRandom());
230 AliGenPythiaPlus::~AliGenPythiaPlus()
233 if(fEventsTime) delete fEventsTime;
236 void AliGenPythiaPlus::SetInteractionRate(Float_t rate,Float_t timewindow)
238 // Generate pileup using user specified rate
239 fInteractionRate = rate;
240 fTimeWindow = timewindow;
244 void AliGenPythiaPlus::GeneratePileup()
246 // Generate sub events time for pileup
248 if(fInteractionRate == 0.) {
249 Warning("GeneratePileup","Zero interaction specified. Skipping pileup generation.\n");
253 Int_t npart = NumberParticles();
255 Warning("GeneratePileup","Negative number of particles. Skipping pileup generation.\n");
259 if(fEventsTime) delete fEventsTime;
260 fEventsTime = new TArrayF(npart);
261 TArrayF &array = *fEventsTime;
262 for(Int_t ipart = 0; ipart < npart; ipart++)
265 Float_t eventtime = 0.;
268 eventtime += (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
269 if(eventtime > fTimeWindow) break;
270 array.Set(array.GetSize()+1);
271 array[array.GetSize()-1] = eventtime;
277 eventtime -= (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
278 if(TMath::Abs(eventtime) > fTimeWindow) break;
279 array.Set(array.GetSize()+1);
280 array[array.GetSize()-1] = eventtime;
283 SetNumberParticles(fEventsTime->GetSize());
286 void AliGenPythiaPlus::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
287 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
289 // Set pycell parameters
290 fPycellEtaMax = etamax;
293 fPycellThreshold = thresh;
294 fPycellEtSeed = etseed;
295 fPycellMinEtJet = minet;
296 fPycellMaxRadius = r;
301 void AliGenPythiaPlus::SetEventListRange(Int_t eventFirst, Int_t eventLast)
303 // Set a range of event numbers, for which a table
304 // of generated particle will be printed
305 fDebugEventFirst = eventFirst;
306 fDebugEventLast = eventLast;
307 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
310 void AliGenPythiaPlus::Init()
314 // SetMC(AliPythia::Instance());
315 // fPythia=(AliPythia*) fMCEvGen;
318 fParentWeight=1./Float_t(fNpart);
322 fPythia->SetPtHardRange(fPtHardMin, fPtHardMax);
323 fPythia->SetYHardRange(fYHardMin, fYHardMax);
325 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget);
327 if (fFragmentation) {
328 fPythia->SetFragmentation(1);
330 fPythia->SetFragmentation(0);
334 // initial state radiation
335 fPythia->SetInitialAndFinalStateRadiation(fGinit, fGfinal);
338 fPythia->SetIntrinsicKt(fPtKick);
341 fRL = AliRunLoader::Open(fFileName, "Partons");
342 fRL->LoadKinematics();
348 fPythia->ProcInit(fProcess, fEnergyCMS, fStrucFunc);
349 // Forward Paramters to the AliPythia object
350 fDecayer->SetForceDecay(fForceDecay);
351 // Switch off Heavy Flavors on request
353 fPythia->SwitchHFOff();
354 // Switch off g->QQbar splitting in decay table
355 ((AliDecayerPythia*) fDecayer)->HeavyFlavourOff();
361 // Parent and Children Selection
364 case kPyOldUEQ2ordered:
365 case kPyOldUEQ2ordered2:
369 case kPyCharmUnforced:
370 case kPyCharmPbPbMNR:
373 case kPyCharmppMNRwmi:
374 fParentSelect[0] = 411;
375 fParentSelect[1] = 421;
376 fParentSelect[2] = 431;
377 fParentSelect[3] = 4122;
378 fParentSelect[4] = 4232;
379 fParentSelect[5] = 4132;
380 fParentSelect[6] = 4332;
386 fParentSelect[0] = 421;
389 case kPyDPlusPbPbMNR:
392 fParentSelect[0] = 411;
395 case kPyDPlusStrangePbPbMNR:
396 case kPyDPlusStrangepPbMNR:
397 case kPyDPlusStrangeppMNR:
398 fParentSelect[0] = 431;
401 case kPyLambdacppMNR:
402 fParentSelect[0] = 4122;
407 case kPyBeautyPbPbMNR:
408 case kPyBeautypPbMNR:
410 case kPyBeautyppMNRwmi:
411 fParentSelect[0]= 511;
412 fParentSelect[1]= 521;
413 fParentSelect[2]= 531;
414 fParentSelect[3]= 5122;
415 fParentSelect[4]= 5132;
416 fParentSelect[5]= 5232;
417 fParentSelect[6]= 5332;
420 case kPyBeautyUnforced:
421 fParentSelect[0] = 511;
422 fParentSelect[1] = 521;
423 fParentSelect[2] = 531;
424 fParentSelect[3] = 5122;
425 fParentSelect[4] = 5132;
426 fParentSelect[5] = 5232;
427 fParentSelect[6] = 5332;
432 fParentSelect[0] = 443;
434 case kPyMbAtlasTuneMC09:
437 case kPyMbWithDirectPhoton:
450 // JetFinder for Trigger
452 // Configure detector (EMCAL like)
454 fPythia->SetPycellParameters(fPycellEtaMax,fPycellNEta, fPycellNPhi,
455 fPycellThreshold, fPycellEtSeed,
456 fPycellMinEtJet, fPycellMaxRadius);
458 // This counts the total number of calls to Pyevnt() per run.
473 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
477 fPythia->InitQuenching(0., 0.1, 0.6e6, 0, 0.97, 30);
480 // fPythia->SetPARJ(200, 0.0);
482 // if (fQuench == 3) {
483 // // Nestor's change of the splittings
484 // fPythia->SetPARJ(200, 0.8);
485 // fPythia->SetMSTJ(41, 1); // QCD radiation only
486 // fPythia->SetMSTJ(42, 2); // angular ordering
487 // fPythia->SetMSTJ(44, 2); // option to run alpha_s
488 // fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
489 // fPythia->SetMSTJ(50, 0); // No coherence in first branching
490 // fPythia->SetPARJ(82, 1.); // Cut off for parton showers
494 void AliGenPythiaPlus::Generate()
496 // Generate one event
498 fDecayer->ForceDecay();
500 Float_t polar[3] = {0,0,0};
501 Float_t origin[3] = {0,0,0};
503 // converts from mm/c to s
504 const Float_t kconv=0.001/2.999792458e8;
514 // Set collision vertex position
515 if (fVertexSmear == kPerEvent) Vertex();
524 // Switch hadronisation off
526 // fPythia->SwitchHadronisationOff();
528 // Either produce new event or read partons from file
530 if (!fReadFromFile) {
532 fPythia->GenerateEvent();
534 fPythia->GenerateMIEvent();
536 fNpartons = fPythia->GetNumberOfParticles();
538 printf("Loading Event %d\n",AliRunLoader::Instance()->GetEventNumber());
539 fRL->GetEvent(AliRunLoader::Instance()->GetEventNumber());
540 fPythia->SetNumberOfParticles(0);
541 fPythia->LoadEvent(fRL->Stack(), 0 , 1);
542 fPythia->EditEventList(21);
546 // Run quenching routine
550 } else if (fQuench == 2){
551 fPythia->Pyquen(208., 0, 0.);
552 } else if (fQuench == 3) {
553 // Quenching is via multiplicative correction of the splittings
557 // Switch hadronisation on
559 // fPythia->SwitchHadronisationOn();
561 // .. and perform hadronisation
562 // printf("Calling hadronisation %d\n", fPythia->GetN());
563 // fPythia->HadronizeEvent();
565 fPythia->GetParticles(&fParticles);
573 Int_t np = fParticles.GetEntriesFast();
575 if (np == 0) continue;
579 Int_t* pParent = new Int_t[np];
580 Int_t* pSelected = new Int_t[np];
581 Int_t* trackIt = new Int_t[np];
582 for (i = 0; i < np; i++) {
588 Int_t nc = 0; // Total n. of selected particles
589 Int_t nParents = 0; // Selected parents
590 Int_t nTkbles = 0; // Trackable particles
591 if (fProcess != kPyMbDefault &&
593 fProcess != kPyMbWithDirectPhoton &&
594 fProcess != kPyJets &&
595 fProcess != kPyDirectGamma &&
596 fProcess != kPyMbNonDiffr &&
597 fProcess != kPyMbMSEL1 &&
600 fProcess != kPyCharmppMNRwmi &&
601 fProcess != kPyBeautyppMNRwmi) {
603 for (i = 0; i < np; i++) {
604 TParticle* iparticle = (TParticle *) fParticles.At(i);
605 Int_t ks = iparticle->GetStatusCode();
606 kf = CheckPDGCode(iparticle->GetPdgCode());
607 // No initial state partons
608 if (ks==21) continue;
610 // Heavy Flavor Selection
617 if (kfl > 100000) kfl %= 100000;
618 if (kfl > 10000) kfl %= 10000;
620 if (kfl > 10) kfl/=100;
622 if (kfl > 10) kfl/=10;
623 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
626 // Establish mother daughter relation between heavy quarks and mesons
628 if (kf >= fFlavorSelect && kf <= 6) {
629 Int_t idau = (fPythia->Version() == 6) ? (iparticle->GetFirstDaughter() - 1) :(iparticle->GetFirstDaughter());
631 TParticle* daughter = (TParticle *) fParticles.At(idau);
632 Int_t pdgD = daughter->GetPdgCode();
633 if (pdgD == 91 || pdgD == 92) {
634 Int_t jmin = (fPythia->Version() == 6) ? (daughter->GetFirstDaughter() - 1) : (daughter->GetFirstDaughter());
635 Int_t jmax = (fPythia->Version() == 6) ? (daughter->GetLastDaughter() - 1) : (daughter->GetLastDaughter());
637 for (Int_t jp = jmin; jp <= jmax; jp++)
638 ((TParticle *) fParticles.At(jp))->SetFirstMother(i+1);
639 } // is string or cluster
645 TParticle * mother = (TParticle *) fParticles.At(ipa);
646 kfMo = TMath::Abs(mother->GetPdgCode());
649 // What to keep in Stack?
650 Bool_t flavorOK = kFALSE;
651 Bool_t selectOK = kFALSE;
653 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
655 if (kfl > fFlavorSelect) {
659 if (kfl == fFlavorSelect) flavorOK = kTRUE;
661 switch (fStackFillOpt) {
662 case kFlavorSelection:
665 case kParentSelection:
666 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
669 if (flavorOK && selectOK) {
671 // Heavy flavor hadron or quark
673 // Kinematic seletion on final state heavy flavor mesons
674 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
679 if (ParentSelected(kf)) ++nParents; // Update parent count
680 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
682 // Kinematic seletion on decay products
683 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
684 && !KinematicSelection(iparticle, 1))
690 // Select if mother was selected and is not tracked
692 if (pSelected[ipa] &&
693 !trackIt[ipa] && // mother will be tracked ?
694 kfMo != 5 && // mother is b-quark, don't store fragments
695 kfMo != 4 && // mother is c-quark, don't store fragments
696 kf != 92) // don't store string
699 // Semi-stable or de-selected: diselect decay products:
702 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
704 Int_t ipF = iparticle->GetFirstDaughter();
705 Int_t ipL = iparticle->GetLastDaughter();
706 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
708 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
709 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
712 if (pSelected[i] == -1) pSelected[i] = 0;
713 if (!pSelected[i]) continue;
714 // Count quarks only if you did not include fragmentation
715 if (fFragmentation && kf <= 10) continue;
718 // Decision on tracking
721 // Track final state particle
722 if (ks == 1) trackIt[i] = 1;
723 // Track semi-stable particles
724 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
725 // Track particles selected by process if undecayed.
726 if (fForceDecay == kNoDecay) {
727 if (ParentSelected(kf)) trackIt[i] = 1;
729 if (ParentSelected(kf)) trackIt[i] = 0;
731 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
735 } // particle selection loop
737 for (i = 0; i < np; i++) {
738 if (!pSelected[i]) continue;
739 TParticle * iparticle = (TParticle *) fParticles.At(i);
740 kf = CheckPDGCode(iparticle->GetPdgCode());
741 Int_t ks = iparticle->GetStatusCode();
742 p[0] = iparticle->Px();
743 p[1] = iparticle->Py();
744 p[2] = iparticle->Pz();
745 p[3] = iparticle->Energy();
747 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
748 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
749 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
751 Float_t tof = kconv*iparticle->T();
752 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
753 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
755 PushTrack(fTrackIt*trackIt[i], iparent, kf,
756 p[0], p[1], p[2], p[3],
757 origin[0], origin[1], origin[2], tof,
758 polar[0], polar[1], polar[2],
759 kPPrimary, nt, 1., ks);
776 switch (fCountMode) {
778 // printf(" Count all \n");
782 // printf(" Count parents \n");
785 case kCountTrackables:
786 // printf(" Count trackable \n");
790 if (jev >= fNpart || fNpart == -1) {
791 fKineBias=Float_t(fNpart)/Float_t(fTrials);
792 fPythia->GetXandQ(fQ, fX1, fX2);
793 fTrialsRun += fTrials;
800 SetHighWaterMark(nt);
801 // Adjust weight due to kinematic selection
804 fXsection = fPythia->GetXSection();
807 Int_t AliGenPythiaPlus::GenerateMB()
810 // Min Bias selection and other global selections
812 Int_t i, kf, nt, iparent;
815 Float_t polar[3] = {0,0,0};
816 Float_t origin[3] = {0,0,0};
817 // converts from mm/c to s
818 const Float_t kconv = 0.001 / 2.999792458e8;
820 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
822 Int_t* pParent = new Int_t[np];
823 for (i=0; i< np; i++) pParent[i] = -1;
824 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
825 TParticle* jet1 = (TParticle *) fParticles.At(6);
826 TParticle* jet2 = (TParticle *) fParticles.At(7);
827 if (!CheckTrigger(jet1, jet2)) {
833 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
834 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
839 if (fFragPhotonInCalo) pdg = 22 ; // Photon
840 else if (fPi0InCalo) pdg = 111 ; // Pi0
842 for (i=0; i< np; i++) {
843 TParticle* iparticle = (TParticle *) fParticles.At(i);
844 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
845 iparticle->Pt() > fFragPhotonOrPi0MinPt){
846 Int_t imother = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
847 TParticle* pmother = (TParticle *) fParticles.At(imother);
849 (pdg == 22 && pmother->GetStatusCode() != 11))//No photon from hadron decay
851 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
852 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
853 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
854 (fCheckPHOS && IsInPHOS(phi,eta)) )
864 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
865 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
871 for (i=0; i< np; i++) {
872 TParticle* iparticle = (TParticle *) fParticles.At(i);
873 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
874 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
876 if(iparticle->GetStatusCode() == 1
877 && iparticle->GetPdgCode() == pdg
878 && iparticle->Pt() > fPhotonMinPt
881 // first check if the photon is in PHOS phi
882 if(IsInPHOS(phi,eta)){
886 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
891 if(!okd && iphcand != -1) // execute rotation in phi
892 RotatePhi(iphcand,okd);
898 if (fTriggerParticle) {
899 Bool_t triggered = kFALSE;
900 for (i = 0; i < np; i++) {
901 TParticle * iparticle = (TParticle *) fParticles.At(i);
902 kf = CheckPDGCode(iparticle->GetPdgCode());
903 if (kf != fTriggerParticle) continue;
904 if (iparticle->Pt() == 0.) continue;
905 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
916 // Check if there is a ccbar or bbbar pair with at least one of the two
917 // in fYMin < y < fYMax
918 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi) {
919 TParticle *partCheck;
921 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
922 Bool_t theChild=kFALSE;
924 Int_t pdg,mpdg,mpdgUpperFamily;
925 for(i=0; i<np; i++) {
926 partCheck = (TParticle*)fParticles.At(i);
927 pdg = partCheck->GetPdgCode();
928 if(TMath::Abs(pdg) == fFlavorSelect) { // quark
929 if(pdg>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
930 y = 0.5*TMath::Log((partCheck->Energy()+partCheck->Pz()+1.e-13)/
931 (partCheck->Energy()-partCheck->Pz()+1.e-13));
932 if(y>fYMin && y<fYMax) inYcut=kTRUE;
935 if(fCutOnChild && TMath::Abs(pdg) == fPdgCodeParticleforAcceptanceCut) {
936 Int_t mi = partCheck->GetFirstMother() - 1;
938 mother = (TParticle*)fParticles.At(mi);
939 mpdg=TMath::Abs(mother->GetPdgCode());
940 mpdgUpperFamily=(mpdg>1000 ? mpdg+1000 : mpdg+100); // keep e from c from b
941 if ( ParentSelected(mpdg) ||
942 (fFlavorSelect==5 && ParentSelected(mpdgUpperFamily))) {
943 if (KinematicSelection(partCheck,1)) {
949 if (!theQ || !theQbar || !inYcut) { // one of the c/b conditions not satisfied
953 if (fCutOnChild && !theChild) { // one of the child conditions not satisfied
960 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
961 if ( (fProcess == kPyW ||
963 fProcess == kPyMbDefault ||
965 fProcess == kPyMbWithDirectPhoton ||
966 fProcess == kPyMbNonDiffr)
967 && (fCutOnChild == 1) ) {
968 if ( !CheckKinematicsOnChild() ) {
975 for (i = 0; i < np; i++) {
977 TParticle * iparticle = (TParticle *) fParticles.At(i);
978 kf = CheckPDGCode(iparticle->GetPdgCode());
979 Int_t ks = iparticle->GetStatusCode();
980 Int_t km = iparticle->GetFirstMother();
981 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
983 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
985 if (ks == 1) trackIt = 1;
987 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
988 iparent = (ipa > -1) ? pParent[ipa] : -1;
989 if (ipa >= np) fPythia->EventListing();
992 // store track information
993 p[0] = iparticle->Px();
994 p[1] = iparticle->Py();
995 p[2] = iparticle->Pz();
996 p[3] = iparticle->Energy();
999 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
1000 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
1001 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
1003 Float_t tof = fEventTime + kconv * iparticle->T();
1005 PushTrack(fTrackIt*trackIt, iparent, kf,
1006 p[0], p[1], p[2], p[3],
1007 origin[0], origin[1], origin[2], tof,
1008 polar[0], polar[1], polar[2],
1009 kPPrimary, nt, 1., ks);
1014 // Special Treatment to store color-flow
1016 if (ks == 3 || ks == 13 || ks == 14) {
1017 TParticle* particle = 0;
1019 particle = fStack->Particle(nt);
1021 particle = AliRunLoader::Instance()->Stack()->Particle(nt);
1023 // particle->SetFirstDaughter(fPythia->GetK(2, i));
1024 // particle->SetLastDaughter(fPythia->GetK(3, i));
1029 SetHighWaterMark(nt);
1031 } // select particle
1040 void AliGenPythiaPlus::FinishRun()
1042 // Print x-section summary
1043 fPythia->PrintStatistics();
1051 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1052 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1055 void AliGenPythiaPlus::AdjustWeights() const
1057 // Adjust the weights after generation of all events
1061 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1062 for (Int_t i=0; i<ntrack; i++) {
1063 part= gAlice->GetMCApp()->Particle(i);
1064 part->SetWeight(part->GetWeight()*fKineBias);
1069 void AliGenPythiaPlus::SetNuclei(Int_t a1, Int_t a2)
1071 // Treat protons as inside nuclei with mass numbers a1 and a2
1079 void AliGenPythiaPlus::MakeHeader()
1082 // Make header for the simulated event
1085 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1086 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->EventListing();
1089 // Builds the event header, to be called after each event
1090 if (fHeader) delete fHeader;
1091 fHeader = new AliGenPythiaEventHeader("Pythia");
1094 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->ProcessCode());
1097 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1100 fHeader->SetPrimaryVertex(fVertex);
1103 // Number of primaries
1104 fHeader->SetNProduced(fNprimaries);
1106 // Jets that have triggered
1108 if (fProcess == kPyJets)
1111 Float_t jets[4][10];
1112 GetJets(njet, ntrig, jets);
1115 for (Int_t i = 0; i < ntrig; i++) {
1116 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1121 // Copy relevant information from external header, if present.
1126 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1127 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1129 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1132 exHeader->TriggerJet(i, uqJet);
1133 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1137 // Store quenching parameters
1144 fPythia->GetQuenchingParameters(xp, yp, z);
1147 Double_t r1 = PARIMP.rb1;
1148 Double_t r2 = PARIMP.rb2;
1149 Double_t b = PARIMP.b1;
1150 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1151 Double_t phi = PARIMP.psib1;
1152 xp = r * TMath::Cos(phi);
1153 yp = r * TMath::Sin(phi);
1156 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1157 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1161 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetPtHard());
1169 Bool_t AliGenPythiaPlus::CheckTrigger(TParticle* jet1, TParticle* jet2)
1171 // Check the kinematic trigger condition
1174 eta[0] = jet1->Eta();
1175 eta[1] = jet2->Eta();
1177 phi[0] = jet1->Phi();
1178 phi[1] = jet2->Phi();
1180 pdg[0] = jet1->GetPdgCode();
1181 pdg[1] = jet2->GetPdgCode();
1182 Bool_t triggered = kFALSE;
1184 if (fProcess == kPyJets) {
1187 Float_t jets[4][10];
1189 // Use Pythia clustering on parton level to determine jet axis
1191 GetJets(njets, ntrig, jets);
1193 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1198 if (pdg[0] == kGamma) {
1202 //Check eta range first...
1203 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1204 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1206 //Eta is okay, now check phi range
1207 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1208 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1219 Bool_t AliGenPythiaPlus::CheckKinematicsOnChild(){
1221 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1223 Bool_t checking = kFALSE;
1224 Int_t j, kcode, ks, km;
1225 Int_t nPartAcc = 0; //number of particles in the acceptance range
1226 Int_t numberOfAcceptedParticles = 1;
1227 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1228 Int_t npart = fParticles.GetEntriesFast();
1230 for (j = 0; j<npart; j++) {
1231 TParticle * jparticle = (TParticle *) fParticles.At(j);
1232 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1233 ks = jparticle->GetStatusCode();
1234 km = jparticle->GetFirstMother();
1236 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1239 if( numberOfAcceptedParticles <= nPartAcc){
1248 void AliGenPythiaPlus::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1251 // Calls the Pythia jet finding algorithm to find jets in the current event
1258 fPythia->Pycell(njets);
1260 for (i = 0; i < njets; i++) {
1261 Float_t px, py, pz, e;
1262 fPythia->GetJet(i, px, py, pz, e);
1271 void AliGenPythiaPlus::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1274 // Calls the Pythia clustering algorithm to find jets in the current event
1278 if (fJetReconstruction == kCluster) {
1280 // Configure cluster algorithm
1282 // fPythia->SetPARU(43, 2.);
1283 // fPythia->SetMSTU(41, 1);
1285 // Call cluster algorithm
1287 fPythia->Pyclus(nJets);
1289 // Loading jets from common block
1295 fPythia->Pycell(nJets);
1299 for (i = 0; i < nJets; i++) {
1300 Float_t px, py, pz, e;
1301 fPythia->GetJet(i, px, py, pz, e);
1302 Float_t pt = TMath::Sqrt(px * px + py * py);
1303 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1304 Float_t theta = TMath::ATan2(pt,pz);
1305 Float_t et = e * TMath::Sin(theta);
1306 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1308 eta > fEtaMinJet && eta < fEtaMaxJet &&
1309 phi > fPhiMinJet && phi < fPhiMaxJet &&
1310 et > fEtMinJet && et < fEtMaxJet
1313 jets[0][nJetsTrig] = px;
1314 jets[1][nJetsTrig] = py;
1315 jets[2][nJetsTrig] = pz;
1316 jets[3][nJetsTrig] = e;
1323 void AliGenPythiaPlus::GetSubEventTime()
1325 // Calculates time of the next subevent
1328 TArrayF &array = *fEventsTime;
1329 fEventTime = array[fCurSubEvent++];
1331 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1338 Bool_t AliGenPythiaPlus::IsInEMCAL(Float_t phi, Float_t eta)
1340 // Is particle in EMCAL acceptance?
1341 // phi in degrees, etamin=-etamax
1342 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1349 Bool_t AliGenPythiaPlus::IsInPHOS(Float_t phi, Float_t eta)
1351 // Is particle in PHOS acceptance?
1352 // Acceptance slightly larger considered.
1353 // phi in degrees, etamin=-etamax
1354 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1361 void AliGenPythiaPlus::RotatePhi(Int_t iphcand, Bool_t& okdd)
1363 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1364 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1365 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1366 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1368 //calculate deltaphi
1369 TParticle* ph = (TParticle *) fParticles.At(iphcand);
1370 Double_t phphi = ph->Phi();
1371 Double_t deltaphi = phiPHOS - phphi;
1375 //loop for all particles and produce the phi rotation
1376 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
1377 Double_t oldphi, newphi;
1378 Double_t newVx, newVy, R, Vz, time;
1379 Double_t newPx, newPy, pt, Pz, e;
1380 for(Int_t i=0; i< np; i++) {
1381 TParticle* iparticle = (TParticle *) fParticles.At(i);
1382 oldphi = iparticle->Phi();
1383 newphi = oldphi + deltaphi;
1384 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1385 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1388 newVx = R*TMath::Cos(newphi);
1389 newVy = R*TMath::Sin(newphi);
1390 Vz = iparticle->Vz(); // don't transform
1391 time = iparticle->T(); // don't transform
1393 pt = iparticle->Pt();
1394 newPx = pt*TMath::Cos(newphi);
1395 newPy = pt*TMath::Sin(newphi);
1396 Pz = iparticle->Pz(); // don't transform
1397 e = iparticle->Energy(); // don't transform
1400 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1401 iparticle->SetMomentum(newPx, newPy, Pz, e);
1403 } //end particle loop
1405 // now let's check that we put correctly the candidate photon in PHOS
1406 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1407 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1408 if(IsInPHOS(phi,eta))
1414 void AliGenPythiaPlus::Streamer(TBuffer &R__b)
1416 // Stream an object of class AliGenPythia.
1418 if (R__b.IsReading()) {
1419 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1420 AliGenerator::Streamer(R__b);
1421 R__b >> (Int_t&)fProcess;
1422 R__b >> (Int_t&)fStrucFunc;
1423 R__b >> (Int_t&)fForceDecay;
1427 fParentSelect.Streamer(R__b);
1428 fChildSelect.Streamer(R__b);
1430 // (AliPythia::Instance())->Streamer(R__b);
1433 // if (fDecayer) fDecayer->Streamer(R__b);
1435 R__b.WriteVersion(AliGenPythiaPlus::IsA());
1436 AliGenerator::Streamer(R__b);
1437 R__b << (Int_t)fProcess;
1438 R__b << (Int_t)fStrucFunc;
1439 R__b << (Int_t)fForceDecay;
1443 fParentSelect.Streamer(R__b);
1444 fChildSelect.Streamer(R__b);
1449 // fDecayer->Streamer(R__b);