OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Monitor.h
Go to the documentation of this file.
1 //
2 // Class Monitor
3 // Defines the abstract interface for a beam position monitor.
4 //
5 // Copyright (c) 2000 - 2021, Paul Scherrer Institut, Villigen PSI, Switzerland
6 // All rights reserved.
7 //
8 // This file is part of OPAL.
9 //
10 // OPAL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17 //
18 #ifndef CLASSIC_Monitor_HH
19 #define CLASSIC_Monitor_HH
20 
21 #include "AbsBeamline/Component.h"
23 #include "Structure/LossDataSink.h"
24 
25 #include <map>
26 #include <string>
27 
28 template <class T, unsigned Dim>
29 class PartBunchBase;
30 class BeamlineVisitor;
31 
32 class Monitor: public Component {
33 
34 public:
35 
37  enum Plane {
39  OFF,
41  X,
43  Y,
45  XY
46  };
47 
49  explicit Monitor(const std::string &name);
50 
51  Monitor();
52  Monitor(const Monitor &);
53  virtual ~Monitor();
54 
56  virtual void accept(BeamlineVisitor &) const override;
57 
59  virtual StraightGeometry &getGeometry() override = 0;
60 
62  virtual const StraightGeometry &getGeometry() const override = 0;
63 
65  virtual Plane getPlane() const = 0;
66 
67  virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override;
68 
69  virtual bool applyToReferenceParticle(const Vector_t &R,
70  const Vector_t &P,
71  const double &t,
72  Vector_t &E,
73  Vector_t &B) override;
74 
75  virtual void initialise(PartBunchBase<double, 3> *bunch, double &startField, double &endField) override;
76 
77  virtual void finalise() override;
78 
79  virtual bool bends() const override;
80 
81  virtual void goOnline(const double &kineticEnergy) override;
82 
83  virtual void goOffline() override;
84 
85  virtual ElementBase::ElementType getType() const override;
86 
87  virtual void getDimensions(double &zBegin, double &zEnd) const override;
88 
90 
91  static void writeStatistics();
92 
93  virtual int getRequiredNumberOfTimeSteps() const override;
94 
95  virtual bool isInside(const Vector_t &r) const override;
96 private:
97 
98  // Not implemented.
99  void operator=(const Monitor &);
100  std::string filename_m;
103  unsigned int numPassages_m;
104 
105  std::unique_ptr<LossDataSink> lossDs_m;
106 
107  static std::map<double, SetStatistics> statFileEntries_sm;
108  static const double halfLength_s;
109 };
110 
111 inline
113  type_m = type;
114 }
115 
116 inline
118 {
119  return 1;
120 }
121 
122 inline
123 bool Monitor::isInside(const Vector_t &r) const
124 {
125  const double length = getElementLength();
126  return std::abs(r(2)) <= 0.5 * length && isInsideTransverse(r);
127 }
128 
129 
130 #endif // CLASSIC_Monitor_HH
CollectionType
Definition: LossDataSink.h:72
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
const std::string name
boost::function< boost::tuple< double, bool >arguments_t)> type
Definition: function.hpp:21
Interface for a single beam element.
Definition: Component.h:50
virtual double getElementLength() const
Get design length.
Definition: ElementBase.h:432
bool isInsideTransverse(const Vector_t &r) const
CollectionType type_m
Definition: Monitor.h:102
static void writeStatistics()
Definition: Monitor.cpp:206
virtual void accept(BeamlineVisitor &) const override
Apply visitor to Monitor.
Definition: Monitor.cpp:66
std::string filename_m
Definition: Monitor.h:100
virtual void goOnline(const double &kineticEnergy) override
Definition: Monitor.cpp:177
virtual bool applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override
Definition: Monitor.cpp:92
Plane
Plane selection.
Definition: Monitor.h:37
@ XY
Monitor acts on both planes.
Definition: Monitor.h:45
@ Y
Monitor acts on y-plane.
Definition: Monitor.h:43
@ OFF
Monitor is off (inactive).
Definition: Monitor.h:39
@ X
Monitor acts on x-plane.
Definition: Monitor.h:41
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
Definition: Monitor.cpp:142
virtual StraightGeometry & getGeometry() override=0
Get geometry.
virtual const StraightGeometry & getGeometry() const override=0
Get geometry. Version for const object.
virtual void goOffline() override
Definition: Monitor.cpp:181
std::unique_ptr< LossDataSink > lossDs_m
Definition: Monitor.h:105
virtual void getDimensions(double &zBegin, double &zEnd) const override
Definition: Monitor.cpp:196
Monitor()
Definition: Monitor.cpp:39
virtual ~Monitor()
Definition: Monitor.cpp:62
Plane plane_m
Definition: Monitor.h:101
static std::map< double, SetStatistics > statFileEntries_sm
Definition: Monitor.h:107
virtual void finalise() override
Definition: Monitor.cpp:173
unsigned int numPassages_m
Definition: Monitor.h:103
void operator=(const Monitor &)
virtual Plane getPlane() const =0
Get plane on which monitor observes.
virtual int getRequiredNumberOfTimeSteps() const override
Definition: Monitor.h:117
static const double halfLength_s
Definition: Monitor.h:108
virtual bool bends() const override
Definition: Monitor.cpp:192
virtual ElementBase::ElementType getType() const override
Get element type std::string.
Definition: Monitor.cpp:202
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
Definition: Monitor.cpp:70
void setCollectionType(CollectionType type)
Definition: Monitor.h:112
virtual bool isInside(const Vector_t &r) const override
Definition: Monitor.h:123
A geometry representing a straight line.