コード例 #1
0
ファイル: higgs_plots.cpp プロジェクト: manuelfs/babar_code
double HiggsPlot::ProbChi2(int iDecay, double tBmH, double RD[2], double RDs[2]){
  double chi2;
  double valMeas[3][2] = {{Measurement[0][0], Measurement[1][0]},
			  {MeasuredRD[0]->Eval(tBmH), MeasuredRD[2]->Eval(tBmH)},
			  {MeasuredRD[1]->Eval(tBmH), MeasuredRD[3]->Eval(tBmH)}};
  int ndof=1;
  if(iDecay<3) {
    chi2 = Chi2(RD,valMeas[iDecay]);
  } else {
    TMatrixT<double> CovM(2,2), DiffRD(1,2), MDiff(1,2); //CovM is the covariance matrix
    if(_varyRD){
      CovM(0,0) = pow(RD[1],2) +pow(valMeas[1][1],2);
      CovM(1,1) = pow(RDs[1],2)+pow(valMeas[2][1],2);
      CovM(1,0) = Measurement[3][0]*valMeas[1][1]*valMeas[2][1];
      DiffRD(0,0) = valMeas[1][0]-RD[0]; DiffRD(0,1) = valMeas[2][0]-RDs[0];
    } else {
      CovM(0,0) = pow(RD[1],2) +pow(Measurement[1][1],2);
      CovM(1,1) = pow(RDs[1],2)+pow(Measurement[2][1],2);
      CovM(1,0) = Measurement[3][0]*Measurement[1][1]*Measurement[2][1];
      DiffRD(0,0) = Measurement[1][0]-RD[0]; DiffRD(0,1) = Measurement[2][0]-RDs[0];
    }
    CovM(0,1) = CovM(1,0);
    CovM.Invert();
    MDiff.Mult(DiffRD,CovM);
    chi2 = MDiff(0,0)*DiffRD(0,0) + MDiff(0,1)*DiffRD(0,1);
    ndof++;
    if(tBmH==0 && _varyRD) 
      cout<<endl<<"SM chi2 is "<<RoundNumber(chi2,2)<<" with a p-value of "<<TMath::Prob(chi2,ndof)<<". This is "
	  <<RoundNumber(sqrt(2)*TMath::ErfInverse(1 - TMath::Prob(chi2,ndof)),2)<<" sigma away"<<endl<<endl;
  }

  return 1 - TMath::Prob(chi2,ndof);
}
コード例 #2
0
double Verosimilitud::LLH(std::vector<double> param)
{

  	dlib::matrix<double,0,1> nuisance(4);
  	
  	nuisance(0)=(param)[0];
  	nuisance(1)=(param)[1];
  	nuisance(2)=(param)[2];
  	nuisance(3)=(param)[3];

	return Chi2(nuisance);
}
コード例 #3
0
ファイル: higgs_plots.cpp プロジェクト: manuelfs/babar_code
double HiggsPlot::ProbChi2(int iDecay, double tBmH, double rL){
  double RD[2], RDs[2], chi2;
  double valMeas[3][2] = {{Measurement[0][0], Measurement[1][0]},
			  {MeasuredRD[0]->Eval(tBmH), MeasuredRD[2]->Eval(tBmH)},
			  {MeasuredRD[1]->Eval(tBmH), MeasuredRD[3]->Eval(tBmH)}};
  int ndof=1;
  if(iDecay<3) {
    Compute(tBmH,RD,iDecay);
    chi2 = Chi2(RD,valMeas[iDecay]);
  } else {
    if(iDecay==3) {Compute(tBmH,RD,1); Compute(tBmH,RDs,2);}
    else {
      double mb = 4.2, rRrL = tBmH + rL, tBmH_Eff = sqrt(fabs(rRrL/(mTau*mb))); 
      if(rRrL > 0) RDCoef[0][0][1] = fabs(RDCoef[0][0][1]);
      Compute(tBmH_Eff,RD,1);
      valMeas[1][0] = MeasuredRD[0]->Eval(tBmH_Eff);
      valMeas[1][1] = MeasuredRD[2]->Eval(tBmH_Eff);
      rRrL = tBmH - rL; tBmH_Eff = sqrt(fabs(rRrL/(mTau*mb)));
      if(rRrL > 0) RDCoef[1][0][1] = fabs(RDCoef[1][0][1]);
      Compute(tBmH_Eff,RDs,2);
      RDCoef[0][0][1] = -fabs(RDCoef[0][0][1]); RDCoef[1][0][1] = -fabs(RDCoef[1][0][1]);
      valMeas[2][0] = MeasuredRD[1]->Eval(tBmH_Eff);
      valMeas[2][1] = MeasuredRD[3]->Eval(tBmH_Eff);
//       cout<<RoundNumber(RD[0],3)<<" +- "<<RoundNumber(RD[1],3)<<", "
// 	  <<RoundNumber(RDs[0],3)<<" +- "<<RoundNumber(RDs[1],3)<<" at tBmH = "<<tBmH_Eff<<endl;
    }
    //if(tBmH==0) {RD[0] = 0.316; RD[1] = 0.014;}  // MILC 2012
    //if(tBmH==0) {RD[0] = 0.302; RD[1] = 0.016;}  // Tanaka 2010
    //if(tBmH==0) {RD[0] = 0.310; RD[1] = 0.020;}  // Nierste 2008
    TMatrixT<double> CovM(2,2), DiffRD(1,2), MDiff(1,2); //CovM is the covariance matrix
    if(_varyRD){
      CovM(0,0) = pow(RD[1],2) +pow(valMeas[1][1],2);
      CovM(1,1) = pow(RDs[1],2)+pow(valMeas[2][1],2);
      CovM(1,0) = Measurement[3][0]*valMeas[1][1]*valMeas[2][1];
      DiffRD(0,0) = valMeas[1][0]-RD[0]; DiffRD(0,1) = valMeas[2][0]-RDs[0];
    } else {
      CovM(0,0) = pow(RD[1],2) +pow(Measurement[1][1],2);
      CovM(1,1) = pow(RDs[1],2)+pow(Measurement[2][1],2);
      CovM(1,0) = Measurement[3][0]*Measurement[1][1]*Measurement[2][1];
      DiffRD(0,0) = Measurement[1][0]-RD[0]; DiffRD(0,1) = Measurement[2][0]-RDs[0];
    }
    CovM(0,1) = CovM(1,0);
    CovM.Invert();
    MDiff.Mult(DiffRD,CovM);
    chi2 = MDiff(0,0)*DiffRD(0,0) + MDiff(0,1)*DiffRD(0,1);
    ndof++;
//     if(tBmH==0 && _varyRD) 
//       cout<<endl<<"SM chi2 is "<<RoundNumber(chi2,2)<<" with a p-value of "<<TMath::Prob(chi2,ndof)<<". This is "
// 	  <<RoundNumber(sqrt(2)*TMath::ErfInverse(1 - TMath::Prob(chi2,ndof)),2)<<" sigma away"<<endl<<endl;
  }

  return 1 - TMath::Prob(chi2,ndof);
}
コード例 #4
0
std::vector<double> Verosimilitud::MinLLH(std::vector<double> param, std::vector<double> low_bound, std::vector<double> high_bound, std::vector<bool> param_to_minimize)
{
	if(param.size() != param_to_minimize.size()){
		std::cout << "sizes param do not match. break" <<std::endl;
		exit(1);
	}

	if(low_bound.size() != param_to_minimize.size()){
		std::cout << "sizes low do not match. break" <<std::endl;
		exit(1);
	}

	if(high_bound.size() != param_to_minimize.size()){
		std::cout << "sizes high do not match. break" <<std::endl;
		exit(1);
	}

	unsigned int number_of_parameters_to_minimize = std::count(param_to_minimize.begin(),param_to_minimize.end(),true);
 
	//set initial values and boundaries
	dlib::matrix<double,0,1> nuisance(number_of_parameters_to_minimize);
	dlib::matrix<double,0,1> lo_bounds(number_of_parameters_to_minimize);
	dlib::matrix<double,0,1> hi_bounds(number_of_parameters_to_minimize);
	unsigned int j=0;
	for(unsigned int i=0; i<param.size(); i++){
		if(param_to_minimize[i]){
			nuisance(j)=param[i];
			lo_bounds(j)=low_bound[i];
			hi_bounds(j)=high_bound[i];
			j++;
		}
	}
	
	/* all ok
	std::cout << "Input" << std::endl;
	std::cout << nuisance << std::endl;
	std::cout << lo_bounds << std::endl;
	std::cout << hi_bounds << std::endl;
	*/
	
// 	dlib::find_min_box_constrained(dlib::bfgs_search_strategy(),
// 							   dlib::objective_delta_stop_strategy(1e-7),
// 							   Chi2_caller(this,param,param_to_minimize),
// 							   Chi2grad_caller(this,param,param_to_minimize),
// 							   nuisance,
// 							   lo_bounds,
// 							   hi_bounds);

	dlib::find_min_box_constrained(dlib::lbfgs_search_strategy(10),
							   dlib::gradient_norm_stop_strategy(1e-1),
							   Chi2_caller(this,param,param_to_minimize),
							   Chi2grad_caller(this,param,param_to_minimize),
							   nuisance,
							   lo_bounds,
							   hi_bounds);

	std::vector<double> ret(param.size()+1,0);

	dlib::matrix<double,0,1> param_eval(param.size());
	unsigned int jj=0;
	for (unsigned int i=0; i<param.size(); i++){
		if(param_to_minimize[i]){
			ret[i] = nuisance(jj);
			param_eval(i) = nuisance(jj);
			jj++;
		} else {
			ret[i] = param[i];
			param_eval(i) = param[i];
		}
	}
	ret[param.size()] = Chi2(param_eval);

	return ret;
}
コード例 #5
0
ファイル: Parameters.cpp プロジェクト: gkasieczka/Code
/////////////////////////////////
//   y    := observables
//   x    := gen level quantities
//   type := decides the TF
/////////////////////////////////
double MEM::transfer_function(double* y, double* x, const TFType::TFType& type, int& out_of_range, const double& cutoff, const int& debug){

  // return value
  double w{1.};

  // temporary values;
  double E, H;
  double m1,s1, m2, s2, f, rho, c1, c2;

  // parameters
  const double* par;

  switch( type ){
    
  case TFType::bReco:
    // x[0] = parton energy ; 
    // x[1] = parton eta;
    // y[0] = jet energy;
    E  = x[0];
    H  = x[1];
    par = TF_B_param[ eta_to_bin(H) ];    

    f  = par[10];
    m1 = par[0] + par[1]*E;
    m2 = par[5] + par[6]*E;
    s1 = E*TMath::Sqrt(par[2]*par[2] + par[3]*par[3]/E + par[4]*par[4]/E/E);
    s2 = E*TMath::Sqrt(par[7]*par[7] + par[8]*par[8]/E + par[9]*par[9]/E/E);
    c1 = Chi2(y[0], m1, s1);
    c2 = Chi2(y[0], m2, s2);
    if( c1>cutoff && c2>cutoff ) ++out_of_range;
    w *= (1./sqrt(2*PI) * (f/s1*TMath::Exp(-0.5*c1) + (1-f)/s2*TMath::Exp(-0.5*c2) ));
#ifdef DEBUG_MODE
    if( debug&DebugVerbosity::integration) 
      cout << "\t\ttransfer_function: Evaluate W(" << y[0] << " | E=" << E << ", y=" << H << ", TFType::bReco) = " << w << endl;
#endif
    break;
    
  case TFType::qReco:
    // x[0] = parton energy ; 
    // x[1] = parton eta;
    // y[0] = jet energy;
    E   = x[0];
    H   = x[1];
    par = TF_Q_param[ eta_to_bin(H) ];
    m1  = par[0] + par[1]*E;
    s1  = E*TMath::Sqrt(par[2]*par[2] + par[3]*par[3]/E + par[4]*par[4]/E/E);
    c1  = Chi2(y[0], m1, s1);
    if( c1>cutoff ) ++out_of_range;

    w *= (1./sqrt(2*PI)/s1*TMath::Exp(-0.5*c1));
#ifdef DEBUG_MODE
    if( debug&DebugVerbosity::integration) 
      cout << "\t\ttransfer_function: Evaluate W(" << y[0] << " | E=" << E << ", y=" << H << ", TFType::qReco) = " << w << endl;
#endif
    break;
    
  case TFType::MET:
    // x[0] = sum nu_x ; x[1] = sum nu_y
    // y[0] = MET_x    ; y[1] = MET_y

    par = TF_MET_param;
    s1  = par[0];
    s2  = par[1];
    rho = par[2];
    c1  = Chi2Corr(y[0]-x[0], y[1]-x[1], s1, s2, rho);

    if( c1/2>cutoff ) ++out_of_range;

    w *= 1./(2*PI)/s1/s2/sqrt(1.-rho*rho)*TMath::Exp( -0.5*c1 );
#ifdef DEBUG_MODE
    if( debug&DebugVerbosity::integration) 
      cout << "\t\ttransfer_function: Evaluate W(" << y[0] << "-" << x[0] << " , " << y[1] << "-" << x[1] << ", TFType::MET) = " << w << endl;
#endif
    break;

  case TFType::Recoil:
    // Sudakov factor
    // x[0] = pT
    // y[0] = rhoT if extra_jets==0, else  par[2]+1GeV 

    par = TF_RECOIL_param;    
    m1 = par[0];
    s1 = par[1];
    if( y[0] < par[2] )
      w *= TMath::Gaus( log(x[0]), m1, s1, 1 );
    else 
      w *= 1.;
#ifdef DEBUG_MODE
    if( debug&DebugVerbosity::integration) 
      cout << "\t\ttransfer_function: Evaluate W( log(" << x[0] << "); TFType::Recoil) = " << w << endl;
#endif
    break;

  case TFType::bLost:
  case TFType::qLost:
    // x[0]     = parton energy ;
    // x[1]     = parton eta;
    // y[0]     = jet energy
    // par: [0]-> eta acceptance, [1]-> pT cut, [2]-> E max, [3]->acceptance (cos*phi)

    if( TMath::Abs(x[1])>TF_ACC_param[0] ){
      w *= 1.;      
#ifdef DEBUG_MODE
      if( debug&DebugVerbosity::integration) 
	cout << "\t\ttransfer_function: Evaluate W(" << x[0] << ", " << x[1] << ", TFType::qLost) = " << w << endl;
#endif
    }
    else{
      // x[0]     = parton energy ; 
      // x[1]     = parton eta
      // y[0]     = 0.
      E   = x[0];
      H   = x[1];
      par = TF_Q_param[ eta_to_bin(H) ];
      double mean_e  = (par[0] + par[1]*E);
      double sigma_e = E*TMath::Sqrt(par[2]*par[2] + par[3]*par[3]/E + par[4]*par[4]/E/E);
      double sign    = (TF_ACC_param[1]*TMath::CosH(H) >= mean_e) ? +1. : -1.;
      c1 = Chi2( TF_ACC_param[1]*TMath::CosH(H), mean_e, sigma_e);
      if( c1>cutoff ) ++out_of_range;

      w *= 0.5*(TMath::Erf( sqrt(c1/2.)*sign ) + 1 ) ;    
#ifdef DEBUG_MODE
      if( debug&DebugVerbosity::integration) 
	cout << "\t\ttransfer_function: Evaluate W(" <<  TF_ACC_param[1] << " | " << E << ", " << H << ", TFType::qLost) = " << w << endl;
#endif
    }
    break;
  case TFType::Unknown:
    w *= 1.;
#ifdef DEBUG_MODE
    if( debug&DebugVerbosity::integration) 
      cout << "\t\ttransfer_function: Evaluate W = 1 " << endl;
#endif
    break;
  default:
    break;
  }

  return w;
}
コード例 #6
0
ファイル: Parameters.cpp プロジェクト: gkasieczka/Code
double MEM::Chi2Corr(const double& x, const double& y, const double& sx, const double& sy, const double& rho){
  return  1./(1-rho*rho)*( Chi2(x,0.,sx) +  Chi2(y,0.,sy) - 2*rho*x*y/sx/sy ) ;
}