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

In This Package:

AmCNeutronGen.cc

Go to the documentation of this file.
00001 // This is a HepEVT generator of AmC neutron 
00002 // // Modified from K-40 generator by Raymond Tsang, h0237236@hkusua.hku.hk, 30 Aug, 2006.
00003 
00004 //\author Jianglai Liu
00005 //jianglai.liu@sjtu.edu.cn, 16 Feb., 2011
00006 #include <cstdlib>
00007 #include <cstdio>
00008 #include <cstring>
00009 #include <iostream>
00010 #include <math.h>
00011 
00012 #include <CLHEP/Vector/ThreeVector.h>
00013 #include <CLHEP/Random/Randomize.h>
00014 #include <CLHEP/Units/PhysicalConstants.h>
00015 
00016 #include "TFile.h"
00017 #include "TH1.h"
00018 #include "TH2.h"
00019 #include "TCanvas.h"
00020 #include "TRandom.h"
00021 #include "TMath.h"
00022 
00023 using namespace std;
00024 using namespace CLHEP;
00025 
00026 void ProcessArgs(int argc, char** argv, long* rseed, char** outfilename, 
00027                  unsigned int* nevents );
00028 void Usage();
00029 
00030 
00031 int main(int argc, char** argv) {
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 }
00101 
00102 
00103 
00104 
00105 
00106 void ProcessArgs(int argc, char** argv, long *rseed, 
00107                  char** outfilename, unsigned int* nevents) {
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 }
00129 
00130 void Usage() {
00131   printf("AmCNeutron.exe [-seed seed] [-o outputfilename] [-n nevents]\n");
00132         
00133 }
00134 
00135 
| 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