EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
e_starlight.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file e_starlight.cpp
1 
2 //
3 // Copyright 2017
4 //
5 // This file is part of estarlight.
6 //
7 // starlight is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // starlight is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with starlight. If not, see <http://www.gnu.org/licenses/>.
19 //
21 //
22 // File and Version Information:
23 // $Rev:: 263 $: revision of last commit
24 // $Author:: mlomnitz $: author of last commit
25 // $Date:: 02/28/2017 #$: date of last commit
26 //
27 // Description:
28 //
29 // Main interface for eSTARlight code inherited from STARlight
30 //
31 //
33 
34 
35 #include <iostream>
36 #include <fstream>
37 #include <cstdlib>
38 
39 #include "starlightconfig.h"
40 
41 #ifdef ENABLE_PYTHIA
42 #include "PythiaStarlight.h"
43 #endif
44 
45 #ifdef ENABLE_PYTHIA6
46 #include "starlightpythia.h"
47 #endif
48 
49 #include "reportingUtils.h"
50 #include "inputParameters.h"
51 #include "eventchannel.h"
52 #include "gammagammasingle.h"
53 #include "gammaavm.h"
54 #include "twophotonluminosity.h"
55 #include "gammaaluminosity.h"
56 #include "gammaeluminosity.h"
58 #include "e_starlight.h"
59 
60 
61 using namespace std;
62 using namespace starlightConstants;
63 
64 
66  _beamSystem (0),
67  _eventChannel (0),
68  _nmbEventsPerFile (100),
69  _isInitialised (false),
70  _inputParameters (0)
71 { }
72 
73 
75 { }
76 
77 
78 bool
80 {
81  // ???
82  if(Starlight_VERSION_MAJOR == 9999)
83  {
84  cout << endl << "#########################################" << endl
85  << " Initialising Starlight version: trunk..." << endl
86  << "#########################################" << endl << endl;
87  }
88  else
89  {
90  cout << endl << "#########################################" << endl
91  << " Initialising Starlight version: " << Starlight_VERSION_MAJOR << "."
92  << Starlight_VERSION_MINOR << "." << Starlight_VERSION_MINOR_MINOR << "..." << endl
93  << "#########################################" << endl << endl;
94  }
95 
96  _nmbEventsPerFile = _inputParameters->nmbEvents(); // for now we write only one file...
97 
99 
100  // This sets the precision used by cout for printing
101  cout.setf(ios_base::fixed,ios_base::floatfield);
102  cout.precision(3);
103 
104  std::string _baseFileName;
105  _baseFileName = _inputParameters->baseFileName();
106  _lumLookUpTableFileName = _baseFileName + ".txt";
107 
108  const bool lumTableIsValid = luminosityTableIsValid();
109 
110  // Do some sanity checks of the input parameters here.
111  if( _inputParameters->targetBeamA() == 0 ){
112  // printErr << endl << "One of the two beams must be an electron in eSTARlight" << endl;
113  return false;
114  }
115 
116  bool createChannel = true;
117  switch (_inputParameters->interactionType()) {
118  // Photon-photon scattering is not implemented in eSTARlight as of yet
119  /*
120  case PHOTONPHOTON:
121  if (!lumTableIsValid) {
122  printInfo << "creating luminosity table for photon-photon channel" << endl;
123  twoPhotonLuminosity(*_inputParameters, _beamSystem->beam1(), _beamSystem->beam2());
124  }
125  break;
126  */
127  case E_PHOTONPOMERONNARROW: // narrow and wide resonances use
128  case E_PHOTONPOMERONWIDE: // the same luminosity function
129  if (!lumTableIsValid) {
130  printInfo << "creating luminosity table for coherent photon-Pomeron channel" <<endl;
132  }
133  break;
134  // Incoherent electro-production is still pending
135  /* case PHOTONPOMERONINCOHERENT: // narrow and wide resonances use
136  if (!lumTableIsValid) {
137  printInfo << "creating luminosity table for incoherent photon-Pomeron channel" << endl;
138  incoherentPhotonNucleusLuminosity lum(*_inputParameters, *_beamSystem);
139  }
140  break;*/
141  default:
142  {
143  printWarn << "unknown interaction type '" << _inputParameters->interactionType() << "'."
144  << " cannot initialize eSTARlight." << endl;
145  return false;
146  }
147  }
148 
149  if(createChannel)
150  {
151  if (!createEventChannel())
152  return false;
153  }
154 
155  _isInitialised = true;
156  return true;
157 }
158 
159 
160 eXEvent
162 {
163  if (!_isInitialised) {
164  // printErr << "trying to generate event but Starlight is not initialised. aborting." << endl;
165  exit(-1);
166  }
167  return _eventChannel->e_produceEvent();
168 }
169 
170 
171 bool
173 {
174  printInfo << "using random seed = " << _inputParameters->randomSeed() << endl;
175 
176  ifstream lumLookUpTableFile(_lumLookUpTableFileName.c_str());
177  lumLookUpTableFile.precision(15);
178  if ((!lumLookUpTableFile) || (!lumLookUpTableFile.good())) {
179  return false;
180  }
181 
182  unsigned int targetBeamZ, targetBeamA;
183  double beamLorentzGamma = 0;
184  double maxW = 0, minW = 0;
185  unsigned int nmbWBins;
186  double maxRapidity = 0;
187  unsigned int nmbRapidityBins;
188  int productionMode, beamBreakupMode;
189  //Remove interference options for eX collisions (no logner symmetric)
190  // bool interferenceEnabled = false;
191  // double interferenceStrength = 0;
192  bool coherentProduction = false;
193  double incoherentFactor = 0, deuteronSlopePar = 0, maxPtInterference = 0;
194  int nmbPtBinsInterference;
195  std::string validationKey;
196  if (!(lumLookUpTableFile
197  >> validationKey
198  >> targetBeamZ >> targetBeamA
199  >> beamLorentzGamma
200  >> maxW >> minW >> nmbWBins
201  >> maxRapidity >> nmbRapidityBins
202  >> productionMode
203  >> beamBreakupMode
204  >> maxPtInterference
205  >> nmbPtBinsInterference
206  >> coherentProduction >> incoherentFactor
207  >> deuteronSlopePar))
208  // cannot read parameters from lookup table file
209  return false;
210 
211  std::string validationKeyEnd;
212  while(!lumLookUpTableFile.eof())
213  {
214  lumLookUpTableFile >> validationKeyEnd;
215  }
216  lumLookUpTableFile.close();
217  return (validationKey == _inputParameters->parameterValueKey() && validationKeyEnd == validationKey);
218  return true;
219 }
220 
221 
222 bool
224 {
225  switch (_inputParameters->prodParticleType()) {
226  case ELECTRON:
227  case MUON:
228  case TAUON:
229  case TAUONDECAY:
230  printWarn << "cannot construct Gammagammaleptonpair event channel." << endl;
231  return false;
232 
233  case A2: // jetset/pythia
234  case ETA: // jetset/pythia
235  case ETAPRIME: // jetset/pythia
236  case ETAC: // jetset/pythia
237  case F0: // jetset/pythia
238  {
239 
240  //#ifdef ENABLE_PYTHIA
241  // PythiaOutput = true;
242  // cout<<"Pythia is enabled!"<<endl;
243 // return true;
244 //#else
245 // printWarn << "Starlight is not compiled against Pythia8; "
246 // << "jetset event channel cannot be used." << endl;
247 // return false;
248 //#endif
249  }
250  case F2:
251  case F2PRIME:
252  case ZOVERZ03:
253  case AXION: // AXION HACK
254  {
255  // #ifdef ENABLE_PYTHIA
256  cout<<" This is f2, f2prim, rho^0 rho^0, or axion "<<endl;
258  if (_eventChannel)
259  return true;
260  else {
261  printWarn << "cannot construct Gammagammasingle event channel." << endl;
262  return false;
263  }
264  }
265  case RHO:
266  case RHOZEUS:
267  case FOURPRONG:
268  case OMEGA:
269  case OMEGA_pi0gamma:
270  case PHI:
271  case JPSI:
272  case JPSI2S:
273  case JPSI2S_ee:
274  case JPSI2S_mumu:
275  case JPSI_ee:
276  case JPSI_mumu:
277  case UPSILON:
278  case UPSILON_ee:
279  case UPSILON_mumu:
280  case UPSILON2S:
281  case UPSILON2S_ee:
282  case UPSILON2S_mumu:
283  case UPSILON3S:
284  case UPSILON3S_ee:
285  case UPSILON3S_mumu:
286  {
289  if (_eventChannel)
290  return true;
291  else {
292  printWarn << "cannot construct Gammaanarrowvm event channel." << endl;
293  return false;
294  }
295  }
296 
299  if (_eventChannel)
300  return true;
301  else {
302  printWarn << "cannot construct Gammaawidevm event channel." << endl;
303  return false;
304  }
305  }
306 
307 
308  printWarn << "interaction type '" << _inputParameters->interactionType() << "' "
309  << "cannot be used with particle type '" << _inputParameters->prodParticleType() << "'. "
310  << "cannot create event channel." << endl;
311  return false;
312  }
313  default:
314  {
315  printWarn << "unknown event channel '" << _inputParameters->prodParticleType() << "'."
316  << " cannot create event channel." << endl;
317  return false;
318  }
319  }
320 }