OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
OpalPepperPot.cpp
Go to the documentation of this file.
1 //
2 // Class OpalPepperPot
3 // The PEPPERPOT element.
4 // The class of OPAL pepperpot collimators.
5 //
6 // Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
7 // All rights reserved
8 //
9 // This file is part of OPAL.
10 //
11 // OPAL is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
18 //
19 #include "Elements/OpalPepperPot.h"
20 #include "Attributes/Attributes.h"
23 
24 
26  OpalElement(SIZE, "PEPPERPOT",
27  "The \"PEPPERPOT\" element defines an pepperpot collimator."),
28  parmatint_m(NULL) {
30  ("XSIZE", "Size in x of the pepperpot in m");
32  ("YSIZE", "Size in y of the pepperpot in m");
34  ("NHOLX", "Number of holes in x");
36  ("NHOLY", "Number of holes in y");
38  ("R", "Radios of a holes in m");
39 
41 
42  setElement(new FlexibleCollimatorRep("PEPPERPOT"));
43 }
44 
45 
46 OpalPepperPot::OpalPepperPot(const std::string& name, OpalPepperPot* parent):
47  OpalElement(name, parent),
48  parmatint_m(NULL) {
50 }
51 
52 
54  if (parmatint_m)
55  delete parmatint_m;
56 }
57 
58 
59 OpalPepperPot* OpalPepperPot::clone(const std::string& name) {
60  return new OpalPepperPot(name, this);
61 }
62 
63 
66 
68  dynamic_cast<FlexibleCollimatorRep*>(getElement());
69 
70  double length = Attributes::getReal(itsAttr[LENGTH]);
71  ppo->setElementLength(length);
73 
74  if (getOpalName() != "PEPPERPOT") {
75  double xsize = Attributes::getReal(itsAttr[XSIZE]);
76  double ysize = Attributes::getReal(itsAttr[YSIZE]);
77  double diameter = 2 * Attributes::getReal(itsAttr[R]);
78  int repX = Attributes::getReal(itsAttr[NHOLX]) - 1;
79  int repY = Attributes::getReal(itsAttr[NHOLY]) - 1;
80 
81  double shiftx = (xsize - diameter) / repX;
82  double shifty = (ysize - diameter) / repY;
83 
84  std::stringstream description;
85  description << "repeat(repeat(translate(ellipse("
86  << diameter << "," << diameter << "),"
87  << -shiftx * 0.5 * repX << "," << -shifty * 0.5 * repY << "),"
88  << repX << "," << shiftx << ",0.0),"
89  << repY << ",0.0," << shifty << ")";
90 
91  std::cout << "OpalPepperPot.cpp: " << __LINE__ << "\t"
92  << description.str() << std::endl;
93  ppo->setDescription(description.str());
94  exit(1);
95  }
96 
98  const std::string matterDescriptor = Attributes::getString(itsAttr[PARTICLEMATTERINTERACTION]);
100  parmatint_m = orig->clone(matterDescriptor);
103  }
104 
105  // Transmit "unknown" attributes.
107 }
@ SIZE
Definition: IndexMap.cpp:174
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
const std::string name
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:120
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:125
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:281
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:436
void setOutputFN(std::string fn)
Set output filename.
virtual void setParticleMatterInteraction(ParticleMatterInteractionHandler *spys)
void setDescription(const std::string &desc)
@ PARTICLEMATTERINTERACTION
Definition: OpalElement.h:39
virtual void updateUnknown(ElementBase *)
Transmit the `‘unknown’' (not known to OPAL) attributes to CLASSIC.
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const
ParticleMatterInteraction * parmatint_m
Definition: OpalPepperPot.h:60
virtual void update()
Update the embedded CLASSIC collimator.
OpalPepperPot()
Exemplar constructor.
virtual OpalPepperPot * clone(const std::string &name)
Make clone.
virtual ~OpalPepperPot()
virtual ParticleMatterInteraction * clone(const std::string &name)
Make clone.
static ParticleMatterInteraction * find(const std::string &name)
Find named PARTICLEMATTERINTERACTION.
ParticleMatterInteractionHandler * handler_m
void initParticleMatterInteractionHandler(ElementBase &element)