#include <rarDatasets.hh>
Inheritance diagram for rarDatasets:
Public Member Functions | |
rarDatasets () | |
Trivial ctor. | |
rarDatasets (const char *configFile, const char *configSec, const char *actionSec) | |
Default ctor. | |
virtual | ~rarDatasets () |
virtual RooArgSet * | getPrimaryObs () |
Return primary observables in dataset files. | |
virtual RooArgSet * | getAddOnCols () |
Return addon columns for datasets. | |
virtual RooArgSet * | getFullFObs () |
Return full observables. | |
virtual TString | getDSName (TString name) |
Create dataset name based on input string. | |
virtual RooDataSet * | getData (const char *name=0) |
Return the named dataset. | |
virtual TList * | getDatasetList () |
Get dataset list. | |
virtual TString | ubStr (TString dsName, const char *ubStrVal=0) |
Return/set the unblind string for the dataset. | |
virtual Bool_t | isBlind (TString dsName) |
Check if the named dataset is blind or not. | |
Protected Member Functions | |
void | init () |
Initial function called by ctor. | |
virtual void | tabulateDatasets (const char *dsName=0) |
Tabulate datasets wrt cats. | |
TString | getWeightVarName (TString datasetName) |
return the name of the weighted variable to be used in this dataset | |
Protected Attributes | |
TString | _actionSec |
Action config section name. | |
rarDatasetDef * | _dsd |
Dataset definition object. | |
TList | _dataSets |
Defined datasets. | |
RooArgSet * | _fullFObs |
Full set of fundamental observables. | |
RooArgSet | _UBs |
Unblind strings for datasets. | |
Private Member Functions | |
rarDatasets (const rarDatasets &) | |
ClassDef (rarDatasets, 0) |
This class instantiates a rarDatasetDef class for dataset definition, reads in and holds all the datasets from ascii/root files. It also holds datasets derived from those primary datasets.
Definition at line 27 of file rarDatasets.hh.
rarDatasets::rarDatasets | ( | ) |
rarDatasets::rarDatasets | ( | const char * | configFile, | |
const char * | configSec, | |||
const char * | actionSec | |||
) |
Default ctor.
configFile | The config file | |
configSec | The config section | |
actionSec | The action section |
Definition at line 61 of file rarDatasets.cc.
References init().
00063 : rarConfig(configFile, configSec, "null", "Datasets", "Datasets"), 00064 _actionSec(actionSec), _dsd(0), _fullFObs(0) 00065 { 00066 init(); 00067 }
rarDatasets::~rarDatasets | ( | ) | [virtual] |
rarDatasets::rarDatasets | ( | const rarDatasets & | ) | [private] |
rarDatasets::ClassDef | ( | rarDatasets | , | |
0 | ||||
) | [private] |
virtual RooArgSet* rarDatasets::getAddOnCols | ( | ) | [inline, virtual] |
Return addon columns for datasets.
Reimplemented from rarConfig.
Definition at line 40 of file rarDatasets.hh.
References _dsd, and rarDatasetDef::getAddOnCols().
Referenced by rarBasePdf::getAddOnCols().
00040 {return _dsd->getAddOnCols();}
RooDataSet * rarDatasets::getData | ( | const char * | name = 0 |
) | [virtual] |
Return the named dataset.
name | The name of the dataset to return |
name
exsits in _dataSets, if yes, it returns the dataset, if no, it parses name
and if the number of tokens is greater than 0, it will check if there is dataset named as the first token, if yes, it will reduce that dataset according to the second token and return the reduced dataset. Otherwise, it returns null.
Reimplemented from rarConfig.
Definition at line 241 of file rarDatasets.cc.
References _dataSets, getDSName(), isBlind(), rarStrParser::nArgs(), tabulateDatasets(), and ubStr().
Referenced by rarMLFitter::doContourPlot(), rarBasePdf::doPdfPlot(), rarMLFitter::doProjPlot(), rarMLFitter::doScanPlot(), rarMLFitter::doSPlot(), rarMLFitter::doToyStudy(), rarMLFitter::generate(), rarMLPdf::init(), rarMLFitter::run(), rarBasePdf::setFitData(), and ubStr().
00242 { 00243 RooDataSet *theData=(RooDataSet*)_dataSets.FindObject(getDSName(name)); 00244 if (theData) return theData; 00245 // can not find the data set parser the name 00246 rarStrParser nameParser=name; 00247 if (nameParser.nArgs()<=0) return theData; 00248 theData=(RooDataSet*)_dataSets.FindObject(getDSName(nameParser[0])); 00249 if (!theData) return theData; //can not find any 00250 // reduce the dataset 00251 theData=(RooDataSet*)theData->reduce(nameParser[1]); 00252 theData->SetName(getDSName(name)); 00253 _dataSets.Add(theData); 00254 // check if need to set ub bit 00255 if (!isBlind(getDSName(nameParser[0]))) { 00256 ubStr(getDSName(name), "Unblinded"); 00257 } 00258 cout<<" New dataset created"<<endl; 00259 if (theData) { 00260 //theData->Print("v"); 00261 theData->Print(); 00262 tabulateDatasets(theData->GetName()); 00263 } 00264 return theData; 00265 }
virtual TList* rarDatasets::getDatasetList | ( | ) | [inline, virtual] |
Get dataset list.
Definition at line 51 of file rarDatasets.hh.
References _dataSets.
Referenced by rarMLFitter::doToyStudy(), and rarMLFitter::run().
00051 {return &_dataSets;}
TString rarDatasets::getDSName | ( | TString | name | ) | [virtual] |
Create dataset name based on input string.
name | The input name string |
Definition at line 210 of file rarDatasets.cc.
Referenced by rarMLFitter::doToyStudy(), getData(), and init().
00211 { 00212 // first remove " 00213 name.ReplaceAll("\"", ""); 00214 name.ReplaceAll(" ", " "); 00215 name.ReplaceAll(">=", ".GE."); 00216 name.ReplaceAll(">", ".GT."); 00217 name.ReplaceAll("<=", ".LE."); 00218 name.ReplaceAll("<", ".LT."); 00219 name.ReplaceAll("==", ".EQ."); 00220 name.ReplaceAll("!=", ".NEQ."); 00221 name.ReplaceAll("=", ".EQ."); 00222 name.ReplaceAll("&&", ".AND."); 00223 name.ReplaceAll("||", ".OR."); 00224 for (Int_t i=0; i<name.Length(); i++) 00225 if (!isalnum(name[i])) name[i]='_'; 00226 00227 return name; 00228 }
virtual RooArgSet* rarDatasets::getFullFObs | ( | ) | [inline, virtual] |
Return full observables.
Definition at line 44 of file rarDatasets.hh.
References _fullFObs.
Referenced by rarBasePdf::init().
00044 {return _fullFObs;}
virtual RooArgSet* rarDatasets::getPrimaryObs | ( | ) | [inline, virtual] |
Return primary observables in dataset files.
Reimplemented from rarConfig.
Definition at line 36 of file rarDatasets.hh.
References _dsd, and rarDatasetDef::getPrimaryObs().
Referenced by rarBasePdf::getPrimaryObs().
00036 {return _dsd->getPrimaryObs();}
TString rarDatasets::getWeightVarName | ( | TString | datasetName | ) | [protected] |
return the name of the weighted variable to be used in this dataset
It sets weight var according to configs
Definition at line 156 of file rarDatasets.cc.
References _fullFObs, and rarConfig::readConfStr().
Referenced by init().
00157 { 00158 TString swvStr = readConfStr("setWeightVar", "no"); 00159 if (swvStr.BeginsWith("no")) return(""); // no weight variable 00160 00161 // do we have a default weight variable for all datasets? 00162 rarStrParser swvStrParser = swvStr; 00163 TString swvName = swvStrParser[0]; // either dataset name or default weight variable 00164 // check variable exists 00165 if (_fullFObs->find(swvName)) { 00166 cout << "Will use " << swvName << " as weight for dataset " << datasetName << endl; 00167 } else { 00168 cout << "Can not find " << swvName << " as a variable to use as a weight." << endl; 00169 swvName=""; 00170 } 00171 return(swvName); 00172 }
void rarDatasets::init | ( | ) | [protected, virtual] |
Initial function called by ctor.
init
is called by the ctor. It first instantiates a rarDatasetDef class for dataset definition. It then reads in the info of datasets, and prints out the datasets configured int the config section. It creates those datasets by calling createDataSet and adds them to the dataset list, _dataSets. It also checks if the datasets need to be tabulated for output.
Reimplemented from rarConfig.
Definition at line 83 of file rarDatasets.cc.
References _actionSec, rarConfig::_configFile, rarConfig::_configSec, rarConfig::_createFundamental, _dataSets, _dsd, _fullFObs, rarConfig::_fullNameSchema, rarConfig::_fullObs, rarConfig::_rarVars, rarConfig::createDataSet(), getDSName(), rarConfig::getFullObs(), getWeightVarName(), rarStrParser::nArgs(), rarConfig::readConfStr(), tabulateDatasets(), and ubStr().
Referenced by rarDatasets().
00084 { 00085 cout<<"init of rarDatasets:"<<endl; 00086 // first set #_createFundamental and #_fullNameSchema 00087 _createFundamental=kTRUE; 00088 _fullNameSchema="self"; 00089 00090 // first create dsd object 00091 TString dataDefSec=readConfStr("dsdSec", "Dataset Definition"); 00092 _dsd=new rarDatasetDef(_configFile, dataDefSec); 00093 _fullObs=_dsd->getFullObs(); 00094 // create full fundamental obs 00095 _fullFObs=new RooArgSet("theFullFObs"); 00096 RooArgList fullObs(*_fullObs); 00097 for (Int_t i=0; i<fullObs.getSize(); i++) { 00098 RooAbsArg *theVar=fullObs.at(i); 00099 _fullFObs->add(*((RooAbsArg*)_rarVars.FindObject(theVar->GetName()))); 00100 } 00101 00102 // get number of datasets, first check action section 00103 TString datasetsStr=readConfStr("Datasets", "notSet", _actionSec); 00104 // if not found, go to dsi section 00105 if ("notSet"==datasetsStr) datasetsStr=readConfStr("Datasets", ""); 00106 rarStrParser datasetsStrParser=datasetsStr; 00107 Int_t nDataset=datasetsStrParser.nArgs(); 00108 if (nDataset<=0) { 00109 cout<<"no datasets defined in RooStringVar \"Datasets\" in section \"" 00110 <<_configSec<<"\""<<endl; 00111 exit(-1); 00112 } 00113 // read in datasets info 00114 RooArgSet datasetList("Dataset List"); 00115 for (Int_t i=0; i<nDataset; i++) { 00116 RooStringVar *dataset=new RooStringVar 00117 (datasetsStrParser[i], datasetsStrParser[i], "notSet", 8192); 00118 datasetList.addOwned(*dataset); 00119 } 00120 datasetList.readFromFile(_configFile, 0, _configSec); 00121 //datasetList.Print("v"); 00122 // list configed datasets 00123 cout<<endl 00124 <<"The datasets defined in config file:"<<endl; 00125 for (Int_t i=0; i<nDataset; i++) { 00126 TString datasetStr=(RooStringVar&)datasetList[datasetsStrParser[i]]; 00127 cout<<Form(" dataset%02d ",i)<<datasetsStrParser[i]<<" "<<datasetStr<<endl; 00128 } 00129 cout<<endl; 00130 // now read in the datasets 00131 for (Int_t i=0; i<nDataset; i++) { 00132 Bool_t isUB=kFALSE; 00133 TString datasetStr=(RooStringVar&)datasetList[datasetsStrParser[i]]; 00134 // get name of weight variable 00135 TString wgtVarName = getWeightVarName(getDSName(datasetsStrParser[i])); 00136 00137 RooDataSet *data=createDataSet(datasetsStrParser[i]+" "+datasetStr, isUB, wgtVarName); 00138 data->SetName(getDSName(datasetsStrParser[i])); 00139 _dataSets.Add(data); 00140 if (isUB) ubStr(getDSName(datasetsStrParser[i]), "Unblinded"); 00141 //data->Print("v"); 00142 //data->get()->Print("v"); 00143 } 00144 00145 cout<<endl<<"Datasets read in:"<<endl; 00146 _dataSets.Print(); 00147 cout<<endl; 00148 00149 // do we need to tabulate it? 00150 tabulateDatasets(); 00151 }
Bool_t rarDatasets::isBlind | ( | TString | dsName | ) | [virtual] |
Check if the named dataset is blind or not.
dsName | The name of the dataset |
Definition at line 318 of file rarDatasets.cc.
References rarStrParser::Have(), rarStrParser::nArgs(), rarConfig::readConfStr(), rarStrParser::Remove(), and ubStr().
Referenced by rarMLFitter::chkBlind(), and getData().
00319 { 00320 // magic override 00321 if (getenv("RARFITUNBLIND")) return kFALSE; 00322 00323 // rest of the routine 00324 Bool_t retVal(kTRUE); 00325 TString ubStrVal=ubStr(dsName); 00326 if ("notSet"==ubStrVal) { 00327 cout<<" W A R N I N G !"<<endl 00328 <<" Somehow the ub status for "<<dsName<<" is "<<ubStrVal<<endl 00329 <<" So "<<dsName<<" remains blind. Please double check"<<endl; 00330 return retVal; 00331 } 00332 if ("Unblinded"==ubStrVal) return kFALSE; 00333 rarStrParser ubIDParser=ubStrVal; 00334 rarStrParser dsiUBStrParser=readConfStr("ub_"+dsName, ""); 00335 while(dsiUBStrParser.nArgs()>0) { 00336 TString dsiUBStr=dsiUBStrParser[0]; 00337 dsiUBStrParser.Remove(); 00338 if (ubIDParser.Have(dsiUBStr)) return kFALSE; 00339 } 00340 00341 return retVal; 00342 }
void rarDatasets::tabulateDatasets | ( | const char * | dsName = 0 |
) | [protected, virtual] |
Tabulate datasets wrt cats.
dsName | The dataset name if provided |
Definition at line 178 of file rarDatasets.cc.
References _dataSets, rarConfig::getCats(), and rarConfig::readConfStr().
Referenced by getData(), and init().
00179 { 00180 TString tdsStr=readConfStr("tabulateDatasets", "no"); 00181 if (tdsStr.BeginsWith("no")) return; 00182 00183 cout << "Tabulate Datsets by Category\n" << endl; 00184 RooArgList catList(*getCats()); 00185 for (Int_t dIdx=0; dIdx<_dataSets.GetSize(); dIdx++) { 00186 RooDataSet *data=(RooDataSet*) _dataSets.At(dIdx); 00187 if (dsName&&TString(dsName)!=data->GetName()) continue; 00188 for (Int_t i=0; i<catList.getSize(); i++) { 00189 RooAbsCategory *theCat=(RooAbsCategory *)&(catList[i]); 00190 Roo1DTable *theTable(0); 00191 if (theCat&&(theTable=data->table(*theCat))) { 00192 theTable->Print("v"); 00193 // get frac table 00194 TIterator* catTypeIter = theCat->typeIterator(); 00195 RooCatType *theType(0); 00196 while(theType=(RooCatType*)catTypeIter->Next()) { 00197 TString typeName=theType->GetName(); 00198 cout<<" "<<typeName<<"\t"<<theTable->getFrac(typeName)<<endl; 00199 } 00200 cout<<endl; 00201 delete catTypeIter; 00202 } 00203 } 00204 } 00205 }
TString rarDatasets::ubStr | ( | TString | dsName, | |
const char * | ubStrVal = 0 | |||
) | [virtual] |
Return/set the unblind string for the dataset.
dsName | The name of the dataset | |
ubStrVal | The ubStr value (to set) |
Definition at line 271 of file rarDatasets.cc.
References _UBs, and getData().
Referenced by rarMLFitter::chkBlind(), rarMLFitter::doToyStudy(), getData(), init(), and isBlind().
00272 { 00273 TString ubStrName="ub_"+dsName; 00274 // have we calculated it? 00275 RooStringVar *theStr=(RooStringVar*)_UBs.find(ubStrName); 00276 if (theStr&&("notSet"!=TString(theStr->getVal()))) { 00277 if (ubStrVal) theStr->setVal(ubStrVal); 00278 return theStr->getVal(); 00279 } 00280 if (!theStr) { 00281 theStr=new RooStringVar(ubStrName, ubStrName, "notSet", 8192); 00282 _UBs.add(*theStr); 00283 } 00284 if (ubStrVal) { 00285 theStr->setVal(ubStrVal); 00286 return theStr->getVal(); 00287 } 00288 // compute chksum 00289 TMD5 chksum; 00290 stringstream o; 00291 // read in all the data entries 00292 RooDataSet *theData=getData(dsName); 00293 if (!theData) { 00294 cout<<" W A R N I N G !"<<endl 00295 <<" Can not find dataset named "<<dsName<<" for ub calculation!"<<endl; 00296 return theStr->getVal(); 00297 } 00298 Int_t nEvt=theData->numEntries(); 00299 Int_t nStep=nEvt/10000; 00300 nStep++; 00301 Int_t i=0; 00302 while (i<nEvt) { 00303 RooArgList evt(*theData->get(i)); 00304 evt.writeToStream((ostream&)o, kTRUE); 00305 i+=nStep; 00306 } 00307 string chkStr=o.str(); 00308 chksum.Update((UChar_t*)chkStr.c_str(), chkStr.length()); 00309 chksum.Final(); 00310 theStr->setVal(chksum.AsString()); 00311 00312 return theStr->getVal(); 00313 }
TString rarDatasets::_actionSec [protected] |
TList rarDatasets::_dataSets [protected] |
Defined datasets.
Definition at line 65 of file rarDatasets.hh.
Referenced by getData(), getDatasetList(), init(), and tabulateDatasets().
rarDatasetDef* rarDatasets::_dsd [protected] |
Dataset definition object.
Definition at line 64 of file rarDatasets.hh.
Referenced by getAddOnCols(), getPrimaryObs(), and init().
RooArgSet* rarDatasets::_fullFObs [protected] |
Full set of fundamental observables.
Definition at line 66 of file rarDatasets.hh.
Referenced by getFullFObs(), getWeightVarName(), and init().
RooArgSet rarDatasets::_UBs [protected] |