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