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;
403 case kPyBeautyPbPbMNR:
404 case kPyBeautypPbMNR:
406 case kPyBeautyppMNRwmi:
407 fParentSelect[0]= 511;
408 fParentSelect[1]= 521;
409 fParentSelect[2]= 531;
410 fParentSelect[3]= 5122;
411 fParentSelect[4]= 5132;
412 fParentSelect[5]= 5232;
413 fParentSelect[6]= 5332;
416 case kPyBeautyUnforced:
417 fParentSelect[0] = 511;
418 fParentSelect[1] = 521;
419 fParentSelect[2] = 531;
420 fParentSelect[3] = 5122;
421 fParentSelect[4] = 5132;
422 fParentSelect[5] = 5232;
423 fParentSelect[6] = 5332;
428 fParentSelect[0] = 443;
432 case kPyMbWithDirectPhoton:
445 // JetFinder for Trigger
447 // Configure detector (EMCAL like)
449 fPythia->SetPycellParameters(fPycellEtaMax,fPycellNEta, fPycellNPhi,
450 fPycellThreshold, fPycellEtSeed,
451 fPycellMinEtJet, fPycellMaxRadius);
453 // This counts the total number of calls to Pyevnt() per run.
468 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
472 fPythia->InitQuenching(0., 0.1, 0.6e6, 0, 0.97, 30);
475 // fPythia->SetPARJ(200, 0.0);
477 // if (fQuench == 3) {
478 // // Nestor's change of the splittings
479 // fPythia->SetPARJ(200, 0.8);
480 // fPythia->SetMSTJ(41, 1); // QCD radiation only
481 // fPythia->SetMSTJ(42, 2); // angular ordering
482 // fPythia->SetMSTJ(44, 2); // option to run alpha_s
483 // fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
484 // fPythia->SetMSTJ(50, 0); // No coherence in first branching
485 // fPythia->SetPARJ(82, 1.); // Cut off for parton showers
489 void AliGenPythiaPlus::Generate()
491 // Generate one event
493 fDecayer->ForceDecay();
495 Float_t polar[3] = {0,0,0};
496 Float_t origin[3] = {0,0,0};
498 // converts from mm/c to s
499 const Float_t kconv=0.001/2.999792458e8;
509 // Set collision vertex position
510 if (fVertexSmear == kPerEvent) Vertex();
519 // Switch hadronisation off
521 // fPythia->SwitchHadronisationOff();
523 // Either produce new event or read partons from file
525 if (!fReadFromFile) {
527 fPythia->GenerateEvent();
529 fPythia->GenerateMIEvent();
531 fNpartons = fPythia->GetNumberOfParticles();
533 printf("Loading Event %d\n",AliRunLoader::Instance()->GetEventNumber());
534 fRL->GetEvent(AliRunLoader::Instance()->GetEventNumber());
535 fPythia->SetNumberOfParticles(0);
536 fPythia->LoadEvent(fRL->Stack(), 0 , 1);
537 fPythia->EditEventList(21);
541 // Run quenching routine
545 } else if (fQuench == 2){
546 fPythia->Pyquen(208., 0, 0.);
547 } else if (fQuench == 3) {
548 // Quenching is via multiplicative correction of the splittings
552 // Switch hadronisation on
554 // fPythia->SwitchHadronisationOn();
556 // .. and perform hadronisation
557 // printf("Calling hadronisation %d\n", fPythia->GetN());
558 // fPythia->HadronizeEvent();
560 fPythia->GetParticles(&fParticles);
568 Int_t np = fParticles.GetEntriesFast();
570 if (np == 0) continue;
574 Int_t* pParent = new Int_t[np];
575 Int_t* pSelected = new Int_t[np];
576 Int_t* trackIt = new Int_t[np];
577 for (i = 0; i < np; i++) {
583 Int_t nc = 0; // Total n. of selected particles
584 Int_t nParents = 0; // Selected parents
585 Int_t nTkbles = 0; // Trackable particles
586 if (fProcess != kPyMbDefault &&
588 fProcess != kPyMbWithDirectPhoton &&
589 fProcess != kPyJets &&
590 fProcess != kPyDirectGamma &&
591 fProcess != kPyMbNonDiffr &&
592 fProcess != kPyMbMSEL1 &&
595 fProcess != kPyCharmppMNRwmi &&
596 fProcess != kPyBeautyppMNRwmi) {
598 for (i = 0; i < np; i++) {
599 TParticle* iparticle = (TParticle *) fParticles.At(i);
600 Int_t ks = iparticle->GetStatusCode();
601 kf = CheckPDGCode(iparticle->GetPdgCode());
602 // No initial state partons
603 if (ks==21) continue;
605 // Heavy Flavor Selection
612 if (kfl > 100000) kfl %= 100000;
613 if (kfl > 10000) kfl %= 10000;
615 if (kfl > 10) kfl/=100;
617 if (kfl > 10) kfl/=10;
618 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
621 // Establish mother daughter relation between heavy quarks and mesons
623 if (kf >= fFlavorSelect && kf <= 6) {
624 Int_t idau = (fPythia->Version() == 6) ? (iparticle->GetFirstDaughter() - 1) :(iparticle->GetFirstDaughter());
626 TParticle* daughter = (TParticle *) fParticles.At(idau);
627 Int_t pdgD = daughter->GetPdgCode();
628 if (pdgD == 91 || pdgD == 92) {
629 Int_t jmin = (fPythia->Version() == 6) ? (daughter->GetFirstDaughter() - 1) : (daughter->GetFirstDaughter());
630 Int_t jmax = (fPythia->Version() == 6) ? (daughter->GetLastDaughter() - 1) : (daughter->GetLastDaughter());
632 for (Int_t jp = jmin; jp <= jmax; jp++)
633 ((TParticle *) fParticles.At(jp))->SetFirstMother(i+1);
634 } // is string or cluster
640 TParticle * mother = (TParticle *) fParticles.At(ipa);
641 kfMo = TMath::Abs(mother->GetPdgCode());
644 // What to keep in Stack?
645 Bool_t flavorOK = kFALSE;
646 Bool_t selectOK = kFALSE;
648 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
650 if (kfl > fFlavorSelect) {
654 if (kfl == fFlavorSelect) flavorOK = kTRUE;
656 switch (fStackFillOpt) {
657 case kFlavorSelection:
660 case kParentSelection:
661 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
664 if (flavorOK && selectOK) {
666 // Heavy flavor hadron or quark
668 // Kinematic seletion on final state heavy flavor mesons
669 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
674 if (ParentSelected(kf)) ++nParents; // Update parent count
675 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
677 // Kinematic seletion on decay products
678 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
679 && !KinematicSelection(iparticle, 1))
685 // Select if mother was selected and is not tracked
687 if (pSelected[ipa] &&
688 !trackIt[ipa] && // mother will be tracked ?
689 kfMo != 5 && // mother is b-quark, don't store fragments
690 kfMo != 4 && // mother is c-quark, don't store fragments
691 kf != 92) // don't store string
694 // Semi-stable or de-selected: diselect decay products:
697 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
699 Int_t ipF = iparticle->GetFirstDaughter();
700 Int_t ipL = iparticle->GetLastDaughter();
701 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
703 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
704 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
707 if (pSelected[i] == -1) pSelected[i] = 0;
708 if (!pSelected[i]) continue;
709 // Count quarks only if you did not include fragmentation
710 if (fFragmentation && kf <= 10) continue;
713 // Decision on tracking
716 // Track final state particle
717 if (ks == 1) trackIt[i] = 1;
718 // Track semi-stable particles
719 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
720 // Track particles selected by process if undecayed.
721 if (fForceDecay == kNoDecay) {
722 if (ParentSelected(kf)) trackIt[i] = 1;
724 if (ParentSelected(kf)) trackIt[i] = 0;
726 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
730 } // particle selection loop
732 for (i = 0; i < np; i++) {
733 if (!pSelected[i]) continue;
734 TParticle * iparticle = (TParticle *) fParticles.At(i);
735 kf = CheckPDGCode(iparticle->GetPdgCode());
736 Int_t ks = iparticle->GetStatusCode();
737 p[0] = iparticle->Px();
738 p[1] = iparticle->Py();
739 p[2] = iparticle->Pz();
740 p[3] = iparticle->Energy();
742 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
743 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
744 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
746 Float_t tof = kconv*iparticle->T();
747 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
748 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
750 PushTrack(fTrackIt*trackIt[i], iparent, kf,
751 p[0], p[1], p[2], p[3],
752 origin[0], origin[1], origin[2], tof,
753 polar[0], polar[1], polar[2],
754 kPPrimary, nt, 1., ks);
771 switch (fCountMode) {
773 // printf(" Count all \n");
777 // printf(" Count parents \n");
780 case kCountTrackables:
781 // printf(" Count trackable \n");
785 if (jev >= fNpart || fNpart == -1) {
786 fKineBias=Float_t(fNpart)/Float_t(fTrials);
787 fPythia->GetXandQ(fQ, fX1, fX2);
788 fTrialsRun += fTrials;
795 SetHighWaterMark(nt);
796 // Adjust weight due to kinematic selection
799 fXsection = fPythia->GetXSection();
802 Int_t AliGenPythiaPlus::GenerateMB()
805 // Min Bias selection and other global selections
807 Int_t i, kf, nt, iparent;
810 Float_t polar[3] = {0,0,0};
811 Float_t origin[3] = {0,0,0};
812 // converts from mm/c to s
813 const Float_t kconv = 0.001 / 2.999792458e8;
815 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
817 Int_t* pParent = new Int_t[np];
818 for (i=0; i< np; i++) pParent[i] = -1;
819 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
820 TParticle* jet1 = (TParticle *) fParticles.At(6);
821 TParticle* jet2 = (TParticle *) fParticles.At(7);
822 if (!CheckTrigger(jet1, jet2)) {
828 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
829 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
834 if (fFragPhotonInCalo) pdg = 22 ; // Photon
835 else if (fPi0InCalo) pdg = 111 ; // Pi0
837 for (i=0; i< np; i++) {
838 TParticle* iparticle = (TParticle *) fParticles.At(i);
839 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
840 iparticle->Pt() > fFragPhotonOrPi0MinPt){
841 Int_t imother = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
842 TParticle* pmother = (TParticle *) fParticles.At(imother);
844 (pdg == 22 && pmother->GetStatusCode() != 11))//No photon from hadron decay
846 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
847 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
848 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
849 (fCheckPHOS && IsInPHOS(phi,eta)) )
859 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
860 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
866 for (i=0; i< np; i++) {
867 TParticle* iparticle = (TParticle *) fParticles.At(i);
868 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
869 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
871 if(iparticle->GetStatusCode() == 1
872 && iparticle->GetPdgCode() == pdg
873 && iparticle->Pt() > fPhotonMinPt
876 // first check if the photon is in PHOS phi
877 if(IsInPHOS(phi,eta)){
881 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
886 if(!okd && iphcand != -1) // execute rotation in phi
887 RotatePhi(iphcand,okd);
893 if (fTriggerParticle) {
894 Bool_t triggered = kFALSE;
895 for (i = 0; i < np; i++) {
896 TParticle * iparticle = (TParticle *) fParticles.At(i);
897 kf = CheckPDGCode(iparticle->GetPdgCode());
898 if (kf != fTriggerParticle) continue;
899 if (iparticle->Pt() == 0.) continue;
900 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
911 // Check if there is a ccbar or bbbar pair with at least one of the two
912 // in fYMin < y < fYMax
913 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi) {
914 TParticle *partCheck;
916 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
917 Bool_t theChild=kFALSE;
919 Int_t pdg,mpdg,mpdgUpperFamily;
920 for(i=0; i<np; i++) {
921 partCheck = (TParticle*)fParticles.At(i);
922 pdg = partCheck->GetPdgCode();
923 if(TMath::Abs(pdg) == fFlavorSelect) { // quark
924 if(pdg>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
925 y = 0.5*TMath::Log((partCheck->Energy()+partCheck->Pz()+1.e-13)/
926 (partCheck->Energy()-partCheck->Pz()+1.e-13));
927 if(y>fYMin && y<fYMax) inYcut=kTRUE;
930 if(fCutOnChild && TMath::Abs(pdg) == fPdgCodeParticleforAcceptanceCut) {
931 Int_t mi = partCheck->GetFirstMother() - 1;
933 mother = (TParticle*)fParticles.At(mi);
934 mpdg=TMath::Abs(mother->GetPdgCode());
935 mpdgUpperFamily=(mpdg>1000 ? mpdg+1000 : mpdg+100); // keep e from c from b
936 if ( ParentSelected(mpdg) ||
937 (fFlavorSelect==5 && ParentSelected(mpdgUpperFamily))) {
938 if (KinematicSelection(partCheck,1)) {
944 if (!theQ || !theQbar || !inYcut) { // one of the c/b conditions not satisfied
948 if (fCutOnChild && !theChild) { // one of the child conditions not satisfied
955 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
956 if ( (fProcess == kPyW ||
958 fProcess == kPyMbDefault ||
960 fProcess == kPyMbWithDirectPhoton ||
961 fProcess == kPyMbNonDiffr)
962 && (fCutOnChild == 1) ) {
963 if ( !CheckKinematicsOnChild() ) {
970 for (i = 0; i < np; i++) {
972 TParticle * iparticle = (TParticle *) fParticles.At(i);
973 kf = CheckPDGCode(iparticle->GetPdgCode());
974 Int_t ks = iparticle->GetStatusCode();
975 Int_t km = iparticle->GetFirstMother();
976 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
978 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
980 if (ks == 1) trackIt = 1;
982 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
983 iparent = (ipa > -1) ? pParent[ipa] : -1;
984 if (ipa >= np) fPythia->EventListing();
987 // store track information
988 p[0] = iparticle->Px();
989 p[1] = iparticle->Py();
990 p[2] = iparticle->Pz();
991 p[3] = iparticle->Energy();
994 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
995 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
996 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
998 Float_t tof = fEventTime + kconv * iparticle->T();
1000 PushTrack(fTrackIt*trackIt, iparent, kf,
1001 p[0], p[1], p[2], p[3],
1002 origin[0], origin[1], origin[2], tof,
1003 polar[0], polar[1], polar[2],
1004 kPPrimary, nt, 1., ks);
1009 // Special Treatment to store color-flow
1011 if (ks == 3 || ks == 13 || ks == 14) {
1012 TParticle* particle = 0;
1014 particle = fStack->Particle(nt);
1016 particle = AliRunLoader::Instance()->Stack()->Particle(nt);
1018 // particle->SetFirstDaughter(fPythia->GetK(2, i));
1019 // particle->SetLastDaughter(fPythia->GetK(3, i));
1024 SetHighWaterMark(nt);
1026 } // select particle
1035 void AliGenPythiaPlus::FinishRun()
1037 // Print x-section summary
1038 fPythia->PrintStatistics();
1046 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1047 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1050 void AliGenPythiaPlus::AdjustWeights() const
1052 // Adjust the weights after generation of all events
1056 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1057 for (Int_t i=0; i<ntrack; i++) {
1058 part= gAlice->GetMCApp()->Particle(i);
1059 part->SetWeight(part->GetWeight()*fKineBias);
1064 void AliGenPythiaPlus::SetNuclei(Int_t a1, Int_t a2)
1066 // Treat protons as inside nuclei with mass numbers a1 and a2
1074 void AliGenPythiaPlus::MakeHeader()
1077 // Make header for the simulated event
1080 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1081 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->EventListing();
1084 // Builds the event header, to be called after each event
1085 if (fHeader) delete fHeader;
1086 fHeader = new AliGenPythiaEventHeader("Pythia");
1089 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->ProcessCode());
1092 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1095 fHeader->SetPrimaryVertex(fVertex);
1098 // Number of primaries
1099 fHeader->SetNProduced(fNprimaries);
1101 // Jets that have triggered
1103 if (fProcess == kPyJets)
1106 Float_t jets[4][10];
1107 GetJets(njet, ntrig, jets);
1110 for (Int_t i = 0; i < ntrig; i++) {
1111 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1116 // Copy relevant information from external header, if present.
1121 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1122 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1124 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1127 exHeader->TriggerJet(i, uqJet);
1128 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1132 // Store quenching parameters
1139 fPythia->GetQuenchingParameters(xp, yp, z);
1142 Double_t r1 = PARIMP.rb1;
1143 Double_t r2 = PARIMP.rb2;
1144 Double_t b = PARIMP.b1;
1145 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1146 Double_t phi = PARIMP.psib1;
1147 xp = r * TMath::Cos(phi);
1148 yp = r * TMath::Sin(phi);
1151 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1152 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1156 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetPtHard());
1164 Bool_t AliGenPythiaPlus::CheckTrigger(TParticle* jet1, TParticle* jet2)
1166 // Check the kinematic trigger condition
1169 eta[0] = jet1->Eta();
1170 eta[1] = jet2->Eta();
1172 phi[0] = jet1->Phi();
1173 phi[1] = jet2->Phi();
1175 pdg[0] = jet1->GetPdgCode();
1176 pdg[1] = jet2->GetPdgCode();
1177 Bool_t triggered = kFALSE;
1179 if (fProcess == kPyJets) {
1182 Float_t jets[4][10];
1184 // Use Pythia clustering on parton level to determine jet axis
1186 GetJets(njets, ntrig, jets);
1188 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1193 if (pdg[0] == kGamma) {
1197 //Check eta range first...
1198 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1199 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1201 //Eta is okay, now check phi range
1202 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1203 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1214 Bool_t AliGenPythiaPlus::CheckKinematicsOnChild(){
1216 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1218 Bool_t checking = kFALSE;
1219 Int_t j, kcode, ks, km;
1220 Int_t nPartAcc = 0; //number of particles in the acceptance range
1221 Int_t numberOfAcceptedParticles = 1;
1222 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1223 Int_t npart = fParticles.GetEntriesFast();
1225 for (j = 0; j<npart; j++) {
1226 TParticle * jparticle = (TParticle *) fParticles.At(j);
1227 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1228 ks = jparticle->GetStatusCode();
1229 km = jparticle->GetFirstMother();
1231 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1234 if( numberOfAcceptedParticles <= nPartAcc){
1243 void AliGenPythiaPlus::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1246 // Calls the Pythia jet finding algorithm to find jets in the current event
1253 fPythia->Pycell(njets);
1255 for (i = 0; i < njets; i++) {
1256 Float_t px, py, pz, e;
1257 fPythia->GetJet(i, px, py, pz, e);
1266 void AliGenPythiaPlus::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1269 // Calls the Pythia clustering algorithm to find jets in the current event
1273 if (fJetReconstruction == kCluster) {
1275 // Configure cluster algorithm
1277 // fPythia->SetPARU(43, 2.);
1278 // fPythia->SetMSTU(41, 1);
1280 // Call cluster algorithm
1282 fPythia->Pyclus(nJets);
1284 // Loading jets from common block
1290 fPythia->Pycell(nJets);
1294 for (i = 0; i < nJets; i++) {
1295 Float_t px, py, pz, e;
1296 fPythia->GetJet(i, px, py, pz, e);
1297 Float_t pt = TMath::Sqrt(px * px + py * py);
1298 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1299 Float_t theta = TMath::ATan2(pt,pz);
1300 Float_t et = e * TMath::Sin(theta);
1301 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1303 eta > fEtaMinJet && eta < fEtaMaxJet &&
1304 phi > fPhiMinJet && phi < fPhiMaxJet &&
1305 et > fEtMinJet && et < fEtMaxJet
1308 jets[0][nJetsTrig] = px;
1309 jets[1][nJetsTrig] = py;
1310 jets[2][nJetsTrig] = pz;
1311 jets[3][nJetsTrig] = e;
1318 void AliGenPythiaPlus::GetSubEventTime()
1320 // Calculates time of the next subevent
1323 TArrayF &array = *fEventsTime;
1324 fEventTime = array[fCurSubEvent++];
1326 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1333 Bool_t AliGenPythiaPlus::IsInEMCAL(Float_t phi, Float_t eta)
1335 // Is particle in EMCAL acceptance?
1336 // phi in degrees, etamin=-etamax
1337 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1344 Bool_t AliGenPythiaPlus::IsInPHOS(Float_t phi, Float_t eta)
1346 // Is particle in PHOS acceptance?
1347 // Acceptance slightly larger considered.
1348 // phi in degrees, etamin=-etamax
1349 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1356 void AliGenPythiaPlus::RotatePhi(Int_t iphcand, Bool_t& okdd)
1358 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1359 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1360 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1361 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1363 //calculate deltaphi
1364 TParticle* ph = (TParticle *) fParticles.At(iphcand);
1365 Double_t phphi = ph->Phi();
1366 Double_t deltaphi = phiPHOS - phphi;
1370 //loop for all particles and produce the phi rotation
1371 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
1372 Double_t oldphi, newphi;
1373 Double_t newVx, newVy, R, Vz, time;
1374 Double_t newPx, newPy, pt, Pz, e;
1375 for(Int_t i=0; i< np; i++) {
1376 TParticle* iparticle = (TParticle *) fParticles.At(i);
1377 oldphi = iparticle->Phi();
1378 newphi = oldphi + deltaphi;
1379 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1380 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1383 newVx = R*TMath::Cos(newphi);
1384 newVy = R*TMath::Sin(newphi);
1385 Vz = iparticle->Vz(); // don't transform
1386 time = iparticle->T(); // don't transform
1388 pt = iparticle->Pt();
1389 newPx = pt*TMath::Cos(newphi);
1390 newPy = pt*TMath::Sin(newphi);
1391 Pz = iparticle->Pz(); // don't transform
1392 e = iparticle->Energy(); // don't transform
1395 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1396 iparticle->SetMomentum(newPx, newPy, Pz, e);
1398 } //end particle loop
1400 // now let's check that we put correctly the candidate photon in PHOS
1401 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1402 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1403 if(IsInPHOS(phi,eta))
1409 void AliGenPythiaPlus::Streamer(TBuffer &R__b)
1411 // Stream an object of class AliGenPythia.
1413 if (R__b.IsReading()) {
1414 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1415 AliGenerator::Streamer(R__b);
1416 R__b >> (Int_t&)fProcess;
1417 R__b >> (Int_t&)fStrucFunc;
1418 R__b >> (Int_t&)fForceDecay;
1422 fParentSelect.Streamer(R__b);
1423 fChildSelect.Streamer(R__b);
1425 // (AliPythia::Instance())->Streamer(R__b);
1428 // if (fDecayer) fDecayer->Streamer(R__b);
1430 R__b.WriteVersion(AliGenPythiaPlus::IsA());
1431 AliGenerator::Streamer(R__b);
1432 R__b << (Int_t)fProcess;
1433 R__b << (Int_t)fStrucFunc;
1434 R__b << (Int_t)fForceDecay;
1438 fParentSelect.Streamer(R__b);
1439 fChildSelect.Streamer(R__b);
1444 // fDecayer->Streamer(R__b);