Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

MJGeneratorUtil.cc

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------//
00002 //bb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nu//
00003 //                                                                           //
00004 //                         MAJORANA Simulation                               //
00005 //                                                                           //
00006 //      This code implementation is the intellectual property of the         //
00007 //      MAJORANA Collaboration. It is based on Geant4, an intellectual       //
00008 //      property of the RD44 GEANT4 collaboration.                           //
00009 //                                                                           //
00010 //                        *********************                              //
00011 //                                                                           //
00012 //    Neither the authors of this software system, nor their employing       //
00013 //    institutes, nor the agencies providing financial support for this      //
00014 //    work  make  any representation or  warranty, express or implied,       //
00015 //    regarding this software system or assume any liability for its use.    //
00016 //    By copying, distributing or modifying the Program (or any work based   //
00017 //    on on the Program) you indicate your acceptance of this statement,     //
00018 //    and all its terms.                                                     //
00019 //                                                                           //
00020 //bb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nu//
00021 //---------------------------------------------------------------------------//
00022 //
00023 // $Id: MJGeneratorUtil.cc,v 1.1 2004/11/22 13:07:41 gast Exp $
00024 //
00025 // CLASS IMPLEMENTATION:  MJGeneratorUtil.cc
00026 //---------------------------------------------------------------------------//
00036 // --------------------------------------------------------------------------//
00037 
00038 #include "generators/MJGeneratorUtil.hh"
00039 
00040 MJGeneratorUtil::MJGeneratorUtil()
00041 {;}
00042 
00043 MJGeneratorUtil::~MJGeneratorUtil()
00044 {;}
00045 
00046 G4ThreeVector MJGeneratorUtil::pick_isotropic() 
00047 {
00048   G4double phi       = twopi * G4UniformRand();
00049   G4double cos_theta = -1.0 + 2.0*G4UniformRand();
00050   G4double theta     = acos(cos_theta);
00051   G4double sin_theta = sin(theta);
00052   G4double cos_x     = sin_theta*cos(phi);
00053   G4double cos_y     = sin_theta*sin(phi);
00054   G4double cos_z     = cos_theta;
00055 
00056   G4ThreeVector direction(cos_x,cos_y,cos_z);
00057 
00058   return direction;
00059 }
00060 
00061 G4ThreeVector MJGeneratorUtil::pick_point_in_box(G4double x_lo, G4double x_hi,
00062                                 G4double y_lo, G4double y_hi,
00063                                 G4double z_lo, G4double z_hi) {
00064   G4double dx = x_hi - x_lo;
00065   G4double dy = y_hi - y_lo;
00066   G4double dz = z_hi - z_lo;
00067 
00068   G4double x = x_lo + dx*G4UniformRand();
00069   G4double y = y_lo + dy*G4UniformRand();
00070   G4double z = z_lo + dz*G4UniformRand();
00071 
00072   G4ThreeVector pos(x,y,z);
00073 
00074   return pos;
00075 }
00076  
00077 //*************************************************************************
00078 void MJGeneratorUtil::pick_point_in_circle(G4double Radius, G4double &x, G4double &y) {
00079 
00080   G4double b     = Radius*Radius;
00081   G4double x_rnd = G4UniformRand();
00082   G4double r     = sqrt(b*x_rnd);
00083   G4double phi   = twopi * G4UniformRand();
00084 
00085   x = r*cos(phi);
00086   y = r*sin(phi);
00087 }
00088 
00089 //*************************************************************************
00090 G4ThreeVector MJGeneratorUtil::pick_point_in_annulus(G4double r1, G4double r2, G4double h) 
00091 {
00092   G4double a = r1*r1;
00093   G4double b = r2*r2 - a;
00094 
00095   G4double x_rnd = G4UniformRand();
00096   G4double r = sqrt(b*x_rnd + a);
00097 
00098   G4double phi = twopi * G4UniformRand();
00099 
00100   G4double x = r * cos(phi);
00101   G4double y = r * sin(phi);
00102 
00103   G4double z = h * (-0.5 + G4UniformRand());
00104 
00105   G4ThreeVector pos(x,y,z);
00106 
00107   return pos;
00108 
00109 }
00110 //*************************************************************************
00111 G4ThreeVector MJGeneratorUtil::pick_point_in_annulus(G4double r1, G4double r2, G4double h,
00112                                     G4double theta0, G4double dtheta) {
00113 
00114   G4double a = r1*r1;
00115   G4double b = r2*r2 - a;
00116 
00117   G4double x_rnd = G4UniformRand();
00118   G4double r = sqrt(b*x_rnd + a);
00119 
00120   G4double phi = theta0 + dtheta * G4UniformRand();
00121 
00122   G4double x = r * cos(phi);
00123   G4double y = r * sin(phi);
00124 
00125   G4double z = h * (-0.5 + G4UniformRand());
00126 
00127   G4ThreeVector pos(x,y,z);
00128 
00129   return pos;
00130 
00131 }
00132 
00133 //*************************************************************************
00134 G4ThreeVector MJGeneratorUtil::pick_point_in_cylinder(G4double R, G4double L) {
00135 
00136   return pick_point_in_annulus(0.0, R, L);
00137 
00138 }
00139 
00140 //*************************************************************************
00141 G4ThreeVector MJGeneratorUtil::pick_point_on_cylinder(G4double R, G4double L) 
00142 {
00143   G4double phi = twopi * G4UniformRand();
00144   G4double x = R*cos(phi);
00145   G4double y = R*sin(phi);
00146 
00147   G4double z = L * (-0.5 + G4UniformRand());
00148 
00149   G4ThreeVector pos(x,y,z);
00150 
00151   return pos;
00152 }
00153 
00154 
00155 //*************************************************************************
00156 G4ThreeVector MJGeneratorUtil::pick_point_in_shell(G4double r1, G4double r2) 
00157 {
00158   const G4double ONE_THIRD = 1.0/3.0;
00159 
00160   G4double r1_3 = pow(r1,3);
00161   G4double r2_3 = pow(r2,3);
00162   G4double d    = r2_3 - r1_3;
00163 
00164   G4double x_rnd = r1_3 + d * G4UniformRand();
00165   G4double r = pow(x_rnd,ONE_THIRD);
00166 
00167   return r*pick_isotropic();
00168 }
00169 
00170 //*************************************************************************
00171 G4ThreeVector MJGeneratorUtil::pick_point_in_sphere(G4double r) 
00172 {
00173   return pick_point_in_shell(0.0, r);
00174 }
00175 
00176 //*************************************************************************
00177 G4ThreeVector MJGeneratorUtil::pick_point_on_sphere(G4double r) 
00178 {
00179   return r*pick_isotropic();
00180 }
00181 

Generated on Mon Nov 29 16:58:51 2004 for Majorana Simulation by  doxygen 1.3.9.1