Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPMTParametersMap.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JPMTPARAMETERSMAP__
2 #define __JDETECTOR__JPMTPARAMETERSMAP__
3 
4 #include <istream>
5 #include <ostream>
6 #include <sstream>
7 #include <fstream>
8 #include <map>
9 
14 #include "JLang/JException.hh"
15 #include "JLang/JThrow.hh"
16 #include "JLang/JStringStream.hh"
17 #include "JLang/JObjectStreamIO.hh"
18 #include "Jeep/JComment.hh"
19 #include "Jeep/JProperties.hh"
20 #include "JSystem/JStat.hh"
21 
22 
23 /**
24  * \author mdejong
25  * \file
26  * Map of PMT parameters.
27  */
28 
29 namespace JDETECTOR {}
30 namespace JPP { using namespace JDETECTOR; }
31 
32 namespace JDETECTOR {
33 
39  using JLANG::JException;
40  using JLANG::JThrow;
41  using JEEP::JComment;
42 
43 
44  /**
45  * Type definition of map PMT identifier to PMT parameters.
46  */
48 
49 
50  /**
51  * Auxiliary class for map of PMT parameters.
52  *
53  * Input syntax as follows:
54  * <pre>
55  * QE=<value>
56  * mu=<value>
57  *
58  * %.<key>=<value>
59  *
60  * PMT=<module> <pmt> <PMT parameters>
61  *
62  * pmt=<module> <pmt> <key>=<value>[, <key>=<value>]
63  *
64  * file=<file name>
65  *
66  * </pre>
67  * where
68  * - QE refers to the global quantum efficiency which is reserved for the so-called light scaling;
69  * - mu refers to the expectation value for number of photo-electrons given two-fold (or higher) coincidence rate;
70  * - '\%' to the default values;
71  * - <module> to the module identifier;
72  * - <pmt> to the readout channel;
73  * - <key> to one of the data members of the JDETECTOR::JPMTParameters data structure; and
74  * - <value> to the corresponding value.
75  *
76  * The global QE is applied as a multiplicative factor to the default and PMT specific QEs.
77  * It is set (read overwritten) in the JTriggerEfficiency[RunByRun].sh scripts.
78  *
79  * The default values are provided by the method getDefaultPMTParameters and
80  * can also be modified using method setDefaultPMTParameters.
81  * If no optional values are given, the default values are maintained.
82  *
83  * Finally, <PMT parameters> corresponds to the list of PMT parameter values that should
84  * be compatible with the I/O methods of the JDETECTOR::JPMTParameters data structure.
85  *
86  * Note that multiple input sequences should be seperated by a semicolumn ';' or be terminated by a newline.
87  * When multiple input sequences appear for the same target, the last sequence prevails.
88  */
90  public JPMTParametersMap_t,
91  public JObjectStreamIO<JPMTParametersMap>,
92  public JThrow<JPMTParametersMap>
93  {
94  public:
95  /**
96  * Constructor.
97  *
98  * \param parameters PMT parameters
99  */
102  QE(1.0),
103  mu(0.0)
104  {
106  }
107 
108 
109  /**
110  * Constructor.
111  *
112  * \param file_name file name
113  */
114  JPMTParametersMap(const char* const file_name) :
116  QE(1.0),
117  mu(0.0)
118  {
119  using namespace std;
120 
121  ifstream in(file_name);
122 
123  in >> *this;
124 
125  in.close();
126  }
127 
128 
129  /**
130  * Get PMT parameters.\n
131  * This method returns the default PMT parameters if the parameters
132  * corresponding to the given PMT identifier have not been defined.
133  *
134  * Note that the value of QE as part of the return value has been scaled
135  * with the global QE of the PMT parameters map.
136  *
137  * \param id PMT identifier
138  * \return PMT parameters
139  */
141  {
142  static JPMTParameters parameters;
143 
144  JPMTParametersMap_t::const_iterator i = find(id);
145 
146  if (i != end())
147  parameters = i->second;
148  else
149  parameters = getDefaultPMTParameters();
150 
151  parameters.QE *= this->QE;
152 
153  return parameters;
154  }
155 
156 
157  /**
158  * Get QE of given PMT.
159  *
160  * \param id PMT identifier
161  * \return QE
162  */
163  double getQE(const JPMTIdentifier& id) const
164  {
165  return getPMTParameters(id).QE;
166  }
167 
168 
169  /**
170  * Get ratio of hit probabilities of given PMT.
171  *
172  * \param id PMT identifier
173  * \return ratio
174  */
175  double getHitProbability(const JPMTIdentifier& id) const
176  {
178 
179  return getHitProbability(getQE(id), this->mu);
180  }
181 
182 
183  /**
184  * Get default PMT parameters.
185  *
186  * \return PMT parameters
187  */
189  {
190  return defaultPMTParameters;
191  }
192 
193 
194  /**
195  * Set default PMT parameters.
196  *
197  * \param parameters PMT parameters
198  */
200  {
202  }
203 
204 
205  /**
206  * Get global QE.
207  *
208  * \return QE
209  */
210  double getQE() const
211  {
212  return this->QE;
213  }
214 
215 
216  /**
217  * Set global QE.
218  *
219  * \param QE QE
220  */
221  void setQE(const double QE)
222  {
223  this->QE = QE;
224  }
225 
226 
227  /**
228  * Get expectation value for number of photo-electrons given two-fold (or higher) coincidence rate.
229  *
230  * \return expectation value
231  */
232  double getMu() const
233  {
234  return this->mu;
235  }
236 
237 
238  /**
239  * Check validity of PMT parameters.
240  *
241  * \return true if valid; else false
242  */
243  bool is_valid() const
244  {
245  try {
246 
247  if (this->QE < 0) {
248  THROW(JException, "Invalid global QE " << QE);
249  }
250 
251  if (this->mu < 0) {
252  THROW(JException, "Invalid expectation value number of photo-electrons " << mu);
253  }
254 
256  THROW(JException, "Invalid default PMT parameters");
257  }
258 
259  for (const_iterator i = this->begin(); i != this->end(); ++i) {
260 
261  if (!i->second.is_valid()) {
262  THROW(JException, "Invalid PMT parameters at " << i->first);
263  }
264 
265  if (i->second.QE * this->QE > 1.0 ||
266  i->second.QE * this->QE < 0.0) {
267  THROW(JException, "Invalid PMT QE at " << i->first << ' ' << i->second.QE * this->QE);
268  }
269  }
270 
271  return true;
272  }
273  catch(const JException& error) {
274 
275  Throw(error);
276 
277  return false;
278  }
279  }
280 
281 
282  /**
283  * Convert the hit probabilities to QEs for given expectation value.
284  *
285  * The expectation value corresponds to the number of photo-electrons given
286  * the multiplicity range of coincidences as specified at JCalibrateK40.cc.\n
287  *
288  * \param mu expectation value
289  */
290  void convertHitProbabilityToQE(const double mu)
291  {
292  using namespace std;
294  using JDETECTOR::getQE;
295 
296  this->mu = mu;
297 
298  const double Pmax = getMaximalHitProbability(this->mu);
299 
300  for (JPMTParametersMap::const_iterator i = this->begin(); i != this->end(); ++i) {
301  if (i->second.QE > Pmax) {
302  THROW(JValueOutOfRange, "Hit probability PMT " << i->first << ' ' << i->second.QE << " > maximum probability given expectation value " << this->mu << endl);
303  }
304  }
305 
306  for (JPMTParametersMap::iterator i = this->begin(); i != this->end(); ++i) {
307 
308  if (i->second.QE > 0.0)
309  i->second.QE = getQE(i->second.QE, this->mu);
310  else
311  i->second.QE = 0.0;
312  }
313  }
314 
315 
316  /**
317  * Stream input
318  *
319  * \param in input stream
320  * \param object PMT parameters map
321  * \return input stream
322  */
323  friend inline std::istream& operator>>(std::istream& in, JPMTParametersMap& object)
324  {
325  using namespace std;
326  using namespace JPP;
327 
328  JStringStream is(in);
329 
330  if (getFileStatus(is.str().c_str())) {
331  is.load();
332  }
333 
334  JProperties properties(getEquationParameters(), 1);
335 
337  JProperties demo = object.defaultPMTParameters.getProperties();
338 
339  properties["PMT"] = static_cast<JPMTParametersMap_t&>(object);
340  properties["pmt"] = helper;
341  properties["%"] = demo;
342  properties["QE"] = object.QE;
343  properties["mu"] = object.mu;
344 
345  is >> object.comment;
346  is >> properties;
347 
348  return in;
349  }
350 
351 
352  /**
353  * Stream output
354  *
355  * \param out output stream
356  * \param object PMT parameters map
357  * \return output stream
358  */
359  friend inline std::ostream& operator<<(std::ostream& out, const JPMTParametersMap& object)
360  {
361  using namespace JLANG;
362 
363  JProperties properties(getEquationParameters());
364 
365  JProperties demo = object.defaultPMTParameters.getProperties();
366 
367  properties["PMT"] = static_cast<const JPMTParametersMap_t&>(object);
368  properties["%"] = demo;
369 
370  out << object.comment;
373  out << properties;
374 
375  return out;
376  }
377 
378 
379  /**
380  * Get equation parameters.
381  *
382  * \return equation parameters
383  */
385  {
387 
388  return parameters;
389  }
390 
391 
392  /**
393  * Set equation parameters.
394  *
395  * \param equation equation parameters
396  */
397  static inline void setEquationParameters(const JEquationParameters& equation)
398  {
399  getEquationParameters() = equation;
400  }
401 
402 
404 
405  protected:
406  /**
407  * Default PMT parameters.
408  */
410 
411  /**
412  * Global QE.
413  */
414  double QE;
415 
416 
417  /**
418  * Expectation value for number of photo-electrons given two-fold (or higher) coincidence rate.
419  */
420  double mu;
421 
422  private:
423  /**
424  * Auxiliary class for I/O of PMT parameters map.
425  */
427  public:
428  /**
429  * Constructor.
430  *
431  * \param __object PMT parameters map
432  * \param __equation equation parameters
433  */
435  const JEquationParameters& __equation) :
436  object (__object),
437  equation(__equation)
438  {}
439 
440 
441  /**
442  * Stream input PMT parameters map helper.
443  *
444  * \param in input stream
445  * \param helper PMT parameters map helper
446  * \return input stream
447  */
448  friend inline std::istream& operator>>(std::istream& in, JPMTParametersMapHelper& helper)
449  {
450  JPMTIdentifier id;
451 
452  if (in >> id) {
453  helper.object[id].getProperties().read(in);
454  }
455 
456  return in;
457  }
458 
459 
460  /**
461  * Stream output PMT parameters map helper.
462  *
463  * \param out output stream
464  * \param helper PMT parameters map helper
465  * \return output stream
466  */
467  friend inline std::ostream& operator<<(std::ostream& out, const JPMTParametersMapHelper& helper)
468  {
469  for (JPMTParametersMap::const_iterator i = helper.object.begin(); i != helper.object.end(); ++i) {
470 
471  out << i->first;
472 
473  i->second.getProperties(helper.equation).write(out);
474 
475  out << std::endl;
476  }
477 
478  return out;
479  }
480 
481  private:
484  };
485  };
486 }
487 
488 #endif
Exception for opening of file.
Definition: JException.hh:342
General exception.
Definition: JException.hh:23
static void setEquationParameters(const JEquationParameters &equation)
Set equation parameters.
Exception for reading of file.
Definition: JException.hh:360
Exceptions.
void setQE(const double QE)
Set global QE.
JPMTParametersMap(const JPMTParameters &parameters=JPMTParameters())
Constructor.
Auxiliary base class for controling the throwing of exceptions.
Definition: JThrow.hh:25
double getMu() const
Get expectation value for number of photo-electrons given two-fold (or higher) coincidence rate...
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
Utility class to parse parameter values.
Definition: JProperties.hh:496
const JPMTParameters & getPMTParameters(const JPMTIdentifier &id) const
Get PMT parameters.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
static equation_type< T > make_equation(const std::string &key, const T &value)
Auxiliary method to create equation type.
Definition: JEquation.hh:117
Simple data structure to support I/O of equations (see class JLANG::JEquation).
double mu
Expectation value for number of photo-electrons given two-fold (or higher) coincidence rate...
friend std::ostream & operator<<(std::ostream &out, const JPMTParametersMap &object)
Stream output.
is
Definition: JDAQCHSM.chsm:167
void convertHitProbabilityToQE(const double mu)
Convert the hit probabilities to QEs for given expectation value.
std::map< JPMTIdentifier, JPMTParameters > JPMTParametersMap_t
Type definition of map PMT identifier to PMT parameters.
JPMTParametersMapHelper(JPMTParametersMap &__object, const JEquationParameters &__equation)
Constructor.
Utility class to parse parameter values.
Auxiliary class for I/O of PMT parameters map.
double getQE() const
Get global QE.
double getQE(const double R, const double mu)
Get QE for given ratio of hit probabilities and expectation value of the number of photo-electrons...
bool is_valid() const
Check validity of PMT parameters.
const JPMTParameters & getDefaultPMTParameters() const
Get default PMT parameters.
Auxiliary class for map of PMT parameters.
JPMTParameters defaultPMTParameters
Default PMT parameters.
double getQE(const JPMTIdentifier &id) const
Get QE of given PMT.
friend std::istream & operator>>(std::istream &in, JPMTParametersMap &object)
Stream input.
double getHitProbability(const double QE, const double mu)
Get ratio of hit probabilities for given QE and expectation value of the number of photo-electrons...
static JEquationParameters & getEquationParameters()
Get equation parameters.
bool is_valid() const
Check validity of PMT parameters.
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
Auxiliary class for comment.
Definition: JComment.hh:41
JLANG::JEquationFacet setequation
Type definition of stream manipulator for equational I/O.
void setDefaultPMTParameters(const JPMTParameters &parameters)
Set default PMT parameters.
Exception handling.
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
Data structure for PMT parameters.
Auxiliary base class for storing and loading a single object to and from an ASCII file...
friend std::istream & operator>>(std::istream &in, JPMTParametersMapHelper &helper)
Stream input PMT parameters map helper.
JPMTParametersMap(const char *const file_name)
Constructor.
friend std::ostream & operator<<(std::ostream &out, const JPMTParametersMapHelper &helper)
Stream output PMT parameters map helper.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36
double getMaximalHitProbability(const double mu)
Get maximal ratio of hit probabilities for given QE and expectation value of the number of photo-elec...
double QE
relative quantum efficiency
double getHitProbability(const JPMTIdentifier &id) const
Get ratio of hit probabilities of given PMT.
static void Throw(const bool option)
Enable/disable throw option.
Definition: JThrow.hh:37
File status.