| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

AmCNeutronGen.cc File Reference

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <CLHEP/Vector/ThreeVector.h>
#include <CLHEP/Random/Randomize.h>
#include <CLHEP/Units/PhysicalConstants.h>
#include "TFile.h"
#include "TH1.h"
#include "TH2.h"
#include "TCanvas.h"
#include "TRandom.h"
#include "TMath.h"

Include dependency graph for AmCNeutronGen.cc:

Go to the source code of this file.


Namespaces

namespace  std
namespace  CLHEP

Functions

void ProcessArgs (int argc, char **argv, long *rseed, char **outfilename, unsigned int *nevents)
void Usage ()
int main (int argc, char **argv)

Function Documentation

void ProcessArgs ( int  argc,
char **  argv,
long *  rseed,
char **  outfilename,
unsigned int *  nevents 
)

Definition at line 106 of file AmCNeutronGen.cc.

00107                                                             {
00108   int i;
00109   for( i=1 ; i<argc ; i++ ) {
00110     if( strcmp(argv[i], "-seed")==0 ) {
00111       i++;
00112       sscanf(argv[i], "%ld", rseed);
00113     }
00114     else if( strcmp(argv[i], "-o")==0 ) {
00115       i++;
00116       *outfilename = new char[strlen(argv[i]) +1];
00117       strcpy(*outfilename, argv[i]);
00118     } 
00119     else if( strcmp(argv[i], "-n")==0 ) { 
00120       i++;
00121       sscanf(argv[i], "%ud", nevents);
00122     }  
00123     else {
00124       Usage();
00125       exit(0);
00126     }
00127   }
00128 }

void Usage (  ) 

Definition at line 130 of file AmCNeutronGen.cc.

00130              {
00131   printf("AmCNeutron.exe [-seed seed] [-o outputfilename] [-n nevents]\n");
00132         
00133 }

int main ( int  argc,
char **  argv 
)

Definition at line 31 of file AmCNeutronGen.cc.

00031                                 {
00032   long rseed = 0;
00033   char* outFilename = NULL;
00034   unsigned int nEvents = 1000000000; // a billion. Default to something big for piping 
00035   ProcessArgs(argc, argv, &rseed, &outFilename, &nEvents);
00036   Hep3Vector p0; // the beta  momentum vector. Unit GeV/c
00037   Hep3Vector p1; // the gamma momentum vector. Unit GeV/c
00038   Hep3Vector p2; // the gamma momentum vector. Unit GeV/c
00039   
00040   FILE* stream = stdout;
00041   if( outFilename!=NULL ) {
00042     stream = fopen(outFilename, "w");
00043     if( stream==NULL ) {
00044       printf("Please enter a valid filename.\n");
00045       Usage();
00046       exit(0);
00047     }
00048   }
00049   HepRandom::setTheSeed(rseed);
00050   gRandom->SetSeed(rseed);
00051   //start by printing some information to comment lines
00052   fprintf(stream, "# File generated by %s.\n", argv[0]);
00053   fprintf(stream, "# Ransom seed for generator = %ld.\n", rseed);
00054   
00055 
00056   // The root file used by this generator should be located at 
00057   // $SITEROOT/dybgaudi/Generators/RadioActivity/AmC/
00058   std::string specfilename = "AmC_neutron.root";
00059   const char* prefix = getenv("SITEROOT");
00060   if(prefix) {
00061     if(strlen(prefix)>0) {
00062       std::string newname = prefix;
00063       newname += "/dybgaudi/Generators/RadioActivity/AmC/";
00064       newname += specfilename;
00065       specfilename = newname;
00066     }
00067   }
00068   
00069 
00070   //cout<<specfilename<<endl;
00071 
00072   TFile  *rootFile = TFile::Open(specfilename.c_str());
00073   
00074   if(!rootFile)
00075     cout << "Can not open "<<specfilename.c_str()<<". "
00076          << "Make sure SITEROOT or AmC_neutron.root is set to it's location."
00077          << "rootfile location is at $SITEROOT/dybgaudi/Generators/RadioActivity/AmC/" << endl;
00078   if(!(rootFile->IsOpen()))
00079     cout << "Can not open  AmC_neutron.root. "
00080          << "Make sure SITEROOT is set to it's location."
00081          << "rootfile location is at $SITEROOT/dybgaudi/Generators/RadioActivity/AmC/" << endl;
00082   
00083   TH2F *h2 = (TH2F*)rootFile->Get("hEnergyAngle");
00084   
00085   double Tn(0);
00086   double cosTheta(0), theta(0), azimuth(0); // angles used
00087   Hep3Vector pn; // neutron momentum vector. Unit GeV/c
00088   for( int i=0 ; i<nEvents ; i++ ) {
00089     h2->GetRandom2(cosTheta, Tn);
00090     Tn *= MeV;
00091     azimuth = RandFlat::shoot( 2.0*M_PI );
00092     double momentum = sqrt(Tn*Tn + 2*Tn*neutron_mass_c2);
00093     
00094     pn.setRThetaPhi(momentum, acos(cosTheta), azimuth);
00095     
00096     fprintf(stream, "1\n");
00097     fprintf(stream, "1\t2112 0 0 %e %e %e %e\n", pn.x()/GeV, pn.y()/GeV, pn.z()/GeV, neutron_mass_c2/GeV );
00098   }
00099   return 0;
00100 }

| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:06:32 2011 for AmC by doxygen 1.4.7