26 #define _APERTURE_RADIUS_DEFAULT_ (0.01)
30 #define _ZMIN_ (-40.00)
32 #define _ZMAX_ (40.00)
36 Bore(
double rZin,
double rZout,
double dOut):
37 mApertureRadiusZin(rZin), mApertureRadiusZout(rZout), mOutsideDiameter(dOut) {};
40 double mApertureRadiusZin, mApertureRadiusZout, mOutsideDiameter;
43 static std::map<std::string, Bore*>
bores;
49 mTHETAstart(0.0), mTHETAend(0.0),
50 mSstart(0.0), mSend(0.0), mXstart(0.0), mYstart(0.0), mZstart(0.0), mXend(0.0), mYend(0.0), mZend(0.0),
51 mLength(0.0), mX(0.0), mY(0.0), mZ(0.0), mTHETA(0.0) {
63 virtual double GetField(
void )
const {
return 0.0; };
68 virtual void Calculate(
double Brho) = 0;
69 virtual void Print(
void ) {
printf(
"%10s -> L = %7.3f; X = %7.3f, Z = %8.3f, TH = %7.2f mrad",
70 mName.c_str(), mLength, mX, mZ, mTHETA * 1000); };
73 fprintf(fout,
"%10s %8.4f %8.4f %8.4f %7.4f %7.3f %7.4f %7.3f %7.2f %7.3f %8.3f\n",
74 mName.c_str(), mX, mY, mZ, mApertureRadiusZin, mApertureRadiusZout, mOutsideDiameter, mLength, mTHETA * 1000., GetField(), GetGradient()); };
83 double mXstart, mYstart,
mZstart, mXend, mYend, mZend;
86 double mLength, mX, mY,
mZ, mTHETA;
94 double GetField(
void )
const {
return mField; };
95 void Calculate(
double Brho) { mField = Brho * mANGLE/mLength; };
109 void Calculate(
double Brho) { mGradient = Brho * mK1L/mLength; };
119 BeamLine(
unsigned data_par_num,
unsigned survey_par_num,
bool rear =
false):
120 mBrho(0.0), mDataParNum(data_par_num), mSurveyParNum(survey_par_num) {};
123 void AddDataFile(
const char *fname) { mDataFiles.push_back(fname); };
124 void AddSurveyFile(
const char *fname) { mSurveyFiles.push_back(fname); };
139 static char rname[1024];
140 assert(strlen(name) < 1024);
142 strcpy(rname, name + (name[0] ==
'\"' ? 1 : 0));
144 unsigned slen = strlen(rname);
146 if (rname[slen-1] ==
'\"') rname[slen-1] = 0;
149 unsigned slen = strlen(rname);
150 if (!strcmp(rname+slen-2,
"_E") || !strcmp(rname+slen-2,
"_F")) rname[slen-2] = 0;
151 if (!strcmp(rname+slen-2,
"_6")) rname[slen-2] = 0;
152 if (!strcmp(rname+slen-3,
"_E1") || !strcmp(rname+slen-3,
"_E2")) rname[slen-3] = 0;
160 unsigned slen = strlen(name);
163 return (!strcmp(name+slen-2,
"_F") || !strcmp(name+slen-3,
"_E2") ||
164 !strcmp(name+slen-3,
"_F\"") || !strcmp(name+slen-4,
"_E2\""));
169 unsigned slen = strlen(name);
171 return (!strcmp(name+slen-2,
"_E") || !strcmp(name+slen-3,
"_E1") ||
172 !strcmp(name+slen-3,
"_E\"") || !strcmp(name+slen-4,
"_E1\"") || !strcmp(name+slen-3,
"_6\""));
175 int main(
int argc,
char **argv)
179 electron->
AddDataFile(
"rr-data-norad-ver3-10GeV-elke.tfs.no-dash");
181 hadron->AddDataFile(
"Hadron-275GeV.dataForward");
182 hadron->AddSurveyFile(
"Hadron-275GeV.surveyForward");
183 hadron->AddDataFile(
"Hadron-275GeV.dataRear");
184 hadron->AddSurveyFile(
"Hadron-275GeV.surveyRear");
188 FILE *fbore = fopen(
"bores.txt",
"r");
193 while (fgets(buffer, 1024, fbore)) {
194 if (!strlen(buffer) || buffer[0] ==
'#')
continue;
197 double rZin, rZout, rOut;
198 int ret = sscanf(buffer,
"%s %lf %lf %lf", name, &rZin, &rZout, &rOut);
207 for(
unsigned bl=0; bl<2; bl++) {
211 for(
unsigned fl=0; fl<beamline->
mDataFiles.size(); fl++)
213 for(
unsigned fl=0; fl<beamline->
mSurveyFiles.size(); fl++)
217 for(
unsigned fl=0; fl<beamline->
mAllFiles.size(); fl++) {
218 std::string &fname = beamline->
mAllFiles[fl];
220 bool zflip = fname.find(
"Rear") != std::string::npos;
221 if (beamline == electron) zflip =
true;
223 printf(
"\n --> %s\n\n", fname.c_str());
225 FILE *fin = fopen(fname.c_str(),
"r");
232 while (fgets(buffer, 1024, fin)) {
234 char str1[128], str2[128], str3[128], str4[128], str5[128], *vptr = 0;
235 int hret = sscanf(buffer,
"%s %s %s %s %s", str1, str2, str3, str4, str5);
244 if (!strcmp(str2,
"PC")) {
246 double value = atof(vptr) * 3.335640951;
248 assert(value == beamline->
mBrho);
255 if (fl < beamline->mDataFiles.size()) {
256 double S,
L, BETX, ALFX, BETY, ALFY, MUX, MUY, DX, DPX, ANGLE, K0L, K1L, K2L;
263 char qname[256] =
"";
266 ret = sscanf(buffer,
"%s %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %s %lf",
267 name, &S, &L, &BETX, &ALFX, &BETY, &MUX, &MUY, &DX, &DPX, &ANGLE, &K0L, qname, &K2L);
273 ret = sscanf(buffer,
"%s %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
274 name, &S, &L, &BETX, &ALFX, &BETY, &ALFY, &MUX, &MUY, &DX, &DPX, &ANGLE, &K0L, &K1L, &K2L);
285 if (!ANGLE && !K1L)
continue;
299 double S,
L, ANGLE, X, Y, Z, THETA, dummy;
302 int ret = sscanf(buffer,
"%s %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
303 name, &S, &L, &ANGLE, &X, &Y, &Z, &THETA, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy);
306 if (zflip) Z *= -1.0;
307 if (THETA < -6.0) THETA += 2*
M_PI;
331 printf(
"Orhpan beam line element: %s\n", rname);
342 for(std::map<std::string, MagElement*>::iterator
it = beamline->
mMagElements.begin();
348 printf(
" %10s -> Sstart = %8.4f, Send = %8.4f\n",
it->first.c_str(), element->
mSstart, element->
mSend);
367 printf(
" \n bl#%d: Dipoles:\n", bl);
368 for(std::map<std::string, MagElement*>::iterator
it = beamline->
mMagElements.begin();
371 if (dipole) dipole->
Print();
373 printf(
" \n bl#%d: Quads:\n", bl);
374 for(std::map<std::string, MagElement*>::iterator
it = beamline->
mMagElements.begin();
377 if (quad) quad->
Print();
381 printf(
" \n bl#%d: Ordered element sequence:\n", bl);
390 snprintf(fname, 1024-1,
"%s/ir-magnets-2018-04-04-%s.dat", bl ?
"E" :
"H", bl ?
"electrons" :
"hadrons");
391 FILE *fout = fopen(fname,
"w"); assert(fout);
395 FILE *fheader = fopen(
"header.txt",
"r");
400 while (fgets(buffer, 1024-1, fheader)) fprintf(fout,
"%s", buffer);
409 it->second->WriteOut(fout);