@@ -14,27 +14,31 @@ def __init__(self, optics_mode, circumference=None, n_segments=None, s=None, nam
1414 accQ_x = None , accQ_y = None , Qp_x = 0 , Qp_y = 0 , app_x = 0 , app_y = 0 , app_xy = 0 ,
1515 alpha_mom_compaction = None , longitudinal_mode = None , Q_s = None ,
1616 h_RF = None , V_RF = None , dphi_RF = None , p0 = None , p_increment = None ,
17- charge = None , mass = None , RF_at = 'middle' , other_detuners = [],
18- use_cython = True , ** kwargs ):
17+ charge = None , mass = None , RF_at = 'middle' , other_detuners = [],
18+ use_cython = True , verbose = False , ** kwargs ):
19+
1920
20-
2121 self .optics_mode = optics_mode
2222 self .longitudinal_mode = longitudinal_mode
2323 self .charge = charge
2424 self .mass = mass
2525 self .p0 = p0
26-
26+
2727 self .one_turn_map = []
2828
29- # construct transverse map
30- self ._contruct_transverse_map (optics_mode = optics_mode , circumference = circumference , n_segments = n_segments , s = s , name = name ,
29+ # construct transverse map
30+ self ._construct_transverse_map (optics_mode = optics_mode , circumference = circumference , n_segments = n_segments , s = s , name = name ,
3131 alpha_x = alpha_x , beta_x = beta_x , D_x = D_x , alpha_y = alpha_y , beta_y = beta_y , D_y = D_y ,
3232 accQ_x = accQ_x , accQ_y = accQ_y , Qp_x = Qp_x , Qp_y = Qp_y , app_x = app_x , app_y = app_y , app_xy = app_xy , other_detuners = other_detuners ,
3333 use_cython = use_cython )
34-
35- # construct longitudinal map
36- self ._contruct_longitudinal_map (alpha_mom_compaction = alpha_mom_compaction , longitudinal_mode = longitudinal_mode , Q_s = Q_s ,
37- h_RF = h_RF , V_RF = V_RF , dphi_RF = dphi_RF , p_increment = p_increment , RF_at = RF_at )
34+
35+ # construct longitudinal map
36+ self ._construct_longitudinal_map (alpha_mom_compaction = alpha_mom_compaction , longitudinal_mode = longitudinal_mode , Q_s = Q_s ,
37+ h_RF = h_RF , V_RF = V_RF , dphi_RF = dphi_RF , p_increment = p_increment , RF_at = RF_at )
38+
39+ if verbose :
40+ from pprint import pprint
41+ pprint ([vars (m ) for m in self .one_turn_map ])
3842
3943 @property
4044 def gamma (self ):
@@ -66,15 +70,15 @@ def p0(self):
6670 @p0 .setter
6771 def p0 (self , value ):
6872 self .gamma = 1 / (c * self .mass ) * np .sqrt (value ** 2 + self .mass ** 2 * c ** 2 )
69-
73+
7074 @property
71- def Q_x (self ):
72- return np .atleast_1d (self .transverse_map .accQ_x )[- 1 ]
73-
75+ def Q_x (self ):
76+ return np .atleast_1d (self .transverse_map .accQ_x )[- 1 ]
77+
7478 @property
75- def Q_y (self ):
76- return np .atleast_1d (self .transverse_map .accQ_y )[- 1 ]
77-
79+ def Q_y (self ):
80+ return np .atleast_1d (self .transverse_map .accQ_y )[- 1 ]
81+
7882 def track (self , bunch , verbose = False ):
7983 for m in self .one_turn_map :
8084 if verbose :
@@ -111,25 +115,25 @@ def generate_6D_Gaussian_bunch(self, n_macroparticles, intensity,
111115 else :
112116 raise NotImplementedError (
113117 'Something wrong with self.longitudinal_mode' )
114-
118+
115119 eta = self .longitudinal_map .alpha_array [0 ] - self .gamma ** - 2
116120 beta_z = np .abs (eta )* self .circumference / 2. / np .pi / Qs
117121 sigma_dp = sigma_z / beta_z
118122 epsx_geo = epsn_x / self .betagamma
119123 epsy_geo = epsn_y / self .betagamma
120-
124+
121125 injection_optics = self .transverse_map .get_injection_optics ()
122-
126+
123127 bunch = gen .ParticleGenerator (macroparticlenumber = n_macroparticles ,
124128 intensity = intensity , charge = self .charge , mass = self .mass ,
125129 circumference = self .circumference , gamma = self .gamma ,
126130 distribution_x = gen .gaussian2D (epsx_geo ), alpha_x = injection_optics ['alpha_x' ], beta_x = injection_optics ['beta_x' ], D_x = injection_optics ['D_x' ],
127131 distribution_y = gen .gaussian2D (epsy_geo ), alpha_y = injection_optics ['alpha_y' ], beta_y = injection_optics ['beta_y' ], D_y = injection_optics ['D_y' ],
128132 distribution_z = gen .cut_distribution (gen .gaussian2D_asymmetrical (sigma_u = sigma_z , sigma_up = sigma_dp ),is_accepted = check_inside_bucket ),
129133 ).generate ()
130-
134+
131135 return bunch
132-
136+
133137 def generate_6D_Gaussian_bunch_matched (
134138 self , n_macroparticles , intensity , epsn_x , epsn_y ,
135139 sigma_z = None , epsn_z = None ):
@@ -140,48 +144,48 @@ def generate_6D_Gaussian_bunch_matched(
140144 the non-linear bucket. Thus, the bunch length should amount
141145 to the one specificed and should not change significantly
142146 during the synchrotron motion.
143-
147+
144148 Requires self.longitudinal_mode == 'non-linear'
145149 for the bucket.
146150 '''
147151 assert self .longitudinal_mode == 'non-linear'
148152 epsx_geo = epsn_x / self .betagamma
149153 epsy_geo = epsn_y / self .betagamma
150-
154+
151155 injection_optics = self .transverse_map .get_injection_optics ()
152-
156+
153157 bunch = gen .ParticleGenerator (macroparticlenumber = n_macroparticles ,
154158 intensity = intensity , charge = self .charge , mass = self .mass ,
155159 circumference = self .circumference , gamma = self .gamma ,
156160 distribution_x = gen .gaussian2D (epsx_geo ), alpha_x = injection_optics ['alpha_x' ], beta_x = injection_optics ['beta_x' ], D_x = injection_optics ['D_x' ],
157161 distribution_y = gen .gaussian2D (epsy_geo ), alpha_y = injection_optics ['alpha_y' ], beta_y = injection_optics ['beta_y' ], D_y = injection_optics ['D_y' ],
158162 distribution_z = gen .RF_bucket_distribution (self .longitudinal_map .get_bucket (gamma = self .gamma ), sigma_z = sigma_z , epsn_z = epsn_z ),
159163 ).generate ()
160-
164+
161165 return bunch
162-
163- def _contruct_transverse_map (self , optics_mode = None , circumference = None , n_segments = None , s = None , name = None ,
166+
167+ def _construct_transverse_map (self , optics_mode = None , circumference = None , n_segments = None , s = None , name = None ,
164168 alpha_x = None , beta_x = None , D_x = None , alpha_y = None , beta_y = None , D_y = None ,
165169 accQ_x = None , accQ_y = None , Qp_x = None , Qp_y = None , app_x = None , app_y = None , app_xy = None , other_detuners = None ,
166- use_cython = None ):
167-
168- if use_cython :
169- try :
170- from PyHEADTAIL .trackers .transverse_tracking_cython import TransverseMap
171- from PyHEADTAIL .trackers .detuners_cython import (Chromaticity ,
172- AmplitudeDetuning )
173- except ImportError as e :
174- print ("*** Warning: could not import cython variants of trackers, "
175- "did you cythonize (use the following command)?\n "
176- "$ make \n "
177- "Falling back to (slower) python version." )
178- from PyHEADTAIL .trackers .transverse_tracking import TransverseMap
179- from PyHEADTAIL .trackers .detuners import Chromaticity , AmplitudeDetuning
170+ use_cython = None ):
171+
172+ if use_cython :
173+ try :
174+ from PyHEADTAIL .trackers .transverse_tracking_cython import TransverseMap
175+ from PyHEADTAIL .trackers .detuners_cython import (Chromaticity ,
176+ AmplitudeDetuning )
177+ except ImportError as e :
178+ print ("*** Warning: could not import cython variants of trackers, "
179+ "did you cythonize (use the following command)?\n "
180+ "$ make \n "
181+ "Falling back to (slower) python version." )
182+ from PyHEADTAIL .trackers .transverse_tracking import TransverseMap
183+ from PyHEADTAIL .trackers .detuners import Chromaticity , AmplitudeDetuning
180184 else :
181- "Transverse tracking: forcing python implementation."
182- from PyHEADTAIL .trackers .transverse_tracking import TransverseMap
183- from PyHEADTAIL .trackers .detuners import Chromaticity , AmplitudeDetuning
184-
185+ "Transverse tracking: forcing python implementation."
186+ from PyHEADTAIL .trackers .transverse_tracking import TransverseMap
187+ from PyHEADTAIL .trackers .detuners import Chromaticity , AmplitudeDetuning
188+
185189
186190 if optics_mode == 'smooth' :
187191 if circumference is None :
@@ -216,14 +220,14 @@ def _contruct_transverse_map(self, optics_mode=None, circumference=None, n_segme
216220
217221 else :
218222 raise ValueError ('optics_mode not recognized' )
219-
223+
220224 detuners = []
221225 if Qp_x != 0 or Qp_y != 0 :
222- detuners .append (Chromaticity (Qp_x , Qp_y ))
226+ detuners .append (Chromaticity (Qp_x , Qp_y ))
223227 if app_x != 0 or app_y != 0 or app_xy != 0 :
224- detuners .append (AmplitudeDetuning (app_x , app_y , app_xy ))
225- detuners += other_detuners
226-
228+ detuners .append (AmplitudeDetuning (app_x , app_y , app_xy ))
229+ detuners += other_detuners
230+
227231 self .transverse_map = TransverseMap (s = s ,
228232 alpha_x = alpha_x ,
229233 beta_x = beta_x ,
@@ -232,16 +236,16 @@ def _contruct_transverse_map(self, optics_mode=None, circumference=None, n_segme
232236 beta_y = beta_y ,
233237 D_y = D_y ,
234238 accQ_x = accQ_x , accQ_y = accQ_y , detuners = detuners )
235-
239+
236240 self .circumference = s [- 1 ]
237241 self .transverse_map .n_segments = len (s )- 1
238-
242+
239243 if name is None :
240- self .transverse_map .name = ['P_%d' % ip for ip in xrange (len (s )- 1 )]
244+ self .transverse_map .name = ['P_%d' % ip for ip in xrange (len (s )- 1 )]
241245 self .transverse_map .name .append ('end_ring' )
242246 else :
243247 self .transverse_map .name = name
244-
248+
245249 for i_seg , m in enumerate (self .transverse_map ):
246250 m .i0 = i_seg
247251 m .i1 = i_seg + 1
@@ -252,48 +256,48 @@ def _contruct_transverse_map(self, optics_mode=None, circumference=None, n_segme
252256 m .beta_x0 = self .transverse_map .beta_x [i_seg ]
253257 m .beta_x1 = self .transverse_map .beta_x [i_seg + 1 ]
254258 m .beta_y0 = self .transverse_map .beta_y [i_seg ]
255- m .beta_y1 = self .transverse_map .beta_y [i_seg + 1 ]
256-
259+ m .beta_y1 = self .transverse_map .beta_y [i_seg + 1 ]
260+
257261 # insert transverse map in the ring
258262 for m in self .transverse_map :
259263 self .one_turn_map .append (m )
260264
261- def _contruct_longitudinal_map (self , alpha_mom_compaction = None , longitudinal_mode = None , Q_s = None ,
265+ def _construct_longitudinal_map (self , alpha_mom_compaction = None , longitudinal_mode = None , Q_s = None ,
262266 h_RF = None , V_RF = None , dphi_RF = None , p_increment = None , RF_at = None ):
263-
267+
264268 if longitudinal_mode is None :
265- return
269+ return
266270
267271 if RF_at == 'middle' :
268- # compute the index of the element before which to insert
269- # the longitudinal map
270- if longitudinal_mode is not None :
271- for insert_before , si in enumerate (self .transverse_map .s ):
272- if si > 0.5 * self .circumference :
273- break
272+ # compute the index of the element before which to insert
273+ # the longitudinal map
274+ if longitudinal_mode is not None :
275+ for insert_before , si in enumerate (self .transverse_map .s ):
276+ if si > 0.5 * self .circumference :
277+ break
274278 elif RF_at == 'end_of_transverse' :
275- insert_before = - 1
279+ insert_before = - 1
276280 else :
277- raise ValueError ('RF_at=%s not recognized!' )
278-
279-
281+ raise ValueError ('RF_at=%s not recognized!' )
282+
283+
280284 if longitudinal_mode == 'linear' :
281-
282- eta = alpha_mom_compaction - self .gamma ** - 2
283-
284- if Q_s == None :
285- if p_increment != 0 or dphi_RF != 0 :
286- raise ValueError ('Formula not valid in this case!!!!' )
287- else :
288- Q_s = np .sqrt ( e * np .abs (eta )* (h_RF * V_RF )
289- / (2 * np .pi * self .p0 * self .beta * c ) )
285+
286+ eta = alpha_mom_compaction - self .gamma ** - 2
287+
288+ if Q_s == None :
289+ if p_increment != 0 or dphi_RF != 0 :
290+ raise ValueError ('Formula not valid in this case!!!!' )
291+ else :
292+ Q_s = np .sqrt ( e * np .abs (eta )* (h_RF * V_RF )
293+ / (2 * np .pi * self .p0 * self .beta * c ) )
290294
291295 self .longitudinal_map = LinearMap (
292296 np .atleast_1d (alpha_mom_compaction ),
293297 self .circumference , Q_s ,
294298 D_x = self .transverse_map .D_x [insert_before ],
295299 D_y = self .transverse_map .D_y [insert_before ])
296-
300+
297301 elif longitudinal_mode == 'non-linear' :
298302 self .longitudinal_map = RFSystems (
299303 self .circumference , np .atleast_1d (h_RF ),
@@ -308,6 +312,6 @@ def _contruct_longitudinal_map(self, alpha_mom_compaction=None, longitudinal_mod
308312 'Something wrong with longitudinal_mode' )
309313
310314 if insert_before == - 1 :
311- self .one_turn_map .append (self .longitudinal_map )
315+ self .one_turn_map .append (self .longitudinal_map )
312316 else :
313- self .one_turn_map .insert (insert_before , self .longitudinal_map )
317+ self .one_turn_map .insert (insert_before , self .longitudinal_map )
0 commit comments