/usr/include/CLHEP/GenericFunctions/FourierFit.icc is in libclhep-dev 2.1.4.1+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | // -*- C++ -*-
// $Id:
#include <sstream>
#include <cmath>
#include <complex>
namespace Genfun {
FUNCTION_OBJECT_IMP(FourierFit)
inline
FourierFit::FourierFit(unsigned int N):
N(N)
{
for (unsigned int i=0;i<N;i++) {
std::ostringstream stream;
stream << "Fraction " << i;
fraction.push_back(new Parameter(stream.str(), 0.5, 0.0, 1.0));
}
for (unsigned int i=0;i<N;i++) {
std::ostringstream stream;
stream << "Phase " << i;
phase.push_back(new Parameter(stream.str(), M_PI, 0.0, 2.0*M_PI));
}
}
inline
FourierFit::~FourierFit() {
for (unsigned int i=0;i<N;i++) {
delete fraction[i];
delete phase[i];
}
}
inline
FourierFit::FourierFit(const FourierFit & right):
N(right.N)
{
for (int i=0;i<N;i++) {
fraction.push_back(new Parameter(*right.fraction[i]));
phase.push_back(new Parameter(*right.phase[i]));
}
}
inline
double FourierFit::operator() (double x) const {
unsigned int n=N;
std::complex<double> P=0.0;
std::complex<double> I(0,1.0);
double f=1.0;
while (1) {
if (n==0) {
double fn=1.0;
double Pn=sqrt(1/2.0/M_PI);
P+=(sqrt(f*fn)*Pn);
break;
}
else {
double fn=getFraction(n-1)->getValue();
double px=getPhase(n-1)->getValue();
double Pn=sqrt(1/M_PI)*sin(n*x/2.0);
P+=exp(I*px)*sqrt(f*fn)*Pn;
f*=(1-fn);
n--;
}
}
return std::norm(P);
}
inline
unsigned int FourierFit::order() const{
return N;
}
inline
Parameter *FourierFit::getFraction(unsigned int i) {
return fraction[i];
}
inline
const Parameter *FourierFit::getFraction(unsigned int i) const{
return fraction[i];
}
inline
Parameter *FourierFit::getPhase(unsigned int i) {
return phase[i];
}
inline
const Parameter *FourierFit::getPhase(unsigned int i) const{
return phase[i];
}
} // end namespace Genfun
|