CMS 3D CMS Logo

MultiHistoChiSquare.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_Utilities_MultiHistoChiSquare_h
00002 #define PhysicsTools_Utilities_MultiHistoChiSquare_h
00003 
00004 #include "PhysicsTools/Utilities/interface/HistoChiSquare.h"
00005 #include "TH1.h"
00006 #include <iostream>
00007 
00008 namespace fit {
00009   namespace helper {
00010     struct MultiHistoChiSquareNoArg { };
00011   }
00012 
00013  template<typename T1, 
00014           typename T2 = helper::MultiHistoChiSquareNoArg, 
00015           typename T3 = helper::MultiHistoChiSquareNoArg, 
00016           typename T4 = helper::MultiHistoChiSquareNoArg,
00017           typename T5 = helper::MultiHistoChiSquareNoArg,
00018           typename T6 = helper::MultiHistoChiSquareNoArg>
00019   class MultiHistoChiSquare { 
00020    public:
00021     MultiHistoChiSquare() { }
00022     MultiHistoChiSquare(T1 & t1, TH1 *histo1,
00023                         T2 & t2, TH1 *histo2,
00024                         T3 & t3, TH1 *histo3,
00025                         T4 & t4, TH1 *histo4,
00026                         T5 & t5, TH1 *histo5,
00027                         T6 & t6, TH1 *histo6,
00028                         double rangeMin, double rangeMax) :
00029    chi1_(t1, histo1, rangeMin, rangeMax), 
00030    chi2_(t2, histo2, rangeMin, rangeMax), 
00031    chi3_(t3, histo3, rangeMin, rangeMax),
00032    chi4_(t4, histo4, rangeMin, rangeMax),
00033    chi5_(t5, histo5, rangeMin, rangeMax),
00034    chi6_(t6, histo6, rangeMin, rangeMax) {
00035    }
00036    double operator()() const { 
00037      double chi2 = chi1_() + chi2_() + chi3_() + chi4_() + chi5_() + chi6_();
00038      static size_t count = 0;
00039      ++count;
00040      if(count % 10 == 0)
00041      std::cout << ">>> " << count << ") chi2 = " << chi2 << std::endl;
00042      return chi2;
00043 
00044    }
00045    void setHistos(TH1 *histo1, TH1 *histo2, TH1 *histo3, TH1 * histo4, TH1 * histo5, TH1 * histo6 ) { 
00046      chi1_.setHistos(histo1);
00047      chi2_.setHistos(histo2);
00048      chi3_.setHistos(histo3);
00049      chi4_.setHistos(histo4);
00050      chi5_.setHistos(histo5);
00051      chi6_.setHistos(histo6);
00052    }
00053    size_t degreesOfFreedom() const { 
00054      return 
00055      chi1_.degreesOfFreedom() +
00056      chi2_.degreesOfFreedom() +
00057      chi3_.degreesOfFreedom() +
00058      chi4_.degreesOfFreedom() +
00059      chi5_.degreesOfFreedom() +
00060      chi6_.degreesOfFreedom() ;
00061    }
00062    T1 & function1() { return chi1_.function(); }
00063    const T1 & function1() const { return chi1_.function(); }
00064    T2 & function2() { return chi2_.function(); }
00065    const T2 & function2() const { return chi2_.function(); }
00066    T3 & function3() { return chi3_.function(); }
00067    const T3 & function3() const { return chi3_.function(); }
00068    T4 & function4() { return chi4_.function(); }
00069    const T4 & function4() const { return chi4_.function(); }
00070    T5 & function5() { return chi5_.function(); }
00071    const T5 & function5() const { return chi5_.function(); }
00072    T6 & function6() { return chi6_.function(); }
00073    const T6 & function6() const { return chi6_.function(); }
00074   private:
00075    HistoChiSquare<T1> chi1_;
00076    HistoChiSquare<T2> chi2_;
00077    HistoChiSquare<T3> chi3_;
00078    HistoChiSquare<T4> chi4_;
00079    HistoChiSquare<T5> chi5_;
00080    HistoChiSquare<T6> chi6_;
00081 };
00082 
00083 
00084   
00085   template<typename T1, typename T2, typename T3, typename T4, typename T5>
00086   class MultiHistoChiSquare<T1, T2, T3, T4, T5,
00087                             helper::MultiHistoChiSquareNoArg> { 
00088    public:
00089     MultiHistoChiSquare() { }
00090     MultiHistoChiSquare(T1 & t1, TH1 *histo1,
00091                         T2 & t2, TH1 *histo2,
00092                         T3 & t3, TH1 *histo3,
00093                         T4 & t4, TH1 *histo4,
00094                         T5 & t5, TH1 *histo5,
00095                         double rangeMin, double rangeMax) :
00096    chi1_(t1, histo1, rangeMin, rangeMax), 
00097    chi2_(t2, histo2, rangeMin, rangeMax), 
00098    chi3_(t3, histo3, rangeMin, rangeMax),
00099    chi4_(t4, histo4, rangeMin, rangeMax),
00100    chi5_(t5, histo5, rangeMin, rangeMax) {
00101    }
00102    double operator()() const { 
00103      double chi2 = chi1_() + chi2_() + chi3_() + chi4_() + chi5_();
00104      static size_t count = 0;
00105      ++count;
00106      if(count % 10 == 0) std::cout << ">>> total chi-2: " << chi2 << std::endl;
00107      return chi2;
00108    }
00109    void setHistos(TH1 *histo1, TH1 *histo2, TH1 *histo3, TH1 * histo4, TH1 * histo5) { 
00110      chi1_.setHistos(histo1);
00111      chi2_.setHistos(histo2);
00112      chi3_.setHistos(histo3);
00113      chi4_.setHistos(histo4);
00114      chi5_.setHistos(histo5);
00115    }
00116    size_t degreesOfFreedom() const { 
00117      return 
00118      chi1_.degreesOfFreedom() +
00119      chi2_.degreesOfFreedom() +
00120      chi3_.degreesOfFreedom() +
00121      chi4_.degreesOfFreedom() +
00122      chi5_.degreesOfFreedom();
00123    }
00124    T1 & function1() { return chi1_.function(); }
00125    const T1 & function1() const { return chi1_.function(); }
00126    T2 & function2() { return chi2_.function(); }
00127    const T2 & function2() const { return chi2_.function(); }
00128    T3 & function3() { return chi3_.function(); }
00129    const T3 & function3() const { return chi3_.function(); }
00130    T4 & function4() { return chi4_.function(); }
00131    const T4 & function4() const { return chi4_.function(); }
00132    T5 & function5() { return chi5_.function(); }
00133    const T5 & function5() const { return chi5_.function(); }
00134   private:
00135    HistoChiSquare<T1> chi1_;
00136    HistoChiSquare<T2> chi2_;
00137    HistoChiSquare<T3> chi3_;
00138    HistoChiSquare<T4> chi4_;
00139    HistoChiSquare<T5> chi5_;
00140 };
00141 
00142   template<typename T1, typename T2, typename T3, typename T4>
00143   class MultiHistoChiSquare<T1, T2, T3, T4,
00144                             helper::MultiHistoChiSquareNoArg,
00145                             helper::MultiHistoChiSquareNoArg> { 
00146    public:
00147     MultiHistoChiSquare() { }
00148     MultiHistoChiSquare(T1 & t1, TH1 *histo1,
00149                         T2 & t2, TH1 *histo2,
00150                         T3 & t3, TH1 *histo3,
00151                         T4 & t4, TH1 *histo4,
00152                         double rangeMin, double rangeMax) :
00153    chi1_(t1, histo1, rangeMin, rangeMax), 
00154    chi2_(t2, histo2, rangeMin, rangeMax), 
00155    chi3_(t3, histo3, rangeMin, rangeMax),
00156    chi4_(t4, histo4, rangeMin, rangeMax) {
00157    }
00158    double operator()() const { 
00159      double chi2 = chi1_() + chi2_() + chi3_() + chi4_();
00160      static size_t count = 0;
00161      ++count;
00162      if(count % 10 == 0) std::cout << ">>> total chi-2: " << chi2 << std::endl;
00163      return chi2;
00164    }
00165    void setHistos(TH1 *histo1, TH1 *histo2, TH1 *histo3, TH1 * histo4) { 
00166      chi1_.setHistos(histo1);
00167      chi2_.setHistos(histo2);
00168      chi3_.setHistos(histo3);
00169      chi4_.setHistos(histo4);
00170    }
00171    size_t degreesOfFreedom() const { 
00172      return 
00173      chi1_.degreesOfFreedom() +
00174      chi2_.degreesOfFreedom() +
00175      chi3_.degreesOfFreedom() +
00176      chi4_.degreesOfFreedom();
00177    }
00178    T1 & function1() { return chi1_.function(); }
00179    const T1 & function1() const { return chi1_.function(); }
00180    T2 & function2() { return chi2_.function(); }
00181    const T2 & function2() const { return chi2_.function(); }
00182    T3 & function3() { return chi3_.function(); }
00183    const T3 & function3() const { return chi3_.function(); }
00184    T4 & function4() { return chi4_.function(); }
00185    const T4 & function4() const { return chi4_.function(); }
00186   private:
00187    HistoChiSquare<T1> chi1_;
00188    HistoChiSquare<T2> chi2_;
00189    HistoChiSquare<T3> chi3_;
00190    HistoChiSquare<T4> chi4_;
00191 };
00192 
00193 
00194   template<typename T1, typename T2,typename T3>
00195   class MultiHistoChiSquare<T1, T2, T3, helper::MultiHistoChiSquareNoArg,
00196                                         helper::MultiHistoChiSquareNoArg,
00197                                         helper::MultiHistoChiSquareNoArg> { 
00198    public:
00199     MultiHistoChiSquare() { }
00200     MultiHistoChiSquare(T1 & t1, TH1 *histo1,
00201                         T2 & t2, TH1 *histo2,
00202                         T3 & t3, TH1 *histo3,
00203                         double rangeMin, double rangeMax) :
00204    chi1_(t1, histo1, rangeMin, rangeMax), 
00205    chi2_(t2, histo2, rangeMin, rangeMax), 
00206    chi3_(t3, histo3, rangeMin, rangeMax) {
00207    }
00208    double operator()() const { 
00209      return chi1_() + chi2_() + chi3_();
00210    }
00211    void setHistos(TH1 *histo1, TH1 *histo2, TH1 *histo3) { 
00212      chi1_.setHistos(histo1);
00213      chi2_.setHistos(histo2);
00214      chi3_.setHistos(histo3);
00215    }
00216    size_t degreesOfFreedom() const { 
00217      return 
00218        chi1_.degreesOfFreedom() +
00219        chi2_.degreesOfFreedom() +
00220        chi3_.degreesOfFreedom();
00221    }
00222    T1 & function1() { return chi1_.function(); }
00223    const T1 & function1() const { return chi1_.function(); }
00224    T2 & function2() { return chi2_.function(); }
00225    const T2 & function2() const { return chi2_.function(); }
00226    T3 & function3() { return chi3_.function(); }
00227    const T3 & function3() const { return chi3_.function(); }
00228   private:
00229    HistoChiSquare<T1> chi1_;
00230    HistoChiSquare<T2> chi2_;
00231    HistoChiSquare<T3> chi3_;
00232 };
00233 
00234   template<typename T1, typename T2>
00235   class MultiHistoChiSquare<T1, T2, 
00236                             helper::MultiHistoChiSquareNoArg, 
00237                             helper::MultiHistoChiSquareNoArg,
00238                             helper::MultiHistoChiSquareNoArg,
00239                             helper::MultiHistoChiSquareNoArg> {
00240    public:
00241     MultiHistoChiSquare() { }
00242     MultiHistoChiSquare(T1 & t1, TH1 *histo1,
00243                         T2 & t2, TH1 *histo2, 
00244                         double rangeMin, double rangeMax): 
00245       chi1_(t1, histo1, rangeMin, rangeMax), 
00246       chi2_(t2, histo2, rangeMin, rangeMax) {
00247     }
00248     double operator()() const { 
00249       return chi1_() + chi2_();
00250     }
00251     void setHistos(TH1 *histo1, TH1 *histo2) { 
00252       chi1_.setHistos(histo1);
00253       chi2_.setHistos(histo2);
00254     }
00255     size_t degreesOfFreedom() const { 
00256       return 
00257         chi1_.degreesOfFreedom() +
00258         chi2_.degreesOfFreedom();
00259     }
00260    private:
00261     HistoChiSquare<T1> chi1_;
00262     HistoChiSquare<T2> chi2_;
00263   };
00264   
00265   template<typename T1>
00266   class MultiHistoChiSquare<T1, 
00267                             helper::MultiHistoChiSquareNoArg, 
00268                             helper::MultiHistoChiSquareNoArg, 
00269                             helper::MultiHistoChiSquareNoArg,
00270                             helper::MultiHistoChiSquareNoArg,
00271                             helper::MultiHistoChiSquareNoArg> {
00272    public:
00273     MultiHistoChiSquare() { }
00274     MultiHistoChiSquare(T1 & t1, TH1 *histo1, double rangeMin, double rangeMax) 
00275       : chi1_(t1, histo1, rangeMin, rangeMax) {
00276     }
00277     double operator()() const { 
00278       return chi1_();
00279     }
00280     void setHistos(TH1 *histo1) { 
00281       chi1_.setHistos(histo1);
00282     }
00283     size_t degreesOfFreedom() const { 
00284       return chi1_.degreesOfFreedom(); 
00285     }
00286    private:
00287     HistoChiSquare<T1> chi1_;
00288   };
00289 }
00290 
00291 #endif

Generated on Tue Jun 9 17:42:42 2009 for CMSSW by  doxygen 1.5.4