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

NuMatrixMethod.cxx

Go to the documentation of this file.
00001 
00002 // $Id: NuMatrixMethod.cxx,v 1.33 2009/10/01 18:56:09 bckhouse Exp $
00003 //
00004 // Performs the Matrix Method extrapolation.
00005 //
00006 // Justin Evans
00007 // j.evans2@physics.ox.ac.uk
00008 // Adapted from code by Chris Smith
00009 //
00010 // $Log: NuMatrixMethod.cxx,v $
00011 // Revision 1.33  2009/10/01 18:56:09  bckhouse
00012 // Centralize calculation of oscillation functions into NuUtilities: function OscillationWeight, DecayWeight, DecoherenceWeight.
00013 //
00014 // Revision 1.32  2008/04/14 15:39:06  evans
00015 // Making the optimised compilier happier by removing unitialised
00016 // variable possibilities.
00017 //
00018 // Revision 1.31  2008/03/06 14:51:40  evans
00019 // Making the way the (tiny) numubar background is handled more explicit.
00020 //
00021 // Revision 1.30  2008/02/29 12:01:26  evans
00022 // Putting an 'if' in so the tau code is only run for the PRL-style
00023 // analysis. No it shouldn't crash Alex's code.
00024 //
00025 // Revision 1.29  2008/02/28 12:30:39  evans
00026 // Adding an underscore to a variable name.
00027 //
00028 // Revision 1.28  2008/02/28 11:52:55  evans
00029 // A fix to the tau cross section correction function: it now uses tau
00030 // cross sections.
00031 //
00032 // Revision 1.27  2008/02/28 02:28:59  ahimmel
00033 //
00034 //
00035 // Fixed a bug in the Transition methods.  Oops.  Problem solved.
00036 //
00037 // Revision 1.26  2008/02/28 01:24:31  ahimmel
00038 //
00039 //
00040 // Fixing (hopefully) the bias problem for the Transition analysis.  The problem was that the NuMu efficiency was not being divided off when making the PotentialApperanceFlux.  The SetFDAppearedFidFlux and GetFDPotentialAppearanceFidFlux have been overhauled so that their actions are now clear.  They are also now nearly identical to one another (as they should be) which the only differences being the sources of the initial histogram value and whether cross section and efficency are multiplied or divided.
00041 //
00042 // Revision 1.25  2008/02/26 14:36:46  evans
00043 // The PRL fitter now includes CC tau neutrinos in its FD prediction. It
00044 // inverse-oscillates the numus, corrects their cross sections to be
00045 // those for nutaus, corrects for nutau reconstruction and selection
00046 // efficiencies, puts them through a nutau true->reco matrix, and adds
00047 // them into the predictions. It's all very reminiscent of the nubar
00048 // appearance analysis.
00049 //
00050 // Revision 1.24  2008/02/25 13:09:47  evans
00051 // Pulling in the tau neutrino cross sections.
00052 //
00053 // Revision 1.23  2008/02/20 16:07:33  evans
00054 // The histogram binning is now configured from the .xml files.
00055 //
00056 // Revision 1.22  2008/02/12 14:40:32  evans
00057 // Correcting the decoherence function.
00058 //
00059 // Revision 1.21  2008/02/12 10:00:34  evans
00060 // Adding alternative disappearance models, controled with a new argument
00061 // in the NuMatrixFitter fitter functions (defaults to oscillations so
00062 // existing scripts will still work).
00063 //
00064 // Revision 1.20  2008/02/08 16:10:19  evans
00065 // Memory management fixes to ensure no seg faults for any analyses.
00066 //
00067 // Revision 1.19  2008/01/24 19:29:30  ahimmel
00068 //
00069 // Committing some small changes that got overlooked.  Changed NuMatrixInput so it inherits from TObject and can be stored in files.  Updated the fitters so they look for an already existing NuMatrixInput before generating one based on the file.  Fixed some kFatal messages in NuMatrixMethod.cxx.
00070 //
00071 // Revision 1.18  2008/01/20 01:08:19  evans
00072 // A new setting to perform the PRL-style CC analysis.
00073 //
00074 // Revision 1.17  2008/01/18 07:42:15  evans
00075 // Lots of bug fixes to get the no charge cut CC fit working.
00076 //
00077 // Revision 1.16  2008/01/17 01:24:26  evans
00078 // Object can now have a NuXMLConfig passed into its constructor. If it
00079 // does, then it does an online systematic shift to the cross section
00080 // file it's been passed.
00081 //
00082 // Revision 1.15  2008/01/11 20:17:16  evans
00083 // Changing TH1D::Clear() to TH1D::Reset().
00084 //
00085 // Revision 1.14  2008/01/09 01:01:19  evans
00086 // New functions to perform the modularised no-charge-cut CC analysis in
00087 // the way the modularised CPT analysis with fixed dm2,sn2 works, to
00088 // allow systematics studies to be performed on the no-charge-cut CC
00089 // analysis with the existing mechanism.
00090 //
00091 // Revision 1.13  2008/01/05 23:59:07  ahimmel
00092 //
00093 //
00094 // - Added a function WriteInputForFitter to write a NuMatrixInput file with the results of the extrapolation.  This writes the same information that is in the WriteFileForFitter but in a different format.
00095 //
00096 // - Added an fextrpScheme variable so the object keeps track of what extrapolation scheme it is using.
00097 //
00098 // Revision 1.12  2007/12/24 11:51:02  evans
00099 // Adding a modular fitter for the numu->numubar transition analysis. The
00100 // interface is identical to the CPT version. This has required some
00101 // additions to the NuMatrixOutput class (holding an extra histogram and
00102 // a best fit transition probability), so the ClassDef has been
00103 // incremented. But only additions have been made: no data members have
00104 // been removed.
00105 //
00106 // Revision 1.11  2007/12/12 10:06:57  evans
00107 // Allowing the cross section stage to be switched off (for a combined
00108 // numu+numubar extrapolation in which the cross sections are included in
00109 // the beam matrix).
00110 //
00111 // Revision 1.10  2007/12/05 12:31:33  evans
00112 // Updating the numu->numubar transition analysis so that no oscillation
00113 // parameters are required until the final modular fit stage.
00114 //
00115 // Revision 1.9  2007/11/30 16:40:08  evans
00116 // Adding code to nu a numu->numubar appearance analysis with the matrix
00117 // method.
00118 //
00119 // Revision 1.8  2007/11/20 12:41:18  evans
00120 // Debugging the modular MM fitter.
00121 //
00122 // Revision 1.7  2007/11/19 16:27:43  evans
00123 // Writing a function to do a nubar CPT modular MM fit for systematics
00124 // studies.
00125 //
00126 // Revision 1.6  2007/11/06 18:34:38  hartnell
00127 //
00128 // Modified by Justin and I to output the set of files needed for an
00129 // external fitter to fit for dm2bar, etc.
00130 //
00131 // Revision 1.5  2007/09/12 14:39:42  evans
00132 // The extrapolation and fitting is now working (likelihood fit only: I
00133 // need to rebin the histograms before a chi2 fit will work). The code
00134 // can either do the standard CC analysis's extrapolation, or a CPT fit.
00135 //
00136 // Revision 1.4  2007/09/11 17:08:17  evans
00137 // Bug fixes. Mainly memory management in CombineMMHelpers.C. Also a problem
00138 // with units in the oscillation formulae in NuMatrixMethod. Got rid of unused
00139 // parameters in NuMatrixFitter.
00140 //
00141 // Revision 1.3  2007/09/11 13:43:01  evans
00142 // Made more extrapolation parameters configurable. Ensured the correct cross-
00143 // sections are picked up for each neutrino type. Other minor bug fixes.
00144 //
00145 // Revision 1.2  2007/09/06 12:19:30  evans
00146 // Matrix extrapolation updated to include a CPT antineutrino extrapolation.
00147 //
00148 // NuMatrixMethod extrapolates one ND data spectrum to the FD. NuMatrixFitter
00149 // is a wrapper that creates as many NuMatrixMethod objects as necessary to
00150 // extrapolate the required individual fluxes (e.g. numus and nubars
00151 // independently). So far two CPT analysis methods are implemented: one
00152 // performs the standard CC extrapolation on the numus and numubars separately
00153 // with extra stages in the FD to oscillate the CC background. The other uses
00154 // the CC numu extrapolation to calculate the CC numu background to the CC
00155 // numubar prediction, and vice-versa.
00156 //
00157 // The code still requires testing.
00158 //
00159 // Revision 1.1  2007/09/04 14:45:58  evans
00160 // Begun porting the matrix method extrapolation code into NtupleUtils.
00161 //
00162 // NuMatrixMethod is the new class that does the extrapolation.
00163 // RunMMPrediction.C is an example of how to run it.
00164 //
00165 // At present, the code only runs the standard CC extrapolation on neutrinos.
00166 //
00167 //
00169 
00170 #include "TArrayD.h"
00171 #include "TFile.h"
00172 #include "TGraph.h"
00173 #include "TH1D.h"
00174 #include "TH2D.h"
00175 #include "TMath.h"
00176 
00177 #include "Conventions/Munits.h"
00178 #include "MessageService/MsgService.h"
00179 #include "NtupleUtils/NuMatrixInput.h"
00180 #include "NtupleUtils/NuMatrixMethod.h"
00181 #include "NtupleUtils/NuSystematic.h"
00182 #include "NtupleUtils/NuXMLConfig.h"
00183 
00184 using std::string;
00185 using namespace NuMMExtrapolation;
00186 
00187 ClassImp(NuMatrixMethod)
00188 
00189 CVSID("$Id: NuMatrixMethod.cxx,v 1.33 2009/10/01 18:56:09 bckhouse Exp $");
00190 
00191 //____________________________________________________________________72
00192 NuMatrixMethod::NuMatrixMethod()
00193   : fDoXSecStep(true),
00194     fNDPoT(1.0),
00195     fFDPoT(1.0),
00196     fFluxPoT(1.0),
00197     fNDFidMass(1.0),
00198     fFDFidMass(1.0),
00199     fFDDistance(735.0*Munits::km)
00200 {
00201   fxmlConfig = 0;
00202   
00203   const NuUtilities utils;
00204   const vector<Double_t> recoBins = utils.RecoBins(NuBinningScheme::kUnknown);
00205   fNRecoBins = recoBins.size()-1;
00206   fRecoBinEdges = new Double_t[fNRecoBins+1];
00207   {
00208     Int_t i=0;
00209     for (vector<Double_t>::const_iterator itBin = recoBins.begin();
00210          itBin != recoBins.end();
00211          ++itBin, ++i){
00212       fRecoBinEdges[i] = *itBin;
00213     }
00214   }
00215   
00216   const vector<Double_t> trueBins = utils.TrueBins(NuBinningScheme::kUnknown);
00217   fNTrueBins = trueBins.size()-1;
00218   fTrueBinEdges = new Double_t[fNTrueBins+1];
00219   {
00220     Int_t i=0;
00221     for (vector<Double_t>::const_iterator itBin = trueBins.begin();
00222          itBin != trueBins.end();
00223          ++itBin, ++i){
00224       fTrueBinEdges[i] = *itBin;
00225     }
00226   }
00227 
00228   fRecoEnergyPurCor_ND = new
00229     TH1D("RecoEnergyPurCor_ND",
00230          "ND Reconstructed Energy After Purity Correction",
00231          fNRecoBins,fRecoBinEdges);
00232   fTrueEnergyPurCor_ND = new
00233     TH1D("TrueEnergyPurCor_ND",
00234          "ND True Energy After Purity Correction",
00235          fNTrueBins,fTrueBinEdges);
00236   fTrueEnergyEffCor_ND = new
00237     TH1D("TrueEnergyEffCor_ND",
00238          "ND True Energy After Purity & Efficiency Corrections",
00239          fNTrueBins,fTrueBinEdges);
00240   fTrueEnergyFlux_ND = new
00241     TH1D("TrueEnergyFlux_ND",
00242          "ND True Energy After XSec Corrections (flux)",
00243          fNTrueBins,fTrueBinEdges);
00244   fTrueEnergyMatrix_FD = new
00245     TH1D("TrueEnergyMatrix_FD",
00246          "FD True Energy After Matrix Application (flux)",
00247          fNTrueBins,fTrueBinEdges);
00248   fTrueEnergyCC_FD = new
00249     TH1D("TrueEnergyCC_FD",
00250          "FD True CC Energy After XSec Application",
00251          fNTrueBins,fTrueBinEdges);
00252   fTrueEnergyEffCor_FD = new
00253     TH1D("TrueEnergyEffCor_FD",
00254          "FD True Energy After Efficiency Correction",
00255          fNTrueBins,fTrueBinEdges);
00256   //Two special case histos for FD no oscillations:
00257   fRecoEnergyNoOsc_FD = new
00258     TH1D("RecoEnergyNoOsc_FD",
00259          "FD CC Reco Energy Without Oscillations (no background)",
00260          fNRecoBins,fRecoBinEdges);
00261   fRecoEnergyNoOscPred_FD = new
00262     TH1D("RecoEnergyNoOscPred_FD",
00263          "FD Predicted Reco Energy Without Oscillations",
00264          fNRecoBins,fRecoBinEdges);
00265   fRecoUnoscNCBackground_FD=new 
00266     TH1D("UnoscNCBackground_FD",
00267          "Reco energy unoscillated NC background prediction",
00268          fNRecoBins,fRecoBinEdges);
00269   //After the digression:
00270   fTrueEnergyOsc_FD = new
00271     TH1D("TrueEnergyOsc_FD",
00272          "FD True Energy With Oscillations",
00273          fNTrueBins,fTrueBinEdges);
00274   fRecoEnergyOsc_FD = new
00275     TH1D("RecoEnergyOsc_FD",
00276          "FD Reco Energy With Oscillations",
00277          fNRecoBins,fRecoBinEdges);
00278   fRecoEnergyPred_FD = new
00279     TH1D("RecoEnergyPred_FD",
00280          "FD Predicted Reco Energy",
00281          fNRecoBins,fRecoBinEdges);
00282   
00283   fRecoEnergyMeas_ND = 0;
00284   fRecoEnergyMeas_FD = 0;
00285   fEffCorTau_FD = 0;
00286 
00287   fPurity_ND = 0;          
00288   fRecoVsTrueEnergy_ND = 0;
00289   fEfficiency_ND = 0;      
00290   fXSec_CC_Graph = 0;
00291   fTau_XSec_CC_Graph = 0;
00292   fFDVsNDMatrixRW = 0;     
00293   fEfficiency_FD = 0;
00294   fRecoVsTrueEnergy_FD = 0;
00295   fPurity_FD = 0;          
00296   fCCContamination_FD = 0;
00297   fNCContamination_FD = 0;
00298   fRecoToTrueCCContamination_FD = 0;
00299   fTrueToRecoCCContamination_FD = 0;
00300   fSuppliedTrueUnoscCCBackground_FD = 0;
00301   fOtherEfficiency_FD = 0;
00302 
00303   fAppearedTrueEffCor_FD = new
00304     TH1D("AppearedTrueEffCor_FD",
00305          "FD appearance spectrum, true energy, efficiency corrected",
00306          fNTrueBins,fTrueBinEdges);
00307 
00308   fEfficiencyTau_FD = 0;
00309   fRecoVsTrueEnergyTau_FD = 0;
00310 }
00311 
00312 //____________________________________________________________________72
00313 NuMatrixMethod::NuMatrixMethod(const Int_t NbinsX,
00314                                const Double_t LowX,
00315                                const Double_t UppX,
00316                                const Double_t NDPoT,
00317                                const Double_t FDPoT,
00318                                const Double_t FluxPoT,
00319                                const Double_t NDFidMass,
00320                                const Double_t FDFidMass,
00321                                const string helperfilename,
00322                                const string xsecfilename,
00323                                const string NDDatafilename,
00324                                const string outputFileName,
00325                                const NuXMLConfig* xmlConfig)
00326   : fDoXSecStep(true),
00327     fFDDistance(735.0*Munits::km)
00328 {
00329   fxmlConfig = xmlConfig;
00330   fOutName = outputFileName;
00331   fhelperfilename = helperfilename;
00332   fxsecfilename = xsecfilename;
00333   fndDataFilename = NDDatafilename;
00334 
00335   fNRecoBins = NbinsX;
00336   fNTrueBins = NbinsX;
00337   Double_t bwidth = (UppX-LowX)/Double_t(NbinsX);
00338   fRecoBinEdges=new Double_t[fNRecoBins+1];
00339   fTrueBinEdges=new Double_t[fNTrueBins+1];
00340   for(Int_t i=0;i<NbinsX+1;i++){
00341     fRecoBinEdges[i] = LowX + i*bwidth;
00342     fTrueBinEdges[i] = LowX + i*bwidth;
00343   }
00344 
00345   fNDPoT = NDPoT;
00346   fFDPoT = FDPoT;
00347   fFluxPoT = FluxPoT;
00348   fNDFidMass = NDFidMass;
00349   fFDFidMass = FDFidMass;
00350 
00351   fRecoEnergyPurCor_ND = new
00352     TH1D("RecoEnergyPurCor_ND",
00353          "ND Reconstructed Energy After Purity Correction",
00354          fNRecoBins,fRecoBinEdges);
00355   fTrueEnergyPurCor_ND = new
00356     TH1D("TrueEnergyPurCor_ND",
00357          "ND True Energy After Purity Correction",
00358          fNTrueBins,fTrueBinEdges);
00359   fTrueEnergyEffCor_ND = new
00360     TH1D("TrueEnergyEffCor_ND",
00361          "ND True Energy After Purity & Efficiency Corrections",
00362          fNTrueBins,fTrueBinEdges);
00363   fTrueEnergyFlux_ND = new
00364     TH1D("TrueEnergyFlux_ND",
00365          "ND True Energy After XSec Corrections (flux)",
00366          fNTrueBins,fTrueBinEdges);
00367   fTrueEnergyMatrix_FD = new
00368     TH1D("TrueEnergyMatrix_FD",
00369          "FD True Energy After Matrix Application (flux)",
00370          fNTrueBins,fTrueBinEdges);
00371   fTrueEnergyCC_FD = new
00372     TH1D("TrueEnergyCC_FD",
00373          "FD True CC Energy After XSec Application",
00374          fNTrueBins,fTrueBinEdges);
00375   fTrueEnergyEffCor_FD = new
00376     TH1D("TrueEnergyEffCor_FD",
00377          "FD True Energy After Efficiency Correction",
00378          fNTrueBins,fTrueBinEdges);
00379   //Two special case histos for FD no oscillations:
00380   fRecoEnergyNoOsc_FD = new
00381     TH1D("RecoEnergyNoOsc_FD",
00382          "FD CC Reco Energy Without Oscillations (no background)",
00383          fNRecoBins,fRecoBinEdges);
00384   fRecoEnergyNoOscPred_FD = new
00385     TH1D("RecoEnergyNoOscPred_FD",
00386          "FD Predicted Reco Energy Without Oscillations",
00387          fNRecoBins,fRecoBinEdges);
00388   fRecoUnoscNCBackground_FD=new
00389     TH1D("UnoscNCBackground_FD",
00390          "Reco energy unoscillated NC background prediction",
00391          fNRecoBins,fRecoBinEdges);
00392   //After the digression:
00393   fTrueEnergyOsc_FD = new
00394     TH1D("TrueEnergyOsc_FD",
00395          "FD True Energy With Oscillations",
00396          fNTrueBins,fTrueBinEdges);
00397   fRecoEnergyOsc_FD = new
00398     TH1D("RecoEnergyOsc_FD",
00399          "FD Reco Energy With Oscillations",
00400          fNRecoBins,fRecoBinEdges);
00401   fRecoEnergyPred_FD = new
00402     TH1D("RecoEnergyPred_FD",
00403          "FD Predicted Reco Energy",
00404          fNRecoBins,fRecoBinEdges);
00405   fEffCorTau_FD = 0;
00406   /*
00407   //Get cross-sections
00408   TFile *xsecfile = new TFile(xsecfilename.c_str(),"READ");
00409   TH1F* XSec_CC = (TH1F*) xsecfile->Get("h_numu_cc_tot");
00410   XSec_CC->SetDirectory(0);
00411   xsecfile->Close();
00412   if (xsecfile){delete xsecfile; xsecfile = 0;}
00413   Float_t *x = new Float_t[XSec_CC->GetNbinsX()];
00414   Float_t *y = new Float_t[XSec_CC->GetNbinsX()];
00415   for(int i=0;i<XSec_CC->GetNbinsX();i++) {
00416     x[i] = XSec_CC->GetBinCenter(i+1);
00417     y[i] = XSec_CC->GetBinContent(i+1);
00418   }
00419   fXSec_CC_Graph = new TGraph(XSec_CC->GetNbinsX(),x,y);
00420   if (x) {delete[] x; x = 0;}
00421   if (y) {delete[] y; y = 0;}
00422   
00423   //Get the helper histograms:
00424   TFile* helperFile = new TFile(helperfilename.c_str(),"READ");
00425   fRecoVsTrueEnergy_ND = (TH2D*) helperFile->Get("RecoVsTrueEnergy_ND");
00426   fRecoVsTrueEnergy_ND->SetDirectory(0);
00427   fRecoVsTrueEnergy_FD = (TH2D*) helperFile->Get("RecoVsTrueEnergy_FD");
00428   fRecoVsTrueEnergy_FD->SetDirectory(0);
00429   
00430   fFDVsNDMatrixRW = (TH2D*) helperFile->Get("FDVsNDMatrixRW");
00431   if(fFDVsNDMatrixRW) fFDVsNDMatrixRW->SetDirectory(0);
00432   
00433   fEfficiency_ND = (TH1D*) helperFile->Get("Efficiency_ND");
00434   fEfficiency_ND->SetDirectory(0);
00435   fEfficiency_FD = (TH1D*) helperFile->Get("Efficiency_FD");
00436   fEfficiency_FD->SetDirectory(0);
00437   fPurity_ND = (TH1D*) helperFile->Get("Purity_ND");
00438   fPurity_ND->SetDirectory(0);
00439   fPurity_FD = (TH1D*) helperFile->Get("Purity_FD");
00440   fPurity_FD->SetDirectory(0);
00441   */
00442   fCCContamination_FD = 0;
00443   fNCContamination_FD = 0;
00444   fRecoToTrueCCContamination_FD = 0;
00445   fTrueToRecoCCContamination_FD = 0;
00446   fSuppliedTrueUnoscCCBackground_FD = 0;
00447   fOtherEfficiency_FD = 0;
00448 
00449   fAppearedTrueEffCor_FD = new
00450     TH1D("AppearedTrueEffCor_FD",
00451          "FD appearance spectrum, true energy, efficiency corrected",
00452          fNTrueBins,fTrueBinEdges);
00453 
00454   fEfficiencyTau_FD = 0;
00455   fRecoVsTrueEnergyTau_FD = 0;
00456 
00457   /*
00458   helperFile->Close();
00459   if (helperFile) {delete helperFile; helperFile = 0;}
00460 
00461   //Get the data:
00462   TFile* ndDataFile = new TFile(NDDatafilename.c_str(), "READ");
00463   fRecoEnergyMeas_ND = (TH1D*) ndDataFile->Get("RecoEnergy_ND");
00464   fRecoEnergyMeas_ND->SetDirectory(0);
00465   ndDataFile->Close();
00466   if (ndDataFile){delete ndDataFile; ndDataFile = 0;}
00467   */
00468   /*
00469   TFile* fdDataFile = new TFile(FDDatafilename.c_str(), "READ");
00470   fRecoEnergyMeas_FD = (TH1D*) fdDataFile->Get("RecoEnergy_FD");
00471   fRecoEnergyMeas_FD->SetDirectory(0);
00472   fdDataFile->Close();
00473   if (fdDataFile){delete fdDataFile; fdDataFile = 0;}
00474   */
00475 }
00476 
00477 //____________________________________________________________________72
00478 NuMatrixMethod::NuMatrixMethod
00479 (const NuBinningScheme::NuBinningScheme_t binningScheme,
00480  const Double_t NDPoT,
00481  const Double_t FDPoT,
00482  const Double_t FluxPoT,
00483  const Double_t NDFidMass,
00484  const Double_t FDFidMass,
00485  const string helperfilename,
00486  const string xsecfilename,
00487  const string NDDatafilename,
00488  const string outputFileName,
00489  const NuXMLConfig* xmlConfig)
00490   : fDoXSecStep(true),
00491     fFDDistance(735.0*Munits::km)
00492 {
00493   fxmlConfig = xmlConfig;
00494   fOutName = outputFileName;
00495   fhelperfilename = helperfilename;
00496   fxsecfilename = xsecfilename;
00497   fndDataFilename = NDDatafilename;
00498   
00499   const NuUtilities utils;
00500   const vector<Double_t> recoBins = utils.RecoBins(binningScheme);
00501   fNRecoBins = recoBins.size()-1;
00502   fRecoBinEdges = new Double_t[fNRecoBins+1];
00503   {
00504     Int_t i=0;
00505     for (vector<Double_t>::const_iterator itBin = recoBins.begin();
00506          itBin != recoBins.end();
00507          ++itBin, ++i){
00508       fRecoBinEdges[i] = *itBin;
00509     }
00510   }
00511   
00512   const vector<Double_t> trueBins = utils.TrueBins(binningScheme);
00513   fNTrueBins = trueBins.size()-1;
00514   fTrueBinEdges = new Double_t[fNTrueBins+1];
00515   {
00516     Int_t i=0;
00517     for (vector<Double_t>::const_iterator itBin = trueBins.begin();
00518          itBin != trueBins.end();
00519          ++itBin, ++i){
00520       fTrueBinEdges[i] = *itBin;
00521     }
00522   }
00523   
00524   fNDPoT = NDPoT;
00525   fFDPoT = FDPoT;
00526   fFluxPoT = FluxPoT;
00527   fNDFidMass = NDFidMass;
00528   fFDFidMass = FDFidMass;
00529 
00530   fRecoEnergyPurCor_ND = new
00531     TH1D("RecoEnergyPurCor_ND",
00532          "ND Reconstructed Energy After Purity Correction",
00533          fNRecoBins,fRecoBinEdges);
00534   fTrueEnergyPurCor_ND = new
00535     TH1D("TrueEnergyPurCor_ND",
00536          "ND True Energy After Purity Correction",
00537          fNTrueBins,fTrueBinEdges);
00538   fTrueEnergyEffCor_ND = new
00539     TH1D("TrueEnergyEffCor_ND",
00540          "ND True Energy After Purity & Efficiency Corrections",
00541          fNTrueBins,fTrueBinEdges);
00542   fTrueEnergyFlux_ND = new
00543     TH1D("TrueEnergyFlux_ND",
00544          "ND True Energy After XSec Corrections (flux)",
00545          fNTrueBins,fTrueBinEdges);
00546   fTrueEnergyMatrix_FD = new
00547     TH1D("TrueEnergyMatrix_FD",
00548          "FD True Energy After Matrix Application (flux)",
00549          fNTrueBins,fTrueBinEdges);
00550   fTrueEnergyCC_FD = new
00551     TH1D("TrueEnergyCC_FD",
00552          "FD True CC Energy After XSec Application",
00553          fNTrueBins,fTrueBinEdges);
00554   fTrueEnergyEffCor_FD = new
00555     TH1D("TrueEnergyEffCor_FD",
00556          "FD True Energy After Efficiency Correction",
00557          fNTrueBins,fTrueBinEdges);
00558   //Two special case histos for FD no oscillations:
00559   fRecoEnergyNoOsc_FD = new
00560     TH1D("RecoEnergyNoOsc_FD",
00561          "FD CC Reco Energy Without Oscillations (no background)",
00562          fNRecoBins,fRecoBinEdges);
00563   fRecoEnergyNoOscPred_FD = new
00564     TH1D("RecoEnergyNoOscPred_FD",
00565          "FD Predicted Reco Energy Without Oscillations",
00566          fNRecoBins,fRecoBinEdges);
00567   fRecoUnoscNCBackground_FD=new
00568     TH1D("UnoscNCBackground_FD",
00569          "Reco energy unoscillated NC background prediction",
00570          fNRecoBins,fRecoBinEdges);
00571   //After the digression:
00572   fTrueEnergyOsc_FD = new
00573     TH1D("TrueEnergyOsc_FD",
00574          "FD True Energy With Oscillations",
00575          fNTrueBins,fTrueBinEdges);
00576   fRecoEnergyOsc_FD = new
00577     TH1D("RecoEnergyOsc_FD",
00578          "FD Reco Energy With Oscillations",
00579          fNRecoBins,fRecoBinEdges);
00580   fRecoEnergyPred_FD = new
00581     TH1D("RecoEnergyPred_FD",
00582          "FD Predicted Reco Energy",
00583          fNRecoBins,fRecoBinEdges);
00584   fEffCorTau_FD = 0;
00585 
00586   fCCContamination_FD = 0;
00587   fNCContamination_FD = 0;
00588   fRecoToTrueCCContamination_FD = 0;
00589   fTrueToRecoCCContamination_FD = 0;
00590   fSuppliedTrueUnoscCCBackground_FD = 0;
00591   fOtherEfficiency_FD = 0;
00592 
00593   fAppearedTrueEffCor_FD = new
00594     TH1D("AppearedTrueEffCor_FD",
00595          "FD appearance spectrum, true energy, efficiency corrected",
00596          fNTrueBins,fTrueBinEdges);
00597 
00598   fEfficiencyTau_FD = 0;
00599   fRecoVsTrueEnergyTau_FD = 0;
00600 }
00601 
00602 //____________________________________________________________________72
00603 NuMatrixMethod
00604 ::NuMatrixMethod(const NuMatrixInput& mmInput,
00605                  const NuMMExtrapolation::NuMMScheme_t extrpScheme)
00606   : fDoXSecStep(true),
00607     fFDDistance(735.0*Munits::km)
00608 {
00609   fxmlConfig = 0;//Shouldn't need this for FD only steps.
00610   if (NuMMExtrapolation::kModularNuMuCPTFit == extrpScheme){
00611     //M numu(bar)
00612     fRecoVsTrueEnergy_FD = new
00613       TH2D(*mmInput.NuMuTrueToRecoFD());
00614     //M-squigle numu(bar) for WS
00615     fTrueToRecoCCContamination_FD = new
00616       TH2D(*mmInput.NuMuTrueToRecoCCBkgFD());
00617     //T
00618     fTrueEnergyEffCor_FD = new
00619       TH1D(*mmInput.NuMuTrueEnFD());
00620     //K
00621     fSuppliedTrueUnoscCCBackground_FD = new
00622       TH1D(*mmInput.NuMuTrueEnCCBkgFD());
00623     //Z
00624     fRecoUnoscNCBackground_FD = new
00625       TH1D(*mmInput.NuMuRecoEnNCBkgFD());
00626     //numubar->numu appearance spectrum
00627     fAppearedTrueEffCor_FD = new
00628       TH1D(*mmInput.NuMuTrueEnPotentialAppearanceEffCorFD());
00629   }
00630   else if (NuMMExtrapolation::kModularNuMuBarCPTFit == extrpScheme){
00631     //M numu(bar)
00632     fRecoVsTrueEnergy_FD = new
00633       TH2D(*mmInput.NuMuBarTrueToRecoFD());
00634     //M-squigle numu(bar) for WS
00635     fTrueToRecoCCContamination_FD = new
00636       TH2D(*mmInput.NuMuBarTrueToRecoCCBkgFD());
00637     //T
00638     fTrueEnergyEffCor_FD = new
00639       TH1D(*mmInput.NuMuBarTrueEnFD());
00640     //K
00641     fSuppliedTrueUnoscCCBackground_FD = new
00642       TH1D(*mmInput.NuMuBarTrueEnCCBkgFD());
00643     //Z
00644     fRecoUnoscNCBackground_FD = new
00645       TH1D(*mmInput.NuMuBarRecoEnNCBkgFD());
00646     //numu->numubar appearance spectrum
00647     fAppearedTrueEffCor_FD = new
00648       TH1D(*mmInput.NuMuBarTrueEnPotentialAppearanceEffCorFD());
00649   }
00650   else if (NuMMExtrapolation::kModularNuMuBarTransitionFit == extrpScheme){
00651     //M numu(bar)
00652     fRecoVsTrueEnergy_FD = new
00653       TH2D(*mmInput.NuMuBarTrueToRecoFD());
00654     //M-squigle numu(bar) for WS
00655     fTrueToRecoCCContamination_FD = new
00656       TH2D(*mmInput.NuMuBarTrueToRecoCCBkgFD());
00657     //T
00658     fTrueEnergyEffCor_FD = new
00659       TH1D(*mmInput.NuMuBarTrueEnFD());
00660     //K
00661     fSuppliedTrueUnoscCCBackground_FD = new
00662       TH1D(*mmInput.NuMuBarTrueEnCCBkgFD());
00663     //Z
00664     fRecoUnoscNCBackground_FD = new
00665       TH1D(*mmInput.NuMuBarRecoEnNCBkgFD());
00666     //numu->numubar appearance spectrum
00667     fAppearedTrueEffCor_FD = new
00668       TH1D(*mmInput.NuMuBarTrueEnPotentialAppearanceEffCorFD());
00669   }
00670   else if (NuMMExtrapolation::kModularNoChargeCutFit == extrpScheme){
00671     //M numu(bar)
00672     fRecoVsTrueEnergy_FD = new
00673       TH2D(*mmInput.NoChargeCutTrueToRecoFD());
00674 //     //M-squigle numu(bar) for WS
00675 //     fTrueToRecoCCContamination_FD = new
00676 //       TH2D(*mmInput.NoChargeCutTrueToRecoCCBkgFD());
00677     //T
00678     fTrueEnergyEffCor_FD = new
00679       TH1D(*mmInput.NoChargeCutTrueEnFD());
00680 //     //K
00681 //     fSuppliedTrueUnoscCCBackground_FD = new
00682 //       TH1D(*mmInput.NoChargeCutTrueEnCCBkgFD());
00683     //Z
00684     fRecoUnoscNCBackground_FD = new
00685       TH1D(*mmInput.NoChargeCutRecoEnNCBkgFD());
00686     //numu->numubar appearance spectrum
00687 //     fAppearedTrueEffCor_FD = new
00688 //       TH1D(*mmInput.NuMuBarTrueEnPotentialAppearanceEffCorFD());
00689     fAppearedTrueEffCor_FD = 0;
00690   }
00691   else if (NuMMExtrapolation::kModularPRLCCFit == extrpScheme){
00692     //M numu(bar)
00693     fRecoVsTrueEnergy_FD = new
00694       TH2D(*mmInput.NuMuTrueToRecoFD());
00695     //T
00696     fTrueEnergyEffCor_FD = new
00697       TH1D(*mmInput.NuMuTrueEnFD());
00698     //Z
00699     fRecoUnoscNCBackground_FD = new
00700       TH1D(*mmInput.NuMuRecoEnNCBkgFD());
00701     fAppearedTrueEffCor_FD = 0;
00702     fEffCorTau_FD = new
00703       TH1D(*mmInput.NuMuEffCorTaus_FD());
00704     fRecoVsTrueEnergyTau_FD = new
00705       TH2D(*mmInput.NuMuRecoVsTrueTaus_FD());
00706   }
00707   else{
00708     try {
00709       MSG("NuMatrixMethod.cxx", Msg::kFatal) 
00710         << "Not a valid extrapolation scheme for a modular "
00711         << "UK matrix method fit"
00712         << endl;
00713     }
00714     catch(MSGException) {
00715       MSG("NuMatrixMethod.cxx", Msg::kError)
00716         << "Not a valid extrapolation scheme for a modular "
00717         << "UK matrix method fit"
00718         << endl;
00719     }
00720     
00721     
00722   }
00723   //Create the other histograms we need, using existing ones to get binning
00724   fTrueEnergyOsc_FD = new TH1D(*fTrueEnergyEffCor_FD);
00725   fTrueEnergyOsc_FD->Reset();
00726   
00727   fRecoEnergyOsc_FD = new TH1D(*fRecoUnoscNCBackground_FD);
00728   fRecoEnergyOsc_FD->Reset();
00729   
00730   fRecoEnergyPred_FD = new TH1D(*fRecoUnoscNCBackground_FD);
00731   fRecoEnergyPred_FD->Reset();
00732 
00733   fNRecoBins = fRecoEnergyPred_FD->GetNbinsX();
00734   const TArrayD* recoBinEdges = fRecoEnergyPred_FD->GetXaxis()->GetXbins();
00735   fRecoBinEdges = new Double_t[recoBinEdges->GetSize()];
00736   for (Int_t i=0; i<recoBinEdges->GetSize(); ++i){
00737     fRecoBinEdges[i] = recoBinEdges->At(i);
00738   }
00739 
00740   fNTrueBins = fTrueEnergyEffCor_FD->GetNbinsX();
00741   const TArrayD* trueBinEdges = fTrueEnergyEffCor_FD->GetXaxis()->GetXbins();
00742   fTrueBinEdges = new Double_t[trueBinEdges->GetSize()];
00743   for (Int_t i=0; i<trueBinEdges->GetSize(); ++i){
00744     fTrueBinEdges[i] = trueBinEdges->At(i);
00745   }
00746 
00747   fOutName = "";
00748   
00749   fextrpScheme = extrpScheme;
00750 
00751   fEfficiencyTau_FD = 0;
00752   //  fRecoVsTrueEnergyTau_FD = 0;
00753 
00754   //Zero all the histograms we don't need.
00755   fRecoEnergyMeas_ND = 0;  
00756   fRecoEnergyMeas_FD = 0;  
00757   fPurity_ND = 0;          
00758   fRecoVsTrueEnergy_ND = 0;
00759   fEfficiency_ND = 0;      
00760   fXSec_CC_Graph = 0;
00761   fTau_XSec_CC_Graph = 0;
00762   fFDVsNDMatrixRW = 0;     
00763   fEfficiency_FD = 0;
00764   fPurity_FD = 0;
00765   fCCContamination_FD = 0;
00766   fNCContamination_FD = 0;
00767   fRecoToTrueCCContamination_FD = 0;
00768   fOtherEfficiency_FD = 0;
00769   fRecoEnergyPurCor_ND = 0;
00770   fTrueEnergyPurCor_ND = 0;
00771   fTrueEnergyEffCor_ND = 0;
00772   fTrueEnergyFlux_ND = 0;
00773   fTrueEnergyMatrix_FD = 0;
00774   fTrueEnergyCC_FD = 0;
00775   fRecoEnergyNoOsc_FD = 0;
00776   fRecoEnergyNoOscPred_FD = 0;
00777 }
00778 
00779 //____________________________________________________________________72
00780 NuMatrixMethod::~NuMatrixMethod()
00781 {
00782   if (""!=fOutName){
00783     TFile *sfile = new TFile(fOutName.c_str(),"UPDATE");
00784     sfile->cd();
00785     fRecoEnergyPurCor_ND->Write();
00786     fTrueEnergyPurCor_ND->Write();
00787     fTrueEnergyEffCor_ND->Write();
00788     fTrueEnergyFlux_ND->Write();
00789     fTrueEnergyMatrix_FD->Write();
00790     fTrueEnergyCC_FD->Write();
00791     fTrueEnergyEffCor_FD->Write();
00792     fTrueEnergyOsc_FD->Write();
00793     fRecoEnergyOsc_FD->Write();
00794     fRecoEnergyPred_FD->Write();  
00795     fRecoEnergyNoOsc_FD->Write();
00796     fRecoEnergyNoOscPred_FD->Write();
00797     
00798     fRecoEnergyMeas_ND->Write("NDData");
00799     // fRecoEnergyMeas_FD->Write("FDData");
00800     
00801     sfile->Close();
00802   }
00803 
00804   if (fRecoEnergyPurCor_ND){
00805     delete fRecoEnergyPurCor_ND;
00806     fRecoEnergyPurCor_ND = 0;
00807   }
00808   if (fTrueEnergyPurCor_ND){
00809     delete fTrueEnergyPurCor_ND;
00810     fTrueEnergyPurCor_ND = 0;
00811   }
00812   if (fTrueEnergyEffCor_ND){
00813     delete fTrueEnergyEffCor_ND;
00814     fTrueEnergyEffCor_ND = 0;
00815   }
00816   if (fTrueEnergyFlux_ND){
00817     delete fTrueEnergyFlux_ND;
00818     fTrueEnergyFlux_ND = 0;
00819   }
00820   if (fTrueEnergyMatrix_FD){
00821     delete fTrueEnergyMatrix_FD;
00822     fTrueEnergyMatrix_FD = 0;
00823   }
00824   if (fTrueEnergyCC_FD){
00825     delete fTrueEnergyCC_FD;
00826     fTrueEnergyCC_FD = 0;
00827   }
00828   if (fTrueEnergyEffCor_FD){
00829     delete fTrueEnergyEffCor_FD;
00830     fTrueEnergyEffCor_FD = 0;
00831   }
00832   if (fRecoEnergyNoOsc_FD){
00833     delete fRecoEnergyNoOsc_FD;
00834     fRecoEnergyNoOsc_FD = 0;
00835   }
00836   if (fRecoEnergyNoOscPred_FD){
00837     delete fRecoEnergyNoOscPred_FD;
00838     fRecoEnergyNoOscPred_FD = 0;
00839   }
00840   if (fEffCorTau_FD){
00841     delete fEffCorTau_FD;
00842     fEffCorTau_FD = 0;
00843   }
00844 }
00845 
00846 //____________________________________________________________________72
00847 
00848 void NuMatrixMethod::WriteFilesForFitter(std::string sPrefix)
00849 {
00851   
00852   //helper files
00853   //M numu(bar)
00854   fRecoVsTrueEnergy_FD->
00855     Write((sPrefix+"TrueToRecoFD").c_str());
00856   //M-squigle numu(bar) for WS
00857   if (fTrueToRecoCCContamination_FD){
00858     fTrueToRecoCCContamination_FD->
00859       Write((sPrefix+"TrueToRecoCCBkgFD").c_str());
00860   }
00861   
00862   //data or mock data
00863   //T
00864   fTrueEnergyEffCor_FD->
00865   Write((sPrefix+"TrueEnFD").c_str());
00866   //K
00867   if (fSuppliedTrueUnoscCCBackground_FD){
00868     fSuppliedTrueUnoscCCBackground_FD->
00869       Write((sPrefix+"TrueEnCCBkgFD").c_str());
00870   }
00871   //Z
00872   if (fRecoVsTrueEnergy_FD){
00873     fRecoUnoscNCBackground_FD->
00874       Write((sPrefix+"RecoEnNCBkgFD").c_str());
00875   }
00876 
00877   //Appeared spectrum for numu->nubar analysis, efficiency corrected
00878   if (fAppearedTrueEffCor_FD){
00879     fAppearedTrueEffCor_FD->
00880       Write((sPrefix+"TrueEnPotentialAppearanceEffCor").c_str());
00881   }
00882 
00883   //Potential taus (efficiency corrected)
00884   if (fEffCorTau_FD){
00885     fEffCorTau_FD->Write((sPrefix+"EffCorTau_FD").c_str());
00886   }
00887   //Tau reco v. true energy matrix
00888   if (fRecoVsTrueEnergyTau_FD){
00889     fRecoVsTrueEnergyTau_FD->Write((sPrefix+"RecoVsTrueEnergyTau_FD").c_str());
00890   }
00891 }
00892 
00893 //____________________________________________________________________72
00894 
00895 void NuMatrixMethod::WriteInputForFitter(NuMatrixInput *mmInput)
00896 {
00897   bool charge = false;
00898   if (NuMMExtrapolation::kCCNuMuNoOscBackground == fextrpScheme ||
00899       NuMMExtrapolation::kCCNuMuOscBackgroundUncombined == fextrpScheme ||
00900       NuMMExtrapolation::kCCNuMuOscBackgroundCombined == fextrpScheme   ||
00901       NuMMExtrapolation::kModularNuMuCPTFit == fextrpScheme
00902       )
00903     charge = true;
00904   else if (NuMMExtrapolation::kCCNuMuBarOscBackgroundUncombined == fextrpScheme ||
00905            NuMMExtrapolation::kCCNuMuBarOscBackgroundCombined == fextrpScheme ||
00906            NuMMExtrapolation::kModularNuMuBarCPTFit == fextrpScheme ||
00907            NuMMExtrapolation::kModularNuMuBarTransitionFit == fextrpScheme
00908            )
00909     charge = false;
00910   else{
00911     try {
00912       MSG("NuMatrixMethod.cxx", Msg::kFatal) 
00913         << "Not a valid extrapolation scheme for a modular "
00914         << "UK matrix method fit"
00915         << endl;
00916     }
00917     catch(MSGException) {
00918       MSG("NuMatrixMethod.cxx", Msg::kError)
00919         << "Not a valid extrapolation scheme for a modular "
00920         << "UK matrix method fit"
00921         << endl;
00922     }
00923   }
00924   
00925   mmInput->M(fRecoVsTrueEnergy_FD, charge);
00926   mmInput->Mtilde(fTrueToRecoCCContamination_FD, charge);
00927   mmInput->T(fTrueEnergyEffCor_FD, charge);
00928   mmInput->K(fSuppliedTrueUnoscCCBackground_FD, charge);
00929   mmInput->Z(fRecoUnoscNCBackground_FD, charge);
00930   mmInput->Appear(fAppearedTrueEffCor_FD, charge);
00931 }
00932 
00933 //____________________________________________________________________72
00934 void NuMatrixMethod
00935 ::SetExtrapolationScheme(const NuMMScheme_t scheme)
00936 {
00937   fextrpScheme = scheme;
00938   switch (scheme){
00939   case kCCNuMuNoOscBackground:
00940     {
00941       //Get the helper histograms:
00942       TFile* helperFile = new TFile(fhelperfilename.c_str(),"READ");
00943       fRecoVsTrueEnergy_ND = (TH2D*) helperFile->Get("RecoVsTrueEnergy_ND");
00944       fRecoVsTrueEnergy_ND->SetDirectory(0);
00945       fRecoVsTrueEnergy_FD = (TH2D*) helperFile->Get("RecoVsTrueEnergy_FD");
00946       fRecoVsTrueEnergy_FD->SetDirectory(0);
00947       
00948       fFDVsNDMatrixRW = (TH2D*) helperFile->Get("FDVsNDMatrixRW");
00949       if(fFDVsNDMatrixRW) fFDVsNDMatrixRW->SetDirectory(0);
00950       fDoXSecStep = true;
00951       
00952       fEfficiency_ND = (TH1D*) helperFile->Get("Efficiency_ND");
00953       fEfficiency_ND->SetDirectory(0);
00954       fEfficiency_FD = (TH1D*) helperFile->Get("Efficiency_FD");
00955       fEfficiency_FD->SetDirectory(0);
00956       fPurity_ND = (TH1D*) helperFile->Get("Purity_ND");
00957       fPurity_ND->SetDirectory(0);
00958       fPurity_FD = (TH1D*) helperFile->Get("Purity_FD");
00959       fPurity_FD->SetDirectory(0);
00960       
00961       helperFile->Close();
00962       if (helperFile) {delete helperFile; helperFile = 0;}
00963       
00964       //Get cross-sections (numu)
00965       TFile *xsecfile = new TFile(fxsecfilename.c_str(),"READ");
00966       TH1F* XSec_CC = (TH1F*) xsecfile->Get("h_numu_cc_tot");
00967       XSec_CC->SetDirectory(0);
00968       xsecfile->Close();
00969       if (xsecfile){delete xsecfile; xsecfile = 0;}
00970       Float_t *x = new Float_t[XSec_CC->GetNbinsX()];
00971       Float_t *y = new Float_t[XSec_CC->GetNbinsX()];
00972       for(int i=0;i<XSec_CC->GetNbinsX();i++) {
00973         x[i] = XSec_CC->GetBinCenter(i+1);
00974         y[i] = XSec_CC->GetBinContent(i+1);
00975       }
00976       fXSec_CC_Graph = new TGraph(XSec_CC->GetNbinsX(),x,y);
00977       if (x) {delete[] x; x = 0;}
00978       if (y) {delete[] y; y = 0;}
00979       
00980       //Get cross-sections (tau)
00981       xsecfile = new TFile(fxsecfilename.c_str(),"READ");
00982       TH1F* tau_XSec_CC = (TH1F*) xsecfile->Get("h_nutau_cc_tot");
00983       tau_XSec_CC->SetDirectory(0);
00984       xsecfile->Close();
00985       if (xsecfile){delete xsecfile; xsecfile = 0;}
00986       x = new Float_t[tau_XSec_CC->GetNbinsX()];
00987       y = new Float_t[tau_XSec_CC->GetNbinsX()];
00988       for(int i=0;i<tau_XSec_CC->GetNbinsX();i++) {
00989         x[i] = tau_XSec_CC->GetBinCenter(i+1);
00990         y[i] = tau_XSec_CC->GetBinContent(i+1);
00991       }
00992       fTau_XSec_CC_Graph = new TGraph(fNTrueBins,x,y);
00993       if (x) {delete[] x; x = 0;}
00994       if (y) {delete[] y; y = 0;}
00995 
00996       //Get the data:
00997       TFile* ndDataFile = new TFile(fndDataFilename.c_str(), "READ");
00998       fRecoEnergyMeas_ND = (TH1D*) ndDataFile->Get("RecoEnergy_ND");
00999       fRecoEnergyMeas_ND->SetDirectory(0);
01000       ndDataFile->Close();
01001       if (ndDataFile){delete ndDataFile; ndDataFile = 0;}
01002     }
01003     break;
01004   case kCCNuMuOscBackgroundUncombined:
01005     {
01006       //Get the helper histograms:
01007       TFile* helperFile = new TFile(fhelperfilename.c_str(),"READ");
01008       fRecoVsTrueEnergy_ND = (TH2D*) helperFile->Get("RecoVsTrueEnergy_ND");
01009       fRecoVsTrueEnergy_ND->SetDirectory(0);
01010       fRecoVsTrueEnergy_FD = (TH2D*) helperFile->Get("RecoVsTrueEnergy_FD");
01011       fRecoVsTrueEnergy_FD->SetDirectory(0);
01012       
01013       fFDVsNDMatrixRW = (TH2D*) helperFile->Get("FDVsNDMatrixRW");
01014       if(fFDVsNDMatrixRW) fFDVsNDMatrixRW->SetDirectory(0);
01015       fDoXSecStep = true;
01016       
01017       fEfficiency_ND = (TH1D*) helperFile->Get("Efficiency_ND");
01018       fEfficiency_ND->SetDirectory(0);
01019       fEfficiency_FD = (TH1D*) helperFile->Get("Efficiency_FD");
01020       fEfficiency_FD->SetDirectory(0);
01021       fPurity_ND = (TH1D*) helperFile->Get("Purity_ND");
01022       fPurity_ND->SetDirectory(0);
01023       fPurity_FD = (TH1D*) helperFile->Get("Purity_FD");
01024       fPurity_FD->SetDirectory(0);
01025       
01026       fCCContamination_FD = (TH1D*) helperFile->Get("CCContamination_FD");
01027       fCCContamination_FD->SetDirectory(0);
01028       fNCContamination_FD = (TH1D*) helperFile->Get("NCContamination_FD");
01029       fNCContamination_FD->SetDirectory(0);
01030       fRecoToTrueCCContamination_FD = (TH2D*)
01031         helperFile->Get("CCContaminationRecoVsTrue_FD");
01032       fRecoToTrueCCContamination_FD->SetDirectory(0);
01033       fTrueToRecoCCContamination_FD = new TH2D(*fRecoToTrueCCContamination_FD);
01034       fTrueToRecoCCContamination_FD->SetDirectory(0);
01035       fSuppliedTrueUnoscCCBackground_FD = 0;
01036       
01037       helperFile->Close();
01038       if (helperFile) {delete helperFile; helperFile = 0;}
01039       
01040       //Get cross-sections (numu)
01041       TFile *xsecfile = new TFile(fxsecfilename.c_str(),"READ");
01042       TH1F* XSec_CC = (TH1F*) xsecfile->Get("h_numu_cc_tot");
01043       XSec_CC->SetDirectory(0);
01044       xsecfile->Close();
01045       if (xsecfile){delete xsecfile; xsecfile = 0;}
01046       Float_t *x = new Float_t[XSec_CC->GetNbinsX()];
01047       Float_t *y = new Float_t[XSec_CC->GetNbinsX()];
01048       for(int i=0;i<XSec_CC->GetNbinsX();i++) {
01049         x[i] = XSec_CC->GetBinCenter(i+1);
01050         y[i] = XSec_CC->GetBinContent(i+1);
01051       }
01052       fXSec_CC_Graph = new TGraph(XSec_CC->GetNbinsX(),x,y);
01053       if (x) {delete[] x; x = 0;}
01054       if (y) {delete[] y; y = 0;}
01055       
01056       //Get cross-sections (tau)
01057       xsecfile = new TFile(fxsecfilename.c_str(),"READ");
01058       TH1F* tau_XSec_CC = (TH1F*) xsecfile->Get("h_nutau_cc_tot");
01059       tau_XSec_CC->SetDirectory(0);
01060       xsecfile->Close();
01061       if (xsecfile){delete xsecfile; xsecfile = 0;}
01062       x = new Float_t[tau_XSec_CC->GetNbinsX()];
01063       y = new Float_t[tau_XSec_CC->GetNbinsX()];
01064       for(int i=0;i<tau_XSec_CC->GetNbinsX();i++) {
01065         x[i] = tau_XSec_CC->GetBinCenter(i+1);
01066         y[i] = tau_XSec_CC->GetBinContent(i+1);
01067       }
01068       fTau_XSec_CC_Graph = new TGraph(fNTrueBins,x,y);
01069       if (x) {delete[] x; x = 0;}
01070       if (y) {delete[] y; y = 0;}
01071 
01072       //Get the data:
01073       TFile* ndDataFile = new TFile(fndDataFilename.c_str(), "READ");
01074       fRecoEnergyMeas_ND = (TH1D*) ndDataFile->Get("RecoEnergy_ND");
01075       fRecoEnergyMeas_ND->SetDirectory(0);
01076       ndDataFile->Close();
01077       if (ndDataFile){delete ndDataFile; ndDataFile = 0;}
01078     }
01079     break;
01080   case kCCNuMuBarOscBackgroundUncombined:
01081     {
01082       //Get the helper histograms:
01083       TFile* helperFile = new TFile(fhelperfilename.c_str(),"READ");
01084       fRecoVsTrueEnergy_ND = (TH2D*) helperFile->Get("RecoVsTrueEnergyPQ_ND");
01085       fRecoVsTrueEnergy_ND->SetDirectory(0);
01086       fRecoVsTrueEnergy_FD = (TH2D*) helperFile->Get("RecoVsTrueEnergyPQ_FD");
01087       fRecoVsTrueEnergy_FD->SetDirectory(0);
01088       
01089       fFDVsNDMatrixRW = (TH2D*) helperFile->Get("FDVsNDMatrixRWPQ");
01090       if(fFDVsNDMatrixRW) fFDVsNDMatrixRW->SetDirectory(0);
01091       fDoXSecStep = true;
01092       
01093       fEfficiency_ND = (TH1D*) helperFile->Get("EfficiencyPQ_ND");
01094       fEfficiency_ND->SetDirectory(0);
01095       fEfficiency_FD = (TH1D*) helperFile->Get("EfficiencyPQ_FD");
01096       fEfficiency_FD->SetDirectory(0);
01097       fPurity_ND = (TH1D*) helperFile->Get("PurityPQ_ND");
01098       fPurity_ND->SetDirectory(0);
01099       fPurity_FD = (TH1D*) helperFile->Get("PurityPQ_FD");
01100       fPurity_FD->SetDirectory(0);
01101       
01102       fCCContamination_FD = (TH1D*) helperFile->Get("CCContaminationPQ_FD");
01103       fCCContamination_FD->SetDirectory(0);
01104       fNCContamination_FD = (TH1D*) helperFile->Get("NCContaminationPQ_FD");
01105       fNCContamination_FD->SetDirectory(0);
01106       fRecoToTrueCCContamination_FD = (TH2D*)
01107         helperFile->Get("CCContaminationRecoVsTruePQ_FD");
01108       fRecoToTrueCCContamination_FD->SetDirectory(0);
01109       fTrueToRecoCCContamination_FD = new TH2D(*fRecoToTrueCCContamination_FD);
01110       fTrueToRecoCCContamination_FD->SetDirectory(0);
01111       fSuppliedTrueUnoscCCBackground_FD = 0;
01112       
01113       helperFile->Close();
01114       if (helperFile) {delete helperFile; helperFile = 0;}
01115       
01116       //Get cross-sections (numubar)
01117       TFile *xsecfile = new TFile(fxsecfilename.c_str(),"READ");
01118       TH1F* XSec_CC = (TH1F*) xsecfile->Get("h_numubar_cc_tot");
01119       XSec_CC->SetDirectory(0);
01120       xsecfile->Close();
01121       if (xsecfile){delete xsecfile; xsecfile = 0;}
01122       Float_t *x = new Float_t[XSec_CC->GetNbinsX()];
01123       Float_t *y = new Float_t[XSec_CC->GetNbinsX()];
01124       for(int i=0;i<XSec_CC->GetNbinsX();i++) {
01125         x[i] = XSec_CC->GetBinCenter(i+1);
01126         y[i] = XSec_CC->GetBinContent(i+1);
01127       }
01128       fXSec_CC_Graph = new TGraph(XSec_CC->GetNbinsX(),x,y);
01129       if (x) {delete[] x; x = 0;}
01130       if (y) {delete[] y; y = 0;}
01131       
01132       //Get cross-sections (taubar)
01133       xsecfile = new TFile(fxsecfilename.c_str(),"READ");
01134       TH1F* tau_XSec_CC = (TH1F*) xsecfile->Get("h_nutaubar_cc_tot");
01135       tau_XSec_CC->SetDirectory(0);
01136       xsecfile->Close();
01137       if (xsecfile){delete xsecfile; xsecfile = 0;}
01138       x = new Float_t[tau_XSec_CC->GetNbinsX()];
01139       y = new Float_t[tau_XSec_CC->GetNbinsX()];
01140       for(int i=0;i<tau_XSec_CC->GetNbinsX();i++) {
01141         x[i] = tau_XSec_CC->GetBinCenter(i+1);
01142         y[i] = tau_XSec_CC->GetBinContent(i+1);
01143       }
01144       fTau_XSec_CC_Graph = new TGraph(fNTrueBins,x,y);
01145       if (x) {delete[] x; x = 0;}
01146       if (y) {delete[] y; y = 0;}
01147 
01148       //Get the data:
01149       TFile* ndDataFile = new TFile(fndDataFilename.c_str(), "READ");
01150       fRecoEnergyMeas_ND = (TH1D*) ndDataFile->Get("RecoEnergyPQ_ND");
01151       fRecoEnergyMeas_ND->SetDirectory(0);
01152       ndDataFile->Close();
01153       if (ndDataFile){delete ndDataFile; ndDataFile = 0;}
01154     }
01155     break;
01156   case kCCNuMuOscBackgroundCombined:
01157     {
01158       //Get the helper histograms:
01159       TFile* helperFile = new TFile(fhelperfilename.c_str(),"READ");
01160       fRecoVsTrueEnergy_ND = (TH2D*) helperFile->Get("RecoVsTrueEnergy_ND");
01161       fRecoVsTrueEnergy_ND->SetDirectory(0);
01162       fRecoVsTrueEnergy_FD = (TH2D*) helperFile->Get("RecoVsTrueEnergy_FD");
01163       fRecoVsTrueEnergy_FD->SetDirectory(0);
01164       
01165       fFDVsNDMatrixRW = (TH2D*) helperFile->Get("FDVsNDMatrixRW");
01166       if(fFDVsNDMatrixRW) fFDVsNDMatrixRW->SetDirectory(0);
01167       fDoXSecStep = true;
01168       
01169       fEfficiency_ND = (TH1D*) helperFile->Get("Efficiency_ND");
01170       fEfficiency_ND->SetDirectory(0);
01171       fEfficiency_FD = (TH1D*) helperFile->Get("Efficiency_FD");
01172       fEfficiency_FD->SetDirectory(0);
01173       fPurity_ND = (TH1D*) helperFile->Get("Purity_ND");
01174       fPurity_ND->SetDirectory(0);
01175       fPurity_FD = (TH1D*) helperFile->Get("Purity_FD");
01176       fPurity_FD->SetDirectory(0);
01177       
01178       fCCContamination_FD = (TH1D*) helperFile->Get("CCContamination_FD");
01179       fCCContamination_FD->SetDirectory(0);
01180       fNCContamination_FD = (TH1D*) helperFile->Get("NCContamination_FD");
01181       fNCContamination_FD->SetDirectory(0);
01182       fRecoToTrueCCContamination_FD = (TH2D*)
01183         helperFile->Get("CCContaminationRecoVsTrue_FD");
01184       fRecoToTrueCCContamination_FD->SetDirectory(0);
01185       fTrueToRecoCCContamination_FD = new TH2D(*fRecoToTrueCCContamination_FD);
01186       fTrueToRecoCCContamination_FD->SetDirectory(0);
01187       fSuppliedTrueUnoscCCBackground_FD = 0;
01188       fOtherEfficiency_FD = (TH1D*)
01189         helperFile->Get("OtherEfficiency_FD");
01190       fOtherEfficiency_FD->SetDirectory(0);
01191       
01192       helperFile->Close();
01193       if (helperFile) {delete helperFile; helperFile = 0;}
01194       
01195       //Get cross-sections (numu)
01196       TFile *xsecfile = new TFile(fxsecfilename.c_str(),"READ");
01197       TH1F* XSec_CC = (TH1F*) xsecfile->Get("h_numu_cc_tot");
01198       XSec_CC->SetDirectory(0);
01199       xsecfile->Close();
01200       if (xsecfile){delete xsecfile; xsecfile = 0;}
01201       Float_t *x = new Float_t[XSec_CC->GetNbinsX()];
01202       Float_t *y = new Float_t[XSec_CC->GetNbinsX()];
01203       for(int i=0;i<XSec_CC->GetNbinsX();i++) {
01204         x[i] = XSec_CC->GetBinCenter(i+1);
01205         y[i] = XSec_CC->GetBinContent(i+1);
01206       }
01207       fXSec_CC_Graph = new TGraph(XSec_CC->GetNbinsX(),x,y);
01208       if (x) {delete[] x; x = 0;}
01209       if (y) {delete[] y; y = 0;}
01210       
01211       //Get cross-sections (tau)
01212       xsecfile = new TFile(fxsecfilename.c_str(),"READ");
01213       TH1F* tau_XSec_CC = (TH1F*) xsecfile->Get("h_nutau_cc_tot");
01214       tau_XSec_CC->SetDirectory(0);
01215       xsecfile->Close();
01216       if (xsecfile){delete xsecfile; xsecfile = 0;}
01217       x = new Float_t[tau_XSec_CC->GetNbinsX()];
01218       y = new Float_t[tau_XSec_CC->GetNbinsX()];
01219       for(int i=0;i<tau_XSec_CC->GetNbinsX();i++) {
01220         x[i] = tau_XSec_CC->GetBinCenter(i+1);
01221         y[i] = tau_XSec_CC->GetBinContent(i+1);
01222       }
01223       fTau_XSec_CC_Graph = new TGraph(fNTrueBins,x,y);
01224       if (x) {delete[] x; x = 0;}
01225       if (y) {delete[] y; y = 0;}
01226 
01227       //Get the data:
01228       TFile* ndDataFile = new TFile(fndDataFilename.c_str(), "READ");
01229       fRecoEnergyMeas_ND = (TH1D*) ndDataFile->Get("RecoEnergy_ND");
01230       fRecoEnergyMeas_ND->SetDirectory(0);
01231       ndDataFile->Close();
01232       if (ndDataFile){delete ndDataFile; ndDataFile = 0;}
01233     }
01234     break;
01235   case kCCNuMuBarOscBackgroundCombined:
01236     {
01237       //Get the helper histograms:
01238       TFile* helperFile = new TFile(fhelperfilename.c_str(),"READ");
01239       fRecoVsTrueEnergy_ND = (TH2D*) helperFile->Get("RecoVsTrueEnergyPQ_ND");
01240       fRecoVsTrueEnergy_ND->SetDirectory(0);
01241       fRecoVsTrueEnergy_FD = (TH2D*) helperFile->Get("RecoVsTrueEnergyPQ_FD");
01242       fRecoVsTrueEnergy_FD->SetDirectory(0);
01243       
01244       fFDVsNDMatrixRW = (TH2D*) helperFile->Get("FDVsNDMatrixRWPQ");
01245       if(fFDVsNDMatrixRW) fFDVsNDMatrixRW->SetDirectory(0);
01246       fDoXSecStep = true;
01247       
01248       fEfficiency_ND = (TH1D*) helperFile->Get("EfficiencyPQ_ND");
01249       fEfficiency_ND->SetDirectory(0);
01250       fEfficiency_FD = (TH1D*) helperFile->Get("EfficiencyPQ_FD");
01251       fEfficiency_FD->SetDirectory(0);
01252       fPurity_ND = (TH1D*) helperFile->Get("PurityPQ_ND");
01253       fPurity_ND->SetDirectory(0);
01254       fPurity_FD = (TH1D*) helperFile->Get("PurityPQ_FD");
01255       fPurity_FD->SetDirectory(0);
01256       
01257       fCCContamination_FD = (TH1D*) helperFile->Get("CCContaminationPQ_FD");
01258       fCCContamination_FD->SetDirectory(0);
01259       fNCContamination_FD = (TH1D*) helperFile->Get("NCContaminationPQ_FD");
01260       fNCContamination_FD->SetDirectory(0);
01261       fRecoToTrueCCContamination_FD = (TH2D*)
01262         helperFile->Get("CCContaminationRecoVsTruePQ_FD");
01263       fRecoToTrueCCContamination_FD->SetDirectory(0);
01264       fTrueToRecoCCContamination_FD = new TH2D(*fRecoToTrueCCContamination_FD);
01265       fTrueToRecoCCContamination_FD->SetDirectory(0);
01266       fSuppliedTrueUnoscCCBackground_FD = 0;
01267       fOtherEfficiency_FD = (TH1D*)
01268         helperFile->Get("OtherEfficiencyPQ_FD");
01269       fOtherEfficiency_FD->SetDirectory(0);
01270       
01271       helperFile->Close();
01272       if (helperFile) {delete helperFile; helperFile = 0;}
01273       
01274       //Get cross-sections (numubar)
01275       TFile *xsecfile = new TFile(fxsecfilename.c_str(),"READ");
01276       TH1F* XSec_CC = (TH1F*) xsecfile->Get("h_numubar_cc_tot");
01277       XSec_CC->SetDirectory(0);
01278       xsecfile->Close();
01279       if (xsecfile){delete xsecfile; xsecfile = 0;}
01280       Float_t *x = new Float_t[XSec_CC->GetNbinsX()];
01281       Float_t *y = new Float_t[XSec_CC->GetNbinsX()];
01282       for(int i=0;i<XSec_CC->GetNbinsX();i++) {
01283         x[i] = XSec_CC->GetBinCenter(i+1);
01284         y[i] = XSec_CC->GetBinContent(i+1);
01285       }
01286       fXSec_CC_Graph = new TGraph(XSec_CC->GetNbinsX(),x,y);
01287       if (x) {delete[] x; x = 0;}
01288       if (y) {delete[] y; y = 0;}
01289       
01290       //Get cross-sections (taubar)
01291       xsecfile = new TFile(fxsecfilename.c_str(),"READ");
01292       TH1F* tau_XSec_CC = (TH1F*) xsecfile->Get("h_nutaubar_cc_tot");
01293       tau_XSec_CC->SetDirectory(0);
01294       xsecfile->Close();
01295       if (xsecfile){delete xsecfile; xsecfile = 0;}
01296       x = new Float_t[tau_XSec_CC->GetNbinsX()];
01297       y = new Float_t[tau_XSec_CC->GetNbinsX()];
01298       for(int i=0;i<tau_XSec_CC->GetNbinsX();i++) {
01299         x[i] = tau_XSec_CC->GetBinCenter(i+1);
01300         y[i] = tau_XSec_CC->GetBinContent(i+1);
01301       }
01302       fTau_XSec_CC_Graph = new TGraph(fNTrueBins,x,y);
01303       if (x) {delete[] x; x = 0;}
01304       if (y) {delete[] y; y = 0;}
01305 
01306       //Get the data:
01307       TFile* ndDataFile = new TFile(fndDataFilename.c_str(), "READ");
01308       fRecoEnergyMeas_ND = (TH1D*) ndDataFile->Get("RecoEnergyPQ_ND");
01309       fRecoEnergyMeas_ND->SetDirectory(0);
01310       ndDataFile->Close();
01311       if (ndDataFile){delete ndDataFile; ndDataFile = 0;}
01312     }
01313     break;
01314   case kCCNoChargeCut:
01315     {
01316       //Get the helper histograms:
01317       TFile* helperFile = new TFile(fhelperfilename.c_str(),"READ");
01318       fRecoVsTrueEnergy_ND = (TH2D*) helperFile->Get("RecoVsTrueEnergyAll_ND");
01319       fRecoVsTrueEnergy_ND->SetDirectory(0);
01320       fRecoVsTrueEnergy_FD = (TH2D*) helperFile->Get("RecoVsTrueEnergyAll_FD");
01321       fRecoVsTrueEnergy_FD->SetDirectory(0);
01322       
01323       fFDVsNDMatrixRW = (TH2D*) helperFile->Get("FDVsNDMatrixXSecRWAllCC");
01324       if(fFDVsNDMatrixRW) fFDVsNDMatrixRW->SetDirectory(0);
01325       fDoXSecStep = false;
01326       
01327       fEfficiency_ND = (TH1D*) helperFile->Get("EfficiencyAll_ND");
01328       fEfficiency_ND->SetDirectory(0);
01329       fEfficiency_FD = (TH1D*) helperFile->Get("EfficiencyAll_FD");
01330       fEfficiency_FD->SetDirectory(0);
01331       fPurity_ND = (TH1D*) helperFile->Get("PurityAll_ND");
01332       fPurity_ND->SetDirectory(0);
01333       fPurity_FD = (TH1D*) helperFile->Get("PurityAll_FD");
01334       fPurity_FD->SetDirectory(0);
01335       
01336       fNCContamination_FD = new TH1D(*fPurity_FD);
01337       fNCContamination_FD->Reset();
01338       for(int i=1;i<=fNCContamination_FD->GetNbinsX();i++) {
01339         fNCContamination_FD->SetBinContent(i,1.0);
01340       }
01341       fNCContamination_FD->Add(fPurity_FD,-1.0);
01342       fNCContamination_FD->SetDirectory(0);
01343       
01344       helperFile->Close();
01345       if (helperFile) {delete helperFile; helperFile = 0;}
01346       
01347       //Get cross-sections (numu; unused, I belive)
01348       TFile *xsecfile = new TFile(fxsecfilename.c_str(),"READ");
01349       TH1F* XSec_CC = (TH1F*) xsecfile->Get("h_numu_cc_tot");
01350       XSec_CC->SetDirectory(0);
01351       xsecfile->Close();
01352       if (xsecfile){delete xsecfile; xsecfile = 0;}
01353       Float_t *x = new Float_t[XSec_CC->GetNbinsX()];
01354       Float_t *y = new Float_t[XSec_CC->GetNbinsX()];
01355       for(int i=0;i<XSec_CC->GetNbinsX();i++) {
01356         x[i] = XSec_CC->GetBinCenter(i+1);
01357         y[i] = XSec_CC->GetBinContent(i+1);
01358       }
01359       fXSec_CC_Graph = new TGraph(XSec_CC->GetNbinsX(),x,y);
01360       if (x) {delete[] x; x = 0;}
01361       if (y) {delete[] y; y = 0;}
01362       
01363       //Get cross-sections (tau; again: unused at present)
01364       xsecfile = new TFile(fxsecfilename.c_str(),"READ");
01365       TH1F* tau_XSec_CC = (TH1F*) xsecfile->Get("h_nutau_cc_tot");
01366       tau_XSec_CC->SetDirectory(0);
01367       xsecfile->Close();
01368       if (xsecfile){delete xsecfile; xsecfile = 0;}
01369       x = new Float_t[tau_XSec_CC->GetNbinsX()];
01370       y = new Float_t[tau_XSec_CC->GetNbinsX()];
01371       for(int i=0;i<tau_XSec_CC->GetNbinsX();i++) {
01372         x[i] = tau_XSec_CC->GetBinCenter(i+1);
01373         y[i] = tau_XSec_CC->GetBinContent(i+1);
01374       }
01375       fTau_XSec_CC_Graph = new TGraph(fNTrueBins,x,y);
01376       if (x) {delete[] x; x = 0;}
01377       if (y) {delete[] y; y = 0;}
01378 
01379       //Get the data:
01380       TFile* ndDataFile = new TFile(fndDataFilename.c_str(), "READ");
01381       fRecoEnergyMeas_ND = (TH1D*) ndDataFile->Get("RecoEnergyAll_ND");
01382       fRecoEnergyMeas_ND->SetDirectory(0);
01383       ndDataFile->Close();
01384       if (ndDataFile){delete ndDataFile; ndDataFile = 0;}
01385     }
01386     break;
01387   case kPRLCCAnalysis:
01388     {
01389       //Get the helper histograms:
01390       TFile* helperFile = new TFile(fhelperfilename.c_str(),"READ");
01391       fRecoVsTrueEnergy_ND = (TH2D*) helperFile->Get("RecoVsTrueEnergy_ND");
01392       fRecoVsTrueEnergy_ND->SetDirectory(0);
01393       fRecoVsTrueEnergy_FD = (TH2D*) helperFile->Get("RecoVsTrueEnergy_FD");
01394       fRecoVsTrueEnergy_FD->SetDirectory(0);
01395       
01396       fFDVsNDMatrixRW = (TH2D*) helperFile->Get("FDVsNDMatrixRW");
01397       if(fFDVsNDMatrixRW) fFDVsNDMatrixRW->SetDirectory(0);
01398       fDoXSecStep = true;
01399       
01400       fEfficiency_ND = (TH1D*) helperFile->Get("Efficiency_ND");
01401       fEfficiency_ND->SetDirectory(0);
01402       fEfficiency_FD = (TH1D*) helperFile->Get("Efficiency_FD");
01403       fEfficiency_FD->SetDirectory(0);
01404       //The purity histograms in the helper file remove both the ND
01405       //background and the wrong sign CCs: the PRL analysis doesn't
01406       //remove the latter.
01407       
01408        fPurity_FD = (TH1D*) helperFile->Get("NCContamination_FD");
01409        fPurity_FD->SetDirectory(0);
01410        fPurity_ND = (TH1D*) helperFile->Get("NCContamination_ND");
01411        fPurity_ND->SetDirectory(0);
01412        for (int i=1; i<=fPurity_ND->GetNbinsX(); ++i){
01413         fPurity_ND->SetBinContent(i, 1.0 -
01414                                   fPurity_ND->GetBinContent(i));
01415         fPurity_FD->SetBinContent(i, 1.0 -
01416                                   fPurity_FD->GetBinContent(i));
01417        }
01418     
01419        fNCContamination_FD = (TH1D*) helperFile->Get("NCContamination_FD");
01420        fNCContamination_FD->SetDirectory(0);
01421       
01422        /*
01423       fPurity_ND = (TH1D*) helperFile->Get("Purity_ND");
01424       fPurity_ND->SetDirectory(0);
01425       fPurity_FD = (TH1D*) helperFile->Get("Purity_FD");
01426       fPurity_FD->SetDirectory(0);
01427        */
01428       //Tau helpers
01429       fEfficiencyTau_FD = (TH1D*) helperFile->Get("EfficiencyTau_FD");
01430       fEfficiencyTau_FD->SetDirectory(0);
01431       fRecoVsTrueEnergyTau_FD = (TH2D*)
01432         helperFile->Get("RecoVsTrueEnergyTau_FD");
01433       fRecoVsTrueEnergyTau_FD->SetDirectory(0);
01434       
01435       helperFile->Close();
01436       if (helperFile) {delete helperFile; helperFile = 0;}
01437       
01438       //Get cross-sections (numu)
01439       TFile *xsecfile = new TFile(fxsecfilename.c_str(),"READ");
01440       TH1F* XSec_CC = (TH1F*) xsecfile->Get("h_numu_cc_tot");
01441       XSec_CC->SetDirectory(0);
01442       xsecfile->Close();
01443       if (xsecfile){delete xsecfile; xsecfile = 0;}
01444       Float_t *x = new Float_t[XSec_CC->GetNbinsX()];
01445       Float_t *y = new Float_t[XSec_CC->GetNbinsX()];
01446       for(int i=0;i<XSec_CC->GetNbinsX();i++) {
01447         x[i] = XSec_CC->GetBinCenter(i+1);
01448         y[i] = XSec_CC->GetBinContent(i+1);
01449       }
01450       fXSec_CC_Graph = new TGraph(XSec_CC->GetNbinsX(),x,y);
01451       if (x) {delete[] x; x = 0;}
01452       if (y) {delete[] y; y = 0;}
01453       
01454       //Get cross-sections (tau)
01455       xsecfile = new TFile(fxsecfilename.c_str(),"READ");
01456       TH1F* tau_XSec_CC = (TH1F*) xsecfile->Get("h_nutau_cc_tot");
01457       tau_XSec_CC->SetDirectory(0);
01458       xsecfile->Close();
01459       if (xsecfile){delete xsecfile; xsecfile = 0;}
01460       x = new Float_t[tau_XSec_CC->GetNbinsX()];
01461       y = new Float_t[tau_XSec_CC->GetNbinsX()];
01462       for(int i=0;i<tau_XSec_CC->GetNbinsX();i++) {
01463         x[i] = tau_XSec_CC->GetBinCenter(i+1);
01464         y[i] = tau_XSec_CC->GetBinContent(i+1);
01465       }
01466       fTau_XSec_CC_Graph = new TGraph(fNTrueBins,x,y);
01467       if (x) {delete[] x; x = 0;}
01468       if (y) {delete[] y; y = 0;}
01469 
01470       //Get the data:
01471       TFile* ndDataFile = new TFile(fndDataFilename.c_str(), "READ");
01472       fRecoEnergyMeas_ND = (TH1D*) ndDataFile->Get("RecoEnergy_ND");
01473       fRecoEnergyMeas_ND->SetDirectory(0);
01474       ndDataFile->Close();
01475       if (ndDataFile){delete ndDataFile; ndDataFile = 0;}
01476     }
01477     break;
01478   default:
01479     {
01480     }
01481     break;
01482   }
01483       
01484   if (fRecoToTrueCCContamination_FD){
01485     //Normalise the FD CC contamination reco to true CC matrix
01486     //First loop over true axis:
01487     for (Int_t j=1; j<=fRecoToTrueCCContamination_FD->GetNbinsY(); ++j){
01488       //Find out the total number of reco events in this row:
01489       Double_t recoEvents = 0.0;
01490       for (Int_t i=1; i<=fRecoToTrueCCContamination_FD->GetNbinsX(); ++i){
01491         recoEvents += fRecoToTrueCCContamination_FD->GetBinContent(i,j);
01492       }
01493       //Loop again, this time normalise.
01494       for (Int_t i=1; i<=fRecoToTrueCCContamination_FD->GetNbinsX(); ++i){
01495         if (recoEvents>0){
01496           Double_t oldContent =
01497             fRecoToTrueCCContamination_FD->GetBinContent(i,j);
01498           Double_t oldError =
01499             fRecoToTrueCCContamination_FD->GetBinError(i,j);
01500           fRecoToTrueCCContamination_FD->SetBinContent
01501             (i,j,oldContent/recoEvents);
01502           fRecoToTrueCCContamination_FD->SetBinError
01503             (i,j,oldError/recoEvents);
01504         }
01505         else{
01506           fRecoToTrueCCContamination_FD->SetBinContent(i,j,0);
01507           
01508           fRecoToTrueCCContamination_FD->SetBinError(i,j,0);
01509         }
01510       }
01511     }
01512   }
01513   
01514   if (fTrueToRecoCCContamination_FD){ 
01515     //Normalise the FD CC contamination true to reco CC matrix
01516     //First loop over reco axis:
01517     for (Int_t i=1; i<=fTrueToRecoCCContamination_FD->GetNbinsX(); ++i){
01518       //Find out the total number of true events in this column:
01519       Double_t trueEvents = 0.0;
01520       for (Int_t j=1; j<=fTrueToRecoCCContamination_FD->GetNbinsY(); ++j){
01521         trueEvents += fTrueToRecoCCContamination_FD->GetBinContent(i,j);
01522       }
01523       //Loop again, this time normalise.
01524       for (Int_t j=1; j<=fTrueToRecoCCContamination_FD->GetNbinsY(); ++j){
01525         if (trueEvents>0){
01526           Double_t oldContent =
01527             fTrueToRecoCCContamination_FD->GetBinContent(i,j);
01528           Double_t oldError =
01529             fTrueToRecoCCContamination_FD->GetBinError(i,j);
01530           fTrueToRecoCCContamination_FD->SetBinContent
01531             (i,j,oldContent/trueEvents);
01532           fTrueToRecoCCContamination_FD->SetBinError
01533             (i,j,oldError/trueEvents);
01534         }
01535         else{
01536           fTrueToRecoCCContamination_FD->SetBinContent(i,j,0);
01537           
01538           fTrueToRecoCCContamination_FD->SetBinError(i,j,0);
01539         }
01540       }
01541     }
01542   }
01543 //   if (fxmlConfig){
01544 //     this->ShiftXSecGraph();
01545 //   }
01546 }
01547 
01548 //____________________________________________________________________72
01549 void NuMatrixMethod::ShiftXSecGraph()
01550 {
01551   NuSystematic nuSyst(*fxmlConfig);
01552   NuParticle::NuParticleType_t particle = NuParticle::kUndefined;
01553   if (NuMMExtrapolation::kCCNuMuNoOscBackground == fextrpScheme ||
01554       NuMMExtrapolation::kCCNuMuOscBackgroundUncombined == fextrpScheme ||
01555       NuMMExtrapolation::kCCNuMuOscBackgroundCombined == fextrpScheme ||
01556       NuMMExtrapolation::kModularNuMuCPTFit == fextrpScheme ||
01557       NuMMExtrapolation::kModularPRLCCFit == fextrpScheme){
01558     particle = NuParticle::kNuMu;
01559   }
01560   else if (NuMMExtrapolation::kCCNuMuBarOscBackgroundUncombined == fextrpScheme ||
01561       NuMMExtrapolation::kCCNuMuBarOscBackgroundCombined == fextrpScheme ||
01562       NuMMExtrapolation::kModularNuMuBarCPTFit == fextrpScheme ||
01563       NuMMExtrapolation::kModularNuMuBarTransitionFit == fextrpScheme){
01564     particle = NuParticle::kNuMuBar;
01565   }
01566   else if (NuMMExtrapolation::kCCNoChargeCut == fextrpScheme ||
01567            NuMMExtrapolation::kModularNoChargeCutFit == fextrpScheme){
01568     MSG("NuMatrixMethod.cxx",Msg::kInfo)
01569       << "Cross section file isn't used by NuMatrixMethod for this fitting mode"
01570       << endl;
01571     particle = NuParticle::kUndefined;
01572     return;
01573   }
01574   else {
01575     MSG("NuMatrixMethod.cxx",Msg::kWarning)
01576       << "I don't know what I'm extrapolaing!"
01577       << endl;
01578     particle = NuParticle::kUndefined;
01579   }
01580   if (NuParticle::kUndefined != particle){
01581     //Loop over graph
01582     for (Int_t point = 0; point < fXSec_CC_Graph->GetN(); ++point){
01583       //Get energy & nominal cross section
01584       Double_t energy = 0;
01585       Double_t xSec = 0;
01586       fXSec_CC_Graph->GetPoint(point,energy,xSec);
01587       xSec *= nuSyst.XSecShiftScale(energy,particle);
01588       fXSec_CC_Graph->SetPoint(point,energy,xSec);
01589     }
01590   }
01591 }
01592 
01593 //____________________________________________________________________72
01594 void NuMatrixMethod::PredictFDFluxUnosc()
01595 {
01597 
01598   //just zero everything
01599   this->ResetUnoscHistograms();
01600 
01601   //subtract background
01602   this->PurityCorrectND();
01603 
01604   //convert ND reco spectrum into true spectrum
01605   this->RecoToTrueND();
01606 
01607   //correct for eff. in true energy
01608   //numerator is true CC events reco'd in the fid vol that pass all cuts
01609   //denominator is true CC events with true vtx in fid vol
01610   //hence efficiency can be >1 if more leak-in than leak-out
01611   this->EfficiencyCorrectND();
01612 
01613   //convert to flux (divide by NDmass, NDpot, xsec (xsec only if not
01614   //doing combined extrapolation))
01615   this->XSecCorrectND();
01616 
01617   //APPLY THE BEAM MATRIX
01618   this->ExtrapolateNDToFD();
01619 
01620   //covert from flux to events (times by FDmass, FDpot and xsec). Only
01621   //if fDoXSecStep == true are the cross sections included: for a
01622   //combined numu+numubar extrapolation, the cross sections are
01623   //included in the beam matrix.
01624   this->XSecCorrectFD();
01625 
01626   //correct for eff. in true energy
01627   //numerator is true CC events reco'd in the fid vol that pass all cuts
01628   //denominator is true CC events with true vtx in fid vol
01629   //hence efficiency can be >1 if more leak-in than leak-out
01630   //The "T" spectrum to pass out to external fitter is now created
01631   this->EfficiencyCorrectFD();
01632 
01634   //Now create the Z spectrum (NC events)
01635   //apply true to reco matrix to get pure reco CC spectrum
01636   this->UnoscTrueToRecoFD();
01637 
01638   //divide by overall purity to get the actual unoscillated FD spectrum
01639   this->UnoscPurityCorrectFD();
01640 
01641   //take unoscillated FD spectrum and times by NC contamination
01642   //to get the NC spectrum
01643   //The "Z" spectrum to pass out to external fitter is now created
01644   this->CalculateNCContamination();
01645   
01647   //Calculate the true energy tau spectrum as if every numu has turned
01648   //into a tau (only do for PRL-style analysis so far)
01649   if (NuMMExtrapolation::kPRLCCAnalysis == fextrpScheme){
01650     this->PotentialTausTrueEnergy();
01651   }
01652 }
01653 
01654 //____________________________________________________________________72
01655 const TH1D* NuMatrixMethod
01656 ::PredictFDSpectrumBackgroundNoOsc(const Double_t dm2,
01657                                    const Double_t sn2)
01658 {
01659   this->OscillateFD(dm2,sn2);
01660   //Get the true tau spectrum
01661   TH1D trueTauSpectrum = this->InverseOscillate(*fEffCorTau_FD,dm2,sn2);
01662   //true to reco the numus:
01663   this->TrueToRecoFD();
01664   //true to reco the taus:
01665   TH1D recoTauSpectrum = this->TrueToReco(trueTauSpectrum,
01666                                           *fRecoVsTrueEnergyTau_FD);
01667   //Add in the NCs
01668   this->PurityCorrectFDBackgroundNoOsc();
01669   //Add in the taus
01670   TH1D finalPrediction = this->AddInImpurity(*fRecoEnergyPred_FD,
01671                                              recoTauSpectrum);
01672   
01673   //This line is if I don't want taus:
01674   //       TH1D finalPrediction = *fRecoEnergyPred_FD;
01675   
01676   //Put the answer somewhere I can get to it later
01677   if (fRecoEnergyPred_FD){delete fRecoEnergyPred_FD; fRecoEnergyPred_FD=0;}
01678   fRecoEnergyPred_FD = new TH1D(finalPrediction);
01679   return fRecoEnergyPred_FD;
01680 }
01681 
01682 //____________________________________________________________________72
01683 const TH1D* NuMatrixMethod
01684 ::PredictFDDecaySpectrumBackgroundNoOsc(const Double_t alpha,
01685                                         const Double_t sn2)
01686 {
01687   this->DecayFD(alpha,sn2);
01688   this->TrueToRecoFD();
01689   this->PurityCorrectFDBackgroundNoOsc();
01690   return fRecoEnergyPred_FD;
01691 }
01692 
01693 //____________________________________________________________________72
01694 const TH1D* NuMatrixMethod
01695 ::PredictFDDecoherenceSpectrumBackgroundNoOsc(const Double_t mu2,
01696                                               const Double_t sn2)
01697 {
01698   this->DecohereFD(mu2,sn2);
01699   this->TrueToRecoFD();
01700   this->PurityCorrectFDBackgroundNoOsc();
01701   return fRecoEnergyPred_FD;
01702 }
01703 
01704 //____________________________________________________________________72
01705 const TH1D* NuMatrixMethod::
01706 PredictFDSpectrumBackgroundOscUncombined(const Double_t dm2,
01707                                          const Double_t sn2,
01708                                          const Double_t backdm2,
01709                                          const Double_t backsn2)
01710 {
01711   this->OscillateFD(dm2,sn2);
01712   this->TrueToRecoFD();
01713   this->PurityCorrectFDBackgroundOscUncombined(backdm2,backsn2);
01714   return fRecoEnergyPred_FD;
01715 }
01716 
01717 //____________________________________________________________________72
01718 const TH1D* NuMatrixMethod
01719 ::PredictFDSpectrumAppearance(const Double_t dm2,
01720                               const Double_t sn2,
01721                               const Double_t backdm2,
01722                               const Double_t backsn2,
01723                               const Double_t appearanceFraction)
01724 {
01725   this->OscillateFD(dm2,sn2);
01726   this->AddInAppearedEvents(backdm2,backsn2,appearanceFraction);
01727   this->TrueToRecoFD();
01728   this->PurityCorrectFDBackgroundOscCombined(backdm2,backsn2);
01729   return fRecoEnergyPred_FD;
01730 }
01731 
01732 //____________________________________________________________________72
01733 void NuMatrixMethod
01734 ::AddInAppearedEvents(const Double_t otherDm2,
01735                       const Double_t otherSn2,
01736                       const Double_t appearanceFraction)
01737 {
01738   for(int i=1;i<=fTrueEnergyOsc_FD->GetNbinsX();i++) {
01739    
01740     Double_t energy = fTrueEnergyOsc_FD->GetBinCenter(i);
01741     Double_t transProb = otherSn2*(1-NuUtilities::OscillationWeight(energy, otherDm2, otherSn2));
01742     transProb *= appearanceFraction;
01743     
01744     fTrueEnergyOsc_FD->
01745       AddBinContent(i,
01746                     fAppearedTrueEffCor_FD->GetBinContent(i)*transProb);
01747 
01748     Double_t binError =
01749       TMath::Power(fTrueEnergyOsc_FD->GetBinError(i),2);
01750     binError += TMath::Power
01751       (fAppearedTrueEffCor_FD->GetBinContent(i)*transProb,2);
01752     if (binError>0){binError = TMath::Sqrt(binError);}
01753     else{binError = 0;}
01754     fTrueEnergyOsc_FD->SetBinError(i,binError);
01755 
01756   }
01757   return;
01758 }
01759 
01760 
01761 //____________________________________________________________________72
01762 void NuMatrixMethod::SetFDAppearedFidFlux(const TH1D& hFDAppearedFidFlux)
01763 {
01764   if (fAppearedTrueEffCor_FD){
01765     delete fAppearedTrueEffCor_FD;
01766     fAppearedTrueEffCor_FD = 0;
01767   }
01768   fAppearedTrueEffCor_FD = new TH1D(hFDAppearedFidFlux);
01769   fAppearedTrueEffCor_FD->SetDirectory(0);
01770 
01771   double val, err, energy;
01772   double newval, newerr;
01773   double eff, efferr, xsec;
01774 
01775   for(int i = 1; i <= fAppearedTrueEffCor_FD->GetNbinsX(); i++) {
01776     val = fAppearedTrueEffCor_FD->GetBinContent(i);
01777     err = fAppearedTrueEffCor_FD->GetBinError(i);
01778     energy = fAppearedTrueEffCor_FD->GetBinCenter(i);
01779 
01780     xsec = fXSec_CC_Graph->Eval(energy,0,"");
01781     eff = fEfficiency_FD->GetBinContent(i);
01782     efferr = fEfficiency_FD->GetBinError(i);
01783     
01784     // Add in xsec, eff Flux => Events
01785     newval = val * xsec * eff;
01786     
01787     newerr = TMath::Power(err/val,2) + TMath::Power(efferr/eff,2);
01788     newerr = TMath::Sqrt(newerr) * newval;
01789     
01790     fAppearedTrueEffCor_FD->SetBinContent(i,newval);
01791     fAppearedTrueEffCor_FD->SetBinError(i,newerr);
01792   }
01793   return;
01794 }
01795 
01796 
01797 //____________________________________________________________________72
01798 const TH1D NuMatrixMethod::GetFDPotentialAppearanceFidFlux() const
01799 {
01800   TH1D hPotential("hTrueEnergyPotentialAppearance",
01801                  "True energy potential appearance spectrum",
01802                  fNTrueBins,fTrueBinEdges);
01803   double val, err, energy;
01804   double newval, newerr;
01805   double eff, efferr, xsec;
01806 
01807   for(int i = 1; i <= hPotential.GetNbinsX(); i++) {
01808     val = fTrueEnergyEffCor_FD->GetBinContent(i);
01809     err = fTrueEnergyEffCor_FD->GetBinError(i);
01810     energy = hPotential.GetBinCenter(i);
01811     
01812     xsec = fXSec_CC_Graph->Eval(energy,0,"");
01813     eff = fEfficiency_FD->GetBinContent(i);
01814     efferr = fEfficiency_FD->GetBinError(i);
01815     
01816     // Remove xsec, eff: Events => Flux
01817     if (eff == 0 || xsec == 0) newval = 0;
01818     else newval = val / xsec / eff;
01819     
01820     newerr = TMath::Power(err/val,2) + TMath::Power(efferr/eff,2);
01821     newerr = TMath::Sqrt(newerr) * newval;
01822     
01823     hPotential.SetBinContent(i,newval);
01824     hPotential.SetBinError(i,newerr);
01825   }
01826   return hPotential;
01827 }
01828 
01829 //____________________________________________________________________72
01830 const TH1D* NuMatrixMethod
01831 ::PredictFDSpectrumBackgroundOscCombined(const Double_t dm2,
01832                                          const Double_t sn2,
01833                                          const Double_t backdm2,
01834                                          const Double_t backsn2)
01835 {
01836   //applies osc to "T"
01837   this->OscillateFD(dm2,sn2);
01838 
01839   //does true to reco on osc true spectrum
01840   this->TrueToRecoFD();
01841 
01842   this->PurityCorrectFDBackgroundOscCombined(backdm2,backsn2);
01843 
01844   //give back the final oscillated reco energy spectrum with all
01845   //contaminations
01846   return fRecoEnergyPred_FD;
01847 }
01848 
01849 //____________________________________________________________________72
01850 const TH1D* NuMatrixMethod
01851 ::PredictFDDecaySpectrumBackgroundDecayCombined(const Double_t alpha,
01852                                                 const Double_t sn2,
01853                                                 const Double_t backalpha,
01854                                                 const Double_t backsn2)
01855 {
01856   //sn2 is now sin^{2}theta, not sin^{2}2theta
01857 
01858   //applies osc to "T"
01859   this->DecayFD(alpha,sn2);
01860 
01861   //does true to reco on osc true spectrum
01862   this->TrueToRecoFD();
01863 
01864   this->PurityCorrectFDBackgroundDecayCombined(backalpha,backsn2);
01865 
01866   //give back the final oscillated reco energy spectrum with all
01867   //contaminations
01868   return fRecoEnergyPred_FD;
01869 }
01870 
01871 //____________________________________________________________________72
01872 const TH1D* NuMatrixMethod
01873 ::PredictFDDecoherenceSpectrumBackgroundDecohereCombined(const Double_t mu2,
01874                                                          const Double_t sn2,
01875                                                          const Double_t backmu2,
01876                                                          const Double_t backsn2)
01877 {
01878   //sn2 is now sin^{2}theta, not sin^{2}2theta
01879 
01880   //applies osc to "T"
01881   this->DecohereFD(mu2,sn2);
01882 
01883   //does true to reco on osc true spectrum
01884   this->TrueToRecoFD();
01885 
01886   this->PurityCorrectFDBackgroundDecohereCombined(backmu2,backsn2);
01887 
01888   //give back the final oscillated reco energy spectrum with all
01889   //contaminations
01890   return fRecoEnergyPred_FD;
01891 }
01892 
01893 //____________________________________________________________________72
01894 const TH1D NuMatrixMethod::InverseOscillate(const TH1D& inputSpectrum,
01895                                             const Double_t dm2,
01896                                             const Double_t sn2) const
01897 {
01898   TH1D outputSpectrum(inputSpectrum);
01899   outputSpectrum.Reset();
01900 
01901   for(int i=1;i<=outputSpectrum.GetNbinsX();i++) {
01902     Double_t energy = outputSpectrum.GetBinCenter(i);
01903     Double_t oscProb = 1-NuUtilities::OscillationWeight(energy, dm2, sn2);
01904     outputSpectrum.
01905       SetBinContent(i,inputSpectrum.GetBinContent(i)*oscProb);
01906     outputSpectrum.
01907       SetBinError(i,inputSpectrum.GetBinError(i)*oscProb);
01908   }
01909 
01910   return outputSpectrum;
01911 }
01912 
01913 //____________________________________________________________________72
01914 void NuMatrixMethod::OscillateFD(const Double_t dm2,
01915                                  const Double_t sn2)
01916 {
01917   //8: Oscillate FD spectrum:
01918   for(int i=1;i<=fTrueEnergyOsc_FD->GetNbinsX();i++) {
01919     Double_t energy = fTrueEnergyOsc_FD->GetBinCenter(i);
01920     Double_t oscProb = NuUtilities::OscillationWeight(energy, dm2, sn2);
01921     fTrueEnergyOsc_FD->
01922       SetBinContent(i,fTrueEnergyEffCor_FD->GetBinContent(i)*oscProb);
01923     fTrueEnergyOsc_FD->
01924       SetBinError(i,fTrueEnergyEffCor_FD->GetBinError(i)*oscProb);
01925   }
01926 }
01927 
01928 // //____________________________________________________________________72
01929 // void NuMatrixMethod::OscillateFD(const Double_t dm2,
01930 //                               const Double_t sn2)
01931 // {
01932 //   //8: Oscillate FD spectrum:
01933 //   for(int i=1;i<=fTrueEnergyOsc_FD->GetNbinsX();i++) {
01934 //     Double_t energy = fTrueEnergyOsc_FD->GetBinCenter(i);
01935 //     Double_t oscProb = NuUtilities::OscillationWeight(energy, dm2, sn2);
01936 //     fTrueEnergyOsc_FD->
01937 //       SetBinContent(i,fTrueEnergyEffCor_FD->GetBinContent(i)*oscProb);
01938 //     fTrueEnergyOsc_FD->
01939 //       SetBinError(i,fTrueEnergyEffCor_FD->GetBinError(i)*oscProb);
01940 //   }
01941 // }
01942 
01943 //____________________________________________________________________72
01944 void NuMatrixMethod::DecayFD(const Double_t alpha,
01945                              const Double_t sn2)
01946 {
01947   //8: decay FD spectrum:
01948   for(int i=1;i<=fTrueEnergyOsc_FD->GetNbinsX();i++) {
01949     Double_t energy = fTrueEnergyOsc_FD->GetBinCenter(i);
01950     Double_t decayProb =
01951       TMath::Power
01952       (sn2 + (1.0-sn2)*exp(-(alpha*fFDDistance/Munits::km)/(2*energy)),
01953        2);
01954     fTrueEnergyOsc_FD->
01955       SetBinContent(i,fTrueEnergyEffCor_FD->GetBinContent(i)*decayProb);
01956     fTrueEnergyOsc_FD->
01957       SetBinError(i,fTrueEnergyEffCor_FD->GetBinError(i)*decayProb);
01958   }
01959 }
01960 
01961 //____________________________________________________________________72
01962 void NuMatrixMethod::DecohereFD(const Double_t mu2,
01963                                 const Double_t sn2)
01964 {
01965   //8: Oscillate FD spectrum:
01966   for(int i=1;i<=fTrueEnergyOsc_FD->GetNbinsX();i++) {
01967     Double_t energy = fTrueEnergyOsc_FD->GetBinCenter(i);
01968     Double_t decoherenceProb =
01969       1.0 - (sn2/2)*
01970       (1 - exp(-(mu2*fFDDistance/Munits::km)/(2*energy)));
01971     fTrueEnergyOsc_FD->
01972       SetBinContent(i,fTrueEnergyEffCor_FD->GetBinContent(i)*decoherenceProb);
01973     fTrueEnergyOsc_FD->
01974       SetBinError(i,fTrueEnergyEffCor_FD->GetBinError(i)*decoherenceProb);
01975   }
01976 }
01977 
01978 //____________________________________________________________________72
01979 const TH1D NuMatrixMethod::TrueToReco(const TH1D& inputSpectrum,
01980                                       const TH2D& recoVsTrueHistogram) const
01981 {
01982   TH1D outputSpectrum(inputSpectrum);
01983   outputSpectrum.Reset();
01984 
01985   //working space:
01986   Double_t *val = new Double_t[outputSpectrum.GetNbinsX()+1];
01987   Double_t *valerr = new Double_t[outputSpectrum.GetNbinsX()+1];
01988   
01989   //9: Convert to reco:
01990   for(int i=1;i<=outputSpectrum.GetNbinsX();i++){
01991     val[i-1] = 0; valerr[i-1] = 0;
01992   }
01993   for(int i=1;i<=inputSpectrum.GetNbinsX();i++){ //loop over true
01994     for(int j=1;j<=outputSpectrum.GetNbinsX()+1;j++){ //loop over reco
01995       val[j-1] += ( inputSpectrum.GetBinContent(i) *
01996                     recoVsTrueHistogram.GetBinContent(i,j));
01997       
01998       Double_t error = 0;
01999       if(inputSpectrum.GetBinContent(i)>0 &&
02000          recoVsTrueHistogram.GetBinContent(i,j)>0) {
02001         error = TMath::Power(inputSpectrum.GetBinError(i)/
02002                              inputSpectrum.GetBinContent(i),2);
02003         error += TMath::Power(recoVsTrueHistogram.GetBinError(i,j)/
02004                               recoVsTrueHistogram.GetBinContent(i,j),2);
02005         error *= TMath::Power(inputSpectrum.GetBinContent(i) * 
02006                               recoVsTrueHistogram.GetBinContent(i,j),2);
02007       }
02008       valerr[j-1] += error;
02009       
02010     }
02011   }
02012   for(int i=1;i<=outputSpectrum.GetNbinsX()+1;i++) {
02013     outputSpectrum.SetBinContent(i,val[i-1]);
02014     if(valerr[i-1]>0) outputSpectrum.SetBinError(i,TMath::Sqrt(valerr[i-1]));
02015     else outputSpectrum.SetBinError(i,0);
02016   }
02017 
02018   return outputSpectrum;
02019 }
02020 
02021 //____________________________________________________________________72
02022 void NuMatrixMethod::TrueToRecoFD()
02023 {
02024   //working space:
02025   Double_t *val = new Double_t[fRecoEnergyOsc_FD->GetNbinsX()+1];
02026   Double_t *valerr = new Double_t[fRecoEnergyOsc_FD->GetNbinsX()+1];
02027   
02028   //9: Convert to reco:
02029   for(int i=1;i<=fRecoEnergyOsc_FD->GetNbinsX();i++){
02030     val[i-1] = 0; valerr[i-1] = 0;
02031   }
02032   for(int i=1;i<=fTrueEnergyOsc_FD->GetNbinsX();i++){ //loop over true
02033     for(int j=1;j<=fRecoEnergyOsc_FD->GetNbinsX()+1;j++){ //loop over reco
02034       val[j-1] += ( fTrueEnergyOsc_FD->GetBinContent(i) *
02035                     fRecoVsTrueEnergy_FD->GetBinContent(i,j));
02036       
02037       Double_t error = 0;
02038       if(fTrueEnergyOsc_FD->GetBinContent(i)>0 &&
02039          fRecoVsTrueEnergy_FD->GetBinContent(i,j)>0) {
02040         error = TMath::Power(fTrueEnergyOsc_FD->GetBinError(i)/
02041                              fTrueEnergyOsc_FD->GetBinContent(i),2);
02042         error += TMath::Power(fRecoVsTrueEnergy_FD->GetBinError(i,j)/
02043                               fRecoVsTrueEnergy_FD->GetBinContent(i,j),2);
02044         error *= TMath::Power(fTrueEnergyOsc_FD->GetBinContent(i) * 
02045                               fRecoVsTrueEnergy_FD->GetBinContent(i,j),2);
02046       }
02047       valerr[j-1] += error;
02048       
02049     }
02050   }
02051   for(int i=1;i<=fRecoEnergyOsc_FD->GetNbinsX()+1;i++) {
02052     fRecoEnergyOsc_FD->SetBinContent(i,val[i-1]);
02053     if(valerr[i-1]>0) fRecoEnergyOsc_FD->SetBinError(i,TMath::Sqrt(valerr[i-1]));
02054     else fRecoEnergyOsc_FD->SetBinError(i,0);
02055   }
02056 }
02057 
02058 //____________________________________________________________________72
02059 void NuMatrixMethod::PurityCorrectFDBackgroundNoOsc()
02060 {
02061   //10: Correct for purity (need to use noosc histogram to add 
02062   //    back in background otherwise it will be underestimated!):
02063   // THIS ONLY WORKS UNDER THE ASSUMPTION THAT YOUR BACKGROUND
02064   // DOES NOT OSCILLATE!
02065   // Background = ND, nutau CC, numubar CC, nue CC
02066   
02067   if (NuMMExtrapolation::kModularNoChargeCutFit == fextrpScheme ||
02068       NuMMExtrapolation::kModularPRLCCFit == fextrpScheme){
02069     for(int i=1;i<=fRecoEnergyPred_FD->GetNbinsX()+1;i++){
02070       fRecoEnergyPred_FD->
02071         SetBinContent(i,
02072                       fRecoEnergyOsc_FD->GetBinContent(i) +
02073                       fRecoUnoscNCBackground_FD->GetBinContent(i)
02074                       );
02075       Double_t error = 0.0;
02076       error +=
02077         TMath::Power(fRecoEnergyOsc_FD->GetBinError(i),2);
02078       error +=
02079         TMath::Power(fRecoUnoscNCBackground_FD->GetBinError(i),2);
02080       if (error > 0){
02081         fRecoEnergyPred_FD->SetBinError(i, TMath::Sqrt(error));
02082       }
02083       else{
02084         fRecoEnergyPred_FD->SetBinError(i, 0);
02085       }
02086     }
02087   }
02088   else{
02089     for(int i=1;i<=fRecoEnergyPred_FD->GetNbinsX()+1;i++){
02090       fRecoEnergyPred_FD->
02091         SetBinContent(i,fRecoEnergyOsc_FD->GetBinContent(i) +
02092                       fRecoEnergyNoOscPred_FD->GetBinContent(i) *
02093                       (1. - fPurity_FD->GetBinContent(i)));
02094       
02095       
02096       Double_t error = 0;
02097       if(fRecoEnergyNoOscPred_FD->GetBinContent(i)>0 &&
02098          (1.-fPurity_FD->GetBinContent(i))>0) {
02099         
02100         Double_t error =
02101           TMath::Power(fRecoEnergyNoOscPred_FD->GetBinError(i)/
02102                        fRecoEnergyNoOscPred_FD->GetBinContent(i),
02103                        2);
02104         error += TMath::Power(fPurity_FD->GetBinError(i) /
02105                               (1. - fPurity_FD->GetBinContent(i)),
02106                               2);
02107         error = error*TMath::Power(fRecoEnergyNoOscPred_FD->GetBinContent(i) *
02108                                    (1. - fPurity_FD->GetBinContent(i)),
02109                                    2);
02110       }
02111       error += TMath::Power(fRecoEnergyOsc_FD->GetBinError(i),2);
02112       if(error>0) fRecoEnergyPred_FD->SetBinError(i,TMath::Sqrt(error));
02113       else fRecoEnergyPred_FD->SetBinError(i,0);   
02114     }
02115   }
02116 }
02117 
02118 //____________________________________________________________________72
02119 const TH1D NuMatrixMethod::AddInImpurity(const TH1D& inputSpectrum,
02120                                          const TH1D& impuritySpectrum) const
02121 {
02122   TH1D outputSpectrum(inputSpectrum);
02123   outputSpectrum.Reset();
02124   
02125   for(int i=1;i<=outputSpectrum.GetNbinsX()+1;i++){
02126     outputSpectrum.
02127       SetBinContent(i,
02128                     inputSpectrum.GetBinContent(i) +
02129                     impuritySpectrum.GetBinContent(i)
02130                     );
02131     Double_t error = 0.0;
02132     error +=
02133       TMath::Power(inputSpectrum.GetBinError(i),2);
02134     error +=
02135       TMath::Power(impuritySpectrum.GetBinError(i),2);
02136     if (error > 0){
02137       outputSpectrum.SetBinError(i, TMath::Sqrt(error));
02138     }
02139     else{
02140       outputSpectrum.SetBinError(i, 0);
02141     }
02142   }
02143   
02144   return outputSpectrum;
02145 }
02146 
02147 //____________________________________________________________________72
02148 void NuMatrixMethod::
02149 PurityCorrectFDBackgroundOscUncombined(Double_t dm2Back,
02150                                         Double_t sn2Back)
02151 {
02152   //10: Correct for purity assuming the background can oscillate.
02153   //Perform reco->true->oscillate->reco on the CC background.
02154 
02155   //working space:
02156   Double_t *val = new Double_t[fNTrueBins+1];
02157   Double_t *valerr = new Double_t[fNTrueBins+1];
02158 
02159   //A: Calculate unoscillated FD CC contamination:
02160   TH1D hRecoUnoscCCBackground_FD
02161     ("hUnoscCCBackground_FD",
02162      "Reco energy unoscillated CC background prediction",
02163      fNRecoBins,fRecoBinEdges);
02164 
02165   for(int i=1;i<=fNRecoBins+1;i++){
02166     hRecoUnoscCCBackground_FD.
02167       SetBinContent(i,
02168                     fRecoEnergyNoOscPred_FD->GetBinContent(i)*
02169                     fCCContamination_FD->GetBinContent(i)
02170                     );
02171 
02172     if(fRecoEnergyNoOscPred_FD->GetBinContent(i)>0 &&
02173        fCCContamination_FD->GetBinContent(i)>0) {
02174       Double_t error =
02175         TMath::Power(fRecoEnergyNoOscPred_FD->GetBinError(i) / 
02176                      fRecoEnergyNoOscPred_FD->GetBinContent(i),2);
02177       error += TMath::Power(fCCContamination_FD->GetBinError(i) / 
02178                             fCCContamination_FD->GetBinContent(i),2);
02179       error =
02180         TMath::Sqrt(error) * hRecoUnoscCCBackground_FD.GetBinContent(i);
02181       hRecoUnoscCCBackground_FD.SetBinError(i,error);   
02182     }
02183     else hRecoUnoscCCBackground_FD.SetBinError(i,0);
02184   }
02185   
02186   //B: Get true energy spectrum of FD unoscillated CC contamination:
02187   TH1D hTrueUnoscCCBackground_FD
02188     ("fTrueUnoscCCBackground_FD",
02189      "True energy unoscillated CC background prediction",
02190      fNTrueBins,fTrueBinEdges);
02191 
02192   for(int i=1;i<=fNTrueBins;i++) { val[i-1] = 0; valerr[i-1] = 0; }
02193   for(int i=1;i<=fNRecoBins+1;i++){
02194     //loop over reco dimension
02195     //include overflow
02196     for(int j=1;j<=fNTrueBins;j++){
02197       //loop over true dimension
02198       val[j-1] += ( hRecoUnoscCCBackground_FD.GetBinContent(i) * 
02199                     fRecoToTrueCCContamination_FD->GetBinContent(j,i) );
02200       Double_t error = 0;
02201       if(hRecoUnoscCCBackground_FD.GetBinContent(i)>0 &&
02202          fRecoToTrueCCContamination_FD->GetBinContent(j,i)>0) {
02203         error =
02204           TMath::Power(hRecoUnoscCCBackground_FD.GetBinError(i)/
02205                        hRecoUnoscCCBackground_FD.GetBinContent(i),2);
02206         error +=
02207           TMath::Power(fRecoToTrueCCContamination_FD->GetBinError(j,i)/
02208                        fRecoToTrueCCContamination_FD->GetBinContent(j,i),2);
02209         error *=
02210           TMath::Power(hRecoUnoscCCBackground_FD.GetBinContent(i) * 
02211                        fRecoToTrueCCContamination_FD->GetBinContent(j,i),2);
02212       }
02213       valerr[j-1] += error;
02214     }
02215   }
02216   for(int i=1;i<=fNTrueBins;i++) {
02217     hTrueUnoscCCBackground_FD.SetBinContent(i,val[i-1]);
02218     hTrueUnoscCCBackground_FD.SetBinError(i,TMath::Sqrt(valerr[i-1]));
02219   }
02220 
02221   //C: Oscillated CC background:
02222   TH1D hTrueOscCCBackground_FD
02223     ("hTrueOscCCBackground_FD",
02224      "True energy oscillated CC background prediction",
02225      fNTrueBins,fTrueBinEdges);
02226   for(int i=1;i<=fNTrueBins;i++) {
02227     Double_t energy = hTrueOscCCBackground_FD.GetBinCenter(i);
02228     Double_t oscProb = NuUtilities::OscillationWeight(energy, dm2Back, sn2Back);
02229     hTrueOscCCBackground_FD.
02230       SetBinContent(i,hTrueUnoscCCBackground_FD.GetBinContent(i)*oscProb);
02231     hTrueOscCCBackground_FD.
02232       SetBinError(i,hTrueUnoscCCBackground_FD.GetBinError(i)*oscProb);
02233   }
02234 
02235   //D: True->Reco CC background:
02236   TH1D hRecoOscCCBackground_FD
02237     ("hRecoOscCCBackground_FD",
02238      "Reco energy oscillated CC background prediction",
02239      fNRecoBins,fRecoBinEdges);
02240   
02241   for(int i=1;i<=fNRecoBins;i++) { val[i-1] = 0; valerr[i-1] = 0; }
02242   for(int i=1;i<=fNTrueBins;i++){ //loop over true
02243     for(int j=1;j<=fNRecoBins+1;j++){ //loop over reco
02244       val[j-1] += ( hTrueOscCCBackground_FD.GetBinContent(i) *
02245                     fTrueToRecoCCContamination_FD->GetBinContent(i,j));
02246       
02247       Double_t error = 0;
02248       if(hTrueOscCCBackground_FD.GetBinContent(i)>0 &&
02249          fTrueToRecoCCContamination_FD->GetBinContent(i,j)>0) {
02250         error = TMath::Power(hTrueOscCCBackground_FD.GetBinError(i)/
02251                              hTrueOscCCBackground_FD.GetBinContent(i),2);
02252         error += TMath::Power(fTrueToRecoCCContamination_FD->GetBinError(i,j)/
02253                               fTrueToRecoCCContamination_FD->GetBinContent(i,j),2);
02254         error *= TMath::Power(hTrueOscCCBackground_FD.GetBinContent(i) * 
02255                               fTrueToRecoCCContamination_FD->GetBinContent(i,j),2);
02256       }
02257       valerr[j-1] += error;
02258       
02259     }
02260   }
02261   for(int i=1;i<=fNRecoBins+1;i++) {
02262     hRecoOscCCBackground_FD.SetBinContent(i,val[i-1]);
02263     if(valerr[i-1]>0) hRecoOscCCBackground_FD.SetBinError(i,TMath::Sqrt(valerr[i-1]));
02264     else hRecoOscCCBackground_FD.SetBinError(i,0);
02265   }
02266 
02267   //E: Calculate unoscillated FD NC contamination:
02268   /*
02269   TH1D hRecoUnoscNCBackground_FD
02270     ("hUnoscNCBackground_FD",
02271      "Reco energy unoscillated NC background prediction",
02272      fNRecoBins,fRecoBinEdges);
02273 
02274   for(int i=1;i<=fNRecoBins+1;i++){
02275     fRecoUnoscNCBackground_FD->
02276       SetBinContent(i,
02277                     fRecoEnergyNoOscPred_FD->GetBinContent(i)*
02278                     fNCContamination_FD->GetBinContent(i)
02279                     );
02280 
02281     if(fRecoEnergyNoOscPred_FD->GetBinContent(i)>0 &&
02282        fNCContamination_FD->GetBinContent(i)>0) {
02283       Double_t error =
02284         TMath::Power(fRecoEnergyNoOscPred_FD->GetBinError(i) / 
02285                      fRecoEnergyNoOscPred_FD->GetBinContent(i),2);
02286       error += TMath::Power(fNCContamination_FD->GetBinError(i) / 
02287                             fNCContamination_FD->GetBinContent(i),2);
02288       error =
02289         TMath::Sqrt(error) * fRecoUnoscNCBackground_FD->GetBinContent(i);
02290       fRecoUnoscNCBackground_FD->SetBinError(i,error);  
02291     }
02292     else fRecoUnoscNCBackground_FD->SetBinError(i,0);
02293   }
02294   */
02295   //F: Add the NC & oscillated CC backgrounds to the FD prediction:
02296   for(int i=1;i<=fNRecoBins+1;i++){
02297     fRecoEnergyPred_FD->
02298       SetBinContent(i,
02299                     fRecoEnergyOsc_FD->GetBinContent(i) +
02300                     fRecoUnoscNCBackground_FD->GetBinContent(i) +
02301                     hRecoOscCCBackground_FD.GetBinContent(i)
02302                     );
02303     Double_t error = 0.0;
02304     error +=
02305       TMath::Power(fRecoEnergyOsc_FD->GetBinError(i),2);
02306     error +=
02307       TMath::Power(fRecoUnoscNCBackground_FD->GetBinError(i),2);
02308     error +=
02309       TMath::Power(hRecoOscCCBackground_FD.GetBinError(i),2);
02310     if (error > 0){
02311       fRecoEnergyPred_FD->SetBinError(i, TMath::Sqrt(error));
02312     }
02313     else{
02314       fRecoEnergyPred_FD->SetBinError(i, 0);
02315     }
02316   }
02317 }
02318 
02319 //____________________________________________________________________72
02320 void NuMatrixMethod::
02321 SetFDCCTrueUnoscBackground(const TH1D& hFDCCTrueUnoscBack)
02322 {
02323   if (fSuppliedTrueUnoscCCBackground_FD){
02324     delete fSuppliedTrueUnoscCCBackground_FD;
02325     fSuppliedTrueUnoscCCBackground_FD = 0;
02326   }
02327   fSuppliedTrueUnoscCCBackground_FD = new TH1D(hFDCCTrueUnoscBack);
02328   fSuppliedTrueUnoscCCBackground_FD->SetDirectory(0);
02329   return;
02330 }
02331 
02332 //____________________________________________________________________72
02333 void NuMatrixMethod::
02334 PurityCorrectFDBackgroundOscCombined(Double_t dm2Back,
02335                                      Double_t sn2Back)
02336 {
02337   //10: Correct for purity assuming the background can oscillate.
02338   //Use true CC background calculated from the extrapolation of the
02339   //other spectrum.
02340 
02341   //working space:
02342   Double_t *val = new Double_t[fNRecoBins+1];
02343   Double_t *valerr = new Double_t[fNRecoBins+1];
02344 
02345   //C: Oscillated CC background:
02346   TH1D hTrueOscCCBackground_FD
02347     ("hTrueOscCCBackground_FD",
02348      "True energy oscillated CC background prediction",
02349      fNTrueBins,fTrueBinEdges);
02350   for(int i=1;i<=fNTrueBins;i++) {
02351     Double_t energy = hTrueOscCCBackground_FD.GetBinCenter(i);
02352     Double_t oscProb = NuUtilities::OscillationWeight(energy, dm2Back, sn2Back);
02353     hTrueOscCCBackground_FD.
02354       SetBinContent(i,fSuppliedTrueUnoscCCBackground_FD->GetBinContent(i)*oscProb);
02355     hTrueOscCCBackground_FD.
02356       SetBinError(i,fSuppliedTrueUnoscCCBackground_FD->GetBinError(i)*oscProb);
02357   }
02358 
02359   //D: True->Reco CC background:
02360   TH1D hRecoOscCCBackground_FD
02361     ("hRecoOscCCBackground_FD",
02362      "Reco energy oscillated CC background prediction",
02363      fNRecoBins,fRecoBinEdges);
02364   
02365   for(int i=1;i<=fNRecoBins;i++) { val[i-1] = 0; valerr[i-1] = 0; }
02366   for(int i=1;i<=fNTrueBins;i++){ //loop over true
02367     for(int j=1;j<=fNRecoBins+1;j++){ //loop over reco
02368       val[j-1] += ( hTrueOscCCBackground_FD.GetBinContent(i) *
02369                     fTrueToRecoCCContamination_FD->GetBinContent(i,j));
02370       
02371       Double_t error = 0;
02372       if(hTrueOscCCBackground_FD.GetBinContent(i)>0 &&
02373          fTrueToRecoCCContamination_FD->GetBinContent(i,j)>0) {
02374         error = TMath::Power(hTrueOscCCBackground_FD.GetBinError(i)/
02375                              hTrueOscCCBackground_FD.GetBinContent(i),2);
02376         error += TMath::Power(fTrueToRecoCCContamination_FD->GetBinError(i,j)/
02377                               fTrueToRecoCCContamination_FD->GetBinContent(i,j),2);
02378         error *= TMath::Power(hTrueOscCCBackground_FD.GetBinContent(i) * 
02379                               fTrueToRecoCCContamination_FD->GetBinContent(i,j),2);
02380       }
02381       valerr[j-1] += error;
02382       
02383     }
02384   }
02385   for(int i=1;i<=fNRecoBins+1;i++) {
02386     hRecoOscCCBackground_FD.SetBinContent(i,val[i-1]);
02387     if(valerr[i-1]>0) hRecoOscCCBackground_FD.SetBinError(i,TMath::Sqrt(valerr[i-1]));
02388     else hRecoOscCCBackground_FD.SetBinError(i,0);
02389   }
02390 
02391   //E: Calculate unoscillated FD NC contamination:
02392   /*
02393     //moved to CalculateNCContamination()
02394   TH1D hRecoUnoscNCBackground_FD
02395     ("hUnoscNCBackground_FD",
02396      "Reco energy unoscillated NC background prediction",
02397      fNRecoBins,fRecoBinEdges);
02398 
02399   for(int i=1;i<=fNRecoBins+1;i++){
02400     fRecoUnoscNCBackground_FD->
02401       SetBinContent(i,
02402                     fRecoEnergyNoOscPred_FD->GetBinContent(i)*
02403                     fNCContamination_FD->GetBinContent(i)
02404                     );
02405 
02406     if(fRecoEnergyNoOscPred_FD->GetBinContent(i)>0 &&
02407        fNCContamination_FD->GetBinContent(i)>0) {
02408       Double_t error =
02409         TMath::Power(fRecoEnergyNoOscPred_FD->GetBinError(i) / 
02410                      fRecoEnergyNoOscPred_FD->GetBinContent(i),2);
02411       error += TMath::Power(fNCContamination_FD->GetBinError(i) / 
02412                             fNCContamination_FD->GetBinContent(i),2);
02413       error =
02414         TMath::Sqrt(error) * fRecoUnoscNCBackground_FD->GetBinContent(i);
02415       fRecoUnoscNCBackground_FD->SetBinError(i,error);  
02416     }
02417     else fRecoUnoscNCBackground_FD->SetBinError(i,0);
02418   }
02419   */
02420 
02421   //F: Add the NC & oscillated CC backgrounds to the FD prediction:
02422   for(int i=1;i<=fNRecoBins+1;i++){
02423     fRecoEnergyPred_FD->
02424       SetBinContent(i,
02425                     fRecoEnergyOsc_FD->GetBinContent(i) +
02426                     fRecoUnoscNCBackground_FD->GetBinContent(i) +
02427                     hRecoOscCCBackground_FD.GetBinContent(i)
02428                     );
02429     Double_t error = 0.0;
02430     error +=
02431       TMath::Power(fRecoEnergyOsc_FD->GetBinError(i),2);
02432     error +=
02433       TMath::Power(fRecoUnoscNCBackground_FD->GetBinError(i),2);
02434     error +=
02435       TMath::Power(hRecoOscCCBackground_FD.GetBinError(i),2);
02436     if (error > 0){
02437       fRecoEnergyPred_FD->SetBinError(i, TMath::Sqrt(error));
02438     }
02439     else{
02440       fRecoEnergyPred_FD->SetBinError(i, 0);
02441     }
02442   }
02443 }
02444 
02445 //____________________________________________________________________72
02446 void NuMatrixMethod::
02447 PurityCorrectFDBackgroundDecayCombined(Double_t alphaBack,
02448                                        Double_t sn2Back)
02449 {
02450   //10: Correct for purity assuming the background can oscillate.
02451   //Use true CC background calculated from the extrapolation of the
02452   //other spectrum.
02453 
02454   //working space:
02455   Double_t *val = new Double_t[fNRecoBins+1];
02456   Double_t *valerr = new Double_t[fNRecoBins+1];
02457 
02458   //C: Oscillated CC background:
02459   TH1D hTrueOscCCBackground_FD
02460     ("hTrueOscCCBackground_FD",
02461      "True energy oscillated CC background prediction",
02462      fNTrueBins,fTrueBinEdges);
02463   for(int i=1;i<=fNTrueBins;i++) {
02464     Double_t energy = hTrueOscCCBackground_FD.GetBinCenter(i);
02465     Double_t oscProb =
02466       TMath::Power
02467       (sn2Back + (1.0-sn2Back)*exp(-(alphaBack*fFDDistance/Munits::km)/(2*energy)),
02468        2);
02469     hTrueOscCCBackground_FD.
02470       SetBinContent(i,fSuppliedTrueUnoscCCBackground_FD->GetBinContent(i)*oscProb);
02471     hTrueOscCCBackground_FD.
02472       SetBinError(i,fSuppliedTrueUnoscCCBackground_FD->GetBinError(i)*oscProb);
02473   }
02474 
02475   //D: True->Reco CC background:
02476   TH1D hRecoOscCCBackground_FD
02477     ("hRecoOscCCBackground_FD",
02478      "Reco energy oscillated CC background prediction",
02479      fNRecoBins,fRecoBinEdges);
02480   
02481   for(int i=1;i<=fNRecoBins;i++) { val[i-1] = 0; valerr[i-1] = 0; }
02482   for(int i=1;i<=fNTrueBins;i++){ //loop over true
02483     for(int j=1;j<=fNRecoBins+1;j++){ //loop over reco
02484       val[j-1] += ( hTrueOscCCBackground_FD.GetBinContent(i) *
02485                     fTrueToRecoCCContamination_FD->GetBinContent(i,j));
02486       
02487       Double_t error = 0;
02488       if(hTrueOscCCBackground_FD.GetBinContent(i)>0 &&
02489          fTrueToRecoCCContamination_FD->GetBinContent(i,j)>0) {
02490         error = TMath::Power(hTrueOscCCBackground_FD.GetBinError(i)/
02491                              hTrueOscCCBackground_FD.GetBinContent(i),2);
02492         error += TMath::Power(fTrueToRecoCCContamination_FD->GetBinError(i,j)/
02493                               fTrueToRecoCCContamination_FD->GetBinContent(i,j),2);
02494         error *= TMath::Power(hTrueOscCCBackground_FD.GetBinContent(i) * 
02495                               fTrueToRecoCCContamination_FD->GetBinContent(i,j),2);
02496       }
02497       valerr[j-1] += error;
02498       
02499     }
02500   }
02501   for(int i=1;i<=fNRecoBins+1;i++) {
02502     hRecoOscCCBackground_FD.SetBinContent(i,val[i-1]);
02503     if(valerr[i-1]>0) hRecoOscCCBackground_FD.SetBinError(i,TMath::Sqrt(valerr[i-1]));
02504     else hRecoOscCCBackground_FD.SetBinError(i,0);
02505   }
02506 
02507   //F: Add the NC & oscillated CC backgrounds to the FD prediction:
02508   for(int i=1;i<=fNRecoBins+1;i++){
02509     fRecoEnergyPred_FD->
02510       SetBinContent(i,
02511                     fRecoEnergyOsc_FD->GetBinContent(i) +
02512                     fRecoUnoscNCBackground_FD->GetBinContent(i) +
02513                     hRecoOscCCBackground_FD.GetBinContent(i)
02514                     );
02515     Double_t error = 0.0;
02516     error +=
02517       TMath::Power(fRecoEnergyOsc_FD->GetBinError(i),2);
02518     error +=
02519       TMath::Power(fRecoUnoscNCBackground_FD->GetBinError(i),2);
02520     error +=
02521       TMath::Power(hRecoOscCCBackground_FD.GetBinError(i),2);
02522     if (error > 0){
02523       fRecoEnergyPred_FD->SetBinError(i, TMath::Sqrt(error));
02524     }
02525     else{
02526       fRecoEnergyPred_FD->SetBinError(i, 0);
02527     }
02528   }
02529 }
02530 
02531 //____________________________________________________________________72
02532 void NuMatrixMethod::
02533 PurityCorrectFDBackgroundDecohereCombined(Double_t mu2Back,
02534                                           Double_t sn2Back)
02535 {
02536   //10: Correct for purity assuming the background can oscillate.
02537   //Use true CC background calculated from the extrapolation of the
02538   //other spectrum.
02539 
02540   //working space:
02541   Double_t *val = new Double_t[fNRecoBins+1];
02542   Double_t *valerr = new Double_t[fNRecoBins+1];
02543 
02544   //C: Oscillated CC background:
02545   TH1D hTrueOscCCBackground_FD
02546     ("hTrueOscCCBackground_FD",
02547      "True energy oscillated CC background prediction",
02548      fNTrueBins,fTrueBinEdges);
02549   for(int i=1;i<=fNTrueBins;i++) {
02550     Double_t energy = hTrueOscCCBackground_FD.GetBinCenter(i);
02551     Double_t oscProb =
02552       1.0 - (sn2Back/2)*
02553       (1 - exp(-(mu2Back*fFDDistance/Munits::km)*(2*energy)));
02554     hTrueOscCCBackground_FD.
02555       SetBinContent(i,fSuppliedTrueUnoscCCBackground_FD->GetBinContent(i)*oscProb);
02556     hTrueOscCCBackground_FD.
02557       SetBinError(i,fSuppliedTrueUnoscCCBackground_FD->GetBinError(i)*oscProb);
02558   }
02559 
02560   //D: True->Reco CC background:
02561   TH1D hRecoOscCCBackground_FD
02562     ("hRecoOscCCBackground_FD",
02563      "Reco energy oscillated CC background prediction",
02564      fNRecoBins,fRecoBinEdges);
02565   
02566   for(int i=1;i<=fNRecoBins;i++) { val[i-1] = 0; valerr[i-1] = 0; }
02567   for(int i=1;i<=fNTrueBins;i++){ //loop over true
02568     for(int j=1;j<=fNRecoBins+1;j++){ //loop over reco
02569       val[j-1] += ( hTrueOscCCBackground_FD.GetBinContent(i) *
02570                     fTrueToRecoCCContamination_FD->GetBinContent(i,j));
02571       
02572       Double_t error = 0;
02573       if(hTrueOscCCBackground_FD.GetBinContent(i)>0 &&
02574          fTrueToRecoCCContamination_FD->GetBinContent(i,j)>0) {
02575         error = TMath::Power(hTrueOscCCBackground_FD.GetBinError(i)/
02576                              hTrueOscCCBackground_FD.GetBinContent(i),2);
02577         error += TMath::Power(fTrueToRecoCCContamination_FD->GetBinError(i,j)/
02578                               fTrueToRecoCCContamination_FD->GetBinContent(i,j),2);
02579         error *= TMath::Power(hTrueOscCCBackground_FD.GetBinContent(i) * 
02580                               fTrueToRecoCCContamination_FD->GetBinContent(i,j),2);
02581       }
02582       valerr[j-1] += error;
02583       
02584     }
02585   }
02586   for(int i=1;i<=fNRecoBins+1;i++) {
02587     hRecoOscCCBackground_FD.SetBinContent(i,val[i-1]);
02588     if(valerr[i-1]>0) hRecoOscCCBackground_FD.SetBinError(i,TMath::Sqrt(valerr[i-1]));
02589     else hRecoOscCCBackground_FD.SetBinError(i,0);
02590   }
02591 
02592   //F: Add the NC & oscillated CC backgrounds to the FD prediction:
02593   for(int i=1;i<=fNRecoBins+1;i++){
02594     fRecoEnergyPred_FD->
02595       SetBinContent(i,
02596                     fRecoEnergyOsc_FD->GetBinContent(i) +
02597                     fRecoUnoscNCBackground_FD->GetBinContent(i) +
02598                     hRecoOscCCBackground_FD.GetBinContent(i)
02599                     );
02600     Double_t error = 0.0;
02601     error +=
02602       TMath::Power(fRecoEnergyOsc_FD->GetBinError(i),2);
02603     error +=
02604       TMath::Power(fRecoUnoscNCBackground_FD->GetBinError(i),2);
02605     error +=
02606       TMath::Power(hRecoOscCCBackground_FD.GetBinError(i),2);
02607     if (error > 0){
02608       fRecoEnergyPred_FD->SetBinError(i, TMath::Sqrt(error));
02609     }
02610     else{
02611       fRecoEnergyPred_FD->SetBinError(i, 0);
02612     }
02613   }
02614 }
02615 
02616 //____________________________________________________________________72
02617 void NuMatrixMethod::ResetUnoscHistograms()
02618 {
02619   fRecoEnergyPurCor_ND->Reset();
02620   fTrueEnergyPurCor_ND->Reset();
02621   fTrueEnergyEffCor_ND->Reset();
02622   fTrueEnergyFlux_ND->Reset();
02623   fTrueEnergyMatrix_FD->Reset();
02624   fTrueEnergyCC_FD->Reset();
02625   fTrueEnergyEffCor_FD->Reset();
02626   fRecoEnergyNoOsc_FD->Reset();
02627   fRecoEnergyNoOscPred_FD->Reset();
02628   return;
02629 }
02630  
02631 //____________________________________________________________________72
02632 void NuMatrixMethod::PurityCorrectND()
02633 { 
02634   //1: Correct ND reco spectrum for purity
02635   for(int i=1;i<=fNRecoBins+1;i++){
02636     fRecoEnergyPurCor_ND->
02637       SetBinContent(i,fRecoEnergyMeas_ND->GetBinContent(i) *
02638                     fPurity_ND->GetBinContent(i));
02639     if(fRecoEnergyMeas_ND->GetBinContent(i)>0 &&
02640        fPurity_ND->GetBinContent(i)>0) {
02641       Double_t error =
02642         TMath::Power(fRecoEnergyMeas_ND->GetBinError(i) / 
02643                      fRecoEnergyMeas_ND->GetBinContent(i),2);
02644       error += TMath::Power(fPurity_ND->GetBinError(i) / 
02645                             fPurity_ND->GetBinContent(i),2);
02646       error =
02647         TMath::Sqrt(error) * fRecoEnergyPurCor_ND->GetBinContent(i);
02648       fRecoEnergyPurCor_ND->SetBinError(i,error);       
02649     }
02650     else fRecoEnergyPurCor_ND->SetBinError(i,0);
02651   }
02652   return;
02653 }
02654 
02655 //____________________________________________________________________72
02656 void NuMatrixMethod::RecoToTrueND()
02657 { 
02658   //working space:
02659   Double_t *val = new Double_t[fNTrueBins+1];
02660   Double_t *valerr = new Double_t[fNTrueBins+1];
02661 
02662   //2: Convert ND spectrum to true energies:
02663   for(int i=1;i<=fNTrueBins;i++) { val[i-1] = 0; valerr[i-1] = 0; }
02664   for(int i=1;i<=fNTrueBins;i++){
02665     //loop over reco dimension
02666     //include overflow
02667     for(int j=1;j<=fNRecoBins;j++){
02668       //loop over true dimension
02669       val[j-1] += ( fRecoEnergyPurCor_ND->GetBinContent(i) * 
02670                     fRecoVsTrueEnergy_ND->GetBinContent(j,i) );
02671       Double_t error = 0;
02672       if(fRecoEnergyPurCor_ND->GetBinContent(i)>0 &&
02673          fRecoVsTrueEnergy_ND->GetBinContent(j,i)>0) {
02674         error =
02675           TMath::Power(fRecoEnergyPurCor_ND->GetBinError(i)/
02676                        fRecoEnergyPurCor_ND->GetBinContent(i),2);
02677         error +=
02678           TMath::Power(fRecoVsTrueEnergy_ND->GetBinError(j,i)/
02679                        fRecoVsTrueEnergy_ND->GetBinContent(j,i),2);
02680         error *=
02681           TMath::Power(fRecoEnergyPurCor_ND->GetBinContent(i) * 
02682                        fRecoVsTrueEnergy_ND->GetBinContent(j,i),2);
02683       }
02684       valerr[j-1] += error;
02685     }
02686   }
02687   for(int i=1;i<=fNTrueBins;i++) {
02688     fTrueEnergyPurCor_ND->SetBinContent(i,val[i-1]);
02689     fTrueEnergyPurCor_ND->SetBinError(i,TMath::Sqrt(valerr[i-1]));
02690   }
02691   return;
02692 }
02693 
02694 //____________________________________________________________________72
02695 void NuMatrixMethod::EfficiencyCorrectND()
02696 {
02697   //3: Correct ND true energy spectrum for efficiencies:
02698   for(int i=1;i<=fNTrueBins;i++) {
02699     if(fEfficiency_ND->GetBinContent(i)>0 &&
02700        fTrueEnergyPurCor_ND->GetBinContent(i)>0) {
02701       fTrueEnergyEffCor_ND->
02702         SetBinContent(i,
02703                       fTrueEnergyPurCor_ND->GetBinContent(i) /
02704                       fEfficiency_ND->GetBinContent(i));        
02705       Double_t error =
02706         TMath::Power(fTrueEnergyPurCor_ND->GetBinError(i)/
02707                      fTrueEnergyPurCor_ND->GetBinContent(i),2);
02708       error += TMath::Power(fEfficiency_ND->GetBinError(i)/
02709                             fEfficiency_ND->GetBinContent(i),2);
02710       error =
02711         TMath::Sqrt(error) * fTrueEnergyEffCor_ND->GetBinContent(i);
02712       fTrueEnergyEffCor_ND->SetBinError(i,error);
02713     }
02714     else {
02715       fTrueEnergyEffCor_ND->SetBinContent(i,0);
02716       fTrueEnergyEffCor_ND->SetBinError(i,0);
02717     }
02718   }
02719   return;
02720 }
02721 
02722 //____________________________________________________________________72
02723 void NuMatrixMethod::XSecCorrectND()
02724 {
02725   //4: Get ND neutrino flux:
02726   if (fDoXSecStep){
02727     for(int i=1;i<=fNTrueBins;i++) {
02728       fTrueEnergyFlux_ND->
02729         SetBinContent(i,fTrueEnergyEffCor_ND->GetBinContent(i) *
02730                       (fFluxPoT/fNDPoT) / 
02731                       ( fNDFidMass *
02732                         fXSec_CC_Graph->Eval(fTrueEnergyFlux_ND->
02733                                              GetBinCenter(i),0,"") ) ); 
02734       fTrueEnergyFlux_ND->
02735         SetBinError(i,fTrueEnergyEffCor_ND->GetBinError(i) *
02736                     (fFluxPoT/fNDPoT) /
02737                     ( fNDFidMass *
02738                       fXSec_CC_Graph->Eval(fTrueEnergyFlux_ND->
02739                                            GetBinCenter(i),0,"") ) );
02740     }
02741   }
02742   else{
02743     for(int i=1;i<=fNTrueBins;i++) {
02744       fTrueEnergyFlux_ND->
02745         SetBinContent(i,fTrueEnergyEffCor_ND->GetBinContent(i) *
02746                       (fFluxPoT/fNDPoT) / 
02747                       ( fNDFidMass ) ); 
02748       fTrueEnergyFlux_ND->
02749         SetBinError(i,fTrueEnergyEffCor_ND->GetBinError(i) *
02750                     (fFluxPoT/fNDPoT) /
02751                     ( fNDFidMass ) );
02752     }
02753   }
02754   return;
02755 }
02756  
02757 //____________________________________________________________________72
02758 void NuMatrixMethod::ExtrapolateNDToFD()
02759 {
02760   //working space:
02761   Double_t *val = new Double_t[fNTrueBins+1];
02762   Double_t *valerr = new Double_t[fNTrueBins+1];
02763 
02764   //5: Get FD spectrum:
02765   for(int i=1;i<=fNTrueBins;i++) { val[i-1] = 0; valerr[i-1] = 0; }
02766   for(int i=1;i<=fNTrueBins;i++) { //loop over ND bins
02767     for(int j=1;j<=fNTrueBins;j++) { //loop over FD bins
02768       val[j-1] += ( fTrueEnergyFlux_ND->GetBinContent(i) *
02769                     fFDVsNDMatrixRW->GetBinContent(i,j));
02770       Double_t error = 0;
02771       if(fTrueEnergyFlux_ND->GetBinContent(i)>0 &&
02772          fFDVsNDMatrixRW->GetBinContent(i,j)>0) {
02773         error = TMath::Power(fTrueEnergyFlux_ND->GetBinError(i)/
02774                              fTrueEnergyFlux_ND->GetBinContent(i),2);
02775         error += TMath::Power(fFDVsNDMatrixRW->GetBinError(i,j)/
02776                               fFDVsNDMatrixRW->GetBinContent(i,j),2);
02777         error *= TMath::Power(fTrueEnergyFlux_ND->GetBinContent(i) * 
02778                               fFDVsNDMatrixRW->GetBinContent(i,j),2);
02779       }
02780       valerr[j-1] += error;
02781     }
02782   }
02783   for(int i=1;i<=fNTrueBins;i++) {
02784     fTrueEnergyMatrix_FD->SetBinContent(i,val[i-1]);
02785     fTrueEnergyMatrix_FD->SetBinError(i,TMath::Sqrt(valerr[i-1]));
02786   }
02787   return;
02788 }
02789 //____________________________________________________________________72
02790 void NuMatrixMethod::XSecCorrectFD()
02791 { 
02792   //6: Apply x-sec to get CC flux
02793   if (fDoXSecStep){
02794     for(int i=1;i<=fNTrueBins;i++) {
02795       fTrueEnergyCC_FD->SetBinContent(i,fTrueEnergyMatrix_FD->GetBinContent(i) *
02796                                       fXSec_CC_Graph->Eval(fTrueEnergyCC_FD->
02797                                                            GetBinCenter(i),0,"")*
02798                                       fFDFidMass * (fFDPoT/fFluxPoT));
02799       fTrueEnergyCC_FD->SetBinError(i,fTrueEnergyMatrix_FD->GetBinError(i) *
02800                                     fXSec_CC_Graph->Eval(fTrueEnergyCC_FD->
02801                                                          GetBinCenter(i),0,"")*
02802                                     fFDFidMass * (fFDPoT/fFluxPoT));
02803     }
02804   }
02805   else{
02806     for(int i=1;i<=fNTrueBins;i++) {
02807       fTrueEnergyCC_FD->SetBinContent(i,fTrueEnergyMatrix_FD->GetBinContent(i) *
02808                                       fFDFidMass * (fFDPoT/fFluxPoT));
02809       fTrueEnergyCC_FD->SetBinError(i,fTrueEnergyMatrix_FD->GetBinError(i) *
02810                                     fFDFidMass * (fFDPoT/fFluxPoT));
02811     }
02812   }
02813   return;
02814 }
02815 
02816 //____________________________________________________________________72
02817 void NuMatrixMethod::PotentialTausTrueEnergy()
02818 {
02819   TH1D hTrueEnergyTau_FD(this->TauXSecCorrectFD(*fTrueEnergyMatrix_FD));
02820   if (fEffCorTau_FD){delete fEffCorTau_FD; fEffCorTau_FD = 0;}
02821   fEffCorTau_FD = new TH1D(this->MultiplyInInefficiencies(hTrueEnergyTau_FD,
02822                                                           *fEfficiencyTau_FD));
02823 }
02824 
02825 //____________________________________________________________________72
02826 const TH1D NuMatrixMethod::TauXSecCorrectFD(const TH1D& tauFlux) const
02827 { 
02828   TH1D hTrueEnergyTau_FD("hTrueEnergyTau_FD","hTrueEnergyTau_FD",
02829                          fNTrueBins,fTrueBinEdges);
02830   //6: Apply x-sec to get CC flux
02831   if (fDoXSecStep){
02832     for(int i=1;i<=fNTrueBins;i++) {
02833       hTrueEnergyTau_FD.SetBinContent(i,tauFlux.GetBinContent(i) *
02834                                       fTau_XSec_CC_Graph->Eval(hTrueEnergyTau_FD.
02835                                                            GetBinCenter(i),0,"")*
02836                                       fFDFidMass * (fFDPoT/fFluxPoT));
02837       hTrueEnergyTau_FD.SetBinError(i,tauFlux.GetBinError(i) *
02838                                     fTau_XSec_CC_Graph->Eval(hTrueEnergyTau_FD.
02839                                                          GetBinCenter(i),0,"")*
02840                                     fFDFidMass * (fFDPoT/fFluxPoT));
02841     }
02842   }
02843   else{
02844     for(int i=1;i<=fNTrueBins;i++) {
02845       hTrueEnergyTau_FD.SetBinContent(i,tauFlux.GetBinContent(i) *
02846                                       fFDFidMass * (fFDPoT/fFluxPoT));
02847       hTrueEnergyTau_FD.SetBinError(i,tauFlux.GetBinError(i) *
02848                                     fFDFidMass * (fFDPoT/fFluxPoT));
02849     }
02850   }
02851   return hTrueEnergyTau_FD;
02852 }
02853 
02854 //____________________________________________________________________72
02855 const TH1D NuMatrixMethod::MultiplyInInefficiencies(const TH1D& inputSpectrum,
02856                                                     const TH1D& efficiencyPlot) const
02857 {
02858   TH1D outputSpectrum(inputSpectrum);
02859   outputSpectrum.Reset();
02860 
02861   for(int i=1;i<=inputSpectrum.GetNbinsX();i++) {
02862     outputSpectrum.SetBinContent(i,inputSpectrum.GetBinContent(i) *
02863                                  efficiencyPlot.GetBinContent(i));
02864     if(inputSpectrum.GetBinContent(i)>0 &&
02865        efficiencyPlot.GetBinContent(i)>0) {
02866       Double_t error = TMath::Power(inputSpectrum.GetBinError(i)/
02867                                     inputSpectrum.GetBinContent(i),2);
02868       error += TMath::Power(efficiencyPlot.GetBinError(i)/
02869                             efficiencyPlot.GetBinContent(i),2);
02870       error = TMath::Sqrt(error)*outputSpectrum.GetBinContent(i);
02871       outputSpectrum.SetBinError(i,error);
02872     }
02873     else outputSpectrum.SetBinError(i,0);
02874   }
02875   return outputSpectrum;
02876 }
02877 
02878 //____________________________________________________________________72
02879 void NuMatrixMethod::EfficiencyCorrectFD()
02880 { 
02881   //7: Apply FD efficiencies:
02882   for(int i=1;i<=fNTrueBins;i++) {
02883     fTrueEnergyEffCor_FD->SetBinContent(i,fTrueEnergyCC_FD->GetBinContent(i) *
02884                                         fEfficiency_FD->GetBinContent(i));
02885     if(fTrueEnergyCC_FD->GetBinContent(i)>0 &&
02886        fEfficiency_FD->GetBinContent(i)>0) {
02887       Double_t error = TMath::Power(fTrueEnergyCC_FD->GetBinError(i)/
02888                                     fTrueEnergyCC_FD->GetBinContent(i),2);
02889       error += TMath::Power(fEfficiency_FD->GetBinError(i)/
02890                             fEfficiency_FD->GetBinContent(i),2);
02891       error = TMath::Sqrt(error)*fTrueEnergyEffCor_FD->GetBinContent(i);
02892       fTrueEnergyEffCor_FD->SetBinError(i,error);
02893     }
02894     else fTrueEnergyEffCor_FD->SetBinError(i,0);
02895   }
02896   return;
02897 }
02898 
02899 //____________________________________________________________________72
02900 const TH1D NuMatrixMethod::GetFDOtherCCTrueUnoscBackground()
02901 { 
02902   TH1D hTrueEnergyOtherCCTrueUnoscBack
02903     ("hTrueEnergyOtherCCTrueUnoscBack",
02904      "True energy unoscillated CC background for the other neutrinos",
02905      fNTrueBins,fTrueBinEdges);
02906 
02907   for(int i=1;i<=fNTrueBins;i++) {
02908     hTrueEnergyOtherCCTrueUnoscBack.
02909       SetBinContent(i,fTrueEnergyCC_FD->GetBinContent(i) *
02910                     fOtherEfficiency_FD->GetBinContent(i));
02911     if(fTrueEnergyCC_FD->GetBinContent(i)>0 &&
02912        fOtherEfficiency_FD->GetBinContent(i)>0) {
02913       Double_t error = TMath::Power(fTrueEnergyCC_FD->GetBinError(i)/
02914                                     fTrueEnergyCC_FD->GetBinContent(i),2);
02915       error += TMath::Power(fOtherEfficiency_FD->GetBinError(i)/
02916                             fOtherEfficiency_FD->GetBinContent(i),2);
02917       error = TMath::Sqrt(error)*hTrueEnergyOtherCCTrueUnoscBack.GetBinContent(i);
02918       hTrueEnergyOtherCCTrueUnoscBack.SetBinError(i,error);
02919     }
02920     else hTrueEnergyOtherCCTrueUnoscBack.SetBinError(i,0);
02921   }
02922   return hTrueEnergyOtherCCTrueUnoscBack;
02923 }
02924 
02925 //____________________________________________________________________72
02926 void NuMatrixMethod::UnoscTrueToRecoFD()
02927 {
02928   //working space:
02929   Double_t *val = new Double_t[fNRecoBins+1];
02930   Double_t *valerr = new Double_t[fNRecoBins+1];
02931 
02932   // Now we are going to digress in order to make the unoscillated FD spectrum:
02933   for(int i=1;i<=fNRecoBins+1;i++) { val[i-1] = 0; valerr[i-1] = 0; }
02934   for(int i=1;i<=fNTrueBins;i++){ //loop over true
02935     for(int j=1;j<=fNRecoBins+1;j++){ //loop over reco
02936       val[j-1] += ( fTrueEnergyEffCor_FD->GetBinContent(i) *
02937                     fRecoVsTrueEnergy_FD->GetBinContent(i,j) );
02938       Double_t error = 0;
02939       if(fTrueEnergyEffCor_FD->GetBinContent(i)>0 &&
02940          fRecoVsTrueEnergy_FD->GetBinContent(i,j)>0) {
02941         error = TMath::Power(fTrueEnergyEffCor_FD->GetBinError(i)/
02942                              fTrueEnergyEffCor_FD->GetBinContent(i),2);
02943         error += TMath::Power(fRecoVsTrueEnergy_FD->GetBinError(i,j)/
02944                               fRecoVsTrueEnergy_FD->GetBinContent(i,j),2);
02945         error *= TMath::Power(fTrueEnergyEffCor_FD->GetBinContent(i) * 
02946                               fRecoVsTrueEnergy_FD->GetBinContent(i,j),2);
02947       }
02948       valerr[j-1] += error;
02949     }
02950   }
02951   for(int i=1;i<=fNRecoBins+1;i++) {
02952     fRecoEnergyNoOsc_FD->SetBinContent(i,val[i-1]);
02953     fRecoEnergyNoOsc_FD->SetBinError(i,TMath::Sqrt(valerr[i-1]));
02954   }
02955   return;
02956 }
02957  
02958 //____________________________________________________________________72
02959 
02960 void NuMatrixMethod::CalculateNCContamination()
02961 {
02962   if (NuMMExtrapolation::kPRLCCAnalysis == fextrpScheme ||
02963       NuMMExtrapolation::kCCNuMuNoOscBackground == fextrpScheme){
02964     for(int i=1;i<=fNRecoBins+1;i++){
02965       fRecoUnoscNCBackground_FD->
02966       SetBinContent(i,
02967                     fRecoEnergyNoOscPred_FD->GetBinContent(i)*
02968                     (1.0-fPurity_FD->GetBinContent(i))
02969                     );
02970       
02971       if(fRecoEnergyNoOscPred_FD->GetBinContent(i)>0 &&
02972          1.0-fPurity_FD->GetBinContent(i)>0) {
02973         Double_t error =
02974           TMath::Power(fRecoEnergyNoOscPred_FD->GetBinError(i) / 
02975                        fRecoEnergyNoOscPred_FD->GetBinContent(i),2);
02976         error += TMath::Power((fPurity_FD->GetBinError(i)) / 
02977                               (1.0-fPurity_FD->GetBinContent(i)),2);
02978         error =
02979           TMath::Sqrt(error)*fRecoUnoscNCBackground_FD->GetBinContent(i);
02980         fRecoUnoscNCBackground_FD->SetBinError(i,error);        
02981       }
02982       else fRecoUnoscNCBackground_FD->SetBinError(i,0);
02983     }
02984   }
02985   else{
02986     for(int i=1;i<=fNRecoBins+1;i++){
02987       fRecoUnoscNCBackground_FD->
02988       SetBinContent(i,
02989                     fRecoEnergyNoOscPred_FD->GetBinContent(i)*
02990                     fNCContamination_FD->GetBinContent(i)
02991                     );
02992       
02993       if(fRecoEnergyNoOscPred_FD->GetBinContent(i)>0 &&
02994          fNCContamination_FD->GetBinContent(i)>0) {
02995         Double_t error =
02996           TMath::Power(fRecoEnergyNoOscPred_FD->GetBinError(i) / 
02997                        fRecoEnergyNoOscPred_FD->GetBinContent(i),2);
02998         error += TMath::Power(fNCContamination_FD->GetBinError(i) / 
02999                               fNCContamination_FD->GetBinContent(i),2);
03000         error =
03001           TMath::Sqrt(error)*fRecoUnoscNCBackground_FD->GetBinContent(i);
03002         fRecoUnoscNCBackground_FD->SetBinError(i,error);        
03003       }
03004       else fRecoUnoscNCBackground_FD->SetBinError(i,0);
03005     }
03006   }
03007 }
03008 
03009 //____________________________________________________________________72
03010 void NuMatrixMethod::UnoscPurityCorrectFD()
03011 { 
03012   // Correct for purity:
03013   for(int i=1;i<=fNRecoBins+1;i++){
03014     if(fRecoEnergyNoOsc_FD->GetBinContent(i)>1e-5 &&
03015        fPurity_FD->GetBinContent(i)>1e-5) {
03016       fRecoEnergyNoOscPred_FD->SetBinContent(i,fRecoEnergyNoOsc_FD->GetBinContent(i)/
03017                                              fPurity_FD->GetBinContent(i));
03018       Double_t error = TMath::Power(fRecoEnergyNoOsc_FD->GetBinError(i) / 
03019                                     fRecoEnergyNoOsc_FD->GetBinContent(i),2);
03020       error += TMath::Power(fPurity_FD->GetBinError(i) / 
03021                             fPurity_FD->GetBinContent(i),2);
03022       error = TMath::Sqrt(error) * fRecoEnergyNoOscPred_FD->GetBinContent(i);
03023       fRecoEnergyNoOscPred_FD->SetBinError(i,error);
03024     }
03025     else {
03026       fRecoEnergyNoOscPred_FD->SetBinContent(i,0);
03027       fRecoEnergyNoOscPred_FD->SetBinError(i,0);
03028     }
03029   }
03030   return;
03031 }
03032 
03033 //____________________________________________________________________72

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