NueFit2D Class Reference

#include <NueFit2D.h>

Inheritance diagram for NueFit2D:
NueFit2D_Joint

List of all members.

Public Member Functions

 NueFit2D ()
virtual ~NueFit2D ()
void RunScaledChi2Sensitivity ()
void RunStandardChi2Sensitivity ()
void RunFCAnalytical ()
void RunPseudoExperiments ()
virtual void RunMultiBinPseudoExpts (bool Print=true)
void RunFCTraditional ()
void RunMultiBinFC ()
virtual double GetSensitivityAt (double delta=0, bool normalhier=true)
virtual void RunDeltaChi2Contour (int cl=0)
virtual void RunSterileContour (int cl=0)
 THIS FUNCTION IS OBSOLETE.
virtual void Run2DSterileSlice ()
void LetsIH (int lihinput=0)
virtual double GetLikelihood (double t12=0.6, double t23=0.785398, double t13=0, double dm2_32=2.32e-3, double dm2_21=7.59e-5, double delta=0)
virtual void RunDataGrid (string filenorm, string fileinvt)
virtual void AddExtrap (Extrapolate2D *E)
void SetNObs (TH1D *n)
void SetFracBkgdError (TH1D *n)
void SetFracSigError (TH1D *n)
void SetSystErrorMatrix (TH2D *n)
void SetIncludeOscParErrs ()
void SetOutputFile (string s="SensOut.root")
void SetNExperiments (int n=2000)
void FormatChi2Hists (int nx=504, double xlow=-0.0005, double xhigh=0.5035, int ny=101, double ylow=-0.01, double yhigh=2.01)
void SetPseudoExperimentInputFile (string s="PseudoExp.root")
void SetGridFiles (string snorm="Grid_1stAna_Norm.root", string sinvt="Grid_1stAna_Invt.root")
void SetGridNorm (double n=0)
void SetNDeltaSteps (int n=20)
void SetNSinSq2Th13Steps (int n=3000)
void SetNSinSq2Th14Steps (int n=3000)
void SetDeltaRange (double l=0, double h=2)
void SetSinSq2Th13Range (double l=0.05, double h=0.35)
void SetSinSq2Th14Range (double l=0.001, double h=0.301)
void SetNSinSqTh14Steps (int n=100)
void SetNSinSqTh24Steps (int n=100)
void SetSinSqTh14Range (double l=0.0, double h=1.0)
void SetSinSqTh24Range (double l=0.0, double h=1.0)
void SetNepsetauSteps (int n=3000)
void SetepsetauRange (double l=-4.0, double h=4.0)
void SetFitMethod (int m=0)
void AddError (ErrorCalc *Err)
void SetFracError (vector< TH1D * > bkglist, vector< TH1D * > siglist)
double StdLikeComparison (vector< double > npar)
double BinLikeComparison (vector< double > npar)
virtual void RunMultiBinPseudoExpts_MHDeltaFit (bool Print=true)
virtual void RunMultiBinFC_MHDeltaFit ()
void DefTheta13 (double t13, double t13unc)
void DefTheta23 (double t23, double t23unc)
void DefTheta12 (double t12, double t12unc)
void DefDMS32 (double dms32, double dms32unc)
void DefDMS21 (double dms21, double dms21unc)
void DefDeltaCP (double deltaCP)
void DefTheta24 (double t24)
void DefTheta14 (double t14)
void DefDMS41 (double dms41)
void DefEps_ee (double eps_ee)
void DefEps_emu (double eps_emu)
void DefEps_etau (double eps_etau, double eps_etau_unc)
void DefDelta_etau (double delta_etau, double delta_etau_unc)

Public Attributes

Double_t Theta12
Double_t Theta12Unc
Double_t Theta23
Double_t Theta23Unc
Double_t Theta13
Double_t Theta13Unc
Double_t DeltaMSq32
Double_t DeltaMSq32Unc
Double_t DeltaMSq21
Double_t DeltaMSq21Unc
Double_t delta
double Eps_ee
double Eps_emu
double Eps_etau
double Eps_etau_unc
double Eps_mumu
double Eps_mutau
double Eps_tautau
double Delta_emu
double Delta_etau
double Delta_etau_unc
double Delta_mutau
double Theta24
double Theta14
double DeltaMSq41

Protected Member Functions

double DoStdMinParam ()
double StandardLikelihood ()
virtual void DefineStdDlnLMinuit ()
double DoBinMinParam ()
double BinLikelihood ()
virtual void DefineBinDlnLMinuit ()
virtual void CalculateDlnLMatrix (TH2D *SystMatrix, TH2D *HOOHEMatrix)
virtual void ReadGridFiles ()
void SetupChi2Hists ()
void GenerateOneExperiment (TH1D *nexp_bkgd, TH1D *nexp_signal, TH1D *dnexp_oscpar=0)
void GenerateOneCorrelatedExp (TH1D *nexp, TH2D *err)
double ScaledChi2 (TH1D *nexp_bkgd, TH1D *nexp_signal)
double PoissonChi2 (TH1D *nexp)
double StandardChi2 (TH1D *nexp)
void CalculateErrorMatrixInv (TH1D *nexp)
virtual double GetMinLikelihood (double delta=0, bool normalhier=true)
virtual double GetMinLikelihood_Delta (bool normalhier=true)
double EvaluateOmega (double signal, double background)
double CalculateRank (int n, double s, double b, double errBg, double k, double errK)
bool FindBestFit (int n, double s, double b, double errBg, double k, double errK, double *res)

Protected Attributes

ErrorCalcErrCalc
std::vector< TH1D * > FracErr_Bkgd_List
std::vector< TH1D * > FracErr_Sig_List
TMinuit * minuit
string outFileName
vector< Extrapolate2D * > Extrap
TH1D * NObs
TH1D * FracErr_Bkgd
TH1D * FracErr_Sig
TH1D * Bkgd
TH1D * Sig
TH1D * NExp
TH2D * ErrorMatrix
TH2D * InvErrorMatrix
TH2D * ExternalErrorMatrix
unsigned int nBins
TH2D * Chi2_Normal
TH2D * Chi2_Inverted
string GridFileName_Normal
string GridFileName_Inverted
vector< TTree * > GridTree_Normal
vector< TTree * > GridTree_Inverted
vector< vector< TTree * > > GridTree_2_Normal
vector< vector< TTree * > > GridTree_2_Inverted
TTree * paramtree_Normal
TTree * paramtree_Inverted
double grid_background
double grid_signal
double grid_delta
double grid_sinsq2th13
double grid_oscparerr
double grid_nc
double grid_numucc
double grid_bnuecc
double grid_nutaucc
double grid_nue
vector< double > grid_bin_oscparerr
double grid_n_th12
double grid_n_th23
double grid_n_dm2_32
double grid_n_dm2_21
double grid_n_th13
double grid_i_th12
double grid_i_th23
double grid_i_dm2_32
double grid_i_dm2_21
double grid_i_th13
int nPts_Normal
int nPts_Inverted
int NumExpts
string PseudoExpFile
double GridNorm
double GridScale_Normal
double GridScale_Inverted
bool IncludeOscParErrs
int nSinSq2Th13_Chi2Hist
int nDelta_Chi2Hist
double SinSq2Th13Low_Chi2Hist
double SinSq2Th13High_Chi2Hist
double DeltaLow_Chi2Hist
double DeltaHigh_Chi2Hist
int nDeltaSteps
int nSinSq2Th13Steps
int nSinSq2Th14Steps
int nSinSqTh14Steps
int nSinSqTh24Steps
double DeltaLow
double DeltaHigh
double SinSq2Th13Low
double SinSq2Th13High
double SinSq2Th14Low
double SinSq2Th14High
double SinSqTh14Low
double SinSqTh14High
double SinSqTh24Low
double SinSqTh24High
int nepsetauSteps
double epsetauLow
double epsetauHigh
int FitMethod
int LIH

Detailed Description

Definition at line 29 of file NueFit2D.h.


Constructor & Destructor Documentation

NueFit2D::NueFit2D (  ) 
NueFit2D::~NueFit2D (  )  [virtual]

Definition at line 98 of file NueFit2D.cxx.

00099 {
00100 }


Member Function Documentation

void NueFit2D::AddError ( ErrorCalc Err  ) 

Definition at line 346 of file NueFit2D.cxx.

References ErrCalc.

00347 {
00348   //References the ErrorCalc object
00349   ErrCalc = Err;
00350   return;
00351 }

void NueFit2D::AddExtrap ( Extrapolate2D E  )  [virtual]

Reimplemented in NueFit2D_Joint.

Definition at line 138 of file NueFit2D.cxx.

References Extrap.

00139 {
00140   Extrap.push_back(E);
00141   return;
00142 }

double NueFit2D::BinLikeComparison ( vector< double >  npar  ) 

Definition at line 765 of file NueFit2D.cxx.

References Bkgd, ErrCalc, InvErrorMatrix, nBins, NObs, and Sig.

Referenced by binFunction(), and BinLikelihood().

00765                                                      {
00766 
00767   float dlnl=0.0;
00768   double temp=0.0;
00769 
00770   double sig=0.0;
00771   double bkg=0.0;
00772   double nobs=0.0;
00773   double nexp=0.0;
00774 
00775   //Loop over fit bins:
00776   for (unsigned int i=0;i<nBins;i++)
00777   {
00778 
00779     //Get Signal and background for prediction:
00780     sig = Sig->GetBinContent(i+1);
00781     bkg = Bkgd->GetBinContent(i+1);
00782 
00783     //Prediction:
00784     nexp = sig + bkg;
00785 
00786     //Add nuisance parameter shift if using matrix:
00787     if (npar.size()>0 && ErrCalc!=0 && InvErrorMatrix!=0){
00788     double f = npar.at(i);
00789     nexp += f;
00790     }
00791 
00792     //Observed distribution:
00793     nobs = NObs->GetBinContent(i+1);
00794 
00795     temp=0;
00796 
00797     //Likelihood comparison:
00798     if (nobs>0&&nexp>0) {
00799     //Regular (both distributions positive):
00800       temp = nexp - nobs + nobs*TMath::Log(nobs) - nobs*TMath::Log(nexp);
00801     } else if (nobs==0&&nexp>0){
00802       //No data was seen in this bin:
00803       temp = nexp;
00804     } else if (nexp==0&&nobs==0){
00805       //Nothing was seen, nothing expected:
00806       temp = 0;
00807     } else {
00808       //Something weird happened:
00809       return 1.0e10;
00810     }
00811 
00812     dlnl  += 2.0*temp;
00813 
00814   }
00815   if (npar.size()>0 && InvErrorMatrix!=0){
00816     for (unsigned int i=0; i<npar.size();i++){
00817       for (unsigned int j=0; j<npar.size();j++){
00818         //Covariance terms 
00819         dlnl += npar.at(i)*InvErrorMatrix->GetBinContent(i+1,j+1)*npar.at(j);
00820       }
00821     }
00822   }
00823   /*
00824   for (unsigned int j=0; j< npar.size();j++){
00825     cout << "NPAR"<<j<<" = "<< npar.at(j)<< endl;
00826   }
00827   */
00828 
00829   return dlnl;
00830 
00831 }

double NueFit2D::BinLikelihood (  )  [protected]

Definition at line 723 of file NueFit2D.cxx.

References BinLikeComparison(), CalculateDlnLMatrix(), ErrorCalc::CalculateHOOError(), ErrorCalc::CalculateSystErrorMatrix(), ErrorCalc::CovMatrix, ErrorCalc::CovMatrix_Decomp, DoBinMinParam(), ErrCalc, and minuit.

Referenced by NueFit2D_Joint::DoDeltaFit(), NueFit2D_Joint::DoNSIFitForever(), NueFit2D_Joint::DoNSIFitQuick(), NueFit2D_Joint::GetLikelihood(), GetLikelihood(), GetMinLikelihood(), NueFit2D_Joint::GetMinLikelihood(), GetMinLikelihood_Delta(), NueFit2D_Joint::GetMinLikelihood_Delta(), NueFit2D_Joint::GetNSIFFX2(), NueFit2D_Joint::GetSensitivityAt(), GetSensitivityAt(), Run2DSterileSlice(), RunDataGrid(), NueFit2D_Joint::RunDataGrid(), RunDeltaChi2Contour(), NueFit2D_Joint::RunDeltaChi2Contour(), RunMultiBinFC(), RunMultiBinFC_MHDeltaFit(), NueFit2D_Joint::RunMultiBinFC_MHDeltaFit(), NueFit2D_Joint::RunMultiBinPseudoExpts(), RunMultiBinPseudoExpts(), RunMultiBinPseudoExpts_MHDeltaFit(), NueFit2D_Joint::RunMultiBinPseudoExpts_MHDeltaFit(), NueFit2D_Joint::RunNSIDeltaChi2Contour(), and RunSterileContour().

00724 {
00725 
00726   //Define the covariance matrix
00727   if (ErrCalc!=0){
00728 
00729     //Calculate the systematic error covariance matrix:
00730     ErrCalc->CalculateSystErrorMatrix();
00731     
00732     //Calculate the decomposition systematic covariance matrix
00733     ErrCalc->CalculateHOOError();
00734 
00735     //Combine HOOHE and Syst into matrix, and invert 
00736     CalculateDlnLMatrix(ErrCalc->CovMatrix,ErrCalc->CovMatrix_Decomp);
00737   }
00738 
00739 
00740   double dlnl=1.0e10;
00741   vector<double> npar;
00742   if (ErrCalc==0){
00743     //Just use the empty parameter array if no error matrix set:
00744     dlnl = BinLikeComparison(npar);
00745   } else {
00746     //Otherwise, do a Minuit minimization
00747     dlnl = DoBinMinParam();
00748 
00749     Double_t fmin,fedm,errdef;
00750     Int_t npari,nparx,istat;
00751     minuit->mnstat(fmin,fedm,errdef,npari,nparx,istat);
00752     if(istat!=3&&fedm>0.01)
00753       {
00754         cout << "Fit failed with status "<< istat << endl;
00755         cout << "---> FMIN=" << fmin << " FEDM=" << fedm
00756              << " ERRDEF=" << errdef << " NPARI=" << npari
00757              << " NPARX=" << nparx << endl;
00758       }
00759 
00760   }
00761 
00762   return dlnl;
00763 }

void NueFit2D::CalculateDlnLMatrix ( TH2D *  SystMatrix = 0,
TH2D *  HOOHEMatrix = 0 
) [protected, virtual]

Reimplemented in NueFit2D_Joint.

Definition at line 353 of file NueFit2D.cxx.

References InvErrorMatrix, and nBins.

Referenced by BinLikelihood().

00353                                                                         {
00354   //Calculate the covariance matrix for the "bin by bin" method
00355 
00356   //Make new inverted matrix if not done already
00357   if (InvErrorMatrix==0){
00358     if (SysMatrix){
00359       InvErrorMatrix = (TH2D*)SysMatrix->Clone("InvErrorMatrix");
00360     } else if (HOOHEMatrix) {
00361       InvErrorMatrix = (TH2D*)HOOHEMatrix->Clone("InvErrorMatrix");
00362     } else {
00363       cout << "Didn't give me any matrices to invert!" << endl;
00364       return;
00365     }
00366   }
00367   //Reset everything to zero:
00368   InvErrorMatrix->Reset();
00369   int totbins = nBins;
00370   int i=0;
00371   int j=0;
00372   int k=0;
00373 
00374   //Add together error elements into a single array
00375   double *Varray = new double[totbins*totbins];
00376   for(i=0;i<totbins;i++)
00377   {
00378     for(j=0;j<totbins;j++)
00379     {
00380       k = i*totbins + j;
00381       Varray[k]=0;
00382       if (SysMatrix!=0) {
00383         Varray[k] += SysMatrix->GetBinContent(i+1,j+1);
00384       }
00385 
00386       if (HOOHEMatrix!=0) {
00387         Varray[k] += HOOHEMatrix->GetBinContent(i+1,j+1);
00388       }
00389     }
00390   }
00391 
00392   //Hand elements to a TMatrix
00393   TMatrixD *Vmatrix = new TMatrixD(totbins,totbins,Varray);
00394 
00395   //Insert it (determ found for debugging purposes)!
00396   double determ;
00397   TMatrixD Vinvmatrix = Vmatrix->Invert(&determ);
00398   //cout << "DETERM=" << determ << endl;
00399 
00400   //Extract the array of the inverted matrix:
00401   Double_t *Vinvarray = Vinvmatrix.GetMatrixArray();
00402 
00403   //Turn it into the inverted covariance matrix
00404 
00405   //make Vinv out of array
00406   for(i=0;i<totbins;i++)
00407   {
00408     for(j=0;j<totbins;j++)
00409     {
00410       InvErrorMatrix->SetBinContent(i+1,j+1,Vinvarray[i*totbins + j]);
00411     }
00412   }
00413 
00414   delete [] Varray;
00415   
00416   return;
00417 
00418 }

void NueFit2D::CalculateErrorMatrixInv ( TH1D *  nexp  )  [protected]

Definition at line 2859 of file NueFit2D.cxx.

References ErrorCalc::CalculateHOOError(), ErrorCalc::CalculateSystErrorMatrix(), ErrorCalc::CovMatrix, ErrorCalc::CovMatrix_Decomp, ErrCalc, ErrorMatrix, ExternalErrorMatrix, InvErrorMatrix, and nBins.

Referenced by StandardChi2().

02860 {
02861   ErrorMatrix->Reset();
02862   InvErrorMatrix->Reset();
02863   
02864   if(ErrCalc!=0)//if ErrorCalc object has been added, use it to calculate covariance matrix
02865   {
02866     ErrCalc->CalculateSystErrorMatrix();
02867     ErrorMatrix->Add(ErrCalc->CovMatrix);
02868     ErrCalc->CalculateHOOError();
02869     ErrorMatrix->Add(ErrCalc->CovMatrix_Decomp);
02870   }
02871   else if(ExternalErrorMatrix!=0)//if setting a systematic matrix externally, use it 
02872   {
02873     ErrorMatrix->Add(ExternalErrorMatrix);
02874   }
02875   //otherwise, it'll be statistics only
02876   
02877   unsigned int i,j,k;
02878   double ele;
02879   for(j=0;j<nBins;j++)
02880   {
02881     ele=ErrorMatrix->GetBinContent(j+1,j+1);
02882     ele+=nexp->GetBinContent(j+1);
02883     ErrorMatrix->SetBinContent(j+1,j+1,ele);
02884   }
02885   
02886   //take CovMatrix and make array appropiate for TMatrix
02887   double *Varray = new double[nBins*nBins];
02888   for(i=0;i<nBins;i++)
02889   {
02890     for(j=0;j<nBins;j++)
02891     {
02892       k = i*nBins + j;
02893       Varray[k] = ErrorMatrix->GetBinContent(i+1,j+1);
02894     }
02895   }
02896   
02897   //make TMatrix
02898   TMatrixD *Vmatrix = new TMatrixD(nBins,nBins,Varray);
02899   
02900   //get determinant
02901   //   Double_t det = Vmatrix->Determinant();
02902   //   cout<<"Covariance Matrix det = "<<det<<endl;
02903   
02904   //invert
02905   TMatrixD Vinvmatrix = Vmatrix->Invert();
02906   
02907   //make array out of inverse
02908   Double_t *Vinvarray = Vinvmatrix.GetMatrixArray();
02909   
02910   //make Vinv out of array
02911   for(i=0;i<nBins;i++)
02912   {
02913     for(j=0;j<nBins;j++)
02914     {
02915       InvErrorMatrix->SetBinContent(i+1,j+1,Vinvarray[i*nBins + j]);
02916     }
02917   }
02918   
02919   delete [] Varray;
02920   
02921   return;
02922 }

double NueFit2D::CalculateRank ( int  n,
double  s,
double  b,
double  errBg,
double  k,
double  errK 
) [protected]

Definition at line 3090 of file NueFit2D.cxx.

References FindBestFit().

Referenced by EvaluateOmega().

03091 {
03092   double results[3]; 
03093    //Calculate the numerator
03094   FindBestFit(n, s, b, errBg, k, errK, results);
03095 
03096 //   double numerator = results[2];
03097    
03098   double sBest, kBest, bBest;
03099 
03100    // Now calculate the denominator 
03101   if(n >= b) { // then we have n = sk+b, Beta = b; k = k0// don't have to do anything  
03102     sBest = (n-b)/k; kBest = k; bBest = b;
03103   }
03104   else{   //if(n < b) {
03105     bBest = 0.5*(b - errBg + TMath::Sqrt( (b-errBg)*(b - errBg) + 4*n*errBg)); 
03106         // then we have no signal at best fit point
03107     sBest = 0;  kBest = k;
03108   }
03109 
03110   double betaHat = results[0];
03111   double kHat = results[1];
03112   double logN = n*TMath::Log(s*kHat+betaHat) - (s*kHat+betaHat) - (betaHat-b)*(betaHat-b)/(2*errBg)
03113         - (kHat-k)*(kHat-k)/(2*errK);
03114   double logD = n*TMath::Log(sBest*kBest+bBest) - (sBest*kBest+bBest) - (bBest-b)*(bBest-b)/(2*errBg)
03115         - (kBest-k)*(kBest-k)/(2*errK);
03116 
03117   double rank = 1.0;
03118   if(logD != 0) { rank = TMath::Exp(logN-logD); }
03119   else std::cout<<"odd"<<std::endl;
03120   
03121   return rank;
03122 }

void NueFit2D::DefDelta_etau ( double  delta_etau,
double  delta_etau_unc 
) [inline]

Definition at line 193 of file NueFit2D.h.

References Delta_etau, and Delta_etau_unc.

00193                                                                 {
00194       Delta_etau = delta_etau;
00195       Delta_etau_unc = delta_etau_unc;
00196       return;
00197     } 

void NueFit2D::DefDeltaCP ( double  deltaCP  )  [inline]

Definition at line 155 of file NueFit2D.h.

References delta.

00155                                    {
00156       delta = deltaCP;
00157       return;
00158     }

void NueFit2D::DefDMS21 ( double  dms21,
double  dms21unc 
) [inline]

Definition at line 149 of file NueFit2D.h.

References DeltaMSq21, and DeltaMSq21Unc.

00149                                                 {
00150       DeltaMSq21 = dms21;
00151       DeltaMSq21Unc = dms21unc;
00152       return;
00153     }

void NueFit2D::DefDMS32 ( double  dms32,
double  dms32unc 
) [inline]

Definition at line 143 of file NueFit2D.h.

References DeltaMSq32, and DeltaMSq32Unc.

00143                                                 {
00144       DeltaMSq32 = dms32;
00145       DeltaMSq32Unc = dms32unc;
00146       return;
00147     }

void NueFit2D::DefDMS41 ( double  dms41  )  [inline]

Definition at line 168 of file NueFit2D.h.

References DeltaMSq41.

00168                                {
00169       DeltaMSq41 = dms41;
00170       return;
00171     }

void NueFit2D::DefEps_ee ( double  eps_ee  )  [inline]

Definition at line 177 of file NueFit2D.h.

References Eps_ee.

00177                                  {
00178       Eps_ee = eps_ee;
00179       return;
00180     }

void NueFit2D::DefEps_emu ( double  eps_emu  )  [inline]

Definition at line 182 of file NueFit2D.h.

References Eps_emu.

00182                                    {
00183       Eps_emu = eps_emu;
00184       return;
00185     }

void NueFit2D::DefEps_etau ( double  eps_etau,
double  eps_etau_unc 
) [inline]

Definition at line 187 of file NueFit2D.h.

References Eps_etau, and Eps_etau_unc.

00187                                                           {
00188       Eps_etau = eps_etau;
00189       Eps_etau_unc = eps_etau_unc;
00190       return;
00191     }

void NueFit2D::DefineBinDlnLMinuit (  )  [protected, virtual]

Reimplemented in NueFit2D_Joint.

Definition at line 279 of file NueFit2D.cxx.

References Extrap, minuit, nBins, and NObs.

Referenced by GetLikelihood(), GetMinLikelihood(), GetMinLikelihood_Delta(), GetSensitivityAt(), Run2DSterileSlice(), RunDataGrid(), RunDeltaChi2Contour(), RunMultiBinFC(), RunMultiBinFC_MHDeltaFit(), RunMultiBinPseudoExpts(), RunMultiBinPseudoExpts_MHDeltaFit(), and RunSterileContour().

00279                                   {
00280   //Function sets the maximum size of Minuit.
00281 
00282   //Clear things first:
00283 
00284   int npar = 0;
00285 
00286   if (nBins != 0){
00287     npar = nBins;
00288   } else if (NObs != 0){
00289       npar = NObs->GetNbinsX();
00290   } else if (Extrap.size()!=0){
00291     npar = Extrap[0]->Pred_TotalBkgd_VsBinNumber->GetNbinsX();
00292   } else {
00293     cout << "ERROR: Add extrapolation or NObs before initializing Minuit size"
00294          << endl;
00295     return;
00296   }
00297 
00298   //Make new minuit:
00299   minuit = new TMinuit(npar);
00300   minuit->SetPrintLevel(-1);
00301 
00302   double arglist[1];
00303   int ierflg=0;
00304 
00305   arglist[0] = 1.e-5;
00306   minuit->mnexcm("SET EPS",arglist,1,ierflg);
00307 
00308 
00309 }

void NueFit2D::DefineStdDlnLMinuit (  )  [protected, virtual]

Reimplemented in NueFit2D_Joint.

Definition at line 311 of file NueFit2D.cxx.

References Extrap, FracErr_Bkgd_List, minuit, nBins, and NObs.

Referenced by GetLikelihood(), GetMinLikelihood(), GetMinLikelihood_Delta(), GetSensitivityAt(), Run2DSterileSlice(), RunDataGrid(), RunDeltaChi2Contour(), RunMultiBinFC(), RunMultiBinFC_MHDeltaFit(), RunMultiBinPseudoExpts(), RunMultiBinPseudoExpts_MHDeltaFit(), and RunSterileContour().

00311                                   {
00312   //Function sets the maximum size of Minuit.
00313 
00314   //Clear things first:
00315   //minuit->mncler();
00316 
00317   int npar = 0;
00318 
00319   //Number of systematics inputted:
00320   if (FracErr_Bkgd_List.size()!=0){
00321     npar = FracErr_Bkgd_List.size();
00322   } 
00323 
00324   int nb = 0;
00325   //Number of bins (for HOOHE):
00326   if (nBins != 0){
00327     nb = nBins;
00328   } else if (NObs != 0){
00329     nb = NObs->GetNbinsX();
00330   } else if (Extrap.size()!=0){
00331     nb = Extrap[0]->Pred_TotalBkgd_VsBinNumber->GetNbinsX();
00332   } else {
00333     cout << "ERROR: Add extrapolation or NObs before initializing Minuit size"
00334          << endl;
00335     return;
00336   }
00337 
00338   npar += nb;
00339 
00340   //make new minuit
00341   minuit = new TMinuit(npar+nb);
00342   minuit->SetPrintLevel(-1);
00343 
00344 }

void NueFit2D::DefTheta12 ( double  t12,
double  t12unc 
) [inline]

Definition at line 137 of file NueFit2D.h.

References Theta12, and Theta12Unc.

00137                                               {
00138       Theta12 = t12;
00139       Theta12Unc = t12unc;
00140       return;
00141     }

void NueFit2D::DefTheta13 ( double  t13,
double  t13unc 
) [inline]

Definition at line 125 of file NueFit2D.h.

References Theta13, and Theta13Unc.

00125                                               {
00126       Theta13 = t13;
00127       Theta13Unc = t13unc;
00128       return;
00129     }

void NueFit2D::DefTheta14 ( double  t14  )  [inline]

Definition at line 164 of file NueFit2D.h.

References Theta14.

00164                                {
00165       Theta14 = t14;
00166       return;
00167     }

void NueFit2D::DefTheta23 ( double  t23,
double  t23unc 
) [inline]

Definition at line 131 of file NueFit2D.h.

References Theta23, and Theta23Unc.

00131                                               {
00132       Theta23 = t23;
00133       Theta23Unc = t23unc;
00134       return;
00135     }

void NueFit2D::DefTheta24 ( double  t24  )  [inline]

Definition at line 160 of file NueFit2D.h.

References Theta24.

00160                                {
00161       Theta24 = t24;
00162       return;
00163     }

double NueFit2D::DoBinMinParam (  )  [protected]

Definition at line 676 of file NueFit2D.cxx.

References binFunction(), Form(), minuit, and nBins.

Referenced by BinLikelihood().

00676                               {
00677 
00678   int sys_size = nBins;
00679   
00680   if  (sys_size>minuit->fMaxpar){
00681   cout << "WARNING: WRONG MINUIT SIZE" << endl;
00682   }
00683 
00684   Double_t *vstrt = new Double_t[sys_size];
00685   Double_t *stp = new Double_t[sys_size];
00686   Double_t *bmin = new Double_t[sys_size];
00687   Double_t *bmax = new Double_t[sys_size];
00688   Int_t ierflg = 0;
00689  
00690   //Pass on the object and set the static function:
00691   gMinuit=minuit;
00692   minuit->SetObjectFit(this);
00693   minuit->SetFCN(binFunction);
00694 
00695   //Set the parameters
00696  for (Int_t i=0;i<sys_size;i++){
00697     vstrt[i] = 0.0;
00698     stp[i] = 1.0;
00699     bmin[i] = 0.0;
00700     bmax[i] = 0.0;
00701     minuit->mnparm(i, Form("f%i",i), vstrt[i],stp[i],bmin[i],bmax[i],ierflg);
00702  }
00703 
00704  //Resets function value and errors to UNDEFINED:
00705   minuit->mnrset(1);
00706 
00707   //1 std dev for dlnl:
00708   minuit->SetErrorDef(1.0);
00709 
00710   //Max iterations:
00711   minuit->SetMaxIterations(500);
00712 
00713   //Go minimize!
00714   minuit->Migrad();
00715 
00716   //Get the minimum for the function
00717   double minpoint = minuit->fAmin;
00718 
00719   return minpoint;
00720 
00721   }

double NueFit2D::DoStdMinParam (  )  [protected]

Definition at line 454 of file NueFit2D.cxx.

References dlnlFunction(), Form(), FracErr_Bkgd_List, minuit, and nBins.

Referenced by StandardLikelihood().

00454                               {
00455 
00456   //Size of systematics.  The +nBins will be for HOOHE.
00457   int sys_size = FracErr_Bkgd_List.size()+nBins;
00458 
00459   if  (sys_size>minuit->fMaxpar){
00460   cout << "WARNING: WRONG MINUIT SIZE" << endl;
00461   }
00462 
00463   Double_t *vstrt = new Double_t[sys_size];
00464   Double_t *stp = new Double_t[sys_size];
00465   Double_t *bmin = new Double_t[sys_size];
00466   Double_t *bmax = new Double_t[sys_size];
00467   Int_t ierflg = 0;
00468  
00469   //Pass on the object and set the static function:
00470   gMinuit=minuit;
00471   minuit->SetObjectFit(this);
00472   minuit->SetFCN(dlnlFunction);
00473 
00474   //Set the parameters
00475  for (Int_t i=0;i<sys_size;i++){
00476     vstrt[i] = 0.0;
00477     stp[i] = 1.0;
00478     bmin[i] = 0.0;
00479     bmax[i] = 0.0;
00480 
00481     //HOO disabled for now:
00482     //if (InvErrorMatrix==0&&(unsigned int)i>=FracErr_Bkgd_List.size()) vstrt[i] = 1.0;
00483     if ((unsigned int)i>=FracErr_Bkgd_List.size()) vstrt[i] = 1.0;
00484 
00485     minuit->mnparm(i, Form("f%i",i), vstrt[i],stp[i],bmin[i],bmax[i],ierflg);
00486 
00487     //HOO disabled for now:
00488     //if (InvErrorMatrix==0&&(unsigned int)i>=FracErr_Bkgd_List.size()) minuit->FixParameter(i);
00489     if ((unsigned int)i>=FracErr_Bkgd_List.size()) minuit->FixParameter(i);
00490  }
00491 
00492  //Resets function value and errors to UNDEFINED:
00493   minuit->mnrset(1);
00494 
00495   //2*dlnl style error definition
00496   minuit->SetErrorDef(1.0);
00497 
00498   //Max iterations:
00499   minuit->SetMaxIterations(500);
00500 
00501   //Go minimize!
00502   minuit->Migrad();
00503 
00504  // // Uncomment this for examining nuisance parameters.
00505  //  for (Int_t i=0;i<sys_size;i++){
00506  //    double opt_f;
00507  //    double err_f;
00508  //
00509  //    minuit->GetParameter(i,opt_f,err_f);
00510  //
00511  //    cout << opt_f << " ";
00512  //  }
00513  //  cout << endl;
00514 
00515   double minpoint = minuit->fAmin;
00516 
00517   return minpoint;
00518 
00519 }

double NueFit2D::EvaluateOmega ( double  signal,
double  background 
) [protected]

Definition at line 2923 of file NueFit2D.cxx.

References CalculateRank(), delta, MuELoss::e, FindBestFit(), FracErr_Bkgd, FracErr_Sig, Gaussian(), NObs, and Poisson().

Referenced by RunFCAnalytical().

02924 {
02925   //this will only be called for a single bin fit
02926   
02927   int n0 = (int)NObs->GetBinContent(1,1);
02928   double b0 = background;
02929   double s0 = signal;
02930   double k0 = 1.0;
02931   
02932   double errbkgd = FracErr_Bkgd->GetBinContent(1,1);
02933   double errsig = FracErr_Sig->GetBinContent(1,1);
02934 
02935   double errK = 1.0;
02936   if(s0 > 0) errK = (errsig)*(errsig);
02937   if(errK < 1e-5){ errK = 1.0;  std::cout<<"can't do perfect signal"<<std::endl; }
02938   double errBg = errbkgd*b0*errbkgd*b0;
02939  
02940   double rank0 = CalculateRank(n0, s0, b0, errBg, k0, errK);
02941 
02942   double results[3];
02943   FindBestFit(n0, s0, b0, errBg, k0, errK, results);
02944 
02945   double betaHat = results[0];
02946   double kHat = results[1];
02947 
02948   errBg = (betaHat*errbkgd)*(betaHat*errbkgd);
02949   errK = (errsig)*(errsig)*kHat*kHat;
02950 
02951 //   std::cout<<n0<<"  "<<s0<<"  "<<b0<<"  "<<k0<<"  "<<betaHat<<" "<<kHat<<"  "<<errBg<<" "<<errK<<std::endl;
02952 //   std::cout<<s0*kHat + betaHat<<"  "<<n0<<std::endl;
02953 
02954   double omega = 0;
02955   double omegaBar = Poisson(s0*kHat + betaHat, n0);
02956 
02957   int nBase = int(s0*kHat + betaHat);
02958 
02959   int nHigh = nBase;
02960   int nLow  = nBase - 1;
02961 
02962   double delta = 1.0;
02963   bool filled = false;
02964 
02965   const int NUMB = 30;
02966   const int NUMK = 30;
02967 
02968   static double bVal[NUMB];
02969   static double kVal[NUMK];
02970   static double errBVar[NUMB];
02971   static double errKVar[NUMK];
02972 
02973   static bool first = true;
02974   static double scale = 1.0;
02975 
02976   double bStart = 0.4*b0;   double bStop = 2.2*b0;
02977   double kStart = 0.4;   double kStop = 1.6;
02978 
02979   if(first){
02980     for(int i = 0; i < NUMB; i++) { 
02981       bVal[i] = bStart + i*(bStop - bStart)/float(NUMB); 
02982       errBVar[i] = errbkgd*errbkgd*bVal[i]*bVal[i];
02983     }
02984   
02985     for(int i = 0; i < NUMK; i++) { 
02986       kVal[i] = kStart + i*(kStop - kStart)/float(NUMK);
02987       errKVar[i] = (errsig)*(errsig)*kVal[i]*kVal[i];
02988     }
02989     first = false; 
02990     scale = (bStop-bStart)*(kStop-kStart)/(NUMK*NUMB);
02991   }
02992   double bkProb[NUMB][NUMK];
02993 
02994    /*   so lets be clear about this, the values for these gaussians are the same
02995   but its the rank that changes for any given value of n (the values themselve differ with mu)
02996   so the first time through i calculate the contribution for each point in the space
02997   then when looping through just look it up in a giant array             */
02998 
02999    // better yet - I can save cycles by building the arrays separately on the first pass 
03000 
03001   double bGauss[NUMB];
03002   double kGauss[NUMK];
03003 
03004   for(int i = 0; i < NUMB; i++) { 
03005     bGauss[i] = Gaussian(betaHat, bVal[i], errBg);
03006   }
03007   for(int i = 0; i < NUMB; i++) { 
03008     kGauss[i] = Gaussian(kHat, kVal[i], errK);
03009   }    
03010 
03011   bool risingH = false, risingL = false;
03012   bool doneH = false;  // some calc savers
03013   bool doneL = false;  // some calc savers
03014 
03015   double ThreshHold = 1e-5;
03016   double pfThresh = ThreshHold*1e-2;
03017 
03018   double slip = 0;   // Error on the numerical integral
03019 
03020   while(delta > ThreshHold || (1 - (omega + omegaBar) > 2*ThreshHold) )
03021   {
03022     if(nHigh == n0) nHigh++;
03023     if(nLow == n0) nLow--;
03024 
03025     double dOmegaH = 0.0, dOmegaBarH = 0.0;
03026     double dOmegaL = 0.0, dOmegaBarL = 0.0;
03027 
03028     double PrefactorH = Poisson(s0*kHat+betaHat, nHigh);
03029     double PrefactorL = Poisson(s0*kHat+betaHat, nLow);
03030 
03031     if(PrefactorH > pfThresh) risingH = true;
03032     if(PrefactorL > pfThresh) risingL = true;
03033     if(PrefactorH < pfThresh && risingH) doneH = true;
03034     if(PrefactorL < pfThresh && risingL) doneL = true;
03035     if(doneH && doneL){
03036           // just a sanity check that the code doesn't think its done too early, this will cause an inf loop
03037       if(1 - (omega + omegaBar) < 1.5*slip) break;
03038       std::cout<<"Thats unexpected:  "<<1 - (omega + omegaBar)<<"  "<<slip<<std::endl;
03039     }
03040 
03041     if(PrefactorH > pfThresh || PrefactorL > pfThresh){  // No need to loop if contribution too small
03042       for(int i = 0; i < NUMB; i++) //  0 to infinity
03043       {
03044         double b = bVal[i];
03045         double eb = errBVar[i];
03046         for(int j = 0 ; j < NUMK; j++) //  -inf to inf
03047         {
03048           double k = kVal[j];
03049           if(!filled) bkProb[i][j] = bGauss[i]*kGauss[j];
03050  
03051           double val = bkProb[i][j];   
03052           double eK = errKVar[j];
03053           if(val < ThreshHold*1e-4) continue; // no point in using these contributions 
03054               
03055           double rank = 1.0;
03056 
03057           if(PrefactorH > pfThresh){
03058             rank = CalculateRank(nHigh, s0, b, eb, k, eK);
03059             if(rank > rank0) dOmegaH += val*scale;
03060             else          dOmegaBarH += val*scale; 
03061           }
03062  
03063           if(PrefactorL > pfThresh){
03064             if(nLow >= 0){
03065               rank = CalculateRank(nLow, s0, b, eb, k, eK);
03066               if(rank > rank0) dOmegaL += val*scale;
03067               else          dOmegaBarL += val*scale; 
03068             }
03069           }
03070         }
03071       }
03072       if(!filled) filled = true;          
03073       if(PrefactorH > pfThresh && 1 - (dOmegaH+ dOmegaBarH) > slip) slip = 1 - (dOmegaH+ dOmegaBarH);
03074       if(PrefactorL > pfThresh && 1 - (dOmegaL+ dOmegaBarL) > slip) slip = 1 - (dOmegaL+ dOmegaBarL);
03075     }
03076     delta = TMath::Max(PrefactorH*dOmegaH + PrefactorL*dOmegaL, PrefactorH*dOmegaBarH + PrefactorL*dOmegaBarL);
03077     omega += PrefactorH*dOmegaH + PrefactorL*dOmegaL;
03078     omegaBar += PrefactorH*dOmegaBarH + PrefactorL*dOmegaBarL;
03079     nHigh++; nLow--;
03080   }
03081 
03082   if(slip > ThreshHold){
03083     std::cout<<"Integral error past threshold:  "<<omega<<"  "<<omegaBar<<"  "<<omega+omegaBar<<"  "<<slip<<std::endl;
03084     std::cout<<n0<<"  "<<s0<<"  "<<b0<<"  "<<k0<<"  "<<betaHat<<" "<<kHat<<"  "<<errBg<<" "<<errK<<std::endl;
03085     std::cout<<s0*kHat + betaHat<<"  "<<n0<<std::endl;
03086   }
03087   
03088   return omega;
03089 }

bool NueFit2D::FindBestFit ( int  n,
double  s,
double  b,
double  errBg,
double  k,
double  errK,
double *  res 
) [protected]

Definition at line 3123 of file NueFit2D.cxx.

References Munits::rad.

Referenced by CalculateRank(), and EvaluateOmega().

03124 {
03125 //  At the moment this function is solvable in ~closed form (we ignore the dependance of errBg, errK on khat, betaHat
03126 //  this lets us avoid having a numerical minimization, but the second half of this function is the code that allows for that
03127 
03128   double sol_A = 1 + errK/errBg*s*s;
03129   double sol_B = errBg + s*k - 2*errK*s*s*b/errBg - b + s*s*errK;
03130   double sol_C = -n*errBg + s*k*errBg - s*s*errK*b - s*k*b + s*s*b*b*errK/errBg;
03131 
03132   double rad = sol_B*sol_B-4*sol_A*sol_C;
03133   if(rad < 0) std::cout<<"negative radical - not sure about this...."<<std::endl;
03134 
03135   double betaHat = (-sol_B + TMath::Sqrt(rad))/(2*sol_A);
03136 
03137    //solving for kHat given betaHat
03138   double kHat = k - s*errK/errBg*(b-betaHat);
03139 
03140   res[0] = betaHat;
03141   res[1] = kHat;
03142 
03143 /*
03144   fFixedFitPar[0] = n;
03145   fFixedFitPar[1] = s;
03146   fFixedFitPar[2] = b;
03147   fFixedFitPar[3] = errBg;
03148   fFixedFitPar[4] = k;
03149   fFixedFitPar[5] = errK;
03150 */
03151 //   res[2] = fResult = Poisson(s*kHat+betaHat, n, true)*Gaussian(betaHat, b, errBg)*Gaussian(kHat, k, errK);
03152 /*
03153   static bool first = true;
03154   static TMinuit *min = 0;
03155 
03156   if(first){    
03157   min = new TMinuit(2);
03158   gMinuit = min;
03159   min->SetFCN(WrapperFunction);
03160   min->SetObjectFit(this);
03161   min->DefineParameter(0,"bfit",fObserved,1, 0,60);
03162   min->DefineParameter(1,"kfit",1,0.99, 0,22);
03163 
03164   const double ERRDEF=1.;
03165   min->SetErrorDef(ERRDEF);
03166   min->SetPrintLevel(-1);
03167   first = false;
03168   std::cout<<"Built"<<std::endl;
03169 }
03170   Double_t arglist[10];
03171   Int_t ierflg = 0;
03172 
03173   arglist[0] = 10000;       //max calls
03174   arglist[1] = 0.01;         //tolerance
03175 
03176   min->mnexcm("SIMPLEX",arglist,2,ierflg);
03177 
03178   double errs[2];
03179   for(int i=0;i<2;i++){
03180   min->GetParameter(i,res[i],errs[i]);
03181 //     std::cout<<res[i]<<"  "<<errs[i]<<std::endl;
03182 }
03183 */
03184 //   res[2] = fResult;
03185   
03186   return true;
03187 }

void NueFit2D::FormatChi2Hists ( int  nx = 504,
double  xlow = -0.0005,
double  xhigh = 0.5035,
int  ny = 101,
double  ylow = -0.01,
double  yhigh = 2.01 
)

Definition at line 833 of file NueFit2D.cxx.

References DeltaHigh_Chi2Hist, DeltaLow_Chi2Hist, nDelta_Chi2Hist, nSinSq2Th13_Chi2Hist, SinSq2Th13High_Chi2Hist, and SinSq2Th13Low_Chi2Hist.

Referenced by NueFit2D(), and NueFit2D_Joint::NueFit2D_Joint().

00834 {
00835   nSinSq2Th13_Chi2Hist = nx;
00836   SinSq2Th13Low_Chi2Hist = xlow;
00837   SinSq2Th13High_Chi2Hist= xhigh;
00838   nDelta_Chi2Hist = ny;
00839   DeltaLow_Chi2Hist = ylow;
00840   DeltaHigh_Chi2Hist = yhigh;
00841   
00842   return;
00843 }

void NueFit2D::GenerateOneCorrelatedExp ( TH1D *  nexp,
TH2D *  err 
) [protected]

Definition at line 2683 of file NueFit2D.cxx.

References nBins, and NObs.

Referenced by NueFit2D_Joint::RunMultiBinPseudoExpts(), RunMultiBinPseudoExpts(), NueFit2D_Joint::RunMultiBinPseudoExpts_MHDeltaFit(), and RunMultiBinPseudoExpts_MHDeltaFit().

02684 {
02685   NObs = (TH1D*)nexp->Clone("NObs");
02686   NObs->Reset();
02687   nBins = NObs->GetNbinsX();
02688   
02689   unsigned int i,j,k;
02690   
02691   //error matrix
02692   double *Varray = new double[nBins*nBins];
02693   for(i=0;i<nBins;i++)
02694   {
02695     for(j=0;j<nBins;j++)
02696     {
02697       k = i*nBins + j;
02698       Varray[k] = err->GetBinContent(i+1,j+1);
02699     }
02700   }
02701   const TMatrixD M(nBins,nBins,Varray);
02702 //   cout<<"M:"<<endl;
02703 //   for(i=0;i<nBins;i++)
02704 //   {
02705 //     for(j=0;j<nBins;j++)
02706 //     {
02707 //       cout<<M[i][j]<<" ";
02708 //     }
02709 //     cout<<endl;
02710 //   }
02711   
02712   //get eigenvectors of M
02713   TMatrixDEigen V(M);
02714   //construct matrix of eigenvectors
02715   TMatrixD AT = V.GetEigenVectors();
02716 //   cout<<"AT:"<<endl;
02717 //   for(i=0;i<nBins;i++)
02718 //   {
02719 //     for(j=0;j<nBins;j++)
02720 //     {
02721 //       cout<<AT[i][j]<<" ";
02722 //     }
02723 //     cout<<endl;
02724 //   }
02725   
02726   //transpose to get transformation matrix A
02727   TMatrixD A = AT;
02728   A.Transpose(A);
02729 //   cout<<"A:"<<endl;
02730 //   for(i=0;i<nBins;i++)
02731 //   {
02732 //     for(j=0;j<nBins;j++)
02733 //     {
02734 //       cout<<A[i][j]<<" ";
02735 //     }
02736 //     cout<<endl;
02737 //   }
02738   
02739   //diagonalize M
02740   TMatrixD D(nBins,nBins);
02741   D = A*M*AT;
02742 //   cout<<"D:"<<endl;
02743 //   for(i=0;i<nBins;i++)
02744 //   {
02745 //     for(j=0;j<nBins;j++)
02746 //     {
02747 //       cout<<D[i][j]<<" ";
02748 //     }
02749 //     cout<<endl;
02750 //   }
02751   
02752   //transform prediction to diagonal basis using A
02753   vector<double> nnew;
02754   double t;
02755   for(i=0;i<nBins;i++)
02756   {
02757     t=0;
02758     for(j=0;j<nBins;j++)
02759     {
02760       t+=A[i][j]*nexp->GetBinContent(j+1);
02761     }
02762     nnew.push_back(t);
02763   }
02764   
02765   //randomize prediction in diagonal basis
02766   vector<double> nrand;
02767   for(i=0;i<nBins;i++)
02768   {
02769 //     cout<<"nexp_ = "<<nexp_->GetBinContent(i+1)<<" "<<sqrt(D[i][i])<<endl;
02770     if(D[i][i]<0)
02771     {
02772       cout<<"Warning in NueFit2D::GenerateOneCorrelatedExp(): Negative element in diagonalized systematic error matrix ... setting to 0."<<endl;
02773       D[i][i]=0;
02774     }
02775     nrand.push_back(gRandom->Gaus(nnew[i],sqrt(D[i][i])));
02776   }
02777   
02778   //transform randomized prediction back to original basis
02779   for(i=0;i<nBins;i++)
02780   {
02781     t=0;
02782     for(j=0;j<nBins;j++)
02783     {
02784       t+=AT[i][j]*nrand[j];
02785     }
02786     t = gRandom->Poisson(t);
02787     NObs->SetBinContent(i+1,t);
02788 //     cout<<t<<endl;
02789   }
02790   
02791   delete [] Varray;
02792   
02793   return;
02794 }

void NueFit2D::GenerateOneExperiment ( TH1D *  nexp_bkgd,
TH1D *  nexp_signal,
TH1D *  dnexp_oscpar = 0 
) [protected]

Definition at line 2647 of file NueFit2D.cxx.

References FracErr_Bkgd, FracErr_Sig, IncludeOscParErrs, nBins, and NObs.

Referenced by RunPseudoExperiments().

02648 {
02649   NObs = (TH1D*)nexp_bkgd->Clone("NObs");
02650   NObs->Reset();
02651   nBins = NObs->GetNbinsX();
02652   
02653   int obs;
02654   double b,s,eb,es,bgauss,sgauss;
02655   double tot,etot;
02656   double temp;
02657   
02658   for(unsigned int i=0;i<nBins;i++)
02659   {
02660     b = nexp_bkgd->GetBinContent(i+1);
02661     s = nexp_signal->GetBinContent(i+1);
02662     eb = FracErr_Bkgd->GetBinContent(i+1)*nexp_bkgd->GetBinContent(i+1);
02663     es = FracErr_Sig->GetBinContent(i+1)*nexp_signal->GetBinContent(i+1);
02664     
02665     bgauss = gRandom->Gaus(b,eb);
02666     sgauss = gRandom->Gaus(s,es);
02667     tot = bgauss + sgauss;
02668     
02669     if(IncludeOscParErrs)
02670     {
02671       etot = dnexp_oscpar->GetBinContent(i+1)*tot;
02672       temp = gRandom->Gaus(tot,etot);
02673       tot = temp;
02674     }
02675     
02676     obs = gRandom->Poisson(tot);
02677     
02678     NObs->SetBinContent(i+1,obs);
02679   }
02680   
02681   return;
02682 }

double NueFit2D::GetLikelihood ( double  t12 = 0.6,
double  t23 = 0.785398,
double  t13 = 0,
double  dm2_32 = 2.32e-3,
double  dm2_21 = 7.59e-5,
double  delta = 0 
) [virtual]

Reimplemented in NueFit2D_Joint.

Definition at line 4096 of file NueFit2D.cxx.

References BinLikelihood(), Bkgd, DefineBinDlnLMinuit(), DefineStdDlnLMinuit(), ErrorMatrix, Extrap, FitMethod, FracErr_Bkgd, FracErr_Sig, InvErrorMatrix, OscPar::kDelta, OscPar::kDeltaM12, OscPar::kDeltaM23, OscPar::kTh12, OscPar::kTh13, OscPar::kTh23, nBins, NExp, NObs, nSinSq2Th13Steps, PoissonChi2(), ScaledChi2(), Sig, SinSq2Th13High, SinSq2Th13Low, StandardChi2(), and StandardLikelihood().

04097 {
04098   if(NObs==0)
04099   {
04100     cout<<"NObs not set.  Quitting..."<<endl;
04101     return 0;
04102   }
04103   if(FitMethod==1 && (FracErr_Bkgd==0 || FracErr_Sig==0))
04104   {
04105     cout<<"FracErr_Bkgd and FracErr_Sig need to be set for ScaledChi2.  Quitting..."<<endl;
04106     return 0;
04107   }
04108   if(Extrap.size()==0)
04109   {
04110     cout<<"No Extrapolate2D input.  Quitting..."<<endl;
04111     return 0;
04112   }
04113   
04114   if(FitMethod==3) DefineStdDlnLMinuit();
04115   if(FitMethod==4) DefineBinDlnLMinuit();
04116   
04117   Bkgd = (TH1D*)NObs->Clone("Bkgd");
04118   Bkgd->Reset();
04119   Sig = (TH1D*)NObs->Clone("Sig");
04120   Sig->Reset();
04121   TH1D *NExp = (TH1D*)NObs->Clone("NExp");
04122   NExp->Reset();
04123   
04124   unsigned int ie;
04125   for(ie=0;ie<Extrap.size();ie++)
04126   {
04127     Extrap[ie]->GetPrediction();
04128     Extrap[ie]->SetOscPar(OscPar::kTh12,t12);
04129     Extrap[ie]->SetOscPar(OscPar::kTh23,t23);
04130     Extrap[ie]->SetOscPar(OscPar::kTh13,t13);
04131     Extrap[ie]->SetOscPar(OscPar::kDeltaM23,dm2_32);
04132     Extrap[ie]->SetOscPar(OscPar::kDeltaM12,dm2_21);
04133     Extrap[ie]->SetOscPar(OscPar::kDelta,delta);
04134     Extrap[ie]->OscillatePrediction();
04135   }
04136   
04137   Int_t i;
04138   
04139   if(ErrorMatrix==0) ErrorMatrix = new TH2D("ErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
04140   if(InvErrorMatrix==0) InvErrorMatrix = new TH2D("InvErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
04141   
04142   Double_t ss2th13 = 0;
04143   Double_t delchi2 = 0;
04144   Double_t best = 0;
04145   Double_t Th13increment = 0;
04146   if(nSinSq2Th13Steps>0) Th13increment = (SinSq2Th13High - SinSq2Th13Low)/(nSinSq2Th13Steps);
04147   double chi2[3],val[3];
04148   TGraph *g3;
04149   TF1* fit;
04150   double minchi2;
04151   
04152   best=-1.;
04153   minchi2=100;
04154   for(i=0;i<3;i++)
04155   {
04156     chi2[i]=-1.;
04157     val[i]=-1.;
04158   }
04159   for(i=0;i<nSinSq2Th13Steps+1;i++)
04160   {
04161     chi2[0] = chi2[1];
04162     chi2[1] = chi2[2];
04163     val[0] = val[1];
04164     val[1] = val[2];
04165     ss2th13 = i*Th13increment + SinSq2Th13Low;
04166     for(ie=0;ie<Extrap.size();ie++)
04167     {
04168       Extrap[ie]->SetSinSq2Th13(ss2th13);
04169       Extrap[ie]->OscillatePrediction();
04170     }
04171     Bkgd->Reset();
04172     Sig->Reset();
04173     NExp->Reset();
04174     for(ie=0;ie<Extrap.size();ie++)
04175     {
04176       Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
04177       Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
04178     }
04179     NExp->Add(Bkgd);
04180     NExp->Add(Sig);
04181     
04182     chi2[2] = 1e10;
04183     if(FitMethod==0)
04184     {
04185       chi2[2] = PoissonChi2(NExp);
04186     }
04187     else if(FitMethod==1)
04188     {
04189       chi2[2] = ScaledChi2(Bkgd,Sig);
04190     }
04191     else if(FitMethod==2)
04192     {
04193       chi2[2] = StandardChi2(NExp);
04194     }
04195     else if(FitMethod==3)
04196     {
04197       //Likelihood: "Standard" (N syst, N nuisance)
04198       //Calculate the likelihood (x2 for chi)
04199       chi2[2] = StandardLikelihood();
04200     }
04201     else if(FitMethod==4)
04202     {
04203       //Likelihood: Bin by Bin Calculation of Systematics
04204       //Calculate the likelihood (x2 for chi)
04205       chi2[2] = BinLikelihood();
04206     }
04207     else
04208     {
04209       cout<<"Error in GetLikelihood(): Unknown 'FitMethod'."<<endl;
04210     }
04211     
04212     val[2] = ss2th13;
04213     
04214     if(i<2) continue;
04215     
04216     if(i<3 && chi2[2]>chi2[1] && chi2[1]>chi2[0])//first three points are increasing, first point is minimum.
04217     {
04218       best = val[0];
04219       minchi2 = chi2[0];
04220       cout<<"minimum at 1st point: "<<minchi2<<" at "<<best<<endl;
04221       break;
04222     }
04223     
04224     if(chi2[2]>chi2[1] && chi2[0]>chi2[1])//found minimum
04225     {
04226       g3 = new TGraph(3, val, chi2);
04227       fit = new TF1("pol2", "pol2");
04228       g3->Fit(fit, "Q");//fit to second order polynominal
04229       if(fit->GetParameter(2) > 0)//if the x^2 term is nonzero
04230       {
04231         best = -fit->GetParameter(1)/(2*fit->GetParameter(2));//the location of the minimum is -p1/(2*p2)
04232         minchi2 = fit->GetParameter(0) + fit->GetParameter(1)*best + fit->GetParameter(2)*best*best;
04233         cout<<"minimum with fit: "<<minchi2<<" at "<<best<<endl;
04234       }
04235       else//if the x^2 term is zero, then just use the minimum you got by scanning
04236       {
04237         best = val[1];
04238         minchi2 = chi2[1];
04239         cout<<"minimum with scan: "<<minchi2<<" at "<<best<<endl;
04240       }
04241       break;
04242     }
04243   }
04244   
04245   for(ie=0;ie<Extrap.size();ie++)
04246   {
04247     Extrap[ie]->SetOscPar(OscPar::kTh13,t13);
04248     Extrap[ie]->OscillatePrediction();
04249   }
04250   Bkgd->Reset();
04251   Sig->Reset();
04252   NExp->Reset();
04253   for(ie=0;ie<Extrap.size();ie++)
04254   {
04255     Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
04256     Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
04257   }
04258   NExp->Add(Bkgd);
04259   NExp->Add(Sig);
04260   
04261   delchi2 = 1e10;
04262   if(FitMethod==0)
04263   {
04264     delchi2 = PoissonChi2(NExp) - minchi2;
04265   }
04266   else if(FitMethod==1)
04267   {
04268     delchi2 = ScaledChi2(Bkgd,Sig) - minchi2;
04269   }
04270   else if(FitMethod==2)
04271   {
04272     delchi2 = StandardChi2(NExp) - minchi2;
04273   }
04274   else if(FitMethod==3)
04275   {
04276     //Likelihood: "Standard" (N syst, N nuisance)
04277     //Calculate the likelihood (x2 for chi)
04278     delchi2 = StandardLikelihood() - minchi2;
04279   }
04280   else if(FitMethod==4)
04281   {
04282     //Likelihood: Bin by Bin Calculation of Systematics
04283     //Calculate the likelihood (x2 for chi)
04284     delchi2 = BinLikelihood() - minchi2;
04285   }
04286   else
04287   {
04288     cout<<"Error in GetLikelihood(): Unknown 'FitMethod'."<<endl;
04289   }
04290   
04291   cout<<"delchi2 = "<<delchi2<<endl;
04292   
04293   return delchi2;
04294 }

double NueFit2D::GetMinLikelihood ( double  delta = 0,
bool  normalhier = true 
) [protected, virtual]

Reimplemented in NueFit2D_Joint.

Definition at line 4295 of file NueFit2D.cxx.

References BinLikelihood(), Bkgd, DefineBinDlnLMinuit(), DefineStdDlnLMinuit(), ErrCalc, ErrorMatrix, Extrap, FitMethod, FracErr_Bkgd, FracErr_Sig, Munits::g, grid_i_dm2_21, grid_i_dm2_32, grid_i_th12, grid_i_th23, grid_n_dm2_21, grid_n_dm2_32, grid_n_th12, grid_n_th23, InvErrorMatrix, OscPar::kDelta, OscPar::kDeltaM12, OscPar::kDeltaM23, OscPar::kTh12, OscPar::kTh23, max, nBins, NExp, NObs, Munits::ns, PoissonChi2(), ScaledChi2(), ErrorCalc::SetUseGrid(), Sig, StandardChi2(), and StandardLikelihood().

Referenced by RunDataGrid(), RunMultiBinFC(), and RunMultiBinPseudoExpts().

04296 {
04297   if(NObs==0)
04298   {
04299     cout<<"NObs not set.  Quitting..."<<endl;
04300     return 0;
04301   }
04302   if(FitMethod==1 && (FracErr_Bkgd==0 || FracErr_Sig==0))
04303   {
04304     cout<<"FracErr_Bkgd and FracErr_Sig need to be set for ScaledChi2.  Quitting..."<<endl;
04305     return 0;
04306   }
04307   if(Extrap.size()==0)
04308   {
04309     cout<<"No Extrapolate2D input.  Quitting..."<<endl;
04310     return 0;
04311   }
04312   
04313   if(FitMethod==3) DefineStdDlnLMinuit();
04314   if(FitMethod==4) DefineBinDlnLMinuit();
04315   if(FitMethod==3 || FitMethod==4)
04316   {
04317     if(ErrCalc!=0) ErrCalc->SetUseGrid(false);
04318   }
04319   
04320   Bkgd = (TH1D*)NObs->Clone("Bkgd");
04321   Bkgd->Reset();
04322   Sig = (TH1D*)NObs->Clone("Sig");
04323   Sig->Reset();
04324   TH1D *NExp = (TH1D*)NObs->Clone("NExp");
04325   NExp->Reset();
04326   
04327   unsigned int ie;
04328   for(ie=0;ie<Extrap.size();ie++)
04329   {
04330     Extrap[ie]->GetPrediction();
04331     if(normalhier)
04332     {
04333       Extrap[ie]->SetOscPar(OscPar::kTh12,grid_n_th12);
04334       Extrap[ie]->SetOscPar(OscPar::kTh23,grid_n_th23);
04335       Extrap[ie]->SetOscPar(OscPar::kDeltaM12,grid_n_dm2_21);
04336       Extrap[ie]->SetOscPar(OscPar::kDeltaM23,grid_n_dm2_32);
04337     }
04338     else
04339     {
04340       Extrap[ie]->SetOscPar(OscPar::kTh12,grid_i_th12);
04341       Extrap[ie]->SetOscPar(OscPar::kTh23,grid_i_th23);
04342       Extrap[ie]->SetOscPar(OscPar::kDeltaM12,grid_i_dm2_21);
04343       Extrap[ie]->SetOscPar(OscPar::kDeltaM23,grid_i_dm2_32);
04344     }
04345     Extrap[ie]->SetOscPar(OscPar::kDelta,delta);
04346     Extrap[ie]->OscillatePrediction();
04347   }
04348   
04349   Int_t i;
04350   
04351   if(ErrorMatrix==0) ErrorMatrix = new TH2D("ErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
04352   if(InvErrorMatrix==0) InvErrorMatrix = new TH2D("InvErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
04353   
04354   Double_t ss2th13 = 0;
04355   TF1* fit;
04356   double minchi2;
04357   
04358   const int ns=30;
04359   double max=0.6;
04360   double width = max/ns;
04361   double th13[ns],c2[ns];
04362   for(i=0;i<ns;i++)
04363   {
04364     ss2th13 = i*width;
04365     th13[i] = ss2th13;
04366     for(ie=0;ie<Extrap.size();ie++)
04367     {
04368       Extrap[ie]->SetSinSq2Th13(ss2th13);
04369       Extrap[ie]->OscillatePrediction();
04370     }
04371     Bkgd->Reset();
04372     Sig->Reset();
04373     NExp->Reset();
04374     for(ie=0;ie<Extrap.size();ie++)
04375     {
04376       Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
04377       Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
04378     }
04379     NExp->Add(Bkgd);
04380     NExp->Add(Sig);
04381     
04382     c2[i] = 1e10;
04383     if(FitMethod==0)
04384     {
04385       c2[i] = PoissonChi2(NExp);
04386     }
04387     else if(FitMethod==1)
04388     {
04389       c2[i] = ScaledChi2(Bkgd,Sig);
04390     }
04391     else if(FitMethod==2)
04392     {
04393       c2[i] = StandardChi2(NExp);
04394     }
04395     else if(FitMethod==3)
04396     {
04397       //Likelihood: "Standard" (N syst, N nuisance)
04398       //Calculate the likelihood (x2 for chi)
04399       c2[i] = StandardLikelihood();
04400     }
04401     else if(FitMethod==4)
04402     {
04403       //Likelihood: Bin by Bin Calculation of Systematics
04404       //Calculate the likelihood (x2 for chi)
04405       c2[i] = BinLikelihood();
04406     }
04407     else
04408     {
04409       cout<<"Error in GetMinLikelihood(): Unknown 'FitMethod'."<<endl;
04410     }
04411   }
04412   
04413   TGraph *g = new TGraph(ns,th13,c2);
04414   fit = new TF1("pol6", "pol6");
04415   g->Fit(fit, "Q");//fit to second order polynominal
04416   minchi2 = fit->GetMinimum(0,max);
04417   
04418   return minchi2;
04419 }

double NueFit2D::GetMinLikelihood_Delta ( bool  normalhier = true  )  [protected, virtual]

Reimplemented in NueFit2D_Joint.

Definition at line 4420 of file NueFit2D.cxx.

References BinLikelihood(), Bkgd, DefineBinDlnLMinuit(), DefineStdDlnLMinuit(), delta, ErrCalc, ErrorMatrix, Extrap, FitMethod, FracErr_Bkgd, FracErr_Sig, grid_i_dm2_21, grid_i_dm2_32, grid_i_th12, grid_i_th13, grid_i_th23, grid_n_dm2_21, grid_n_dm2_32, grid_n_th12, grid_n_th13, grid_n_th23, InvErrorMatrix, OscPar::kDeltaM12, OscPar::kDeltaM23, OscPar::kTh12, OscPar::kTh13, OscPar::kTh23, nBins, nDeltaSteps, NExp, NObs, PoissonChi2(), ScaledChi2(), ErrorCalc::SetUseGrid(), Sig, StandardChi2(), and StandardLikelihood().

Referenced by RunMultiBinFC_MHDeltaFit(), and RunMultiBinPseudoExpts_MHDeltaFit().

04421 {
04422   if(NObs==0)
04423   {
04424     cout<<"NObs not set.  Quitting..."<<endl;
04425     return 0;
04426   }
04427   if(FitMethod==1 && (FracErr_Bkgd==0 || FracErr_Sig==0))
04428   {
04429     cout<<"FracErr_Bkgd and FracErr_Sig need to be set for ScaledChi2.  Quitting..."<<endl;
04430     return 0;
04431   }
04432   if(Extrap.size()==0)
04433   {
04434     cout<<"No Extrapolate2D input.  Quitting..."<<endl;
04435     return 0;
04436   }
04437   
04438   if(FitMethod==3) DefineStdDlnLMinuit();
04439   if(FitMethod==4) DefineBinDlnLMinuit();
04440   if(FitMethod==3 || FitMethod==4)
04441   {
04442     if(ErrCalc!=0) ErrCalc->SetUseGrid(false);
04443   }
04444   
04445   Bkgd = (TH1D*)NObs->Clone("Bkgd");
04446   Bkgd->Reset();
04447   Sig = (TH1D*)NObs->Clone("Sig");
04448   Sig->Reset();
04449   TH1D *NExp = (TH1D*)NObs->Clone("NExp");
04450   NExp->Reset();
04451   
04452   unsigned int ie;
04453   for(ie=0;ie<Extrap.size();ie++)
04454   {
04455     Extrap[ie]->GetPrediction();
04456     if(normalhier)
04457     {
04458       Extrap[ie]->SetOscPar(OscPar::kTh13,grid_n_th13);
04459       Extrap[ie]->SetOscPar(OscPar::kTh12,grid_n_th12);
04460       Extrap[ie]->SetOscPar(OscPar::kTh23,grid_n_th23);
04461       Extrap[ie]->SetOscPar(OscPar::kDeltaM12,grid_n_dm2_21);
04462       Extrap[ie]->SetOscPar(OscPar::kDeltaM23,grid_n_dm2_32);
04463     }
04464     else
04465     {
04466       Extrap[ie]->SetOscPar(OscPar::kTh13,grid_i_th13);
04467       Extrap[ie]->SetOscPar(OscPar::kTh12,grid_i_th12);
04468       Extrap[ie]->SetOscPar(OscPar::kTh23,grid_i_th23);
04469       Extrap[ie]->SetOscPar(OscPar::kDeltaM12,grid_i_dm2_21);
04470       Extrap[ie]->SetOscPar(OscPar::kDeltaM23,grid_i_dm2_32);
04471     }
04472     Extrap[ie]->OscillatePrediction();
04473   }
04474   
04475   Int_t i;
04476   
04477   if(ErrorMatrix==0) ErrorMatrix = new TH2D("ErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
04478   if(InvErrorMatrix==0) InvErrorMatrix = new TH2D("InvErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
04479   
04480   Double_t delta = 0;
04481   //   TF1* fit;
04482   double minchi2,mindelta;
04483   Double_t increment = 0;
04484   if(nDeltaSteps>0) increment = 2*TMath::Pi()/(nDeltaSteps);
04485   const int nd=nDeltaSteps+1;
04486   double *d = new double[nDeltaSteps+1];
04487   double *c2 = new double[nDeltaSteps+1];
04488   for(i=0;i<nd;i++)
04489   {
04490     delta = i*increment;
04491     d[i] = delta;
04492     for(ie=0;ie<Extrap.size();ie++)
04493     {
04494       Extrap[ie]->SetDeltaCP(delta);
04495       Extrap[ie]->OscillatePrediction();
04496     }
04497     Bkgd->Reset();
04498     Sig->Reset();
04499     NExp->Reset();
04500     for(ie=0;ie<Extrap.size();ie++)
04501     {
04502       Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
04503       Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
04504     }
04505     NExp->Add(Bkgd);
04506     NExp->Add(Sig);
04507     
04508     c2[i] = 1e10;
04509     if(FitMethod==0)
04510     {
04511       c2[i] = PoissonChi2(NExp);
04512     }
04513     else if(FitMethod==1)
04514     {
04515       c2[i] = ScaledChi2(Bkgd,Sig);
04516     }
04517     else if(FitMethod==2)
04518     {
04519       c2[i] = StandardChi2(NExp);
04520     }
04521     else if(FitMethod==3)
04522     {
04523       //Likelihood: "Standard" (N syst, N nuisance)
04524       //Calculate the likelihood (x2 for chi)
04525       c2[i] = StandardLikelihood();
04526     }
04527     else if(FitMethod==4)
04528     {
04529       //Likelihood: Bin by Bin Calculation of Systematics
04530       //Calculate the likelihood (x2 for chi)
04531       c2[i] = BinLikelihood();
04532     }
04533     else
04534     {
04535       cout<<"Error in GetMinLikelihood_Delta(): Unknown 'FitMethod'."<<endl;
04536     }
04537   }
04538   
04539   //can we actually fit this to a nice function?
04540   //   TGraph *g = new TGraph(ns,th13,c2);
04541   //   fit = new TF1("pol6", "pol6");
04542   //   g->Fit(fit, "Q");//fit to second order polynominal
04543   //   minchi2 = fit->GetMinimum(0,max);
04544   
04545   minchi2=1000;
04546   mindelta=0;
04547   for(i=0;i<nd;i++)
04548   {
04549     if(c2[i]<minchi2)
04550     {
04551       minchi2 = c2[i];
04552       mindelta = d[i];
04553     }
04554   }
04555   
04556   cout<<"min delta = "<<mindelta<<" , min chi2 = "<<minchi2<<endl;
04557   
04558   delete [] d;
04559   delete [] c2;
04560   
04561   return minchi2;
04562 }

double NueFit2D::GetSensitivityAt ( double  delta = 0,
bool  normalhier = true 
) [virtual]

Reimplemented in NueFit2D_Joint.

Definition at line 3188 of file NueFit2D.cxx.

References BinLikelihood(), Bkgd, DefineBinDlnLMinuit(), DefineStdDlnLMinuit(), ErrorMatrix, Extrap, FitMethod, FracErr_Bkgd, FracErr_Sig, InvErrorMatrix, nBins, NExp, NObs, nSinSq2Th13Steps, PoissonChi2(), ScaledChi2(), Sig, SinSq2Th13High, SinSq2Th13Low, StandardChi2(), and StandardLikelihood().

03189 {
03190 
03191   if(NObs==0)
03192   {
03193     cout<<"NObs not set.  Quitting..."<<endl;
03194     return 0;
03195   }
03196   if(FitMethod==1 && (FracErr_Bkgd==0 || FracErr_Sig==0))
03197   {
03198     cout<<"FracErr_Bkgd and FracErr_Sig need to be set for ScaledChi2.  Quitting..."<<endl;
03199     return 0;
03200   }
03201   if(Extrap.size()==0)
03202   {
03203     cout<<"No Extrapolate2D input.  Quitting..."<<endl;
03204     return 0;
03205   }
03206   
03207   if(FitMethod==3) DefineStdDlnLMinuit();
03208   if(FitMethod==4) DefineBinDlnLMinuit();
03209   
03210   Bkgd = (TH1D*)NObs->Clone("Bkgd");
03211   Bkgd->Reset();
03212   Sig = (TH1D*)NObs->Clone("Sig");
03213   Sig->Reset();
03214   TH1D *NExp = (TH1D*)NObs->Clone("NExp");
03215   NExp->Reset();
03216   
03217   unsigned int ie;
03218   for(ie=0;ie<Extrap.size();ie++)
03219   {
03220     Extrap[ie]->GetPrediction();
03221   }
03222   
03223   Int_t i;
03224   
03225   if(ErrorMatrix==0) ErrorMatrix = new TH2D("ErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
03226   if(InvErrorMatrix==0) InvErrorMatrix = new TH2D("InvErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
03227   
03228   Double_t ss2th13 = 0;
03229   Double_t delchi2 = 0,delchi2prev = 0;
03230   Double_t contourlvl = 2.71;
03231   Double_t prev = 0;
03232   Double_t best = 0;
03233   Double_t Th13increment = 0;
03234   if(nSinSq2Th13Steps>0) Th13increment = (SinSq2Th13High - SinSq2Th13Low)/(nSinSq2Th13Steps);
03235   double sens=-1;
03236   double chi2[3],val[3];
03237   TGraph *g3;
03238   TF1* fit;
03239   double minchi2;
03240   double limit = 0;
03241   
03242   for(ie=0;ie<Extrap.size();ie++)
03243   {
03244     Extrap[ie]->SetDeltaCP(delta);
03245     if(!normalhier) Extrap[ie]->InvertMassHierarchy();
03246   }
03247   
03248   contourlvl = 2.71;
03249   
03250   best=-1.;
03251   minchi2=100;
03252   for(i=0;i<3;i++)
03253   {
03254     chi2[i]=-1.;
03255     val[i]=-1.;
03256   }
03257   for(i=0;i<nSinSq2Th13Steps+1;i++)
03258   {
03259     chi2[0] = chi2[1];
03260     chi2[1] = chi2[2];
03261     val[0] = val[1];
03262     val[1] = val[2];
03263     ss2th13 = i*Th13increment + SinSq2Th13Low;
03264     for(ie=0;ie<Extrap.size();ie++)
03265     {
03266       Extrap[ie]->SetSinSq2Th13(ss2th13);
03267       Extrap[ie]->OscillatePrediction();
03268     }
03269     Bkgd->Reset();
03270     Sig->Reset();
03271     NExp->Reset();
03272     for(ie=0;ie<Extrap.size();ie++)
03273     {
03274       Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
03275       Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
03276     }
03277     NExp->Add(Bkgd);
03278     NExp->Add(Sig);
03279     
03280     chi2[2] = 1e10;
03281     if(FitMethod==0)
03282     {
03283       chi2[2] = PoissonChi2(NExp);
03284     }
03285     else if(FitMethod==1)
03286     {
03287       chi2[2] = ScaledChi2(Bkgd,Sig);
03288     }
03289     else if(FitMethod==2)
03290     {
03291       chi2[2] = StandardChi2(NExp);
03292     }
03293     else if(FitMethod==3)
03294     {
03295       //Likelihood: "Standard" (N syst, N nuisance)
03296       //Calculate the likelihood (x2 for chi)
03297       chi2[2] = StandardLikelihood();
03298     }
03299     else if(FitMethod==4)
03300     {
03301       //Likelihood: Bin by Bin Calculation of Systematics
03302       //Calculate the likelihood (x2 for chi)
03303       chi2[2] = BinLikelihood();
03304     }
03305     else
03306     {
03307       cout<<"Error in GetSensitivityAt(): Unknown 'FitMethod'."<<endl;
03308     }
03309     
03310     val[2] = ss2th13;
03311     
03312     if(i<2) continue;
03313     
03314     if(i<3 && chi2[2]>chi2[1] && chi2[1]>chi2[0])//first three points are increasing, first point is minimum.
03315     {
03316       best = val[0];
03317       minchi2 = chi2[0];
03318       cout<<"minimum at 1st point: "<<minchi2<<" at "<<best<<endl;
03319       break;
03320     }
03321     
03322     if(chi2[2]>chi2[1] && chi2[0]>chi2[1])//found minimum
03323     {
03324       g3 = new TGraph(3, val, chi2);
03325       fit = new TF1("pol2", "pol2");
03326       g3->Fit(fit, "Q");//fit to second order polynominal
03327       if(fit->GetParameter(2) > 0)//if the x^2 term is nonzero
03328       {
03329         best = -fit->GetParameter(1)/(2*fit->GetParameter(2));//the location of the minimum is -p1/(2*p2)
03330         minchi2 = fit->GetParameter(0) + fit->GetParameter(1)*best + fit->GetParameter(2)*best*best;
03331         cout<<"minimum with fit: "<<minchi2<<" at "<<best<<endl;
03332       }
03333       else//if the x^2 term is zero, then just use the minimum you got by scanning
03334       {
03335         best = val[1];
03336         minchi2 = chi2[1];
03337         cout<<"minimum with scan: "<<minchi2<<" at "<<best<<endl;
03338       }
03339       break;
03340     }
03341   }
03342   
03343   limit = -1;
03344   delchi2prev = 1000;
03345   prev = 0;
03346   for(i=0;i<nSinSq2Th13Steps+1;i++)
03347   {
03348     ss2th13 = i*Th13increment + SinSq2Th13Low;
03349     for(ie=0;ie<Extrap.size();ie++)
03350     {
03351       Extrap[ie]->SetSinSq2Th13(ss2th13);
03352       Extrap[ie]->OscillatePrediction();
03353     }
03354     
03355     Bkgd->Reset();
03356     Sig->Reset();
03357     NExp->Reset();
03358     
03359     for(ie=0;ie<Extrap.size();ie++)
03360     {
03361       Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
03362       Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
03363     }
03364     NExp->Add(Bkgd);
03365     NExp->Add(Sig);
03366     
03367     delchi2 = 1e10;
03368     if(FitMethod==0)
03369     {
03370       delchi2 = PoissonChi2(NExp) - minchi2;
03371     }
03372     else if(FitMethod==1)
03373     {
03374       delchi2 = ScaledChi2(Bkgd,Sig) - minchi2;
03375     }
03376     else if(FitMethod==2)
03377     {
03378       delchi2 = StandardChi2(NExp) - minchi2;
03379     }
03380     else if(FitMethod==3)
03381     {
03382       //Likelihood: "Standard" (N syst, N nuisance)
03383       //Calculate the likelihood (x2 for chi)
03384       delchi2 = StandardLikelihood() - minchi2;
03385     }
03386     else if(FitMethod==4)
03387     {
03388       //Likelihood: Bin by Bin Calculation of Systematics
03389       //Calculate the likelihood (x2 for chi)
03390       delchi2 = BinLikelihood() - minchi2;
03391     }
03392     else
03393     {
03394       cout<<"Error in GetSensitivityAt(): Unknown 'FitMethod'."<<endl;
03395     }
03396 
03397     //RBT: How to run the separate options
03398 
03399 //     if (opt==0){
03400 //       //Chi2 standard
03401 //       chi2 = StandardChi2(NExp);
03402 //     } else if (opt==1){
03403 //       //Likelihood: Bin by Bin Calculation of Systematics
03404 //       //Calculate the likelihood (x2 for chi)
03405 //       chi2 = BinLikelihood();
03406 //     } else if (opt==2){
03407 //       //Likelihood: "Standard" (N syst, N nuisance)
03408 //       //Calculate the likelihood (x2 for chi)
03409 //       chi2 = StandardLikelihood();
03410 //     }
03411 
03412     if(delchi2>contourlvl && delchi2prev<contourlvl && TMath::Abs(delchi2prev-delchi2)<0.1)
03413     {
03414       limit = ss2th13 + ((ss2th13-prev)/(delchi2 - delchi2prev))*(contourlvl - delchi2);
03415       sens = limit;
03416       break;
03417     }
03418     delchi2prev = delchi2;
03419     prev = ss2th13;
03420   }
03421   
03422   return sens;
03423 }

void NueFit2D::LetsIH ( int  lihinput = 0  )  [inline]

Definition at line 46 of file NueFit2D.h.

References LIH.

00046                                {
00047       LIH = lihinput;
00048     }

double NueFit2D::PoissonChi2 ( TH1D *  nexp  )  [protected]
void NueFit2D::ReadGridFiles (  )  [protected, virtual]

Reimplemented in NueFit2D_Joint.

Definition at line 144 of file NueFit2D.cxx.

References Extrap, Form(), grid_background, grid_bin_oscparerr, grid_bnuecc, grid_delta, grid_i_dm2_21, grid_i_dm2_32, grid_i_th12, grid_i_th13, grid_i_th23, grid_n_dm2_21, grid_n_dm2_32, grid_n_th12, grid_n_th13, grid_n_th23, grid_nc, grid_nue, grid_numucc, grid_nutaucc, grid_signal, grid_sinsq2th13, GridFileName_Inverted, GridFileName_Normal, GridNorm, GridScale_Inverted, GridScale_Normal, GridTree_2_Inverted, GridTree_2_Normal, GridTree_Inverted, GridTree_Normal, gSystem(), IncludeOscParErrs, nBins, nPts_Inverted, nPts_Normal, paramtree_Inverted, and paramtree_Normal.

Referenced by RunDataGrid(), RunFCAnalytical(), RunFCTraditional(), RunMultiBinFC(), RunMultiBinFC_MHDeltaFit(), RunMultiBinPseudoExpts(), RunMultiBinPseudoExpts_MHDeltaFit(), and RunPseudoExperiments().

00145 {
00146   double fp;
00147   unsigned int i;
00148   TTree *temp=0;
00149   unsigned int j;
00150   
00151   for(i=0;i<nBins;i++)
00152   {
00153     grid_bin_oscparerr.push_back(0);
00154   }
00155   
00156   TFile *fnorm;
00157   GridTree_Normal.clear();
00158   GridTree_2_Normal.clear();
00159   nPts_Normal = 0;
00160   if(!gSystem->AccessPathName(gSystem->ExpandPathName(GridFileName_Normal.c_str())))//if file exists
00161   {
00162     fnorm = new TFile(gSystem->ExpandPathName(GridFileName_Normal.c_str()),"READ");
00163     for(i=0;i<nBins;i++)
00164     {
00165       temp = (TTree*)fnorm->Get(Form("Bin_%i",i));
00166       temp->SetName(Form("Bin_%i_Normal",i));
00167       temp->SetBranchAddress("Background",&grid_background);
00168       temp->SetBranchAddress("Signal",&grid_signal);
00169       temp->SetBranchAddress("Delta",&grid_delta);
00170       temp->SetBranchAddress("Th13Axis",&grid_sinsq2th13);
00171       if(IncludeOscParErrs)
00172       {
00173         temp->SetBranchAddress("DNExp_DOscPars",&grid_bin_oscparerr[i]);
00174       }
00175       GridTree_Normal.push_back(temp);
00176       
00177       GridTree_2_Normal.push_back( vector<TTree*>() );
00178       
00179       for(j=0;j<Extrap.size();j++)
00180       {
00181         temp = (TTree*)fnorm->Get(Form("Bin_%i_Run_%i",i,j));
00182         temp->SetName(Form("Bin_%i_Run_%i_Normal",i,j));
00183         temp->SetBranchAddress("NC",&grid_nc);
00184         temp->SetBranchAddress("NuMuCC",&grid_numucc);
00185         temp->SetBranchAddress("BNueCC",&grid_bnuecc);
00186         temp->SetBranchAddress("NuTauCC",&grid_nutaucc);
00187         temp->SetBranchAddress("Signal",&grid_nue);
00188         temp->SetBranchAddress("Delta",&grid_delta);
00189         temp->SetBranchAddress("Th13Axis",&grid_sinsq2th13);
00190         GridTree_2_Normal[i].push_back(temp);
00191       }
00192     }
00193     nPts_Normal = GridTree_Normal[0]->GetEntries();
00194     
00195     paramtree_Normal = (TTree*)fnorm->Get("paramtree");
00196     paramtree_Normal->SetName("paramtree_Normal");
00197     paramtree_Normal->SetBranchAddress("farPOT",&fp);
00198     paramtree_Normal->SetBranchAddress("Theta12",&grid_n_th12);
00199     paramtree_Normal->SetBranchAddress("Theta23",&grid_n_th23);
00200     paramtree_Normal->SetBranchAddress("DeltaMSq23",&grid_n_dm2_32);
00201     paramtree_Normal->SetBranchAddress("DeltaMSq12",&grid_n_dm2_21);
00202     paramtree_Normal->SetBranchAddress("Theta13",&grid_n_th13);
00203     paramtree_Normal->GetEntry(0);
00204     
00205     if(GridNorm>0)
00206     {
00207       GridScale_Normal = GridNorm/fp;
00208     }
00209   }
00210   else
00211   {
00212     cout<<"Grid file (normal hierarchy) doesn't exist."<<endl;
00213     return;
00214   }
00215   
00216   TFile *finvt;
00217   GridTree_Inverted.clear();
00218   nPts_Inverted = 0;
00219   if(!gSystem->AccessPathName(gSystem->ExpandPathName(GridFileName_Inverted.c_str())))//if file exists
00220   {
00221     finvt = new TFile(gSystem->ExpandPathName(GridFileName_Inverted.c_str()),"READ");
00222     for(i=0;i<nBins;i++)
00223     {
00224       temp = (TTree*)finvt->Get(Form("Bin_%i",i));
00225       temp->SetName(Form("Bin_%i_Inverted",i));
00226       temp->SetBranchAddress("Background",&grid_background);
00227       temp->SetBranchAddress("Signal",&grid_signal);
00228       temp->SetBranchAddress("Delta",&grid_delta);
00229       temp->SetBranchAddress("Th13Axis",&grid_sinsq2th13);
00230       if(IncludeOscParErrs)
00231       {
00232         temp->SetBranchAddress("DNExp_DOscPars",&grid_bin_oscparerr[i]);
00233       }
00234       GridTree_Inverted.push_back(temp);
00235       
00236       GridTree_2_Inverted.push_back( vector<TTree*>() );
00237       
00238       for(j=0;j<Extrap.size();j++)
00239       {
00240         temp = (TTree*)finvt->Get(Form("Bin_%i_Run_%i",i,j));
00241         temp->SetName(Form("Bin_%i_Run_%i_Inverted",i,j));
00242         temp->SetBranchAddress("NC",&grid_nc);
00243         temp->SetBranchAddress("NuMuCC",&grid_numucc);
00244         temp->SetBranchAddress("BNueCC",&grid_bnuecc);
00245         temp->SetBranchAddress("NuTauCC",&grid_nutaucc);
00246         temp->SetBranchAddress("Signal",&grid_nue);
00247         temp->SetBranchAddress("Delta",&grid_delta);
00248         temp->SetBranchAddress("Th13Axis",&grid_sinsq2th13);
00249         GridTree_2_Inverted[i].push_back(temp);
00250       }
00251     }
00252     nPts_Inverted = GridTree_Inverted[0]->GetEntries();
00253     
00254     paramtree_Inverted = (TTree*)finvt->Get("paramtree");
00255     paramtree_Inverted->SetName("paramtree_Inverted");
00256     paramtree_Inverted->SetBranchAddress("farPOT",&fp);
00257     paramtree_Inverted->SetBranchAddress("Theta12",&grid_i_th12);
00258     paramtree_Inverted->SetBranchAddress("Theta23",&grid_i_th23);
00259     paramtree_Inverted->SetBranchAddress("DeltaMSq23",&grid_i_dm2_32);
00260     paramtree_Inverted->SetBranchAddress("DeltaMSq12",&grid_i_dm2_21);
00261     paramtree_Inverted->SetBranchAddress("Theta13",&grid_i_th13);
00262     paramtree_Inverted->GetEntry(0);
00263     
00264     if(GridNorm>0)
00265     {
00266       GridScale_Inverted = GridNorm/fp;
00267     }
00268   }
00269   else
00270   {
00271     cout<<"Grid file (inverted hierarchy) doesn't exist."<<endl;
00272     return;
00273   }
00274   
00275   return;
00276 }

void NueFit2D::Run2DSterileSlice (  )  [virtual]

Definition at line 5862 of file NueFit2D.cxx.

References BinLikelihood(), Bkgd, DefineBinDlnLMinuit(), DefineStdDlnLMinuit(), ErrorMatrix, Extrap, FitMethod, FracErr_Bkgd, FracErr_Sig, gSystem(), InvErrorMatrix, LIH, nBins, NExp, NObs, nSinSqTh14Steps, nSinSqTh24Steps, outFileName, PoissonChi2(), ScaledChi2(), Sig, SinSqTh14High, SinSqTh14Low, SinSqTh24High, SinSqTh24Low, StandardChi2(), StandardLikelihood(), and Theta14.

05862                                 {
05863   //Given a value of Dm41, produces a 2D chisquared graph of both sin(th14)^2 vs sin(th24)^2
05864 
05865 
05866 
05867   if(NObs==0)
05868     {
05869       cout<<"NObs not set.  Quitting..."<<endl;
05870       return;
05871     }
05872   if(FitMethod==1 && (FracErr_Bkgd==0 || FracErr_Sig==0))
05873     {
05874       cout<<"FracErr_Bkgd and FracErr_Sig need to be set for ScaledChi2.  Quitting..."<<endl;
05875       return;
05876     }
05877   if(Extrap.size()==0)
05878     {
05879       cout<<"No Extrapolate2D input.  Quitting..."<<endl;
05880       return;
05881     }
05882   
05883   if(FitMethod==3) DefineStdDlnLMinuit();
05884   if(FitMethod==4) DefineBinDlnLMinuit();
05885 
05886   Bkgd = (TH1D*)NObs->Clone("Bkgd");
05887   Bkgd->Reset();
05888   Sig = (TH1D*)NObs->Clone("Sig");
05889   Sig->Reset();
05890   NExp = (TH1D*)NObs->Clone("NExp");
05891   NExp->Reset();
05892   
05893 
05894   unsigned int ie;
05895   for(ie=0;ie<Extrap.size();ie++)
05896   {
05897     Extrap[ie]->GetPrediction();
05898   }
05899   
05900   if(ErrorMatrix==0) ErrorMatrix = new TH2D("ErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
05901   if(InvErrorMatrix==0) InvErrorMatrix = new TH2D("InvErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
05902   
05903   Double_t Theta14;
05904   //Double_t Theta24;
05905   //Double_t D41;
05906 
05907   Int_t i,j,k,s;
05908   Int_t idx = 0; //Array indexer
05909 
05910   int arraysize = (nSinSqTh14Steps+1)*(nSinSqTh24Steps+1);
05911   cout << arraysize << endl;
05912 
05913   double Ue42[2601];
05914   //double Um42[2601];
05915   double Ssqth24[2601];
05916   double chi[2601];
05917   double dchi[2601];
05918 
05919   double minchi2;
05920   double mc2;
05921 
05922   Double_t ssth14 = 0;
05923   Double_t csth14 = 0;
05924   Double_t Th14increment = 0;
05925   if(nSinSqTh14Steps>0) Th14increment = (SinSqTh14High - SinSqTh14Low)/(nSinSqTh14Steps);
05926  
05927   Double_t ssth24 = 0;
05928   Double_t Th24increment = 0;
05929   if(nSinSqTh24Steps>0) Th24increment = (SinSqTh24High - SinSqTh24Low)/(nSinSqTh24Steps);
05930 
05931   if(LIH==1){
05932     for(ie=0;ie<Extrap.size();ie++) Extrap[ie]->InvertMassHierarchy();
05933   }
05934 
05935   for(i=0; i<nSinSqTh14Steps+1;i++){
05936 
05937     ssth14 = i*Th14increment + SinSqTh14Low;
05938     Theta14 = TMath::ASin(TMath::Sqrt(ssth14));
05939     csth14 = TMath::Cos(Theta14)*TMath::Cos(Theta14);
05940       
05941 
05942     for(ie=0;ie<Extrap.size();ie++){
05943       Extrap[ie]->SetSinSqTh14(ssth14);
05944     }
05945 
05946     minchi2=100;
05947     mc2=1000;
05948 
05949     for(j=0;j<nSinSqTh24Steps+1;j++){
05950 
05951       ssth24 = j*Th24increment + SinSqTh24Low;
05952  
05953       for(ie=0;ie<Extrap.size();ie++){
05954         Extrap[ie]->SetSinSqTh24(ssth24);
05955         Extrap[ie]->OscillatePrediction();
05956       }
05957 
05958       Bkgd->Reset();
05959       Sig->Reset();
05960       NExp->Reset();
05961 
05962       for(ie=0;ie<Extrap.size();ie++)
05963       {
05964         Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
05965         Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
05966       }
05967       NExp->Add(Bkgd);
05968       NExp->Add(Sig);
05969       
05970       //delchi2 = 1e10;
05971       if(FitMethod==0)
05972       {
05973         Ue42[idx] = ssth14;
05974         //Um42[idx] = csth14*ssth24;
05975         Ssqth24[idx] = ssth24;
05976         chi[idx] = PoissonChi2(NExp);
05977       }
05978       else if(FitMethod==1)
05979       {
05980         Ue42[idx] = ssth14;
05981         //Um42[idx] = csth14*ssth24;
05982         Ssqth24[idx] = ssth24;
05983         chi[idx] = ScaledChi2(Bkgd,Sig);
05984       }
05985       else if(FitMethod==2)
05986       {
05987         Ue42[idx] = ssth14;
05988         //Um42[idx] = csth14*ssth24;
05989         Ssqth24[idx] = ssth24;
05990         chi[idx] = StandardChi2(NExp);
05991       }
05992       else if(FitMethod==3)
05993       {
05994         //Likelihood: "Standard" (N syst, N nuisance)
05995         //Calculate the likelihood (x2 for chi)
05996         Ue42[idx] = ssth14;
05997         //Um42[idx] = csth14*ssth24;
05998         Ssqth24[idx] = ssth24;
05999         chi[idx] = StandardLikelihood();
06000       }
06001       else if(FitMethod==4)
06002       {
06003         //Likelihood: Bin by Bin Calculation of Systematics
06004         //Calculate the likelihood (x2 for chi)
06005         Ue42[idx] = ssth14;
06006         //Um42[idx] = csth14*ssth24;
06007         Ssqth24[idx] = ssth24;
06008         chi[idx] = BinLikelihood();
06009       }
06010       else
06011       {
06012         cout<<"Error in Run2DSterileSlice(): Unknown 'FitMethod'."<<endl;
06013       }
06014 
06015       idx++;      
06016 
06017     }//TH24 loop
06018 
06019 
06020   }//TH14 loop
06021 
06022   double Ue42best[1];
06023   //double Um42best[1];
06024   double Ssqth24best[1];
06025   
06026  for(k=0;k<arraysize;k++){
06027    if(chi[k]<mc2){
06028      mc2=chi[k];
06029      Ue42best[0]=Ue42[k];
06030      //Um42best[0]=Um42[k];
06031      Ssqth24best[0]=Ssqth24[k];
06032    }
06033  }
06034 
06035  for(s=0;s<arraysize;s++){
06036    dchi[s]=chi[s]-mc2;
06037    if(abs(dchi[s])<0.00001){
06038      cout <<"I have a zero!"<<endl;
06039    }
06040   
06041  }
06042 
06043 
06044 
06045 
06046   //make a TGraph
06047   TFile *w = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"RECREATE");
06048   Int_t d = 1;
06049 
06050   TGraph *bpss = new TGraph(d,Ue42best,Ssqth24best);
06051   bpss->SetName("bpss");
06052   bpss->Write();
06053 
06054   /*
06055   TGraph *bpUU = new TGraph(d,Ue42best,Um42best);
06056   bpUU->SetName("bpUU");
06057   bpUU->Write();
06058   */
06059 
06060   TGraph2D *ss = new TGraph2D(arraysize,Ue42,Ssqth24,chi);
06061   ss->SetName("ss");
06062   ss->GetXaxis()->SetTitle("sin^{2}#theta_{14}");
06063   ss->GetYaxis()->SetTitle("sin^{2}#theta_{24}");
06064   ss->GetZaxis()->SetTitle("-2lnL");
06065   ss->Write();
06066 
06067   TGraph2D *dss = new TGraph2D(arraysize,Ue42,Ssqth24,dchi);
06068   dss->SetName("dss");
06069   dss->GetXaxis()->SetTitle("sin^{2}#theta_{14}");
06070   dss->GetYaxis()->SetTitle("sin^{2}#theta_{24}");
06071   dss->GetZaxis()->SetTitle("-2#DeltalnL");
06072   dss->Write();
06073 
06074   /*
06075   TGraph2D *UU = new TGraph2D(arraysize,Ue42,Um42,chi);
06076   UU->SetName("UU");
06077   UU->GetXaxis()->SetTitle("sin^{2}#theta_{14}");
06078   UU->GetYaxis()->SetTitle("cos^{2}#theta_{14}sin^{2}#theta_{24}");
06079   UU->GetZaxis()->SetTitle("-2lnL");
06080   UU->Write();
06081 
06082   TGraph2D *dUU = new TGraph2D(arraysize,Ue42,Um42,dchi);
06083   dUU->SetName("dUU");
06084   dUU->GetXaxis()->SetTitle("sin^{2}#theta_{14}");
06085   dUU->GetYaxis()->SetTitle("cos^{2}#theta_{14}sin^{2}#theta_{24}");
06086   dUU->GetZaxis()->SetTitle("-2#DeltalnL");
06087   dUU->Write();
06088   */
06089 
06090   w->Close();
06091   return;
06092 
06093 
06094 }//2D SterileSlice

void NueFit2D::RunDataGrid ( string  filenorm,
string  fileinvt 
) [virtual]

Reimplemented in NueFit2D_Joint.

Definition at line 1861 of file NueFit2D.cxx.

References BinLikelihood(), Bkgd, DefineBinDlnLMinuit(), DefineStdDlnLMinuit(), ErrCalc, ErrorMatrix, Extrap, FitMethod, FracErr_Bkgd, FracErr_Sig, GetMinLikelihood(), grid_background, grid_bnuecc, grid_delta, grid_nc, grid_nue, grid_numucc, grid_nutaucc, grid_signal, grid_sinsq2th13, GridScale_Inverted, GridScale_Normal, GridTree_2_Inverted, GridTree_2_Normal, GridTree_Inverted, GridTree_Normal, gSystem(), InvErrorMatrix, nBins, NObs, nPts_Inverted, nPts_Normal, PoissonChi2(), ReadGridFiles(), ScaledChi2(), ErrorCalc::SetGridPred(), ErrorCalc::SetUseGrid(), Sig, StandardChi2(), and StandardLikelihood().

01862 {
01863   if(NObs==0)
01864   {
01865     cout<<"NObs not set.  Quitting..."<<endl;
01866     return;
01867   }
01868   if(Extrap.size()==0)
01869   {
01870     cout<<"No Extrapolate2D input.  Quitting..."<<endl;
01871     return;
01872   }
01873   for(unsigned int ie=0;ie<Extrap.size();ie++)
01874   {
01875     Extrap[ie]->GetPrediction();
01876   }
01877   if(FitMethod==1 && (FracErr_Bkgd==0 || FracErr_Sig==0))
01878   {
01879     cout<<"FracErr_Bkgd and FracErr_Sig need to be set for ScaledChi2.  Quitting..."<<endl;
01880     return;
01881   }
01882   if(ErrCalc==0)
01883   {
01884     cout<<"No ErrorCalc object set!  Quitting..."<<endl;
01885     return;
01886   }
01887   if(FitMethod==3) DefineStdDlnLMinuit();
01888   if(FitMethod==4) DefineBinDlnLMinuit();
01889   
01890   nBins = NObs->GetNbinsX();
01891   if(ErrorMatrix==0) ErrorMatrix = new TH2D("ErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
01892   if(InvErrorMatrix==0) InvErrorMatrix = new TH2D("InvErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
01893   
01894   ReadGridFiles();
01895   
01896   if(nPts_Normal==0 || nPts_Inverted==0) return;
01897   
01898   TH1D *nexp_bkgd = new TH1D("nexp_bkgd","",nBins,-0.5,nBins-0.5);
01899   TH1D *nexp_signal = new TH1D("nexp_signal","",nBins,-0.5,nBins-0.5);
01900   TH1D *nexp = new TH1D("nexp","",nBins,-0.5,nBins-0.5);
01901   
01902   int i;
01903   unsigned int j,k;
01904   
01905   double chi2data,chi2min;
01906   
01907   vector< vector<double> > nc,numucc,bnuecc,nutaucc,sig;
01908   for(j=0;j<nBins;j++)
01909   {
01910     nc.push_back( vector<double>() );
01911     numucc.push_back( vector<double>() );
01912     bnuecc.push_back( vector<double>() );
01913     nutaucc.push_back( vector<double>() );
01914     sig.push_back( vector<double>() );
01915     for(k=0;k<Extrap.size();k++)
01916     {
01917       nc[j].push_back(0);
01918       numucc[j].push_back(0);
01919       bnuecc[j].push_back(0);
01920       nutaucc[j].push_back(0);
01921       sig[j].push_back(0);
01922     }
01923   }
01924   
01925   Bkgd = (TH1D*)NObs->Clone("Bkgd");
01926   Bkgd->Reset();
01927   Sig = (TH1D*)NObs->Clone("Sig");
01928   Sig->Reset();
01929   
01930   //normal hierarchy
01931   
01932   ofstream myfile;
01933   myfile.open(gSystem->ExpandPathName(filenorm.c_str()));
01934   
01935   for(i=0;i<nPts_Normal;i++)
01936   {
01937     if(i%100==0) cout<<100.*i/nPts_Normal<<"% complete for normal hierarchy"<<endl;
01938     
01939     nexp_bkgd->Reset();
01940     nexp_signal->Reset();
01941     nexp->Reset();
01942     
01943     for(j=0;j<nBins;j++)
01944     {
01945       GridTree_Normal[j]->GetEntry(i);
01946       nexp_bkgd->SetBinContent(j+1,grid_background*GridScale_Normal);
01947       nexp_signal->SetBinContent(j+1,grid_signal*GridScale_Normal);
01948       
01949       for(k=0;k<Extrap.size();k++)
01950       {
01951         GridTree_2_Normal[j][k]->GetEntry(i);
01952         nc[j][k] = grid_nc*GridScale_Normal;
01953         numucc[j][k] = grid_numucc*GridScale_Normal;
01954         bnuecc[j][k] = grid_bnuecc*GridScale_Normal;
01955         nutaucc[j][k] = grid_nutaucc*GridScale_Normal;
01956         sig[j][k] = grid_nue*GridScale_Normal;
01957       }
01958     }
01959     nexp->Add(nexp_bkgd,nexp_signal,1,1);
01960     ErrCalc->SetGridPred(nBins,nc,numucc,bnuecc,nutaucc,sig);
01961     
01962     chi2min=GetMinLikelihood(grid_delta,true);
01963     
01964     ErrCalc->SetUseGrid(true);//use grid predictions set up above
01965     chi2data = 1e10;
01966     if(FitMethod==0)
01967     {
01968       chi2data = PoissonChi2(nexp) - chi2min;
01969     }
01970     else if(FitMethod==1)
01971     {
01972       chi2data = ScaledChi2(Bkgd,Sig) - chi2min;
01973     }
01974     else if(FitMethod==2)
01975     {
01976       chi2data = StandardChi2(nexp) - chi2min;
01977     }
01978     else if(FitMethod==3)
01979     {
01980       //Likelihood: "Standard" (N syst, N nuisance)
01981       //Calculate the likelihood (x2 for chi)
01982       Bkgd->Reset();
01983       Bkgd->Add(nexp_bkgd);
01984       Sig->Reset();
01985       Sig->Add(nexp_signal);
01986       chi2data = StandardLikelihood() - chi2min;
01987     }
01988     else if(FitMethod==4)
01989     {
01990       //Likelihood: Bin by Bin Calculation of Systematics
01991       //Calculate the likelihood (x2 for chi)
01992       Bkgd->Reset();
01993       Bkgd->Add(nexp_bkgd);
01994       Sig->Reset();
01995       Sig->Add(nexp_signal);
01996       chi2data = BinLikelihood() - chi2min;
01997     }
01998     else
01999     {
02000       cout<<"Error in RunMultiBinFC(): Unknown 'FitMethod'."<<endl;
02001     }
02002     
02003     myfile << grid_sinsq2th13 << " " << grid_delta << " " << nexp_signal->Integral() << " ";
02004     for(j=0;j<nBins;j++)
02005     {
02006       myfile << nexp_signal->GetBinContent(j+1) << " ";
02007     }
02008     myfile << chi2data << endl;
02009   }
02010   
02011   myfile.close();
02012   
02013   //inverted hierarchy
02014   
02015   myfile.open(gSystem->ExpandPathName(fileinvt.c_str()));
02016   
02017   for(i=0;i<nPts_Inverted;i++)
02018   {
02019     if(i%100==0) cout<<100.*i/nPts_Inverted<<"% complete for inverted hierarchy"<<endl;
02020     
02021     nexp_bkgd->Reset();
02022     nexp_signal->Reset();
02023     nexp->Reset();
02024     
02025     for(j=0;j<nBins;j++)
02026     {
02027       GridTree_Inverted[j]->GetEntry(i);
02028       nexp_bkgd->SetBinContent(j+1,grid_background*GridScale_Inverted);
02029       nexp_signal->SetBinContent(j+1,grid_signal*GridScale_Inverted);
02030       
02031       for(k=0;k<Extrap.size();k++)
02032       {
02033         GridTree_2_Inverted[j][k]->GetEntry(i);
02034         nc[j][k] = grid_nc*GridScale_Inverted;
02035         numucc[j][k] = grid_numucc*GridScale_Inverted;
02036         bnuecc[j][k] = grid_bnuecc*GridScale_Inverted;
02037         nutaucc[j][k] = grid_nutaucc*GridScale_Inverted;
02038         sig[j][k] = grid_nue*GridScale_Inverted;
02039       }
02040     }
02041     nexp->Add(nexp_bkgd,nexp_signal,1,1);
02042     ErrCalc->SetGridPred(nBins,nc,numucc,bnuecc,nutaucc,sig);
02043     
02044     chi2min=GetMinLikelihood(grid_delta,false);
02045     
02046     ErrCalc->SetUseGrid(true);//use grid predictions set up above
02047     chi2data = 1e10;
02048     if(FitMethod==0)
02049     {
02050       chi2data = PoissonChi2(nexp) - chi2min;
02051     }
02052     else if(FitMethod==1)
02053     {
02054       chi2data = ScaledChi2(Bkgd,Sig) - chi2min;
02055     }
02056     else if(FitMethod==2)
02057     {
02058       chi2data = StandardChi2(nexp) - chi2min;
02059     }
02060     else if(FitMethod==3)
02061     {
02062       //Likelihood: "Standard" (N syst, N nuisance)
02063       //Calculate the likelihood (x2 for chi)
02064       Bkgd->Reset();
02065       Bkgd->Add(nexp_bkgd);
02066       Sig->Reset();
02067       Sig->Add(nexp_signal);
02068       chi2data = StandardLikelihood() - chi2min;
02069     }
02070     else if(FitMethod==4)
02071     {
02072       //Likelihood: Bin by Bin Calculation of Systematics
02073       //Calculate the likelihood (x2 for chi)
02074       Bkgd->Reset();
02075       Bkgd->Add(nexp_bkgd);
02076       Sig->Reset();
02077       Sig->Add(nexp_signal);
02078       chi2data = BinLikelihood() - chi2min;
02079     }
02080     else
02081     {
02082       cout<<"Error in RunMultiBinFC(): Unknown 'FitMethod'."<<endl;
02083     }
02084     
02085     myfile << grid_sinsq2th13 << " " << grid_delta << " " << nexp_signal->Integral() << " ";
02086     for(j=0;j<nBins;j++)
02087     {
02088       myfile << nexp_signal->GetBinContent(j+1) << " ";
02089     }
02090     myfile << chi2data << endl;
02091   }
02092   
02093   myfile.close();
02094   
02095   return;
02096 }

void NueFit2D::RunDeltaChi2Contour ( int  cl = 0  )  [virtual]

Reimplemented in NueFit2D_Joint.

Definition at line 3424 of file NueFit2D.cxx.

References BinLikelihood(), Bkgd, DefineBinDlnLMinuit(), DefineStdDlnLMinuit(), delta, DeltaHigh, DeltaLow, ErrorMatrix, Extrap, FitMethod, FracErr_Bkgd, FracErr_Sig, gSystem(), InvErrorMatrix, nBins, nDeltaSteps, NExp, NObs, nSinSq2Th13Steps, outFileName, PoissonChi2(), ScaledChi2(), Sig, SinSq2Th13High, SinSq2Th13Low, StandardChi2(), and StandardLikelihood().

03425 {
03426   if(NObs==0)
03427   {
03428     cout<<"NObs not set.  Quitting..."<<endl;
03429     return;
03430   }
03431   if(FitMethod==1 && (FracErr_Bkgd==0 || FracErr_Sig==0))
03432   {
03433     cout<<"FracErr_Bkgd and FracErr_Sig need to be set for ScaledChi2.  Quitting..."<<endl;
03434     return;
03435   }
03436   if(Extrap.size()==0)
03437   {
03438     cout<<"No Extrapolate2D input.  Quitting..."<<endl;
03439     return;
03440   }
03441   
03442   if(FitMethod==3) DefineStdDlnLMinuit();
03443   if(FitMethod==4) DefineBinDlnLMinuit();
03444 
03445   Bkgd = (TH1D*)NObs->Clone("Bkgd");
03446   Bkgd->Reset();
03447   Sig = (TH1D*)NObs->Clone("Sig");
03448   Sig->Reset();
03449   NExp = (TH1D*)NObs->Clone("NExp");
03450   NExp->Reset();
03451   
03452   unsigned int ie;
03453   for(ie=0;ie<Extrap.size();ie++)
03454   {
03455     Extrap[ie]->GetPrediction();
03456   }
03457   
03458   if(ErrorMatrix==0) ErrorMatrix = new TH2D("ErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
03459   if(InvErrorMatrix==0) InvErrorMatrix = new TH2D("InvErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
03460   
03461   Int_t i,j;
03462   
03463   Double_t ss2th13 = 0;
03464   Double_t delta = 0;
03465   Double_t Deltaincrement = 0;
03466   if(nDeltaSteps>0) Deltaincrement = (DeltaHigh - DeltaLow)/(nDeltaSteps);
03467   Double_t Th13increment = 0;
03468   if(nSinSq2Th13Steps>0) Th13increment = (SinSq2Th13High - SinSq2Th13Low)/(nSinSq2Th13Steps);
03469   
03470   double chi2[3],val[3];
03471   TGraph *g3;
03472   TF1* fit;
03473   double best;
03474   double minchi2;
03475   
03476   double limit;
03477   double delchi2;
03478   double sprev,delchi2prev;
03479   double contourlvl = 0;
03480   if(cl==0)//90% CL
03481   {
03482     contourlvl = 2.71;
03483   }
03484   else if(cl==1)//68.3% cL
03485   {
03486     contourlvl = 1.0;
03487   }
03488   else
03489   {
03490     cout<<"Error in RunDeltaChi2Contour(): Input value should be 0 or 1 for 90% or 68.3%.  Quitting..."<<endl;
03491     return;
03492   }
03493   
03494   cout<<"Seeking ";
03495   if(cl==0) cout<<"90% ";
03496   else cout<<"68% ";
03497   cout<<" CL upper limit"<<endl;
03498   
03499   vector<double> deltapts;
03500   vector<double> bestfit_norm;
03501   vector<double> bestfit_invt;
03502   vector<double> limit_norm;
03503   vector<double> limit_invt;
03504   vector<double> lowlimit_norm;
03505   vector<double> lowlimit_invt;
03506 
03507 
03508   for(j=0;j<nDeltaSteps+1;j++)
03509   {
03510     delta = j*Deltaincrement*TMath::Pi() + DeltaLow;
03511     for(ie=0;ie<Extrap.size();ie++)
03512     {
03513       Extrap[ie]->SetDeltaCP(delta);
03514 
03515     }
03516     deltapts.push_back(delta/TMath::Pi());
03517     
03518     best=-1.;
03519     minchi2=100;
03520     for(i=0;i<3;i++)
03521     {
03522       chi2[i]=-1.;
03523       val[i]=-1.;
03524     }
03525     for(i=0;i<nSinSq2Th13Steps+1;i++)
03526     {
03527       chi2[0] = chi2[1];
03528       chi2[1] = chi2[2];
03529       val[0] = val[1];
03530       val[1] = val[2];
03531       ss2th13 = i*Th13increment + SinSq2Th13Low;
03532       for(ie=0;ie<Extrap.size();ie++)
03533       {
03534         Extrap[ie]->SetSinSq2Th13(ss2th13);
03535         Extrap[ie]->OscillatePrediction();
03536       }
03537       Bkgd->Reset();
03538       Sig->Reset();
03539       NExp->Reset();
03540       for(ie=0;ie<Extrap.size();ie++)
03541       {
03542         Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
03543         Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
03544       }
03545       NExp->Add(Bkgd);
03546       NExp->Add(Sig);
03547       
03548       chi2[2] = 1e10;
03549       if(FitMethod==0)
03550       {
03551         chi2[2] = PoissonChi2(NExp);
03552       }
03553       else if(FitMethod==1)
03554       {
03555         chi2[2] = ScaledChi2(Bkgd,Sig);
03556       }
03557       else if(FitMethod==2)
03558       {
03559         chi2[2] = StandardChi2(NExp);
03560       }
03561       else if(FitMethod==3)
03562       {
03563         //Likelihood: "Standard" (N syst, N nuisance)
03564         //Calculate the likelihood (x2 for chi)
03565         chi2[2] = StandardLikelihood();
03566       }
03567       else if(FitMethod==4)
03568       {
03569         //Likelihood: Bin by Bin Calculation of Systematics
03570         //Calculate the likelihood (x2 for chi)
03571         chi2[2] = BinLikelihood();
03572       }
03573       else
03574       {
03575         cout<<"Error in RunDeltaChi2Contour(): Unknown 'FitMethod'."<<endl;
03576       }
03577       
03578       val[2] = ss2th13;
03579       
03580       if(i<2) continue;
03581       
03582       if(i<3 && chi2[2]>chi2[1] && chi2[1]>chi2[0])//first three points are increasing, first point is minimum.
03583       {
03584         best = val[0];
03585         minchi2 = chi2[0];
03586         cout<<"minimum at 1st point: "<<minchi2<<" at "<<best<<endl;
03587         break;
03588       }
03589       
03590       if(chi2[2]>chi2[1] && chi2[0]>chi2[1])//found minimum
03591       {
03592         g3 = new TGraph(3, val, chi2);
03593         fit = new TF1("pol2", "pol2");
03594         g3->Fit(fit, "Q");//fit to second order polynominal
03595         if(fit->GetParameter(2) > 0)//if the x^2 term is nonzero
03596         {
03597           best = -fit->GetParameter(1)/(2*fit->GetParameter(2));//the location of the minimum is -p1/(2*p2)
03598           minchi2 = fit->GetParameter(0) + fit->GetParameter(1)*best + fit->GetParameter(2)*best*best;
03599           cout<<"minimum with fit: "<<minchi2<<" at "<<best<<endl;
03600         }
03601         else//if the x^2 term is zero, then just use the minimum you got by scanning
03602         {
03603           best = val[1];
03604           minchi2 = chi2[1];
03605           cout<<"minimum with scan: "<<minchi2<<" at "<<best<<endl;
03606         }
03607         break;
03608       }
03609     }
03610     bestfit_norm.push_back(best);
03611     
03612     limit = -1.;
03613     delchi2prev = 1000;
03614     sprev = 0;
03615     for(i=0;i<(SinSq2Th13High-best)/Th13increment;i++){
03616       
03617       ss2th13 = i*Th13increment + best; //SinSq2Th13Low;
03618       for(ie=0;ie<Extrap.size();ie++)
03619       {
03620         Extrap[ie]->SetSinSq2Th13(ss2th13);
03621         Extrap[ie]->OscillatePrediction();
03622       }
03623       Bkgd->Reset();
03624       Sig->Reset();
03625       NExp->Reset();
03626       for(ie=0;ie<Extrap.size();ie++)
03627       {
03628         Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
03629         Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
03630       }
03631       NExp->Add(Bkgd);
03632       NExp->Add(Sig);
03633       
03634       delchi2 = 1e10;
03635       if(FitMethod==0)
03636       {
03637         delchi2 = PoissonChi2(NExp) - minchi2;
03638       }
03639       else if(FitMethod==1)
03640       {
03641         delchi2 = ScaledChi2(Bkgd,Sig) - minchi2;
03642       }
03643       else if(FitMethod==2)
03644       {
03645         delchi2 = StandardChi2(NExp) - minchi2;
03646       }
03647       else if(FitMethod==3)
03648       {
03649         //Likelihood: "Standard" (N syst, N nuisance)
03650         //Calculate the likelihood (x2 for chi)
03651         delchi2 = StandardLikelihood() - minchi2;
03652       }
03653       else if(FitMethod==4)
03654       {
03655         //Likelihood: Bin by Bin Calculation of Systematics
03656         //Calculate the likelihood (x2 for chi)
03657         delchi2 = BinLikelihood() - minchi2;
03658       }
03659       else
03660       {
03661         cout<<"Error in RunDeltaChi2Contour(): Unknown 'FitMethod'."<<endl;
03662       }
03663       
03664       if(i==1) continue;
03665       
03666       if(delchi2>contourlvl && delchi2prev<contourlvl)
03667       {
03668         limit = ss2th13 + ((ss2th13-sprev)/(delchi2 - delchi2prev))*(contourlvl - delchi2);
03669         cout<<delchi2prev<<", "<<sprev<<", "<<delchi2<<", "<<ss2th13<<", "<<limit<<endl;
03670         break;
03671       }
03672       delchi2prev = delchi2;
03673       sprev = ss2th13;
03674     }
03675     limit_norm.push_back(limit);
03676 
03677 
03678     limit = 0.;
03679     delchi2prev = 1000;
03680     sprev = 0;
03681     for(i=0;i<(best-SinSq2Th13Low)/Th13increment;i++){
03682       
03683       ss2th13 = -i*Th13increment + best; 
03684       for(ie=0;ie<Extrap.size();ie++)
03685       {
03686         Extrap[ie]->SetSinSq2Th13(ss2th13);
03687         Extrap[ie]->OscillatePrediction();
03688       }
03689       Bkgd->Reset();
03690       Sig->Reset();
03691       NExp->Reset();
03692       for(ie=0;ie<Extrap.size();ie++)
03693       {
03694         Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
03695         Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
03696       }
03697       NExp->Add(Bkgd);
03698       NExp->Add(Sig);
03699       
03700       delchi2 = 1e10;
03701       if(FitMethod==0)
03702       {
03703         delchi2 = PoissonChi2(NExp) - minchi2;
03704       }
03705       else if(FitMethod==1)
03706       {
03707         delchi2 = ScaledChi2(Bkgd,Sig) - minchi2;
03708       }
03709       else if(FitMethod==2)
03710       {
03711         delchi2 = StandardChi2(NExp) - minchi2;
03712       }
03713       else if(FitMethod==3)
03714       {
03715         //Likelihood: "Standard" (N syst, N nuisance)
03716         //Calculate the likelihood (x2 for chi)
03717         delchi2 = StandardLikelihood() - minchi2;
03718       }
03719       else if(FitMethod==4)
03720       {
03721         //Likelihood: Bin by Bin Calculation of Systematics
03722         //Calculate the likelihood (x2 for chi)
03723         delchi2 = BinLikelihood() - minchi2;
03724       }
03725       else
03726       {
03727         cout<<"Error in RunDeltaChi2Contour(): Unknown 'FitMethod'."<<endl;
03728       }
03729       
03730       if(i==1) continue;
03731       
03732       if(delchi2>contourlvl && delchi2prev<contourlvl)
03733       {
03734         limit = ss2th13 + ((ss2th13-sprev)/(delchi2 - delchi2prev))*(contourlvl - delchi2);
03735         cout<<delchi2prev<<", "<<sprev<<", "<<delchi2<<", "<<ss2th13<<", "<<limit<<endl;
03736         break;
03737       }
03738       delchi2prev = delchi2;
03739       sprev = ss2th13;
03740     }
03741     lowlimit_norm.push_back(limit);
03742 
03743   }
03744   
03745   for(ie=0;ie<Extrap.size();ie++)
03746   {
03747     Extrap[ie]->InvertMassHierarchy();
03748   }
03749   
03750   for(j=0;j<nDeltaSteps+1;j++)
03751   {
03752     delta = j*Deltaincrement*TMath::Pi() + DeltaLow;
03753     for(ie=0;ie<Extrap.size();ie++)
03754     {
03755       Extrap[ie]->SetDeltaCP(delta);
03756     }
03757     
03758     best=-1.;
03759     minchi2=100;
03760     for(i=0;i<3;i++)
03761     {
03762       chi2[i]=-1.;
03763       val[i]=-1.;
03764     }
03765     for(i=0;i<nSinSq2Th13Steps+1;i++)
03766     {
03767       chi2[0] = chi2[1];
03768       chi2[1] = chi2[2];
03769       val[0] = val[1];
03770       val[1] = val[2];
03771       ss2th13 = i*Th13increment + SinSq2Th13Low;
03772       for(ie=0;ie<Extrap.size();ie++)
03773       {
03774         Extrap[ie]->SetSinSq2Th13(ss2th13);
03775         Extrap[ie]->OscillatePrediction();
03776       }
03777       Bkgd->Reset();
03778       Sig->Reset();
03779       NExp->Reset();
03780       for(ie=0;ie<Extrap.size();ie++)
03781       {
03782         Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
03783         Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
03784       }
03785       NExp->Add(Bkgd);
03786       NExp->Add(Sig);
03787       
03788       chi2[2] = 1e10;
03789       if(FitMethod==0)
03790       {
03791         chi2[2] = PoissonChi2(NExp);
03792       }
03793       else if(FitMethod==1)
03794       {
03795         chi2[2] = ScaledChi2(Bkgd,Sig);
03796       }
03797       else if(FitMethod==2)
03798       {
03799         chi2[2] = StandardChi2(NExp);
03800       }
03801       else if(FitMethod==3)
03802       {
03803         //Likelihood: "Standard" (N syst, N nuisance)
03804         //Calculate the likelihood (x2 for chi)
03805         chi2[2] = StandardLikelihood();
03806       }
03807       else if(FitMethod==4)
03808       {
03809         //Likelihood: Bin by Bin Calculation of Systematics
03810         //Calculate the likelihood (x2 for chi)
03811         chi2[2] = BinLikelihood();
03812       }
03813       else
03814       {
03815         cout<<"Error in RunDeltaChi2Contour(): Unknown 'FitMethod'."<<endl;
03816       }
03817       
03818       val[2] = ss2th13;
03819       
03820       if(i<2) continue;
03821       
03822       if(i<3 && chi2[2]>chi2[1] && chi2[1]>chi2[0])//first three points are increasing, first point is minimum.
03823       {
03824         best = val[0];
03825         minchi2 = chi2[0];
03826         cout<<"minimum at 1st point: "<<minchi2<<" at "<<best<<endl;
03827         break;
03828       }
03829       
03830       if(chi2[2]>chi2[1] && chi2[0]>chi2[1])//found minimum
03831       {
03832         g3 = new TGraph(3, val, chi2);
03833         fit = new TF1("pol2", "pol2");
03834         g3->Fit(fit, "Q");//fit to second order polynominal
03835         if(fit->GetParameter(2) > 0)//if the x^2 term is nonzero
03836         {
03837           best = -fit->GetParameter(1)/(2*fit->GetParameter(2));//the location of the minimum is -p1/(2*p2)
03838           minchi2 = fit->GetParameter(0) + fit->GetParameter(1)*best + fit->GetParameter(2)*best*best;
03839           cout<<"minimum with fit: "<<minchi2<<" at "<<best<<endl;
03840         }
03841         else//if the x^2 term is zero, then just use the minimum you got by scanning
03842         {
03843           best = val[1];
03844           minchi2 = chi2[1];
03845           cout<<"minimum with scan: "<<minchi2<<" at "<<best<<endl;
03846         }
03847         break;
03848       }
03849     }
03850     bestfit_invt.push_back(best);
03851     
03852     limit = -1.;
03853     delchi2prev = 1000;
03854     sprev = 0;
03855     for(i=0;i<(SinSq2Th13High-best)/Th13increment;i++)
03856     {
03857       ss2th13 = i*Th13increment + best; //SinSq2Th13Low;
03858       for(ie=0;ie<Extrap.size();ie++)
03859       {
03860         Extrap[ie]->SetSinSq2Th13(ss2th13);
03861         Extrap[ie]->OscillatePrediction();
03862       }
03863       Bkgd->Reset();
03864       Sig->Reset();
03865       NExp->Reset();
03866       for(ie=0;ie<Extrap.size();ie++)
03867       {
03868         Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
03869         Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
03870       }
03871       NExp->Add(Bkgd);
03872       NExp->Add(Sig);
03873       
03874       delchi2 = 1e10;
03875       if(FitMethod==0)
03876       {
03877         delchi2 = PoissonChi2(NExp) - minchi2;
03878       }
03879       else if(FitMethod==1)
03880       {
03881         delchi2 = ScaledChi2(Bkgd,Sig) - minchi2;
03882       }
03883       else if(FitMethod==2)
03884       {
03885         delchi2 = StandardChi2(NExp) - minchi2;
03886       }
03887       else if(FitMethod==3)
03888       {
03889         //Likelihood: "Standard" (N syst, N nuisance)
03890         //Calculate the likelihood (x2 for chi)
03891         delchi2 = StandardLikelihood() - minchi2;
03892       }
03893       else if(FitMethod==4)
03894       {
03895         //Likelihood: Bin by Bin Calculation of Systematics
03896         //Calculate the likelihood (x2 for chi)
03897         delchi2 = BinLikelihood() - minchi2;
03898       }
03899       else
03900       {
03901         cout<<"Error in RunDeltaChi2Contour(): Unknown 'FitMethod'."<<endl;
03902       }
03903       
03904       if(i==1) continue;
03905       
03906       if(delchi2>contourlvl && delchi2prev<contourlvl)
03907       {
03908         limit = ss2th13 + ((ss2th13-sprev)/(delchi2 - delchi2prev))*(contourlvl - delchi2);
03909         cout<<delchi2prev<<", "<<sprev<<", "<<delchi2<<", "<<ss2th13<<", "<<limit<<endl;
03910         break;
03911       }
03912       delchi2prev = delchi2;
03913       sprev = ss2th13;
03914     }
03915     limit_invt.push_back(limit);
03916 
03917     limit = 0.;
03918     delchi2prev = 1000;
03919     sprev = 0;
03920     for(i=0;i<(best-SinSq2Th13Low)/Th13increment;i++)
03921     {
03922       ss2th13 = -i*Th13increment + best; //SinSq2Th13Low;
03923       for(ie=0;ie<Extrap.size();ie++)
03924       {
03925         Extrap[ie]->SetSinSq2Th13(ss2th13);
03926         Extrap[ie]->OscillatePrediction();
03927       }
03928       Bkgd->Reset();
03929       Sig->Reset();
03930       NExp->Reset();
03931       for(ie=0;ie<Extrap.size();ie++)
03932       {
03933         Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
03934         Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
03935       }
03936       NExp->Add(Bkgd);
03937       NExp->Add(Sig);
03938       
03939       delchi2 = 1e10;
03940       if(FitMethod==0)
03941       {
03942         delchi2 = PoissonChi2(NExp) - minchi2;
03943       }
03944       else if(FitMethod==1)
03945       {
03946         delchi2 = ScaledChi2(Bkgd,Sig) - minchi2;
03947       }
03948       else if(FitMethod==2)
03949       {
03950         delchi2 = StandardChi2(NExp) - minchi2;
03951       }
03952       else if(FitMethod==3)
03953       {
03954         //Likelihood: "Standard" (N syst, N nuisance)
03955         //Calculate the likelihood (x2 for chi)
03956         delchi2 = StandardLikelihood() - minchi2;
03957       }
03958       else if(FitMethod==4)
03959       {
03960         //Likelihood: Bin by Bin Calculation of Systematics
03961         //Calculate the likelihood (x2 for chi)
03962         delchi2 = BinLikelihood() - minchi2;
03963       }
03964       else
03965       {
03966         cout<<"Error in RunDeltaChi2Contour(): Unknown 'FitMethod'."<<endl;
03967       }
03968       
03969       if(i==1) continue;
03970       
03971       if(delchi2>contourlvl && delchi2prev<contourlvl)
03972       {
03973         limit = ss2th13 + ((ss2th13-sprev)/(delchi2 - delchi2prev))*(contourlvl - delchi2);
03974         cout<<delchi2prev<<", "<<sprev<<", "<<delchi2<<", "<<ss2th13<<", "<<limit<<endl;
03975         break;
03976       }
03977       delchi2prev = delchi2;
03978       sprev = ss2th13;
03979     }
03980     lowlimit_invt.push_back(limit);
03981 
03982   }
03983   
03984   double *s_best_n = new double[nDeltaSteps+1];
03985   double *s_best_i = new double[nDeltaSteps+1];
03986   double *s_limit_n = new double[nDeltaSteps+1];
03987   double *s_limit_i = new double[nDeltaSteps+1];
03988   double *s_limit_nlow = new double[nDeltaSteps+1];
03989   double *s_limit_ilow = new double[nDeltaSteps+1];
03990   double *d = new double[nDeltaSteps+1];
03991   for(i=0;i<nDeltaSteps+1;i++)
03992   {
03993     d[i] = deltapts.at(i);
03994     s_best_n[i] = bestfit_norm.at(i);
03995     s_best_i[i] = bestfit_invt.at(i);
03996     s_limit_n[i] = limit_norm.at(i);
03997     s_limit_i[i] = limit_invt.at(i);
03998     s_limit_nlow[i] = lowlimit_norm.at(i);
03999     s_limit_ilow[i] = lowlimit_invt.at(i);
04000   }
04001   
04002   TGraph *gn = new TGraph(nDeltaSteps+1,s_best_n,d);
04003   gn->SetMarkerStyle(20);
04004   gn->SetTitle("");
04005   gn->GetYaxis()->SetTitle("#delta");
04006   gn->GetXaxis()->SetTitle("sin^{2}2#theta_{13}");
04007   gn->GetXaxis()->SetLimits(0,0.6);
04008   gn->SetLineWidth(4);
04009   gn->SetMaximum(2);
04010   gn->SetName("BestFit_Normal");
04011   
04012   TGraph *gi = new TGraph(nDeltaSteps+1,s_best_i,d);
04013   gi->SetMarkerStyle(20);
04014   gi->SetTitle("");
04015   gi->GetYaxis()->SetTitle("#delta");
04016   gi->GetXaxis()->SetTitle("sin^{2}2#theta_{13}");
04017   gi->GetXaxis()->SetLimits(0,0.6);
04018   gi->SetLineWidth(4);
04019   gi->SetLineStyle(2);
04020   gi->SetMaximum(2);
04021   gi->SetName("BestFit_Inverted");
04022   
04023   TGraph *gn_limit = new TGraph(nDeltaSteps+1,s_limit_n,d);
04024   gn_limit->SetMarkerStyle(20);
04025   gn_limit->SetTitle("");
04026   gn_limit->GetYaxis()->SetTitle("#delta");
04027   gn_limit->GetXaxis()->SetTitle("sin^{2}2#theta_{13}");
04028   gn_limit->GetXaxis()->SetLimits(0,0.6);
04029   gn_limit->SetLineWidth(4);
04030   gn_limit->SetLineColor(kBlue);
04031   gn_limit->SetMarkerColor(kBlue);
04032   gn_limit->SetMaximum(2);
04033   gn_limit->SetName("UpperLimit_Normal");
04034   
04035   TGraph *gi_limit = new TGraph(nDeltaSteps+1,s_limit_i,d);
04036   gi_limit->SetMarkerStyle(20);
04037   gi_limit->SetTitle("");
04038   gi_limit->GetYaxis()->SetTitle("#delta");
04039   gi_limit->GetXaxis()->SetTitle("sin^{2}2#theta_{13}");
04040   gi_limit->GetXaxis()->SetLimits(0,0.6);
04041   gi_limit->SetLineWidth(4);
04042   gi_limit->SetLineColor(kRed);
04043   gi_limit->SetMarkerColor(kRed);
04044   gi_limit->SetMaximum(2);
04045   gi_limit->SetName("UpperLimit_Inverted");
04046 
04047  TGraph *gnl_limit = new TGraph(nDeltaSteps+1,s_limit_nlow,d);
04048   gnl_limit->SetMarkerStyle(20);
04049   gnl_limit->SetTitle("");
04050   gnl_limit->GetYaxis()->SetTitle("#delta");
04051   gnl_limit->GetXaxis()->SetTitle("sin^{2}2#theta_{13}");
04052   gnl_limit->GetXaxis()->SetLimits(0,0.6);
04053   gnl_limit->SetLineWidth(4);
04054   gnl_limit->SetLineColor(kBlue);
04055   gnl_limit->SetMarkerColor(kBlue);
04056   gnl_limit->SetMaximum(2);
04057   gnl_limit->SetName("LowerLimit_Normal");
04058   
04059   TGraph *gil_limit = new TGraph(nDeltaSteps+1,s_limit_ilow,d);
04060   gil_limit->SetMarkerStyle(20);
04061   gil_limit->SetTitle("");
04062   gil_limit->GetYaxis()->SetTitle("#delta");
04063   gil_limit->GetXaxis()->SetTitle("sin^{2}2#theta_{13}");
04064   gil_limit->GetXaxis()->SetLimits(0,0.6);
04065   gil_limit->SetLineWidth(4);
04066   gil_limit->SetLineColor(kRed);
04067   gil_limit->SetMarkerColor(kRed);
04068   gil_limit->SetMaximum(2);
04069   gil_limit->SetName("LowerLimit_Inverted");
04070 
04071   
04072   if(cl==0) cout<<"90% ";
04073   if(cl==1) cout<<"68% ";
04074   cout<<"confidence level limit = "<<limit_norm.at(0)<<", "<<limit_invt.at(0)<<endl;
04075   
04076   TFile *fout = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"RECREATE");
04077   gn->Write();
04078   gi->Write();
04079   gn_limit->Write();
04080   gi_limit->Write();
04081   gnl_limit->Write();
04082   gil_limit->Write();
04083   fout->Write();
04084   fout->Close();
04085   
04086   delete [] s_best_n;
04087   delete [] s_best_i;
04088   delete [] s_limit_n;
04089   delete [] s_limit_i;
04090   delete [] s_limit_nlow;
04091   delete [] s_limit_ilow;
04092   delete [] d;
04093   
04094   return;
04095 }

void NueFit2D::RunFCAnalytical (  ) 

Definition at line 1376 of file NueFit2D.cxx.

References Chi2_Inverted, Chi2_Normal, EvaluateOmega(), FracErr_Bkgd, FracErr_Sig, grid_background, grid_delta, grid_signal, grid_sinsq2th13, GridScale_Inverted, GridScale_Normal, GridTree_Inverted, GridTree_Normal, gSystem(), nBins, NObs, nPts_Inverted, nPts_Normal, outFileName, ReadGridFiles(), and SetupChi2Hists().

01377 {
01378   if(NObs==0)
01379   {
01380     cout<<"NObs not set.  Quitting..."<<endl;
01381     return;
01382   }
01383   if(FracErr_Bkgd==0)
01384   {
01385     cout<<"FracErr_Bkgd not set.  Quitting..."<<endl;
01386     return;
01387   }
01388   if(FracErr_Sig==0)
01389   {
01390     cout<<"FracErr_Sig not set.  Quitting..."<<endl;
01391     return;
01392   }
01393   
01394   if(nBins>1)
01395   {
01396     cout<<"Analytical Feldman-Cousins Method should only be used for a single bin fit.  Quitting..."<<endl;
01397     return;
01398   }
01399   
01400   ReadGridFiles();
01401   SetupChi2Hists();
01402   
01403   if(nPts_Normal==0 || nPts_Inverted==0) return;
01404   
01405   int i;
01406   double omega;
01407   
01408   for(i=0;i<nPts_Normal;i++)
01409   {
01410     if(i%100==0) cout<<100.*i/nPts_Normal<<"% complete for normal hierarchy"<<endl;
01411     GridTree_Normal[0]->GetEntry(i);
01412     omega = EvaluateOmega(grid_signal*GridScale_Normal, grid_background*GridScale_Normal);
01413     Chi2_Normal->Fill(grid_sinsq2th13,grid_delta/TMath::Pi(),omega);
01414   }
01415   
01416   for(i=0;i<nPts_Inverted;i++)
01417   {
01418     if(i%100==0) cout<<100.*i/nPts_Inverted<<"% complete for inverted hierarchy"<<endl;
01419     GridTree_Inverted[0]->GetEntry(i);
01420     omega = EvaluateOmega(grid_signal*GridScale_Inverted, grid_background*GridScale_Inverted);
01421     Chi2_Inverted->Fill(grid_sinsq2th13,grid_delta/TMath::Pi(),omega);
01422   }
01423   
01424   TFile *f = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"RECREATE");
01425   Chi2_Normal->Write();
01426   Chi2_Inverted->Write();
01427   f->Close();
01428   
01429   return;
01430 }

void NueFit2D::RunFCTraditional (  ) 

Definition at line 1431 of file NueFit2D.cxx.

References Chi2_Inverted, Chi2_Normal, Extrap, Form(), grid_background, grid_delta, grid_signal, grid_sinsq2th13, GridScale_Inverted, GridScale_Normal, GridTree_Inverted, GridTree_Normal, gSystem(), nBins, NObs, nPts_Inverted, nPts_Normal, outFileName, PoissonChi2(), PseudoExpFile, ReadGridFiles(), and SetupChi2Hists().

01432 {
01433   if(NObs==0)
01434   {
01435     cout<<"NObs not set.  Quitting..."<<endl;
01436     return;
01437   }
01438   if(Extrap.size()==0)
01439   {
01440     cout<<"No Extrapolate2D input.  Quitting..."<<endl;
01441     return;
01442   }
01443   
01444   ReadGridFiles();
01445   SetupChi2Hists();
01446   
01447   if(nPts_Normal==0 || nPts_Inverted==0) return;
01448   
01449   TH1D *nexp_bkgd = new TH1D("nexp_bkgd","",nBins,-0.5,nBins-0.5);
01450   TH1D *nexp_signal = new TH1D("nexp_signal","",nBins,-0.5,nBins-0.5);
01451   TH1D *nexp = new TH1D("nexp","",nBins,-0.5,nBins-0.5);
01452   
01453   bool calcchi2min;//if nobs<nexpmin for any bin, then chi2min!=0 and needs to be calculated
01454   TH1D *nexpmin=0;
01455   
01456   int i;
01457   unsigned int j;
01458   
01459   if(gSystem->AccessPathName(gSystem->ExpandPathName(PseudoExpFile.c_str())))
01460   {
01461     cout<<"Pseudo-experiment file doesn't exist."<<endl;
01462     return;
01463   }
01464   
01465   TFile *f = new TFile(gSystem->ExpandPathName(PseudoExpFile.c_str()),"READ");
01466   
01467   double chi2data;
01468   int chi2databin;
01469   TH1D *chi2hist = (TH1D*)f->Get("Chi2Hist_Normal_0");
01470   double chi2binwidth = chi2hist->GetBinWidth(1);
01471   double chi2start = chi2hist->GetXaxis()->GetBinLowEdge(1);
01472   double frac;
01473   delete chi2hist;
01474   
01475   //normal hierarchy
01476   for(j=0;j<Extrap.size();j++)
01477   {
01478     Extrap[j]->GetPrediction();
01479     Extrap[j]->SetSinSq2Th13(0);
01480     Extrap[j]->OscillatePrediction();
01481     if(j==0)
01482     {
01483       nexpmin = (TH1D*)Extrap[j]->Pred_TotalBkgd_VsBinNumber->Clone("nexpmin");
01484       nexpmin->Add(Extrap[j]->Pred_Signal_VsBinNumber);
01485     }
01486     else
01487     {
01488       nexpmin->Add(Extrap[j]->Pred_TotalBkgd_VsBinNumber);
01489       nexpmin->Add(Extrap[j]->Pred_Signal_VsBinNumber);
01490     }
01491   }
01492   
01493   for(i=0;i<nPts_Normal;i++)
01494   {
01495     if(i%100==0) cout<<100.*i/nPts_Normal<<"% complete for normal hierarchy"<<endl;
01496     
01497     nexp_bkgd->Reset();
01498     nexp_signal->Reset();
01499     nexp->Reset();
01500     for(j=0;j<nBins;j++)
01501     {
01502       GridTree_Normal[j]->GetEntry(i);
01503       nexp_bkgd->SetBinContent(j+1,grid_background*GridScale_Normal);
01504       nexp_signal->SetBinContent(j+1,grid_signal*GridScale_Normal);
01505     }
01506     nexp->Add(nexp_bkgd,nexp_signal,1,1);
01507     chi2data = PoissonChi2(nexp);
01508     calcchi2min=false;
01509     for(j=0;j<nBins;j++)
01510     {
01511       if(NObs->GetBinContent(j+1)<nexpmin->GetBinContent(j+1))
01512       {
01513         calcchi2min=true;
01514       }
01515     }
01516     if(calcchi2min) chi2data = chi2data - PoissonChi2(nexpmin);
01517     chi2databin = int((chi2data-chi2start)/chi2binwidth)+1;
01518     
01519     TH1D *chi2hist = (TH1D*)f->Get(Form("Chi2Hist_Normal_%i",i));
01520     frac = chi2hist->Integral(1,chi2databin-1)/chi2hist->Integral();
01521     if(chi2databin==1) frac=0;
01522     
01523     Chi2_Normal->Fill(grid_sinsq2th13,grid_delta/TMath::Pi(),frac);
01524     
01525     delete chi2hist;
01526   }
01527   
01528   //inverted hierarchy
01529   for(j=0;j<Extrap.size();j++)
01530   {
01531     Extrap[j]->SetSinSq2Th13(0);
01532     Extrap[j]->InvertMassHierarchy();
01533     Extrap[j]->OscillatePrediction();
01534     if(j==0)
01535     {
01536       nexpmin = (TH1D*)Extrap[j]->Pred_TotalBkgd_VsBinNumber->Clone("nexpmin");
01537       nexpmin->Add(Extrap[j]->Pred_Signal_VsBinNumber);
01538     }
01539     else
01540     {
01541       nexpmin->Add(Extrap[j]->Pred_TotalBkgd_VsBinNumber);
01542       nexpmin->Add(Extrap[j]->Pred_Signal_VsBinNumber);
01543     }
01544   }
01545   
01546   for(i=0;i<nPts_Inverted;i++)
01547   {
01548     if(i%100==0) cout<<100.*i/nPts_Inverted<<"% complete for inverted hierarchy"<<endl;
01549     
01550     nexp_bkgd->Reset();
01551     nexp_signal->Reset();
01552     nexp->Reset();
01553     for(j=0;j<nBins;j++)
01554     {
01555       GridTree_Inverted[j]->GetEntry(i);
01556       nexp_bkgd->SetBinContent(j+1,grid_background*GridScale_Inverted);
01557       nexp_signal->SetBinContent(j+1,grid_signal*GridScale_Inverted);
01558     }
01559     nexp->Add(nexp_bkgd,nexp_signal,1,1);
01560     chi2data = PoissonChi2(nexp);
01561     calcchi2min=false;
01562     for(j=0;j<nBins;j++)
01563     {
01564       if(NObs->GetBinContent(j+1)<nexpmin->GetBinContent(j+1))
01565       {
01566         calcchi2min=true;
01567       }
01568     }
01569     if(calcchi2min) chi2data = chi2data - PoissonChi2(nexpmin);
01570     chi2databin = int((chi2data-chi2start)/chi2binwidth)+1;
01571     
01572     TH1D *chi2hist = (TH1D*)f->Get(Form("Chi2Hist_Inverted_%i",i));
01573     frac = chi2hist->Integral(1,chi2databin-1)/chi2hist->Integral();
01574     if(chi2databin==1) frac=0;
01575     
01576     Chi2_Inverted->Fill(grid_sinsq2th13,grid_delta/TMath::Pi(),frac);
01577     
01578     delete chi2hist;
01579   }
01580   
01581   f->Close();
01582   
01583   TFile *fout = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"RECREATE");
01584   Chi2_Normal->Write();
01585   Chi2_Inverted->Write();
01586   fout->Close();
01587   
01588   return;
01589 }

void NueFit2D::RunMultiBinFC (  ) 

Definition at line 1590 of file NueFit2D.cxx.

References BinLikelihood(), Bkgd, Chi2_Inverted, Chi2_Normal, DefineBinDlnLMinuit(), DefineStdDlnLMinuit(), ErrCalc, ErrorMatrix, Extrap, FitMethod, Form(), FracErr_Bkgd, FracErr_Sig, GetMinLikelihood(), grid_background, grid_bnuecc, grid_delta, grid_nc, grid_nue, grid_numucc, grid_nutaucc, grid_signal, grid_sinsq2th13, GridScale_Inverted, GridScale_Normal, GridTree_2_Inverted, GridTree_2_Normal, GridTree_Inverted, GridTree_Normal, gSystem(), InvErrorMatrix, nBins, NObs, nPts_Inverted, nPts_Normal, outFileName, PoissonChi2(), PseudoExpFile, ReadGridFiles(), ScaledChi2(), ErrorCalc::SetGridPred(), SetupChi2Hists(), ErrorCalc::SetUseGrid(), Sig, StandardChi2(), and StandardLikelihood().

01591 {
01592   if(NObs==0)
01593   {
01594     cout<<"NObs not set.  Quitting..."<<endl;
01595     return;
01596   }
01597   if(Extrap.size()==0)
01598   {
01599     cout<<"No Extrapolate2D input.  Quitting..."<<endl;
01600     return;
01601   }
01602   for(unsigned int ie=0;ie<Extrap.size();ie++)
01603   {
01604     Extrap[ie]->GetPrediction();
01605   }
01606   if(FitMethod==1 && (FracErr_Bkgd==0 || FracErr_Sig==0))
01607   {
01608     cout<<"FracErr_Bkgd and FracErr_Sig need to be set for ScaledChi2.  Quitting..."<<endl;
01609     return;
01610   }
01611   if(ErrCalc==0)
01612   {
01613     cout<<"No ErrorCalc object set!  Quitting..."<<endl;
01614     return;
01615   }
01616   if(FitMethod==3) DefineStdDlnLMinuit();
01617   if(FitMethod==4) DefineBinDlnLMinuit();
01618   
01619   nBins = NObs->GetNbinsX();
01620   if(ErrorMatrix==0) ErrorMatrix = new TH2D("ErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
01621   if(InvErrorMatrix==0) InvErrorMatrix = new TH2D("InvErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
01622   
01623   ReadGridFiles();
01624   SetupChi2Hists();
01625   
01626   if(nPts_Normal==0 || nPts_Inverted==0) return;
01627   
01628   TH1D *nexp_bkgd = new TH1D("nexp_bkgd","",nBins,-0.5,nBins-0.5);
01629   TH1D *nexp_signal = new TH1D("nexp_signal","",nBins,-0.5,nBins-0.5);
01630   TH1D *nexp = new TH1D("nexp","",nBins,-0.5,nBins-0.5);
01631   
01632   int i;
01633   unsigned int j,k;
01634   
01635   if(gSystem->AccessPathName(gSystem->ExpandPathName(PseudoExpFile.c_str())))
01636   {
01637     cout<<"Pseudo-experiment file doesn't exist."<<endl;
01638     return;
01639   }
01640   
01641   TFile *f = new TFile(gSystem->ExpandPathName(PseudoExpFile.c_str()),"READ");
01642   
01643   double chi2data,chi2min;
01644   int chi2databin;
01645   TH1D *chi2hist = (TH1D*)f->Get("Chi2Hist_Normal_0");
01646   double chi2binwidth = chi2hist->GetBinWidth(1);
01647   double chi2start = chi2hist->GetXaxis()->GetBinLowEdge(1);
01648   double frac;
01649   delete chi2hist;
01650   
01651   vector< vector<double> > nc,numucc,bnuecc,nutaucc,sig;
01652   for(j=0;j<nBins;j++)
01653   {
01654     nc.push_back( vector<double>() );
01655     numucc.push_back( vector<double>() );
01656     bnuecc.push_back( vector<double>() );
01657     nutaucc.push_back( vector<double>() );
01658     sig.push_back( vector<double>() );
01659     for(k=0;k<Extrap.size();k++)
01660     {
01661       nc[j].push_back(0);
01662       numucc[j].push_back(0);
01663       bnuecc[j].push_back(0);
01664       nutaucc[j].push_back(0);
01665       sig[j].push_back(0);
01666     }
01667   }
01668   
01669   Bkgd = (TH1D*)NObs->Clone("Bkgd");
01670   Bkgd->Reset();
01671   Sig = (TH1D*)NObs->Clone("Sig");
01672   Sig->Reset();
01673   
01674   //normal hierarchy
01675   
01676   for(i=0;i<nPts_Normal;i++)
01677   {
01678     if(i%100==0) cout<<100.*i/nPts_Normal<<"% complete for normal hierarchy"<<endl;
01679     
01680     nexp_bkgd->Reset();
01681     nexp_signal->Reset();
01682     nexp->Reset();
01683     
01684     for(j=0;j<nBins;j++)
01685     {
01686       GridTree_Normal[j]->GetEntry(i);
01687       nexp_bkgd->SetBinContent(j+1,grid_background*GridScale_Normal);
01688       nexp_signal->SetBinContent(j+1,grid_signal*GridScale_Normal);
01689       
01690       for(k=0;k<Extrap.size();k++)
01691       {
01692         GridTree_2_Normal[j][k]->GetEntry(i);
01693         nc[j][k] = grid_nc*GridScale_Normal;
01694         numucc[j][k] = grid_numucc*GridScale_Normal;
01695         bnuecc[j][k] = grid_bnuecc*GridScale_Normal;
01696         nutaucc[j][k] = grid_nutaucc*GridScale_Normal;
01697         sig[j][k] = grid_nue*GridScale_Normal;
01698       }
01699     }
01700     nexp->Add(nexp_bkgd,nexp_signal,1,1);
01701     ErrCalc->SetGridPred(nBins,nc,numucc,bnuecc,nutaucc,sig);
01702     
01703     chi2min=GetMinLikelihood(grid_delta,true);
01704     
01705     ErrCalc->SetUseGrid(true);//use grid predictions set up above
01706     chi2data = 1e10;
01707     if(FitMethod==0)
01708     {
01709       chi2data = PoissonChi2(nexp) - chi2min;
01710     }
01711     else if(FitMethod==1)
01712     {
01713       chi2data = ScaledChi2(Bkgd,Sig) - chi2min;
01714     }
01715     else if(FitMethod==2)
01716     {
01717       chi2data = StandardChi2(nexp) - chi2min;
01718     }
01719     else if(FitMethod==3)
01720     {
01721       //Likelihood: "Standard" (N syst, N nuisance)
01722       //Calculate the likelihood (x2 for chi)
01723       Bkgd->Reset();
01724       Bkgd->Add(nexp_bkgd);
01725       Sig->Reset();
01726       Sig->Add(nexp_signal);
01727       chi2data = StandardLikelihood() - chi2min;
01728     }
01729     else if(FitMethod==4)
01730     {
01731       //Likelihood: Bin by Bin Calculation of Systematics
01732       //Calculate the likelihood (x2 for chi)
01733       Bkgd->Reset();
01734       Bkgd->Add(nexp_bkgd);
01735       Sig->Reset();
01736       Sig->Add(nexp_signal);
01737       chi2data = BinLikelihood() - chi2min;
01738     }
01739     else
01740     {
01741       cout<<"Error in RunMultiBinFC(): Unknown 'FitMethod'."<<endl;
01742     }
01743     chi2databin = int((chi2data-chi2start)/chi2binwidth)+1;
01744     
01745     TH1D *chi2hist = (TH1D*)f->Get(Form("Chi2Hist_Normal_%i",i));
01746     if(chi2hist->Integral()<1)
01747     {
01748       cout<<"Warning, chi2hist is empty."<<endl;
01749       frac=0;
01750     }
01751     else
01752     {
01753       frac = chi2hist->Integral(1,chi2databin-1)/chi2hist->Integral();
01754     }
01755     
01756     if(chi2databin==1) frac=0;
01757     
01758     Chi2_Normal->Fill(grid_sinsq2th13,grid_delta/TMath::Pi(),frac);
01759     
01760     delete chi2hist;
01761   }
01762   
01763   //inverted hierarchy
01764   
01765   for(i=0;i<nPts_Inverted;i++)
01766   {
01767     if(i%100==0) cout<<100.*i/nPts_Inverted<<"% complete for inverted hierarchy"<<endl;
01768     
01769     nexp_bkgd->Reset();
01770     nexp_signal->Reset();
01771     nexp->Reset();
01772     
01773     for(j=0;j<nBins;j++)
01774     {
01775       GridTree_Inverted[j]->GetEntry(i);
01776       nexp_bkgd->SetBinContent(j+1,grid_background*GridScale_Inverted);
01777       nexp_signal->SetBinContent(j+1,grid_signal*GridScale_Inverted);
01778       
01779       for(k=0;k<Extrap.size();k++)
01780       {
01781         GridTree_2_Inverted[j][k]->GetEntry(i);
01782         nc[j][k] = grid_nc*GridScale_Inverted;
01783         numucc[j][k] = grid_numucc*GridScale_Inverted;
01784         bnuecc[j][k] = grid_bnuecc*GridScale_Inverted;
01785         nutaucc[j][k] = grid_nutaucc*GridScale_Inverted;
01786         sig[j][k] = grid_nue*GridScale_Inverted;
01787       }
01788     }
01789     nexp->Add(nexp_bkgd,nexp_signal,1,1);
01790     ErrCalc->SetGridPred(nBins,nc,numucc,bnuecc,nutaucc,sig);
01791     
01792     chi2min=GetMinLikelihood(grid_delta,false);
01793     
01794     ErrCalc->SetUseGrid(true);//use grid predictions set up above
01795     chi2data = 1e10;
01796     if(FitMethod==0)
01797     {
01798       chi2data = PoissonChi2(nexp) - chi2min;
01799     }
01800     else if(FitMethod==1)
01801     {
01802       chi2data = ScaledChi2(Bkgd,Sig) - chi2min;
01803     }
01804     else if(FitMethod==2)
01805     {
01806       chi2data = StandardChi2(nexp) - chi2min;
01807     }
01808     else if(FitMethod==3)
01809     {
01810       //Likelihood: "Standard" (N syst, N nuisance)
01811       //Calculate the likelihood (x2 for chi)
01812       Bkgd->Reset();
01813       Bkgd->Add(nexp_bkgd);
01814       Sig->Reset();
01815       Sig->Add(nexp_signal);
01816       chi2data = StandardLikelihood() - chi2min;
01817     }
01818     else if(FitMethod==4)
01819     {
01820       //Likelihood: Bin by Bin Calculation of Systematics
01821       //Calculate the likelihood (x2 for chi)
01822       Bkgd->Reset();
01823       Bkgd->Add(nexp_bkgd);
01824       Sig->Reset();
01825       Sig->Add(nexp_signal);
01826       chi2data = BinLikelihood() - chi2min;
01827     }
01828     else
01829     {
01830       cout<<"Error in RunMultiBinFC(): Unknown 'FitMethod'."<<endl;
01831     }
01832     chi2databin = int((chi2data-chi2start)/chi2binwidth)+1;
01833     
01834     TH1D *chi2hist = (TH1D*)f->Get(Form("Chi2Hist_Inverted_%i",i));
01835     if(chi2hist->Integral()<1)
01836     {
01837       cout<<"Warning, chi2hist is empty."<<endl;
01838       frac=0;
01839     }
01840     else
01841     {
01842       frac = chi2hist->Integral(1,chi2databin-1)/chi2hist->Integral();
01843     }
01844     
01845     if(chi2databin==1) frac=0;
01846     
01847     Chi2_Inverted->Fill(grid_sinsq2th13,grid_delta/TMath::Pi(),frac);
01848     
01849     delete chi2hist;
01850   }
01851   
01852   f->Close();
01853   
01854   TFile *fout = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"RECREATE");
01855   Chi2_Normal->Write();
01856   Chi2_Inverted->Write();
01857   fout->Close();
01858   
01859   return;
01860 }

void NueFit2D::RunMultiBinFC_MHDeltaFit (  )  [virtual]

Reimplemented in NueFit2D_Joint.

Definition at line 5112 of file NueFit2D.cxx.

References BinLikelihood(), Bkgd, DefineBinDlnLMinuit(), DefineStdDlnLMinuit(), ErrCalc, ErrorMatrix, Extrap, FitMethod, Form(), FracErr_Bkgd, FracErr_Sig, GetMinLikelihood_Delta(), grid_background, grid_bnuecc, grid_delta, grid_nc, grid_nue, grid_numucc, grid_nutaucc, grid_signal, GridScale_Inverted, GridScale_Normal, GridTree_2_Inverted, GridTree_2_Normal, GridTree_Inverted, GridTree_Normal, gSystem(), InvErrorMatrix, nBins, NObs, nPts_Inverted, nPts_Normal, outFileName, PoissonChi2(), PseudoExpFile, ReadGridFiles(), ScaledChi2(), ErrorCalc::SetGridPred(), SetupChi2Hists(), ErrorCalc::SetUseGrid(), Sig, StandardChi2(), and StandardLikelihood().

05113 {
05114   if(NObs==0)
05115   {
05116     cout<<"NObs not set.  Quitting..."<<endl;
05117     return;
05118   }
05119   if(Extrap.size()==0)
05120   {
05121     cout<<"No Extrapolate2D input.  Quitting..."<<endl;
05122     return;
05123   }
05124   for(unsigned int ie=0;ie<Extrap.size();ie++)
05125   {
05126     Extrap[ie]->GetPrediction();
05127   }
05128   if(FitMethod==1 && (FracErr_Bkgd==0 || FracErr_Sig==0))
05129   {
05130     cout<<"FracErr_Bkgd and FracErr_Sig need to be set for ScaledChi2.  Quitting..."<<endl;
05131     return;
05132   }
05133   if(ErrCalc==0)
05134   {
05135     cout<<"No ErrorCalc object set!  Quitting..."<<endl;
05136     return;
05137   }
05138   if(FitMethod==3) DefineStdDlnLMinuit();
05139   if(FitMethod==4) DefineBinDlnLMinuit();
05140   
05141   nBins = NObs->GetNbinsX();
05142   if(ErrorMatrix==0) ErrorMatrix = new TH2D("ErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
05143   if(InvErrorMatrix==0) InvErrorMatrix = new TH2D("InvErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
05144   
05145   ReadGridFiles();
05146   SetupChi2Hists();
05147   
05148   if(nPts_Normal==0 || nPts_Inverted==0) return;
05149   
05150   TH1D *nexp_bkgd = new TH1D("nexp_bkgd","",nBins,-0.5,nBins-0.5);
05151   TH1D *nexp_signal = new TH1D("nexp_signal","",nBins,-0.5,nBins-0.5);
05152   TH1D *nexp = new TH1D("nexp","",nBins,-0.5,nBins-0.5);
05153   
05154   int i;
05155   unsigned int j,k;
05156   
05157   if(gSystem->AccessPathName(gSystem->ExpandPathName(PseudoExpFile.c_str())))
05158   {
05159     cout<<"Pseudo-experiment file doesn't exist."<<endl;
05160     return;
05161   }
05162   
05163   TFile *f = new TFile(gSystem->ExpandPathName(PseudoExpFile.c_str()),"READ");
05164   
05165   double *chi2data_NH = new double[nPts_Normal];
05166   double *chi2data_IH = new double[nPts_Inverted];
05167   double *chi2min_NH = new double[nPts_Normal];
05168   double *chi2min_IH = new double[nPts_Inverted];
05169   
05170   int chi2databin;
05171   TH1D *chi2hist = (TH1D*)f->Get("Chi2Hist_MHFit_Normal_0");
05172   double chi2binwidth = chi2hist->GetBinWidth(1);
05173   double chi2start = chi2hist->GetXaxis()->GetBinLowEdge(1);
05174   double frac;
05175   delete chi2hist;
05176   
05177   double *deltapts = new double[nPts_Normal];
05178   
05179   vector< vector<double> > nc,numucc,bnuecc,nutaucc,sig;
05180   for(j=0;j<nBins;j++)
05181   {
05182     nc.push_back( vector<double>() );
05183     numucc.push_back( vector<double>() );
05184     bnuecc.push_back( vector<double>() );
05185     nutaucc.push_back( vector<double>() );
05186     sig.push_back( vector<double>() );
05187     for(k=0;k<Extrap.size();k++)
05188     {
05189       nc[j].push_back(0);
05190       numucc[j].push_back(0);
05191       bnuecc[j].push_back(0);
05192       nutaucc[j].push_back(0);
05193       sig[j].push_back(0);
05194     }
05195   }
05196   
05197   Bkgd = (TH1D*)NObs->Clone("Bkgd");
05198   Bkgd->Reset();
05199   Sig = (TH1D*)NObs->Clone("Sig");
05200   Sig->Reset();
05201   
05202   //normal hierarchy
05203   
05204   for(i=0;i<nPts_Normal;i++)
05205   {
05206     if(i%100==0) cout<<100.*i/nPts_Normal<<"% complete for normal hierarchy"<<endl;
05207     
05208     nexp_bkgd->Reset();
05209     nexp_signal->Reset();
05210     nexp->Reset();
05211     
05212     for(j=0;j<nBins;j++)
05213     {
05214       GridTree_Normal[j]->GetEntry(i);
05215       nexp_bkgd->SetBinContent(j+1,grid_background*GridScale_Normal);
05216       nexp_signal->SetBinContent(j+1,grid_signal*GridScale_Normal);
05217       
05218       for(k=0;k<Extrap.size();k++)
05219       {
05220         GridTree_2_Normal[j][k]->GetEntry(i);
05221         nc[j][k] = grid_nc*GridScale_Normal;
05222         numucc[j][k] = grid_numucc*GridScale_Normal;
05223         bnuecc[j][k] = grid_bnuecc*GridScale_Normal;
05224         nutaucc[j][k] = grid_nutaucc*GridScale_Normal;
05225         sig[j][k] = grid_nue*GridScale_Normal;
05226       }
05227     }
05228     nexp->Add(nexp_bkgd,nexp_signal,1,1);
05229     ErrCalc->SetGridPred(nBins,nc,numucc,bnuecc,nutaucc,sig);
05230     
05231     chi2min_NH[i]=GetMinLikelihood_Delta(true);
05232     
05233     ErrCalc->SetUseGrid(true);//use grid predictions set up above
05234     chi2data_NH[i] = 1e10;
05235     if(FitMethod==0)
05236     {
05237       chi2data_NH[i] = PoissonChi2(nexp);
05238     }
05239     else if(FitMethod==1)
05240     {
05241       chi2data_NH[i] = ScaledChi2(Bkgd,Sig);
05242     }
05243     else if(FitMethod==2)
05244     {
05245       chi2data_NH[i] = StandardChi2(nexp);
05246     }
05247     else if(FitMethod==3)
05248     {
05249       //Likelihood: "Standard" (N syst, N nuisance)
05250       //Calculate the likelihood (x2 for chi)
05251       Bkgd->Reset();
05252       Bkgd->Add(nexp_bkgd);
05253       Sig->Reset();
05254       Sig->Add(nexp_signal);
05255       chi2data_NH[i] = StandardLikelihood();
05256     }
05257     else if(FitMethod==4)
05258     {
05259       //Likelihood: Bin by Bin Calculation of Systematics
05260       //Calculate the likelihood (x2 for chi)
05261       Bkgd->Reset();
05262       Bkgd->Add(nexp_bkgd);
05263       Sig->Reset();
05264       Sig->Add(nexp_signal);
05265       chi2data_NH[i] = BinLikelihood();
05266     }
05267     else
05268     {
05269       cout<<"Error in RunMultiBinFC_MHDeltaFit(): Unknown 'FitMethod'."<<endl;
05270     }
05271     
05272     deltapts[i] = grid_delta/TMath::Pi();
05273   }
05274   
05275   //inverted hierarchy
05276   
05277   for(i=0;i<nPts_Inverted;i++)
05278   {
05279     if(i%100==0) cout<<100.*i/nPts_Inverted<<"% complete for inverted hierarchy"<<endl;
05280     
05281     nexp_bkgd->Reset();
05282     nexp_signal->Reset();
05283     nexp->Reset();
05284     
05285     for(j=0;j<nBins;j++)
05286     {
05287       GridTree_Inverted[j]->GetEntry(i);
05288       nexp_bkgd->SetBinContent(j+1,grid_background*GridScale_Inverted);
05289       nexp_signal->SetBinContent(j+1,grid_signal*GridScale_Inverted);
05290       
05291       for(k=0;k<Extrap.size();k++)
05292       {
05293         GridTree_2_Inverted[j][k]->GetEntry(i);
05294         nc[j][k] = grid_nc*GridScale_Inverted;
05295         numucc[j][k] = grid_numucc*GridScale_Inverted;
05296         bnuecc[j][k] = grid_bnuecc*GridScale_Inverted;
05297         nutaucc[j][k] = grid_nutaucc*GridScale_Inverted;
05298         sig[j][k] = grid_nue*GridScale_Inverted;
05299       }
05300     }
05301     nexp->Add(nexp_bkgd,nexp_signal,1,1);
05302     ErrCalc->SetGridPred(nBins,nc,numucc,bnuecc,nutaucc,sig);
05303     
05304     chi2min_IH[i]=GetMinLikelihood_Delta(false);
05305     
05306     ErrCalc->SetUseGrid(true);//use grid predictions set up above
05307     chi2data_IH[i] = 1e10;
05308     if(FitMethod==0)
05309     {
05310       chi2data_IH[i] = PoissonChi2(nexp);
05311     }
05312     else if(FitMethod==1)
05313     {
05314       chi2data_IH[i] = ScaledChi2(Bkgd,Sig);
05315     }
05316     else if(FitMethod==2)
05317     {
05318       chi2data_IH[i] = StandardChi2(nexp);
05319     }
05320     else if(FitMethod==3)
05321     {
05322       //Likelihood: "Standard" (N syst, N nuisance)
05323       //Calculate the likelihood (x2 for chi)
05324       Bkgd->Reset();
05325       Bkgd->Add(nexp_bkgd);
05326       Sig->Reset();
05327       Sig->Add(nexp_signal);
05328       chi2data_IH[i] = StandardLikelihood();
05329     }
05330     else if(FitMethod==4)
05331     {
05332       //Likelihood: Bin by Bin Calculation of Systematics
05333       //Calculate the likelihood (x2 for chi)
05334       Bkgd->Reset();
05335       Bkgd->Add(nexp_bkgd);
05336       Sig->Reset();
05337       Sig->Add(nexp_signal);
05338       chi2data_IH[i] = BinLikelihood();
05339     }
05340     else
05341     {
05342       cout<<"Error in RunMultiBinFC_MHDeltaFit(): Unknown 'FitMethod'."<<endl;
05343     }
05344   }
05345   
05346   if(nPts_Normal!=nPts_Inverted) cout<<"different number of points"<<endl;
05347   
05348   double *deltafit_nh = new double[nPts_Normal];
05349   double *deltafit_ih = new double[nPts_Inverted];
05350   double *mhfit_nh = new double[nPts_Normal];
05351   double *mhfit_ih = new double[nPts_Inverted];
05352   double delchi2,delchi2_norm,delchi2_invt,delchi2_bestmh;
05353   
05354   //delta fit
05355   for(i=0;i<nPts_Normal;i++)
05356   {
05357     //normal
05358     delchi2 = chi2data_NH[i] - chi2min_NH[i];
05359     chi2databin = int((delchi2-chi2start)/chi2binwidth)+1;
05360     
05361     TH1D *chi2hist = (TH1D*)f->Get(Form("Chi2Hist_DeltaFit_Normal_%i",i));
05362     
05363     if(chi2hist->Integral()<1)
05364     {
05365       cout<<"Warning, chi2hist is empty."<<endl;
05366       frac=0;
05367     }
05368     else
05369     {
05370       frac = chi2hist->Integral(1,chi2databin-1)/chi2hist->Integral();
05371     }
05372     if(chi2databin==1) frac=0;
05373     
05374     deltafit_nh[i] = frac;
05375     
05376     //inverted
05377     delchi2 = chi2data_IH[i] - chi2min_IH[i];
05378     chi2databin = int((delchi2-chi2start)/chi2binwidth)+1;
05379     
05380     chi2hist = (TH1D*)f->Get(Form("Chi2Hist_DeltaFit_Inverted_%i",i));
05381     
05382     if(chi2hist->Integral()<1)
05383     {
05384       cout<<"Warning, chi2hist is empty."<<endl;
05385       frac=0;
05386     }
05387     else
05388     {
05389       frac = chi2hist->Integral(1,chi2databin-1)/chi2hist->Integral();
05390     }
05391     if(chi2databin==1) frac=0;
05392     
05393     deltafit_ih[i] = frac;
05394     
05395     delete chi2hist;
05396   }
05397   
05398   //mh fit
05399   for(i=0;i<nPts_Normal;i++)
05400   {
05401     delchi2_norm = chi2data_NH[i] - chi2min_NH[i];
05402     delchi2_invt = chi2data_IH[i] - chi2min_IH[i];
05403     delchi2_bestmh = delchi2_invt;
05404     if(delchi2_norm<delchi2_bestmh) delchi2_bestmh = delchi2_norm;
05405     cout<<"NH: chi2min = "<<chi2min_NH[i]<<", IH: chi2min = "<<chi2min_IH[i]<<endl;
05406     
05407     delchi2 = delchi2_norm - delchi2_bestmh;
05408     chi2databin = int((delchi2-chi2start)/chi2binwidth)+1;
05409     
05410     TH1D *chi2hist = (TH1D*)f->Get(Form("Chi2Hist_MHFit_Normal_%i",i));
05411     
05412     if(chi2hist->Integral()<1)
05413     {
05414       cout<<"Warning, chi2hist is empty."<<endl;
05415       frac=0;
05416     }
05417     else
05418     {
05419       frac = chi2hist->Integral(1,chi2databin-1)/chi2hist->Integral();
05420     }
05421     if(chi2databin==1) frac=0;
05422     
05423     mhfit_nh[i] = frac;
05424     
05425     delchi2 = delchi2_invt - delchi2_bestmh;
05426     chi2databin = int((delchi2-chi2start)/chi2binwidth)+1;
05427     
05428     chi2hist = (TH1D*)f->Get(Form("Chi2Hist_MHFit_Inverted_%i",i));
05429     
05430     if(chi2hist->Integral()<1)
05431     {
05432       cout<<"Warning, chi2hist is empty."<<endl;
05433       frac=0;
05434     }
05435     else
05436     {
05437       frac = chi2hist->Integral(1,chi2databin-1)/chi2hist->Integral();
05438     }
05439     if(chi2databin==1) frac=0;
05440     
05441     mhfit_ih[i] = frac;
05442     
05443     delete chi2hist;
05444   }
05445   
05446   f->Close();
05447   
05448   TGraph *g_delta_NH = new TGraph(nPts_Normal,deltapts,deltafit_nh);
05449   g_delta_NH->SetName("delta_NH");
05450   
05451   TGraph *g_delta_IH = new TGraph(nPts_Normal,deltapts,deltafit_ih);
05452   g_delta_IH->SetName("delta_IH");
05453   
05454   TGraph *g_MH_NH = new TGraph(nPts_Normal,deltapts,mhfit_nh);
05455   g_MH_NH->SetName("mh_NH");
05456   
05457   TGraph *g_MH_IH = new TGraph(nPts_Normal,deltapts,mhfit_ih);
05458   g_MH_IH->SetName("mh_IH");
05459   
05460   TFile *fout = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"RECREATE");
05461   g_delta_NH->Write();
05462   g_delta_IH->Write();
05463   g_MH_NH->Write();
05464   g_MH_IH->Write();
05465   fout->Close();
05466   
05467   delete [] chi2data_NH;
05468   delete [] chi2data_IH;
05469   delete [] chi2min_NH;
05470   delete [] chi2min_IH;
05471   delete [] deltafit_nh;
05472   delete [] deltafit_ih;
05473   delete [] mhfit_nh;
05474   delete [] mhfit_ih;
05475   
05476   return;
05477 }

void NueFit2D::RunMultiBinPseudoExpts ( bool  Print = true  )  [virtual]

Reimplemented in NueFit2D_Joint.

Definition at line 2270 of file NueFit2D.cxx.

References BinLikelihood(), Bkgd, ErrorCalc::CalculateHOOError(), ErrorCalc::CalculateSystErrorMatrix(), ErrorCalc::CovMatrix, ErrorCalc::CovMatrix_Decomp, DefineBinDlnLMinuit(), DefineStdDlnLMinuit(), ErrCalc, ErrorMatrix, Extrap, FitMethod, Form(), FracErr_Bkgd, FracErr_Sig, GenerateOneCorrelatedExp(), GetMinLikelihood(), grid_background, grid_bin_oscparerr, grid_bnuecc, grid_delta, grid_nc, grid_nue, grid_numucc, grid_nutaucc, grid_signal, grid_sinsq2th13, GridScale_Inverted, GridScale_Normal, GridTree_2_Inverted, GridTree_2_Normal, GridTree_Inverted, GridTree_Normal, gSystem(), IncludeOscParErrs, InvErrorMatrix, nBins, NObs, nPts_Inverted, nPts_Normal, NumExpts, outFileName, PoissonChi2(), ReadGridFiles(), ScaledChi2(), ErrorCalc::SetGridPred(), ErrorCalc::SetUseGrid(), Sig, StandardChi2(), and StandardLikelihood().

02271 {
02272   if(FitMethod==1 && (FracErr_Bkgd==0 || FracErr_Sig==0))
02273   {
02274     cout<<"FracErr_Bkgd and FracErr_Sig need to be set for ScaledChi2.  Quitting..."<<endl;
02275     return;
02276   }
02277   if(Extrap.size()==0)
02278   {
02279     cout<<"No Extrapolate2D input.  Quitting..."<<endl;
02280     return;
02281   }
02282   for(unsigned int ie=0;ie<Extrap.size();ie++)
02283   {
02284     Extrap[ie]->GetPrediction();
02285   }
02286   if(ErrCalc==0)
02287   {
02288     cout<<"Need to set ErrorCalc object!  Quitting..."<<endl;
02289     return;
02290   }
02291   if(FitMethod==3) DefineStdDlnLMinuit();
02292   if(FitMethod==4) DefineBinDlnLMinuit();
02293   
02294   nBins = Extrap[0]->Pred_TotalBkgd_VsBinNumber->GetNbinsX();
02295   if(ErrorMatrix==0) ErrorMatrix = new TH2D("ErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
02296   if(InvErrorMatrix==0) InvErrorMatrix = new TH2D("InvErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
02297   
02298   TH2D *Error4Expts = new TH2D("Error4Expts","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
02299   
02300   ReadGridFiles();
02301   
02302   if(nPts_Normal==0 || nPts_Inverted==0) return;
02303   
02304   gRandom->SetSeed(0);
02305   
02306   int i,u;
02307   unsigned int j,k;
02308   TH1D *nexp_bkgd = new TH1D("nexp_bkgd","",nBins,-0.5,nBins-0.5);
02309   TH1D *nexp_signal = new TH1D("nexp_signal","",nBins,-0.5,nBins-0.5);
02310   TH1D *nexp = new TH1D("nexp","",nBins,-0.5,nBins-0.5);
02311   double delchi2,chi2min;
02312   TH1D *chi2hist = new TH1D("chi2hist","",110000,-10,100);
02313   double ele;
02314   int noff;
02315   
02316   vector< vector<double> > nc,numucc,bnuecc,nutaucc,sig;
02317   for(j=0;j<nBins;j++)
02318   {
02319     nc.push_back( vector<double>() );
02320     numucc.push_back( vector<double>() );
02321     bnuecc.push_back( vector<double>() );
02322     nutaucc.push_back( vector<double>() );
02323     sig.push_back( vector<double>() );
02324     for(k=0;k<Extrap.size();k++)
02325     {
02326       nc[j].push_back(0);
02327       numucc[j].push_back(0);
02328       bnuecc[j].push_back(0);
02329       nutaucc[j].push_back(0);
02330       sig[j].push_back(0);
02331     }
02332   }
02333   
02334   Bkgd = (TH1D*)nexp->Clone("Bkgd");
02335   Bkgd->Reset();
02336   Sig = (TH1D*)nexp->Clone("Sig");
02337   Sig->Reset();
02338   
02339   ofstream myfile;
02340   string file,ofile;
02341   
02342   //normal hierarchy
02343   
02344   TFile *f = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"RECREATE");
02345   
02346   if(Print)
02347   {
02348     ofile = gSystem->ExpandPathName(outFileName.c_str());
02349     file = ofile.substr(0,ofile.length()-5) + "_Normal.dat";
02350     myfile.open(gSystem->ExpandPathName(file.c_str()));
02351   }
02352   
02353   for(i=0;i<nPts_Normal;i++)
02354   {
02355     cout<<"point "<<(i+1)<<"/"<<nPts_Normal<<" (normal hierarchy)"<<endl;
02356     
02357     nexp_bkgd->Reset();
02358     nexp_signal->Reset();
02359     nexp->Reset();
02360     
02361     for(j=0;j<nBins;j++)
02362     {
02363       GridTree_Normal[j]->GetEntry(i);
02364       nexp_bkgd->SetBinContent(j+1,grid_background*GridScale_Normal);
02365       nexp_signal->SetBinContent(j+1,grid_signal*GridScale_Normal);
02366       
02367       for(k=0;k<Extrap.size();k++)
02368       {
02369         GridTree_2_Normal[j][k]->GetEntry(i);
02370         nc[j][k] = grid_nc*GridScale_Normal;
02371         numucc[j][k] = grid_numucc*GridScale_Normal;
02372         bnuecc[j][k] = grid_bnuecc*GridScale_Normal;
02373         nutaucc[j][k] = grid_nutaucc*GridScale_Normal;
02374         sig[j][k] = grid_nue*GridScale_Normal;
02375       }
02376     }
02377     nexp->Add(nexp_bkgd,nexp_signal,1,1);
02378     ErrCalc->SetGridPred(nBins,nc,numucc,bnuecc,nutaucc,sig);
02379     
02380     Error4Expts->Reset();
02381     ErrCalc->SetUseGrid(true);
02382     ErrCalc->CalculateSystErrorMatrix();
02383     Error4Expts->Add(ErrCalc->CovMatrix);
02384     ErrCalc->CalculateHOOError();
02385     Error4Expts->Add(ErrCalc->CovMatrix_Decomp);
02386     if(IncludeOscParErrs)
02387     {
02388       noff=0;
02389       for(j=0;j<nBins;j++)
02390       {
02391         ele=Error4Expts->GetBinContent(j+1,j+1);
02392         ele+=(grid_bin_oscparerr[j]*grid_bin_oscparerr[j]*nexp->GetBinContent(j+1)*nexp->GetBinContent(j+1));
02393         Error4Expts->SetBinContent(j+1,j+1,ele);
02394         
02395         for(k=0;k<nBins;k++)
02396         {
02397           if(k>j)
02398           {
02399             ele=Error4Expts->GetBinContent(j+1,k+1);
02400             ele+=(grid_bin_oscparerr[j]*grid_bin_oscparerr[k]*nexp->GetBinContent(j+1)*nexp->GetBinContent(k+1));
02401             Error4Expts->SetBinContent(j+1,k+1,ele);
02402             
02403             ele=Error4Expts->GetBinContent(k+1,j+1);
02404             ele+=(grid_bin_oscparerr[j]*grid_bin_oscparerr[k]*nexp->GetBinContent(j+1)*nexp->GetBinContent(k+1));
02405             Error4Expts->SetBinContent(k+1,j+1,ele);
02406             
02407             noff++;
02408           }
02409         }
02410       }
02411     }
02412     
02413     chi2hist->Reset();
02414     chi2hist->SetName(Form("Chi2Hist_Normal_%i",i));
02415     
02416     for(u=0;u<NumExpts;u++)
02417     {
02418       cout<<"expt "<<(u+1)<<"/"<<NumExpts<<endl;
02419       
02420       GenerateOneCorrelatedExp(nexp,Error4Expts);
02421       if(Print)
02422       {
02423         myfile << grid_sinsq2th13 << " " << grid_delta << " ";
02424         for(j=0;j<nBins;j++)
02425         {
02426           myfile << NObs->GetBinContent(j+1) << " ";
02427         }
02428         myfile << endl;
02429       }
02430       
02431       chi2min=GetMinLikelihood(grid_delta,true);
02432       
02433       ErrCalc->SetUseGrid(true);//will use the grid predictions set above
02434       delchi2 = 1e10;
02435       if(FitMethod==0)
02436       {
02437         delchi2 = PoissonChi2(nexp) - chi2min;
02438       }
02439       else if(FitMethod==1)
02440       {
02441         delchi2 = ScaledChi2(nexp_bkgd,nexp_signal) - chi2min;
02442       }
02443       else if(FitMethod==2)
02444       {
02445         delchi2 = StandardChi2(nexp) - chi2min;
02446       }
02447       else if(FitMethod==3)
02448       {
02449         //Likelihood: "Standard" (N syst, N nuisance)
02450         //Calculate the likelihood (x2 for chi)
02451         Bkgd->Reset();
02452         Bkgd->Add(nexp_bkgd);
02453         Sig->Reset();
02454         Sig->Add(nexp_signal);
02455         delchi2 = StandardLikelihood() - chi2min;
02456       }
02457       else if(FitMethod==4)
02458       {
02459         //Likelihood: Bin by Bin Calculation of Systematics
02460         //Calculate the likelihood (x2 for chi)
02461         Bkgd->Reset();
02462         Bkgd->Add(nexp_bkgd);
02463         Sig->Reset();
02464         Sig->Add(nexp_signal);
02465         delchi2 = BinLikelihood() - chi2min;
02466       }
02467       else
02468       {
02469         cout<<"Error in RunMultiBinPseudoExpts(): Unknown 'FitMethod'."<<endl;
02470       }
02471       chi2hist->Fill(delchi2);
02472       
02473     }
02474     f->cd();
02475     chi2hist->Write();
02476     f->Close();
02477     
02478     f = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"UPDATE");
02479   }
02480   
02481   if(Print) myfile.close();
02482   
02483   for(j=0;j<nBins;j++)
02484   {
02485     GridTree_Normal[j]->Write();
02486     
02487     for(k=0;k<Extrap.size();k++)
02488     {
02489       GridTree_2_Normal[j][k]->Write();
02490     }
02491   }
02492   
02493   f->Close();
02494   
02495   //inverted hierarchy
02496   
02497   f = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"UPDATE");
02498   
02499   if(Print)
02500   {
02501     ofile = gSystem->ExpandPathName(outFileName.c_str());
02502     file = ofile.substr(0,ofile.length()-5) + "_Inverted.dat";
02503     myfile.open(gSystem->ExpandPathName(file.c_str()));
02504   }
02505   
02506   for(i=0;i<nPts_Inverted;i++)
02507   {
02508     cout<<"point "<<(i+1)<<"/"<<nPts_Inverted<<" (inverted hierarchy)"<<endl;
02509     
02510     nexp_bkgd->Reset();
02511     nexp_signal->Reset();
02512     nexp->Reset();
02513     
02514     for(j=0;j<nBins;j++)
02515     {
02516       GridTree_Inverted[j]->GetEntry(i);
02517       nexp_bkgd->SetBinContent(j+1,grid_background*GridScale_Inverted);
02518       nexp_signal->SetBinContent(j+1,grid_signal*GridScale_Inverted);
02519       
02520       for(k=0;k<Extrap.size();k++)
02521       {
02522         GridTree_2_Inverted[j][k]->GetEntry(i);
02523         nc[j][k] = grid_nc*GridScale_Inverted;
02524         numucc[j][k] = grid_numucc*GridScale_Inverted;
02525         bnuecc[j][k] = grid_bnuecc*GridScale_Inverted;
02526         nutaucc[j][k] = grid_nutaucc*GridScale_Inverted;
02527         sig[j][k] = grid_nue*GridScale_Inverted;
02528       }
02529     }
02530     nexp->Add(nexp_bkgd,nexp_signal,1,1);
02531     ErrCalc->SetGridPred(nBins,nc,numucc,bnuecc,nutaucc,sig);
02532     
02533     Error4Expts->Reset();
02534     ErrCalc->SetUseGrid(true);
02535     ErrCalc->CalculateSystErrorMatrix();
02536     Error4Expts->Add(ErrCalc->CovMatrix);
02537     ErrCalc->CalculateHOOError();
02538     Error4Expts->Add(ErrCalc->CovMatrix_Decomp);
02539     if(IncludeOscParErrs)
02540     {
02541       noff=0;
02542       for(j=0;j<nBins;j++)
02543       {
02544         ele=Error4Expts->GetBinContent(j+1,j+1);
02545         ele+=(grid_bin_oscparerr[j]*grid_bin_oscparerr[j]*nexp->GetBinContent(j+1)*nexp->GetBinContent(j+1));
02546         Error4Expts->SetBinContent(j+1,j+1,ele);
02547         
02548         for(k=0;k<nBins;k++)
02549         {
02550           if(k>j)
02551           {
02552             ele=Error4Expts->GetBinContent(j+1,k+1);
02553             ele+=(grid_bin_oscparerr[j]*grid_bin_oscparerr[k]*nexp->GetBinContent(j+1)*nexp->GetBinContent(k+1));
02554             Error4Expts->SetBinContent(j+1,k+1,ele);
02555             
02556             ele=Error4Expts->GetBinContent(k+1,j+1);
02557             ele+=(grid_bin_oscparerr[j]*grid_bin_oscparerr[k]*nexp->GetBinContent(j+1)*nexp->GetBinContent(k+1));
02558             Error4Expts->SetBinContent(k+1,j+1,ele);
02559             
02560             noff++;
02561           }
02562         }
02563       }
02564     }
02565     
02566     chi2hist->Reset();
02567     chi2hist->SetName(Form("Chi2Hist_Inverted_%i",i));
02568     
02569     for(u=0;u<NumExpts;u++)
02570     {
02571       cout<<"expt "<<(u+1)<<"/"<<NumExpts<<endl;
02572       
02573       GenerateOneCorrelatedExp(nexp,Error4Expts);
02574       if(Print)
02575       {
02576         myfile << grid_sinsq2th13 << " " << grid_delta << " ";
02577         for(j=0;j<nBins;j++)
02578         {
02579           myfile << NObs->GetBinContent(j+1) << " ";
02580         }
02581         myfile << endl;
02582       }
02583       
02584       chi2min=GetMinLikelihood(grid_delta,false);
02585       
02586       ErrCalc->SetUseGrid(true);//will use the grid predictions set above
02587       delchi2 = 1e10;
02588       if(FitMethod==0)
02589       {
02590         delchi2 = PoissonChi2(nexp) - chi2min;
02591       }
02592       else if(FitMethod==1)
02593       {
02594         delchi2 = ScaledChi2(nexp_bkgd,nexp_signal) - chi2min;
02595       }
02596       else if(FitMethod==2)
02597       {
02598         delchi2 = StandardChi2(nexp) - chi2min;
02599       }
02600       else if(FitMethod==3)
02601       {
02602         //Likelihood: "Standard" (N syst, N nuisance)
02603         //Calculate the likelihood (x2 for chi)
02604         Bkgd->Reset();
02605         Bkgd->Add(nexp_bkgd);
02606         Sig->Reset();
02607         Sig->Add(nexp_signal);
02608         delchi2 = StandardLikelihood() - chi2min;
02609       }
02610       else if(FitMethod==4)
02611       {
02612         //Likelihood: Bin by Bin Calculation of Systematics
02613         //Calculate the likelihood (x2 for chi)
02614         Bkgd->Reset();
02615         Bkgd->Add(nexp_bkgd);
02616         Sig->Reset();
02617         Sig->Add(nexp_signal);
02618         delchi2 = BinLikelihood() - chi2min;
02619       }
02620       else
02621       {
02622         cout<<"Error in RunMultiBinPseudoExpts(): Unknown 'FitMethod'."<<endl;
02623       }
02624       chi2hist->Fill(delchi2);
02625     }
02626     f->cd();
02627     chi2hist->Write();
02628     f->Close();
02629     f = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"UPDATE");
02630   }
02631   
02632   if(Print) myfile.close();
02633   
02634   for(j=0;j<nBins;j++)
02635   {
02636     GridTree_Inverted[j]->Write();
02637     for(k=0;k<Extrap.size();k++)
02638     {
02639       GridTree_2_Inverted[j][k]->Write();
02640     }
02641   }
02642   
02643   f->Close();
02644   
02645   return;
02646 }

void NueFit2D::RunMultiBinPseudoExpts_MHDeltaFit ( bool  Print = true  )  [virtual]

Reimplemented in NueFit2D_Joint.

Definition at line 4563 of file NueFit2D.cxx.

References BinLikelihood(), Bkgd, ErrorCalc::CalculateHOOError(), ErrorCalc::CalculateSystErrorMatrix(), ErrorCalc::CovMatrix, ErrorCalc::CovMatrix_Decomp, DefineBinDlnLMinuit(), DefineStdDlnLMinuit(), ErrCalc, ErrorMatrix, Extrap, FitMethod, Form(), FracErr_Bkgd, FracErr_Sig, GenerateOneCorrelatedExp(), GetMinLikelihood_Delta(), grid_background, grid_bin_oscparerr, grid_bnuecc, grid_delta, grid_nc, grid_nue, grid_numucc, grid_nutaucc, grid_signal, grid_sinsq2th13, GridScale_Inverted, GridScale_Normal, GridTree_2_Inverted, GridTree_2_Normal, GridTree_Inverted, GridTree_Normal, gSystem(), IncludeOscParErrs, InvErrorMatrix, nBins, NObs, nPts_Inverted, nPts_Normal, NumExpts, outFileName, PoissonChi2(), ReadGridFiles(), ScaledChi2(), ErrorCalc::SetGridPred(), ErrorCalc::SetUseGrid(), Sig, StandardChi2(), and StandardLikelihood().

04564 {
04565   if(FitMethod==1 && (FracErr_Bkgd==0 || FracErr_Sig==0))
04566   {
04567     cout<<"FracErr_Bkgd and FracErr_Sig need to be set for ScaledChi2.  Quitting..."<<endl;
04568     return;
04569   }
04570   if(Extrap.size()==0)
04571   {
04572     cout<<"No Extrapolate2D input.  Quitting..."<<endl;
04573     return;
04574   }
04575   for(unsigned int ie=0;ie<Extrap.size();ie++)
04576   {
04577     Extrap[ie]->GetPrediction();
04578   }
04579   if(ErrCalc==0)
04580   {
04581     cout<<"Need to set ErrorCalc object!  Quitting..."<<endl;
04582     return;
04583   }
04584   if(FitMethod==3) DefineStdDlnLMinuit();
04585   if(FitMethod==4) DefineBinDlnLMinuit();
04586   
04587   nBins = Extrap[0]->Pred_TotalBkgd_VsBinNumber->GetNbinsX();
04588   if(ErrorMatrix==0) ErrorMatrix = new TH2D("ErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
04589   if(InvErrorMatrix==0) InvErrorMatrix = new TH2D("InvErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
04590   
04591   TH2D *Error4Expts = new TH2D("Error4Expts","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
04592   
04593   ReadGridFiles();
04594   
04595   if(nPts_Normal==0 || nPts_Inverted==0) return;
04596   
04597   gRandom->SetSeed(0);
04598   
04599   int i,u;
04600   unsigned int j,k;
04601   TH1D *nexp_bkgd_n = new TH1D("nexp_bkgd_n","",nBins,-0.5,nBins-0.5);
04602   TH1D *nexp_signal_n = new TH1D("nexp_signal_n","",nBins,-0.5,nBins-0.5);
04603   TH1D *nexp_n = new TH1D("nexp_n","",nBins,-0.5,nBins-0.5);
04604   
04605   TH1D *nexp_bkgd_i = new TH1D("nexp_bkgd_i","",nBins,-0.5,nBins-0.5);
04606   TH1D *nexp_signal_i = new TH1D("nexp_signal_i","",nBins,-0.5,nBins-0.5);
04607   TH1D *nexp_i = new TH1D("nexp_i","",nBins,-0.5,nBins-0.5);
04608   
04609   double chi2_norm,chi2_invt,chi2min_norm,chi2min_invt;
04610   double delchi2_norm, delchi2_invt,delchi2_bestmh;
04611   
04612   TH1D *chi2hist_deltafit = new TH1D("chi2hist_deltafit","",110000,-10,100);
04613   TH1D *chi2hist_mhfit = new TH1D("chi2hist_mhfit","",110000,-10,100);
04614   double ele;
04615   int noff;
04616   
04617   vector< vector<double> > nc_n,numucc_n,bnuecc_n,nutaucc_n,sig_n;
04618   vector< vector<double> > nc_i,numucc_i,bnuecc_i,nutaucc_i,sig_i;
04619   for(j=0;j<nBins;j++)
04620   {
04621     nc_n.push_back( vector<double>() );
04622     numucc_n.push_back( vector<double>() );
04623     bnuecc_n.push_back( vector<double>() );
04624     nutaucc_n.push_back( vector<double>() );
04625     sig_n.push_back( vector<double>() );
04626     
04627     nc_i.push_back( vector<double>() );
04628     numucc_i.push_back( vector<double>() );
04629     bnuecc_i.push_back( vector<double>() );
04630     nutaucc_i.push_back( vector<double>() );
04631     sig_i.push_back( vector<double>() );
04632     
04633     for(k=0;k<Extrap.size();k++)
04634     {
04635       nc_n[j].push_back(0);
04636       numucc_n[j].push_back(0);
04637       bnuecc_n[j].push_back(0);
04638       nutaucc_n[j].push_back(0);
04639       sig_n[j].push_back(0);
04640       
04641       nc_i[j].push_back(0);
04642       numucc_i[j].push_back(0);
04643       bnuecc_i[j].push_back(0);
04644       nutaucc_i[j].push_back(0);
04645       sig_i[j].push_back(0);
04646     }
04647   }
04648   
04649   Bkgd = (TH1D*)nexp_n->Clone("Bkgd");
04650   Bkgd->Reset();
04651   Sig = (TH1D*)nexp_n->Clone("Sig");
04652   Sig->Reset();
04653   
04654   ofstream myfile;
04655   string file,ofile;
04656   
04657   //normal hierarchy
04658   
04659   TFile *f = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"RECREATE");
04660   
04661   if(Print)
04662   {
04663     ofile = gSystem->ExpandPathName(outFileName.c_str());
04664     file = ofile.substr(0,ofile.length()-5) + "_Normal.dat";
04665     myfile.open(gSystem->ExpandPathName(file.c_str()));
04666   }
04667   
04668   for(i=0;i<nPts_Normal;i++)
04669   {
04670     cout<<"point "<<(i+1)<<"/"<<nPts_Normal<<" (normal hierarchy)"<<endl;
04671     
04672     nexp_bkgd_n->Reset();
04673     nexp_signal_n->Reset();
04674     nexp_n->Reset();
04675     
04676     nexp_bkgd_i->Reset();
04677     nexp_signal_i->Reset();
04678     nexp_i->Reset();
04679     
04680     for(j=0;j<nBins;j++)
04681     {
04682       GridTree_Normal[j]->GetEntry(i);
04683       nexp_bkgd_n->SetBinContent(j+1,grid_background*GridScale_Normal);
04684       nexp_signal_n->SetBinContent(j+1,grid_signal*GridScale_Normal);
04685       
04686       GridTree_Inverted[j]->GetEntry(i);
04687       nexp_bkgd_i->SetBinContent(j+1,grid_background*GridScale_Inverted);
04688       nexp_signal_i->SetBinContent(j+1,grid_signal*GridScale_Inverted);
04689       
04690       for(k=0;k<Extrap.size();k++)
04691       {
04692         GridTree_2_Normal[j][k]->GetEntry(i);
04693         nc_n[j][k] = grid_nc*GridScale_Normal;
04694         numucc_n[j][k] = grid_numucc*GridScale_Normal;
04695         bnuecc_n[j][k] = grid_bnuecc*GridScale_Normal;
04696         nutaucc_n[j][k] = grid_nutaucc*GridScale_Normal;
04697         sig_n[j][k] = grid_nue*GridScale_Normal;
04698         
04699         GridTree_2_Inverted[j][k]->GetEntry(i);
04700         nc_i[j][k] = grid_nc*GridScale_Inverted;
04701         numucc_i[j][k] = grid_numucc*GridScale_Inverted;
04702         bnuecc_i[j][k] = grid_bnuecc*GridScale_Inverted;
04703         nutaucc_i[j][k] = grid_nutaucc*GridScale_Inverted;
04704         sig_i[j][k] = grid_nue*GridScale_Inverted;
04705       }
04706     }
04707     nexp_n->Add(nexp_bkgd_n,nexp_signal_n,1,1);
04708     nexp_i->Add(nexp_bkgd_i,nexp_signal_i,1,1);
04709     
04710     //want to generate pseudos for normal hierarchy
04711     ErrCalc->SetGridPred(nBins,nc_n,numucc_n,bnuecc_n,nutaucc_n,sig_n);
04712     Error4Expts->Reset();
04713     ErrCalc->SetUseGrid(true);
04714     ErrCalc->CalculateSystErrorMatrix();
04715     Error4Expts->Add(ErrCalc->CovMatrix);
04716     ErrCalc->CalculateHOOError();
04717     Error4Expts->Add(ErrCalc->CovMatrix_Decomp);
04718     if(IncludeOscParErrs)
04719     {
04720       noff=0;
04721       for(j=0;j<nBins;j++)
04722       {
04723         GridTree_Normal[j]->GetEntry(i);
04724         ele=Error4Expts->GetBinContent(j+1,j+1);
04725         ele+=(grid_bin_oscparerr[j]*grid_bin_oscparerr[j]*nexp_n->GetBinContent(j+1)*nexp_n->GetBinContent(j+1));
04726         Error4Expts->SetBinContent(j+1,j+1,ele);
04727         
04728         for(k=0;k<nBins;k++)
04729         {
04730           if(k>j)
04731           {
04732             ele=Error4Expts->GetBinContent(j+1,k+1);
04733             ele+=(grid_bin_oscparerr[j]*grid_bin_oscparerr[k]*nexp_n->GetBinContent(j+1)*nexp_n->GetBinContent(k+1));
04734             Error4Expts->SetBinContent(j+1,k+1,ele);
04735             
04736             ele=Error4Expts->GetBinContent(k+1,j+1);
04737             ele+=(grid_bin_oscparerr[j]*grid_bin_oscparerr[k]*nexp_n->GetBinContent(j+1)*nexp_n->GetBinContent(k+1));
04738             Error4Expts->SetBinContent(k+1,j+1,ele);
04739             
04740             noff++;
04741           }
04742         }
04743       }
04744     }
04745     
04746     chi2hist_deltafit->Reset();
04747     chi2hist_deltafit->SetName(Form("Chi2Hist_DeltaFit_Normal_%i",i));
04748     
04749     chi2hist_mhfit->Reset();
04750     chi2hist_mhfit->SetName(Form("Chi2Hist_MHFit_Normal_%i",i));
04751     
04752     for(u=0;u<NumExpts;u++)
04753     {
04754       cout<<"expt "<<(u+1)<<"/"<<NumExpts<<endl;
04755       
04756       GenerateOneCorrelatedExp(nexp_n,Error4Expts);
04757       if(Print)
04758       {
04759         myfile << grid_sinsq2th13 << " " << grid_delta << " ";
04760         for(j=0;j<nBins;j++)
04761         {
04762           myfile << NObs->GetBinContent(j+1) << " ";
04763         }
04764       }
04765       
04766       chi2min_norm=GetMinLikelihood_Delta(true);
04767       chi2min_invt=GetMinLikelihood_Delta(false);
04768       
04769       ErrCalc->SetGridPred(nBins,nc_n,numucc_n,bnuecc_n,nutaucc_n,sig_n);
04770       ErrCalc->SetUseGrid(true);
04771       chi2_norm = 1e10;
04772       if(FitMethod==0)
04773       {
04774         chi2_norm = PoissonChi2(nexp_n);
04775       }
04776       else if(FitMethod==1)
04777       {
04778         chi2_norm = ScaledChi2(nexp_bkgd_n,nexp_signal_n);
04779       }
04780       else if(FitMethod==2)
04781       {
04782         chi2_norm = StandardChi2(nexp_n);
04783       }
04784       else if(FitMethod==3)
04785       {
04786         //Likelihood: "Standard" (N syst, N nuisance)
04787         //Calculate the likelihood (x2 for chi)
04788         Bkgd->Reset();
04789         Bkgd->Add(nexp_bkgd_n);
04790         Sig->Reset();
04791         Sig->Add(nexp_signal_n);
04792         chi2_norm = StandardLikelihood();
04793       }
04794       else if(FitMethod==4)
04795       {
04796         //Likelihood: Bin by Bin Calculation of Systematics
04797         //Calculate the likelihood (x2 for chi)
04798         Bkgd->Reset();
04799         Bkgd->Add(nexp_bkgd_n);
04800         Sig->Reset();
04801         Sig->Add(nexp_signal_n);
04802         chi2_norm = BinLikelihood();
04803       }
04804       else
04805       {
04806         cout<<"Error in RunMultiBinPseudoExpts_MHDeltaFit(): Unknown 'FitMethod'."<<endl;
04807       }
04808       
04809       ErrCalc->SetGridPred(nBins,nc_i,numucc_i,bnuecc_i,nutaucc_i,sig_i);
04810       ErrCalc->SetUseGrid(true);
04811       chi2_invt = 1e10;
04812       if(FitMethod==0)
04813       {
04814         chi2_invt = PoissonChi2(nexp_i);
04815       }
04816       else if(FitMethod==1)
04817       {
04818         chi2_invt = ScaledChi2(nexp_bkgd_i,nexp_signal_i);
04819       }
04820       else if(FitMethod==2)
04821       {
04822         chi2_invt = StandardChi2(nexp_i);
04823       }
04824       else if(FitMethod==3)
04825       {
04826         //Likelihood: "Standard" (N syst, N nuisance)
04827         //Calculate the likelihood (x2 for chi)
04828         Bkgd->Reset();
04829         Bkgd->Add(nexp_bkgd_i);
04830         Sig->Reset();
04831         Sig->Add(nexp_signal_i);
04832         chi2_invt = StandardLikelihood();
04833       }
04834       else if(FitMethod==4)
04835       {
04836         //Likelihood: Bin by Bin Calculation of Systematics
04837         //Calculate the likelihood (x2 for chi)
04838         Bkgd->Reset();
04839         Bkgd->Add(nexp_bkgd_i);
04840         Sig->Reset();
04841         Sig->Add(nexp_signal_i);
04842         chi2_invt = BinLikelihood();
04843       }
04844       else
04845       {
04846         cout<<"Error in RunMultiBinPseudoExpts_MHDeltaFit(): Unknown 'FitMethod'."<<endl;
04847       }
04848       
04849       if(Print)
04850       {
04851         myfile << chi2_norm << " " << chi2_invt << " " << chi2min_norm << " " << chi2min_invt << endl;
04852       }
04853       
04854       delchi2_norm = chi2_norm - chi2min_norm;
04855       delchi2_invt = chi2_invt - chi2min_invt;
04856       delchi2_bestmh = delchi2_norm;
04857       if(delchi2_invt<delchi2_bestmh) delchi2_bestmh = delchi2_invt;
04858       
04859       chi2hist_deltafit->Fill(delchi2_norm);
04860       chi2hist_mhfit->Fill(delchi2_norm - delchi2_bestmh);
04861     }
04862     f->cd();
04863     chi2hist_deltafit->Write();
04864     chi2hist_mhfit->Write();
04865     f->Close();
04866     
04867     f = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"UPDATE");
04868   }
04869   
04870   if(Print) myfile.close();
04871   
04872   for(j=0;j<nBins;j++)
04873   {
04874     GridTree_Normal[j]->Write();
04875     
04876     for(k=0;k<Extrap.size();k++)
04877     {
04878       GridTree_2_Normal[j][k]->Write();
04879     }
04880   }
04881   
04882   f->Close();
04883   
04884   //inverted hierarchy
04885   
04886   f = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"UPDATE");
04887   
04888   if(Print)
04889   {
04890     ofile = gSystem->ExpandPathName(outFileName.c_str());
04891     file = ofile.substr(0,ofile.length()-5) + "_Inverted.dat";
04892     myfile.open(gSystem->ExpandPathName(file.c_str()));
04893   }
04894   
04895   for(i=0;i<nPts_Inverted;i++)
04896   {
04897     cout<<"point "<<(i+1)<<"/"<<nPts_Inverted<<" (inverted hierarchy)"<<endl;
04898     
04899     nexp_bkgd_n->Reset();
04900     nexp_signal_n->Reset();
04901     nexp_n->Reset();
04902     
04903     nexp_bkgd_i->Reset();
04904     nexp_signal_i->Reset();
04905     nexp_i->Reset();
04906     
04907     for(j=0;j<nBins;j++)
04908     {
04909       GridTree_Normal[j]->GetEntry(i);
04910       nexp_bkgd_n->SetBinContent(j+1,grid_background*GridScale_Normal);
04911       nexp_signal_n->SetBinContent(j+1,grid_signal*GridScale_Normal);
04912       
04913       GridTree_Inverted[j]->GetEntry(i);
04914       nexp_bkgd_i->SetBinContent(j+1,grid_background*GridScale_Inverted);
04915       nexp_signal_i->SetBinContent(j+1,grid_signal*GridScale_Inverted);
04916       
04917       for(k=0;k<Extrap.size();k++)
04918       {
04919         GridTree_2_Normal[j][k]->GetEntry(i);
04920         nc_n[j][k] = grid_nc*GridScale_Normal;
04921         numucc_n[j][k] = grid_numucc*GridScale_Normal;
04922         bnuecc_n[j][k] = grid_bnuecc*GridScale_Normal;
04923         nutaucc_n[j][k] = grid_nutaucc*GridScale_Normal;
04924         sig_n[j][k] = grid_nue*GridScale_Normal;
04925         
04926         GridTree_2_Inverted[j][k]->GetEntry(i);
04927         nc_i[j][k] = grid_nc*GridScale_Inverted;
04928         numucc_i[j][k] = grid_numucc*GridScale_Inverted;
04929         bnuecc_i[j][k] = grid_bnuecc*GridScale_Inverted;
04930         nutaucc_i[j][k] = grid_nutaucc*GridScale_Inverted;
04931         sig_i[j][k] = grid_nue*GridScale_Inverted;
04932       }
04933     }
04934     nexp_n->Add(nexp_bkgd_n,nexp_signal_n,1,1);
04935     nexp_i->Add(nexp_bkgd_i,nexp_signal_i,1,1);
04936     
04937     //want to generate pseudos for inverted hierarchy
04938     ErrCalc->SetGridPred(nBins,nc_i,numucc_i,bnuecc_i,nutaucc_i,sig_i);
04939     Error4Expts->Reset();
04940     ErrCalc->SetUseGrid(true);
04941     ErrCalc->CalculateSystErrorMatrix();
04942     Error4Expts->Add(ErrCalc->CovMatrix);
04943     ErrCalc->CalculateHOOError();
04944     Error4Expts->Add(ErrCalc->CovMatrix_Decomp);
04945     if(IncludeOscParErrs)
04946     {
04947       noff=0;
04948       for(j=0;j<nBins;j++)
04949       {
04950         GridTree_Inverted[j]->GetEntry(i);
04951         ele=Error4Expts->GetBinContent(j+1,j+1);
04952         ele+=(grid_bin_oscparerr[j]*grid_bin_oscparerr[j]*nexp_i->GetBinContent(j+1)*nexp_i->GetBinContent(j+1));
04953         Error4Expts->SetBinContent(j+1,j+1,ele);
04954         
04955         for(k=0;k<nBins;k++)
04956         {
04957           if(k>j)
04958           {
04959             ele=Error4Expts->GetBinContent(j+1,k+1);
04960             ele+=(grid_bin_oscparerr[j]*grid_bin_oscparerr[k]*nexp_i->GetBinContent(j+1)*nexp_i->GetBinContent(k+1));
04961             Error4Expts->SetBinContent(j+1,k+1,ele);
04962             
04963             ele=Error4Expts->GetBinContent(k+1,j+1);
04964             ele+=(grid_bin_oscparerr[j]*grid_bin_oscparerr[k]*nexp_i->GetBinContent(j+1)*nexp_i->GetBinContent(k+1));
04965             Error4Expts->SetBinContent(k+1,j+1,ele);
04966             
04967             noff++;
04968           }
04969         }
04970       }
04971     }
04972     
04973     chi2hist_deltafit->Reset();
04974     chi2hist_deltafit->SetName(Form("Chi2Hist_DeltaFit_Inverted_%i",i));
04975     
04976     chi2hist_mhfit->Reset();
04977     chi2hist_mhfit->SetName(Form("Chi2Hist_MHFit_Inverted_%i",i));
04978     
04979     for(u=0;u<NumExpts;u++)
04980     {
04981       cout<<"expt "<<(u+1)<<"/"<<NumExpts<<endl;
04982       
04983       GenerateOneCorrelatedExp(nexp_i,Error4Expts);
04984       if(Print)
04985       {
04986         myfile << grid_sinsq2th13 << " " << grid_delta << " ";
04987         for(j=0;j<nBins;j++)
04988         {
04989           myfile << NObs->GetBinContent(j+1) << " ";
04990         }
04991       }
04992       
04993       chi2min_norm=GetMinLikelihood_Delta(true);
04994       chi2min_invt=GetMinLikelihood_Delta(false);
04995       
04996       ErrCalc->SetGridPred(nBins,nc_n,numucc_n,bnuecc_n,nutaucc_n,sig_n);
04997       ErrCalc->SetUseGrid(true);
04998       chi2_norm = 1e10;
04999       if(FitMethod==0)
05000       {
05001         chi2_norm = PoissonChi2(nexp_n);
05002       }
05003       else if(FitMethod==1)
05004       {
05005         chi2_norm = ScaledChi2(nexp_bkgd_n,nexp_signal_n);
05006       }
05007       else if(FitMethod==2)
05008       {
05009         chi2_norm = StandardChi2(nexp_n);
05010       }
05011       else if(FitMethod==3)
05012       {
05013         //Likelihood: "Standard" (N syst, N nuisance)
05014         //Calculate the likelihood (x2 for chi)
05015         Bkgd->Reset();
05016         Bkgd->Add(nexp_bkgd_n);
05017         Sig->Reset();
05018         Sig->Add(nexp_signal_n);
05019         chi2_norm = StandardLikelihood();
05020       }
05021       else if(FitMethod==4)
05022       {
05023         //Likelihood: Bin by Bin Calculation of Systematics
05024         //Calculate the likelihood (x2 for chi)
05025         Bkgd->Reset();
05026         Bkgd->Add(nexp_bkgd_n);
05027         Sig->Reset();
05028         Sig->Add(nexp_signal_n);
05029         chi2_norm = BinLikelihood();
05030       }
05031       else
05032       {
05033         cout<<"Error in RunMultiBinPseudoExpts_MHDeltaFit(): Unknown 'FitMethod'."<<endl;
05034       }
05035       
05036       ErrCalc->SetGridPred(nBins,nc_i,numucc_i,bnuecc_i,nutaucc_i,sig_i);
05037       ErrCalc->SetUseGrid(true);
05038       chi2_invt = 1e10;
05039       if(FitMethod==0)
05040       {
05041         chi2_invt = PoissonChi2(nexp_i);
05042       }
05043       else if(FitMethod==1)
05044       {
05045         chi2_invt = ScaledChi2(nexp_bkgd_i,nexp_signal_i);
05046       }
05047       else if(FitMethod==2)
05048       {
05049         chi2_invt = StandardChi2(nexp_i);
05050       }
05051       else if(FitMethod==3)
05052       {
05053         //Likelihood: "Standard" (N syst, N nuisance)
05054         //Calculate the likelihood (x2 for chi)
05055         Bkgd->Reset();
05056         Bkgd->Add(nexp_bkgd_i);
05057         Sig->Reset();
05058         Sig->Add(nexp_signal_i);
05059         chi2_invt = StandardLikelihood();
05060       }
05061       else if(FitMethod==4)
05062       {
05063         //Likelihood: Bin by Bin Calculation of Systematics
05064         //Calculate the likelihood (x2 for chi)
05065         Bkgd->Reset();
05066         Bkgd->Add(nexp_bkgd_i);
05067         Sig->Reset();
05068         Sig->Add(nexp_signal_i);
05069         chi2_invt = BinLikelihood();
05070       }
05071       else
05072       {
05073         cout<<"Error in RunMultiBinPseudoExpts_MHDeltaFit(): Unknown 'FitMethod'."<<endl;
05074       }
05075       
05076       if(Print)
05077       {
05078         myfile << chi2_norm << " " << chi2_invt << " " << chi2min_norm << " " << chi2min_invt << endl;
05079       }
05080       
05081       delchi2_norm = chi2_norm - chi2min_norm;
05082       delchi2_invt = chi2_invt - chi2min_invt;
05083       delchi2_bestmh = delchi2_invt;
05084       if(delchi2_norm<delchi2_bestmh) delchi2_bestmh = delchi2_norm;
05085       
05086       chi2hist_deltafit->Fill(delchi2_invt);
05087       chi2hist_mhfit->Fill(delchi2_invt - delchi2_bestmh);
05088     }
05089     f->cd();
05090     chi2hist_deltafit->Write();
05091     chi2hist_mhfit->Write();
05092     f->Close();
05093     
05094     f = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"UPDATE");
05095   }
05096   
05097   if(Print) myfile.close();
05098   
05099   for(j=0;j<nBins;j++)
05100   {
05101     GridTree_Inverted[j]->Write();
05102     for(k=0;k<Extrap.size();k++)
05103     {
05104       GridTree_2_Inverted[j][k]->Write();
05105     }
05106   }
05107   
05108   f->Close();
05109   
05110   return;
05111 }

void NueFit2D::RunPseudoExperiments (  ) 

Definition at line 2097 of file NueFit2D.cxx.

References Extrap, Form(), FracErr_Bkgd, FracErr_Sig, GenerateOneExperiment(), grid_background, grid_oscparerr, grid_signal, GridScale_Inverted, GridScale_Normal, GridTree_Inverted, GridTree_Normal, gSystem(), IncludeOscParErrs, nBins, NObs, nPts_Inverted, nPts_Normal, NumExpts, outFileName, PoissonChi2(), and ReadGridFiles().

02098 {
02099   if(FracErr_Bkgd==0)
02100   {
02101     cout<<"FracErr_Bkgd not set.  Quitting..."<<endl;
02102     return;
02103   }
02104   if(FracErr_Sig==0)
02105   {
02106     cout<<"FracErr_Sig not set.  Quitting..."<<endl;
02107     return;
02108   }
02109   if(Extrap.size()==0)
02110   {
02111     cout<<"No Extrapolate2D input.  Quitting..."<<endl;
02112     return;
02113   }
02114   
02115   gRandom->SetSeed(0);
02116   
02117   ReadGridFiles();
02118   
02119   if(nPts_Normal==0 || nPts_Inverted==0) return;
02120   
02121   int i,k;
02122   unsigned int j;
02123   TH1D *nexp_bkgd = new TH1D("nexp_bkgd","",nBins,-0.5,nBins-0.5);
02124   TH1D *nexp_signal = new TH1D("nexp_signal","",nBins,-0.5,nBins-0.5);
02125   TH1D *dnexp_oscpar = new TH1D("dnexp_oscpar","",nBins,-0.5,nBins-0.5);
02126   TH1D *nexp = new TH1D("nexp","",nBins,-0.5,nBins-0.5);
02127   double delchi2;
02128   bool calcchi2min;//if nobs<nexpmin for any bin, then chi2min!=0 and needs to be calculated
02129   TH1D *nexpmin=0;
02130   TH1D *chi2hist = new TH1D("chi2hist","",110000,-10,100);
02131   
02132   //normal hierarchy
02133   for(j=0;j<Extrap.size();j++)
02134   {
02135     Extrap[j]->GetPrediction();
02136     Extrap[j]->SetSinSq2Th13(0);
02137     Extrap[j]->OscillatePrediction();
02138     if(j==0)
02139     {
02140       nexpmin = (TH1D*)Extrap[j]->Pred_TotalBkgd_VsBinNumber->Clone("nexpmin");
02141       nexpmin->Add(Extrap[j]->Pred_Signal_VsBinNumber);
02142     }
02143     else
02144     {
02145       nexpmin->Add(Extrap[j]->Pred_TotalBkgd_VsBinNumber);
02146       nexpmin->Add(Extrap[j]->Pred_Signal_VsBinNumber);
02147     }
02148   }
02149   
02150   TFile *f = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"RECREATE");
02151   
02152   for(i=0;i<nPts_Normal;i++)
02153   {
02154     if(i%100==0) cout<<100.*i/nPts_Normal<<"% complete for normal hierarchy"<<endl;
02155     
02156     nexp_bkgd->Reset();
02157     nexp_signal->Reset();
02158     nexp->Reset();
02159     dnexp_oscpar->Reset();
02160     for(j=0;j<nBins;j++)
02161     {
02162       GridTree_Normal[j]->GetEntry(i);
02163       nexp_bkgd->SetBinContent(j+1,grid_background*GridScale_Normal);
02164       nexp_signal->SetBinContent(j+1,grid_signal*GridScale_Normal);
02165       dnexp_oscpar->SetBinContent(j+1,grid_oscparerr);
02166     }
02167     nexp->Add(nexp_bkgd,nexp_signal,1,1);
02168     
02169     chi2hist->Reset();
02170     chi2hist->SetName(Form("Chi2Hist_Normal_%i",i));
02171     
02172     for(k=0;k<NumExpts;k++)
02173     {
02174       if(IncludeOscParErrs) GenerateOneExperiment(nexp_bkgd,nexp_signal,dnexp_oscpar);
02175       else GenerateOneExperiment(nexp_bkgd,nexp_signal);
02176       delchi2 = PoissonChi2(nexp);
02177       calcchi2min=false;
02178       for(j=0;j<nBins;j++)
02179       {
02180         if(NObs->GetBinContent(j+1)<nexpmin->GetBinContent(j+1))
02181         {
02182           calcchi2min=true;
02183         }
02184       }
02185       if(calcchi2min) delchi2 = delchi2 - PoissonChi2(nexpmin);
02186       chi2hist->Fill(delchi2);
02187     }
02188     chi2hist->Write();
02189     f->Close();
02190     f = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"UPDATE");
02191   }
02192   
02193   for(j=0;j<nBins;j++)
02194   {
02195     GridTree_Normal[j]->Write();
02196   }
02197   
02198   f->Close();
02199   
02200   //inverted hierarchy
02201   for(j=0;j<Extrap.size();j++)
02202   {
02203     Extrap[j]->SetSinSq2Th13(0);
02204     Extrap[j]->InvertMassHierarchy();
02205     Extrap[j]->OscillatePrediction();
02206     if(j==0)
02207     {
02208       nexpmin = (TH1D*)Extrap[j]->Pred_TotalBkgd_VsBinNumber->Clone("nexpmin");
02209       nexpmin->Add(Extrap[j]->Pred_Signal_VsBinNumber);
02210     }
02211     else
02212     {
02213       nexpmin->Add(Extrap[j]->Pred_TotalBkgd_VsBinNumber);
02214       nexpmin->Add(Extrap[j]->Pred_Signal_VsBinNumber);
02215     }
02216   }
02217   
02218   f = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"UPDATE");
02219   
02220   for(i=0;i<nPts_Inverted;i++)
02221   {
02222     if(i%100==0) cout<<100.*i/nPts_Inverted<<"% complete for inverted hierarchy"<<endl;
02223     
02224     nexp_bkgd->Reset();
02225     nexp_signal->Reset();
02226     nexp->Reset();
02227     dnexp_oscpar->Reset();
02228     for(j=0;j<nBins;j++)
02229     {
02230       GridTree_Inverted[j]->GetEntry(i);
02231       nexp_bkgd->SetBinContent(j+1,grid_background*GridScale_Inverted);
02232       nexp_signal->SetBinContent(j+1,grid_signal*GridScale_Inverted);
02233       dnexp_oscpar->SetBinContent(j+1,grid_oscparerr);
02234     }
02235     nexp->Add(nexp_bkgd,nexp_signal,1,1);
02236     
02237     chi2hist->Reset();
02238     chi2hist->SetName(Form("Chi2Hist_Inverted_%i",i));
02239     
02240     for(k=0;k<NumExpts;k++)
02241     {
02242       if(IncludeOscParErrs) GenerateOneExperiment(nexp_bkgd,nexp_signal,dnexp_oscpar);
02243       else GenerateOneExperiment(nexp_bkgd,nexp_signal);
02244       delchi2 = PoissonChi2(nexp);
02245       calcchi2min=false;
02246       for(j=0;j<nBins;j++)
02247       {
02248         if(NObs->GetBinContent(j+1)<nexpmin->GetBinContent(j+1))
02249         {
02250           calcchi2min=true;
02251         }
02252       }
02253       if(calcchi2min) delchi2 = delchi2 - PoissonChi2(nexpmin);
02254       chi2hist->Fill(delchi2);
02255     }
02256     chi2hist->Write();
02257     f->Close();
02258     f = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"UPDATE");
02259   }
02260   
02261   for(j=0;j<nBins;j++)
02262   {
02263     GridTree_Inverted[j]->Write();
02264   }
02265   
02266   f->Close();
02267   
02268   return;
02269 }

void NueFit2D::RunScaledChi2Sensitivity (  ) 

Definition at line 1165 of file NueFit2D.cxx.

References Bkgd, delta, DeltaHigh, DeltaLow, Extrap, FracErr_Bkgd, FracErr_Sig, gSystem(), nDeltaSteps, NObs, nSinSq2Th13Steps, outFileName, ScaledChi2(), Sig, SinSq2Th13High, and SinSq2Th13Low.

01166 {
01167   if(NObs==0)
01168   {
01169     cout<<"NObs not set.  Quitting..."<<endl;
01170     return;
01171   }
01172   
01173   if(FracErr_Bkgd==0)
01174   {
01175     cout<<"FracErr_Bkgd not set. Quitting..."<<endl;
01176     return;
01177   }
01178   
01179   if(Extrap.size()==0)
01180   {
01181     cout<<"No Extrapolate2D input.  Quitting..."<<endl;
01182     return;
01183   }
01184   
01185   Bkgd = (TH1D*)NObs->Clone("Bkgd");
01186   Bkgd->Reset();
01187   Sig = (TH1D*)NObs->Clone("Sig");
01188   Sig->Reset();
01189   FracErr_Sig = (TH1D*)NObs->Clone("FracErr_Sig");
01190   FracErr_Sig->Reset();
01191   //for sensitivity, signal err is ignored
01192   
01193   unsigned int ie;
01194   for(ie=0;ie<Extrap.size();ie++)
01195   {
01196     Extrap[ie]->GetPrediction();
01197   }
01198   
01199   Int_t i,j;
01200   
01201   Double_t ss2th13 = 0;
01202   Double_t delta = 0;
01203   Double_t chi2 = 0,chi2prev = 0;
01204   Double_t contourlvl = 2.71;
01205   Double_t prev = 0;
01206   Double_t best = 0;
01207   Double_t Deltaincrement = 0;
01208   if(nDeltaSteps>0) Deltaincrement = (DeltaHigh - DeltaLow)/(nDeltaSteps);
01209   Double_t Th13increment = 0;
01210   if(nSinSq2Th13Steps>0) Th13increment = (SinSq2Th13High - SinSq2Th13Low)/(nSinSq2Th13Steps);
01211   
01212   vector<Double_t> limit90_norm;
01213   vector<Double_t> limit90_invt;
01214   vector<double> deltapts_norm;
01215   vector<double> deltapts_invt;
01216   
01217   for(j=0;j<nDeltaSteps+1;j++)
01218   {
01219     delta = j*Deltaincrement*TMath::Pi() + DeltaLow;
01220     for(ie=0;ie<Extrap.size();ie++)
01221     {
01222       Extrap[ie]->SetDeltaCP(delta);
01223     }
01224     
01225     contourlvl = 2.71;
01226     
01227     best = 0;
01228     chi2prev = 0;
01229     prev = 0;
01230     for(i=0;i<nSinSq2Th13Steps+1;i++)
01231     {
01232       ss2th13 = i*Th13increment + SinSq2Th13Low;
01233       for(ie=0;ie<Extrap.size();ie++)
01234       {
01235         Extrap[ie]->SetSinSq2Th13(ss2th13);
01236         Extrap[ie]->OscillatePrediction();
01237       }
01238       
01239       Bkgd->Reset();
01240       Sig->Reset();
01241       
01242       for(ie=0;ie<Extrap.size();ie++)
01243       {
01244         Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
01245         Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
01246       }
01247       
01248       chi2 = ScaledChi2(Bkgd,Sig);
01249       
01250       if(chi2>contourlvl && chi2prev<contourlvl)
01251       {
01252         best = ss2th13 + ((ss2th13-prev)/(chi2 - chi2prev))*(contourlvl - chi2);
01253         limit90_norm.push_back(best);
01254         deltapts_norm.push_back(delta/TMath::Pi());
01255         cout<<chi2prev<<", "<<prev<<", "<<chi2<<", "<<ss2th13<<", "<<best<<endl;
01256         break;
01257       }
01258       chi2prev = chi2;
01259       prev = ss2th13;
01260     }
01261   }
01262   
01263   for(ie=0;ie<Extrap.size();ie++)
01264   {
01265     Extrap[ie]->InvertMassHierarchy();
01266   }
01267   
01268   for(j=0;j<nDeltaSteps+1;j++)
01269   {
01270     delta = j*Deltaincrement*TMath::Pi() + DeltaLow;
01271     for(ie=0;ie<Extrap.size();ie++)
01272     {
01273       Extrap[ie]->SetDeltaCP(delta);
01274     }
01275     
01276     contourlvl = 2.71;
01277     
01278     best = 0;
01279     chi2prev = 0;
01280     prev = 0;
01281     for(i=0;i<nSinSq2Th13Steps+1;i++)
01282     {
01283       ss2th13 = i*Th13increment + SinSq2Th13Low;
01284       for(ie=0;ie<Extrap.size();ie++)
01285       {
01286         Extrap[ie]->SetSinSq2Th13(ss2th13);
01287         Extrap[ie]->OscillatePrediction();
01288       }
01289       
01290       Bkgd->Reset();
01291       Sig->Reset();
01292       
01293       for(ie=0;ie<Extrap.size();ie++)
01294       {
01295         Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
01296         Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
01297       }
01298       
01299       chi2 = ScaledChi2(Bkgd,Sig);
01300       
01301       if(chi2>contourlvl && chi2prev<contourlvl)
01302       {
01303         best = ss2th13 + ((ss2th13-prev)/(chi2 - chi2prev))*(contourlvl - chi2);
01304         limit90_invt.push_back(best);
01305         deltapts_invt.push_back(delta/TMath::Pi());
01306         cout<<chi2prev<<", "<<prev<<", "<<chi2<<", "<<ss2th13<<", "<<best<<endl;
01307         break;
01308       }
01309       chi2prev = chi2;
01310       prev = ss2th13;
01311     }
01312   }
01313   
01314   if(limit90_norm.size()==0)
01315   {
01316     cout<<chi2<<endl;
01317     cout<<"Didn't find limit.  Quitting..."<<endl;
01318     return;
01319   }
01320   
01321   double *s_n = new double[nDeltaSteps+1];
01322   double *s_i = new double[nDeltaSteps+1];
01323   double *de_n = new double[nDeltaSteps+1];
01324   double *de_i = new double[nDeltaSteps+1];
01325   Int_t n_n,n_i;
01326   n_n = limit90_norm.size();
01327   n_i = limit90_invt.size();
01328   for(i=0;i<n_n;i++)
01329   {
01330     de_n[i] = deltapts_norm.at(i);
01331     s_n[i] = limit90_norm.at(i);
01332   }
01333   for(i=0;i<n_i;i++)
01334   {
01335     de_i[i] = deltapts_invt.at(i);
01336     s_i[i] = limit90_invt.at(i);
01337   }
01338   TGraph *gn = new TGraph(n_n,s_n,de_n);
01339   gn->SetMarkerStyle(20);
01340   gn->SetTitle("");
01341   gn->GetYaxis()->SetTitle("#delta");
01342   gn->GetXaxis()->SetTitle("sin^{2}2#theta_{13}");
01343   gn->GetXaxis()->SetLimits(0,0.6);
01344   gn->SetLineWidth(2);
01345   gn->SetLineColor(kBlue);
01346   gn->SetMarkerColor(kBlue);
01347   gn->SetMaximum(2);
01348   gn->SetName("Limit_Normal");
01349   TGraph *gi = new TGraph(n_i,s_i,de_i);
01350   gi->SetMarkerStyle(20);
01351   gi->SetTitle("");
01352   gi->GetYaxis()->SetTitle("#delta");
01353   gi->GetXaxis()->SetTitle("sin^{2}2#theta_{13}");
01354   gi->GetXaxis()->SetLimits(0,0.6);
01355   gi->SetLineWidth(2);
01356   gi->SetLineColor(kRed);
01357   gi->SetMarkerColor(kRed);
01358   gi->SetMaximum(2);
01359   gi->SetName("Limit_Inverted");
01360   
01361   cout<<"90% confidence level limit = "<<limit90_norm.at(0)<<", "<<limit90_invt.at(0)<<endl;
01362   
01363   TFile *fout = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"RECREATE");
01364   gn->Write();
01365   gi->Write();
01366   fout->Write();
01367   fout->Close();
01368   
01369   delete [] s_n;
01370   delete [] s_i;
01371   delete [] de_n;
01372   delete [] de_i;
01373   
01374   return;
01375 }

void NueFit2D::RunStandardChi2Sensitivity (  ) 

Definition at line 953 of file NueFit2D.cxx.

References Bkgd, delta, DeltaHigh, DeltaLow, ErrorMatrix, Extrap, gSystem(), InvErrorMatrix, nBins, nDeltaSteps, NExp, NObs, nSinSq2Th13Steps, outFileName, Sig, SinSq2Th13High, SinSq2Th13Low, and StandardChi2().

00954 {
00955   if(NObs==0)
00956   {
00957     cout<<"NObs not set.  Quitting..."<<endl;
00958     return;
00959   } 
00960   if(Extrap.size()==0)
00961   {
00962     cout<<"No Extrapolate2D input.  Quitting..."<<endl;
00963     return;
00964   }
00965   
00966   Bkgd = (TH1D*)NObs->Clone("Bkgd");
00967   Bkgd->Reset();
00968   Sig = (TH1D*)NObs->Clone("Sig");
00969   Sig->Reset();
00970   TH1D *NExp = (TH1D*)NObs->Clone("NExp");
00971   NExp->Reset();
00972   
00973   unsigned int ie;
00974   for(ie=0;ie<Extrap.size();ie++)
00975   {
00976     Extrap[ie]->GetPrediction();
00977   }
00978   
00979   if(ErrorMatrix==0) ErrorMatrix = new TH2D("ErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
00980   if(InvErrorMatrix==0) InvErrorMatrix = new TH2D("InvErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
00981   
00982   Int_t i,j;
00983   
00984   Double_t ss2th13 = 0;
00985   Double_t delta = 0;
00986   Double_t chi2 = 0,chi2prev = 0;
00987   Double_t contourlvl = 2.71;
00988   Double_t prev = 0;
00989   Double_t best = 0;
00990   Double_t Deltaincrement = 0;
00991   if(nDeltaSteps>0) Deltaincrement = (DeltaHigh - DeltaLow)/(nDeltaSteps);
00992   Double_t Th13increment = 0;
00993   if(nSinSq2Th13Steps>0) Th13increment = (SinSq2Th13High - SinSq2Th13Low)/(nSinSq2Th13Steps);
00994   
00995   vector<Double_t> limit90_norm;
00996   vector<Double_t> limit90_invt;
00997   vector<double> deltapts_norm;
00998   vector<double> deltapts_invt;
00999   
01000   for(j=0;j<nDeltaSteps+1;j++)
01001   {
01002     delta = j*Deltaincrement*TMath::Pi() + DeltaLow;
01003     for(ie=0;ie<Extrap.size();ie++)
01004     {
01005       Extrap[ie]->SetDeltaCP(delta);
01006     }
01007     
01008     contourlvl = 2.71;
01009     
01010     best = 0;
01011     chi2prev = 0;
01012     prev = 0;
01013     for(i=0;i<nSinSq2Th13Steps+1;i++)
01014     {
01015       ss2th13 = i*Th13increment + SinSq2Th13Low;
01016       for(ie=0;ie<Extrap.size();ie++)
01017       {
01018         Extrap[ie]->SetSinSq2Th13(ss2th13);
01019         Extrap[ie]->OscillatePrediction();
01020       }
01021       
01022       Bkgd->Reset();
01023       Sig->Reset();
01024       NExp->Reset();
01025       
01026       for(ie=0;ie<Extrap.size();ie++)
01027       {
01028         Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
01029         Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
01030       }
01031       NExp->Add(Bkgd);
01032       NExp->Add(Sig);
01033       
01034       chi2 = StandardChi2(NExp);
01035           
01036       if(chi2>contourlvl && chi2prev<contourlvl)
01037       {
01038         best = ss2th13 + ((ss2th13-prev)/(chi2 - chi2prev))*(contourlvl - chi2);
01039         limit90_norm.push_back(best);
01040         deltapts_norm.push_back(delta/TMath::Pi());
01041         cout<<chi2prev<<", "<<prev<<", "<<chi2<<", "<<ss2th13<<", "<<best<<endl;
01042         break;
01043       }
01044       chi2prev = chi2;
01045       prev = ss2th13;
01046     }
01047   }
01048   
01049   for(ie=0;ie<Extrap.size();ie++)
01050   {
01051     Extrap[ie]->InvertMassHierarchy();
01052   }
01053   
01054   for(j=0;j<nDeltaSteps+1;j++)
01055   {
01056     delta = j*Deltaincrement*TMath::Pi() + DeltaLow;
01057     for(ie=0;ie<Extrap.size();ie++)
01058     {
01059       Extrap[ie]->SetDeltaCP(delta);
01060     }
01061     
01062     contourlvl = 2.71;
01063     
01064     best = 0;
01065     chi2prev = 0;
01066     prev = 0;
01067     for(i=0;i<nSinSq2Th13Steps+1;i++)
01068     {
01069       ss2th13 = i*Th13increment + SinSq2Th13Low;
01070       for(ie=0;ie<Extrap.size();ie++)
01071       {
01072         Extrap[ie]->SetSinSq2Th13(ss2th13);
01073         Extrap[ie]->OscillatePrediction();
01074       }
01075       
01076       Bkgd->Reset();
01077       Sig->Reset();
01078       NExp->Reset();
01079       
01080       for(ie=0;ie<Extrap.size();ie++)
01081       {
01082         Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
01083         Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
01084       }
01085       NExp->Add(Bkgd);
01086       NExp->Add(Sig);
01087       
01088       chi2 = StandardChi2(NExp);
01089           
01090       if(chi2>contourlvl && chi2prev<contourlvl)
01091       {
01092         best = ss2th13 + ((ss2th13-prev)/(chi2 - chi2prev))*(contourlvl - chi2);
01093         limit90_invt.push_back(best);
01094         deltapts_invt.push_back(delta/TMath::Pi());
01095         cout<<chi2prev<<", "<<prev<<", "<<chi2<<", "<<ss2th13<<", "<<best<<endl;
01096         break;
01097       }
01098       chi2prev = chi2;
01099       prev = ss2th13;
01100     }
01101   }
01102   
01103   if(limit90_norm.size()==0)
01104   {
01105     cout<<chi2<<endl;
01106     cout<<"Didn't find limit.  Quitting..."<<endl;
01107     return;
01108   }
01109   
01110   double *s_n = new double[nDeltaSteps+1];
01111   double *s_i = new double[nDeltaSteps+1];
01112   double *de_n = new double[nDeltaSteps+1];
01113   double *de_i = new double[nDeltaSteps+1];
01114   Int_t n_n,n_i;
01115   n_n = limit90_norm.size();
01116   n_i = limit90_invt.size();
01117   for(i=0;i<n_n;i++)
01118   {
01119     de_n[i] = deltapts_norm.at(i);
01120     s_n[i] = limit90_norm.at(i);
01121   }
01122   for(i=0;i<n_i;i++)
01123   {
01124     de_i[i] = deltapts_invt.at(i);
01125     s_i[i] = limit90_invt.at(i);
01126   }
01127   TGraph *gn = new TGraph(n_n,s_n,de_n);
01128   gn->SetMarkerStyle(20);
01129   gn->SetTitle("");
01130   gn->GetYaxis()->SetTitle("#delta");
01131   gn->GetXaxis()->SetTitle("sin^{2}2#theta_{13}");
01132   gn->GetXaxis()->SetLimits(0,0.6);
01133   gn->SetLineWidth(2);
01134   gn->SetLineColor(kBlue);
01135   gn->SetMarkerColor(kBlue);
01136   gn->SetMaximum(2);
01137   gn->SetName("Limit_Normal");
01138   TGraph *gi = new TGraph(n_i,s_i,de_i);
01139   gi->SetMarkerStyle(20);
01140   gi->SetTitle("");
01141   gi->GetYaxis()->SetTitle("#delta");
01142   gi->GetXaxis()->SetTitle("sin^{2}2#theta_{13}");
01143   gi->GetXaxis()->SetLimits(0,0.6);
01144   gi->SetLineWidth(2);
01145   gi->SetLineColor(kRed);
01146   gi->SetMarkerColor(kRed);
01147   gi->SetMaximum(2);
01148   gi->SetName("Limit_Inverted");
01149   
01150   cout<<"90% confidence level limit = "<<limit90_norm.at(0)<<", "<<limit90_invt.at(0)<<endl;
01151   
01152   TFile *fout = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"RECREATE");
01153   gn->Write();
01154   gi->Write();
01155   fout->Write();
01156   fout->Close();
01157   
01158   delete [] s_n;
01159   delete [] s_i;
01160   delete [] de_n;
01161   delete [] de_i;
01162   
01163   return;
01164 }

void NueFit2D::RunSterileContour ( int  cl = 0  )  [virtual]

THIS FUNCTION IS OBSOLETE.

Definition at line 5484 of file NueFit2D.cxx.

References BinLikelihood(), Bkgd, DefineBinDlnLMinuit(), DefineStdDlnLMinuit(), delta, ErrorMatrix, Extrap, FitMethod, FracErr_Bkgd, FracErr_Sig, gSystem(), InvErrorMatrix, nBins, nDeltaSteps, NExp, NObs, nSinSq2Th14Steps, outFileName, PoissonChi2(), ScaledChi2(), Sig, SinSq2Th14High, SinSq2Th14Low, StandardChi2(), StandardLikelihood(), Theta14, and Theta24.

05485 {
05486   if(NObs==0)
05487   {
05488     cout<<"NObs not set.  Quitting..."<<endl;
05489     return;
05490   }
05491   if(FitMethod==1 && (FracErr_Bkgd==0 || FracErr_Sig==0))
05492   {
05493     cout<<"FracErr_Bkgd and FracErr_Sig need to be set for ScaledChi2.  Quitting..."<<endl;
05494     return;
05495   }
05496   if(Extrap.size()==0)
05497   {
05498     cout<<"No Extrapolate2D input.  Quitting..."<<endl;
05499     return;
05500   }
05501   
05502   if(FitMethod==3) DefineStdDlnLMinuit();
05503   if(FitMethod==4) DefineBinDlnLMinuit();
05504 
05505   Bkgd = (TH1D*)NObs->Clone("Bkgd");
05506   Bkgd->Reset();
05507   Sig = (TH1D*)NObs->Clone("Sig");
05508   Sig->Reset();
05509   NExp = (TH1D*)NObs->Clone("NExp");
05510   NExp->Reset();
05511   
05512 
05513   double sinsqth24 = TMath::Sin(Theta24)*TMath::Sin(Theta24);
05514   cout << Theta24 << " " << sinsqth24 << endl;  
05515 
05516   unsigned int ie;
05517   for(ie=0;ie<Extrap.size();ie++)
05518   {
05519     Extrap[ie]->GetPrediction();
05520   }
05521   
05522   if(ErrorMatrix==0) ErrorMatrix = new TH2D("ErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
05523   if(InvErrorMatrix==0) InvErrorMatrix = new TH2D("InvErrorMatrix","",nBins,-0.5,nBins-0.5,nBins,-0.5,nBins-0.5);
05524   
05525   Int_t i,j,dm;
05526   Double_t delta;  
05527   Double_t Theta14;
05528   Double_t bth14;
05529   Double_t dm4[37];
05530   for(dm=0;dm<9;dm++){
05531     dm4[dm]=.01+dm*.01;
05532   }
05533   for(dm=9;dm<18;dm++){
05534     dm4[dm]=.1+(dm-9)*.1;
05535   }
05536   for(dm=18;dm<27;dm++){
05537     dm4[dm]=1+(dm-18);
05538   }
05539   for(dm=27;dm<36;dm++){
05540     dm4[dm]=10+10*(dm-27);
05541   }
05542   dm4[36]=100;
05543 
05544   Double_t ss2th14 = 0;
05545   Double_t Th14increment = 0;
05546   if(nSinSq2Th14Steps>0) Th14increment = (SinSq2Th14High - SinSq2Th14Low)/(nSinSq2Th14Steps);
05547   
05548   double chi2[3],val[3];
05549   TGraph *g3;
05550   TF1* fit;
05551   double best;
05552   double minchi2;
05553   
05554   double limit;
05555   double delchi2;
05556   double sprev,delchi2prev;
05557   double contourlvl = 0;
05558   if(cl==0)//90% CL
05559   {
05560     contourlvl = 2.71;
05561   }
05562   else if(cl==1)//68.3% cL
05563   {
05564     contourlvl = 1.0;
05565   }
05566   else
05567   {
05568     cout<<"Error in RunDeltaChi2Contour(): Input value should be 0 or 1 for 90% or 68.3%.  Quitting..."<<endl;
05569     return;
05570   }
05571   
05572   cout<<"Seeking ";
05573   if(cl==0) cout<<"90% ";
05574   else cout<<"68% ";
05575   cout<<" CL upper limit"<<endl;
05576   
05577   vector<double> deltapts;
05578   vector<double> bestfit_norm;
05579   vector<double> bestfit_invt;
05580   vector<double> limit_norm;
05581   vector<double> limit_invt;
05582 
05583 
05584   for(j=0;j<19;j++)
05585   {
05586     delta = dm4[j];
05587     for(ie=0;ie<Extrap.size();ie++)
05588     {
05589       Extrap[ie]->SetDm41(delta);
05590 
05591     }
05592     deltapts.push_back(delta);
05593     
05594     best=-1.;
05595     minchi2=100;
05596     for(i=0;i<3;i++)
05597     {
05598       chi2[i]=-1.;
05599       val[i]=-1.;
05600     }
05601     for(i=0;i<nSinSq2Th14Steps+1;i++)
05602     {
05603       chi2[0] = chi2[1];
05604       chi2[1] = chi2[2];
05605       val[0] = val[1];
05606       val[1] = val[2];
05607       ss2th14 = i*Th14increment + SinSq2Th14Low;
05608       for(ie=0;ie<Extrap.size();ie++)
05609       {
05610         Theta14 = TMath::ASin(TMath::Sqrt(ss2th14))/2.0;
05611         //sinsqth24 = (TMath::Tan(Theta14))*(TMath::Tan(Theta14));
05612         Extrap[ie]->SetSinSq2Th14(ss2th14);
05613         Extrap[ie]->SetSinSqTh24(sinsqth24);
05614         Extrap[ie]->OscillatePrediction();
05615       }
05616       Bkgd->Reset();
05617       Sig->Reset();
05618       NExp->Reset();
05619       for(ie=0;ie<Extrap.size();ie++)
05620       {
05621         Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
05622         Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
05623       }
05624       NExp->Add(Bkgd);
05625       NExp->Add(Sig);
05626       
05627       chi2[2] = 1e10;
05628       if(FitMethod==0)
05629       {
05630         chi2[2] = PoissonChi2(NExp);
05631       }
05632       else if(FitMethod==1)
05633       {
05634         chi2[2] = ScaledChi2(Bkgd,Sig);
05635       }
05636       else if(FitMethod==2)
05637       {
05638         chi2[2] = StandardChi2(NExp);
05639       }
05640       else if(FitMethod==3)
05641       {
05642         //Likelihood: "Standard" (N syst, N nuisance)
05643         //Calculate the likelihood (x2 for chi)
05644         chi2[2] = StandardLikelihood();
05645       }
05646       else if(FitMethod==4)
05647       {
05648         //Likelihood: Bin by Bin Calculation of Systematics
05649         //Calculate the likelihood (x2 for chi)
05650         chi2[2] = BinLikelihood();
05651       }
05652       else
05653       {
05654         cout<<"Error in RunDeltaChi2Contour(): Unknown 'FitMethod'."<<endl;
05655       }
05656       
05657       val[2] = ss2th14;
05658       
05659       if(i<2) continue;
05660       
05661       if(i<3 && chi2[2]>chi2[1] && chi2[1]>chi2[0])//first three points are increasing, first point is minimum.
05662       {
05663         best = val[0];
05664         minchi2 = chi2[0];
05665         cout<<"minimum at 1st point: "<<minchi2<<" at "<<best<<endl;
05666         bth14 = TMath::ASin(TMath::Sqrt(best))/2.0;
05667         //sinsqth24 = (TMath::Tan(bth14))*(TMath::Tan(bth14));
05668         break;
05669       }
05670       
05671       if(chi2[2]>chi2[1] && chi2[0]>chi2[1])//found minimum
05672       {
05673         g3 = new TGraph(3, val, chi2);
05674         fit = new TF1("pol2", "pol2");
05675         g3->Fit(fit, "Q");//fit to second order polynominal
05676         if(fit->GetParameter(2) > 0)//if the x^2 term is nonzero
05677         {
05678           best = -fit->GetParameter(1)/(2*fit->GetParameter(2));//the location of the minimum is -p1/(2*p2)
05679           minchi2 = fit->GetParameter(0) + fit->GetParameter(1)*best + fit->GetParameter(2)*best*best;
05680           cout<<"minimum with fit: "<<minchi2<<" at "<<best<<endl;
05681         }
05682         else//if the x^2 term is zero, then just use the minimum you got by scanning
05683         {
05684           best = val[1];
05685           minchi2 = chi2[1];
05686           cout<<"minimum with scan: "<<minchi2<<" at "<<best<<endl;
05687         }
05688         bth14 = TMath::ASin(TMath::Sqrt(best))/2.0;
05689         //sinsqth24 = (TMath::Tan(bth14))*(TMath::Tan(bth14));
05690         break;
05691       }
05692     }
05693     cout << sinsqth24 << endl;
05694     bestfit_norm.push_back(best);
05695     
05696     limit = 10000.;
05697     delchi2prev = 1000;
05698     sprev = 0;
05699     for(i=0;i<nSinSq2Th14Steps+1;i++)
05700     {
05701       ss2th14 = i*Th14increment + SinSq2Th14Low;
05702       for(ie=0;ie<Extrap.size();ie++)
05703       {
05704         Theta14 = TMath::ASin(TMath::Sqrt(ss2th14))/2.0;
05705         //sinsqth24 = (TMath::Tan(Theta14))*(TMath::Tan(Theta14));
05706         Extrap[ie]->SetSinSq2Th14(ss2th14);
05707         Extrap[ie]->SetSinSqTh24(sinsqth24);
05708         Extrap[ie]->OscillatePrediction();
05709       }
05710       Bkgd->Reset();
05711       Sig->Reset();
05712       NExp->Reset();
05713       for(ie=0;ie<Extrap.size();ie++)
05714       {
05715         Bkgd->Add(Extrap[ie]->Pred_TotalBkgd_VsBinNumber);
05716         Sig->Add(Extrap[ie]->Pred_Signal_VsBinNumber);
05717       }
05718       NExp->Add(Bkgd);
05719       NExp->Add(Sig);
05720       
05721       delchi2 = 1e10;
05722       if(FitMethod==0)
05723       {
05724         delchi2 = PoissonChi2(NExp) - minchi2;
05725       }
05726       else if(FitMethod==1)
05727       {
05728         delchi2 = ScaledChi2(Bkgd,Sig) - minchi2;
05729       }
05730       else if(FitMethod==2)
05731       {
05732         delchi2 = StandardChi2(NExp) - minchi2;
05733       }
05734       else if(FitMethod==3)
05735       {
05736         //Likelihood: "Standard" (N syst, N nuisance)
05737         //Calculate the likelihood (x2 for chi)
05738         delchi2 = StandardLikelihood() - minchi2;
05739       }
05740       else if(FitMethod==4)
05741       {
05742         //Likelihood: Bin by Bin Calculation of Systematics
05743         //Calculate the likelihood (x2 for chi)
05744         delchi2 = BinLikelihood() - minchi2;
05745       }
05746       else
05747       {
05748         cout<<"Error in RunDeltaChi2Contour(): Unknown 'FitMethod'."<<endl;
05749       }
05750       
05751       if(i==1) continue;
05752       
05753       if(delchi2>contourlvl && delchi2prev<contourlvl)
05754       {
05755         limit = (ss2th14 + ((ss2th14-sprev)/(delchi2 - delchi2prev))*(contourlvl - delchi2));
05756         cout<<delchi2prev<<", "<<sprev<<", "<<delchi2<<", "<<ss2th14<<", "<<limit<<endl;
05757         bth14 = TMath::ASin(TMath::Sqrt(limit))/2.0;
05758         //sinsqth24 = (TMath::Tan(bth14))*(TMath::Tan(bth14));
05759         break;
05760       }
05761       delchi2prev = delchi2;
05762       sprev = ss2th14;
05763     }
05764     cout << sinsqth24 << endl;
05765     limit_norm.push_back(limit);
05766   }
05767   
05768   int nDeltaSteps=18;
05769   double *s_sinsqth24 = new double[nDeltaSteps+1];
05770   double *s_best_n = new double[nDeltaSteps+1];
05771   double *s_limit_n = new double[nDeltaSteps+1];
05772   double *s_LSND = new double[nDeltaSteps+1];
05773   double *d = new double[nDeltaSteps+1];
05774   for(i=0;i<nDeltaSteps+1;i++)
05775   {
05776     d[i] = deltapts.at(i);
05777     s_sinsqth24[i] = sinsqth24;
05778     s_best_n[i] = bestfit_norm.at(i);
05779     s_limit_n[i] = limit_norm.at(i);
05780     s_LSND[i] = sinsqth24*limit_norm.at(i);
05781 
05782   }
05783   
05784   TGraph *gn = new TGraph(nDeltaSteps+1,s_best_n,d);
05785   gn->SetMarkerStyle(20);
05786   gn->SetTitle("");
05787   gn->GetYaxis()->SetTitle("#Deltam^{2}_{41}");
05788   gn->GetYaxis()->SetRangeUser(0.01,1);
05789   gn->SetMinimum(0.01);
05790   gn->SetMaximum(1);
05791   gn->GetXaxis()->SetTitle("sin^{2}2#theta_{14}");
05792   gn->GetXaxis()->SetLimits(0,1);
05793   gn->SetLineWidth(4);
05794   gn->SetName("bfn");
05795 
05796   TGraph *gl = new TGraph(nDeltaSteps+1,s_LSND,d);
05797   gl->SetMarkerStyle(20);
05798   gl->SetTitle("");
05799   gl->GetYaxis()->SetTitle("#Deltam^{2}_{41}");
05800   gl->GetYaxis()->SetRangeUser(0.01,1);
05801   gl->SetMinimum(0.01);
05802   gl->SetMaximum(1);
05803   gl->GetXaxis()->SetTitle("sin^{2}#theta_{24}sin^{2}2#theta_{14}");
05804   gl->GetXaxis()->SetLimits(0,1);
05805   gl->SetLineWidth(4);
05806   gl->SetName("lsnd");
05807   
05808  
05809   TGraph *gi = new TGraph(nDeltaSteps+1,s_sinsqth24,d);
05810   gi->SetMarkerStyle(20);
05811   gi->SetTitle("");
05812   gi->GetYaxis()->SetTitle("#Deltam^{2}_{41}");
05813   gi->GetYaxis()->SetRangeUser(0.01,1);
05814   gi->SetMinimum(0.01);
05815   gi->SetMaximum(1);
05816   gi->GetXaxis()->SetTitle("sin^{2}#theta_{24}");
05817   gi->GetXaxis()->SetLimits(0,1);
05818   gi->SetLineWidth(4);
05819   gi->SetLineStyle(2);
05820   gi->SetName("sinsqth24");
05821  
05822 
05823   TGraph *gn_limit = new TGraph(nDeltaSteps+1,s_limit_n,d);
05824   gn_limit->SetMarkerStyle(20);
05825   gn_limit->SetTitle("");
05826   gn_limit->GetYaxis()->SetTitle("#Deltam^{2}_{41}");
05827   gn_limit->GetYaxis()->SetRangeUser(0.01,1);
05828   gn_limit->SetMinimum(0.01);
05829   gn_limit->SetMaximum(1);
05830   gn_limit->GetXaxis()->SetTitle("sin^{2}2#theta_{14}");
05831   gn_limit->GetXaxis()->SetLimits(0,1);
05832   gn_limit->SetLineWidth(4);
05833   gn_limit->SetLineColor(kBlue);
05834   gn_limit->SetMarkerColor(kBlue);
05835   gn_limit->SetName("lmn");
05836   
05837  
05838   if(cl==0) cout<<"90% ";
05839   if(cl==1) cout<<"68% ";
05840   cout<<"confidence level limit = "<<limit_norm.at(0)<< endl; //", "<<limit_invt.at(0)<<endl;
05841   
05842   TFile *fout = new TFile(gSystem->ExpandPathName(outFileName.c_str()),"RECREATE");
05843   gn->Write();
05844   gl->Write();
05845   gn_limit->Write();
05846   gi->Write();
05847   fout->Write();
05848   fout->Close();
05849   
05850   delete [] s_best_n;
05851   delete [] s_limit_n;
05852   delete [] s_sinsqth24;
05853   delete [] s_LSND;
05854   delete [] d;
05855   
05856   return;
05857 }

double NueFit2D::ScaledChi2 ( TH1D *  nexp_bkgd,
TH1D *  nexp_signal 
) [protected]

Definition at line 2795 of file NueFit2D.cxx.

References FracErr_Bkgd, FracErr_Sig, nBins, NObs, and Munits::ns.

Referenced by NueFit2D_Joint::DoDeltaFit(), NueFit2D_Joint::DoNSIFitForever(), NueFit2D_Joint::DoNSIFitQuick(), NueFit2D_Joint::GetLikelihood(), GetLikelihood(), GetMinLikelihood(), NueFit2D_Joint::GetMinLikelihood(), GetMinLikelihood_Delta(), NueFit2D_Joint::GetMinLikelihood_Delta(), NueFit2D_Joint::GetNSIFFX2(), NueFit2D_Joint::GetSensitivityAt(), GetSensitivityAt(), Run2DSterileSlice(), RunDataGrid(), NueFit2D_Joint::RunDataGrid(), RunDeltaChi2Contour(), NueFit2D_Joint::RunDeltaChi2Contour(), RunMultiBinFC(), RunMultiBinFC_MHDeltaFit(), NueFit2D_Joint::RunMultiBinFC_MHDeltaFit(), NueFit2D_Joint::RunMultiBinPseudoExpts(), RunMultiBinPseudoExpts(), NueFit2D_Joint::RunMultiBinPseudoExpts_MHDeltaFit(), RunMultiBinPseudoExpts_MHDeltaFit(), NueFit2D_Joint::RunNSIDeltaChi2Contour(), RunScaledChi2Sensitivity(), and RunSterileContour().

02796 {
02797   double chi2=0;
02798   double nb,ns,nobs,eb,es,nexp,errscale;
02799   
02800   for(unsigned int i=0;i<nBins;i++)
02801   {
02802     nb = nexp_bkgd->GetBinContent(i+1);
02803     ns = nexp_signal->GetBinContent(i+1);
02804     nexp = nb+ns;
02805     nobs = NObs->GetBinContent(i+1);
02806     eb = FracErr_Bkgd->GetBinContent(i+1);
02807     es = FracErr_Sig->GetBinContent(i+1);
02808     errscale = nexp/(eb*eb*nb*nb + es*es*ns*ns + nexp);
02809     if(nobs>0)
02810     {
02811       chi2 += (2*(nexp - nobs + nobs*TMath::Log(nobs/nexp))*errscale);
02812     }
02813     else if(nobs==0)
02814     {
02815       chi2 += (2*nexp*errscale);
02816     }
02817     //chi2 is undefined if nexp is 0
02818   }
02819   
02820   return chi2;
02821 }

void NueFit2D::SetDeltaRange ( double  l = 0,
double  h = 2 
)

Definition at line 851 of file NueFit2D.cxx.

References DeltaHigh, and DeltaLow.

Referenced by NueFit2D(), and NueFit2D_Joint::NueFit2D_Joint().

00852 {
00853   DeltaLow = l;
00854   DeltaHigh = h;
00855   
00856   return;
00857 }

void NueFit2D::SetepsetauRange ( double  l = -4.0,
double  h = 4.0 
)

Definition at line 933 of file NueFit2D.cxx.

References epsetauHigh, and epsetauLow.

Referenced by NueFit2D(), and NueFit2D_Joint::NueFit2D_Joint().

00934 {
00935   /* 
00936  if(l<0 || l>1)
00937   {
00938     cout<<"Unphysical value of Eps_etau.  Setting low value to 0."<<endl;
00939     l=0;
00940   }
00941   if(h<0 || h>1)
00942   {
00943     cout<<"Unphysical value of Eps_etau.  Setting high value to 1."<<endl;
00944     h=1;
00945   }
00946   */
00947   epsetauLow = l;
00948   epsetauHigh = h;
00949   
00950   return;
00951 }

void NueFit2D::SetFitMethod ( int  m = 0  )  [inline]

Definition at line 83 of file NueFit2D.h.

References FitMethod, and Munits::m.

Referenced by NueFit2D(), and NueFit2D_Joint::NueFit2D_Joint().

00083 { FitMethod = m; };//0 = poisson, 1 = scaled chi2, 2 = standard chi2, 3 = standard (nuisance param for each syst) likelihood, 4 = bin by bin likelihood

void NueFit2D::SetFracBkgdError ( TH1D *  n  ) 

Definition at line 107 of file NueFit2D.cxx.

References FracErr_Bkgd, and nBins.

00108 {
00109   FracErr_Bkgd = (TH1D*)n->Clone("FracErr_Bkgd");
00110   nBins = FracErr_Bkgd->GetNbinsX();
00111   return;
00112 }

void NueFit2D::SetFracError ( vector< TH1D * >  bkglist,
vector< TH1D * >  siglist 
)

Definition at line 420 of file NueFit2D.cxx.

References Form(), FracErr_Bkgd_List, and FracErr_Sig_List.

00420                                                                        {
00421   //Set the vectors of fractional errors for the "Standard" likelihood
00422 
00423   if (bkglist.size()==0){
00424     cout << "Forgot to add a Background systematic list!" << endl;
00425     cout << "->Nothing will be set."<< endl;
00426     return;
00427   }
00428 
00429   if (siglist.size()==0){
00430     cout << "Forgot to add a Signal systematic list!" << endl;
00431     cout << "->Nothing will be set."<< endl;
00432     return;
00433   }
00434 
00435   if (bkglist.size()!=siglist.size()){
00436     cout << "Signal and Background error lists are different sizes." << endl;
00437     cout << "->Nothing will be set."<< endl;
00438     return;
00439   }
00440 
00441   //Reset everything:
00442   FracErr_Bkgd_List.clear();
00443   FracErr_Sig_List.clear();
00444   
00445   for (unsigned int i=0; i < bkglist.size(); i++){
00446     
00447     FracErr_Bkgd_List.push_back((TH1D*)(bkglist[i]->Clone(Form("FracErr_Bkgd_%i",i))));
00448     FracErr_Sig_List.push_back((TH1D*)(siglist[i]->Clone(Form("FracErr_Sig_%i",i))));
00449 
00450   }
00451   
00452 }

void NueFit2D::SetFracSigError ( TH1D *  n  ) 

Definition at line 113 of file NueFit2D.cxx.

References FracErr_Sig, and nBins.

00114 {
00115   FracErr_Sig = (TH1D*)n->Clone("FracErr_Sig");
00116   nBins = FracErr_Sig->GetNbinsX();
00117   return;
00118 }

void NueFit2D::SetGridFiles ( string  snorm = "Grid_1stAna_Norm.root",
string  sinvt = "Grid_1stAna_Invt.root" 
)

Definition at line 132 of file NueFit2D.cxx.

References GridFileName_Inverted, and GridFileName_Normal.

00133 {
00134   GridFileName_Normal = snorm;
00135   GridFileName_Inverted = sinvt;
00136   return;
00137 }

void NueFit2D::SetGridNorm ( double  n = 0  )  [inline]

Definition at line 66 of file NueFit2D.h.

References GridNorm, and n.

Referenced by NueFit2D(), and NueFit2D_Joint::NueFit2D_Joint().

00066 { GridNorm = n; };//in case you want a different normalization than the grid files were made with

void NueFit2D::SetIncludeOscParErrs (  )  [inline]

Definition at line 60 of file NueFit2D.h.

References IncludeOscParErrs.

00060 { IncludeOscParErrs = true; };

void NueFit2D::SetNDeltaSteps ( int  n = 20  )  [inline]

Definition at line 68 of file NueFit2D.h.

References n, and nDeltaSteps.

Referenced by NueFit2D(), and NueFit2D_Joint::NueFit2D_Joint().

00068 { nDeltaSteps = n; };

void NueFit2D::SetNepsetauSteps ( int  n = 3000  )  [inline]

Definition at line 80 of file NueFit2D.h.

References n, and nepsetauSteps.

Referenced by NueFit2D(), and NueFit2D_Joint::NueFit2D_Joint().

00080 { nepsetauSteps = n; };

void NueFit2D::SetNExperiments ( int  n = 2000  )  [inline]

Definition at line 62 of file NueFit2D.h.

References n, and NumExpts.

Referenced by NueFit2D(), and NueFit2D_Joint::NueFit2D_Joint().

00062 { NumExpts = n; };

void NueFit2D::SetNObs ( TH1D *  n  ) 

Definition at line 101 of file NueFit2D.cxx.

References nBins, and NObs.

00102 {
00103   NObs = (TH1D*)n->Clone("NObs");
00104   nBins = NObs->GetNbinsX();
00105   return;
00106 }

void NueFit2D::SetNSinSq2Th13Steps ( int  n = 3000  )  [inline]

Definition at line 69 of file NueFit2D.h.

References n, and nSinSq2Th13Steps.

Referenced by NueFit2D(), and NueFit2D_Joint::NueFit2D_Joint().

00069 { nSinSq2Th13Steps = n; };

void NueFit2D::SetNSinSq2Th14Steps ( int  n = 3000  )  [inline]

Definition at line 70 of file NueFit2D.h.

References n, and nSinSq2Th14Steps.

Referenced by NueFit2D().

00070 { nSinSq2Th14Steps = n; };

void NueFit2D::SetNSinSqTh14Steps ( int  n = 100  )  [inline]

Definition at line 75 of file NueFit2D.h.

References n, and nSinSqTh14Steps.

Referenced by NueFit2D().

00075 { nSinSqTh14Steps = n; };

void NueFit2D::SetNSinSqTh24Steps ( int  n = 100  )  [inline]

Definition at line 76 of file NueFit2D.h.

References n, and nSinSqTh24Steps.

Referenced by NueFit2D().

00076 { nSinSqTh24Steps = n; };

void NueFit2D::SetOutputFile ( string  s = "SensOut.root"  ) 

Definition at line 127 of file NueFit2D.cxx.

References outFileName.

Referenced by NueFit2D(), and NueFit2D_Joint::NueFit2D_Joint().

00128 {
00129   outFileName = s;
00130   return;
00131 }

void NueFit2D::SetPseudoExperimentInputFile ( string  s = "PseudoExp.root"  )  [inline]

Definition at line 64 of file NueFit2D.h.

References PseudoExpFile.

00064 { PseudoExpFile = s; };

void NueFit2D::SetSinSq2Th13Range ( double  l = 0.05,
double  h = 0.35 
)

Definition at line 858 of file NueFit2D.cxx.

References SinSq2Th13High, and SinSq2Th13Low.

Referenced by NueFit2D(), and NueFit2D_Joint::NueFit2D_Joint().

00859 {
00860   if(l<0 || l>1)
00861   {
00862     cout<<"Unphysical value of SinSq2Th13.  Setting low value to 0."<<endl;
00863     l=0;
00864   }
00865   if(h<0 || h>1)
00866   {
00867     cout<<"Unphysical value of SinSq2Th13.  Setting high value to 1."<<endl;
00868     h=1;
00869   }
00870   
00871   SinSq2Th13Low = l;
00872   SinSq2Th13High = h;
00873   
00874   return;
00875 }

void NueFit2D::SetSinSq2Th14Range ( double  l = 0.001,
double  h = 0.301 
)

Definition at line 876 of file NueFit2D.cxx.

References SinSq2Th14High, and SinSq2Th14Low.

Referenced by NueFit2D().

00877 {
00878   if(l<0 || l>1)
00879   {
00880     cout<<"Unphysical value of SinSq2Th14.  Setting low value to 0."<<endl;
00881     l=0;
00882   }
00883   if(h<0 || h>1)
00884   {
00885     cout<<"Unphysical value of SinSq2Th14.  Setting high value to 1."<<endl;
00886     h=1;
00887   }
00888   
00889   SinSq2Th14Low = l;
00890   SinSq2Th14High = h;
00891   
00892   return;
00893 }

void NueFit2D::SetSinSqTh14Range ( double  l = 0.0,
double  h = 1.0 
)

Definition at line 895 of file NueFit2D.cxx.

References SinSqTh14High, and SinSqTh14Low.

Referenced by NueFit2D().

00896 {
00897   if(l<0 || l>1)
00898   {
00899     cout<<"Unphysical value of SinSqTh14.  Setting low value to 0."<<endl;
00900     l=0;
00901   }
00902   if(h<0 || h>1)
00903   {
00904     cout<<"Unphysical value of SinSqTh14.  Setting high value to 1."<<endl;
00905     h=1;
00906   }
00907   
00908   SinSqTh14Low = l;
00909   SinSqTh14High = h;
00910   
00911   return;
00912 }

void NueFit2D::SetSinSqTh24Range ( double  l = 0.0,
double  h = 1.0 
)

Definition at line 914 of file NueFit2D.cxx.

References SinSqTh24High, and SinSqTh24Low.

Referenced by NueFit2D().

00915 {
00916   if(l<0 || l>1)
00917   {
00918     cout<<"Unphysical value of SinSqTh24.  Setting low value to 0."<<endl;
00919     l=0;
00920   }
00921   if(h<0 || h>1)
00922   {
00923     cout<<"Unphysical value of SinSqTh24.  Setting high value to 1."<<endl;
00924     h=1;
00925   }
00926   
00927   SinSqTh24Low = l;
00928   SinSqTh24High = h;
00929   
00930   return;
00931 }

void NueFit2D::SetSystErrorMatrix ( TH2D *  n  ) 

Definition at line 120 of file NueFit2D.cxx.

References ExternalErrorMatrix, and nBins.

00121 {
00122   ExternalErrorMatrix = (TH2D*)n->Clone("ExternalErrorMatrix");
00123   nBins = ExternalErrorMatrix->GetNbinsX();
00124   
00125   return;
00126 }

void NueFit2D::SetupChi2Hists (  )  [protected]
double NueFit2D::StandardChi2 ( TH1D *  nexp  )  [protected]
double NueFit2D::StandardLikelihood (  )  [protected]

Definition at line 522 of file NueFit2D.cxx.

References DoStdMinParam(), FracErr_Bkgd_List, minuit, and StdLikeComparison().

Referenced by NueFit2D_Joint::DoDeltaFit(), NueFit2D_Joint::DoNSIFitForever(), NueFit2D_Joint::DoNSIFitQuick(), NueFit2D_Joint::GetLikelihood(), GetLikelihood(), GetMinLikelihood(), NueFit2D_Joint::GetMinLikelihood(), GetMinLikelihood_Delta(), NueFit2D_Joint::GetMinLikelihood_Delta(), NueFit2D_Joint::GetNSIFFX2(), NueFit2D_Joint::GetSensitivityAt(), GetSensitivityAt(), Run2DSterileSlice(), RunDataGrid(), NueFit2D_Joint::RunDataGrid(), RunDeltaChi2Contour(), NueFit2D_Joint::RunDeltaChi2Contour(), RunMultiBinFC(), RunMultiBinFC_MHDeltaFit(), NueFit2D_Joint::RunMultiBinFC_MHDeltaFit(), NueFit2D_Joint::RunMultiBinPseudoExpts(), RunMultiBinPseudoExpts(), NueFit2D_Joint::RunMultiBinPseudoExpts_MHDeltaFit(), RunMultiBinPseudoExpts_MHDeltaFit(), NueFit2D_Joint::RunNSIDeltaChi2Contour(), and RunSterileContour().

00523 {
00524 
00525   //HOO Matrix does not converge.  Don't use me for now.
00526 
00527   //Define the HOO matrix
00528   //if (ErrCalc!=0){
00529 
00530     //Calculate the decomposition systematic covariance matrix
00531     //ErrCalc->CalculateHOOError();
00532 
00533     //Invert HOO matrix and put it in inverror
00534     //CalculateDlnLMatrix(0,ErrCalc->CovMatrix_Decomp);
00535 
00536   //}
00537 
00538   //Call the likelihood equation either with or without systematics.
00539   
00540   double dlnl=1.0e10;
00541   
00542   //empty vector
00543   vector<double> npar;
00544 
00545   unsigned int sys_size = FracErr_Bkgd_List.size();
00546 
00547   //If we are using systematics, do a minimization
00548   if (sys_size>0){
00549 
00550     dlnl = DoStdMinParam();
00551 
00552     //Check if the fit converged.
00553     Double_t fmin,fedm,errdef;
00554     Int_t npari,nparx,istat;
00555     minuit->mnstat(fmin,fedm,errdef,npari,nparx,istat);
00556     if(istat!=3&&fedm>0.01)
00557       {
00558         cout << "Fit failed with status "<< istat << endl;
00559         cout << "---> FMIN=" << fmin << " FEDM=" << fedm
00560              << " ERRDEF=" << errdef << " NPARI=" << npari
00561              << " NPARX=" << nparx << endl;
00562       }
00563 
00564   } else {
00565     //This will bypass the minimization and systematics.
00566     dlnl = StdLikeComparison(npar);
00567   }
00568   return dlnl;
00569   
00570 }

double NueFit2D::StdLikeComparison ( vector< double >  npar  ) 

Definition at line 572 of file NueFit2D.cxx.

References Bkgd, FracErr_Bkgd_List, FracErr_Sig_List, nBins, NObs, and Sig.

Referenced by dlnlFunction(), and StandardLikelihood().

00572                                                      {
00573 
00574   //Actual likelihood comparison happens here.  This gets minimized.
00575 
00576   float dlnl=0.0;
00577   double temp=0.0;
00578   
00579   double sig=0.0;
00580   double bkg=0.0;
00581   double nobs=0.0;
00582   double nexp=0.0;
00583   double sigma_bkg=0.0;
00584   double sigma_sig=0.0;
00585 
00586   //unsigned int size_syst = npar.size();
00587 
00588   //Check there is one nuisance parameter per systematic:
00589   //(The "+nBins" is for the HOO background)
00590   //if (size_syst>0&&size_syst!=FracErr_Bkgd_List.size()+nBins){
00591   //  cout << "Error: different number of systematics and nuisance parameters!"
00592   //  << endl;
00593   //  return 1.0e10;
00594   // }
00595   
00596 
00597   for(unsigned int i=0;i<nBins;i++)
00598   {
00599     //Signal and background predictions:
00600     sig = Sig->GetBinContent(i+1);
00601     bkg = Bkgd->GetBinContent(i+1);
00602 
00603     //Loop through systematics and add contributions
00604     for (unsigned int j=0; j<FracErr_Bkgd_List.size();j++){
00605 
00606       //Get the nuisance parameter:
00607         double f = npar.at(j);
00608 
00609         //Total shift on background:
00610         sigma_bkg = FracErr_Bkgd_List[j]->GetBinContent(i+1);
00611         bkg += f*sigma_bkg*bkg;
00612 
00613         //Total shift on signal:
00614         sigma_sig = FracErr_Sig_List[j]->GetBinContent(i+1);
00615         sig += f*sigma_sig*sig;
00616 
00617     }
00618 
00619     //RBT: this is disabled for now:
00620     //if (InvErrorMatrix!=0){
00621     //  //RBT: Add a shift due to HOO error in this bin.
00622     //  unsigned int par_hoo = FracErr_Bkgd_List.size() + i;     
00623     //  double g = npar.at(par_hoo);
00624     //  bkg += g;
00625     //}
00626 
00627     //"Data" distribution:
00628     nobs = NObs->GetBinContent(i+1);
00629 
00630     //Expected distribution (with appropriate nuisance shifts)
00631     nexp = sig + bkg;
00632     temp=0;
00633 
00634     //Likelihood comparison:
00635     if (nobs>0&&nexp>0) {
00636     //Regular (both distributions positive):
00637       temp = nexp - nobs + nobs*TMath::Log(nobs) - nobs*TMath::Log(nexp);
00638     } else if (nobs==0&&nexp>0){
00639       //No data was seen in this bin:
00640       temp = nexp;
00641     } else if (nexp==0&&nobs==0){
00642       //Nothing was seen, nothing expected:
00643       temp = 0;
00644     } else {
00645       //Something weird happened:
00646       return 1.0e10;
00647     }
00648 
00649     //Turn it into a chi2:
00650     dlnl  += 2.0*temp;
00651 
00652   }
00653 
00654   //Add penalty term for nuisance parameters:
00655   for (unsigned int j=0; j<FracErr_Bkgd_List.size();j++){
00656     dlnl += npar.at(j)*npar.at(j);
00657   }
00658 
00659   //HOO gets a covariance term as well:
00660 
00661   //if (InvErrorMatrix!=0){
00662   //  for (unsigned int i=FracErr_Bkgd_List.size(); i<FracErr_Bkgd_List.size()+nBins;i++){
00663   //    for (unsigned int j=FracErr_Bkgd_List.size(); j<FracErr_Bkgd_List.size()+nBins;j++){
00664   //    //This needs to be defined.  Will be zero for now!
00665   //    dlnl += npar.at(i)*InvErrorMatrix->GetBinContent(i+1,j+1)*npar.at(j);
00666   //    }
00667   //  }
00668   //}
00669 
00670   //Return the log likelihood:
00671   return dlnl;
00672 
00673 }


Member Data Documentation

TH1D* NueFit2D::Bkgd [protected]
TH2D* NueFit2D::Chi2_Inverted [protected]

Definition at line 254 of file NueFit2D.h.

Referenced by RunFCAnalytical(), RunFCTraditional(), RunMultiBinFC(), and SetupChi2Hists().

TH2D* NueFit2D::Chi2_Normal [protected]

Definition at line 253 of file NueFit2D.h.

Referenced by RunFCAnalytical(), RunFCTraditional(), RunMultiBinFC(), and SetupChi2Hists().

Double_t NueFit2D::delta

Definition at line 116 of file NueFit2D.h.

Referenced by NueFit2D_Joint::NueFit2D_Joint().

Definition at line 117 of file NueFit2D.h.

Referenced by DefDelta_etau(), and NueFit2D_Joint::NueFit2D_Joint().

Definition at line 118 of file NueFit2D.h.

Referenced by DefDelta_etau(), and NueFit2D_Joint::NueFit2D_Joint().

Definition at line 119 of file NueFit2D.h.

Referenced by NueFit2D_Joint::NueFit2D_Joint().

double NueFit2D::DeltaHigh [protected]
double NueFit2D::DeltaHigh_Chi2Hist [protected]

Definition at line 287 of file NueFit2D.h.

Referenced by FormatChi2Hists(), and SetupChi2Hists().

double NueFit2D::DeltaLow [protected]
double NueFit2D::DeltaLow_Chi2Hist [protected]

Definition at line 287 of file NueFit2D.h.

Referenced by FormatChi2Hists(), and SetupChi2Hists().

Definition at line 106 of file NueFit2D.h.

Referenced by DefDMS21(), and NueFit2D_Joint::NueFit2D_Joint().

Definition at line 123 of file NueFit2D.h.

Referenced by DefDMS41().

Definition at line 109 of file NueFit2D.h.

Referenced by DefEps_ee(), and NueFit2D_Joint::NueFit2D_Joint().

Definition at line 110 of file NueFit2D.h.

Referenced by DefEps_emu(), and NueFit2D_Joint::NueFit2D_Joint().

Definition at line 111 of file NueFit2D.h.

Referenced by DefEps_etau(), and NueFit2D_Joint::NueFit2D_Joint().

Definition at line 112 of file NueFit2D.h.

Referenced by DefEps_etau(), and NueFit2D_Joint::NueFit2D_Joint().

Definition at line 113 of file NueFit2D.h.

Referenced by NueFit2D_Joint::NueFit2D_Joint().

Definition at line 114 of file NueFit2D.h.

Referenced by NueFit2D_Joint::NueFit2D_Joint().

Definition at line 115 of file NueFit2D.h.

Referenced by NueFit2D_Joint::NueFit2D_Joint().

double NueFit2D::epsetauHigh [protected]
double NueFit2D::epsetauLow [protected]
TH2D* NueFit2D::ErrorMatrix [protected]
TH2D* NueFit2D::ExternalErrorMatrix [protected]
int NueFit2D::FitMethod [protected]
TH1D* NueFit2D::FracErr_Bkgd [protected]
std::vector<TH1D*> NueFit2D::FracErr_Bkgd_List [protected]
TH1D* NueFit2D::FracErr_Sig [protected]
std::vector<TH1D*> NueFit2D::FracErr_Sig_List [protected]

Definition at line 214 of file NueFit2D.h.

Referenced by SetFracError(), and StdLikeComparison().

double NueFit2D::grid_background [protected]
vector<double> NueFit2D::grid_bin_oscparerr [protected]
double NueFit2D::grid_bnuecc [protected]
double NueFit2D::grid_delta [protected]
double NueFit2D::grid_i_dm2_21 [protected]
double NueFit2D::grid_i_dm2_32 [protected]
double NueFit2D::grid_i_th12 [protected]
double NueFit2D::grid_i_th13 [protected]
double NueFit2D::grid_i_th23 [protected]
double NueFit2D::grid_n_dm2_21 [protected]
double NueFit2D::grid_n_dm2_32 [protected]
double NueFit2D::grid_n_th12 [protected]
double NueFit2D::grid_n_th13 [protected]
double NueFit2D::grid_n_th23 [protected]
double NueFit2D::grid_nc [protected]
double NueFit2D::grid_nue [protected]
double NueFit2D::grid_numucc [protected]
double NueFit2D::grid_nutaucc [protected]
double NueFit2D::grid_oscparerr [protected]

Definition at line 265 of file NueFit2D.h.

Referenced by RunPseudoExperiments().

double NueFit2D::grid_signal [protected]
double NueFit2D::grid_sinsq2th13 [protected]
string NueFit2D::GridFileName_Inverted [protected]

Definition at line 257 of file NueFit2D.h.

Referenced by ReadGridFiles(), NueFit2D_Joint::ReadGridFiles(), and SetGridFiles().

string NueFit2D::GridFileName_Normal [protected]

Definition at line 256 of file NueFit2D.h.

Referenced by ReadGridFiles(), NueFit2D_Joint::ReadGridFiles(), and SetGridFiles().

double NueFit2D::GridNorm [protected]

Definition at line 278 of file NueFit2D.h.

Referenced by ReadGridFiles(), NueFit2D_Joint::ReadGridFiles(), and SetGridNorm().

double NueFit2D::GridScale_Inverted [protected]
double NueFit2D::GridScale_Normal [protected]
vector< vector<TTree*> > NueFit2D::GridTree_2_Normal [protected]
vector<TTree*> NueFit2D::GridTree_Inverted [protected]
vector<TTree*> NueFit2D::GridTree_Normal [protected]
bool NueFit2D::IncludeOscParErrs [protected]
TH2D* NueFit2D::InvErrorMatrix [protected]
int NueFit2D::LIH [protected]

Definition at line 305 of file NueFit2D.h.

Referenced by LetsIH(), and Run2DSterileSlice().

TMinuit* NueFit2D::minuit [protected]
unsigned int NueFit2D::nBins [protected]

Definition at line 251 of file NueFit2D.h.

Referenced by BinLikeComparison(), CalculateDlnLMatrix(), NueFit2D_Joint::CalculateDlnLMatrix(), CalculateErrorMatrixInv(), DefineBinDlnLMinuit(), NueFit2D_Joint::DefineBinDlnLMinuit(), NueFit2D_Joint::DefineStdDlnLMinuit(), DefineStdDlnLMinuit(), DoBinMinParam(), NueFit2D_Joint::DoDeltaFit(), NueFit2D_Joint::DoNSIFitForever(), NueFit2D_Joint::DoNSIFitQuick(), DoStdMinParam(), GenerateOneCorrelatedExp(), GenerateOneExperiment(), NueFit2D_Joint::GetLikelihood(), GetLikelihood(), GetMinLikelihood(), NueFit2D_Joint::GetMinLikelihood(), GetMinLikelihood_Delta(), NueFit2D_Joint::GetMinLikelihood_Delta(), NueFit2D_Joint::GetNSIFFX2(), NueFit2D_Joint::GetSensitivityAt(), GetSensitivityAt(), NueFit2D(), NueFit2D_Joint::NueFit2D_Joint(), PoissonChi2(), ReadGridFiles(), NueFit2D_Joint::ReadGridFiles(), Run2DSterileSlice(), RunDataGrid(), NueFit2D_Joint::RunDataGrid(), RunDeltaChi2Contour(), NueFit2D_Joint::RunDeltaChi2Contour(), RunFCAnalytical(), RunFCTraditional(), RunMultiBinFC(), RunMultiBinFC_MHDeltaFit(), NueFit2D_Joint::RunMultiBinFC_MHDeltaFit(), NueFit2D_Joint::RunMultiBinPseudoExpts(), RunMultiBinPseudoExpts(), RunMultiBinPseudoExpts_MHDeltaFit(), NueFit2D_Joint::RunMultiBinPseudoExpts_MHDeltaFit(), NueFit2D_Joint::RunNSIDeltaChi2Contour(), RunPseudoExperiments(), RunStandardChi2Sensitivity(), RunSterileContour(), ScaledChi2(), SetFracBkgdError(), SetFracSigError(), SetNObs(), SetSystErrorMatrix(), StandardChi2(), and StdLikeComparison().

int NueFit2D::nDelta_Chi2Hist [protected]

Definition at line 285 of file NueFit2D.h.

Referenced by FormatChi2Hists(), and SetupChi2Hists().

int NueFit2D::nDeltaSteps [protected]
int NueFit2D::nepsetauSteps [protected]
TH1D* NueFit2D::NExp [protected]
TH1D* NueFit2D::NObs [protected]
int NueFit2D::nPts_Inverted [protected]
int NueFit2D::nPts_Normal [protected]

Definition at line 284 of file NueFit2D.h.

Referenced by FormatChi2Hists(), and SetupChi2Hists().

int NueFit2D::nSinSq2Th13Steps [protected]
int NueFit2D::nSinSq2Th14Steps [protected]

Definition at line 291 of file NueFit2D.h.

Referenced by RunSterileContour(), and SetNSinSq2Th14Steps().

int NueFit2D::nSinSqTh14Steps [protected]

Definition at line 292 of file NueFit2D.h.

Referenced by Run2DSterileSlice(), and SetNSinSqTh14Steps().

int NueFit2D::nSinSqTh24Steps [protected]

Definition at line 293 of file NueFit2D.h.

Referenced by Run2DSterileSlice(), and SetNSinSqTh24Steps().

int NueFit2D::NumExpts [protected]
string NueFit2D::outFileName [protected]
TTree * NueFit2D::paramtree_Inverted [protected]

Definition at line 263 of file NueFit2D.h.

Referenced by ReadGridFiles(), and NueFit2D_Joint::ReadGridFiles().

TTree* NueFit2D::paramtree_Normal [protected]

Definition at line 263 of file NueFit2D.h.

Referenced by ReadGridFiles(), and NueFit2D_Joint::ReadGridFiles().

string NueFit2D::PseudoExpFile [protected]
TH1D* NueFit2D::Sig [protected]
double NueFit2D::SinSq2Th13High [protected]

Definition at line 286 of file NueFit2D.h.

Referenced by FormatChi2Hists(), and SetupChi2Hists().

double NueFit2D::SinSq2Th13Low [protected]

Definition at line 286 of file NueFit2D.h.

Referenced by FormatChi2Hists(), and SetupChi2Hists().

double NueFit2D::SinSq2Th14High [protected]

Definition at line 296 of file NueFit2D.h.

Referenced by RunSterileContour(), and SetSinSq2Th14Range().

double NueFit2D::SinSq2Th14Low [protected]

Definition at line 296 of file NueFit2D.h.

Referenced by RunSterileContour(), and SetSinSq2Th14Range().

double NueFit2D::SinSqTh14High [protected]

Definition at line 297 of file NueFit2D.h.

Referenced by Run2DSterileSlice(), and SetSinSqTh14Range().

double NueFit2D::SinSqTh14Low [protected]

Definition at line 297 of file NueFit2D.h.

Referenced by Run2DSterileSlice(), and SetSinSqTh14Range().

double NueFit2D::SinSqTh24High [protected]

Definition at line 298 of file NueFit2D.h.

Referenced by Run2DSterileSlice(), and SetSinSqTh24Range().

double NueFit2D::SinSqTh24Low [protected]

Definition at line 298 of file NueFit2D.h.

Referenced by Run2DSterileSlice(), and SetSinSqTh24Range().

Definition at line 98 of file NueFit2D.h.

Referenced by DefTheta12(), and NueFit2D_Joint::NueFit2D_Joint().

Definition at line 122 of file NueFit2D.h.

Referenced by DefTheta14(), Run2DSterileSlice(), and RunSterileContour().

Definition at line 121 of file NueFit2D.h.

Referenced by DefTheta24(), and RunSterileContour().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1