-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSynradTypes.cpp
135 lines (115 loc) · 3.31 KB
/
SynradTypes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
Program: MolFlow+ / Synrad+
Description: Monte Carlo simulator for ultra-high vacuum and synchrotron radiation
Authors: Jean-Luc PONS / Roberto KERSEVAN / Marton ADY
Copyright: E.S.R.F / CERN
Website: https://cern.ch/molflow
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Full license text: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
*/
#include <math.h>
#include "SynradTypes.h"
#include "GLApp/MathTools.h"
#include "File.h" //Error
double Trajectory_Point::Critical_Energy(const double &gamma) {
double crit_en=2.959905E-5*pow(gamma,3)/rho.Norme(); //rho in cm...
return crit_en;
}
double Trajectory_Point::dAlpha(const double &dL) {
return dL/rho.Norme();
}
Histogram::Histogram(){
number_of_bins=0;
logarithmic=0;
min=0;
max=0;
delta=0;
}
Histogram::Histogram(double min_V,double max_V,int N,bool logscale){
number_of_bins=N;
try {
counts.resize(number_of_bins);
}
catch (...){
throw Error("Can't reserve memory for histogram");
}
logarithmic=logscale;
this->min=min_V;
this->max=max_V;
if (!logarithmic) { //linearly distributed bins
delta=(max-min)/number_of_bins;
} else {
delta=(log10(max)-log10(min))/number_of_bins;
}
}
Histogram::~Histogram() {
//free(counts);
}
void Histogram::Add(const double &x,const ProfileSlice &increment) {
if (x<max && x>=min) {
int binIndex;
if (!logarithmic) {
binIndex = (int)((x - min) / delta);
} else {
binIndex = (int)((log10(x) - log10(min)) / delta);
}
double binX = GetX(binIndex);
counts[binIndex] += increment;
}
}
ProfileSlice Histogram::GetCounts(size_t index){
return counts[index];
}
double Histogram::GetX(size_t index){
double X;
if (!logarithmic) {
X=min+index*delta;
} else {
X=Pow10(log10(min)+index*delta);
}
return X;
}
void Histogram::ResetCounts(){
std::vector<ProfileSlice>(counts.size()).swap(counts);
}
ProfileSlice & ProfileSlice::operator+=(const ProfileSlice & rhs)
{
this->count_absorbed += rhs.count_absorbed;
this->count_incident += rhs.count_incident;
this->flux_absorbed += rhs.flux_absorbed;
this->flux_incident += rhs.flux_incident;
this->power_absorbed += rhs.power_absorbed;
this->power_incident += rhs.power_incident;
return *this;
}
ProfileSlice & ProfileSlice::operator=(const ProfileSlice & rhs)
{
this->count_absorbed = rhs.count_absorbed;
this->count_incident = rhs.count_incident;
this->flux_absorbed = rhs.flux_absorbed;
this->flux_incident = rhs.flux_incident;
this->power_absorbed = rhs.power_absorbed;
this->power_incident = rhs.power_incident;
return *this;
}
TextureCell &TextureCell::operator+=(const TextureCell & rhs)
{
this->count += rhs.count;
this->flux += rhs.flux;
this->power += rhs.power;
return *this;
}
TextureCell &TextureCell::operator=(const TextureCell & rhs)
{
this->count = rhs.count;
this->flux = rhs.flux;
this->power = rhs.power;
return *this;
}