19 #include <Pythia8/Pythia.h>
20 #include <Pythia8Plugins/HepMC2.h>
21 #include <phgeom/PHGeomUtility.h>
22 #include <boost/format.hpp>
29 #include <gsl/gsl_randist.h>
30 #include <Geant4/G4ParticleTable.hh>
42 const double pi = TMath::Pi();
47 const double mp = 0.93827;
48 const double mmu = 0.10566;
90 pdf = LHAPDF::mkPDF(
"CT10nlo", 0);
110 ppGen.readString(
"PDF:pSet = 7 ");
111 ppGen.readString(
"ParticleDecays:limitTau = on");
112 ppGen.readString(
"WeakSingleBoson:ffbar2ffbar(s:gm) = on");
113 ppGen.readString(
"Beams:frameType = 2");
114 ppGen.readString(
"Beams:idA = 2212");
115 ppGen.readString(
"Beams:eA = 120.");
116 ppGen.readString(
"Beams:eB = 0.");
117 ppGen.readString(
"Beams:allowVertexSpread = on");
120 pnGen.readString(
"PDF:pSet = 7 ");
121 pnGen.readString(
"ParticleDecays:limitTau = on");
122 pnGen.readString(
"WeakSingleBoson:ffbar2ffbar(s:gm) = on");
123 pnGen.readString(
"Beams:frameType = 2");
124 pnGen.readString(
"Beams:idA = 2212");
125 pnGen.readString(
"Beams:eA = 120.");
126 pnGen.readString(
"Beams:eB = 0.");
127 pnGen.readString(
"Beams:allowVertexSpread = on");
131 ppGen.readString(
"Beams:idB = 2212");
132 pnGen.readString(
"Beams:idB = 2112");
136 if (seed > 900000000)
138 seed = seed % 900000000;
141 if ((seed > 0) && (seed <= 900000000))
143 ppGen.readString(
"Random:setSeed = on");
144 ppGen.readString(str(boost::format(
"Random:seed = %1%") % seed));
146 pnGen.readString(
"Random:setSeed = on");
147 pnGen.readString(str(boost::format(
"Random:seed = %1%") % seed));
162 ineve = findNode::getClass<PHG4InEvent>(topNode,
"PHG4INEVENT");
172 _mcevt = findNode::getClass<SQMCEvent>(topNode,
"SQMCEvent");
178 _vec_dim = findNode::getClass<SQDimuonVector>(topNode,
"SQTruthDimuonVector");
193 double x_vtx,y_vtx,z_vtx;
197 _vertexGen->
traverse(geoManager->GetTopNode(),x_vtx,y_vtx, z_vtx);
201 vtx.SetXYZ(x_vtx,y_vtx,z_vtx);
217 double mass = gRandom->Uniform(0,1)*(massMax - massMin) + massMin;
218 double xF = gRandom->Uniform(0,1)*(xfMax - xfMin) + xfMin;
224 double dim_mass, dim_pT, dim_x1, dim_x2, dim_xF, dim_costh, dim_phi;
225 UtilDimuon::CalcVar(_dim_gen, dim_mass, dim_pT, dim_x1, dim_x2, dim_xF, dim_costh, dim_phi);
231 double zOverA = pARatio;
232 double nOverA = 1. - zOverA;
234 double dbar1 = pdf->xfxQ(-1, dim_x1, dim_mass)/dim_x1;
235 double ubar1 = pdf->xfxQ(-2, dim_x1, dim_mass)/dim_x1;
236 double d1 = pdf->xfxQ( 1, dim_x1, dim_mass)/dim_x1;
237 double u1 = pdf->xfxQ( 2, dim_x1, dim_mass)/dim_x1;
238 double s1 = pdf->xfxQ( 3, dim_x1, dim_mass)/dim_x1;
239 double c1 = pdf->xfxQ( 4, dim_x1, dim_mass)/dim_x1;
241 double dbar2 = pdf->xfxQ(-1, dim_x2, dim_mass)/dim_x2;
242 double ubar2 = pdf->xfxQ(-2, dim_x2, dim_mass)/dim_x2;
243 double d2 = pdf->xfxQ( 1, dim_x2, dim_mass)/dim_x2;
244 double u2 = pdf->xfxQ( 2, dim_x2, dim_mass)/dim_x2;
245 double s2 = pdf->xfxQ( 3, dim_x2, dim_mass)/dim_x2;
246 double c2 = pdf->xfxQ( 4, dim_x2, dim_mass)/dim_x2;
248 double xsec_pdf = 4./9.*(u1*(zOverA*ubar2 + nOverA*dbar2) + ubar1*(zOverA*u2 + nOverA*d2) + 2*c1*c2) +
249 1./9.*(d1*(zOverA*dbar2 + nOverA*ubar2) + dbar1*(zOverA*d2 + nOverA*u2) + 2*s1*s2);
254 double xsec_kfactor = 1.;
259 else if(dim_mass < 7.5)
261 xsec_kfactor = 1.25 + (1.82 - 1.25)*(dim_mass - 2.5)/5.;
270 double xsec_phsp = dim_x1*dim_x2/(dim_x1 + dim_x2)/dim_mass/dim_mass/dim_mass;
273 double xsec_limit = (massMax - massMin)*(xfMax - xfMin)*(cosThetaMax*cosThetaMax*cosThetaMax/3.
274 +cosThetaMax - cosThetaMin*cosThetaMin*cosThetaMin/3.
275 - cosThetaMin)*4./3.;
278 double xsec = xsec_pdf*xsec_kfactor*xsec_phsp*xsec_limit*luminosity;
281 InsertEventInfo(xsec, vtx);
288 double mass = gRandom->Uniform(0,1)*(massMax - massMin) + massMin;
289 double xF = gRandom->Uniform(0,1)*(xfMax - xfMin) + xfMin;
295 double dim_mass, dim_pT, dim_x1, dim_x2, dim_xF, dim_costh, dim_phi;
296 UtilDimuon::CalcVar(_dim_gen, dim_mass, dim_pT, dim_x1, dim_x2, dim_xF, dim_costh, dim_phi);
304 double xsec_limit = xfMax - xfMin;
309 InsertEventInfo(xsec, vtx);
316 double mass = gRandom->Uniform(0,1)*(massMax - massMin) + massMin;
317 double xF = gRandom->Uniform(0,1)*(xfMax - xfMin) + xfMin;
323 double dim_mass, dim_pT, dim_x1, dim_x2, dim_xF, dim_costh, dim_phi;
324 UtilDimuon::CalcVar(_dim_gen, dim_mass, dim_pT, dim_x1, dim_x2, dim_xF, dim_costh, dim_phi);
332 double xsec_limit = xfMax - xfMin;
337 InsertEventInfo(xsec, vtx);
345 Pythia8::Pythia* p_pythia =gRandom->Uniform(0,1) < pARatio ? &ppGen : &pnGen ;
349 while(!p_pythia->next()) {}
352 for(
int i = 1; i < p_pythia->event.size(); ++i)
355 Pythia8::Particle par = p_pythia->event[i];
356 if(par.status() <= 0 && par.id() == 22)
continue;
360 if(par.mother1() == 0 && par.mother2()==0)
continue;
361 if(par.pz()<5.0)
continue;
365 vtxindex = ineve->
AddVtx(vtx.X()+(par.xProd()*CLHEP::mm),vtx.Y()+(par.yProd()*CLHEP::mm),vtx.Z()+(par.zProd()*CLHEP::mm),0.);
372 particle->
set_px(par.px());
373 particle->
set_py(par.py());
374 particle->
set_pz(par.pz());
375 particle->
set_e(par.e());
395 if(pTmaxSq < 0.)
return false;
397 double pTmax = sqrt(pTmaxSq);
402 pT = pTmax*sqrt(gRandom->Uniform(0,1));
414 double px = pT*TMath::Cos(phi);
415 double py = pT*TMath::Sin(phi);
418 TLorentzVector p_dimuon;
419 p_dimuon.SetXYZM(px, py, pz, mass);
421 double masses[2] = {0.105658,0.105658};
422 phaseGen.SetDecay(p_dimuon, 2, masses);
424 bool firstTry =
true;
425 double dim_mass, dim_pT, dim_x1, dim_x2, dim_xF, dim_costh, dim_phi;
428 while(firstTry || angular)
435 UtilDimuon::CalcVar(_dim_gen, dim_mass, dim_pT, dim_x1, dim_x2, dim_xF, dim_costh, dim_phi);
436 angular = 2.*gRandom->Uniform(0,1) > 1. + pow(dim_costh, 2);
439 if(dim_x1 < x1Min || dim_x1 > x1Max)
return false;
440 if(dim_x2 < x2Min || dim_x2 > x2Max)
return false;
441 if(dim_costh < cosThetaMin || dim_costh >cosThetaMax)
return false;
451 void SQPrimaryParticleGen::InsertMuonPair(TVector3& vtx)
453 int vtxindex = ineve->
AddVtx(vtx.X(),vtx.Y(),vtx.Z(),0.);
482 void SQPrimaryParticleGen::InsertEventInfo(
double xsec, TVector3& vtx)
484 static int dim_id = 0;
void traverse(TGeoNode *node, double &xvertex, double &yvertex, double &zvertex)
int process_event(PHCompositeNode *topNode)
int generateDrellYan(PHCompositeNode *topNode, TVector3 vtx, const double pARatio, double luminosity)
Various generators.
PHNode * findFirst(const std::string &, const std::string &)
virtual void set_cross_section(const double a)=0
int InitRun(PHCompositeNode *topNode)
virtual void set_pz(const double x)
virtual void set_pos(const TVector3 a)=0
virtual void set_dimuon_id(const int a)=0
PHBoolean addNode(PHNode *)
int AddParticle(const int vtxid, PHG4Particle *particle)
virtual void set_mom_pos(const TLorentzVector a)=0
void CalcVar(const SQDimuon *dim, double &mass, double &pT, double &x1, double &x2, double &xF, double &costh, double &phi)
Calculate the key kinematic variables of dimuon.
virtual void set_px(const double x)
virtual void set_py(const double x)
virtual TLorentzVector get_mom_neg() const =0
Return the momentum of the negative track at vertex.
virtual void set_e(const double e)
virtual ~SQPrimaryParticleGen()
virtual void set_weight(const double a)=0
const TLorentzVector p_beam(0., 0., TMath::Sqrt(ebeam *ebeam-mp *mp), ebeam)
bool generateDimuon(double mass, double xF, bool angular=false)
Dimuon phase space generator.
int generatePythia(PHCompositeNode *topNode, TVector3 vtx, const double pARatio)
virtual void set_track_id_neg(const int a)=0
virtual void set_mom(const TLorentzVector a)=0
virtual void set_mom_neg(const TLorentzVector a)=0
virtual TLorentzVector get_mom_pos() const =0
Return the momentum of the positive track at vertex.
void InitRun(PHCompositeNode *topNode)
virtual void set_track_id_pos(const int a)=0
static TGeoManager * GetTGeoManager(PHCompositeNode *topNode)
Main user interface: DST node -> TGeoManager for downstream use.
virtual void set_pid(const int i)
int AddVtx(const double x, const double y, const double z, const double t)
const TLorentzVector p_cms
const TLorentzVector p_target(0., 0., 0., mp)
virtual void set_track_id(const int i)
virtual void set_name(const std::string &name)
int Init(PHCompositeNode *topNode)
int generatePsip(PHCompositeNode *topNode, TVector3 vtx, const double pARatio, double luminosity)
virtual void set_vtx_id(const int i)
virtual void push_back(const SQDimuon *dim)=0
int generateJPsi(PHCompositeNode *topNode, TVector3 vtx, const double pARatio, double luminosity)