Jpp 21.0.0-rc.1-88-g0130508c4
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#include "JSystem/JStat.hh"
21
22
23/**
24 * \author mdejong
25 * \file
26 * Map of PMT parameters.
27 */
28
29namespace JDETECTOR {}
30namespace JPP { using namespace JDETECTOR; }
31
32namespace JDETECTOR {
33
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 overall 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 */
91 public JObjectStreamIO<JPMTParametersMap>,
92 public JThrow<JPMTParametersMap>
93 {
94 public:
95 /**
96 * Constructor.
97 *
98 * \param parameters PMT parameters
99 */
105
106
107 /**
108 * Constructor.
109 *
110 * \param file_name file name
111 */
112 JPMTParametersMap(const char* const file_name) :
114 {
115 using namespace std;
116
117 ifstream in(file_name);
118
119 in >> *this;
120
121 in.close();
122 }
123
124
125 /**
126 * Get PMT parameters.\n
127 * This method returns the default PMT parameters if the parameters
128 * corresponding to the given PMT identifier have not been defined.
129 *
130 * Note that the value of QE as part of the return value has been scaled
131 * with the global QE of the PMT parameters map.
132 *
133 * \param id PMT identifier
134 * \return PMT parameters
135 */
137 {
139
140 JPMTParametersMap_t::const_iterator i = find(id);
141
142 if (i != end()) {
143 parameters = i->second;
144 } else {
146 }
147
148 parameters.QE *= internal.QE;
149
150 return parameters;
151 }
152
153
154 /**
155 * Get QE of given PMT.
156 *
157 * \param id PMT identifier
158 * \return QE
159 */
160 double getQE(const JPMTIdentifier& id) const
161 {
162 return getPMTParameters(id).QE;
163 }
164
165
166 /**
167 * Get ratio of hit probabilities of given PMT.
168 *
169 * \param id PMT identifier
170 * \return ratio
171 */
172 double getHitProbability(const JPMTIdentifier& id) const
173 {
175 }
176
177
178 /**
179 * Get default PMT parameters.
180 *
181 * \return PMT parameters
182 */
184 {
185 return internal.parameters;
186 }
187
188
189 /**
190 * Get default PMT parameters.
191 *
192 * \return PMT parameters
193 */
195 {
196 return internal.parameters;
197 }
198
199
200 /**
201 * Set default PMT parameters.
202 *
203 * \param parameters PMT parameters
204 */
206 {
207 internal.parameters = parameters;
208 }
209
210
211 /**
212 * Get global QE.
213 *
214 * \return QE
215 */
216 double getQE() const
217 {
218 return internal.QE;
219 }
220
221
222 /**
223 * Set global QE.
224 *
225 * \param QE QE
226 */
227 void setQE(const double QE)
228 {
229 internal.QE = QE;
230 }
231
232
233 /**
234 * Get expectation value for number of photo-electrons given two-fold (or higher) coincidence rate.
235 *
236 * \return expectation value
237 */
238 double getMu() const
239 {
240 return internal.mu;
241 }
242
243
244 /**
245 * Check validity of PMT parameters.
246 *
247 * \return true if valid; else false
248 */
249 bool is_valid() const
250 {
251 try {
252
253 if (internal.QE < 0.0) {
254 THROW(JException, "Invalid global QE " << internal.QE);
255 }
256
257 if (internal.mu < 0.0) {
258 THROW(JException, "Invalid expectation value number of photo-electrons " << internal.mu);
259 }
260
261 if (!internal.parameters.is_valid()) {
262 THROW(JException, "Invalid default PMT parameters");
263 }
264
265 for (const_iterator i = this->begin(); i != this->end(); ++i) {
266
267 if (!i->second.is_valid()) {
268 THROW(JException, "Invalid PMT parameters at " << i->first);
269 }
270
271 if (i->second.QE * internal.QE > 1.0 ||
272 i->second.QE * internal.QE < 0.0) {
273 THROW(JException, "Invalid PMT QE at " << i->first << ' ' << i->second.QE * internal.QE);
274 }
275 }
276
277 return true;
278 }
279 catch(const JException& error) {
280
281 Throw(error);
282
283 return false;
284 }
285 }
286
287
288 /**
289 * Convert the hit probabilities to QEs for given expectation value.
290 *
291 * The expectation value corresponds to the number of photo-electrons given
292 * the multiplicity range of coincidences as specified at JCalibrateK40.cc.\n
293 *
294 * \param mu expectation value
295 */
296 void convertHitProbabilityToQE(const double mu)
297 {
298 if (internal.mu != 0.0) {
299 THROW(JValueOutOfRange, "Non-zero internal expectation value " << internal.mu << "; use first method convertQEToHitProbability().");
300 }
301
302 const double Pmax = getMaximalHitProbability(mu);
303
304 for (JPMTParametersMap::const_iterator i = this->begin(); i != this->end(); ++i) {
305 if (i->second.QE > Pmax) {
306 THROW(JValueOutOfRange, "Hit probability PMT " << i->first << ' ' << i->second.QE << " > maximum probability given expectation value " << mu);
307 }
308 }
309
310 internal.mu = mu;
311
312 for (JPMTParametersMap::iterator i = this->begin(); i != this->end(); ++i) {
313
314 if (i->second.QE > 0.0)
315 i->second.QE = JDETECTOR::getQE(i->second.QE, internal.mu);
316 else
317 i->second.QE = 0.0;
318 }
319 }
320
321
322 /**
323 * Convert the QEs to hit probabilities for given expectation value.
324 *
325 * The expectation value is set to zero.
326 */
328 {
329 // backward correction QE -> P
330
331 if (internal.mu > 0.0) {
332
333 for (JPMTParametersMap::iterator i = this->begin(); i != this->end(); ++i) {
334
335 if (i->second.QE > 0.0)
336 i->second.QE = JDETECTOR::getHitProbability(i->second.QE, internal.mu);
337 else
338 i->second.QE = 0.0;
339 }
340
341 internal.mu = 0.0;
342 }
343 }
344
345
346 /**
347 * Access parameters corresponding to given PMT identifier.
348 *
349 * Note: The default PMT parameters are inserted if no parameters for the given PMT identifier are contained
350 * at the time of the function call.
351 *
352 * \param id PMT identifier
353 * \return parameters
354 */
356 {
357 JPMTParametersMap_t::iterator i = find(id);
358
359 if (i == end()) {
360 i = this->insert(i, std::make_pair(id, getDefaultPMTParameters()));
361 }
362
363 return i->second;
364 }
365
366
367 /**
368 * Stream input
369 *
370 * \param in input stream
371 * \param object PMT parameters map
372 * \return input stream
373 */
374 friend inline std::istream& operator>>(std::istream& in, JPMTParametersMap& object)
375 {
376 using namespace std;
377 using namespace JPP;
378
379 JStringStream is(in);
380
381 if (getFileStatus(is.str().c_str())) {
382 is.load();
383 }
384
385 JProperties properties(getEquationParameters(), 1);
386
388 JProperties demo = object.internal.parameters.getProperties();
389
390 properties["PMT"] = static_cast<JPMTParametersMap_t&>(object);
391 properties["pmt"] = helper;
392 properties["%"] = demo;
393 properties["QE"] = object.internal.QE;
394 properties["mu"] = object.internal.mu;
395
396 is >> object.comment;
397 is >> properties;
398
399 return in;
400 }
401
402
403 /**
404 * Stream output
405 *
406 * \param out output stream
407 * \param object PMT parameters map
408 * \return output stream
409 */
410 friend inline std::ostream& operator<<(std::ostream& out, const JPMTParametersMap& object)
411 {
412 using namespace JLANG;
413
415
416 JProperties demo = object.internal.parameters.getProperties();
417
418 properties["PMT"] = static_cast<const JPMTParametersMap_t&>(object);
419 properties["%"] = demo;
420
421 out << object.comment;
422 out << setequation(getEquationParameters()) << JEquation::make_equation("QE", object.internal.QE);
423 out << setequation(getEquationParameters()) << JEquation::make_equation("mu", object.internal.mu);
424 out << properties;
425
426 return out;
427 }
428
429
430 /**
431 * Get equation parameters.
432 *
433 * \return equation parameters
434 */
436 {
438
439 return parameters;
440 }
441
442
443 /**
444 * Set equation parameters.
445 *
446 * \param equation equation parameters
447 */
448 static inline void setEquationParameters(const JEquationParameters& equation)
449 {
450 getEquationParameters() = equation;
451 }
452
453
455
456 protected:
457
458 struct {
459 JPMTParameters parameters; //!< Default PMT parameters.
460 double QE = 1.0; //!< Global QE.
461 double mu = 0.0; //!< Expectation value for number of photo-electrons given two-fold (or higher) coincidence rate.
463
464 private:
465 /**
466 * Auxiliary class for I/O of PMT parameters map.
467 */
469 public:
470 /**
471 * Constructor.
472 *
473 * \param __object PMT parameters map
474 * \param __equation equation parameters
475 */
477 const JEquationParameters& __equation) :
478 object (__object),
479 equation(__equation)
480 {}
481
482
483 /**
484 * Stream input PMT parameters map helper.
485 *
486 * \param in input stream
487 * \param helper PMT parameters map helper
488 * \return input stream
489 */
490 friend inline std::istream& operator>>(std::istream& in, JPMTParametersMapHelper& helper)
491 {
493
494 if (in >> id) {
495 helper.object[id].getProperties().read(in);
496 }
497
498 return in;
499 }
500
501
502 /**
503 * Stream output PMT parameters map helper.
504 *
505 * \param out output stream
506 * \param helper PMT parameters map helper
507 * \return output stream
508 */
509 friend inline std::ostream& operator<<(std::ostream& out, const JPMTParametersMapHelper& helper)
510 {
511 for (JPMTParametersMap::const_iterator i = helper.object.begin(); i != helper.object.end(); ++i) {
512
513 out << i->first;
514
515 i->second.getProperties(helper.equation).write(out);
516
517 out << std::endl;
518 }
519
520 return out;
521 }
522
523 private:
526 };
527 };
528}
529
530#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Utility class to parse parameter values.
File status.
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.
void load()
Load data from file with name corresponding to current contents.
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,...