NuFCDelegateArchiver Class Reference

#include <NuFCDelegate.h>

Inheritance diagram for NuFCDelegateArchiver:
NuFCDelegate

List of all members.

Public Member Functions

 NuFCDelegateArchiver (const NuFCRunner &runner, const TString &archivedir=".")
virtual ~NuFCDelegateArchiver ()
void StartExperiment (Int_t experiment)
 Called when we start a new experiment.
virtual void EndExperiment (void)
 Called when an experiment finished.
void GotNDSpectrum (const NuFCRunInfo &run, const NuSystematicShifts &shifts, const NuMatrix *ndMatrix)
 Called when we have got the ND matrix.
void GotFDSpectrum (const NuFCRunInfo &run, const NuSystematicShifts &shifts, const NuMatrix *fdMatrix)
 Called when we have got the FD matrix.
void GotDeltaChi2 (const NuMMParameters &bestFit, Double_t deltaChi2)
 Called when we have the final answer.
void UseFitter (NuSystFitter &fitter)
 Called to give the delegate a fitter object so it can do what it wants.
virtual void GotHistogram (TString name, const NuMatrix *matrix)
 A generic histogram passthrough for writing.
void SetArchiveDir (const TString &dir)

Protected Member Functions

 NuFCDelegateArchiver ()

Private Member Functions

void CloseFile (void)
 Close the internal TFile.

Private Attributes

TFile * fTFile
 A TFile object for the current file, to dump to.
TString fArchiveDir
Double_t fDeltaChi2
NuMMParameters fBestFit

Detailed Description

Definition at line 85 of file NuFCDelegate.h.


Constructor & Destructor Documentation

NuFCDelegateArchiver::NuFCDelegateArchiver ( const NuFCRunner runner,
const TString &  archivedir = "." 
)

Definition at line 137 of file NuFCDelegate.cxx.

00138   : NuFCDelegate(runner), fTFile(0), fArchiveDir(".")
00139 {
00140   
00141 }

NuFCDelegateArchiver::~NuFCDelegateArchiver (  )  [virtual]

Definition at line 145 of file NuFCDelegate.cxx.

References CloseFile(), and fTFile.

00146 {
00147   if (fTFile) CloseFile();
00148   
00149 }

NuFCDelegateArchiver::NuFCDelegateArchiver (  )  [inline, protected]

Definition at line 128 of file NuFCDelegate.h.

00128 {}


Member Function Documentation

void NuFCDelegateArchiver::CloseFile ( void   )  [private]

Close the internal TFile.

Definition at line 153 of file NuFCDelegate.cxx.

References fTFile.

Referenced by EndExperiment(), StartExperiment(), and ~NuFCDelegateArchiver().

00154 {
00155   if (fTFile) {
00156     fTFile->Close();
00157     fTFile = 0;
00158   }
00159 }

void NuFCDelegateArchiver::EndExperiment ( void   )  [virtual]

Called when an experiment finished.

Reimplemented from NuFCDelegate.

Definition at line 180 of file NuFCDelegate.cxx.

References CloseFile().

00181 {
00182   CloseFile();
00183 }

void NuFCDelegateArchiver::GotDeltaChi2 ( const NuMMParameters bestFit,
Double_t  deltaChi2 
) [virtual]

Called when we have the final answer.

Reimplemented from NuFCDelegate.

Definition at line 251 of file NuFCDelegate.cxx.

References fBestFit, and fDeltaChi2.

00252 {
00253   NuFCDelegate::GotDeltaChi2(fit, deltaChi2);
00254   fDeltaChi2 = deltaChi2;
00255   fBestFit = fit;
00256 }

void NuFCDelegateArchiver::GotFDSpectrum ( const NuFCRunInfo run,
const NuSystematicShifts shifts,
const NuMatrix fdMatrix 
) [virtual]

Called when we have got the FD matrix.

Reimplemented from NuFCDelegate.

Definition at line 219 of file NuFCDelegate.cxx.

References fTFile, NuFCRunInfo::GetName(), NuMatrix::GetPOT(), Msg::kError, MSG, and NuMatrix::Write().

00222 {
00223   if (!fdMatrix) {
00224     MSG("NuFCDelegateArchiver",Msg::kError)
00225       << "Generated FD Spectrum for run: " << run.GetName()
00226       << " is blank." << endl;
00227     return;
00228   }
00229   // MSG("NuFCDelegate",Msg::kInfo)
00230   //   << "Generated FD Spectrum for run: " << run.GetName()
00231   //   << " (POT: " << fdMatrix->GetPOT() << ")" << endl;  
00232   // Build a POT histogram to write
00233   TH1D pot("hTotalPot","hTotalPot",1,-0.5, 0.5);
00234   pot.SetBinContent(1, fdMatrix->GetPOT());
00235   
00236   
00237   TDirectory *curdir = gDirectory;
00238   fTFile->cd();
00239   
00240   // build a name for the histogram
00241   TString hname = TString("FD_") + run.GetName();
00242   // Write this spectrum to the file
00243   fdMatrix->Write(hname);
00244   pot.Write();
00245   fTFile->Flush();
00246   curdir->cd();
00247 }

void NuFCDelegateArchiver::GotHistogram ( TString  name,
const NuMatrix matrix 
) [virtual]

A generic histogram passthrough for writing.

Reimplemented from NuFCDelegate.

Definition at line 306 of file NuFCDelegate.cxx.

References fTFile, and NuMatrix::Write().

00307 {
00308   // MSG("NuFCDelegate",Msg::kInfo)
00309   //   << "Got histogram \"" << name << "\"."
00310   //   << " POT: " << matrix->GetPOT() << endl;
00311   // 
00312   TDirectory *curdir = gDirectory;
00313   fTFile->cd();
00314 
00315   matrix->Write(name);
00316   fTFile->Flush();
00317   curdir->cd();
00318 
00319 }

void NuFCDelegateArchiver::GotNDSpectrum ( const NuFCRunInfo run,
const NuSystematicShifts shifts,
const NuMatrix ndMatrix 
) [virtual]

Called when we have got the ND matrix.

Reimplemented from NuFCDelegate.

Definition at line 187 of file NuFCDelegate.cxx.

References fTFile, NuFCRunInfo::GetName(), NuMatrix::GetPOT(), Msg::kError, MSG, and NuMatrix::Write().

00190 {
00191   if (!ndMatrix) {
00192     MSG("NuFCDelegateArchiver",Msg::kError)
00193       << "Generated ND Spectrum for run: " << run.GetName()
00194       << " is blank." << endl;
00195     return;
00196   }
00197   // MSG("NuFCDelegateArchiver",Msg::kInfo)
00198   //   << "Generated ND Spectrum for run: " << run.GetName()
00199   //   << " (POT: " << ndMatrix->GetPOT() << ")" << endl;
00200 
00201   // Build a POT histogram to write
00202   TH1D pot("hTotalPotND","hTotalPotND",1,-0.5, 0.5);
00203   pot.SetBinContent(1, ndMatrix->GetPOT());
00204   
00205   TDirectory *curdir = gDirectory;
00206   fTFile->cd();
00207   
00208   // build a name for the histogram
00209   TString hname = TString("ND_") + run.GetName();
00210   // Write this spectrum to the file
00211   ndMatrix->Write(hname);
00212   pot.Write();
00213   fTFile->Flush();
00214   curdir->cd();
00215 }

void NuFCDelegateArchiver::SetArchiveDir ( const TString &  dir  )  [inline]

Definition at line 122 of file NuFCDelegate.h.

References fArchiveDir.

00122                                          {
00123     fArchiveDir = dir;
00124   } 

void NuFCDelegateArchiver::StartExperiment ( Int_t  experiment  )  [virtual]

Called when we start a new experiment.

Reimplemented from NuFCDelegate.

Definition at line 163 of file NuFCDelegate.cxx.

References CloseFile(), fArchiveDir, fname, Plot::Format(), fTFile, Msg::kInfo, Msg::kWarning, and MSG.

00164 {
00165   // Make sure the file was closed properly from before
00166   if (fTFile) {
00167     MSG("NuFCDelegateArchiver",Msg::kWarning) << "Archive file was not closed correctly." << endl;
00168     CloseFile();
00169   }
00170 
00171   // ostringstream fname;
00172   // fname << archive << 
00173   TString fname = fArchiveDir + TString::Format("/FCArchive_%d.root", experiment);
00174   
00175   MSG("NuFCDelegateArchiver",Msg::kInfo) << "Opening file " << fname << " for archiving" << endl;
00176     
00177   fTFile = new TFile(fname, "RECREATE");
00178 }

void NuFCDelegateArchiver::UseFitter ( NuSystFitter fitter  )  [virtual]

Called to give the delegate a fitter object so it can do what it wants.

Reimplemented from NuFCDelegate.

Definition at line 260 of file NuFCDelegate.cxx.

References NuMMParameters::Dm2Bar(), MuELoss::e, fBestFit, fDeltaChi2, NuSystFitter::FillLikelihoodSurfaceBar(), NuFCDelegate::fRunner, fTFile, NuFCRunner::GetTrueParameters(), Msg::kInfo, NuSystFitter::Likelihood(), min, MSG, and NuMMParameters::Sn2Bar().

00261 {
00262   // cout << "Delegate has been handed fitter" << endl;
00263   if (fDeltaChi2 < 0.0) {
00264     MSG("NuFCDelegateArchiver",Msg::kInfo)
00265       << "GOT NEGATIVE DELTA-CHI2" << endl
00266       << "Filling likelihood surface" << endl;
00267     TH2D *c2hist = new TH2D("like","like",1,0.92,0.92,300,0,50e-3);
00268     Double_t min = fitter.FillLikelihoodSurfaceBar(*c2hist, fBestFit);
00269     // Offset the histogram to zero
00270     for (Int_t xbin = 1; xbin <= c2hist->GetNbinsX(); ++xbin)
00271     {
00272       for (Int_t ybin = 1; ybin <= c2hist->GetNbinsY(); ++ybin)
00273       {
00274         c2hist->SetBinContent(xbin, ybin, c2hist->GetBinContent(xbin, ybin)-min);
00275       }      
00276     }
00277     TH1D *c21d = c2hist->ProjectionY();
00278     Double_t truthlike = fitter.Likelihood(fRunner->GetTrueParameters());
00279     Double_t fitlike = fitter.Likelihood(fBestFit);
00280     cout << "Likelihood of fit is: " << fitlike << endl
00281          << "  versus        grid: " << min << endl
00282          << "  versus       truth: " << truthlike << endl;
00283     
00284     // Make a TGraph for the best fit
00285     TGraph graFit(1), graTrue(1);
00286     graFit.SetName("graFit");
00287     graTrue.SetName("graTrue");
00288     graFit.SetPoint(0, fBestFit.Sn2Bar(), fBestFit.Dm2Bar());
00289     graTrue.SetPoint(0, fRunner->GetTrueParameters().Sn2Bar(), fRunner->GetTrueParameters().Dm2Bar());
00290     
00291     // Write things out to file
00292     TDirectory *curdir = gDirectory;
00293     fTFile->cd();
00294 
00295     c2hist->Write();
00296     c21d->Write();
00297     graFit.Write();
00298     graTrue.Write();
00299     fTFile->Flush();
00300     curdir->cd();
00301   }
00302 }


Member Data Documentation

Definition at line 89 of file NuFCDelegate.h.

Referenced by SetArchiveDir(), and StartExperiment().

Definition at line 93 of file NuFCDelegate.h.

Referenced by GotDeltaChi2(), and UseFitter().

Definition at line 92 of file NuFCDelegate.h.

Referenced by GotDeltaChi2(), and UseFitter().

TFile* NuFCDelegateArchiver::fTFile [private]

A TFile object for the current file, to dump to.

Definition at line 88 of file NuFCDelegate.h.

Referenced by CloseFile(), GotFDSpectrum(), GotHistogram(), GotNDSpectrum(), StartExperiment(), UseFitter(), and ~NuFCDelegateArchiver().


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

Generated on 3 Oct 2018 for loon by  doxygen 1.6.1