0001 function [...
0002 ringmultipoles,...
0003 bnsyst,...
0004 bnrand,...
0005 anrand...
0006 ]=SetMultipoleErrorsMagDesign_S28D(...
0007 ring,...
0008 systematicerrorflag,...
0009 randomerrorflag,...
0010 scalerandmulterr,...
0011 dipquaderrors)
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 if nargin==1
0036 disp('Setting All multipoles')
0037 systematicerrorflag=1;
0038 randomerrorflag=1;
0039 end
0040
0041 warning('Injection magnets as cell magnets!');
0042
0043 magfamsnames={...
0044 'QF1',...
0045 'QD2',...
0046 'DL1_1',...
0047 'DL1_2_5',...
0048 'QD3',...
0049 'SD1',...
0050 'QF4',...
0051 'SF ',...
0052 'OF ',...
0053 'QD5',...
0054 'QF6',...
0055 'DQ1',...
0056 'QF8',...
0057 'DQ2'};
0058
0059 magindexes={...
0060 findcells(ring,'FamName','QF1\w*'),...
0061 findcells(ring,'FamName','QD2\w*'),...
0062 findcells(ring,'FamName','DL\w*_1'),...
0063 findcells(ring,'FamName','DL\w*_[2-5]'),...
0064 findcells(ring,'FamName','QD3\w*'),...
0065 findcells(ring,'FamName','S[DJ]1\w*'),...
0066 findcells(ring,'FamName','QF4[A-Z]'),...
0067 findcells(ring,'FamName','S[FIJ]2\w*'),...
0068 findcells(ring,'FamName','O[FIJ]\w*'),...
0069 findcells(ring,'FamName','QD5\w*'),...
0070 findcells(ring,'FamName','QF6\w*'),...
0071 findcells(ring,'FamName','DQ1\w*'),...
0072 findcells(ring,'FamName','QF8\w*'),...
0073 findcells(ring,'FamName','DQ2\w*'),...
0074 };
0075
0076 onoff=ones(1,length(magindexes));
0077
0078 onoff=onoff*1;
0079
0080 if nargin==4
0081
0082 dipquaderrors=0;
0083 end
0084
0085 offmult=find(onoff==0);
0086 if ~isempty(offmult)
0087 warning(['Setting to zero SOME multipoles!']);
0088 for iii=1:length(offmult)
0089 disp(['setting to zero ' magfamsnames{offmult(iii)} ' multipoles!']);
0090 end
0091 end
0092 disp(['Scaling multipoles by ' num2str(onoff(1))]);
0093
0094
0095
0096
0097
0098 qf1bn=[
0099 0
0100 10000
0101 0
0102 0
0103 0
0104 1.10934
0105 0
0106 0
0107 0
0108 -5.18658
0109 0
0110 0
0111 0
0112 4.45567
0113 0
0114 0
0115 0
0116 -0.922755
0117 0
0118 0
0119 0
0120 -0.0349446
0121 0
0122 0
0123 0
0124 0.0401289
0125 0
0126 0
0127 0
0128 -0.00454002
0129 0
0130 0
0131 ];
0132
0133
0134 qd2qf4qd5bn=[
0135 0
0136 10000
0137 0
0138 0
0139 0
0140 1.05689
0141 0
0142 0
0143 0
0144 -5.0583
0145 0
0146 0
0147 0
0148 4.30472
0149 0
0150 0
0151 0
0152 -0.900747
0153 0
0154 0
0155 0
0156 -0.032636
0157 0
0158 0
0159 0
0160 0.0392085
0161 0
0162 0
0163 0
0164 -0.00455189
0165 0
0166 0
0167 ];
0168
0169
0170 qd3bn=[
0171 0
0172 10000
0173 0
0174 0
0175 0
0176 0.213039
0177 0
0178 0
0179 0
0180 -5.38733
0181 0
0182 0
0183 0
0184 4.24571
0185 0
0186 0
0187 0
0188 -0.869278
0189 0
0190 0
0191 0
0192 -0.0369974
0193 0
0194 0
0195 0
0196 0.0389081
0197 0
0198 0
0199 0
0200 -0.00427762
0201 0
0202 0
0203 ];
0204
0205
0206
0207 qf6bn=[
0208 0
0209 10000
0210 0
0211 0
0212 0
0213 -0.141575
0214 0
0215 0
0216 0
0217 0.37436
0218 0
0219 0
0220 0
0221 -0.416586
0222 0
0223 0
0224 0
0225 0.0331539
0226 0
0227 0
0228 0
0229 -0.00202149
0230 0
0231 0
0232 0
0233 0.000173277
0234 0
0235 0
0236 0
0237 -0.000015608
0238 0
0239 0
0240 ];
0241
0242
0243 qf8bn=[
0244 0
0245 10000
0246 0
0247 0
0248 0
0249 -0.0286179
0250 0
0251 0
0252 0
0253 0.507304
0254 0
0255 0
0256 0
0257 -0.518238
0258 0
0259 0
0260 0
0261 0.0519398
0262 0
0263 0
0264 0
0265 -0.00397534
0266 0
0267 0
0268 0
0269 0.000326059
0270 0
0271 0
0272 0
0273 -2.60953E-05
0274 0
0275 0
0276 ];
0277
0278
0279
0280 dq1bn=[
0281 10000
0282 4499.22*dipquaderrors*0
0283 1.3194
0284 -3.52302
0285 -1.37691
0286 9.23649
0287 1.06358
0288 -10.1486
0289 -3.14353
0290 2.6593
0291 2.20996
0292 -0.0810461
0293 -1.00213
0294 -0.534322
0295 0.0956301
0296 0.230463
0297 0.0973052
0298 -0.028557
0299 -0.0408101
0300 -0.0100374
0301 0.0117989
0302 0.016608
0303 -0.0180537
0304 -0.0091815
0305 -0.0033418
0306 0.00478292
0307 0.017508
0308 0.0104226
0309 0.0563036
0310 0.0103595
0311 0.140688
0312 0.0239935
0313 ];
0314
0315 dq2bn=[
0316 10000
0317 5532.12*dipquaderrors*0
0318 -0.638178
0319 25.8143
0320 5.20062
0321 -17.2604
0322 -5.60715
0323 -3.13825
0324 0.700903
0325 0.594722
0326 -0.0168115
0327 -0.0909287
0328 -0.099857
0329 0.126364
0330 0.102901
0331 0.0660892
0332 ];
0333
0334
0335 dl25bn=[
0336 10000
0337 -0.114587528*dipquaderrors
0338 -10.90737749
0339 0.000826888
0340 -9.553706569
0341 0.001844252
0342 40.27705914
0343 0.000985885
0344 -39.06399784
0345 -0.02128641
0346 12.18333403
0347 0.042352407
0348 4.097949452
0349 -0.048263899
0350 -8.461398324
0351 0.033963307
0352 7.417928542
0353 0.006952543
0354 -5.297735568
0355 -0.065757173
0356 3.677007672
0357 0.1190935
0358 -2.698133257
0359 -0.170708161
0360 2.052958641
0361 0.210328708
0362 -1.477094684
0363 -0.236478376
0364 0.896419778
0365 0.241228991
0366 -0.363207639
0367 -0.212722702
0368 -0.048637051
0369 0.171068182
0370 0.277425745
0371 -0.129839868
0372 -0.306962067
0373 0.124492321
0374 0.170936777
0375 ];
0376
0377 dl1bn=[
0378 10000
0379 -0.120136117*dipquaderrors
0380 -18.78769519
0381 -0.04104429
0382 -9.229796041
0383 0.175741454
0384 39.31519315
0385 -0.047200252
0386 -37.91431184
0387 0.057877333
0388 11.99815634
0389 0.029617722
0390 3.88913231
0391 -0.116902012
0392 -8.01975352
0393 0.115098705
0394 7.090914685
0395 -0.027823358
0396 -5.007313249
0397 -0.043452941
0398 3.516510125
0399 0.127367135
0400 -2.520179322
0401 -0.131847244
0402 1.922521376
0403 0.081749897
0404 -1.303745402
0405 -0.008143467
0406 0.728894405
0407 -0.034517217
0408 -0.149670856
0409 0.071987846
0410 -0.263699771
0411 -0.148112903
0412 0.553683203
0413 0.162973312
0414 -0.621075716
0415 -0.14177974
0416 0.525840645
0417 ];
0418
0419
0420
0421 sfdbn=[
0422 0,...
0423 0,...
0424 10000,...
0425 0,...
0426 0,...
0427 0,...
0428 0,...
0429 19.996,...
0430 0,...
0431 0,...
0432 0,...
0433 0,...
0434 0,...
0435 0,...
0436 -7.5048,...
0437 0,...
0438 0,...
0439 0,...
0440 0,...
0441 0,...
0442 -0.0510856,...
0443 ]';
0444
0445 ofbn=[
0446 0
0447 0
0448 0
0449 10000
0450 0
0451 0
0452 0
0453 0
0454 0
0455 0];
0456
0457
0458
0459
0460
0461
0462 bnsyst={...
0463 [...
0464 qf1bn]*1e-4*onoff(1),...
0465 [...
0466 qd2qf4qd5bn]*1e-4*onoff(2),...
0467 [...
0468 dl1bn]*1e-4*onoff(3),...
0469 [...
0470 dl25bn]*1e-4*onoff(4),...
0471 [...
0472 qd3bn]*1e-4*onoff(5),...
0473 [...
0474 sfdbn]*1e-4*onoff(6),...
0475 [...
0476 qd2qf4qd5bn]*1e-4*onoff(7),...
0477 [...
0478 sfdbn]*1e-4*onoff(8),...
0479 [...
0480 ofbn]*1e-4*onoff(9),...
0481 [...
0482 qd2qf4qd5bn]*1e-4*onoff(10),...
0483 [...
0484 qf6bn]*1e-4*onoff(11),...
0485 [...
0486 dq1bn]*1e-4*onoff(12),...
0487 [...
0488 qf8bn]*1e-4*onoff(13),...
0489 [...
0490 dq2bn]*1e-4*onoff(14),...
0491 };
0492
0493
0494
0495
0496
0497
0498 qf1qd2qd3qf4qd5_bnr=[
0499 0
0500 0
0501 3.072975926
0502 2.54644786
0503 2.219625361
0504 1.830077863
0505 1.525070225
0506 1.224277182
0507 1.037263493
0508 0.864779645
0509 0.723679911
0510 0.54251811
0511 0.473629212
0512 0.372401109
0513 ]*scalerandmulterr;
0514 qf1qd2qd3qf4qd5_bnr(2)=1e4;
0515
0516 qf1qd2qd3qf4qd5_anr=[
0517 0
0518 0
0519 3.072975926
0520 2.54644786
0521 2.219625361
0522 1.830077863
0523 1.525070225
0524 1.224277182
0525 1.037263493
0526 0.864779645
0527 0.723679911
0528 0.54251811
0529 0.473629212
0530 0.372401109
0531 ]*scalerandmulterr;
0532
0533 dq1bnr=[
0534 0
0535 10000
0536 9.360035
0537 6.231414
0538 4.040027
0539 2.390795
0540 1.598305];
0541
0542 dq2bnr=[
0543 0
0544 10000
0545 9.360035
0546 6.231414
0547 4.040027
0548 2.390795
0549 1.598305];
0550
0551 dlbnr=[
0552 10000
0553 0
0554 0
0555 0
0556 0
0557 0];
0558
0559 sextbnr=[
0560 0.0022*dipquaderrors
0561 0.0017*dipquaderrors
0562 0
0563 7.2330e-04
0564 3.9599e-04
0565 1.4986e-04
0566 4.2453e-05
0567 1.2127e-05
0568 2.7490e-05
0569 3.5432e-05
0570 3.1562e-05
0571 2.0812e-05
0572 1.5015e-05
0573 8.5440e-06
0574 3.9749e-06
0575 2.8271e-06
0576 1.3636e-06
0577 4.1152e-07
0578 ]*1e4*30/50*scalerandmulterr;
0579 sextbnr(3)=1e4;
0580
0581 octbnr=[
0582 0
0583 0
0584 0
0585 10000
0586 0
0587 0
0588 0
0589 0
0590 0];
0591
0592
0593
0594 qf6qf8_bnr=[
0595 0
0596 0
0597 4.803458371
0598 1.910276957
0599 1.055734675
0600 0.588073151
0601 0.312742308
0602 0.175288289
0603 0.101114708
0604 0.064747269
0605 0.038242921
0606 0.022608539
0607 0.01461673
0608 0.008751506
0609 ]*scalerandmulterr;
0610 qf6qf8_bnr(2)=1e4;
0611
0612 qf6qf8_anr=[
0613 0
0614 0
0615 4.803458371
0616 1.910276957
0617 1.055734675
0618 0.588073151
0619 0.312742308
0620 0.175288289
0621 0.101114708
0622 0.064747269
0623 0.038242921
0624 0.022608539
0625 0.01461673
0626 0.008751506
0627 ]*scalerandmulterr;
0628
0629 dq1anr=[
0630 0
0631 0
0632 9.360035
0633 6.231414
0634 4.040027
0635 2.390795
0636 1.598305];
0637
0638 dq2anr=[
0639 0
0640 0
0641 9.360035
0642 6.231414
0643 4.040027
0644 2.390795
0645 1.598305];
0646
0647
0648 dlanr=[0
0649 0
0650 0
0651 0
0652 0
0653 0];
0654
0655 sextanr=[
0656 0.0020*dipquaderrors
0657 0.0018*dipquaderrors
0658 0.0013
0659 7.4844e-04
0660 3.2321e-04
0661 1.6012e-04
0662 3.8491e-05
0663 1.2814e-05
0664 3.4294e-05
0665 3.6640e-05
0666 2.5829e-05
0667 2.2166e-05
0668 1.3582e-05
0669 9.0634e-06
0670 5.5419e-06
0671 2.9239e-06
0672 1.1148e-06
0673 4.3986e-07
0674 ]*1e4*30/50*scalerandmulterr;
0675
0676 octanr=[
0677 0
0678 0
0679 0
0680 0
0681 0
0682 0
0683 0
0684 0
0685 0];
0686
0687
0688 bnrand={...
0689 [...
0690 qf1qd2qd3qf4qd5_bnr]*1e-4*onoff(1),...
0691 [...
0692 qf1qd2qd3qf4qd5_bnr]*1e-4*onoff(2),...
0693 [...
0694 dlbnr]*1e-4*onoff(3),...
0695 [...
0696 dl25bn]*1e-4*onoff(4),...
0697 [...
0698 qf1qd2qd3qf4qd5_bnr]*1e-4*onoff(5),...
0699 [...
0700 sextbnr]*1e-4*onoff(6),...
0701 [...
0702 qf1qd2qd3qf4qd5_bnr]*1e-4*onoff(7),...
0703 [...
0704 sextbnr]*1e-4*onoff(8),...
0705 [...
0706 octbnr]*1e-4*onoff(9),...
0707 [...
0708 qf1qd2qd3qf4qd5_bnr]*1e-4*onoff(10),...
0709 [...
0710 qf6qf8_bnr]*1e-4*onoff(11),...
0711 [...
0712 dq1bnr]*1e-4*onoff(12),...
0713 [...
0714 qf6qf8_bnr]*1e-4*onoff(13),...
0715 [...
0716 dq2bnr]*1e-4*onoff(14),...
0717 };
0718
0719
0720
0721 anrand={...
0722 [...
0723 qf1qd2qd3qf4qd5_anr]*1e-4*onoff(1),...
0724 [...
0725 qf1qd2qd3qf4qd5_anr]*1e-4*onoff(2),...
0726 [...
0727 dlanr]*1e-4*onoff(3),...
0728 [...
0729 dlanr]*1e-4*onoff(4),...
0730 [...
0731 qf1qd2qd3qf4qd5_anr]*1e-4*onoff(5),...
0732 [...
0733 sextanr]*1e-4*onoff(6),...
0734 [...
0735 qf1qd2qd3qf4qd5_anr]*1e-4*onoff(7),...
0736 [...
0737 sextanr]*1e-4*onoff(8),...
0738 [...
0739 octanr]*1e-4*onoff(9),...
0740 [...
0741 qf1qd2qd3qf4qd5_anr]*1e-4*onoff(10),...
0742 [...
0743 qf6qf8_anr]*1e-4*onoff(11),...
0744 [...
0745 dq1anr]*1e-4*onoff(12),...
0746 [...
0747 qf6qf8_anr]*1e-4*onoff(13),...
0748 [...
0749 dq2anr]*1e-4*onoff(14),...
0750 };
0751
0752
0753
0754
0755 if systematicerrorflag
0756
0757 for imag=1:length(magindexes)
0758
0759 if ~isempty(bnsyst{imag})
0760
0761 bs=bnsyst{imag};
0762 refMult=find(bs==1);
0763
0764 if isempty(refMult)
0765 maxord=ring{magindexes{imag}(1)}.MaxOrder+1;
0766
0767 [~,maxcoef]=max(abs(ring{magindexes{imag}(1)}.PolynomB));
0768 refMult=min(maxord,maxcoef);
0769 end
0770
0771 bs(refMult)=0;
0772 if onoff(imag)
0773 disp(['Systematic: ' magfamsnames{imag}...
0774 ', refmultipole: ' num2str(refMult)...
0775 ', std(berr): ' num2str(std(bs))])
0776
0777
0778 rho=getcellstruct(ring,'RefRadius',magindexes{imag});
0779 rho(isnan(rho))=0.013;
0780
0781
0782
0783 [ring,pb]=AssignFieldErr(ring,magindexes{imag},refMult,rho,bs');
0784
0785
0786 if find(isnan(pb))
0787
0788 error(['NaN in PolynomB for ' magfamsnames{imag}])
0789 end
0790 end
0791
0792 else
0793 warning(['Missing Systematic multipole data for: ' magfamsnames{imag} ])
0794 end
0795 end
0796
0797 end
0798
0799
0800 if randomerrorflag
0801
0802 for imag=1:length(magindexes)
0803
0804 if ~isempty(bnrand{imag}) || ~isempty(anrand{imag})
0805
0806 bs=bnrand{imag};
0807 refMult=find(bs==1);
0808
0809
0810 if isempty(refMult)
0811 maxord=ring{magindexes{imag}(1)}.MaxOrder+1;
0812 [~,maxcoef]=max(abs(ring{magindexes{imag}(1)}.PolynomB));
0813 refMult=min(maxord,maxcoef);
0814 end
0815
0816 bs(refMult)=0;
0817 as=anrand{imag};
0818 as(refMult)=0;
0819
0820 if onoff(imag)
0821 disp(['Random: ' magfamsnames{imag} ', refmultipole: ' num2str(refMult)])
0822 indh=magindexes{imag};
0823 rho=getcellstruct(ring,'RefRadius',magindexes{imag});
0824 rho(isnan(rho))=0.013;
0825 Nsig=2;
0826
0827 if find(bs)
0828 ipolb=find(bs);
0829 for indpolb=1:length(ipolb)
0830 bsr(ipolb(indpolb),:)=TruncatedGaussian(bs(ipolb(indpolb)),abs(Nsig*bs(ipolb(indpolb))),length(indh));
0831 end
0832
0833 if find(as)
0834 ipolb=find(as);
0835 for indpolb=1:length(ipolb)
0836 asr(ipolb(indpolb),:)=TruncatedGaussian(as(ipolb(indpolb)),abs(Nsig*as(ipolb(indpolb))),length(indh));
0837 end
0838 else
0839 asr=zeros(size(bsr));
0840 end
0841
0842 for jpolb=1:length(magindexes{imag})
0843 ring=AssignFieldErr(ring,indh(jpolb),refMult,rho(jpolb),bsr(:,jpolb)',asr(:,jpolb)');
0844 end
0845 end
0846 clear bsr
0847 clear asr
0848 end
0849 else
0850 warning(['Missing Random multipole data for: ' magfamsnames{imag} ])
0851 end
0852
0853 end
0854
0855 end
0856
0857 ringmultipoles=ring;