00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "RooFit.h"
00031
00032 #include "RooChi2Var.h"
00033 #include "RooChi2Var.h"
00034 #include "RooDataHist.h"
00035 #include "RooAbsPdf.h"
00036 #include "RooCmdConfig.h"
00037 #include "RooMsgService.h"
00038
00039 #include "Riostream.h"
00040
00041 #include "RooRealVar.h"
00042
00043
00044 ClassImp(RooChi2Var)
00045 ;
00046
00047 RooArgSet RooChi2Var::_emptySet ;
00048
00049
00050
00051 RooChi2Var::RooChi2Var(const char *name, const char* title, RooAbsReal& func, RooDataHist& hdata,
00052 const RooCmdArg& arg1,const RooCmdArg& arg2,const RooCmdArg& arg3,
00053 const RooCmdArg& arg4,const RooCmdArg& arg5,const RooCmdArg& arg6,
00054 const RooCmdArg& arg7,const RooCmdArg& arg8,const RooCmdArg& arg9) :
00055 RooAbsOptTestStatistic(name,title,func,hdata,_emptySet,
00056 RooCmdConfig::decodeStringOnTheFly("RooChi2Var::RooChi2Var","RangeWithName",0,"",arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9),
00057 0,
00058 RooCmdConfig::decodeIntOnTheFly("RooChi2Var::RooChi2Var","NumCPU",0,1,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9),
00059 RooCmdConfig::decodeIntOnTheFly("RooChi2Var::RooChi2Var","Verbose",0,1,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9),
00060 0)
00061
00062
00063
00064
00065
00066
00067 {
00068 RooCmdConfig pc("RooChi2Var::RooChi2Var") ;
00069 pc.defineInt("etype","DataError",0,(Int_t)RooDataHist::SumW2) ;
00070 pc.allowUndefined() ;
00071
00072 pc.process(arg1) ; pc.process(arg2) ; pc.process(arg3) ;
00073 pc.process(arg4) ; pc.process(arg5) ; pc.process(arg6) ;
00074 pc.process(arg7) ; pc.process(arg8) ; pc.process(arg9) ;
00075
00076 _funcMode = Function ;
00077 _etype = (RooDataHist::ErrorType) pc.getInt("etype") ;
00078 }
00079
00080
00081
00082
00083 RooChi2Var::RooChi2Var(const char *name, const char* title, RooAbsPdf& pdf, RooDataHist& hdata,
00084 const RooCmdArg& arg1,const RooCmdArg& arg2,const RooCmdArg& arg3,
00085 const RooCmdArg& arg4,const RooCmdArg& arg5,const RooCmdArg& arg6,
00086 const RooCmdArg& arg7,const RooCmdArg& arg8,const RooCmdArg& arg9) :
00087 RooAbsOptTestStatistic(name,title,pdf,hdata,
00088 *(const RooArgSet*)RooCmdConfig::decodeObjOnTheFly("RooChi2Var::RooChi2Var","ProjectedObservables",0,&_emptySet
00089 ,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9),
00090 RooCmdConfig::decodeStringOnTheFly("RooChi2Var::RooChi2Var","RangeWithName",0,"",arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9),
00091 RooCmdConfig::decodeStringOnTheFly("RooChi2Var::RooChi2Var","AddCoefRange",0,"",arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9),
00092 RooCmdConfig::decodeIntOnTheFly("RooChi2Var::RooChi2Var","NumCPU",0,1,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9),
00093 RooCmdConfig::decodeIntOnTheFly("RooChi2Var::RooChi2Var","Verbose",0,1,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9),
00094 RooCmdConfig::decodeIntOnTheFly("RooChi2Var::RooChi2Var","SplitRange",0,0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9))
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 {
00106 RooCmdConfig pc("RooChi2Var::RooChi2Var") ;
00107 pc.defineInt("extended","Extended",0,kFALSE) ;
00108 pc.defineInt("etype","DataError",0,(Int_t)RooDataHist::SumW2) ;
00109 pc.allowUndefined() ;
00110
00111 pc.process(arg1) ; pc.process(arg2) ; pc.process(arg3) ;
00112 pc.process(arg4) ; pc.process(arg5) ; pc.process(arg6) ;
00113 pc.process(arg7) ; pc.process(arg8) ; pc.process(arg9) ;
00114
00115 _funcMode = pc.getInt("extended") ? ExtendedPdf : Pdf ;
00116 _etype = (RooDataHist::ErrorType) pc.getInt("etype") ;
00117 }
00118
00119
00120
00121
00122 RooChi2Var::RooChi2Var(const char *name, const char *title, RooAbsPdf& pdf, RooDataHist& hdata,
00123 Bool_t extended, const char* cutRange, const char* addCoefRange,
00124 Int_t nCPU, Bool_t interleave, Bool_t verbose, Bool_t splitCutRange, RooDataHist::ErrorType etype) :
00125 RooAbsOptTestStatistic(name,title,pdf,hdata,RooArgSet(),cutRange,addCoefRange,nCPU,interleave,verbose,splitCutRange),
00126 _etype(etype), _funcMode(extended?ExtendedPdf:Pdf)
00127 {
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 }
00143
00144
00145
00146
00147 RooChi2Var::RooChi2Var(const char *name, const char *title, RooAbsReal& func, RooDataHist& hdata,
00148 const RooArgSet& projDeps, RooChi2Var::FuncMode fmode, const char* cutRange, const char* addCoefRange,
00149 Int_t nCPU, Bool_t interleave, Bool_t verbose, Bool_t splitCutRange, RooDataHist::ErrorType etype) :
00150 RooAbsOptTestStatistic(name,title,func,hdata,projDeps,cutRange,addCoefRange,nCPU,interleave,verbose,splitCutRange),
00151 _etype(etype), _funcMode(fmode)
00152 {
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 }
00169
00170
00171
00172
00173 RooChi2Var::RooChi2Var(const RooChi2Var& other, const char* name) :
00174 RooAbsOptTestStatistic(other,name),
00175 _etype(other._etype),
00176 _funcMode(other._funcMode)
00177 {
00178
00179 }
00180
00181
00182
00183
00184 RooChi2Var::~RooChi2Var()
00185 {
00186
00187 }
00188
00189
00190
00191
00192 Double_t RooChi2Var::evaluatePartition(Int_t firstEvent, Int_t lastEvent, Int_t stepSize) const
00193 {
00194
00195
00196 Int_t i ;
00197 Double_t result(0) ;
00198
00199
00200
00201 Double_t normFactor(Function) ;
00202 switch (_funcMode) {
00203 case Function: normFactor=1 ; break ;
00204 case Pdf: normFactor = _dataClone->sumEntries() ; break ;
00205 case ExtendedPdf: normFactor = ((RooAbsPdf*)_funcClone)->expectedEvents(_dataClone->get()) ; break ;
00206 }
00207
00208
00209 RooDataHist* hdata = (RooDataHist*) _dataClone ;
00210 for (i=firstEvent ; i<lastEvent ; i+=stepSize) {
00211
00212
00213 hdata->get(i);
00214
00215 if (!hdata->valid()) {
00216 continue ;
00217 }
00218
00219 Double_t nData = hdata->weight() ;
00220
00221 Double_t nPdf = _funcClone->getVal(_normSet) * normFactor * hdata->binVolume() ;
00222
00223 Double_t eExt = nPdf-nData ;
00224
00225 Double_t eIntLo,eIntHi ;
00226 hdata->weightError(eIntLo,eIntHi,_etype) ;
00227 Double_t eInt = (eExt>0) ? eIntHi : eIntLo ;
00228
00229
00230
00231 if (eInt==0. && nData==0. && nPdf==0) continue ;
00232
00233
00234 if (eInt==0.) {
00235 coutE(Eval) << "RooChi2Var::RooChi2Var(" << GetName() << ") INFINITY ERROR: bin " << i
00236 << " has zero error, but function is not zero (" << nPdf << ")" << endl ;
00237 return 0 ;
00238 }
00239
00240
00241
00242 result += eExt*eExt/(eInt*eInt) ;
00243 }
00244
00245
00246 return result ;
00247 }
00248
00249
00250