#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 "TH1F.h"#include "TCanvas.h"#include "TRandom.h"#include "TMath.h"Include dependency graph for Li8DecayGen.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) |
| void ProcessArgs | ( | int | argc, | |
| char ** | argv, | |||
| long * | rseed, | |||
| char ** | outfilename, | |||
| unsigned int * | nevents | |||
| ) |
Definition at line 122 of file Li8DecayGen.cc.
00123 { 00124 int i; 00125 for( i=1 ; i<argc ; i++ ) { 00126 if( strcmp(argv[i], "-seed")==0 ) { 00127 i++; 00128 sscanf(argv[i], "%ld", rseed); 00129 } 00130 else if( strcmp(argv[i], "-o")==0 ) { 00131 i++; 00132 *outfilename = new char[strlen(argv[i]) +1]; 00133 strcpy(*outfilename, argv[i]); 00134 } 00135 else if( strcmp(argv[i], "-n")==0 ) { 00136 i++; 00137 sscanf(argv[i], "%ud", nevents); 00138 } 00139 else { 00140 Usage(); 00141 exit(0); 00142 } 00143 } 00144 }
| void Usage | ( | ) |
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 31 of file Li8DecayGen.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 alpha 1 momentum vector. Unit GeV/c 00038 00039 FILE* stream = stdout; 00040 if( outFilename!=NULL ) { 00041 stream = fopen(outFilename, "w"); 00042 if( stream==NULL ) { 00043 printf("Please enter a valid filename.\n"); 00044 Usage(); 00045 exit(0); 00046 } 00047 } 00048 HepRandom::setTheSeed(rseed); 00049 gRandom->SetSeed(rseed); 00050 //start by printing some information to comment lines 00051 fprintf(stream, "# File generated by %s.\n", argv[0]); 00052 fprintf(stream, "# Random seed for generator = %ld.\n", rseed); 00053 00054 00055 00056 // The root file used by this generator should be located at 00057 // $SITEROOT/dybgaudi/Generators/RadioActivity/Li8/ 00058 std::string specfilename = "Li8BetaSpectrum.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/Li8/"; 00064 newname += specfilename; 00065 specfilename = newname; 00066 } 00067 } 00068 00069 00070 //cout<<specfilename<<endl; 00071 00072 TFile *betaSpec = TFile::Open(specfilename.c_str()); 00073 00074 if(!betaSpec) 00075 cout << "Can not open Li8BetaSpectrum.root. " 00076 << "Make sure SITEROOT or Li8BetaSpectrum.root is set to it's location." 00077 << "rootfile location is at $SITEROOT/dybgaudi/Generators/RadioActivity/Li8/" << endl; 00078 if(!(betaSpec->IsOpen())) 00079 cout << "Can not open Li8BetaSpectrum.root " 00080 << "Make sure SITEROOT is set to it's location." 00081 << "rootfile location is at $SITEROOT/dybgaudi/Generators/RadioActivity/Li8/" << endl; 00082 00083 double cosTheta, theta, azimuth; // angles used 00084 unsigned int i; 00085 00086 TH1F *h0 = (TH1F*)betaSpec->Get("Li8"); 00087 00088 for( i=0 ; i<nEvents ; i++ ) { 00089 00090 cosTheta = RandFlat::shoot(-1, 1); 00091 azimuth = RandFlat::shoot( 2.0*M_PI ); 00092 theta = acos(cosTheta); 00093 p0.setRThetaPhi(1, acos(cosTheta), azimuth); 00094 00095 cosTheta = RandFlat::shoot(-1, 1); 00096 azimuth = RandFlat::shoot( 2.0*M_PI ); 00097 theta = acos(cosTheta); 00098 p1.setRThetaPhi(1, acos(cosTheta), azimuth); 00099 00100 const double alpha_mass_c2=3727.0*MeV; 00101 double ke = h0->GetRandom(); 00102 double ka =1.513*MeV/keV; 00103 double pe = sqrt(ke*ke + 2*ke*electron_mass_c2/keV); 00104 double pa = sqrt(ka*ka + 2*ka*alpha_mass_c2/keV); 00105 p0=p0*pe*keV; 00106 p1=p1*pa*keV; 00107 fprintf(stream, "3\n"); 00108 fprintf(stream, "1\t11 0 0 %e %e %e %e\n", p0.x()/GeV, p0.y()/GeV, p0.z()/GeV, electron_mass_c2/GeV ); 00109 fprintf(stream, "1\t1000020040 0 0 %e %e %e %e\n", p1.x()/GeV, p1.y()/GeV, p1.z()/GeV,alpha_mass_c2/GeV ); 00110 fprintf(stream, "1\t1000020040 0 0 %e %e %e %e\n", -p1.x()/GeV, -p1.y()/GeV, -p1.z()/GeV,alpha_mass_c2/GeV ); 00111 00112 } 00113 00114 00115 return 0; 00116 }
1.4.7