1 | /*
|
---|
2 | ---- Hector the simulator ----
|
---|
3 | A fast simulator of particles through generic beamlines.
|
---|
4 | J. de Favereau, X. Rouby ~~~ hector_devel@cp3.phys.ucl.ac.be
|
---|
5 |
|
---|
6 | http://www.fynu.ucl.ac.be/hector.html
|
---|
7 |
|
---|
8 | Centre de Physique des Particules et de Phénoménologie (CP3)
|
---|
9 | Université Catholique de Louvain (UCL)
|
---|
10 | */
|
---|
11 |
|
---|
12 | /// \file H_OpticalElement.cc
|
---|
13 | /// \brief Class aiming at describing any beam optical element.
|
---|
14 |
|
---|
15 | // c++ #includes
|
---|
16 | #include <iostream>
|
---|
17 | #include <string>
|
---|
18 |
|
---|
19 | // ROOT #includes
|
---|
20 | //#include "TPaveLabel.h"
|
---|
21 |
|
---|
22 | // local #includes
|
---|
23 | #include "H_TransportMatrices.h"
|
---|
24 | #include "H_Aperture.h"
|
---|
25 | #include "H_OpticalElement.h"
|
---|
26 | using namespace std;
|
---|
27 |
|
---|
28 | /// called by the constructors
|
---|
29 | void H_OpticalElement::init(const string nameE, const int typeE, const double s, const double k, const double l, H_Aperture* the_app) {
|
---|
30 | // this is called by the constructors
|
---|
31 | // must be in public section !
|
---|
32 | // xpos and ypos are vectors with n point. They define the aperture shape of the optical element.
|
---|
33 | name = nameE;
|
---|
34 | fs = s;
|
---|
35 | fk = k;
|
---|
36 | xpos = 0;
|
---|
37 | ypos = 0;
|
---|
38 | txpos = 0;
|
---|
39 | typos = 0;
|
---|
40 | element_length = l;
|
---|
41 | type = typeE;
|
---|
42 | element_mat = new TMatrix(MDIM,MDIM);
|
---|
43 | setAperture(the_app);
|
---|
44 |
|
---|
45 | if(element_length<0) { if(VERBOSE) cout<<"\t ERROR : Interpenetration of elements !"<<endl; }
|
---|
46 | if(element_length==0) { if(VERBOSE) cout<<"\t WARNING : 0-length element ! (" << name << ") " << " at " << fs << endl; }
|
---|
47 | betax =0;
|
---|
48 | betay =0;
|
---|
49 | }
|
---|
50 |
|
---|
51 | H_OpticalElement::H_OpticalElement() {
|
---|
52 | H_Aperture* the_app = new H_Aperture();
|
---|
53 | init("",DRIFT,0.,0.,0.1,the_app);
|
---|
54 | }
|
---|
55 |
|
---|
56 | H_OpticalElement::H_OpticalElement(const string nameE, const int typeE, const double s, const double k, const double l) {
|
---|
57 | H_Aperture* the_app = new H_Aperture();
|
---|
58 | init(nameE,typeE,s,k,l,the_app);
|
---|
59 | }
|
---|
60 |
|
---|
61 | H_OpticalElement::H_OpticalElement(const string nameE, const int typeE, const double s, const double k, const double l, H_Aperture* the_app) {
|
---|
62 | init(nameE,typeE,s,k,l,the_app);
|
---|
63 | }
|
---|
64 |
|
---|
65 | H_OpticalElement::H_OpticalElement(const int typeE, const double s, const double k, const double l, H_Aperture* the_app) {
|
---|
66 | init("",typeE,s,k,l,the_app);
|
---|
67 | }
|
---|
68 |
|
---|
69 | H_OpticalElement::H_OpticalElement(const int typeE, const double s, const double k, const double l) {
|
---|
70 | H_Aperture* the_app = new H_Aperture();
|
---|
71 | init("",typeE,s,k,l,the_app);
|
---|
72 | }
|
---|
73 |
|
---|
74 | H_OpticalElement::H_OpticalElement(const H_OpticalElement& el) {
|
---|
75 | fs = el.fs;
|
---|
76 | element_length = el.element_length;
|
---|
77 | fk = el.fk;
|
---|
78 | xpos = el.xpos;
|
---|
79 | ypos = el.ypos;
|
---|
80 | txpos = el.txpos;
|
---|
81 | typos = el.typos;
|
---|
82 | betax = el.betax;
|
---|
83 | betay = el.betay;
|
---|
84 | type = el.type;
|
---|
85 | name = el.name;
|
---|
86 | typestring = el.typestring;
|
---|
87 | element_mat = new TMatrix(*(el.element_mat));
|
---|
88 | element_aperture = new H_Aperture(*(el.element_aperture));
|
---|
89 | }
|
---|
90 |
|
---|
91 | H_OpticalElement& H_OpticalElement::operator=(const H_OpticalElement& el) {
|
---|
92 | if(this==&el) return *this;
|
---|
93 | fs = el.fs;
|
---|
94 | element_length = el.element_length;
|
---|
95 | fk = el.fk;
|
---|
96 | xpos = el.xpos;
|
---|
97 | ypos = el.ypos;
|
---|
98 | txpos = el.txpos;
|
---|
99 | typos = el.typos;
|
---|
100 | betax = el.betax;
|
---|
101 | betay = el.betay;
|
---|
102 | type = el.type;
|
---|
103 | name = el.name;
|
---|
104 | typestring = el.typestring;
|
---|
105 | delete element_mat;
|
---|
106 | delete element_aperture;
|
---|
107 | element_mat = new TMatrix(*(el.element_mat));
|
---|
108 | element_aperture = new H_Aperture(*(el.element_aperture));
|
---|
109 | return *this;
|
---|
110 | }
|
---|
111 |
|
---|
112 | void H_OpticalElement::setAperture(H_Aperture * ap) {
|
---|
113 | // element_aperture = const_cast<H_Aperture*>(ap);
|
---|
114 | element_aperture = ap;
|
---|
115 | return;
|
---|
116 | }
|
---|
117 |
|
---|
118 | void H_OpticalElement::printProperties() const {
|
---|
119 | cout << typestring;
|
---|
120 | cout << name;
|
---|
121 | cout <<"\t at s = " << fs;
|
---|
122 | cout <<"\t length = "<< element_length;
|
---|
123 | if(fk!=0) cout <<"\t strength = " << fk;
|
---|
124 | if(element_aperture->getType()!=NONE) {
|
---|
125 | cout <<"\t aperture type = " << element_aperture->getTypeString();
|
---|
126 | element_aperture->printProperties();
|
---|
127 | }
|
---|
128 |
|
---|
129 | cout<<endl;
|
---|
130 | if(element_length<0) { if(VERBOSE) cout<<"\t ERROR : Interpenetration of elements !"<<endl; }
|
---|
131 | if(element_length==0) { if(VERBOSE) cout<<"\t WARNING : 0-length "<< typestring << " !" << endl; }
|
---|
132 |
|
---|
133 | return;
|
---|
134 | }
|
---|
135 |
|
---|
136 | void H_OpticalElement::showMatrix() const {
|
---|
137 | printMatrix(element_mat);
|
---|
138 | return;
|
---|
139 | }
|
---|
140 |
|
---|
141 | void H_OpticalElement::drawAperture() const {
|
---|
142 | element_aperture->draw();
|
---|
143 | return;
|
---|
144 | }
|
---|
145 |
|
---|
146 | TMatrix H_OpticalElement::getMatrix() const {
|
---|
147 | return *element_mat;
|
---|
148 | }
|
---|
149 |
|
---|
150 | TMatrix H_OpticalElement::getMatrix(const float eloss, const float p_mass, const float p_charge) const {
|
---|
151 | setMatrix(eloss,p_mass,p_charge);
|
---|
152 | return *element_mat;
|
---|
153 | }
|
---|
154 |
|
---|
155 | void H_OpticalElement::draw(const float meight, const float height) const{
|
---|
156 | /* /// @param meight is the minimal extend of the graph
|
---|
157 | /// @param height is the maximal extend of the graph
|
---|
158 | float x1 = getS();
|
---|
159 | float x2 = getS() + getLength();
|
---|
160 | float y1 = meight;
|
---|
161 | float y2 = height;
|
---|
162 | TPaveLabel* cur_box = new TPaveLabel(x1,y1,x2,y2,"");
|
---|
163 | cur_box->SetBorderSize(1);
|
---|
164 | cur_box->SetFillStyle(1001);
|
---|
165 | cur_box->SetFillColor((int)getType());
|
---|
166 | cur_box->Draw();
|
---|
167 | */
|
---|
168 | }
|
---|
169 |
|
---|