OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
MultiBunchHandler.h
Go to the documentation of this file.
1 #ifndef OPAL_MULTI_BUNCH_HANDLER_H
2 #define OPAL_MULTI_BUNCH_HANDLER_H
3 
5 
6 #include <vector>
7 
8 /* Helper class that stores bunch injection
9  * information like azimuth, radius etc. of first
10  * bunch in multi-bunch mode of ParallelCyclotronTracker.
11  */
13 public:
14  struct injection_t {
16  : time(0.0)
17  , pathlength(0.0)
18  , azimuth(0.0)
19  , radius(0.0)
20  { };
21 
22  double time; // ns
23  double pathlength; // m
24  double azimuth; // deg
25  double radius; // mm
26  };
27 
28  struct beaminfo_t {
29  beaminfo_t(const injection_t& injection = injection_t())
30  : time(injection.time)
31  , azimuth(injection.azimuth)
32  , radius(injection.radius)
33  , prevAzimuth(-1.0)
34  , pathlength(injection.pathlength)
35  , nParticles(0)
36  , ekin(0.0)
37  , dEkin(0.0)
38  , rrms{0.0}
39  , prms{0.0}
40  , emit{0.0}
41  , mean{0.0}
42  , correlation{0.0}
43  , halo{0.0}
44  { };
45 
46  double time;
47  double azimuth;
48  double radius;
49  double prevAzimuth;
50  double pathlength;
51  long unsigned int nParticles;
52  double ekin;
53  double dEkin;
54  double rrms[3];
55  double prms[3];
56  double emit[3];
57  double mean[3];
58  double correlation[3];
59  double halo[3];
60  };
61 
62  // multi-bunch modes
63  enum class MB_MODE {
64  FORCE = 0,
65  AUTO = 1
66  };
67 
68  // multi-bunch binning type
69  enum class MB_BINNING {
70  GAMMA = 0,
71  BUNCH = 1
72  };
73 
74  /*
75  * @param numBunch > 1 --> multi bunch mode
76  * @param eta binning value
77  * @param para only for MB_MODE::AUTO
78  * @param mode of multi-bunch
79  * @param binning type of particle binning
80  */
82  const int& numBunch,
83  const double& eta,
84  const double& para,
85  const std::string& mode,
86  const std::string& binning);
87 
89 
91  const PartData& ref);
92 
93  /* Returns:
94  * 0 - if nothing happened
95  * 1 - if bunch got saved
96  * 2 - if bunch got injected
97  */
99  const PartData& ref,
100  bool& flagTransition);
101 
103 
105  void setMode(const std::string& mbmode);
106 
107  // set binning type
108  void setBinning(std::string binning);
109 
110  void setRadiusTurns(const double& radius);
111 
112  void setNumBunch(short n);
113 
114  short getNumBunch() const;
115 
116  bool isForceMode() const;
117 
118  bool calcBunchBeamParameters(PartBunchBase<double, 3>* beam, short bunchNr);
119 
120  beaminfo_t& getBunchInfo(short bunchNr);
121 
122  const beaminfo_t& getBunchInfo(short bunchNr) const;
123 
124  injection_t& getInjectionValues();
125 
126  void updateTime(const double& dt);
127 
128  void updatePathLength(const std::vector<double>& lpaths);
129 
130 private:
131  // store the data of the beam which are required for injecting a
132  // new bunch for multibunch filename
133  std::string onebunch_m;
134 
136  short numBunch_m;
137 
138  // parameter for reset bin in multi-bunch run
139  double eta_m;
140 
141  // 0 for single bunch (default),
142  // 1 for FORCE,
143  // 2 for AUTO
144  MB_MODE mode_m; //multiBunchMode_m;
145 
146  // 0 for GAMMA (default),
147  // 1 for BUNCH
148  MB_BINNING binning_m; //binningType_m;
149 
150  // control parameter for AUTO multi-bunch mode
152 
153  // used for automatic injection in multi-bunch mode
156 
157  // record how many bunches has already been injected.
159 
160  // each list entry belongs to a bunch
161  std::vector<beaminfo_t> binfo_m;
162 
163  // global attributes of injection
165 };
166 
167 
168 inline
170  bunchCount_m = n;
171 }
172 
173 
174 inline
176  return bunchCount_m;
177 }
178 
179 
180 inline
182  return (mode_m == MB_MODE::FORCE);
183 }
184 
185 
186 inline
188  PAssert_GE(bunchNr, 0);
189  PAssert_LT(bunchNr, (short)binfo_m.size());
190  return binfo_m[bunchNr];
191 }
192 
193 
194 inline
196  PAssert_GE(bunchNr, 0);
197  PAssert_LT(bunchNr, (short)binfo_m.size());
198  return binfo_m[bunchNr];
199 }
200 
201 
202 inline
204  return injection_m;
205 }
206 
207 #endif
void setBinning(std::string binning)
void updateTime(const double &dt)
short injectBunch(PartBunchBase< double, 3 > *beam, const PartData &ref, bool &flagTransition)
short numBunch_m
The number of bunches specified in TURNS of RUN commond.
Particle reference data.
Definition: PartData.h:38
MultiBunchHandler(PartBunchBase< double, 3 > *beam, const int &numBunch, const double &eta, const double &para, const std::string &mode, const std::string &binning)
bool calcBunchBeamParameters(PartBunchBase< double, 3 > *beam, short bunchNr)
bool readBunch(PartBunchBase< double, 3 > *beam, const PartData &ref)
void setNumBunch(short n)
void saveBunch(PartBunchBase< double, 3 > *beam)
#define PAssert_LT(a, b)
Definition: PAssert.h:121
void updatePathLength(const std::vector< double > &lpaths)
#define PAssert_GE(a, b)
Definition: PAssert.h:124
injection_t & getInjectionValues()
void setRadiusTurns(const double &radius)
bool isForceMode() const
std::vector< beaminfo_t > binfo_m
beaminfo_t & getBunchInfo(short bunchNr)
short getNumBunch() const
void setMode(const std::string &mbmode)
set the working sub-mode for multi-bunch mode: &quot;FORCE&quot; or &quot;AUTO&quot;
void updateParticleBins(PartBunchBase< double, 3 > *beam)