00001
00002
00003
00004
00005
00006
00007 #include <cstdlib>
00008 #include <cstdio>
00009 #include <cstring>
00010 #include <iostream>
00011 #include <math.h>
00012
00013 #include <CLHEP/Vector/ThreeVector.h>
00014 #include <CLHEP/Random/Randomize.h>
00015 #include <CLHEP/Units/PhysicalConstants.h>
00016
00017 #include "TFile.h"
00018 #include "TH1F.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;
00035 ProcessArgs(argc, argv, &rseed, &outFilename, &nEvents);
00036 Hep3Vector p0;
00037 Hep3Vector p1;
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
00051 fprintf(stream, "# File generated by %s.\n", argv[0]);
00052 fprintf(stream, "# Random seed for generator = %ld.\n", rseed);
00053
00054
00055
00056
00057
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
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;
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 }
00117
00118
00119
00120
00121
00122 void ProcessArgs(int argc, char** argv, long *rseed,
00123 char** outfilename, unsigned int* nevents) {
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 }
00145
00146 void Usage() {
00147 printf("Li8.exe [-seed seed] [-o outputfilename] [-n nevents]\n");
00148
00149 }