BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
element.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "element.h"
19#include "elementtype.h"
20#include "parameters.h"
21#include "parser.h"
22
23#include <cstdio>
24#include <cstdlib>
25#include <iostream>
26#include <sstream>
27#include <string>
28
29using namespace GMAD;
30
31namespace
32{
34 void print(const std::list<Element>& l, int ident=0)
35 {
36 if (ident == 0)
37 {std::cout << "using line " << Parser::Instance()->current_line << std::endl;}
38
39 for (auto& el : l)
40 {el.print();}
41 }
42}
43
45 lst(nullptr)
46{
47 flush();
48
50}
51
53{
54 publish("userTypeName", &Element::userTypeName);
55 publish("userParameters", &Element::userParameters);
56
57 publish("l", &Element::l);
58 publish("scaling", &Element::scaling);
59 publish("scalingFieldOuter", &Element::scalingFieldOuter);
60 publish("ks", &Element::ks);
61 publish("k1", &Element::k1);
62 publish("k2", &Element::k2);
63 publish("k3", &Element::k3);
64 publish("k4", &Element::k4);
65 publish("angle", &Element::angle);
66 publish("B", &Element::B);
67 publish("e1", &Element::e1);
68 publish("e2", &Element::e2);
69 publish("fint", &Element::fint);
70 publish("fintx", &Element::fintx);
71 publish("fintK2", &Element::fintK2);
72 publish("fintxK2", &Element::fintxK2);
73 publish("hgap", &Element::hgap);
74 publish("h1", &Element::h1);
75 publish("h2", &Element::h2);
76 publish("kick", &Element::kick);
77 publish("hkick", &Element::hkick);
78 publish("vkick", &Element::vkick);
79 publish("knl", &Element::knl);
80 publish("ksl", &Element::ksl);
81 publish("gradient", &Element::gradient);
82 publish("E", &Element::E);
83 publish("frequency", &Element::frequency);
84 publish("phase", &Element::phase);
85 publish("tOffset", &Element::tOffset);
86 publish("fieldModulator", &Element::fieldModulator);
87 publish("kg", &Element::kg);
88
89 // rmatrix elements, only 4x4
90 publish("kick1", &Element::kick1);
91 publish("kick2", &Element::kick2);
92 publish("kick3", &Element::kick3);
93 publish("kick4", &Element::kick4);
94 publish("rmat11", &Element::rmat11);
95 publish("rmat12", &Element::rmat12);
96 publish("rmat13", &Element::rmat13);
97 publish("rmat14", &Element::rmat14);
98 publish("rmat21", &Element::rmat21);
99 publish("rmat22", &Element::rmat22);
100 publish("rmat23", &Element::rmat23);
101 publish("rmat24", &Element::rmat24);
102 publish("rmat31", &Element::rmat31);
103 publish("rmat32", &Element::rmat32);
104 publish("rmat33", &Element::rmat33);
105 publish("rmat34", &Element::rmat34);
106 publish("rmat41", &Element::rmat41);
107 publish("rmat42", &Element::rmat42);
108 publish("rmat43", &Element::rmat43);
109 publish("rmat44", &Element::rmat44);
110
111 // beampipe information, new aperture model
112 publish("beampipeThickness",&Element::beampipeThickness);
113 publish("aper1", &Element::aper1);
114 publish("aper", &Element::aper1);
115 alternativeNames["aper"] = "aper1";
116 publish("aperture", &Element::aper1);
117 alternativeNames["aperture"] = "aper1";
118 publish("aperture1", &Element::aper1);
119 alternativeNames["aperture1"] = "aper1";
120 publish("beampipeRadius", &Element::aper1);
121 alternativeNames["beampipeRadius"] = "aper1";
122 publish("aper2", &Element::aper2);
123 publish("aperture2", &Element::aper2);
124 alternativeNames["aperture2"] = "aper2";
125 publish("aper3", &Element::aper3);
126 publish("aperture3", &Element::aper3);
127 alternativeNames["aperture3"] = "aper3";
128 publish("aper4", &Element::aper4);
129 publish("aperture4", &Element::aper4);
130 alternativeNames["aperture4"] = "aper4";
131 publish("apertureType", &Element::apertureType);
132 publish("beampipeMaterial", &Element::beampipeMaterial);
133 publish("vacuumMaterial", &Element::vacuumMaterial);
134
135 // magnet geometry
136 publish("magnetGeometryType", &Element::magnetGeometryType);
137 publish("horizontalWidth", &Element::horizontalWidth);
138 publish("outerDiameter", &Element::horizontalWidth);
139 alternativeNames["outerDiameter"] = "horizontalWidth";
140 publish("yokeOnInside", &Element::yokeOnInside);
141 publish("hStyle", &Element::hStyle);
142 publish("vhRatio", &Element::vhRatio);
143 publish("coilWidthFraction", &Element::coilWidthFraction);
144 publish("coilHeightFraction", &Element::coilHeightFraction);
145 publish("tilt", &Element::tilt);
146 publish("xsize", &Element::xsize);
147 publish("ysize", &Element::ysize);
148 publish("xsizeOut", &Element::xsizeOut);
149 publish("ysizeOut", &Element::ysizeOut);
150 publish("xsizeLeft", &Element::xsizeLeft);
151 publish("xsizeRight", &Element::xsizeRight);
152 publish("offsetX", &Element::offsetX);
153 publish("offsetY", &Element::offsetY);
154 publish("jawTiltLeft", &Element::jawTiltLeft);
155 publish("jawTiltRight", &Element::jawTiltRight);
156
157 // PWFA
158 publish("xsize2", &Element::xsize2);
159 publish("ysize2", &Element::ysize2);
160 publish("offsetX2", &Element::offsetX2);
161 publish("offsetY2", &Element::offsetY2);
162 publish("tilt2", &Element::tilt2);
163 publish("outerShape", &Element::outerShape);
164
165 // screen parameters
166 publish("tscint", &Element::tscint);
167 publish("twindow", &Element::twindow);
168 publish("tmount", &Element::tmount);
169 publish("windowScreenGap", &Element::windowScreenGap);
170 publish("screenXSize", &Element::screenXSize);
171 publish("screenYSize", &Element::screenYSize);
172 publish("layerThicknesses",&Element::layerThicknesses);
173 publish("layerMaterials", &Element::layerMaterials);
174 publish("layerIsSampler", &Element::layerIsSampler);
175
176 // for AWAKE spectrometer
177 publish("screenPSize", &Element::screenPSize);
178 publish("screenEndZ", &Element::screenEndZ);
179 publish("poleStartZ", &Element::poleStartZ);
180 publish("screenWidth", &Element::screenWidth);
181 publish("awakeMagnetOffsetX", &Element::awakeMagnetOffsetX);
182 publish("windowmaterial", &Element::windowmaterial);
183 publish("scintmaterial", &Element::scintmaterial);
184 publish("mountmaterial", &Element::mountmaterial);
185
186 // for 3d transform and laser
187 publish("x", &Element::xdir);
188 alternativeNames["x"] = "xdir";
189 publish("y", &Element::ydir);
190 alternativeNames["y"] = "ydir";
191 publish("z", &Element::zdir);
192 alternativeNames["z"] = "zdir";
193 publish("xdir", &Element::xdir);
194 publish("ydir", &Element::ydir);
195 publish("zdir", &Element::zdir);
196 publish("wavelength", &Element::wavelength);
197 publish("waveLength", &Element::wavelength);
198 alternativeNames["waveLength"] = "wavelength";
199 publish("phi", &Element::phi);
200 publish("theta", &Element::theta);
201 publish("psi", &Element::psi);
202 publish("axisX", &Element::axisX);
203 publish("axisY", &Element::axisY);
204 publish("axisZ", &Element::axisZ);
205 publish("axisAngle", &Element::axisAngle);
206
207 // for degrader
208 publish("numberWedges", &Element::numberWedges);
209 publish("wedgeLength", &Element::wedgeLength);
210 publish("degraderHeight", &Element::degraderHeight);
211 publish("materialThickness", &Element::materialThickness);
212 publish("degraderOffset", &Element::degraderOffset);
213
214 publish("laserBeam", &Element::laserBeam);
215 publish("laserOffsetTheta", &Element::laserOffsetTheta);
216 publish("laserOffsetPhi", &Element::laserOffsetPhi);
217 publish("laserOffsetX", &Element::laserOffsetX);
218 publish("laserOffsetY", &Element::laserOffsetY);
219 publish("laserOffsetZ", &Element::laserOffsetZ);
220
221 publish("undulatorPeriod", &Element::undulatorPeriod);
222 publish("undulatorGap", &Element::undulatorGap);
223 publish("undulatorMagnetHeight", &Element::undulatorMagnetHeight);
224
225 // for wirescanner
226 publish("wireDiameter", &Element::wireDiameter);
227 publish("wireLength", &Element::wireLength);
228 publish("wireOffsetX", &Element::wireOffsetX);
229 publish("wireOffsetY", &Element::wireOffsetY);
230 publish("wireOffsetZ", &Element::wireOffsetZ);
231 publish("wireAngle", &Element::wireAngle);
232
233 // for undulator
234 publish("undulatorPeriod", &Element::undulatorPeriod);
235 publish("undulatorGap", &Element::undulatorGap);
236 publish("undulatorMagnetHeight", &Element::undulatorMagnetHeight);
237
238 // for gabor lens
239 publish("anodeRadius", &Element::anodeRadius);
240 publish("anodeLength", &Element::anodeLength);
241 publish("anodeThickness", &Element::anodeThickness);
242 publish("electrodeRadius", &Element::electrodeRadius);
243 publish("electrodeLength", &Element::electrodeLength);
244 publish("electrodeThickness", &Element::electrodeThickness);
245
246 // for jaw collimator with tip
247 publish("tipThickness", &Element::tipThickness);
248 publish("tipMaterial", &Element::tipMaterial);
249
250 // bias
251 publish("bias", &Element::bias);
252 publish("biasMaterial", &Element::biasMaterial);
253 publish("biasVacuum", &Element::biasVacuum);
254 publish("biasMaterialLV", &Element::biasMaterialLV);
255
256 publish("minimumKineticEnergy",&Element::minimumKineticEnergy);
257
258 publish("samplerName", &Element::samplerName);
259 publish("samplerType", &Element::samplerType);
260 publish("r", &Element::samplerRadius); // historic
261 publish("samplerRadius", &Element::samplerRadius);
262 alternativeNames["r"] ="samplerRadius";
263
264 publish("region", &Element::region);
265 publish("fieldOuter", &Element::fieldOuter);
266 publish("fieldVacuum", &Element::fieldVacuum);
267 publish("fieldAll", &Element::fieldAll);
268 publish("bmap", &Element::fieldAll);
269 alternativeNames["bmap"] = "fieldAll";
270
271 publish("geometryFile", &Element::geometryFile);
272 publish("geometry", &Element::geometryFile);
273 alternativeNames["geometry"] = "geometryFile"; // backwards compatibility
274 publish("stripOuterVolume", &Element::stripOuterVolume);
275 publish("autoColour", &Element::autoColour);
276 publish("elementLengthIsArcLength", &Element::elementLengthIsArcLength);
277 publish("material", &Element::material);
278 publish("outerMaterial", &Element::material);
279 alternativeNames["outerMaterial"] = "material";
280 publish("namedVacuumVolumes", &Element::namedVacuumVolumes);
281 publish("markAsCollimator", &Element::markAsCollimator);
282 publish("spec", &Element::spec);
283 publish("cavityModel", &Element::cavityModel);
284 publish("cavityFieldType", &Element::cavityFieldType);
285
286 publish("dicomDataPath", &Element::dicomDataPath);
287 publish("dicomDataFile", &Element::dicomDataFile);
288
289 publish("colour", &Element::colour);
290
291 publish("crystalLeft", &Element::crystalLeft);
292 publish("crystalRight", &Element::crystalRight);
293 publish("crystalBoth", &Element::crystalBoth);
294 publish("crystalAngleYAxisLeft" , &Element::crystalAngleYAxisLeft);
295 publish("crystalAngleYAxisRight", &Element::crystalAngleYAxisRight);
296
297 publish("coolingDefinition", &Element::coolingDefinition);
298
299 attribute_map_list_double["knl"] = &knl;
300 attribute_map_list_double["ksl"] = &ksl;
301 attribute_map_list_double["layerThicknesses"] = &layerThicknesses;
302 attribute_map_list_string["layerMaterials"] = &layerMaterials;
303 attribute_map_list_int["layerIsSampler"] = &layerIsSampler;
304 attribute_map_list_string["biasMaterialList"] = &biasMaterialList;
305 attribute_map_list_string["biasVacuumList"] = &biasVacuumList;
306 attribute_map_list_string["biasMaterialLVList"] = &biasMaterialLVList;
307}
308
309std::string Element::getPublishedName(const std::string& nameIn) const
310{
311 auto it = alternativeNames.find(nameIn);
312 if (it != alternativeNames.end())
313 {return it->second;}
314 // if not found return name
315 return nameIn;
316}
317
319{
320 return (type == ElementType::_TRANSFORM3D ||
321 type == ElementType::_MARKER ||
322 type == ElementType::_LINE ||
323 type == ElementType::_REV_LINE);
324}
325
326void Element::print(int ident) const
327{
328 for(int i=0;i<ident;i++)
329 {std::cout << "--";}
330
331 std::cout << name << " : " << type << std::endl;
332 if (l > 0.0)
333 {std::cout << "l = " << l << "m" << std::endl;}
334 if (horizontalWidth > 0)
335 {std::cout << "horizontalWidth = " << horizontalWidth << "m" << std::endl;}
336 if (samplerType != "none")
337 {
338 std::cout << "samplerType = " << samplerType << "\n"
339 << "samplerRadius = " << samplerRadius << "\n"
340 << "samplerarticleSetID = " << samplerParticleSetID << std::endl;
341 }
342
343 switch(type)
344 {
345 case ElementType::_SBEND:
346 case ElementType::_RBEND:
347 {
348 std::cout << "B = " << B << std::endl
349 << "angle = " << angle << std::endl
350 << "k1 = " << k1 << std::endl;
351 break;
352 }
353 case ElementType::_QUAD:
354 {std::cout << "k1 = " << k1 << std::endl; break;}
355 case ElementType::_SEXTUPOLE:
356 {std::cout << "k2 = " << k2 << std::endl; break;}
357 case ElementType::_OCTUPOLE:
358 {std::cout << "k3 = " << k3 << std::endl; break;}
359 case ElementType::_DECAPOLE:
360 {std::cout << "k4 = " << k4 << std::endl; break;}
361 case ElementType::_SOLENOID:
362 {std::cout << "ks = " << ks << std::endl; break;}
363 case ElementType::_MULT:
364 case ElementType::_THINMULT:
365 {
366 std::cout << " , knl={";
367 for (auto value : knl)
368 {std::cout << value << ", ";}
369 std::cout << "}, ksl={";
370 for (auto value : ksl)
371 {std::cout << value << ", ";}
372 std::cout << "}" << std::endl;
373 break;
374 }
375 case ElementType::_ECOL:
376 case ElementType::_RCOL:
377 case ElementType::_BMCOL:
378 case ElementType::_JCOL:
379 case ElementType::_JCOLTIP:
380 {
381 std::cout << "x half aperture = " << xsize <<" m" << std::endl
382 << "y half aperture = " << ysize <<" m" << std::endl
383 << "material = \"" << material << "\"" << std::endl;
384 break;
385 }
386 case ElementType::_ELEMENT:
387 {
388 std::cout << "horizontalWidth: " << horizontalWidth << "m" << std::endl
389 << "geometryFile: " << geometryFile << std::endl
390 << "fieldAll: " << fieldAll << std::endl;
391 break;
392 }
393 case ElementType::_RF:
394 case ElementType::_RFX:
395 case ElementType::_RFY:
396 {
397 std::cout << "E (voltage): " << E << " V" << std::endl
398 << "gradient (e field): " << gradient << " V/m" << std::endl
399 << "cavityFieldType: " << cavityFieldType << std::endl
400 << "cavityModel: " << cavityModel << std::endl
401 << "frequency: " << frequency << " Hz" << std::endl
402 << "phase: " << phase << " rad" << std::endl;
403 break;
404 }
405 case ElementType::_CT:
406 {
407 std::cout << "dicomDataPath: " << dicomDataPath << std::endl;
408 std::cout << "dicomDataFile: " << dicomDataFile << std::endl;
409 break;
410 }
411 case ElementType::_AWAKESCREEN:
412 {
413 std::cout << "twindow = " << twindow*1e6 << " um" << std::endl
414 << "tscint = " << tscint*1e6 << " um" << std::endl
415 << "windowScreenGap = " << windowScreenGap*1e6 << " um" << std::endl
416 << "windowmaterial = " << windowmaterial << std::endl
417 << "scintmaterial = " << scintmaterial << std::endl;
418 break;
419 }
420 case ElementType::_AWAKESPECTROMETER:
421 {
422 std::cout << "twindow = " << twindow*1e6 << " um" << std::endl
423 << "tscint = " << tscint*1e6 << " um" << std::endl
424 << "screenPSize = " << screenPSize*1e6 << " um" << std::endl
425 << "windowScreenGap = " << windowScreenGap*1e6 << " um" << std::endl
426 << "windowmaterial = " << windowmaterial << std::endl
427 << "tmount = " << tmount*1e6 << " um" << std::endl
428 << "mountmaterial = " << mountmaterial << std::endl
429 << "scintmaterial = " << scintmaterial << std::endl;
430 break;
431 }
432 case ElementType::_LASERWIREOLD:
433 {
434 std::cout << "lambda= " << wavelength << "m" << std::endl
435 << "xSigma= " << xsize << "m" << std::endl
436 << "ySigma= " << ysize << "m" << std::endl
437 << "xdir= " << xdir << std::endl
438 << "ydir= " << ydir << std::endl
439 << "zdir= " << zdir << std::endl;
440 break;
441 }
442 case ElementType::_SCREEN:
443 {
444 std::cout << "angle= " << angle <<"rad" << std::endl;
445 break;
446 }
447 case ElementType::_TRANSFORM3D:
448 {
449 std::cout << "xdir= " << xdir << "m" << std::endl
450 << "ydir= " << ydir << "m" << std::endl
451 << "zdir= " << zdir << "m" << std::endl
452 << "phi= " << phi << "rad" << std::endl
453 << "theta= " << theta << "rad" << std::endl
454 << "psi= " << psi << "rad" << std::endl;
455 break;
456 }
457 case ElementType::_GABORLENS:
458 {
459 std::cout << "b= " << B << "T" << std::endl
460 << "kg= " << kg << std::endl;
461 break;
462 }
463 default:
464 {break;}
465 }
466
467 switch (type)
468 {
469 case ElementType::_RBEND:
470 case ElementType::_SBEND:
471 case ElementType::_QUAD:
472 case ElementType::_SEXTUPOLE:
473 case ElementType::_OCTUPOLE:
474 case ElementType::_DECAPOLE:
475 case ElementType::_SOLENOID:
476 case ElementType::_MULT:
477 case ElementType::_THINMULT:
478 case ElementType::_AWAKESPECTROMETER:
479 case ElementType::_MUONSPOILER:
480 case ElementType::_HKICKER:
481 case ElementType::_VKICKER:
482 case ElementType::_KICKER:
483 case ElementType::_TKICKER:
484 case ElementType::_UNDULATOR:
485 case ElementType::_RF:
486 case ElementType::_RFX:
487 case ElementType::_RFY:
488 {
489 std::cout << "scaling = " << scaling << std::endl;
490 if (scalingFieldOuter != 1)
491 {std::cout << "scalingFieldOuter = " << scalingFieldOuter << std::endl;}
492 std::cout << "fieldModulator = \"" << fieldModulator << "\"" << std::endl;
493 break;
494 }
495 case ElementType::_MUONCOOLER:
496 {
497 std::cout << "coolingDefinition= " << coolingDefinition << std::endl;
498 break;
499 }
500
501 default:
502 {break;}
503 }
504
505 if (lst)
506 {::print(*lst,++ident);}
507}
508
510{
511 type = ElementType::_NONE;
512 name = "";
513 userTypeName = "";
514 userParameters = "";
515 l = 0;
516 scaling = 1;
518 ks = 0;
519 k1 = 0;
520 k2 = 0;
521 k3 = 0;
522 k4 = 0;
523 angle = 0;
524 B = 0;
525 e1 = 0;
526 e2 = 0;
527 fint = 0;
528 fintx = -1;
529 fintK2 = 0;
530 fintxK2 = 0;
531 hgap = 0;
532 h1 = 0;
533 h2 = 0;
534 kick = 0;
535 hkick = 0;
536 vkick = 0;
537 knl.clear();
538 ksl.clear();
539 gradient = 0;
540 E = 0;
541 frequency = 0;
542 phase = 0;
543 tOffset = 0;
544 fieldModulator = "";
545 kg = 0;
546
547 // rmatrix
548 kick1 = 0;
549 kick2 = 0;
550 kick3 = 0;
551 kick4 = 0;
552 rmat11= 1.0;
553 rmat12= 0;
554 rmat13= 0;
555 rmat14= 0;
556 rmat21= 0;
557 rmat22= 1.0;
558 rmat23= 0;
559 rmat24= 0;
560 rmat31= 0;
561 rmat32= 0;
562 rmat33= 1.0;
563 rmat34= 0;
564 rmat41= 0;
565 rmat42= 0;
566 rmat43= 0;
567 rmat44= 1.0;
568
569 // new aperture model
571 aper1 = 0;
572 aper2 = 0;
573 aper3 = 0;
574 aper4 = 0;
575 apertureType = "";
576 beampipeMaterial = "";
577 vacuumMaterial = "";
578
579 // magnet geometry
580 magnetGeometryType = "";
581 horizontalWidth = 0;
582 yokeOnInside = true;
583 hStyle = -1;
584 vhRatio = -1;
586 coilHeightFraction = -1; // signifies use default in factory
587 tilt = 0;
588 xsize = 0;
589 ysize = 0;
590 xsizeOut = 0;
591 ysizeOut = 0;
592 xsizeLeft = 0;
593 xsizeRight = 0;
594 offsetX = 0;
595 offsetY = 0;
596 jawTiltLeft = 0;
597 jawTiltRight = 0;
598 tipThickness = 0;
599
600 // PWFA
601 xsize2 = 0;
602 ysize2 = 0;
603 offsetX2 = 0;
604 offsetY2 = 0;
605 tilt2 = 0;
606 outerShape = "rectangular";
607
608 // screen parameters
609 tscint = 0.0003;
610 twindow = 0;
611 tmount = 0;
612 windowScreenGap = 0;
613 screenXSize = 0;
614 screenYSize = 0;
615 layerThicknesses.clear();
616 layerMaterials.clear();
617 layerIsSampler.clear();
618
619 // for AWAKE spectrometer
620 screenPSize = 0;
621 screenEndZ = 0;
622 poleStartZ = 0;
623 screenWidth = 0;
624 awakeMagnetOffsetX = 0.13;
625 windowmaterial = "vacuum";
626 scintmaterial = "";
627 mountmaterial = "";
628
629 // for 3d transform and laser
630 xdir = 0;
631 ydir = 0;
632 zdir = 0;
633 wavelength = 0;
634 gradient = 0;
635 phi = 0;
636 theta = 0;
637 psi = 0;
638 axisX = 0;
639 axisY = 0;
640 axisZ = 0;
641 axisAngle = false;
642
643 // for degrader
644 numberWedges = 1;
645 wedgeLength = 0;
646 degraderHeight = 0;
648 degraderOffset = 0;
649
650 // laserwire
651 laserBeam = "";
653 laserOffsetPhi = 0;
654 laserOffsetX = 0;
655 laserOffsetY = 0;
656 laserOffsetZ = 0;
657
658 // for wirescanner
659 wireDiameter = 0;
660 wireLength = 0;
661 wireOffsetX = 0;
662 wireOffsetY = 0;
663 wireOffsetZ = 0;
664 wireAngle = 0;
665
666 // undulator
667 undulatorPeriod = 1;
668 undulatorGap = 0;
670
671 // gabor lens
672 anodeLength = 0;
673 anodeRadius = 0;
674 anodeThickness = 0;
675 electrodeLength = 0;
676 electrodeRadius = 0;
678
679 // bias
680 bias = "";
681 biasMaterial = "";
682 biasVacuum = "";
683 biasMaterialLV = "";
684 biasMaterialList.clear();
685 biasVacuumList.clear();
686 biasMaterialLVList.clear();
687
689
690 samplerName = "";
691 samplerType = "none"; // allowed "none", "plane", "cylinder"
692 samplerRadius = 0;
693 samplerParticleSetID = -1; // -1 is code for none
694
695 region = "";
696 fieldOuter = "";
697 fieldVacuum = "";
698 fieldAll = "";
699
700 geometryFile = "";
701 stripOuterVolume = false;
702 autoColour = true;
704 material="";
706 markAsCollimator = false;
707 spec = "";
708 cavityModel = "";
709 cavityFieldType = "";
710
711 dicomDataFile = "";
712 dicomDataPath = "";
713
714 colour = "";
715
716 crystalLeft = "";
717 crystalRight = "";
718 crystalBoth = "";
719 crystalAngleYAxisLeft = 0;
720 crystalAngleYAxisRight = 0;
721
723
724 angleSet = false;
725 scalingFieldOuterSet = false;
726
727 lst = nullptr;
728}
729
730double Element::property_lookup(std::string property_name) const
731{
732 double value;
733 try
734 {value = get<double>(this,property_name);}
735 catch (const std::runtime_error&)
736 {
737 std::cerr << "element.cc> Error: unknown property \"" << property_name
738 << "\" (only works on numerical properties)" << std::endl;
739 exit(1);
740 }
741 return value;
742}
743
744void Element::set(const Parameters& params, std::string nameIn, ElementType typeIn)
745{
746 // common parameters for all elements
747 type = typeIn;
748 name = nameIn;
749
750 set(params);
751
752 if (params.setMap.at("angle"))
753 {angleSet = true;}
754 else if (params.setMap.at("scalingFieldOuter"))
755 {scalingFieldOuterSet = true;}
756}
757
758void Element::set(const Parameters& params)
759{
760 for (auto& i : params.setMap)
761 {
762 if (i.second)
763 {
764 std::string property = i.first;
765
766 // method can in theory throw runtime_error (shouldn't happen), catch and exit gracefully
767 try
768 {Published<Element>::set(this,(Element*)&params,property);}
769 catch(const std::runtime_error&)
770 {
771 std::cerr << "Error: parser> unknown property \"" << property
772 << "\" for element " << name << std::endl;
773 exit(1);
774 }
775
776 // split bias into tokens and add to both material and vacuum
777 if (property == "bias")
778 {
779 std::stringstream ss(bias);
780 std::string tok;
781 while(ss >> tok)
782 {
783 biasMaterialList.push_back(tok);
784 biasVacuumList.push_back(tok);
785 biasMaterialLVList.push_back(tok);
786 }
787 }
788 else if (property == "biasMaterial")
789 {
790 std::stringstream ss(biasMaterial);
791 std::string tok;
792 while(ss >> tok) {biasMaterialList.push_back(tok);}
793 }
794 else if (property == "biasVacuum")
795 {
796 std::stringstream ss(biasVacuum);
797 std::string tok;
798 while(ss >> tok) {biasVacuumList.push_back(tok);}
799 }
800 else if (property == "biasMaterialLV")
801 {
802 std::stringstream ss(biasMaterialLV);
803 std::string tok;
804 while(ss >> tok) {biasMaterialLVList.push_back(tok);}
805 }
806 }
807 }
808}
809
810void Element::setSamplerInfo(std::string samplerTypeIn,
811 std::string samplerNameIn,
812 double samplerRadiusIn,
813 int particleSetIDIn)
814{
815 if (samplerType != "none")
816 {std::cout << "WARNING: overwriting already defined sampler info for element: " << name << std::endl;}
817
818 samplerType = samplerTypeIn;
819 samplerName = samplerNameIn;
820 samplerRadius = samplerRadiusIn;
821 samplerParticleSetID = particleSetIDIn;
822}
823
824void Element::set_value_array(const std::string& property, Array* value, bool bExit)
825{
826 auto search1 = attribute_map_list_int.find(property);
827 if (search1 != attribute_map_list_int.end())
828 {
829 value->set_vector(*search1->second);
830 return;
831 }
832
833 auto search2 = attribute_map_list_double.find(property);
834 if (search2 != attribute_map_list_double.end())
835 {
836 value->set_vector(*search2->second);
837 return;
838 }
839
840 auto search3 = attribute_map_list_string.find(property);
841 if (search3 != attribute_map_list_string.end()) {
842 value->set_vector(*search3->second);
843 return;
844 }
845
846 std::cerr << "Error: parser> unknown element option \"" << property << "\", or doesn't expect vector type" << std::endl;
847 if(bExit)
848 {exit(1);}
849 else
850 {std::rethrow_exception(std::current_exception());}
851}
852
853#if __cplusplus >= 201703L
854std::list<std::variant<bool, int, double, std::string>> Element::get_value_array(const std::string & property) {
855 std::list<std::variant<bool, int, double, std::string>> retval;
856
857 // search int list
858 auto search1 = attribute_map_list_int.find(property);
859 if (search1 != attribute_map_list_int.end()) {
860 retval.resize((*search1).second->size());
861 std::copy((*search1).second->begin(),(*search1).second->end(), retval.begin());
862 }
863
864 // search double list
865 auto search2 = attribute_map_list_double.find(property);
866 if (search2 != attribute_map_list_double.end()) {
867 retval.resize((*search2).second->size());
868 std::copy((*search2).second->begin(),(*search2).second->end(), retval.begin());
869 }
870
871 // search string list
872 auto search3 = attribute_map_list_string.find(property);
873 if (search3 != attribute_map_list_string.end()) {
874 retval.resize((*search3).second->size());
875 std::copy((*search3).second->begin(),(*search3).second->end(), retval.begin());
876 }
877
878 return retval;
879}
880#endif
Representation of arrays used in tokens.
Definition array.h:39
void set_vector(Container< std::string, std::allocator< std::string > > &dst) const
Copy symbols into STL string containers.
Definition array.h:101
std::string current_line
Name of beamline.
Definition parser.h:213
static Parser * Instance()
Access method.
Definition parser.cc:121
void publish(const std::string &name, T C::*mp)
Make pointer to member from class C and type T with accessible with a name.
Definition published.h:93
void set(C *instance, const std::string &name, double value)
Definition published.h:100
Parser namespace for GMAD language. Combination of Geant4 and MAD.
ElementType
types of elements
Definition elementtype.h:27
Element class.
Definition element.h:47
double property_lookup(std::string property_name) const
Definition element.cc:730
double hkick
fractional delta px for hkicker
Definition element.h:74
std::string dicomDataFile
for CT, file for DICOM construction data
Definition element.h:266
std::string spec
Arbitrary specification to pass to beamline builder.
Definition element.h:261
void print(int ident=0) const
print method
Definition element.cc:326
std::string biasMaterial
temporary string for bias setting
Definition element.h:225
double twindow
thickness of window
Definition element.h:145
double B
magnetic field
Definition element.h:63
double aper4
beampipe information, new aperture model
Definition element.h:115
double hgap
half distance of pole separation for purposes of fringe fields - 'half gap'
Definition element.h:70
void set(const Parameters &params)
set method from Parameters structure
Definition element.cc:758
void PublishMembers()
publish members so these can be looked up from parser
Definition element.cc:52
std::string beampipeMaterial
beampipe information, new aperture model
Definition element.h:117
std::string samplerType
element has a sampler of this type (default "none")
Definition element.h:240
double ysize2
size of the beam mask second aperture
Definition element.h:138
double laserOffsetTheta
for laserwire
Definition element.h:186
double rmat33
rmatrix elements, only 4x4
Definition element.h:101
double rmat11
rmatrix elements, only 4x4
Definition element.h:91
double rmat43
rmatrix elements, only 4x4
Definition element.h:105
double laserOffsetPhi
for laserwire
Definition element.h:187
std::list< std::string > layerMaterials
for screen
Definition element.h:151
std::string userParameters
String for passing user parameters through.
Definition element.h:51
double scaling
Overall scaling of field strength.
Definition element.h:54
std::string cavityFieldType
Name for type of field to use in a cavity.
Definition element.h:263
double windowScreenGap
air gap between window and screen
Definition element.h:147
std::string tipMaterial
tip material
Definition element.h:220
double gradient
for rf cavities in V / m
Definition element.h:78
double degraderOffset
for degrader
Definition element.h:181
bool isSpecial() const
check if element is of a special type
Definition element.cc:318
double aper2
beampipe information, new aperture model
Definition element.h:113
double anodeLength
for gabor lens
Definition element.h:209
double fintx
fringe field integral at the dipole exit
Definition element.h:67
double kick4
rmatrix elements, only 4x4
Definition element.h:90
std::list< Element > * lst
in case the element is a list itself (line)
Definition element.h:288
double k2
sextupole
Definition element.h:59
double rmat42
rmatrix elements, only 4x4
Definition element.h:104
double aper1
beampipe information, new aperture model
Definition element.h:112
double rmat41
rmatrix elements, only 4x4
Definition element.h:103
double h2
output pole face curvature for bends
Definition element.h:72
std::string outerShape
'rectangular' or 'circular'. used in gascap and bmcol
Definition element.h:141
double laserOffsetY
for laserwire
Definition element.h:189
double awakeMagnetOffsetX
for AWAKE spectrometer
Definition element.h:160
double zdir
for 3d transform and laser
Definition element.h:169
double h1
input pole face curvature for bends
Definition element.h:71
std::string namedVacuumVolumes
For imported geometry - identify vacuum volumes.
Definition element.h:259
std::string biasMaterialLV
temporary string for bias setting
Definition element.h:227
double anodeThickness
for gabor lens
Definition element.h:211
bool stripOuterVolume
For Element. Make it an assembly.
Definition element.h:253
double screenPSize
for AWAKE spectrometer
Definition element.h:156
double xdir
for 3d transform and laser
Definition element.h:167
double rmat34
rmatrix elements, only 4x4
Definition element.h:102
double psi
for 3d transforms
Definition element.h:172
double rmat31
rmatrix elements, only 4x4
Definition element.h:99
double wedgeLength
for degrader
Definition element.h:178
double vhRatio
ratio of vertial to horizontal for some magnets
Definition element.h:126
double rmat22
rmatrix elements, only 4x4
Definition element.h:96
double fintxK2
second fringe field integral at the dipole exit - for TRANSPORT matching
Definition element.h:69
std::string userTypeName
User component element type name.
Definition element.h:50
double offsetY2
offset of the beam mask second aperture
Definition element.h:139
double kick3
rmatrix elements, only 4x4
Definition element.h:89
double rmat24
rmatrix elements, only 4x4
Definition element.h:98
double tOffset
time offset used for phase calculation (ns)
Definition element.h:82
std::list< std::string > biasMaterialList
Definition element.h:230
double fint
fringe field integral at the dipole entrance
Definition element.h:66
double xsizeRight
individual collimator jaw half widths
Definition element.h:132
std::string bias
temporary string for bias setting
Definition element.h:224
double coilWidthFraction
Fraction of available h space the coil will take up.
Definition element.h:127
double rmat44
rmatrix elements, only 4x4
Definition element.h:106
double ks
solenoid
Definition element.h:56
std::string fieldAll
Field for everything.
Definition element.h:250
double electrodeRadius
for gabor lens
Definition element.h:213
double jawTiltRight
jaw collimator jaw tilts (angle in x-z plane)
Definition element.h:133
std::string region
region with range cuts
Definition element.h:247
double wireDiameter
@[ for wirescanner
Definition element.h:194
int samplerParticleSetID
Definition element.h:245
double tmount
thickness of the screen mount
Definition element.h:146
std::list< double > ksl
skew multipole expansion
Definition element.h:77
int numberWedges
for degrader
Definition element.h:177
double kick1
rmatrix elements, only 4x4
Definition element.h:87
std::list< std::string > biasMaterialLVList
physics biasing list for specific LVs
Definition element.h:234
std::string getPublishedName(const std::string &name) const
returns 'official' member name for property
Definition element.cc:309
std::list< double > knl
multipole expansion coefficients
Definition element.h:76
std::string windowmaterial
for AWAKE spectrometer
Definition element.h:161
double e2
output pole face rotation for bends
Definition element.h:65
double phase
phase of rf cavity (rad)
Definition element.h:81
double ysizeOut
collimator aperture or laser spotsize for laser
Definition element.h:131
std::string fieldVacuum
Vacuum field.
Definition element.h:249
bool autoColour
Automagically colour the external geometry.
Definition element.h:254
double angle
bending angle
Definition element.h:62
double electrodeThickness
for gabor lens
Definition element.h:214
int hStyle
-1 = unset; 0 = false (ie c style); 1 = true, use hstyle
Definition element.h:125
std::string geometryFile
For Element. File for external geometry.
Definition element.h:252
std::string vacuumMaterial
beampipe information, new aperture model
Definition element.h:118
double vkick
fractional delta py for vkicker
Definition element.h:75
double laserOffsetZ
for laserwire
Definition element.h:190
double E
voltage for rf cavities in V that will be assumed over length l
Definition element.h:79
double coilHeightFraction
Fraction of availalbe v space the coil will take up.
Definition element.h:128
std::list< int > layerIsSampler
for screen
Definition element.h:152
double laserOffsetX
for laserwire
Definition element.h:188
bool elementLengthIsArcLength
For Element. Treat the length as arc length, if not chord.
Definition element.h:256
double screenYSize
Definition element.h:148
double offsetX
offset X
Definition element.h:134
double screenEndZ
for AWAKE spectrometer
Definition element.h:157
double ysize
collimator aperture or laser spotsize for laser
Definition element.h:130
std::string coolingDefinition
For muon cooler.
Definition element.h:278
double rmat23
rmatrix elements, only 4x4
Definition element.h:97
Element()
constructor
Definition element.cc:44
std::string colour
Override colour for certain items.
Definition element.h:269
double rmat13
rmatrix elements, only 4x4
Definition element.h:93
double anodeRadius
for gabor lens
Definition element.h:210
double tilt
tilt
Definition element.h:129
double materialThickness
for degrader
Definition element.h:180
void flush()
flush method
Definition element.cc:509
double l
length in metres
Definition element.h:53
double kick
fractional delta p for either h or v kicker
Definition element.h:73
double rmat14
rmatrix elements, only 4x4
Definition element.h:94
double beampipeThickness
beampipe information, new aperture model
Definition element.h:111
std::string dicomDataPath
for CT, file for DICOM construction data
Definition element.h:265
double wavelength
for laser wire and 3d transforms
Definition element.h:171
double minimumKineticEnergy
minimum kinetic energy for user limits - respected on element by element basis
Definition element.h:237
std::string scintmaterial
for AWAKE spectrometer
Definition element.h:162
double ydir
for 3d transform and laser
Definition element.h:168
double undulatorMagnetHeight
for undulator
Definition element.h:205
void setSamplerInfo(std::string samplerType, std::string samplerName, double samplerRadius, int samplerParticleSetIDIn=-1)
set sampler info
Definition element.cc:810
double tipThickness
for jaw collimator with tip
Definition element.h:219
std::string cavityModel
Name of geometry model object for rfconstantinz cavities.
Definition element.h:262
void set_value_array(const std::string &property, Array *value, bool bExit=true)
Set method for lists.
Definition element.cc:824
double e1
input pole face rotation for bends
Definition element.h:64
std::list< std::variant< bool, int, double, std::string > > get_value_array(const std::string &)
Get method for lists.
Definition element.cc:854
double k1
quadrupole
Definition element.h:58
std::string fieldOuter
Outer field.
Definition element.h:248
std::string laserBeam
for laserwire
Definition element.h:185
double undulatorPeriod
for undulator
Definition element.h:203
std::string biasVacuum
temporary string for bias setting
Definition element.h:226
double electrodeLength
for gabor lens
Definition element.h:212
std::map< std::string, std::string > alternativeNames
map that translates between alternative parser names for members, could be made static
Definition element.h:328
double tilt2
tilt of the beam mask second aperture
Definition element.h:140
double undulatorGap
for undulator
Definition element.h:204
double poleStartZ
for AWAKE spectrometer
Definition element.h:158
double fintK2
second fringe field integral at the dipole entrance - for TRANSPORT matching
Definition element.h:68
bool angleSet
Definition element.h:283
std::string mountmaterial
for AWAKE spectrometer
Definition element.h:163
double k4
decapole
Definition element.h:61
double samplerRadius
Definition element.h:241
double aper3
beampipe information, new aperture model
Definition element.h:114
ElementType type
element enum
Definition element.h:48
std::list< std::string > biasVacuumList
physics biasing list for the vacuum
Definition element.h:232
double offsetY
offset Y
Definition element.h:135
std::list< double > layerThicknesses
for screen
Definition element.h:150
double scalingFieldOuter
Extra arbitrary scaling for outer field - compounded with 'scaling'.
Definition element.h:55
double kg
gabor lens
Definition element.h:84
std::string samplerName
name of sampler (default empty)
Definition element.h:239
double degraderHeight
for degrader
Definition element.h:179
double tscint
thickness of scintillating part of screen
Definition element.h:144
double k3
octupole
Definition element.h:60
double screenWidth
for AWAKE spectrometer
Definition element.h:159
double frequency
frequency for rf cavity in Hz
Definition element.h:80
double kick2
rmatrix elements, only 4x4
Definition element.h:88
double rmat12
rmatrix elements, only 4x4
Definition element.h:92
std::string apertureType
beampipe information, new aperture model
Definition element.h:116
double rmat21
rmatrix elements, only 4x4
Definition element.h:95
double rmat32
rmatrix elements, only 4x4
Definition element.h:100
Parameters - Element class with booleans.
Definition parameters.h:43
std::map< std::string, bool > setMap
Map that holds booleans for every member of element.
Definition parameters.h:46