Добавил:
okley
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Моделирование (1 сем, мага) / m5 / prog5
.cpp#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "hist.hpp"
// This function generates basic random
double gamma(){
return (rand()+0.5)/(RAND_MAX+1.0);
}
// scattered photon energy probability
double g_compton(double x, double E){
return x/E + E/x + (1/E - 1/x)*(2 + 1/E - 1/x);
}
// simulate compton
double compton(double E){
double g1, emin;
double ksi;
// ************************************************
// simulate compton
// ************************************************
return ksi;
}
// functions to calculate mu for all processes
double mu_phot(double E){return 0.1/E;}
double mu_compt(double E){return 0.05*E;}
double mu_pair(double E){
if( E>2 ) return 0.03*(E-2);
return 0;
}
int main(){
double d = 3; // thickness
double Einit = 8; // initial energy
srand(time(NULL)); // initialize the random generator
int num_bin = 51;
Hist *hist = new Hist(-0.1, 10.1, num_bin); // energy deposit
Hist *hist_pm = new Hist(-0.1, 10.1, num_bin); // pm amplitude
for( int i=0; i<500000; i++ ){
double E=Einit, x=0., E1=-1, x1; // start event photon1: E=Einit, x=0; photon2 does not exists E=-1;
double de=0; // energy deposit = 0
// **************************************************************
// here simulation code
// **************************************************************
hist->fill(de); // fill histogramm
double de_pm = sqrt(-2.0*log(gamma()))*cos(2*3.1416*gamma())*0.1*sqrt(de) + de;
hist_pm->fill(de_pm); // fill histogramm
}
for(int i=0; i<hist->get_num_bin(); i++){
cout << hist->get_bin(i) << "\t"; // get middle of bin boundary
cout << hist->get_bin_value(i) << "\t"; // get number of counts in the bin
cout << hist_pm->get_bin_value(i) << "\n"; // get number of counts in the bin
}
hist->draw(60);
hist_pm->draw(60);
delete hist; // destroy histogramm
delete hist_pm; // destroy histogramm
getchar(); // wait "Enter" to close window
}
