Monitor.h 3.75 KB
Newer Older
gsell's avatar
gsell committed
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
#ifndef CLASSIC_Monitor_HH
#define CLASSIC_Monitor_HH

// ------------------------------------------------------------------------
// $RCSfile: Monitor.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: Monitor
//   Defines the abstract interface for a beam position monitor.
//
// ------------------------------------------------------------------------
// Class category: AbsBeamline
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:32:31 $
// $Author: fci $
//
// ------------------------------------------------------------------------

#include "AbsBeamline/Component.h"
#include "BeamlineGeometry/StraightGeometry.h"
26
#include "Structure/LossDataSink.h"
gsell's avatar
gsell committed
27

snuverink_j's avatar
snuverink_j committed
28 29
#include <map>
#include <string>
adelmann's avatar
adelmann committed
30

31 32
template <class T, unsigned Dim>
class PartBunchBase;
snuverink_j's avatar
snuverink_j committed
33
class BeamlineVisitor;
34

gsell's avatar
gsell committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
// Class Monitor
// ------------------------------------------------------------------------
/// Interface for beam position monitors.
//  Class Monitor defines the abstract interface for general beam position
//  monitors.

class Monitor: public Component {

public:

    /// Plane selection.
    enum Plane {
        /// Monitor is off (inactive).
        OFF,
        /// Monitor acts on x-plane.
        X,
        /// Monitor acts on y-plane.
        Y,
        /// Monitor acts on both planes.
        XY
    };

kraus's avatar
kraus committed
57 58 59 60 61
    enum Type {
        TEMPORAL,
        SPATIAL
    };

gsell's avatar
gsell committed
62 63 64 65 66 67 68 69
    /// Constructor with given name.
    explicit Monitor(const std::string &name);

    Monitor();
    Monitor(const Monitor &);
    virtual ~Monitor();

    /// Apply visitor to Monitor.
70
    virtual void accept(BeamlineVisitor &) const override;
gsell's avatar
gsell committed
71 72

    /// Get geometry.
73
    virtual StraightGeometry &getGeometry() override = 0;
gsell's avatar
gsell committed
74 75

    /// Get geometry. Version for const object.
76
    virtual const StraightGeometry &getGeometry() const override = 0;
gsell's avatar
gsell committed
77 78 79 80

    /// Get plane on which monitor observes.
    virtual Plane getPlane() const = 0;

81
    virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override;
gsell's avatar
gsell committed
82

83 84 85 86
    virtual bool applyToReferenceParticle(const Vector_t &R,
                                          const Vector_t &P,
                                          const double &t,
                                          Vector_t &E,
87
                                          Vector_t &B) override;
gsell's avatar
gsell committed
88

89
    virtual void initialise(PartBunchBase<double, 3> *bunch, double &startField, double &endField) override;
gsell's avatar
gsell committed
90

91
    virtual void finalise() override;
gsell's avatar
gsell committed
92

93
    virtual bool bends() const override;
gsell's avatar
gsell committed
94

95
    virtual void goOnline(const double &kineticEnergy) override;
gsell's avatar
gsell committed
96

97
    virtual void goOffline() override;
gsell's avatar
gsell committed
98

99
    virtual ElementBase::ElementType getType() const override;
gsell's avatar
gsell committed
100

101
    virtual void getDimensions(double &zBegin, double &zEnd) const override;
gsell's avatar
gsell committed
102 103 104

    void setOutputFN(std::string fn);

kraus's avatar
kraus committed
105
    void setType(Type type);
106 107

    static void writeStatistics();
108 109

    virtual bool isInside(const Vector_t &r) const override;
gsell's avatar
gsell committed
110 111 112 113 114 115
private:

    // Not implemented.
    void operator=(const Monitor &);
    std::string filename_m;               /**< The name of the outputfile*/
    Plane plane_m;
kraus's avatar
kraus committed
116
    Type type_m;
117
    unsigned int numPassages_m;
gsell's avatar
gsell committed
118

adelmann's avatar
adelmann committed
119
    std::unique_ptr<LossDataSink> lossDs_m;
120

121
    static std::map<double, SetStatistics> statFileEntries_sm;
122
    static const double halfLength_s;
gsell's avatar
gsell committed
123 124
};

kraus's avatar
kraus committed
125 126 127 128
inline
void Monitor::setType(Monitor::Type type) {
    type_m = type;
}
129

130 131 132 133 134 135 136 137
inline
bool Monitor::isInside(const Vector_t &r) const
{
    const double length = getElementLength();
    return std::abs(r(2)) <= 0.5 * length && isInsideTransverse(r);
}

#endif // CLASSIC_Monitor_HH