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

In This Package:

Cobalt_60_gammas.cc

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 #include <cstdio>
00010 #include <cstdlib>
00011 #include <cstring>
00012 #include <iostream>
00013 
00014 #include <CLHEP/Vector/ThreeVector.h>
00015 #include <CLHEP/Random/Randomize.h>
00016 #include <CLHEP/Units/PhysicalConstants.h>
00017 
00018 
00019 using namespace std;
00020 using namespace CLHEP;
00021 
00022 void ProcessArgs(int argc, char** argv, long* rseed, char** outfilename, 
00023                  unsigned int* nevents );
00024 void Usage();
00025 
00026 
00027 int main(int argc, char** argv) {
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 }
00083 
00084 
00085 void ProcessArgs(int argc, char** argv, long *rseed, 
00086                  char** outfilename, unsigned int* nevents) {
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 }
00105 
00106 void Usage() {
00107   printf("Cobalt-60-gammas [-seed seed] [-o outputfilename] [-n nevents]\n");
00108 }
00109 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:07:01 2011 for Co60 by doxygen 1.4.7