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 **************************************************************************/
18 // Generator using AMPT as an external generator
20 #include "AliGenAmpt.h"
22 #include <TClonesArray.h>
25 #include <TLorentzVector.h>
27 #include <TParticle.h>
28 #include <TVirtualMC.h>
29 #include <TParticlePDG.h>
30 #include "AliGenHijingEventHeader.h"
31 #define AliGenAmptEventHeader AliGenHijingEventHeader
32 #include "AliAmptRndm.h"
35 #include "AliDecayer.h"
39 AliGenAmpt::AliGenAmpt()
65 fPhiMaxJet(TMath::TwoPi()),
75 fNoHeavyQuarks(kFALSE),
84 fHeader(new AliGenAmptEventHeader("Ampt")),
89 AliAmptRndm::SetAmptRandom(GetRandom());
92 AliGenAmpt::AliGenAmpt(Int_t npart)
118 fPhiMaxJet(2. * TMath::Pi()),
128 fNoHeavyQuarks(kFALSE),
137 fHeader(new AliGenAmptEventHeader("Ampt")),
140 // Default PbPb collisions at 2.76 TeV
144 fTitle= "Particle Generator using AMPT";
145 AliAmptRndm::SetAmptRandom(GetRandom());
148 AliGenAmpt::~AliGenAmpt()
151 if ( fDsigmaDb) delete fDsigmaDb;
152 if ( fDnDb) delete fDnDb;
153 if ( fHeader) delete fHeader;
156 void AliGenAmpt::Init()
162 fProjectile.Resize(8);
164 fAmpt = new TAmpt(fEnergyCMS, fFrame, fProjectile, fTarget,
165 fAProjectile, fZProjectile, fATarget, fZTarget,
166 fMinImpactParam, fMaxImpactParam);
169 fAmpt->SetIHPR2(2, fRadiation);
170 fAmpt->SetIHPR2(3, fTrigger);
171 fAmpt->SetIHPR2(6, fShadowing);
172 fAmpt->SetIHPR2(12, fDecaysOff);
173 fAmpt->SetIHPR2(21, fKeep);
174 fAmpt->SetHIPR1(8, fPtHardMin);
175 fAmpt->SetHIPR1(9, fPtHardMax);
176 fAmpt->SetHIPR1(10, fPtMinJet);
177 fAmpt->SetHIPR1(50, fSimpleJet);
180 // fQuench = 0: no quenching
181 // fQuench = 1: Hijing default
182 // fQuench = 2: new LHC parameters for HIPR1(11) and HIPR1(14)
183 // fQuench = 3: new RHIC parameters for HIPR1(11) and HIPR1(14)
184 // fQuench = 4: new LHC parameters with log(e) dependence
185 // fQuench = 5: new RHIC parameters with log(e) dependence
186 fAmpt->SetIHPR2(50, 0);
188 fAmpt->SetIHPR2(4, 1);
190 fAmpt->SetIHPR2(4, 0);
193 fAmpt->SetHIPR1(14, 1.1);
194 fAmpt->SetHIPR1(11, 3.7);
195 } else if (fQuench == 3) {
196 fAmpt->SetHIPR1(14, 0.20);
197 fAmpt->SetHIPR1(11, 2.5);
198 } else if (fQuench == 4) {
199 fAmpt->SetIHPR2(50, 1);
200 fAmpt->SetHIPR1(14, 4.*0.34);
201 fAmpt->SetHIPR1(11, 3.7);
202 } else if (fQuench == 5) {
203 fAmpt->SetIHPR2(50, 1);
204 fAmpt->SetHIPR1(14, 0.34);
205 fAmpt->SetHIPR1(11, 2.5);
209 if (fNoHeavyQuarks) {
210 fAmpt->SetIHPR2(49, 1);
212 fAmpt->SetIHPR2(49, 0);
216 fAmpt->SetIsoft(fIsoft);
217 fAmpt->SetNtMax(fNtMax);
218 fAmpt->SetIpop(fIpop);
220 fAmpt->SetAlpha(fAlpha);
221 fAmpt->SetStringFrag(fStringA, fStringB);
228 EvaluateCrossSections();
231 void AliGenAmpt::Generate()
233 // Generate one event
235 Float_t polar[3] = {0,0,0};
236 Float_t origin[3] = {0,0,0};
237 Float_t origin0[3] = {0,0,0};
241 // converts from mm/c to s
242 const Float_t kconv = 0.001/2.99792458e8;
246 Int_t j, kf, ks, ksp, imo;
250 for (j = 0;j < 3; j++)
251 origin0[j] = fOrigin[j];
253 if(fVertexSmear == kPerEvent) {
255 for (j=0; j < 3; j++)
256 origin0[j] = fVertex[j];
259 Float_t sign = (fRandomPz && (Rndm() < 0.5))? -1. : 1.;
262 // Generate one event
263 Int_t fpemask = gSystem->GetFPEMask();
264 gSystem->SetFPEMask(0);
265 fAmpt->GenerateEvent();
266 gSystem->SetFPEMask(fpemask);
269 fAmpt->ImportParticles(&fParticles,"All");
270 Int_t np = fParticles.GetEntriesFast();
274 if (fTrigger != kNoTrigger) {
279 AliDecayer *decayer = 0;
281 decayer = gMC->GetDecayer();
283 if (decayer&&fDecay) {
284 TClonesArray arr("TParticle",100);
286 for (Int_t i = 0; i < np; i++) {
287 TParticle *iparticle = (TParticle *)fParticles.At(i);
288 if (!Stable(iparticle))
290 kf = iparticle->GetPdgCode();
293 if (0) { // this turned out to be too cumbersome!
294 if (kf!=331&&kf!=3114&&kf!=3114&&kf!=411&&kf!=-4122&&kf!=-3324&&kf!=-3312&&kf!=-3114&&
295 kf!=-311&&kf!=3214&&kf!=-3214&&kf!=-433&&kf!=413&&kf!=3122&&kf!=-3122&&kf!=-413&&
296 kf!=-421&&kf!=-423&&kf!=3324&&kf!=-313&&kf!=213&&kf!=-213&&kf!=3314&&kf!=3222&&
297 kf!=-3222&&kf!=3224&&kf!=-3224&&kf!=-4212&&kf!=4212&&kf!=433&&kf!=423&&kf!=-3322&&
299 continue; //decay eta',Sigma*+,Sigma*-,D+,Lambda_c-,Xi*0_bar,Xi-_bar,Sigma*-,
300 // K0_bar,Sigma*0,Sigma*0_bar,D*_s-,D*+,Lambda0,Lambda0_bar,D*-
301 // D0_bar,D*0_bar,Xi*0,K*0_bar,rho+,rho-,Xi*-,Sigma-,
302 // Sigma+,Sigma*+,Sigma*-,Sigma_c-,Sigma_c+,D*_s+,D*0,Xi0_bar
304 } else { // really only decay particles if there are not known to Geant3
305 if (gMC->IdFromPDG(kf)>0)
308 if (0) { // defining the particle for Geant3 leads to a floating point exception.
309 TParticlePDG *pdg = iparticle->GetPDG(1);
310 //pdg->Print(); printf("%s\n",pdg->ParticleClass());
311 TString ptype(pdg->ParticleClass());
312 TMCParticleType mctype(kPTUndefined);
313 if (ptype=="Baryon" || ptype=="Meson")
315 gMC->DefineParticle(pdg->PdgCode(), pdg->GetName(), mctype, pdg->Mass(), pdg->Charge(), pdg->Lifetime(),
316 ptype,pdg->Width(), (Int_t)pdg->Spin(), (Int_t)pdg->Parity(), 0,
317 (Int_t)pdg->Isospin(), 0, 0, 0, 0, pdg->Stable());
318 gMC->SetUserDecay(pdg->PdgCode());
322 TLorentzVector pmom(iparticle->Px(),iparticle->Py(),iparticle->Pz(),iparticle->Energy());
323 decayer->Decay(kf,&pmom);
324 decayer->ImportParticles(&arr);
325 Int_t ndecayed = arr.GetEntries();
327 if (np2+ndecayed>fParticles.GetSize())
328 fParticles.Expand(2*fParticles.GetSize());
330 iparticle->SetStatusCode(2);
331 iparticle->SetFirstDaughter(np2);
332 for (Int_t jj = 1; jj < ndecayed; jj++) {
333 TParticle *jp = (TParticle *)arr.At(jj);
334 if (jp->GetFirstMother()!=1)
336 TParticle *newp = new(fParticles[np2]) TParticle(jp->GetPdgCode(),
342 jp->Px(),jp->Py(),jp->Pz(),jp->Energy(),
343 jp->Vx(),jp->Vy(),jp->Vz(),jp->T());
344 newp->SetUniqueID(999);
347 iparticle->SetLastDaughter(np2-1);
350 np = fParticles.GetEntries();
352 AliError(Form("Something is fishy: %d %d\n", np,np2));
356 AliError("No decayer found, but fDecay==kTRUE!");
363 Int_t* newPos = new Int_t[np];
364 Int_t* pSelected = new Int_t[np];
366 for (Int_t i = 0; i < np; i++) {
372 //TParticle * iparticle = (TParticle *) fParticles.At(0);
373 fVertex[0] = origin0[0];
374 fVertex[1] = origin0[1];
375 fVertex[2] = origin0[2];
377 // First select parent particles
378 for (Int_t i = 0; i < np; i++) {
379 TParticle *iparticle = (TParticle *) fParticles.At(i);
381 // Is this a parent particle ?
382 if (Stable(iparticle)) continue;
383 Bool_t selected = kTRUE;
384 Bool_t hasSelectedDaughters = kFALSE;
385 kf = iparticle->GetPdgCode();
386 ks = iparticle->GetStatusCode();
391 selected = KinematicSelection(iparticle, 0) && SelectFlavor(kf);
392 hasSelectedDaughters = DaughtersSelection(iparticle);
394 // Put particle on the stack if it is either selected or
395 // it is the mother of at least one seleted particle
396 if (selected || hasSelectedDaughters) {
400 } // particle loop parents
402 // Now select the final state particles
403 fProjectileSpecn = 0;
404 fProjectileSpecp = 0;
407 for (Int_t i = 0; i<np; i++) {
408 TParticle *iparticle = (TParticle *) fParticles.At(i);
409 // Is this a final state particle ?
410 if (!Stable(iparticle))
412 Bool_t selected = kTRUE;
413 kf = iparticle->GetPdgCode();
416 ks = iparticle->GetStatusCode();
417 ksp = iparticle->GetUniqueID();
419 // --------------------------------------------------------------------------
420 // Count spectator neutrons and protons
421 if(ksp == 0 || ksp == 1) {
422 if(kf == kNeutron) fProjectileSpecn += 1;
423 if(kf == kProton) fProjectileSpecp += 1;
424 } else if(ksp == 10 || ksp == 11) {
425 if(kf == kNeutron) fTargetSpecn += 1;
426 if(kf == kProton) fTargetSpecp += 1;
428 // --------------------------------------------------------------------------
430 selected = KinematicSelection(iparticle,0)&&SelectFlavor(kf);
431 if (!fSpectators && selected)
432 selected = (ksp != 0 && ksp != 1 && ksp != 10 && ksp != 11);
435 // Put particle on the stack if selected
439 if (0) printf("---> %d %d %d %s\n",i,nc,kf,iparticle->GetName());
441 } // particle loop final state
443 //Time of the interactions
445 if (fPileUpTimeWindow > 0.)
446 tInt = fPileUpTimeWindow * (2. * gRandom->Rndm() - 1.);
448 // Write particles to stack
449 for (Int_t i = 0; i<np; i++) {
450 TParticle *iparticle = (TParticle *) fParticles.At(i);
451 Bool_t hasMother = (iparticle->GetFirstMother() >=0);
452 Bool_t hasDaughter = (iparticle->GetFirstDaughter() >=0);
454 kf = iparticle->GetPdgCode();
455 ks = iparticle->GetStatusCode();
456 p[0] = iparticle->Px();
457 p[1] = iparticle->Py();
458 p[2] = iparticle->Pz() * sign;
459 origin[0] = origin0[0]+iparticle->Vx()/10;
460 origin[1] = origin0[1]+iparticle->Vy()/10;
461 origin[2] = origin0[2]+iparticle->Vz()/10;
464 if (TestBit(kVertexRange)) {
465 fEventTime = sign * origin0[2] / 2.99792458e10;
466 tof = kconv * iparticle->T() + fEventTime;
468 tof = kconv * iparticle->T();
470 if (fPileUpTimeWindow > 0.) tof += tInt;
473 TParticle* mother = 0;
475 imo = iparticle->GetFirstMother();
476 mother = (TParticle *) fParticles.At(imo);
477 imo = (mother->GetPdgCode() != 92) ? newPos[imo] : -1;
479 Bool_t tFlag = (fTrackIt && !hasDaughter);
480 PushTrack(tFlag,imo,kf,p,origin,polar,tof,kPNoProcess,nt, 1., ks);
489 AliInfo(Form("\n I've put %i particles on the stack \n",nc));
492 if (jev >= fNpart || fNpart == -1) {
493 fKineBias = Float_t(fNpart)/Float_t(fTrials);
494 AliInfo(Form("\n Trials: %i %i %i\n",fTrials, fNpart, jev));
500 SetHighWaterMark(nt);
503 void AliGenAmpt::EvaluateCrossSections()
505 // Glauber Calculation of geometrical x-section
507 Float_t xTot = 0.; // barn
508 Float_t xTotHard = 0.; // barn
509 Float_t xPart = 0.; // barn
510 Float_t xPartHard = 0.; // barn
511 Float_t sigmaHard = 0.1; // mbarn
513 Float_t bMax = fAmpt->GetHIPR1(34)+fAmpt->GetHIPR1(35);
514 const Float_t kdib = 0.2;
515 Int_t kMax = Int_t((bMax-bMin)/kdib)+1;
517 printf("\n Projectile Radius (fm): %f \n",fAmpt->GetHIPR1(34));
518 printf("\n Target Radius (fm): %f \n",fAmpt->GetHIPR1(35));
521 Float_t oldvalue= 0.;
522 Float_t* b = new Float_t[kMax]; memset(b,0,kMax*sizeof(Float_t));
523 Float_t* si1 = new Float_t[kMax]; memset(si1,0,kMax*sizeof(Float_t));
524 Float_t* si2 = new Float_t[kMax]; memset(si2,0,kMax*sizeof(Float_t));
525 for (i = 0; i < kMax; i++) {
526 Float_t xb = bMin+i*kdib;
527 Float_t ov=fAmpt->Profile(xb);
528 Float_t gb = 2.*0.01*fAmpt->GetHIPR1(40)*kdib*xb*(1.-TMath::Exp(-fAmpt->GetHINT1(12)*ov));
529 Float_t gbh = 2.*0.01*fAmpt->GetHIPR1(40)*kdib*xb*sigmaHard*ov;
532 printf("profile %f %f %f\n", xb, ov, fAmpt->GetHINT1(12));
534 if (xb > fMinImpactParam && xb < fMaxImpactParam) {
539 if ((oldvalue) && ((xTot-oldvalue)/oldvalue<0.0001))
542 printf("\n Total cross section (barn): %d %f %f \n",i, xb, xTot);
543 printf("\n Hard cross section (barn): %d %f %f \n\n",i, xb, xTotHard);
551 printf("\n Total cross section (barn): %f \n",xTot);
552 printf("\n Hard cross section (barn): %f \n \n",xTotHard);
553 printf("\n Partial cross section (barn): %f %f \n",xPart, xPart/xTot*100.);
554 printf("\n Partial hard cross section (barn): %f %f \n",xPartHard, xPartHard/xTotHard*100.);
556 // Store result as a graph
561 fDsigmaDb = new TGraph(i, b, si1);
563 fDnDb = new TGraph(i, b, si2);
566 Bool_t AliGenAmpt::DaughtersSelection(TParticle* iparticle)
568 // Looks recursively if one of the daughters has been selected
569 //printf("\n Consider daughters %d:",iparticle->GetPdgCode());
572 Bool_t hasDaughters = (iparticle->GetFirstDaughter() >=0);
573 Bool_t selected = kFALSE;
575 imin = iparticle->GetFirstDaughter();
576 imax = iparticle->GetLastDaughter();
577 for (Int_t i = imin; i <= imax; i++){
578 TParticle * jparticle = (TParticle *) fParticles.At(i);
579 Int_t ip = jparticle->GetPdgCode();
580 if (KinematicSelection(jparticle,0)&&SelectFlavor(ip)) {
581 selected=kTRUE; break;
583 if (DaughtersSelection(jparticle)) {selected=kTRUE; break; }
591 Bool_t AliGenAmpt::SelectFlavor(Int_t pid)
593 // Select flavor of particle
595 // 4: charm and beauty
602 Int_t ifl = TMath::Abs(pid/100);
603 if (ifl > 10) ifl/=10;
604 res = (fFlavor == ifl);
607 // This part if gamma writing is inhibited
609 res = res && (pid != kGamma && pid != kPi0);
614 Bool_t AliGenAmpt::Stable(TParticle* particle) const
616 // Return true for a stable particle
620 if (particle->GetFirstDaughter() < 0 )
625 void AliGenAmpt::MakeHeader()
627 // Fills the event header, to be called after each event
629 fHeader->SetNProduced(fNprimaries);
630 fHeader->SetImpactParameter(fAmpt->GetHINT1(19));
631 fHeader->SetTotalEnergy(fAmpt->GetEATT());
632 fHeader->SetHardScatters(fAmpt->GetJATT());
633 fHeader->SetParticipants(fAmpt->GetNP(), fAmpt->GetNT());
634 fHeader->SetCollisions(fAmpt->GetN0(),
638 fHeader->SetSpectators(fProjectileSpecn, fProjectileSpecp,
639 fTargetSpecn,fTargetSpecp);
640 fHeader->SetReactionPlaneAngle(fAmpt->GetHINT1(20));
641 //printf("Impact Parameter %13.3f \n", fAmpt->GetHINT1(19));
643 // 4-momentum vectors of the triggered jets.
644 // Before final state gluon radiation.
645 TLorentzVector* jet1 = new TLorentzVector(fAmpt->GetHINT1(21),
648 fAmpt->GetHINT1(24));
650 TLorentzVector* jet2 = new TLorentzVector(fAmpt->GetHINT1(31),
653 fAmpt->GetHINT1(34));
654 // After final state gluon radiation.
655 TLorentzVector* jet3 = new TLorentzVector(fAmpt->GetHINT1(26),
658 fAmpt->GetHINT1(29));
660 TLorentzVector* jet4 = new TLorentzVector(fAmpt->GetHINT1(36),
663 fAmpt->GetHINT1(39));
664 fHeader->SetJets(jet1, jet2, jet3, jet4);
665 // Bookkeeping for kinematic bias
666 fHeader->SetTrials(fTrials);
668 fHeader->SetPrimaryVertex(fVertex);
669 fHeader->SetInteractionTime(fEventTime);
671 fCollisionGeometry = fHeader;
676 Bool_t AliGenAmpt::CheckTrigger()
678 // Check the kinematic trigger condition
680 Bool_t triggered = kFALSE;
684 TLorentzVector* jet1 = new TLorentzVector(fAmpt->GetHINT1(26),
687 fAmpt->GetHINT1(29));
689 TLorentzVector* jet2 = new TLorentzVector(fAmpt->GetHINT1(36),
692 fAmpt->GetHINT1(39));
693 Double_t eta1 = jet1->Eta();
694 Double_t eta2 = jet2->Eta();
695 Double_t phi1 = jet1->Phi();
696 Double_t phi2 = jet2->Phi();
697 //printf("\n Trigger: %f %f %f %f", fEtaMinJet, fEtaMaxJet, fPhiMinJet, fPhiMaxJet);
698 if ( (eta1 < fEtaMaxJet && eta1 > fEtaMinJet &&
699 phi1 < fPhiMaxJet && phi1 > fPhiMinJet)
701 (eta2 < fEtaMaxJet && eta2 > fEtaMinJet &&
702 phi2 < fPhiMaxJet && phi2 > fPhiMinJet)
705 } else if (fTrigger == 2) {
707 Int_t np = fParticles.GetEntriesFast();
708 for (Int_t i = 0; i < np; i++) {
709 TParticle* part = (TParticle*) fParticles.At(i);
710 Int_t kf = part->GetPdgCode();
711 Int_t ksp = part->GetUniqueID();
712 if (kf == 22 && ksp == 40) {
713 Float_t phi = part->Phi();
714 Float_t eta = part->Eta();
715 if (eta < fEtaMaxJet &&
721 } // check phi,eta within limits