EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
e_starlightStandalone.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file e_starlightStandalone.cpp
1 
2 //
3 // Copyright 2010
4 //
5 // This file is part of starlight.
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:: 270 $: revision of last commit
24 // $Author:: jnystrand $: author of last commit
25 // $Date:: 2016-07-08 16:31:51 +0100 #$: date of last commit
26 //
27 // Description:
28 //
29 //
30 //
32 
33 
34 #include <iostream>
35 #include <chrono>
36 #include "reportingUtils.h"
37 #include "e_starlight.h"
38 #include "inputParameters.h"
39 #include "eventfilewriter.h"
40 #include "e_starlightStandalone.h"
41 
42 
43 using namespace std;
44 
45 
47  : _configFileName ("slight.in"),
48  _starlight (0),
49  _nmbEventsTot (1),
50  _nmbEventsPerFile (_nmbEventsTot)
51 { }
52 
53 
55 { }
56 
57 
58 bool
60 {
62  // read input parameters from config file
64  if (!_inputParameters->init()) {
65  printWarn << "problems initializing input parameters. cannot initialize starlight." << endl;
66  return false;
67  }
68 
69  // copy input file to one with baseFileName naming scheme
70  std::string inputCopyName, _baseFileName;
71  _baseFileName = _inputParameters->baseFileName();
72  if (_baseFileName != "slight") {
73  inputCopyName = _baseFileName +".in";
74 
75  ofstream inputCopyFile;
76  inputCopyFile.open(inputCopyName.c_str());
77 
78  std::ifstream infile(_configFileName.c_str());
79  if ((!infile) || (!infile.good()))
80  {
81  return -1;
82  }
83 
84  int lineSize = 256;
85  char tmp[lineSize];
86  while (!infile.getline(tmp, lineSize).eof())
87  {
88  cout << tmp << endl;
89  inputCopyFile << tmp << endl;
90  }
91  inputCopyFile.close();
92  }
93 
94  // get the number of events
95  // for now we write everything to one file
98 
99  // create the starlight object
100  _starlight = new e_starlight();
101 
102  // give starlight the input parameters
104 
105  // initialize starlight
106  return _starlight->init();
107 }
108 
109 
110 bool
112 {
113  if (!_starlight) {
114  printWarn << "null pointer to starlight object. make sure that init() was called. "
115  << "cannot generate events." << endl;
116  return false;
117  }
118 
119  // open output file
121  eventFileWriter fileWriterLUND;
126  fileWriter.open(_eventDataFileName);
127  //
128  fileWriter.writeInit(*_inputParameters);
129  //
131  fileWriterLUND.open("slight_LUND.txt");
132  //
133  fileWriterLUND.writeInitLUND(*_inputParameters);
134  //
135  }
136  printInfo << "generating events:" << endl;
137  unsigned int nmbEvents = 0;
138  std::chrono::steady_clock::time_point begin= std::chrono::steady_clock::now();
139  while (nmbEvents < _nmbEventsTot) {
140  for (unsigned int iEvent = 0; (iEvent < _nmbEventsPerFile) && (nmbEvents < _nmbEventsTot);
141  ++iEvent, ++nmbEvents) {
142  progressIndicator(iEvent, _nmbEventsTot, true, 4);
143  eXEvent event = _starlight->produceEvent();
144  // Boost event from back to lab reference frame
145  boostEvent(event);
146  reflectEvent(event);
147  fileWriter.writeEvent(event, iEvent);
149  fileWriterLUND.writeEventLUND(event, iEvent);
150  }
151  }
152  }
153  std::chrono::steady_clock::time_point end= std::chrono::steady_clock::now();
154  float running_total = 1E-3*std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count();
155  cout<<"Total time "<<running_total<<" s ("<<1E3*running_total/nmbEvents<<" ms/ev)"<<endl;
156  fileWriter.close();
158  fileWriterLUND.close();
159  }
160 
161  if( _starlight->nmbAttempts() == 0 )return true;
162 
163  double _branchingRatio = _inputParameters->inputBranchingRatio();
164  printInfo << "number of attempts = " << _starlight->nmbAttempts() << ", "
165  << "number of accepted events = " << _starlight->nmbAccepted() << endl;
166  double selectedCrossSection =
167  ((double)_starlight->nmbAccepted()/_starlight->nmbAttempts())*_branchingRatio*_starlight->getTotalCrossSection();
168  if (selectedCrossSection > 1.){
169  cout<< " The cross section of the generated sample is "<<selectedCrossSection<<" barn."<<endl;
170  } else if (1.E3*selectedCrossSection > 1.){
171  cout<< " The cross section of the generated sample is "<<1.E3*selectedCrossSection<<" mb."<<endl;
172  } else if (1.E6*selectedCrossSection > 1.){
173  cout<< " The cross section of the generated sample is "<<1.E6*selectedCrossSection<<" microbarn."<<endl;
174  } else if (1.E9*selectedCrossSection > 1.){
175  cout<< " The cross section of the generated sample is "<<1.E9*selectedCrossSection<<" nanobarn."<<endl;
176  } else if (1.E12*selectedCrossSection > 1.){
177  cout<< " The cross section of the generated sample is "<<1.E12*selectedCrossSection<<" picobarn."<<endl;
178  } else {
179  cout<< " The cross section of the generated sample is " <<1.E15*selectedCrossSection<<" femtob."<<endl;
180  }
181 
182  return true;
183 }
185 {
186 
187  // Calculate CMS boost
188  double rap2 = -acosh(_inputParameters->targetBeamLorentzGamma());
189  double boost = _inputParameters->rap_CM();
190  event.boost(boost, rap2); // Boost back to laboratory reference frame. Electron initially in target frame and V.M. in CMS
191  // Assuming electron is electronBeam
192 
193 
194 }
195 
196 
198 {
199  event.reflect(); //Change all z to -z
200 }