Develop its own diagnostic

https://www.dacm-logiciels.fr/tracewin
JapanBruce Yee
Competent
Competent
Posts: 86
Joined: Tue 22 Dec 2020 03:47
Country:
Japan (jp)
Japan

Develop its own diagnostic

Post by JapanBruce Yee »

Dear Didier,

I want to develop my own diagnostic element for my beam studies.

As a first step, I used the example "main.cpp" provided in the manual (
main.cpp
(11.37 KiB) Downloaded 198 times
).

Here just a small comment for compile command

// g++.exe m32 -Wall -c main.cpp -o main.o (we required to add "-" before "m32", like g++.exe -m32 -Wall )

// g++.exe m32 -shared -Wl,--dll main.o -o my_elements.dll (for the second, in additon to -m32, "--dll" is "-dll")

This is no important but for not expert like me, it saves some minutes.

I compared the diagnostic created by main.cpp "my_pos_and_size" against the "Diag_Position". I associated the diagnostic element with the adjust command.

However, the "my_pos_and_size" diagnostic does not adjust the value. I checked the code, I am not sure if the "my_pos_and_size" makes the comparison between the target value and the computed. It seems that only computes either the position or the rms size in X. I attached the input files.(
main.cpp
(11.37 KiB) Downloaded 198 times
)
Could you comment on it?

My goal is to develop a diagnostic element equivalent to "DIAG_DENERGY" or "DIAG_DPHASE" for the twiss parameters.
Could you give some hints to implement that?

Best regards,

Bruce
Attachments
TEST.zip
(41.6 KiB) Downloaded 217 times
User avatar
FranceDidier
Administrator
Administrator
Posts: 975
Joined: Wed 26 Aug 2020 14:40
Country:
France (fr)
France

Re: Develop its own diagnostic

Post by FranceDidier »

Dear Bruce,

I read on my manual "-m32", not "m32" ! Where did you find this error ?
And on my side, "-Wl,--dll" works, but anyway, this part can be removed without changing anything.

Now checking our example, I had to change two lines.
In trackning part I replaced "xmoy/ng;" by "if (ng>0) xmoy/=ng; else xmoy=1e6;"' because due to loss that will generate an error.
In envelope part I replaced " *diag_value=Bcent[1];" by "*diag_value=Bcent[0];" becasue Bent[1] is xp

For work on Denergy or/and Dphase, I think Bcent[4] & Bcent[5] are the right variables to use, just don't forget to make convertion between z->phase and dp/p->energy

Regards,

Didier
JapanBruce Yee
Competent
Competent
Posts: 86
Joined: Tue 22 Dec 2020 03:47
Country:
Japan (jp)
Japan

Re: Develop its own diagnostic

Post by JapanBruce Yee »

Dear Didier,

Thank you very much for your reply.

About your comment,

1)Where did you find this error ?
The error was in my pdf manual.

2) I modified the main.cpp to include the vertical plane. I include the source file and the library. (
Code.zip
(33.35 KiB) Downloaded 188 times
).

I made the comparison of "DIAG_POSITION" vs "My_DIAG"
I associated the diagnostic with "Steerer" element, the next figure show the results
Diagnostic.PNG
Diagnostic.PNG (51.71 KiB) Viewed 3869 times
On the left is the "DIAG_POSITION", center "MY_DIAG" and on the right the code.

As you can see, only horizontal adjustment is done.
I would like to know how I can make the adjustment on the vertical one?

3) Could you tell me in which part of the script the "target value" is compared against the "diag_value"?

4) Finally, about the Denergy and Dphase diagnostic, I want to know how does the diagnostic call or acces to the so-called "perfect linac energy measurements" or "perfect linac phase measurements".
I asked that because my goal is to develop a DTwissparameters diagnostic, which obtained the delta between "Beam Twissparameter" and the "Perfect linac Twiss parameters measurements".
Thus, I want to understand how it works these two diagnostics (Denergy and Dphase diagnostic) to create the "DTwissparameters diagnostic".

Best regards,

Bruce
User avatar
FranceDidier
Administrator
Administrator
Posts: 975
Joined: Wed 26 Aug 2020 14:40
Country:
France (fr)
France

Re: Develop its own diagnostic

Post by FranceDidier »

Dear Bruce,

1) here my manual :
manual_pdf.png
manual_pdf.png (80.28 KiB) Viewed 3865 times
2 & 3) You made a confusion about how return the criteria value, please use that instead:

Code: Select all

*diag_value=sqrt(Bcent[0]*Bcent[0]+Bcent[2]*Bcent[2]);   // X & Y beam position (m)
4) I think it will not be possible to compare the Twiss parameters of the perfect linac and the one with imperfections. The only data available here and in the code is the central particle transported in the 2 cases, this difference being represented in the variable Bcent.

Regards,

Didier
JapanBruce Yee
Competent
Competent
Posts: 86
Joined: Tue 22 Dec 2020 03:47
Country:
Japan (jp)
Japan

Re: Develop its own diagnostic

Post by JapanBruce Yee »

Dear Didier,

Thanks for your help.

1) About the command in the manual.
I tried to say that you are right, the official version appears "-m32". The error was in my personal pdf manual (for some bizarre reason appeared; however, I already replaced it with a new one and everything is fine.)

2) About the diagnostic.
I implemented the command "*diag_value=sqrt(Bcent[0]*Bcent[0]+Bcent[2]*Bcent[2]); // X & Y beam position (m)".

Now, it also made the adjustment in vertical.

One question, If I want a specific certain value for x and y independently. What should I do?

For the notes in the code:

// param[1] : target_value

// param[2] : you can use this second parameter to define to diagnostic types

// param[3->8] : free

The param[1] is assigned for the target_value, if now I have two target_values What should I do?

3) When you said that "The only data available here and in the code is the central particle transported in the 2 cases".
You mean only Bcent matrix is available, right? Is also Bmat available?

I want to compute the Twiss parameters from the Bmat, saved for the perfect linac as a kind of Bcent for the Twiss. And the apply the same as D phase diagnostic.

By that way, Could you tell me how does "DIAG_TWISS" work?
In the end, it is similar to what I want to do; however, in my case, the code itself provides the Twiss parameters.

Thanks for your help and time.

Bruce
User avatar
FranceDidier
Administrator
Administrator
Posts: 975
Joined: Wed 26 Aug 2020 14:40
Country:
France (fr)
France

Re: Develop its own diagnostic

Post by FranceDidier »

Dear Bruce,

1) Ok,

2) Yes, I think I'll do something like that: diag_value=sqrt((Bcent[0]-param[1])*(Bcent[0]-param[1])+(Bcent[2]-param[2])*(Bcent[2]-param[2]))

3) Probably, there is a way to do what you want to do, because if you include error in your simulation using error commands provided by TraceWin, simulation will use this dll for both cases, wihtout errors and with errors and using static variables allowing to save Bmat in memory of the frist step and use it during the second step made with error.

4) Have a look in "Mismatch factor" in manual.

Regards,

Didier
JapanBruce Yee
Competent
Competent
Posts: 86
Joined: Tue 22 Dec 2020 03:47
Country:
Japan (jp)
Japan

Re: Develop its own diagnostic

Post by JapanBruce Yee »

Dear Didier,

Thank you very much for your suggestions.

About the use of "diag_value=sqrt((Bcent[0]-param[1])*(Bcent[0]-param[1])+(Bcent[2]-param[2])*(Bcent[2]-param[2]))". (A.1)

I have the next comments,

1) It seems that optimization criteria is the following "TraceWin Criteria = pow(target_value - diag_value),2)" (A.2)
(This is written in the code main.cpp)

And given that " // param[1] : target_value" (A.3) (This is written in the code main.cpp)

The value of diag_value (Eq. A.1) is only compared against param[1] (Using A.2 and A.3).

I found a way to overcome this by using the following

MY_DIAG (my_pos_and_size) Nelem Param[1] Param[2] Param[3] Param[4] (A.4)

and "diag_value=sqrt((Bcent[0]-param[2])*(Bcent[0]-param[2])+(Bcent[2]-param[3])*(Bcent[2]-param[3]))". (A.5)

In my case Param[1]=0 , Param[2]= Xwanted, Param[3] Y wanted, Param[4] = 0 for position and 1 for size.

What do you think?

2) About saving value for the "perfect linacs", in the case of "DIAG_DENERGY" how do you save the Bcent[5] for the perfect linacs to be compared with Bcent[5] of the error ones?
As you said if I have access to the Bmat on the first step, I can compute the twiss. Could you give me some hints on how to do it?

3) Mismatch factor,
I understand for the "DIAG_TWISS" you computed the mismatch factor. I was also thinking about that. Moreover, I want to use the Twiss_criterion in the manual.
Twiss_criterion.PNG
Twiss_criterion.PNG (6.59 KiB) Viewed 3857 times
For that diagnostic element, How do you compute the twiss? I guess that using the following formulas
Twiss.PNG
Twiss.PNG (53.01 KiB) Viewed 3857 times
Where the sigma matrix is the Bmat??

Thanks for your time and help,

Bruce
User avatar
FranceDidier
Administrator
Administrator
Posts: 975
Joined: Wed 26 Aug 2020 14:40
Country:
France (fr)
France

Re: Develop its own diagnostic

Post by FranceDidier »

Dear Bruce,

1) Yes I forgot this point (A.2), even if my first suggestion works, it's clearly not the best way
So I suggest you to do like that:

Code: Select all

if (param[2]==0) {
   *diag_value=Bcent[0];   // X beam position (m)
}
if (param[2]==1) {
   *diag_value=Bcent[2];   // Y beam position (m)
}
So, two diag are needed to set X & Y beam position like following.

Code: Select all

MY_DIAG (my_pos_and_size) 1 wanted_X(m) 0
MY_DIAG (my_pos_and_size) 1 wanted_Y(m) 1
2) Fisrt Bcent(4) and Bcent(5) variable already represente the difference between perfect and unperfect linac, but that's all. For the rest, I'm sorry but I said a mistake when I suggest you to save Bmat during the two step of simulation. Actually it's wrong only one step is perform and it's not possible to do that. Sorry, I spoke to fast.
The simulation is done directly including errors, so usually when I want to set the Twiss parameters with error equal to those without error, I first do a simulation without error. I read the TWiss parameters obtained at a given position and define here a DIAG_TWISS using them. Then I run a simulation with errors. It's a bit heavy, because it forces to do it in two steps, but it works.

3) I don't understand your question. Bmat is indeed the beam matrix and so you can extract the Twiss parameters using the formulas you have noted.

Regards,

Didier
JapanBruce Yee
Competent
Competent
Posts: 86
Joined: Tue 22 Dec 2020 03:47
Country:
Japan (jp)
Japan

Re: Develop its own diagnostic

Post by JapanBruce Yee »

Dear Didier,

Thank you very much for your explanations.

1) Please allow me to add something.
When you use adjusted like this:

MY_DIAG (my_pos_and_size) 1 wanted_X(m) 0
MY_DIAG (my_pos_and_size) 1 wanted_Y(m) 1

I believe that the code adjusts first on the X plane, and then on the Y, right?
I am wondering if when Y is adjusted, this affects the result on X.

2) I will follow your advice and run the two simulations.

3) Sorry for the confusing question; however, your explanation answers my question.

Best regards,

Bruce
User avatar
FranceDidier
Administrator
Administrator
Posts: 975
Joined: Wed 26 Aug 2020 14:40
Country:
France (fr)
France

Re: Develop its own diagnostic

Post by FranceDidier »

Dear Bruce,

1) No, they are adjusted in same time and considering you have a solenoid, yes both planes are coupled. Bu don't worry, the algorithm is done to manage that.

Regards,

Didier
Post Reply