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():
82 fDecayer(new AliDecayerPythia()),
90 fPhiMaxJet(2.* TMath::Pi()),
91 fJetReconstruction(kCell),
95 fPhiMaxGamma(2. * TMath::Pi()),
101 fPycellMinEtJet(10.),
102 fPycellMaxRadius(1.),
103 fStackFillOpt(kFlavorSelection),
105 fFragmentation(kTRUE),
111 fCountMode(kCountAll),
115 fFragPhotonInCalo(kFALSE),
117 fPhotonInCalo(kFALSE),
120 fCheckPHOSeta(kFALSE),
121 fFragPhotonOrPi0MinPt(0),
131 // Default Constructor
133 if (!AliPythiaRndm::GetPythiaRandom())
134 AliPythiaRndm::SetPythiaRandom(GetRandom());
137 AliGenPythiaPlus::AliGenPythiaPlus(AliPythiaBase* pythia)
150 fInteractionRate(0.),
163 fHadronisation(kTRUE),
165 fReadFromFile(kFALSE),
169 fDecayer(new AliDecayerPythia()),
170 fDebugEventFirst(-1),
177 fPhiMaxJet(2.* TMath::Pi()),
178 fJetReconstruction(kCell),
182 fPhiMaxGamma(2. * TMath::Pi()),
186 fPycellThreshold(0.),
188 fPycellMinEtJet(10.),
189 fPycellMaxRadius(1.),
190 fStackFillOpt(kFlavorSelection),
192 fFragmentation(kTRUE),
198 fCountMode(kCountAll),
202 fFragPhotonInCalo(kFALSE),
204 fPhotonInCalo(kFALSE),
207 fCheckPHOSeta(kFALSE),
208 fFragPhotonOrPi0MinPt(0),
217 // default charm production at 5. 5 TeV
219 // structure function GRVHO
222 fTitle= "Particle Generator using PYTHIA";
224 // Set random number generator
225 if (!AliPythiaRndm::GetPythiaRandom())
226 AliPythiaRndm::SetPythiaRandom(GetRandom());
227 fParticles = new TClonesArray("TParticle",1000);
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);
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;
384 fParentSelect[0] = 421;
387 case kPyDPlusPbPbMNR:
390 fParentSelect[0] = 411;
393 case kPyDPlusStrangePbPbMNR:
394 case kPyDPlusStrangepPbMNR:
395 case kPyDPlusStrangeppMNR:
396 fParentSelect[0] = 431;
400 case kPyBeautyPbPbMNR:
401 case kPyBeautypPbMNR:
403 case kPyBeautyppMNRwmi:
404 fParentSelect[0]= 511;
405 fParentSelect[1]= 521;
406 fParentSelect[2]= 531;
407 fParentSelect[3]= 5122;
408 fParentSelect[4]= 5132;
409 fParentSelect[5]= 5232;
410 fParentSelect[6]= 5332;
413 case kPyBeautyUnforced:
414 fParentSelect[0] = 511;
415 fParentSelect[1] = 521;
416 fParentSelect[2] = 531;
417 fParentSelect[3] = 5122;
418 fParentSelect[4] = 5132;
419 fParentSelect[5] = 5232;
420 fParentSelect[6] = 5332;
425 fParentSelect[0] = 443;
441 // JetFinder for Trigger
443 // Configure detector (EMCAL like)
445 fPythia->SetPycellParameters(fPycellEtaMax,fPycellNEta, fPycellNPhi,
446 fPycellThreshold, fPycellEtSeed,
447 fPycellMinEtJet, fPycellMaxRadius);
449 // This counts the total number of calls to Pyevnt() per run.
464 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
468 fPythia->InitQuenching(0., 0.1, 0.6e6, 0, 0.97, 30);
471 // fPythia->SetPARJ(200, 0.0);
473 // if (fQuench == 3) {
474 // // Nestor's change of the splittings
475 // fPythia->SetPARJ(200, 0.8);
476 // fPythia->SetMSTJ(41, 1); // QCD radiation only
477 // fPythia->SetMSTJ(42, 2); // angular ordering
478 // fPythia->SetMSTJ(44, 2); // option to run alpha_s
479 // fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
480 // fPythia->SetMSTJ(50, 0); // No coherence in first branching
481 // fPythia->SetPARJ(82, 1.); // Cut off for parton showers
485 void AliGenPythiaPlus::Generate()
487 // Generate one event
489 fDecayer->ForceDecay();
491 Float_t polar[3] = {0,0,0};
492 Float_t origin[3] = {0,0,0};
494 // converts from mm/c to s
495 const Float_t kconv=0.001/2.999792458e8;
505 // Set collision vertex position
506 if (fVertexSmear == kPerEvent) Vertex();
515 // Switch hadronisation off
517 // fPythia->SwitchHadronisationOff();
519 // Either produce new event or read partons from file
521 if (!fReadFromFile) {
523 fPythia->GenerateEvent();
525 fPythia->GenerateMIEvent();
527 fNpartons = fPythia->GetNumberOfParticles();
529 printf("Loading Event %d\n",AliRunLoader::GetRunLoader()->GetEventNumber());
530 fRL->GetEvent(AliRunLoader::GetRunLoader()->GetEventNumber());
531 fPythia->SetNumberOfParticles(0);
532 fPythia->LoadEvent(fRL->Stack(), 0 , 1);
533 fPythia->EditEventList(21);
537 // Run quenching routine
541 } else if (fQuench == 2){
542 fPythia->Pyquen(208., 0, 0.);
543 } else if (fQuench == 3) {
544 // Quenching is via multiplicative correction of the splittings
548 // Switch hadronisation on
550 // fPythia->SwitchHadronisationOn();
552 // .. and perform hadronisation
553 // printf("Calling hadronisation %d\n", fPythia->GetN());
554 // fPythia->HadronizeEvent();
556 fPythia->GetParticles(fParticles);
564 Int_t np = fParticles->GetEntriesFast();
566 if (np == 0) continue;
570 Int_t* pParent = new Int_t[np];
571 Int_t* pSelected = new Int_t[np];
572 Int_t* trackIt = new Int_t[np];
573 for (i = 0; i < np; i++) {
579 Int_t nc = 0; // Total n. of selected particles
580 Int_t nParents = 0; // Selected parents
581 Int_t nTkbles = 0; // Trackable particles
582 if (fProcess != kPyMbDefault &&
584 fProcess != kPyJets &&
585 fProcess != kPyDirectGamma &&
586 fProcess != kPyMbNonDiffr &&
587 fProcess != kPyMbMSEL1 &&
590 fProcess != kPyCharmppMNRwmi &&
591 fProcess != kPyBeautyppMNRwmi) {
593 for (i = 0; i < np; i++) {
594 TParticle* iparticle = (TParticle *) fParticles->At(i);
595 Int_t ks = iparticle->GetStatusCode();
596 kf = CheckPDGCode(iparticle->GetPdgCode());
597 // No initial state partons
598 if (ks==21) continue;
600 // Heavy Flavor Selection
607 if (kfl > 100000) kfl %= 100000;
608 if (kfl > 10000) kfl %= 10000;
610 if (kfl > 10) kfl/=100;
612 if (kfl > 10) kfl/=10;
613 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
616 // Establish mother daughter relation between heavy quarks and mesons
618 if (kf >= fFlavorSelect && kf <= 6) {
619 Int_t idau = (fPythia->Version() == 6) ? (iparticle->GetFirstDaughter() - 1) :(iparticle->GetFirstDaughter());
621 TParticle* daughter = (TParticle *) fParticles->At(idau);
622 Int_t pdgD = daughter->GetPdgCode();
623 if (pdgD == 91 || pdgD == 92) {
624 Int_t jmin = (fPythia->Version() == 6) ? (daughter->GetFirstDaughter() - 1) : (daughter->GetFirstDaughter());
625 Int_t jmax = (fPythia->Version() == 6) ? (daughter->GetLastDaughter() - 1) : (daughter->GetLastDaughter());
627 for (Int_t j = jmin; j <= jmax; j++)
628 ((TParticle *) fParticles->At(j))->SetFirstMother(i+1);
629 } // is string or cluster
635 TParticle * mother = (TParticle *) fParticles->At(ipa);
636 kfMo = TMath::Abs(mother->GetPdgCode());
639 // What to keep in Stack?
640 Bool_t flavorOK = kFALSE;
641 Bool_t selectOK = kFALSE;
643 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
645 if (kfl > fFlavorSelect) {
649 if (kfl == fFlavorSelect) flavorOK = kTRUE;
651 switch (fStackFillOpt) {
652 case kFlavorSelection:
655 case kParentSelection:
656 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
659 if (flavorOK && selectOK) {
661 // Heavy flavor hadron or quark
663 // Kinematic seletion on final state heavy flavor mesons
664 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
669 if (ParentSelected(kf)) ++nParents; // Update parent count
670 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
672 // Kinematic seletion on decay products
673 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
674 && !KinematicSelection(iparticle, 1))
680 // Select if mother was selected and is not tracked
682 if (pSelected[ipa] &&
683 !trackIt[ipa] && // mother will be tracked ?
684 kfMo != 5 && // mother is b-quark, don't store fragments
685 kfMo != 4 && // mother is c-quark, don't store fragments
686 kf != 92) // don't store string
689 // Semi-stable or de-selected: diselect decay products:
692 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
694 Int_t ipF = iparticle->GetFirstDaughter();
695 Int_t ipL = iparticle->GetLastDaughter();
696 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
698 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
699 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
702 if (pSelected[i] == -1) pSelected[i] = 0;
703 if (!pSelected[i]) continue;
704 // Count quarks only if you did not include fragmentation
705 if (fFragmentation && kf <= 10) continue;
708 // Decision on tracking
711 // Track final state particle
712 if (ks == 1) trackIt[i] = 1;
713 // Track semi-stable particles
714 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
715 // Track particles selected by process if undecayed.
716 if (fForceDecay == kNoDecay) {
717 if (ParentSelected(kf)) trackIt[i] = 1;
719 if (ParentSelected(kf)) trackIt[i] = 0;
721 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
725 } // particle selection loop
727 for (i = 0; i < np; i++) {
728 if (!pSelected[i]) continue;
729 TParticle * iparticle = (TParticle *) fParticles->At(i);
730 kf = CheckPDGCode(iparticle->GetPdgCode());
731 Int_t ks = iparticle->GetStatusCode();
732 p[0] = iparticle->Px();
733 p[1] = iparticle->Py();
734 p[2] = iparticle->Pz();
735 p[3] = iparticle->Energy();
737 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
738 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
739 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
741 Float_t tof = kconv*iparticle->T();
742 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
743 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
745 PushTrack(fTrackIt*trackIt[i], iparent, kf,
746 p[0], p[1], p[2], p[3],
747 origin[0], origin[1], origin[2], tof,
748 polar[0], polar[1], polar[2],
749 kPPrimary, nt, 1., ks);
766 switch (fCountMode) {
768 // printf(" Count all \n");
772 // printf(" Count parents \n");
775 case kCountTrackables:
776 // printf(" Count trackable \n");
780 if (jev >= fNpart || fNpart == -1) {
781 fKineBias=Float_t(fNpart)/Float_t(fTrials);
782 fPythia->GetXandQ(fQ, fX1, fX2);
783 fTrialsRun += fTrials;
790 SetHighWaterMark(nt);
791 // Adjust weight due to kinematic selection
794 fXsection = fPythia->GetXSection();
797 Int_t AliGenPythiaPlus::GenerateMB()
800 // Min Bias selection and other global selections
802 Int_t i, kf, nt, iparent;
805 Float_t polar[3] = {0,0,0};
806 Float_t origin[3] = {0,0,0};
807 // converts from mm/c to s
808 const Float_t kconv = 0.001 / 2.999792458e8;
810 Int_t np = (fHadronisation) ? fParticles->GetEntriesFast() : fNpartons;
812 Int_t* pParent = new Int_t[np];
813 for (i=0; i< np; i++) pParent[i] = -1;
814 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
815 TParticle* jet1 = (TParticle *) fParticles->At(6);
816 TParticle* jet2 = (TParticle *) fParticles->At(7);
817 if (!CheckTrigger(jet1, jet2)) {
823 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
824 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
829 if (fFragPhotonInCalo) pdg = 22 ; // Photon
830 else if (fPi0InCalo) pdg = 111 ; // Pi0
832 for (i=0; i< np; i++) {
833 TParticle* iparticle = (TParticle *) fParticles->At(i);
834 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
835 iparticle->Pt() > fFragPhotonOrPi0MinPt){
836 Int_t imother = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
837 TParticle* pmother = (TParticle *) fParticles->At(imother);
839 (pdg == 22 && pmother->GetStatusCode() != 11))//No photon from hadron decay
841 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
842 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
843 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
844 (fCheckPHOS && IsInPHOS(phi,eta)) )
854 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
855 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
861 for (i=0; i< np; i++) {
862 TParticle* iparticle = (TParticle *) fParticles->At(i);
863 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
864 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
866 if(iparticle->GetStatusCode() == 1
867 && iparticle->GetPdgCode() == pdg
868 && iparticle->Pt() > fPhotonMinPt
871 // first check if the photon is in PHOS phi
872 if(IsInPHOS(phi,eta)){
876 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
881 if(!okd && iphcand != -1) // execute rotation in phi
882 RotatePhi(iphcand,okd);
888 if (fTriggerParticle) {
889 Bool_t triggered = kFALSE;
890 for (i = 0; i < np; i++) {
891 TParticle * iparticle = (TParticle *) fParticles->At(i);
892 kf = CheckPDGCode(iparticle->GetPdgCode());
893 if (kf != fTriggerParticle) continue;
894 if (iparticle->Pt() == 0.) continue;
895 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
906 // Check if there is a ccbar or bbbar pair with at least one of the two
907 // in fYMin < y < fYMax
908 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi) {
910 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
913 for(i=0; i<np; i++) {
914 hvq = (TParticle*)fParticles->At(i);
915 pdgQ = hvq->GetPdgCode();
916 if(TMath::Abs(pdgQ) != fFlavorSelect) continue;
917 if(pdgQ>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
918 yQ = 0.5*TMath::Log((hvq->Energy()+hvq->Pz()+1.e-13)/
919 (hvq->Energy()-hvq->Pz()+1.e-13));
920 if(yQ>fYMin && yQ<fYMax) inYcut=kTRUE;
922 if (!theQ || !theQbar || !inYcut) {
928 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
929 if ( (fProcess == kPyW ||
931 fProcess == kPyMbDefault ||
933 fProcess == kPyMbNonDiffr)
934 && (fCutOnChild == 1) ) {
935 if ( !CheckKinematicsOnChild() ) {
942 for (i = 0; i < np; i++) {
944 TParticle * iparticle = (TParticle *) fParticles->At(i);
945 kf = CheckPDGCode(iparticle->GetPdgCode());
946 Int_t ks = iparticle->GetStatusCode();
947 Int_t km = iparticle->GetFirstMother();
948 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
950 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
952 if (ks == 1) trackIt = 1;
954 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
955 iparent = (ipa > -1) ? pParent[ipa] : -1;
956 if (ipa >= np) fPythia->EventListing();
959 // store track information
960 p[0] = iparticle->Px();
961 p[1] = iparticle->Py();
962 p[2] = iparticle->Pz();
963 p[3] = iparticle->Energy();
966 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
967 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
968 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
970 Float_t tof = fEventTime + kconv * iparticle->T();
972 PushTrack(fTrackIt*trackIt, iparent, kf,
973 p[0], p[1], p[2], p[3],
974 origin[0], origin[1], origin[2], tof,
975 polar[0], polar[1], polar[2],
976 kPPrimary, nt, 1., ks);
981 // Special Treatment to store color-flow
983 if (ks == 3 || ks == 13 || ks == 14) {
984 TParticle* particle = 0;
986 particle = fStack->Particle(nt);
988 particle = gAlice->Stack()->Particle(nt);
990 // particle->SetFirstDaughter(fPythia->GetK(2, i));
991 // particle->SetLastDaughter(fPythia->GetK(3, i));
996 SetHighWaterMark(nt);
1007 void AliGenPythiaPlus::FinishRun()
1009 // Print x-section summary
1010 fPythia->PrintStatistics();
1018 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1019 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1022 void AliGenPythiaPlus::AdjustWeights() const
1024 // Adjust the weights after generation of all events
1028 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1029 for (Int_t i=0; i<ntrack; i++) {
1030 part= gAlice->GetMCApp()->Particle(i);
1031 part->SetWeight(part->GetWeight()*fKineBias);
1036 void AliGenPythiaPlus::SetNuclei(Int_t a1, Int_t a2)
1038 // Treat protons as inside nuclei with mass numbers a1 and a2
1046 void AliGenPythiaPlus::MakeHeader()
1049 // Make header for the simulated event
1052 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1053 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->EventListing();
1056 // Builds the event header, to be called after each event
1057 if (fHeader) delete fHeader;
1058 fHeader = new AliGenPythiaEventHeader("Pythia");
1061 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->ProcessCode());
1064 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1067 fHeader->SetPrimaryVertex(fVertex);
1070 // Number of primaries
1071 fHeader->SetNProduced(fNprimaries);
1073 // Jets that have triggered
1075 if (fProcess == kPyJets)
1078 Float_t jets[4][10];
1079 GetJets(njet, ntrig, jets);
1082 for (Int_t i = 0; i < ntrig; i++) {
1083 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1088 // Copy relevant information from external header, if present.
1093 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1094 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1096 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1099 exHeader->TriggerJet(i, uqJet);
1100 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1104 // Store quenching parameters
1111 fPythia->GetQuenchingParameters(xp, yp, z);
1114 Double_t r1 = PARIMP.rb1;
1115 Double_t r2 = PARIMP.rb2;
1116 Double_t b = PARIMP.b1;
1117 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1118 Double_t phi = PARIMP.psib1;
1119 xp = r * TMath::Cos(phi);
1120 yp = r * TMath::Sin(phi);
1123 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1124 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1128 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetPtHard());
1136 Bool_t AliGenPythiaPlus::CheckTrigger(TParticle* jet1, TParticle* jet2)
1138 // Check the kinematic trigger condition
1141 eta[0] = jet1->Eta();
1142 eta[1] = jet2->Eta();
1144 phi[0] = jet1->Phi();
1145 phi[1] = jet2->Phi();
1147 pdg[0] = jet1->GetPdgCode();
1148 pdg[1] = jet2->GetPdgCode();
1149 Bool_t triggered = kFALSE;
1151 if (fProcess == kPyJets) {
1154 Float_t jets[4][10];
1156 // Use Pythia clustering on parton level to determine jet axis
1158 GetJets(njets, ntrig, jets);
1160 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1165 if (pdg[0] == kGamma) {
1169 //Check eta range first...
1170 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1171 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1173 //Eta is okay, now check phi range
1174 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1175 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1186 Bool_t AliGenPythiaPlus::CheckKinematicsOnChild(){
1188 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1190 Bool_t checking = kFALSE;
1191 Int_t j, kcode, ks, km;
1192 Int_t nPartAcc = 0; //number of particles in the acceptance range
1193 Int_t numberOfAcceptedParticles = 1;
1194 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1195 Int_t npart = fParticles->GetEntriesFast();
1197 for (j = 0; j<npart; j++) {
1198 TParticle * jparticle = (TParticle *) fParticles->At(j);
1199 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1200 ks = jparticle->GetStatusCode();
1201 km = jparticle->GetFirstMother();
1203 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1206 if( numberOfAcceptedParticles <= nPartAcc){
1215 void AliGenPythiaPlus::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1218 // Calls the Pythia jet finding algorithm to find jets in the current event
1225 fPythia->Pycell(njets);
1227 for (i = 0; i < njets; i++) {
1228 Float_t px, py, pz, e;
1229 fPythia->GetJet(i, px, py, pz, e);
1238 void AliGenPythiaPlus::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1241 // Calls the Pythia clustering algorithm to find jets in the current event
1245 if (fJetReconstruction == kCluster) {
1247 // Configure cluster algorithm
1249 // fPythia->SetPARU(43, 2.);
1250 // fPythia->SetMSTU(41, 1);
1252 // Call cluster algorithm
1254 fPythia->Pyclus(nJets);
1256 // Loading jets from common block
1262 fPythia->Pycell(nJets);
1266 for (i = 0; i < nJets; i++) {
1267 Float_t px, py, pz, e;
1268 fPythia->GetJet(i, px, py, pz, e);
1269 Float_t pt = TMath::Sqrt(px * px + py * py);
1270 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1271 Float_t theta = TMath::ATan2(pt,pz);
1272 Float_t et = e * TMath::Sin(theta);
1273 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1275 eta > fEtaMinJet && eta < fEtaMaxJet &&
1276 phi > fPhiMinJet && phi < fPhiMaxJet &&
1277 et > fEtMinJet && et < fEtMaxJet
1280 jets[0][nJetsTrig] = px;
1281 jets[1][nJetsTrig] = py;
1282 jets[2][nJetsTrig] = pz;
1283 jets[3][nJetsTrig] = e;
1290 void AliGenPythiaPlus::GetSubEventTime()
1292 // Calculates time of the next subevent
1295 TArrayF &array = *fEventsTime;
1296 fEventTime = array[fCurSubEvent++];
1298 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1305 Bool_t AliGenPythiaPlus::IsInEMCAL(Float_t phi, Float_t eta)
1307 // Is particle in EMCAL acceptance?
1308 // phi in degrees, etamin=-etamax
1309 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1316 Bool_t AliGenPythiaPlus::IsInPHOS(Float_t phi, Float_t eta)
1318 // Is particle in PHOS acceptance?
1319 // Acceptance slightly larger considered.
1320 // phi in degrees, etamin=-etamax
1321 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1328 void AliGenPythiaPlus::RotatePhi(Int_t iphcand, Bool_t& okdd)
1330 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1331 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1332 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1333 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1335 //calculate deltaphi
1336 TParticle* ph = (TParticle *) fParticles->At(iphcand);
1337 Double_t phphi = ph->Phi();
1338 Double_t deltaphi = phiPHOS - phphi;
1342 //loop for all particles and produce the phi rotation
1343 Int_t np = (fHadronisation) ? fParticles->GetEntriesFast() : fNpartons;
1344 Double_t oldphi, newphi;
1345 Double_t newVx, newVy, R, Vz, time;
1346 Double_t newPx, newPy, pt, Pz, e;
1347 for(Int_t i=0; i< np; i++) {
1348 TParticle* iparticle = (TParticle *) fParticles->At(i);
1349 oldphi = iparticle->Phi();
1350 newphi = oldphi + deltaphi;
1351 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1352 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1355 newVx = R*TMath::Cos(newphi);
1356 newVy = R*TMath::Sin(newphi);
1357 Vz = iparticle->Vz(); // don't transform
1358 time = iparticle->T(); // don't transform
1360 pt = iparticle->Pt();
1361 newPx = pt*TMath::Cos(newphi);
1362 newPy = pt*TMath::Sin(newphi);
1363 Pz = iparticle->Pz(); // don't transform
1364 e = iparticle->Energy(); // don't transform
1367 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1368 iparticle->SetMomentum(newPx, newPy, Pz, e);
1370 } //end particle loop
1372 // now let's check that we put correctly the candidate photon in PHOS
1373 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1374 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1375 if(IsInPHOS(phi,eta))
1381 void AliGenPythiaPlus::Streamer(TBuffer &R__b)
1383 // Stream an object of class AliGenPythia.
1385 if (R__b.IsReading()) {
1386 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1387 AliGenerator::Streamer(R__b);
1388 R__b >> (Int_t&)fProcess;
1389 R__b >> (Int_t&)fStrucFunc;
1390 R__b >> (Int_t&)fForceDecay;
1394 fParentSelect.Streamer(R__b);
1395 fChildSelect.Streamer(R__b);
1397 // (AliPythia::Instance())->Streamer(R__b);
1400 // if (fDecayer) fDecayer->Streamer(R__b);
1402 R__b.WriteVersion(AliGenPythiaPlus::IsA());
1403 AliGenerator::Streamer(R__b);
1404 R__b << (Int_t)fProcess;
1405 R__b << (Int_t)fStrucFunc;
1406 R__b << (Int_t)fForceDecay;
1410 fParentSelect.Streamer(R__b);
1411 fChildSelect.Streamer(R__b);
1416 // fDecayer->Streamer(R__b);