]>
Commit | Line | Data |
---|---|---|
da32329d AM |
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 | // | |
20 | /////////////////////////////////////////////////////////////////////////// | |
21 | // | |
22 | // File and Version Information: | |
0e1bd874 | 23 | // $Rev:: 181 $: revision of last commit |
24 | // $Author:: jnystrand $: author of last commit | |
25 | // $Date:: 2014-09-12 00:37:55 +0200 #$: date of last commit | |
da32329d AM |
26 | // |
27 | // Description: | |
28 | // | |
29 | // | |
30 | // | |
31 | /////////////////////////////////////////////////////////////////////////// | |
32 | ||
33 | ||
34 | #ifndef INPUTPARAMETERS_H | |
35 | #define INPUTPARAMETERS_H | |
36 | ||
37 | ||
38 | #include "starlightconstants.h" | |
39 | #include "inputParser.h" | |
40 | #include "singleton.h" | |
41 | #include <string> | |
42 | #include <ostream> | |
43 | #include <vector> | |
44 | #include <sstream> | |
45 | ||
46 | class parameterbase; | |
47 | ||
48 | ||
49 | class parameterlist | |
50 | { | |
51 | public: | |
52 | ||
53 | parameterlist() : _parameters(0) {} | |
54 | ||
55 | void add(parameterbase* p) { | |
56 | _parameters.push_back(p); | |
57 | } | |
58 | ||
59 | // Returns a string with a key of the current state of the parameter list | |
60 | // only | |
61 | inline std::string validationKey(); | |
62 | ||
63 | ||
64 | private: | |
65 | ||
66 | std::vector<parameterbase*> _parameters; | |
67 | ||
68 | }; | |
69 | ||
70 | // Base class for parameters, needed to keep a list of parameters | |
71 | class parameterbase | |
72 | { | |
73 | public: | |
74 | ||
75 | // Add this to parameter list | |
76 | parameterbase() | |
77 | { | |
78 | _parameters.add(this); | |
79 | } | |
80 | virtual ~parameterbase() {} | |
0e1bd874 | 81 | |
da32329d AM |
82 | virtual std::string validationkey() = 0; |
83 | ||
84 | template<typename T> | |
85 | std::string toString(T v) | |
86 | { | |
87 | std::stringstream s; | |
88 | s << v; | |
89 | return s.str(); | |
90 | } | |
91 | inline friend std::ostream& operator<<(std::ostream& os, const parameterbase& par); | |
92 | ||
93 | // List of all parameters | |
94 | static parameterlist _parameters; | |
95 | ||
96 | ||
97 | ||
98 | }; | |
99 | // Need to init the static variable | |
100 | // parameterlist parameterbase::_parameters; | |
101 | ||
102 | ||
103 | // The actual parameter class | |
104 | // validate parameter specifies if the parameter should be a part of the validity check of the current parameters | |
105 | template<typename T, bool validate> | |
106 | class parameter : public parameterbase | |
107 | { | |
108 | public: | |
109 | ||
45d54d9a | 110 | // Constructor |
0e1bd874 | 111 | parameter(const std::string &name, T value, bool required = true) :parameterbase(),_name(name), _value(value), _validate(validate), _required(required) {} |
45d54d9a | 112 | |
0e1bd874 | 113 | virtual ~parameter() {} |
da32329d AM |
114 | // T operator()() const { |
115 | // return _value; | |
116 | // } | |
117 | ||
118 | parameter &operator=(T v) { _value = v; return *this;} | |
119 | T* ptr() const { | |
120 | return const_cast<T*>(&_value); | |
121 | } | |
122 | ||
123 | T value() const { return _value; } | |
124 | ||
125 | std::string name() const { return _name;} | |
126 | ||
127 | bool required() const { return _required; } | |
128 | ||
129 | void setValue(T v) { _value = v; } | |
130 | ||
0e1bd874 | 131 | void setName(std::string name) { _name = name; } |
da32329d AM |
132 | |
133 | void setRequired(bool r) { _required = r; } | |
134 | ||
135 | // Validation key for this parameter | |
136 | std::string validationkey() | |
137 | { | |
138 | return (_validate ? _name + ":" + toString(_value) + "-" : std::string("")); | |
139 | } | |
140 | ||
141 | template<typename S, bool v> | |
b48ced01 | 142 | friend std::ostream& operator<<(std::ostream& os, const parameter<S,v>& par); |
da32329d AM |
143 | |
144 | ||
145 | ||
146 | private: | |
147 | std::string _name; | |
148 | ||
149 | T _value; // Value | |
150 | bool _validate; // true if a change in the parameter invalidates x-sec tables | |
151 | bool _required; // true if this is required option. | |
152 | ||
153 | parameter(); | |
154 | }; | |
155 | ||
156 | template<typename S, bool v> | |
157 | std::ostream& operator<<(std::ostream& os, const parameter<S,v>& par) | |
158 | { | |
159 | os << par._value; | |
160 | return os; | |
161 | } | |
162 | ||
163 | std::ostream& operator<<(std::ostream& os, const parameterbase& par) | |
164 | { | |
165 | os << par._parameters.validationKey(); | |
166 | return os; | |
167 | } | |
168 | std::string parameterlist::validationKey() | |
169 | { | |
170 | std::stringstream s; | |
171 | for(unsigned int i = 0; i < _parameters.size(); ++i) | |
172 | { | |
173 | s << _parameters[i]->validationkey(); // Will print names and values of validation parameters | |
174 | } | |
175 | return s.str(); | |
176 | } | |
177 | ||
178 | class inputParameters { | |
179 | ||
180 | private: | |
181 | // inputParameters is now a singleton | |
182 | friend class Singleton<inputParameters>; | |
a2de4243 | 183 | inputParameters(); |
a2de4243 | 184 | public: |
da32329d | 185 | |
0e1bd874 | 186 | ~inputParameters(); |
187 | ||
da32329d AM |
188 | bool init(); |
189 | bool configureFromFile(const std::string &configFileName = "./config/slight.in"); | |
190 | ||
191 | unsigned int beam1Z () const { return _beam1Z.value(); } ///< returns atomic number of beam particle 1 | |
192 | unsigned int beam1A () const { return _beam1A.value(); } ///< returns atomic mass number of beam particle 1 | |
193 | unsigned int beam2Z () const { return _beam2Z.value(); } ///< returns atomic number of beam particle 2 | |
194 | unsigned int beam2A () const { return _beam2A.value(); } ///< returns atomic mass number of beam particle 2 | |
45d54d9a | 195 | double beamLorentzGamma () const { return _beamLorentzGamma; } ///< returns Lorentz gamma factor of both beams in beam CMS frame |
da32329d AM |
196 | double beam1LorentzGamma () const { return _beam1LorentzGamma.value(); } ///< returns Lorentz gamma factor of beam 1 in collider frame |
197 | double beam2LorentzGamma () const { return _beam2LorentzGamma.value(); } ///< returns Lorentz gamma factor of beam 2 in collider frame | |
198 | double maxW () const { return _maxW.value(); } ///< returns maximum mass W of produced hadronic system [GeV/c^2] | |
199 | double minW () const { return _minW.value(); } ///< returns minimum mass W of produced hadronic system [GeV/c^2] | |
200 | unsigned int nmbWBins () const { return _nmbWBins.value(); } ///< returns number of W bins in lookup table | |
201 | double maxRapidity () const { return _maxRapidity.value(); } ///< returns maximum absolute value of rapidity | |
202 | unsigned int nmbRapidityBins () const { return _nmbRapidityBins.value(); } ///< returns number of rapidity bins in lookup table | |
203 | bool ptCutEnabled () const { return _ptCutEnabled.value(); } ///< returns cut in pt | |
204 | double ptCutMin () const { return _ptCutMin.value(); } ///< returns minimum pt | |
205 | double ptCutMax () const { return _ptCutMax.value(); } ///< returns maximum pt | |
206 | bool etaCutEnabled () const { return _etaCutEnabled.value(); } ///< returns cut in eta | |
207 | double etaCutMin () const { return _etaCutMin.value(); } ///< returns minimum eta | |
208 | double etaCutMax () const { return _etaCutMax.value(); } ///< returns maximum eta | |
209 | int productionMode () const { return _productionMode.value(); } ///< returns production mode | |
210 | unsigned int nmbEvents () const { return _nmbEventsTot.value(); } ///< returns total number of events to generate | |
211 | int prodParticleId () const { return _prodParticleId.value(); } ///< returns PDG particle ID of produced particle | |
212 | int randomSeed () const { return _randomSeed.value(); } ///< returns seed for random number generator | |
da32329d AM |
213 | int beamBreakupMode () const { return _beamBreakupMode.value(); } ///< returns breakup mode for beam particles |
214 | bool interferenceEnabled () const { return _interferenceEnabled.value(); } ///< returns whether interference is taken into account | |
215 | double interferenceStrength () const { return _interferenceStrength.value(); } ///< returns percentage of interference | |
da32329d AM |
216 | double maxPtInterference () const { return _maxPtInterference.value(); } ///< returns maximum p_T for interference calculation [GeV/c] |
217 | int nmbPtBinsInterference () const { return _nmbPtBinsInterference.value(); } ///< returns number of p_T bins for interference calculation | |
218 | double ptBinWidthInterference() const { return _ptBinWidthInterference.value(); } ///< returns width of p_T bins for interference calculation [GeV/c] | |
45d54d9a | 219 | bool coherentProduction () const { return _coherentProduction.value(); } ///< returns whether production is coherent or incoherent |
220 | double incoherentFactor () const { return _incoherentFactor.value(); } ///< returns incoherent contribution in vector meson production | |
da32329d AM |
221 | double minGammaEnergy () const { return _minGammaEnergy.value(); } ///< returns minimum gamma energy in case of photo nuclear processes [GeV] |
222 | double maxGammaEnergy () const { return _maxGammaEnergy.value(); } ///< returns maximum gamma energy in case of photo nuclear processes [GeV] | |
223 | std::string pythiaParams () const { return _pythiaParams.value(); } ///< returns parameters to be passed to pythia | |
224 | bool pythiaFullEventRecord () const { return _pythiaFullEventRecord.value(); } ///< returns if the full pythia event record should be printed | |
225 | int xsecCalcMethod () const { return _xsecCalcMethod.value(); } ///< returns the method used for the x-sec calculation | |
da32329d AM |
226 | starlightConstants::particleTypeEnum prodParticleType () const { return _particleType; } ///< returns type of produced particle |
227 | starlightConstants::decayTypeEnum prodParticleDecayType() const { return _decayType; } ///< returns decay type of produced particle | |
228 | starlightConstants::interactionTypeEnum interactionType () const { return _interactionType; } ///< returns interaction type | |
229 | // double vmPhotonCoupling(); | |
230 | // double slopeParameter(); | |
231 | double protonEnergy () const { return _protonEnergy.value(); } | |
232 | ||
233 | void setBeam1Z (unsigned int v) { _beam1Z = v; } ///< returns atomic number of beam particle 1 | |
234 | void setBeam1A (unsigned int v) { _beam1A = v; } ///< returns atomic mass number of beam particle 1 | |
235 | void setBeam2Z (unsigned int v) { _beam2Z = v; } ///< returns atomic number of beam particle 2 | |
236 | void setBeam2A (unsigned int v) { _beam2A = v; } ///< returns atomic mass number of beam particle 2 | |
237 | void setBeamLorentzGamma (double v) { _beamLorentzGamma = v; } ///< returns Lorentz gamma factor of both beams in beam CMS frame | |
238 | void setBeam1LorentzGamma (double v) { _beam1LorentzGamma = v; } ///< returns Lorentz gamma factor of beam 1 in collider frame | |
239 | void setBeam2LorentzGamma (double v) { _beam2LorentzGamma = v; } ///< returns Lorentz gamma factor of beam 2 in collider frame | |
240 | void setMaxW (double v) { _maxW = v; } ///< returns maximum mass W of produced hadronic system [GeV/c^2] | |
241 | void setMinW (double v) { _minW = v; } ///< returns minimum mass W of produced hadronic system [GeV/c^2] | |
242 | void setNmbWBins (unsigned int v) { _nmbWBins = v; } ///< returns number of W bins in lookup table | |
243 | void setMaxRapidity (double v) { _maxRapidity = v; } ///< returns maximum absolute value of rapidity | |
244 | void setNmbRapidityBins (unsigned int v) { _nmbRapidityBins = v; } ///< returns number of rapidity bins in lookup table | |
245 | void setPtCutEnabled (bool v) { _ptCutEnabled = v; } ///< returns cut in pt | |
246 | void setPtCutMin (double v) { _ptCutMin = v; } ///< returns minimum pt | |
247 | void setPtCutMax (double v) { _ptCutMax = v; } ///< returns maximum pt | |
248 | void setEtaCutEnabled (bool v) { _etaCutEnabled = v; } ///< returns cut in eta | |
249 | void setEtaCutMin (double v) { _etaCutMin = v; } ///< returns minimum eta | |
250 | void setEtaCutMax (double v) { _etaCutMax = v; } ///< returns maximum eta | |
251 | void setProductionMode (int v) { _productionMode = v; } ///< returns production mode | |
252 | void setNmbEvents (unsigned int v) { _nmbEventsTot = v; } ///< returns total number of events to generate | |
253 | void setProdParticleId (int v) { _prodParticleId = v; } ///< returns PDG particle ID of produced particle | |
254 | void setRandomSeed (int v) { _randomSeed = v; } ///< returns seed for random number generator | |
da32329d AM |
255 | void setBeamBreakupMode (int v) { _beamBreakupMode = v; } ///< returns breakup mode for beam particles |
256 | void setInterferenceEnabled (bool v) { _interferenceEnabled = v; } ///< returns whether interference is taken into account | |
257 | void setInterferenceStrength (double v) { _interferenceStrength = v; } ///< returns percentage of interference | |
da32329d AM |
258 | void setMaxPtInterference (double v) { _maxPtInterference = v; } ///< returns maximum p_T for voiderference calculation [GeV/c] |
259 | void setNmbPtBinsInterference (int v) { _nmbPtBinsInterference = v; } ///< returns number of p_T bins for interference calculation | |
260 | void setPtBinWidthInterference(double v) { _ptBinWidthInterference = v; } ///< returns width of p_T bins for voiderference calculation [GeV/c] | |
45d54d9a | 261 | void setCoherentProduction (bool v) { _coherentProduction = v; } ///< returns whether production is coherent or incoherent |
262 | void setIncoherentFactor (double v) { _incoherentFactor = v; } ///< returns incoherent contribution in vector meson production | |
da32329d AM |
263 | void setMinGammaEnergy (double v) { _minGammaEnergy = v; } ///< returns minimum gamma energy in case of photo nuclear processes [GeV] |
264 | void setMaxGammaEnergy (double v) { _maxGammaEnergy = v; } ///< returns maximum gamma energy in case of photo nuclear processes [GeV] | |
265 | void setPythiaParams (std::string v) { _pythiaParams = v; } ///< returns parameters to be passed to pythia | |
266 | void setPythiaFullEventRecord (bool v) { _pythiaFullEventRecord = v; } ///< returns if the full pythia event record should be prvoided | |
267 | void setXsecCalcMethod (int v) { _xsecCalcMethod = v; } ///< returns the method used for the x-sec calculation | |
da32329d AM |
268 | |
269 | void setProdParticleType (starlightConstants::particleTypeEnum v) { _particleType = v; } ///< returns type of produced particle | |
270 | void setProdParticleDecayType (starlightConstants::decayTypeEnum v) { _decayType = v; } ///< returns decay type of produced particle | |
271 | void setInteractionType (starlightConstants::interactionTypeEnum v) { _interactionType = v; } ///< returns interaction type | |
272 | ||
273 | // double vmPhotonCoupling(); | |
274 | // double slopeParameter(); | |
275 | void setProtonEnergy (double v) { _protonEnergy = v; } | |
276 | ||
0e1bd874 | 277 | // template<typename T> |
da32329d AM |
278 | inline bool setParameter(std::string expression); |
279 | ||
280 | std::ostream& print(std::ostream& out) const; ///< prints parameter summary | |
281 | std::ostream& write(std::ostream& out) const; ///< writes parameters back to an ostream | |
282 | ||
283 | std::string parameterValueKey() const; ///< Generates key for the current parameters | |
284 | ||
285 | ||
286 | private: | |
287 | ||
288 | ||
289 | // To indicate if the crossection table should be re-calculated if parameter changes | |
290 | #define VALIDITY_CHECK true | |
291 | #define NO_VALIDITY_CHECK false | |
292 | ||
293 | std::string _configFileName; ///< path to configuration file (default = ./config/slight.in) | |
294 | ||
295 | // config file parameters | |
296 | parameter<unsigned int,VALIDITY_CHECK> _beam1Z; ///< atomic number of beam particle 1 | |
297 | parameter<unsigned int,VALIDITY_CHECK> _beam1A; ///< atomic mass number of beam particle 1 | |
298 | parameter<unsigned int,VALIDITY_CHECK> _beam2Z; ///< atomic number of beam particle 2 | |
299 | parameter<unsigned int,VALIDITY_CHECK> _beam2A; ///< atomic mass number of beam particle 2 | |
300 | parameter<double, VALIDITY_CHECK> _beam1LorentzGamma; ///< Lorentz gamma factor of beam 1 in collider frame | |
301 | parameter<double, VALIDITY_CHECK> _beam2LorentzGamma; ///< Lorentz gamma factor of beam 2 in collider frame | |
302 | parameter<double, VALIDITY_CHECK> _maxW; ///< maximum mass W of produced hadronic system [GeV/c^2] | |
303 | parameter<double, VALIDITY_CHECK> _minW; ///< minimum mass W of produced hadronic system; if set to -1 default value is taken [GeV/c^2] | |
304 | parameter<unsigned int, VALIDITY_CHECK> _nmbWBins; ///< number of W bins in lookup table | |
305 | parameter<double, VALIDITY_CHECK> _maxRapidity; ///< maximum absolute value of rapidity | |
306 | parameter<unsigned int, VALIDITY_CHECK> _nmbRapidityBins; ///< number of rapidity bins in lookup table | |
307 | parameter<bool, VALIDITY_CHECK> _ptCutEnabled; ///< en/disables cut in pt | |
308 | parameter<double, VALIDITY_CHECK> _ptCutMin; ///< minimum pt, if cut is enabled | |
309 | parameter<double, VALIDITY_CHECK> _ptCutMax; ///< maximum pt, if cut is enabled | |
310 | parameter<bool, VALIDITY_CHECK> _etaCutEnabled; ///< en/disables cut in eta | |
311 | parameter<double, VALIDITY_CHECK> _etaCutMin; ///< minimum eta, if cut is enabled | |
312 | parameter<double, VALIDITY_CHECK> _etaCutMax; ///< maximum eta, if cut is enabled | |
313 | parameter<unsigned int, VALIDITY_CHECK> _productionMode; ///< \brief production mode | |
314 | ///< | |
315 | ///< 1 = photon-photon fusion, | |
316 | ///< 2 = narrow vector meson resonance in photon-Pomeron fusion, | |
317 | ///< 3 = Breit-Wigner vector meson resonance in photon-Pomeron fusion | |
318 | parameter<unsigned int, VALIDITY_CHECK> _nmbEventsTot; ///< total number of events to generate | |
319 | parameter<unsigned int, VALIDITY_CHECK> _prodParticleId; ///< PDG particle ID of produced particle | |
320 | parameter<unsigned int, VALIDITY_CHECK> _randomSeed; ///< seed for random number generator | |
da32329d AM |
321 | ///< |
322 | ///< 1 = ASCII | |
323 | ///< 2 = GSTARtext, | |
324 | ///< 3 = PAW ntuple (not working) | |
325 | parameter<unsigned int, VALIDITY_CHECK> _beamBreakupMode; ///< \brief breakup mode for beam particles | |
326 | ///< | |
327 | ///< 1 = hard sphere nuclei (b > 2R), | |
328 | ///< 2 = both nuclei break up (XnXn), | |
329 | ///< 3 = a single neutron from each nucleus (1n1n), | |
330 | ///< 4 = neither nucleon breaks up (with b > 2R), | |
331 | ///< 5 = no hadronic break up (similar to option 1, but with the actual hadronic interaction) | |
332 | parameter<bool, VALIDITY_CHECK> _interferenceEnabled; ///< if VALIDITY_CHECK, interference is taken into account | |
333 | parameter<double, VALIDITY_CHECK> _interferenceStrength; ///< percentage of interference: from 0 = none to 1 = full | |
da32329d AM |
334 | parameter<double, VALIDITY_CHECK> _maxPtInterference; ///< maximum p_T for interference calculation [GeV/c] |
335 | parameter<unsigned int, VALIDITY_CHECK> _nmbPtBinsInterference; ///< number of p_T bins for interference calculation | |
336 | parameter<double, VALIDITY_CHECK> _ptBinWidthInterference; ///< width of p_T bins for interference calculation [GeV/c] | |
45d54d9a | 337 | parameter<bool, VALIDITY_CHECK> _coherentProduction; ///< if VALIDITY_CHECK, production is coherent, else incoherent |
338 | parameter<double, VALIDITY_CHECK> _incoherentFactor; ///< allows to scale the incoherent contribution in vector meson production | |
da32329d AM |
339 | parameter<double, VALIDITY_CHECK> _protonEnergy; |
340 | parameter<double, VALIDITY_CHECK> _minGammaEnergy; ///< minimum gamma energy in case of photo nuclear processes [GeV] | |
341 | parameter<double, VALIDITY_CHECK> _maxGammaEnergy; ///< maximum gamma energy in case of photo nuclear processes [GeV] | |
342 | parameter<std::string,NO_VALIDITY_CHECK> _pythiaParams; ///< semi-colon separated parameters to pass to pythia, e.g. "mstj(1)=0;paru(13)=0.1" | |
45d54d9a | 343 | parameter<bool, NO_VALIDITY_CHECK> _pythiaFullEventRecord; ///< if the full pythia event record should be in the output |
0e1bd874 | 344 | parameter<unsigned int, VALIDITY_CHECK> _xsecCalcMethod; ///< Select x-sec calc method. (0 is standard starlight method, 1 must be used for assym. collisions (e.g. p-A), but is slow) |
345 | ||
da32329d AM |
346 | starlightConstants::particleTypeEnum _particleType; |
347 | starlightConstants::decayTypeEnum _decayType; | |
348 | starlightConstants::interactionTypeEnum _interactionType; | |
349 | ||
350 | double _beamLorentzGamma; ///< Lorentz gamma factor of the beams in CMS frame, not an input parameter | |
351 | ||
0e1bd874 | 352 | inputParser _ip; |
da32329d AM |
353 | |
354 | }; | |
355 | ||
356 | #define inputParametersInstance Singleton<inputParameters>::instance() | |
357 | ||
0e1bd874 | 358 | //template<typename T> |
da32329d AM |
359 | inline |
360 | bool inputParameters::setParameter(std::string expression) | |
361 | { | |
362 | ||
363 | return _ip.parseString(expression); | |
364 | ||
365 | ||
366 | } | |
367 | ||
368 | inline | |
369 | std::ostream& | |
370 | operator <<(std::ostream& out, | |
371 | const inputParameters& par) | |
372 | { | |
373 | return par.print(out); | |
374 | } | |
375 | ||
376 | ||
377 | #endif // INPUTPARAMETERS_H |