<!DOCTYPE HTML PUBLIC "-// IETF/DTD HTML 2.0// EN">
<html>
<!--                                             -->
<!-- Author: ROOT team (rootdev@hpsalo.cern.ch)  -->
<!--                                             -->
<!--   Date: Tue Apr  6 15:50:09 1999            -->
<!--                                             -->
<head>
<title>MCDiag - 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>//  R. Shanks      February (?) 1999</b>
<b>//  J. Bogart      31 Mar 1999   Changed all <a href="../ListOfTypes.html#float">float</a> to <a href="../ListOfTypes.html#double">double</a></b>

#include "<a href="../MCDiag.h">MCDiag.h</a>"
<b>//#ifdef WIN32</b>
<b>//#define hepevt_ HEPEVT</b>
<b>//#endif</b>

struct hepevt HEPEVT;
<b>  //////////////////////////////////////////////////////////////////////////</b>
<b>  //                                                                      //</b>
<b>  // <a href=".././MCDiag.html">MCDiag</a>                                                               //</b>
<b>  //                                                                      //</b>
<b>  // The <a href=".././MCDiag.html">MCDiag</a> class produces a stream of N particles with their         //</b>
<b>  // momentum spread out in magnitude and direction. The resulting        //</b>
<b>  // particles are output to a file in StdHep format.                     //</b>
<b>  //                                                                      //</b>
<b>  //////////////////////////////////////////////////////////////////////////</b>

<a href="../ListOfTypes.html#Int_t">Int_t</a> <a href=".././MCDiag.html#MCDiag:m_known_parts">MCDiag::m_known_parts</a>[] = {11,13,111,211,2212,2112,321,310,130};
<a href="../ListOfTypes.html#Double_t">Double_t</a> <a href=".././MCDiag.html#MCDiag:m_known_masses">MCDiag::m_known_masses</a>[] = {0.000511,0.105658,0.1349739,0.1395675,
				    0.938272,0.939566,0.493646,0.497671,
				    0.497671};
<a href="../ListOfTypes.html#Int_t">Int_t</a> <a href=".././MCDiag.html#MCDiag:m_num_known_parts">MCDiag::m_num_known_parts</a> = 9;

ClassImp(<a href=".././MCDiag.html">MCDiag</a>)

<b>///_________________________________________________________________________</b>
<a name="MCDiag:MCDiag"> </a><a href=".././MCDiag.html#MCDiag:MCDiag">MCDiag::MCDiag</a>(<a href="../ListOfTypes.html#char">char</a>* ofile):<a href=".././MCDiag.html#MCDiag:m_MagSpread">m_MagSpread</a>(0.0),<a href=".././MCDiag.html#MCDiag:m_CosThSpread">m_CosThSpread</a>(0.0),<a href=".././MCDiag.html#MCDiag:m_PhiSpread">m_PhiSpread</a>(0.0),<a href=".././MCDiag.html#MCDiag:m_NumParticles">m_NumParticles</a>(1), <a href=".././MCDiag.html#MCDiag:m_xpoint">m_xpoint</a>(0),<a href=".././MCDiag.html#MCDiag:m_ypoint">m_ypoint</a>(0),<a href=".././MCDiag.html#MCDiag:m_zpoint">m_zpoint</a>(0),<a href=".././MCDiag.html#MCDiag:m_prod_time">m_prod_time</a>(0)
{
<b>  // <a href="http://root.cern.ch/root/html/TStyle.html">Default</a> constructor</b>
  <a href=".././MCDiag.html#MCDiag:m_mag">m_mag</a> = 5.00; // GeV
  <a href=".././MCDiag.html#MCDiag:m_phi">m_phi</a> = <a href="http://root.cern.ch/root/html/TMath.html#TMath:Pi">TMath::Pi</a>()/4;
  <a href=".././MCDiag.html#MCDiag:m_costheta">m_costheta</a> = 0.707;
  <a href=".././MCDiag.html#MCDiag:m_type">m_type</a> = 13; // Muon by default
  hepevt_.nevhep = 0;
  <a href=".././MCDiag.html#MCDiag:factor">factor</a> = new <a href="http://root.cern.ch/root/html/TRandom.html">TRandom</a>();

  <a href=".././MCDiag.html#MCDiag:ilbl">ilbl</a> = 1;
  <a href=".././MCDiag.html#MCDiag:istr">istr</a> = 0; 

  if(StdHepXdrWriteInit(ofile,"Robs file", 1, <a href=".././MCDiag.html#MCDiag:istr">istr</a>)){
    printf("<a href=".././MCDiag.html">MCDiag</a>: Failed to initialize output file "%s".n", ofile);
    exit(1);
  }// All StdHep routines return non zero if an error has occured	
  
}
<b>///_________________________________________________________________________</b>
<a name="MCDiag:Set_Seed"> </a><a href="../ListOfTypes.html#void">void</a> <a href=".././MCDiag.html#MCDiag:Set_Seed">MCDiag::Set_Seed</a>(<a href="../ListOfTypes.html#UInt_t">UInt_t</a> seed){
<b>  // Set the seed of the random number generator. If zero then seed</b>
<b>  // is set to current machine clock</b>
  <a href=".././MCDiag.html#MCDiag:factor">factor</a>-&gt;<a href="http://root.cern.ch/root/html/TRandom.html#TRandom:SetSeed">SetSeed</a>(seed);
}
<b>///_________________________________________________________________________</b>
<a name="MCDiag:Set_Spread"> </a><a href="../ListOfTypes.html#void">void</a> <a href=".././MCDiag.html#MCDiag:Set_Spread">MCDiag::Set_Spread</a>(<a href="../ListOfTypes.html#Double_t">Double_t</a> magspread, <a href="../ListOfTypes.html#Double_t">Double_t</a> costhspread, <a href="../ListOfTypes.html#Double_t">Double_t</a> phispread){
<b>  // The user is prompted for the momentum spread parameters</b>
  <a href=".././MCDiag.html#MCDiag:m_MagSpread">m_MagSpread</a> = magspread;
  <a href=".././MCDiag.html#MCDiag:m_CosThSpread">m_CosThSpread</a> = costhspread;
  <a href=".././MCDiag.html#MCDiag:m_PhiSpread">m_PhiSpread</a> = phispread;
}
<b>///_________________________________________________________________________</b>
<a name="MCDiag:Set_Momentum"> </a><a href="../ListOfTypes.html#void">void</a> <a href=".././MCDiag.html#MCDiag:Set_Momentum">MCDiag::Set_Momentum</a>(<a href="../ListOfTypes.html#Double_t">Double_t</a> mag, <a href="../ListOfTypes.html#Double_t">Double_t</a> costheta, <a href="../ListOfTypes.html#Double_t">Double_t</a> phi){
<b>  // Sets the mean components of the momentum vectors</b>
  <a href=".././MCDiag.html#MCDiag:m_mag">m_mag</a> = mag;
  <a href=".././MCDiag.html#MCDiag:m_phi">m_phi</a> = phi;
  <a href=".././MCDiag.html#MCDiag:m_costheta">m_costheta</a> = costheta;
}
<b>///_________________________________________________________________________</b>
<a name="MCDiag:Set_Start_Point"> </a><a href="../ListOfTypes.html#void">void</a> <a href=".././MCDiag.html#MCDiag:Set_Start_Point">MCDiag::Set_Start_Point</a>(<a href="../ListOfTypes.html#Double_t">Double_t</a> xpoint, <a href="../ListOfTypes.html#Double_t">Double_t</a> ypoint, <a href="../ListOfTypes.html#Double_t">Double_t</a> zpoint){
<b>  // Sets the starting point of the particles(s).</b>
<b>  // <a href="http://root.cern.ch/root/html/TStyle.html">Default</a> is (0,0,0) aka the IP.</b>
  <a href=".././MCDiag.html#MCDiag:m_xpoint">m_xpoint</a> = xpoint;
  <a href=".././MCDiag.html#MCDiag:m_ypoint">m_ypoint</a> = ypoint;
  <a href=".././MCDiag.html#MCDiag:m_zpoint">m_zpoint</a> = zpoint;
}
<b>///_________________________________________________________________________</b>
<a name="MCDiag:Set_Production_Time"> </a><a href="../ListOfTypes.html#void">void</a> <a href=".././MCDiag.html#MCDiag:Set_Production_Time">MCDiag::Set_Production_Time</a>(<a href="../ListOfTypes.html#Double_t">Double_t</a>  time){
<b>  // Sets the time of production of the particles(s).</b>
<b>  // <a href="http://root.cern.ch/root/html/TStyle.html">Default</a> is 0.0</b>
	<a href=".././MCDiag.html#MCDiag:m_prod_time">m_prod_time</a> = time;
}
<b>///_________________________________________________________________________</b>
<a name="MCDiag:Set_Particles"> </a><a href="../ListOfTypes.html#void">void</a> <a href=".././MCDiag.html#MCDiag:Set_Particles">MCDiag::Set_Particles</a>(<a href="../ListOfTypes.html#Int_t">Int_t</a> num){
<b>  // Sets the number of particles</b>
  <a href=".././MCDiag.html#MCDiag:m_NumParticles">m_NumParticles</a> = num;
}
<b>///_________________________________________________________________________</b>
<a name="MCDiag:Set_Type"> </a><a href="../ListOfTypes.html#void">void</a> <a href=".././MCDiag.html#MCDiag:Set_Type">MCDiag::Set_Type</a>(<a href="../ListOfTypes.html#Int_t">Int_t</a> type){
<b>  // Sets the particle type. NOTE: Must use StdHep numbering scheme.Particle </b>
<b>  // mass is set from type</b>
  <a href=".././MCDiag.html#MCDiag:m_type">m_type</a> = type;
  for(<a href="../ListOfTypes.html#Int_t">Int_t</a> i =0;i&lt;<a href=".././MCDiag.html#MCDiag:m_num_known_parts">m_num_known_parts</a>;i++){
    if((<a href=".././MCDiag.html#MCDiag:m_known_parts">m_known_parts</a>[i] == type)||(<a href=".././MCDiag.html#MCDiag:m_known_parts">m_known_parts</a>[i] == -type)){
      <a href=".././MCDiag.html#MCDiag:m_mass">m_mass</a> = <a href=".././MCDiag.html#MCDiag:m_known_masses">m_known_masses</a>[i]; // mass
      return;
    }
    else continue;
  }
  printf("Particle type %i unknown.n Supported types include:n",type);
  printf("11 electronn13 muonn111 pi-zeron211 pi-plusn2112 neutronn2212 protonn321 k-plusn310 k0-<a href="../ListOfTypes.html#short">short</a>n130 k0-<a href="../ListOfTypes.html#long">long</a>");
  exit(1); 
      
}
<b>///_________________________________________________________________________</b>
<a name="MCDiag:getEvent"> </a><a href="../ListOfTypes.html#Int_t">Int_t</a> <a href=".././MCDiag.html#MCDiag:getEvent">MCDiag::getEvent</a>(<a href="http://root.cern.ch/root/html/Event.html">Event</a>* event){

  <a href="../ListOfTypes.html#Int_t">Int_t</a> ierr;
  if(ierr = <a href="#MCDiag:doit">doit</a>()){
    printf("<a href=".././MCDiag.html#MCDiag:Error">MCDiag::Error</a> in filling common block.");
    return(1);
  }
  <a href=".././readStdFile.html">readStdFile</a>* rsf = new <a href=".././readStdFile.html">readStdFile</a>();
  if(ierr = rsf-&gt;makeMCs(event)){
    printf("<a href=".././MCDiag.html#MCDiag:Error">MCDiag::Error</a> in filling the event structure.");
    return(1);
  }
  return(0);
}
<b>///_________________________________________________________________________</b>
<a name="MCDiag:doit"> </a><a href="../ListOfTypes.html#Int_t">Int_t</a> <a href=".././MCDiag.html#MCDiag:doit">MCDiag::doit</a>(){
<b>  // Create the stream of Particles</b>
  hepevt_.nevhep += 1;
  hepevt_.nhep = <a href=".././MCDiag.html#MCDiag:m_NumParticles">m_NumParticles</a>;
  for(<a href="../ListOfTypes.html#Int_t">Int_t</a> i =0;i&lt;<a href=".././MCDiag.html#MCDiag:m_NumParticles">m_NumParticles</a>; i++){
    <a href="../ListOfTypes.html#Double_t">Double_t</a> newmag = <a href=".././MCDiag.html#MCDiag:m_mag">m_mag</a> + (2*<a href=".././MCDiag.html#MCDiag:factor">factor</a>-&gt;<a href="http://root.cern.ch/root/html/TRandom.html#TRandom:Rndm">Rndm</a>()-1)*(<a href=".././MCDiag.html#MCDiag:m_MagSpread">m_MagSpread</a>);
    <a href="../ListOfTypes.html#Double_t">Double_t</a> newcth = <a href=".././MCDiag.html#MCDiag:m_costheta">m_costheta</a> +(2*<a href=".././MCDiag.html#MCDiag:factor">factor</a>-&gt;<a href="http://root.cern.ch/root/html/TRandom.html#TRandom:Rndm">Rndm</a>()-1)*(<a href=".././MCDiag.html#MCDiag:m_CosThSpread">m_CosThSpread</a>);
    <a href="../ListOfTypes.html#Double_t">Double_t</a> sinth = sqrt(1.-newcth*newcth);
    <a href="../ListOfTypes.html#Double_t">Double_t</a> newphi = <a href=".././MCDiag.html#MCDiag:m_phi">m_phi</a> + (2*<a href=".././MCDiag.html#MCDiag:factor">factor</a>-&gt;<a href="http://root.cern.ch/root/html/TRandom.html#TRandom:Rndm">Rndm</a>()-1)*(<a href=".././MCDiag.html#MCDiag:m_PhiSpread">m_PhiSpread</a>);
    if(newphi &lt; 0) newphi += 2*<a href="http://root.cern.ch/root/html/TMath.html#TMath:Pi">TMath::Pi</a>();
    if(newphi &gt; 2*<a href="http://root.cern.ch/root/html/TMath.html#TMath:Pi">TMath::Pi</a>()) newphi -= 2*<a href="http://root.cern.ch/root/html/TMath.html#TMath:Pi">TMath::Pi</a>();

    hepevt_.isthep[i] = 1;                // Status code
    hepevt_.idhep[i] = <a href=".././MCDiag.html#MCDiag:m_type">m_type</a>;            // Particle ID
    hepevt_.jmohep[i][0] = 0;             // index of mother
    hepevt_.phep[i][0] = newmag*sinth*<a href="http://root.cern.ch/root/html/TMath.html#TMath:Cos">TMath::Cos</a>(newphi);// x momentum
    hepevt_.phep[i][1] = newmag*sinth*<a href="http://root.cern.ch/root/html/TMath.html#TMath:Sin">TMath::Sin</a>(newphi);// y momentum
    hepevt_.phep[i][2] = newmag*newcth;// z momentum
    hepevt_.phep[i][4] = <a href=".././MCDiag.html#MCDiag:m_mass">m_mass</a>; 
    hepevt_.phep[i][3] = sqrt(newmag*newmag + 
			      hepevt_.phep[i][4]*hepevt_.phep[i][4]);
    hepevt_.vhep[i][0] = <a href=".././MCDiag.html#MCDiag:m_xpoint">m_xpoint</a>; // x position
    hepevt_.vhep[i][1] = <a href=".././MCDiag.html#MCDiag:m_ypoint">m_ypoint</a>; // y position
    hepevt_.vhep[i][2] = <a href=".././MCDiag.html#MCDiag:m_zpoint">m_zpoint</a>; // z position
    hepevt_.vhep[i][3] = <a href=".././MCDiag.html#MCDiag:m_prod_time">m_prod_time</a>; // production time
  }
  return(0);
}
<b>///_________________________________________________________________________</b>
<a name="MCDiag:spew"> </a><a href="../ListOfTypes.html#Int_t">Int_t</a> <a href=".././MCDiag.html#MCDiag:spew">MCDiag::spew</a>(<a href="../ListOfTypes.html#char">char</a>* ofile)const {
<b>    // Save the particle data into the hepevt common block</b>
<b>    // Write the common block out ot file using StdHepXdrWrite()</b>

  if(StdHepXdrWrite(<a href=".././MCDiag.html#MCDiag:ilbl">ilbl</a>,<a href=".././MCDiag.html#MCDiag:istr">istr</a>)){
    printf("Write failed.n");
    exit(1);
  }
  StdHepZero();
    return(0);
}
<b>///________________________________________________________________________</b>
<a name="MCDiag:cleanup"> </a><a href="../ListOfTypes.html#void">void</a> <a href=".././MCDiag.html#MCDiag:cleanup">MCDiag::cleanup</a>(){
<b>  // Closes the output stream.</b>
    StdHepXdrEnd(<a href=".././MCDiag.html#MCDiag:istr">istr</a>);
}


</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>
