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

In This Package:

C11DecayGen.cc

Go to the documentation of this file.
00001 // This is a HepEVT generator of C11 beta+ decay (resulting positrons  ). 
00002 // // Modified from K-40 generator by Raymond Tsang, h0237236@hkusua.hku.hk, 30 Aug, 2006.
00003 // //
00004 // // //\author Fengpeng An
00005 // // //anfp@ihep.ac.cn, 8 Nov., 2009
00006 #include <cstdlib>
00007 #include <cstdio>
00008 #include <cstring>
00009 #include <iostream>
00010 #include <math.h>
00011 
00012 #include <CLHEP/Vector/ThreeVector.h>
00013 #include <CLHEP/Random/Randomize.h>
00014 #include <CLHEP/Units/PhysicalConstants.h>
00015 
00016 #include "TFile.h"
00017 #include "TH1F.h"
00018 #include "TCanvas.h"
00019 #include "TRandom.h"
00020 #include "TMath.h"
00021 
00022 using namespace std;
00023 using namespace CLHEP;
00024 
00025 void ProcessArgs(int argc, char** argv, long* rseed, char** outfilename, 
00026                  unsigned int* nevents );
00027 void Usage();
00028 
00029 
00030 int main(int argc, char** argv) {
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 }
00105 
00106 
00107 void ProcessArgs(int argc, char** argv, long *rseed, 
00108                  char** outfilename, unsigned int* nevents) {
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 }
00127 
00128 void Usage() {
00129   printf("C11.exe [-seed seed] [-o outputfilename] [-n nevents]\n");
00130 }
00131 
| 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