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;
430 case kPyMbAtlasTuneMC09:
433 case kPyMbWithDirectPhoton:
446 // JetFinder for Trigger
448 // Configure detector (EMCAL like)
450 fPythia->SetPycellParameters(fPycellEtaMax,fPycellNEta, fPycellNPhi,
451 fPycellThreshold, fPycellEtSeed,
452 fPycellMinEtJet, fPycellMaxRadius);
454 // This counts the total number of calls to Pyevnt() per run.
469 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
473 fPythia->InitQuenching(0., 0.1, 0.6e6, 0, 0.97, 30);
476 // fPythia->SetPARJ(200, 0.0);
478 // if (fQuench == 3) {
479 // // Nestor's change of the splittings
480 // fPythia->SetPARJ(200, 0.8);
481 // fPythia->SetMSTJ(41, 1); // QCD radiation only
482 // fPythia->SetMSTJ(42, 2); // angular ordering
483 // fPythia->SetMSTJ(44, 2); // option to run alpha_s
484 // fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
485 // fPythia->SetMSTJ(50, 0); // No coherence in first branching
486 // fPythia->SetPARJ(82, 1.); // Cut off for parton showers
490 void AliGenPythiaPlus::Generate()
492 // Generate one event
494 fDecayer->ForceDecay();
496 Float_t polar[3] = {0,0,0};
497 Float_t origin[3] = {0,0,0};
499 // converts from mm/c to s
500 const Float_t kconv=0.001/2.999792458e8;
510 // Set collision vertex position
511 if (fVertexSmear == kPerEvent) Vertex();
520 // Switch hadronisation off
522 // fPythia->SwitchHadronisationOff();
524 // Either produce new event or read partons from file
526 if (!fReadFromFile) {
528 fPythia->GenerateEvent();
530 fPythia->GenerateMIEvent();
532 fNpartons = fPythia->GetNumberOfParticles();
534 printf("Loading Event %d\n",AliRunLoader::Instance()->GetEventNumber());
535 fRL->GetEvent(AliRunLoader::Instance()->GetEventNumber());
536 fPythia->SetNumberOfParticles(0);
537 fPythia->LoadEvent(fRL->Stack(), 0 , 1);
538 fPythia->EditEventList(21);
542 // Run quenching routine
546 } else if (fQuench == 2){
547 fPythia->Pyquen(208., 0, 0.);
548 } else if (fQuench == 3) {
549 // Quenching is via multiplicative correction of the splittings
553 // Switch hadronisation on
555 // fPythia->SwitchHadronisationOn();
557 // .. and perform hadronisation
558 // printf("Calling hadronisation %d\n", fPythia->GetN());
559 // fPythia->HadronizeEvent();
561 fPythia->GetParticles(&fParticles);
569 Int_t np = fParticles.GetEntriesFast();
571 if (np == 0) continue;
575 Int_t* pParent = new Int_t[np];
576 Int_t* pSelected = new Int_t[np];
577 Int_t* trackIt = new Int_t[np];
578 for (i = 0; i < np; i++) {
584 Int_t nc = 0; // Total n. of selected particles
585 Int_t nParents = 0; // Selected parents
586 Int_t nTkbles = 0; // Trackable particles
587 if (fProcess != kPyMbDefault &&
589 fProcess != kPyMbWithDirectPhoton &&
590 fProcess != kPyJets &&
591 fProcess != kPyDirectGamma &&
592 fProcess != kPyMbNonDiffr &&
593 fProcess != kPyMbMSEL1 &&
596 fProcess != kPyCharmppMNRwmi &&
597 fProcess != kPyBeautyppMNRwmi) {
599 for (i = 0; i < np; i++) {
600 TParticle* iparticle = (TParticle *) fParticles.At(i);
601 Int_t ks = iparticle->GetStatusCode();
602 kf = CheckPDGCode(iparticle->GetPdgCode());
603 // No initial state partons
604 if (ks==21) continue;
606 // Heavy Flavor Selection
613 if (kfl > 100000) kfl %= 100000;
614 if (kfl > 10000) kfl %= 10000;
616 if (kfl > 10) kfl/=100;
618 if (kfl > 10) kfl/=10;
619 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
622 // Establish mother daughter relation between heavy quarks and mesons
624 if (kf >= fFlavorSelect && kf <= 6) {
625 Int_t idau = (fPythia->Version() == 6) ? (iparticle->GetFirstDaughter() - 1) :(iparticle->GetFirstDaughter());
627 TParticle* daughter = (TParticle *) fParticles.At(idau);
628 Int_t pdgD = daughter->GetPdgCode();
629 if (pdgD == 91 || pdgD == 92) {
630 Int_t jmin = (fPythia->Version() == 6) ? (daughter->GetFirstDaughter() - 1) : (daughter->GetFirstDaughter());
631 Int_t jmax = (fPythia->Version() == 6) ? (daughter->GetLastDaughter() - 1) : (daughter->GetLastDaughter());
633 for (Int_t jp = jmin; jp <= jmax; jp++)
634 ((TParticle *) fParticles.At(jp))->SetFirstMother(i+1);
635 } // is string or cluster
641 TParticle * mother = (TParticle *) fParticles.At(ipa);
642 kfMo = TMath::Abs(mother->GetPdgCode());
645 // What to keep in Stack?
646 Bool_t flavorOK = kFALSE;
647 Bool_t selectOK = kFALSE;
649 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
651 if (kfl > fFlavorSelect) {
655 if (kfl == fFlavorSelect) flavorOK = kTRUE;
657 switch (fStackFillOpt) {
658 case kFlavorSelection:
661 case kParentSelection:
662 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
665 if (flavorOK && selectOK) {
667 // Heavy flavor hadron or quark
669 // Kinematic seletion on final state heavy flavor mesons
670 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
675 if (ParentSelected(kf)) ++nParents; // Update parent count
676 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
678 // Kinematic seletion on decay products
679 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
680 && !KinematicSelection(iparticle, 1))
686 // Select if mother was selected and is not tracked
688 if (pSelected[ipa] &&
689 !trackIt[ipa] && // mother will be tracked ?
690 kfMo != 5 && // mother is b-quark, don't store fragments
691 kfMo != 4 && // mother is c-quark, don't store fragments
692 kf != 92) // don't store string
695 // Semi-stable or de-selected: diselect decay products:
698 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
700 Int_t ipF = iparticle->GetFirstDaughter();
701 Int_t ipL = iparticle->GetLastDaughter();
702 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
704 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
705 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
708 if (pSelected[i] == -1) pSelected[i] = 0;
709 if (!pSelected[i]) continue;
710 // Count quarks only if you did not include fragmentation
711 if (fFragmentation && kf <= 10) continue;
714 // Decision on tracking
717 // Track final state particle
718 if (ks == 1) trackIt[i] = 1;
719 // Track semi-stable particles
720 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
721 // Track particles selected by process if undecayed.
722 if (fForceDecay == kNoDecay) {
723 if (ParentSelected(kf)) trackIt[i] = 1;
725 if (ParentSelected(kf)) trackIt[i] = 0;
727 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
731 } // particle selection loop
733 for (i = 0; i < np; i++) {
734 if (!pSelected[i]) continue;
735 TParticle * iparticle = (TParticle *) fParticles.At(i);
736 kf = CheckPDGCode(iparticle->GetPdgCode());
737 Int_t ks = iparticle->GetStatusCode();
738 p[0] = iparticle->Px();
739 p[1] = iparticle->Py();
740 p[2] = iparticle->Pz();
741 p[3] = iparticle->Energy();
743 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
744 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
745 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
747 Float_t tof = kconv*iparticle->T();
748 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
749 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
751 PushTrack(fTrackIt*trackIt[i], iparent, kf,
752 p[0], p[1], p[2], p[3],
753 origin[0], origin[1], origin[2], tof,
754 polar[0], polar[1], polar[2],
755 kPPrimary, nt, 1., ks);
772 switch (fCountMode) {
774 // printf(" Count all \n");
778 // printf(" Count parents \n");
781 case kCountTrackables:
782 // printf(" Count trackable \n");
786 if (jev >= fNpart || fNpart == -1) {
787 fKineBias=Float_t(fNpart)/Float_t(fTrials);
788 fPythia->GetXandQ(fQ, fX1, fX2);
789 fTrialsRun += fTrials;
796 SetHighWaterMark(nt);
797 // Adjust weight due to kinematic selection
800 fXsection = fPythia->GetXSection();
803 Int_t AliGenPythiaPlus::GenerateMB()
806 // Min Bias selection and other global selections
808 Int_t i, kf, nt, iparent;
811 Float_t polar[3] = {0,0,0};
812 Float_t origin[3] = {0,0,0};
813 // converts from mm/c to s
814 const Float_t kconv = 0.001 / 2.999792458e8;
816 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
818 Int_t* pParent = new Int_t[np];
819 for (i=0; i< np; i++) pParent[i] = -1;
820 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
821 TParticle* jet1 = (TParticle *) fParticles.At(6);
822 TParticle* jet2 = (TParticle *) fParticles.At(7);
823 if (!CheckTrigger(jet1, jet2)) {
829 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
830 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
835 if (fFragPhotonInCalo) pdg = 22 ; // Photon
836 else if (fPi0InCalo) pdg = 111 ; // Pi0
838 for (i=0; i< np; i++) {
839 TParticle* iparticle = (TParticle *) fParticles.At(i);
840 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
841 iparticle->Pt() > fFragPhotonOrPi0MinPt){
842 Int_t imother = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
843 TParticle* pmother = (TParticle *) fParticles.At(imother);
845 (pdg == 22 && pmother->GetStatusCode() != 11))//No photon from hadron decay
847 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
848 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
849 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
850 (fCheckPHOS && IsInPHOS(phi,eta)) )
860 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
861 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
867 for (i=0; i< np; i++) {
868 TParticle* iparticle = (TParticle *) fParticles.At(i);
869 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
870 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
872 if(iparticle->GetStatusCode() == 1
873 && iparticle->GetPdgCode() == pdg
874 && iparticle->Pt() > fPhotonMinPt
877 // first check if the photon is in PHOS phi
878 if(IsInPHOS(phi,eta)){
882 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
887 if(!okd && iphcand != -1) // execute rotation in phi
888 RotatePhi(iphcand,okd);
894 if (fTriggerParticle) {
895 Bool_t triggered = kFALSE;
896 for (i = 0; i < np; i++) {
897 TParticle * iparticle = (TParticle *) fParticles.At(i);
898 kf = CheckPDGCode(iparticle->GetPdgCode());
899 if (kf != fTriggerParticle) continue;
900 if (iparticle->Pt() == 0.) continue;
901 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
912 // Check if there is a ccbar or bbbar pair with at least one of the two
913 // in fYMin < y < fYMax
914 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi) {
915 TParticle *partCheck;
917 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
918 Bool_t theChild=kFALSE;
920 Int_t pdg,mpdg,mpdgUpperFamily;
921 for(i=0; i<np; i++) {
922 partCheck = (TParticle*)fParticles.At(i);
923 pdg = partCheck->GetPdgCode();
924 if(TMath::Abs(pdg) == fFlavorSelect) { // quark
925 if(pdg>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
926 y = 0.5*TMath::Log((partCheck->Energy()+partCheck->Pz()+1.e-13)/
927 (partCheck->Energy()-partCheck->Pz()+1.e-13));
928 if(y>fYMin && y<fYMax) inYcut=kTRUE;
931 if(fCutOnChild && TMath::Abs(pdg) == fPdgCodeParticleforAcceptanceCut) {
932 Int_t mi = partCheck->GetFirstMother() - 1;
934 mother = (TParticle*)fParticles.At(mi);
935 mpdg=TMath::Abs(mother->GetPdgCode());
936 mpdgUpperFamily=(mpdg>1000 ? mpdg+1000 : mpdg+100); // keep e from c from b
937 if ( ParentSelected(mpdg) ||
938 (fFlavorSelect==5 && ParentSelected(mpdgUpperFamily))) {
939 if (KinematicSelection(partCheck,1)) {
945 if (!theQ || !theQbar || !inYcut) { // one of the c/b conditions not satisfied
949 if (fCutOnChild && !theChild) { // one of the child conditions not satisfied
956 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
957 if ( (fProcess == kPyW ||
959 fProcess == kPyMbDefault ||
961 fProcess == kPyMbWithDirectPhoton ||
962 fProcess == kPyMbNonDiffr)
963 && (fCutOnChild == 1) ) {
964 if ( !CheckKinematicsOnChild() ) {
971 for (i = 0; i < np; i++) {
973 TParticle * iparticle = (TParticle *) fParticles.At(i);
974 kf = CheckPDGCode(iparticle->GetPdgCode());
975 Int_t ks = iparticle->GetStatusCode();
976 Int_t km = iparticle->GetFirstMother();
977 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
979 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
981 if (ks == 1) trackIt = 1;
983 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
984 iparent = (ipa > -1) ? pParent[ipa] : -1;
985 if (ipa >= np) fPythia->EventListing();
988 // store track information
989 p[0] = iparticle->Px();
990 p[1] = iparticle->Py();
991 p[2] = iparticle->Pz();
992 p[3] = iparticle->Energy();
995 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
996 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
997 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
999 Float_t tof = fEventTime + kconv * iparticle->T();
1001 PushTrack(fTrackIt*trackIt, iparent, kf,
1002 p[0], p[1], p[2], p[3],
1003 origin[0], origin[1], origin[2], tof,
1004 polar[0], polar[1], polar[2],
1005 kPPrimary, nt, 1., ks);
1010 // Special Treatment to store color-flow
1012 if (ks == 3 || ks == 13 || ks == 14) {
1013 TParticle* particle = 0;
1015 particle = fStack->Particle(nt);
1017 particle = AliRunLoader::Instance()->Stack()->Particle(nt);
1019 // particle->SetFirstDaughter(fPythia->GetK(2, i));
1020 // particle->SetLastDaughter(fPythia->GetK(3, i));
1025 SetHighWaterMark(nt);
1027 } // select particle
1036 void AliGenPythiaPlus::FinishRun()
1038 // Print x-section summary
1039 fPythia->PrintStatistics();
1047 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1048 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1051 void AliGenPythiaPlus::AdjustWeights() const
1053 // Adjust the weights after generation of all events
1057 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1058 for (Int_t i=0; i<ntrack; i++) {
1059 part= gAlice->GetMCApp()->Particle(i);
1060 part->SetWeight(part->GetWeight()*fKineBias);
1065 void AliGenPythiaPlus::SetNuclei(Int_t a1, Int_t a2)
1067 // Treat protons as inside nuclei with mass numbers a1 and a2
1075 void AliGenPythiaPlus::MakeHeader()
1078 // Make header for the simulated event
1081 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1082 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->EventListing();
1085 // Builds the event header, to be called after each event
1086 if (fHeader) delete fHeader;
1087 fHeader = new AliGenPythiaEventHeader("Pythia");
1090 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->ProcessCode());
1093 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1096 fHeader->SetPrimaryVertex(fVertex);
1099 // Number of primaries
1100 fHeader->SetNProduced(fNprimaries);
1102 // Jets that have triggered
1104 if (fProcess == kPyJets)
1107 Float_t jets[4][10];
1108 GetJets(njet, ntrig, jets);
1111 for (Int_t i = 0; i < ntrig; i++) {
1112 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1117 // Copy relevant information from external header, if present.
1122 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1123 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1125 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1128 exHeader->TriggerJet(i, uqJet);
1129 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1133 // Store quenching parameters
1140 fPythia->GetQuenchingParameters(xp, yp, z);
1143 Double_t r1 = PARIMP.rb1;
1144 Double_t r2 = PARIMP.rb2;
1145 Double_t b = PARIMP.b1;
1146 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1147 Double_t phi = PARIMP.psib1;
1148 xp = r * TMath::Cos(phi);
1149 yp = r * TMath::Sin(phi);
1152 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1153 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1157 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetPtHard());
1165 Bool_t AliGenPythiaPlus::CheckTrigger(TParticle* jet1, TParticle* jet2)
1167 // Check the kinematic trigger condition
1170 eta[0] = jet1->Eta();
1171 eta[1] = jet2->Eta();
1173 phi[0] = jet1->Phi();
1174 phi[1] = jet2->Phi();
1176 pdg[0] = jet1->GetPdgCode();
1177 pdg[1] = jet2->GetPdgCode();
1178 Bool_t triggered = kFALSE;
1180 if (fProcess == kPyJets) {
1183 Float_t jets[4][10];
1185 // Use Pythia clustering on parton level to determine jet axis
1187 GetJets(njets, ntrig, jets);
1189 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1194 if (pdg[0] == kGamma) {
1198 //Check eta range first...
1199 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1200 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1202 //Eta is okay, now check phi range
1203 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1204 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1215 Bool_t AliGenPythiaPlus::CheckKinematicsOnChild(){
1217 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1219 Bool_t checking = kFALSE;
1220 Int_t j, kcode, ks, km;
1221 Int_t nPartAcc = 0; //number of particles in the acceptance range
1222 Int_t numberOfAcceptedParticles = 1;
1223 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1224 Int_t npart = fParticles.GetEntriesFast();
1226 for (j = 0; j<npart; j++) {
1227 TParticle * jparticle = (TParticle *) fParticles.At(j);
1228 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1229 ks = jparticle->GetStatusCode();
1230 km = jparticle->GetFirstMother();
1232 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1235 if( numberOfAcceptedParticles <= nPartAcc){
1244 void AliGenPythiaPlus::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1247 // Calls the Pythia jet finding algorithm to find jets in the current event
1254 fPythia->Pycell(njets);
1256 for (i = 0; i < njets; i++) {
1257 Float_t px, py, pz, e;
1258 fPythia->GetJet(i, px, py, pz, e);
1267 void AliGenPythiaPlus::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1270 // Calls the Pythia clustering algorithm to find jets in the current event
1274 if (fJetReconstruction == kCluster) {
1276 // Configure cluster algorithm
1278 // fPythia->SetPARU(43, 2.);
1279 // fPythia->SetMSTU(41, 1);
1281 // Call cluster algorithm
1283 fPythia->Pyclus(nJets);
1285 // Loading jets from common block
1291 fPythia->Pycell(nJets);
1295 for (i = 0; i < nJets; i++) {
1296 Float_t px, py, pz, e;
1297 fPythia->GetJet(i, px, py, pz, e);
1298 Float_t pt = TMath::Sqrt(px * px + py * py);
1299 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1300 Float_t theta = TMath::ATan2(pt,pz);
1301 Float_t et = e * TMath::Sin(theta);
1302 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1304 eta > fEtaMinJet && eta < fEtaMaxJet &&
1305 phi > fPhiMinJet && phi < fPhiMaxJet &&
1306 et > fEtMinJet && et < fEtMaxJet
1309 jets[0][nJetsTrig] = px;
1310 jets[1][nJetsTrig] = py;
1311 jets[2][nJetsTrig] = pz;
1312 jets[3][nJetsTrig] = e;
1319 void AliGenPythiaPlus::GetSubEventTime()
1321 // Calculates time of the next subevent
1324 TArrayF &array = *fEventsTime;
1325 fEventTime = array[fCurSubEvent++];
1327 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1334 Bool_t AliGenPythiaPlus::IsInEMCAL(Float_t phi, Float_t eta)
1336 // Is particle in EMCAL acceptance?
1337 // phi in degrees, etamin=-etamax
1338 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1345 Bool_t AliGenPythiaPlus::IsInPHOS(Float_t phi, Float_t eta)
1347 // Is particle in PHOS acceptance?
1348 // Acceptance slightly larger considered.
1349 // phi in degrees, etamin=-etamax
1350 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1357 void AliGenPythiaPlus::RotatePhi(Int_t iphcand, Bool_t& okdd)
1359 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1360 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1361 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1362 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1364 //calculate deltaphi
1365 TParticle* ph = (TParticle *) fParticles.At(iphcand);
1366 Double_t phphi = ph->Phi();
1367 Double_t deltaphi = phiPHOS - phphi;
1371 //loop for all particles and produce the phi rotation
1372 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
1373 Double_t oldphi, newphi;
1374 Double_t newVx, newVy, R, Vz, time;
1375 Double_t newPx, newPy, pt, Pz, e;
1376 for(Int_t i=0; i< np; i++) {
1377 TParticle* iparticle = (TParticle *) fParticles.At(i);
1378 oldphi = iparticle->Phi();
1379 newphi = oldphi + deltaphi;
1380 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1381 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1384 newVx = R*TMath::Cos(newphi);
1385 newVy = R*TMath::Sin(newphi);
1386 Vz = iparticle->Vz(); // don't transform
1387 time = iparticle->T(); // don't transform
1389 pt = iparticle->Pt();
1390 newPx = pt*TMath::Cos(newphi);
1391 newPy = pt*TMath::Sin(newphi);
1392 Pz = iparticle->Pz(); // don't transform
1393 e = iparticle->Energy(); // don't transform
1396 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1397 iparticle->SetMomentum(newPx, newPy, Pz, e);
1399 } //end particle loop
1401 // now let's check that we put correctly the candidate photon in PHOS
1402 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1403 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1404 if(IsInPHOS(phi,eta))
1410 void AliGenPythiaPlus::Streamer(TBuffer &R__b)
1412 // Stream an object of class AliGenPythia.
1414 if (R__b.IsReading()) {
1415 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1416 AliGenerator::Streamer(R__b);
1417 R__b >> (Int_t&)fProcess;
1418 R__b >> (Int_t&)fStrucFunc;
1419 R__b >> (Int_t&)fForceDecay;
1423 fParentSelect.Streamer(R__b);
1424 fChildSelect.Streamer(R__b);
1426 // (AliPythia::Instance())->Streamer(R__b);
1429 // if (fDecayer) fDecayer->Streamer(R__b);
1431 R__b.WriteVersion(AliGenPythiaPlus::IsA());
1432 AliGenerator::Streamer(R__b);
1433 R__b << (Int_t)fProcess;
1434 R__b << (Int_t)fStrucFunc;
1435 R__b << (Int_t)fForceDecay;
1439 fParentSelect.Streamer(R__b);
1440 fChildSelect.Streamer(R__b);
1445 // fDecayer->Streamer(R__b);