EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
readinluminosity.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file readinluminosity.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:: 265 $: revision of last commit
24 // $Author:: butter $: author of last commit
25 // $Date:: 2016-06-06 21:37:26 +0100 #$: date of last commit
26 //
27 // Description:
28 // Added 18->19 for reading in the luminosity table
29 // Incoherent factor added to table --Joey
30 //
31 //
32 //
34 
35 
36 #include <iostream>
37 #include <fstream>
38 
39 #include "readinluminosity.h"
40 #include "starlightconstants.h"
41 #include "inputParameters.h"
42 
43 using namespace std;
44 
45 
46 //______________________________________________________________________________
47 readLuminosity::readLuminosity(const inputParameters& inputParametersInstance)
48  : _Warray(0), _Yarray(0), _Farray(0), _Farray1(0), _Farray2(0),
49  _f_WYarray(0), _g_Earray(0)/*, _g_EQ2array(0)*/
50  , _ReadInputNPT(inputParametersInstance.nmbPtBinsInterference())
51  , _ReadInputnumy(inputParametersInstance.nmbRapidityBins())
52  , _ReadInputnumw(inputParametersInstance.nmbWBins())
53  , _ReadInputnumega(inputParametersInstance.nmbEnergyBins())
54  , _ReadInputnumQ2(inputParametersInstance.nmbGammaQ2Bins())
55  , _ReadInputgg_or_gP(inputParametersInstance.productionMode())
56  , _ReadInputinterferencemode(inputParametersInstance.interferenceEnabled())
57  , _baseFileName(inputParametersInstance.baseFileName())
58 {
59 
60 }
61 
62 
63 //______________________________________________________________________________
65 {
66  if(_Warray) delete [] _Warray;
67  if(_Yarray) delete [] _Yarray;
68  if(_Farray) delete [] _Farray;
69  if(_Farray1) delete [] _Farray1;
70  if(_Farray2) delete [] _Farray2;
71  // For eSTARLIGHT
72  if(_f_WYarray) delete [] _f_WYarray;
73  if(_g_Earray) delete [] _g_Earray;
74  if(_g_EQ2array) delete _g_EQ2array;
75 }
76 
77 
78 //______________________________________________________________________________
80 {
81 
82  if(!_Warray) _Warray = new double[_ReadInputnumw];
83  if(!_Yarray) _Yarray = new double[_ReadInputnumy];
84  if(!_Farray)
85  {
86  _Farray = new double*[_ReadInputnumw];
87  for(int i = 0; i < _ReadInputnumw; i++)
88  {
89  _Farray[i] = new double[_ReadInputnumy];
90  }
91  }
92  if(!_Farray1)
93  {
94  _Farray1 = new double*[_ReadInputnumw];
95  for(int i = 0; i < _ReadInputnumw; i++)
96  {
97  _Farray1[i] = new double[_ReadInputnumy];
98  }
99  }
100  if(!_Farray2)
101  {
102  _Farray2 = new double*[_ReadInputnumw];
103  for(int i = 0; i < _ReadInputnumw; i++)
104  {
105  _Farray2[i] = new double[_ReadInputnumy];
106  }
107  }
108 
109  double dummy[17]; //number of lines used to read in input parameters saved to lookup table[slight.txt].
110 
111 
112  std::string wyFileName;
113  wyFileName = _baseFileName +".txt";
114 
115 // cout << "wyFileName being read in" << wyFileName << endl;
116 
117  double fpart =0.;
118  double fptsum=0.;
119  ifstream wylumfile;
120 
121  _f_max=0.0;
122  _f_max1=0.0;
123  _f_max2=0.0;
124 
125  wylumfile.open(wyFileName.c_str());
126 
127  for(int i=0;i < 17;i++){
128  wylumfile >> dummy[i];
129  }
130  int A_1 = dummy[1];
131  int A_2 = dummy[3];
132 
133  for(int i=0;i<_ReadInputnumw;i++){
134  wylumfile >> _Warray[i];
135  }
136  for(int i=0;i<_ReadInputnumy;i++){
137  wylumfile >> _Yarray[i];
138  }
139 
140  if( (_ReadInputgg_or_gP == 1) || (A_2 == 1 && A_1 != 1) || (A_1 ==1 && A_2 != 1) ){
141  for(int i=0;i<_ReadInputnumw;i++){
142  for(int j=0;j<_ReadInputnumy;j++){
143  wylumfile >> _Farray[i][j];
144  if( _Farray[i][j] > _f_max ) _f_max=_Farray[i][j];
145  }
146  }
147  //Normalize farray
148  for(int i=0;i<_ReadInputnumw;i++){
149  for(int j=0;j<_ReadInputnumy;j++){
150  _Farray[i][j]=_Farray[i][j]/_f_max;
151  }
152  }
153  } else {
154  for(int i=0;i<_ReadInputnumw;i++){
155  for(int j=0;j<_ReadInputnumy;j++){
156  wylumfile >> _Farray1[i][j];
157  }
158  }
159  for(int i=0;i<_ReadInputnumw;i++){
160  for(int j=0;j<_ReadInputnumy;j++){
161  wylumfile >> _Farray2[i][j];
162  if( _Farray1[i][j] + _Farray2[i][j] > _f_max ) _f_max=(_Farray1[i][j] + _Farray2[i][j]);
163  }
164  }
165  //Normalize farray, farray1, farray2
166  for(int i=0;i<_ReadInputnumw;i++){
167  for(int j=0;j<_ReadInputnumy;j++){
168  _Farray1[i][j]=_Farray1[i][j]/_f_max;
169  _Farray2[i][j]=_Farray2[i][j]/_f_max;
170  _Farray[i][j]=_Farray1[i][j]+_Farray2[i][j];
171  }
172  }
173  }
174  wylumfile >> _bwnormsave;
175 
177  // only numy/2 y bins here, from 0 (not -ymax) to ymax
178  double **finterm = new double*[starlightLimits::MAXWBINS];
179  for (int i = 0; i < starlightLimits::MAXWBINS; i++) finterm[i] = new double[starlightLimits::MAXYBINS];
180  for (int i=0;i<_ReadInputnumy;i++) {
181  //fmax=0;
182  //we want to convert _fptarray to an integral array where fpt(i,j) is near 0, and fpt(j,NPT) ~1. This will facilitate a simple table loookup
183  fptsum=0.;
184  for (int j=0;j<_ReadInputNPT;j++) {
185  wylumfile >> fpart;
186  finterm[i][j] = fpart;
187  _fptarray[i][j]=0.;
188  fptsum=fptsum+fpart;
189  }
190  //convert array to integral
191  _fptarray[i][0]=finterm[i][0]/fptsum;
192  for (int j=1;j<_ReadInputNPT;j++) {
193  for (int k=0;k<j;k++) {
194  _fptarray[i][j]=_fptarray[i][j]+finterm[i][k];
195  }
196  _fptarray[i][j]=_fptarray[i][j]/fptsum;
197  }
198  }
199  delete [] finterm;
200 
201  }
202  wylumfile.close();
203  return;
204 }
205 
206 
207 //______________________________________________________________________________
209 {
210  if(!_Warray) _Warray = new double[_ReadInputnumw];
211  if(!_Yarray) _Yarray = new double[_ReadInputnumy];
212  if(!_BWarray) _BWarray = new double[_ReadInputnumw];
213  if(!_f_WYmax)
214  {
215  _f_WYarray = new double*[_ReadInputnumega];
216  for(int i = 0; i < _ReadInputnumega; i++)
217  {
218  _f_WYarray[i] = new double[_ReadInputnumQ2];
219  }
220  }
221  if(!_g_Earray)
222  {
223  _g_Earray = new double*[_ReadInputnumega];
224  for(int i = 0; i < _ReadInputnumega; i++)
225  {
226  _g_Earray[i] = new double[_ReadInputnumQ2];
227  }
228  }
229 
230  double dummy[13]; //number of lines used to read in input parameters saved to lookup table[slight.txt].
231 
232 
233  std::string wyFileName;
234  wyFileName = _baseFileName +".txt";
235 
236 // cout << "wyFileName being read in" << wyFileName << endl;
237 
238  ifstream wylumfile;
239 
240  _f_WYmax=0.0;
241  _g_Emax=0.0;
242 
243  wylumfile.open(wyFileName.c_str());
244 
245  for(int i=0;i < 13;i++){
246  wylumfile >> dummy[i];
247  }
248  int A_1 = dummy[1];
249  int A_2 = dummy[3];
250 
251  for(int i=0;i<_ReadInputnumw;i++){
252  wylumfile >> _Warray[i];
253  }
254  //No longer needed, can be removed later
255  for(int i=0;i<_ReadInputnumy;i++){
256  wylumfile >> _Yarray[i];
257  }
258 
259  //New table saving the Breit-Wigner function for form factor
260  double bw_max = 0 ;
261  for(int i=0;i<_ReadInputnumw;i++){
262  wylumfile >> _BWarray[i];
263  if( _BWarray[i] > bw_max )
264  bw_max = _BWarray[i];
265  }
266  for(int i=0;i<_ReadInputnumw;i++){
267  _BWarray[i] = _BWarray[i]/bw_max;
268  }
269 
270 
271  if( (A_2 == 0 && A_1 >= 1) || (A_1 ==0 && A_2 >= 1) ){
272  for(int i=0;i<_ReadInputnumega;i++){
273  for(int j=0;j<_ReadInputnumQ2;j++){
274  wylumfile >> _f_WYarray[i][j];
275  if( _f_WYarray[i][j] > _f_WYmax ) _f_WYmax=_f_WYarray[i][j];
276  //
277  //wylumfile >> _g_Earray[i][j];
278  //if( _g_Earray[i][j] > _g_Emax ) _g_Emax = _g_Earray[i][j];
279  }
280  }
281  //Normalize f_WY array, g does not need to be normalized, it is used for normalization
282  for(int i=0;i<_ReadInputnumega;i++){
283  for(int j=0;j<_ReadInputnumQ2;j++){
284  _f_WYarray[i][j] = _f_WYarray[i][j]/( _f_WYmax );
285  //_g_Earray[i][j] = _g_Earray[i][j]/_g_Emax;
286  }
287  }
288  }
289  wylumfile >> _bwnormsave;
290 
291  wylumfile.close();
292  cout<<"Done reading wylumi file"<<endl;
293  std::string EQ2FileName;
294  EQ2FileName = "e_"+_baseFileName+".txt";
295  ifstream EQlumfile;
296 
297  EQlumfile.open(EQ2FileName.c_str());
298  int n_steps;
299  EQlumfile >> n_steps;
300  double integrated_max = 0 ;
301  // _g_EQ2array = new map<string,std::vector<double> >();
302  _g_EQ2array = new vector< std::pair< double, vector<double> > > ();
303  while( !EQlumfile.eof() ){
304  _g_EQ2max = 0 ;
305  double integral;
306  std::vector<double> p;
307  for( int iQ2 = 0 ; iQ2 < _ReadInputnumQ2+3 ; ++iQ2){
308  if(iQ2 == 0 ){
309  EQlumfile >> integral;
310  if( integral > integrated_max)
311  integrated_max = integral;
312  }
313  else{
314  double temp;
315  EQlumfile >> temp;
316  p.push_back(temp);
317  //cout<<p[iQ2-1]<<endl;
318  }
319  if( iQ2 > 2 && p[iQ2-1] > _g_EQ2max){
320  _g_EQ2max = p[iQ2-1];
321  }
322  }
323  for( unsigned int iQ2=2; iQ2 < p.size(); ++iQ2)
324  p[iQ2] = p[iQ2]/_g_EQ2max;
325 
326  _g_EQ2array->push_back(std::pair< double, std::vector<double> >(integral,p));
327  }
328  for( std::vector< std::pair<double, std::vector<double> > >::iterator it =_g_EQ2array->begin() ; it != _g_EQ2array->end(); ++it){
329  //cout<<it->first<<endl;
330  it->first = it->first/integrated_max;
331  //cout<<"Now"<<it->first<<endl;
332  }
333 
334  //normalize
335  /*for( std::map<string,std::vector<double> >::iterator it =_g_EQ2array->begin() ; it != _g_EQ2array->end(); ++it){
336  std::string key = it->first;
337  if(key=="")
338  continue;
339  for(unsigned int iQ2=2; iQ2 < it->second.size(); ++iQ2)
340  it->second[iQ2] = it->second[iQ2]/_g_EQ2max;
341  }*/
342  EQlumfile.close();
343  return;
344 
345 }
346