EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
inputParameters.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file inputParameters.h
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:: 276 $: revision of last commit
24 // $Author:: jnystrand $: author of last commit
25 // $Date:: 2016-09-13 19:54:42 +0100 #$: date of last commit
26 //
27 // Description:
28 //
29 //
30 //
32 
33 
34 #ifndef INPUTPARAMETERS_H
35 #define INPUTPARAMETERS_H
36 
37 
38 #include "starlightconstants.h"
39 #include "inputParser.h"
40 #include <string>
41 #include <ostream>
42 #include <vector>
43 #include <sstream>
44 
45 class parameterbase;
46 
47 
49 {
50 public:
51 
53 
54  void add(parameterbase* p) {
55  _parameters.push_back(p);
56  }
57 
58  // Returns a string with a key of the current state of the parameter list
59  // only
60  inline std::string validationKey();
61 
62 
63 private:
64 
65  std::vector<parameterbase*> _parameters;
66 
67 };
68 
69 // Base class for parameters, needed to keep a list of parameters
71 {
72 public:
73 
74  // Add this to parameter list
76  {
77  _parameters.add(this);
78  }
79  virtual std::string validationkey() = 0;
80 
81  template<typename T>
82  std::string toString(T v)
83  {
84  std::stringstream s;
85  s << v;
86  return s.str();
87  }
88  inline friend std::ostream& operator<<(std::ostream& os, const parameterbase& par);
89 
90  // List of all parameters
92 
93 
94 
95 };
96 // Need to init the static variable
97 // parameterlist parameterbase::_parameters;
98 
99 
100 // The actual parameter class
101 // validate parameter specifies if the parameter should be a part of the validity check of the current parameters
102 template<typename T, bool validate>
103 class parameter : public parameterbase
104 {
105 public:
106 
107  // Constructor
108  parameter(const std::string &name, T value, bool required = true) :parameterbase(),_name(name), _value(value), _validate(validate), _required(required) {}
109 
110 
111  parameter &operator=(T v) { _value = v; return *this;}
112  T* ptr() const {
113  return const_cast<T*>(&_value);
114  }
115 
116  T value() const { return _value; }
117 
118  std::string name() const { return _name;}
119 
120  bool required() const { return _required; }
121 
122  void setValue(T v) { _value = v; }
123 
124  void setName(std::string name) { _name = name; }
125 
126  void setRequired(bool r) { _required = r; }
127 
128  // Validation key for this parameter
129  std::string validationkey()
130  {
131  return (_validate ? _name + ":" + toString(_value) + "-" : std::string(""));
132  }
133 
134  template<typename S, bool v>
135  inline friend std::ostream& operator<<(std::ostream& os, const parameter<S,v>& par);
136 
137 
138 
139 private:
140  std::string _name;
141 
142  T _value; // Value
143  bool _validate; // true if a change in the parameter invalidates x-sec tables
144  bool _required; // true if this is required option.
145 
146  parameter();
147 };
148 
149 template<typename S, bool v>
150 inline std::ostream& operator<<(std::ostream& os, const parameter<S,v>& par)
151 {
152  os << par._value;
153  return os;
154 }
155 
156 std::ostream& operator<<(std::ostream& os, const parameterbase& par)
157 {
158  os << par._parameters.validationKey();
159  return os;
160 }
162 {
163  std::stringstream s;
164  for(unsigned int i = 0; i < _parameters.size(); ++i)
165  {
166  s << _parameters[i]->validationkey(); // Will print names and values of validation parameters
167  }
168  return s.str();
169 }
170 
172 
173 public:
174  inputParameters();
176 
177  bool init();
178  bool configureFromFile(const std::string &configFileName = "./config/slight.in");
179 
180  std::string baseFileName () const { return _baseFileName.value(); }
181 
182  int targetBeamZ () const { return _targetBeamZ.value(); }
183  unsigned int targetBeamA () const { return _targetBeamA.value(); }
184  double targetLorentzGamma () const { return _targetLorentzGamma; }
185  double beamLorentzGamma () const { return _beamLorentzGamma; }
187  double targetBeamLorentzGamma () const { return _targetBeamLorentzGamma.value(); }
188  double rap_CM () const { return _rap_CM; }
189  double targetMaxPhotonEnergy () const { return _targetMaxPhotonEnergy; }
190  double cmsMaxPhotonEnergy () const { return _cmsMaxPhotonEnergy; }
191  double targetMinPhotonEnergy () const { return _targetMinPhotonEnergy; }
192  double cmsMinPhotonEnergy () const { return _cmsMinPhotonEnergy; }
193  double maxW () const { return _maxW.value(); }
194  double minW () const { return _minW.value(); }
195  double maxW_GP () const { return _maxW_GP.value(); }
196  double minW_GP () const { return _minW_GP.value(); }
197  unsigned int nmbWBins () const { return _nmbWBins.value(); }
198  double maxRapidity () const { return _maxRapidity.value(); }
199  unsigned int nmbRapidityBins () const { return _nmbRapidityBins.value(); }
200  unsigned int nmbEnergyBins () const { return _nmbEnergyBins.value(); }
201  bool ptCutEnabled () const { return _ptCutEnabled.value(); }
202  double ptCutMin () const { return _ptCutMin.value(); }
203  double ptCutMax () const { return _ptCutMax.value(); }
204  bool etaCutEnabled () const { return _etaCutEnabled.value(); }
205  double etaCutMin () const { return _etaCutMin.value(); }
206  double etaCutMax () const { return _etaCutMax.value(); }
207  int productionMode () const { return _productionMode.value(); }
208  unsigned int nmbEvents () const { return _nmbEventsTot.value(); }
209  int prodParticleId () const { return _prodParticleId.value(); }
210  int randomSeed () const { return _randomSeed.value(); }
211  int beamBreakupMode () const { return _beamBreakupMode.value(); }
212  bool interferenceEnabled () const { return _interferenceEnabled.value(); }
213  double interferenceStrength () const { return _interferenceStrength.value(); }
214  double maxPtInterference () const { return _maxPtInterference.value(); }
217  double minGammaEnergy () const { return _minGammaEnergy.value(); }
218  double maxGammaEnergy () const { return _maxGammaEnergy.value(); }
219  double minGammaQ2 () const { return _minGammaQ2.value(); }
220  double maxGammaQ2 () const { return _maxGammaQ2.value(); }
221  bool fixedQ2Range () const { return _fixedQ2Range; }
222  unsigned int nmbGammaQ2Bins () const { return _nmbGammaQ2Bins.value(); }
223  std::string pythiaParams () const { return _pythiaParams.value(); }
224  bool defaultFullEventRecord() const { bool a; _outputFormat.value()==0 ? a=true : a=false; return a;}
225  bool pythiaFullEventRecord () const { bool a; _outputFormat.value()==1 ? a=true : a=false; return a;}
226  bool hepmc3FullEventRecord () const { bool a; _outputFormat.value()==2 ? a=true : a=false; return a;}
227  bool lundFullEventRecord () const { bool a; _outputFormat.value()==3 ? a=true : a=false; return a;}
228  int outputFormat () const { return _outputFormat.value(); }
229  bool backwardsProduction () const { return _backwardsProduction.value(); }
230  int xsecCalcMethod () const { return _xsecCalcMethod.value(); }
231  double axionMass () const { return _axionMass.value(); }
232  int bslopeDefinition () const { return _bslopeDefinition.value(); }
233  double bslopeValue () const { return _bslopeValue.value(); }
234  int impulseVM () const { return _impulseVM.value(); }
235  int quantumGlauber () const { return _quantumGlauber.value(); }
239  double protonEnergy () const { return _protonEnergy.value(); }
240  double electronEnergy () const { return _electronEnergy.value(); }
241  double inputBranchingRatio () const { return _inputBranchingRatio; }
242  double targetRadius () const { return _targetR; }
243 
244  void setBaseFileName (std::string v ) { _baseFileName = v; }
245  void setTargetBeamZ (unsigned int v) { _targetBeamZ = v; }
246  void setTargetBeamA (unsigned int v) { _targetBeamA = v; }
248  void setBeamLorentzGamma (double v) { _beamLorentzGamma = v; }
250  void setRapCM (double v) { _rap_CM = v; }
251  //void setMaxPhotonEnergy (double v) { _maxPhotonEnergy = v ; } ///< sets maximim photon energy
252  void setMaxW (double v) { _maxW = v; }
253  void setMinW (double v) { _minW = v; }
254  void setmaxW_GP (double v) { _maxW_GP = v; }
255  void setminW_GP (double v) { _minW_GP = v; }
256  void setNmbWBins (unsigned int v) { _nmbWBins = v; }
257  void setMaxRapidity (double v) { _maxRapidity = v; }
258  void setNmbRapidityBins (unsigned int v) { _nmbRapidityBins = v; }
259  void setNmbEgaBins (unsigned int v) { _nmbEnergyBins = v; }
260  void setPtCutEnabled (bool v) { _ptCutEnabled = v; }
261  void setPtCutMin (double v) { _ptCutMin = v; }
262  void setPtCutMax (double v) { _ptCutMax = v; }
263  void setEtaCutEnabled (bool v) { _etaCutEnabled = v; }
264  void setEtaCutMin (double v) { _etaCutMin = v; }
265  void setEtaCutMax (double v) { _etaCutMax = v; }
267  void setNmbEvents (unsigned int v) { _nmbEventsTot = v; }
269  void setRandomSeed (int v) { _randomSeed = v; }
276  void setMinGammaEnergy (double v) { _minGammaEnergy = v; }
277  void setMaxGammaEnergy (double v) { _maxGammaEnergy = v; }
278  void setMinGammaQ2 (double v) { _minGammaQ2 = v; }
279  void setMaxGammaQ2 (double v) { _maxGammaQ2 = v; }
280  void setPythiaParams (std::string v) { _pythiaParams = v; }
281  void setOutputFormat (int v) { _outputFormat = v; }
284  void setAxionMass (double v) { _axionMass = v; }
286  void setbslopeValue (double v) { _bslopeValue = v; }
287  void setimpulseVM (int v) { _impulseVM = v; }
289 
293 
294  void setProtonEnergy (double v) { _protonEnergy = v; }
295  void setElectronEnergy (double v) { _electronEnergy = v; }
296  template<typename T>
297  inline bool setParameter(std::string expression);
298 
299  std::ostream& print(std::ostream& out) const;
300  std::ostream& write(std::ostream& out) const;
301 
302  std::string parameterValueKey() const;
303 
304 
305 private:
306 
307 
308 // To indicate if the crossection table should be re-calculated if parameter changes
309 #define VALIDITY_CHECK true
310 #define NO_VALIDITY_CHECK false
311 
312  std::string _configFileName;
313 
314  // config file parameters
335 
336 
337 
338 
342 
343 
344 
345 
347 
348 
349 
350 
351 
352 
366  //parameter<bool, NO_VALIDITY_CHECK> _pythiaFullEventRecord; ///< if the full pythia event record should be in the output
367  //parameter<bool, NO_VALIDITY_CHECK> _hepmc3FullEventRecord; ///< if the full hepmc3 event record should be in the output
368  //parameter<bool, NO_VALIDITY_CHECK> _lundFullEventRecord; ///< if the full lund event record should be in the output
377 
381 
384  double _rap_CM;
385  double _targetR;
393 
394 };
395 
396 
397 template<typename T>
398 inline
399 bool inputParameters::setParameter(std::string expression)
400 {
401 
402  return _ip.parseString(expression);
403 
404 
405 }
406 
407 inline
408 std::ostream&
409 operator <<(std::ostream& out,
410  const inputParameters& par)
411 {
412  return par.print(out);
413 }
414 
415 
416 #endif // INPUTPARAMETERS_H