Jpp 21.0.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JRootfit.hh
Go to the documentation of this file.
1#ifndef __JROOT__JROOTFIT__
2#define __JROOT__JROOTFIT__
3
4#include <ostream>
5#include <iomanip>
6#include <vector>
7#include <set>
8#include <limits>
9#include <algorithm>
10#include <memory>
11
12#include "TH1.h"
13#include "TH2.h"
14#include "TH3.h"
15#include "TF1.h"
16#include "TF2.h"
17#include "TF3.h"
18#include "TGraphErrors.h"
19#include "TGraph2DErrors.h"
20#include "TList.h"
21
22#include "JFit/JGandalf.hh"
23#include "JFit/JMEstimator.hh"
25#include "JMath/JMathlib.hh"
26#include "JTools/JRange.hh"
27#include "JLang/JManip.hh"
28
29
30/**
31 * \author mdejong
32 */
33
34namespace JROOT {}
35namespace JPP { using namespace JROOT; }
36
37namespace JROOT {
38
39 using JFIT::JGandalf;
42 using JMATH::poisson;
45
46
47 /**
48 * Type definiton of abscissa range.
49 */
51
52
53 /**
54 * Get range of given axis.
55 *
56 * \param pAxis pointer to axis
57 * \return range
58 */
59 inline range_type getRange(TAxis* pAxis)
60 {
61 if (pAxis != NULL)
62 return range_type(pAxis->GetXmin(), pAxis->GetXmax());
63 else
64 return range_type();
65 }
66
67
68 /**
69 * Get range of given graph.
70 *
71 * \param nx number of values
72 * \param pX pointer to array of values
73 * \return range
74 */
75 inline range_type getRange(const Int_t nx, const Double_t* pX)
76 {
78
79 for (Int_t i = 0; i != nx; ++i) {
80 range.include(pX[i]);
81 }
82
83 return range;
84 }
85
86
87 /**
88 * Get range of given graph.
89 *
90 * \param g1 graph
91 * \return range
92 */
93 inline range_type getRange(const TGraph& g1)
94 {
95 return getRange(g1.GetN(), g1.GetX());
96 }
97
98
99 /**
100 * Get range of given graph.
101 *
102 * \param g2 graph
103 * \return range
104 */
105 inline range_type getRangeX(const TGraph2D& g2)
106 {
107 return getRange(g2.GetN(), g2.GetX());
108 }
109
110
111 /**
112 * Get range of given graph.
113 *
114 * \param g2 graph
115 * \return range
116 */
117 inline range_type getRangeY(const TGraph2D& g2)
118 {
119 return getRange(g2.GetN(), g2.GetY());
120 }
121
122
123 /**
124 * Data point for counting measurement.
125 */
126 struct m_count {
127 /**
128 * Default constructor.
129 */
131 count(0)
132 {}
133
134
135 /**
136 * Constructor.
137 *
138 * \param count count
139 */
140 m_count(const size_t count) :
141 count(count)
142 {}
143
144
145 /**
146 * Minimal value for numerical computations.
147 *
148 * \return epsilon
149 */
150 static inline double epsilon()
151 {
152 return std::numeric_limits<double>::min();
153 }
154
155
156 /**
157 * Get chi2.
158 *
159 * \param z expectation value
160 * \return chi2
161 */
162 inline double getRho(const double z) const
163 {
164 const double P = poisson(count, z > epsilon() ? z : epsilon());
165
166 return -log(P > epsilon() ? P : epsilon());
167 }
168
169
170 /**
171 * Get derivative of chi2.
172 *
173 * \param z expectation value
174 * \return derivative of chi2
175 */
176 inline double getPsi(const double z) const
177 {
178 return 1.0 - count/(z > epsilon() ? z : epsilon());
179 }
180
181
182 size_t count; //!< count
183 };
184
185
186 /**
187 * Data point for value with error.
188 */
189 struct m_value {
190
191 typedef std::shared_ptr<JMEstimator> estimator_type;
192
193 /**
194 * Default constructor.
195 */
197 value(0.0),
198 error(0.0)
199 {}
200
201
202 /**
203 * Constructor.
204 *
205 * \param value value
206 * \param error error
207 */
208 m_value(const double value,
209 const double error) :
210 value(value),
211 error (error)
212 {}
213
214
215 /**
216 * Get chi2.
217 *
218 * \param z expectation value
219 * \return chi2
220 */
221 inline double getRho(const double z) const
222 {
223 const double u = (z - value) / error;
224
225 return getMEstimator()->getRho(u) / getMEstimator()->getRho(1.0);
226 }
227
228
229 /**
230 * Get derivative of chi2.
231 *
232 * \param z expectation value
233 * \return derivative of chi2
234 */
235 inline double getPsi(const double z) const
236 {
237 const double u = (z - value) / error;
238
239 return getMEstimator()->getPsi(u) * getMEstimator()->getRho(1.0);
240 }
241
242
243 double value; //!< value
244 double error; //!< error
245
246
247 /**
248 * Get M-estimator.
249 *
250 * \return M-estimator
251 */
253 {
254 return get_mestimator();
255 }
256
257
258 /**
259 * Set M-estimator.
260 *
261 * \param type M-estimator type
262 */
263 static const void setMEstimator(int type)
264 {
265 get_mestimator().reset(JFIT::getMEstimator(type));
266 }
267
268 private:
269 /**
270 * Get M-estimator.
271 *
272 * \return M-estimator
273 */
275 {
276 static estimator_type estimator(new JFIT::JMEstimatorNormal());
277
278 return estimator;
279 }
280 };
281
282
283 /**
284 * 1D data point.
285 */
286 template<class T>
287 struct m_1d :
288 public T
289 {
290 /**
291 * Default constructor.
292 */
294 T(),
295 x(0.0)
296 {}
297
298
299 /**
300 * Constructor.
301 *
302 * \param x abscissa
303 * \param v ordinate
304 */
305 m_1d(const double x, const T& v) :
306 T(v),
307 x(x)
308 {}
309
310 double x; //!< abscissa
311 };
312
313
314 /**
315 * 2D data point.
316 */
317 template<class T>
318 struct m_2d :
319 public T
320 {
321 /**
322 * Default constructor.
323 */
325 T(),
326 x(0.0),
327 y(0.0)
328 {}
329
330
331 /**
332 * Constructor.
333 *
334 * \param x abscissa
335 * \param y abscissa
336 * \param v ordinate
337 */
338 m_2d(const double x, const double y, const T& v) :
339 T(v),
340 x(x),
341 y(y)
342 {}
343
344 double x; //!< abscissa
345 double y; //!< abscissa
346 };
347
348
349 /**
350 * 3D data point.
351 */
352 template<class T>
353 struct m_3d :
354 public T
355 {
356 /**
357 * Default constructor.
358 */
360 T(),
361 x(0.0),
362 y(0.0),
363 z(0.0)
364 {}
365
366
367 /**
368 * Constructor.
369 *
370 * \param x abscissa
371 * \param y abscissa
372 * \param z abscissa
373 * \param v ordinate
374 */
375 m_3d(const double x, const double y, const double z, const T& v) :
376 T(v),
377 x(x),
378 y(y),
379 z(z)
380 {}
381
382 double x; //!< abscissa
383 double y; //!< abscissa
384 double z; //!< abscissa
385 };
386
387
388 /**
389 * Template definition of data structure for set of data points.
390 */
391 template<class T>
392 struct data_type;
393
394
395 /**
396 * Template specialisation of data structure for set of 1D data points.
397 */
398 template<class T>
399 struct data_type< m_1d<T> > :
400 public std::vector< m_1d<T> >
401 {
402 /**
403 * Default constructor.
404 */
406 {}
407
408
409 /**
410 * Unpack constructor.
411 *
412 * \param h1 1D histogram
413 * \param X abscissa range
414 */
415 data_type(const TH1& h1,
416 const range_type& X = range_type())
417 {
418 unpack(h1, X);
419 }
420
421
422 /**
423 * Unpack constructor.
424 *
425 * \param g1 1D graph
426 * \param X abscissa range
427 */
428 data_type(const TGraphErrors& g1,
429 const range_type& X = range_type())
430 {
431 unpack(g1, X);
432 }
433
434
435 /**
436 * Unpack 1D-histogram.
437 *
438 * \param h1 histogram
439 * \param X abscissa range
440 */
441 void unpack(const TH1& h1,
442 const range_type& X = range_type());
443
444
445 /**
446 * Unpack 1D-graph.
447 *
448 * \param g1 graph
449 * \param X abscissa range
450 */
451 void unpack(const TGraphErrors& g1,
452 const range_type& X = range_type());
453 };
454
455
456 /**
457 * Unpack 1D-histogram.
458 *
459 * \param h1 histogram
460 * \param X abscissa range
461 */
462 template<>
463 void data_type< m_1d<m_count> >::unpack(const TH1& h1,
464 const range_type& X)
465 {
466 for (Int_t ix = 1; ix <= h1.GetXaxis()->GetNbins(); ++ix) {
467
468 const double x = h1.GetXaxis()->GetBinCenter(ix);
469 const size_t count = h1.GetBinContent(ix);
470
471 if (X(x)) {
472 this->push_back(m_1d<m_count>(x, count));
473 }
474 }
475 }
476
477
478 /**
479 * Unpack 1D-histogram.
480 *
481 * \param h1 histogram
482 * \param X abscissa range
483 */
484 template<>
485 void data_type< m_1d<m_value> >::unpack(const TH1& h1,
486 const range_type& X)
487 {
488 for (Int_t ix = 1; ix <= h1.GetXaxis()->GetNbins(); ++ix) {
489
490 const double x = h1.GetXaxis()->GetBinCenter(ix);
491 const double value = h1.GetBinContent(ix);
492 const double error = h1.GetBinError (ix);
493
494 if (X(x) && error > 0.0) {
495 this->push_back(m_1d<m_value>(x, m_value(value, error)));
496 }
497 }
498 }
499
500
501 /**
502 * Unpack 1D-graph
503 *
504 * \param g1 graph
505 * \param X abscissa range
506 */
507 template<>
508 void data_type< m_1d<m_value> >::unpack(const TGraphErrors& g1,
509 const range_type& X)
510 {
511 for (Int_t i = 0; i != g1.GetN(); ++i) {
512
513 const double x = g1.GetX()[i];
514 const double value = g1.GetY()[i];
515 const double error = g1.GetEY()[i];
516
517 if (X(x) && error > 0.0) {
518 this->push_back(m_1d<m_value>(x, m_value(value, error)));
519 }
520 }
521 }
522
523
524 /**
525 * Template specialisation of data structure for set of 2D data points.
526 */
527 template<class T>
528 struct data_type< m_2d<T> > :
529 public std::vector< m_2d<T> >
530 {
531 /**
532 * Default constructor.
533 */
535 {}
536
537
538 /**
539 * Unpack constructor.
540 *
541 * \param h2 2D histogram
542 * \param X abscissa range
543 * \param Y abscissa range
544 */
545 data_type(const TH2& h2,
546 const range_type& X = range_type(),
547 const range_type& Y = range_type())
548 {
549 unpack(h2, X, Y);
550 }
551
552
553 /**
554 * Unpack constructor.
555 *
556 * \param g2 graph
557 * \param X abscissa range
558 * \param Y abscissa range
559 */
560 data_type(const TGraph2DErrors& g2,
561 const range_type& X = range_type(),
562 const range_type& Y = range_type())
563 {
564 unpack(g2, X, Y);
565 }
566
567
568 /**
569 * Unpack 2D-histogram.
570 *
571 * \param h2 histogram
572 * \param X abscissa range
573 * \param Y abscissa range
574 */
575 void unpack(const TH2& h2,
576 const range_type& X = range_type(),
577 const range_type& Y = range_type());
578
579
580 /**
581 * Unpack 2D-graph.
582 *
583 * \param g2 graph
584 * \param X abscissa range
585 * \param Y abscissa range
586 */
587 void unpack(const TGraph2DErrors& g2,
588 const range_type& X = range_type(),
589 const range_type& Y = range_type());
590 };
591
592
593 /**
594 * Unpack 2D-histogram.
595 *
596 * \param h2 histogram
597 * \param X abscissa range
598 * \param Y abscissa range
599 */
600 template<>
601 void data_type< m_2d<m_count> >::unpack(const TH2& h2,
602 const range_type& X,
603 const range_type& Y)
604 {
605 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
606 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
607
608 const double x = h2.GetXaxis()->GetBinCenter(ix);
609 const double y = h2.GetYaxis()->GetBinCenter(iy);
610 const size_t count = h2.GetBinContent(ix,iy);
611
612 if (X(x) && Y(y)) {
613 this->push_back(m_2d<m_count>(x, y, count));
614 }
615 }
616 }
617 }
618
619
620 /**
621 * Unpack 2D-histogram.
622 *
623 * \param h2 histogram
624 * \param X abscissa range
625 * \param Y abscissa range
626 */
627 template<>
628 void data_type< m_2d<m_value> >::unpack(const TH2& h2,
629 const range_type& X,
630 const range_type& Y)
631 {
632 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
633 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
634
635 const double x = h2.GetXaxis()->GetBinCenter(ix);
636 const double y = h2.GetYaxis()->GetBinCenter(iy);
637 const double value = h2.GetBinContent(ix,iy);
638 const double error = h2.GetBinError (ix,iy);
639
640 if (X(x) && Y(y) && error > 0.0) {
641 this->push_back(m_2d<m_value>(x, y, m_value(value, error)));
642 }
643 }
644 }
645 }
646
647
648 /**
649 * Unpack 2D-graph
650 *
651 * \param g2 graph
652 * \param X abscissa range
653 * \param Y abscissa range
654 */
655 template<>
656 void data_type< m_2d<m_value> >::unpack(const TGraph2DErrors& g2,
657 const range_type& X,
658 const range_type& Y)
659 {
660 for (Int_t i = 0; i != g2.GetN(); ++i) {
661
662 const double x = g2.GetX()[i];
663 const double y = g2.GetY()[i];
664 const double value = g2.GetZ()[i];
665 const double error = g2.GetEZ()[i];
666
667 if (X(x) && Y(y) && error > 0.0) {
668 this->push_back(m_2d<m_value>(x, y, m_value(value, error)));
669 }
670 }
671 }
672
673
674 /**
675 * Template specialisation of data structure for set of 3D data points.
676 */
677 template<class T>
678 struct data_type< m_3d<T> > :
679 public std::vector< m_3d<T> >
680 {
681 /**
682 * Default constructor.
683 */
685 {}
686
687
688 /**
689 * Unpack constructor.
690 *
691 * \param h3 2D histogram
692 * \param X abscissa range
693 * \param Y abscissa range
694 * \param Z abscissa range
695 */
696 data_type(const TH3& h3,
697 const range_type& X = range_type(),
698 const range_type& Y = range_type(),
699 const range_type& Z = range_type())
700 {
701 unpack(h3, X, Y, Z);
702 }
703
704
705 /**
706 * Unpack 3D-histogram.
707 *
708 * \param h3 histogram
709 * \param X abscissa range
710 * \param Y abscissa range
711 * \param Z abscissa range
712 */
713 void unpack(const TH3& h3,
714 const range_type& X = range_type(),
715 const range_type& Y = range_type(),
716 const range_type& Z = range_type());
717 };
718
719
720 /**
721 * Unpack 3D-histogram.
722 *
723 * \param h3 histogram
724 * \param X abscissa range
725 * \param Y abscissa range
726 * \param Z abscissa range
727 */
728 template<>
729 void data_type< m_3d<m_count> >::unpack(const TH3& h3,
730 const range_type& X,
731 const range_type& Y,
732 const range_type& Z)
733 {
734 for (Int_t ix = 1; ix <= h3.GetXaxis()->GetNbins(); ++ix) {
735 for (Int_t iy = 1; iy <= h3.GetYaxis()->GetNbins(); ++iy) {
736 for (Int_t iz = 1; iz <= h3.GetZaxis()->GetNbins(); ++iz) {
737
738 const double x = h3.GetXaxis()->GetBinCenter(ix);
739 const double y = h3.GetYaxis()->GetBinCenter(iy);
740 const double z = h3.GetZaxis()->GetBinCenter(iz);
741 const size_t count = h3.GetBinContent(ix,iy,iz);
742
743 if (X(x) && Y(y) && Z(z)) {
744 this->push_back(m_3d<m_count>(x, y, z, count));
745 }
746 }
747 }
748 }
749 }
750
751
752 /**
753 * Unpack 3D-histogram.
754 *
755 * \param h3 histogram
756 * \param X abscissa range
757 * \param Y abscissa range
758 * \param Z abscissa range
759 */
760 template<>
761 void data_type< m_3d<m_value> >::unpack(const TH3& h3,
762 const range_type& X,
763 const range_type& Y,
764 const range_type& Z)
765 {
766 for (Int_t ix = 1; ix <= h3.GetXaxis()->GetNbins(); ++ix) {
767 for (Int_t iy = 1; iy <= h3.GetYaxis()->GetNbins(); ++iy) {
768 for (Int_t iz = 1; iz <= h3.GetZaxis()->GetNbins(); ++iz) {
769
770 const double x = h3.GetXaxis()->GetBinCenter(ix);
771 const double y = h3.GetYaxis()->GetBinCenter(iy);
772 const double z = h3.GetZaxis()->GetBinCenter(iz);
773 const double value = h3.GetBinContent(ix,iy,iz);
774 const double error = h3.GetBinError (ix,iy,iz);
775
776 if (X(x) && Y(y) && Z(z) && error > 0.0) {
777 this->push_back(m_3d<m_value>(x, y, z, m_value(value, error)));
778 }
779 }
780 }
781 }
782 }
783
784
785 /**
786 * Wrapper data structure to build ROOT 1D function.
787 */
788 struct JF1 :
789 public TF1
790 {
791 /**
792 * Constructor.
793 *
794 * \param name name
795 * \param f1 function
796 * \param X fit range
797 */
798 template<class JF1_t>
799 JF1(const char* const name,
800 const JF1_t& f1,
801 const range_type& X) :
802 TF1(name,
803 helper<JF1_t>(f1),
804 X.getLowerLimit(),
805 X.getUpperLimit(),
806 0)
807 {
808 this->SetNpx(1000);
809 };
810
811
812 /**
813 * Helper.
814 */
815 template<class JF1_t>
816 struct helper :
817 public JF1_t
818 {
819 /**
820 * Constructor.
821 *
822 * \param f1 function
823 */
824 helper(const JF1_t& f1) :
825 JF1_t(f1)
826 {}
827
828
829 /**
830 * ROOT compatible function call.
831 *
832 * \param x pointer to abscissa values
833 * \param parameters pointer to parameter values
834 * \return function value
835 */
836 double operator()(const double* x, const double* parameters)
837 {
838 setParameters(this, parameters);
839
840 return this->getValue(x[0]);
841 }
842 };
843 };
844
845
846 /**
847 * Wrapper data structure to build ROOT 2D function.
848 */
849 struct JF2 :
850 public TF2
851 {
852 /**
853 * Constructor.
854 *
855 * \param name name
856 * \param f2 function
857 * \param X fit range
858 * \param Y fit range
859 */
860 template<class JF2_t>
861 JF2(const char* const name,
862 const JF2_t& f2,
863 const range_type& X,
864 const range_type& Y) :
865 TF2(name,
866 helper<JF2_t>(f2),
867 X.getLowerLimit(),
868 X.getUpperLimit(),
869 Y.getLowerLimit(),
870 Y.getUpperLimit(),
871 0)
872 {
873 this->SetNpx(1000);
874 this->SetNpy(1000);
875 };
876
877
878 /**
879 * Helper.
880 */
881 template<class JF2_t>
882 struct helper :
883 public JF2_t
884 {
885 /**
886 * Constructor.
887 *
888 * \param f2 function
889 */
890 helper(const JF2_t& f2) :
891 JF2_t(f2)
892 {}
893
894
895 /**
896 * ROOT compatible function call.
897 *
898 * \param x pointer to abscissa values
899 * \param parameters pointer to parameter values
900 * \return function value
901 */
902 double operator()(const double* x, const double* parameters)
903 {
904 setParameters(this, parameters);
905
906 return this->getValue(x[0], x[1]);
907 }
908 };
909 };
910
911
912 /**
913 * Wrapper data structure to build ROOT 3D function.
914 */
915 struct JF3 :
916 public TF3
917 {
918 /**
919 * Constructor.
920 *
921 * \param name name
922 * \param f3 function
923 * \param X fit range
924 * \param Y fit range
925 * \param Z fit range
926 */
927 template<class JF3_t>
928 JF3(const char* const name,
929 const JF3_t& f3,
930 const range_type& X,
931 const range_type& Y,
932 const range_type& Z) :
933 TF3(name,
934 helper<JF3_t>(f3),
935 X.getLowerLimit(),
936 X.getUpperLimit(),
937 Y.getLowerLimit(),
938 Y.getUpperLimit(),
939 Z.getLowerLimit(),
940 Z.getUpperLimit(),
941 0)
942 {
943 this->SetNpx(300);
944 this->SetNpy(300);
945 this->SetNpz(300);
946 };
947
948
949 /**
950 * Helper.
951 */
952 template<class JF3_t>
953 struct helper :
954 public JF3_t
955 {
956 /**
957 * Constructor.
958 *
959 * \param f3 function
960 */
961 helper(const JF3_t& f3) :
962 JF3_t(f3)
963 {}
964
965
966 /**
967 * ROOT compatible function call.
968 *
969 * \param x pointer to abscissa values
970 * \param parameters pointer to parameter values
971 * \return function value
972 */
973 double operator()(const double* x, const double* parameters)
974 {
975 setParameters(this, parameters);
976
977 return this->getValue(x[0], x[1], x[2]);
978 }
979 };
980 };
981
982
983 /**
984 * Auxiliary data structure for list of fixed parameters.
985 */
986 struct index_list :
987 public std::set<size_t>
988 {
989 /**
990 * Default constructor.
991 */
993 {}
994
995
996 /**
997 * Constructor.
998 *
999 * \param indices indices
1000 */
1002 std::set<size_t>(indices)
1003 {}
1004
1005
1006 /**
1007 * Conversion constructor.
1008 *
1009 * \param parameters parameters
1010 */
1011 template<class T>
1013 {
1014 for (size_t i = 0; i != T::parameters.size(); ++i) {
1015 if (std::find(parameters.begin(), parameters.end(), T::parameters[i]) != parameters.end()) {
1016 this->insert(i);
1017 }
1018 }
1019 }
1020 };
1021
1022
1023 /**
1024 * Base class for result of ROOT Fit.
1025 */
1026 template<class JFs_t>
1028 public JGandalf<JFs_t>
1029 {
1030 protected:
1031 /**
1032 * Default constructor.
1033 */
1035 npx (0),
1036 chi2(0.0)
1037 {
1039 JGandalf<JFs_t>::EPSILON = 1.0e-5;
1041 }
1042
1043
1044 size_t npx; //!< number of data points
1045 double chi2; //!< chi2
1046
1047 public:
1048 /**
1049 * Get function.
1050 *
1051 * \return function.
1052 */
1053 const JFs_t& getFunction() const
1054 {
1055 return this->value;
1056 }
1057
1058
1059 /**
1060 * Get number of parameters.
1061 *
1062 * \return number of parameters
1063 */
1065 {
1066 return JFs_t::parameters.size();
1067 }
1068
1069
1070 /**
1071 * Get number of free parameters.
1072 *
1073 * \return number of free parameters
1074 */
1076 {
1077 return this->parameters.size();
1078 }
1079
1080
1081 /**
1082 * Get number of data points.
1083 *
1084 * \return number of data points
1085 */
1086 size_t getN() const
1087 {
1088 return npx;
1089 }
1090
1091
1092 /**
1093 * Get chi2.
1094 *
1095 * \return chi2
1096 */
1097 double getChi2() const
1098 {
1099 return chi2;
1100 }
1101
1102
1103 /**
1104 * Get number of degrees of freedom.
1105 *
1106 * \return number of degrees of freedom
1107 */
1108 int getNDF() const
1109 {
1110 return (int) getN() - (int) getNumberOfFreeParameters();
1111 }
1112
1113
1114 /**
1115 * Get value of parameter at given index.
1116 *
1117 * \param i index
1118 */
1119 double getValue(size_t i) const
1120 {
1121 return (this->value)[i];
1122 }
1123
1124
1125 /**
1126 * Get error of parameter at given index.
1127 *
1128 * \param i index
1129 */
1130 double getError(size_t i) const
1131 {
1132 return (this->error)[i];
1133 }
1134
1135
1136 /**
1137 * Print result.
1138 *
1139 * \param out output stream
1140 */
1141 void print(std::ostream& out) const
1142 {
1143 using namespace std;
1144
1145 out << "chi2/NDF " << FIXED(7,3) << this->getChi2() << "/" << this->getNDF() << endl;
1146
1147 out << "Number of iterations " << this->numberOfIterations << endl;
1148
1149 for (size_t i = 0; i != this->getNumberOfParameters(); ++i) {
1150 out << setw(2) << i << ' '
1151 << FIXED(15,9) << this->getValue(i) << " +/- "
1152 << FIXED(15,9) << this->getError(i) << endl;
1153 }
1154 }
1155 };
1156
1157
1158 /**
1159 * ROOT Fit.
1160 */
1161 template<class JFs_t>
1162 class JRootfit :
1163 public JRootfit_t<JFs_t>
1164 {
1165 public:
1166
1168
1169
1170 /**
1171 * Default constructor.
1172 */
1174 {}
1175
1176
1177 /**
1178 * Fit.
1179 *
1180 * \param h1 histogram
1181 * \param f1 start value
1182 * \param type type of data for histogram unpacking
1183 * \param ls list of fixed parameters
1184 * \param X fit range
1185 * \return result
1186 */
1187 template<class T>
1188 const result_type& operator()(const TH1& h1,
1189 const JFs_t& f1,
1190 const T& type,
1191 const index_list& ls = index_list(),
1192 const range_type& X = range_type())
1193 {
1194 return eval(f1, ls, data_type< m_1d<T> >(h1, X));
1195 }
1196
1197
1198 /**
1199 * Fit.
1200 *
1201 * The fitted function is added to the input histogram.
1202 *
1203 * \param h1 pointer to histogram
1204 * \param f1 start value
1205 * \param type type of data for histogram unpacking
1206 * \param ls list of fixed parameters
1207 * \param X fit range
1208 * \return result
1209 */
1210 template<class T>
1211 const result_type& operator()(TH1* h1,
1212 const JFs_t& f1,
1213 const T& type,
1214 const index_list& ls = index_list(),
1215 const range_type& X = range_type())
1216 {
1217 (*this)(*h1, f1, type, ls, X);
1218
1219 h1->GetListOfFunctions()->Add(new JF1("f1",
1220 this->value,
1221 JTOOLS::join(X, getRange(h1->GetXaxis()))));
1222
1223 return static_cast<const result_type&>(*this);
1224 }
1225
1226
1227 /**
1228 * Fit.
1229 *
1230 * \param g1 graph
1231 * \param f1 start value
1232 * \param ls list of fixed parameters
1233 * \param X fit range
1234 * \return result
1235 */
1236 const result_type& operator()(const TGraphErrors& g1,
1237 const JFs_t& f1,
1238 const index_list& ls = index_list(),
1239 const range_type& X = range_type())
1240 {
1241 return eval(f1, ls, data_type< m_1d<m_value> >(g1, X));
1242 }
1243
1244
1245 /**
1246 * Fit.
1247 *
1248 * \param g1 pointer to graph
1249 * \param f1 start value
1250 * \param ls list of fixed parameters
1251 * \param X fit range
1252 * \return result
1253 */
1254 const result_type& operator()(TGraphErrors* g1,
1255 const JFs_t& f1,
1256 const index_list& ls = index_list(),
1257 const range_type& X = range_type())
1258 {
1259 (*this)(*g1, f1, ls, X);
1260
1261 g1->GetListOfFunctions()->Add(new JF1("f1",
1262 this->value,
1263 JTOOLS::join(X, getRange(*g1))));
1264
1265 return static_cast<const result_type&>(*this);
1266 }
1267
1268
1269 /**
1270 * Fit.
1271 *
1272 * \param h2 histogram
1273 * \param f2 start value
1274 * \param type type of data for histogram unpacking
1275 * \param ls list of fixed parameters
1276 * \param X fit range
1277 * \param Y fit range
1278 * \return result
1279 */
1280 template<class T>
1281 const result_type& operator()(const TH2& h2,
1282 const JFs_t& f2,
1283 const T& type,
1284 const index_list& ls = index_list(),
1285 const range_type& X = range_type(),
1286 const range_type& Y = range_type())
1287 {
1288 return eval(f2, ls, data_type< m_2d<T> >(h2, X, Y));
1289 }
1290
1291
1292 /**
1293 * Fit.
1294 *
1295 * The fitted function is added to the input histogram.
1296 *
1297 * \param h2 pointer to histogram
1298 * \param f2 start value
1299 * \param type type of data for histogram unpacking
1300 * \param ls list of fixed parameters
1301 * \param X fit range
1302 * \param Y fit range
1303 * \return result
1304 */
1305 template<class T>
1306 const result_type& operator()(TH2* h2,
1307 const JFs_t& f2,
1308 const T& type,
1309 const index_list& ls = index_list(),
1310 const range_type& X = range_type(),
1311 const range_type& Y = range_type())
1312 {
1313 (*this)(*h2, f2, type, ls, X, Y);
1314
1315 h2->GetListOfFunctions()->Add(new JF2("f2",
1316 this->value,
1317 JTOOLS::join(X, getRange(h2->GetXaxis())),
1318 JTOOLS::join(Y, getRange(h2->GetYaxis()))));
1319
1320 return static_cast<const result_type&>(*this);
1321 }
1322
1323
1324 /**
1325 * Fit.
1326 *
1327 * \param g2 graph
1328 * \param f2 start value
1329 * \param ls list of fixed parameters
1330 * \param X fit range
1331 * \param Y fit range
1332 * \return result
1333 */
1334 const result_type& operator()(const TGraph2DErrors& g2,
1335 const JFs_t& f2,
1336 const index_list& ls = index_list(),
1337 const range_type& X = range_type(),
1338 const range_type& Y = range_type())
1339 {
1340 return eval(f2, ls, data_type< m_2d<m_value> >(g2, X, Y));
1341 }
1342
1343
1344 /**
1345 * Fit.
1346 *
1347 * \param g2 pointer to graph
1348 * \param f2 start value
1349 * \param ls list of fixed parameters
1350 * \param X fit range
1351 * \param Y fit range
1352 * \return result
1353 */
1354 const result_type& operator()(TGraph2DErrors* g2,
1355 const JFs_t& f2,
1356 const index_list& ls = index_list(),
1357 const range_type& X = range_type(),
1358 const range_type& Y = range_type())
1359 {
1360 (*this)(*g2, f2, ls, X, Y);
1361
1362 g2->GetListOfFunctions()->Add(new JF2("f2",
1363 this->value,
1364 JTOOLS::join(X, getRangeX(*g2)),
1365 JTOOLS::join(Y, getRangeY(*g2))));
1366
1367 return static_cast<const result_type&>(*this);
1368 }
1369
1370
1371 /**
1372 * Fit.
1373 *
1374 * \param h3 histogram
1375 * \param f3 start value
1376 * \param type type of data for histogram unpacking
1377 * \param ls list of fixed parameters
1378 * \param X fit range
1379 * \param Y fit range
1380 * \param Z fit range
1381 * \return result
1382 */
1383 template<class T>
1384 const result_type& operator()(const TH3& h3,
1385 const JFs_t& f3,
1386 const T& type,
1387 const index_list& ls = index_list(),
1388 const range_type& X = range_type(),
1389 const range_type& Y = range_type(),
1390 const range_type& Z = range_type())
1391 {
1392 return eval(f3, ls, data_type< m_3d<T> >(h3, X, Y, Z));
1393 }
1394
1395
1396 /**
1397 * Fit.
1398 *
1399 * The fitted function is added to the input histogram.
1400 *
1401 * \param h3 pointer to histogram
1402 * \param f3 start value
1403 * \param type type of data for histogram unpacking
1404 * \param ls list of fixed parameters
1405 * \param X fit range
1406 * \param Y fit range
1407 * \param Z fit range
1408 * \return result
1409 */
1410 template<class T>
1411 const result_type& operator()(TH3* h3,
1412 const JFs_t& f3,
1413 const T& type,
1414 const index_list& ls = index_list(),
1415 const range_type& X = range_type(),
1416 const range_type& Y = range_type(),
1417 const range_type& Z = range_type())
1418 {
1419 (*this)(*h3, f3, type, ls, X, Y, Z);
1420
1421 h3->GetListOfFunctions()->Add(new JF3("f3",
1422 this->value,
1423 JTOOLS::join(X, getRange(h3->GetXaxis())),
1424 JTOOLS::join(Y, getRange(h3->GetYaxis())),
1425 JTOOLS::join(Z, getRange(h3->GetZaxis()))));
1426
1427 return static_cast<const result_type&>(*this);
1428 }
1429
1430
1431 static JRootfit Fit; //!< Global fit object
1432
1433 private:
1434 size_t getNumberOfFreeParameters(); // hide method
1435 size_t getN(); // hide method
1436 double getChi2(); // hide method
1437 int getNDF(); // hide method
1438
1439
1440 /**
1441 * Evaluate fit.
1442 *
1443 * \param fs start value
1444 * \param ls list of fixed parameters
1445 * \param data data
1446 * \return result
1447 */
1448 template<class T>
1449 const result_type& eval(const JFs_t& fs,
1450 const index_list& ls,
1451 const data_type<T>& data)
1452 {
1453 this->parameters.clear();
1454
1455 for (size_t i = 0; i != JFs_t::parameters.size(); ++i) {
1456 if (ls.count(i) == 0) {
1457 this->parameters.push_back(JFs_t::parameters[i]);
1458 }
1459 }
1460
1461 this->value = fs;
1462 this->npx = data.size();
1463 this->chi2 = static_cast<JGandalf<JFs_t>&>(*this)(this->fit, data.begin(), data.end()).chi2;
1464
1465 return static_cast<const result_type&>(*this);
1466 }
1467
1468
1469 /**
1470 * Auxiliary data structure for fit functions.
1471 */
1472 const struct function_type {
1473
1475
1476 /**
1477 * Fit function.
1478 *
1479 * \param fs function
1480 * \param mp data point
1481 * \return chi2 and gradient
1482 */
1483 template<class T>
1484 inline const result_type& operator()(const JFs_t& fs, const m_1d<T>& mp) const
1485 {
1486 const double y = fs.getValue(mp.x);
1487
1488 result.chi2 = mp.getRho(y);
1489 result.gradient = fs.getGradient(mp.x);
1490 result.gradient *= mp.getPsi(y);
1491
1492 return result;
1493 }
1494
1495
1496 /**
1497 * Fit function.
1498 *
1499 * \param fs function
1500 * \param mp data point
1501 * \return chi2 and gradient
1502 */
1503 template<class T>
1504 inline const result_type& operator()(const JFs_t& fs, const m_2d<T>& mp) const
1505 {
1506 const double y = fs.getValue(mp.x, mp.y);
1507
1508 result.chi2 = mp.getRho(y);
1509 result.gradient = fs.getGradient(mp.x, mp.y);
1510 result.gradient *= mp.getPsi(y);
1511
1512 return result;
1513 }
1514
1515
1516 /**
1517 * Fit function.
1518 *
1519 * \param fs function
1520 * \param mp data point
1521 * \return chi2 and gradient
1522 */
1523 template<class T>
1524 inline const result_type& operator()(const JFs_t& fs, const m_3d<T>& mp) const
1525 {
1526 const double y = fs.getValue(mp.x, mp.y, mp.z);
1527
1528 result.chi2 = mp.getRho(y);
1529 result.gradient = fs.getGradient(mp.x, mp.y, mp.z);
1530 result.gradient *= mp.getPsi(y);
1531
1532 return result;
1533 }
1534
1535 private:
1538 };
1539
1540
1541 /**
1542 * Global fit object.
1543 */
1544 template<class JFs_t>
1546
1547
1548 /**
1549 * Global fit fuction.
1550 *
1551 * The template parameter <tt>T</tt> refers to the measurement and can be <tt>m_count</tt> or <tt>m_value</tt>.\n
1552 *
1553 * \param h1 histogram
1554 * \param f1 start value
1555 * \param ls list of fixed parameters
1556 * \param X fit range
1557 * \return result
1558 */
1559 template<class T, class JF1_t>
1560 inline JRootfit_t<JF1_t> Fit(const TH1& h1,
1561 const JF1_t& f1,
1562 const index_list& ls = index_list(),
1563 const range_type& X = range_type())
1564 {
1565 return JRootfit<JF1_t>::Fit(h1, f1, T(), ls, X);
1566 }
1567
1568
1569 /**
1570 * Global fit fuction.
1571 *
1572 * The template parameter <tt>T</tt> refers to the measurement and can be <tt>m_count</tt> or <tt>m_value</tt>.\n
1573 * The fitted function is added to the input histogram.
1574 *
1575 * \param h1 pointer to histogram
1576 * \param f1 start value
1577 * \param ls list of fixed parameters
1578 * \param X fit range
1579 * \return result
1580 */
1581 template<class T, class JF1_t>
1582 inline JRootfit_t<JF1_t> Fit(TH1* h1,
1583 const JF1_t& f1,
1584 const index_list& ls = index_list(),
1585 const range_type& X = range_type())
1586 {
1587 return JRootfit<JF1_t>::Fit(h1, f1, T(), ls, X);
1588 }
1589
1590
1591 /**
1592 * Global fit fuction.
1593 *
1594 * \param g1 graph
1595 * \param f1 start value
1596 * \param ls list of fixed parameters
1597 * \param X fit range
1598 * \return result
1599 */
1600 template<class JF1_t>
1601 inline JRootfit_t<JF1_t> Fit(const TGraphErrors& g1,
1602 const JF1_t& f1,
1603 const index_list& ls = index_list(),
1604 const range_type& X = range_type())
1605 {
1606 return JRootfit<JF1_t>::Fit(g1, f1, ls, X);
1607 }
1608
1609
1610 /**
1611 * Global fit fuction.
1612 *
1613 * \param g1 pointer to graph
1614 * \param f1 start value
1615 * \param ls list of fixed parameters
1616 * \param X fit range
1617 * \return result
1618 */
1619 template<class JF1_t>
1620 inline JRootfit_t<JF1_t> Fit(TGraphErrors* g1,
1621 const JF1_t& f1,
1622 const index_list& ls = index_list(),
1623 const range_type& X = range_type())
1624 {
1625 return JRootfit<JF1_t>::Fit(g1, f1, ls, X);
1626 }
1627
1628
1629 /**
1630 * Global fit fuction.
1631 *
1632 * The template parameter <tt>T</tt> refers to the measurement and can be <tt>m_count</tt> or <tt>m_value</tt>.\n
1633 *
1634 * \param h2 histogram
1635 * \param f2 start value
1636 * \param ls list of fixed parameters
1637 * \param X fit range
1638 * \param Y fit range
1639 * \return result
1640 */
1641 template<class T, class JF2_t>
1642 inline JRootfit_t<JF2_t> Fit(const TH2& h2,
1643 const JF2_t& f2,
1644 const index_list& ls = index_list(),
1645 const range_type& X = range_type(),
1646 const range_type& Y = range_type())
1647 {
1648 return JRootfit<JF2_t>::Fit(h2, f2, T(), ls, X, Y);
1649 }
1650
1651
1652 /**
1653 * Global fit fuction.
1654 *
1655 * The template parameter <tt>T</tt> refers to the measurement and can be <tt>m_count</tt> or <tt>m_value</tt>.\n
1656 * The fitted function is added to the input histogram.
1657 *
1658 * \param h2 pointer to histogram
1659 * \param f2 start value
1660 * \param ls list of fixed parameters
1661 * \param X fit range
1662 * \param Y fit range
1663 * \return result
1664 */
1665 template<class T, class JF2_t>
1666 inline JRootfit_t<JF2_t> Fit(TH2* h2,
1667 const JF2_t& f2,
1668 const index_list& ls = index_list(),
1669 const range_type& X = range_type(),
1670 const range_type& Y = range_type())
1671 {
1672 return JRootfit<JF2_t>::Fit(h2, f2, T(), ls, X, Y);
1673 }
1674
1675
1676 /**
1677 * Global fit fuction.
1678 *
1679 * \param g2 graph
1680 * \param f2 start value
1681 * \param ls list of fixed parameters
1682 * \param X fit range
1683 * \param Y fit range
1684 * \return result
1685 */
1686 template<class JF2_t>
1687 inline JRootfit_t<JF2_t> Fit(const TGraph2DErrors& g2,
1688 const JF2_t& f2,
1689 const index_list& ls = index_list(),
1690 const range_type& X = range_type(),
1691 const range_type& Y = range_type())
1692 {
1693 return JRootfit<JF2_t>::Fit(g2, f2, ls, X, Y);
1694 }
1695
1696
1697 /**
1698 * Global fit fuction.
1699 *
1700 * \param g2 pointer to graph
1701 * \param f2 start value
1702 * \param ls list of fixed parameters
1703 * \param X fit range
1704 * \param Y fit range
1705 * \return result
1706 */
1707 template<class JF2_t>
1708 inline JRootfit_t<JF2_t> Fit(TGraph2DErrors* g2,
1709 const JF2_t& f2,
1710 const index_list& ls = index_list(),
1711 const range_type& X = range_type(),
1712 const range_type& Y = range_type())
1713
1714 {
1715 return JRootfit<JF2_t>::Fit(g2, f2, ls, X, Y);
1716 }
1717
1718
1719 /**
1720 * Global fit fuction.
1721 *
1722 * The template parameter <tt>T</tt> refers to the measurement and can be <tt>m_count</tt> or <tt>m_value</tt>.\n
1723 *
1724 * \param h3 histogram
1725 * \param f3 start value
1726 * \param ls list of fixed parameters
1727 * \param X fit range
1728 * \param Y fit range
1729 * \param Z fit range
1730 * \return result
1731 */
1732 template<class T, class JF3_t>
1733 inline JRootfit_t<JF3_t> Fit(const TH3& h3,
1734 const JF3_t& f3,
1735 const index_list& ls = index_list(),
1736 const range_type& X = range_type(),
1737 const range_type& Y = range_type(),
1738 const range_type& Z = range_type())
1739 {
1740 return JRootfit<JF3_t>::Fit(h3, f3, T(), ls, X, Y, Z);
1741 }
1742
1743
1744 /**
1745 * Global fit fuction.
1746 *
1747 * The template parameter <tt>T</tt> refers to the measurement and can be <tt>m_count</tt> or <tt>m_value</tt>.\n
1748 * The fitted function is added to the input histogram.
1749 *
1750 * \param h3 pointer to histogram
1751 * \param f3 start value
1752 * \param ls list of fixed parameters
1753 * \param X fit range
1754 * \param Y fit range
1755 * \param Z fit range
1756 * \return result
1757 */
1758 template<class T, class JF3_t>
1759 inline JRootfit_t<JF3_t> Fit(TH3* h3,
1760 const JF3_t& f3,
1761 const index_list& ls = index_list(),
1762 const range_type& X = range_type(),
1763 const range_type& Y = range_type(),
1764 const range_type& Z = range_type())
1765 {
1766 return JRootfit<JF3_t>::Fit(h3, f3, T(), ls, X, Y, Z);
1767 }
1768}
1769
1770#endif
Maximum likelihood estimator (M-estimators).
I/O manipulators.
Auxiliary methods for mathematics.
Functional algebra.
double f3(const double x, const double y, const double z)
3D function.
Double_t g1(const Double_t x)
Function.
Definition JQuantiles.cc:25
Auxiliary class to define a range between two values.
Fit method based on the Levenberg-Marquardt method.
Definition JGandalf.hh:87
std::vector< parameter_type > parameters
fit parameters
Definition JGandalf.hh:339
int numberOfIterations
number of iterations
Definition JGandalf.hh:340
JModel_t value
value
Definition JGandalf.hh:342
JModel_t error
error
Definition JGandalf.hh:343
Base class for result of ROOT Fit.
Definition JRootfit.hh:1029
JRootfit_t()
Default constructor.
Definition JRootfit.hh:1034
double chi2
chi2
Definition JRootfit.hh:1045
void print(std::ostream &out) const
Print result.
Definition JRootfit.hh:1141
const JFs_t & getFunction() const
Get function.
Definition JRootfit.hh:1053
int getNDF() const
Get number of degrees of freedom.
Definition JRootfit.hh:1108
size_t getNumberOfParameters() const
Get number of parameters.
Definition JRootfit.hh:1064
double getChi2() const
Get chi2.
Definition JRootfit.hh:1097
double getValue(size_t i) const
Get value of parameter at given index.
Definition JRootfit.hh:1119
double getError(size_t i) const
Get error of parameter at given index.
Definition JRootfit.hh:1130
size_t getNumberOfFreeParameters() const
Get number of free parameters.
Definition JRootfit.hh:1075
size_t getN() const
Get number of data points.
Definition JRootfit.hh:1086
size_t npx
number of data points
Definition JRootfit.hh:1044
static JRootfit Fit
Global fit object.
Definition JRootfit.hh:1431
const result_type & operator()(const TGraphErrors &g1, const JFs_t &f1, const index_list &ls=index_list(), const range_type &X=range_type())
Fit.
Definition JRootfit.hh:1236
const result_type & operator()(TH3 *h3, const JFs_t &f3, const T &type, const index_list &ls=index_list(), const range_type &X=range_type(), const range_type &Y=range_type(), const range_type &Z=range_type())
Fit.
Definition JRootfit.hh:1411
const result_type & operator()(TH1 *h1, const JFs_t &f1, const T &type, const index_list &ls=index_list(), const range_type &X=range_type())
Fit.
Definition JRootfit.hh:1211
const result_type & operator()(TGraphErrors *g1, const JFs_t &f1, const index_list &ls=index_list(), const range_type &X=range_type())
Fit.
Definition JRootfit.hh:1254
const result_type & operator()(const TH3 &h3, const JFs_t &f3, const T &type, const index_list &ls=index_list(), const range_type &X=range_type(), const range_type &Y=range_type(), const range_type &Z=range_type())
Fit.
Definition JRootfit.hh:1384
size_t getNumberOfFreeParameters()
const result_type & operator()(TH2 *h2, const JFs_t &f2, const T &type, const index_list &ls=index_list(), const range_type &X=range_type(), const range_type &Y=range_type())
Fit.
Definition JRootfit.hh:1306
const result_type & operator()(const TH2 &h2, const JFs_t &f2, const T &type, const index_list &ls=index_list(), const range_type &X=range_type(), const range_type &Y=range_type())
Fit.
Definition JRootfit.hh:1281
const result_type & operator()(const TGraph2DErrors &g2, const JFs_t &f2, const index_list &ls=index_list(), const range_type &X=range_type(), const range_type &Y=range_type())
Fit.
Definition JRootfit.hh:1334
const result_type & operator()(TGraph2DErrors *g2, const JFs_t &f2, const index_list &ls=index_list(), const range_type &X=range_type(), const range_type &Y=range_type())
Fit.
Definition JRootfit.hh:1354
const struct JROOT::JRootfit::function_type fit
double getChi2()
const result_type & operator()(const TH1 &h1, const JFs_t &f1, const T &type, const index_list &ls=index_list(), const range_type &X=range_type())
Fit.
Definition JRootfit.hh:1188
JRootfit_t< JFs_t > result_type
Definition JRootfit.hh:1167
const result_type & eval(const JFs_t &fs, const index_list &ls, const data_type< T > &data)
Evaluate fit.
Definition JRootfit.hh:1449
JRootfit()
Default constructor.
Definition JRootfit.hh:1173
Range of values.
Definition JRange.hh:42
static JRange< double, std::less< double > > DEFAULT_RANGE()
Definition JRange.hh:555
range_type & include(argument_type x)
Include given value to range.
Definition JRange.hh:397
JMEstimator * getMEstimator(const int type)
Get M-Estimator.
constexpr size_t getNumberOfParameters()
Get number of parameters.
Definition JMathlib.hh:135
void setParameters(JF1_t *f1, const double *values)
Set values of all parameters.
Definition JMathlib.hh:148
double poisson(const size_t n, const double mu)
Poisson probability density distribution.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
range_type getRangeX(const TGraph2D &g2)
Get range of given graph.
Definition JRootfit.hh:105
range_type getRangeY(const TGraph2D &g2)
Get range of given graph.
Definition JRootfit.hh:117
JTOOLS::JRange< double > range_type
Type definiton of abscissa range.
Definition JRootfit.hh:50
JRootfit_t< JF1_t > Fit(const TH1 &h1, const JF1_t &f1, const index_list &ls=index_list(), const range_type &X=range_type())
Global fit fuction.
Definition JRootfit.hh:1560
range_type getRange(TAxis *pAxis)
Get range of given axis.
Definition JRootfit.hh:59
JRange< T, JComparator_t > join(const JRange< T, JComparator_t > &first, const JRange< T, JComparator_t > &second)
Join ranges.
Definition JRange.hh:659
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Data structure for return value of fit function.
Definition JGandalf.hh:102
JModel_t gradient
partial derivatives of chi2
Definition JGandalf.hh:137
Normal M-estimator.
Interface for maximum likelihood estimator (M-estimator).
double operator()(const double *x, const double *parameters)
ROOT compatible function call.
Definition JRootfit.hh:836
helper(const JF1_t &f1)
Constructor.
Definition JRootfit.hh:824
Wrapper data structure to build ROOT 1D function.
Definition JRootfit.hh:790
JF1(const char *const name, const JF1_t &f1, const range_type &X)
Constructor.
Definition JRootfit.hh:799
double operator()(const double *x, const double *parameters)
ROOT compatible function call.
Definition JRootfit.hh:902
helper(const JF2_t &f2)
Constructor.
Definition JRootfit.hh:890
Wrapper data structure to build ROOT 2D function.
Definition JRootfit.hh:851
JF2(const char *const name, const JF2_t &f2, const range_type &X, const range_type &Y)
Constructor.
Definition JRootfit.hh:861
helper(const JF3_t &f3)
Constructor.
Definition JRootfit.hh:961
double operator()(const double *x, const double *parameters)
ROOT compatible function call.
Definition JRootfit.hh:973
Wrapper data structure to build ROOT 3D function.
Definition JRootfit.hh:917
JF3(const char *const name, const JF3_t &f3, const range_type &X, const range_type &Y, const range_type &Z)
Constructor.
Definition JRootfit.hh:928
Auxiliary data structure for fit functions.
Definition JRootfit.hh:1472
JGandalf< JFs_t >::result_type result_type
Definition JRootfit.hh:1474
const result_type & operator()(const JFs_t &fs, const m_1d< T > &mp) const
Fit function.
Definition JRootfit.hh:1484
const result_type & operator()(const JFs_t &fs, const m_2d< T > &mp) const
Fit function.
Definition JRootfit.hh:1504
const result_type & operator()(const JFs_t &fs, const m_3d< T > &mp) const
Fit function.
Definition JRootfit.hh:1524
void unpack(const TGraphErrors &g1, const range_type &X=range_type())
Unpack 1D-graph.
data_type(const TH1 &h1, const range_type &X=range_type())
Unpack constructor.
Definition JRootfit.hh:415
void unpack(const TH1 &h1, const range_type &X=range_type())
Unpack 1D-histogram.
data_type(const TGraphErrors &g1, const range_type &X=range_type())
Unpack constructor.
Definition JRootfit.hh:428
data_type()
Default constructor.
Definition JRootfit.hh:405
void unpack(const TGraph2DErrors &g2, const range_type &X=range_type(), const range_type &Y=range_type())
Unpack 2D-graph.
void unpack(const TH2 &h2, const range_type &X=range_type(), const range_type &Y=range_type())
Unpack 2D-histogram.
data_type(const TGraph2DErrors &g2, const range_type &X=range_type(), const range_type &Y=range_type())
Unpack constructor.
Definition JRootfit.hh:560
data_type()
Default constructor.
Definition JRootfit.hh:534
data_type(const TH2 &h2, const range_type &X=range_type(), const range_type &Y=range_type())
Unpack constructor.
Definition JRootfit.hh:545
data_type()
Default constructor.
Definition JRootfit.hh:684
data_type(const TH3 &h3, const range_type &X=range_type(), const range_type &Y=range_type(), const range_type &Z=range_type())
Unpack constructor.
Definition JRootfit.hh:696
void unpack(const TH3 &h3, const range_type &X=range_type(), const range_type &Y=range_type(), const range_type &Z=range_type())
Unpack 3D-histogram.
Template definition of data structure for set of data points.
Definition JRootfit.hh:392
void unpack(const TH1 &h1, const range_type &X)
Unpack 1D-histogram.
Definition JRootfit.hh:463
Auxiliary data structure for list of fixed parameters.
Definition JRootfit.hh:988
index_list(const std::initializer_list< size_t > &indices)
Constructor.
Definition JRootfit.hh:1001
index_list()
Default constructor.
Definition JRootfit.hh:992
index_list(const std::initializer_list< double T::* > &parameters)
Conversion constructor.
Definition JRootfit.hh:1012
1D data point.
Definition JRootfit.hh:289
m_1d()
Default constructor.
Definition JRootfit.hh:293
m_1d(const double x, const T &v)
Constructor.
Definition JRootfit.hh:305
double x
abscissa
Definition JRootfit.hh:310
2D data point.
Definition JRootfit.hh:320
double y
abscissa
Definition JRootfit.hh:345
m_2d(const double x, const double y, const T &v)
Constructor.
Definition JRootfit.hh:338
m_2d()
Default constructor.
Definition JRootfit.hh:324
double x
abscissa
Definition JRootfit.hh:344
3D data point.
Definition JRootfit.hh:355
double x
abscissa
Definition JRootfit.hh:382
m_3d(const double x, const double y, const double z, const T &v)
Constructor.
Definition JRootfit.hh:375
double z
abscissa
Definition JRootfit.hh:384
double y
abscissa
Definition JRootfit.hh:383
m_3d()
Default constructor.
Definition JRootfit.hh:359
Data point for counting measurement.
Definition JRootfit.hh:126
double getPsi(const double z) const
Get derivative of chi2.
Definition JRootfit.hh:176
double getRho(const double z) const
Get chi2.
Definition JRootfit.hh:162
static double epsilon()
Minimal value for numerical computations.
Definition JRootfit.hh:150
m_count()
Default constructor.
Definition JRootfit.hh:130
size_t count
count
Definition JRootfit.hh:182
m_count(const size_t count)
Constructor.
Definition JRootfit.hh:140
Data point for value with error.
Definition JRootfit.hh:189
static const estimator_type & getMEstimator()
Get M-estimator.
Definition JRootfit.hh:252
double getRho(const double z) const
Get chi2.
Definition JRootfit.hh:221
static estimator_type & get_mestimator()
Get M-estimator.
Definition JRootfit.hh:274
m_value(const double value, const double error)
Constructor.
Definition JRootfit.hh:208
m_value()
Default constructor.
Definition JRootfit.hh:196
std::shared_ptr< JMEstimator > estimator_type
Definition JRootfit.hh:191
double getPsi(const double z) const
Get derivative of chi2.
Definition JRootfit.hh:235
double value
value
Definition JRootfit.hh:243
static const void setMEstimator(int type)
Set M-estimator.
Definition JRootfit.hh:263
double error
error
Definition JRootfit.hh:244