WakeFunction.hh 1.33 KB
Newer Older
gsell's avatar
gsell committed
1 2 3
#ifndef WAKEFUNCTION_HH
#define WAKEFUNCTION_HH

4 5 6
#include <string>
#include <vector>

gsell's avatar
gsell committed
7 8 9 10 11
class ElementBase;
class PartBunch;

class WakeFunction {
public:
12
    WakeFunction(std::string name, ElementBase *elref, unsigned int n):
13 14
        nBins_m(n),
        name_m(name) { };
15

gsell's avatar
gsell committed
16
    virtual ~WakeFunction(){ };
17
    virtual void initialize(const ElementBase *ref){ };
gsell's avatar
gsell committed
18 19
    virtual void apply(PartBunch &bunch) = 0;
    virtual const std::string getType() const = 0;
20 21 22
    const std::string & getName() const {
        return name_m;
    }
gsell's avatar
gsell committed
23

24 25 26
protected:
    const unsigned int nBins_m;

gsell's avatar
gsell committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
private:
    const std::string name_m;
};

class LineDensity: public std::vector<double> {
public:
    LineDensity(int size = 0, double defaultValue = 0.0) : std::vector<double>(size, defaultValue) {}
    void getFirstDerivative(std::vector<double> &firstDerivative, const double &hz);
};

inline void LineDensity::getFirstDerivative(std::vector<double> &firstDerivative, const double &hz) {
    const size_t size = this->size();
    if(firstDerivative.size() != size)
        firstDerivative.resize(size, 0.0);

    firstDerivative[0] = ((*this)[1] - (*this)[0]) / hz;
    for(unsigned int i = 1; i + 1 < size; ++i)
        firstDerivative[i] = ((*this)[i + 1] - (*this)[i - 1]) / hz;
    firstDerivative[size - 1] = ((*this)[size - 1] - (*this)[size - 2]) / hz;
}

#endif // WAKEFUNCTION_HH