00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00014
00015
00016
00017
00018
00019
00020 #include "RooRarFit/rarVersion.hh"
00021
00022 #include "Riostream.h"
00023
00024 #include "RooFitCore/RooArgList.hh"
00025 #include "RooFitCore/RooDataSet.hh"
00026 #include "RooFitCore/RooProdPdf.hh"
00027 #include "RooFitCore/RooStringVar.hh"
00028
00029 #include "RooRarFit/rarCompBase.hh"
00030
00031 ClassImp(rarCompBase)
00032 ;
00033
00037 rarCompBase::rarCompBase()
00038 : rarBasePdf(),
00039 _nComp(0)
00040 {
00041 setControlBits("UseBasePdfFit");
00042 init();
00043 }
00044
00061 rarCompBase::rarCompBase(const char *configFile, const char *configSec,
00062 const char *configStr,
00063 rarDatasets *theDatasets, RooDataSet *theData,
00064 const char *name, const char *title,
00065 Bool_t useBasePdfFit)
00066 : rarBasePdf(configFile, configSec, configStr,
00067 theDatasets, theData, name, title),
00068 _nComp(0)
00069 {
00070 if (useBasePdfFit) setControlBits("UseBasePdfFit");
00071 else setControlBits("noUseBasePdfFit");
00072 init();
00073 }
00074
00075 rarCompBase::~rarCompBase()
00076 {
00077 }
00078
00083 void rarCompBase::init()
00084 {
00085 cout<<"init of rarCompBase for "<<GetName()<<":"<<endl;
00086
00087 createPdfs("Comps", &_pdfList, &_subPdfs);
00088 _nComp=_pdfList.GetSize();
00089 if (_nComp<=0) {
00090 cout<<"no components defined in RooStringVar \"Comps\" in section \""
00091 <<_configSec<<"\""<<endl;
00092 exit(-1);
00093 }
00094
00095
00096 addProtVars();
00097
00098 }
00099
00106 void rarCompBase::setSimPdf(RooSimultaneous *simPdf)
00107 {
00108 rarBasePdf::setSimPdf(simPdf);
00109 for (Int_t i=0; i<_nComp; i++) {
00110 rarBasePdf *thePdf=(rarBasePdf*)_pdfList.At(i);
00111 thePdf->setSimPdf(simPdf);
00112 }
00113 }
00114
00119 RooArgSet rarCompBase::getParams()
00120 {
00121 RooArgSet paramSet(rarBasePdf::getParams());
00122
00123 for (Int_t i=0; i<_nComp; i++) {
00124 rarBasePdf *thePdf=(rarBasePdf*)_pdfList.At(i);
00125 paramSet.add(thePdf->getParams());
00126 }
00127 return paramSet;
00128 }
00129
00135 void rarCompBase::preAction()
00136 {
00137 cout<<" In rarCompBase preAction for "<<GetName()<<endl;
00138
00139 rarBasePdf::preAction();
00140
00141 for (Int_t i=0; i<_nComp; i++) {
00142 rarBasePdf *thePdf=(rarBasePdf*)_pdfList.At(i);
00143 thePdf->preAction();
00144 }
00145 }
00146
00157 RooArgSet rarCompBase::getArgSet(TString paramNames, Bool_t useRead,
00158 RooArgSet *fullSet)
00159 {
00160
00161 RooArgSet retVal(rarBasePdf::getArgSet(paramNames, useRead, fullSet));
00162
00163 if (useRead) {
00164 for (Int_t i=0; i<_nComp; i++) {
00165 rarBasePdf *thePdf=(rarBasePdf*)_pdfList.At(i);
00166 retVal.add(thePdf->getArgSet(paramNames, useRead, fullSet));
00167 }
00168 }
00169 return retVal;
00170 }
00171
00178 RooArgSet rarCompBase::getCorrCoeffs()
00179 {
00180 RooArgSet theSet(rarBasePdf::getCorrCoeffs());
00181
00182 for (Int_t i=0; i<_nComp; i++) {
00183 rarBasePdf *thePdf=(rarBasePdf*)_pdfList.At(i);
00184 theSet.add(thePdf->getCorrCoeffs());
00185 }
00186 return theSet;
00187 }
00188
00197 void rarCompBase::doPdfFit(TString pdfList)
00198 {
00199
00200 doXPdfFit(pdfList);
00201
00202 cout<<endl<<" In rarCompBase doPdfFit for "<<GetName()<<endl;
00203 if (!getControlBit("PdfFit")) return;
00204 if (getControlBit("UseBasePdfFit")) return rarBasePdf::doPdfFit(pdfList);
00205
00206 for (Int_t i=0; i<_nComp; i++) {
00207 rarBasePdf *thePdf=(rarBasePdf*)_pdfList.At(i);
00208 thePdf->doPdfFit(pdfList);
00209 }
00210 if (getControlBit("UseAlsoBasePdfFit")) return rarBasePdf::doPdfFit(pdfList);
00211 }
00212
00222 RooPlot *rarCompBase::doPdfPlot(TList &plotList, TString pdfList)
00223 {
00224 RooPlot *frame(0);
00225
00226 frame=doXPdfPlot(plotList, pdfList);
00227
00228 cout<<endl<<" In rarCompBase doPdfPlot for "<<GetName()<<endl;
00229
00230
00231 if (!getControlBit("PdfPlot")) return frame;
00232 if (getControlBit("PdfPlotDone")) return frame;
00233
00234
00235 string obsSaveStr, coeffParamSSaver;
00236 RooArgSet *theParams(0);
00237 if (getControlBit("UseBasePdfFit")) {
00238 writeToStr(_fObsSet, obsSaveStr);
00239
00240 theParams=_thePdf->getParameters(_theData);
00241 writeToStr(*theParams, coeffParamSSaver);
00242 readFromStr(*theParams, _afterFitSaverStr);
00243 }
00244
00245 for (Int_t i=0; i<_nComp; i++) {
00246 rarBasePdf *thePdf=(rarBasePdf*)_pdfList.At(i);
00247 frame=thePdf->doPdfPlot(plotList, pdfList);
00248 }
00249
00250
00251 if (getControlBit("UseBasePdfFit")) {
00252 readFromStr(*theParams, coeffParamSSaver);
00253 readFromStr(_fObsSet, obsSaveStr);
00254 }
00255 setControlBits("PdfPlotDone");
00256
00257 return frame;
00258 }
00259
00266 RooArgList rarCompBase::getPdfsWOvar(RooArgList ignoredObs)
00267 {
00268 RooArgList thePdfs;
00269 for (Int_t i=0; i<_nComp; i++) {
00270 rarBasePdf *thePdf=(rarBasePdf*)_pdfList.At(i);
00271 thePdfs.add(*thePdf->getPdfWOvar(ignoredObs));
00272 }
00273
00274
00275 return thePdfs;
00276 }
00277
00282 RooAbsPdf *rarCompBase::getProtGen()
00283 {
00284 if (_theProtGen) return _theProtGen;
00285 if (_subProtGenPdfs.getSize()<1) {
00286 for (Int_t i=0; i<_nComp; i++) {
00287 rarBasePdf *thePdf=(rarBasePdf*)_pdfList.At(i);
00288 _subProtGenPdfs.add(*thePdf->getProtGen());
00289 }
00290 }
00291 for (Int_t i=0; i<_nComp; i++)
00292 if (!((rarBasePdf*)_pdfList.At(i))->protGenIsDummy())return _theProtGen;
00293
00294 setControlBits("dummySubGenPdfs");
00295
00296 return _theProtGen;
00297 }
00298
00303 void rarCompBase::attachDataSet(const RooAbsData &data)
00304 {
00305
00306 rarBasePdf::attachDataSet(data);
00307
00308 for (Int_t i=0; i<_nComp; i++) {
00309 rarBasePdf *thePdf=(rarBasePdf*)_pdfList.At(i);
00310 thePdf->attachDataSet(data);
00311 }
00312 }
00313
00316 Bool_t rarCompBase::isNegativeValue()
00317 {
00318
00319 Bool_t isNegative(kFALSE);
00320
00321 isNegative=rarBasePdf::isNegativeValue();
00322 if (isNegative) return isNegative;
00323
00324 for (Int_t i=0; i<_nComp; i++) {
00325 rarBasePdf *thePdf=(rarBasePdf*)_pdfList.At(i);
00326 isNegative=thePdf->isNegativeValue();
00327 if (isNegative) return isNegative;
00328 }
00329 return isNegative;
00330 }