Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

NuFCGridPoint.cxx

Go to the documentation of this file.
00001 #include <string>
00002 #include <sstream>
00003 #include <vector>
00004 #include <map>  // For std::pair
00005 #include <stdexcept>
00006 
00007 
00008 using namespace std;
00009 
00010 #include "TH1.h"
00011 #include "TRandom3.h"
00012 
00013 #include "NtupleUtils/NuMMRunFC.h"
00014 #include "NtupleUtils/NuMatrixSpectrum.h"
00015 
00016 #include "NtupleUtils/NuFCGridPoint.h"
00017 #include "NtupleUtils/NuFCExperiment.h"
00018 #include "NtupleUtils/NuFCExperimentFactory.h"
00019 #include "NtupleUtils/NuFCFitter.h"
00020 #include "NtupleUtils/NuFCConfig.h"
00021 
00022 #include "MessageService/MsgService.h"
00023 
00024 CVSID("$Id: NuFCGridPoint.cxx,v 1.10 2009/04/15 13:53:41 nickd Exp $");
00025 
00027 
00028 NuFCGridPoint::NuFCGridPoint(Double_t sin, Double_t dm2, const NuMatrixSpectrum &ndNQData,
00029   const NuMatrixSpectrum &ndPQData, const NuMMHelperCPT &helper)
00030   : fsin2(sin),
00031     fdm2(dm2),
00032     fHelper(helper),
00033     ffdPredictionNQ(0),
00034     ffdPredictionPQ(0),
00035     fndNQ(ndNQData),
00036     fndPQ(ndPQData),
00037     fRandy(0),
00038     fArchive(false),
00039     fArchiveFilename("archive.root"),
00040     fExperimentFactory(0)
00041 { 
00042   // Initialise the NuMMParameters object
00043   // Use default parameters for neutrinos, even though this is bad
00044   fmmPars.Dm2(2.43e-3);
00045   fmmPars.Sn2(1.0);
00046 
00047   // Set the neutrino parameters
00048   fmmPars.Dm2Bar(fdm2);
00049   fmmPars.Sn2Bar(fsin2);
00050   // Fix everything except antineutrino fitting
00051   fmmPars.FixNorm();
00052   fmmPars.FixShwScale();
00053   fmmPars.FixNCBackground();
00054   fmmPars.FixDm2();
00055   fmmPars.FixSn2();
00056 
00057   // Set up the random number generator
00058   fRandy = new TRandom3(0);
00059   
00060   // Load the configuration
00061   NuFCConfig &cfg = NuFCConfig::GetConfig();
00062   // Set up the experiment factory... if we want to
00063 
00064   // We always use the experiment factory now
00065   string near_events = cfg.GetEventsND();
00066   string far_events = cfg.GetEventsFD();
00067   string tau_events = cfg.GetEventsTau();
00068   fExperimentFactory = new NuFCExperimentFactory(fRandy, near_events, far_events, tau_events);
00069   
00070   // Turn off systematics if we've said we don't want them
00071   if (cfg.Systematics() == false) fExperimentFactory->NoSystematics();
00072   
00073   // Are we doing a one-parameter fit?
00074   if (cfg.FixedSin()) {
00075     fmmPars.FixSn2Bar();
00076   }
00077 }
00078 
00080 
00081 NuFCGridPoint::~NuFCGridPoint()
00082 {
00083   // Delete the far detector predictions
00084   if (ffdPredictionNQ) delete ffdPredictionNQ;
00085   if (ffdPredictionPQ) delete ffdPredictionPQ;
00086   ffdPredictionNQ = ffdPredictionPQ = 0;
00087   
00088   // // Delete the near detector spectra
00089   // if (fndNQ) delete fndNQ;
00090   // if (fndPQ) delete fndPQ;
00091   // fndNQ = fndPQ = 0;
00092 
00093 }
00094 
00096 
00097 // Uses user-generated spectra for the far detector data
00098 void NuFCGridPoint::UsePrediction(const NuMatrixSpectrum &fdNQData,
00099                                   const NuMatrixSpectrum &fdPQData)
00100 {
00101   // Delete the far spectra if they exist
00102   if (ffdPredictionNQ) delete ffdPredictionNQ;
00103   if (ffdPredictionPQ) delete ffdPredictionPQ;
00104 
00105   // Make a copy of the passed in data spectra
00106   // this->ffdPredictionNQ = static_cast<TH1*>( fdNQData.Spectrum()->Clone() );
00107   // this->ffdPredictionPQ = static_cast<TH1*>( fdPQData.Spectrum()->Clone() );
00108   // ffdPredictionNQ->SetDirectory(0);
00109   // ffdPredictionPQ->SetDirectory(0);
00110   ffdPredictionNQ = new NuMatrixSpectrum(fdNQData);
00111   ffdPredictionPQ = new NuMatrixSpectrum(fdPQData);
00112 }
00113 
00115 
00116 void NuFCGridPoint::PredictSpectrum(Double_t POT)
00117 {
00118   // We want to make an extrapolation of the near detector data
00119   MSG("NuFCGridPoint", Msg::kInfo) << "Generating Extrapolated Near Detector\n"
00120     << "Using Oscillation Parameters sn2bar: " << fmmPars.Sn2Bar()
00121     << ", dm2bar: " << fmmPars.Dm2Bar() << endl;
00122   
00123   // Give blank prediction spectra, as we won't be checking the far data
00124   NuMatrixSpectrum blankpot(POT);
00125   // Make the extrapolator
00126   NuMMRunFC mmFakeFar(&fHelper, &fndNQ, &fndPQ, &blankpot, &blankpot);
00127   mmFakeFar.QuietModeOn();
00128   
00129   // Now, grab the extrapolations, and pretend they are far detector data
00130   pair<NuMatrixSpectrum,NuMatrixSpectrum> fakefar = mmFakeFar.MakeFDPred(fmmPars);
00131 
00132   // Tell the user what POT we got out
00133   MSG("NuFCGridPoint", Msg::kInfo) << "Far extrapolation is at POT "
00134     << fakefar.second.PoT() << " (" << fakefar.second.Spectrum()->Integral()
00135     << " events)" << endl;
00136 
00137   // Grab a copy of these Spectra
00138   // ffdPredictionNQ = static_cast<TH1*>( fakefar.first.Spectrum()->Clone() );
00139   // ffdPredictionPQ = static_cast<TH1*>( fakefar.second.Spectrum()->Clone() );
00140   ffdPredictionNQ = new NuMatrixSpectrum(fakefar.first);
00141   ffdPredictionPQ = new NuMatrixSpectrum(fakefar.second);
00142 }
00143 
00145 
00146 void NuFCGridPoint::SetRandom(TRandom3 *ranGen)
00147 {
00148   // Reassign our random number generator, deleting if needed
00149   if (fRandy) delete fRandy;
00150   fRandy = ranGen;
00151 }
00152 
00154 
00155 void NuFCGridPoint::SetSeed(UInt_t seed)
00156 {
00157   fRandy->SetSeed(seed);
00158 }
00159 
00161 
00162 const NuMatrixSpectrum &NuFCGridPoint::GetBarSpectrum()
00163 {
00164   if (!ffdPredictionPQ) {
00165     // We are backed into a corner... throw an exception as this is
00166     // a better alternative than a segfault!
00167     ostringstream err;
00168     err << "NuFCGridPoint::GetBarSpectrum(): Asking for reference to prediction\n"
00169         << "    before it is calculated. Try calling NuFCGridPoint::PredictSpectrum\n"
00170         << "    or NuFCGridPoint::UsePrediction first.";
00171     throw runtime_error(err.str().c_str());
00172   }
00173    return *ffdPredictionPQ;
00174 }
00175 
00176 const NuMatrixSpectrum &NuFCGridPoint::GetNuSpectrum()
00177 {
00178   if (!ffdPredictionPQ) {
00179     // Also backed into a corner here. Nothing left but an exception!
00180     ostringstream err;
00181     err << "NuFCGridPoint::GetNuSpectrum(): Asking for reference to prediction\n"
00182         << "    before it is calculated. Try calling NuFCGridPoint::PredictSpectrum\n"
00183         << "    or NuFCGridPoint::UsePrediction first.";
00184     throw runtime_error(err.str().c_str());
00185   }
00186   
00187   return *ffdPredictionPQ;
00188 }
00189 
00191 
00192 void NuFCGridPoint::Run(UInt_t number)
00193 {
00194   for (UInt_t i = 0; i < number; i++)
00195   {
00196     // Say we are starting!
00197     MSG("NuFCGridPoint", Msg::kInfo) << "Running experiment " << i << endl;
00198     
00199     // Create a new experiment
00200     // NuFCExperiment fcexp(i, *ffdPredictionPQ, fRandy);
00201 
00202     // Make a blank extrapolator for predictions
00203     NuMatrixSpectrum blankpot(ffdPredictionPQ->PoT());
00204     NuMMRunFC extrapolator(&fHelper, &fndNQ, &fndPQ, &blankpot, &blankpot);
00205     extrapolator.QuietModeOn();
00206 
00207     // Generte the fake experiment
00208     fExperimentFactory->GenerateNewExperiment(&extrapolator, fmmPars);
00209     NuFCExperiment fcexp(i, fExperimentFactory->GetNQSpectrum(), fExperimentFactory->GetPQSpectrum());
00210     
00211     // Grab the (possibly shifted) near detector histograms
00212     NuMatrixSpectrum ndNQ = fExperimentFactory->GetNQSpectrumND();
00213     NuMatrixSpectrum ndPQ = fExperimentFactory->GetPQSpectrumND();
00214     
00215     // Create the fitter
00216     NuFCFitter fitter(&fcexp, &fHelper, &ndNQ, &ndPQ, fmmPars);
00217     
00218     // Do we want to archive every fit?
00219     if (fArchive) fitter.AlwaysArchive(fArchiveFilename);
00220     else fitter.ArchiveTo(fArchiveFilename);
00221     
00222     // Run the fit
00223     Double_t fitDeltachi = fitter.Fit(fmmPars);
00224     
00225     // Store the delta chi2
00226     fdeltaChi2.push_back(fitDeltachi);
00227   }
00228 }
00229 
00230 void NuFCGridPoint::SetPars(const NuMMParameters &pars)
00231 {
00232     fmmPars = pars;    
00233 }

Generated on Mon Feb 15 11:07:13 2010 for loon by  doxygen 1.3.9.1