Jpp 19.3.0-rc.4
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.range.getLowerLimit() << "," << FIXED(12,6) << object.range.getUpperLimit() << "]";
440 }
441
442 return out;
443 }
444
445
446 double value = 0.0;
449 };
450
451
452 /**
453 * Fit parameters for single PMT.
454 */
456
457 static constexpr double QE_MIN = 0.0; //!< minimal QE
458 static constexpr double QE_MAX = 2.0; //!< maximal QE
459 static constexpr double TTS_NS = 2.0; //!< start value transition-time spread [ns]
460
461 /**
462 * Default constructor.
463 */
465 {
466 reset();
467 }
468
469
470 /**
471 * Get default values.
472 *
473 * \return parameters
474 */
476 {
477 static JPMTParameters_t parameters;
478
480
481 parameters.status = true;
482
483 parameters.QE .set(1.0);
484 parameters.TTS.set(TTS_NS);
485 parameters.t0 .set(0.0);
486 parameters.bg .set(0.0);
487
488 return parameters;
489 }
490
491
492 /**
493 * Reset.
494 */
495 void reset()
496 {
497 status = true;
498
499 QE .set(0.0);
500 TTS.set(0.0);
501 t0 .set(0.0);
502 bg .set(0.0);
503 }
504
505
506 /**
507 * Set parameters that are free to given values.
508 *
509 * \param parameters parameters
510 */
511 void set(const JPMTParameters_t& parameters)
512 {
513 if (QE .isFree()) { QE .set(parameters.QE); }
514 if (TTS.isFree()) { TTS.set(parameters.TTS); }
515 if (t0 .isFree()) { t0 .set(parameters.t0); }
516 if (bg .isFree()) { bg .set(parameters.bg); }
517 }
518
519
520 /**
521 * Get number of fit parameters.
522 *
523 * \return number of parameters
524 */
525 inline size_t getN() const
526 {
527 return ((QE. isFree() ? 1 : 0) +
528 (TTS.isFree() ? 1 : 0) +
529 (t0 .isFree() ? 1 : 0) +
530 (bg .isFree() ? 1 : 0));
531 }
532
533
534 /**
535 * Get index of parameter.
536 *
537 * \param p pointer to data member
538 * \return index
539 */
541 {
542 if (!(this->*p).isFree()) {
543 return INVALID_INDEX;
544 }
545
546 int N = 0;
547
548 if (p == &JPMTParameters_t::QE ) { return N; }; if (QE .isFree()) { ++N; }
549 if (p == &JPMTParameters_t::TTS) { return N; }; if (TTS.isFree()) { ++N; }
550 if (p == &JPMTParameters_t::t0 ) { return N; }; if (t0 .isFree()) { ++N; }
551 if (p == &JPMTParameters_t::bg ) { return N; }; if (bg .isFree()) { ++N; }
552
553 return INVALID_INDEX;
554 }
555
556
557 /**
558 * Disable PMT.
559 */
560 void disable()
561 {
562 status = false;
563
564 QE .fix(0.0);
565 TTS.fix(TTS_NS);
566 t0 .fix(0.0);
567 bg .fix(0.0);
568 }
569
570
571 /**
572 * Enable PMT.
573 */
574 void enable()
575 {
576 status = true;
577
578 QE .set();
579 TTS.set();
580 t0 .set();
581 bg .set();
582 }
583
584
585 /**
586 * Write PMT parameters to output stream.
587 *
588 * \param out output stream
589 * \param object PMT parameters
590 * \return output stream
591 */
592 friend inline std::ostream& operator<<(std::ostream& out, const JPMTParameters_t& object)
593 {
594 using namespace std;
595
596 out << "QE " << FIXED(7,3) << object.QE << endl;
597 out << "TTS " << FIXED(7,3) << object.TTS << endl;
598 out << "t0 " << FIXED(7,3) << object.t0 << endl;
599 out << "bg " << FIXED(7,3) << object.bg << endl;
600
601 return out;
602 }
603
604
605 bool status; //!< status
606 JParameter_t QE; //!< relative quantum efficiency [unit]
607 JParameter_t TTS; //!< transition-time spread [ns]
608 JParameter_t t0; //!< time offset [ns]
609 JParameter_t bg; //!< background [Hz/ns]
610 };
611
612
613 /**
614 * Fit parameters for two-fold coincidence rate due to K40.
615 */
617 /**
618 * Default constructor.
619 */
621 {
622 reset();
623 }
624
625
626 /**
627 * Get K40 parameters.
628 *
629 * \return K40 parameters
630 */
632 {
633 return static_cast<const JK40Parameters_t&>(*this);
634 }
635
636
637 /**
638 * Set K40 parameters.
639 *
640 * \param parameters K40 parameters
641 */
642 void setK40Parameters(const JK40Parameters_t& parameters)
643 {
644 static_cast<JK40Parameters_t&>(*this) = parameters;
645 }
646
647
648 /**
649 * Reset.
650 */
651 void reset()
652 {
653 R .set(0.0);
654 p1.set(0.0);
655 p2.set(0.0);
656 p3.set(0.0);
657 p4.set(0.0);
658 cc.set(0.0);
659 bc.set(0.0);
660 }
661
662
663 /**
664 * Write model parameters to output stream.
665 *
666 * \param out output stream
667 * \param object model parameters
668 * \return output stream
669 */
670 friend inline std::ostream& operator<<(std::ostream& out, const JK40Parameters_t& object)
671 {
672 using namespace std;
673
674 out << "Rate [Hz] " << FIXED(12,6) << object.R << endl;
675 out << "p1 " << FIXED(12,6) << object.p1 << endl;
676 out << "p2 " << FIXED(12,6) << object.p2 << endl;
677 out << "p3 " << FIXED(12,6) << object.p3 << endl;
678 out << "p4 " << FIXED(12,6) << object.p4 << endl;
679 out << "cc " << FIXED(12,6) << object.cc << endl;
680 out << "bc " << FIXED(12,6) << object.bc << endl;
681
682 return out;
683 }
684
685 JParameter_t R; //!< maximal coincidence rate [Hz]
686 JParameter_t p1; //!< 1st order angle dependence coincidence rate
687 JParameter_t p2; //!< 2nd order angle dependence coincidence rate
688 JParameter_t p3; //!< 3rd order angle dependence coincidence rate
689 JParameter_t p4; //!< 4th order angle dependence coincidence rate
690 JParameter_t cc; //!< fraction of signal correlated background
691 JParameter_t bc; //!< constant background
692 };
693
694
695 /**
696 * Fit parameters for two-fold coincidence rate due to K40.
697 */
700 {
701 /**
702 * Default constructor.
703 */
706
707
708 /**
709 * Get default values.
710 *
711 * The default parameter values are set to those obtained from a designated simulation
712 * of K40 decays (see http://wiki.km3net.de/index.php/OMGsim_simulations_for_K40_fit).\n
713 * If you change these values, you may also want to change the corresponding values in JK40DefaultSimulator.hh.
714 *
715 * \return parameters
716 */
718 {
719 static JK40Parameters parameters;
720
721 parameters.R .set(18.460546);
722 parameters.p1.set( 3.0767);
723 parameters.p2.set(-1.2078);
724 parameters.p3.set( 0.9905);
725 parameters.p4.set( 0.9379);
726 parameters.cc.set( 0.0);
727 parameters.bc.set( 0.0);
728
729 return parameters;
730 }
731
732
733 /**
734 * Get number of fit parameters.
735 *
736 * \return number of parameters
737 */
738 inline size_t getN() const
739 {
740 return ((R .isFree() ? 1 : 0) +
741 (p1.isFree() ? 1 : 0) +
742 (p2.isFree() ? 1 : 0) +
743 (p3.isFree() ? 1 : 0) +
744 (p4.isFree() ? 1 : 0) +
745 (cc.isFree() ? 1 : 0) +
746 (bc.isFree() ? 1 : 0));
747 }
748
749
750 /**
751 * Get index of parameter.
752 *
753 * \param p pointer to data member
754 * \return index
755 */
757 {
758 if (!(this->*p).isFree()) {
759 return INVALID_INDEX;
760 }
761
762 int N = 0;
763
764 if (p == &JK40Parameters::R) { return N; } if (R .isFree()) { ++N; }
765 if (p == &JK40Parameters::p1) { return N; } if (p1.isFree()) { ++N; }
766 if (p == &JK40Parameters::p2) { return N; } if (p2.isFree()) { ++N; }
767 if (p == &JK40Parameters::p3) { return N; } if (p3.isFree()) { ++N; }
768 if (p == &JK40Parameters::p4) { return N; } if (p4.isFree()) { ++N; }
769 if (p == &JK40Parameters::cc) { return N; } if (cc.isFree()) { ++N; }
770 if (p == &JK40Parameters::bc) { return N; } if (bc.isFree()) { ++N; }
771
772 return INVALID_INDEX;
773 }
774
775
776 /**
777 * Get K40 coincidence rate as a function of cosine angle between PMT axes.
778 *
779 * \param ct cosine angle between PMT axes
780 * \return rate [Hz]
781 */
782 double getValue(const double ct) const
783 {
784 return R * exp(ct*(p1+ct*(p2+ct*(p3+ct*p4))) - (p1+p2+p3+p4));
785 }
786
787
788 /**
789 * Get gradient.
790 *
791 * \param ct cosine angle between PMT axes
792 * \return gradient
793 */
794 const JK40Parameters_t& getGradient(const double ct) const
795 {
796 gradient.reset();
797
798 const double rate = getValue(ct);
799 const double ct2 = ct * ct;
800
801 if (R .isFree()) { gradient.R = rate / R; }
802 if (p1.isFree()) { gradient.p1 = rate * ct - rate; }
803 if (p2.isFree()) { gradient.p2 = rate * ct2 - rate; }
804 if (p3.isFree()) { gradient.p3 = rate * ct2 * ct - rate; }
805 if (p4.isFree()) { gradient.p4 = rate * ct2 * ct2 - rate; }
806 if (cc.isFree()) { gradient.cc = rate; }
807 if (bc.isFree()) { gradient.bc = 1.0; }
808
809 return gradient;
810 }
811
812 private:
814 };
815
816
817 /**
818 * Fit model.
819 */
820 struct JModel_t :
821 public JK40Parameters
822 {
824
825
826 /**
827 * Write model parameters to output stream.
828 *
829 * \param out output stream
830 * \param object model parameters
831 * \return output stream
832 */
833 friend inline std::ostream& operator<<(std::ostream& out, const JModel_t& object)
834 {
835 using namespace std;
836
837 out << static_cast<const JK40Parameters&>(object);
838
839 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
840 out << "PMT[" << FILL(2,'0') << i << FILL() << "]." << object.parameters[i].status << endl << object.parameters[i];
841 }
842
843 return out;
844 }
845 };
846
847
848 /**
849 * Fit model.
850 *
851 * In the absence of TDC constraints, the average time offset is fixed to zero.
852 */
853 struct JModel :
854 public JModel_t,
855 public JModule,
856 public JCombinatorics_t
857 {
861
862
863 /**
864 * Auxiliary data structure for derived quantities of a given PMT pair.
865 */
866 struct real_type {
867 double ct; //!< cosine angle between PMT axes
868 double t0; //!< time offset [ns]
869 double sigma; //!< total width [ns]
870 double signal; //!< combined signal
871 double background; //!< combined background
872 double cc; //!< correlated background
873 double bc; //!< uncorrelated background
874 };
875
876
877 /**
878 * Default constructor.
879 */
881 {}
882
883
884 /**
885 * Constructor.
886 *
887 * \param module detector module
888 * \param parameters K40 parameters
889 * \param TDC TDC constraints
890 * \param option option
891 */
892 JModel(const JModule& module,
894 const JTDC_t::range_type& TDC,
895 const int option) :
896 JModule (module),
897 JCombinatorics_t(module)
898 {
900
901 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
902 this->parameters[i] = JPMTParameters_t::getInstance();
903 }
904
905 for (JTDC_t::const_iterator i = TDC.first; i != TDC.second; ++i) {
906
907 if (i->second != JTDC_t::WILDCARD) {
908
909 this->parameters[i->second].t0.fix();
910
911 } else {
912
913 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
914 this->parameters[i].t0.fix();
915 }
916 }
917 }
918
919 this->index = (TDC.first == TDC.second ? 0 : INVALID_INDEX);
920
922 }
923
924
925 /**
926 * Constructor.
927 *
928 * \param module detector module
929 * \param parameters K40 parameters
930 */
931 JModel(const JModule& module,
932 const JK40Parameters& parameters) :
933 JModule (module),
934 JCombinatorics_t(module)
935 {
937
938 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
939 this->parameters[i] = JPMTParameters_t::getInstance();
940 }
941 }
942
943
944 /**
945 * Get fit option.
946 *
947 * \return option
948 */
950 {
951 return option;
952 }
953
954
955 /**
956 * Set fit option.
957 *
958 * \param option option
959 */
960 inline void setOption(const int option)
961 {
962 switch (option) {
963
964 case FIT_PMTS_t:
965
966 R .fix();
967 p1.fix();
968 p2.fix();
969 p3.fix();
970 p4.fix();
971
972 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
973 parameters[i].bg.fix();
974 }
975
976 break;
977
979
980 R .fix();
981
982 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
983 parameters[i].bg.fix();
984 }
985
986 break;
987
989
990 R .fix();
991 p1.fix();
992 p2.fix();
993 p3.fix();
994 p4.fix();
995
996 break;
997
999
1000 R .fix();
1001 p1.fix();
1002 p2.fix();
1003 p3.fix();
1004 p4.fix();
1005
1006 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
1007 parameters[i].QE.fix();
1008 parameters[i].bg.fix();
1009 }
1010
1011 break;
1012
1013 case FIT_MODEL_t:
1014
1015 //cc.fix();
1016 //bc.fix();
1017
1018 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
1019 parameters[i].QE.fix();
1020 parameters[i].t0.fix();
1021 parameters[i].bg.fix();
1022 }
1023
1024 break;
1025
1026 default:
1027
1028 THROW(JValueOutOfRange, "Invalid option " << option);
1029 }
1030
1031 this->option = static_cast<JOption_t>(option);
1032 }
1033
1034
1035 /**
1036 * Check if time offset is fixed.
1037 *
1038 * \return true if time offset fixed; else false
1039 */
1041 {
1042 return index != INVALID_INDEX;
1043 }
1044
1045
1046 /**
1047 * Get time offset.
1048 *
1049 * \return time offset
1050 */
1051 double getFixedTimeOffset() const
1052 {
1053 double t0 = 0.0;
1054 size_t N = 0;
1055
1056 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
1057 if (parameters[i].t0.isFree()) {
1058 t0 += parameters[i].t0;
1059 N += 1;
1060 }
1061 }
1062
1063 return t0 /= N;
1064 }
1065
1066
1067 /**
1068 * Get index of PMT used for fixed time offset.
1069 *
1070 * \return index
1071 */
1072 int getIndex() const
1073 {
1074 return index;
1075 }
1076
1077
1078 /**
1079 * Set index of PMT used for fixed time offset.
1080 */
1082 {
1083 if (index != INVALID_INDEX) {
1084
1085 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
1086
1087 if (parameters[i].status) {
1088
1089 index = i;
1090
1092
1093 return;
1094 }
1095 }
1096
1097 THROW(JValueOutOfRange, "No valid index.");
1098 }
1099 }
1100
1101
1102 /**
1103 * Get number of fit parameters.
1104 *
1105 * \return number of parameters
1106 */
1107 inline size_t getN() const
1108 {
1109 size_t N = JK40Parameters::getN();
1110
1111 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
1112 N += parameters[i].getN();
1113 }
1114
1115 return N;
1116 }
1117
1118
1119 /**
1120 * Get index of parameter.
1121 *
1122 * \param pmt PMT
1123 * \return index
1124 */
1125 int getIndex(int pmt) const
1126 {
1127 int N = JK40Parameters::getN();
1128
1129 for (int i = 0; i != pmt; ++i) {
1130 N += parameters[i].getN();
1131 }
1132
1133 return N;
1134 }
1135
1136
1137 /**
1138 * Get index of parameter.
1139 *
1140 * \param pmt PMT
1141 * \param p pointer to data member
1142 * \return index
1143 */
1145 {
1146 return getIndex(pmt) + parameters[pmt].getIndex(p);
1147 }
1148
1149
1150 /**
1151 * Get intrinsic K40 arrival time spread.
1152 *
1153 * \return sigma [ns]
1154 */
1155 double getSigmaK40() const
1156 {
1157 return this->sigmaK40_ns;
1158 }
1159
1160
1161 /**
1162 * Set intrinsic K40 arrival time spread.
1163 *
1164 * \param sigma sigma [ns]
1165 */
1166 void setSigmaK40(const double sigma)
1167 {
1168 this->sigmaK40_ns = sigma;
1169 }
1170
1171
1172 /**
1173 * Get derived quantities.
1174 *
1175 * \param pair PMT pair
1176 * \return quantities
1177 */
1178 const real_type& getReal(const pair_type& pair) const
1179 {
1180 real.ct = JPP::getDot((*this)[pair.first].getDirection(), (*this)[pair.second].getDirection());
1181
1182 real.t0 = (pair.first == this->index ? -this->parameters[pair.second].t0() :
1183 pair.second == this->index ? +this->parameters[pair.first ].t0() :
1184 this->parameters[pair.first].t0() - this->parameters[pair.second].t0());
1185
1186 real.sigma = sqrt(this->parameters[pair.first ].TTS() * this->parameters[pair.first ].TTS() +
1187 this->parameters[pair.second].TTS() * this->parameters[pair.second].TTS() +
1188 this->getSigmaK40() * this->getSigmaK40());
1189
1190 real.signal = this->parameters[pair.first].QE() * this->parameters[pair.second].QE();
1191
1192 real.background = this->parameters[pair.first].bg() + this->parameters[pair.second].bg();
1193
1194 real.cc = real.signal * this->cc();
1195 real.bc = this->bc();
1196
1197 return real;
1198 }
1199
1200
1201 /**
1202 * Get K40 coincidence rate.
1203 *
1204 * \param pair PMT pair
1205 * \param dt_ns time difference [ns]
1206 * \return rate [Hz/ns]
1207 */
1208 double getValue(const pair_type& pair, const double dt_ns) const
1209 {
1210 using namespace std;
1211 using namespace JPP;
1212
1213 const real_type& real = getReal(pair);
1214
1215 const JGauss gauss(real.t0, real.sigma, real.signal);
1216
1217 const double R1 = this->getValue(real.ct);
1218 const double R2 = gauss.getValue(dt_ns);
1219
1220 return real.bc + real.background + R1 * (real.cc + R2);
1221 }
1222
1223
1224 /**
1225 * Get K40 coincidence rate.
1226 *
1227 * \param pair PMT pair
1228 * \return rate [Hz]
1229 */
1230 double getValue(const pair_type& pair) const
1231 {
1232 using namespace std;
1233 using namespace JPP;
1234
1235 const real_type& real = getReal(pair);
1236
1237 const double R1 = this->getValue(real.ct);
1238 const double R2 = real.signal;
1239
1240 return real.bc + real.background + R1 * (real.cc + R2);
1241 }
1242
1243
1244 /**
1245 * Write model parameters to output stream.
1246 *
1247 * \param out output stream
1248 * \param object model parameters
1249 * \return output stream
1250 */
1251 friend inline std::ostream& operator<<(std::ostream& out, const JModel& object)
1252 {
1253 using namespace std;
1254
1255 out << "Module " << setw(10) << object.getID() << endl;
1256 out << "option " << object.option << endl;
1257 out << "index " << object.index << endl;
1258
1259 out << static_cast<const JModel_t&>(object);
1260
1261 return out;
1262 }
1263
1264 private:
1265 int index; //!< index of PMT used for fixed time offset
1266 double sigmaK40_ns = 0.54; //!< intrinsic K40 arrival time spread [ns]
1269 };
1270
1271
1272 /**
1273 * Fit.
1274 */
1275 class JFit
1276 {
1277 public:
1278 /**
1279 * Result type.
1280 */
1282 double chi2;
1283 int ndf;
1284 };
1285
1286 typedef std::shared_ptr<JMEstimator> estimator_type;
1287
1288
1289 /**
1290 * Constructor
1291 *
1292 * \param option M-estimator
1293 * \param debug debug
1294 */
1295 JFit(const int option, const int debug) :
1296 debug(debug)
1297 {
1298 using namespace JPP;
1299
1300 estimator.reset(getMEstimator(option));
1301 }
1302
1303
1304 /**
1305 * Fit.
1306 *
1307 * \param data data
1308 * \return chi2, NDF
1309 */
1311 {
1312 using namespace std;
1313 using namespace JPP;
1314
1315
1316 value.setIndex();
1317
1318 const size_t N = value.getN();
1319
1320 V.resize(N);
1321 Y.resize(N);
1322 h.resize(N);
1323
1324 double xmax = numeric_limits<double>::lowest();
1325 double xmin = numeric_limits<double>::max();
1326
1327 int ndf = 0;
1328
1329 for (data_type::const_iterator ix = data.begin(); ix != data.end(); ++ix) {
1330
1331 const pair_type& pair = ix->first;
1332
1333 if (value.parameters[pair.first ].status &&
1334 value.parameters[pair.second].status) {
1335
1336 ndf += ix->second.size();
1337
1338 for (const rate_type& iy : ix->second) {
1339 if (iy.dt_ns > xmax) { xmax = iy.dt_ns; }
1340 if (iy.dt_ns < xmin) { xmin = iy.dt_ns; }
1341 }
1342 }
1343 }
1344
1345 ndf -= value.getN();
1346
1347 if (ndf < 0) {
1348 return { 0.0, ndf };
1349 }
1350
1351 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
1352 if (value.parameters[pmt].t0.isFree()) {
1353 value.parameters[pmt].t0.setRange(xmin, xmax);
1354 }
1355 }
1356
1357
1359
1360 double precessor = numeric_limits<double>::max();
1361
1363
1364 DEBUG("step: " << numberOfIterations << endl);
1365
1366 evaluate(data);
1367
1368 DEBUG("lambda: " << FIXED(12,5) << lambda << endl);
1369 DEBUG("chi2: " << FIXED(12,3) << successor << endl);
1370
1371 if (successor < precessor) {
1372
1373 if (numberOfIterations != 0) {
1374
1375 if (fabs(precessor - successor) < EPSILON) {
1376
1377 seterr(data);
1378
1379 return { successor / estimator->getRho(1.0), ndf };
1380 }
1381
1382 if (lambda > LAMBDA_MIN) {
1384 }
1385 }
1386
1387 precessor = successor;
1388 previous = value;
1389
1390 } else {
1391
1392 value = previous;
1393 lambda *= LAMBDA_UP;
1394
1395 if (lambda > LAMBDA_MAX) {
1396 break;
1397 }
1398
1399 evaluate(data);
1400 }
1401
1402 if (debug >= debug_t) {
1403
1404 size_t row = 0;
1405
1406 if (value.R .isFree()) { cout << "R " << FIXED(12,5) << Y[row] << endl; ++row; }
1407 if (value.p1.isFree()) { cout << "p1 " << FIXED(12,5) << Y[row] << endl; ++row; }
1408 if (value.p2.isFree()) { cout << "p2 " << FIXED(12,5) << Y[row] << endl; ++row; }
1409 if (value.p3.isFree()) { cout << "p3 " << FIXED(12,5) << Y[row] << endl; ++row; }
1410 if (value.p4.isFree()) { cout << "p4 " << FIXED(12,5) << Y[row] << endl; ++row; }
1411 if (value.cc.isFree()) { cout << "cc " << FIXED(12,3) << Y[row] << endl; ++row; }
1412
1413 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
1414 if (value.parameters[pmt].QE .isFree()) { cout << "PMT[" << setw(2) << pmt << "].QE " << FIXED(12,5) << Y[row] << endl; ++row; }
1415 if (value.parameters[pmt].TTS.isFree()) { cout << "PMT[" << setw(2) << pmt << "].TTS " << FIXED(12,5) << Y[row] << endl; ++row; }
1416 if (value.parameters[pmt].t0 .isFree()) { cout << "PMT[" << setw(2) << pmt << "].t0 " << FIXED(12,5) << Y[row] << endl; ++row; }
1417 if (value.parameters[pmt].bg .isFree()) { cout << "PMT[" << setw(2) << pmt << "].bg " << FIXED(12,5) << Y[row] << endl; ++row; }
1418 }
1419 }
1420
1421 // force definite positiveness
1422
1423 for (size_t i = 0; i != N; ++i) {
1424
1425 if (V(i,i) < PIVOT) {
1426 V(i,i) = PIVOT;
1427 }
1428
1429 h[i] = 1.0 / sqrt(V(i,i));
1430 }
1431
1432 // normalisation
1433
1434 for (size_t i = 0; i != N; ++i) {
1435 for (size_t j = 0; j != i; ++j) {
1436 V(j,i) *= h[i] * h[j];
1437 V(i,j) = V(j,i);
1438 }
1439 }
1440
1441 for (size_t i = 0; i != N; ++i) {
1442 V(i,i) = 1.0 + lambda;
1443 }
1444
1445 // solve A x = b
1446
1447 for (size_t col = 0; col != N; ++col) {
1448 Y[col] *= h[col];
1449 }
1450
1451 try {
1452 V.solve(Y);
1453 }
1454 catch (const exception& error) {
1455
1456 ERROR("JGandalf: " << error.what() << endl << V << endl);
1457
1458 break;
1459 }
1460
1461 // update value
1462
1463 const double factor = 2.0;
1464
1465 size_t row = 0;
1466
1467 if (value.R .isFree()) { value.R -= factor * h[row] * Y[row]; ++row; }
1468 if (value.p1.isFree()) { value.p1 -= factor * h[row] * Y[row]; ++row; }
1469 if (value.p2.isFree()) { value.p2 -= factor * h[row] * Y[row]; ++row; }
1470 if (value.p3.isFree()) { value.p3 -= factor * h[row] * Y[row]; ++row; }
1471 if (value.p4.isFree()) { value.p4 -= factor * h[row] * Y[row]; ++row; }
1472 if (value.cc.isFree()) { value.cc -= factor * h[row] * Y[row]; ++row; }
1473 if (value.bc.isFree()) { value.bc -= factor * h[row] * Y[row]; ++row; }
1474
1475 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
1476 if (value.parameters[pmt].QE .isFree()) { value.parameters[pmt].QE -= factor * h[row] * Y[row]; ++row; }
1477 if (value.parameters[pmt].TTS.isFree()) { value.parameters[pmt].TTS -= factor * h[row] * Y[row]; ++row; }
1478 if (value.parameters[pmt].t0 .isFree()) { value.parameters[pmt].t0 -= factor * h[row] * Y[row]; ++row; }
1479 if (value.parameters[pmt].bg .isFree()) { value.parameters[pmt].bg -= factor * h[row] * Y[row]; ++row; }
1480 }
1481 }
1482
1483 seterr(data);
1484
1485 return { precessor / estimator->getRho(1.0), ndf };
1486 }
1487
1488
1489 static constexpr int MAXIMUM_ITERATIONS = 100000; //!< maximal number of iterations.
1490 static constexpr double EPSILON = 1.0e-3; //!< maximal distance to minimum.
1491 static constexpr double LAMBDA_MIN = 1.0e-2; //!< minimal value control parameter
1492 static constexpr double LAMBDA_MAX = 1.0e+4; //!< maximal value control parameter
1493 static constexpr double LAMBDA_UP = 10.0; //!< multiplication factor control parameter
1494 static constexpr double LAMBDA_DOWN = 10.0; //!< multiplication factor control parameter
1495 static constexpr double PIVOT = std::numeric_limits<double>::epsilon(); //!< minimal value diagonal element of matrix
1496
1498 estimator_type estimator; //!< M-Estimator function
1499
1500 double lambda;
1505
1506 private:
1507 /**
1508 * Evaluation of fit.
1509 *
1510 * \param data data
1511 */
1512 void evaluate(const data_type& data)
1513 {
1514 using namespace std;
1515 using namespace JPP;
1516
1517 typedef JModel::real_type real_type;
1518
1519
1520 successor = 0.0;
1521
1522 V.reset();
1523 Y.reset();
1524
1525
1526 // model parameter indices
1527
1528 const struct M_t {
1529 M_t(const JModel& model)
1530 {
1531 R = model.getIndex(&JK40Parameters_t::R);
1532 p1 = model.getIndex(&JK40Parameters_t::p1);
1533 p2 = model.getIndex(&JK40Parameters_t::p2);
1534 p3 = model.getIndex(&JK40Parameters_t::p3);
1535 p4 = model.getIndex(&JK40Parameters_t::p4);
1536 cc = model.getIndex(&JK40Parameters_t::cc);
1537 bc = model.getIndex(&JK40Parameters_t::bc);
1538 }
1539
1540 int R;
1541 int p1;
1542 int p2;
1543 int p3;
1544 int p4;
1545 int cc;
1546 int bc;
1547
1548 } M(value);
1549
1550
1551 // PMT parameter indices
1552
1553 struct I_t {
1554 I_t(const JModel& model, const int pmt) :
1555 QE (INVALID_INDEX),
1556 TTS(INVALID_INDEX),
1557 t0 (INVALID_INDEX),
1558 bg (INVALID_INDEX)
1559 {
1560 const int index = model.getIndex(pmt);
1561
1562 int N = 0;
1563
1564 if (model.parameters[pmt].QE .isFree()) { QE = index + N; ++N; }
1565 if (model.parameters[pmt].TTS.isFree()) { TTS = index + N; ++N; }
1566 if (model.parameters[pmt].t0 .isFree()) { t0 = index + N; ++N; }
1567 if (model.parameters[pmt].bg .isFree()) { bg = index + N; ++N; }
1568 }
1569
1570 int QE;
1571 int TTS;
1572 int t0;
1573 int bg;
1574 };
1575
1576
1578
1579 buffer_type buffer;
1580
1581 for (data_type::const_iterator ix = data.begin(); ix != data.end(); ++ix) {
1582
1583 const pair_type& pair = ix->first;
1584
1585 if (value.parameters[pair.first ].status &&
1586 value.parameters[pair.second].status) {
1587
1588 const real_type& real = value.getReal(pair);
1589
1590 const JGauss gauss(real.t0, real.sigma, real.signal);
1591
1592 const double R1 = value.getValue (real.ct);
1593 const JK40Parameters_t& R1p = value.getGradient(real.ct);
1594
1595 const std::pair<I_t, I_t> PMT(I_t(value, pair.first),
1596 I_t(value, pair.second));
1597
1598 for (const rate_type& iy : ix->second) {
1599
1600 const double R2 = gauss.getValue (iy.dt_ns);
1601 const JGauss& R2p = gauss.getGradient(iy.dt_ns);
1602
1603 const double R = real.bc + real.background + R1 * (real.cc + R2);
1604 const double u = (iy.value - R) / iy.error;
1605 const double w = -estimator->getPsi(u) / iy.error;
1606
1607 successor += estimator->getRho(u);
1608
1609 buffer.clear();
1610
1611 if (M.R != INVALID_INDEX) { buffer.push_back({M.R, w * (value.cc() + R2) * R1p.R () * value.R .getDerivative()}); }
1612 if (M.p1 != INVALID_INDEX) { buffer.push_back({M.p1, w * (value.cc() + R2) * R1p.p1() * value.p1.getDerivative()}); }
1613 if (M.p2 != INVALID_INDEX) { buffer.push_back({M.p2, w * (value.cc() + R2) * R1p.p2() * value.p2.getDerivative()}); }
1614 if (M.p3 != INVALID_INDEX) { buffer.push_back({M.p3, w * (value.cc() + R2) * R1p.p3() * value.p3.getDerivative()}); }
1615 if (M.p4 != INVALID_INDEX) { buffer.push_back({M.p4, w * (value.cc() + R2) * R1p.p4() * value.p4.getDerivative()}); }
1616 if (M.cc != INVALID_INDEX) { buffer.push_back({M.cc, w * R1 * R1p.cc() * value.cc.getDerivative()}); }
1617 if (M.bc != INVALID_INDEX) { buffer.push_back({M.bc, w * R1p.bc() * value.bc.getDerivative()}); }
1618
1619 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()}); }
1620 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()}); }
1621 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}); }
1622 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}); }
1623 if (PMT.first .t0 != INVALID_INDEX) { buffer.push_back({PMT.first .t0, w * R1 * R2p.mean * value.parameters[pair.first ].t0 .getDerivative() * +1.0}); }
1624 if (PMT.second.t0 != INVALID_INDEX) { buffer.push_back({PMT.second.t0, w * R1 * R2p.mean * value.parameters[pair.second].t0 .getDerivative() * -1.0}); }
1625 if (PMT.first .bg != INVALID_INDEX) { buffer.push_back({PMT.first .bg, w * value.parameters[pair.first ].bg .getDerivative()}); }
1626 if (PMT.second.bg != INVALID_INDEX) { buffer.push_back({PMT.second.bg, w * value.parameters[pair.second].bg .getDerivative()}); }
1627
1628 for (buffer_type::const_iterator row = buffer.begin(); row != buffer.end(); ++row) {
1629
1630 Y[row->first] += row->second;
1631
1632 V[row->first][row->first] += row->second * row->second;
1633
1634 for (buffer_type::const_iterator col = buffer.begin(); col != row; ++col) {
1635 V[row->first][col->first] += row->second * col->second;
1636 V[col->first][row->first] = V[row->first][col->first];
1637 }
1638 }
1639 }
1640 }
1641 }
1642 }
1643
1644
1645 /**
1646 * Set errors.
1647 *
1648 * \param data data
1649 */
1650 void seterr(const data_type& data)
1651 {
1652 using namespace std;
1653
1654 error.reset();
1655
1656 evaluate(data);
1657
1658 try {
1659 V.invert();
1660 }
1661 catch (const exception& error) {}
1662
1663#define SQRT(X) (X >= 0.0 ? sqrt(X) : std::numeric_limits<double>::max())
1664
1665 size_t i = 0;
1666
1667 if (value.R .isFree()) { error.R = SQRT(V(i,i)); ++i; }
1668 if (value.p1.isFree()) { error.p1 = SQRT(V(i,i)); ++i; }
1669 if (value.p2.isFree()) { error.p2 = SQRT(V(i,i)); ++i; }
1670 if (value.p3.isFree()) { error.p3 = SQRT(V(i,i)); ++i; }
1671 if (value.p4.isFree()) { error.p4 = SQRT(V(i,i)); ++i; }
1672 if (value.cc.isFree()) { error.cc = SQRT(V(i,i)); ++i; }
1673 if (value.bc.isFree()) { error.bc = SQRT(V(i,i)); ++i; }
1674
1675 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
1676 if (value.parameters[pmt].QE .isFree()) { error.parameters[pmt].QE = SQRT(V(i,i)); ++i; }
1677 if (value.parameters[pmt].TTS.isFree()) { error.parameters[pmt].TTS = SQRT(V(i,i)); ++i; }
1678 if (value.parameters[pmt].t0 .isFree()) { error.parameters[pmt].t0 = SQRT(V(i,i)); ++i; }
1679 if (value.parameters[pmt].bg .isFree()) { error.parameters[pmt].bg = SQRT(V(i,i)); ++i; }
1680 }
1681
1682#undef SQRT
1683 }
1684
1685
1686 JMATH::JVectorND Y; // gradient
1689 std::vector<double> h; // normalisation vector
1690 };
1691}
1692
1693#endif
1694
1695
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:1286
std::vector< double > h
Definition JFitK40.hh:1689
static constexpr double LAMBDA_MIN
minimal value control parameter
Definition JFitK40.hh:1491
static constexpr double LAMBDA_DOWN
multiplication factor control parameter
Definition JFitK40.hh:1494
result_type operator()(const data_type &data)
Fit.
Definition JFitK40.hh:1310
void seterr(const data_type &data)
Set errors.
Definition JFitK40.hh:1650
static constexpr double LAMBDA_MAX
maximal value control parameter
Definition JFitK40.hh:1492
static constexpr double LAMBDA_UP
multiplication factor control parameter
Definition JFitK40.hh:1493
JMATH::JMatrixNS V
Definition JFitK40.hh:1504
static constexpr double EPSILON
maximal distance to minimum.
Definition JFitK40.hh:1490
JFit(const int option, const int debug)
Constructor.
Definition JFitK40.hh:1295
void evaluate(const data_type &data)
Evaluation of fit.
Definition JFitK40.hh:1512
static constexpr int MAXIMUM_ITERATIONS
maximal number of iterations.
Definition JFitK40.hh:1489
static constexpr double PIVOT
minimal value diagonal element of matrix
Definition JFitK40.hh:1495
estimator_type estimator
M-Estimator function.
Definition JFitK40.hh:1498
JMATH::JVectorND Y
Definition JFitK40.hh:1686
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:616
JParameter_t bc
constant background
Definition JFitK40.hh:691
JParameter_t R
maximal coincidence rate [Hz]
Definition JFitK40.hh:685
JParameter_t p1
1st order angle dependence coincidence rate
Definition JFitK40.hh:686
JParameter_t p2
2nd order angle dependence coincidence rate
Definition JFitK40.hh:687
friend std::ostream & operator<<(std::ostream &out, const JK40Parameters_t &object)
Write model parameters to output stream.
Definition JFitK40.hh:670
JParameter_t p3
3rd order angle dependence coincidence rate
Definition JFitK40.hh:688
const JK40Parameters_t & getK40Parameters() const
Get K40 parameters.
Definition JFitK40.hh:631
JParameter_t p4
4th order angle dependence coincidence rate
Definition JFitK40.hh:689
JParameter_t cc
fraction of signal correlated background
Definition JFitK40.hh:690
JK40Parameters_t()
Default constructor.
Definition JFitK40.hh:620
void setK40Parameters(const JK40Parameters_t &parameters)
Set K40 parameters.
Definition JFitK40.hh:642
Fit parameters for two-fold coincidence rate due to K40.
Definition JFitK40.hh:700
size_t getN() const
Get number of fit parameters.
Definition JFitK40.hh:738
const JK40Parameters_t & getGradient(const double ct) const
Get gradient.
Definition JFitK40.hh:794
JK40Parameters_t gradient
Definition JFitK40.hh:813
static const JK40Parameters & getInstance()
Get default values.
Definition JFitK40.hh:717
int getIndex(JParameter_t JK40Parameters::*p) const
Get index of parameter.
Definition JFitK40.hh:756
double getValue(const double ct) const
Get K40 coincidence rate as a function of cosine angle between PMT axes.
Definition JFitK40.hh:782
JK40Parameters()
Default constructor.
Definition JFitK40.hh:704
Auxiliary data structure for derived quantities of a given PMT pair.
Definition JFitK40.hh:866
double signal
combined signal
Definition JFitK40.hh:870
double sigma
total width [ns]
Definition JFitK40.hh:869
double cc
correlated background
Definition JFitK40.hh:872
double background
combined background
Definition JFitK40.hh:871
double t0
time offset [ns]
Definition JFitK40.hh:868
double bc
uncorrelated background
Definition JFitK40.hh:873
double ct
cosine angle between PMT axes
Definition JFitK40.hh:867
friend std::ostream & operator<<(std::ostream &out, const JModel_t &object)
Write model parameters to output stream.
Definition JFitK40.hh:833
JPMTParameters_t parameters[NUMBER_OF_PMTS]
Definition JFitK40.hh:823
JModel()
Default constructor.
Definition JFitK40.hh:880
int getIndex(int pmt, JParameter_t JPMTParameters_t::*p) const
Get index of parameter.
Definition JFitK40.hh:1144
friend std::ostream & operator<<(std::ostream &out, const JModel &object)
Write model parameters to output stream.
Definition JFitK40.hh:1251
int getIndex(int pmt) const
Get index of parameter.
Definition JFitK40.hh:1125
size_t getN() const
Get number of fit parameters.
Definition JFitK40.hh:1107
double getValue(const pair_type &pair) const
Get K40 coincidence rate.
Definition JFitK40.hh:1230
double sigmaK40_ns
intrinsic K40 arrival time spread [ns]
Definition JFitK40.hh:1266
JOption_t getOption() const
Get fit option.
Definition JFitK40.hh:949
double getFixedTimeOffset() const
Get time offset.
Definition JFitK40.hh:1051
void setSigmaK40(const double sigma)
Set intrinsic K40 arrival time spread.
Definition JFitK40.hh:1166
int getIndex() const
Get index of PMT used for fixed time offset.
Definition JFitK40.hh:1072
double getSigmaK40() const
Get intrinsic K40 arrival time spread.
Definition JFitK40.hh:1155
void setOption(const int option)
Set fit option.
Definition JFitK40.hh:960
const real_type & getReal(const pair_type &pair) const
Get derived quantities.
Definition JFitK40.hh:1178
JModel(const JModule &module, const JK40Parameters &parameters)
Constructor.
Definition JFitK40.hh:931
double getValue(const pair_type &pair, const double dt_ns) const
Get K40 coincidence rate.
Definition JFitK40.hh:1208
void setIndex()
Set index of PMT used for fixed time offset.
Definition JFitK40.hh:1081
JModel(const JModule &module, const JK40Parameters &parameters, const JTDC_t::range_type &TDC, const int option)
Constructor.
Definition JFitK40.hh:892
bool hasFixedTimeOffset() const
Check if time offset is fixed.
Definition JFitK40.hh:1040
int index
index of PMT used for fixed time offset
Definition JFitK40.hh:1265
Fit parameters for single PMT.
Definition JFitK40.hh:455
static constexpr double QE_MIN
minimal QE
Definition JFitK40.hh:457
friend std::ostream & operator<<(std::ostream &out, const JPMTParameters_t &object)
Write PMT parameters to output stream.
Definition JFitK40.hh:592
JParameter_t t0
time offset [ns]
Definition JFitK40.hh:608
static constexpr double TTS_NS
start value transition-time spread [ns]
Definition JFitK40.hh:459
JParameter_t TTS
transition-time spread [ns]
Definition JFitK40.hh:607
void disable()
Disable PMT.
Definition JFitK40.hh:560
size_t getN() const
Get number of fit parameters.
Definition JFitK40.hh:525
JPMTParameters_t()
Default constructor.
Definition JFitK40.hh:464
void set(const JPMTParameters_t &parameters)
Set parameters that are free to given values.
Definition JFitK40.hh:511
JParameter_t bg
background [Hz/ns]
Definition JFitK40.hh:609
static constexpr double QE_MAX
maximal QE
Definition JFitK40.hh:458
void enable()
Enable PMT.
Definition JFitK40.hh:574
int getIndex(JParameter_t JPMTParameters_t::*p) const
Get index of parameter.
Definition JFitK40.hh:540
static const JPMTParameters_t & getInstance()
Get default values.
Definition JFitK40.hh:475
JParameter_t QE
relative quantum efficiency [unit]
Definition JFitK40.hh:606
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.