00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00015
00016
00017
00018
00019
00020
00021 #include "RooRarFit/rarVersion.hh"
00022
00023 #include "Riostream.h"
00024
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <unistd.h>
00028
00029 #include "TROOT.h"
00030 #include "TApplication.h"
00031 #include "TStopwatch.h"
00032
00033 #include "RooFitCore/RooArgList.hh"
00034 #include "RooFitCore/RooArgSet.hh"
00035 #include "RooFitCore/RooRandom.hh"
00036 #include "RooFitCore/RooRealVar.hh"
00037 #include "RooFitCore/RooStringVar.hh"
00038
00039 #include "RooRarFit/rarDatasets.hh"
00040 #include "RooRarFit/rarMLFitter.hh"
00041
00042 extern Int_t doBanner();
00043
00047 void rarFitUsage(TString myCommand)
00048 {
00049 cout <<"Usage for RooRarFit ("<< RARFIT_VERSION <<") :" << endl << endl
00050 <<myCommand<<" [-options] <RooRarFit_Config_file>"<<endl
00051 <<"\t-h this help page"<<endl
00052 <<"\t-D <data input section>"
00053 <<" (default \"Dataset Input\")"<<endl
00054 <<"\t-C <mlFitter config section>"
00055 <<" (default \"mlFitter Config\")"<<endl
00056 <<"\t-A <fitter action section>"
00057 <<" (default \"Fitter Action\")"<<endl
00058 <<"\t-t <toy job id> (default 0)"<<endl
00059 <<"\t-n <toyNexp> (default 0, use config)"<<endl
00060 <<"\t-d <toy dir> (default .toyData)"<<endl
00061 <<"e.g."<<endl
00062 <<"\tTo run "<<myCommand<<" from config file demo.config"<<endl
00063 <<myCommand<<" demo.config"<<endl
00064 <<"\tand with mlfitter config from section [myMLFitter]"<<endl
00065 <<myCommand<<" -C myMLFitter demo.config"<<endl
00066 <<"\tand with mlfitter action from section"
00067 <<" [my Fit Action]"<<endl
00068 <<myCommand<<" -C myMLFitter"
00069 <<" -A \"my Fit Action\" demo.config"<<endl
00070 <<endl;
00071 }
00072
00084 int main(int argc, char **argv)
00085 {
00086 Int_t optFlag;
00087 TString dataInputSec="Dataset Input";
00088 TString fitterConfigSec="mlFitter Config";
00089 TString fitterActionSec="Fitter Action";
00090 Int_t randomBase(0);
00091 Int_t toyID(0);
00092 Int_t toyNexp(0);
00093 TString toyDir(".toyData");
00094 while (EOF!=(optFlag=getopt(argc, argv, "hD:C:A:t:n:d:"))) {
00095 switch (optFlag) {
00096 case 'h' :
00097 rarFitUsage(argv[0]);
00098 return 0;
00099 break;
00100 case 'D' :
00101 dataInputSec=optarg;
00102 break;
00103 case 'C' :
00104 fitterConfigSec=optarg;
00105 break;
00106 case 'A' :
00107 fitterActionSec=optarg;
00108 break;
00109 case 't' :
00110 toyID=atoi(optarg);
00111 break;
00112 case 'n' :
00113 toyNexp=atoi(optarg);
00114 break;
00115 case 'd' :
00116 toyDir=optarg;
00117 break;
00118 }
00119 }
00120
00121 if (optind >= argc) {
00122 rarFitUsage(argv[0]);
00123 return 0;
00124 }
00125
00126
00127 TString ConfigFile=argv[optind];
00128 ifstream ifs(ConfigFile);
00129 if(ifs.fail()) {
00130 cout<<argv[0]<<": can not open config file "<<ConfigFile<<endl;
00131 exit(-1);
00132 }
00133 ifs.close();
00134
00135
00136 TStopwatch timer;
00137 timer.Start();
00138
00139 cout<<endl<<" "<<argv[0]<<" S T A R T E D ("<<RARFIT_VERSION<<")"
00140 <<endl<<endl
00141 <<"Config File: "<<ConfigFile<<endl
00142 <<"Dataset Input Section: \""<<dataInputSec<<"\""<<endl
00143 <<"mlFitter Config Section: \""<<fitterConfigSec<<"\""<<endl
00144 <<"mlFitter Action Section: \""<<fitterActionSec<<"\""<<endl
00145 <<endl<<endl;
00146
00147 static bool dummy = false;
00148 if ( dummy ) {
00149 doBanner();
00150 }
00151
00152
00153
00154 RooRealVar::printScientific(kTRUE);
00155
00156
00157 if (getenv("RANDOMSEEDBASE")) randomBase=atoi(getenv("RANDOMSEEDBASE"));
00158 Int_t randomSeed=randomBase+toyID;
00159 if (randomSeed) {
00160 cout<<" Set random seed to "<<randomSeed<<endl;
00161 RooRandom::randomGenerator()->SetSeed(randomSeed);
00162 }
00163
00164
00165 rarDatasets theDatasets(ConfigFile, dataInputSec, fitterActionSec);
00166
00167 rarConfig::setMasterSec(fitterConfigSec);
00168 rarConfig::setRunSec(fitterActionSec);
00169
00170 rarMLFitter theFitter(ConfigFile, fitterConfigSec,
00171 "mlFitter MLFitter \"ML Function\"",
00172 &theDatasets, 0, "mlFitter", "ML Function");
00173
00174 TString paramDir=".params";
00175 if (getenv("PARAMDIR")) paramDir=getenv("PARAMDIR");
00176 theFitter.setParamDir(paramDir);
00177 TString resultDir="results";
00178 if (getenv("RESULTDIR")) resultDir=getenv("RESULTDIR");
00179 theFitter.setResultDir(resultDir);
00180 theFitter.setToyID(toyID);
00181 theFitter.setToyNexp(toyNexp);
00182 theFitter.setToyDir(toyDir);
00183
00184 theFitter.run();
00185
00186 timer.Stop();
00187 cout<<endl<<endl
00188 <<" "<<argv[0]<<" F I N I S H E D"
00189 << " RealTime = " << timer.RealTime()
00190 << " secs. CpuTime = " << timer.CpuTime() << " secs." << endl;
00191
00192 return 0;
00193
00194 }