forked from jkomppula/PyHEADTAIL_feedback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeedback.py
707 lines (577 loc) · 31.5 KB
/
feedback.py
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
import numpy as np
import collections
from PyHEADTAIL.mpi import mpi_data
from core import get_processor_variables, process, Parameters
from core import z_bins_to_bin_edges, append_bin_edges
from processors.register import VectorSumCombiner, CosineSumCombiner
from processors.register import HilbertCombiner, DummyCombiner
from scipy.constants import c
from inspect import isclass
"""
This file contains objecst, which can be used as transverse feedback
systems in the one turn map in PyHEADTAIL. The signal processing in the
feedback systems can be modelled by giving a list of the necessary signal
processors describing the system to the objects.
@author Jani Komppula
@date 11/10/2017
"""
class IdealBunchFeedback(object):
""" The simplest possible feedback. It corrects a gain fraction of a mean xp/yp value of the bunch.
"""
def __init__(self,gain, multi_bunch=False):
if isinstance(gain, collections.Container):
self._gain_x = gain[0]
self._gain_y = gain[1]
else:
self._gain_x = gain
self._gain_y = gain
self.multi_bunch = multi_bunch
def track(self,bunch):
if self.multi_bunch:
bunch_list = bunch.split_to_views()
for b in bunch_list:
b.xp -= self._gain_x *b.mean_xp()
b.yp -= self._gain_y*b.mean_yp()
else:
bunch.xp -= self._gain_x *bunch.mean_xp()
bunch.yp -= self._gain_y*bunch.mean_yp()
class IdealSliceFeedback(object):
"""Corrects a gain fraction of a mean xp/yp value of each slice in the bunch."""
def __init__(self,gain,slicer, multi_bunch=False):
if isinstance(gain, collections.Container):
self._gain_x = gain[0]
self._gain_y = gain[1]
else:
self._gain_x = gain
self._gain_y = gain
self.multi_bunch = multi_bunch
self._slicer = slicer
def track(self,bunch):
if self.multi_bunch:
bunch_list = bunch.split_to_views()
for b in bunch_list:
slice_set = b.get_slices(self._slicer, statistics = ['mean_xp', 'mean_yp'])
p_idx = slice_set.particles_within_cuts
s_idx = slice_set.slice_index_of_particle.take(p_idx)
b.xp[p_idx] -= self._gain_x * slice_set.mean_xp[s_idx]
b.yp[p_idx] -= self._gain_y * slice_set.mean_yp[s_idx]
else:
slice_set = bunch.get_slices(self._slicer, statistics = ['mean_xp', 'mean_yp'])
# Reads a particle index and a slice index for each macroparticle
p_idx = slice_set.particles_within_cuts
s_idx = slice_set.slice_index_of_particle.take(p_idx)
bunch.xp[p_idx] -= self._gain_x * slice_set.mean_xp[s_idx]
bunch.yp[p_idx] -= self._gain_y * slice_set.mean_yp[s_idx]
class GenericOneTurnMapObject(object):
def __init__(self, gain, slicer, processors_x, processors_y=None,
pickup_axis='divergence', kicker_axis=None, mpi=False,
phase_x=None, phase_y=None, location_x=0., location_y=0.,
beta_x=1., beta_y=1., **kwargs):
if isinstance(gain, collections.Container):
self._gain_x = gain[0]
self._gain_y = gain[1]
else:
self._gain_x = gain
self._gain_y = gain
self._slicer = slicer
self._processors_x = processors_x
self._processors_y = processors_y
# beam parameters
self._pickup_axis = pickup_axis
self._kicker_axis = kicker_axis
self._phase_x = phase_x
self._phase_y = phase_y
self._location_x = location_x
self._location_y = location_y
self._beta_x = beta_x
self._beta_y = beta_y
self._local_sets = None
self._signal_sets_x = None
self._signal_sets_y = None
self._loc_signal_sets_x = None
self._loc_signal_sets_y = None
self._required_variables = []
if self._processors_x is not None:
if (self._pickup_axis == 'divergence') or (phase_x is not None):
self._required_variables.append('mean_xp')
if (self._pickup_axis == 'displacement') or (phase_x is not None):
self._required_variables.append('mean_x')
self._required_variables = get_processor_variables(self._processors_x,
self._required_variables)
if self._processors_y is not None:
if (self._pickup_axis == 'divergence') or (phase_y is not None):
self._required_variables.append('mean_yp')
if (self._pickup_axis == 'displacement') or (phase_y is not None):
self._required_variables.append('mean_y')
self._required_variables = get_processor_variables(self._processors_y,
self._required_variables)
# # TODO: Normally n_macroparticles_per_slice is removed from
# # the statistical variables. Check if it is not necessary.
self._mpi = mpi
if self._mpi:
self._mpi_gatherer = mpi_data.MpiGatherer(self._slicer,
self._required_variables)
self._parameters_x = None
self._signal_x = None
self._parameters_y = None
self._signal_y = None
def _init_signals(self, bunch_list, signal_slice_sets_x, signal_slice_sets_y):
beta_beam = bunch_list[0].beta
if self._processors_x is not None:
self._parameters_x = self._generate_parameters(signal_slice_sets_x,
self._location_x,
self._beta_x, beta_beam)
n_segments = self._parameters_x['n_segments']
n_bins_per_segment = self._parameters_x['n_bins_per_segment']
self._signal_x = np.zeros(n_segments * n_bins_per_segment)
if self._processors_y is not None:
self._parameters_y = self._generate_parameters(signal_slice_sets_y,
self._location_y,
self._beta_y, beta_beam)
n_segments = self._parameters_y['n_segments']
n_bins_per_segment = self._parameters_y['n_bins_per_segment']
self._signal_y = np.zeros(n_segments * n_bins_per_segment)
def _get_slice_sets(self, superbunch):
if self._mpi:
self._mpi_gatherer.gather(superbunch)
all_slice_sets = self._mpi_gatherer.bunch_by_bunch_data
local_slice_sets = self._mpi_gatherer.slice_set_list
bunch_list = self._mpi_gatherer.bunch_list
self._local_sets = self._mpi_gatherer.local_bunch_indexes
else:
all_slice_sets = [superbunch.get_slices(self._slicer,
statistics=self._required_variables)]
local_slice_sets = all_slice_sets
bunch_list = [superbunch]
self._local_sets = [0]
beta_beam = superbunch.beta
if (self._signal_sets_x is None) and (self._signal_sets_y is None):
if self._processors_x is not None:
indexes = self._parse_relevant_bunches(local_slice_sets,
all_slice_sets,
self._processors_x, beta_beam)
self._signal_sets_x = indexes[0]
self._loc_signal_sets_x = indexes[1]
if self._processors_y is not None:
indexes = self._parse_relevant_bunches(local_slice_sets,
all_slice_sets,
self._processors_y, beta_beam)
self._signal_sets_y = indexes[0]
self._loc_signal_sets_y = indexes[1]
if self._processors_x is not None:
signal_slice_sets_x = []
for idx in self._signal_sets_x:
signal_slice_sets_x.append(all_slice_sets[idx])
else:
signal_slice_sets_x = None
if self._processors_y is not None:
signal_slice_sets_y = []
for idx in self._signal_sets_y:
signal_slice_sets_y.append(all_slice_sets[idx])
else:
signal_slice_sets_y = None
return bunch_list, local_slice_sets, signal_slice_sets_x, signal_slice_sets_y
def _generate_parameters(self, signal_slice_sets, location, beta, beta_beam):
bin_edges = None
segment_ref_points = []
if len(signal_slice_sets) > 1:
circumference = signal_slice_sets[0].circumference
h_bunch = signal_slice_sets[0].h_bunch
else:
circumference=None
h_bunch=None
for slice_set in signal_slice_sets:
z_bins = np.copy(slice_set.z_bins)
if circumference is not None:
z_bins -= slice_set.bucket_id*circumference/float(h_bunch)
edges = -1.*z_bins_to_bin_edges(z_bins)/(c*beta_beam)
segment_ref_points.append(-1.*np.mean(z_bins)/(c*beta_beam))
if bin_edges is None:
bin_edges = np.copy(edges)
else:
bin_edges = append_bin_edges(bin_edges, edges)
bin_edges = bin_edges[::-1]
bin_edges = np.fliplr(bin_edges)
segment_ref_points = segment_ref_points[::-1]
n_bins_per_segment = len(bin_edges)/len(signal_slice_sets)
segment_ref_points = np.array(segment_ref_points)
parameters = Parameters()
parameters['class'] = 0
parameters['bin_edges'] = bin_edges
parameters['n_segments'] = len(signal_slice_sets)
parameters['n_bins_per_segment'] = n_bins_per_segment
parameters['segment_ref_points'] = segment_ref_points
parameters['location'] = location
parameters['beta'] = beta
return parameters
def _parse_relevant_bunches(self, local_slice_sets, all_slice_sets, processors, beta_beam):
circumference = all_slice_sets[0].circumference
h_bunch = all_slice_sets[0].h_bunch
time_scale = 0.
for processor in processors:
if processor.time_scale > time_scale:
time_scale = processor.time_scale
local_set_edges = np.zeros((len(local_slice_sets), 2))
included_sets = []
set_is_included = np.zeros(len(all_slice_sets), dtype=int)
set_counter = np.zeros(len(all_slice_sets), dtype=int)
for i, slice_set in enumerate(local_slice_sets):
local_set_edges[i,0] = np.min(slice_set.z_bins-slice_set.bucket_id*circumference/float(h_bunch))/(c*beta_beam)
local_set_edges[i,1] = np.max(slice_set.z_bins-slice_set.bucket_id*circumference/float(h_bunch))/(c*beta_beam)
local_min = np.min(local_set_edges)
local_max = np.max(local_set_edges)
counter = 0
for i, slice_set in enumerate(all_slice_sets):
set_min = np.min(slice_set.z_bins-slice_set.bucket_id*circumference/float(h_bunch))/(c*beta_beam)
set_max = np.max(slice_set.z_bins-slice_set.bucket_id*circumference/float(h_bunch))/(c*beta_beam)
# print 'set_min ' + str(set_min) + ' and (local_min - time_scale)' + str((local_min - time_scale))
if (set_max > (local_min - time_scale)) and (set_min < (local_max + time_scale)):
included_sets.append(i)
set_is_included[i] = 1
set_counter[i] = counter
counter += 1
else:
pass
# print('skip!!!')
local_sets = []
for idx in self._local_sets:
if set_is_included[idx] != 1:
raise ValueError('All local bunches are not included!')
else:
local_sets.append(set_counter[idx])
return included_sets, local_sets
def _read_signal(self, signal, signal_slice_sets, plane, betatron_phase,
beta_value):
if self._mpi:
n_slices_per_bunch = signal_slice_sets[0]._n_slices
else:
n_slices_per_bunch = signal_slice_sets[0].n_slices
total_length = len(signal_slice_sets) * n_slices_per_bunch
if (signal is None) or (len(signal) != total_length):
raise ValueError('Wrong signal length')
for idx, slice_set in enumerate(signal_slice_sets):
idx_from = idx * n_slices_per_bunch
idx_to = (idx + 1) * n_slices_per_bunch
if plane == 'x':
if self._pickup_axis == 'displacement' or (betatron_phase is not None):
x_values = np.copy(slice_set.mean_x)
if (self._pickup_axis == 'divergence') or (betatron_phase is not None):
xp_values = np.copy(slice_set.mean_xp)
elif plane == 'y':
if self._pickup_axis == 'displacement' or (betatron_phase is not None):
x_values = np.copy(slice_set.mean_y)
if (self._pickup_axis == 'divergence') or (betatron_phase is not None):
xp_values = np.copy(slice_set.mean_yp)
else:
raise ValueError('Unknown plane')
if self._pickup_axis == 'divergence':
if betatron_phase is None:
np.copyto(signal[idx_from:idx_to], xp_values)
else:
np.copyto(signal[idx_from:idx_to], (-np.sin(betatron_phase)*x_values/beta_value +
np.cos(betatron_phase)*xp_values))
elif self._pickup_axis == 'displacement':
if betatron_phase is None:
np.copyto(signal[idx_from:idx_to], x_values)
else:
np.copyto(signal[idx_from:idx_to], (np.cos(betatron_phase)*x_values +
beta_value*np.sin(betatron_phase)*xp_values))
else:
raise ValueError('Unknown axis')
if signal is not None:
np.copyto(signal, signal[::-1])
def _kick_bunches(self, signal, plane, local_slice_sets, bunch_list, local_sets):
if signal is not None:
np.copyto(signal, signal[::-1])
n_slices_per_bunch = local_slice_sets[0].n_slices
for slice_set, bunch_idx, bunch in zip(local_slice_sets,
local_sets, bunch_list):
idx_from = bunch_idx * n_slices_per_bunch
idx_to = (bunch_idx + 1) * n_slices_per_bunch
p_idx = slice_set.particles_within_cuts
s_idx = slice_set.slice_index_of_particle.take(p_idx)
if self._kicker_axis == 'divergence':
if plane == 'x':
correction_x = np.array(signal[idx_from:idx_to], copy=False)
bunch.xp[p_idx] -= correction_x[s_idx]
elif plane == 'y':
correction_y = np.array(signal[idx_from:idx_to], copy=False)
bunch.yp[p_idx] -= correction_y[s_idx]
else:
raise ValueError('Unknown plane')
elif self._kicker_axis == 'displacement':
if plane == 'x':
correction_x = np.array(signal[idx_from:idx_to], copy=False)
bunch.x[p_idx] -= correction_x[s_idx]
elif plane == 'y':
correction_y = np.array(signal[idx_from:idx_to], copy=False)
bunch.y[p_idx] -= correction_y[s_idx]
else:
raise ValueError('Unknown plane')
else:
raise ValueError('Unknown axis')
class OneboxFeedback(GenericOneTurnMapObject):
""" An transverse feedback object for the one turn map in PyHEADTAIL.
By using this object, the pickup and the kicker are in the same location
of the accelerator. Bandwidth limitations, turn delays, noise, etc can be
applied by using signal processors. The axises for the pickup signal and
the correction are by default same, but they can be also specified to be
different (e.g. displacement and divergence).
"""
def __init__(self, gain, slicer, processors_x, processors_y,
pickup_axis='divergence', kicker_axis=None, mpi=False,
phase_x=None, phase_y=None, beta_x=1., beta_y=1., **kwargs):
"""
Parameters
----------
gain : float or tuple
A fraction of the oscillations is corrected, when the perfectly
betatron motion corrected pickup signal by passes the signal
processors without modifications, i.e. 2/(damping time [turns]).
Separate values can be set to x and y planes by giving two values
in a tuple.
slicer : PyHEADTAIL slicer object
processors_x : list
A list of signal processors for the x-plane
processors_y : list
A list of signal processors for the y-plane
pickup_axis : str
A axis, which values are used as a pickup signal
kicker_axis : str
A axis, to which the correction is applied. If None, the axis is
same as the pickup axis
mpi : bool
If True, data from multiple bunches are gathered by using MPI
phase_x : float
Initial betatron phase rotation for the signal in x-plane in the
units of radians
phase_y : float
Initial betatron phase rotation for the signal in y-plane in the
units of radians
beta_x : float
A value of the x-plane beta function in the feedback location
beta_y : float
A value of the y-plane beta function in the feedback location
"""
if kicker_axis is None:
kicker_axis = pickup_axis
super(self.__class__, self).__init__(gain, slicer, processors_x,
processors_y=processors_y, pickup_axis=pickup_axis,
kicker_axis=kicker_axis, mpi=mpi, phase_x=phase_x,
phase_y=phase_y, beta_x=beta_x, beta_y=beta_y, **kwargs)
def track(self, bunch):
bunch_list, local_slice_sets, signal_slice_sets_x, signal_slice_sets_y = self._get_slice_sets(bunch)
if (self._signal_x is None) and (self._signal_y is None):
self._init_signals(bunch_list, signal_slice_sets_x, signal_slice_sets_y)
if self._processors_x is not None:
self._read_signal(self._signal_x, signal_slice_sets_x, 'x',
self._phase_x, self._beta_x)
kick_parameters_x, kick_signal_x = process(self._parameters_x,
self._signal_x,
self._processors_x,
slice_sets=signal_slice_sets_x)
if kick_signal_x is not None:
kick_signal_x = kick_signal_x * self._gain_x
if self._pickup_axis == 'displacement' and self._kicker_axis == 'divergence':
kick_signal_x = kick_signal_x / self._beta_x
elif self._pickup_axis == 'divergence' and self._kicker_axis == 'displacement':
kick_signal_x = kick_signal_x * self._beta_x
self._kick_bunches(kick_signal_x, 'x', local_slice_sets, bunch_list,
self._loc_signal_sets_x)
if self._processors_y is not None:
self._read_signal(self._signal_y, signal_slice_sets_y, 'y',
self._phase_y, self._beta_y)
kick_parameters_y, kick_signal_y = process(self._parameters_y,
self._signal_y,
self._processors_y,
slice_sets=signal_slice_sets_y)
if kick_signal_y is not None:
kick_signal_y = kick_signal_y * self._gain_y
if self._pickup_axis == 'displacement' and self._kicker_axis == 'divergence':
kick_signal_y = kick_signal_y / self._beta_y
elif self._pickup_axis == 'divergence' and self._kicker_axis == 'displacement':
kick_signal_y = kick_signal_y * self._beta_y
self._kick_bunches(kick_signal_y, 'y', local_slice_sets, bunch_list,
self._loc_signal_sets_y)
class PickUp(GenericOneTurnMapObject):
""" A pickup object for the one turn map in PyHEADTAIL.
This object can be used as a pickup in the trasverse feedback systems
consisting of separate pickup(s) and kicker(s). A model for signal
processing (including, for example, bandwidth limitations and noise) can be
implemented by using signal processors. The signal can be transferred to
kicker(s) by putting registers to the signal processor chains.
"""
def __init__(self, slicer, processors_x, processors_y, location_x, beta_x,
location_y, beta_y, mpi=False, phase_x=None, phase_y=None,
**kwargs):
"""
Parameters
----------
slicer : PyHEADTAIL slicer object
processors_x : list
A list of signal processors for the x-plane
processors_y : list
A list of signal processors for the y-plane
used as a signal source in the y-plane
location_x : float
A location of the pickup in x-plane in the units of betatron phase
advance from a chosen reference point
beta_x : float
A value of the x-plane beta function in the pickup location
location_y : float
A location of the pickup in y-plane in the units of betatron phase
advance from a chosen reference point
beta_y : float
A value of the y-plane beta function in the pickup location
mpi : bool
If True, data from multiple bunches are gathered by using MPI
phase_x : float
Initial betatron phase rotation of the signal in x-plane in the
units of radians
phase_y : float
Initial betatron phase rotation of the signal in y-plane in the
units of radians
"""
super(self.__class__, self).__init__(0, slicer, processors_x,
processors_y=processors_y, pickup_axis='displacement',
kicker_axis=None, mpi=mpi, phase_x=phase_x, location_x=location_x,
location_y=location_y, phase_y=phase_y, beta_x=beta_x,
beta_y=beta_y, **kwargs)
def track(self, bunch):
bunch_list, local_slice_sets, signal_slice_sets_x, signal_slice_sets_y = self._get_slice_sets(bunch)
if (self._signal_x is None) and (self._signal_y is None):
self._init_signals(bunch_list, signal_slice_sets_x, signal_slice_sets_y)
if self._processors_x is not None:
self._read_signal(self._signal_x, signal_slice_sets_x, 'x',
self._phase_x, self._beta_x)
end_parameters_x, end_signal_x = process(self._parameters_x,
self._signal_x,
self._processors_x,
slice_sets=signal_slice_sets_x)
if self._processors_y is not None:
if self._signal_y is None:
self._init_signals(bunch_list, signal_slice_sets_x, signal_slice_sets_y)
self._read_signal(self._signal_y, signal_slice_sets_y, 'y',
self._phase_y, self._beta_y)
end_parameters_y, end_signal_y = process(self._parameters_y,
self._signal_y,
self._processors_y,
slice_sets=signal_slice_sets_y)
class Kicker(GenericOneTurnMapObject):
""" A Kicker object for the one turn map in PyHEADTAIL.
This object can be used as a kicker in the trasverse feedback systems
consisting of separate pickup(s) and kicker(s). A model for signal
processing (including, for example, bandwidth limitations and noise) can be
implemented by using signal processors. The input signals for the kicker
are the lists of register objects given as a input paramter.
"""
def __init__(self, gain, slicer, processors_x, processors_y,
registers_x, registers_y, location_x, beta_x,
location_y, beta_y, combiner='vector_sum', mpi=False,
**kwargs):
"""
Parameters
----------
gain : float or tuple
A fraction of the oscillations is corrected, when the perfectly
betatron motion corrected pickup signal by passes the signal
processors without modifications, i.e. 2/(damping time [turns]).
Separate values can be set to x and y planes by giving two values
in a tuple.
slicer : PyHEADTAIL slicer object
processors_x : list
A list of signal processors for the x-plane
processors_y : list
A list of signal processors for the y-plane
registers_x : list
A list of register object(s) (from pickup(s) processor chain(s)
used as a signal source in the x-plane
registers_y : list
A list of register object(s) (from pickup(s) processor chain(s)
used as a signal source in the y-plane
location_x : float
A location of the kicker in x-plane in the units of betatron phase
advance from a chosen reference point
beta_x : float
A value of the x-plane beta function in the kicker location
location_y : float
A location of the kicker in y-plane in the units of betatron phase
advance from a chosen reference point
beta_y : float
A value of the y-plane beta function in the kicker location
combiner : string or object
A combiner, which is used for combining signals from
the registers.
mpi : bool
If True, data from multiple bunches are gathered by using MPI
"""
if isinstance(combiner, (str,unicode)):
if combiner == 'vector_sum':
self._combiner_x = VectorSumCombiner(registers_x,
location_x, beta_x,
beta_conversion = '90_deg')
self._combiner_y = VectorSumCombiner(registers_y,
location_y, beta_y,
beta_conversion = '90_deg')
elif combiner == 'cosine_sum':
self._combiner_x = CosineSumCombiner(registers_x,
location_x, beta_x,
beta_conversion = '90_deg')
self._combiner_y = CosineSumCombiner(registers_y,
location_y, beta_y,
beta_conversion = '90_deg')
elif combiner == 'hilbert':
self._combiner_x = HilbertCombiner(registers_x,
location_x, beta_x,
beta_conversion = '90_deg')
self._combiner_y = HilbertCombiner(registers_y,
location_y, beta_y,
beta_conversion = '90_deg')
elif combiner == 'dummy':
self._combiner_x = DummyCombiner(registers_x,
location_x, beta_x,
beta_conversion = '90_deg')
self._combiner_y = DummyCombiner(registers_y,
location_y, beta_y,
beta_conversion = '90_deg')
else:
raise ValueError('Unknown combiner type')
elif isclass(combiner):
self._combiner_x = combiner(registers_x, location_x, beta_x,
beta_conversion = '90_deg')
self._combiner_y = combiner(registers_y, location_y, beta_y,
beta_conversion = '90_deg')
elif isinstance(combiner, tuple):
self._combiner_x = combiner[0]
self._combiner_y = combiner[1]
else:
raise ValueError('Unclear combiner input type')
super(self.__class__, self).__init__(gain, slicer, processors_x,
processors_y=processors_y, pickup_axis='divergence',
kicker_axis='divergence', mpi=mpi, location_x=location_x,
location_y=location_y,beta_x=beta_x, beta_y=beta_y, **kwargs)
def track(self, bunch):
bunch_list, local_slice_sets, signal_slice_sets_x, signal_slice_sets_y = self._get_slice_sets(bunch)
if (self._signal_x is None) and (self._signal_y is None):
self._init_signals(bunch_list, signal_slice_sets_x, signal_slice_sets_y)
if self._processors_x is not None:
parameters_x, signal_x = self._combiner_x.process()
parameters_x, signal_x = process(parameters_x,
signal_x,
self._processors_x,
slice_sets=signal_slice_sets_x)
if signal_x is not None:
signal_x = signal_x * self._gain_x
self._kick_bunches(signal_x, 'x', local_slice_sets,
bunch_list, self._loc_signal_sets_x)
if self._processors_y is not None:
# print('Kick y, gain: ' + str(self._gain_y))
self._parameters_y, self._signal_y = self._combiner_y.process()
kick_parameters_y, kick_signal_y = process(self._parameters_y,
self._signal_y,
self._processors_y,
slice_sets=signal_slice_sets_y)
if kick_signal_y is not None:
kick_signal_y = kick_signal_y * self._gain_y
self._kick_bunches(kick_signal_y, 'y', local_slice_sets,
bunch_list, self._loc_signal_sets_y)