NuFCFitter Class Reference

Fits a FC experiment. More...

#include <NuFCFitter.h>

List of all members.

Public Member Functions

 NuFCFitter (NuFCExperiment *experiment, NuMMHelperCPT *helper, NuMatrixSpectrum *ndNQData, NuMatrixSpectrum *ndPQData, const NuMMParameters &trueparams)
 NuFCFitter (NuMMHelperCPT *helper, NuMatrixSpectrum *fdNQData, NuMatrixSpectrum *fdPQData, NuMatrixSpectrum *ndNQData, NuMatrixSpectrum *ndPQData, const NuMMParameters &trueparams)
 NuFCFitter (NuMMRunFC *_run, const NuMMParameters &trueparams)
virtual ~NuFCFitter ()
Double_t Fit (const NuMMParameters &fitParameters)
const NuMMParametersBestFit () const
 Look at the best fit point.
void AlwaysArchive (std::string filename)
 Call if you want to write out every experiment.
void ArchiveTo (std::string filename)
void Archive (std::string filename)
void SetSilent (bool _silent=true)

Private Member Functions

NuMMParameters GridSearch (TH2D &likesurf, NuMMParameters mmGrid, NuMMParameters *Ref=0)
 Does a grid search on an arbitrary surface.
NuMMParameters CoarseGridSearch (NuMMParameters start)
 Do a coarse grid search, to seed minuit.
NuMMParameters FineGridSearch (NuMMParameters start)
 Does a finer grid search, if minuit fails.
NuMMParameters MinuitFit (NuMMParameters start)
 Does a minuit fit.
Double_t DeltaChi (const NuMMParameters &bestfit)
 Calculates the Delta chi2 value.
NuMMParameters RecoverNegativeDeltaChi (const NuMMParameters &bestfit)
 Recovers a negative delta chi2 value.
void ClassifyFitPoint (const NuMMParameters &mmFit)
 Examines the fit point and classifies it.
void DoOutput (const NuMMParameters &mmFit, Double_t deltachi)
 Dos the summary output form the fitting.
void ShiftHistogram (TH2D &surface, Double_t shift)
 Shifts a histogram. Doesn't really belong here, but not sure where else.
 ClassDef (NuFCFitter, 0)

Private Attributes

NuMMRunFCfRun
 Pointer to the run object.
NuMatrixSpectrumffdNQData
NuMatrixSpectrumffdPQData
NuSystFitter fsystFitter
 Fitter object.
NuMMParametersfBestFit
 Copy of the best fit point.
Bool_t fFineGridSearch
Bool_t fNegativeDeltaChi
Bool_t fHighFitPoint
Bool_t fZeroFitPoint
Bool_t fArchive
std::string fArchiveFilename
const NuMMParameters fTrueParams
bool silent


Detailed Description

Fits a FC experiment.

Author:
Nick Devenish, Last checkin
Author
nickd
Version:
Revision
1.10
Date:
Date
2010/09/12 15:27:42
Created on: Sun Aug 17, 2008

Definition at line 30 of file NuFCFitter.h.


Constructor & Destructor Documentation

NuFCFitter::NuFCFitter ( NuFCExperiment experiment,
NuMMHelperCPT helper,
NuMatrixSpectrum ndNQData,
NuMatrixSpectrum ndPQData,
const NuMMParameters trueparams 
)

Creates the fitter object. We have to accept pointers here, as everything else we want to use only accepts them, and we can't easily change without possibly breaking large amounts of existing code.

Parameters:
experiment The experiment (i.e. far data) that we are fitting.
helper The NuMMHelperCPT object that contains the helper data
ndNQData The near detector neutrino data
ndPQData The enar detector antineutrino data

Definition at line 23 of file NuFCFitter.cxx.

References NuSystFitter::BatchModeOn(), ffdNQData, ffdPQData, fRun, fsystFitter, NuFCExperiment::GetNQSpectrum(), NuFCExperiment::GetPQSpectrum(), NuMMRunFC::PredictNus(), NuSystFitter::push_back(), and NuMMRun::SetMaximumEnergy().

00029   : fRun(0),
00030     ffdNQData(0),
00031     ffdPQData(0),
00032     fsystFitter(),
00033     fBestFit(0),
00034     fFineGridSearch(false),
00035     fNegativeDeltaChi(false),
00036     fHighFitPoint(false),
00037     fZeroFitPoint(false),
00038     fArchive(false),
00039     fArchiveFilename("archive.root"),
00040     fTrueParams(trueparams),
00041     silent(false)
00042 {
00043     // Firstly, get copies of the far detector spectrum
00044   //NuMatrixSpectrum *fdNQ = &experiment->GetSpectrum();
00045   ffdPQData = new NuMatrixSpectrum(experiment->GetPQSpectrum());
00046   ffdNQData = new NuMatrixSpectrum(experiment->GetNQSpectrum());
00047   
00048   // Create the run!
00049   fRun = new NuMMRunFC(helper, ndNQData, ndPQData, ffdNQData, ffdPQData);
00050   fRun->PredictNus(false);
00051   fRun->SetMaximumEnergy(49.999);
00052   // fRun->QuietModeOn();
00053   
00054   // Now add this run to the fitter
00055   fsystFitter.push_back(fRun);
00056   //fsystFitter.QuietModeOn();
00057   fsystFitter.BatchModeOn();
00058 }

NuFCFitter::NuFCFitter ( NuMMHelperCPT helper,
NuMatrixSpectrum fdNQData,
NuMatrixSpectrum fdPQData,
NuMatrixSpectrum ndNQData,
NuMatrixSpectrum ndPQData,
const NuMMParameters trueparams 
)

Definition at line 62 of file NuFCFitter.cxx.

References NuSystFitter::BatchModeOn(), fRun, fsystFitter, NuMMRunFC::PredictNus(), NuSystFitter::push_back(), and NuMMRun::SetMaximumEnergy().

00068                     : fRun(0),
00069                       ffdNQData(0),
00070                       ffdPQData(0),
00071                       fsystFitter(),
00072                       fBestFit(0),
00073                       fFineGridSearch(false),
00074                       fNegativeDeltaChi(false),
00075                       fHighFitPoint(false),
00076                       fZeroFitPoint(false),
00077                       fArchive(false),
00078                       fArchiveFilename("archive.root"),
00079                       fTrueParams(trueparams),
00080                       silent(false)
00081 {
00082   // Create the run!
00083   fRun = new NuMMRunFC(helper, ndNQData, ndPQData, fdNQData, fdPQData);
00084   fRun->PredictNus(false);
00085   fRun->SetMaximumEnergy(49.999);
00086   // fRun->QuietModeOn();
00087   
00088   // Now add this run to the fitter
00089   fsystFitter.push_back(fRun);
00090   //fsystFitter.QuietModeOn();
00091   fsystFitter.BatchModeOn();
00092 }

NuFCFitter::NuFCFitter ( NuMMRunFC _run,
const NuMMParameters trueparams 
)

Definition at line 96 of file NuFCFitter.cxx.

References NuSystFitter::BatchModeOn(), fRun, fsystFitter, NuMMRunFC::PredictNus(), NuSystFitter::push_back(), and NuMMRun::SetMaximumEnergy().

00098                     : fRun(0),
00099                       ffdNQData(0),
00100                       ffdPQData(0),
00101                       fsystFitter(),
00102                       fBestFit(0),
00103                       fFineGridSearch(false),
00104                       fNegativeDeltaChi(false),
00105                       fHighFitPoint(false),
00106                       fZeroFitPoint(false),
00107                       fArchive(false),
00108                       fArchiveFilename("archive.root"),
00109                       fTrueParams(trueparams),
00110                       silent(false)
00111 {
00112   // Create the run!
00113   fRun = new NuMMRunFC(*_run);
00114   //fRun = _run;
00115   fRun->PredictNus(false);
00116   fRun->SetMaximumEnergy(49.999);
00117   // fRun->QuietModeOn();
00118   
00119   // Now add this run to the fitter
00120   fsystFitter.push_back(fRun);
00121   //fsystFitter.QuietModeOn();
00122   fsystFitter.BatchModeOn();
00123 }

NuFCFitter::~NuFCFitter (  )  [virtual]

Definition at line 127 of file NuFCFitter.cxx.

References fBestFit, ffdNQData, ffdPQData, and fRun.

00128 {
00129   // Delete our run object
00130   if (fRun) delete fRun;
00131   fRun = 0;
00132   
00133   // Delete our copies of the far detector data
00134   if (ffdNQData) delete ffdNQData;
00135   if (ffdPQData) delete ffdPQData;
00136   ffdNQData = ffdPQData = 0;
00137   
00138   // Delete the copy of the best fit point
00139   if (fBestFit) delete fBestFit;
00140   fBestFit = 0;
00141 }


Member Function Documentation

void NuFCFitter::AlwaysArchive ( std::string  filename  )  [inline]

Call if you want to write out every experiment.

Definition at line 64 of file NuFCFitter.h.

References fArchive, and fArchiveFilename.

Referenced by NuFCGridPoint::Run().

00064                                          {
00065     fArchiveFilename = filename;
00066     fArchive = true;
00067   }

void NuFCFitter::Archive ( std::string  filename  ) 

Definition at line 580 of file NuFCFitter.cxx.

References MuELoss::e, fBestFit, ffdNQData, ffdPQData, NuSystFitter::FillLikelihoodSurfaceBar(), fsystFitter, Msg::kError, Msg::kInfo, MSG, and NuMatrixSpectrum::Spectrum().

Referenced by Fit().

00581 {
00582   //MSG("NuFCFitter",Msg::kInfo) << "Disabled all archiving." << endl;
00583   //return;
00584 
00585   if (!ffdPQData || !ffdNQData) {
00586     MSG("NUFCFitter",Msg::kError) << "No far detector spectrum: Cannot archive" << endl;
00587     return;
00588   }
00589   if (!fBestFit) {
00590     MSG("NuFCFitter", Msg::kError)
00591       << "Error: Trying to archive before fit" << endl;
00592     return;
00593   }
00594   
00595   MSG("NuFCFitter", Msg::kInfo)
00596     << "    Archiving to file " << filename << "..." << endl;
00597 
00598   // The actual experiment spectrum
00599 //  TH1D fdSpec(*(ffdPQData->Spectrum()));
00600   NuMatrixSpectrum fdSpec(*ffdPQData);
00601 //   // fdSpec.RebinTo4GeV();
00602 //   // Grab the name out of this
00603   string basename = fdSpec.Spectrum()->GetName();
00604 // 
00605 // // No longer do the likelihood surface - it takes too long. Instead just write out the spectrum,
00606 // // and we can regenerate the surface later if we wish
00607 //   
00608   // Now we want the likelihood surfaces. First do the linear portion
00609   string surfname = basename + "_surf";
00610   TH2D likesurface(surfname.c_str(), surfname.c_str(), 50, 0, 1, 100, 0, 20e-3);
00611 //  TH2D likesurface(surfname.c_str(), surfname.c_str(), 100, 0.9, 1, 100, 0.002, 0.003);
00612   fsystFitter.FillLikelihoodSurfaceBar(likesurface, *fBestFit);
00613 //   
00614 //   // Now do the logarithmic plot
00615 //   vector<Double_t> bins;
00616 //   for (Int_t i = -204; i <= 0; i++) {
00617 //     bins.push_back(pow(10, (Double_t)i/100.0));
00618 //   }
00619 //   Int_t bincount = bins.size()-1;
00620 //   string logname = surfname + "_log";
00621 //   TH2D logsurf(logname.c_str(), logname.c_str(), 50, 0, 1, bincount, &(bins.front()));
00622 //   Double_t minlog = fsystFitter.FillLikelihoodSurfaceBar(logsurf, *fBestFit);
00623 //   
00624 //   // Now, shift both histograms by the minimum
00625 //   Double_t surfmin = minlin < minlog ? minlin : minlog;
00626 //   ShiftHistogram(likesurface, -surfmin);
00627 //   ShiftHistogram(logsurf, -surfmin);
00628   
00629   // Now, write these out!
00630   TFile tf(filename.c_str(), "UPDATE");
00631     fdSpec.Spectrum()->Write();
00632     likesurface.Write();
00633     // logsurf.Write();
00634   tf.Close();
00635 }

void NuFCFitter::ArchiveTo ( std::string  filename  )  [inline]

Definition at line 69 of file NuFCFitter.h.

References fArchiveFilename.

Referenced by NuFCGridPoint::Run().

00069                                      {
00070     fArchiveFilename = filename;
00071   }

const NuMMParameters * NuFCFitter::BestFit (  )  const

Look at the best fit point.

Definition at line 208 of file NuFCFitter.cxx.

References fBestFit, Msg::kError, and MSG.

Referenced by NuFCGridPoint::Run().

00208                                                 {
00209 
00210   if (!fBestFit) {
00211     MSG("NuFCFitter", Msg::kError)
00212     << "Error: Trying to see the best fit before the fit" << endl;
00213     return 0;
00214   }
00215   
00216   return fBestFit;
00217 }

NuFCFitter::ClassDef ( NuFCFitter  ,
 
) [private]

void NuFCFitter::ClassifyFitPoint ( const NuMMParameters mmFit  )  [private]

Examines the fit point and classifies it.

Definition at line 551 of file NuFCFitter.cxx.

References NuMMParameters::Dm2Bar(), MuELoss::e, fHighFitPoint, fTrueParams, fZeroFitPoint, Msg::kInfo, NuMMParameters::LowerDm2BarLimit(), NuMMParameters::LowerSn2BarLimit(), MSG, silent, and NuMMParameters::Sn2Bar().

Referenced by Fit().

00552 {
00553   // cout << "    Checking against minimum dm: " << fTrueParams.LowerDm2BarLimit() << ", sn: " << fTrueParams.LowerSn2BarLimit() << endl;
00554  
00555   // Check to see if the fit is to 'zero'
00556   if (mmFit.Sn2Bar() <= fTrueParams.LowerSn2BarLimit() + 1e-4 || 
00557       mmFit.Dm2Bar() <= fTrueParams.LowerDm2BarLimit() + 1e-6 )
00558   {
00559       if (!silent) {
00560         MSG("NuFCFitter", Msg::kInfo)
00561           << "    Best fit is to no oscillation case\n";
00562       }
00563       fZeroFitPoint = true;
00564   }
00565     
00566   // Now check if the best fit is maxing out
00567   // This message is a little out of date, but will do for now
00568   if (mmFit.Dm2Bar() >= 30e-3 - 0.25e-4) {
00569     if (!silent) {
00570       MSG("NuFCFitter", Msg::kInfo)
00571        << "    Best fit is maxing out on dm2bar ("
00572        << mmFit.Dm2Bar() << ")" << endl;
00573     }
00574     fHighFitPoint = true;
00575   }
00576 }

NuMMParameters NuFCFitter::CoarseGridSearch ( NuMMParameters  start  )  [private]

Do a coarse grid search, to seed minuit.

Definition at line 288 of file NuFCFitter.cxx.

References NuMMParameters::Dm2Bar(), MuELoss::e, NuFCConfig::FixedSin(), fTrueParams, NuFCConfig::GetConfig(), GridSearch(), NuMMParameters::IsDm2BarConstrained(), NuMMParameters::IsSn2BarConstrained(), Msg::kInfo, NuMMParameters::LowerDm2BarLimit(), NuMMParameters::LowerSn2BarLimit(), max, MAXMSG, min, MSG, silent, NuMMParameters::Sn2Bar(), NuMMParameters::UpperDm2BarLimit(), and NuMMParameters::UpperSn2BarLimit().

Referenced by Fit().

00289 {
00290   Int_t gridWidth = 5;
00291   Double_t sinMin = 0.2;
00292   Double_t sinMax = 1.0;
00293   Double_t dmMin = 2e-3;
00294   Double_t dmMax = 30e-3;
00295 
00296   // Constrain to the tighter of mmGrid constraints
00297   // and the defaults above
00298   if (mmGrid.IsSn2BarConstrained()) {
00299     sinMin = max(sinMin, mmGrid.LowerSn2BarLimit());
00300     sinMax = min(sinMax, mmGrid.UpperSn2BarLimit());
00301     MAXMSG("NuFCFitter",Msg::kInfo,1) << "Performing constrained grid search in sin: " << sinMin << " - " << sinMax << endl;
00302   }
00303   if (mmGrid.IsDm2BarConstrained()) {
00304     dmMin = max(dmMin, mmGrid.LowerDm2BarLimit());
00305     dmMax = min(dmMax, mmGrid.UpperDm2BarLimit());
00306     MAXMSG("NuFCFitter",Msg::kInfo,1) << "Performing constrained grid search in dm2: " << dmMin << " - " << dmMax << endl;
00307   }
00308   
00309   const Int_t gridHeight = 15;
00310   
00311   // Check if we are doing one-parameter fit, and if so constrain the grid search
00312   // to one-dimension
00313   NuFCConfig &cfg = NuFCConfig::GetConfig();
00314   if (cfg.FixedSin()) {
00315     gridWidth = 1;
00316     sinMin = sinMax = fTrueParams.Sn2Bar();
00317   }
00318 
00319   // Generate the surface
00320   TH2D likesurf("likesurf", "likesurf", gridWidth, sinMin, sinMax, gridHeight, dmMin, dmMax);
00321   mmGrid = GridSearch(likesurf, mmGrid);
00322   
00323   // Now do a log search
00324   vector<Double_t> bins;
00325   for (Int_t i = -15; i <= -1; i++) {
00326     bins.push_back(pow(10, (Double_t)i/10.0));
00327   }
00328   Int_t bincount = bins.size()-1;
00329   TH2D logsurf("logsurf", "logsurf", gridWidth, sinMin, sinMax, bincount, &(bins.front()));
00330   mmGrid = GridSearch(logsurf, mmGrid, &mmGrid);
00331 
00332   // Output the minimum
00333   if (!silent) {
00334     MSG("NuFCFitter", Msg::kInfo) << "    Coarse grid search found sn2: "
00335       << mmGrid.Sn2Bar() << ", dm: " << mmGrid.Dm2Bar() << '\n';
00336   }
00337   
00338   return mmGrid;
00339 }

Double_t NuFCFitter::DeltaChi ( const NuMMParameters bestfit  )  [private]

Calculates the Delta chi2 value.

Definition at line 466 of file NuFCFitter.cxx.

References NuMMParameters::Dm2Bar(), fsystFitter, fTrueParams, Msg::kDebug, NuMMParameters::LowerDm2BarLimit(), NuMMParameters::LowerSn2BarLimit(), MSG, NuMMParameters::Sn2Bar(), and NuMMParameters::VectorParameters().

Referenced by Fit().

00467 {
00468     // Calculate the two likelihood points
00469     Double_t fitlike = fsystFitter(bestfit.VectorParameters());
00470 
00471     Double_t truelikelihood = 0;  
00472 
00473     // cout << "bfdm: " << bestfit.Dm2Bar() << ", limit = " << fTrueParams.LowerDm2BarLimit() << endl;
00474 
00475     // Don't allow the parameters to go below constrained - this can
00476     // give us an artificially negative delta chi2
00477     if ( (fTrueParams.Dm2Bar() < fTrueParams.LowerDm2BarLimit()) ||
00478          (fTrueParams.Sn2Bar() < fTrueParams.LowerSn2BarLimit()) ) {  
00479         MSG("NuFCFitter", Msg::kDebug) << "    True point is lower than fit is allowed." << endl;
00480         NuMMParameters pc(bestfit);
00481         pc.Dm2Bar(fTrueParams.LowerDm2BarLimit());
00482         pc.Sn2Bar(fTrueParams.LowerSn2BarLimit());
00483         truelikelihood = fsystFitter(pc.VectorParameters());
00484     } else {
00485         truelikelihood = fsystFitter(fTrueParams.VectorParameters());
00486     }
00487     
00488 
00489     // fmmPars.Dm2Bar(fmmPars.LowerDm2BarLimit());
00490     //   MAXMSG("NuFCGriPoint", 5, Msg::kInfo) << "Moving true grid point "
00491     //   fmmPars.Sn2Bar(fmmPars.LowerSn2BarLimit());
00492     //   
00493     // Double_t truelikelihood = fsystFitter(fTrueParams.VectorParameters());
00494 
00495     // Return the difference
00496     return truelikelihood - fitlike;
00497 }

void NuFCFitter::DoOutput ( const NuMMParameters mmFit,
Double_t  deltachi 
) [private]

Dos the summary output form the fitting.

Definition at line 189 of file NuFCFitter.cxx.

References NuMMParameters::Dm2Bar(), fFineGridSearch, fNegativeDeltaChi, fsystFitter, Msg::kInfo, MSG, NuMMParameters::Sn2Bar(), and NuMMParameters::VectorParameters().

Referenced by Fit().

00190 {
00191   // Output the fit results
00192   Double_t fitlike = fsystFitter(mmFit.VectorParameters());
00193   MSG("NuFCFitter", Msg::kInfo)
00194     << "    Minimum is dm2bar: " << mmFit.Dm2Bar()
00195     << " sn2bar: " << mmFit.Sn2Bar() << '\n'
00196     << "    Fit Likelyhood: " << fitlike << '\n'
00197     << "    Delta Chi2:     " << deltachi << '\n';
00198   
00199   // Did we want to ask the control script to log this?
00200   if (fFineGridSearch || fNegativeDeltaChi) {
00201     MSG("NuFCFitter", Msg::kInfo) << "    Please Log this experiment." << endl;
00202   }
00203   
00204 }

NuMMParameters NuFCFitter::FineGridSearch ( NuMMParameters  start  )  [private]

Does a finer grid search, if minuit fails.

Definition at line 343 of file NuFCFitter.cxx.

References NuMMParameters::Dm2Bar(), MuELoss::e, NuFCConfig::FixedSin(), fTrueParams, NuFCConfig::GetConfig(), GridSearch(), Msg::kInfo, NuMMParameters::LowerDm2BarLimit(), NuMMParameters::LowerSn2BarLimit(), MSG, silent, and NuMMParameters::Sn2Bar().

Referenced by MinuitFit().

00344 {
00345   // Calculate the location of the fine grid search
00346   Double_t gridL, gridR, gridT, gridB;
00347   gridL = gridR = gridT = gridB = -1.0;
00348   
00349   // The width and height of the grid
00350   Int_t gridWidth = 19;
00351   const Int_t gridHeight = 19;
00352   
00353   // Configuration
00354   NuFCConfig &cfg = NuFCConfig::GetConfig();
00355   
00356   // change behavior if we want a one-parameter fit
00357   if (!cfg.FixedSin()) {
00358       // Go +- 0.2 in sin space
00359     gridL = mmStart.Sn2Bar() - 0.2;
00360     gridR = gridL + 0.4;
00361     // Now limit it to the physical realm
00362     if (gridL <= fTrueParams.LowerSn2BarLimit()) gridL = fTrueParams.LowerSn2BarLimit();
00363     if (gridR > 1.0) gridR = 1.0;
00364   } else {
00365     // One-parameter fit
00366     gridL = gridR = fTrueParams.Sn2Bar();
00367     gridWidth = 1;
00368   }
00369 
00370   // And go +-2e-3 in mass space
00371   gridB = mmStart.Dm2Bar() - 2e-3;
00372   gridT = gridB + 4e-3;
00373   // We only really need to worry about lower limit here
00374   if (gridB <= fTrueParams.LowerDm2BarLimit()) gridB = fTrueParams.LowerSn2BarLimit();
00375 
00376   if (!silent) {
00377     MSG("NuFCFitter", Msg::kInfo) 
00378       << "    Doing fine grid search on sin = [ "
00379       << gridL << ", " << gridR << " ]\n"
00380       << "                              dm  = [ "
00381       << gridB << ", " << gridT << " ]\n";
00382   }
00383   // Ensure that we haven't done anything stupid like set low above high
00384   if (gridL > gridR || gridT <= gridB) {
00385 //      cout << "Error: Negative range in fine grid search" << endl;
00386       throw runtime_error("Negative range in fine grid search");
00387   }
00388   
00389   // Make the surface
00390   
00391   // Generate the surface
00392   TH2D likesurf("likesurf", "likesurf", gridWidth, gridL, gridR,
00393     gridHeight, gridB, gridT);
00394     
00395   // And now do a grid search on this
00396   NuMMParameters mmGrid = GridSearch(likesurf, mmStart);
00397   
00398   // Temporarily, archive any fine grid surface
00399   // TFile tf("archives/finegrid.root", "UPDATE");
00400   //   likesurf.Write();
00401   //   tf.Close();
00402   
00403   // Output the minimum
00404   if (!silent) {
00405     MSG("NuFCFitter", Msg::kInfo) << "    Fine grid search found sn2: "
00406       << mmGrid.Sn2Bar() << ", dm: " << mmGrid.Dm2Bar() << '\n';
00407   }  
00408   
00409   return mmGrid;
00410 }

Double_t NuFCFitter::Fit ( const NuMMParameters fitParameters  ) 

Fits the previously passed in FC experiment. Returns an std::pair with the delta chi2, and the best fit

Parameters:
fitParameters a parameters object, set to the true value

Definition at line 145 of file NuFCFitter.cxx.

References Archive(), ClassifyFitPoint(), CoarseGridSearch(), DeltaChi(), DoOutput(), MuELoss::e, fArchive, fArchiveFilename, fBestFit, MinuitFit(), RecoverNegativeDeltaChi(), and silent.

Referenced by NuFCGridPoint::Run().

00146 {
00147   // Start with a coarse grid search, to seed minuit
00148   const NuMMParameters mmGrid = CoarseGridSearch(fitParameters);    
00149 
00150   // Now do a minuit fit
00151   NuMMParameters mmFit = MinuitFit(mmGrid);
00152 
00153   Double_t dchi = DeltaChi(mmFit);
00154 
00155   // If this gave a negative value, rescue it (allow a tiny gap)
00156   if (dchi < 0) {
00157     if (dchi < -1e-5) {
00158       mmFit = RecoverNegativeDeltaChi(mmFit);
00159       dchi = DeltaChi(mmFit);
00160     } else {
00161       // It is below zero, but within error. Set it to zero!
00162       dchi = 0;
00163     }
00164   }
00165 
00166   // Make a copy of the best fit point
00167   if (fBestFit) delete fBestFit;
00168   fBestFit = new NuMMParameters(mmFit);
00169 
00170   // Classify the best fit point i.e. is it zero, high etc
00171   // this is mainly for informational purposes (i.e. the run script)
00172   ClassifyFitPoint(mmFit);
00173 
00174   // Do we want to archive?
00175   if (fArchive) { // || fNegativeDeltaChi
00176     Archive(fArchiveFilename);
00177   }
00178 
00179   if (!silent) {
00180     // Do the output
00181     DoOutput(mmFit, dchi);
00182   }
00183   
00184   return dchi;
00185 }

NuMMParameters NuFCFitter::GridSearch ( TH2D &  likesurf,
NuMMParameters  mmGrid,
NuMMParameters Ref = 0 
) [private]

Does a grid search on an arbitrary surface.

Definition at line 414 of file NuFCFitter.cxx.

References NuMMParameters::Dm2Bar(), NuSystFitter::FillLikelihoodSurfaceBar(), NuFCConfig::FixedSin(), fsystFitter, fTrueParams, NuFCConfig::GetConfig(), Msg::kDebug, MSG, NuMMParameters::Sn2Bar(), and NuMMParameters::VectorParameters().

Referenced by CoarseGridSearch(), and FineGridSearch().

00415 {
00416     Double_t likelihood = fsystFitter.FillLikelihoodSurfaceBar(likesurf, mmGrid);
00417     
00418     // Find the point on this surface that is minimum
00419     Int_t minbinX = 0, minbinY = 0, minbinZ = 0;
00420     likesurf.GetMinimumBin(minbinX, minbinY, minbinZ);
00421     Double_t minsin = likesurf.GetXaxis()->GetBinCenter(minbinX);
00422     Double_t minmass = likesurf.GetYaxis()->GetBinCenter(minbinY);
00423 
00424     // Access the configuration
00425     NuFCConfig &cfg = NuFCConfig::GetConfig();
00426 
00427     // Check the zero point, to see if it is lower than anything else on the grid
00428     mmGrid.Dm2Bar(0);
00429     // Different 'zero' point if one parameter
00430     if (cfg.FixedSin()) {
00431       mmGrid.Sn2Bar(fTrueParams.Sn2Bar());
00432     } else {
00433       mmGrid.Sn2Bar(0);
00434     }
00435     
00436     Double_t zeropoint = fsystFitter(mmGrid.VectorParameters());
00437     if (zeropoint < likelihood) {
00438         // Then the no-oscillation case is the minimum
00439         minsin = 0.0;
00440         minmass = 0.0;
00441         
00442         if (cfg.FixedSin()) {
00443           minsin = fTrueParams.Sn2Bar();
00444         }
00445     }
00446     
00447     // If we have been given a reference point, check to see if this is lower
00448     if (Ref) {
00449       Double_t refpoint = fsystFitter(Ref->VectorParameters());
00450       if (refpoint < likelihood) {
00451         MSG("NuFCFitter", Msg::kDebug) << "    Reference point is lower than grid search" << endl;
00452         minsin = Ref->Sn2Bar();
00453         minmass = Ref->Dm2Bar();
00454       }
00455     }
00456     
00457     // Set mmPars to the newly found point, then return it
00458     mmGrid.Sn2Bar(minsin);
00459     mmGrid.Dm2Bar(minmass);
00460     
00461     return mmGrid;
00462 }

NuMMParameters NuFCFitter::MinuitFit ( NuMMParameters  start  )  [private]

Does a minuit fit.

Definition at line 222 of file NuFCFitter.cxx.

References NuMMParameters::Dm2(), NuMMParameters::Dm2Bar(), fFineGridSearch, FineGridSearch(), NuFCConfig::FixedSin(), NuMMParameters::FixSn2Bar(), fsystFitter, fTrueParams, NuFCConfig::GetConfig(), Msg::kDebug, Msg::kInfo, NuMMParameters::LowerDm2BarLimit(), NuMMParameters::LowerSn2BarLimit(), NuSystFitter::Minimise(), NuMMParameters::MinuitPass(), MSG, silent, NuMMParameters::Sn2(), NuMMParameters::Sn2Bar(), and NuMMParameters::VectorParameters().

Referenced by Fit().

00223 {
00224   // If it is trying to start us at zero, reset to the search minimum
00225   // fTrueParams.LowerDm2BarLimit()) {
00226   if (mmStart.Sn2Bar() == 0) {
00227     if (!silent) {
00228       MSG("NuFCFitter", Msg::kDebug) << "    Starting minuit at no-oscillation; shifting to lower limits" << endl;
00229     }
00230     mmStart.Sn2Bar(fTrueParams.LowerDm2BarLimit());
00231     mmStart.Dm2Bar(fTrueParams.LowerSn2BarLimit());
00232   }
00233   
00234   // Fix the sin, if specified
00235   NuFCConfig &cfg = NuFCConfig::GetConfig();
00236   if (cfg.FixedSin()) {
00237     mmStart.FixSn2Bar();
00238     mmStart.Sn2Bar(fTrueParams.Sn2Bar());
00239   }
00240   
00241   // Now run minuit itself
00242   NuMMParameters mmFit = fsystFitter.Minimise(mmStart);
00243   
00244   // Did minuit succeed?
00245   if (mmFit.MinuitPass())
00246   {
00247     if (!silent) {
00248       // Tell them what minuit found
00249       MSG("NuFCFitter", Msg::kInfo)
00250         << "    Minuit found: dm2: " << mmFit.Dm2()
00251         << " sn2: " << mmFit.Sn2()
00252         << " dm2bar: " << mmFit.Dm2Bar()
00253         << " sn2bar: " << mmFit.Sn2Bar()
00254         << '\n';
00255     }
00256   } else {
00257       // Minuit failed to fit. Use a more intensive grid search,
00258       // starting on the minuit starting point (that we get from
00259       // a grid search)
00260       if (!silent) {
00261         MSG("NuFCFitter", Msg::kInfo) << "    Minuit fit failed." << endl;
00262         MSG("NuFCFitter", Msg::kInfo) << "    Searching fine grid around sn2: " << mmStart.Sn2Bar()
00263                                       << ", dm2: " << mmStart.Dm2Bar() << endl;
00264       }
00265       NuMMParameters mmFineGrid = FineGridSearch(mmStart);
00266       fFineGridSearch = true;
00267       
00268       // Test the fine grid search against the result from minuit = it could be possible
00269       // that minuit found a 'better' point, even if it failed
00270       Double_t minuit_chi = fsystFitter(mmFit.VectorParameters());
00271       Double_t finegrid_chi = fsystFitter(mmFineGrid.VectorParameters());
00272       
00273       if (minuit_chi > finegrid_chi) {
00274         // The new, fine grid point is better
00275         mmFit = mmFineGrid;
00276       } else {
00277         // The minuit fail point is actually better. Use that.
00278         MSG("NuFCFitter", Msg::kInfo) << "    Failed Minuit fit is better than fine grid, using." << endl;
00279       }
00280       
00281   }
00282   
00283   return mmFit;
00284 }

NuMMParameters NuFCFitter::RecoverNegativeDeltaChi ( const NuMMParameters bestfit  )  [private]

Recovers a negative delta chi2 value.

Definition at line 502 of file NuFCFitter.cxx.

References NuMMParameters::Dm2Bar(), NuFCConfig::FixedSin(), NuMMParameters::FixSn2Bar(), fNegativeDeltaChi, fsystFitter, fTrueParams, NuFCConfig::GetConfig(), Msg::kError, Msg::kInfo, NuSystFitter::Minimise(), NuMMParameters::MinuitPass(), MSG, NuMMParameters::Sn2Bar(), and NuMMParameters::VectorParameters().

Referenced by Fit().

00503 {
00504   // Set the failure flag
00505   fNegativeDeltaChi = true;
00506 
00507   // Recalculate the likelihoods
00508   Double_t truelike = fsystFitter(fTrueParams.VectorParameters());
00509   Double_t oldlike = fsystFitter(bestfit.VectorParameters());;
00510 
00511   // Make a copy of the true parameters, to ensure that we do a 1D fit if specified
00512   // (this is assuming we cannot guarantee that the true parameters has the parameter fixed)
00513   NuMMParameters tpcopy(fTrueParams);
00514   NuFCConfig &cfg = NuFCConfig::GetConfig();
00515   if (cfg.FixedSin()) {
00516     tpcopy.FixSn2Bar();
00517   }
00518   // NuMMParameters newFit = fsystFitter.Minimise(fTrueParams);
00519   NuMMParameters newFit = fsystFitter.Minimise(tpcopy);
00520   
00521   MSG("NuFCFitter", Msg::kInfo)
00522     << "    Negative delta chi2 likelihood (" << truelike - oldlike
00523     << ") found. Refitting from true (" << truelike << ")" << endl;
00524   
00525   
00526   // If this passed, and is lower than our old likelihood, then use it
00527   if (newFit.MinuitPass())
00528   {
00529       MSG("NuFCFitter", Msg::kInfo) << "    Refit passed." << endl;
00530       Double_t newlike = fsystFitter(newFit.VectorParameters());
00531       if (newlike > oldlike) {
00532           MSG("NuFCFitter", Msg::kInfo)
00533             << "    New fit point ( dm: " << newFit.Dm2Bar() << ", sn: " << newFit.Sn2Bar() << " )\n"
00534             << "    at " << newlike << " is higher than before ( " << oldlike << " )! strange!\n"
00535             << "    Returning true fit point, as is lowest we have seen."
00536             << endl;
00537           newFit = fTrueParams;
00538       }
00539   } else {
00540       MSG("NuFCFitter", Msg::kError)
00541         << "    Unrecoverable error: Refit on negative deltachi failed."
00542         << endl;
00543       throw logic_error("NuFCFitter Refit on negative deltachi failed.");
00544   }
00545 
00546   return newFit;
00547 }

void NuFCFitter::SetSilent ( bool  _silent = true  )  [inline]

Definition at line 75 of file NuFCFitter.h.

References silent.

Referenced by NuFCGridPoint::Run().

00075 {silent = _silent;}

void NuFCFitter::ShiftHistogram ( TH2D &  surface,
Double_t  shift 
) [private]

Shifts a histogram. Doesn't really belong here, but not sure where else.

Definition at line 639 of file NuFCFitter.cxx.

00640 {
00641     for (Int_t x = 1; x <= surface.GetNbinsX(); x++)
00642     {
00643         for (Int_t y = 1; y <= surface.GetNbinsY(); y++)
00644         {
00645             Double_t contents = surface.GetBinContent(x, y);
00646             surface.SetBinContent(x, y, contents + shift);
00647         }
00648     }
00649 }


Member Data Documentation

Bool_t NuFCFitter::fArchive [private]

Definition at line 126 of file NuFCFitter.h.

Referenced by AlwaysArchive(), and Fit().

std::string NuFCFitter::fArchiveFilename [private]

Definition at line 127 of file NuFCFitter.h.

Referenced by AlwaysArchive(), ArchiveTo(), and Fit().

NuMMParameters* NuFCFitter::fBestFit [private]

Copy of the best fit point.

Definition at line 117 of file NuFCFitter.h.

Referenced by Archive(), BestFit(), Fit(), and ~NuFCFitter().

NuMatrixSpectrum* NuFCFitter::ffdNQData [private]

Pointers to copies of the far detector spectrum - the NuMMRunFC objects only accept pointers, but don't alter or copy them.

Definition at line 110 of file NuFCFitter.h.

Referenced by Archive(), NuFCFitter(), and ~NuFCFitter().

NuMatrixSpectrum* NuFCFitter::ffdPQData [private]

Definition at line 111 of file NuFCFitter.h.

Referenced by Archive(), NuFCFitter(), and ~NuFCFitter().

Bool_t NuFCFitter::fFineGridSearch [private]

Definition at line 120 of file NuFCFitter.h.

Referenced by DoOutput(), and MinuitFit().

Bool_t NuFCFitter::fHighFitPoint [private]

Definition at line 123 of file NuFCFitter.h.

Referenced by ClassifyFitPoint().

Bool_t NuFCFitter::fNegativeDeltaChi [private]

Definition at line 121 of file NuFCFitter.h.

Referenced by DoOutput(), and RecoverNegativeDeltaChi().

NuMMRunFC* NuFCFitter::fRun [private]

Pointer to the run object.

Definition at line 106 of file NuFCFitter.h.

Referenced by NuFCFitter(), and ~NuFCFitter().

NuSystFitter NuFCFitter::fsystFitter [private]

Fitter object.

Definition at line 114 of file NuFCFitter.h.

Referenced by Archive(), DeltaChi(), DoOutput(), GridSearch(), MinuitFit(), NuFCFitter(), and RecoverNegativeDeltaChi().

const NuMMParameters NuFCFitter::fTrueParams [private]

Definition at line 130 of file NuFCFitter.h.

Referenced by ClassifyFitPoint(), CoarseGridSearch(), DeltaChi(), FineGridSearch(), GridSearch(), MinuitFit(), and RecoverNegativeDeltaChi().

Bool_t NuFCFitter::fZeroFitPoint [private]

Definition at line 124 of file NuFCFitter.h.

Referenced by ClassifyFitPoint().

bool NuFCFitter::silent [private]

Definition at line 132 of file NuFCFitter.h.

Referenced by ClassifyFitPoint(), CoarseGridSearch(), FineGridSearch(), Fit(), MinuitFit(), and SetSilent().


The documentation for this class was generated from the following files:
Generated on Mon Sep 1 00:52:12 2014 for loon by  doxygen 1.4.7