#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <CLHEP/Vector/ThreeVector.h>#include <CLHEP/Random/Randomize.h>#include <CLHEP/Units/PhysicalConstants.h>Include dependency graph for Cobalt_60_gammas.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 85 of file Cobalt_60_gammas.cc.
00086 { 00087 int i; 00088 for( i=1 ; i<argc ; i++ ) { 00089 if( strcmp(argv[i], "-seed")==0 ) { 00090 i++; 00091 sscanf(argv[i], "%ld", rseed); 00092 } else if( strcmp(argv[i], "-o")==0 ) { 00093 i++; 00094 *outfilename = new char[strlen(argv[i]) +1]; 00095 strcpy(*outfilename, argv[i]); 00096 } else if( strcmp(argv[i], "-n")==0 ) { 00097 i++; 00098 sscanf(argv[i], "%ud", nevents); 00099 } else { 00100 Usage(); 00101 exit(0); 00102 } 00103 } 00104 }
| void Usage | ( | ) |
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 27 of file Cobalt_60_gammas.cc.
00027 { 00028 long rseed = 0; 00029 char* outFilename = NULL; 00030 unsigned int nEvents = 1000000000; // a billion. Default to something big for piping 00031 ProcessArgs(argc, argv, &rseed, &outFilename, &nEvents); 00032 Hep3Vector p1, p2; // the two gamma momentum vectors. Unit GeV/c 00033 00034 FILE* stream = stdout; 00035 if( outFilename!=NULL ) { 00036 stream = fopen(outFilename, "w"); 00037 if( stream==NULL ) { 00038 printf("Please enetr a valid filename.\n"); 00039 Usage(); 00040 exit(0); 00041 } 00042 } 00043 HepRandom::setTheSeed(rseed); 00044 //start by printing some information to comment lines 00045 fprintf(stream, "# File generated by %s.\n", argv[0]); 00046 fprintf(stream, "# Ransom seed for generator = %ld.\n", rseed); 00047 00048 00049 double cosTheta, cth2, theta, azimuth; // angles used 00050 bool ok; 00051 double rejectVariable; 00052 unsigned int i; 00053 00054 for( i=0 ; i<nEvents ; i++ ) { 00055 p1.setX(0); p1.setY(0); p1.setZ(1); 00056 ok = false; 00057 while( !ok ) { 00058 cosTheta = RandFlat::shoot(-1, 1); 00059 cth2 = cosTheta * cosTheta; 00060 rejectVariable = RandFlat::shoot(1.167); 00061 if( rejectVariable < (1 + 0.125*cth2 + 0.042*cth2*cth2) ) ok = true; 00062 } 00063 azimuth = RandFlat::shoot( 2.0*M_PI ); 00064 p2.setRThetaPhi(1, acos(cosTheta), azimuth); 00065 // p1 and p2 have correct angu;ar correlation. Rotate them randomly 00066 cosTheta = RandFlat::shoot(-1, 1); 00067 theta = acos(cosTheta); 00068 p1.rotateY(theta); 00069 p2.rotateY(theta); 00070 azimuth = RandFlat::shoot( 2.0*M_PI ); 00071 p1.rotateZ(azimuth); 00072 p2.rotateZ(azimuth); 00073 p1 *= 1.173237e-3*GeV; // GeV 00074 p2 *= 1.332501e-3*GeV; // GeV 00075 00076 fprintf(stream, "2\n"); 00077 fprintf(stream, "1\t22 0 0 %e %e %e 0.0\n", p1.x()/GeV, p1.y()/GeV, p1.z()/GeV ); 00078 fprintf(stream, "1\t22 0 0 %e %e %e 0.0\n", p2.x()/GeV, p2.y()/GeV, p2.z()/GeV ); 00079 00080 } 00081 return 0; 00082 }
1.4.7