00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "BDSPlanckEngine.hh"
00010 #include "G4ios.hh"
00011 #include "G4UnitsTable.hh"
00012 #include "Randomize.hh"
00013
00014
00015 BDSPlanckEngine::BDSPlanckEngine(G4double Temperature)
00016 : itsTemperature(Temperature)
00017 {
00018 if(itsTemperature<=0.)
00019 {G4Exception("BDSPlanckEngine: Invalid Temperature");}
00020 kT=k_Boltzmann*Temperature;
00021
00022 a=1.266;
00023 b=-0.6;
00024 c=0.648;
00025
00026 x1=c;
00027 x2=(log(c)-a)/b;
00028
00029 area1 = x1*x1/2;
00030 area2 = area1 + c*(x2-x1);
00031 area3=(- exp(a+b*x2)/b);
00032 TotalArea = area2 + area3;
00033
00034 }
00035
00036
00037 BDSPlanckEngine::~BDSPlanckEngine(){}
00038
00039
00040 G4LorentzVector BDSPlanckEngine::PerformPlanck()
00041 {
00042
00043
00044
00045
00046 G4double phi=twopi * G4UniformRand() ;
00047 G4double sinphi=sin(phi);
00048 G4double cosphi=cos(phi);
00049
00050 G4double costh=2.*G4UniformRand()-1.;
00051 G4double sinth=sqrt(1-costh*costh);
00052
00053 G4int ntry=0;
00054
00055
00056
00057 G4double x;
00058 G4bool repeat=true;
00059
00060 do {ntry++;
00061 G4double area=TotalArea*G4UniformRand();
00062 if(area<=area1)
00063 {x=sqrt(2.*area);
00064 if(x*G4UniformRand()<=PlanckSpectrum(x))repeat=false;
00065 }
00066 else
00067 { if(area<=area2)
00068 {x=x1+ (area-area1)/c ;
00069 if(c*G4UniformRand()<=PlanckSpectrum(x))repeat=false;
00070 }
00071 else
00072 {x= (log((area-TotalArea)*b) - a)/b;
00073 if(exp(a+b*x)*G4UniformRand()<=PlanckSpectrum(x))repeat=false;
00074 }
00075 }
00076 }while(ntry<ntryMax && repeat);
00077
00078
00079 if(ntry==ntryMax)G4Exception("BDSPlanckEngine:Max number of loops exceeded");
00080
00081 G4double Egam=kT*x;
00082
00083 itsFourMom.setPx(Egam*sinth*cosphi);
00084 itsFourMom.setPy(Egam*sinth*sinphi);
00085 itsFourMom.setPz(Egam*costh);
00086 itsFourMom.setE(Egam);
00087
00088 return itsFourMom;
00089 }
00090
00091