Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JFitK40.hh
Go to the documentation of this file.
1#ifndef __JCALIBRATE_JGANDALFK40__
2#define __JCALIBRATE_JGANDALFK40__
3
4#include <vector>
5#include <map>
6#include <memory>
7#include <limits>
8#include <cmath>
9
11
12#include "JLang/JException.hh"
13#include "JLang/JManip.hh"
14
15#include "Jeep/JMessage.hh"
16
17#include "JTools/JRange.hh"
18
19#include "JDetector/JModule.hh"
20
21#include "JMath/JVectorND.hh"
22#include "JMath/JMatrixNS.hh"
23#include "JMath/JMath.hh"
24#include "JMath/JGauss.hh"
25#include "JMath/JMathToolkit.hh"
26
27#include "JFit/JMEstimator.hh"
28
30#include "JCalibrate/JTDC_t.hh"
31
32
33/**
34 * \author mdejong
35 */
36
37namespace JCALIBRATE {}
38namespace JPP { using namespace JCALIBRATE; }
39
40namespace JCALIBRATE {
41
42 using KM3NETDAQ::NUMBER_OF_PMTS;
45 using JMATH::JMath;
47
48
49 /**
50 * Fit options.
51 */
52 enum JOption_t {
53 FIT_PMTS_t = 1, //!< fit parameters of PMTs
54 FIT_PMTS_AND_ANGULAR_DEPENDENCE_t = 2, //!< fit parameters of PMTs and angular dependence of K40 rate
55 FIT_PMTS_AND_BACKGROUND_t = 3, //!< fit parameters of PMTs and background
56 FIT_PMTS_QE_FIXED_t = 4, //!< fit parameters of PMTs with QE fixed
57 FIT_MODEL_t = 5 //!< fit parameters of K40 rate and TTSs of PMTs
58 };
59
60 static const int INVALID_INDEX = -1; //!< invalid index
61
62
63 /**
64 * Data structure for measured coincidence rate of pair of PMTs.
65 */
66 struct rate_type {
67 /**
68 * Default constructor.
69 */
71 dt_ns(0.0),
72 value(0.0),
73 error(0.0)
74 {}
75
76
77 /**
78 * Constructor.
79 *
80 * \param dt_ns time difference [ns]
81 * \param value value of rate [Hz/ns]
82 * \param error error of rate [Hz/ns]
83 */
85 double value,
86 double error) :
87 dt_ns(dt_ns),
88 value(value),
90 {}
91
92 double dt_ns; //!< time difference [ns]
93 double value; //!< value of rate [Hz/ns]
94 double error; //!< error of rate [Hz/ns]
95 };
96
97
98 /**
99 * Data structure for measured coincidence rates of all pairs of PMTs in optical module.
100 */
101 struct data_type :
102 public std::map<pair_type, std::vector<rate_type> >
103 {};
104
105
106 /**
107 * Auxiliary class for fit parameter with optional limits.
108 */
110 public JMath<JParameter_t>
111 {
112 public:
113 /**
114 * Fit options.
115 */
116 enum FIT_t {
117 FREE_t = 0, //!< free
118 FIXED_t //!< fixed
119 };
120
121
122 /**
123 * Type definition for range of parameter values.
124 */
126
127
128 /**
129 * Default constructor.
130 */
132 {
133 set(0.0);
134 }
135
136
137 /**
138 * Constructor.
139 *
140 * \param value value
141 * \param range range
142 */
143 JParameter_t(const double value,
145 range(range)
146 {
147 set(value);
148 }
149
150
151 /**
152 * Negate parameter.
153 *
154 * \return this parameter
155 */
157 {
158 set(-get());
159
160 return *this;
161 }
162
163
164 /**
165 * Add parameter.
166 *
167 * \param parameter parameter
168 * \return this parameter
169 */
170 JParameter_t& add(const JParameter_t& parameter)
171 {
172 set(get() + parameter.get());
173
174 return *this;
175 }
176
177
178 /**
179 * Subtract parameter.
180 *
181 * \param parameter parameter
182 * \return this parameter
183 */
184 JParameter_t& sub(const JParameter_t& parameter)
185 {
186 set(get() - parameter.get());
187
188 return *this;
189 }
190
191
192 /**
193 * Scale parameter.
194 *
195 * \param factor multiplication factor
196 * \return this parameter
197 */
198 JParameter_t& mul(const double factor)
199 {
200 set(get() * factor);
201
202 return *this;
203 }
204
205
206 /**
207 * Scale parameter.
208 *
209 * \param factor division factor
210 * \return this parameter
211 */
212 JParameter_t& div(const double factor)
213 {
214 set(get() / factor);
215
216 return *this;
217 }
218
219
220 /**
221 * Scale parameter.
222 *
223 * \param first first parameter
224 * \param second second parameter
225 * \return this parameter
226 */
227 JParameter_t& mul(const JParameter_t& first, const JParameter_t& second)
228 {
229 set(first.get() * second.get());
230
231 return *this;
232 }
233
234
235 /**
236 * Check if parameter is free.
237 *
238 * \return true if free; else false
239 */
240 bool isFree() const
241 {
242 return option == FREE_t;
243 }
244
245
246 /**
247 * Check if parameter is fixed.
248 *
249 * \return true if fixed; else false
250 */
251 bool isFixed() const
252 {
253 return option == FIXED_t;
254 }
255
256
257 /**
258 * Check if parameter is bound.
259 *
260 * \return true if bound; else false
261 */
262 bool isBound() const
263 {
264 return range.is_valid();
265 }
266
267
268 /**
269 * Set current value.
270 */
271 void set()
272 {
273 option = FREE_t;
274 }
275
276
277 /**
278 * Fix current value.
279 */
280 void fix()
281 {
282 option = FIXED_t;
283 }
284
285
286 /**
287 * Get value.
288 *
289 * \return value
290 */
291 double get() const
292 {
293 if (isBound())
294 return range.getLowerLimit() + 0.5 * range.getLength() * (sin(value) + 1.0);
295 else
296 return value;
297 }
298
299
300 /**
301 * Set value.
302 *
303 * \param value value
304 */
305 void set(const double value)
306 {
307 if (isBound())
308 this->value = asin(2.0 * (range.constrain(value) - range.getLowerLimit()) / range.getLength() - 1.0);
309 else
310 this->value = value;
311
312 set();
313 }
314
315
316 /**
317 * Set range.
318 *
319 * \param xmin minimal value
320 * \param xmax maximal value
321 */
322 void setRange(const double xmin, const double xmax)
323 {
324 const double x = get();
325
326 range = range_type(xmin, xmax);
327
328 set(x);
329 }
330
331
332 /**
333 * Check if parameter is at limit;.
334 *
335 * \param precision precision
336 * \return true if at limit; else false
337 */
338 bool atLimit(const double precision) const
339 {
340 if (isBound())
341 return (get() - range.getLowerLimit() <= precision ||
342 range.getUpperLimit() - get() <= precision);
343 else
344 return false;
345 }
346
347
348 /**
349 * Fix value.
350 *
351 * \param value value
352 */
353 void fix(const double value)
354 {
355 set(value);
356
357 fix();
358 }
359
360
361 /**
362 * Get derivative of value.
363 *
364 * \return derivative of value
365 */
366 double getDerivative() const
367 {
368 if (isBound())
369 return 1.0 / (0.5 * range.getLength() * cos(value));
370 else
371 return 1.0;
372 }
373
374
375 /**
376 * Type conversion operator.
377 *
378 * \return value
379 */
380 double operator()() const
381 {
382 return get();
383 }
384
385
386 /**
387 * Type conversion operator.
388 *
389 * \return value
390 */
391 operator double() const
392 {
393 return get();
394 }
395
396
397 /**
398 * Assignment operator.
399 *
400 * \param value value
401 * \return this parameter
402 */
404 {
405 set(value);
406
407 return *this;
408 }
409
410
411 /**
412 * Read parameter from input stream.
413 *
414 * \param in input stream
415 * \param object parameter
416 * \return input stream
417 */
418 friend inline std::istream& operator>>(std::istream& in, JParameter_t& object)
419 {
420 return in >> object.value;
421 }
422
423
424 /**
425 * Write parameter to output stream.
426 *
427 * \param out output stream
428 * \param object parameter
429 * \return output stream
430 */
431 friend inline std::ostream& operator<<(std::ostream& out, const JParameter_t& object)
432 {
433 using namespace std;
434
435 out << FIXED(12,6) << object.get() << ' '
436 << setw(5) << (object.isFixed() ? "fixed" : " ") << ' ';
437
438 if (object.isBound()) {
439 out << FIXED(12,6) << object.value << ' ';
440 out << FIXED(12,6) << object.range.getLowerLimit() << ' '
441 << FIXED(12,6) << object.range.getUpperLimit();
442 }
443
444 return out;
445 }
446
447
448 double value = 0.0;
451 };
452
453
454 /**
455 * Fit parameters for single PMT.
456 */
458
459 static constexpr double QE_MIN = 0.0; //!< minimal QE
460 static constexpr double QE_MAX = 2.0; //!< maximal QE
461 static constexpr double TTS_NS = 2.0; //!< start value transition-time spread [ns]
462
463 /**
464 * Default constructor.
465 */
467 {
468 reset();
469 }
470
471
472 /**
473 * Get default values.
474 *
475 * \return parameters
476 */
478 {
479 static JPMTParameters_t parameters;
480
482
483 parameters.status = true;
484
485 parameters.QE .set(1.0);
486 parameters.TTS.set(TTS_NS);
487 parameters.t0 .set(0.0);
488 parameters.bg .set(0.0);
489
490 return parameters;
491 }
492
493
494 /**
495 * Reset.
496 */
497 void reset()
498 {
499 status = true;
500
501 QE .set(0.0);
502 TTS.set(0.0);
503 t0 .set(0.0);
504 bg .set(0.0);
505 }
506
507
508 /**
509 * Set parameters that are free to given values.
510 *
511 * \param parameters parameters
512 */
513 void set(const JPMTParameters_t& parameters)
514 {
515 if (QE .isFree()) { QE .set(parameters.QE); }
516 if (TTS.isFree()) { TTS.set(parameters.TTS); }
517 if (t0 .isFree()) { t0 .set(parameters.t0); }
518 if (bg .isFree()) { bg .set(parameters.bg); }
519 }
520
521
522 /**
523 * Get number of fit parameters.
524 *
525 * \return number of parameters
526 */
527 inline size_t getN() const
528 {
529 return ((QE. isFree() ? 1 : 0) +
530 (TTS.isFree() ? 1 : 0) +
531 (t0 .isFree() ? 1 : 0) +
532 (bg .isFree() ? 1 : 0));
533 }
534
535
536 /**
537 * Get index of parameter.
538 *
539 * \param p pointer to data member
540 * \return index
541 */
543 {
544 if (!(this->*p).isFree()) {
545 return INVALID_INDEX;
546 }
547
548 int N = 0;
549
550 if (p == &JPMTParameters_t::QE ) { return N; }; if (QE .isFree()) { ++N; }
551 if (p == &JPMTParameters_t::TTS) { return N; }; if (TTS.isFree()) { ++N; }
552 if (p == &JPMTParameters_t::t0 ) { return N; }; if (t0 .isFree()) { ++N; }
553 if (p == &JPMTParameters_t::bg ) { return N; }; if (bg .isFree()) { ++N; }
554
555 return INVALID_INDEX;
556 }
557
558
559 /**
560 * Disable PMT.
561 */
562 void disable()
563 {
564 status = false;
565
566 QE .fix(0.0);
567 TTS.fix(TTS_NS);
568 t0 .fix(0.0);
569 bg .fix(0.0);
570 }
571
572
573 /**
574 * Enable PMT.
575 */
576 void enable()
577 {
578 status = true;
579
580 QE .set();
581 TTS.set();
582 t0 .set();
583 bg .set();
584 }
585
586
587 /**
588 * Write PMT parameters to output stream.
589 *
590 * \param out output stream
591 * \param object PMT parameters
592 * \return output stream
593 */
594 friend inline std::ostream& operator<<(std::ostream& out, const JPMTParameters_t& object)
595 {
596 using namespace std;
597
598 out << "QE " << FIXED(7,3) << object.QE << endl;
599 out << "TTS " << FIXED(7,3) << object.TTS << endl;
600 out << "t0 " << FIXED(7,3) << object.t0 << endl;
601 out << "bg " << FIXED(7,3) << object.bg << endl;
602
603 return out;
604 }
605
606
607 bool status; //!< status
608 JParameter_t QE; //!< relative quantum efficiency [unit]
609 JParameter_t TTS; //!< transition-time spread [ns]
610 JParameter_t t0; //!< time offset [ns]
611 JParameter_t bg; //!< background [Hz/ns]
612 };
613
614
615 /**
616 * Fit parameters for two-fold coincidence rate due to K40.
617 */
619 /**
620 * Default constructor.
621 */
623 {
624 reset();
625 }
626
627
628 /**
629 * Get K40 parameters.
630 *
631 * \return K40 parameters
632 */
634 {
635 return static_cast<const JK40Parameters_t&>(*this);
636 }
637
638
639 /**
640 * Set K40 parameters.
641 *
642 * \param parameters K40 parameters
643 */
644 void setK40Parameters(const JK40Parameters_t& parameters)
645 {
646 static_cast<JK40Parameters_t&>(*this) = parameters;
647 }
648
649
650 /**
651 * Reset.
652 */
653 void reset()
654 {
655 R .set(0.0);
656 p1.set(0.0);
657 p2.set(0.0);
658 p3.set(0.0);
659 p4.set(0.0);
660 cc.set(0.0);
661 }
662
663
664 JParameter_t R; //!< maximal coincidence rate [Hz]
665 JParameter_t p1; //!< 1st order angle dependence coincidence rate
666 JParameter_t p2; //!< 2nd order angle dependence coincidence rate
667 JParameter_t p3; //!< 3rd order angle dependence coincidence rate
668 JParameter_t p4; //!< 4th order angle dependence coincidence rate
669 JParameter_t cc; //!< fraction of signal correlated background
670 };
671
672
673 /**
674 * Fit parameters for two-fold coincidence rate due to K40.
675 */
678 {
679 /**
680 * Default constructor.
681 */
684
685
686 /**
687 * Get default values.
688 *
689 * The default parameter values are set to those obtained from a designated simulation
690 * of K40 decays (see http://wiki.km3net.de/index.php/OMGsim_simulations_for_K40_fit).\n
691 * If you change these values, you may also want to change the corresponding values in JK40DefaultSimulator.hh.
692 *
693 * \return parameters
694 */
696 {
697 static JK40Parameters parameters;
698
699 parameters.R .set(18.460546);
700 parameters.p1.set( 3.0767);
701 parameters.p2.set(-1.2078);
702 parameters.p3.set( 0.9905);
703 parameters.p4.set( 0.9379);
704 parameters.cc.set( 0.0);
705
706 return parameters;
707 }
708
709
710 /**
711 * Get number of fit parameters.
712 *
713 * \return number of parameters
714 */
715 inline size_t getN() const
716 {
717 return ((R .isFree() ? 1 : 0) +
718 (p1.isFree() ? 1 : 0) +
719 (p2.isFree() ? 1 : 0) +
720 (p3.isFree() ? 1 : 0) +
721 (p4.isFree() ? 1 : 0) +
722 (cc.isFree() ? 1 : 0));
723 }
724
725
726 /**
727 * Get index of parameter.
728 *
729 * \param p pointer to data member
730 * \return index
731 */
733 {
734 if (!(this->*p).isFree()) {
735 return INVALID_INDEX;
736 }
737
738 int N = 0;
739
740 if (p == &JK40Parameters::R) { return N; } if (R .isFree()) { ++N; }
741 if (p == &JK40Parameters::p1) { return N; } if (p1.isFree()) { ++N; }
742 if (p == &JK40Parameters::p2) { return N; } if (p2.isFree()) { ++N; }
743 if (p == &JK40Parameters::p3) { return N; } if (p3.isFree()) { ++N; }
744 if (p == &JK40Parameters::p4) { return N; } if (p4.isFree()) { ++N; }
745 if (p == &JK40Parameters::cc) { return N; } if (cc.isFree()) { ++N; }
746
747 return INVALID_INDEX;
748 }
749
750
751 /**
752 * Get K40 coincidence rate as a function of cosine angle between PMT axes.
753 *
754 * \param ct cosine angle between PMT axes
755 * \return rate [Hz]
756 */
757 double getValue(const double ct) const
758 {
759 return R * exp(ct*(p1+ct*(p2+ct*(p3+ct*p4))) - (p1+p2+p3+p4));
760 }
761
762
763 /**
764 * Get gradient.
765 *
766 * \param ct cosine angle between PMT axes
767 * \return gradient
768 */
769 const JK40Parameters_t& getGradient(const double ct) const
770 {
771 gradient.reset();
772
773 const double rate = getValue(ct);
774 const double ct2 = ct * ct;
775
776 if (R .isFree()) { gradient.R = rate / R; }
777 if (p1.isFree()) { gradient.p1 = rate * ct - rate; }
778 if (p2.isFree()) { gradient.p2 = rate * ct2 - rate; }
779 if (p3.isFree()) { gradient.p3 = rate * ct2 * ct - rate; }
780 if (p4.isFree()) { gradient.p4 = rate * ct2 * ct2 - rate; }
781 if (cc.isFree()) { gradient.cc = rate; }
782
783 return gradient;
784 }
785
786 private:
788 };
789
790
791 /**
792 * Fit model.
793 */
794 struct JModel_t :
795 public JK40Parameters
796 {
798
799
800 /**
801 * Write model parameters to output stream.
802 *
803 * \param out output stream
804 * \param object model parameters
805 * \return output stream
806 */
807 friend inline std::ostream& operator<<(std::ostream& out, const JModel_t& object)
808 {
809 using namespace std;
810
811 out << "Rate [Hz] " << FIXED(12,6) << object.R << endl;
812 out << "p1 " << FIXED(12,6) << object.p1 << endl;
813 out << "p2 " << FIXED(12,6) << object.p2 << endl;
814 out << "p3 " << FIXED(12,6) << object.p3 << endl;
815 out << "p4 " << FIXED(12,6) << object.p4 << endl;
816 out << "cc " << FIXED(12,6) << object.cc << endl;
817
818 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
819 out << "PMT[" << FILL(2,'0') << i << FILL() << "]." << object.parameters[i].status << endl << object.parameters[i];
820 }
821
822 return out;
823 }
824 };
825
826
827 /**
828 * Fit model.
829 *
830 * In the absence of TDC constraints, the average time offset is fixed to zero.
831 */
832 struct JModel :
833 public JModel_t,
834 public JModule,
835 public JCombinatorics_t
836 {
840
841
842 /**
843 * Auxiliary data structure for derived quantities of a given PMT pair.
844 */
845 struct real_type {
846 double ct; //!< cosine angle between PMT axes
847 double t0; //!< time offset [ns]
848 double sigma; //!< total width [ns]
849 double signal; //!< combined signal
850 double background; //!< combined background
851 double cc; //!< correlated background
852 };
853
854
855 /**
856 * Default constructor.
857 */
859 {}
860
861
862 /**
863 * Constructor.
864 *
865 * \param module detector module
866 * \param parameters K40 parameters
867 * \param TDC TDC constraints
868 * \param option option
869 */
870 JModel(const JModule& module,
872 const JTDC_t::range_type& TDC,
873 const int option) :
874 JModule (module),
875 JCombinatorics_t(module)
876 {
878
879 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
880 this->parameters[i] = JPMTParameters_t::getInstance();
881 }
882
883 for (JTDC_t::const_iterator i = TDC.first; i != TDC.second; ++i) {
884
885 if (i->second != JTDC_t::WILDCARD) {
886
887 this->parameters[i->second].t0.fix();
888
889 } else {
890
891 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
892 this->parameters[i].t0.fix();
893 }
894 }
895 }
896
897 this->index = (TDC.first == TDC.second ? 0 : INVALID_INDEX);
898
900 }
901
902
903 /**
904 * Constructor.
905 *
906 * \param module detector module
907 * \param parameters K40 parameters
908 */
909 JModel(const JModule& module,
910 const JK40Parameters& parameters) :
911 JModule (module),
912 JCombinatorics_t(module)
913 {
915
916 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
917 this->parameters[i] = JPMTParameters_t::getInstance();
918 }
919 }
920
921
922 /**
923 * Get fit option.
924 *
925 * \return option
926 */
928 {
929 return option;
930 }
931
932
933 /**
934 * Set fit option.
935 *
936 * \param option option
937 */
938 inline void setOption(const int option)
939 {
940 switch (option) {
941
942 case FIT_PMTS_t:
943
944 R .fix();
945 p1.fix();
946 p2.fix();
947 p3.fix();
948 p4.fix();
949
950 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
951 parameters[i].bg.fix();
952 }
953
954 break;
955
957
958 R .fix();
959
960 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
961 parameters[i].bg.fix();
962 }
963
964 break;
965
967
968 R .fix();
969 p1.fix();
970 p2.fix();
971 p3.fix();
972 p4.fix();
973
974 break;
975
977
978 R .fix();
979 p1.fix();
980 p2.fix();
981 p3.fix();
982 p4.fix();
983
984 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
985 parameters[i].QE.fix();
986 parameters[i].bg.fix();
987 }
988
989 break;
990
991 case FIT_MODEL_t:
992
993 cc.fix();
994
995 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
996 parameters[i].QE.fix();
997 parameters[i].t0.fix();
998 parameters[i].bg.fix();
999 }
1000
1001 break;
1002
1003 default:
1004
1005 THROW(JValueOutOfRange, "Invalid option " << option);
1006 }
1007
1008 this->option = static_cast<JOption_t>(option);
1009 }
1010
1011
1012 /**
1013 * Check if time offset is fixed.
1014 *
1015 * \return true if time offset fixed; else false
1016 */
1018 {
1019 return index != INVALID_INDEX;
1020 }
1021
1022
1023 /**
1024 * Get time offset.
1025 *
1026 * \return time offset
1027 */
1028 double getFixedTimeOffset() const
1029 {
1030 double t0 = 0.0;
1031 size_t N = 0;
1032
1033 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
1034 if (parameters[i].t0.isFree()) {
1035 t0 += parameters[i].t0;
1036 N += 1;
1037 }
1038 }
1039
1040 return t0 /= N;
1041 }
1042
1043
1044 /**
1045 * Get index of PMT used for fixed time offset.
1046 *
1047 * \return index
1048 */
1049 int getIndex() const
1050 {
1051 return index;
1052 }
1053
1054
1055 /**
1056 * Set index of PMT used for fixed time offset.
1057 */
1059 {
1060 if (index != INVALID_INDEX) {
1061
1062 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
1063
1064 if (parameters[i].status) {
1065
1066 index = i;
1067
1069
1070 return;
1071 }
1072 }
1073
1074 THROW(JValueOutOfRange, "No valid index.");
1075 }
1076 }
1077
1078
1079 /**
1080 * Get number of fit parameters.
1081 *
1082 * \return number of parameters
1083 */
1084 inline size_t getN() const
1085 {
1086 size_t N = JK40Parameters::getN();
1087
1088 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
1089 N += parameters[i].getN();
1090 }
1091
1092 return N;
1093 }
1094
1095
1096 /**
1097 * Get index of parameter.
1098 *
1099 * \param pmt PMT
1100 * \return index
1101 */
1102 int getIndex(int pmt) const
1103 {
1104 int N = JK40Parameters::getN();
1105
1106 for (int i = 0; i != pmt; ++i) {
1107 N += parameters[i].getN();
1108 }
1109
1110 return N;
1111 }
1112
1113
1114 /**
1115 * Get index of parameter.
1116 *
1117 * \param pmt PMT
1118 * \param p pointer to data member
1119 * \return index
1120 */
1122 {
1123 return getIndex(pmt) + parameters[pmt].getIndex(p);
1124 }
1125
1126
1127 /**
1128 * Get intrinsic K40 arrival time spread.
1129 *
1130 * \return sigma [ns]
1131 */
1132 double getSigmaK40() const
1133 {
1134 return this->sigmaK40_ns;
1135 }
1136
1137
1138 /**
1139 * Set intrinsic K40 arrival time spread.
1140 *
1141 * \param sigma sigma [ns]
1142 */
1143 void setSigmaK40(const double sigma)
1144 {
1145 this->sigmaK40_ns = sigma;
1146 }
1147
1148
1149 /**
1150 * Get derived parameters.
1151 *
1152 * \param pair PMT pair
1153 * \return parameters
1154 */
1155 const real_type& getReal(const pair_type& pair) const
1156 {
1157 real.ct = JPP::getDot((*this)[pair.first].getDirection(), (*this)[pair.second].getDirection());
1158
1159 real.t0 = (pair.first == this->index ? -this->parameters[pair.second].t0() :
1160 pair.second == this->index ? +this->parameters[pair.first ].t0() :
1161 this->parameters[pair.first].t0() - this->parameters[pair.second].t0());
1162
1163 real.sigma = sqrt(this->parameters[pair.first ].TTS() * this->parameters[pair.first ].TTS() +
1164 this->parameters[pair.second].TTS() * this->parameters[pair.second].TTS() +
1165 this->getSigmaK40() * this->getSigmaK40());
1166
1167 real.signal = this->parameters[pair.first].QE() * this->parameters[pair.second].QE();
1168
1169 real.background = this->parameters[pair.first].bg() + this->parameters[pair.second].bg();
1170
1171 real.cc = real.signal * this->cc();
1172
1173 return real;
1174 }
1175
1176
1177 /**
1178 * Get K40 coincidence rate.
1179 *
1180 * \param pair PMT pair
1181 * \param dt_ns time difference [ns]
1182 * \return rate [Hz/ns]
1183 */
1184 double getValue(const pair_type& pair, const double dt_ns) const
1185 {
1186 using namespace std;
1187 using namespace JPP;
1188
1189 const real_type& real = getReal(pair);
1190
1191 const JGauss gauss(real.t0, real.sigma, real.signal);
1192
1193 const double R1 = this->getValue(real.ct);
1194 const double R2 = gauss.getValue(dt_ns);
1195
1196 return real.background + R1 * (real.cc + R2);
1197 }
1198
1199
1200 /**
1201 * Get K40 coincidence rate.
1202 *
1203 * \param pair PMT pair
1204 * \return rate [Hz]
1205 */
1206 double getValue(const pair_type& pair) const
1207 {
1208 using namespace std;
1209 using namespace JPP;
1210
1211 const real_type& real = getReal(pair);
1212
1213 const double R1 = this->getValue(real.ct);
1214 const double R2 = real.signal;
1215
1216 return real.background + R1 * (cc() + R2);
1217 }
1218
1219
1220 /**
1221 * Write model parameters to output stream.
1222 *
1223 * \param out output stream
1224 * \param object model parameters
1225 * \return output stream
1226 */
1227 friend inline std::ostream& operator<<(std::ostream& out, const JModel& object)
1228 {
1229 using namespace std;
1230
1231 out << "Module " << setw(10) << object.getID() << endl;
1232 out << "option " << object.option << endl;
1233 out << "index " << object.index << endl;
1234
1235 out << static_cast<const JModel_t&>(object);
1236
1237 return out;
1238 }
1239
1240 private:
1241 int index; //!< index of PMT used for fixed time offset
1242 double sigmaK40_ns = 0.54; //!< intrinsic K40 arrival time spread [ns]
1245 };
1246
1247
1248 /**
1249 * Fit.
1250 */
1251 class JFit
1252 {
1253 public:
1254 /**
1255 * Result type.
1256 */
1258 double chi2;
1259 int ndf;
1260 };
1261
1262 typedef std::shared_ptr<JMEstimator> estimator_type;
1263
1264
1265 /**
1266 * Constructor
1267 *
1268 * \param option M-estimator
1269 * \param debug debug
1270 */
1271 JFit(const int option, const int debug) :
1272 debug(debug)
1273 {
1274 using namespace JPP;
1275
1276 estimator.reset(getMEstimator(option));
1277 }
1278
1279
1280 /**
1281 * Fit.
1282 *
1283 * \param data data
1284 * \return chi2, NDF
1285 */
1287 {
1288 using namespace std;
1289 using namespace JPP;
1290
1291
1292 value.setIndex();
1293
1294 const size_t N = value.getN();
1295
1296 V.resize(N);
1297 Y.resize(N);
1298 h.resize(N);
1299
1300 double xmax = numeric_limits<double>::lowest();
1301 double xmin = numeric_limits<double>::max();
1302
1303 int ndf = 0;
1304
1305 for (data_type::const_iterator ix = data.begin(); ix != data.end(); ++ix) {
1306
1307 const pair_type& pair = ix->first;
1308
1309 if (value.parameters[pair.first ].status &&
1310 value.parameters[pair.second].status) {
1311
1312 ndf += ix->second.size();
1313
1314 for (const rate_type& iy : ix->second) {
1315 if (iy.dt_ns > xmax) { xmax = iy.dt_ns; }
1316 if (iy.dt_ns < xmin) { xmin = iy.dt_ns; }
1317 }
1318 }
1319 }
1320
1321 ndf -= value.getN();
1322
1323 if (ndf < 0) {
1324 return { 0.0, ndf };
1325 }
1326
1327 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
1328 if (value.parameters[pmt].t0.isFree()) {
1329 value.parameters[pmt].t0.setRange(xmin, xmax);
1330 }
1331 }
1332
1333
1335
1336 double precessor = numeric_limits<double>::max();
1337
1339
1340 DEBUG("step: " << numberOfIterations << endl);
1341
1342 evaluate(data);
1343
1344 DEBUG("lambda: " << FIXED(12,5) << lambda << endl);
1345 DEBUG("chi2: " << FIXED(12,3) << successor << endl);
1346
1347 if (successor < precessor) {
1348
1349 if (numberOfIterations != 0) {
1350
1351 if (fabs(precessor - successor) < EPSILON) {
1352
1353 seterr(data);
1354
1355 return { successor / estimator->getRho(1.0), ndf };
1356 }
1357
1358 if (lambda > LAMBDA_MIN) {
1360 }
1361 }
1362
1363 precessor = successor;
1364 previous = value;
1365
1366 } else {
1367
1368 value = previous;
1369 lambda *= LAMBDA_UP;
1370
1371 if (lambda > LAMBDA_MAX) {
1372 break;
1373 }
1374
1375 evaluate(data);
1376 }
1377
1378 if (debug >= debug_t) {
1379
1380 size_t row = 0;
1381
1382 if (value.R .isFree()) { cout << "R " << FIXED(12,5) << Y[row] << endl; ++row; }
1383 if (value.p1.isFree()) { cout << "p1 " << FIXED(12,5) << Y[row] << endl; ++row; }
1384 if (value.p2.isFree()) { cout << "p2 " << FIXED(12,5) << Y[row] << endl; ++row; }
1385 if (value.p3.isFree()) { cout << "p3 " << FIXED(12,5) << Y[row] << endl; ++row; }
1386 if (value.p4.isFree()) { cout << "p4 " << FIXED(12,5) << Y[row] << endl; ++row; }
1387 if (value.cc.isFree()) { cout << "cc " << FIXED(12,3) << Y[row] << endl; ++row; }
1388
1389 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
1390 if (value.parameters[pmt].QE .isFree()) { cout << "PMT[" << setw(2) << pmt << "].QE " << FIXED(12,5) << Y[row] << endl; ++row; }
1391 if (value.parameters[pmt].TTS.isFree()) { cout << "PMT[" << setw(2) << pmt << "].TTS " << FIXED(12,5) << Y[row] << endl; ++row; }
1392 if (value.parameters[pmt].t0 .isFree()) { cout << "PMT[" << setw(2) << pmt << "].t0 " << FIXED(12,5) << Y[row] << endl; ++row; }
1393 if (value.parameters[pmt].bg .isFree()) { cout << "PMT[" << setw(2) << pmt << "].bg " << FIXED(12,5) << Y[row] << endl; ++row; }
1394 }
1395 }
1396
1397 // force definite positiveness
1398
1399 for (size_t i = 0; i != N; ++i) {
1400
1401 if (V(i,i) < PIVOT) {
1402 V(i,i) = PIVOT;
1403 }
1404
1405 h[i] = 1.0 / sqrt(V(i,i));
1406 }
1407
1408 // normalisation
1409
1410 for (size_t i = 0; i != N; ++i) {
1411 for (size_t j = 0; j != i; ++j) {
1412 V(j,i) *= h[i] * h[j];
1413 V(i,j) = V(j,i);
1414 }
1415 }
1416
1417 for (size_t i = 0; i != N; ++i) {
1418 V(i,i) = 1.0 + lambda;
1419 }
1420
1421 // solve A x = b
1422
1423 for (size_t col = 0; col != N; ++col) {
1424 Y[col] *= h[col];
1425 }
1426
1427 try {
1428 V.solve(Y);
1429 }
1430 catch (const exception& error) {
1431
1432 ERROR("JGandalf: " << error.what() << endl << V << endl);
1433
1434 break;
1435 }
1436
1437 // update value
1438
1439 const double factor = 2.0;
1440
1441 size_t row = 0;
1442
1443 if (value.R .isFree()) { value.R -= factor * h[row] * Y[row]; ++row; }
1444 if (value.p1.isFree()) { value.p1 -= factor * h[row] * Y[row]; ++row; }
1445 if (value.p2.isFree()) { value.p2 -= factor * h[row] * Y[row]; ++row; }
1446 if (value.p3.isFree()) { value.p3 -= factor * h[row] * Y[row]; ++row; }
1447 if (value.p4.isFree()) { value.p4 -= factor * h[row] * Y[row]; ++row; }
1448 if (value.cc.isFree()) { value.cc -= factor * h[row] * Y[row]; ++row; }
1449
1450 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
1451 if (value.parameters[pmt].QE .isFree()) { value.parameters[pmt].QE -= factor * h[row] * Y[row]; ++row; }
1452 if (value.parameters[pmt].TTS.isFree()) { value.parameters[pmt].TTS -= factor * h[row] * Y[row]; ++row; }
1453 if (value.parameters[pmt].t0 .isFree()) { value.parameters[pmt].t0 -= factor * h[row] * Y[row]; ++row; }
1454 if (value.parameters[pmt].bg .isFree()) { value.parameters[pmt].bg -= factor * h[row] * Y[row]; ++row; }
1455 }
1456 }
1457
1458 seterr(data);
1459
1460 return { precessor / estimator->getRho(1.0), ndf };
1461 }
1462
1463
1464 static constexpr int MAXIMUM_ITERATIONS = 100000; //!< maximal number of iterations.
1465 static constexpr double EPSILON = 1.0e-3; //!< maximal distance to minimum.
1466 static constexpr double LAMBDA_MIN = 1.0e-2; //!< minimal value control parameter
1467 static constexpr double LAMBDA_MAX = 1.0e+4; //!< maximal value control parameter
1468 static constexpr double LAMBDA_UP = 10.0; //!< multiplication factor control parameter
1469 static constexpr double LAMBDA_DOWN = 10.0; //!< multiplication factor control parameter
1470 static constexpr double PIVOT = std::numeric_limits<double>::epsilon(); //!< minimal value diagonal element of matrix
1471
1473 estimator_type estimator; //!< M-Estimator function
1474
1475 double lambda;
1480
1481 private:
1482 /**
1483 * Evaluation of fit.
1484 *
1485 * \param data data
1486 */
1487 void evaluate(const data_type& data)
1488 {
1489 using namespace std;
1490 using namespace JPP;
1491
1492 typedef JModel::real_type real_type;
1493
1494
1495 successor = 0.0;
1496
1497 V.reset();
1498 Y.reset();
1499
1500
1501 // model parameter indices
1502
1503 const struct M_t {
1504 M_t(const JModel& model)
1505 {
1506 R = model.getIndex(&JK40Parameters_t::R);
1507 p1 = model.getIndex(&JK40Parameters_t::p1);
1508 p2 = model.getIndex(&JK40Parameters_t::p2);
1509 p3 = model.getIndex(&JK40Parameters_t::p3);
1510 p4 = model.getIndex(&JK40Parameters_t::p4);
1511 cc = model.getIndex(&JK40Parameters_t::cc);
1512 }
1513
1514 int R;
1515 int p1;
1516 int p2;
1517 int p3;
1518 int p4;
1519 int cc;
1520
1521 } M(value);
1522
1523
1524 // PMT parameter indices
1525
1526 struct I_t {
1527 I_t(const JModel& model, const int pmt) :
1528 QE (INVALID_INDEX),
1529 TTS(INVALID_INDEX),
1530 t0 (INVALID_INDEX),
1531 bg (INVALID_INDEX)
1532 {
1533 const int index = model.getIndex(pmt);
1534
1535 int N = 0;
1536
1537 if (model.parameters[pmt].QE .isFree()) { QE = index + N; ++N; }
1538 if (model.parameters[pmt].TTS.isFree()) { TTS = index + N; ++N; }
1539 if (model.parameters[pmt].t0 .isFree()) { t0 = index + N; ++N; }
1540 if (model.parameters[pmt].bg .isFree()) { bg = index + N; ++N; }
1541 }
1542
1543 int QE;
1544 int TTS;
1545 int t0;
1546 int bg;
1547 };
1548
1549
1551
1552 buffer_type buffer;
1553
1554 for (data_type::const_iterator ix = data.begin(); ix != data.end(); ++ix) {
1555
1556 const pair_type& pair = ix->first;
1557
1558 if (value.parameters[pair.first ].status &&
1559 value.parameters[pair.second].status) {
1560
1561 const real_type& real = value.getReal(pair);
1562
1563 const JGauss gauss(real.t0, real.sigma, real.signal);
1564
1565 const double R1 = value.getValue (real.ct);
1566 const JK40Parameters_t& R1p = value.getGradient(real.ct);
1567
1568 const std::pair<I_t, I_t> PMT(I_t(value, pair.first),
1569 I_t(value, pair.second));
1570
1571 for (const rate_type& iy : ix->second) {
1572
1573 const double R2 = gauss.getValue (iy.dt_ns);
1574 const JGauss& R2p = gauss.getGradient(iy.dt_ns);
1575
1576 const double R = real.background + R1 * (value.cc() + R2);
1577 const double u = (iy.value - R) / iy.error;
1578 const double w = -estimator->getPsi(u) / iy.error;
1579
1580 successor += estimator->getRho(u);
1581
1582 buffer.clear();
1583
1584 if (M.R != INVALID_INDEX) { buffer.push_back({M.R, w * (value.cc() + R2) * R1p.R () * value.R .getDerivative()}); }
1585 if (M.p1 != INVALID_INDEX) { buffer.push_back({M.p1, w * (value.cc() + R2) * R1p.p1() * value.p1.getDerivative()}); }
1586 if (M.p2 != INVALID_INDEX) { buffer.push_back({M.p2, w * (value.cc() + R2) * R1p.p2() * value.p2.getDerivative()}); }
1587 if (M.p3 != INVALID_INDEX) { buffer.push_back({M.p3, w * (value.cc() + R2) * R1p.p3() * value.p3.getDerivative()}); }
1588 if (M.p4 != INVALID_INDEX) { buffer.push_back({M.p4, w * (value.cc() + R2) * R1p.p4() * value.p4.getDerivative()}); }
1589 if (M.cc != INVALID_INDEX) { buffer.push_back({M.cc, w * R1 * R1p.cc() * value.cc.getDerivative()}); }
1590
1591 if (PMT.first .QE != INVALID_INDEX) { buffer.push_back({PMT.first .QE , w * R1 * R2p.signal * value.parameters[pair.second].QE () * value.parameters[pair.first ].QE .getDerivative()}); }
1592 if (PMT.second.QE != INVALID_INDEX) { buffer.push_back({PMT.second.QE , w * R1 * R2p.signal * value.parameters[pair.first ].QE () * value.parameters[pair.second].QE .getDerivative()}); }
1593 if (PMT.first .TTS != INVALID_INDEX) { buffer.push_back({PMT.first .TTS, w * R1 * R2p.sigma * value.parameters[pair.first ].TTS() * value.parameters[pair.first ].TTS.getDerivative() / real.sigma}); }
1594 if (PMT.second.TTS != INVALID_INDEX) { buffer.push_back({PMT.second.TTS, w * R1 * R2p.sigma * value.parameters[pair.second].TTS() * value.parameters[pair.second].TTS.getDerivative() / real.sigma}); }
1595 if (PMT.first .t0 != INVALID_INDEX) { buffer.push_back({PMT.first .t0, w * R1 * R2p.mean * value.parameters[pair.first ].t0 .getDerivative() * +1.0}); }
1596 if (PMT.second.t0 != INVALID_INDEX) { buffer.push_back({PMT.second.t0, w * R1 * R2p.mean * value.parameters[pair.second].t0 .getDerivative() * -1.0}); }
1597 if (PMT.first .bg != INVALID_INDEX) { buffer.push_back({PMT.first .bg, w * value.parameters[pair.first ].bg .getDerivative()}); }
1598 if (PMT.second.bg != INVALID_INDEX) { buffer.push_back({PMT.second.bg, w * value.parameters[pair.second].bg .getDerivative()}); }
1599
1600 for (buffer_type::const_iterator row = buffer.begin(); row != buffer.end(); ++row) {
1601
1602 Y[row->first] += row->second;
1603
1604 V[row->first][row->first] += row->second * row->second;
1605
1606 for (buffer_type::const_iterator col = buffer.begin(); col != row; ++col) {
1607 V[row->first][col->first] += row->second * col->second;
1608 V[col->first][row->first] = V[row->first][col->first];
1609 }
1610 }
1611 }
1612 }
1613 }
1614 }
1615
1616
1617 /**
1618 * Set errors.
1619 *
1620 * \param data data
1621 */
1622 void seterr(const data_type& data)
1623 {
1624 using namespace std;
1625
1626 error.reset();
1627
1628 evaluate(data);
1629
1630 try {
1631 V.invert();
1632 }
1633 catch (const exception& error) {}
1634
1635#define SQRT(X) (X >= 0.0 ? sqrt(X) : std::numeric_limits<double>::max())
1636
1637 size_t i = 0;
1638
1639 if (value.R .isFree()) { error.R = SQRT(V(i,i)); ++i; }
1640 if (value.p1.isFree()) { error.p1 = SQRT(V(i,i)); ++i; }
1641 if (value.p2.isFree()) { error.p2 = SQRT(V(i,i)); ++i; }
1642 if (value.p3.isFree()) { error.p3 = SQRT(V(i,i)); ++i; }
1643 if (value.p4.isFree()) { error.p4 = SQRT(V(i,i)); ++i; }
1644 if (value.cc.isFree()) { error.cc = SQRT(V(i,i)); ++i; }
1645
1646 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
1647 if (value.parameters[pmt].QE .isFree()) { error.parameters[pmt].QE = SQRT(V(i,i)); ++i; }
1648 if (value.parameters[pmt].TTS.isFree()) { error.parameters[pmt].TTS = SQRT(V(i,i)); ++i; }
1649 if (value.parameters[pmt].t0 .isFree()) { error.parameters[pmt].t0 = SQRT(V(i,i)); ++i; }
1650 if (value.parameters[pmt].bg .isFree()) { error.parameters[pmt].bg = SQRT(V(i,i)); ++i; }
1651 }
1652
1653#undef SQRT
1654 }
1655
1656
1657 JMATH::JVectorND Y; // gradient
1660 std::vector<double> h; // normalisation vector
1661 };
1662}
1663
1664#endif
1665
1666
JDAQPMTIdentifier PMT
Command line options.
KM3NeT DAQ constants, bit handling, etc.
TPaveText * p1
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
#define SQRT(X)
Maximum likelihood estimator (M-estimators).
I/O manipulators.
Auxiliary methods for geometrical methods.
Base class for data structures with artithmetic capabilities.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ERROR(A)
Definition JMessage.hh:66
Data structure for optical module.
Auxiliary class to define a range between two values.
std::shared_ptr< JMEstimator > estimator_type
Definition JFitK40.hh:1262
std::vector< double > h
Definition JFitK40.hh:1660
static constexpr double LAMBDA_MIN
minimal value control parameter
Definition JFitK40.hh:1466
static constexpr double LAMBDA_DOWN
multiplication factor control parameter
Definition JFitK40.hh:1469
result_type operator()(const data_type &data)
Fit.
Definition JFitK40.hh:1286
void seterr(const data_type &data)
Set errors.
Definition JFitK40.hh:1622
static constexpr double LAMBDA_MAX
maximal value control parameter
Definition JFitK40.hh:1467
static constexpr double LAMBDA_UP
multiplication factor control parameter
Definition JFitK40.hh:1468
JMATH::JMatrixNS V
Definition JFitK40.hh:1479
static constexpr double EPSILON
maximal distance to minimum.
Definition JFitK40.hh:1465
JFit(const int option, const int debug)
Constructor.
Definition JFitK40.hh:1271
void evaluate(const data_type &data)
Evaluation of fit.
Definition JFitK40.hh:1487
static constexpr int MAXIMUM_ITERATIONS
maximal number of iterations.
Definition JFitK40.hh:1464
static constexpr double PIVOT
minimal value diagonal element of matrix
Definition JFitK40.hh:1470
estimator_type estimator
M-Estimator function.
Definition JFitK40.hh:1473
JMATH::JVectorND Y
Definition JFitK40.hh:1657
Auxiliary class for fit parameter with optional limits.
Definition JFitK40.hh:111
JParameter_t & mul(const double factor)
Scale parameter.
Definition JFitK40.hh:198
void set(const double value)
Set value.
Definition JFitK40.hh:305
void fix()
Fix current value.
Definition JFitK40.hh:280
JParameter_t & sub(const JParameter_t &parameter)
Subtract parameter.
Definition JFitK40.hh:184
JParameter_t & operator=(double value)
Assignment operator.
Definition JFitK40.hh:403
bool isFree() const
Check if parameter is free.
Definition JFitK40.hh:240
friend std::ostream & operator<<(std::ostream &out, const JParameter_t &object)
Write parameter to output stream.
Definition JFitK40.hh:431
friend std::istream & operator>>(std::istream &in, JParameter_t &object)
Read parameter from input stream.
Definition JFitK40.hh:418
JParameter_t & div(const double factor)
Scale parameter.
Definition JFitK40.hh:212
JParameter_t & mul(const JParameter_t &first, const JParameter_t &second)
Scale parameter.
Definition JFitK40.hh:227
double operator()() const
Type conversion operator.
Definition JFitK40.hh:380
void set()
Set current value.
Definition JFitK40.hh:271
JParameter_t(const double value, const range_type &range=range_type::DEFAULT_RANGE())
Constructor.
Definition JFitK40.hh:143
void setRange(const double xmin, const double xmax)
Set range.
Definition JFitK40.hh:322
JParameter_t & negate()
Negate parameter.
Definition JFitK40.hh:156
JParameter_t()
Default constructor.
Definition JFitK40.hh:131
bool atLimit(const double precision) const
Check if parameter is at limit;.
Definition JFitK40.hh:338
JTOOLS::JRange< double > range_type
Type definition for range of parameter values.
Definition JFitK40.hh:125
double getDerivative() const
Get derivative of value.
Definition JFitK40.hh:366
JParameter_t & add(const JParameter_t &parameter)
Add parameter.
Definition JFitK40.hh:170
void fix(const double value)
Fix value.
Definition JFitK40.hh:353
double get() const
Get value.
Definition JFitK40.hh:291
bool isBound() const
Check if parameter is bound.
Definition JFitK40.hh:262
bool isFixed() const
Check if parameter is fixed.
Definition JFitK40.hh:251
Data structure for a composite optical module.
Definition JModule.hh:75
Exception for accessing a value in a collection that is outside of its range.
int getIndex(const int first, const int second) const
Get index of pair of indices.
Range of values.
Definition JRange.hh:42
bool is_valid() const
Check validity of range.
Definition JRange.hh:311
T getLength() const
Get length (difference between upper and lower limit).
Definition JRange.hh:289
T constrain(argument_type x) const
Constrain value to range.
Definition JRange.hh:350
static JRange< double, std::less< double > > DEFAULT_RANGE()
Definition JRange.hh:555
T getLowerLimit() const
Get lower limit.
Definition JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition JRange.hh:213
#define R1(x)
double getDot(const JNeutrinoDirection &first, const JNeutrinoDirection &second)
Dot product.
Auxiliary classes and methods for PMT calibration.
static const int INVALID_INDEX
invalid index
Definition JFitK40.hh:60
JOption_t
Fit options.
Definition JFitK40.hh:52
@ FIT_PMTS_QE_FIXED_t
fit parameters of PMTs with QE fixed
Definition JFitK40.hh:56
@ FIT_PMTS_AND_ANGULAR_DEPENDENCE_t
fit parameters of PMTs and angular dependence of K40 rate
Definition JFitK40.hh:54
@ FIT_MODEL_t
fit parameters of K40 rate and TTSs of PMTs
Definition JFitK40.hh:57
@ FIT_PMTS_AND_BACKGROUND_t
fit parameters of PMTs and background
Definition JFitK40.hh:55
@ FIT_PMTS_t
fit parameters of PMTs
Definition JFitK40.hh:53
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for sequence of same character.
Definition JManip.hh:330
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
PMT combinatorics for optical module.
Fit parameters for two-fold coincidence rate due to K40.
Definition JFitK40.hh:618
JParameter_t R
maximal coincidence rate [Hz]
Definition JFitK40.hh:664
JParameter_t p1
1st order angle dependence coincidence rate
Definition JFitK40.hh:665
JParameter_t p2
2nd order angle dependence coincidence rate
Definition JFitK40.hh:666
JParameter_t p3
3rd order angle dependence coincidence rate
Definition JFitK40.hh:667
const JK40Parameters_t & getK40Parameters() const
Get K40 parameters.
Definition JFitK40.hh:633
JParameter_t p4
4th order angle dependence coincidence rate
Definition JFitK40.hh:668
JParameter_t cc
fraction of signal correlated background
Definition JFitK40.hh:669
JK40Parameters_t()
Default constructor.
Definition JFitK40.hh:622
void setK40Parameters(const JK40Parameters_t &parameters)
Set K40 parameters.
Definition JFitK40.hh:644
Fit parameters for two-fold coincidence rate due to K40.
Definition JFitK40.hh:678
size_t getN() const
Get number of fit parameters.
Definition JFitK40.hh:715
const JK40Parameters_t & getGradient(const double ct) const
Get gradient.
Definition JFitK40.hh:769
JK40Parameters_t gradient
Definition JFitK40.hh:787
static const JK40Parameters & getInstance()
Get default values.
Definition JFitK40.hh:695
int getIndex(JParameter_t JK40Parameters::*p) const
Get index of parameter.
Definition JFitK40.hh:732
double getValue(const double ct) const
Get K40 coincidence rate as a function of cosine angle between PMT axes.
Definition JFitK40.hh:757
JK40Parameters()
Default constructor.
Definition JFitK40.hh:682
Auxiliary data structure for derived quantities of a given PMT pair.
Definition JFitK40.hh:845
double signal
combined signal
Definition JFitK40.hh:849
double sigma
total width [ns]
Definition JFitK40.hh:848
double cc
correlated background
Definition JFitK40.hh:851
double background
combined background
Definition JFitK40.hh:850
double t0
time offset [ns]
Definition JFitK40.hh:847
double ct
cosine angle between PMT axes
Definition JFitK40.hh:846
friend std::ostream & operator<<(std::ostream &out, const JModel_t &object)
Write model parameters to output stream.
Definition JFitK40.hh:807
JPMTParameters_t parameters[NUMBER_OF_PMTS]
Definition JFitK40.hh:797
JModel()
Default constructor.
Definition JFitK40.hh:858
int getIndex(int pmt, JParameter_t JPMTParameters_t::*p) const
Get index of parameter.
Definition JFitK40.hh:1121
friend std::ostream & operator<<(std::ostream &out, const JModel &object)
Write model parameters to output stream.
Definition JFitK40.hh:1227
int getIndex(int pmt) const
Get index of parameter.
Definition JFitK40.hh:1102
size_t getN() const
Get number of fit parameters.
Definition JFitK40.hh:1084
double getValue(const pair_type &pair) const
Get K40 coincidence rate.
Definition JFitK40.hh:1206
double sigmaK40_ns
intrinsic K40 arrival time spread [ns]
Definition JFitK40.hh:1242
JOption_t getOption() const
Get fit option.
Definition JFitK40.hh:927
double getFixedTimeOffset() const
Get time offset.
Definition JFitK40.hh:1028
void setSigmaK40(const double sigma)
Set intrinsic K40 arrival time spread.
Definition JFitK40.hh:1143
int getIndex() const
Get index of PMT used for fixed time offset.
Definition JFitK40.hh:1049
double getSigmaK40() const
Get intrinsic K40 arrival time spread.
Definition JFitK40.hh:1132
void setOption(const int option)
Set fit option.
Definition JFitK40.hh:938
const real_type & getReal(const pair_type &pair) const
Get derived parameters.
Definition JFitK40.hh:1155
JModel(const JModule &module, const JK40Parameters &parameters)
Constructor.
Definition JFitK40.hh:909
double getValue(const pair_type &pair, const double dt_ns) const
Get K40 coincidence rate.
Definition JFitK40.hh:1184
void setIndex()
Set index of PMT used for fixed time offset.
Definition JFitK40.hh:1058
JModel(const JModule &module, const JK40Parameters &parameters, const JTDC_t::range_type &TDC, const int option)
Constructor.
Definition JFitK40.hh:870
bool hasFixedTimeOffset() const
Check if time offset is fixed.
Definition JFitK40.hh:1017
int index
index of PMT used for fixed time offset
Definition JFitK40.hh:1241
Fit parameters for single PMT.
Definition JFitK40.hh:457
static constexpr double QE_MIN
minimal QE
Definition JFitK40.hh:459
friend std::ostream & operator<<(std::ostream &out, const JPMTParameters_t &object)
Write PMT parameters to output stream.
Definition JFitK40.hh:594
JParameter_t t0
time offset [ns]
Definition JFitK40.hh:610
static constexpr double TTS_NS
start value transition-time spread [ns]
Definition JFitK40.hh:461
JParameter_t TTS
transition-time spread [ns]
Definition JFitK40.hh:609
void disable()
Disable PMT.
Definition JFitK40.hh:562
size_t getN() const
Get number of fit parameters.
Definition JFitK40.hh:527
JPMTParameters_t()
Default constructor.
Definition JFitK40.hh:466
void set(const JPMTParameters_t &parameters)
Set parameters that are free to given values.
Definition JFitK40.hh:513
JParameter_t bg
background [Hz/ns]
Definition JFitK40.hh:611
static constexpr double QE_MAX
maximal QE
Definition JFitK40.hh:460
void enable()
Enable PMT.
Definition JFitK40.hh:576
int getIndex(JParameter_t JPMTParameters_t::*p) const
Get index of parameter.
Definition JFitK40.hh:542
static const JPMTParameters_t & getInstance()
Get default values.
Definition JFitK40.hh:477
JParameter_t QE
relative quantum efficiency [unit]
Definition JFitK40.hh:608
Data structure for measured coincidence rates of all pairs of PMTs in optical module.
Definition JFitK40.hh:103
Data structure for measured coincidence rate of pair of PMTs.
Definition JFitK40.hh:66
rate_type(double dt_ns, double value, double error)
Constructor.
Definition JFitK40.hh:84
double error
error of rate [Hz/ns]
Definition JFitK40.hh:94
double value
value of rate [Hz/ns]
Definition JFitK40.hh:93
rate_type()
Default constructor.
Definition JFitK40.hh:70
double dt_ns
time difference [ns]
Definition JFitK40.hh:92
Interface for maximum likelihood estimator (M-estimator).
Auxiliary base class for aritmetic operations of derived class types.
Definition JMath.hh:347
void resize(const size_t size)
Resize matrix.
Definition JMatrixND.hh:446
JMatrixND & reset()
Set matrix to the null matrix.
Definition JMatrixND.hh:459
N x N symmetric matrix.
Definition JMatrixNS.hh:30
void solve(JVectorND_t &u)
Get solution of equation A x = b.
Definition JMatrixNS.hh:308
void invert()
Invert matrix according LDU decomposition.
Definition JMatrixNS.hh:75
Nx1 matrix.
Definition JVectorND.hh:23
void reset()
Reset.
Definition JVectorND.hh:45
Data structure for a pair of indices.