Example #1
0
int
gsl_integration_qag (const gsl_function *f,
                     double a, double b,
                     double epsabs, double epsrel, size_t limit,
                     int key,
                     gsl_integration_workspace * workspace,
                     double * result, double * abserr)
{
  int status ;
  gsl_integration_rule * integration_rule = gsl_integration_qk15 ;

  if (key < GSL_INTEG_GAUSS15)
    {
      key = GSL_INTEG_GAUSS15 ;
    } 
  else if (key > GSL_INTEG_GAUSS61) 
    {
      key = GSL_INTEG_GAUSS61 ;
    }

  switch (key) 
    {
    case GSL_INTEG_GAUSS15:
      integration_rule = gsl_integration_qk15 ;
      break ;
    case GSL_INTEG_GAUSS21:
      integration_rule = gsl_integration_qk21 ;
      break ;
    case GSL_INTEG_GAUSS31:
      integration_rule = gsl_integration_qk31 ; 
      break ;
    case GSL_INTEG_GAUSS41:
      integration_rule = gsl_integration_qk41 ;
      break ;      
    case GSL_INTEG_GAUSS51:
      integration_rule = gsl_integration_qk51 ;
      break ;      
    case GSL_INTEG_GAUSS61:
      integration_rule = gsl_integration_qk61 ;
      break ;      
    default:
      GSL_ERROR("value of key does specify a known integration rule", 
                GSL_EINVAL) ;
    }

  status = qag (f, a, b, epsabs, epsrel, limit,
                workspace, 
                result, abserr, 
                integration_rule) ;
  
  return status ;
}
Real calorimeterLSF::getLSF (Real deltaE1, Real deltaE2)
{
  //  Real answer = qags (deltaE2, deltaE1);
  //  Real answer = qng (deltaE2, deltaE1);
  setEpsRel (1.e-3); // desired accuracy of integral over energy bin
  Real limit = 1.e-10 / itsETau; // below a certain threshold throw out the tail
  if (compare (integrand (deltaE1), limit) == -1) {
    if (compare (integrand (deltaE2), limit) == -1) {
      return 0.;
    }
  }
  Real answer = qag (deltaE2, deltaE1, 4);
  int status = getStatus ();
  if (status) {
    cout << deltaE1 << " " << deltaE2 << " " << answer << "\n";
    cout << integrand (deltaE1) << " " << integrand (deltaE2) << "\n";
  }
  return qags (deltaE2, deltaE1);
}