source: PSPA/madxPSPA/doc/usrguide/control/foot.html @ 430

Last change on this file since 430 was 430, checked in by touze, 11 years ago

import madx-5.01.00

File size: 14.7 KB
Line 
1<head>
2<title>Range Selection</title>
3<!-- Changed by: Chris ISELIN, 27-Jan-1997 -->
4<!-- Changed by: Hans Grote, 10-Jun-2002 -->
5</head>
6
7<body bgcolor="#ffffff">
8
9<center>
10EUROPEAN ORGANIZATION FOR NUCLEAR RESEARCH
11<IMG SRC="http://cern.ch/madx/icons/mx7_25.gif" align=right>
12<h4>Real life example for IF statements, and MACRO usage</h4>
13</center>
14<p>
15<pre>
16! Creates a footprint for head-on + parasitic collisions at IP1+5
17! of lhc.6.5; both lhcb1 (for tracking) and lhcb2 (to define the
18! beam-beam elements, i.e. weak-strong) are used; there are flags to
19! select head-on, left, and right parasitic separately at all IPs.
20! The bunch spacing can be given in nanosec and automatically creates
21! the beam-beam interaction points at the correct positions.
22! It is important to set the correct BEAM parameters, i.e. number
23! of particles, emittances, bunch length, energy.
24
25!--- For completeness, all files needed by this job are copied
26!    to the local directory ldb. The links to the the originals
27!    in offdb (official database) are commented out.
28
29Option,  warn,info,echo;
30!System,
31"ln -fns /afs/cern.ch/eng/sl/MAD-X/dev/test_suite/foot/V3.01.01 ldb";
32!system,"ln -fns /afs/cern.ch/eng/lhc/optics/V6.4 offdb";
33Option, -echo,-info,warn;
34SU=1.0;
35call, file = "ldb/V6.5.seq";
36call,file="ldb/slice_new.madx";
37Option, echo,info,warn;
38
39!+++++++++++++++++++++++++ Step 1 +++++++++++++++++++++++
40!       define beam constants
41!++++++++++++++++++++++++++++++++++++++++++++++++++++++++
42
43b_t_dist = 25.e-9;                  !--- bunch distance in [sec]
44b_h_dist = clight * b_t_dist / 2 ;  !--- bunch half-distance in [m]
45ip1_range = 58.;                     ! range for parasitic collisions
46ip5_range = ip1_range;
47ip2_range = 60.;
48ip8_range = ip2_range;
49
50npara_1 = ip1_range / b_h_dist;     ! # parasitic either side
51npara_2 = ip2_range / b_h_dist;
52npara_5 = ip5_range / b_h_dist;
53npara_8 = ip8_range / b_h_dist;
54
55value,npara_1,npara_2,npara_5,npara_8;
56
57 eg   =  7000;
58 bg   =  eg/pmass;
59 en   = 3.75e-06;
60 epsx = en/bg;
61 epsy = en/bg;
62
63Beam, particle = proton, sequence=lhcb1, energy = eg,
64          sigt=      0.077     ,
65          bv = +1, NPART=1.1E11, sige=      1.1e-4,
66          ex=epsx,   ey=epsy;
67
68Beam, particle = proton, sequence=lhcb2, energy = eg,
69          sigt=      0.077     ,
70          bv = -1, NPART=1.1E11, sige=      1.1e-4,
71          ex=epsx,   ey=epsy;
72
73beamx = beam%lhcb1->ex;   beamy%lhcb1 = beam->ey;
74sigz  = beam%lhcb1->sigt; sige = beam%lhcb1->sige;
75
76!--- split5, 4d
77long_a= 0.53 * sigz/2;
78long_b= 1.40 * sigz/2;
79value,long_a,long_b;
80
81ho_charge = 0.2;
82
83!+++++++++++++++++++++++++ Step 2 +++++++++++++++++++++++
84!       slice, flatten sequence, and cycle start to ip3
85!++++++++++++++++++++++++++++++++++++++++++++++++++++++++
86
87use,sequence=lhcb1;
88makethin,sequence=lhcb1;
89!save,sequence=lhcb1,file=lhcb1_thin_new_seq;
90use,sequence=lhcb2;
91makethin,sequence=lhcb2;
92!save,sequence=lhcb2,file=lhcb2_thin_new_seq;
93!stop;
94
95option,-warn,-echo,-info;
96call,file="ldb/V6.5.thin.coll.str";
97option,warn,echo,info;
98
99! keep sextupoles
100ksf0=ksf; ksd0=ksd;
101use,period=lhcb1;
102select,flag=twiss.1,column=name,x,y,betx,bety;
103twiss,file;
104plot,haxis=s,vaxis=x,y,colour=100,noline;
105
106use,period=lhcb2;
107select,flag=twiss.2,column=name,x,y,betx,bety;
108twiss,file;
109plot,haxis=s,vaxis=x,y,colour=100,noline;
110seqedit,sequence=lhcb1;
111flatten;
112endedit;
113
114seqedit,sequence=lhcb1;
115cycle,start=ip3.b1;
116endedit;
117
118seqedit,sequence=lhcb2;
119flatten;
120endedit;
121
122seqedit,sequence=lhcb2;
123cycle,start=ip3.b2;
124endedit;
125
126bbmarker: marker;  /* for subsequent remove */
127
128
129!+++++++++++++++++++++++++ Step 3 +++++++++++++++++++++++
130!       define the beam-beam elements
131!++++++++++++++++++++++++++++++++++++++++++++++++++++++++
132!
133!===========================================================
134! read macro definitions
135option,-echo;
136call,file="ldb/bb.macros";
137option,echo;
138
139!
140!===========================================================
141!   this sets CHARGE in the head-on beam-beam elements.
142!   set +1 * ho_charge   for parasitic on, 0 for off
143
144 on_ho1  = +1 * ho_charge; ! ho_charge depends on split
145 on_ho2  = +0 * ho_charge; ! because of the "by hand" splitting
146 on_ho5  = +1 * ho_charge;
147 on_ho8  = +0 * ho_charge;
148
149!
150!===========================================================
151!   set CHARGE in the parasitic beam-beam elements.
152!   set +1 for parasitic on, 0 for off
153 on_lr1l = +1;
154 on_lr1r = +1;
155 on_lr2l = +0;
156 on_lr2r = +0;
157 on_lr5l = +1;
158 on_lr5r = +1;
159 on_lr8l = +0;
160 on_lr8r = +0;
161
162!
163!===========================================================
164!   define markers and savebetas
165assign,echo=temp.bb.install;
166!--- ip1
167if (on_ho1 <> 0)
168{
169  exec, mkho(1);
170  exec, sbhomk(1);
171}
172if (on_lr1l <> 0 || on_lr1r <> 0)
173{
174  n=1; ! counter
175  while (n < npara_1)
176  {
177   exec, mkl(1,$n);
178   exec, sbl(1,$n);
179   n=n+1;
180  };
181}
182if (on_lr1r <> 0 || on_lr1l <> 0)
183{
184  n=1; ! counter
185  while (n < npara_1)
186  {
187   exec, mkr(1,$n);
188   exec, sbr(1,$n);
189   n=n+1;
190  };
191}
192!--- ip5
193if (on_ho5 <> 0)
194{
195  exec, mkho(5);
196  exec, sbhomk(5);
197}
198if (on_lr5l <> 0 || on_lr5r <> 0)
199{
200  n=1; ! counter
201  while (n < npara_5)
202  {
203   exec, mkl(5,$n);
204   exec, sbl(5,$n);
205   n=n+1;
206  };
207}
208if (on_lr5r <> 0 || on_lr5l <> 0)
209{
210  n=1; ! counter
211  while (n < npara_5)
212  {
213   exec, mkr(5,$n);
214   exec, sbr(5,$n);
215   n=n+1;
216  };
217}
218!--- ip2
219if (on_ho2 <> 0)
220{
221  exec, mkho(2);
222  exec, sbhomk(2);
223}
224if (on_lr2l <> 0 || on_lr2r <> 0)
225{
226  n=1; ! counter
227  while (n < npara_2)
228  {
229   exec, mkl(2,$n);
230   exec, sbl(2,$n);
231   n=n+1;
232  };
233}
234if (on_lr2r <> 0 || on_lr2l <> 0)
235{
236  n=1; ! counter
237  while (n < npara_2)
238  {
239   exec, mkr(2,$n);
240   exec, sbr(2,$n);
241   n=n+1;
242  };
243}
244!--- ip8
245if (on_ho8 <> 0)
246{
247  exec, mkho(8);
248  exec, sbhomk(8);
249}
250if (on_lr8l <> 0 || on_lr8r <> 0)
251{
252  n=1; ! counter
253  while (n < npara_8)
254  {
255   exec, mkl(8,$n);
256   exec, sbl(8,$n);
257   n=n+1;
258  };
259}
260if (on_lr8r <> 0 || on_lr8l <> 0)
261{
262  n=1; ! counter
263  while (n < npara_8)
264  {
265   exec, mkr(8,$n);
266   exec, sbr(8,$n);
267   n=n+1;
268  };
269}
270assign,echo=terminal;
271call,file=temp.bb.install;
272system, "rm temp.bb.install";
273!
274!===========================================================
275!   install bb markers
276assign,echo=temp.bb.install;
277!--- ip1
278if (on_ho1 <> 0)
279{
280exec, inho(mk,1);
281}
282if (on_lr1l <> 0 || on_lr1r <> 0)
283{
284  n=1; ! counter
285  while (n < npara_1)
286  {
287   exec, inl(mk,1,$n);
288   n=n+1;
289  };
290}
291if (on_lr1r <> 0 || on_lr1l <> 0)
292{
293  n=1; ! counter
294  while (n < npara_1)
295  {
296   exec, inr(mk,1,$n);
297   n=n+1;
298  };
299}
300!--- ip5
301if (on_ho5 <> 0)
302{
303exec, inho(mk,5);
304}
305if (on_lr5l <> 0 || on_lr5r <> 0)
306{
307  n=1; ! counter
308  while (n < npara_5)
309  {
310   exec, inl(mk,5,$n);
311   n=n+1;
312  };
313}
314if (on_lr5r <> 0 || on_lr5l <> 0)
315{
316  n=1; ! counter
317  while (n < npara_5)
318  {
319   exec, inr(mk,5,$n);
320   n=n+1;
321  };
322}
323!--- ip2
324if (on_ho2 <> 0)
325{
326exec, inho(mk,2);
327}
328if (on_lr2l <> 0 || on_lr2r <> 0)
329{
330  n=1; ! counter
331  while (n < npara_2)
332  {
333   exec, inl(mk,2,$n);
334   n=n+1;
335  };
336}
337if (on_lr2r <> 0 || on_lr2l <> 0)
338{
339  n=1; ! counter
340  while (n < npara_2)
341  {
342   exec, inr(mk,2,$n);
343   n=n+1;
344  };
345}
346!--- ip8
347if (on_ho8 <> 0)
348{
349exec, inho(mk,8);
350}
351if (on_lr8l <> 0 || on_lr8r <> 0)
352{
353  n=1; ! counter
354  while (n < npara_8)
355  {
356   exec, inl(mk,8,$n);
357   n=n+1;
358  };
359}
360if (on_lr8r <> 0 || on_lr8l <> 0)
361{
362  n=1; ! counter
363  while (n < npara_8)
364  {
365   exec, inr(mk,8,$n);
366   n=n+1;
367  };
368}
369assign,echo=terminal;
370seqedit,sequence=lhcb2;
371call,file=temp.bb.install;
372endedit;
373system, "rm temp.bb.install";
374
375!
376!===========================================================
377!--- get beta functions at bb in all four IPs
378use,period=lhcb2;
379!select,flag=twiss,class=bbmarker,column=name,s,x,y;
380twiss, sequence=lhcb2; !,file;
381!--- separation for halo collisions at IP2
382on_sep2 = 2.118 * sqrt(epsx * r2ip2->betx) / 0.0007999979093;
383value,on_sep2;
384!===========================================================
385!   define bb elements
386assign,echo=temp.bb.install;
387!--- ip1
388if (on_ho1 <> 0)
389{
390exec, bbho(1);
391}
392if (on_lr1l <> 0)
393{
394  n=1; ! counter
395  while (n < npara_1)
396  {
397   exec, bbl(1,$n);
398   n=n+1;
399  };
400}
401if (on_lr1r <> 0)
402{
403  n=1; ! counter
404  while (n < npara_1)
405  {
406   exec, bbr(1,$n);
407   n=n+1;
408  };
409}
410!--- ip5
411if (on_ho5 <> 0)
412{
413exec, bbho(5);
414}
415if (on_lr5l <> 0)
416{
417  n=1; ! counter
418  while (n < npara_5)
419  {
420   exec, bbl(5,$n);
421   n=n+1;
422  };
423}
424if (on_lr5r <> 0)
425{
426  n=1; ! counter
427  while (n < npara_5)
428  {
429   exec, bbr(5,$n);
430   n=n+1;
431  };
432}
433!--- ip2
434if (on_ho2 <> 0)
435{
436exec, bbho(2);
437}
438if (on_lr2l <> 0)
439{
440  n=1; ! counter
441  while (n < npara_2)
442  {
443   exec, bbl(2,$n);
444   n=n+1;
445  };
446}
447if (on_lr2r <> 0)
448{
449  n=1; ! counter
450  while (n < npara_2)
451  {
452   exec, bbr(2,$n);
453   n=n+1;
454  };
455}
456!--- ip8
457if (on_ho8 <> 0)
458{
459exec, bbho(8);
460}
461if (on_lr8l <> 0)
462{
463  n=1; ! counter
464  while (n < npara_8)
465  {
466   exec, bbl(8,$n);
467   n=n+1;
468  };
469}
470if (on_lr8r <> 0)
471{
472  n=1; ! counter
473  while (n < npara_8)
474  {
475   exec, bbr(8,$n);
476   n=n+1;
477  };
478}
479assign,echo=terminal;
480call,file=temp.bb.install;
481system, "rm temp.bb.install";
482!
483!===========================================================
484!   install bb elements
485assign,echo=temp.bb.install;
486!--- ip1
487if (on_ho1 <> 0)
488{
489exec, inho(bb,1);
490}
491if (on_lr1l <> 0)
492{
493  n=1; ! counter
494  while (n < npara_1)
495  {
496   exec, inl(bb,1,$n);
497   n=n+1;
498  };
499}
500if (on_lr1r <> 0)
501{
502  n=1; ! counter
503  while (n < npara_1)
504  {
505   exec, inr(bb,1,$n);
506   n=n+1;
507  };
508}
509!--- ip5
510if (on_ho5 <> 0)
511{
512exec, inho(bb,5);
513}
514if (on_lr5l <> 0)
515{
516  n=1; ! counter
517  while (n < npara_5)
518  {
519   exec, inl(bb,5,$n);
520   n=n+1;
521  };
522}
523if (on_lr5r <> 0)
524{
525  n=1; ! counter
526  while (n < npara_5)
527  {
528   exec, inr(bb,5,$n);
529   n=n+1;
530  };
531}
532!--- ip2
533if (on_ho2 <> 0)
534{
535exec, inho(bb,2);
536}
537if (on_lr2l <> 0)
538{
539  n=1; ! counter
540  while (n < npara_2)
541  {
542   exec, inl(bb,2,$n);
543   n=n+1;
544  };
545}
546if (on_lr2r <> 0)
547{
548  n=1; ! counter
549  while (n < npara_2)
550  {
551   exec, inr(bb,2,$n);
552   n=n+1;
553  };
554}
555!--- ip8
556if (on_ho8 <> 0)
557{
558exec, inho(bb,8);
559}
560if (on_lr8l <> 0)
561{
562  n=1; ! counter
563  while (n < npara_8)
564  {
565   exec, inl(bb,8,$n);
566   n=n+1;
567  };
568}
569if (on_lr8r <> 0)
570{
571  n=1; ! counter
572  while (n < npara_8)
573  {
574   exec, inr(bb,8,$n);
575   n=n+1;
576  };
577}
578assign,echo=terminal;
579select,flag=seqedit,class=bbmarker;
580seqedit,sequence=lhcb2;
581remove,element=selected;
582endedit;
583select,flag=seqedit,clear;
584
585seqedit,sequence=lhcb1;
586call,file=temp.bb.install;
587endedit;
588
589!--- Now the beam-beam element installation is complete
590
591system, "rm temp.bb.install";
592
593seqedit,sequence=lhcb1;
594cycle,start=ip1;
595endedit;
596
597use,period=lhcb1;
598!twiss, sequence=lhcb1;
599!
600!  make footprint
601!
602
603option,trace;
604small=0.05;
605big=sqrt(1.-small^2);
606track;
607xs=small; ys=small;
608value,xs,ys;
609start,fx=xs,fy=ys;  // zero amplitude
610nsigmax=6;
611n=1; // sigma multiplier
612m=0; // angle multiplier
613while (n <= nsigmax)
614{
615  angle = 15*m*pi/180;
616  if (m == 0) {xs=n*big; ys=n*small;}
617  elseif (m == 6) {xs=n*small; ys=n*big;}
618  else
619  {
620    xs=n*cos(angle);
621    ys=n*sin(angle);
622  }
623  value,xs,ys;
624  start,fx=xs,fy=ys;
625  m=m+1;
626  if (m == 7) { m=0; n=n+1;}
627};
628dynap,fastune,turns=1024;
629endtrack;
630write,table=dynap,file;
631write,table=dynaptune,file;
632system,"foot < dynaptune > footprint";
633stop;
634</pre>
635
636<h4><a name=macro>Real life example of MACRO definitions</a></h4>
637<p>
638<pre>
639bbho(nn): macro = {
640!--- macro defining head-on beam-beam elements; nn = IP number
641print, text="bbipnnl2: beambeam, sigx=sqrt(rnnipnnl2->betx*epsx),";
642print, text="          sigy=sqrt(rnnipnnl2->bety*epsy),";
643print, text="          xma=rnnipnnl2->x,yma=rnnipnnl2->y,";
644print, text="          charge:=on_honn;";
645print, text="bbipnnl1: beambeam, sigx=sqrt(rnnipnnl1->betx*epsx),";
646print, text="          sigy=sqrt(rnnipnnl1->bety*epsy),";
647print, text="          xma=rnnipnnl1->x,yma=rnnipnnl1->y,";
648print, text="          charge:=on_honn;";
649print, text="bbipnn:   beambeam, sigx=sqrt(rnnipnn->betx*epsx),";
650print, text="          sigy=sqrt(rnnipnn->bety*epsy),";
651print, text="          xma=rnnipnn->x,yma=rnnipnn->y,";
652print, text="          charge:=on_honn;";
653print, text="bbipnnr1: beambeam, sigx=sqrt(rnnipnnr1->betx*epsx),";
654print, text="          sigy=sqrt(rnnipnnr1->bety*epsy),";
655print, text="          xma=rnnipnnr1->x,yma=rnnipnnr1->y,";
656print, text="          charge:=on_honn;";
657print, text="bbipnnr2: beambeam, sigx=sqrt(rnnipnnr2->betx*epsx),";
658print, text="          sigy=sqrt(rnnipnnr2->bety*epsy),";
659print, text="          xma=rnnipnnr2->x,yma=rnnipnnr2->y,";
660print, text="          charge:=on_honn;";
661};
662
663mkho(nn): macro = {
664!--- macro defining head-on markers; nn = IP number
665print, text="mkipnnl2: bbmarker;";
666print, text="mkipnnl1: bbmarker;";
667print, text="mkipnn:   bbmarker;";
668print, text="mkipnnr1: bbmarker;";
669print, text="mkipnnr2: bbmarker;";
670};
671
672inho(xx,nn): macro = {
673!--- macro installing bb or markers for head-on beam-beam (split into 5)
674print, text="install, element= xxipnnl2, at=-long_b, from=ipnn;";
675print, text="install, element= xxipnnl1, at=-long_a, from=ipnn;";
676print, text="install, element= xxipnn,   at=1.e-9,   from=ipnn;";
677print, text="install, element= xxipnnr1, at=+long_a, from=ipnn;";
678print, text="install, element= xxipnnr2, at=+long_b, from=ipnn;";
679};
680
681sbhomk(nn): macro = {
682!--- macro to create savebetas for ho markers
683print, text="savebeta, label=rnnipnnl2, place=mkipnnl2;";
684print, text="savebeta, label=rnnipnnl1, place=mkipnnl1;";
685print, text="savebeta, label=rnnipnn,   place=mkipnn;";
686print, text="savebeta, label=rnnipnnr1, place=mkipnnr1;";
687print, text="savebeta, label=rnnipnnr2, place=mkipnnr2;";   
688};
689
690mkl(nn,cc): macro = {
691!--- macro to create parasitic bb marker on left side of ip nn; cc = count
692print, text="mkipnnplcc: bbmarker;";
693};
694
695mkr(nn,cc): macro = {
696!--- macro to create parasitic bb marker on right side of ip nn; cc = count
697print, text="mkipnnprcc: bbmarker;";
698};
699
700sbl(nn,cc): macro = {
701!--- macro to create savebetas for left parasitic
702print, text="savebeta, label=rnnipnnplcc, place=mkipnnplcc;";
703};
704
705sbr(nn,cc): macro = {
706!--- macro to create savebetas for right parasitic
707print, text="savebeta, label=rnnipnnprcc, place=mkipnnprcc;";
708};
709
710inl(xx,nn,cc): macro = {
711!--- macro installing bb and markers for left side parasitic beam-beam
712print, text="install, element= xxipnnplcc, at=-cc*b_h_dist, from=ipnn;";
713};
714
715inr(xx,nn,cc): macro = {
716!--- macro installing bb and markers for right side parasitic beam-beam
717print, text="install, element= xxipnnprcc, at=cc*b_h_dist, from=ipnn;";
718};
719
720bbl(nn,cc): macro = {
721!--- macro defining parasitic beam-beam elements; nn = IP number
722print, text="bbipnnplcc: beambeam, sigx=sqrt(rnnipnnplcc->betx*epsx),";
723print, text="          sigy=sqrt(rnnipnnplcc->bety*epsy),";
724print, text="          xma=rnnipnnplcc->x,yma=rnnipnnplcc->y,";
725print, text="          charge:=on_lrnnl;";
726};
727
728bbr(nn,cc): macro = {
729!--- macro defining parasitic beam-beam elements; nn = IP number
730print, text="bbipnnprcc: beambeam, sigx=sqrt(rnnipnnprcc->betx*epsx),";
731print, text="          sigy=sqrt(rnnipnnprcc->bety*epsy),";
732print, text="          xma=rnnipnnprcc->x,yma=rnnipnnprcc->y,";
733print, text="          charge:=on_lrnnr;";
734};
735</pre>
736
737<address>
738<a href="http://www.cern.ch/Hans.Grote/hansg_sign.html">hansg</a>,
739June 17, 2002
740</address>
741
742</body>
Note: See TracBrowser for help on using the repository browser.