HPS-MC
_util.py
Go to the documentation of this file.
1 """! alignment utilities"""
2 
3 
5  """! Put beamspot constraints on all parameters regardless of floating """
6  s = '\n!Beamspot constraints\n'
7  for d in ['u', 'v', 'w']:
8  PEDE.logger.debug('d=', d)
9  for t in ['t', 'r']:
10  for iAxial in range(2):
11  active = False
12  PEDE.logger.debug('iAx=', iAxial)
13  for p, name in utils.paramMap.iteritems():
14  PEDE.logger.debug('look at ', name, ' ', p)
15  if utils.getModuleNrFromDeName(name) != 0:
16  continue
17  if (utils.isAxial(name) and iAxial == 0) or (not utils.isAxial(name) and iAxial == 1):
18  continue
19  if utils.getDir(p) == d and utils.getType(p) == t:
20  PEDE.logger.debug('found one', name, ' ', p)
21  if not active:
22  PEDE.logger.debug('ACTIVATE')
23  s += 'Constraint 0.\n'
24  s += '%s %.1f\n' % (p, 1.0)
25  active = True
26  else:
27  PEDE.logger.debug('ADD')
28  s += '%s %.1f\n' % (p, -1.0)
29  return s
30 
31 
33  """! put beamspot constraints onto floating parameters"""
34  s = '\n!Beamspot constraints\n'
35  written1 = 0
36  written2 = 0
37  written3 = 0
38  written4 = 0
39  written5 = 0
40  written6 = 0
41  for p in pars:
42  line = p.toString()
43  if ('98' or '99') in line:
44  parNum = int(line.split()[0])
45  isFloat = float(line.split()[2])
46  if ('1198') in line:
47  if (isFloat == 0):
48  if (parNum < 20000 and written1 == 0):
49  s += 'Constraint 0.\n'
50  s += '%s %.1f\n' % (parNum, 1.0)
51  s += '%s %.1f\n' % (parNum+10000, -1.0)
52  s += 'Constraint 0.\n'
53  s += '%s %.1f\n' % (parNum+1, 1.0)
54  s += '%s %.1f\n' % (parNum+1+10000, -1.0)
55  s += '\n'
56 # s += 'Constraint 0.\n'
57 # s += '%s %.1f\n' % (parNum, 1.0)
58 # s += '%s %.1f\n' % (parNum+1, -1.0)
59 # s += 'Constraint 0.\n'
60 # s += '%s %.1f\n' % (parNum+10000, 1.0)
61 # s += '%s %.1f\n' % (parNum+1+10000, -1.0)
62 # s += '\n'
63 # written1 = 1
64  elif (parNum > 20000 and written1 == 0):
65  s += 'Constraint 0.\n'
66  s += '%s %.1f\n' % (parNum, -1.0)
67  s += '%s %.1f\n' % (parNum-10000, 1.0)
68  s += 'Constraint 0.\n'
69  s += '%s %.1f\n' % (parNum+1, -1.0)
70  s += '%s %.1f\n' % (parNum+1-10000, 1.0)
71  s += '\n'
72 # s += 'Constraint 0.\n'
73 # s += '%s %.1f\n' % (parNum, -1.0)
74 # s += '%s %.1f\n' % (parNum+1, 1.0)
75 # s += 'Constraint 0.\n'
76 # s += '%s %.1f\n' % (parNum-10000, -1.0)
77 # s += '%s %.1f\n' % (parNum+1-10000, 1.0)
78 # s += '\n'
79  written1 = 1
80 
81  if ('2198') in line:
82  if (isFloat == 0):
83  if (parNum < 20000 and written2 == 0):
84  s += 'Constraint 0.\n'
85  s += '%s %.1f\n' % (parNum, 1.0)
86  s += '%s %.1f\n' % (parNum+10000, -1.0)
87  s += 'Constraint 0.\n'
88  s += '%s %.1f\n' % (parNum+1, 1.0)
89  s += '%s %.1f\n' % (parNum+1+10000, -1.0)
90  s += '\n'
91 # s += 'Constraint 0.\n'
92 # s += '%s %.1f\n' % (parNum, 1.0)
93 # s += '%s %.1f\n' % (parNum+1, -1.0)
94 # s += 'Constraint 0.\n'
95 # s += '%s %.1f\n' % (parNum+10000, 1.0)
96 # s += '%s %.1f\n' % (parNum+1+10000, -1.0)
97 # s += '\n'
98  written2 = 1
99  elif (parNum > 20000 and written2 == 0):
100  s += 'Constraint 0.\n'
101  s += '%s %.1f\n' % (parNum, -1.0)
102  s += '%s %.1f\n' % (parNum-10000, 1.0)
103  s += 'Constraint 0.\n'
104  s += '%s %.1f\n' % (parNum+1, -1.0)
105  s += '%s %.1f\n' % (parNum+1-10000, 1.0)
106  s += '\n'
107 # s += 'Constraint 0.\n'
108 # s += '%s %.1f\n' % (parNum, -1.0)
109 # s += '%s %.1f\n' % (parNum+1, 1.0)
110 # s += 'Constraint 0.\n'
111 # s += '%s %.1f\n' % (parNum-10000, -1.0)
112 # s += '%s %.1f\n' % (parNum+1-10000, 1.0)
113 # s += '\n'
114  written2 = 1
115 
116  if ('1298') in line:
117  if (isFloat == 0):
118  if (parNum < 20000 and written3 == 0):
119  s += 'Constraint 0.\n'
120  s += '%s %.1f\n' % (parNum, 1.0)
121  s += '%s %.1f\n' % (parNum+10000, -1.0)
122  s += 'Constraint 0.\n'
123  s += '%s %.1f\n' % (parNum+1, 1.0)
124  s += '%s %.1f\n' % (parNum+1+10000, -1.0)
125  s += '\n'
126 # s += 'Constraint 0.\n'
127 # s += '%s %.1f\n' % (parNum, 1.0)
128 # s += '%s %.1f\n' % (parNum+1, -1.0)
129 # s += 'Constraint 0.\n'
130 # s += '%s %.1f\n' % (parNum+10000, 1.0)
131 # s += '%s %.1f\n' % (parNum+1+10000, -1.0)
132 # s += '\n'
133  written3 = 1
134  elif (parNum > 20000 and written3 == 0):
135  s += 'Constraint 0.\n'
136  s += '%s %.1f\n' % (parNum, -1.0)
137  s += '%s %.1f\n' % (parNum-10000, 1.0)
138  s += 'Constraint 0.\n'
139  s += '%s %.1f\n' % (parNum+1, -1.0)
140  s += '%s %.1f\n' % (parNum+1-10000, 1.0)
141  s += '\n'
142 # s += 'Constraint 0.\n'
143 # s += '%s %.1f\n' % (parNum, -1.0)
144 # s += '%s %.1f\n' % (parNum+1, 1.0)
145 # s += 'Constraint 0.\n'
146 # s += '%s %.1f\n' % (parNum-10000, -1.0)
147 # s += '%s %.1f\n' % (parNum+1-10000, 1.0)
148  written3 = 1
149 
150  if ('2298') in line:
151  if (isFloat == 0):
152  if (parNum < 20000 and written4 == 0):
153  s += 'Constraint 0.\n'
154  s += '%s %.1f\n' % (parNum, 1.0)
155  s += '%s %.1f\n' % (parNum+10000, -1.0)
156  s += 'Constraint 0.\n'
157  s += '%s %.1f\n' % (parNum+1, 1.0)
158  s += '%s %.1f\n' % (parNum+1+10000, -1.0)
159  s += '\n'
160 # s += 'Constraint 0.\n'
161 # s += '%s %.1f\n' % (parNum, 1.0)
162 # s += '%s %.1f\n' % (parNum+1, -1.0)
163 # s += 'Constraint 0.\n'
164 # s += '%s %.1f\n' % (parNum+10000, 1.0)
165 # s += '%s %.1f\n' % (parNum+1+10000, -1.0)
166 # s += '\n'
167  written4 = 1
168  elif (parNum > 20000 and written4 == 0):
169  s += 'Constraint 0.\n'
170  s += '%s %.1f\n' % (parNum, -1.0)
171  s += '%s %.1f\n' % (parNum-10000, 1.0)
172  s += 'Constraint 0.\n'
173  s += '%s %.1f\n' % (parNum+1, -1.0)
174  s += '%s %.1f\n' % (parNum+1-10000, 1.0)
175  s += '\n'
176 # s += 'Constraint 0.\n'
177 # s += '%s %.1f\n' % (parNum, -1.0)
178 # s += '%s %.1f\n' % (parNum+1, 1.0)
179 # s += 'Constraint 0.\n'
180 # s += '%s %.1f\n' % (parNum-10000, -1.0)
181 # s += '%s %.1f\n' % (parNum+1-10000, 1.0)
182 # s += '\n'
183  written4 = 1
184 
185  if ('1398') in line:
186  if (isFloat == 0):
187  if (parNum < 20000 and written5 == 0):
188  s += 'Constraint 0.\n'
189  s += '%s %.1f\n' % (parNum, 1.0)
190  s += '%s %.1f\n' % (parNum+10000, -1.0)
191  s += 'Constraint 0.\n'
192  s += '%s %.1f\n' % (parNum+1, 1.0)
193  s += '%s %.1f\n' % (parNum+1+10000, -1.0)
194  s += '\n'
195 # s += 'Constraint 0.\n'
196 # s += '%s %.1f\n' % (parNum, 1.0)
197 # s += '%s %.1f\n' % (parNum+1, -1.0)
198 # s += 'Constraint 0.\n'
199 # s += '%s %.1f\n' % (parNum+10000, 1.0)
200 # s += '%s %.1f\n' % (parNum+1+10000, -1.0)
201 # s += '\n'
202  written5 = 1
203  elif (parNum > 20000 and written5 == 0):
204  s += 'Constraint 0.\n'
205  s += '%s %.1f\n' % (parNum, -1.0)
206  s += '%s %.1f\n' % (parNum-10000, 1.0)
207  s += 'Constraint 0.\n'
208  s += '%s %.1f\n' % (parNum+1, -1.0)
209  s += '%s %.1f\n' % (parNum+1-10000, 1.0)
210  s += '\n'
211 # s += 'Constraint 0.\n'
212 # s += '%s %.1f\n' % (parNum, -1.0)
213 # s += '%s %.1f\n' % (parNum+1, 1.0)
214 # s += 'Constraint 0.\n'
215 # s += '%s %.1f\n' % (parNum-10000, -1.0)
216 # s += '%s %.1f\n' % (parNum+1-10000, 1.0)
217 # s += '\n'
218  written5 = 1
219 
220  if ('2398') in line:
221  if (isFloat == 0):
222  if (parNum < 20000 and written6 == 0):
223  s += 'Constraint 0.\n'
224  s += '%s %.1f\n' % (parNum, 1.0)
225  s += '%s %.1f\n' % (parNum+10000, -1.0)
226  s += 'Constraint 0.\n'
227  s += '%s %.1f\n' % (parNum+1, 1.0)
228  s += '%s %.1f\n' % (parNum+1+10000, -1.0)
229  s += '\n'
230 # s += 'Constraint 0.\n'
231 # s += '%s %.1f\n' % (parNum, 1.0)
232 # s += '%s %.1f\n' % (parNum+1, -1.0)
233 # s += 'Constraint 0.\n'
234 # s += '%s %.1f\n' % (parNum+10000, 1.0)
235 # s += '%s %.1f\n' % (parNum+1+10000, -1.0)
236 # s += '\n'
237  written6 = 1
238  elif (parNum > 20000 and written6 == 0):
239  s += 'Constraint 0.\n'
240  s += '%s %.1f\n' % (parNum, -1.0)
241  s += '%s %.1f\n' % (parNum-10000, 1.0)
242  s += 'Constraint 0.\n'
243  s += '%s %.1f\n' % (parNum+1, -1.0)
244  s += '%s %.1f\n' % (parNum+1-10000, -1.0)
245  s += '\n'
246 # s += 'Constraint 0.\n'
247 # s += '%s %.1f\n' % (parNum, -1.0)
248 # s += '%s %.1f\n' % (parNum+1, 1.0)
249 # s += 'Constraint 0.\n'
250 # s += '%s %.1f\n' % (parNum-10000, -1.0)
251 # s += '%s %.1f\n' % (parNum+1-10000, 1.0)
252 # s += '\n'
253  written6 = 1
254 
255  return s
def getBeamspotConstraints(parMap)
Put beamspot constraints on all parameters regardless of floating.
Definition: _util.py:4
def getBeamspotConstraintsFloatingOnly(pars)
put beamspot constraints onto floating parameters
Definition: _util.py:32