Jpp 21.0.1
the software that should make you happy
Loading...
Searching...
No Matches
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"
18#include "Jeep/JComment.hh"
19#include "Jeep/JProperties.hh"
20
21
22/**
23 * \author mdejong
24 * \file
25 * Map of PMT parameters.
26 */
27
28namespace JDETECTOR {}
29namespace JPP { using namespace JDETECTOR; }
30
31namespace JDETECTOR {
32
39 using JLANG::JThrow;
40 using JEEP::JComment;
41
42
43 /**
44 * Type definition of map PMT identifier to PMT parameters.
45 */
47
48
49 /**
50 * Auxiliary class for map of PMT parameters.
51 *
52 * Input syntax as follows:
53 * <pre>
54 * QE=<value>
55 * mu=<value>
56 *
57 * %.<key>=<value>
58 *
59 * PMT=<module> <pmt> <PMT parameters>
60 *
61 * pmt=<module> <pmt> <key>=<value>[, <key>=<value>]
62 *
63 * file=<file name>
64 *
65 * </pre>
66 * where
67 * - QE refers to the global quantum efficiency which is reserved for the overall light scaling;
68 * - mu refers to the expectation value for number of photo-electrons given two-fold (or higher) coincidence rate;
69 * - '\%' to the default values;
70 * - <module> to the module identifier;
71 * - <pmt> to the readout channel;
72 * - <key> to one of the data members of the JDETECTOR::JPMTParameters data structure; and
73 * - <value> to the corresponding value.
74 *
75 * The global QE is applied as a multiplicative factor to the default and PMT specific QEs.
76 * It is set (read overwritten) in the JTriggerEfficiency[RunByRun].sh scripts.
77 *
78 * The default values are provided by the method getDefaultPMTParameters and
79 * can also be modified using method setDefaultPMTParameters.
80 * If no optional values are given, the default values are maintained.
81 *
82 * Finally, <PMT parameters> corresponds to the list of PMT parameter values that should
83 * be compatible with the I/O methods of the JDETECTOR::JPMTParameters data structure.
84 *
85 * Note that multiple input sequences should be seperated by a semicolumn ';' or be terminated by a newline.
86 * When multiple input sequences appear for the same target, the last sequence prevails.
87 */
90 public JObjectStreamIO<JPMTParametersMap>,
91 public JThrow<JPMTParametersMap>
92 {
93 public:
94 /**
95 * Constructor.
96 *
97 * \param parameters PMT parameters
98 */
104
105
106 /**
107 * Constructor.
108 *
109 * \param file_name file name
110 */
111 JPMTParametersMap(const char* const file_name) :
113 {
114 using namespace std;
115
116 ifstream in(file_name);
117
118 in >> *this;
119
120 in.close();
121 }
122
123
124 /**
125 * Get PMT parameters.\n
126 * This method returns the default PMT parameters if the parameters
127 * corresponding to the given PMT identifier have not been defined.
128 *
129 * Note that the value of QE as part of the return value has been scaled
130 * with the global QE of the PMT parameters map.
131 *
132 * \param id PMT identifier
133 * \return PMT parameters
134 */
136 {
138
139 JPMTParametersMap_t::const_iterator i = find(id);
140
141 if (i != end()) {
142 parameters = i->second;
143 } else {
145 }
146
147 parameters.QE *= internal.QE;
148
149 return parameters;
150 }
151
152
153 /**
154 * Get QE of given PMT.
155 *
156 * \param id PMT identifier
157 * \return QE
158 */
159 double getQE(const JPMTIdentifier& id) const
160 {
161 return getPMTParameters(id).QE;
162 }
163
164
165 /**
166 * Get ratio of hit probabilities of given PMT.
167 *
168 * \param id PMT identifier
169 * \return ratio
170 */
171 double getHitProbability(const JPMTIdentifier& id) const
172 {
174 }
175
176
177 /**
178 * Get default PMT parameters.
179 *
180 * \return PMT parameters
181 */
183 {
184 return internal.parameters;
185 }
186
187
188 /**
189 * Get default PMT parameters.
190 *
191 * \return PMT parameters
192 */
194 {
195 return internal.parameters;
196 }
197
198
199 /**
200 * Set default PMT parameters.
201 *
202 * \param parameters PMT parameters
203 */
205 {
206 internal.parameters = parameters;
207 }
208
209
210 /**
211 * Get global QE.
212 *
213 * \return QE
214 */
215 double getQE() const
216 {
217 return internal.QE;
218 }
219
220
221 /**
222 * Set global QE.
223 *
224 * \param QE QE
225 */
226 void setQE(const double QE)
227 {
228 internal.QE = QE;
229 }
230
231
232 /**
233 * Get expectation value for number of photo-electrons given two-fold (or higher) coincidence rate.
234 *
235 * \return expectation value
236 */
237 double getMu() const
238 {
239 return internal.mu;
240 }
241
242
243 /**
244 * Check validity of PMT parameters.
245 *
246 * \return true if valid; else false
247 */
248 bool is_valid() const
249 {
250 try {
251
252 if (internal.QE < 0.0) {
253 THROW(JException, "Invalid global QE " << internal.QE);
254 }
255
256 if (internal.mu < 0.0) {
257 THROW(JException, "Invalid expectation value number of photo-electrons " << internal.mu);
258 }
259
260 if (!internal.parameters.is_valid()) {
261 THROW(JException, "Invalid default PMT parameters");
262 }
263
264 for (const_iterator i = this->begin(); i != this->end(); ++i) {
265
266 if (!i->second.is_valid()) {
267 THROW(JException, "Invalid PMT parameters at " << i->first);
268 }
269
270 if (i->second.QE * internal.QE > 1.0 ||
271 i->second.QE * internal.QE < 0.0) {
272 THROW(JException, "Invalid PMT QE at " << i->first << ' ' << i->second.QE * internal.QE);
273 }
274 }
275
276 return true;
277 }
278 catch(const JException& error) {
279
280 Throw(error);
281
282 return false;
283 }
284 }
285
286
287 /**
288 * Convert the hit probabilities to QEs for given expectation value.
289 *
290 * The expectation value corresponds to the number of photo-electrons given
291 * the multiplicity range of coincidences as specified at JCalibrateK40.cc.\n
292 *
293 * \param mu expectation value
294 */
295 void convertHitProbabilityToQE(const double mu)
296 {
297 if (internal.mu != 0.0) {
298 THROW(JValueOutOfRange, "Non-zero internal expectation value " << internal.mu << "; use first method convertQEToHitProbability().");
299 }
300
301 const double Pmax = getMaximalHitProbability(mu);
302
303 internal.mu = mu;
304
305 for (JPMTParametersMap::iterator i = this->begin(); i != this->end(); ++i) {
306
307 if (i->second.QE >= Pmax)
308 i->second.QE = Pmax;
309 else if (i->second.QE > 0.0)
310 i->second.QE = JDETECTOR::getQE(i->second.QE, internal.mu);
311 else
312 i->second.QE = 0.0;
313 }
314 }
315
316
317 /**
318 * Convert the QEs to hit probabilities for given expectation value.
319 *
320 * The expectation value is set to zero.
321 */
323 {
324 // backward correction QE -> P
325
326 if (internal.mu > 0.0) {
327
328 for (JPMTParametersMap::iterator i = this->begin(); i != this->end(); ++i) {
329
330 if (i->second.QE > 0.0)
331 i->second.QE = JDETECTOR::getHitProbability(i->second.QE, internal.mu);
332 else
333 i->second.QE = 0.0;
334 }
335
336 internal.mu = 0.0;
337 }
338 }
339
340
341 /**
342 * Access parameters corresponding to given PMT identifier.
343 *
344 * Note: The default PMT parameters are inserted if no parameters for the given PMT identifier are contained
345 * at the time of the function call.
346 *
347 * \param id PMT identifier
348 * \return parameters
349 */
351 {
352 JPMTParametersMap_t::iterator i = find(id);
353
354 if (i == end()) {
355 i = this->insert(i, std::make_pair(id, getDefaultPMTParameters()));
356 }
357
358 return i->second;
359 }
360
361
362 /**
363 * Stream input
364 *
365 * \param in input stream
366 * \param object PMT parameters map
367 * \return input stream
368 */
369 friend inline std::istream& operator>>(std::istream& in, JPMTParametersMap& object)
370 {
371 using namespace std;
372 using namespace JPP;
373
374 JStringStream is(in);
375
376 JProperties properties(getEquationParameters(), 1);
377
379 JProperties demo = object.internal.parameters.getProperties();
380
381 properties["PMT"] = static_cast<JPMTParametersMap_t&>(object);
382 properties["pmt"] = helper;
383 properties["%"] = demo;
384 properties["QE"] = object.internal.QE;
385 properties["mu"] = object.internal.mu;
386
387 is >> object.comment;
388 is >> properties;
389
390 return in;
391 }
392
393
394 /**
395 * Stream output
396 *
397 * \param out output stream
398 * \param object PMT parameters map
399 * \return output stream
400 */
401 friend inline std::ostream& operator<<(std::ostream& out, const JPMTParametersMap& object)
402 {
403 using namespace JLANG;
404
406
407 JProperties demo = object.internal.parameters.getProperties();
408
409 properties["PMT"] = static_cast<const JPMTParametersMap_t&>(object);
410 properties["%"] = demo;
411
412 out << object.comment;
413 out << setequation(getEquationParameters()) << JEquation::make_equation("QE", object.internal.QE);
414 out << setequation(getEquationParameters()) << JEquation::make_equation("mu", object.internal.mu);
415 out << properties;
416
417 return out;
418 }
419
420
421 /**
422 * Get equation parameters.
423 *
424 * \return equation parameters
425 */
427 {
429
430 return parameters;
431 }
432
433
434 /**
435 * Set equation parameters.
436 *
437 * \param equation equation parameters
438 */
439 static inline void setEquationParameters(const JEquationParameters& equation)
440 {
441 getEquationParameters() = equation;
442 }
443
444
446
447 protected:
448
449 struct {
450 JPMTParameters parameters; //!< Default PMT parameters.
451 double QE = 1.0; //!< Global QE.
452 double mu = 0.0; //!< Expectation value for number of photo-electrons given two-fold (or higher) coincidence rate.
454
455 private:
456 /**
457 * Auxiliary class for I/O of PMT parameters map.
458 */
460 public:
461 /**
462 * Constructor.
463 *
464 * \param __object PMT parameters map
465 * \param __equation equation parameters
466 */
468 const JEquationParameters& __equation) :
469 object (__object),
470 equation(__equation)
471 {}
472
473
474 /**
475 * Stream input PMT parameters map helper.
476 *
477 * \param in input stream
478 * \param helper PMT parameters map helper
479 * \return input stream
480 */
481 friend inline std::istream& operator>>(std::istream& in, JPMTParametersMapHelper& helper)
482 {
484
485 if (in >> id) {
486 helper.object[id].getProperties().read(in);
487 }
488
489 return in;
490 }
491
492
493 /**
494 * Stream output PMT parameters map helper.
495 *
496 * \param out output stream
497 * \param helper PMT parameters map helper
498 * \return output stream
499 */
500 friend inline std::ostream& operator<<(std::ostream& out, const JPMTParametersMapHelper& helper)
501 {
502 for (JPMTParametersMap::const_iterator i = helper.object.begin(); i != helper.object.end(); ++i) {
503
504 out << i->first;
505
506 i->second.getProperties(helper.equation).write(out);
507
508 out << std::endl;
509 }
510
511 return out;
512 }
513
514 private:
517 };
518 };
519}
520
521#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Utility class to parse parameter values.
Exception handling.
Auxiliary class for I/O of PMT parameters map.
friend std::ostream & operator<<(std::ostream &out, const JPMTParametersMapHelper &helper)
Stream output PMT parameters map helper.
friend std::istream & operator>>(std::istream &in, JPMTParametersMapHelper &helper)
Stream input PMT parameters map helper.
JPMTParametersMapHelper(JPMTParametersMap &__object, const JEquationParameters &__equation)
Constructor.
Auxiliary class for map of PMT parameters.
JPMTParameters parameters
Default PMT parameters.
void setQE(const double QE)
Set global QE.
static void setEquationParameters(const JEquationParameters &equation)
Set equation parameters.
JPMTParametersMap(const char *const file_name)
Constructor.
JPMTParameters & getDefaultPMTParameters()
Get default PMT parameters.
double getMu() const
Get expectation value for number of photo-electrons given two-fold (or higher) coincidence rate.
friend std::istream & operator>>(std::istream &in, JPMTParametersMap &object)
Stream input.
const JPMTParameters & getPMTParameters(const JPMTIdentifier &id) const
Get PMT parameters.
void convertHitProbabilityToQE(const double mu)
Convert the hit probabilities to QEs for given expectation value.
void convertQEToHitProbability()
Convert the QEs to hit probabilities for given expectation value.
void setDefaultPMTParameters(const JPMTParameters &parameters)
Set default PMT parameters.
struct JDETECTOR::JPMTParametersMap::@9 internal
JPMTParameters & operator[](const JPMTIdentifier &id)
Access parameters corresponding to given PMT identifier.
const JPMTParameters & getDefaultPMTParameters() const
Get default PMT parameters.
double mu
Expectation value for number of photo-electrons given two-fold (or higher) coincidence rate.
static JEquationParameters & getEquationParameters()
Get equation parameters.
double getQE() const
Get global QE.
double getQE(const JPMTIdentifier &id) const
Get QE of given PMT.
double getHitProbability(const JPMTIdentifier &id) const
Get ratio of hit probabilities of given PMT.
JPMTParametersMap(const JPMTParameters &parameters=JPMTParameters())
Constructor.
bool is_valid() const
Check validity of PMT parameters.
friend std::ostream & operator<<(std::ostream &out, const JPMTParametersMap &object)
Stream output.
Data structure for PMT parameters.
double QE
relative quantum efficiency
Utility class to parse parameter values.
Facet class to specify parsing of equations in currect locale (see class JLANG::JEquation).
Simple data structure to support I/O of equations (see class JLANG::JEquation).
General exception.
Definition JException.hh:25
Exception for opening of file.
Exception for reading of file.
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
Auxiliary base class for controling the throwing of exceptions.
Definition JThrow.hh:25
static void Throw(const bool option)
Enable/disable throw option.
Definition JThrow.hh:37
Exception for accessing a value in a collection that is outside of its range.
file Auxiliary data structures and methods for detector calibration.
Definition JAnchor.hh:12
double getMaximalHitProbability(const double mu)
Get maximal ratio of hit probabilities for given QE and expectation value of the number of photo-elec...
std::map< JPMTIdentifier, JPMTParameters > JPMTParametersMap_t
Type definition of map PMT identifier to PMT parameters.
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.
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.
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for comment.
Definition JComment.hh:43
Auxiliary base class for storing and loading a single object to and from an ASCII file,...