NuFCFitterNSINubar Class Reference

Fits a FC experiment. More...

#include <NuFCFitterNSINubar.h>

List of all members.

Public Member Functions

 NuFCFitterNSINubar (NuFCExperiment *experiment, NuMMHelperCPT *helper, NuMatrixSpectrum *ndNQData, NuMatrixSpectrum *ndPQData, const NuMMParameters &trueparams)
 NuFCFitterNSINubar (NuMMHelperCPT *helper, NuMatrixSpectrum *fdNQData, NuMatrixSpectrum *fdPQData, NuMatrixSpectrum *ndNQData, NuMatrixSpectrum *ndPQData, const NuMMParameters &trueparams)
 NuFCFitterNSINubar (NuMMRunFCNSINubar *_run, const NuMMParameters &trueparams)
virtual ~NuFCFitterNSINubar ()
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 (NuFCFitterNSINubar, 0)

Private Attributes

NuMMRunFCNSINubarfRun
 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
zisvan
Version:
Revision
1.1
Date:
Date
2011/03/29 04:11:53

Created on: Sun Aug 17, 2008

Definition at line 30 of file NuFCFitterNSINubar.h.


Constructor & Destructor Documentation

NuFCFitterNSINubar::NuFCFitterNSINubar ( 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 NuFCFitterNSINubar.cxx.

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

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(true)
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 NuMMRunFCNSINubar(helper, ndNQData, ndPQData, ffdNQData, ffdPQData);
00050   fRun->ConfigForNonStandard();
00051   fRun->PredictNus(false);
00052   fRun->SetMaximumEnergy(49.999);
00053   fRun->LinearInterpolation(false);
00054   // fRun->QuietModeOn();
00055   
00056   // Now add this run to the fitter
00057   fsystFitter.push_back(fRun);
00058   //fsystFitter.QuietModeOn();
00059   fsystFitter.BatchModeOn();
00060 }

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

Definition at line 64 of file NuFCFitterNSINubar.cxx.

References NuSystFitter::BatchModeOn(), NuMMRun::ConfigForNonStandard(), fRun, fsystFitter, NuMMRunFCNSINubar::LinearInterpolation(), NuMMRunFCNSINubar::PredictNus(), NuSystFitter::push_back(), and NuMMRun::SetMaximumEnergy().

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

NuFCFitterNSINubar::NuFCFitterNSINubar ( NuMMRunFCNSINubar _run,
const NuMMParameters trueparams 
)

Definition at line 100 of file NuFCFitterNSINubar.cxx.

References NuSystFitter::BatchModeOn(), NuMMRun::ConfigForNonStandard(), fRun, fsystFitter, NuMMRunFCNSINubar::LinearInterpolation(), NuMMRunFCNSINubar::PredictNus(), NuSystFitter::push_back(), and NuMMRun::SetMaximumEnergy().

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

NuFCFitterNSINubar::~NuFCFitterNSINubar (  )  [virtual]

Definition at line 133 of file NuFCFitterNSINubar.cxx.

References fBestFit, ffdNQData, ffdPQData, and fRun.

00134 {
00135   // Delete our run object
00136   if (fRun) delete fRun;
00137   fRun = 0;
00138   
00139   // Delete our copies of the far detector data
00140   if (ffdNQData) delete ffdNQData;
00141   if (ffdPQData) delete ffdPQData;
00142   ffdNQData = ffdPQData = 0;
00143   
00144   // Delete the copy of the best fit point
00145   if (fBestFit) delete fBestFit;
00146   fBestFit = 0;
00147 }


Member Function Documentation

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

Call if you want to write out every experiment.

Definition at line 64 of file NuFCFitterNSINubar.h.

References fArchive, and fArchiveFilename.

Referenced by NuFCGridPointNSINubar::Run().

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

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

Definition at line 590 of file NuFCFitterNSINubar.cxx.

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

Referenced by Fit().

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

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

Definition at line 69 of file NuFCFitterNSINubar.h.

References fArchiveFilename.

Referenced by NuFCGridPointNSINubar::Run().

00069                                      {
00070     fArchiveFilename = filename;
00071   }

const NuMMParameters * NuFCFitterNSINubar::BestFit (  )  const

Look at the best fit point.

Definition at line 215 of file NuFCFitterNSINubar.cxx.

References fBestFit, Msg::kError, and MSG.

Referenced by NuFCGridPointNSINubar::Run().

00215                                                         {
00216 
00217   if (!fBestFit) {
00218     MSG("NuFCFitterNSINubar", Msg::kError)
00219     << "Error: Trying to see the best fit before the fit" << endl;
00220     return 0;
00221   }
00222   
00223   return fBestFit;
00224 }

NuFCFitterNSINubar::ClassDef ( NuFCFitterNSINubar  ,
 
) [private]
void NuFCFitterNSINubar::ClassifyFitPoint ( const NuMMParameters mmFit  )  [private]

Examines the fit point and classifies it.

Definition at line 561 of file NuFCFitterNSINubar.cxx.

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

Referenced by Fit().

00562 {
00563   // cout << "    Checking against minimum dm: " << fTrueParams.LowerDm2BarLimit() << ", sn: " << fTrueParams.LowerSn2BarLimit() << endl;
00564  
00565   // Check to see if the fit is to 'zero'
00566   if (mmFit.Epsilon() <= fTrueParams.LowerEpsilonLimit() + 1e-4 || 
00567       mmFit.Dm2Bar() <= fTrueParams.LowerDm2BarLimit() + 1e-6 )
00568   {
00569       if (!silent) {
00570         MSG("NuFCFitterNSINubar", Msg::kInfo)
00571           << "    Best fit is to no oscillation case\n";
00572       }
00573       fZeroFitPoint = true;
00574   }
00575     
00576   // Now check if the best fit is maxing out
00577   // This message is a little out of date, but will do for now
00578   if (mmFit.Dm2Bar() >= 30e-3 - 0.25e-4) {
00579     if (!silent) {
00580       MSG("NuFCFitterNSINubar", Msg::kInfo)
00581        << "    Best fit is maxing out on dm2bar ("
00582        << mmFit.Dm2Bar() << ")" << endl;
00583     }
00584     fHighFitPoint = true;
00585   }
00586 }

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

Do a coarse grid search, to seed minuit.

Definition at line 296 of file NuFCFitterNSINubar.cxx.

References NuMMParameters::Dm2Bar(), MuELoss::e, NuMMParameters::Epsilon(), NuFCConfig::FixedDm2(), fTrueParams, NuFCConfig::GetConfig(), GridSearch(), NuMMParameters::IsDm2BarConstrained(), NuMMParameters::IsEpsilonConstrained(), Msg::kInfo, NuMMParameters::LowerDm2BarLimit(), NuMMParameters::LowerEpsilonLimit(), max, MAXMSG, min, MSG, silent, NuMMParameters::UpperDm2BarLimit(), and NuMMParameters::UpperEpsilonLimit().

Referenced by Fit().

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

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

Calculates the Delta chi2 value.

Definition at line 476 of file NuFCFitterNSINubar.cxx.

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

Referenced by Fit().

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

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

Dos the summary output form the fitting.

Definition at line 195 of file NuFCFitterNSINubar.cxx.

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

Referenced by Fit().

00196 {
00197   // Output the fit results
00198   Double_t fitlike = fsystFitter(mmFit.VectorParameters());
00199   MSG("NuFCFitterNSINubar", Msg::kInfo)
00200     << "    Minimum is dm2bar: " << mmFit.Dm2Bar()
00201     << " epsilon: " << mmFit.Epsilon() << '\n'
00202     << " sn2bar: " << mmFit.Sn2Bar() << '\n'
00203     << "    Fit Likelyhood: " << fitlike << '\n'
00204     << "    Delta Chi2:     " << deltachi << '\n';
00205   
00206   // Did we want to ask the control script to log this?
00207   if (fFineGridSearch || fNegativeDeltaChi) {
00208     MSG("NuFCFitterNSINubar", Msg::kInfo) << "    Please Log this experiment." << endl;
00209   }
00210   
00211 }

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

Does a finer grid search, if minuit fails.

Definition at line 351 of file NuFCFitterNSINubar.cxx.

References NuMMParameters::Dm2Bar(), MuELoss::e, NuMMParameters::Epsilon(), NuFCConfig::FixedDm2(), fTrueParams, NuFCConfig::GetConfig(), GridSearch(), Msg::kInfo, NuMMParameters::LowerDm2BarLimit(), NuMMParameters::LowerEpsilonLimit(), MSG, and silent.

Referenced by MinuitFit().

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

Double_t NuFCFitterNSINubar::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 151 of file NuFCFitterNSINubar.cxx.

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

Referenced by NuFCGridPointNSINubar::Run().

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

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

Does a grid search on an arbitrary surface.

Definition at line 424 of file NuFCFitterNSINubar.cxx.

References NuMMParameters::Dm2Bar(), NuMMParameters::Epsilon(), NuSystFitter::FillLikelihoodSurfaceNSIBar(), NuFCConfig::FixedDm2(), fsystFitter, fTrueParams, NuFCConfig::GetConfig(), Msg::kDebug, MSG, and NuMMParameters::VectorParameters().

Referenced by CoarseGridSearch(), and FineGridSearch().

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

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

Does a minuit fit.

Definition at line 229 of file NuFCFitterNSINubar.cxx.

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

Referenced by Fit().

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

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

Recovers a negative delta chi2 value.

Definition at line 512 of file NuFCFitterNSINubar.cxx.

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

Referenced by Fit().

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

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

Definition at line 75 of file NuFCFitterNSINubar.h.

References silent.

Referenced by NuFCGridPointNSINubar::Run().

00075 {silent = _silent;}

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

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

Definition at line 649 of file NuFCFitterNSINubar.cxx.

00650 {
00651     for (Int_t x = 1; x <= surface.GetNbinsX(); x++)
00652     {
00653         for (Int_t y = 1; y <= surface.GetNbinsY(); y++)
00654         {
00655             Double_t contents = surface.GetBinContent(x, y);
00656             surface.SetBinContent(x, y, contents + shift);
00657         }
00658     }
00659 }


Member Data Documentation

Bool_t NuFCFitterNSINubar::fArchive [private]

Definition at line 126 of file NuFCFitterNSINubar.h.

Referenced by AlwaysArchive(), and Fit().

std::string NuFCFitterNSINubar::fArchiveFilename [private]

Definition at line 127 of file NuFCFitterNSINubar.h.

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

Copy of the best fit point.

Definition at line 117 of file NuFCFitterNSINubar.h.

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

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

Definition at line 110 of file NuFCFitterNSINubar.h.

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

Definition at line 111 of file NuFCFitterNSINubar.h.

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

Definition at line 120 of file NuFCFitterNSINubar.h.

Referenced by DoOutput(), and MinuitFit().

Definition at line 123 of file NuFCFitterNSINubar.h.

Referenced by ClassifyFitPoint().

Definition at line 121 of file NuFCFitterNSINubar.h.

Referenced by DoOutput(), and RecoverNegativeDeltaChi().

Pointer to the run object.

Definition at line 106 of file NuFCFitterNSINubar.h.

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

Definition at line 124 of file NuFCFitterNSINubar.h.

Referenced by ClassifyFitPoint().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1