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

In This Package:

Ge68.cc

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 #include <stdio.h>
00022 #include <iostream>
00023 
00024 #include <CLHEP/Vector/ThreeVector.h>
00025 #include <CLHEP/Random/Randomize.h>
00026 #include <CLHEP/Units/PhysicalConstants.h>
00027 #include <TRandom.h>
00028 #include <TMath.h>
00029 #include <TF1.h>
00030 #include <TH1.h>
00031 
00032 using namespace std;
00033 using namespace CLHEP;
00034 
00035 //a few hard-coded constants
00036 const double electronMass = 0.510998910e-3; //in GeV 
00037 const double Q_gs = 1.8991e-3; //in GeV
00038 const double Q_1st = 0.8218e-3; //in GeV
00039 const double E_gamma = 1.07735e-3; //in GeV
00040 
00041 Double_t dNdE(Double_t *x, Double_t *par)
00042 {
00043   // par[0] is the Q value in GeV
00044   // x[0] is electron energy with unit GeV
00045   Double_t KE = x[0];
00046   Double_t Q = par[0];
00047 
00048   Double_t Energy = KE + electronMass;
00049   Double_t p = sqrt(KE*(KE+2*electronMass));
00050 
00051   Double_t spec = (Q-KE)*(Q-KE)*Energy*p;
00052   return spec;
00053 }
00054 
00055 void ProcessArgs(int argc, char** argv, long* rseed, char** outfilename, 
00056                  unsigned int* nevents );
00057 void Usage(char* name);
00058 
00059 int main(int argc, char** argv) {
00060   long rseed = 0;
00061   char* outFilename = NULL;
00062   unsigned int nEvents = 1000000000; // a billion. Default to something big for piping 
00063   ProcessArgs(argc, argv, &rseed, &outFilename, &nEvents);
00064   
00065   FILE* stream = stdout;
00066   if( outFilename!=NULL ) {
00067     stream = fopen(outFilename, "w");
00068     if( stream==NULL ) {
00069       printf("Please enetr a valid filename.\n");
00070       Usage(argv[0]);
00071       exit(0);
00072     }
00073   }
00074 
00075   gRandom->SetSeed(rseed);
00076 
00077   //create beta spectrum function
00078   TF1* funcBetaEnergy = new TF1("funcBetaEnergy", dNdE, 0., 2e-3, 1);//GeV
00079 
00080 
00081   //HepRandom::setTheSeed(rseed);
00082   //start by printing some information to comment lines
00083   fprintf(stream, "# File generated by %s.\n", argv[0]);
00084   fprintf(stream, "# Random seed for generator = %ld.\n", rseed);
00085   
00086 
00087 
00088   //create a branch weighting table for random sampling
00089   TH1I *hBranching = new TH1I("hBranching","", 3, 0, 3);
00090   //See notes at the beginning of the code for the prob values below
00091   hBranching->SetBinContent(1,87.94);
00092   hBranching->SetBinContent(2,1.20);
00093   hBranching->SetBinContent(3,2.02);//lump EC 1st excited state with other cascade
00094   
00095   for( size_t i=0 ; i<nEvents ; i++ ) {
00096     Int_t ibranch = hBranching->FindBin(hBranching->GetRandom());
00097     double energyInGeV(0.0), momentumInGeV(0.0);
00098     double px = 0.0, py = 0.0, pz = 0.0;
00099     double phi = 0.0, theta = 0.0;
00100     
00101     if(ibranch==1){//ground state positron emission
00102       funcBetaEnergy->SetParameter(0, Q_gs);//Q value in GeV for G.S.
00103       energyInGeV=funcBetaEnergy->GetRandom();
00104       momentumInGeV = TMath::Sqrt(energyInGeV*energyInGeV
00105                                   +2.0*electronMass*energyInGeV);      
00106       phi= gRandom->Uniform(0.0,2.0*TMath::Pi());
00107       theta= acos(gRandom->Uniform(-1.0,1.0));
00108 
00109       px = cos(phi)*sin(theta)*momentumInGeV;
00110       py = sin(phi)*sin(theta)*momentumInGeV;
00111       pz = cos(theta)*momentumInGeV;
00112 
00113       fprintf(stream, "1\n");
00114       fprintf(stream, "1\t-11 0 0 %e %e %e %e\n", px, py, pz, electronMass); 
00115 
00116     } else if (ibranch==2) {//1st excited state, positron emission
00117       funcBetaEnergy->SetParameter(0, Q_1st);//Q value in GeV for 1st ES
00118       energyInGeV=funcBetaEnergy->GetRandom();
00119       momentumInGeV = TMath::Sqrt(energyInGeV*energyInGeV
00120                                   +2.0*electronMass*energyInGeV);      
00121       phi= gRandom->Uniform(0.0,2.0*TMath::Pi());
00122       theta= acos(gRandom->Uniform(-1.0,1.0));
00123 
00124       px = cos(phi)*sin(theta)*momentumInGeV;
00125       py = sin(phi)*sin(theta)*momentumInGeV;
00126       pz = cos(theta)*momentumInGeV;
00127 
00128       fprintf(stream, "2\n");
00129       fprintf(stream, "1\t-11 0 0 %e %e %e %e\n", px, py, pz, electronMass);      
00130       //now do the gamma, assuming no angular correlation with e+
00131       phi= gRandom->Uniform(0.0,2.0*TMath::Pi());
00132       theta= acos(gRandom->Uniform(-1.0,1.0));
00133       
00134       px = cos(phi)*sin(theta)*E_gamma;
00135       py = sin(phi)*sin(theta)*E_gamma;
00136       pz = cos(theta)*E_gamma;
00137       
00138       fprintf(stream, "1\t22 0 0 %e %e %e 0\n", px, py, pz); 
00139     } else if (ibranch==3) {//single gamma emission
00140       phi= gRandom->Uniform(0.0,2.0*TMath::Pi());
00141       theta= acos(gRandom->Uniform(-1.0,1.0));
00142       
00143       px = cos(phi)*sin(theta)*E_gamma;
00144       py = sin(phi)*sin(theta)*E_gamma;
00145       pz = cos(theta)*E_gamma;
00146       fprintf(stream, "1\n");
00147       fprintf(stream, "1\t22 0 0 %e %e %e 0\n", px, py, pz);
00148     }
00149     else {
00150       cout<<"Wrong branch ID. Ignored ..."<<endl;
00151     }
00152   }
00153   return 0;
00154 }
00155 
00156 
00157 void ProcessArgs(int argc, char** argv, long *rseed, 
00158                  char** outfilename, unsigned int* nevents) {
00159   int i;
00160   for( i=1 ; i<argc ; i++ ) {
00161     if( strcmp(argv[i], "-seed")==0 ) {
00162       i++;
00163       sscanf(argv[i], "%ld", rseed);
00164     } else if( strcmp(argv[i], "-o")==0 ) {
00165       i++;
00166       *outfilename = new char[strlen(argv[i]) +1];
00167       strcpy(*outfilename, argv[i]);
00168     } else if( strcmp(argv[i], "-n")==0 ) { 
00169       i++;
00170       sscanf(argv[i], "%ud", nevents);
00171     } else {
00172       Usage(argv[0]);
00173       exit(0);
00174     }
00175   }
00176 }
00177 
00178 void Usage(char* name) {
00179   printf("%s [-seed seed] [-o outputfilename] [-n nevents]\n", name);
00180 }
00181 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:06:58 2011 for Ge68 by doxygen 1.4.7