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),
217 // default charm production at 5. 5 TeV
219 // structure function GRVHO
223 fTitle= "Particle Generator using PYTHIA";
225 // Set random number generator
226 if (!AliPythiaRndm::GetPythiaRandom())
227 AliPythiaRndm::SetPythiaRandom(GetRandom());
231 AliGenPythiaPlus::~AliGenPythiaPlus()
234 if(fEventsTime) delete fEventsTime;
237 void AliGenPythiaPlus::SetInteractionRate(Float_t rate,Float_t timewindow)
239 // Generate pileup using user specified rate
240 fInteractionRate = rate;
241 fTimeWindow = timewindow;
245 void AliGenPythiaPlus::GeneratePileup()
247 // Generate sub events time for pileup
249 if(fInteractionRate == 0.) {
250 Warning("GeneratePileup","Zero interaction specified. Skipping pileup generation.\n");
254 Int_t npart = NumberParticles();
256 Warning("GeneratePileup","Negative number of particles. Skipping pileup generation.\n");
260 if(fEventsTime) delete fEventsTime;
261 fEventsTime = new TArrayF(npart);
262 TArrayF &array = *fEventsTime;
263 for(Int_t ipart = 0; ipart < npart; ipart++)
266 Float_t eventtime = 0.;
269 eventtime += (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
270 if(eventtime > fTimeWindow) break;
271 array.Set(array.GetSize()+1);
272 array[array.GetSize()-1] = eventtime;
278 eventtime -= (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
279 if(TMath::Abs(eventtime) > fTimeWindow) break;
280 array.Set(array.GetSize()+1);
281 array[array.GetSize()-1] = eventtime;
284 SetNumberParticles(fEventsTime->GetSize());
287 void AliGenPythiaPlus::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
288 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
290 // Set pycell parameters
291 fPycellEtaMax = etamax;
294 fPycellThreshold = thresh;
295 fPycellEtSeed = etseed;
296 fPycellMinEtJet = minet;
297 fPycellMaxRadius = r;
302 void AliGenPythiaPlus::SetEventListRange(Int_t eventFirst, Int_t eventLast)
304 // Set a range of event numbers, for which a table
305 // of generated particle will be printed
306 fDebugEventFirst = eventFirst;
307 fDebugEventLast = eventLast;
308 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
311 void AliGenPythiaPlus::Init()
315 // SetMC(AliPythia::Instance());
316 // fPythia=(AliPythia*) fMCEvGen;
319 fParentWeight=1./Float_t(fNpart);
323 fPythia->SetPtHardRange(fPtHardMin, fPtHardMax);
324 fPythia->SetYHardRange(fYHardMin, fYHardMax);
326 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget);
328 if (fFragmentation) {
329 fPythia->SetFragmentation(1);
331 fPythia->SetFragmentation(0);
335 // initial state radiation
336 fPythia->SetInitialAndFinalStateRadiation(fGinit, fGfinal);
339 fPythia->SetIntrinsicKt(fPtKick);
342 fRL = AliRunLoader::Open(fFileName, "Partons");
343 fRL->LoadKinematics();
349 fPythia->ProcInit(fProcess, fEnergyCMS, fStrucFunc, fItune);
350 // Forward Paramters to the AliPythia object
351 fDecayer->SetForceDecay(fForceDecay);
352 // Switch off Heavy Flavors on request
354 fPythia->SwitchHFOff();
355 // Switch off g->QQbar splitting in decay table
356 ((AliDecayerPythia*) fDecayer)->HeavyFlavourOff();
362 // Parent and Children Selection
365 case kPyOldUEQ2ordered:
366 case kPyOldUEQ2ordered2:
370 case kPyCharmUnforced:
371 case kPyCharmPbPbMNR:
374 case kPyCharmppMNRwmi:
375 fParentSelect[0] = 411;
376 fParentSelect[1] = 421;
377 fParentSelect[2] = 431;
378 fParentSelect[3] = 4122;
379 fParentSelect[4] = 4232;
380 fParentSelect[5] = 4132;
381 fParentSelect[6] = 4332;
387 fParentSelect[0] = 421;
390 case kPyDPlusPbPbMNR:
393 fParentSelect[0] = 411;
396 case kPyDPlusStrangePbPbMNR:
397 case kPyDPlusStrangepPbMNR:
398 case kPyDPlusStrangeppMNR:
399 fParentSelect[0] = 431;
402 case kPyLambdacppMNR:
403 fParentSelect[0] = 4122;
408 case kPyBeautyPbPbMNR:
409 case kPyBeautypPbMNR:
411 case kPyBeautyppMNRwmi:
412 fParentSelect[0]= 511;
413 fParentSelect[1]= 521;
414 fParentSelect[2]= 531;
415 fParentSelect[3]= 5122;
416 fParentSelect[4]= 5132;
417 fParentSelect[5]= 5232;
418 fParentSelect[6]= 5332;
421 case kPyBeautyUnforced:
422 fParentSelect[0] = 511;
423 fParentSelect[1] = 521;
424 fParentSelect[2] = 531;
425 fParentSelect[3] = 5122;
426 fParentSelect[4] = 5132;
427 fParentSelect[5] = 5232;
428 fParentSelect[6] = 5332;
433 fParentSelect[0] = 443;
435 case kPyMbAtlasTuneMC09:
438 case kPyMbWithDirectPhoton:
451 // JetFinder for Trigger
453 // Configure detector (EMCAL like)
455 fPythia->SetPycellParameters(fPycellEtaMax,fPycellNEta, fPycellNPhi,
456 fPycellThreshold, fPycellEtSeed,
457 fPycellMinEtJet, fPycellMaxRadius);
459 // This counts the total number of calls to Pyevnt() per run.
474 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
478 fPythia->InitQuenching(0., 0.1, 0.6e6, 0, 0.97, 30);
481 // fPythia->SetPARJ(200, 0.0);
483 // if (fQuench == 3) {
484 // // Nestor's change of the splittings
485 // fPythia->SetPARJ(200, 0.8);
486 // fPythia->SetMSTJ(41, 1); // QCD radiation only
487 // fPythia->SetMSTJ(42, 2); // angular ordering
488 // fPythia->SetMSTJ(44, 2); // option to run alpha_s
489 // fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
490 // fPythia->SetMSTJ(50, 0); // No coherence in first branching
491 // fPythia->SetPARJ(82, 1.); // Cut off for parton showers
495 void AliGenPythiaPlus::Generate()
497 // Generate one event
499 fDecayer->ForceDecay();
501 Double_t polar[3] = {0,0,0};
502 Double_t origin[3] = {0,0,0};
504 // converts from mm/c to s
505 const Float_t kconv=0.001/2.999792458e8;
515 // Set collision vertex position
516 if (fVertexSmear == kPerEvent) Vertex();
525 // Switch hadronisation off
527 // fPythia->SwitchHadronisationOff();
529 // Either produce new event or read partons from file
531 if (!fReadFromFile) {
533 fPythia->GenerateEvent();
535 fPythia->GenerateMIEvent();
537 fNpartons = fPythia->GetNumberOfParticles();
539 printf("Loading Event %d\n",AliRunLoader::Instance()->GetEventNumber());
540 fRL->GetEvent(AliRunLoader::Instance()->GetEventNumber());
541 fPythia->SetNumberOfParticles(0);
542 fPythia->LoadEvent(fRL->Stack(), 0 , 1);
543 fPythia->EditEventList(21);
547 // Run quenching routine
551 } else if (fQuench == 2){
552 fPythia->Pyquen(208., 0, 0.);
553 } else if (fQuench == 3) {
554 // Quenching is via multiplicative correction of the splittings
558 // Switch hadronisation on
560 // fPythia->SwitchHadronisationOn();
562 // .. and perform hadronisation
563 // printf("Calling hadronisation %d\n", fPythia->GetN());
564 // fPythia->HadronizeEvent();
566 fPythia->GetParticles(&fParticles);
574 Int_t np = fParticles.GetEntriesFast();
576 if (np == 0) continue;
580 Int_t* pParent = new Int_t[np];
581 Int_t* pSelected = new Int_t[np];
582 Int_t* trackIt = new Int_t[np];
583 for (i = 0; i < np; i++) {
589 Int_t nc = 0; // Total n. of selected particles
590 Int_t nParents = 0; // Selected parents
591 Int_t nTkbles = 0; // Trackable particles
592 if (fProcess != kPyMbDefault &&
594 fProcess != kPyMbWithDirectPhoton &&
595 fProcess != kPyJets &&
596 fProcess != kPyDirectGamma &&
597 fProcess != kPyMbNonDiffr &&
598 fProcess != kPyMbMSEL1 &&
601 fProcess != kPyCharmppMNRwmi &&
602 fProcess != kPyBeautyppMNRwmi) {
604 for (i = 0; i < np; i++) {
605 TParticle* iparticle = (TParticle *) fParticles.At(i);
606 Int_t ks = iparticle->GetStatusCode();
607 kf = CheckPDGCode(iparticle->GetPdgCode());
608 // No initial state partons
609 if (ks==21) continue;
611 // Heavy Flavor Selection
618 if (kfl > 100000) kfl %= 100000;
619 if (kfl > 10000) kfl %= 10000;
621 if (kfl > 10) kfl/=100;
623 if (kfl > 10) kfl/=10;
624 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
627 // Establish mother daughter relation between heavy quarks and mesons
629 if (kf >= fFlavorSelect && kf <= 6) {
630 Int_t idau = (fPythia->Version() == 6) ? (iparticle->GetFirstDaughter() - 1) :(iparticle->GetFirstDaughter());
632 TParticle* daughter = (TParticle *) fParticles.At(idau);
633 Int_t pdgD = daughter->GetPdgCode();
634 if (pdgD == 91 || pdgD == 92) {
635 Int_t jmin = (fPythia->Version() == 6) ? (daughter->GetFirstDaughter() - 1) : (daughter->GetFirstDaughter());
636 Int_t jmax = (fPythia->Version() == 6) ? (daughter->GetLastDaughter() - 1) : (daughter->GetLastDaughter());
638 for (Int_t jp = jmin; jp <= jmax; jp++)
639 ((TParticle *) fParticles.At(jp))->SetFirstMother(i+1);
640 } // is string or cluster
646 TParticle * mother = (TParticle *) fParticles.At(ipa);
647 kfMo = TMath::Abs(mother->GetPdgCode());
650 // What to keep in Stack?
651 Bool_t flavorOK = kFALSE;
652 Bool_t selectOK = kFALSE;
654 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
656 if (kfl > fFlavorSelect) {
660 if (kfl == fFlavorSelect) flavorOK = kTRUE;
662 switch (fStackFillOpt) {
663 case kFlavorSelection:
666 case kParentSelection:
667 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
670 if (flavorOK && selectOK) {
672 // Heavy flavor hadron or quark
674 // Kinematic seletion on final state heavy flavor mesons
675 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
680 if (ParentSelected(kf)) ++nParents; // Update parent count
681 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
683 // Kinematic seletion on decay products
684 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
685 && !KinematicSelection(iparticle, 1))
691 // Select if mother was selected and is not tracked
693 if (pSelected[ipa] &&
694 !trackIt[ipa] && // mother will be tracked ?
695 kfMo != 5 && // mother is b-quark, don't store fragments
696 kfMo != 4 && // mother is c-quark, don't store fragments
697 kf != 92) // don't store string
700 // Semi-stable or de-selected: diselect decay products:
703 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
705 Int_t ipF = iparticle->GetFirstDaughter();
706 Int_t ipL = iparticle->GetLastDaughter();
707 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
709 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
710 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
713 if (pSelected[i] == -1) pSelected[i] = 0;
714 if (!pSelected[i]) continue;
715 // Count quarks only if you did not include fragmentation
716 if (fFragmentation && kf <= 10) continue;
719 // Decision on tracking
722 // Track final state particle
723 if (ks == 1) trackIt[i] = 1;
724 // Track semi-stable particles
725 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
726 // Track particles selected by process if undecayed.
727 if (fForceDecay == kNoDecay) {
728 if (ParentSelected(kf)) trackIt[i] = 1;
730 if (ParentSelected(kf)) trackIt[i] = 0;
732 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
736 } // particle selection loop
738 for (i = 0; i < np; i++) {
739 if (!pSelected[i]) continue;
740 TParticle * iparticle = (TParticle *) fParticles.At(i);
741 kf = CheckPDGCode(iparticle->GetPdgCode());
742 Int_t ks = iparticle->GetStatusCode();
743 p[0] = iparticle->Px();
744 p[1] = iparticle->Py();
745 p[2] = iparticle->Pz();
746 p[3] = iparticle->Energy();
748 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
749 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
750 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
752 Float_t tof = fTime + kconv*iparticle->T();
753 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
754 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
756 PushTrack(fTrackIt*trackIt[i], iparent, kf,
757 p[0], p[1], p[2], p[3],
758 origin[0], origin[1], origin[2], tof,
759 polar[0], polar[1], polar[2],
760 kPPrimary, nt, 1., ks);
777 switch (fCountMode) {
779 // printf(" Count all \n");
783 // printf(" Count parents \n");
786 case kCountTrackables:
787 // printf(" Count trackable \n");
791 if (jev >= fNpart || fNpart == -1) {
792 fKineBias=Float_t(fNpart)/Float_t(fTrials);
793 fPythia->GetXandQ(fQ, fX1, fX2);
794 fTrialsRun += fTrials;
801 SetHighWaterMark(nt);
802 // Adjust weight due to kinematic selection
805 fXsection = fPythia->GetXSection();
808 Int_t AliGenPythiaPlus::GenerateMB()
811 // Min Bias selection and other global selections
813 Int_t i, kf, nt, iparent;
816 Float_t polar[3] = {0,0,0};
817 Float_t origin[3] = {0,0,0};
818 // converts from mm/c to s
819 const Float_t kconv = 0.001 / 2.999792458e8;
821 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
823 Int_t* pParent = new Int_t[np];
824 for (i=0; i< np; i++) pParent[i] = -1;
825 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
826 TParticle* jet1 = (TParticle *) fParticles.At(6);
827 TParticle* jet2 = (TParticle *) fParticles.At(7);
828 if (!CheckTrigger(jet1, jet2)) {
834 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
835 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
840 if (fFragPhotonInCalo) pdg = 22 ; // Photon
841 else if (fPi0InCalo) pdg = 111 ; // Pi0
843 for (i=0; i< np; i++) {
844 TParticle* iparticle = (TParticle *) fParticles.At(i);
845 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
846 iparticle->Pt() > fFragPhotonOrPi0MinPt){
847 Int_t imother = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
848 TParticle* pmother = (TParticle *) fParticles.At(imother);
850 (pdg == 22 && pmother->GetStatusCode() != 11))//No photon from hadron decay
852 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
853 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
854 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
855 (fCheckPHOS && IsInPHOS(phi,eta)) )
867 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
868 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
874 for (i=0; i< np; i++) {
875 TParticle* iparticle = (TParticle *) fParticles.At(i);
876 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
877 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
879 if(iparticle->GetStatusCode() == 1
880 && iparticle->GetPdgCode() == pdg
881 && iparticle->Pt() > fPhotonMinPt
884 // first check if the photon is in PHOS phi
885 if(IsInPHOS(phi,eta)){
889 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
894 if(!okd && iphcand != -1) // execute rotation in phi
895 RotatePhi(iphcand,okd);
903 if (fTriggerParticle) {
904 Bool_t triggered = kFALSE;
905 for (i = 0; i < np; i++) {
906 TParticle * iparticle = (TParticle *) fParticles.At(i);
907 kf = CheckPDGCode(iparticle->GetPdgCode());
908 if (kf != fTriggerParticle) continue;
909 if (iparticle->Pt() == 0.) continue;
910 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
921 // Check if there is a ccbar or bbbar pair with at least one of the two
922 // in fYMin < y < fYMax
923 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi) {
924 TParticle *partCheck;
926 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
927 Bool_t theChild=kFALSE;
929 Int_t pdg,mpdg,mpdgUpperFamily;
930 for(i=0; i<np; i++) {
931 partCheck = (TParticle*)fParticles.At(i);
932 pdg = partCheck->GetPdgCode();
933 if(TMath::Abs(pdg) == fFlavorSelect) { // quark
934 if(pdg>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
935 y = 0.5*TMath::Log((partCheck->Energy()+partCheck->Pz()+1.e-13)/
936 (partCheck->Energy()-partCheck->Pz()+1.e-13));
937 if(y>fYMin && y<fYMax) inYcut=kTRUE;
940 if(fCutOnChild && TMath::Abs(pdg) == fPdgCodeParticleforAcceptanceCut) {
941 Int_t mi = partCheck->GetFirstMother() - 1;
943 mother = (TParticle*)fParticles.At(mi);
944 mpdg=TMath::Abs(mother->GetPdgCode());
945 mpdgUpperFamily=(mpdg>1000 ? mpdg+1000 : mpdg+100); // keep e from c from b
946 if ( ParentSelected(mpdg) ||
947 (fFlavorSelect==5 && ParentSelected(mpdgUpperFamily))) {
948 if (KinematicSelection(partCheck,1)) {
954 if (!theQ || !theQbar || !inYcut) { // one of the c/b conditions not satisfied
958 if (fCutOnChild && !theChild) { // one of the child conditions not satisfied
965 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
966 if ( (fProcess == kPyW ||
968 fProcess == kPyMbDefault ||
970 fProcess == kPyMbWithDirectPhoton ||
971 fProcess == kPyMbNonDiffr)
972 && (fCutOnChild == 1) ) {
973 if ( !CheckKinematicsOnChild() ) {
980 for (i = 0; i < np; i++) {
982 TParticle * iparticle = (TParticle *) fParticles.At(i);
983 kf = CheckPDGCode(iparticle->GetPdgCode());
984 Int_t ks = iparticle->GetStatusCode();
985 Int_t km = iparticle->GetFirstMother();
986 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
988 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
990 if (ks == 1) trackIt = 1;
992 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
993 iparent = (ipa > -1) ? pParent[ipa] : -1;
994 if (ipa >= np) fPythia->EventListing();
997 // store track information
998 p[0] = iparticle->Px();
999 p[1] = iparticle->Py();
1000 p[2] = iparticle->Pz();
1001 p[3] = iparticle->Energy();
1004 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
1005 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
1006 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
1008 Float_t tof = fTime + fEventTime + kconv * iparticle->T();
1010 PushTrack(fTrackIt*trackIt, iparent, kf,
1011 p[0], p[1], p[2], p[3],
1012 origin[0], origin[1], origin[2], tof,
1013 polar[0], polar[1], polar[2],
1014 kPPrimary, nt, 1., ks);
1019 // Special Treatment to store color-flow
1022 if (ks == 3 || ks == 13 || ks == 14) {
1023 TParticle* particle = 0;
1025 particle = fStack->Particle(nt);
1027 particle = AliRunLoader::Instance()->Stack()->Particle(nt);
1029 particle->SetFirstDaughter(fPythia->GetK(2, i));
1030 particle->SetLastDaughter(fPythia->GetK(3, i));
1035 SetHighWaterMark(nt);
1037 } // select particle
1046 void AliGenPythiaPlus::FinishRun()
1048 // Print x-section summary
1049 fPythia->PrintStatistics();
1057 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1058 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1061 void AliGenPythiaPlus::AdjustWeights() const
1063 // Adjust the weights after generation of all events
1067 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1068 for (Int_t i=0; i<ntrack; i++) {
1069 part= gAlice->GetMCApp()->Particle(i);
1070 part->SetWeight(part->GetWeight()*fKineBias);
1075 void AliGenPythiaPlus::SetNuclei(Int_t a1, Int_t a2)
1077 // Treat protons as inside nuclei with mass numbers a1 and a2
1085 void AliGenPythiaPlus::MakeHeader()
1088 // Make header for the simulated event
1091 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1092 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->EventListing();
1095 // Builds the event header, to be called after each event
1096 if (fHeader) delete fHeader;
1097 fHeader = new AliGenPythiaEventHeader("Pythia");
1100 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->ProcessCode());
1103 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1106 fHeader->SetPrimaryVertex(fVertex);
1107 fHeader->SetInteractionTime(fTime+fEventTime);
1109 // Number of primaries
1110 fHeader->SetNProduced(fNprimaries);
1112 // Jets that have triggered
1114 if (fProcess == kPyJets)
1117 Float_t jets[4][10];
1118 GetJets(njet, ntrig, jets);
1121 for (Int_t i = 0; i < ntrig; i++) {
1122 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1127 // Copy relevant information from external header, if present.
1132 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1133 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1135 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1138 exHeader->TriggerJet(i, uqJet);
1139 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1143 // Store quenching parameters
1146 Double_t z[4] = {0.};
1151 fPythia->GetQuenchingParameters(xp, yp, z);
1154 Double_t r1 = PARIMP.rb1;
1155 Double_t r2 = PARIMP.rb2;
1156 Double_t b = PARIMP.b1;
1157 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1158 Double_t phi = PARIMP.psib1;
1159 xp = r * TMath::Cos(phi);
1160 yp = r * TMath::Sin(phi);
1163 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1164 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1168 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetPtHard());
1176 Bool_t AliGenPythiaPlus::CheckTrigger(const TParticle* jet1, const TParticle* jet2)
1178 // Check the kinematic trigger condition
1181 eta[0] = jet1->Eta();
1182 eta[1] = jet2->Eta();
1184 phi[0] = jet1->Phi();
1185 phi[1] = jet2->Phi();
1187 pdg[0] = jet1->GetPdgCode();
1188 pdg[1] = jet2->GetPdgCode();
1189 Bool_t triggered = kFALSE;
1191 if (fProcess == kPyJets) {
1194 Float_t jets[4][10];
1196 // Use Pythia clustering on parton level to determine jet axis
1198 GetJets(njets, ntrig, jets);
1200 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1205 if (pdg[0] == kGamma) {
1209 //Check eta range first...
1210 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1211 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1213 //Eta is okay, now check phi range
1214 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1215 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1226 Bool_t AliGenPythiaPlus::CheckKinematicsOnChild(){
1228 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1230 Bool_t checking = kFALSE;
1231 Int_t j, kcode, ks, km;
1232 Int_t nPartAcc = 0; //number of particles in the acceptance range
1233 Int_t numberOfAcceptedParticles = 1;
1234 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1235 Int_t npart = fParticles.GetEntriesFast();
1237 for (j = 0; j<npart; j++) {
1238 TParticle * jparticle = (TParticle *) fParticles.At(j);
1239 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1240 ks = jparticle->GetStatusCode();
1241 km = jparticle->GetFirstMother();
1243 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1246 if( numberOfAcceptedParticles <= nPartAcc){
1255 void AliGenPythiaPlus::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1258 // Calls the Pythia jet finding algorithm to find jets in the current event
1265 fPythia->Pycell(njets);
1267 for (i = 0; i < njets; i++) {
1268 Float_t px, py, pz, e;
1269 fPythia->GetJet(i, px, py, pz, e);
1278 void AliGenPythiaPlus::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1281 // Calls the Pythia clustering algorithm to find jets in the current event
1285 if (fJetReconstruction == kCluster) {
1287 // Configure cluster algorithm
1289 // fPythia->SetPARU(43, 2.);
1290 // fPythia->SetMSTU(41, 1);
1292 // Call cluster algorithm
1294 fPythia->Pyclus(nJets);
1296 // Loading jets from common block
1302 fPythia->Pycell(nJets);
1306 for (i = 0; i < nJets; i++) {
1307 Float_t px, py, pz, e;
1308 fPythia->GetJet(i, px, py, pz, e);
1309 Float_t pt = TMath::Sqrt(px * px + py * py);
1310 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1311 Float_t theta = TMath::ATan2(pt,pz);
1312 Float_t et = e * TMath::Sin(theta);
1313 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1315 eta > fEtaMinJet && eta < fEtaMaxJet &&
1316 phi > fPhiMinJet && phi < fPhiMaxJet &&
1317 et > fEtMinJet && et < fEtMaxJet
1320 jets[0][nJetsTrig] = px;
1321 jets[1][nJetsTrig] = py;
1322 jets[2][nJetsTrig] = pz;
1323 jets[3][nJetsTrig] = e;
1330 void AliGenPythiaPlus::GetSubEventTime()
1332 // Calculates time of the next subevent
1335 TArrayF &array = *fEventsTime;
1336 fEventTime = array[fCurSubEvent++];
1338 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1345 Bool_t AliGenPythiaPlus::IsInEMCAL(Float_t phi, Float_t eta) const
1347 // Is particle in EMCAL acceptance?
1348 // phi in degrees, etamin=-etamax
1349 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1356 Bool_t AliGenPythiaPlus::IsInPHOS(Float_t phi, Float_t eta) const
1358 // Is particle in PHOS acceptance?
1359 // Acceptance slightly larger considered.
1360 // phi in degrees, etamin=-etamax
1361 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1368 void AliGenPythiaPlus::RotatePhi(Int_t iphcand, Bool_t& okdd)
1370 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1371 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1372 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1373 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1375 //calculate deltaphi
1376 TParticle* ph = (TParticle *) fParticles.At(iphcand);
1377 Double_t phphi = ph->Phi();
1378 Double_t deltaphi = phiPHOS - phphi;
1382 //loop for all particles and produce the phi rotation
1383 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
1384 Double_t oldphi, newphi;
1385 Double_t newVx, newVy, R, Vz, time;
1386 Double_t newPx, newPy, pt, Pz, e;
1387 for(Int_t i=0; i< np; i++) {
1388 TParticle* iparticle = (TParticle *) fParticles.At(i);
1389 oldphi = iparticle->Phi();
1390 newphi = oldphi + deltaphi;
1391 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1392 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1395 newVx = R*TMath::Cos(newphi);
1396 newVy = R*TMath::Sin(newphi);
1397 Vz = iparticle->Vz(); // don't transform
1398 time = iparticle->T(); // don't transform
1400 pt = iparticle->Pt();
1401 newPx = pt*TMath::Cos(newphi);
1402 newPy = pt*TMath::Sin(newphi);
1403 Pz = iparticle->Pz(); // don't transform
1404 e = iparticle->Energy(); // don't transform
1407 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1408 iparticle->SetMomentum(newPx, newPy, Pz, e);
1410 } //end particle loop
1412 // now let's check that we put correctly the candidate photon in PHOS
1413 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1414 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1415 if(IsInPHOS(phi,eta))
1421 void AliGenPythiaPlus::Streamer(TBuffer &R__b)
1423 // Stream an object of class AliGenPythia.
1425 if (R__b.IsReading()) {
1426 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1427 AliGenerator::Streamer(R__b);
1428 R__b >> (Int_t&)fProcess;
1429 R__b >> (Int_t&)fStrucFunc;
1430 R__b >> (Int_t&)fForceDecay;
1434 fParentSelect.Streamer(R__b);
1435 fChildSelect.Streamer(R__b);
1437 // (AliPythia::Instance())->Streamer(R__b);
1440 // if (fDecayer) fDecayer->Streamer(R__b);
1442 R__b.WriteVersion(AliGenPythiaPlus::IsA());
1443 AliGenerator::Streamer(R__b);
1444 R__b << (Int_t)fProcess;
1445 R__b << (Int_t)fStrucFunc;
1446 R__b << (Int_t)fForceDecay;
1450 fParentSelect.Streamer(R__b);
1451 fChildSelect.Streamer(R__b);
1456 // fDecayer->Streamer(R__b);