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

In This Package:

N12DecayGen.cc

Go to the documentation of this file.
00001 // This is a HepEVT generator of N12 decay (resulting positrons & gammas). 
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 
00007 #include <cstdlib>
00008 #include <cstdio>
00009 #include <cstring>
00010 #include <iostream>
00011 #include <math.h>
00012 
00013 #include <CLHEP/Vector/ThreeVector.h>
00014 #include <CLHEP/Random/Randomize.h>
00015 #include <CLHEP/Units/PhysicalConstants.h>
00016 
00017 #include "TFile.h"
00018 #include "TH1F.h"
00019 #include "TCanvas.h"
00020 #include "TRandom.h"
00021 #include "TMath.h"
00022 
00023 using namespace std;
00024 using namespace CLHEP;
00025 
00026 void ProcessArgs(int argc, char** argv, long* rseed, char** outfilename, 
00027                  unsigned int* nevents );
00028 void Usage();
00029 
00030 
00031 int main(int argc, char** argv) {
00032   long rseed = 0;
00033   char* outFilename = NULL;
00034   unsigned int nEvents = 1000000000; // a billion. Default to something big for piping 
00035   ProcessArgs(argc, argv, &rseed, &outFilename, &nEvents);
00036   Hep3Vector p0; // the beta  momentum vector. Unit GeV/c
00037   Hep3Vector p1; // the gamma momentum vector. Unit GeV/c
00038   Hep3Vector p2; // the gamma momentum vector. Unit GeV/c
00039   
00040   FILE* stream = stdout;
00041   if( outFilename!=NULL ) {
00042     stream = fopen(outFilename, "w");
00043     if( stream==NULL ) {
00044       printf("Please enter a valid filename.\n");
00045       Usage();
00046       exit(0);
00047     }
00048   }
00049   HepRandom::setTheSeed(rseed);
00050    gRandom->SetSeed(rseed);
00051   //start by printing some information to comment lines
00052   fprintf(stream, "# File generated by %s.\n", argv[0]);
00053   fprintf(stream, "# Random seed for generator = %ld.\n", rseed);
00054   
00055 
00056 // The root file used by this generator should be located at 
00057 // $SITEROOT/dybgaudi/Generators/RadioActivity/N12/
00058     std::string specfilename = "N12BetaSpectrum.root";
00059     const char* prefix = getenv("SITEROOT");
00060     if(prefix) {
00061         if(strlen(prefix)>0) {
00062             std::string newname = prefix;
00063             newname += "/dybgaudi/Generators/RadioActivity/N12/";
00064             newname += specfilename;
00065             specfilename = newname;
00066         }
00067     }
00068 
00069 
00070 //cout<<specfilename<<endl;
00071 
00072   TFile  *betaSpec = TFile::Open(specfilename.c_str());
00073 
00074     if(!betaSpec)
00075         cout << "Can not open N12BetaSpectrum.root. "
00076                << "Make sure SITEROOT or N12BetaSpectrum.root is set to it's location."
00077                << "rootfile location is at $SITEROOT/dybgaudi/Generators/RadioActivity/N12/" << endl;
00078     if(!(betaSpec->IsOpen()))
00079         cout << "Can not open N12BetaSpectrum.root "
00080                << "Make sure SITEROOT is set to it's location."
00081                << "rootfile location is at $SITEROOT/dybgaudi/Generators/RadioActivity/N12/" << endl;
00082 
00083   double cosTheta, theta, azimuth; // angles used
00084   unsigned int i;
00085 
00086   TH1F *h0 = (TH1F*)betaSpec->Get("N12B0");
00087   TH1F *h1 = (TH1F*)betaSpec->Get("N12B1");
00088   TH1F *h2 = (TH1F*)betaSpec->Get("N12B2");
00089   
00090   for( i=0 ; i<nEvents ; i++ ) {
00091 
00092     if(RandFlat::shoot()<0.027) { //beta & gamma 
00093       cosTheta = RandFlat::shoot(-1, 1);
00094       azimuth = RandFlat::shoot( 2.0*M_PI );
00095       theta = acos(cosTheta);
00096       p0.setRThetaPhi(1, acos(cosTheta), azimuth);
00097 
00098       cosTheta = RandFlat::shoot(-1, 1);
00099       azimuth = RandFlat::shoot( 2.0*M_PI );
00100       theta = acos(cosTheta);
00101       p1.setRThetaPhi(1, acos(cosTheta), azimuth);
00102 
00103       cosTheta = RandFlat::shoot(-1, 1);
00104       azimuth = RandFlat::shoot( 2.0*M_PI );
00105       theta = acos(cosTheta);
00106       p2.setRThetaPhi(1, acos(cosTheta), azimuth);
00107       
00108       double ke = h2->GetRandom();
00109       double pe = sqrt(ke*ke + 2*ke*electron_mass_c2/keV);
00110 
00111       p0=p0*pe*keV;
00112       p1*=3.21483*MeV;
00113       p2*=4.43803*MeV;
00114       fprintf(stream, "3\n");
00115       fprintf(stream, "1\t-11 0 0 %e %e %e %e\n", p0.x()/GeV, p0.y()/GeV, p0.z()/GeV, electron_mass_c2/GeV );
00116       fprintf(stream, "1\t22 0 0 %e %e %e 0.0\n", p1.x()/GeV, p1.y()/GeV, p1.z()/GeV );
00117       fprintf(stream, "1\t22 0 0 %e %e %e 0.0\n", p2.x()/GeV, p2.y()/GeV, p2.z()/GeV );
00118 
00119     }
00120     else if(RandFlat::shoot()>=0.027 && RandFlat::shoot()<0.046) {                  // beta & gamma
00121       cosTheta = RandFlat::shoot(-1, 1);
00122       azimuth = RandFlat::shoot( 2.0*M_PI );
00123       theta = acos(cosTheta);
00124       p0.setRThetaPhi(1, acos(cosTheta), azimuth);
00125 
00126 
00127       cosTheta = RandFlat::shoot(-1, 1);
00128       azimuth = RandFlat::shoot( 2.0*M_PI );
00129       theta = acos(cosTheta);
00130       p2.setRThetaPhi(1, acos(cosTheta), azimuth);
00131       
00132       
00133       double ke = h1->GetRandom();
00134       double pe = sqrt(ke*ke + 2*ke*electron_mass_c2/keV);
00135 
00136       p0=p0*pe*keV;
00137       p2*=4.43803*MeV;
00138       fprintf(stream, "2\n");
00139       fprintf(stream, "1\t-11 0 0 %e %e %e %e\n", p0.x()/GeV, p0.y()/GeV, p0.z()/GeV, electron_mass_c2/GeV );
00140       fprintf(stream, "1\t22 0 0 %e %e %e 0.0\n", p2.x()/GeV, p2.y()/GeV, p2.z()/GeV );
00141     }
00142     
00143     else {
00144       cosTheta = RandFlat::shoot(-1, 1);
00145       azimuth = RandFlat::shoot( 2.0*M_PI );
00146       theta = acos(cosTheta);
00147       p0.setRThetaPhi(1, acos(cosTheta), azimuth);
00148 
00149       double ke = h0->GetRandom();
00150       double pe = sqrt(ke*ke + 2*ke*electron_mass_c2/keV);
00151       p0=p0*pe*keV;
00152       fprintf(stream, "1\n");
00153       fprintf(stream, "1\t-11 0 0 %e %e %e %e\n", p0.x()/GeV, p0.y()/GeV, p0.z()/GeV, electron_mass_c2/GeV );
00154     
00155     }
00156   }
00157 
00158 
00159   return 0;
00160 }
00161 
00162 
00163 
00164 
00165 
00166 void ProcessArgs(int argc, char** argv, long *rseed, 
00167                                  char** outfilename, unsigned int* nevents) {
00168         int i;
00169         for( i=1 ; i<argc ; i++ ) {
00170                 if( strcmp(argv[i], "-seed")==0 ) {
00171                         i++;
00172                         sscanf(argv[i], "%ld", rseed);
00173                                                   }
00174                  else if( strcmp(argv[i], "-o")==0 ) {
00175                         i++;
00176                         *outfilename = new char[strlen(argv[i]) +1];
00177                         strcpy(*outfilename, argv[i]);
00178                                                      } 
00179                 else if( strcmp(argv[i], "-n")==0 ) { 
00180                         i++;
00181                         sscanf(argv[i], "%ud", nevents);
00182                                                     }  
00183                 else {
00184                         Usage();
00185                         exit(0);
00186                      }
00187                                    }
00188 }
00189 
00190 void Usage() {
00191         printf("N12.exe [-seed seed] [-o outputfilename] [-n nevents]\n");
00192 
00193 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:06:35 2011 for N12 by doxygen 1.4.7