Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > 5f484ffc0df874d32e4e8944dabff8f7 > files > 10

lhapdf-doc-5.9.1-2.fc18.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.3.1"/>
<title>LHAPDF C++ wrapper: /examples/CCTest2.cc</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">LHAPDF C++ wrapper
   &#160;<span id="projectnumber">5.4</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.3.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;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><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">/examples/CCTest2.cc</div>  </div>
</div><!--header-->
<div class="contents">
<p>An example of a program using the C++ interface to <a class="el" href="namespaceLHAPDF.html" title="Namespace containing all the LHAPDF wrapper functions.">LHAPDF</a> to calculate PDF errors.</p>
<div class="fragment"><div class="line"></div>
<div class="line"><span class="comment">// Program to demonstrate usage of the MRST 2006 NNLO PDFs.    //</span></div>
<div class="line"><span class="comment">// to calculate errors.                                        //</span></div>
<div class="line"><span class="comment"></span><span class="preprocessor">#include &quot;LHAPDF/LHAPDF.h&quot;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;cmath&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;cstdio&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;cstdlib&gt;</span></div>
<div class="line"><span class="keyword">using namespace </span>std;</div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span>LHAPDF;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">double</span> logdist_x(<span class="keywordtype">double</span> xmin, <span class="keywordtype">double</span> xmax, <span class="keywordtype">size_t</span> ix, <span class="keywordtype">size_t</span> nx) {</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">double</span> log10xmin = log10(xmin);</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">double</span> log10xmax = log10(xmax);</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">double</span> log10x = log10xmin + (ix/<span class="keyword">static_cast&lt;</span><span class="keywordtype">double</span><span class="keyword">&gt;</span>(nx-1))*(log10xmax-log10xmin);</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">double</span> x = pow(10.0, log10x);</div>
<div class="line">  <span class="keywordflow">return</span> x;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main() {</div>
<div class="line">  <span class="comment">// Show initialisation banner only once</span></div>
<div class="line">  <a class="code" href="namespaceLHAPDF.html#a54d0a3e29ef9a2bf17777da61c99ad3e" title="Choose level of noisiness.">setVerbosity</a>(LOWKEY); <span class="comment">// or SILENT, for no banner at all</span></div>
<div class="line"></div>
<div class="line">  <span class="comment">// You could explicitly set the path to the PDFsets directory</span></div>
<div class="line">  <span class="comment">// setPDFPath(&quot;/home/whalley/local/share/lhapdf/PDFsets&quot;);</span></div>
<div class="line">  </div>
<div class="line">  <span class="comment">// Initialize PDF sets</span></div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">string</span> NAME = <span class="stringliteral">&quot;MRST2006nnlo&quot;</span>;</div>
<div class="line">  initPDFSetM(1, NAME, LHGRID);</div>
<div class="line">  initPDFSetM(2, NAME, LHGRID);</div>
<div class="line">  initPDFSetM(3, NAME, LHGRID);</div>
<div class="line">  </div>
<div class="line">  <span class="comment">// Find the number of eigensets from numberPDF()</span></div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">int</span> neigen = numberPDFM(1)/2;</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;Number of eigensets in this fit = &quot;</span> &lt;&lt; neigen &lt;&lt; endl;</div>
<div class="line">  <span class="comment">// Find the min and max values of x and Q2 </span></div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">double</span> xmin = <a class="code" href="namespaceLHAPDF.html#a4b68147f30e452ed7bbe300630b46a3f" title="Minimum  value considered valid for this set, as specified by the set authors.">getXmin</a>(0);</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">double</span> xmax = <a class="code" href="namespaceLHAPDF.html#a9674750111bc08eee46291537f5aca71" title="Maximum  value considered valid for this set, as specified by the set authors.">getXmax</a>(0);</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;Valid x-range = [&quot;</span> &lt;&lt; xmin &lt;&lt; <span class="stringliteral">&quot;, &quot;</span> &lt;&lt; xmax &lt;&lt; <span class="stringliteral">&quot;]&quot;</span> &lt;&lt; endl;</div>
<div class="line">  <span class="comment">// Number of x values to sample</span></div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">int</span> nx = 10;</div>
<div class="line">  <span class="comment">// Set the Q scale and flavour</span></div>
<div class="line">  <span class="keywordtype">double</span> q = 10;</div>
<div class="line">  <span class="keywordtype">int</span> flav = 4;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Get x&#39;s and central PDF values</span></div>
<div class="line">  initPDFM(1, 0);</div>
<div class="line">  vector&lt;double&gt; fc(nx), x(nx);</div>
<div class="line">  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> ix = 0; ix &lt; nx; ++ix) {</div>
<div class="line">    x[ix] = logdist_x(xmin, 0.9*xmax, ix, nx);</div>
<div class="line">    fc[ix] = xfxM(1, x[ix], q, flav);</div>
<div class="line">  }</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Sum over error contributions (two ways, depending on how LHDPAF was compiled)</span></div>
<div class="line">  vector&lt;double&gt; summax(nx), summin(nx), sum(nx);</div>
<div class="line"><span class="preprocessor">  #ifndef LHAPDF_LOWMEM</span></div>
<div class="line"><span class="preprocessor"></span>  <span class="comment">// This is the normal, efficient, way to do this, with the error</span></div>
<div class="line">  <span class="comment">// sets being initialised the minimum number of times</span></div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;Using efficient set looping&quot;</span> &lt;&lt; endl;</div>
<div class="line">  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> ieigen = 1; ieigen &lt;= neigen; ++ieigen) {</div>
<div class="line">    initPDFM(2, 2*ieigen-1);</div>
<div class="line">    initPDFM(3, 2*ieigen);</div>
<div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> ix = 0; ix &lt; nx; ++ix) {</div>
<div class="line">      <span class="comment">// Find central and plus/minus values</span></div>
<div class="line">      <span class="keyword">const</span> <span class="keywordtype">double</span> fp = xfxM(2, x[ix], q, flav);</div>
<div class="line">      <span class="keyword">const</span> <span class="keywordtype">double</span> fm = xfxM(3, x[ix], q, flav);</div>
<div class="line">      <span class="comment">// Construct shifts</span></div>
<div class="line">      <span class="keyword">const</span> <span class="keywordtype">double</span> plus = max(max(fp-fc[ix], fm-fc[ix]),0.0);</div>
<div class="line">      <span class="keyword">const</span> <span class="keywordtype">double</span> minus = min(min(fp-fc[ix], fm-fc[ix]),0.0);</div>
<div class="line">      <span class="keyword">const</span> <span class="keywordtype">double</span> diff = fp-fm;</div>
<div class="line">      <span class="comment">// Add it together</span></div>
<div class="line">      summax[ix] += plus*plus;</div>
<div class="line">      summin[ix] += minus*minus;</div>
<div class="line">      sum[ix] += diff*diff;</div>
<div class="line">    }</div>
<div class="line">  }</div>
<div class="line"><span class="preprocessor">  #else</span></div>
<div class="line"><span class="preprocessor"></span>  <span class="comment">// In low memory mode, the sets need to be re-initialised with every </span></div>
<div class="line">  <span class="comment">// change of member. Using the approach above gives wrong answers, and</span></div>
<div class="line">  <span class="comment">// reinitialising in all the nested loops is sloooooow! The best way is </span></div>
<div class="line">  <span class="comment">// to calculate the values, plus and minus errors separately.</span></div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;Using low-mem mode set looping&quot;</span> &lt;&lt; endl;</div>
<div class="line">  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> ieigen = 1; ieigen &lt;= neigen; ++ieigen) {</div>
<div class="line">    vector&lt;double&gt; fp(nx), fm(nx);</div>
<div class="line">    initPDFM(2, 2*ieigen-1);</div>
<div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> ix = 0; ix &lt; nx; ++ix) {</div>
<div class="line">      fp[ix] = xfxM(2, x[ix], q, flav);</div>
<div class="line">    }</div>
<div class="line">    initPDFM(3, 2*ieigen);</div>
<div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> ix = 0; ix &lt; nx; ++ix) {</div>
<div class="line">      fm[ix] = xfxM(3, x[ix], q, flav);</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> ix = 0; ix &lt; nx; ++ix) {</div>
<div class="line">      <span class="comment">// Construct shifts</span></div>
<div class="line">      <span class="keyword">const</span> <span class="keywordtype">double</span> plus = max(max(fp[ix]-fc[ix], fm[ix]-fc[ix]), 0.0);</div>
<div class="line">      <span class="keyword">const</span> <span class="keywordtype">double</span> minus = min(min(fp[ix]-fc[ix], fm[ix]-fc[ix]), 0.0);</div>
<div class="line">      <span class="keyword">const</span> <span class="keywordtype">double</span> diff = fp[ix]-fm[ix];</div>
<div class="line">      <span class="comment">// Add it together</span></div>
<div class="line">      summax[ix] += plus*plus;</div>
<div class="line">      summin[ix] += minus*minus;</div>
<div class="line">      sum[ix] += diff*diff;</div>
<div class="line">    }</div>
<div class="line">  }</div>
<div class="line"><span class="preprocessor">  #endif</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line">  <span class="comment">// Print out results</span></div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;flavour = &quot;</span> &lt;&lt; flav &lt;&lt; <span class="stringliteral">&quot;               Asymmetric (%)   Symmetric (%)&quot;</span> &lt;&lt; endl;</div>
<div class="line">  cout &lt;&lt; <span class="stringliteral">&quot;     x    Q**2    xf(x)    plus    minus      +-      &quot;</span> &lt;&lt; endl;</div>
<div class="line">  <span class="keywordflow">for</span>  (<span class="keywordtype">int</span> ix = 0; ix &lt; nx; ++ix) {</div>
<div class="line">    printf(<span class="stringliteral">&quot;%0.7f %.0f %10.2E %8.2f %8.2f %8.2f \n&quot;</span>,</div>
<div class="line">           x[ix], q*q, fc[ix], </div>
<div class="line">           sqrt(summax[ix])*100/fc[ix],</div>
<div class="line">           sqrt(summin[ix])*100/fc[ix],</div>
<div class="line">           0.5*sqrt(sum[ix])*100/fc[ix]);</div>
<div class="line">  }</div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">return</span> EXIT_SUCCESS;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &quot;FortranWrappers.h&quot;</span></div>
<div class="line"><span class="preprocessor">#ifdef FC_DUMMY_MAIN</span></div>
<div class="line"><span class="preprocessor"></span><span class="keywordtype">int</span> FC_DUMMY_MAIN() { <span class="keywordflow">return</span> 1; }</div>
<div class="line"><span class="preprocessor">#endif</span></div>
</div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Thu Nov 21 2013 06:02:29 for LHAPDF C++ wrapper by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.3.1
</small></address>
</body>
</html>