Coder Social home page Coder Social logo

How to obtain BPM readings? about cpymad HOT 3 CLOSED

Landau1908 avatar Landau1908 commented on July 29, 2024
How to obtain BPM readings?

from cpymad.

Comments (3)

coldfix avatar coldfix commented on July 29, 2024

There is no MAD-X command called TABLE, so your code is clearly incorrect. Also, it looks like you might be passing an incorrect file name. Furthermore, you did (again) not deliver the MAD-X example file with your issue. What are you trying to achieve exactly? BTW: I'm not a MAD-X expert, so if you're asking for some basic MAD-X functionality, ask them.

from cpymad.

Landau1908 avatar Landau1908 commented on July 29, 2024

Thanks, Thomas
I want to simulate orbit correct, and the BPM readings are essential for calculating Orbit Response Matrix (ORM). Recently, I write a code to obtain the BPM readings, and I think it is very verbose using this way to obtain the BPM readings, although it works well. Is there any elegant method to get the BPM readings? Below is my code and the Madx file used.

from __future__ import division
import matplotlib.pylab as plt
from cpymad.madx import Madx
def readBpm(bpm, sequence="himm"):
    """
    read the x value of BPM 
    """
    madx.command.twiss(sequence=sequence)
    twiss = madx.get_table("twiss")
    bpm = bpm
    ind = []
    for bpm0 in bpm:
        ind.append([i for i, bpm1 in enumerate(twiss['name']) if bpm1 == bpm0])
    #print ind
    s = []
    x = []
    for i0 in ind:
        s.append(twiss['s'][i0])
        x.append(twiss['x'][i0])
    return s, x
madx = Madx(command_log="HIMM_log.madx") 
madx.command.call(file="HIMM_cpymad")
madx.command.twiss(sequence="himm")
#plot bpm data before correct
bpm = ['bpm11:1','bpm12:1','bpm21:1','bpm31:1','bpm32:1','bpm33:1','bpm42:1','bpm41:1']
sequence = "himm"
bpmData = readBpm(bpm, sequence)
s = bpmData[0]
x = bpmData[1]
plt.plot(s,x,'b-o',label="befor correct")
plt.legend()
plt.show()

Max file, named as "HIMM_cpymad".

TITLE,'HIMM Project';
  OPTION, INFO, -ECHO,WARN;
 BEAM, particle = carbon, energy = 0.007;

! Defining elements

! drift--------------------------------------------------------------

  D11:drift,l=1.75;
  D12:drift,l=0.40;
  D13:drift,l=0.25;
  D14:drift,l=0.10;
  D15:drift,l=0.13;
  D16:drift,l=0.15;
  D17:drift,l=1.775;
  D18:drift,l=0.125;
  D19:drift,l=0.25;
  D1a:drift,l=0.53;

  D21:drift,l=0.43;
  D22:drift,l=0.35;
  D23:drift,l=0.40;
  D24:drift,l=0.15;
  D25:drift,l=2.00;
  D26:drift,l=0.44;
  D27:drift,l=0.10;
  D28:drift,l=0.24;
  D29:drift,l=1.75;

  D31:drift,l=0.67;
  D32:drift,l=0.10;
  D33:drift,l=0.63;
  D34:drift,l=0.40;
  D35:drift,l=0.25;
  D36:drift,l=0.13;
  D37:drift,l=0.15;
  !D38:drift,l=2.00;
  D39:drift,l=0.45;
  D3a:drift,l=0.33;
 D3b:drift,l=0.125;
 D3c:drift,l=1.775;

  D41:drift,l=0.43;
  D42:drift,l=0.35;
  D43:drift,l=0.40;
  D44:drift,l=0.15;
  !D45:drift,l=2.00;
  D46:drift,l=0.455;
  D47:drift,l=0.075;
  D48:drift,l=0.25;
  D491:drift,l=0.06;
  D492:drift,l=0.07;
  D4a:drift,l=0.81;
 D4b:drift,l=0.73;
 D4c:drift,l=1.17;
! marker-------------------------------------------------------------

  m1:marker;
  m2:marker;

! constant definition of dipoles-------------------------------------

  N=8;
  !bero=6.342738
  !Bm=1.58568
  ro = 4.0; !bero/Bm
  leng := ro*(twopi/N);

  Rr=0.07; !Reference radius of field measurement
  a1=0; !quadrupole component in dipoles
  a2=0.0; !end field
  a3=0.0; !end field

! dipole without multipole-------------------------------------------

  RB: SBEND, L=leng,ANGLE=TWOPI/N,K0=1/ro,K1=a1*(1/ro)*(1/Rr),
             E1=PI/8,E2=PI/8,FINT=0.55,FINTX=0.55,HGAP=0.037;
  !EB: RBEND, ANGLE=a2*TWOPI/N;
  !EA: RBEND, ANGLE=a3*TWOPI/N;

! dipole definition--------------------------------------------------

   B11:RB;
   B12:RB;
   B21:RB;
   B22:RB;
   B31:RB;
   B32:RB;
   B41:RB;
   B42:RB;

   HB11: LINE=(B11);
   HB12: LINE=(B12);

   HB21: LINE=(B21);
   HB22: LINE=(B22);

   HB31: LINE=(B31);
   HB32: LINE=(B32);

   HB41: LINE=(B41);
   HB42: LINE=(B42);

! quadrupole without multipole---------------------------------------

  QF: QUADRUPOLE, L=0.2, K1=0.799839688766;
  QD: QUADRUPOLE, L=0.2, K1=-1.00783349327;
  QFF: QUADRUPOLE, L=0.35, K1=1.038161630875;
  !FQ: QUADRUPOLE, L=0.15,K1=0.00;

! quadrupole definition----------------------------------------------

  Q11:QF;
  Q12:QD;
  Q13:QFF;

  Q21:QF;
  Q22:QD;
  Q23:QFF;

  Q31:QF;
  Q32:QD;
  Q33:QFF;

  Q41:QF;
  Q42:QD;
  Q43:QFF;

  !FQ41: FQ;

! chromaticity sextupole definition----------------------------------

  SEXTCH:  sextupole,l=0.15, k2=0.0;
  SEXTCV:  sextupole,l=0.15, k2=0.0;

  SH11: SEXTCH;
  SH31: SEXTCH;
  SV21: SEXTCV;
  SV41: SEXTCV;

! resonance sextupole definition-------------------------------------

  SEXTR:  sextupole,l=0.15, k2=0.0;

  SR11: SEXTR;
  SR21: SEXTR;
  SR31: SEXTR;
  SR41: SEXTR;
  S41: SEXTR;

! corrector Kicker---------------------------------------------------

  CYX: KICKER, L=0.1, HKICK:=0.0, VKICK:=0.0;
  CY: VKICKER, L=0.1, KICK:=0.0;
  CX: HKICKER, L=0.1, KICK:=0.0;
  CX1:CX, KICK=0.004543802;
  CX2:CX, KICK=-0.001323422;
  CX3:CX, KICK=0.001031226;
  CX4:CX, KICK=0.000204781;
  CX5:CX, KICK=0.006345063;
  CX6:CX, KICK=-0.000924923;
  CY11:CY;
  CY22:CY;
  CY31:CY;
  CY32:CY;
  CY41:CY;
  CY42:CY;
  C21:CYX;


! MONITOR------------------------------------------------------------

  PKUP: MONITOR, L=0.25;

  BPM11: PKUP;
  BPM12: PKUP;

  BPM21: PKUP;

  BPM31: PKUP;
  BPM32: PKUP;
  BPM33: PKUP;

  BPM41: PKUP;
  BPM42: PKUP;

  PU11: LINE=(BPM11);
  PU12: LINE=(BPM12);

  PU21: LINE=(BPM21);

  PU31: LINE=(BPM31);
  PU32: LINE=(BPM32);
  PU33: LINE=(BPM33);

  PU41: LINE=(BPM41);
  PU42: LINE=(BPM42);

! ring definition----------------------------------------------------

  CELL1:Line=(D11,Q11,D12,HB11,D13,PU11,D14,CY11,D15,
              SR11,D16,Q12,D17,CX1,D18,SH11,D16,Q13,
              D12,HB12,D19,PU12,D1a);

  CELL2:Line=(CY22,D21,SV21,D22,HB22,D23,Q23,D24,SR21,
              D25,Q22,D26,CX2,D27,PU21,D28,HB21,D23,
              Q21,D29);

  CELL3:Line=(D31,PU31,D32,CX3,D33,Q31,D34,HB31,D35,
              PU32,D32,CY31,D36,SR31,D37,Q32,D3c,CX4,D3b,SH31,
              D37,Q33,D34,HB32,D39,CY32,D3a,PU33);

  CELL4:Line=(D41,SV41,D42,HB42,D43,Q43,D44,SR41,D4b,CX6,D4c,
              Q42,D46,CY42,D47,PU42,D48,HB41,D43,Q41,
              D44,S41,D491,CX5,D492,CY41,D491,PU41,D4a);

  himm: Line=(CELL1,CELL2,CELL3,CELL4);
 USE, SEQUENCE = himm;
//--------------error definition of dipole-------------

//EOPT,seed = 912345678

SELECT, FLAG = ERROR, CLEAR;
SELECT, FLAG=ERROR, CLASS=B11;
EFCOMP, ORDER=0, RADIUS=0.5,
DKN = {1E-2,0,0},
DKS = {0,0,0};

from cpymad.

coldfix avatar coldfix commented on July 29, 2024

I'm not your personal advisor. And yes, this can be written much shorter - with just some knowledge in python programming. It has nothing to do with cpymad.

from cpymad.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.