NuFCRunner Class Reference

#include <NuFCRunner.h>

List of all members.

Public Member Functions

 NuFCRunner (void)
 ~NuFCRunner ()
void push_back (NuFCRunInfo *runInfo)
void SetTrueParameters (const NuMMParameters &truth)
 Set the true set of parameters.
NuMMParameters GetTrueParameters (void) const
 Retrieves the true parameter set object.
void SetDelegate (NuFCDelegate *delegate)
 Set the delegate object.
void RunExperiments (const Int_t num)
 Run a fixed number of experiments.
void SetFitter (NuFCFittingInterface *fitter)
 Set the fitter to use for experiments.

Static Public Member Functions

static NuFCRunnerBuildFromConfig (const TString filename)
static NuFCRunnerBuildFromConfig (ConfigFile &config)

Private Member Functions

void GenerateExperiment (NuFCRunInfo &run, const NuSystematicShifts &shifts)
 Does the generation for a single experiment.
void PrepareRunInfos (void)
 Makes sure all run information objects are ready.
NuMMParameters RunFitter (void)
 Manage the running of the fitting routine.
std::auto_ptr< NuSystFitterGetSystFitter (void) const
 Returns a NuSystFitter build with the current runs.
void ProcessPredictions (const NuMMParameters &pars)
 Processes the predictions at the best fit.

Private Attributes

std::vector< NuFCRunInfo * > fRuns
NuMMParameters fTrueParams
NuFCDelegate fInternalDelegate
NuFCDelegatefDelegate
NuFCFittingInterfacefFitter
std::vector< NuFCRunInfo * > fOwnedRunsSubset
 Which of the owned runs can be safely deleted?

Detailed Description

Class to choreograph the running of a FC procedure

Definition at line 18 of file NuFCRunner.h.


Constructor & Destructor Documentation

NuFCRunner::NuFCRunner ( void   ) 

Definition at line 22 of file NuFCRunner.cxx.

Referenced by BuildFromConfig().

00023   : fInternalDelegate(*this),
00024     fDelegate(&fInternalDelegate),
00025     fFitter(0)
00026 {
00027   
00028 }

NuFCRunner::~NuFCRunner (  ) 

Definition at line 32 of file NuFCRunner.cxx.

References fDelegate.

00033 {
00034   // Never delete the fDelegate pointer - either it was passed in or
00035   // was a pointer to one of our internal objects
00036   fDelegate = 0;
00037 }


Member Function Documentation

NuFCRunner * NuFCRunner::BuildFromConfig ( ConfigFile config  )  [static]

Definition at line 234 of file NuFCRunner.cxx.

References BuildFromConfig(), Plot::Format(), fOwnedRunsSubset, ConfigFile::GetBool(), ConfigFile::GetInt(), ConfigFile::Has_Section(), Msg::kError, MSG, NuFCRunner(), and push_back().

00235 {
00236   Int_t runcount = cfg.GetInt("Runs", "General", 0);
00237   Bool_t systematics = cfg.GetBool("Systematics", "General", false);
00238   
00239   // Check we haven't enabled systematics; this isn't working yet
00240   if (systematics) {
00241     MSG("NuFCRunner",Msg::kError) << "Error Reading Configuration File; Systematics not yet implemented" << endl;
00242     throw runtime_error("Error reading configuration file: Systematics not yet implemented!");
00243   }
00244   
00245   // Create the base NuRunner object
00246   NuFCRunner *runner = new NuFCRunner();
00247   
00248   // Loop over each of the runs
00249   for (Int_t i = 0; i < runcount; ++i) {
00250     // Validate the section for this run exists
00251     TString section = TString::Format("Run_%d", i);
00252     cout << "Processing " << section << endl;
00253     assert(cfg.Has_Section(section.Data()));
00254     
00255     // Build a run information object from this section
00256     NuFCRunInfo *runinfo = NuFCRunInfo::BuildFromConfig(cfg, section);
00257     // Add this to our run list, and our "can delete" list
00258     runner->fOwnedRunsSubset.push_back(runinfo);
00259     runner->push_back(runinfo);
00260   }
00261   
00262   return runner;
00263 }

NuFCRunner * NuFCRunner::BuildFromConfig ( const TString  filename  )  [static]

Build a runner object from a configuration file.

Definition at line 224 of file NuFCRunner.cxx.

Referenced by BuildFromConfig().

00225 {
00226   // Load the configuration file
00227   ConfigFile cfg(filename.Data());
00228   
00229   return BuildFromConfig(cfg);
00230 }

void NuFCRunner::GenerateExperiment ( NuFCRunInfo run,
const NuSystematicShifts shifts 
) [private]

Does the generation for a single experiment.

Definition at line 116 of file NuFCRunner.cxx.

References fDelegate, fTrueParams, NuFCExperimentGenerator::GenerateFD(), NuFCExperimentGenerator::GenerateND(), NuFCRunInfo::GetRun(), NuFCDelegate::GotFDSpectrum(), NuFCDelegate::GotNDSpectrum(), NuMMRun::ResetFDData(), NuMMRun::ResetNDData(), and NuFCExperimentGenerator::SetDelegate().

Referenced by RunExperiments().

00117 {
00118   // Create a generator for this experiment
00119   NuFCExperimentGenerator gen(run, fTrueParams);
00120   // Use the delegate for intermediate output
00121   gen.SetDelegate(fDelegate);
00122   
00123   // Build the near detector spectrum
00124   auto_ptr<NuMatrix> ndData = gen.GenerateND(shifts);
00125   fDelegate->GotNDSpectrum(run, shifts, ndData.get());
00126   // Update the run objects ND data
00127   run.GetRun().ResetNDData(*ndData);
00128   
00129   // Now, do the Far detector
00130   auto_ptr<NuMatrix> fdData = gen.GenerateFD(shifts);
00131   fDelegate->GotFDSpectrum(run, shifts, fdData.get());
00132   // Update the run objects FD data
00133   run.GetRun().ResetFDData(*fdData);
00134     
00135 }

auto_ptr< NuSystFitter > NuFCRunner::GetSystFitter ( void   )  const [private]

Returns a NuSystFitter build with the current runs.

Definition at line 172 of file NuFCRunner.cxx.

References fRuns, and it.

Referenced by ProcessPredictions(), RunExperiments(), and RunFitter().

00173 {
00174   // Build a NuSystFitter object
00175   auto_ptr<NuSystFitter> fitter(new NuSystFitter);
00176   // fitter->QuietModeOn();
00177   fitter->BatchModeOn();
00178   // Add every run to the fitter
00179   std::vector<NuFCRunInfo*>::const_iterator it;
00180   for (it = fRuns.begin(); it != fRuns.end(); ++it)
00181   {
00182     fitter->push_back(&(*it)->GetRun());
00183   }
00184   // We should set quiet mode here
00185   
00186   return fitter;
00187 }

NuMMParameters NuFCRunner::GetTrueParameters ( void   )  const [inline]

Retrieves the true parameter set object.

Definition at line 53 of file NuFCRunner.h.

References fTrueParams.

Referenced by NuFCDelegateArchiver::UseFitter().

00053 { return fTrueParams; }

void NuFCRunner::PrepareRunInfos ( void   )  [private]

Makes sure all run information objects are ready.

Definition at line 139 of file NuFCRunner.cxx.

References fRuns, fTrueParams, and it.

Referenced by RunExperiments().

00140 {
00141   // Build Summaries for every run
00142   std::vector<NuFCRunInfo*>::iterator it;
00143   for (it = fRuns.begin(); it != fRuns.end(); ++it)
00144   {
00145     (*it)->BuildSummaries();
00146     (*it)->BuildSampleWeights(fTrueParams);
00147   }
00148 }

void NuFCRunner::ProcessPredictions ( const NuMMParameters pars  )  [private]

Processes the predictions at the best fit.

Definition at line 191 of file NuFCRunner.cxx.

References fDelegate, fRuns, fTrueParams, GetSystFitter(), NuFCDelegate::GotHistogram(), it, NuMMRun::MakeFDPrediction(), and run().

Referenced by RunExperiments().

00192 {
00193   auto_ptr<NuSystFitter> fitter = GetSystFitter();
00194   
00195   // Do for every run
00196   std::vector<NuFCRunInfo*>::const_iterator it;
00197   for (it = fRuns.begin(); it != fRuns.end(); ++it)
00198   {
00199     // Keep a handy reference to the run around
00200     NuMMRun &run = (*it)->GetRun();
00201 
00202     // Get the oscillated prediction
00203     auto_ptr<NuMatrix> oscMatrix = run.MakeFDPrediction(pars);
00204     TString name = "FD_" + (*it)->GetName() + "_bestfit";
00205     fDelegate->GotHistogram(name, oscMatrix.get());
00206     
00207     // Get the unoscillated prediction
00208     NuMMParameters unosc;
00209     auto_ptr<NuMatrix> unoscMatrix = run.MakeFDPrediction(unosc);
00210     name = "FD_" + (*it)->GetName() + "_unosc";
00211     fDelegate->GotHistogram(name, unoscMatrix.get());
00212     
00213     // Get the Truth prediction
00214     auto_ptr<NuMatrix> trueMatrix = run.MakeFDPrediction(fTrueParams);
00215     name = "FD_" + (*it)->GetName() + "_truth";
00216     fDelegate->GotHistogram(name, trueMatrix.get());
00217   }
00218   
00219   
00220 }

void NuFCRunner::push_back ( NuFCRunInfo runInfo  ) 

Definition at line 41 of file NuFCRunner.cxx.

References fRuns, Msg::kWarning, MSG, and NuFCRunInfo::Validate().

Referenced by BuildFromConfig().

00042 {
00043   if (!runInfo->Validate()) {
00044     MSG("NuFCRunner",Msg::kWarning) << "Run being added is not valid" << endl;
00045   }
00046   fRuns.push_back(runInfo);
00047 }

void NuFCRunner::RunExperiments ( const Int_t  num  ) 

Run a fixed number of experiments.

Definition at line 51 of file NuFCRunner.cxx.

References NuFCDelegate::EndExperiment(), NuFCDelegate::EndRunning(), fDelegate, fFitter, fRuns, fTrueParams, GenerateExperiment(), GetSystFitter(), NuFCDelegate::GotBestFit(), NuFCDelegate::GotDeltaChi2(), it, Msg::kWarning, MAXMSG, PrepareRunInfos(), ProcessPredictions(), run(), RunFitter(), NuFCDelegate::StartExperiment(), NuFCDelegate::StartFitting(), NuFCDelegate::StartRunning(), and NuFCDelegate::UseFitter().

00052 {
00053   // Make sure all run info objects are prepared for running
00054   PrepareRunInfos();
00055   
00056   // Let our delegate know what we are doing
00057   fDelegate->StartRunning(num);
00058   
00059   // Start the main loop over all experiments
00060   for (Int_t exp = 0; exp < num; ++exp)
00061   {
00062     fDelegate->StartExperiment(exp);
00063     
00064     // Roll the systematics for a single experiment
00065     // this gets us a description object
00066     NuSystematicShifts shifts;
00067     
00068     // Loop over runs
00069     std::vector<NuFCRunInfo*>::iterator it;
00070     for (it = fRuns.begin(); it != fRuns.end(); ++it)
00071     {
00072       // Convert the iterator into a reference to the run
00073       NuFCRunInfo &run = **it;
00074       
00075       GenerateExperiment(run, shifts);
00076     }
00077     
00078     // Do the Fitting
00079     NuMMParameters BestFit;
00080     if (fFitter) {
00081       fDelegate->StartFitting();
00082       BestFit = RunFitter();
00083     } else {
00084       MAXMSG("NuFCRunner",Msg::kWarning,5)
00085         << "Not fitting: Have not been given a fitter to use" << endl;
00086       BestFit = fTrueParams;
00087     }
00088     
00089     // We now have a best fit. Work out the Chi2 and DeltaChi2 for this
00090     auto_ptr<NuSystFitter> fitter = GetSystFitter();
00091     Double_t chi2Fit  = fitter->Likelihood(BestFit);
00092     Double_t chi2True = fitter->Likelihood(fTrueParams);
00093     Double_t deltaChi2 = chi2True - chi2Fit;
00094     // It is unacceptable for the fitter to pass and be worse than the truth
00095     // assert(deltaChi2 >= 0);
00096     // Give the delegate the information
00097     fDelegate->GotBestFit(BestFit, chi2Fit);
00098     fDelegate->GotDeltaChi2(BestFit, deltaChi2);
00099     
00100     // Pass the delegate a NuSystFitter so it can do anything it wants with the result
00101     fDelegate->UseFitter(*fitter.get());
00102     
00103     // Pass the delegate all the prediction histograms
00104     ProcessPredictions(BestFit);
00105     
00106     fDelegate->EndExperiment();
00107   }
00108   
00109   fDelegate->EndRunning();
00110  
00111 }

NuMMParameters NuFCRunner::RunFitter ( void   )  [private]

Manage the running of the fitting routine.

Definition at line 151 of file NuFCRunner.cxx.

References fFitter, NuFCFittingInterface::Fit(), NuFCFittingInterface::GetFit(), GetSystFitter(), Msg::kError, MSG, and NuFCFittingInterface::SetSystFitter().

Referenced by RunExperiments().

00152 {
00153   // Make sure we have a fitter at this stage
00154   assert(fFitter);
00155   
00156   // Pass a NuSystFitter to our fitting object
00157   fFitter->SetSystFitter(GetSystFitter());
00158   
00159   // Do the fitting. For now, halt on a failed fit
00160   Bool_t fitsuccess = fFitter->Fit();
00161   if (!fitsuccess) {
00162     MSG("NuFCRunner",Msg::kError) << "Failed to Fit Experiment!" << endl;
00163     assert(fitsuccess);
00164   }
00165   
00166   // Return the successful fit
00167   return fFitter->GetFit();
00168 }

void NuFCRunner::SetDelegate ( NuFCDelegate delegate  )  [inline]

Set the delegate object.

Definition at line 56 of file NuFCRunner.h.

References fDelegate.

00056 { fDelegate = delegate; }

void NuFCRunner::SetFitter ( NuFCFittingInterface fitter  )  [inline]

Set the fitter to use for experiments.

Definition at line 62 of file NuFCRunner.h.

References fFitter.

00062 { fFitter = fitter; }

void NuFCRunner::SetTrueParameters ( const NuMMParameters truth  )  [inline]

Set the true set of parameters.

Definition at line 51 of file NuFCRunner.h.

References fTrueParams.

00051 { fTrueParams = truth; }


Member Data Documentation

Definition at line 24 of file NuFCRunner.h.

Referenced by RunExperiments(), RunFitter(), and SetFitter().

Definition at line 22 of file NuFCRunner.h.

std::vector<NuFCRunInfo*> NuFCRunner::fOwnedRunsSubset [private]

Which of the owned runs can be safely deleted?

Definition at line 26 of file NuFCRunner.h.

Referenced by BuildFromConfig().

std::vector<NuFCRunInfo*> NuFCRunner::fRuns [private]

The documentation for this class was generated from the following files:

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1