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