-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathwaveform.py
577 lines (476 loc) · 15.2 KB
/
waveform.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
import sys
import os
import math
from orbit.utils import NamedObject, TypedObject
class Waveform(NamedObject, TypedObject):
"""
The base abstract class of waveforms hierarchy.
"""
def __init__(self, name="no name"):
NamedObject.__init__(self, name)
TypedObject.__init__(self, "base waveform")
class KickerWaveform(Waveform):
"""
Subclass of Waveform class. The abstract class of kicker waveforms.
"""
def __init__(self, name="no name"):
Waveform.__init__(self, name)
self.setType("kicker waveform")
self.kx = None
self.ky = None
def setKx(self, kx):
self.kx = kx
def getKx(self):
return self.kx
def setKy(self, ky):
self.ky = ky
def getKy(self):
return self.ky
class ConstantKickerWaveform(KickerWaveform):
"""
Kicker waveform of constant strength.
"""
def __init__(self, name="no name"):
KickerWaveform.__init__(self, name)
def initialize(self, kx, ky):
self.setKx(kx)
self.setKy(ky)
def calc(self, time):
pass
class SquareRootKickerWaveform(KickerWaveform):
"""
Square Root Waveform of Kicker.
"""
def __init__(self, name="no name"):
KickerWaveform.__init__(self, name)
self.__initial = []
def initialize(self, t1, t2, kx, ky, dx, dy):
self.__initial = (t1, t2, dx, dy)
self.setKx(kx)
self.setKy(ky)
def calc(self, time):
t = time
(t1, t2, dx, dy) = self.__initial
dt = sqrt((t - t1) / (t2 - t1))
self.setKx(self.getKx() * (1 - dt) + dx)
self.setKy(self.getKy() * (1 - dt) + dy)
class MagnetWaveform(Waveform):
"""
Subclass of Waveform class. The abstract class of magnet waveforms.
"""
def __init__(self, name="no name"):
Waveform.__init__(self, name)
self.setType("magnet waveform")
self.strength = None
def setStrength(self, strength):
self.strength = strength
def getStrength(self):
return self.strength
class ConstantMagnetWaveform(MagnetWaveform):
"""
Magnet waveform of constant strength.
"""
def __init__(self, name="no name"):
MagnetWaveform.__init__(self, name)
def initialize(self, strength):
self.setStrength(strength)
def calc(self, time):
pass
class LinearMagnetWaveform(MagnetWaveform):
"""
Linear lattice strength variation between t1 and t2
"""
def __init__(self, name="no name"):
MagnetWaveform.__init__(self, name)
self.__initial = []
def initialize(self, t1, t2, s1, s2):
self.__initial = (t1, t2, s1, s2)
def calc(self, t):
(t1, t2, s1, s2) = self.__initial
if t < t1:
self.strength = s1
elif t > t2:
self.strength = s2
else:
dt = (t - t1) / (t2 - t1)
self.setStrength(s1 + dt * (s2 - s1))
class ConstantWaveform:
"""
Waveform of constant strength.
"""
def __init__(self, syncpart, lattlength, strength):
self.name = "constant waveform"
self.syncpart = syncpart
self.lattlength = lattlength
self.strength = strength
def getStrength(self):
return self.strength
class SquareRootWaveform:
"""
Square root waveform.
"""
def __init__(self, syncpart, lattlength, ti, tf, si, sf):
self.name = "square root waveform"
self.syncpart = syncpart
self.lattlength = lattlength
self.ti = ti
self.tf = tf
self.si = si
self.sf = sf
def getStrength(self):
time = self.syncpart.time()
if time < self.ti:
strength = self.si
elif time > self.tf:
strength = self.sf
else:
dt = math.sqrt((time - self.ti) / (self.tf - self.ti))
strength = (self.si - self.sf) * (1.0 - dt) + self.sf
return strength
class LinearWaveform:
"""
Linear strength variation between ti and tf
"""
def __init__(self, syncpart, lattlength, ti, tf, si, sf):
self.name = "linear waveform"
self.syncpart = syncpart
self.lattlength = lattlength
self.ti = ti
self.tf = tf
self.si = si
self.sf = sf
def getStrength(self):
time = self.syncpart.time()
if time < self.ti:
strength = self.si
elif time > self.tf:
strength = self.sf
else:
dt = (time - self.ti) / (self.tf - self.ti)
strength = (self.sf - self.si) * dt + self.si
return strength
class OneTimeKick:
"""
Deliver a single kick on a specific turn
"""
def __init__(self, syncpart, lattlength, kickturn, strength):
self.name = "linear waveform"
self.syncpart = syncpart
self.lattlength = lattlength
self.kickturn = kickturn
self.strength = strength
self.turn = 0
def setturn(self, turn):
self.turn = turn
def getStrength(self):
strength = 0.0
if self.turn == self.kickturn:
strength = self.strength
return strength
class JPARC_08:
"""
Generates noise signal QFL
"""
def __init__(self, syncpart, lattlength):
self.name = "JPARC_08"
self.syncpart = syncpart
self.lattlength = lattlength
def getStrength(self):
# time in msec, since this taken from old ORBIT
time = 1000.0 * self.syncpart.time()
QFLBase = 0.156944849901
QFLNoise = time * (
-0.0002569
+ time
* (
0.00054243
+ time
* (
-0.00012826
+ time
* (
0.000016387
+ time * (-0.0000012873 + time * (0.000000061252 + time * (-0.0000000016099 + time * (0.000000000017885))))
)
)
)
)
strength = (QFLBase + QFLNoise) / QFLBase
return strength
class JPARC_09:
"""
Generates noise signal QDL
"""
def __init__(self, syncpart, lattlength):
self.name = "JPARC_09"
self.syncpart = syncpart
self.lattlength = lattlength
def getStrength(self):
# time in msec, since this taken from old ORBIT
time = 1000.0 * self.syncpart.time()
QDLBase = -0.167375195725
QDLNoise = time * (
0.000031569
+ time
* (
-0.00022683
+ time
* (
0.000075352
+ time
* (
-0.000012569
+ time * (0.0000011936 + time * (-0.000000064555 + time * (0.0000000018493 + time * (-0.00000000002179))))
)
)
)
)
strength = (QDLBase + QDLNoise) / QDLBase
return strength
class JPARC_15:
"""
Generates noise signal QFM
"""
def __init__(self, syncpart, lattlength):
self.name = "JPARC_15"
self.syncpart = syncpart
self.lattlength = lattlength
def getStrength(self):
# time in msec, since this taken from old ORBIT
time = 1000.0 * self.syncpart.time()
QFMBase = 0.150484620592
QFMNoise = time * (
-0.00039206
+ time
* (
0.00072671
+ time
* (
-0.00015812
+ time
* (
0.000018344
+ time * (-0.0000013108 + time * (0.000000057474 + time * (-0.0000000014143 + time * (0.000000000014925))))
)
)
)
)
strength = (QFMBase + QFMNoise) / QFMBase
return strength
class JPARC_8to9and15:
"""
Generates noise signal
"""
def __init__(self, syncpart, lattlength, QBase, Coeffs):
self.name = "JPARC_8to9and15"
self.syncpart = syncpart
self.lattlength = lattlength
self.QBase = QBase
self.Coeffs = Coeffs
def getStrength(self):
# time in msec, since this taken from old ORBIT
time = 1000.0 * self.syncpart.time()
QNoise = time * (
self.Coeffs[0]
+ time
* (
self.Coeffs[1]
+ time
* (
self.Coeffs[2]
+ time
* (
self.Coeffs[3]
+ time * (self.Coeffs[4] + time * (self.Coeffs[5] + time * (self.Coeffs[6] + time * (self.Coeffs[7]))))
)
)
)
)
strength = (self.QBase + QNoise) / self.QBase
return strength
class JPARC_12:
"""
Pranab 2011/07/27: copied from rcsdel05.
For time-dependent Sextupoles
"""
def __init__(self, syncpart, lattlength):
self.name = "JPARC_12"
self.syncpart = syncpart
self.lattlength = lattlength
def getStrength(self):
Bsync0 = 0.1808950855 # JPARC 181 MeV
gamma0 = (self.syncpart.mass + 0.181) / self.syncpart.mass
mom0 = math.sqrt((gamma0 + 1.0) * (gamma0 - 1.0))
mom = math.sqrt((self.syncpart.gamma + 1.0) * (self.syncpart.gamma - 1.0))
strength = mom0 / mom
return strength
class JPARC_14:
"""
Pranab 2011/07/27: copied from rcsdel05.
For time-dependent Sextupoles
"""
def __init__(self, syncpart, lattlength):
self.name = "JPARC_14"
self.syncpart = syncpart
self.lattlength = lattlength
def getStrength(self):
Bsync0 = 0.2828661203 # JPARC 400 MeV
gamma0 = (self.syncpart.mass + 0.400) / self.syncpart.mass
mom0 = math.sqrt((gamma0 + 1.0) * (gamma0 - 1.0))
mom = math.sqrt((self.syncpart.gamma + 1.0) * (self.syncpart.gamma - 1.0))
strength = mom0 / mom
return strength
class JPARC_12and14:
"""
Pranab 2011/07/27: copied from rcsdel05.
For time-dependent Sextupoles
"""
def __init__(self, syncpart, lattlength, ke0):
self.name = "JPARC_12and14"
self.syncpart = syncpart
self.lattlength = lattlength
self.ke0 = ke0
def getStrength(self):
gamma0 = (self.syncpart.mass + ke0) / self.syncpart.mass
mom0 = math.sqrt((gamma0 + 1.0) * (gamma0 - 1.0))
mom = math.sqrt((self.syncpart.gamma + 1.0) * (self.syncpart.gamma - 1.0))
strength = mom0 / mom
return strength
class JPARC_16to19:
"""
Pranab: BM 1kZ ripple WF16-19
tinit time is adjusted to match the measured beam
oscillation(turn-by-turn)
"""
def __init__(self, syncpart, lattlength, kebot, tinit, tdt, BMripple):
self.name = "JPARC_16to19"
self.syncpart = syncpart
self.lattlength = lattlength
self.kebot = kebot
self.tinit = tinit
self.tdt = tdt
self.BMripple = BMripple
def getStrength(self):
time = self.syncpart.time()
BcalNew1 = math.sin(math.pi * (time - self.tinit) / self.tdt)
strength = BcalNew1 * self.kebot * self.BMripple / self.syncpart.kinEnergy()
return strength
class JPARC_20:
"""
Pranab: DC leakage field with strength factor
"""
def __init__(self, syncpart, lattlength, ke0, LeakFld):
self.name = "JPARC_20"
self.syncpart = syncpart
self.lattlength = lattlength
self.ke0 = ke0
self.LeakFld = LeakFld
def getStrength(self):
gamma0 = (self.syncpart.mass() + self.ke0) / self.syncpart.mass()
mom0 = math.sqrt((gamma0 + 1.0) * (gamma0 - 1.0))
mom = math.sqrt((self.syncpart.gamma() + 1.0) * (self.syncpart.gamma() - 1.0))
strength = mom0 * self.LeakFld / mom
return strength
class JPARC_21to27:
"""
Pranab: DC leakage field with strength factor
"""
def __init__(self, syncpart, lattlength, QNoise):
self.name = "JPARC_21to27"
self.syncpart = syncpart
self.lattlength = lattlength
self.QNoise = QNoise
self.time = []
self.dQ = []
Noise_in = open(self.QNoise, "r")
for line in Noise_in.readlines():
splitline = line.split()
value = map(float, splitline)
self.time.append(value[0])
self.dQ.append(value[1])
self.turn = 0
def getStrength(self):
dQVal = self.dQ[self.turn]
self.turn = self.turn + 1
strength = 1.0 + dQVal
return strength
class JPARC_28:
"""
Pranab 2016/03/14: Sextupole user-defined pattern.
Linear between ti -> tf, constant outside.
Set to J-PARC parameters.
"""
def __init__(self, syncpart, lattlength, ti, tf, si, sf):
self.name = "JPARC_28"
self.syncpart = syncpart
self.lattlength = lattlength
self.ti = ti
self.tf = tf
self.si = si
self.sf = sf
def getStrength(self):
Bsync0 = 0.2828661203 # JPARC 400 MeV
gamma0 = (self.syncpart.mass() + 0.400) / self.syncpart.mass()
mom0 = math.sqrt((gamma0 + 1.0) * (gamma0 - 1.0))
mom = math.sqrt((self.syncpart.gamma() + 1.0) * (self.syncpart.gamma() - 1.0))
Bsync = Bsync0 * mom / mom0
stri = Bsync0 * self.si / Bsync
strf = self.sf
time = self.syncpart.time()
if time <= self.ti:
strength = stri
elif time > self.tf:
strength = strf
else:
dt = (time - self.ti) / (self.tf - self.ti)
strength = (strf - stri) * dt + stri
return strength
class JPARC_31to34:
"""
Pranab 2016/04/12: Square Root Waveform for multipole hkickers.
"""
def __init__(self, syncpart, lattlength, ti, tf, tflin, tsclin, tcutoff, six, sfx, siy, sfy):
self.name = "JPARC_31to34"
self.syncpart = syncpart
self.lattlength = lattlength
self.ti = ti
self.tf = tf
self.tflin = tflin
self.tsclin = tsclin
self.tcutoff = tcutoff
self.six = six
self.sfx = sfx
self.siy = siy
self.sfy = sfy
def getStrength(self):
time = self.syncpart.time()
dt = 0.0
if time <= self.tflin:
dt = (time - self.ti) / (self.tsclin - self.ti)
if dt < 0.0:
dt = 0.0
if dt > 1.0:
dt = 1.0
sx = (self.sfx - self.six) * dt + self.six
sy = (self.sfy - self.siy) * dt + self.siy
elif (time > self.tflin) and (time <= self.tf):
dt = math.sqrt((time - self.ti) / (self.tf - self.ti))
if dt < 0.0:
dt = 0.0
if dt > 1.0:
dt = 1.0
sx = (self.sfx - self.six) * dt + self.six
sy = (self.sfy - self.siy) * dt + self.siy
elif (time > self.tf) and (time <= self.tcutoff):
dt = (time - self.tf) / (self.tcutoff - self.tf)
if dt < 0.0:
dt = 0.0
if dt > 1.0:
dt = 1.0
sx = self.sfx * (1.0 - dt)
sy = self.sfy * (1.0 - dt)
else:
sx = 0.0
sy = 0.0
strength = sx
return strength