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()),
101 fPycellThreshold(0.),
103 fPycellMinEtJet(10.),
104 fPycellMaxRadius(1.),
105 fStackFillOpt(kFlavorSelection),
107 fFragmentation(kTRUE),
113 fCountMode(kCountAll),
117 fFragPhotonInCalo(kFALSE),
119 fPhotonInCalo(kFALSE),
122 fCheckPHOSeta(kFALSE),
123 fFragPhotonOrPi0MinPt(0),
134 // Default Constructor
137 if (!AliPythiaRndm::GetPythiaRandom())
138 AliPythiaRndm::SetPythiaRandom(GetRandom());
141 AliGenPythiaPlus::AliGenPythiaPlus(AliPythiaBase* pythia)
153 fInteractionRate(0.),
166 fHadronisation(kTRUE),
168 fReadFromFile(kFALSE),
172 fDecayer(new AliDecayerPythia()),
173 fDebugEventFirst(-1),
180 fPhiMaxJet(2.* TMath::Pi()),
181 fJetReconstruction(kCell),
185 fPhiMaxGamma(2. * TMath::Pi()),
192 fPycellThreshold(0.),
194 fPycellMinEtJet(10.),
195 fPycellMaxRadius(1.),
196 fStackFillOpt(kFlavorSelection),
198 fFragmentation(kTRUE),
204 fCountMode(kCountAll),
208 fFragPhotonInCalo(kFALSE),
210 fPhotonInCalo(kFALSE),
213 fCheckPHOSeta(kFALSE),
214 fFragPhotonOrPi0MinPt(0),
225 // default charm production at 5. 5 TeV
227 // structure function GRVHO
231 fTitle= "Particle Generator using PYTHIA";
233 // Set random number generator
234 if (!AliPythiaRndm::GetPythiaRandom())
235 AliPythiaRndm::SetPythiaRandom(GetRandom());
239 AliGenPythiaPlus::~AliGenPythiaPlus()
242 if(fEventsTime) delete fEventsTime;
245 void AliGenPythiaPlus::SetInteractionRate(Float_t rate,Float_t timewindow)
247 // Generate pileup using user specified rate
248 fInteractionRate = rate;
249 fTimeWindow = timewindow;
253 void AliGenPythiaPlus::GeneratePileup()
255 // Generate sub events time for pileup
257 if(fInteractionRate == 0.) {
258 Warning("GeneratePileup","Zero interaction specified. Skipping pileup generation.\n");
262 Int_t npart = NumberParticles();
264 Warning("GeneratePileup","Negative number of particles. Skipping pileup generation.\n");
268 if(fEventsTime) delete fEventsTime;
269 fEventsTime = new TArrayF(npart);
270 TArrayF &array = *fEventsTime;
271 for(Int_t ipart = 0; ipart < npart; ipart++)
274 Float_t eventtime = 0.;
277 eventtime += (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
278 if(eventtime > fTimeWindow) break;
279 array.Set(array.GetSize()+1);
280 array[array.GetSize()-1] = eventtime;
286 eventtime -= (AliPythiaRndm::GetPythiaRandom())->Exp(1./fInteractionRate);
287 if(TMath::Abs(eventtime) > fTimeWindow) break;
288 array.Set(array.GetSize()+1);
289 array[array.GetSize()-1] = eventtime;
292 SetNumberParticles(fEventsTime->GetSize());
295 void AliGenPythiaPlus::SetPycellParameters(Float_t etamax, Int_t neta, Int_t nphi,
296 Float_t thresh, Float_t etseed, Float_t minet, Float_t r)
298 // Set pycell parameters
299 fPycellEtaMax = etamax;
302 fPycellThreshold = thresh;
303 fPycellEtSeed = etseed;
304 fPycellMinEtJet = minet;
305 fPycellMaxRadius = r;
310 void AliGenPythiaPlus::SetEventListRange(Int_t eventFirst, Int_t eventLast)
312 // Set a range of event numbers, for which a table
313 // of generated particle will be printed
314 fDebugEventFirst = eventFirst;
315 fDebugEventLast = eventLast;
316 if (fDebugEventLast==-1) fDebugEventLast=fDebugEventFirst;
319 void AliGenPythiaPlus::Init()
323 // SetMC(AliPythia::Instance());
324 // fPythia=(AliPythia*) fMCEvGen;
327 fParentWeight=1./Float_t(fNpart);
331 fPythia->SetPtHardRange(fPtHardMin, fPtHardMax);
332 fPythia->SetYHardRange(fYHardMin, fYHardMax);
334 if (fAProjectile > 0 && fATarget > 0) fPythia->SetNuclei(fAProjectile, fATarget);
336 if (fFragmentation) {
337 fPythia->SetFragmentation(1);
339 fPythia->SetFragmentation(0);
343 // initial state radiation
344 fPythia->SetInitialAndFinalStateRadiation(fGinit, fGfinal);
347 fPythia->SetIntrinsicKt(fPtKick);
350 fRL = AliRunLoader::Open(fFileName, "Partons");
351 fRL->LoadKinematics();
357 fPythia->ProcInit(fProcess, fEnergyCMS, fStrucFunc, fItune);
358 // Forward Paramters to the AliPythia object
359 fDecayer->SetForceDecay(fForceDecay);
360 // Switch off Heavy Flavors on request
362 fPythia->SwitchHFOff();
363 // Switch off g->QQbar splitting in decay table
364 ((AliDecayerPythia*) fDecayer)->HeavyFlavourOff();
370 // Parent and Children Selection
373 case kPyOldUEQ2ordered:
374 case kPyOldUEQ2ordered2:
378 case kPyCharmUnforced:
379 case kPyCharmPbPbMNR:
382 case kPyCharmppMNRwmi:
384 fParentSelect[0] = 411;
385 fParentSelect[1] = 421;
386 fParentSelect[2] = 431;
387 fParentSelect[3] = 4122;
388 fParentSelect[4] = 4232;
389 fParentSelect[5] = 4132;
390 fParentSelect[6] = 4332;
396 fParentSelect[0] = 421;
399 case kPyDPlusPbPbMNR:
402 fParentSelect[0] = 411;
405 case kPyDPlusStrangePbPbMNR:
406 case kPyDPlusStrangepPbMNR:
407 case kPyDPlusStrangeppMNR:
408 fParentSelect[0] = 431;
411 case kPyLambdacppMNR:
412 fParentSelect[0] = 4122;
417 case kPyBeautyPbPbMNR:
418 case kPyBeautypPbMNR:
420 case kPyBeautyppMNRwmi:
422 fParentSelect[0]= 511;
423 fParentSelect[1]= 521;
424 fParentSelect[2]= 531;
425 fParentSelect[3]= 5122;
426 fParentSelect[4]= 5132;
427 fParentSelect[5]= 5232;
428 fParentSelect[6]= 5332;
431 case kPyBeautyUnforced:
432 fParentSelect[0] = 511;
433 fParentSelect[1] = 521;
434 fParentSelect[2] = 531;
435 fParentSelect[3] = 5122;
436 fParentSelect[4] = 5132;
437 fParentSelect[5] = 5232;
438 fParentSelect[6] = 5332;
443 fParentSelect[0] = 443;
445 case kPyMbAtlasTuneMC09:
448 case kPyMbWithDirectPhoton:
460 case kPyMBRSingleDiffraction:
461 case kPyMBRDoubleDiffraction:
462 case kPyMBRCentralDiffraction:
467 // JetFinder for Trigger
469 // Configure detector (EMCAL like)
471 fPythia->SetPycellParameters(fPycellEtaMax,fPycellNEta, fPycellNPhi,
472 fPycellThreshold, fPycellEtSeed,
473 fPycellMinEtJet, fPycellMaxRadius);
475 // This counts the total number of calls to Pyevnt() per run.
490 Warning("Init","SetNuclei used. Use SetProjectile + SetTarget instead. fDyBoost has been reset to 0\n");
494 fPythia->InitQuenching(0., 0.1, 0.6e6, 0, 0.97, 30);
497 // fPythia->SetPARJ(200, 0.0);
499 // if (fQuench == 3) {
500 // // Nestor's change of the splittings
501 // fPythia->SetPARJ(200, 0.8);
502 // fPythia->SetMSTJ(41, 1); // QCD radiation only
503 // fPythia->SetMSTJ(42, 2); // angular ordering
504 // fPythia->SetMSTJ(44, 2); // option to run alpha_s
505 // fPythia->SetMSTJ(47, 0); // No correction back to hard scattering element
506 // fPythia->SetMSTJ(50, 0); // No coherence in first branching
507 // fPythia->SetPARJ(82, 1.); // Cut off for parton showers
511 void AliGenPythiaPlus::SetSeed(UInt_t seed)
513 fPythia->SetSeed(seed);
516 void AliGenPythiaPlus::Generate()
518 // Generate one event
520 fDecayer->ForceDecay();
522 Double_t polar[3] = {0,0,0};
523 Double_t origin[3] = {0,0,0};
525 // converts from mm/c to s
526 const Float_t kconv=0.001/2.999792458e8;
536 // Set collision vertex position
537 if (fVertexSmear == kPerEvent) Vertex();
546 // Switch hadronisation off
548 // fPythia->SwitchHadronisationOff();
550 // Either produce new event or read partons from file
552 if (!fReadFromFile) {
554 fPythia->GenerateEvent();
556 fPythia->GenerateMIEvent();
558 fNpartons = fPythia->GetNumberOfParticles();
560 printf("Loading Event %d\n",AliRunLoader::Instance()->GetEventNumber());
561 fRL->GetEvent(AliRunLoader::Instance()->GetEventNumber());
562 fPythia->SetNumberOfParticles(0);
563 fPythia->LoadEvent(fRL->Stack(), 0 , 1);
564 fPythia->EditEventList(21);
568 // Run quenching routine
572 } else if (fQuench == 2){
573 fPythia->Pyquen(208., 0, 0.);
574 } else if (fQuench == 3) {
575 // Quenching is via multiplicative correction of the splittings
579 // Switch hadronisation on
581 // fPythia->SwitchHadronisationOn();
583 // .. and perform hadronisation
584 // printf("Calling hadronisation %d\n", fPythia->GetN());
585 // fPythia->HadronizeEvent();
587 fPythia->GetParticles(&fParticles);
595 Int_t np = fParticles.GetEntriesFast();
597 if (np == 0) continue;
601 Int_t* pParent = new Int_t[np];
602 Int_t* pSelected = new Int_t[np];
603 Int_t* trackIt = new Int_t[np];
604 for (i = 0; i < np; i++) {
610 Int_t nc = 0; // Total n. of selected particles
611 Int_t nParents = 0; // Selected parents
612 Int_t nTkbles = 0; // Trackable particles
613 if (fProcess != kPyMbDefault &&
615 fProcess != kPyMbWithDirectPhoton &&
616 fProcess != kPyJets &&
617 fProcess != kPyDirectGamma &&
618 fProcess != kPyMbNonDiffr &&
619 fProcess != kPyMbMSEL1 &&
622 fProcess != kPyZgamma &&
623 fProcess != kPyCharmppMNRwmi &&
624 fProcess != kPyBeautyppMNRwmi &&
625 fProcess != kPyWPWHG &&
626 fProcess != kPyJetsPWHG &&
627 fProcess != kPyCharmPWHG &&
628 fProcess != kPyBeautyPWHG) {
630 for (i = 0; i < np; i++) {
631 TParticle* iparticle = (TParticle *) fParticles.At(i);
632 Int_t ks = iparticle->GetStatusCode();
633 kf = CheckPDGCode(iparticle->GetPdgCode());
634 // No initial state partons
635 if (ks==21) continue;
637 // Heavy Flavor Selection
644 if (kfl > 100000) kfl %= 100000;
645 if (kfl > 10000) kfl %= 10000;
647 if (kfl > 10) kfl/=100;
649 if (kfl > 10) kfl/=10;
650 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
653 // Establish mother daughter relation between heavy quarks and mesons
655 if (kf >= fFlavorSelect && kf <= 6) {
656 Int_t idau = (fPythia->Version() == 6) ? (iparticle->GetFirstDaughter() - 1) :(iparticle->GetFirstDaughter());
658 TParticle* daughter = (TParticle *) fParticles.At(idau);
659 Int_t pdgD = daughter->GetPdgCode();
660 if (pdgD == 91 || pdgD == 92) {
661 Int_t jmin = (fPythia->Version() == 6) ? (daughter->GetFirstDaughter() - 1) : (daughter->GetFirstDaughter());
662 Int_t jmax = (fPythia->Version() == 6) ? (daughter->GetLastDaughter() - 1) : (daughter->GetLastDaughter());
664 for (Int_t jp = jmin; jp <= jmax; jp++)
665 ((TParticle *) fParticles.At(jp))->SetFirstMother(i+1);
666 } // is string or cluster
672 TParticle * mother = (TParticle *) fParticles.At(ipa);
673 kfMo = TMath::Abs(mother->GetPdgCode());
676 // What to keep in Stack?
677 Bool_t flavorOK = kFALSE;
678 Bool_t selectOK = kFALSE;
680 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
682 if (kfl > fFlavorSelect) {
686 if (kfl == fFlavorSelect) flavorOK = kTRUE;
688 switch (fStackFillOpt) {
689 case kFlavorSelection:
692 case kParentSelection:
693 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
696 if (flavorOK && selectOK) {
698 // Heavy flavor hadron or quark
700 // Kinematic seletion on final state heavy flavor mesons
701 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
706 if (ParentSelected(kf)) ++nParents; // Update parent count
707 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
709 // Kinematic seletion on decay products
710 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
711 && !KinematicSelection(iparticle, 1))
717 // Select if mother was selected and is not tracked
719 if (pSelected[ipa] &&
720 !trackIt[ipa] && // mother will be tracked ?
721 kfMo != 5 && // mother is b-quark, don't store fragments
722 kfMo != 4 && // mother is c-quark, don't store fragments
723 kf != 92) // don't store string
726 // Semi-stable or de-selected: diselect decay products:
729 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
731 Int_t ipF = iparticle->GetFirstDaughter();
732 Int_t ipL = iparticle->GetLastDaughter();
733 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
735 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
736 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
739 if (pSelected[i] == -1) pSelected[i] = 0;
740 if (!pSelected[i]) continue;
741 // Count quarks only if you did not include fragmentation
742 if (fFragmentation && kf <= 10) continue;
745 // Decision on tracking
748 // Track final state particle
749 if (ks == 1) trackIt[i] = 1;
750 // Track semi-stable particles
751 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
752 // Track particles selected by process if undecayed.
753 if (fForceDecay == kNoDecay) {
754 if (ParentSelected(kf)) trackIt[i] = 1;
756 if (ParentSelected(kf)) trackIt[i] = 0;
758 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
762 } // particle selection loop
764 for (i = 0; i < np; i++) {
765 if (!pSelected[i]) continue;
766 TParticle * iparticle = (TParticle *) fParticles.At(i);
767 kf = CheckPDGCode(iparticle->GetPdgCode());
768 Int_t ks = iparticle->GetStatusCode();
769 p[0] = iparticle->Px();
770 p[1] = iparticle->Py();
771 p[2] = iparticle->Pz();
772 p[3] = iparticle->Energy();
774 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
775 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
776 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
778 Float_t tof = fTime + kconv*iparticle->T();
779 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
780 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
782 PushTrack(fTrackIt*trackIt[i], iparent, kf,
783 p[0], p[1], p[2], p[3],
784 origin[0], origin[1], origin[2], tof,
785 polar[0], polar[1], polar[2],
786 kPPrimary, nt, 1., ks);
803 switch (fCountMode) {
805 // printf(" Count all \n");
809 // printf(" Count parents \n");
812 case kCountTrackables:
813 // printf(" Count trackable \n");
817 if (jev >= fNpart || fNpart == -1) {
818 fKineBias=Float_t(fNpart)/Float_t(fTrials);
819 if (fInfo) fPythia->GetXandQ(fX1, fX2, fQ);
820 fTrialsRun += fTrials;
827 SetHighWaterMark(nt);
828 // Adjust weight due to kinematic selection
831 fXsection = fPythia->GetXSection();
834 Int_t AliGenPythiaPlus::GenerateMB()
837 // Min Bias selection and other global selections
839 Int_t i, kf, nt, iparent;
842 Float_t polar[3] = {0,0,0};
843 Float_t origin[3] = {0,0,0};
844 // converts from mm/c to s
845 const Float_t kconv = 0.001 / 2.999792458e8;
847 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
849 Int_t* pParent = new Int_t[np];
850 for (i=0; i< np; i++) pParent[i] = -1;
851 if (fProcess == kPyJets || fProcess == kPyDirectGamma || fProcess == kPyJetsPWHG || fProcess == kPyCharmPWHG || fProcess == kPyBeautyPWHG ) {
852 TParticle* jet1 = (TParticle *) fParticles.At(6);
853 TParticle* jet2 = (TParticle *) fParticles.At(7);
854 if (!CheckTrigger(jet1, jet2)) {
860 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
861 if ((fProcess == kPyJets || fProcess == kPyJetsPWHG) && (fFragPhotonInCalo || fPi0InCalo) ) {
866 if (fFragPhotonInCalo) pdg = 22 ; // Photon
867 else if (fPi0InCalo) pdg = 111 ; // Pi0
869 for (i=0; i< np; i++) {
870 TParticle* iparticle = (TParticle *) fParticles.At(i);
871 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
872 iparticle->Pt() > fFragPhotonOrPi0MinPt){
873 Int_t imother = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
874 TParticle* pmother = (TParticle *) fParticles.At(imother);
876 (pdg == 22 && pmother->GetStatusCode() != 11))//No photon from hadron decay
878 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
879 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
880 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
881 (fCheckPHOS && IsInPHOS(phi,eta)) )
893 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
894 if ((fProcess == kPyJets || fProcess == kPyJetsPWHG || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
900 for (i=0; i< np; i++) {
901 TParticle* iparticle = (TParticle *) fParticles.At(i);
902 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
903 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
905 if(iparticle->GetStatusCode() == 1
906 && iparticle->GetPdgCode() == pdg
907 && iparticle->Pt() > fPhotonMinPt
910 // first check if the photon is in PHOS phi
911 if(IsInPHOS(phi,eta)){
915 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
920 if(!okd && iphcand != -1) // execute rotation in phi
921 RotatePhi(iphcand,okd);
929 if (fTriggerParticle) {
930 Bool_t triggered = kFALSE;
931 for (i = 0; i < np; i++) {
932 TParticle * iparticle = (TParticle *) fParticles.At(i);
933 kf = CheckPDGCode(iparticle->GetPdgCode());
934 if (kf != fTriggerParticle) continue;
935 if (iparticle->Pt() == 0.) continue;
936 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
947 // Check if there is a ccbar or bbbar pair with at least one of the two
948 // in fYMin < y < fYMax
949 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi) {
950 TParticle *partCheck;
952 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
953 Bool_t theChild=kFALSE;
955 Int_t pdg,mpdg,mpdgUpperFamily;
956 for(i=0; i<np; i++) {
957 partCheck = (TParticle*)fParticles.At(i);
958 pdg = partCheck->GetPdgCode();
959 if(TMath::Abs(pdg) == fFlavorSelect) { // quark
960 if(pdg>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
961 y = 0.5*TMath::Log((partCheck->Energy()+partCheck->Pz()+1.e-13)/
962 (partCheck->Energy()-partCheck->Pz()+1.e-13));
963 if(fUseYCutHQ && y>fYMinHQ && y<fYMaxHQ) inYcut=kTRUE;
964 if(!fUseYCutHQ && y>fYMin && y<fYMax) inYcut=kTRUE;
967 if(fCutOnChild && TMath::Abs(pdg) == fPdgCodeParticleforAcceptanceCut) {
968 Int_t mi = partCheck->GetFirstMother() - 1;
970 mother = (TParticle*)fParticles.At(mi);
971 mpdg=TMath::Abs(mother->GetPdgCode());
972 mpdgUpperFamily=(mpdg>1000 ? mpdg+1000 : mpdg+100); // keep e from c from b
973 if ( ParentSelected(mpdg) ||
974 (fFlavorSelect==5 && ParentSelected(mpdgUpperFamily))) {
975 if (KinematicSelection(partCheck,1)) {
981 if (!theQ || !theQbar || !inYcut) { // one of the c/b conditions not satisfied
985 if (fCutOnChild && !theChild) { // one of the child conditions not satisfied
992 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
994 fProcess == kPyWPWHG ||
997 fProcess == kPyZgamma ||
998 fProcess == kPyMbDefault ||
1000 fProcess == kPyMbWithDirectPhoton ||
1001 fProcess == kPyMbNonDiffr)
1002 && (fCutOnChild == 1) ) {
1003 if ( !CheckKinematicsOnChild() ) {
1010 for (i = 0; i < np; i++) {
1012 TParticle * iparticle = (TParticle *) fParticles.At(i);
1013 kf = CheckPDGCode(iparticle->GetPdgCode());
1014 Int_t ks = iparticle->GetStatusCode();
1015 Int_t km = iparticle->GetFirstMother();
1016 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
1018 ((fProcess == kPyJets || fProcess == kPyJetsPWHG) && ks == 21 && km == 0 && i>1)) {
1020 if (ks == 1) trackIt = 1;
1022 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
1023 iparent = (ipa > -1) ? pParent[ipa] : -1;
1024 if (ipa >= np) fPythia->EventListing();
1027 // store track information
1028 p[0] = iparticle->Px();
1029 p[1] = iparticle->Py();
1030 p[2] = iparticle->Pz();
1031 p[3] = iparticle->Energy();
1034 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
1035 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
1036 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
1038 Float_t tof = fTime + fEventTime + kconv * iparticle->T();
1040 PushTrack(fTrackIt*trackIt, iparent, kf,
1041 p[0], p[1], p[2], p[3],
1042 origin[0], origin[1], origin[2], tof,
1043 polar[0], polar[1], polar[2],
1044 kPPrimary, nt, 1., ks);
1049 // Special Treatment to store color-flow
1052 if (ks == 3 || ks == 13 || ks == 14) {
1053 TParticle* particle = 0;
1055 particle = fStack->Particle(nt);
1057 particle = AliRunLoader::Instance()->Stack()->Particle(nt);
1059 particle->SetFirstDaughter(fPythia->GetK(2, i));
1060 particle->SetLastDaughter(fPythia->GetK(3, i));
1065 SetHighWaterMark(nt);
1067 } // select particle
1076 void AliGenPythiaPlus::FinishRun()
1078 // Print x-section summary
1079 fPythia->PrintStatistics();
1087 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1088 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1091 void AliGenPythiaPlus::AdjustWeights() const
1093 // Adjust the weights after generation of all events
1097 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1098 for (Int_t i=0; i<ntrack; i++) {
1099 part= gAlice->GetMCApp()->Particle(i);
1100 part->SetWeight(part->GetWeight()*fKineBias);
1105 void AliGenPythiaPlus::SetNuclei(Int_t a1, Int_t a2)
1107 // Treat protons as inside nuclei with mass numbers a1 and a2
1115 void AliGenPythiaPlus::MakeHeader()
1118 // Make header for the simulated event
1121 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1122 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->EventListing();
1125 // Builds the event header, to be called after each event
1126 if (fHeader) delete fHeader;
1127 fHeader = new AliGenPythiaEventHeader("Pythia");
1128 fHeader->SetTitle(GetTitle());
1132 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->ProcessCode());
1135 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1138 fHeader->SetPrimaryVertex(fVertex);
1139 fHeader->SetInteractionTime(fTime+fEventTime);
1141 // Number of primaries
1142 fHeader->SetNProduced(fNprimaries);
1144 // Jets that have triggered
1146 if (fProcess == kPyJets || fProcess == kPyJetsPWHG)
1149 Float_t jets[4][10];
1150 GetJets(njet, ntrig, jets);
1153 for (Int_t i = 0; i < ntrig; i++) {
1154 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1159 // Copy relevant information from external header, if present.
1164 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1165 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1167 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1170 exHeader->TriggerJet(i, uqJet);
1171 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1175 // Store quenching parameters
1178 Double_t z[4] = {0.};
1183 fPythia->GetQuenchingParameters(xp, yp, z);
1186 Double_t r1 = PARIMP.rb1;
1187 Double_t r2 = PARIMP.rb2;
1188 Double_t b = PARIMP.b1;
1189 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1190 Double_t phi = PARIMP.psib1;
1191 xp = r * TMath::Cos(phi);
1192 yp = r * TMath::Sin(phi);
1195 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1196 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1200 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetPtHard());
1208 Bool_t AliGenPythiaPlus::CheckTrigger(const TParticle* jet1, const TParticle* jet2)
1210 // Check the kinematic trigger condition
1213 eta[0] = jet1->Eta();
1214 eta[1] = jet2->Eta();
1216 phi[0] = jet1->Phi();
1217 phi[1] = jet2->Phi();
1219 pdg[0] = jet1->GetPdgCode();
1220 pdg[1] = jet2->GetPdgCode();
1221 Bool_t triggered = kFALSE;
1223 if (fProcess == kPyJets || fProcess == kPyJetsPWHG) {
1226 Float_t jets[4][10];
1228 // Use Pythia clustering on parton level to determine jet axis
1230 GetJets(njets, ntrig, jets);
1232 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1237 if (pdg[0] == kGamma) {
1241 //Check eta range first...
1242 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1243 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1245 //Eta is okay, now check phi range
1246 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1247 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1258 Bool_t AliGenPythiaPlus::CheckKinematicsOnChild(){
1260 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1262 Bool_t checking = kFALSE;
1263 Int_t j, kcode, ks, km;
1264 Int_t nPartAcc = 0; //number of particles in the acceptance range
1265 Int_t numberOfAcceptedParticles = 1;
1266 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1267 Int_t npart = fParticles.GetEntriesFast();
1269 for (j = 0; j<npart; j++) {
1270 TParticle * jparticle = (TParticle *) fParticles.At(j);
1271 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1272 ks = jparticle->GetStatusCode();
1273 km = jparticle->GetFirstMother();
1275 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1278 if( numberOfAcceptedParticles <= nPartAcc){
1287 void AliGenPythiaPlus::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1290 // Calls the Pythia jet finding algorithm to find jets in the current event
1297 fPythia->Pycell(njets);
1299 for (i = 0; i < njets; i++) {
1300 Float_t px, py, pz, e;
1301 fPythia->GetJet(i, px, py, pz, e);
1310 void AliGenPythiaPlus::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1313 // Calls the Pythia clustering algorithm to find jets in the current event
1317 if (fJetReconstruction == kCluster) {
1319 // Configure cluster algorithm
1321 // fPythia->SetPARU(43, 2.);
1322 // fPythia->SetMSTU(41, 1);
1324 // Call cluster algorithm
1326 fPythia->Pyclus(nJets);
1328 // Loading jets from common block
1334 fPythia->Pycell(nJets);
1338 for (i = 0; i < nJets; i++) {
1339 Float_t px, py, pz, e;
1340 fPythia->GetJet(i, px, py, pz, e);
1341 Float_t pt = TMath::Sqrt(px * px + py * py);
1342 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1343 Float_t theta = TMath::ATan2(pt,pz);
1344 Float_t et = e * TMath::Sin(theta);
1345 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1347 eta > fEtaMinJet && eta < fEtaMaxJet &&
1348 phi > fPhiMinJet && phi < fPhiMaxJet &&
1349 et > fEtMinJet && et < fEtMaxJet
1352 jets[0][nJetsTrig] = px;
1353 jets[1][nJetsTrig] = py;
1354 jets[2][nJetsTrig] = pz;
1355 jets[3][nJetsTrig] = e;
1362 void AliGenPythiaPlus::GetSubEventTime()
1364 // Calculates time of the next subevent
1367 TArrayF &array = *fEventsTime;
1368 fEventTime = array[fCurSubEvent++];
1370 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1377 Bool_t AliGenPythiaPlus::IsInEMCAL(Float_t phi, Float_t eta) const
1379 // Is particle in EMCAL acceptance?
1380 // phi in degrees, etamin=-etamax
1381 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1388 Bool_t AliGenPythiaPlus::IsInPHOS(Float_t phi, Float_t eta) const
1390 // Is particle in PHOS acceptance?
1391 // Acceptance slightly larger considered.
1392 // phi in degrees, etamin=-etamax
1393 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1400 void AliGenPythiaPlus::RotatePhi(Int_t iphcand, Bool_t& okdd)
1402 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1403 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1404 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1405 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1407 //calculate deltaphi
1408 TParticle* ph = (TParticle *) fParticles.At(iphcand);
1409 Double_t phphi = ph->Phi();
1410 Double_t deltaphi = phiPHOS - phphi;
1414 //loop for all particles and produce the phi rotation
1415 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
1416 Double_t oldphi, newphi;
1417 Double_t newVx, newVy, R, Vz, time;
1418 Double_t newPx, newPy, pt, Pz, e;
1419 for(Int_t i=0; i< np; i++) {
1420 TParticle* iparticle = (TParticle *) fParticles.At(i);
1421 oldphi = iparticle->Phi();
1422 newphi = oldphi + deltaphi;
1423 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1424 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1427 newVx = R*TMath::Cos(newphi);
1428 newVy = R*TMath::Sin(newphi);
1429 Vz = iparticle->Vz(); // don't transform
1430 time = iparticle->T(); // don't transform
1432 pt = iparticle->Pt();
1433 newPx = pt*TMath::Cos(newphi);
1434 newPy = pt*TMath::Sin(newphi);
1435 Pz = iparticle->Pz(); // don't transform
1436 e = iparticle->Energy(); // don't transform
1439 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1440 iparticle->SetMomentum(newPx, newPy, Pz, e);
1442 } //end particle loop
1444 // now let's check that we put correctly the candidate photon in PHOS
1445 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1446 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1447 if(IsInPHOS(phi,eta))
1453 void AliGenPythiaPlus::Streamer(TBuffer &R__b)
1455 // Stream an object of class AliGenPythia.
1457 if (R__b.IsReading()) {
1458 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1459 AliGenerator::Streamer(R__b);
1460 R__b >> (Int_t&)fProcess;
1461 R__b >> (Int_t&)fStrucFunc;
1462 R__b >> (Int_t&)fForceDecay;
1466 fParentSelect.Streamer(R__b);
1467 fChildSelect.Streamer(R__b);
1469 // (AliPythia::Instance())->Streamer(R__b);
1472 // if (fDecayer) fDecayer->Streamer(R__b);
1474 R__b.WriteVersion(AliGenPythiaPlus::IsA());
1475 AliGenerator::Streamer(R__b);
1476 R__b << (Int_t)fProcess;
1477 R__b << (Int_t)fStrucFunc;
1478 R__b << (Int_t)fForceDecay;
1482 fParentSelect.Streamer(R__b);
1483 fChildSelect.Streamer(R__b);
1488 // fDecayer->Streamer(R__b);