Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PGun.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PGun.cc
1 /*******************************************************************************
2  * Copyright (c) The JETSCAPE Collaboration, 2018
3  *
4  * Modular, task-based framework for simulating all aspects of heavy-ion collisions
5  *
6  * For the list of contributors see AUTHORS.
7  *
8  * Report issues at https://github.com/JETSCAPE/JETSCAPE/issues
9  *
10  * or via email to bugs.jetscape@gmail.com
11  *
12  * Distributed under the GNU General Public License 3.0 (GPLv3 or later).
13  * See COPYING for details.
14  ******************************************************************************/
15 //Parton Gun Test
16 
17 #include "PGun.h"
18 #include "JetScapeParticles.h"
19 #include "Pythia8/Pythia.h"
20 
21 using namespace Jetscape;
22 
23 // Register the module with the base class
25 
26 Pythia8::Pythia PGun::InternalHelperPythia("IntentionallyEmpty", false);
27 
29  fixed_pT = 0;
30  parID = 21;
31  SetId("PGun");
32  VERBOSE(8);
33 }
34 
36 
38  JSDEBUG << "Initialize PGun Brick (Test) ...";
39  VERBOSE(8);
40 
41  std::string s = GetXMLElementText({"Hard", "PGun", "name"});
42  JSDEBUG << s << " to be initialized ...";
43 
44  fixed_pT = GetXMLElementDouble({"Hard", "PGun", "pT"});
45  JSDEBUG << s << " with fixed pT = " << fixed_pT;
46  JSINFO << "Parton Gun with fixed pT = " << fixed_pT;
47 
48  parID = GetXMLElementDouble({"Hard", "PGun", "parID"});
49  JSINFO << "Parton Gun with parID = " << parID;
50 }
51 
52 void PGun::Exec() {
53  VERBOSE(2) << "Run Hard Process : " << GetId() << " ...";
54 
55  double p[4], xLoc[4];
56 
57  double pT, rapidity, phi, pseudorapidity;
58  double eta_cut = 1.0;
59  double tempRand;
60  const double maxN = 1.0 * RAND_MAX;
61  const double PI = 3.1415926;
62 
63  double ppx, ppy, ppz, pp0, mass;
64 
65  // for (int i=0;i<1;i++)
66  // {
67  // tempRand = rand()/maxN;
68  // if(tempRand < 0.25) parID = 21;
69  // else if(tempRand < 0.50) parID = 1;
70  // else if(tempRand < 0.75) parID = 2;
71  // else parID = 3;
72  // if (parID != 21) {
73  // tempRand = rand()/maxN;
74  // if(tempRand < 0.50) parID = -parID;
75  // }
76  // mass = 0.0;
77  mass = InternalHelperPythia.particleData.m0(parID);
78  //JSINFO << BOLDYELLOW << " Mass = " << mass ;
79  pT = fixed_pT; //max_pT*(rand()/maxN);
80 
81  phi = 2.0 * PI * (rand() / maxN);
82  rapidity = 0; //2.0*eta_cut*(rand()/maxN)-eta_cut;
83  phi = 0.0;
84 
85  p[1] = pT * cos(phi);
86  p[2] = pT * sin(phi);
87  p[3] = sqrt(pT * pT + mass * mass) * sinh(rapidity);
88  p[0] = sqrt(pT * pT + mass * mass) * cosh(rapidity);
89 
90  double p_abs = std::sqrt(pT*pT + p[3]*p[3]);
91  if(std::abs(p_abs - p[3]) > rounding_error){
92  pseudorapidity = 0.5 * std::log((p_abs + p[3]) / (p_abs - p[3]));
93  } else {
94  JSWARN << "Particle in PGun has infinite pseudorapidity.";
95  }
96 
97  // Roll for a starting point
98  // See: https://stackoverflow.com/questions/15039688/random-generator-from-vector-with-probability-distribution-in-c
99  for (int i = 0; i <= 3; i++) {
100  xLoc[i] = 0.0;
101  };
102 
103  if (!ini) {
104  VERBOSE(1)
105  << "No initial state module, setting the starting location to 0. ";
106  } else {
107  double x, y;
108  ini->SampleABinaryCollisionPoint(x, y);
109  xLoc[1] = x;
110  xLoc[2] = y;
111  }
112 
113  xLoc[1] = 0.0;
114  xLoc[2] = 0.0;
115 
116  auto ptn = make_shared<Parton>(0, parID, 0, pT, pseudorapidity, phi, p[0], xLoc);
117  ptn->set_color((parID > 0) ? 100 : 0);
118  ptn->set_anti_color(((parID > 0) || (parID == 21)) ? 0 : 101);
119  ptn->set_max_color(102);
120  AddParton(ptn);
121 
122  VERBOSE(8) << GetNHardPartons();
123 }