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  * The survival probability is taken into account in the conversion
288  * (see method JDETECTOR::getSurvivalProbability).
289  *
290  * \param mu expectation value
291  */
292  void convertHitProbabilityToQE(const double mu)
293  {
294  using namespace std;
296  using JDETECTOR::getQE;
297 
298  this->mu = mu;
299 
300  const double Pmax = getMaximalHitProbability(this->mu);
301 
302  for (JPMTParametersMap::const_iterator i = this->begin(); i != this->end(); ++i) {
303  if (i->second.QE > Pmax) {
304  THROW(JValueOutOfRange, "Hit probability PMT " << i->first << ' ' << i->second.QE << " > maximum probability given expectation value " << this->mu << endl);
305  }
306  }
307 
308  for (JPMTParametersMap::iterator i = this->begin(); i != this->end(); ++i) {
309 
310  const double P = getSurvivalProbability(i->second);
311 
312  if (i->second.QE > 0.0 && P > 0.0)
313  i->second.QE = getQE(i->second.QE, this->mu) / P;
314  else
315  i->second.QE = 0.0;
316  }
317  }
318 
319 
320  /**
321  * Stream input
322  *
323  * \param in input stream
324  * \param object PMT parameters map
325  * \return input stream
326  */
327  friend inline std::istream& operator>>(std::istream& in, JPMTParametersMap& object)
328  {
329  using namespace std;
330  using namespace JPP;
331 
332  JStringStream is(in);
333 
334  if (getFileStatus(is.str().c_str())) {
335  is.load();
336  }
337 
338  JProperties properties(getEquationParameters(), 1);
339 
341  JProperties demo = object.defaultPMTParameters.getProperties();
342 
343  properties["PMT"] = static_cast<JPMTParametersMap_t&>(object);
344  properties["pmt"] = helper;
345  properties["%"] = demo;
346  properties["QE"] = object.QE;
347  properties["mu"] = object.mu;
348 
349  is >> object.comment;
350  is >> properties;
351 
352  return in;
353  }
354 
355 
356  /**
357  * Stream output
358  *
359  * \param out output stream
360  * \param object PMT parameters map
361  * \return output stream
362  */
363  friend inline std::ostream& operator<<(std::ostream& out, const JPMTParametersMap& object)
364  {
365  using namespace JLANG;
366 
367  JProperties properties(getEquationParameters());
368 
369  JProperties demo = object.defaultPMTParameters.getProperties();
370 
371  properties["PMT"] = static_cast<const JPMTParametersMap_t&>(object);
372  properties["%"] = demo;
373 
374  out << object.comment;
377  out << properties;
378 
379  return out;
380  }
381 
382 
383  /**
384  * Get equation parameters.
385  *
386  * \return equation parameters
387  */
389  {
391 
392  return parameters;
393  }
394 
395 
396  /**
397  * Set equation parameters.
398  *
399  * \param equation equation parameters
400  */
401  static inline void setEquationParameters(const JEquationParameters& equation)
402  {
403  getEquationParameters() = equation;
404  }
405 
406 
408 
409  protected:
410  /**
411  * Default PMT parameters.
412  */
414 
415  /**
416  * Global QE.
417  */
418  double QE;
419 
420 
421  /**
422  * Expectation value for number of photo-electrons given two-fold (or higher) coincidence rate.
423  */
424  double mu;
425 
426  private:
427  /**
428  * Auxiliary class for I/O of PMT parameters map.
429  */
431  public:
432  /**
433  * Constructor.
434  *
435  * \param __object PMT parameters map
436  * \param __equation equation parameters
437  */
439  const JEquationParameters& __equation) :
440  object (__object),
441  equation(__equation)
442  {}
443 
444 
445  /**
446  * Stream input PMT parameters map helper.
447  *
448  * \param in input stream
449  * \param helper PMT parameters map helper
450  * \return input stream
451  */
452  friend inline std::istream& operator>>(std::istream& in, JPMTParametersMapHelper& helper)
453  {
454  JPMTIdentifier id;
455 
456  if (in >> id) {
457  helper.object[id].getProperties().read(in);
458  }
459 
460  return in;
461  }
462 
463 
464  /**
465  * Stream output PMT parameters map helper.
466  *
467  * \param out output stream
468  * \param helper PMT parameters map helper
469  * \return output stream
470  */
471  friend inline std::ostream& operator<<(std::ostream& out, const JPMTParametersMapHelper& helper)
472  {
473  for (JPMTParametersMap::const_iterator i = helper.object.begin(); i != helper.object.end(); ++i) {
474 
475  out << i->first;
476 
477  i->second.getProperties(helper.equation).write(out);
478 
479  out << std::endl;
480  }
481 
482  return out;
483  }
484 
485  private:
488  };
489  };
490 }
491 
492 #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
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
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:29
double getSurvivalProbability(const JPMTParameters &parameters)
Get model dependent probability that a one photo-electron hit survives the simulation of the PMT assu...
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.
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
then $DIR JPlotNPE PDG P
Definition: JPlotNPE-PDG.sh:60
File status.