Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > eebc325dc36bd6e3b09b9b45133e42f8 > files > 923

HippoDraw-devel-docs-1.21.1-10.fc13.i686.rpm

<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>HippoDraw Class Library</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" href="hippoApp.ico">
</head><body>
<!-- Generated by Doxygen 1.6.2 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_0274a9be98ae47925200be6537e3d505.html">functions</a>
  </div>
</div>
<div class="contents">
<h1>Erfc.cxx</h1><a href="Erfc_8cxx.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00013"></a>00013 <span class="preprocessor">#ifdef _MSC_VER</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#include &quot;msdevstudio/MSconfig.h&quot;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#endif</span>
<a name="l00016"></a>00016 <span class="preprocessor"></span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &quot;<a class="code" href="Erfc_8h.html" title="Complementary Error function class interface (hippodraw::Erfc).">Erfc.h</a>&quot;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;<a class="code" href="FunctionHelper_8h.html" title="FunctionHelper class interface.">FunctionHelper.h</a>&quot;</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;cmath&gt;</span>
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;cassert&gt;</span>
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 <span class="preprocessor">#ifdef ITERATOR_MEMBER_DEFECT</span>
<a name="l00025"></a>00025 <span class="preprocessor"></span><span class="keyword">using namespace </span>std;
<a name="l00026"></a>00026 <span class="preprocessor">#else</span>
<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="keyword">using</span> std::exp;
<a name="l00028"></a>00028 <span class="keyword">using</span> std::vector;
<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span>
<a name="l00031"></a>00031 <span class="keyword">namespace </span>hippodraw {
<a name="l00032"></a>00032 
<a name="l00033"></a><a class="code" href="classhippodraw_1_1Erfc.html#a9874bc6728d450243a5aa6415aea6094">00033</a> <a class="code" href="classhippodraw_1_1Erfc.html#a9874bc6728d450243a5aa6415aea6094" title="The default constructor.">Erfc::Erfc</a> ( )
<a name="l00034"></a>00034 {
<a name="l00035"></a>00035   <a class="code" href="classhippodraw_1_1Erfc.html#a25a40b6614565f755233080a384c35f1" title="Initializes the function and parameter names.">initialize</a> ();
<a name="l00036"></a>00036 }
<a name="l00037"></a>00037 
<a name="l00038"></a><a class="code" href="classhippodraw_1_1Erfc.html#a9cd618279a0ba2e0f1828a662d6a38dd">00038</a> <a class="code" href="classhippodraw_1_1Erfc.html#a9874bc6728d450243a5aa6415aea6094" title="The default constructor.">Erfc::Erfc</a>(<span class="keywordtype">double</span> m, <span class="keywordtype">double</span> s, <span class="keywordtype">double</span> n)
<a name="l00039"></a>00039 {
<a name="l00040"></a>00040   <a class="code" href="classhippodraw_1_1Erfc.html#a25a40b6614565f755233080a384c35f1" title="Initializes the function and parameter names.">initialize</a>();
<a name="l00041"></a>00041   
<a name="l00042"></a>00042   <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[<a class="code" href="classhippodraw_1_1Erfc.html#a06fc87d81c62e9abb8790b6e5713c55bab8037c675dad16b9139e24e000143c78">MEAN</a>]  = m;
<a name="l00043"></a>00043   <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[<a class="code" href="classhippodraw_1_1Erfc.html#a06fc87d81c62e9abb8790b6e5713c55bad3071ccb5d54bbadcd61b726d215b10f">SIGMA</a>] = s;
<a name="l00044"></a>00044   <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[<a class="code" href="classhippodraw_1_1Erfc.html#a06fc87d81c62e9abb8790b6e5713c55bae003ec1158e3a4e295616ced12af154e">NORM</a>]  = n;  
<a name="l00045"></a>00045 }
<a name="l00046"></a>00046 
<a name="l00047"></a><a class="code" href="classhippodraw_1_1Erfc.html#a25a40b6614565f755233080a384c35f1">00047</a> <span class="keywordtype">void</span> <a class="code" href="classhippodraw_1_1Erfc.html#a25a40b6614565f755233080a384c35f1" title="Initializes the function and parameter names.">Erfc::initialize</a> ()
<a name="l00048"></a>00048 {
<a name="l00049"></a>00049   <a class="code" href="classhippodraw_1_1FunctionBase.html#adb41893ba19e889e56c559f25fc1a68a" title="The name of the function.">m_name</a> = <span class="stringliteral">&quot;Erfc&quot;</span>;
<a name="l00050"></a>00050 
<a name="l00051"></a>00051   <a class="code" href="classhippodraw_1_1FunctionBase.html#a96bf64e362e48f2ad4ecd76c32e4bc54" title="The names of the function parameters.">m_parm_names</a>.push_back ( <span class="stringliteral">&quot;Mean&quot;</span> );
<a name="l00052"></a>00052   <a class="code" href="classhippodraw_1_1FunctionBase.html#a96bf64e362e48f2ad4ecd76c32e4bc54" title="The names of the function parameters.">m_parm_names</a>.push_back ( <span class="stringliteral">&quot;Sigma&quot;</span> );
<a name="l00053"></a>00053   <a class="code" href="classhippodraw_1_1FunctionBase.html#a96bf64e362e48f2ad4ecd76c32e4bc54" title="The names of the function parameters.">m_parm_names</a>.push_back ( <span class="stringliteral">&quot;Normalization&quot;</span> );
<a name="l00054"></a>00054 
<a name="l00055"></a>00055   <a class="code" href="classhippodraw_1_1FunctionBase.html#a0fc3d585aa53859602ac79c9c421f2a9" title="Re-sizes the appropriate vectors maintained in this base class.">resize</a> ();
<a name="l00056"></a>00056 }
<a name="l00057"></a>00057 
<a name="l00058"></a><a class="code" href="classhippodraw_1_1Erfc.html#a5e4b003c4faa8b7729e762445c7578d8">00058</a> <a class="code" href="classhippodraw_1_1FunctionBase.html" title="A function that can be added to a DataRep and used in a fitter.">FunctionBase</a> * <a class="code" href="classhippodraw_1_1Erfc.html#a5e4b003c4faa8b7729e762445c7578d8" title="Creates a new function object by copying an existing one.">Erfc::clone</a> ()<span class="keyword"> const</span>
<a name="l00059"></a>00059 <span class="keyword"></span>{
<a name="l00060"></a>00060   <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classhippodraw_1_1Erfc.html#a9874bc6728d450243a5aa6415aea6094" title="The default constructor.">Erfc</a> ( *<span class="keyword">this</span> );
<a name="l00061"></a>00061 }
<a name="l00062"></a>00062 
<a name="l00065"></a>00065 <span class="keywordtype">double</span> <a class="code" href="classhippodraw_1_1Erfc.html#a35b6d3300fa7025c7a1f54d1c7fe6013" title="The function call operator.">Erfc::operator () </a>(<span class="keywordtype">double</span> value)<span class="keyword"> const</span>
<a name="l00066"></a>00066 <span class="keyword"></span>{
<a name="l00067"></a>00067   <span class="keywordtype">double</span> result = 1; <span class="comment">// The return value</span>
<a name="l00068"></a>00068 
<a name="l00069"></a>00069   <span class="keywordtype">double</span> x = <a class="code" href="classhippodraw_1_1Erfc.html#a5610f1b8c5396e3b3a5216896d6a28e4" title="compute the reduced variable: ">calcRed</a>(value); <span class="comment">//reduced variable</span>
<a name="l00070"></a>00070 
<a name="l00071"></a>00071   result = <a class="code" href="classhippodraw_1_1Erfc.html#a672080a40f7ea4f7eb92bbc053e69711">calcErfc</a>(x);  <span class="comment">//this method is a copy of ROOT method in TMath.cxx</span>
<a name="l00072"></a>00072   
<a name="l00073"></a>00073   result *= <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[<a class="code" href="classhippodraw_1_1Erfc.html#a06fc87d81c62e9abb8790b6e5713c55bae003ec1158e3a4e295616ced12af154e">NORM</a>];
<a name="l00074"></a>00074 
<a name="l00075"></a>00075   <span class="keywordflow">return</span> result;
<a name="l00076"></a>00076 }
<a name="l00077"></a>00077 
<a name="l00078"></a>00078 
<a name="l00079"></a>00079 <span class="comment">/* virtual */</span>
<a name="l00080"></a><a class="code" href="classhippodraw_1_1Erfc.html#ac89ece7f0010b352e8d897f0a352f811">00080</a> <span class="keywordtype">void</span>  <a class="code" href="classhippodraw_1_1Erfc.html#ac89ece7f0010b352e8d897f0a352f811" title="returns Erfc computed at the reduced variable  double Erfc::operator () (double value)...">Erfc::initialParameters</a> ( <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1FunctionHelper.html" title="An abstract base class to help FunctionBase objects perform some operations.">FunctionHelper</a> * helper )
<a name="l00081"></a>00081 {
<a name="l00082"></a>00082    <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[<a class="code" href="classhippodraw_1_1Erfc.html#a06fc87d81c62e9abb8790b6e5713c55bab8037c675dad16b9139e24e000143c78">MEAN</a>] = helper-&gt;<a class="code" href="classhippodraw_1_1FunctionHelper.html#a1402e98aa11796bfa8a52d5b8f4fc37b" title="Returns the mean of the coordinates along a X axis in the data set.">meanCoord</a>();
<a name="l00083"></a>00083    <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[<a class="code" href="classhippodraw_1_1Erfc.html#a06fc87d81c62e9abb8790b6e5713c55bad3071ccb5d54bbadcd61b726d215b10f">SIGMA</a>] = 1;
<a name="l00084"></a>00084    <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[<a class="code" href="classhippodraw_1_1Erfc.html#a06fc87d81c62e9abb8790b6e5713c55bae003ec1158e3a4e295616ced12af154e">NORM</a>] = helper-&gt;<a class="code" href="classhippodraw_1_1FunctionHelper.html#a2be3e090b19415ac06d8388b5fc91fe2" title="Returns the largest value in the data set.">maxValue</a> () / 2;
<a name="l00085"></a>00085 }
<a name="l00086"></a>00086 
<a name="l00087"></a>00087 
<a name="l00088"></a><a class="code" href="classhippodraw_1_1Erfc.html#a8617a1aa7536e4cb61f2a4ec29a39f36">00088</a> <span class="keywordtype">double</span> <a class="code" href="classhippodraw_1_1Erfc.html#a8617a1aa7536e4cb61f2a4ec29a39f36" title="Returns the function&amp;#39;s derivative at the coordinate value x with respect to the...">Erfc::derivByParm</a> ( <span class="keywordtype">int</span> i, <span class="keywordtype">double</span> value )<span class="keyword"> const</span>
<a name="l00089"></a>00089 <span class="keyword"></span>{
<a name="l00090"></a>00090    <span class="keywordtype">double</span> result = 0;
<a name="l00091"></a>00091 
<a name="l00092"></a>00092   <span class="keywordflow">switch</span> ( i ) {
<a name="l00093"></a>00093   <span class="keywordflow">case</span> <a class="code" href="classhippodraw_1_1Erfc.html#a06fc87d81c62e9abb8790b6e5713c55bab8037c675dad16b9139e24e000143c78">MEAN</a> :
<a name="l00094"></a>00094     result = -1.0/<a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[<a class="code" href="classhippodraw_1_1Erfc.html#a06fc87d81c62e9abb8790b6e5713c55bad3071ccb5d54bbadcd61b726d215b10f">SIGMA</a>] * <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[<a class="code" href="classhippodraw_1_1Erfc.html#a06fc87d81c62e9abb8790b6e5713c55bae003ec1158e3a4e295616ced12af154e">NORM</a>] * <a class="code" href="classhippodraw_1_1Erfc.html#accdd20961098ca1dbef1e36ab56d9853">derivByRed</a> ( <a class="code" href="classhippodraw_1_1Erfc.html#a5610f1b8c5396e3b3a5216896d6a28e4" title="compute the reduced variable: ">calcRed</a>(value) );
<a name="l00095"></a>00095     <span class="keywordflow">return</span> result; 
<a name="l00096"></a>00096     <span class="keywordflow">break</span>;
<a name="l00097"></a>00097 
<a name="l00098"></a>00098   <span class="keywordflow">case</span> <a class="code" href="classhippodraw_1_1Erfc.html#a06fc87d81c62e9abb8790b6e5713c55bad3071ccb5d54bbadcd61b726d215b10f">SIGMA</a> :
<a name="l00099"></a>00099     result = - <a class="code" href="classhippodraw_1_1Erfc.html#a5610f1b8c5396e3b3a5216896d6a28e4" title="compute the reduced variable: ">calcRed</a>(value)/<a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[<a class="code" href="classhippodraw_1_1Erfc.html#a06fc87d81c62e9abb8790b6e5713c55bad3071ccb5d54bbadcd61b726d215b10f">SIGMA</a>] * <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[<a class="code" href="classhippodraw_1_1Erfc.html#a06fc87d81c62e9abb8790b6e5713c55bae003ec1158e3a4e295616ced12af154e">NORM</a>] * <a class="code" href="classhippodraw_1_1Erfc.html#accdd20961098ca1dbef1e36ab56d9853">derivByRed</a> ( <a class="code" href="classhippodraw_1_1Erfc.html#a5610f1b8c5396e3b3a5216896d6a28e4" title="compute the reduced variable: ">calcRed</a>(value) );
<a name="l00100"></a>00100     <span class="keywordflow">return</span> result; 
<a name="l00101"></a>00101     <span class="keywordflow">break</span>;
<a name="l00102"></a>00102 
<a name="l00103"></a>00103   <span class="keywordflow">case</span> <a class="code" href="classhippodraw_1_1Erfc.html#a06fc87d81c62e9abb8790b6e5713c55bae003ec1158e3a4e295616ced12af154e">NORM</a> :
<a name="l00104"></a>00104    result = <a class="code" href="classhippodraw_1_1Erfc.html#a35b6d3300fa7025c7a1f54d1c7fe6013" title="The function call operator.">operator () </a>( value ) / <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[<a class="code" href="classhippodraw_1_1Erfc.html#a06fc87d81c62e9abb8790b6e5713c55bae003ec1158e3a4e295616ced12af154e">NORM</a>];
<a name="l00105"></a>00105    <span class="keywordflow">return</span> result; 
<a name="l00106"></a>00106    <span class="keywordflow">break</span>;
<a name="l00107"></a>00107 
<a name="l00108"></a>00108   <span class="keywordflow">default</span> :
<a name="l00109"></a>00109     assert ( <span class="keyword">false</span> );
<a name="l00110"></a>00110     <span class="keywordflow">break</span>;
<a name="l00111"></a>00111   }
<a name="l00112"></a>00112 
<a name="l00113"></a>00113   <span class="keywordflow">return</span> 0.0; 
<a name="l00114"></a>00114 }
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 
<a name="l00117"></a>00117 <span class="comment">//Derivative wrt reduced is gaussian!</span>
<a name="l00118"></a><a class="code" href="classhippodraw_1_1Erfc.html#accdd20961098ca1dbef1e36ab56d9853">00118</a> <span class="keywordtype">double</span> <a class="code" href="classhippodraw_1_1Erfc.html#accdd20961098ca1dbef1e36ab56d9853">Erfc::derivByRed</a>( <span class="keyword">const</span> <span class="keywordtype">double</span> x )<span class="keyword"> const</span>
<a name="l00119"></a>00119 <span class="keyword"></span>{ 
<a name="l00120"></a>00120   <span class="comment">//I don&#39;t know if this is platform independant: std::M_2_SQRTPI from math.h</span>
<a name="l00121"></a>00121   <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">double</span> m_2_sqrtpi = 1.12837916709551257390; <span class="comment">// 2/sqrt(pi)</span>
<a name="l00122"></a>00122 
<a name="l00123"></a>00123   <span class="keywordtype">double</span> result = - m_2_sqrtpi; <span class="comment">// minus sign comes from the fact that x is lower</span>
<a name="l00124"></a>00124                                 <span class="comment">// bound of Erfc definition</span>
<a name="l00125"></a>00125   result *= exp(-x*x);
<a name="l00126"></a>00126   <span class="keywordflow">return</span> result;
<a name="l00127"></a>00127 }
<a name="l00128"></a>00128 
<a name="l00129"></a>00129 
<a name="l00130"></a>00130 <span class="comment">//this is the copy from ROOT TMath.cxx</span>
<a name="l00131"></a><a class="code" href="classhippodraw_1_1Erfc.html#a672080a40f7ea4f7eb92bbc053e69711">00131</a> <span class="keywordtype">double</span> <a class="code" href="classhippodraw_1_1Erfc.html#a672080a40f7ea4f7eb92bbc053e69711">Erfc::calcErfc</a>(<span class="keywordtype">double</span> x)<span class="keyword"> const</span>
<a name="l00132"></a>00132 <span class="keyword"></span>{
<a name="l00133"></a>00133   <span class="comment">// Compute the complementary error function erfc(x).</span>
<a name="l00134"></a>00134   <span class="comment">// Erfc(x) = (2/sqrt(pi)) Integral(exp(-t^2))dt between x and infinity</span>
<a name="l00135"></a>00135   <span class="comment">//</span>
<a name="l00136"></a>00136   <span class="comment">//--- Nve 14-nov-1998 UU-SAP Utrecht</span>
<a name="l00137"></a>00137   
<a name="l00138"></a>00138   <span class="comment">// The parameters of the Chebyshev fit</span>
<a name="l00139"></a>00139   <span class="keyword">const</span> <span class="keywordtype">double</span> 
<a name="l00140"></a>00140     a1 = -1.26551223,   a2 = 1.00002368,
<a name="l00141"></a>00141     a3 =  0.37409196,   a4 = 0.09678418,
<a name="l00142"></a>00142     a5 = -0.18628806,   a6 = 0.27886807,
<a name="l00143"></a>00143     a7 = -1.13520398,   a8 = 1.48851587,
<a name="l00144"></a>00144     a9 = -0.82215223,  a10 = 0.17087277;
<a name="l00145"></a>00145 
<a name="l00146"></a>00146    <span class="keywordtype">double</span> v = 1; <span class="comment">// The return value</span>
<a name="l00147"></a>00147 
<a name="l00148"></a>00148    <span class="keywordtype">double</span> z = x&gt;=0 ? x : -x; <span class="comment">//absolute value</span>
<a name="l00149"></a>00149 
<a name="l00150"></a>00150    <span class="keywordflow">if</span> (z &lt;= 0) <span class="keywordflow">return</span> v; <span class="comment">// erfc(0)=1</span>
<a name="l00151"></a>00151 
<a name="l00152"></a>00152    <span class="keywordtype">double</span> t = 1/(1+0.5*z);
<a name="l00153"></a>00153 
<a name="l00154"></a>00154    v = t*exp((-z*z) +a1+t*(a2+t*(a3+t*(a4+t*(a5+t*(a6+t*(a7+t*(a8+t*(a9+t*a10)))))))));
<a name="l00155"></a>00155 
<a name="l00156"></a>00156    <span class="keywordflow">if</span> (x &lt; 0) v = 2-v; <span class="comment">// erfc(-x)=2-erfc(x)</span>
<a name="l00157"></a>00157 
<a name="l00158"></a>00158    <span class="keywordflow">return</span> v;
<a name="l00159"></a>00159 }
<a name="l00160"></a>00160 
<a name="l00161"></a>00161 } <span class="comment">// namespace hippodraw</span>
</pre></div></div>
<hr size="1"><address style="align: right;"><small>
Generated for HippoDraw Class Library by <a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0>
</a> </small></address>
</body>
</html>