rarFit.cc File Reference

#include "RooRarFit/rarVersion.hh"
#include "Riostream.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "TROOT.h"
#include "TApplication.h"
#include "TStopwatch.h"
#include "RooFitCore/RooArgList.hh"
#include "RooFitCore/RooArgSet.hh"
#include "RooFitCore/RooRandom.hh"
#include "RooFitCore/RooRealVar.hh"
#include "RooFitCore/RooStringVar.hh"
#include "RooRarFit/rarDatasets.hh"
#include "RooRarFit/rarMLFitter.hh"

Go to the source code of this file.

Functions

Int_t doBanner ()
void rarFitUsage (TString myCommand)
 Usage page.
int main (int argc, char **argv)
 Main program of the mlFitter.


Function Documentation

Int_t doBanner (  ) 

Referenced by main().

int main ( int  argc,
char **  argv 
)

Main program of the mlFitter.

After it parses all the command line options, with normal operation, it first creates a rarDatasets object through which all the datasets are read in, then it instantiates mlFitter class, rarMLFitter, so that all the PDFs are created, and finally it sets toyID (random seed) and calls rarMLFitter::run() of the fitter to finish the job. If successfully compiled and linked, type rarFit in workdir to see short help page.

Definition at line 84 of file rarFit.cc.

References doBanner(), RARFIT_VERSION, rarFitUsage(), rarMLFitter::run(), rarConfig::setMasterSec(), rarMLFitter::setParamDir(), rarMLFitter::setResultDir(), rarConfig::setRunSec(), rarMLFitter::setToyDir(), rarMLFitter::setToyID(), and rarMLFitter::setToyNexp().

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   // always run with at least one argument, the config file
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   // started
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();  // force linker to leave it in; will print the RooFit banner
00150   }
00151   
00152   // due to inconsistency between RooRealVar::format() and parser,
00153   // use printScientific method
00154   RooRealVar::printScientific(kTRUE);
00155   
00156   // set random seed
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   // read in the datasets (for sig, bkg, MC, Onpeak data, etc.)
00165   rarDatasets theDatasets(ConfigFile, dataInputSec, fitterActionSec);
00166   // first set the mlFitter/action section name
00167   rarConfig::setMasterSec(fitterConfigSec);
00168   rarConfig::setRunSec(fitterActionSec);
00169   // instantiate the ML fitter
00170   rarMLFitter theFitter(ConfigFile, fitterConfigSec,
00171                         "mlFitter MLFitter \"ML Function\"",
00172                         &theDatasets, 0, "mlFitter", "ML Function");
00173   // set other initial values from user for the fitter
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   // then run it with configs
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   // isn't it simple?
00194 }

void rarFitUsage ( TString  myCommand  ) 

Usage page.

Print a short help page.

Definition at line 47 of file rarFit.cc.

References RARFIT_VERSION.

Referenced by main().

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 }


Generated on 30 Oct 2013 for RooRarFit by  doxygen 1.4.7