00001 #include <string>
00002 #include <sstream>
00003 #include <vector>
00004 #include <map>
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
00043
00044 fmmPars.Dm2(2.43e-3);
00045 fmmPars.Sn2(1.0);
00046
00047
00048 fmmPars.Dm2Bar(fdm2);
00049 fmmPars.Sn2Bar(fsin2);
00050
00051 fmmPars.FixNorm();
00052 fmmPars.FixShwScale();
00053 fmmPars.FixNCBackground();
00054 fmmPars.FixDm2();
00055 fmmPars.FixSn2();
00056
00057
00058 fRandy = new TRandom3(0);
00059
00060
00061 NuFCConfig &cfg = NuFCConfig::GetConfig();
00062
00063
00064
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
00071 if (cfg.Systematics() == false) fExperimentFactory->NoSystematics();
00072
00073
00074 if (cfg.FixedSin()) {
00075 fmmPars.FixSn2Bar();
00076 }
00077 }
00078
00080
00081 NuFCGridPoint::~NuFCGridPoint()
00082 {
00083
00084 if (ffdPredictionNQ) delete ffdPredictionNQ;
00085 if (ffdPredictionPQ) delete ffdPredictionPQ;
00086 ffdPredictionNQ = ffdPredictionPQ = 0;
00087
00088
00089
00090
00091
00092
00093 }
00094
00096
00097
00098 void NuFCGridPoint::UsePrediction(const NuMatrixSpectrum &fdNQData,
00099 const NuMatrixSpectrum &fdPQData)
00100 {
00101
00102 if (ffdPredictionNQ) delete ffdPredictionNQ;
00103 if (ffdPredictionPQ) delete ffdPredictionPQ;
00104
00105
00106
00107
00108
00109
00110 ffdPredictionNQ = new NuMatrixSpectrum(fdNQData);
00111 ffdPredictionPQ = new NuMatrixSpectrum(fdPQData);
00112 }
00113
00115
00116 void NuFCGridPoint::PredictSpectrum(Double_t POT)
00117 {
00118
00119 MSG("NuFCGridPoint", Msg::kInfo) << "Generating Extrapolated Near Detector\n"
00120 << "Using Oscillation Parameters sn2bar: " << fmmPars.Sn2Bar()
00121 << ", dm2bar: " << fmmPars.Dm2Bar() << endl;
00122
00123
00124 NuMatrixSpectrum blankpot(POT);
00125
00126 NuMMRunFC mmFakeFar(&fHelper, &fndNQ, &fndPQ, &blankpot, &blankpot);
00127 mmFakeFar.QuietModeOn();
00128
00129
00130 pair<NuMatrixSpectrum,NuMatrixSpectrum> fakefar = mmFakeFar.MakeFDPred(fmmPars);
00131
00132
00133 MSG("NuFCGridPoint", Msg::kInfo) << "Far extrapolation is at POT "
00134 << fakefar.second.PoT() << " (" << fakefar.second.Spectrum()->Integral()
00135 << " events)" << endl;
00136
00137
00138
00139
00140 ffdPredictionNQ = new NuMatrixSpectrum(fakefar.first);
00141 ffdPredictionPQ = new NuMatrixSpectrum(fakefar.second);
00142 }
00143
00145
00146 void NuFCGridPoint::SetRandom(TRandom3 *ranGen)
00147 {
00148
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
00166
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
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
00197 MSG("NuFCGridPoint", Msg::kInfo) << "Running experiment " << i << endl;
00198
00199
00200
00201
00202
00203 NuMatrixSpectrum blankpot(ffdPredictionPQ->PoT());
00204 NuMMRunFC extrapolator(&fHelper, &fndNQ, &fndPQ, &blankpot, &blankpot);
00205 extrapolator.QuietModeOn();
00206
00207
00208 fExperimentFactory->GenerateNewExperiment(&extrapolator, fmmPars);
00209 NuFCExperiment fcexp(i, fExperimentFactory->GetNQSpectrum(), fExperimentFactory->GetPQSpectrum());
00210
00211
00212 NuMatrixSpectrum ndNQ = fExperimentFactory->GetNQSpectrumND();
00213 NuMatrixSpectrum ndPQ = fExperimentFactory->GetPQSpectrumND();
00214
00215
00216 NuFCFitter fitter(&fcexp, &fHelper, &ndNQ, &ndPQ, fmmPars);
00217
00218
00219 if (fArchive) fitter.AlwaysArchive(fArchiveFilename);
00220 else fitter.ArchiveTo(fArchiveFilename);
00221
00222
00223 Double_t fitDeltachi = fitter.Fit(fmmPars);
00224
00225
00226 fdeltaChi2.push_back(fitDeltachi);
00227 }
00228 }
00229
00230 void NuFCGridPoint::SetPars(const NuMMParameters &pars)
00231 {
00232 fmmPars = pars;
00233 }