From b94a01f68f6a91fbfd719e8b8d57646aa30b1891 Mon Sep 17 00:00:00 2001
From: zhang <zhang@9a6e40ed-f3a0-4838-9b4a-bf418f78e88d>
Date: Mon, 10 Jan 2011 10:35:49 +0000
Subject: [PATCH] 10/01/2011

1)
 Change SetErr( ) to SetErr2( )  which is delicated for the soleil lattice with two half quadrupoles.
Add SetErr( ) which is delicated for the lattice with full quadrupoles.
---
 tracy/tracy/inc/soleillib.h  |  3 +-
 tracy/tracy/src/soleillib.cc | 75 ++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/tracy/tracy/inc/soleillib.h b/tracy/tracy/inc/soleillib.h
index e2a0f04..6fc47b6 100644
--- a/tracy/tracy/inc/soleillib.h
+++ b/tracy/tracy/inc/soleillib.h
@@ -9,7 +9,8 @@
 */
 
  /**** Protypes ****/
-void SetErr(long seed,double fac);
+void SetErr2(long seed,double fac);  //set error for lattice with two half quadrupoles
+void SetErr(long seed,double fac);   //set error for lattice with one full quadrupoles
 void InducedAmplitude(long spos);
 void Hfonction(long pos, double dP);
 //void Hcofonction(long pos, double dP,Vector2 H);
diff --git a/tracy/tracy/src/soleillib.cc b/tracy/tracy/src/soleillib.cc
index f598114..78aa4d3 100644
--- a/tracy/tracy/src/soleillib.cc
+++ b/tracy/tracy/src/soleillib.cc
@@ -280,6 +280,7 @@ void Hcofonction(long pos, double dP)
        Definir une distribution aleatoire de quadripoles tournes associee a chaque
        quadripole de la machine
        Distribution gaussienne d'ecart type fac et coupe a normcut*sigma
+       This function works for the lattice with full quadrupoles
 
    Input:
        seed: random seed number
@@ -303,9 +304,83 @@ void Hcofonction(long pos, double dP)
        Only valid if quad split into two part (cf pair variable)
        Rotation inversion to do as in BETA code
        Test if normal quad sin(theta) = 0. Do not work if tilt error
+       
+       Modified by Jianfeng Zhang 19/01/2011 @soleil
 
 ****************************************************************************/
 void SetErr(long seed,double fac)
+{
+  double  normcut = 0.0;
+  long    i = 0L;
+ // CellType Cell;
+  double theta = 0.0;
+  bool prt=false;
+  
+  
+  if(!prt){
+    printf("\n");
+    printf(" Setting random rotation errors to quadrupole magnets:\n");
+    printf("   random seed number is: %ld, rms value of the rotation error is: %lf rad\n",seed,fac);
+  }
+  
+  setrancut(normcut=2L);
+  iniranf(seed);
+
+  for (i = 1L; i <= globval.Cell_nLoc; i++)
+  {
+    if (Cell[i].Elem.Pkind == 2L)
+    {
+      if (Cell[i].Elem.M->Porder == 2L && Cell[i].dT[1] == 0)
+      {
+        theta = fac*normranf(); /* random error every 2 elements (quad split into 2) */
+        Cell[i].Elem.M->PBpar[HOMmax-2L] = -Cell[i].Elem.M->PBpar[HOMmax+2L]*sin(2.0*theta);
+        Cell[i].Elem.M->PBpar[HOMmax+2L] =  Cell[i].Elem.M->PBpar[HOMmax+2L]*cos(2.0*theta);
+        if (trace) printf("%6s % .5e % .5e % .5e\n",Cell[i].Elem.PName,
+                           Cell[i].Elem.M->PBpar[HOMmax-2L], Cell[i].Elem.M->PBpar[HOMmax+2L],theta);
+
+        Mpole_SetPB(Cell[i].Fnum, Cell[i].Knum, -2L);
+        Mpole_SetPB(Cell[i].Fnum, Cell[i].Knum, 2L);
+      }
+    }
+  }
+}
+
+/****************************************************************************/
+/* void SetErr2(long seed,double fac)
+
+   Purpose:
+       Set error
+       Definir une distribution aleatoire de quadripoles tournes associee a chaque
+       quadripole de la machine
+       Distribution gaussienne d'ecart type fac et coupe a normcut*sigma
+       This function works for the lattice with two half quadrupoles
+
+   Input:
+       seed: random seed number
+       fac :  RMS value of the rotation angle of the quadrupole
+   Output:
+       none
+
+   Return:
+       none
+
+   Global variables:
+       globval
+       HOMmax
+
+   specific functions:
+       setrandcut, initranf
+       getelem, putelem
+       Mpole_SetPB
+
+   Comments:
+       Only valid if quad split into two part (cf pair variable)
+       Rotation inversion to do as in BETA code
+       Test if normal quad sin(theta) = 0. Do not work if tilt error
+       
+
+****************************************************************************/
+void SetErr2(long seed,double fac)
 {
   double  normcut = 0.0;
   long    i = 0L;
-- 
GitLab