StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StarPythia6.cxx
1 #include "StarPythia6.h"
2 ClassImp(StarPythia6);
3 
4 #include "StarCallf77.h"
5 #include "StarGenerator/EVENT/StarGenPPEvent.h"
6 #include "StarGenerator/EVENT/StarGenEPEvent.h"
7 #include "StarGenerator/EVENT/StarGenParticle.h"
8 
9 #include "StarGenerator/UTIL/StarRandom.h"
10 #include <map>
11 #include <iostream>
12 
13 #include "TGenericTable.h"
14 
15 StMaker *_maker = 0;
16 
17 TGenericTable *regtable( const Char_t *type, const Char_t *name, void *address )
18 {
19  TGenericTable *table = new TGenericTable(type,name);
20  table->Adopt( 1, address );
21  _maker -> AddData( table, ".const" );
22  return table;
23 };
24 
25 // ----------------------------------------------------------------------------
26 // Remap pythia's random number generator to StarRandom
27 extern "C" {
28  Double_t pyrstar_( Int_t *idummy ){ return StarRandom::Instance().flat(); };
29 };
30 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
33 StarPythia6::StarPythia6( const Char_t *name ) : StarGenerator(name)
34 {
35 
36  // Setup a map between pythia6 status codes and the HepMC status codes
37  // used in StarEvent
38  mStatusCode[0] = StarGenParticle::kNull;
39  mStatusCode[1] = StarGenParticle::kFinal;
40  const Int_t decays[] = { 2, 3, 4, 5, 11, 12, 13, 14, 15 };
41  for ( UInt_t i=0;i<sizeof(decays)/sizeof(Int_t); i++ )
42  {
43  mStatusCode[decays[i]]=StarGenParticle::kDecayed;
44  }
45  const Int_t docum[] = { 21, 31, 32, 41, 42, 51, 52 };
46  for ( UInt_t i=0;i<sizeof(docum)/sizeof(Int_t); i++ )
47  {
48  mStatusCode[docum[i]]=StarGenParticle::kDocumentation;
49  }
50 
51  _maker = this;
52 
53  regtable("PyJets_t", "pyjets", address_of_pyjets() );
54  regtable("PySubs_t", "pysubs", address_of_pysubs() );
55  regtable("PyDat1_t", "pydat1", address_of_pydat1() );
56  regtable("PyDat3_t", "pydat3", address_of_pydat3() );
57  regtable("PyPars_t", "pypars", address_of_pypars() );
58  regtable("PyInt5_t", "pyint5", address_of_pyint5() );
59 
60 }
61 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
64 void StarPythia6::PyTune( Int_t tune ){ ::PyTune(tune); }
65 void StarPythia6::PyStat( Int_t stat ){ ::PyStat(stat); }
66 void StarPythia6::PyList( Int_t list ){ ::PyList(list); }
67 void StarPythia6::PyGive( const char* give){ ::PyGive(give); }
68 
69 // ----------------------------------------------------------------------------
70 Int_t StarPythia6::Init()
71 {
72 
73  //
74  // Create a new event record for either pp or ep events
75  //
76  if ( mBlue == "proton" ) mEvent = new StarGenPPEvent();
77  else mEvent = new StarGenEPEvent();
78 
84  pydat3().mdcy(102,1)=0; // PI0 111
85  pydat3().mdcy(106,1)=0; // PI+ 211
86  pydat3().mdcy(109,1)=0; // ETA 221
87  pydat3().mdcy(116,1)=0; // K+ 321
88  pydat3().mdcy(112,1)=0; // K_SHORT 310
89  pydat3().mdcy(105,1)=0; // K_LONG 130
90  pydat3().mdcy(164,1)=0; // LAMBDA0 3122
91  pydat3().mdcy(167,1)=0; // SIGMA0 3212
92  pydat3().mdcy(162,1)=0; // SIGMA- 3112
93  pydat3().mdcy(169,1)=0; // SIGMA+ 3222
94  pydat3().mdcy(172,1)=0; // Xi- 3312
95  pydat3().mdcy(174,1)=0; // Xi0 3322
96  pydat3().mdcy(176,1)=0; // OMEGA- 3334
97 
98 
99  // Remap the ROOT names to pythia6 names
100  std::map< TString, string > particle;
101  particle["proton"]="p";
102  particle["e-"]="e-";
103 
104  // For frames other than CMS, we need to set the beam momenta in pyjets
105  if ( mFrame=="3MOM" || mFrame=="4MOM" || mFrame=="5MOM" )
106  {
107  for ( Int_t i=0;i<3;i++ ) pyjets().p(1,i+1) = mBlueMomentum[i];
108  for ( Int_t i=0;i<3;i++ ) pyjets().p(2,i+1) = mYellMomentum[i];
109  }
110  if ( mFrame=="4MOM" || mFrame=="5MOM" )
111  { Int_t i=3;
112  pyjets().p(1,i+1) = mBlueMomentum[i];
113  pyjets().p(2,i+1) = mYellMomentum[i];
114  }
115 
116 
117  // Initialize pythia
118  PyInit( mFrame.Data(), particle[mBlue], particle[mYell], mRootS );
119 
120  return StMaker::Init();
121 }
122 // ----------------------------------------------------------------------------
123 //
124 // ----------------------------------------------------------------------------
125 Int_t StarPythia6::Generate()
126 {
127 
128  // Generate the event
129  PyEvnt();
130 
131  // Blue beam is a proton, running PP
132  if ( mBlue == "proton" ) FillPP( mEvent );
133  // Otherwise, runnin EP
134  else FillEP( mEvent );
135 
136  // Loop over all particles in the event
137  mNumberOfParticles = pyjets().n;
138  for ( Int_t idx=1; idx<=mNumberOfParticles; idx++ )
139  {
140 
141  Int_t id = pyjets().k(idx,2);
142  Int_t stat = mStatusCode[ pyjets().k(idx,1) ];
143  if ( !stat ) {
145  }
146  Int_t m1 = pyjets().k(idx,3);
147  Int_t m2 = 0;
148  Int_t d1 = pyjets().k(idx,4);
149  Int_t d2 = pyjets().k(idx,5);
150  Double_t px = pyjets().p(idx,1);
151  Double_t py = pyjets().p(idx,2);
152  Double_t pz = pyjets().p(idx,3);
153  Double_t E = pyjets().p(idx,4);
154  Double_t M = pyjets().p(idx,5);
155  Double_t vx = pyjets().v(idx,1);
156  Double_t vy = pyjets().v(idx,2);
157  Double_t vz = pyjets().v(idx,3);
158  Double_t vt = pyjets().v(idx,4);
159 
160  mEvent -> AddParticle( stat, id, m1, m2, d1, d2, px, py, pz, E, M, vx, vy, vz, vt );
161 
162  }
163 
164  return kStOK;
165 }
166 // ----------------------------------------------------------------------------
167 //
168 // ----------------------------------------------------------------------------
169 void StarPythia6::FillPP( StarGenEvent *event )
170 {
171 
172  // Fill the event-wise information
173  StarGenPPEvent *myevent = (StarGenPPEvent *)event;
174 
175  myevent -> idBlue = pypars().msti(11);
176  myevent -> idYell = pypars().msti(12);
177  myevent -> process = pysubs().msel;
178  myevent -> subprocess = pypars().msti(1);
179 
180  myevent -> idParton1 = pypars().msti(15);
181  myevent -> idParton2 = pypars().msti(16);
182  myevent -> xParton1 = pypars().pari(31);
183  myevent -> xParton2 = pypars().pari(32);
184  myevent -> xPdf1 = 0;
185  myevent -> xPdf2 = 0;
186  myevent -> Q2fac = pypars().pari(22);
187  myevent -> Q2ren = 0.;
188  myevent -> valence1 = -1;
189  myevent -> valence2 = -1;
190 
191  myevent -> sHat = pypars().pari(14);
192  myevent -> tHat = pypars().pari(15);
193  myevent -> uHat = pypars().pari(16);
194  myevent -> ptHat = pypars().pari(17);
195  myevent -> thetaHat = TMath::ACos( pypars().pari(41) );
196  myevent -> phiHat = -999;
197 
198  myevent -> weight = pypars().pari(7);
199 
200  myevent -> mstu72 = pydat1().mstu(72);
201  myevent -> mstu73 = pydat1().mstu(73);
202 
203 }
204 // ----------------------------------------------------------------------------
205 //
206 // ----------------------------------------------------------------------------
207 void StarPythia6::FillEP( StarGenEvent *event )
208 {
209 
210  // Fill the event-wise information
211  StarGenEPEvent *myevent = (StarGenEPEvent *)event;
212 
213  myevent -> idBlue = pypars().msti(11);
214  myevent -> idYell = pypars().msti(12);
215  myevent -> process = pysubs().msel;
216  myevent -> subprocess = pypars().msti(1);
217 
218  // ID of the colliding parton. If MSTI(15) isn't a parton, grab MSTI(16)
219  Int_t id = pypars().msti(15);
220  Double_t x = pypars().pari(31);
221  if ( TMath::Abs(id)>6 ) { id = pypars().msti(16); x = pypars().pari(32); }
222  myevent -> idParton = id;
223  myevent -> xParton = x;
224 
225  myevent -> xPdf = 0;
226 
227  myevent -> Q2 = pypars().pari(22);
228  myevent -> weight = pypars().pari(7);
229 
230 }
231 
233 {
234  StarGenStats stats("Pythia6Stats","Pythia 6 Run Statistics");
235  PyStat(1);
236 
237  stats.nTried = pyint5().ngen(0,1);
238  stats.nSelected = pyint5().ngen(0,2);
239  stats.nAccepted = pyint5().ngen(0,3);
240  stats.sigmaGen = pyint5().xsec(0,3); //xsection
241  // ... we may want to extend StarGenStats to add these, if they are useful ...
242  // stats.xxxxxxxx = pyint5().xsec(0,1); //estimated maximum differential cross section
243  // stats.xxxxxxxxxxxx = pyint5().xsec(0,2); //gives the sum of differential cross sections phase-space points evaluated so far
244 
245  stats.nFilterSeen = stats.nAccepted;
246  stats.nFilterAccept = stats.nAccepted;
247 
248  //stats.Dump();
249 
250  // Return a copy of the class we just created
251  return stats;
252 }
253 
254 void StarPythia6::SetDecayFlag ( const int kf, const int flagw )
255 {
256  int kc = PyComp( kf );
257  if ( kc ) {
258  pydat3().mdcy(kc,1)=0;
259  }
260  else {
261  LOG_WARN << "Incorrect kf = " << kf << endm;
262  }
263 
264 }
void FillEP(StarGenEvent *event)
(Optional) Method to fill a DIS event
void PyTune(Int_t tune)
Calls the pytune function.
Definition: StarPythia6.cxx:44
Double_t mRootS
CMS energy or incident beam momentum for fixed target collisions.
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)
PyDat3_t & pydat3()
Returns a reference to the /PYDAT3/ common block.
Definition: StarPythia6.h:65
Event record class tailored to PP kinematics.
static void SetDecayFlag(const int kf, const int flag)
TLorentzVector mYellMomentum
4-Momentum of the yellow beam
ABC for defining event generator interfaces.
Definition: StarGenerator.h:34
StarGenEvent * mEvent
Generated event.
void FillPP(StarGenEvent *event)
(Optional) Method to fill a PP event
Int_t Init()
Definition: StarPythia6.cxx:49
Int_t Generate()
PyInt5_t & pyint5()
Returns a reference to the /PYINT5/ common block.
Definition: StarPythia6.h:69
void PyStat(Int_t stat)
Calls the pystat function.
Definition: StarPythia6.cxx:45
TLorentzVector mBlueMomentum
4-Momentum of the blue beam
PyDat1_t & pydat1()
Returns a reference to the /PYDAT1/ common block.
Definition: StarPythia6.h:63
PySubs_t & pysubs()
Returns a reference to the /PYSUBS/ common block.
Definition: StarPythia6.h:61
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
StarGenStats Stats()
Create and retrieve end-of-run statistics.
PyJets_t & pyjets()
Returns a reference to the /PYJETS/ common block.
Definition: StarPythia6.h:59
Base class for event records.
Definition: StarGenEvent.h:81
Interface to pythia 6.
Definition: StarPythia6.h:48
static void PyGive(const char *give)
Calls the pygive function.
Definition: StarPythia6.cxx:67
Event record class tailored to DIS kinemaics.
Definition: Stypes.h:40
PyPars_t & pypars()
Returns a reference to the /PYPARS/ common block.
Definition: StarPythia6.h:67
TString mFrame
Frame of the collision, i.e. CMS, FIXT, 3MOM, 4MOM, 5MOM.
TString mBlue
Name of the blue beam particle (+z)
void PyList(Int_t list)
Calls the pylist function.
Definition: StarPythia6.cxx:46
virtual void Adopt(Int_t n, void *array)
Definition: TTable.cxx:1107