Skip to content

Commit 64df551

Browse files
committed
Refactored backend such that uncertainties are always registered with an individual cutoff for rng generation
1 parent 95156e4 commit 64df551

File tree

5 files changed

+53
-45
lines changed

5 files changed

+53
-45
lines changed

SCapplyErrors.m

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,8 @@
102102

103103
% Loop over uncertainties
104104
for field=fieldnames(SC.SIG.RF{ord})'
105-
% Check if individual cutoff is defined
106-
if iscell(SC.SIG.RF{ord}.(field{1}))
107-
SC.RING{ord}.(field{1}) = SC.SIG.RF{ord}.(field{1}){1} * SCrandnc(SC.SIG.RF{ord}.(field{1}){2});
108-
else
109-
SC.RING{ord}.(field{1}) = SC.SIG.RF{ord}.(field{1}) * SCrandnc(par.nSig);
110-
end
105+
% Apply errors
106+
SC.RING{ord}.(field{1}) = rndn_cutoff(SC.SIG.RF{ord}.(field{1}),par.nSig);
111107
end
112108
end
113109
end
@@ -152,12 +148,8 @@
152148
if regexp(field{1},'Noise')
153149
SC.RING{ord}.(field{1}) = SC.SIG.BPM{ord}.(field{1});
154150
else
155-
% Check if individual cutoff is defined
156-
if iscell(SC.SIG.BPM{ord}.(field{1}))
157-
SC.RING{ord}.(field{1}) = SC.SIG.BPM{ord}.(field{1}){1} .* SCrandnc(SC.SIG.BPM{ord}.(field{1}){2},size(SC.SIG.BPM{ord}.(field{1}){1}));
158-
else
159-
SC.RING{ord}.(field{1}) = SC.SIG.BPM{ord}.(field{1}) .* SCrandnc(par.nSig,size(SC.SIG.BPM{ord}.(field{1})));
160-
end
151+
% Apply errors
152+
SC.RING{ord}.(field{1}) = rndn_cutoff(SC.SIG.BPM{ord}.(field{1}),par.nSig);
161153
end
162154
end
163155
end
@@ -168,8 +160,12 @@
168160
% Circumference error
169161
function SC = applyCircumferenceError(SC,par)
170162
if isfield(SC.SIG,'Circumference')
171-
% Define circumference error
172-
circScaling = 1 + SC.SIG.Circumference * SCrandnc(par.nSig,1,1);
163+
% Check if individual cutoff is defined
164+
if iscell(SC.SIG.Circumference)
165+
circScaling = 1 + SC.SIG.Circumference{1} * SCrandnc(SC.SIG.Circumference{2},1,1);
166+
else
167+
circScaling = 1 + SC.SIG.Circumference * SCrandnc(par.nSig,1,1);
168+
end
173169
% Apply circumference error
174170
SC.RING = SCscaleCircumference(SC.RING,circScaling,'rel');
175171
fprintf('Circumference error applied.\n');
@@ -182,7 +178,7 @@
182178
function SC = applySupportAlignmentError(SC,par)
183179

184180
% Loop over different support types
185-
for type = {'Girder','Plinth','Section'}
181+
for type = {'Section','Plinth','Girder'}
186182
% Check if support type is registered
187183
if ~isfield(SC.ORD,type{1})
188184
continue;
@@ -201,24 +197,14 @@
201197
if isempty(strfind(field{1},type{1}))
202198
continue;
203199
end
204-
200+
205201
% Generate random error for support structure beginning
206-
if iscell(SC.SIG.Support{ordPair(1)}.(field{1}))
207-
% Individual cutoff is given
208-
SC.RING{ordPair(1)}.(field{1}) = SC.SIG.Support{ordPair(1)}.(field{1}){1} .* SCrandnc(SC.SIG.Support{ordPair(1)}.(field{1}){2},size(SC.SIG.Support{ordPair(1)}.(field{1}){1}));
209-
else
210-
SC.RING{ordPair(1)}.(field{1}) = SC.SIG.Support{ordPair(1)}.(field{1}) .* SCrandnc(par.nSig,size(SC.SIG.Support{ordPair(1)}.(field{1})));
211-
end
202+
SC.RING{ordPair(1)}.(field{1}) = rndn_cutoff(SC.SIG.Support{ordPair(1)}.(field{1}),par.nSig);
212203

213204
% Check if uncertanty is specified for endpoint
214205
if length(SC.SIG.Support)>=ordPair(2) && isfield(SC.SIG.Support{ordPair(2)},field{1})
215206
% Generate random error for support structure endpoint
216-
if iscell(SC.SIG.Support{ordPair(2)}.(field{1}))
217-
% Individual cutoff is given
218-
SC.RING{ordPair(2)}.(field{1}) = SC.SIG.Support{ordPair(2)}.(field{1}){1} .* SCrandnc(SC.SIG.Support{ordPair(2)}.(field{1}){2},size(SC.SIG.Support{ordPair(2)}.(field{1}){1}));
219-
else
220-
SC.RING{ordPair(2)}.(field{1}) = SC.SIG.Support{ordPair(2)}.(field{1}) .* SCrandnc(par.nSig,size(SC.SIG.Support{ordPair(2)}.(field{1})));
221-
end
207+
SC.RING{ordPair(2)}.(field{1}) = rndn_cutoff(SC.SIG.Support{ordPair(2)}.(field{1}),par.nSig);
222208
else
223209
% Copy support structure endpoint from structure beginning
224210
SC.RING{ordPair(2)}.(field{1}) = SC.RING{ordPair(1)}.(field{1});
@@ -284,24 +270,23 @@
284270
end
285271
% Loop over uncertanties
286272
for field=fieldnames(SC.SIG.Mag{ord})'
287-
% Check if individual cutoff is given
288-
if iscell(SC.SIG.Mag{ord}.(field{1}))
289-
nSig = SC.SIG.Mag{ord}.(field{1}){2};
290-
sig = SC.SIG.Mag{ord}.(field{1}){1};
291-
else
292-
nSig = par.nSig;
293-
sig = SC.SIG.Mag{ord}.(field{1});
294-
end
295-
296273
% Bending angle error gets applied differently
297274
if strcmp(field{1},'BendingAngle')
298-
SC.RING{ord}.BendingAngleError = sig * SCrandnc(nSig,1,1);
275+
SC.RING{ord}.BendingAngleError = rndn_cutoff(SC.SIG.Mag{ord}.(field{1}),par.nSig);
299276
else
300-
SC.RING{ord}.(field{1}) = sig .* SCrandnc(nSig,size(sig));
277+
SC.RING{ord}.(field{1}) = rndn_cutoff(SC.SIG.Mag{ord}.(field{1}),par.nSig);
301278
end
302279
end
303280

304281
end
305282
end
306283

307284

285+
function error = rndn_cutoff(field,nSig0)
286+
% Check if cutoff is defined explicitly
287+
if iscell(field)
288+
error = field{1} .* SCrandnc(field{2},size(field{1}));
289+
else
290+
error = field .* SCrandnc(nSig0,size(field));
291+
end
292+
end

SCregisterBPMs.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@
9393
% *SCgetBPMreading*, *SCgetOrds*, *SCsanityCheck*, *SCapplyErrors*, *SCregisterSupport*, *SCupdateSupport*
9494

9595

96+
% Default truncation value for error distribution
97+
cutoff = 2;
98+
9699
% Store BPM ordinates
97100
if isfield(SC,'ORD') && isfield(SC.ORD,'BPM')
98101
SC.ORD.BPM = sort(unique([SC.ORD.BPM BPMords]));
@@ -106,10 +109,14 @@
106109
% Set name/pair-values in sigma structure
107110
if ~isempty(varargin)
108111
for i=1:2:(length(varargin)-1)
109-
SC.SIG.BPM{ord}.(varargin{i}) = varargin{i+1}(:)';
112+
if iscell(varargin{i+1}) || ~isempty(regexp(varargin{i},'Noise'))
113+
SC.SIG.BPM{ord}.(varargin{i}) = varargin{i+1};
114+
else
115+
SC.SIG.BPM{ord}.(varargin{i}) = {varargin{i+1}, cutoff};
116+
end
110117
end
111118
end
112-
119+
113120
% Set TBT BPM noise
114121
SC.RING{ord}.Noise = zeros(1,2);
115122

SCregisterCAVs.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
% *SCgetOrds*, *SCsanityCheck*, *SCapplyErrors*
9494

9595

96+
% Default truncation value for error distribution
97+
cutoff = 2;
9698

9799
% Store cavity ordinates
98100
if isfield(SC,'ORD') && isfield(SC.ORD,'Cavity')
@@ -116,7 +118,11 @@
116118
% Set name/pair-values in sigma structure
117119
if ~isempty(varargin)
118120
for i=1:2:(length(varargin)-1)
119-
SC.SIG.RF{ord}.(varargin{i}) = varargin{i+1}(:)';
121+
if iscell(varargin{i+1})
122+
SC.SIG.RF{ord}.(varargin{i}) = varargin{i+1};
123+
else
124+
SC.SIG.RF{ord}.(varargin{i}) = {varargin{i+1}, cutoff};
125+
end
120126
end
121127
end
122128
end

SCregisterMagnets.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@
239239
% Get name/value-pairs for sigma structure
240240
[nvpairs] = getSigmaPairs(keywords,varargin{:});
241241

242+
% Default truncation value for error distribution
243+
cutoff = 2;
244+
242245
% Loop over magnets
243246
for ord = MAGords(:)'
244247

@@ -283,7 +286,11 @@
283286

284287
% Set name/pair-values in sigma structure
285288
for i=1:2:(length(nvpairs)-1)
286-
SC.SIG.Mag{ord}.(nvpairs{i}) = nvpairs{i+1};
289+
if iscell(nvpairs{i+1})
290+
SC.SIG.Mag{ord}.(nvpairs{i}) = nvpairs{i+1};
291+
else
292+
SC.SIG.Mag{ord}.(nvpairs{i}) = {nvpairs{i+1}, cutoff};
293+
end
287294
end
288295
end
289296

SCregisterSupport.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@
113113

114114
checkInput()
115115

116+
% Default truncation value for error distribution
117+
cutoff = 2;
118+
116119
% Make sure that ordinates are within ring
117120
Nele = length(SC.RING);
118121
ords = mod(varargin{2}-1,Nele)+1;
@@ -143,11 +146,11 @@
143146
end
144147
else
145148
% Define uncertainties for start points
146-
SC.SIG.Support{ordPair(1)}.([type varargin{i}]) = varargin{i+1}(1,:);
149+
SC.SIG.Support{ordPair(1)}.([type varargin{i}]) = {varargin{i+1}(1,:), cutoff};
147150
% Check if endpoint uncertainties are given
148151
if size(varargin{i+1},1)==2
149152
% Define uncertainties for endpoints
150-
SC.SIG.Support{ordPair(2)}.([type varargin{i}]) = varargin{i+1}(2,:);
153+
SC.SIG.Support{ordPair(2)}.([type varargin{i}]) = {varargin{i+1}(2,:),cutoff};
151154
end
152155
end
153156
end

0 commit comments

Comments
 (0)