StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StarPythia8.cxx
1 #include "StarPythia8.h"
2 ClassImp(StarPythia8);
3 
4 #include "TDatabasePDG.h"
5 #include "TParticlePDG.h"
6 
7 #include "StarGenerator/UTIL/StarRandom.h"
8 #include "StarGenerator/EVENT/StarGenPPEvent.h"
9 #include "StarGenerator/EVENT/StarGenEPEvent.h"
10 #include "TString.h"
11 #include "TSystem.h"
12 
13 #ifndef Pythia8_version
14 #error "Pythia8_version is not defined"
15 #endif
16 
17 // ----------------------------------------------------------------------------
18 // Remap pythia's random number generator to StarRandom
19 class PyRand : public Pythia8::RndmEngine {
20 public:
21  double flat() { return StarRandom::Instance().flat(); }
22 };
23 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
26 StarPythia8::StarPythia8(const char *name) : StarGenerator(name)
27 {
28 
29  // Create the new instance of pythia, specifying the path to the
30  // auxilliary files required by pythia.
31  // NOTE: When adding new versions of Pythia8, we need to specify
32  // the version of the code in the source code
33  TString path = "StRoot/StarGenerator/"; path+= Pythia8_version; path+="/xmldoc/";
34  {
35  ifstream in(path);
36  if (!in.good()) { path = "$(STAR)/"+path; }
37  path = gSystem->ExpandPathName(path.Data());
38  }
39 
40 
41  Info(GetName(),Form("MC version is %s data at %s",Pythia8_version,path.Data()));
42  Info(GetName(),Form("Configuration files at %s",path.Data()));
43 
44  mPythia = new Pythia8::Pythia( path.Data() );
45  mPythia -> setRndmEnginePtr( new PyRand() );
46 
47 }
48 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 {
53 
54  //
55  // Remap pythia8 to pdg particles
56  //
57  map<TString,TString> particles;
58  particles["electron"]="e-";
59  particles["proton"]="proton";
60 
61  TString myBlue = particles[mBlue]; if ( myBlue == "" ) myBlue=mBlue;
62  TString myYell = particles[mYell]; if ( myYell == "" ) myYell=mYell;
63 
64  //
65  // Initialize pythia based on the frame and registered beam momenta
66  // TODO: Switch to StarParticleDB
67  //
68  TDatabasePDG &pdg = (*TDatabasePDG::Instance());
69  TParticlePDG *blue = pdg.GetParticle(myBlue); assert(blue);
70  TParticlePDG *yell = pdg.GetParticle(myYell); assert(yell);
71  //
72  if ( mFrame == "CMS" ) InitCMS ( blue->PdgCode(), yell->PdgCode() );
73  if ( mFrame == "FIXT" ) InitFIXT( blue->PdgCode(), yell->PdgCode() );
74  if ( mFrame == "3MOM" ) Init3MOM( blue->PdgCode(), yell->PdgCode() );
75  if ( mFrame == "4MOM" ) Init4MOM( blue->PdgCode(), yell->PdgCode() );
76  if ( mFrame == "5MOM" ) Init5MOM( blue->PdgCode(), yell->PdgCode() );
77  //
78  // Setup event record based upon the beam species
79  //
80  if ( mBlue == "proton" ) mEvent = new StarGenPPEvent();
81  else assert(0); // Pythia 8 does not (yet) support e+p collisions
82  //
83  // Make several particles stable which may cross the beam pipe,
84  // and so the simulation package must be allowed to decide to
85  // decay them or not.
86  //
87  Set("111:onMode=0"); // pi0 stable to permit mother/daughter in star record
88  Set("211:onMode=0"); // pi+/- stable
89  Set("221:onMode=0"); // eta stable
90  Set("321:onMode=0"); // K+/- stable
91  Set("310:onMode=0"); // K short
92  Set("130:onMode=0"); // K long
93  Set("3122:onMode=0"); // Lambda 0
94  Set("3112:onMode=0"); // Sigma -
95  Set("3222:onMode=0"); // Sigma +
96  Set("3212:onMode=0"); // Sigma 0
97  Set("3312:onMode=0"); // Xi -
98  Set("3322:onMode=0"); // Xi 0
99  Set("3334:onMode=0"); // Omega -
100  //
101  return StMaker::Init();
102  //
103 }
104 // ----------------------------------------------------------------------------
106 {
107 
108  //
109  // Generate the event. This is where the action happens. The rest of this
110  // method is just copying data from pythia into the event record.
111  //
112  mPythia -> next();
113 
114  //
115  // Get the pythis event record
116  //
117  Pythia8::Event &event = mPythia->event;
118 
119  //
120  // Get the number of particles in the event. Pythia 8 include a "0th" entry,
121  // which represents the system in the event record. We will skip over this.
122  //
123  mNumberOfParticles = event.size() - 1;
124 
125 
126  if ( mBlue == "proton" ) FillPP( mEvent );
127  else FillEP( mEvent );
128 
129  // Loop over all particles in the event
130  for ( int idx=1; idx <= mNumberOfParticles; idx++ )
131  {
132 
133  int id = event[idx].id();
134  int stat = event.statusHepMC(idx);
135  int mother1 = event[idx].mother1();
136  int mother2 = event[idx].mother2();
137  int daughter1 = event[idx].daughter1();
138  int daughter2 = event[idx].daughter2();
139  double px = event[idx].px();
140  double py = event[idx].py();
141  double pz = event[idx].pz();
142  double energy = event[idx].e();
143  double mass = event[idx].m();
144  double vx = event[idx].xProd(); // mm
145  double vy = event[idx].yProd(); // mm
146  double vz = event[idx].zProd(); // mm
147  double vt = event[idx].tProd(); // mm/c
148 
149  mEvent -> AddParticle( stat, id, mother1, mother2, daughter1, daughter2, px, py, pz, energy, mass, vx, vy, vz, vt );
150 
151  }
152 
153  return kStOK;
154 }
155 // ----------------------------------------------------------------------------
156 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 {
160  //
161  // Fill event-wise information
162  //
163  StarGenEPEvent *event = (StarGenEPEvent *)myevent;
164  Pythia8::Info &info = mPythia->info;
165 
166  event -> idBlue = info.idA(); // Beam particle
167  event -> idYell = info.idB(); // Beam particle
168  event -> process = info.code();
169  event -> subprocess = (info.hasSub())? 0 : info.codeSub();
170 
171  int id = info.id1();
172  double x = info.x1();
173  double xPdf = info.pdf1();
174  int valence = info.isValence1();
175  if ( TMath::Abs(id)>6 )
176  {
177  id = info.id2();
178  x = info.x2();
179  xPdf = info.pdf2();
180  valence = info.isValence2();
181  }
182 
183  event -> idParton = id;
184  event -> xParton = x;
185  event -> xPdf = xPdf;
186 
187  event -> Q2 = info.Q2Fac(); // factorization scale
188  event -> valence = valence;
189 
190 // event -> sHat = info.sHat();
191 // event -> tHat = info.tHat();
192 // event -> uHat = info.uHat();
193 // event -> ptHat = info.pTHat();
194 // event -> thetaHat = info.thetaHat();
195 // event -> phiHat = info.phiHat();
196 
197  event -> weight = info.weight();
198 
199 }
200 // ----------------------------------------------------------------------------
201 // ----------------------------------------------------------------------------
202 // ----------------------------------------------------------------------------
204 {
205  //
206  // Fill event-wise information
207  //
208  StarGenPPEvent *event = (StarGenPPEvent *)myevent;
209  Pythia8::Info &info = mPythia->info;
210 
211  event -> idBlue = info.idA(); // Beam particle
212  event -> idYell = info.idB(); // Beam particle
213  event -> process = info.code();
214  event -> subprocess = (info.hasSub())? 0 : info.codeSub();
215 
216  event -> idParton1 = info.id1();
217  event -> idParton2 = info.id2();
218  event -> xParton1 = info.x1();
219  event -> xParton2 = info.x2();
220  event -> xPdf1 = info.pdf1();
221  event -> xPdf2 = info.pdf2();
222  event -> Q2fac = info.Q2Fac(); // factorization scale
223  event -> Q2ren = info.Q2Ren(); // renormalization scale
224  event -> valence1 = info.isValence1();
225  event -> valence2 = info.isValence2();
226 
227  event -> sHat = info.sHat();
228  event -> tHat = info.tHat();
229  event -> uHat = info.uHat();
230  event -> ptHat = info.pTHat();
231  event -> thetaHat = info.thetaHat();
232  event -> phiHat = info.phiHat();
233 
234  event -> weight = info.weight();
235 
236 }
237 // ----------------------------------------------------------------------------
238 // ----------------------------------------------------------------------------
239 // ----------------------------------------------------------------------------
241 {
242 
243  StarGenStats stats( GetName(), "Pythia 8 Run Statistics" );
244  Pythia8::Info &info = mPythia->info;
245 
246  // Print pythia statistics
247  mPythia->stat();
248 
249  stats.nTried = info.nTried();
250  stats.nSelected = info.nSelected();
251  stats.nAccepted = info.nAccepted();
252  stats.sigmaGen = info.sigmaGen();
253  stats.sigmaErr = info.sigmaErr();
254  stats.sumWeightGen = info.weightSum();
255 
256  stats.nFilterSeen = stats.nAccepted;
257  stats.nFilterAccept = stats.nAccepted;
258 
259  stats.Dump();
260 
261  // Return a copy of the class we just created
262  return stats;
263 
264 }
265 
266 
267 // ----------------------------------------------------------------------------
268 int StarPythia8::InitCMS( int blue, int yell )
269 {
270  mPythia->init( blue, yell, mRootS );
271  return 0;
272 }
273 // ----------------------------------------------------------------------------
274 int StarPythia8::InitFIXT( int blue, int yell )
275 {
276  if ( mRootS > 0 )
277  mPythia->init( blue, yell, mRootS, 0.0 );
278  else
279  mPythia->init( blue, yell, 0, mRootS );
280 
281  return 0;
282 }
283 // ----------------------------------------------------------------------------
284 int StarPythia8::Init3MOM( int blue, int yell )
285 {
286 
287  cout << "Initializing 3MOM: " << endl;
288  mBlueMomentum.Print();
289  mYellMomentum.Print();
290 
291 
292  mPythia -> init( blue, yell,
294  mYellMomentum.X(), mYellMomentum.Y(), mYellMomentum.Z() );
295 
296  return 0;
297 }
298 // ----------------------------------------------------------------------------
299 int StarPythia8::Init4MOM( int blue, int yell )
300 {
301  return Init3MOM( blue, yell );
302 }
303 // ----------------------------------------------------------------------------
304 int StarPythia8::Init5MOM( int blue, int yell )
305 {
306  return Init3MOM( blue, yell );
307 }
308 // ----------------------------------------------------------------------------
Double_t mRootS
CMS energy or incident beam momentum for fixed target collisions.
int Generate()
Generate one event.
static StarRandom & Instance()
Obtain the single instance of the random number generator.
Definition: StarRandom.cxx:87
TString mYell
Name of the yellow beam particle (-z)
Event record class tailored to PP kinematics.
TLorentzVector mYellMomentum
4-Momentum of the yellow beam
ABC for defining event generator interfaces.
Definition: StarGenerator.h:34
StarGenEvent * mEvent
Generated event.
void FillEP(StarGenEvent *event)
(Optional) Method to fill a DIS event
TLorentzVector mBlueMomentum
4-Momentum of the blue beam
Double_t flat() const
Return a random number uniformly distributed between 0 and 1.
Definition: StarRandom.cxx:68
End of run statistics for event generators.
Definition: StarGenStats.h:21
Base class for event records.
Definition: StarGenEvent.h:81
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
Event record class tailored to DIS kinemaics.
Definition: Stypes.h:40
TString mFrame
Frame of the collision, i.e. CMS, FIXT, 3MOM, 4MOM, 5MOM.
TString mBlue
Name of the blue beam particle (+z)
void FillPP(StarGenEvent *event)
(Optional) Method to fill a PP event
int Init()
Initialize the event generator.
Definition: StarPythia8.cxx:51
StarGenStats Stats()
Return end-of-run statistics.
void Set(const char *s)
Pass a string to Pythia8::Pythia::readString(), for user configuration.
Definition: StarPythia8.h:91