CMS 3D CMS Logo

MultiHistoChiSquare.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_Utilities_MultiHistoChiSquare_h
2 #define PhysicsTools_Utilities_MultiHistoChiSquare_h
4 #include "TMath.h"
5 #include "TH1.h"
6 
7 namespace fit {
8  namespace helper {
10  }
11 
12  template<typename T1,
13  typename T2 = helper::MultiHistoChiSquareNoArg,
14  typename T3 = helper::MultiHistoChiSquareNoArg,
19  public:
21  template<typename TT1, typename TT2, typename TT3, typename TT4, typename TT5, typename TT6>
22  MultiHistoChiSquare(TT1 & t1, TH1 *histo1,
23  TT2 & t2, TH1 *histo2,
24  TT3 & t3, TH1 *histo3,
25  TT4 & t4, TH1 *histo4,
26  TT5 & t5, TH1 *histo5,
27  TT6 & t6, TH1 *histo6,
28  double rangeMin, double rangeMax) :
29  chi1_(t1, histo1, rangeMin, rangeMax),
30  chi2_(t2, histo2, rangeMin, rangeMax),
31  chi3_(t3, histo3, rangeMin, rangeMax),
32  chi4_(t4, histo4, rangeMin, rangeMax),
33  chi5_(t5, histo5, rangeMin, rangeMax),
34  chi6_(t6, histo6, rangeMin, rangeMax) {
35  }
36  double operator()() const {
37  double chi2 = chi1_() + chi2_() + chi3_() + chi4_() + chi5_() + chi6_();
38  static size_t count = 0;
39  ++count;
40  if(count % 10 == 0)
41  return chi2;
42 
43  }
44  void setHistos(TH1 *histo1, TH1 *histo2, TH1 *histo3, TH1 * histo4, TH1 * histo5, TH1 * histo6 ) {
45  chi1_.setHistos(histo1);
46  chi2_.setHistos(histo2);
47  chi3_.setHistos(histo3);
48  chi4_.setHistos(histo4);
49  chi5_.setHistos(histo5);
50  chi6_.setHistos(histo6);
51  }
52  size_t numberOfBins() const {
53  return
54  chi1_.numberOfBins() +
55  chi2_.numberOfBins() +
56  chi3_.numberOfBins() +
57  chi4_.numberOfBins() +
58  chi5_.numberOfBins() +
59  chi6_.numberOfBins() ;
60  }
61  T1 & function1() { return chi1_.function(); }
62  const T1 & function1() const { return chi1_.function(); }
63  T2 & function2() { return chi2_.function(); }
64  const T2 & function2() const { return chi2_.function(); }
65  T3 & function3() { return chi3_.function(); }
66  const T3 & function3() const { return chi3_.function(); }
67  T4 & function4() { return chi4_.function(); }
68  const T4 & function4() const { return chi4_.function(); }
69  T5 & function5() { return chi5_.function(); }
70  const T5 & function5() const { return chi5_.function(); }
71  T6 & function6() { return chi6_.function(); }
72  const T6 & function6() const { return chi6_.function(); }
73  private:
74  T1 chi1_;
75  T2 chi2_;
76  T3 chi3_;
77  T4 chi4_;
78  T5 chi5_;
79  T6 chi6_;
80 };
81 
82 
83 
84  template<typename T1, typename T2, typename T3, typename T4, typename T5>
85  class MultiHistoChiSquare<T1, T2, T3, T4, T5,
86  helper::MultiHistoChiSquareNoArg> {
87  public:
89  template<typename TT1, typename TT2, typename TT3, typename TT4, typename TT5>
90  MultiHistoChiSquare(TT1 & t1, TH1 *histo1,
91  TT2 & t2, TH1 *histo2,
92  TT3 & t3, TH1 *histo3,
93  TT4 & t4, TH1 *histo4,
94  TT5 & t5, TH1 *histo5,
95  double rangeMin, double rangeMax) :
96  chi1_(t1, histo1, rangeMin, rangeMax),
97  chi2_(t2, histo2, rangeMin, rangeMax),
98  chi3_(t3, histo3, rangeMin, rangeMax),
99  chi4_(t4, histo4, rangeMin, rangeMax),
100  chi5_(t5, histo5, rangeMin, rangeMax) {
101  }
102  double operator()() const {
103  double chi2 = chi1_() + chi2_() + chi3_() + chi4_() + chi5_();
104  static size_t count = 0;
105  ++count;
106  return chi2;
107  }
108  void setHistos(TH1 *histo1, TH1 *histo2, TH1 *histo3, TH1 * histo4, TH1 * histo5) {
109  chi1_.setHistos(histo1);
110  chi2_.setHistos(histo2);
111  chi3_.setHistos(histo3);
112  chi4_.setHistos(histo4);
113  chi5_.setHistos(histo5);
114  }
115  size_t numberOfBins() const {
116  return
117  chi1_.numberOfBins() +
118  chi2_.numberOfBins() +
119  chi3_.numberOfBins() +
120  chi4_.numberOfBins() +
121  chi5_.numberOfBins();
122  }
123  T1 & function1() { return chi1_.function(); }
124  const T1 & function1() const { return chi1_.function(); }
125  T2 & function2() { return chi2_.function(); }
126  const T2 & function2() const { return chi2_.function(); }
127  T3 & function3() { return chi3_.function(); }
128  const T3 & function3() const { return chi3_.function(); }
129  T4 & function4() { return chi4_.function(); }
130  const T4 & function4() const { return chi4_.function(); }
131  T5 & function5() { return chi5_.function(); }
132  const T5 & function5() const { return chi5_.function(); }
133  private:
134  T1 chi1_;
135  T2 chi2_;
136  T3 chi3_;
137  T4 chi4_;
138  T5 chi5_;
139 };
140 
141  template<typename T1, typename T2, typename T3, typename T4>
142  class MultiHistoChiSquare<T1, T2, T3, T4,
143  helper::MultiHistoChiSquareNoArg,
145  public:
147  template<typename TT1, typename TT2, typename TT3, typename TT4>
148  MultiHistoChiSquare(TT1 & t1, TH1 *histo1,
149  TT2 & t2, TH1 *histo2,
150  TT3 & t3, TH1 *histo3,
151  TT4 & t4, TH1 *histo4,
152  double rangeMin, double rangeMax) :
153  chi1_(t1, histo1, rangeMin, rangeMax),
154  chi2_(t2, histo2, rangeMin, rangeMax),
155  chi3_(t3, histo3, rangeMin, rangeMax),
156  chi4_(t4, histo4, rangeMin, rangeMax) {
157  }
158  double operator()() const {
159  double chi2 = chi1_() + chi2_() + chi3_() + chi4_();
160  static size_t count = 0;
161  ++count;
162  return chi2;
163  }
164  void setHistos(TH1 *histo1, TH1 *histo2, TH1 *histo3, TH1 * histo4) {
165  chi1_.setHistos(histo1);
166  chi2_.setHistos(histo2);
167  chi3_.setHistos(histo3);
168  chi4_.setHistos(histo4);
169  }
170  size_t numberOfBins() const {
171  return
172  chi1_.numberOfBins() +
173  chi2_.numberOfBins() +
174  chi3_.numberOfBins() +
175  chi4_.numberOfBins();
176  }
177  T1 & function1() { return chi1_.function(); }
178  const T1 & function1() const { return chi1_.function(); }
179  T2 & function2() { return chi2_.function(); }
180  const T2 & function2() const { return chi2_.function(); }
181  T3 & function3() { return chi3_.function(); }
182  const T3 & function3() const { return chi3_.function(); }
183  T4 & function4() { return chi4_.function(); }
184  const T4 & function4() const { return chi4_.function(); }
185  private:
186  T1 chi1_;
187  T2 chi2_;
188  T3 chi3_;
189  T4 chi4_;
190 };
191 
192 
193  template<typename T1, typename T2,typename T3>
194  class MultiHistoChiSquare<T1, T2, T3, helper::MultiHistoChiSquareNoArg,
197  public:
199  template<typename TT1, typename TT2, typename TT3>
200  MultiHistoChiSquare(TT1 & t1, TH1 *histo1,
201  TT2 & t2, TH1 *histo2,
202  TT3 & t3, TH1 *histo3,
203  double rangeMin, double rangeMax) :
204  chi1_(t1, histo1, rangeMin, rangeMax),
205  chi2_(t2, histo2, rangeMin, rangeMax),
206  chi3_(t3, histo3, rangeMin, rangeMax) {
207  }
208  double operator()() const {
209  return chi1_() + chi2_() + chi3_();
210  }
211  void setHistos(TH1 *histo1, TH1 *histo2, TH1 *histo3) {
212  chi1_.setHistos(histo1);
213  chi2_.setHistos(histo2);
214  chi3_.setHistos(histo3);
215  }
216  size_t numberOfBins() const {
217  return
218  chi1_.numberOfBins() +
219  chi2_.numberOfBins() +
220  chi3_.numberOfBins();
221  }
222  T1 & function1() { return chi1_.function(); }
223  const T1 & function1() const { return chi1_.function(); }
224  T2 & function2() { return chi2_.function(); }
225  const T2 & function2() const { return chi2_.function(); }
226  T3 & function3() { return chi3_.function(); }
227  const T3 & function3() const { return chi3_.function(); }
228  private:
229  T1 chi1_;
230  T2 chi2_;
231  T3 chi3_;
232 };
233 
234  template<typename T1, typename T2>
235  class MultiHistoChiSquare<T1, T2,
236  helper::MultiHistoChiSquareNoArg,
240  public:
242  template<typename TT1, typename TT2>
243  MultiHistoChiSquare(TT1 & t1, TH1 *histo1,
244  TT2 & t2, TH1 *histo2,
245  double rangeMin, double rangeMax):
246  chi1_(t1, histo1, rangeMin, rangeMax),
247  chi2_(t2, histo2, rangeMin, rangeMax) {
248  }
249  double operator()() const {
250  return chi1_() + chi2_();
251  }
252  void setHistos(TH1 *histo1, TH1 *histo2) {
253  chi1_.setHistos(histo1);
254  chi2_.setHistos(histo2);
255  }
256  size_t numberOfBins() const {
257  return
258  chi1_.numberOfBins() +
259  chi2_.numberOfBins();
260  }
261  private:
262  T1 chi1_;
263  T2 chi2_;
264  };
265 
266  template<typename T1>
268  helper::MultiHistoChiSquareNoArg,
273  public:
275  template<typename TT1>
276  MultiHistoChiSquare(TT1 & t1, TH1 *histo1, double rangeMin, double rangeMax)
277  : chi1_(t1, histo1, rangeMin, rangeMax) {
278  }
279  double operator()() const {
280  return chi1_();
281  }
282  void setHistos(TH1 *histo1) {
283  chi1_.setHistos(histo1);
284  }
285  size_t numberOfBins() const {
286  return chi1_.numberOfBins();
287  }
288  private:
289  T1 chi1_;
290  };
291 
292  template<typename T1, typename T2, typename T3,
293  typename T4, typename T5, typename T6>
294  struct RootMinuitResultPrinter<MultiHistoChiSquare<T1, T2, T3, T4, T5, T6> > {
295  static void print(double amin, unsigned int numberOfFreeParameters,
297  unsigned int ndof = f.numberOfBins() - numberOfFreeParameters;
298  std::cout << "chi-squared/n.d.o.f. = " << amin << "/" << ndof << " = " << amin/ndof
299  << "; prob: " << TMath::Prob(amin, ndof)
300  << std::endl;
301  }
302  };
303 }
304 
305 #endif
const T6 & function6() const
MultiHistoChiSquare(TT1 &t1, TH1 *histo1, TT2 &t2, TH1 *histo2, TT3 &t3, TH1 *histo3, TT4 &t4, TH1 *histo4, double rangeMin, double rangeMax)
Definition: helper.py:1
const T1 & function1() const
MultiHistoChiSquare(TT1 &t1, TH1 *histo1, TT2 &t2, TH1 *histo2, TT3 &t3, TH1 *histo3, TT4 &t4, TH1 *histo4, TT5 &t5, TH1 *histo5, double rangeMin, double rangeMax)
void setHistos(TH1 *histo1, TH1 *histo2, TH1 *histo3, TH1 *histo4, TH1 *histo5)
MultiHistoChiSquare(TT1 &t1, TH1 *histo1, TT2 &t2, TH1 *histo2, TT3 &t3, TH1 *histo3, TT4 &t4, TH1 *histo4, TT5 &t5, TH1 *histo5, TT6 &t6, TH1 *histo6, double rangeMin, double rangeMax)
double f[11][100]
const T5 & function5() const
void setHistos(TH1 *histo1, TH1 *histo2, TH1 *histo3, TH1 *histo4, TH1 *histo5, TH1 *histo6)
const T3 & function3() const
const T2 & function2() const
MultiHistoChiSquare(TT1 &t1, TH1 *histo1, TT2 &t2, TH1 *histo2, TT3 &t3, TH1 *histo3, double rangeMin, double rangeMax)
static void print(double amin, unsigned int numberOfFreeParameters, const MultiHistoChiSquare< T1, T2, T3, T4, T5, T6 > &f)
const T4 & function4() const