Jpp 19.3.0-rc.5
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/JBell.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 static double TEROSTAT_DZ = 0.40; //!< maximal PMT inclination
849 static double TEROSTAT_R1 = 1.00; //!< scaling factor
850 static double BELL_SHAPE = 2.00; //!< Bell shape
851
852 /**
853 * Fit model.
854 *
855 * In the absence of TDC constraints, the average time offset is fixed to zero.
856 */
857 struct JModel :
858 public JModel_t,
859 public JModule,
860 public JCombinatorics_t
861 {
865
866 /**
867 * Auxiliary data structure for derived quantities of a given PMT pair.
868 */
869 struct real_type {
870 double ct; //!< cosine angle between PMT axes
871 double t0; //!< time offset [ns]
872 double sigma; //!< total width [ns]
873 double signal; //!< combined signal
874 double background; //!< combined background
875 double cc; //!< correlated background
876 double bc; //!< uncorrelated background
877 };
878
879
880 /**
881 * Default constructor.
882 */
884 {}
885
886
887 /**
888 * Constructor.
889 *
890 * \param module detector module
891 * \param parameters K40 parameters
892 * \param TDC TDC constraints
893 * \param option option
894 */
895 JModel(const JModule& module,
897 const JTDC_t::range_type& TDC,
898 const int option) :
899 JModule (module),
900 JCombinatorics_t(module)
901 {
903
904 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
905 this->parameters[i] = JPMTParameters_t::getInstance();
906 }
907
908 for (JTDC_t::const_iterator i = TDC.first; i != TDC.second; ++i) {
909
910 if (i->second != JTDC_t::WILDCARD) {
911
912 this->parameters[i->second].t0.fix();
913
914 } else {
915
916 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
917 this->parameters[i].t0.fix();
918 }
919 }
920 }
921
922 this->index = (TDC.first == TDC.second ? 0 : INVALID_INDEX);
923
925 }
926
927
928 /**
929 * Constructor.
930 *
931 * \param module detector module
932 * \param parameters K40 parameters
933 */
934 JModel(const JModule& module,
935 const JK40Parameters& parameters) :
936 JModule (module),
937 JCombinatorics_t(module)
938 {
940
941 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
942 this->parameters[i] = JPMTParameters_t::getInstance();
943 }
944 }
945
946
947 /**
948 * Get fit option.
949 *
950 * \return option
951 */
953 {
954 return option;
955 }
956
957
958 /**
959 * Set fit option.
960 *
961 * \param option option
962 */
963 inline void setOption(const int option)
964 {
965 switch (option) {
966
967 case FIT_PMTS_t:
968
969 R .fix();
970 p1.fix();
971 p2.fix();
972 p3.fix();
973 p4.fix();
974
975 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
976 parameters[i].bg.fix();
977 }
978
979 break;
980
982
983 R .fix();
984
985 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
986 parameters[i].bg.fix();
987 }
988
989 break;
990
992
993 R .fix();
994 p1.fix();
995 p2.fix();
996 p3.fix();
997 p4.fix();
998
999 break;
1000
1002
1003 R .fix();
1004 p1.fix();
1005 p2.fix();
1006 p3.fix();
1007 p4.fix();
1008
1009 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
1010 parameters[i].QE.fix();
1011 parameters[i].bg.fix();
1012 }
1013
1014 break;
1015
1016 case FIT_MODEL_t:
1017
1018 //cc.fix();
1019 //bc.fix();
1020
1021 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
1022 parameters[i].QE.fix();
1023 parameters[i].t0.fix();
1024 parameters[i].bg.fix();
1025 }
1026
1027 break;
1028
1029 default:
1030
1031 THROW(JValueOutOfRange, "Invalid option " << option);
1032 }
1033
1034 this->option = static_cast<JOption_t>(option);
1035 }
1036
1037
1038 /**
1039 * Check if time offset is fixed.
1040 *
1041 * \return true if time offset fixed; else false
1042 */
1044 {
1045 return index != INVALID_INDEX;
1046 }
1047
1048
1049 /**
1050 * Get time offset.
1051 *
1052 * \return time offset
1053 */
1054 double getFixedTimeOffset() const
1055 {
1056 double t0 = 0.0;
1057 size_t N = 0;
1058
1059 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
1060 if (parameters[i].t0.isFree()) {
1061 t0 += parameters[i].t0;
1062 N += 1;
1063 }
1064 }
1065
1066 return t0 /= N;
1067 }
1068
1069
1070 /**
1071 * Get index of PMT used for fixed time offset.
1072 *
1073 * \return index
1074 */
1075 int getIndex() const
1076 {
1077 return index;
1078 }
1079
1080
1081 /**
1082 * Set index of PMT used for fixed time offset.
1083 */
1085 {
1086 if (index != INVALID_INDEX) {
1087
1088 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
1089
1090 if (parameters[i].status) {
1091
1092 index = i;
1093
1095
1096 return;
1097 }
1098 }
1099
1100 THROW(JValueOutOfRange, "No valid index.");
1101 }
1102 }
1103
1104
1105 /**
1106 * Get number of fit parameters.
1107 *
1108 * \return number of parameters
1109 */
1110 inline size_t getN() const
1111 {
1112 size_t N = JK40Parameters::getN();
1113
1114 for (int i = 0; i != NUMBER_OF_PMTS; ++i) {
1115 N += parameters[i].getN();
1116 }
1117
1118 return N;
1119 }
1120
1121
1122 /**
1123 * Get index of parameter.
1124 *
1125 * \param pmt PMT
1126 * \return index
1127 */
1128 int getIndex(int pmt) const
1129 {
1130 int N = JK40Parameters::getN();
1131
1132 for (int i = 0; i != pmt; ++i) {
1133 N += parameters[i].getN();
1134 }
1135
1136 return N;
1137 }
1138
1139
1140 /**
1141 * Get index of parameter.
1142 *
1143 * \param pmt PMT
1144 * \param p pointer to data member
1145 * \return index
1146 */
1148 {
1149 return getIndex(pmt) + parameters[pmt].getIndex(p);
1150 }
1151
1152
1153 /**
1154 * Get intrinsic K40 arrival time spread.
1155 *
1156 * \return sigma [ns]
1157 */
1158 double getSigmaK40() const
1159 {
1160 return this->sigmaK40_ns;
1161 }
1162
1163
1164 /**
1165 * Set intrinsic K40 arrival time spread.
1166 *
1167 * \param sigma sigma [ns]
1168 */
1169 void setSigmaK40(const double sigma)
1170 {
1171 this->sigmaK40_ns = sigma;
1172 }
1173
1174
1175 /**
1176 * Get derived quantities.
1177 *
1178 * \param pair PMT pair
1179 * \return quantities
1180 */
1181 const real_type& getReal(const pair_type& pair) const
1182 {
1183 real.ct = JPP::getDot((*this)[pair.first].getDirection(), (*this)[pair.second].getDirection());
1184
1185 real.t0 = (pair.first == this->index ? -this->parameters[pair.second].t0() :
1186 pair.second == this->index ? +this->parameters[pair.first ].t0() :
1187 this->parameters[pair.first].t0() - this->parameters[pair.second].t0());
1188
1189 real.sigma = sqrt(this->parameters[pair.first ].TTS() * this->parameters[pair.first ].TTS() +
1190 this->parameters[pair.second].TTS() * this->parameters[pair.second].TTS() +
1191 this->getSigmaK40() * this->getSigmaK40());
1192
1193 real.signal = this->parameters[pair.first].QE() * this->parameters[pair.second].QE();
1194
1195 real.background = this->parameters[pair.first].bg() + this->parameters[pair.second].bg();
1196
1197 real.cc = real.signal * this->cc();
1198 real.bc = this->bc();
1199
1200 const double z1 = (*this)[pair.first ].getDirection().getDZ();
1201 const double z2 = (*this)[pair.second].getDirection().getDZ();
1202
1203 if (fabs(z1) <= TEROSTAT_DZ &&
1204 fabs(z2) <= TEROSTAT_DZ &&
1205 signbit(z1) != signbit(z2)) {
1206
1208 }
1209
1210 return real;
1211 }
1212
1213
1214 /**
1215 * Get K40 coincidence rate.
1216 *
1217 * \param pair PMT pair
1218 * \param dt_ns time difference [ns]
1219 * \return rate [Hz/ns]
1220 */
1221 double getValue(const pair_type& pair, const double dt_ns) const
1222 {
1223 using namespace std;
1224 using namespace JPP;
1225
1226 const real_type& real = getReal(pair);
1227
1228 const JBell bell(real.t0, real.sigma, real.signal, 0.0, BELL_SHAPE);
1229
1230 const double R1 = this->getValue(real.ct);
1231 const double R2 = bell.getValue(dt_ns);
1232
1233 return real.bc + real.background + R1 * (real.cc + R2);
1234 }
1235
1236
1237 /**
1238 * Get K40 coincidence rate.
1239 *
1240 * \param pair PMT pair
1241 * \return rate [Hz]
1242 */
1243 double getValue(const pair_type& pair) const
1244 {
1245 using namespace std;
1246 using namespace JPP;
1247
1248 const real_type& real = getReal(pair);
1249
1250 const double R1 = this->getValue(real.ct);
1251 const double R2 = real.signal;
1252
1253 return real.bc + real.background + R1 * (real.cc + R2);
1254 }
1255
1256
1257 /**
1258 * Write model parameters to output stream.
1259 *
1260 * \param out output stream
1261 * \param object model parameters
1262 * \return output stream
1263 */
1264 friend inline std::ostream& operator<<(std::ostream& out, const JModel& object)
1265 {
1266 using namespace std;
1267
1268 out << "Module " << setw(10) << object.getID() << endl;
1269 out << "option " << object.option << endl;
1270 out << "index " << object.index << endl;
1271
1272 out << static_cast<const JModel_t&>(object);
1273
1274 return out;
1275 }
1276
1277 private:
1278 int index; //!< index of PMT used for fixed time offset
1279 double sigmaK40_ns = 0.54; //!< intrinsic K40 arrival time spread [ns]
1282 };
1283
1284
1285 /**
1286 * Fit.
1287 */
1288 class JFit
1289 {
1290 public:
1291 /**
1292 * Result type.
1293 */
1295 double chi2;
1296 int ndf;
1297 };
1298
1299 typedef std::shared_ptr<JMEstimator> estimator_type;
1300
1301
1302 /**
1303 * Constructor
1304 *
1305 * \param option M-estimator
1306 * \param debug debug
1307 */
1308 JFit(const int option, const int debug) :
1309 debug(debug)
1310 {
1311 using namespace JPP;
1312
1313 estimator.reset(getMEstimator(option));
1314 }
1315
1316
1317 /**
1318 * Fit.
1319 *
1320 * \param data data
1321 * \return chi2, NDF
1322 */
1324 {
1325 using namespace std;
1326 using namespace JPP;
1327
1328
1329 value.setIndex();
1330
1331 const size_t N = value.getN();
1332
1333 V.resize(N);
1334 Y.resize(N);
1335 h.resize(N);
1336
1337 double xmax = numeric_limits<double>::lowest();
1338 double xmin = numeric_limits<double>::max();
1339
1340 int ndf = 0;
1341
1342 for (data_type::const_iterator ix = data.begin(); ix != data.end(); ++ix) {
1343
1344 const pair_type& pair = ix->first;
1345
1346 if (value.parameters[pair.first ].status &&
1347 value.parameters[pair.second].status) {
1348
1349 ndf += ix->second.size();
1350
1351 for (const rate_type& iy : ix->second) {
1352 if (iy.dt_ns > xmax) { xmax = iy.dt_ns; }
1353 if (iy.dt_ns < xmin) { xmin = iy.dt_ns; }
1354 }
1355 }
1356 }
1357
1358 ndf -= value.getN();
1359
1360 if (ndf < 0) {
1361 return { 0.0, ndf };
1362 }
1363
1364 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
1365 if (value.parameters[pmt].t0.isFree()) {
1366 value.parameters[pmt].t0.setRange(xmin, xmax);
1367 }
1368 }
1369
1370
1372
1373 double precessor = numeric_limits<double>::max();
1374
1376
1377 DEBUG("step: " << numberOfIterations << endl);
1378
1379 evaluate(data);
1380
1381 DEBUG("lambda: " << FIXED(12,5) << lambda << endl);
1382 DEBUG("chi2: " << FIXED(12,3) << successor << endl);
1383
1384 if (successor < precessor) {
1385
1386 if (numberOfIterations != 0) {
1387
1388 if (fabs(precessor - successor) < EPSILON) {
1389
1390 seterr(data);
1391
1392 return { successor / estimator->getRho(1.0), ndf };
1393 }
1394
1395 if (lambda > LAMBDA_MIN) {
1397 }
1398 }
1399
1400 precessor = successor;
1401 previous = value;
1402
1403 } else {
1404
1405 value = previous;
1406 lambda *= LAMBDA_UP;
1407
1408 if (lambda > LAMBDA_MAX) {
1409 break;
1410 }
1411
1412 evaluate(data);
1413 }
1414
1415 if (debug >= debug_t) {
1416
1417 size_t row = 0;
1418
1419 if (value.R .isFree()) { cout << "R " << FIXED(12,5) << Y[row] << endl; ++row; }
1420 if (value.p1.isFree()) { cout << "p1 " << FIXED(12,5) << Y[row] << endl; ++row; }
1421 if (value.p2.isFree()) { cout << "p2 " << FIXED(12,5) << Y[row] << endl; ++row; }
1422 if (value.p3.isFree()) { cout << "p3 " << FIXED(12,5) << Y[row] << endl; ++row; }
1423 if (value.p4.isFree()) { cout << "p4 " << FIXED(12,5) << Y[row] << endl; ++row; }
1424 if (value.cc.isFree()) { cout << "cc " << FIXED(12,3) << Y[row] << endl; ++row; }
1425
1426 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
1427 if (value.parameters[pmt].QE .isFree()) { cout << "PMT[" << setw(2) << pmt << "].QE " << FIXED(12,5) << Y[row] << endl; ++row; }
1428 if (value.parameters[pmt].TTS.isFree()) { cout << "PMT[" << setw(2) << pmt << "].TTS " << FIXED(12,5) << Y[row] << endl; ++row; }
1429 if (value.parameters[pmt].t0 .isFree()) { cout << "PMT[" << setw(2) << pmt << "].t0 " << FIXED(12,5) << Y[row] << endl; ++row; }
1430 if (value.parameters[pmt].bg .isFree()) { cout << "PMT[" << setw(2) << pmt << "].bg " << FIXED(12,5) << Y[row] << endl; ++row; }
1431 }
1432 }
1433
1434 // force definite positiveness
1435
1436 for (size_t i = 0; i != N; ++i) {
1437
1438 if (V(i,i) < PIVOT) {
1439 V(i,i) = PIVOT;
1440 }
1441
1442 h[i] = 1.0 / sqrt(V(i,i));
1443 }
1444
1445 // normalisation
1446
1447 for (size_t i = 0; i != N; ++i) {
1448 for (size_t j = 0; j != i; ++j) {
1449 V(j,i) *= h[i] * h[j];
1450 V(i,j) = V(j,i);
1451 }
1452 }
1453
1454 for (size_t i = 0; i != N; ++i) {
1455 V(i,i) = 1.0 + lambda;
1456 }
1457
1458 // solve A x = b
1459
1460 for (size_t col = 0; col != N; ++col) {
1461 Y[col] *= h[col];
1462 }
1463
1464 try {
1465 V.solve(Y);
1466 }
1467 catch (const exception& error) {
1468
1469 ERROR("JGandalf: " << error.what() << endl << V << endl);
1470
1471 break;
1472 }
1473
1474 // update value
1475
1476 const double factor = 2.0;
1477
1478 size_t row = 0;
1479
1480 if (value.R .isFree()) { value.R -= factor * h[row] * Y[row]; ++row; }
1481 if (value.p1.isFree()) { value.p1 -= factor * h[row] * Y[row]; ++row; }
1482 if (value.p2.isFree()) { value.p2 -= factor * h[row] * Y[row]; ++row; }
1483 if (value.p3.isFree()) { value.p3 -= factor * h[row] * Y[row]; ++row; }
1484 if (value.p4.isFree()) { value.p4 -= factor * h[row] * Y[row]; ++row; }
1485 if (value.cc.isFree()) { value.cc -= factor * h[row] * Y[row]; ++row; }
1486 if (value.bc.isFree()) { value.bc -= factor * h[row] * Y[row]; ++row; }
1487
1488 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
1489 if (value.parameters[pmt].QE .isFree()) { value.parameters[pmt].QE -= factor * h[row] * Y[row]; ++row; }
1490 if (value.parameters[pmt].TTS.isFree()) { value.parameters[pmt].TTS -= factor * h[row] * Y[row]; ++row; }
1491 if (value.parameters[pmt].t0 .isFree()) { value.parameters[pmt].t0 -= factor * h[row] * Y[row]; ++row; }
1492 if (value.parameters[pmt].bg .isFree()) { value.parameters[pmt].bg -= factor * h[row] * Y[row]; ++row; }
1493 }
1494 }
1495
1496 seterr(data);
1497
1498 return { precessor / estimator->getRho(1.0), ndf };
1499 }
1500
1501
1502 static constexpr int MAXIMUM_ITERATIONS = 100000; //!< maximal number of iterations.
1503 static constexpr double EPSILON = 1.0e-3; //!< maximal distance to minimum.
1504 static constexpr double LAMBDA_MIN = 1.0e-2; //!< minimal value control parameter
1505 static constexpr double LAMBDA_MAX = 1.0e+4; //!< maximal value control parameter
1506 static constexpr double LAMBDA_UP = 10.0; //!< multiplication factor control parameter
1507 static constexpr double LAMBDA_DOWN = 10.0; //!< multiplication factor control parameter
1508 static constexpr double PIVOT = std::numeric_limits<double>::epsilon(); //!< minimal value diagonal element of matrix
1509
1511 estimator_type estimator; //!< M-Estimator function
1512
1513 double lambda;
1518
1519 private:
1520 /**
1521 * Evaluation of fit.
1522 *
1523 * \param data data
1524 */
1525 void evaluate(const data_type& data)
1526 {
1527 using namespace std;
1528 using namespace JPP;
1529
1530 typedef JModel::real_type real_type;
1531
1532
1533 successor = 0.0;
1534
1535 V.reset();
1536 Y.reset();
1537
1538
1539 // model parameter indices
1540
1541 const struct M_t {
1542 M_t(const JModel& model)
1543 {
1544 R = model.getIndex(&JK40Parameters_t::R);
1545 p1 = model.getIndex(&JK40Parameters_t::p1);
1546 p2 = model.getIndex(&JK40Parameters_t::p2);
1547 p3 = model.getIndex(&JK40Parameters_t::p3);
1548 p4 = model.getIndex(&JK40Parameters_t::p4);
1549 cc = model.getIndex(&JK40Parameters_t::cc);
1550 bc = model.getIndex(&JK40Parameters_t::bc);
1551 }
1552
1553 int R;
1554 int p1;
1555 int p2;
1556 int p3;
1557 int p4;
1558 int cc;
1559 int bc;
1560
1561 } M(value);
1562
1563
1564 // PMT parameter indices
1565
1566 struct I_t {
1567 I_t(const JModel& model, const int pmt) :
1568 QE (INVALID_INDEX),
1569 TTS(INVALID_INDEX),
1570 t0 (INVALID_INDEX),
1571 bg (INVALID_INDEX)
1572 {
1573 const int index = model.getIndex(pmt);
1574
1575 int N = 0;
1576
1577 if (model.parameters[pmt].QE .isFree()) { QE = index + N; ++N; }
1578 if (model.parameters[pmt].TTS.isFree()) { TTS = index + N; ++N; }
1579 if (model.parameters[pmt].t0 .isFree()) { t0 = index + N; ++N; }
1580 if (model.parameters[pmt].bg .isFree()) { bg = index + N; ++N; }
1581 }
1582
1583 int QE;
1584 int TTS;
1585 int t0;
1586 int bg;
1587 };
1588
1589
1591
1592 buffer_type buffer;
1593
1594 for (data_type::const_iterator ix = data.begin(); ix != data.end(); ++ix) {
1595
1596 const pair_type& pair = ix->first;
1597
1598 if (value.parameters[pair.first ].status &&
1599 value.parameters[pair.second].status) {
1600
1601 const real_type& real = value.getReal(pair);
1602
1603 const JBell bell(real.t0, real.sigma, real.signal, 0.0, BELL_SHAPE);
1604
1605 const double R1 = value.getValue (real.ct);
1606 const JK40Parameters_t& R1p = value.getGradient(real.ct);
1607
1608 const std::pair<I_t, I_t> PMT(I_t(value, pair.first),
1609 I_t(value, pair.second));
1610
1611 for (const rate_type& iy : ix->second) {
1612
1613 const double R2 = bell.getValue (iy.dt_ns);
1614 const JBell_t& R2p = bell.getGradient(iy.dt_ns);
1615
1616 const double R = real.bc + real.background + R1 * (real.cc + R2);
1617 const double u = (iy.value - R) / iy.error;
1618 const double w = -estimator->getPsi(u) / iy.error;
1619
1620 successor += estimator->getRho(u);
1621
1622 buffer.clear();
1623
1624 if (M.R != INVALID_INDEX) { buffer.push_back({M.R, w * (value.cc() + R2) * R1p.R () * value.R .getDerivative()}); }
1625 if (M.p1 != INVALID_INDEX) { buffer.push_back({M.p1, w * (value.cc() + R2) * R1p.p1() * value.p1.getDerivative()}); }
1626 if (M.p2 != INVALID_INDEX) { buffer.push_back({M.p2, w * (value.cc() + R2) * R1p.p2() * value.p2.getDerivative()}); }
1627 if (M.p3 != INVALID_INDEX) { buffer.push_back({M.p3, w * (value.cc() + R2) * R1p.p3() * value.p3.getDerivative()}); }
1628 if (M.p4 != INVALID_INDEX) { buffer.push_back({M.p4, w * (value.cc() + R2) * R1p.p4() * value.p4.getDerivative()}); }
1629 if (M.cc != INVALID_INDEX) { buffer.push_back({M.cc, w * R1 * R1p.cc() * value.cc.getDerivative()}); }
1630 if (M.bc != INVALID_INDEX) { buffer.push_back({M.bc, w * R1p.bc() * value.bc.getDerivative()}); }
1631
1632 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()}); }
1633 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()}); }
1634 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}); }
1635 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}); }
1636 if (PMT.first .t0 != INVALID_INDEX) { buffer.push_back({PMT.first .t0, w * R1 * R2p.mean * value.parameters[pair.first ].t0 .getDerivative() * +1.0}); }
1637 if (PMT.second.t0 != INVALID_INDEX) { buffer.push_back({PMT.second.t0, w * R1 * R2p.mean * value.parameters[pair.second].t0 .getDerivative() * -1.0}); }
1638 if (PMT.first .bg != INVALID_INDEX) { buffer.push_back({PMT.first .bg, w * value.parameters[pair.first ].bg .getDerivative()}); }
1639 if (PMT.second.bg != INVALID_INDEX) { buffer.push_back({PMT.second.bg, w * value.parameters[pair.second].bg .getDerivative()}); }
1640
1641 for (buffer_type::const_iterator row = buffer.begin(); row != buffer.end(); ++row) {
1642
1643 Y[row->first] += row->second;
1644
1645 V[row->first][row->first] += row->second * row->second;
1646
1647 for (buffer_type::const_iterator col = buffer.begin(); col != row; ++col) {
1648 V[row->first][col->first] += row->second * col->second;
1649 V[col->first][row->first] = V[row->first][col->first];
1650 }
1651 }
1652 }
1653 }
1654 }
1655 }
1656
1657
1658 /**
1659 * Set errors.
1660 *
1661 * \param data data
1662 */
1663 void seterr(const data_type& data)
1664 {
1665 using namespace std;
1666
1667 error.reset();
1668
1669 evaluate(data);
1670
1671 try {
1672 V.invert();
1673 }
1674 catch (const exception& error) {}
1675
1676#define SQRT(X) (X >= 0.0 ? sqrt(X) : std::numeric_limits<double>::max())
1677
1678 size_t i = 0;
1679
1680 if (value.R .isFree()) { error.R = SQRT(V(i,i)); ++i; }
1681 if (value.p1.isFree()) { error.p1 = SQRT(V(i,i)); ++i; }
1682 if (value.p2.isFree()) { error.p2 = SQRT(V(i,i)); ++i; }
1683 if (value.p3.isFree()) { error.p3 = SQRT(V(i,i)); ++i; }
1684 if (value.p4.isFree()) { error.p4 = SQRT(V(i,i)); ++i; }
1685 if (value.cc.isFree()) { error.cc = SQRT(V(i,i)); ++i; }
1686 if (value.bc.isFree()) { error.bc = SQRT(V(i,i)); ++i; }
1687
1688 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
1689 if (value.parameters[pmt].QE .isFree()) { error.parameters[pmt].QE = SQRT(V(i,i)); ++i; }
1690 if (value.parameters[pmt].TTS.isFree()) { error.parameters[pmt].TTS = SQRT(V(i,i)); ++i; }
1691 if (value.parameters[pmt].t0 .isFree()) { error.parameters[pmt].t0 = SQRT(V(i,i)); ++i; }
1692 if (value.parameters[pmt].bg .isFree()) { error.parameters[pmt].bg = SQRT(V(i,i)); ++i; }
1693 }
1694
1695#undef SQRT
1696 }
1697
1698
1699 JMATH::JVectorND Y; // gradient
1702 std::vector<double> h; // normalisation vector
1703 };
1704}
1705
1706#endif
1707
1708
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.
Binary methods for member 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:1299
std::vector< double > h
Definition JFitK40.hh:1702
static constexpr double LAMBDA_MIN
minimal value control parameter
Definition JFitK40.hh:1504
static constexpr double LAMBDA_DOWN
multiplication factor control parameter
Definition JFitK40.hh:1507
result_type operator()(const data_type &data)
Fit.
Definition JFitK40.hh:1323
void seterr(const data_type &data)
Set errors.
Definition JFitK40.hh:1663
static constexpr double LAMBDA_MAX
maximal value control parameter
Definition JFitK40.hh:1505
static constexpr double LAMBDA_UP
multiplication factor control parameter
Definition JFitK40.hh:1506
JMATH::JMatrixNS V
Definition JFitK40.hh:1517
static constexpr double EPSILON
maximal distance to minimum.
Definition JFitK40.hh:1503
JFit(const int option, const int debug)
Constructor.
Definition JFitK40.hh:1308
void evaluate(const data_type &data)
Evaluation of fit.
Definition JFitK40.hh:1525
static constexpr int MAXIMUM_ITERATIONS
maximal number of iterations.
Definition JFitK40.hh:1502
static constexpr double PIVOT
minimal value diagonal element of matrix
Definition JFitK40.hh:1508
estimator_type estimator
M-Estimator function.
Definition JFitK40.hh:1511
JMATH::JVectorND Y
Definition JFitK40.hh:1699
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 double TEROSTAT_R1
scaling factor
Definition JFitK40.hh:849
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
static double TEROSTAT_DZ
maximal PMT inclination
Definition JFitK40.hh:848
static double BELL_SHAPE
Bell shape.
Definition JFitK40.hh:850
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:869
double signal
combined signal
Definition JFitK40.hh:873
double sigma
total width [ns]
Definition JFitK40.hh:872
double cc
correlated background
Definition JFitK40.hh:875
double background
combined background
Definition JFitK40.hh:874
double t0
time offset [ns]
Definition JFitK40.hh:871
double bc
uncorrelated background
Definition JFitK40.hh:876
double ct
cosine angle between PMT axes
Definition JFitK40.hh:870
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:883
int getIndex(int pmt, JParameter_t JPMTParameters_t::*p) const
Get index of parameter.
Definition JFitK40.hh:1147
friend std::ostream & operator<<(std::ostream &out, const JModel &object)
Write model parameters to output stream.
Definition JFitK40.hh:1264
int getIndex(int pmt) const
Get index of parameter.
Definition JFitK40.hh:1128
size_t getN() const
Get number of fit parameters.
Definition JFitK40.hh:1110
double getValue(const pair_type &pair) const
Get K40 coincidence rate.
Definition JFitK40.hh:1243
double sigmaK40_ns
intrinsic K40 arrival time spread [ns]
Definition JFitK40.hh:1279
JOption_t getOption() const
Get fit option.
Definition JFitK40.hh:952
double getFixedTimeOffset() const
Get time offset.
Definition JFitK40.hh:1054
void setSigmaK40(const double sigma)
Set intrinsic K40 arrival time spread.
Definition JFitK40.hh:1169
int getIndex() const
Get index of PMT used for fixed time offset.
Definition JFitK40.hh:1075
double getSigmaK40() const
Get intrinsic K40 arrival time spread.
Definition JFitK40.hh:1158
void setOption(const int option)
Set fit option.
Definition JFitK40.hh:963
const real_type & getReal(const pair_type &pair) const
Get derived quantities.
Definition JFitK40.hh:1181
JModel(const JModule &module, const JK40Parameters &parameters)
Constructor.
Definition JFitK40.hh:934
double getValue(const pair_type &pair, const double dt_ns) const
Get K40 coincidence rate.
Definition JFitK40.hh:1221
void setIndex()
Set index of PMT used for fixed time offset.
Definition JFitK40.hh:1084
JModel(const JModule &module, const JK40Parameters &parameters, const JTDC_t::range_type &TDC, const int option)
Constructor.
Definition JFitK40.hh:895
bool hasFixedTimeOffset() const
Check if time offset is fixed.
Definition JFitK40.hh:1043
int index
index of PMT used for fixed time offset
Definition JFitK40.hh:1278
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).
Bell function object.
Definition JBell.hh:32
const JBell_t & getGradient(const double x) const
Get gradient.
Definition JBell.hh:125
double getValue(const double x) const
Function value.
Definition JBell.hh:85
Gauss model.
Definition JGauss.hh:32
double background
Definition JGauss.hh:164
double signal
Definition JGauss.hh:163
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.