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;
383 fParentSelect[0] = 421;
386 case kPyDPlusPbPbMNR:
389 fParentSelect[0] = 411;
392 case kPyDPlusStrangePbPbMNR:
393 case kPyDPlusStrangepPbMNR:
394 case kPyDPlusStrangeppMNR:
395 fParentSelect[0] = 431;
399 case kPyBeautyPbPbMNR:
400 case kPyBeautypPbMNR:
402 case kPyBeautyppMNRwmi:
403 fParentSelect[0]= 511;
404 fParentSelect[1]= 521;
405 fParentSelect[2]= 531;
406 fParentSelect[3]= 5122;
407 fParentSelect[4]= 5132;
408 fParentSelect[5]= 5232;
409 fParentSelect[6]= 5332;
412 case kPyBeautyUnforced:
413 fParentSelect[0] = 511;
414 fParentSelect[1] = 521;
415 fParentSelect[2] = 531;
416 fParentSelect[3] = 5122;
417 fParentSelect[4] = 5132;
418 fParentSelect[5] = 5232;
419 fParentSelect[6] = 5332;
424 fParentSelect[0] = 443;
428 case kPyMbWithDirectPhoton:
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 != kPyMbWithDirectPhoton &&
585 fProcess != kPyJets &&
586 fProcess != kPyDirectGamma &&
587 fProcess != kPyMbNonDiffr &&
588 fProcess != kPyMbMSEL1 &&
591 fProcess != kPyCharmppMNRwmi &&
592 fProcess != kPyBeautyppMNRwmi) {
594 for (i = 0; i < np; i++) {
595 TParticle* iparticle = (TParticle *) fParticles.At(i);
596 Int_t ks = iparticle->GetStatusCode();
597 kf = CheckPDGCode(iparticle->GetPdgCode());
598 // No initial state partons
599 if (ks==21) continue;
601 // Heavy Flavor Selection
608 if (kfl > 100000) kfl %= 100000;
609 if (kfl > 10000) kfl %= 10000;
611 if (kfl > 10) kfl/=100;
613 if (kfl > 10) kfl/=10;
614 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
617 // Establish mother daughter relation between heavy quarks and mesons
619 if (kf >= fFlavorSelect && kf <= 6) {
620 Int_t idau = (fPythia->Version() == 6) ? (iparticle->GetFirstDaughter() - 1) :(iparticle->GetFirstDaughter());
622 TParticle* daughter = (TParticle *) fParticles.At(idau);
623 Int_t pdgD = daughter->GetPdgCode();
624 if (pdgD == 91 || pdgD == 92) {
625 Int_t jmin = (fPythia->Version() == 6) ? (daughter->GetFirstDaughter() - 1) : (daughter->GetFirstDaughter());
626 Int_t jmax = (fPythia->Version() == 6) ? (daughter->GetLastDaughter() - 1) : (daughter->GetLastDaughter());
628 for (Int_t jp = jmin; jp <= jmax; jp++)
629 ((TParticle *) fParticles.At(jp))->SetFirstMother(i+1);
630 } // is string or cluster
636 TParticle * mother = (TParticle *) fParticles.At(ipa);
637 kfMo = TMath::Abs(mother->GetPdgCode());
640 // What to keep in Stack?
641 Bool_t flavorOK = kFALSE;
642 Bool_t selectOK = kFALSE;
644 if (kfl >= fFlavorSelect) flavorOK = kTRUE;
646 if (kfl > fFlavorSelect) {
650 if (kfl == fFlavorSelect) flavorOK = kTRUE;
652 switch (fStackFillOpt) {
653 case kFlavorSelection:
656 case kParentSelection:
657 if (ParentSelected(kf) || kf <= 10) selectOK = kTRUE;
660 if (flavorOK && selectOK) {
662 // Heavy flavor hadron or quark
664 // Kinematic seletion on final state heavy flavor mesons
665 if (ParentSelected(kf) && !KinematicSelection(iparticle, 0))
670 if (ParentSelected(kf)) ++nParents; // Update parent count
671 // printf("\n particle (HF) %d %d %d", i, pSelected[i], kf);
673 // Kinematic seletion on decay products
674 if (fCutOnChild && ParentSelected(kfMo) && ChildSelected(kf)
675 && !KinematicSelection(iparticle, 1))
681 // Select if mother was selected and is not tracked
683 if (pSelected[ipa] &&
684 !trackIt[ipa] && // mother will be tracked ?
685 kfMo != 5 && // mother is b-quark, don't store fragments
686 kfMo != 4 && // mother is c-quark, don't store fragments
687 kf != 92) // don't store string
690 // Semi-stable or de-selected: diselect decay products:
693 if (pSelected[i] == -1 || fDecayer->GetLifetime(kf) > fMaxLifeTime)
695 Int_t ipF = iparticle->GetFirstDaughter();
696 Int_t ipL = iparticle->GetLastDaughter();
697 if (ipF > 0) for (j = ipF-1; j < ipL; j++) pSelected[j] = -1;
699 // printf("\n particle (decay) %d %d %d", i, pSelected[i], kf);
700 pSelected[i] = (pSelected[i] == -1) ? 0 : 1;
703 if (pSelected[i] == -1) pSelected[i] = 0;
704 if (!pSelected[i]) continue;
705 // Count quarks only if you did not include fragmentation
706 if (fFragmentation && kf <= 10) continue;
709 // Decision on tracking
712 // Track final state particle
713 if (ks == 1) trackIt[i] = 1;
714 // Track semi-stable particles
715 if ((ks == 1) || (fDecayer->GetLifetime(kf) > fMaxLifeTime)) trackIt[i] = 1;
716 // Track particles selected by process if undecayed.
717 if (fForceDecay == kNoDecay) {
718 if (ParentSelected(kf)) trackIt[i] = 1;
720 if (ParentSelected(kf)) trackIt[i] = 0;
722 if (trackIt[i] == 1) ++nTkbles; // Update trackable counter
726 } // particle selection loop
728 for (i = 0; i < np; i++) {
729 if (!pSelected[i]) continue;
730 TParticle * iparticle = (TParticle *) fParticles.At(i);
731 kf = CheckPDGCode(iparticle->GetPdgCode());
732 Int_t ks = iparticle->GetStatusCode();
733 p[0] = iparticle->Px();
734 p[1] = iparticle->Py();
735 p[2] = iparticle->Pz();
736 p[3] = iparticle->Energy();
738 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
739 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
740 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
742 Float_t tof = kconv*iparticle->T();
743 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
744 Int_t iparent = (ipa > -1) ? pParent[ipa] : -1;
746 PushTrack(fTrackIt*trackIt[i], iparent, kf,
747 p[0], p[1], p[2], p[3],
748 origin[0], origin[1], origin[2], tof,
749 polar[0], polar[1], polar[2],
750 kPPrimary, nt, 1., ks);
767 switch (fCountMode) {
769 // printf(" Count all \n");
773 // printf(" Count parents \n");
776 case kCountTrackables:
777 // printf(" Count trackable \n");
781 if (jev >= fNpart || fNpart == -1) {
782 fKineBias=Float_t(fNpart)/Float_t(fTrials);
783 fPythia->GetXandQ(fQ, fX1, fX2);
784 fTrialsRun += fTrials;
791 SetHighWaterMark(nt);
792 // Adjust weight due to kinematic selection
795 fXsection = fPythia->GetXSection();
798 Int_t AliGenPythiaPlus::GenerateMB()
801 // Min Bias selection and other global selections
803 Int_t i, kf, nt, iparent;
806 Float_t polar[3] = {0,0,0};
807 Float_t origin[3] = {0,0,0};
808 // converts from mm/c to s
809 const Float_t kconv = 0.001 / 2.999792458e8;
811 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
813 Int_t* pParent = new Int_t[np];
814 for (i=0; i< np; i++) pParent[i] = -1;
815 if (fProcess == kPyJets || fProcess == kPyDirectGamma) {
816 TParticle* jet1 = (TParticle *) fParticles.At(6);
817 TParticle* jet2 = (TParticle *) fParticles.At(7);
818 if (!CheckTrigger(jet1, jet2)) {
824 // Select jets with fragmentation photon or pi0 going to PHOS or EMCAL
825 if (fProcess == kPyJets && (fFragPhotonInCalo || fPi0InCalo) ) {
830 if (fFragPhotonInCalo) pdg = 22 ; // Photon
831 else if (fPi0InCalo) pdg = 111 ; // Pi0
833 for (i=0; i< np; i++) {
834 TParticle* iparticle = (TParticle *) fParticles.At(i);
835 if(iparticle->GetStatusCode()==1 && iparticle->GetPdgCode()==pdg &&
836 iparticle->Pt() > fFragPhotonOrPi0MinPt){
837 Int_t imother = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
838 TParticle* pmother = (TParticle *) fParticles.At(imother);
840 (pdg == 22 && pmother->GetStatusCode() != 11))//No photon from hadron decay
842 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
843 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
844 if((fCheckEMCAL && IsInEMCAL(phi,eta)) ||
845 (fCheckPHOS && IsInPHOS(phi,eta)) )
855 // Select events with a photon pt > min pt going to PHOS eta acceptance or exactly PHOS eta phi
856 if ((fProcess == kPyJets || fProcess == kPyDirectGamma) && fPhotonInCalo && (fCheckPHOSeta || fCheckPHOS)){
862 for (i=0; i< np; i++) {
863 TParticle* iparticle = (TParticle *) fParticles.At(i);
864 Float_t phi = iparticle->Phi()*180./TMath::Pi(); //Convert to degrees
865 Float_t eta =TMath::Abs(iparticle->Eta());//in calos etamin=-etamax
867 if(iparticle->GetStatusCode() == 1
868 && iparticle->GetPdgCode() == pdg
869 && iparticle->Pt() > fPhotonMinPt
872 // first check if the photon is in PHOS phi
873 if(IsInPHOS(phi,eta)){
877 if(fCheckPHOSeta) iphcand = i; // candiate photon to rotate in phi
882 if(!okd && iphcand != -1) // execute rotation in phi
883 RotatePhi(iphcand,okd);
889 if (fTriggerParticle) {
890 Bool_t triggered = kFALSE;
891 for (i = 0; i < np; i++) {
892 TParticle * iparticle = (TParticle *) fParticles.At(i);
893 kf = CheckPDGCode(iparticle->GetPdgCode());
894 if (kf != fTriggerParticle) continue;
895 if (iparticle->Pt() == 0.) continue;
896 if (TMath::Abs(iparticle->Eta()) > fTriggerEta) continue;
907 // Check if there is a ccbar or bbbar pair with at least one of the two
908 // in fYMin < y < fYMax
909 if (fProcess == kPyCharmppMNRwmi || fProcess == kPyBeautyppMNRwmi) {
911 Bool_t theQ=kFALSE,theQbar=kFALSE,inYcut=kFALSE;
914 for(i=0; i<np; i++) {
915 hvq = (TParticle*)fParticles.At(i);
916 pdgQ = hvq->GetPdgCode();
917 if(TMath::Abs(pdgQ) != fFlavorSelect) continue;
918 if(pdgQ>0) { theQ=kTRUE; } else { theQbar=kTRUE; }
919 yQ = 0.5*TMath::Log((hvq->Energy()+hvq->Pz()+1.e-13)/
920 (hvq->Energy()-hvq->Pz()+1.e-13));
921 if(yQ>fYMin && yQ<fYMax) inYcut=kTRUE;
923 if (!theQ || !theQbar || !inYcut) {
929 //Introducing child cuts in case kPyW, kPyZ, kPyMb, and kPyMbNonDiff
930 if ( (fProcess == kPyW ||
932 fProcess == kPyMbDefault ||
934 fProcess == kPyMbWithDirectPhoton ||
935 fProcess == kPyMbNonDiffr)
936 && (fCutOnChild == 1) ) {
937 if ( !CheckKinematicsOnChild() ) {
944 for (i = 0; i < np; i++) {
946 TParticle * iparticle = (TParticle *) fParticles.At(i);
947 kf = CheckPDGCode(iparticle->GetPdgCode());
948 Int_t ks = iparticle->GetStatusCode();
949 Int_t km = iparticle->GetFirstMother();
950 if ((ks == 1 && kf!=0 && KinematicSelection(iparticle, 0)) ||
952 (fProcess == kPyJets && ks == 21 && km == 0 && i>1)) {
954 if (ks == 1) trackIt = 1;
956 Int_t ipa = (fPythia->Version() == 6) ? (iparticle->GetFirstMother() - 1) :(iparticle->GetFirstMother()) ;
957 iparent = (ipa > -1) ? pParent[ipa] : -1;
958 if (ipa >= np) fPythia->EventListing();
961 // store track information
962 p[0] = iparticle->Px();
963 p[1] = iparticle->Py();
964 p[2] = iparticle->Pz();
965 p[3] = iparticle->Energy();
968 origin[0] = fVertex[0]+iparticle->Vx()/10; // [cm]
969 origin[1] = fVertex[1]+iparticle->Vy()/10; // [cm]
970 origin[2] = fVertex[2]+iparticle->Vz()/10; // [cm]
972 Float_t tof = fEventTime + kconv * iparticle->T();
974 PushTrack(fTrackIt*trackIt, iparent, kf,
975 p[0], p[1], p[2], p[3],
976 origin[0], origin[1], origin[2], tof,
977 polar[0], polar[1], polar[2],
978 kPPrimary, nt, 1., ks);
983 // Special Treatment to store color-flow
985 if (ks == 3 || ks == 13 || ks == 14) {
986 TParticle* particle = 0;
988 particle = fStack->Particle(nt);
990 particle = gAlice->Stack()->Particle(nt);
992 // particle->SetFirstDaughter(fPythia->GetK(2, i));
993 // particle->SetLastDaughter(fPythia->GetK(3, i));
998 SetHighWaterMark(nt);
1000 } // select particle
1009 void AliGenPythiaPlus::FinishRun()
1011 // Print x-section summary
1012 fPythia->PrintStatistics();
1020 printf("\nTotal number of Pyevnt() calls %d\n", fTrialsRun);
1021 printf("\nMean Q, x1, x2: %f %f %f\n", fQ, fX1, fX2);
1024 void AliGenPythiaPlus::AdjustWeights() const
1026 // Adjust the weights after generation of all events
1030 Int_t ntrack=gAlice->GetMCApp()->GetNtrack();
1031 for (Int_t i=0; i<ntrack; i++) {
1032 part= gAlice->GetMCApp()->Particle(i);
1033 part->SetWeight(part->GetWeight()*fKineBias);
1038 void AliGenPythiaPlus::SetNuclei(Int_t a1, Int_t a2)
1040 // Treat protons as inside nuclei with mass numbers a1 and a2
1048 void AliGenPythiaPlus::MakeHeader()
1051 // Make header for the simulated event
1054 if (gAlice->GetEvNumber()>=fDebugEventFirst &&
1055 gAlice->GetEvNumber()<=fDebugEventLast) fPythia->EventListing();
1058 // Builds the event header, to be called after each event
1059 if (fHeader) delete fHeader;
1060 fHeader = new AliGenPythiaEventHeader("Pythia");
1063 ((AliGenPythiaEventHeader*) fHeader)->SetProcessType(fPythia->ProcessCode());
1066 ((AliGenPythiaEventHeader*) fHeader)->SetTrials(fTrials);
1069 fHeader->SetPrimaryVertex(fVertex);
1072 // Number of primaries
1073 fHeader->SetNProduced(fNprimaries);
1075 // Jets that have triggered
1077 if (fProcess == kPyJets)
1080 Float_t jets[4][10];
1081 GetJets(njet, ntrig, jets);
1084 for (Int_t i = 0; i < ntrig; i++) {
1085 ((AliGenPythiaEventHeader*) fHeader)->AddJet(jets[0][i], jets[1][i], jets[2][i],
1090 // Copy relevant information from external header, if present.
1095 AliGenPythiaEventHeader* exHeader = (AliGenPythiaEventHeader*) (fRL->GetHeader()->GenEventHeader());
1096 for (Int_t i = 0; i < exHeader->NTriggerJets(); i++)
1098 printf("Adding Jet %d %d \n", i, exHeader->NTriggerJets());
1101 exHeader->TriggerJet(i, uqJet);
1102 ((AliGenPythiaEventHeader*) fHeader)->AddUQJet(uqJet[0], uqJet[1], uqJet[2], uqJet[3]);
1106 // Store quenching parameters
1113 fPythia->GetQuenchingParameters(xp, yp, z);
1116 Double_t r1 = PARIMP.rb1;
1117 Double_t r2 = PARIMP.rb2;
1118 Double_t b = PARIMP.b1;
1119 Double_t r = 0.5 * TMath::Sqrt(2. * (r1 * r1 + r2 * r2) - b * b);
1120 Double_t phi = PARIMP.psib1;
1121 xp = r * TMath::Cos(phi);
1122 yp = r * TMath::Sin(phi);
1125 ((AliGenPythiaEventHeader*) fHeader)->SetXYJet(xp, yp);
1126 ((AliGenPythiaEventHeader*) fHeader)->SetZQuench(z);
1130 ((AliGenPythiaEventHeader*) fHeader)->SetPtHard(fPythia->GetPtHard());
1138 Bool_t AliGenPythiaPlus::CheckTrigger(TParticle* jet1, TParticle* jet2)
1140 // Check the kinematic trigger condition
1143 eta[0] = jet1->Eta();
1144 eta[1] = jet2->Eta();
1146 phi[0] = jet1->Phi();
1147 phi[1] = jet2->Phi();
1149 pdg[0] = jet1->GetPdgCode();
1150 pdg[1] = jet2->GetPdgCode();
1151 Bool_t triggered = kFALSE;
1153 if (fProcess == kPyJets) {
1156 Float_t jets[4][10];
1158 // Use Pythia clustering on parton level to determine jet axis
1160 GetJets(njets, ntrig, jets);
1162 if (ntrig || fEtMinJet == 0.) triggered = kTRUE;
1167 if (pdg[0] == kGamma) {
1171 //Check eta range first...
1172 if ((eta[ij] < fEtaMaxJet && eta[ij] > fEtaMinJet) &&
1173 (eta[ig] < fEtaMaxGamma && eta[ig] > fEtaMinGamma))
1175 //Eta is okay, now check phi range
1176 if ((phi[ij] < fPhiMaxJet && phi[ij] > fPhiMinJet) &&
1177 (phi[ig] < fPhiMaxGamma && phi[ig] > fPhiMinGamma))
1188 Bool_t AliGenPythiaPlus::CheckKinematicsOnChild(){
1190 //Checking Kinematics on Child (status code 1, particle code ?, kin cuts
1192 Bool_t checking = kFALSE;
1193 Int_t j, kcode, ks, km;
1194 Int_t nPartAcc = 0; //number of particles in the acceptance range
1195 Int_t numberOfAcceptedParticles = 1;
1196 if (fNumberOfAcceptedParticles != 0) { numberOfAcceptedParticles = fNumberOfAcceptedParticles; }
1197 Int_t npart = fParticles.GetEntriesFast();
1199 for (j = 0; j<npart; j++) {
1200 TParticle * jparticle = (TParticle *) fParticles.At(j);
1201 kcode = TMath::Abs( CheckPDGCode(jparticle->GetPdgCode()) );
1202 ks = jparticle->GetStatusCode();
1203 km = jparticle->GetFirstMother();
1205 if( (ks == 1) && (kcode == fPdgCodeParticleforAcceptanceCut) && (KinematicSelection(jparticle,1)) ){
1208 if( numberOfAcceptedParticles <= nPartAcc){
1217 void AliGenPythiaPlus::RecJetsUA1(Int_t& njets, Float_t jets [4][50])
1220 // Calls the Pythia jet finding algorithm to find jets in the current event
1227 fPythia->Pycell(njets);
1229 for (i = 0; i < njets; i++) {
1230 Float_t px, py, pz, e;
1231 fPythia->GetJet(i, px, py, pz, e);
1240 void AliGenPythiaPlus::GetJets(Int_t& nJets, Int_t& nJetsTrig, Float_t jets[4][10])
1243 // Calls the Pythia clustering algorithm to find jets in the current event
1247 if (fJetReconstruction == kCluster) {
1249 // Configure cluster algorithm
1251 // fPythia->SetPARU(43, 2.);
1252 // fPythia->SetMSTU(41, 1);
1254 // Call cluster algorithm
1256 fPythia->Pyclus(nJets);
1258 // Loading jets from common block
1264 fPythia->Pycell(nJets);
1268 for (i = 0; i < nJets; i++) {
1269 Float_t px, py, pz, e;
1270 fPythia->GetJet(i, px, py, pz, e);
1271 Float_t pt = TMath::Sqrt(px * px + py * py);
1272 Float_t phi = TMath::Pi() + TMath::ATan2(-py, -px);
1273 Float_t theta = TMath::ATan2(pt,pz);
1274 Float_t et = e * TMath::Sin(theta);
1275 Float_t eta = -TMath::Log(TMath::Tan(theta / 2.));
1277 eta > fEtaMinJet && eta < fEtaMaxJet &&
1278 phi > fPhiMinJet && phi < fPhiMaxJet &&
1279 et > fEtMinJet && et < fEtMaxJet
1282 jets[0][nJetsTrig] = px;
1283 jets[1][nJetsTrig] = py;
1284 jets[2][nJetsTrig] = pz;
1285 jets[3][nJetsTrig] = e;
1292 void AliGenPythiaPlus::GetSubEventTime()
1294 // Calculates time of the next subevent
1297 TArrayF &array = *fEventsTime;
1298 fEventTime = array[fCurSubEvent++];
1300 // printf(" Event time: %d %f %p",fCurSubEvent,fEventTime,fEventsTime);
1307 Bool_t AliGenPythiaPlus::IsInEMCAL(Float_t phi, Float_t eta)
1309 // Is particle in EMCAL acceptance?
1310 // phi in degrees, etamin=-etamax
1311 if(phi > fEMCALMinPhi && phi < fEMCALMaxPhi &&
1318 Bool_t AliGenPythiaPlus::IsInPHOS(Float_t phi, Float_t eta)
1320 // Is particle in PHOS acceptance?
1321 // Acceptance slightly larger considered.
1322 // phi in degrees, etamin=-etamax
1323 if(phi > fPHOSMinPhi && phi < fPHOSMaxPhi &&
1330 void AliGenPythiaPlus::RotatePhi(Int_t iphcand, Bool_t& okdd)
1332 //calculate the new position random between fPHOSMinPhi and fPHOSMaxPhi
1333 Double_t phiPHOSmin = TMath::Pi()*fPHOSMinPhi/180;
1334 Double_t phiPHOSmax = TMath::Pi()*fPHOSMaxPhi/180;
1335 Double_t phiPHOS = gRandom->Uniform(phiPHOSmin,phiPHOSmax);
1337 //calculate deltaphi
1338 TParticle* ph = (TParticle *) fParticles.At(iphcand);
1339 Double_t phphi = ph->Phi();
1340 Double_t deltaphi = phiPHOS - phphi;
1344 //loop for all particles and produce the phi rotation
1345 Int_t np = (fHadronisation) ? fParticles.GetEntriesFast() : fNpartons;
1346 Double_t oldphi, newphi;
1347 Double_t newVx, newVy, R, Vz, time;
1348 Double_t newPx, newPy, pt, Pz, e;
1349 for(Int_t i=0; i< np; i++) {
1350 TParticle* iparticle = (TParticle *) fParticles.At(i);
1351 oldphi = iparticle->Phi();
1352 newphi = oldphi + deltaphi;
1353 if(newphi < 0) newphi = 2*TMath::Pi() + newphi; // correct angle
1354 if(newphi > 2*TMath::Pi()) newphi = newphi - 2*TMath::Pi(); // correct angle
1357 newVx = R*TMath::Cos(newphi);
1358 newVy = R*TMath::Sin(newphi);
1359 Vz = iparticle->Vz(); // don't transform
1360 time = iparticle->T(); // don't transform
1362 pt = iparticle->Pt();
1363 newPx = pt*TMath::Cos(newphi);
1364 newPy = pt*TMath::Sin(newphi);
1365 Pz = iparticle->Pz(); // don't transform
1366 e = iparticle->Energy(); // don't transform
1369 iparticle->SetProductionVertex(newVx, newVy, Vz, time);
1370 iparticle->SetMomentum(newPx, newPy, Pz, e);
1372 } //end particle loop
1374 // now let's check that we put correctly the candidate photon in PHOS
1375 Float_t phi = ph->Phi()*180./TMath::Pi(); //Convert to degrees
1376 Float_t eta =TMath::Abs(ph->Eta());//in calos etamin=-etamax
1377 if(IsInPHOS(phi,eta))
1383 void AliGenPythiaPlus::Streamer(TBuffer &R__b)
1385 // Stream an object of class AliGenPythia.
1387 if (R__b.IsReading()) {
1388 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1389 AliGenerator::Streamer(R__b);
1390 R__b >> (Int_t&)fProcess;
1391 R__b >> (Int_t&)fStrucFunc;
1392 R__b >> (Int_t&)fForceDecay;
1396 fParentSelect.Streamer(R__b);
1397 fChildSelect.Streamer(R__b);
1399 // (AliPythia::Instance())->Streamer(R__b);
1402 // if (fDecayer) fDecayer->Streamer(R__b);
1404 R__b.WriteVersion(AliGenPythiaPlus::IsA());
1405 AliGenerator::Streamer(R__b);
1406 R__b << (Int_t)fProcess;
1407 R__b << (Int_t)fStrucFunc;
1408 R__b << (Int_t)fForceDecay;
1412 fParentSelect.Streamer(R__b);
1413 fChildSelect.Streamer(R__b);
1418 // fDecayer->Streamer(R__b);