#include <cstdio>
#include <cstring>
#include <math.h>
#include <iostream>
#include "TMath.h"
#include <CLHEP/Vector/ThreeVector.h>
#include <CLHEP/Random/Randomize.h>
#include <CLHEP/Units/PhysicalConstants.h>
Include dependency graph for Potassium_40_gammas.cc:
Go to the source code of this file.
Namespaces | |
namespace | std |
namespace | CLHEP |
Classes | |
class | BetaDecay |
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 192 of file Potassium_40_gammas.cc.
00193 { 00194 int i; 00195 for( i=1 ; i<argc ; i++ ) { 00196 if( strcmp(argv[i], "-seed")==0 ) { 00197 i++; 00198 sscanf(argv[i], "%ld", rseed); 00199 } else if( strcmp(argv[i], "-o")==0 ) { 00200 i++; 00201 *outfilename = new char[strlen(argv[i]) +1]; 00202 strcpy(*outfilename, argv[i]); 00203 } else if( strcmp(argv[i], "-n")==0 ) { 00204 i++; 00205 sscanf(argv[i], "%ud", nevents); 00206 } else { 00207 Usage(); 00208 exit(0); 00209 } 00210 } 00211 }
void Usage | ( | ) |
int main | ( | int | argc, | |
char ** | argv | |||
) |
Definition at line 129 of file Potassium_40_gammas.cc.
00129 { 00130 long rseed = 0; 00131 char* outFilename = NULL; 00132 unsigned int nEvents = 1000000000; // a billion. Default to something big for piping 00133 ProcessArgs(argc, argv, &rseed, &outFilename, &nEvents); 00134 Hep3Vector p1; // the gamma momentum vector. Unit GeV/c 00135 Hep3Vector p2; // the electron momentum vector. Unit GeV/c 00136 00137 FILE* stream = stdout; 00138 if( outFilename!=NULL ) { 00139 stream = fopen(outFilename, "w"); 00140 if( stream==NULL ) { 00141 printf("Please enter a valid filename.\n"); 00142 Usage(); 00143 exit(0); 00144 } 00145 } 00146 HepRandom::setTheSeed(rseed); 00147 //start by printing some information to comment lines 00148 fprintf(stream, "# File generated by %s.\n", argv[0]); 00149 fprintf(stream, "# Ransom seed for generator = %ld.\n", rseed); 00150 00151 double cosTheta, theta, azimuth; // angles used 00152 unsigned int i; 00153 double bf; //K40 decay branching fraction 00154 for( i=0 ; i<nEvents ; i++ ) { 00155 cosTheta = RandFlat::shoot(-1., 1.); 00156 azimuth = RandFlat::shoot( 2.0*M_PI ); 00157 theta = acos(cosTheta); 00158 00159 bf = RandFlat::shoot(0.,1.); 00160 if(bf<0.107){ //10.7% gamma radiation 00161 p1.setRThetaPhi(1, theta, azimuth); 00162 p1*=1.461*MeV; 00163 fprintf(stream, "1\n"); 00164 fprintf(stream, "1\t22 0 0 %e %e %e 0.0\n", p1.x()/GeV, p1.y()/GeV, p1.z()/GeV ); 00165 } 00166 else{ //89.3% beta decay, maximum energy is 1.31 MeV. 00167 bool accept = 0; 00168 double emass = 0.51099892; 00169 while(!accept){ 00170 double rand1 = RandFlat::shoot(0.,1.31);//random energy 00171 double rand2 = RandFlat::shoot(0.,1.7);//1.7> spectrum max 00172 BetaDecay bd = BetaDecay(0,+20,1.31/emass,1.31/emass); 00173 if(bd.dnde(rand1/emass)>rand2) {//accept 00174 //rand1 is kinetic energy, now translate into momentum 00175 double momentum = sqrt((rand1+emass)*(rand1+emass)-emass*emass); 00176 p2.setRThetaPhi(1, theta, azimuth); 00177 p2*=momentum*MeV; 00178 00179 //electron PDG id is 11 00180 fprintf(stream, "1\n"); 00181 fprintf(stream, "1\t11 0 0 %e %e %e 0.51099892e-03\n", p2.x()/GeV, p2.y()/GeV, p2.z()/GeV ); 00182 00183 accept=1; 00184 } 00185 } 00186 } 00187 } 00188 return 0; 00189 }