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

In This Package:

C11DecayGen.cc File Reference

#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 C11DecayGen.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)

Function Documentation

void ProcessArgs ( int  argc,
char **  argv,
long *  rseed,
char **  outfilename,
unsigned int *  nevents 
)

Definition at line 107 of file C11DecayGen.cc.

00108                                                             {
00109   int i;
00110   for( i=1 ; i<argc ; i++ ) {
00111     if( strcmp(argv[i], "-seed")==0 ) {
00112       i++;
00113       sscanf(argv[i], "%ld", rseed);
00114     } else if( strcmp(argv[i], "-o")==0 ) {
00115       i++;
00116       *outfilename = new char[strlen(argv[i]) +1];
00117       strcpy(*outfilename, argv[i]);
00118     } else if( strcmp(argv[i], "-n")==0 ) { 
00119       i++;
00120       sscanf(argv[i], "%ud", nevents);
00121     } else {
00122       Usage();
00123       exit(0);
00124     }
00125   }
00126 }

void Usage (  ) 

Definition at line 128 of file C11DecayGen.cc.

00128              {
00129   printf("C11.exe [-seed seed] [-o outputfilename] [-n nevents]\n");
00130 }

int main ( int  argc,
char **  argv 
)

Definition at line 30 of file C11DecayGen.cc.

00030                                 {
00031   long rseed = 0;
00032   char* outFilename = NULL;
00033   unsigned int nEvents = 1000000000; // a billion. Default to something big for piping 
00034   ProcessArgs(argc, argv, &rseed, &outFilename, &nEvents);
00035   Hep3Vector p1; // the gamma momentum vector. Unit GeV/c
00036   
00037   FILE* stream = stdout;
00038   if( outFilename!=NULL ) {
00039     stream = fopen(outFilename, "w");
00040     if( stream==NULL ) {
00041       printf("Please enter a valid filename.\n");
00042       Usage();
00043       exit(0);
00044     }
00045   }
00046   HepRandom::setTheSeed(rseed);
00047    gRandom->SetSeed(rseed);
00048   //start by printing some information to comment lines
00049   fprintf(stream, "# File generated by %s.\n", argv[0]);
00050   fprintf(stream, "# Random seed for generator = %ld.\n", rseed);
00051 
00052 
00053 // The root file used by this generator should be located at 
00054 // $SITEROOT/dybgaudi/Generators/RadioActivity/C11/
00055     std::string specfilename = "C11BetaSpectrum.root";
00056     const char* prefix = getenv("SITEROOT");
00057     if(prefix) {
00058         if(strlen(prefix)>0) {
00059             std::string newname = prefix;
00060             newname += "/dybgaudi/Generators/RadioActivity/C11/";
00061             newname += specfilename;
00062             specfilename = newname;
00063         }
00064     }
00065 
00066 
00067 //cout<<specfilename<<endl;
00068 
00069   TFile  *betaSpec = TFile::Open(specfilename.c_str());
00070 
00071     if(!betaSpec)
00072         cout << "Can not open C11BetaSpectrum.root. "
00073                << "Make sure SITEROOT or C11BetaSpectrum.root is set to it's location."
00074                << "rootfile location is at $SITEROOT/dybgaudi/Generators/RadioActivity/C11/" << endl;
00075     if(!(betaSpec->IsOpen()))
00076         cout << "Can not open C11BetaSpectrum.root "
00077                << "Make sure SITEROOT is set to it's location."
00078                << "rootfile location is at $SITEROOT/dybgaudi/Generators/RadioActivity/C11/" << endl;
00079 
00080 
00081 
00082   double cosTheta, theta, azimuth; // angles used
00083   unsigned int i;
00084 
00085   TH1F *h1 = (TH1F*)betaSpec->Get("C11");
00086   
00087   for( i=0 ; i<nEvents ; i++ ) {
00088 
00089       cosTheta = RandFlat::shoot(-1, 1);
00090       azimuth = RandFlat::shoot( 2.0*M_PI );
00091       theta = acos(cosTheta);
00092       p1.setRThetaPhi(1, acos(cosTheta), azimuth);
00093 
00094       double ke = h1->GetRandom();
00095       double pe = sqrt(ke*ke + 2*ke*electron_mass_c2/keV);
00096       p1=p1*pe*keV;
00097       fprintf(stream, "1\n");
00098      fprintf(stream, "1\t-11 0 0 %e %e %e %e\n", p1.x()/GeV, p1.y()/GeV, p1.z()/GeV, electron_mass_c2/GeV); 
00099 
00100   
00101   }
00102 
00103   return 0;
00104 }

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

Generated on Mon Apr 11 20:06:37 2011 for C11 by doxygen 1.4.7