<!DOCTYPE HTML PUBLIC "-// IETF/DTD HTML 2.0// EN">
<html>
<!--                                             -->
<!-- Author: ROOT team (rootdev@hpsalo.cern.ch)  -->
<!--                                             -->
<!--   Date: Tue Apr  6 15:50:20 1999            -->
<!--                                             -->
<head>
<title>readStdFile - source file</title>
<link rev=made href="mailto:rootdev@root.cern.ch">
<meta name="rating" content="General">
<meta name="objecttype" content="Manual">
<meta name="keywords" content="software development, oo, object oriented, unix, x11, motif, windows nt, c++, html, rene brun, fons rademakers">
<meta name="description" content="ROOT - An Object Oriented Framework For Large Scale Data Analysis.">
</head>
<body BGCOLOR="#ffffff" LINK="#0000ff" VLINK="#551a8b" ALINK="#ff0000" TEXT="#000000">
<a name="TopOfPage"></a>
<pre>
<b>// 1999/02/26   Adapted for use in lcd simulations from Gismo 2,</b>
<b>// /afs/cern.ch/atlas/software/cvs/offline/arve/gismo/<a href=".././readStdFile.html">readStdFile</a>.cxx,v 1.1.1.1</b>
<b>// 1997/08/14 14:04:13 lat </b>
<b>//</b>


#include "<a href="../Event.h">Event.h</a>"
#include "TMap.h"
#include "<a href="../readStdFile.h">readStdFile.h</a>"

#ifdef WIN32
#define hepevt_ HEPEVT
#endif

struct hepevt HEPEVT;

<b>//______________________________________________________________________</b>
<b>// <a href=".././readStdFile.html">readStdFile</a></b>
<b>//</b>
<b>// This class is one type of event source.  It can get an event from a stdHEP</b>
<b>// file and feed the MC particle information into instances of MC</b>

ClassImp(<a href=".././readStdFile.html">readStdFile</a>)
<a name="readStdFile:readStdFile"> </a><a href=".././readStdFile.html#readStdFile:readStdFile">readStdFile::readStdFile</a>(<a href="../ListOfTypes.html#char">char</a>* filein) {
  <a href=".././readStdFile.html#readStdFile:inputfile">inputfile</a> = filein;
  <a href=".././readStdFile.html#readStdFile:istr">istr</a> = 0;

  assert(! StdHepXdrReadInit(<a href=".././readStdFile.html#readStdFile:inputfile">inputfile</a>, 1, <a href=".././readStdFile.html#readStdFile:istr">istr</a>));
}
<b>//</b>
<b>//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</b>
<b>//</b>
<a name="readStdFile:~readStdFile"> </a><a href=".././readStdFile.html">readStdFile</a>::~<a href=".././readStdFile.html">readStdFile</a>()
{
   StdHepXdrEnd(<a href=".././readStdFile.html#readStdFile:istr">istr</a>);
   printf("Closing input file %c n",<a href=".././readStdFile.html#readStdFile:inputfile">inputfile</a>);
}
<b>//</b>
<b>//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</b>
<b>//</b>
<a name="readStdFile:readEvent"> </a><a href="../ListOfTypes.html#int">int</a> <a href=".././readStdFile.html#readStdFile:readEvent">readStdFile::readEvent</a>() {
<b>  // reading the binary file to fill the common block</b>

  hepevt_.nhep = 0;
  <a href="../ListOfTypes.html#int">int</a> lbl = 1;	

  StdHepZero();
	
  <a href=".././readStdFile.html#readStdFile:ierr">ierr</a> = StdHepXdrRead(&amp;lbl,<a href=".././readStdFile.html#readStdFile:istr">istr</a>);

  if(lbl == 100){
    printf(" Reading StdHep begin run record.n");
    <a href=".././readStdFile.html#readStdFile:ierr">ierr</a> = StdHepXdrRead(&amp;lbl,<a href=".././readStdFile.html#readStdFile:istr">istr</a>);
  } 
  if (<a href=".././readStdFile.html#readStdFile:ierr">ierr</a> != 0) {
    printf(" unexpected end of file after %d eventsn",hepevt_.nhep);
    return 0;
  }
  return (hepevt_.nhep == 0);
}


<a name="readStdFile:getEvent"> </a><a href="../ListOfTypes.html#int">int</a> <a href=".././readStdFile.html#readStdFile:getEvent">readStdFile::getEvent</a>(<a href="http://root.cern.ch/root/html/Event.html">Event</a>* event) {
<b>  // From stdHEP file representation to MCpart instances</b>

  if( <a href="#readStdFile:readEvent">readEvent</a>() )
         return 0;
  <a href="#readStdFile:makeMCs">makeMCs</a>(event);
return 1;
}
<b>//</b>
<b>//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</b>
<b>//</b>
<a name="readStdFile:makeMCs"> </a><a href="../ListOfTypes.html#int">int</a> <a href=".././readStdFile.html#readStdFile:makeMCs">readStdFile::makeMCs</a>(<a href="http://root.cern.ch/root/html/Event.html">Event</a>* event){
<b>  // This method makes <a href="http://root.cern.ch/root/html/McPart.html">McPart</a> objects from the stdHEP common</b>
<b>  // Someday if we have an MCdiag which also wants to output to the</b>
<b>  // stdHEP common this method should be moved to a utility base</b>
<b>  // class from which <a href=".././readStdFile.html">readStdFile</a> and MCdiag could both inherit.</b>

  <a href=".././readStdFile.html#readStdFile:m_event">m_event</a> = event;

  <a href="../ListOfTypes.html#float">float</a> pzero[4] = {0.};
  <a href="../ListOfTypes.html#float">float</a> vzero[4] = {0.};
  <a href="http://root.cern.ch/root/html/McPart.html">McPart</a>* parents[4000] = {0};


<b>  // create a dummy first particle at IP</b>

  <a href="http://root.cern.ch/root/html/McPart.html">McPart</a>* firstMC = new <a href="http://root.cern.ch/root/html/McPart.html">McPart</a>();
  <a href="../ListOfTypes.html#int">int</a> fakeID = 999999, fakeStat = 0;
  <a href="../ListOfTypes.html#float">float</a> fakeChg = 0.;

  firstMC-&gt;SetUpParticle(fakeID,     // fake particle type
			 fakeChg,     // charge
			 fakeStat,    // status
			 0,           // no parent particle
			 pzero,        // set momentum to zero
			 vzero);        // set position to zero


  <a href=".././readStdFile.html#readStdFile:m_event">m_event</a>-&gt;<a href="http://root.cern.ch/root/html/Event.html#Event:MCparticles">MCparticles</a>()-&gt;Add(firstMC);

  parents[0] = firstMC;

  unsigned numsecond = unsigned(hepevt_.nhep);
  for( unsigned i = 0; i &lt; numsecond; i++)
  {										  										  //for different generator output.
    <a href="../ListOfTypes.html#int">int</a> statusCode = hepevt_.isthep[i];
    if( statusCode==0 ) continue;

    <a href="../ListOfTypes.html#float">float</a> mass = hepevt_.phep[i][4];
    <a href="../ListOfTypes.html#int">int</a> parentIndex = static_cast&lt;<a href="../ListOfTypes.html#int">int</a>&gt;(hepevt_.jmohep[i][0]);
    if (parentIndex &lt; 0) parentIndex = 0;
			  
    <a href="../ListOfTypes.html#float">float</a> pvect[4];
    <a href="../ListOfTypes.html#float">float</a> vvect[4];
    pvect[0] = static_cast&lt;<a href="../ListOfTypes.html#float">float</a>&gt;(hepevt_.phep[i][0]);
    pvect[1] = static_cast&lt;<a href="../ListOfTypes.html#float">float</a>&gt;(hepevt_.phep[i][1]);
    pvect[2] = static_cast&lt;<a href="../ListOfTypes.html#float">float</a>&gt;(hepevt_.phep[i][2]);
    pvect[3] = static_cast&lt;<a href="../ListOfTypes.html#float">float</a>&gt;(hepevt_.phep[i][3]);
    vvect[0] = static_cast&lt;<a href="../ListOfTypes.html#float">float</a>&gt;(hepevt_.vhep[i][0]);
    vvect[1] = static_cast&lt;<a href="../ListOfTypes.html#float">float</a>&gt;(hepevt_.vhep[i][1]);
    vvect[2] = static_cast&lt;<a href="../ListOfTypes.html#float">float</a>&gt;(hepevt_.vhep[i][2]);
    vvect[3] = static_cast&lt;<a href="../ListOfTypes.html#float">float</a>&gt;(hepevt_.vhep[i][3]); // not really used

    <a href="../ListOfTypes.html#int">int</a> id = hepevt_.idhep[i];

<b>    // create and fill the <a href="http://root.cern.ch/root/html/McPart.html">McPart</a></b>

    <a href="http://root.cern.ch/root/html/McPart.html">McPart</a>* part = new <a href="http://root.cern.ch/root/html/McPart.html">McPart</a>();

    <a href="http://root.cern.ch/root/html/McPart.html">McPart</a>* p = parents[parentIndex];

    <a href="../ListOfTypes.html#float">float</a> chg = stdchg_(&amp;id);

    part-&gt;SetUpParticle(id,         // particle type
			chg,         // charge
			statusCode,  // status from generator
			p,            // parent particle
			pvect,        // momentum
			vzero);        // set position to zero

<b>    // set the parent's termination point to be the initial position of</b>
<b>    // its daughter.</b>

    if ( p ) p-&gt;SetPosition(vvect);

<b>    // add this guy to parentMap</b>

    parents[i+1] = part;

<b>    // and to the list of <a href="http://root.cern.ch/root/html/McPart.html">McPart</a>'s</b>
    <a href=".././readStdFile.html#readStdFile:m_event">m_event</a>-&gt;<a href="http://root.cern.ch/root/html/Event.html#Event:MCparticles">MCparticles</a>()-&gt;Add(part);
  }

  return 1;
}

</pre>

<!--SIGNATURE-->
<br>
<address>
<hr>
<center>
<a href="http://root.cern.ch/root/Welcome.html">ROOT page</a> - <a href="../ClassIndex.html">Class index</a> - <a href="#TopOfPage">Top of the page</a><br>
</center>
<hr>This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to <a href="mailto:rootdev@root.cern.ch">ROOT support</a>, or contact <a href="mailto:rootdev@root.cern.ch">the developers</a> with any questions or problems regarding ROOT.
</address>
</body>
</html>
