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),
131 // Default Constructor
134 if (!AliPythiaRndm::GetPythiaRandom())
135 AliPythiaRndm::SetPythiaRandom(GetRandom());
138 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),
219 // default charm production at 5. 5 TeV
221 // structure function GRVHO
225 fTitle= "Particle Generator using PYTHIA";
227 // Set random number generator
228 if (!AliPythiaRndm::GetPythiaRandom())
229 AliPythiaRndm::SetPythiaRandom(GetRandom());
233 AliGenPythiaPlus::~AliGenPythiaPlus()
236 if(fEventsTime) delete fEventsTime;
239 void AliGenPythiaPlus::SetInteractionRate(Float_t rate,Float_t timewindow)
241 // Generate pileup using user specified rate
242 fInteractionRate = rate;
243 fTimeWindow = timewindow;
247 void AliGenPythiaPlus::GeneratePileup()
249 // Generate sub events time for pileup
251 if(fInteractionRate == 0.) {
252 Warning("GeneratePileup","Zero interaction specified. Skipping pileup generation.\n");
256 Int_t npart = NumberParticles();
258 Warning("GeneratePileup","Negative number of particles. Skipping pileup generation.\n");
262 if(fEventsTime) delete fEventsTime;
263 fEventsTime = new TArrayF(npart);
264 TArrayF &array = *fEventsTime;
265 for(Int_t ipart = 0; ipart < npart; ipart++)
268 Float_t eventtime = 0.;
271 eventtime += (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
272 if(eventtime > fTimeWindow) break;
273 array.Set(array.GetSize()+1);
274 array[array.GetSize()-1] = eventtime;
280 eventtime -= (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
281 if(TMath::Abs(eventtime) > fTimeWindow) break;
282 array.Set(array.GetSize()+1);
283 array[array.GetSize()-1] = eventtime;
286 SetNumberParticles(fEventsTime->GetSize());
289 void AliGenPythiaPlus::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
290 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
292 // Set pycell parameters
293 fPycellEtaMax = etamax;
296 fPycellThreshold = thresh;
297 fPycellEtSeed = etseed;
298 fPycellMinEtJet = minet;
299 fPycellMaxRadius = r;
304 void AliGenPythiaPlus::SetEventListRange(Int_t eventFirst, Int_t eventLast)
306 // Set a range of event numbers, for which a table
307 // of generated particle will be printed
308 fDebugEventFirst = eventFirst;
309 fDebugEventLast = eventLast;
310 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
313 void AliGenPythiaPlus::Init()
317 // SetMC(AliPythia::Instance());
318 // fPythia=(AliPythia*) fMCEvGen;
321 fParentWeight=1./Float_t(fNpart);
325 fPythia->SetPtHardRange(fPtHardMin, fPtHardMax);
326 fPythia->SetYHardRange(fYHardMin, fYHardMax);
328 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget);
330 if (fFragmentation) {
331 fPythia->SetFragmentation(1);
333 fPythia->SetFragmentation(0);
337 // initial state radiation
338 fPythia->SetInitialAndFinalStateRadiation(fGinit, fGfinal);
341 fPythia->SetIntrinsicKt(fPtKick);
344 fRL = AliRunLoader::Open(fFileName, "Partons");
345 fRL->LoadKinematics();
351 fPythia->ProcInit(fProcess, fEnergyCMS, fStrucFunc, fItune);
352 // Forward Paramters to the AliPythia object
353 fDecayer->SetForceDecay(fForceDecay);
354 // Switch off Heavy Flavors on request
356 fPythia->SwitchHFOff();
357 // Switch off g->QQbar splitting in decay table
358 ((AliDecayerPythia*) fDecayer)->HeavyFlavourOff();
364 // Parent and Children Selection
367 case kPyOldUEQ2ordered:
368 case kPyOldUEQ2ordered2:
372 case kPyCharmUnforced:
373 case kPyCharmPbPbMNR:
376 case kPyCharmppMNRwmi:
378 fParentSelect[0] = 411;
379 fParentSelect[1] = 421;
380 fParentSelect[2] = 431;
381 fParentSelect[3] = 4122;
382 fParentSelect[4] = 4232;
383 fParentSelect[5] = 4132;
384 fParentSelect[6] = 4332;
390 fParentSelect[0] = 421;
393 case kPyDPlusPbPbMNR:
396 fParentSelect[0] = 411;
399 case kPyDPlusStrangePbPbMNR:
400 case kPyDPlusStrangepPbMNR:
401 case kPyDPlusStrangeppMNR:
402 fParentSelect[0] = 431;
405 case kPyLambdacppMNR:
406 fParentSelect[0] = 4122;
411 case kPyBeautyPbPbMNR:
412 case kPyBeautypPbMNR:
414 case kPyBeautyppMNRwmi:
416 fParentSelect[0]= 511;
417 fParentSelect[1]= 521;
418 fParentSelect[2]= 531;
419 fParentSelect[3]= 5122;
420 fParentSelect[4]= 5132;
421 fParentSelect[5]= 5232;
422 fParentSelect[6]= 5332;
425 case kPyBeautyUnforced:
426 fParentSelect[0] = 511;
427 fParentSelect[1] = 521;
428 fParentSelect[2] = 531;
429 fParentSelect[3] = 5122;
430 fParentSelect[4] = 5132;
431 fParentSelect[5] = 5232;
432 fParentSelect[6] = 5332;
437 fParentSelect[0] = 443;
439 case kPyMbAtlasTuneMC09:
442 case kPyMbWithDirectPhoton:
454 case kPyMBRSingleDiffraction:
455 case kPyMBRDoubleDiffraction:
456 case kPyMBRCentralDiffraction:
461 // JetFinder for Trigger
463 // Configure detector (EMCAL like)
465 fPythia->SetPycellParameters(fPycellEtaMax,fPycellNEta, fPycellNPhi,
466 fPycellThreshold, fPycellEtSeed,
467 fPycellMinEtJet, fPycellMaxRadius);
469 // This counts the total number of calls to Pyevnt() per run.
484 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
488 fPythia->InitQuenching(0., 0.1, 0.6e6, 0, 0.97, 30);
491 // fPythia->SetPARJ(200, 0.0);
493 // if (fQuench == 3) {
494 // // Nestor's change of the splittings
495 // fPythia->SetPARJ(200, 0.8);
496 // fPythia->SetMSTJ(41, 1); // QCD radiation only
497 // fPythia->SetMSTJ(42, 2); // angular ordering
498 // fPythia->SetMSTJ(44, 2); // option to run alpha_s
499 // fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
500 // fPythia->SetMSTJ(50, 0); // No coherence in first branching
501 // fPythia->SetPARJ(82, 1.); // Cut off for parton showers
505 void AliGenPythiaPlus::Generate()
507 // Generate one event
509 fDecayer->ForceDecay();
511 Double_t polar[3] = {0,0,0};
512 Double_t origin[3] = {0,0,0};
514 // converts from mm/c to s
515 const Float_t kconv=0.001/2.999792458e8;
525 // Set collision vertex position
526 if (fVertexSmear == kPerEvent) Vertex();
535 // Switch hadronisation off
537 // fPythia->SwitchHadronisationOff();
539 // Either produce new event or read partons from file
541 if (!fReadFromFile) {
543 fPythia->GenerateEvent();
545 fPythia->GenerateMIEvent();
547 fNpartons = fPythia->GetNumberOfParticles();
549 printf("Loading Event %d\n",AliRunLoader::Instance()->GetEventNumber());
550 fRL->GetEvent(AliRunLoader::Instance()->GetEventNumber());
551 fPythia->SetNumberOfParticles(0);
552 fPythia->LoadEvent(fRL->Stack(), 0 , 1);
553 fPythia->EditEventList(21);
557 // Run quenching routine
561 } else if (fQuench == 2){
562 fPythia->Pyquen(208., 0, 0.);
563 } else if (fQuench == 3) {
564 // Quenching is via multiplicative correction of the splittings
568 // Switch hadronisation on
570 // fPythia->SwitchHadronisationOn();
572 // .. and perform hadronisation
573 // printf("Calling hadronisation %d\n", fPythia->GetN());
574 // fPythia->HadronizeEvent();
576 fPythia->GetParticles(&fParticles);
584 Int_t np = fParticles.GetEntriesFast();
586 if (np == 0) continue;
590 Int_t* pParent = new Int_t[np];
591 Int_t* pSelected = new Int_t[np];
592 Int_t* trackIt = new Int_t[np];
593 for (i = 0; i < np; i++) {
599 Int_t nc = 0; // Total n. of selected particles
600 Int_t nParents = 0; // Selected parents
601 Int_t nTkbles = 0; // Trackable particles
602 if (fProcess != kPyMbDefault &&
604 fProcess != kPyMbWithDirectPhoton &&
605 fProcess != kPyJets &&
606 fProcess != kPyDirectGamma &&
607 fProcess != kPyMbNonDiffr &&
608 fProcess != kPyMbMSEL1 &&
611 fProcess != kPyZgamma &&
612 fProcess != kPyCharmppMNRwmi &&
613 fProcess != kPyBeautyppMNRwmi &&
614 fProcess != kPyWPWHG &&
615 fProcess != kPyJetsPWHG &&
616 fProcess != kPyCharmPWHG &&
617 fProcess != kPyBeautyPWHG) {
619 for (i = 0; i < np; i++) {
620 TParticle* iparticle = (TParticle *) fParticles.At(i);
621 Int_t ks = iparticle->GetStatusCode();
622 kf = CheckPDGCode(iparticle->GetPdgCode());
623 // No initial state partons
624 if (ks==21) continue;
626 // Heavy Flavor Selection
633 if (kfl > 100000) kfl %= 100000;
634 if (kfl > 10000) kfl %= 10000;
636 if (kfl > 10) kfl/=100;
638 if (kfl > 10) kfl/=10;
639 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
642 // Establish mother daughter relation between heavy quarks and mesons
644 if (kf >= fFlavorSelect && kf <= 6) {
645 Int_t idau = (fPythia->Version() == 6) ? (iparticle->GetFirstDaughter() - 1) :(iparticle->GetFirstDaughter());
647 TParticle* daughter = (TParticle *) fParticles.At(idau);
648 Int_t pdgD = daughter->GetPdgCode();
649 if (pdgD == 91 || pdgD == 92) {
650 Int_t jmin = (fPythia->Version() == 6) ? (daughter->GetFirstDaughter() - 1) : (daughter->GetFirstDaughter());
651 Int_t jmax = (fPythia->Version() == 6) ? (daughter->GetLastDaughter() - 1) : (daughter->GetLastDaughter());
653 for (Int_t jp = jmin; jp <= jmax; jp++)
654 ((TParticle *) fParticles.At(jp))->SetFirstMother(i+1);
655 } // is string or cluster
661 TParticle * mother = (TParticle *) fParticles.At(ipa);
662 kfMo = TMath::Abs(mother->GetPdgCode());
665 // What to keep in Stack?
666 Bool_t flavorOK = kFALSE;
667 Bool_t selectOK = kFALSE;
669 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
671 if (kfl > fFlavorSelect) {
675 if (kfl == fFlavorSelect) flavorOK = kTRUE;
677 switch (fStackFillOpt) {
678 case kFlavorSelection:
681 case kParentSelection:
682 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
685 if (flavorOK && selectOK) {
687 // Heavy flavor hadron or quark
689 // Kinematic seletion on final state heavy flavor mesons
690 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
695 if (ParentSelected(kf)) ++nParents; // Update parent count
696 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
698 // Kinematic seletion on decay products
699 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
700 && !KinematicSelection(iparticle, 1))
706 // Select if mother was selected and is not tracked
708 if (pSelected[ipa] &&
709 !trackIt[ipa] && // mother will be tracked ?
710 kfMo != 5 && // mother is b-quark, don't store fragments
711 kfMo != 4 && // mother is c-quark, don't store fragments
712 kf != 92) // don't store string
715 // Semi-stable or de-selected: diselect decay products:
718 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
720 Int_t ipF = iparticle->GetFirstDaughter();
721 Int_t ipL = iparticle->GetLastDaughter();
722 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
724 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
725 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
728 if (pSelected[i] == -1) pSelected[i] = 0;
729 if (!pSelected[i]) continue;
730 // Count quarks only if you did not include fragmentation
731 if (fFragmentation && kf <= 10) continue;
734 // Decision on tracking
737 // Track final state particle
738 if (ks == 1) trackIt[i] = 1;
739 // Track semi-stable particles
740 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
741 // Track particles selected by process if undecayed.
742 if (fForceDecay == kNoDecay) {
743 if (ParentSelected(kf)) trackIt[i] = 1;
745 if (ParentSelected(kf)) trackIt[i] = 0;
747 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
751 } // particle selection loop
753 for (i = 0; i < np; i++) {
754 if (!pSelected[i]) continue;
755 TParticle * iparticle = (TParticle *) fParticles.At(i);
756 kf = CheckPDGCode(iparticle->GetPdgCode());
757 Int_t ks = iparticle->GetStatusCode();
758 p[0] = iparticle->Px();
759 p[1] = iparticle->Py();
760 p[2] = iparticle->Pz();
761 p[3] = iparticle->Energy();
763 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
764 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
765 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
767 Float_t tof = fTime + kconv*iparticle->T();
768 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
769 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
771 PushTrack(fTrackIt*trackIt[i], iparent, kf,
772 p[0], p[1], p[2], p[3],
773 origin[0], origin[1], origin[2], tof,
774 polar[0], polar[1], polar[2],
775 kPPrimary, nt, 1., ks);
792 switch (fCountMode) {
794 // printf(" Count all \n");
798 // printf(" Count parents \n");
801 case kCountTrackables:
802 // printf(" Count trackable \n");
806 if (jev >= fNpart || fNpart == -1) {
807 fKineBias=Float_t(fNpart)/Float_t(fTrials);
808 if (fInfo) fPythia->GetXandQ(fX1, fX2, fQ);
809 fTrialsRun += fTrials;
816 SetHighWaterMark(nt);
817 // Adjust weight due to kinematic selection
820 fXsection = fPythia->GetXSection();
823 Int_t AliGenPythiaPlus::GenerateMB()
826 // Min Bias selection and other global selections
828 Int_t i, kf, nt, iparent;
831 Float_t polar[3] = {0,0,0};
832 Float_t origin[3] = {0,0,0};
833 // converts from mm/c to s
834 const Float_t kconv = 0.001 / 2.999792458e8;
836 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
838 Int_t* pParent = new Int_t[np];
839 for (i=0; i< np; i++) pParent[i] = -1;
840 if (fProcess == kPyJets || fProcess == kPyDirectGamma || fProcess == kPyJetsPWHG || fProcess == kPyCharmPWHG || fProcess == kPyBeautyPWHG ) {
841 TParticle* jet1 = (TParticle *) fParticles.At(6);
842 TParticle* jet2 = (TParticle *) fParticles.At(7);
843 if (!CheckTrigger(jet1, jet2)) {
849 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
850 if ((fProcess == kPyJets || fProcess == kPyJetsPWHG) && (fFragPhotonInCalo || fPi0InCalo) ) {
855 if (fFragPhotonInCalo) pdg = 22 ; // Photon
856 else if (fPi0InCalo) pdg = 111 ; // Pi0
858 for (i=0; i< np; i++) {
859 TParticle* iparticle = (TParticle *) fParticles.At(i);
860 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
861 iparticle->Pt() > fFragPhotonOrPi0MinPt){
862 Int_t imother = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
863 TParticle* pmother = (TParticle *) fParticles.At(imother);
865 (pdg == 22 && pmother->GetStatusCode() != 11))//No photon from hadron decay
867 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
868 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
869 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
870 (fCheckPHOS && IsInPHOS(phi,eta)) )
882 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
883 if ((fProcess == kPyJets || fProcess == kPyJetsPWHG || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
889 for (i=0; i< np; i++) {
890 TParticle* iparticle = (TParticle *) fParticles.At(i);
891 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
892 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
894 if(iparticle->GetStatusCode() == 1
895 && iparticle->GetPdgCode() == pdg
896 && iparticle->Pt() > fPhotonMinPt
899 // first check if the photon is in PHOS phi
900 if(IsInPHOS(phi,eta)){
904 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
909 if(!okd && iphcand != -1) // execute rotation in phi
910 RotatePhi(iphcand,okd);
918 if (fTriggerParticle) {
919 Bool_t triggered = kFALSE;
920 for (i = 0; i < np; i++) {
921 TParticle * iparticle = (TParticle *) fParticles.At(i);
922 kf = CheckPDGCode(iparticle->GetPdgCode());
923 if (kf != fTriggerParticle) continue;
924 if (iparticle->Pt() == 0.) continue;
925 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
936 // Check if there is a ccbar or bbbar pair with at least one of the two
937 // in fYMin < y < fYMax
938 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi) {
939 TParticle *partCheck;
941 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
942 Bool_t theChild=kFALSE;
944 Int_t pdg,mpdg,mpdgUpperFamily;
945 for(i=0; i<np; i++) {
946 partCheck = (TParticle*)fParticles.At(i);
947 pdg = partCheck->GetPdgCode();
948 if(TMath::Abs(pdg) == fFlavorSelect) { // quark
949 if(pdg>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
950 y = 0.5*TMath::Log((partCheck->Energy()+partCheck->Pz()+1.e-13)/
951 (partCheck->Energy()-partCheck->Pz()+1.e-13));
952 if(y>fYMin && y<fYMax) inYcut=kTRUE;
955 if(fCutOnChild && TMath::Abs(pdg) == fPdgCodeParticleforAcceptanceCut) {
956 Int_t mi = partCheck->GetFirstMother() - 1;
958 mother = (TParticle*)fParticles.At(mi);
959 mpdg=TMath::Abs(mother->GetPdgCode());
960 mpdgUpperFamily=(mpdg>1000 ? mpdg+1000 : mpdg+100); // keep e from c from b
961 if ( ParentSelected(mpdg) ||
962 (fFlavorSelect==5 && ParentSelected(mpdgUpperFamily))) {
963 if (KinematicSelection(partCheck,1)) {
969 if (!theQ || !theQbar || !inYcut) { // one of the c/b conditions not satisfied
973 if (fCutOnChild && !theChild) { // one of the child conditions not satisfied
980 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
982 fProcess == kPyWPWHG ||
985 fProcess == kPyZgamma ||
986 fProcess == kPyMbDefault ||
988 fProcess == kPyMbWithDirectPhoton ||
989 fProcess == kPyMbNonDiffr)
990 && (fCutOnChild == 1) ) {
991 if ( !CheckKinematicsOnChild() ) {
998 for (i = 0; i < np; i++) {
1000 TParticle * iparticle = (TParticle *) fParticles.At(i);
1001 kf = CheckPDGCode(iparticle->GetPdgCode());
1002 Int_t ks = iparticle->GetStatusCode();
1003 Int_t km = iparticle->GetFirstMother();
1004 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
1006 ((fProcess == kPyJets || fProcess == kPyJetsPWHG) && ks == 21 && km == 0 && i>1)) {
1008 if (ks == 1) trackIt = 1;
1010 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
1011 iparent = (ipa > -1) ? pParent[ipa] : -1;
1012 if (ipa >= np) fPythia->EventListing();
1015 // store track information
1016 p[0] = iparticle->Px();
1017 p[1] = iparticle->Py();
1018 p[2] = iparticle->Pz();
1019 p[3] = iparticle->Energy();
1022 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
1023 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
1024 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
1026 Float_t tof = fTime + fEventTime + kconv * iparticle->T();
1028 PushTrack(fTrackIt*trackIt, iparent, kf,
1029 p[0], p[1], p[2], p[3],
1030 origin[0], origin[1], origin[2], tof,
1031 polar[0], polar[1], polar[2],
1032 kPPrimary, nt, 1., ks);
1037 // Special Treatment to store color-flow
1040 if (ks == 3 || ks == 13 || ks == 14) {
1041 TParticle* particle = 0;
1043 particle = fStack->Particle(nt);
1045 particle = AliRunLoader::Instance()->Stack()->Particle(nt);
1047 particle->SetFirstDaughter(fPythia->GetK(2, i));
1048 particle->SetLastDaughter(fPythia->GetK(3, i));
1053 SetHighWaterMark(nt);
1055 } // select particle
1064 void AliGenPythiaPlus::FinishRun()
1066 // Print x-section summary
1067 fPythia->PrintStatistics();
1075 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1076 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1079 void AliGenPythiaPlus::AdjustWeights() const
1081 // Adjust the weights after generation of all events
1085 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1086 for (Int_t i=0; i<ntrack; i++) {
1087 part= gAlice->GetMCApp()->Particle(i);
1088 part->SetWeight(part->GetWeight()*fKineBias);
1093 void AliGenPythiaPlus::SetNuclei(Int_t a1, Int_t a2)
1095 // Treat protons as inside nuclei with mass numbers a1 and a2
1103 void AliGenPythiaPlus::MakeHeader()
1106 // Make header for the simulated event
1109 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1110 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->EventListing();
1113 // Builds the event header, to be called after each event
1114 if (fHeader) delete fHeader;
1115 fHeader = new AliGenPythiaEventHeader("Pythia");
1118 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->ProcessCode());
1121 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1124 fHeader->SetPrimaryVertex(fVertex);
1125 fHeader->SetInteractionTime(fTime+fEventTime);
1127 // Number of primaries
1128 fHeader->SetNProduced(fNprimaries);
1130 // Jets that have triggered
1132 if (fProcess == kPyJets || fProcess == kPyJetsPWHG)
1135 Float_t jets[4][10];
1136 GetJets(njet, ntrig, jets);
1139 for (Int_t i = 0; i < ntrig; i++) {
1140 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1145 // Copy relevant information from external header, if present.
1150 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1151 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1153 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1156 exHeader->TriggerJet(i, uqJet);
1157 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1161 // Store quenching parameters
1164 Double_t z[4] = {0.};
1169 fPythia->GetQuenchingParameters(xp, yp, z);
1172 Double_t r1 = PARIMP.rb1;
1173 Double_t r2 = PARIMP.rb2;
1174 Double_t b = PARIMP.b1;
1175 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1176 Double_t phi = PARIMP.psib1;
1177 xp = r * TMath::Cos(phi);
1178 yp = r * TMath::Sin(phi);
1181 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1182 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1186 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetPtHard());
1194 Bool_t AliGenPythiaPlus::CheckTrigger(const TParticle* jet1, const TParticle* jet2)
1196 // Check the kinematic trigger condition
1199 eta[0] = jet1->Eta();
1200 eta[1] = jet2->Eta();
1202 phi[0] = jet1->Phi();
1203 phi[1] = jet2->Phi();
1205 pdg[0] = jet1->GetPdgCode();
1206 pdg[1] = jet2->GetPdgCode();
1207 Bool_t triggered = kFALSE;
1209 if (fProcess == kPyJets || fProcess == kPyJetsPWHG) {
1212 Float_t jets[4][10];
1214 // Use Pythia clustering on parton level to determine jet axis
1216 GetJets(njets, ntrig, jets);
1218 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1223 if (pdg[0] == kGamma) {
1227 //Check eta range first...
1228 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1229 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1231 //Eta is okay, now check phi range
1232 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1233 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1244 Bool_t AliGenPythiaPlus::CheckKinematicsOnChild(){
1246 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1248 Bool_t checking = kFALSE;
1249 Int_t j, kcode, ks, km;
1250 Int_t nPartAcc = 0; //number of particles in the acceptance range
1251 Int_t numberOfAcceptedParticles = 1;
1252 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1253 Int_t npart = fParticles.GetEntriesFast();
1255 for (j = 0; j<npart; j++) {
1256 TParticle * jparticle = (TParticle *) fParticles.At(j);
1257 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1258 ks = jparticle->GetStatusCode();
1259 km = jparticle->GetFirstMother();
1261 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1264 if( numberOfAcceptedParticles <= nPartAcc){
1273 void AliGenPythiaPlus::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1276 // Calls the Pythia jet finding algorithm to find jets in the current event
1283 fPythia->Pycell(njets);
1285 for (i = 0; i < njets; i++) {
1286 Float_t px, py, pz, e;
1287 fPythia->GetJet(i, px, py, pz, e);
1296 void AliGenPythiaPlus::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1299 // Calls the Pythia clustering algorithm to find jets in the current event
1303 if (fJetReconstruction == kCluster) {
1305 // Configure cluster algorithm
1307 // fPythia->SetPARU(43, 2.);
1308 // fPythia->SetMSTU(41, 1);
1310 // Call cluster algorithm
1312 fPythia->Pyclus(nJets);
1314 // Loading jets from common block
1320 fPythia->Pycell(nJets);
1324 for (i = 0; i < nJets; i++) {
1325 Float_t px, py, pz, e;
1326 fPythia->GetJet(i, px, py, pz, e);
1327 Float_t pt = TMath::Sqrt(px * px + py * py);
1328 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1329 Float_t theta = TMath::ATan2(pt,pz);
1330 Float_t et = e * TMath::Sin(theta);
1331 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1333 eta > fEtaMinJet && eta < fEtaMaxJet &&
1334 phi > fPhiMinJet && phi < fPhiMaxJet &&
1335 et > fEtMinJet && et < fEtMaxJet
1338 jets[0][nJetsTrig] = px;
1339 jets[1][nJetsTrig] = py;
1340 jets[2][nJetsTrig] = pz;
1341 jets[3][nJetsTrig] = e;
1348 void AliGenPythiaPlus::GetSubEventTime()
1350 // Calculates time of the next subevent
1353 TArrayF &array = *fEventsTime;
1354 fEventTime = array[fCurSubEvent++];
1356 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1363 Bool_t AliGenPythiaPlus::IsInEMCAL(Float_t phi, Float_t eta) const
1365 // Is particle in EMCAL acceptance?
1366 // phi in degrees, etamin=-etamax
1367 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1374 Bool_t AliGenPythiaPlus::IsInPHOS(Float_t phi, Float_t eta) const
1376 // Is particle in PHOS acceptance?
1377 // Acceptance slightly larger considered.
1378 // phi in degrees, etamin=-etamax
1379 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1386 void AliGenPythiaPlus::RotatePhi(Int_t iphcand, Bool_t& okdd)
1388 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1389 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1390 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1391 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1393 //calculate deltaphi
1394 TParticle* ph = (TParticle *) fParticles.At(iphcand);
1395 Double_t phphi = ph->Phi();
1396 Double_t deltaphi = phiPHOS - phphi;
1400 //loop for all particles and produce the phi rotation
1401 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
1402 Double_t oldphi, newphi;
1403 Double_t newVx, newVy, R, Vz, time;
1404 Double_t newPx, newPy, pt, Pz, e;
1405 for(Int_t i=0; i< np; i++) {
1406 TParticle* iparticle = (TParticle *) fParticles.At(i);
1407 oldphi = iparticle->Phi();
1408 newphi = oldphi + deltaphi;
1409 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1410 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1413 newVx = R*TMath::Cos(newphi);
1414 newVy = R*TMath::Sin(newphi);
1415 Vz = iparticle->Vz(); // don't transform
1416 time = iparticle->T(); // don't transform
1418 pt = iparticle->Pt();
1419 newPx = pt*TMath::Cos(newphi);
1420 newPy = pt*TMath::Sin(newphi);
1421 Pz = iparticle->Pz(); // don't transform
1422 e = iparticle->Energy(); // don't transform
1425 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1426 iparticle->SetMomentum(newPx, newPy, Pz, e);
1428 } //end particle loop
1430 // now let's check that we put correctly the candidate photon in PHOS
1431 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1432 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1433 if(IsInPHOS(phi,eta))
1439 void AliGenPythiaPlus::Streamer(TBuffer &R__b)
1441 // Stream an object of class AliGenPythia.
1443 if (R__b.IsReading()) {
1444 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1445 AliGenerator::Streamer(R__b);
1446 R__b >> (Int_t&)fProcess;
1447 R__b >> (Int_t&)fStrucFunc;
1448 R__b >> (Int_t&)fForceDecay;
1452 fParentSelect.Streamer(R__b);
1453 fChildSelect.Streamer(R__b);
1455 // (AliPythia::Instance())->Streamer(R__b);
1458 // if (fDecayer) fDecayer->Streamer(R__b);
1460 R__b.WriteVersion(AliGenPythiaPlus::IsA());
1461 AliGenerator::Streamer(R__b);
1462 R__b << (Int_t)fProcess;
1463 R__b << (Int_t)fStrucFunc;
1464 R__b << (Int_t)fForceDecay;
1468 fParentSelect.Streamer(R__b);
1469 fChildSelect.Streamer(R__b);
1474 // fDecayer->Streamer(R__b);