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 |
|
---|
13 | /// \file H_AbstractBeamLine.cc
|
---|
14 | /// \brief Class describing ideal beamline.
|
---|
15 | ///
|
---|
16 | /// Units : angles [rad], distances [m], energies [GeV], c=[1].
|
---|
17 |
|
---|
18 | // c++ #includes
|
---|
19 | #include <iostream>
|
---|
20 | #include <cmath>
|
---|
21 |
|
---|
22 | // ROOT #includes
|
---|
23 | #include "TPaveLabel.h"
|
---|
24 | #include "TLine.h"
|
---|
25 | #include "TGaxis.h"
|
---|
26 | #include "TLegend.h"
|
---|
27 | #include "TF1.h"
|
---|
28 | #include "TROOT.h"
|
---|
29 |
|
---|
30 | // local #includes
|
---|
31 | #include "H_Parameters.h"
|
---|
32 | #include "H_TransportMatrices.h"
|
---|
33 | #include "H_Drift.h"
|
---|
34 | #include "H_AbstractBeamLine.h"
|
---|
35 | #include "H_RomanPot.h"
|
---|
36 | using namespace std;
|
---|
37 |
|
---|
38 | void H_AbstractBeamLine::init(const float length) {
|
---|
39 | beam_mat.ResizeTo(MDIM,MDIM);
|
---|
40 | beam_mat = driftmat(length);
|
---|
41 | beam_length = length;
|
---|
42 | H_Drift * drift0 = new H_Drift("Drift0",0.,length);
|
---|
43 | add(drift0);
|
---|
44 | return;
|
---|
45 | }
|
---|
46 |
|
---|
47 | H_AbstractBeamLine::H_AbstractBeamLine(const H_AbstractBeamLine& beamline) {
|
---|
48 | elements = beamline.elements;
|
---|
49 | matrices = beamline.matrices;
|
---|
50 | beam_mat.ResizeTo(MDIM,MDIM);
|
---|
51 | beam_mat = beamline.beam_mat;
|
---|
52 | beam_length = beamline.beam_length;
|
---|
53 | }
|
---|
54 |
|
---|
55 | H_AbstractBeamLine& H_AbstractBeamLine::operator=(const H_AbstractBeamLine& beamline) {
|
---|
56 | if(this== &beamline) return *this;
|
---|
57 | elements = beamline.elements;
|
---|
58 | matrices = beamline.matrices;
|
---|
59 | beam_mat = beamline.beam_mat;
|
---|
60 | beam_length = beamline.beam_length;
|
---|
61 | return *this;
|
---|
62 | }
|
---|
63 |
|
---|
64 | H_AbstractBeamLine* H_AbstractBeamLine::clone() const {
|
---|
65 | H_AbstractBeamLine* temp_beam = new H_AbstractBeamLine(beam_length);
|
---|
66 | vector<H_OpticalElement*>::const_iterator element_i;
|
---|
67 | for (element_i = elements.begin(); element_i<elements.end(); element_i++) {
|
---|
68 | if((*element_i)->getType()!=DRIFT) {
|
---|
69 | H_OpticalElement* temp_el = (*element_i)->clone();
|
---|
70 | temp_beam->add(temp_el);
|
---|
71 | }
|
---|
72 | }
|
---|
73 | temp_beam->beam_mat = beam_mat;
|
---|
74 | temp_beam->matrices = matrices;
|
---|
75 | return temp_beam;
|
---|
76 | }
|
---|
77 |
|
---|
78 | H_AbstractBeamLine::~H_AbstractBeamLine() {
|
---|
79 | vector<H_OpticalElement*>::iterator element_i;
|
---|
80 | for (element_i = elements.begin(); element_i<elements.end(); element_i++) {
|
---|
81 | delete (*element_i);
|
---|
82 | }
|
---|
83 | elements.clear();
|
---|
84 | matrices.clear();
|
---|
85 | }
|
---|
86 |
|
---|
87 | void H_AbstractBeamLine::add(H_OpticalElement * newElement) {
|
---|
88 | /// @param newElement is added to the beamline
|
---|
89 | // H_OpticalElement * el = new H_OpticalElement(*newElement);
|
---|
90 | // H_OpticalElement * el = const_cast<H_OpticalElement*> newElement;
|
---|
91 | // H_OpticalElement * el = newElement;
|
---|
92 | elements.push_back(newElement);
|
---|
93 | float a = newElement->getS()+newElement->getLength();
|
---|
94 | if (a > beam_length) {
|
---|
95 | beam_length = a;
|
---|
96 | if(VERBOSE) cout<<"<H_AbstractBeamLine> WARNING : element ("<< newElement->getName()<<") too far away. The beam length has been extended to "<< beam_length << ". "<<endl;
|
---|
97 | }
|
---|
98 | calcSequence();
|
---|
99 | calcMatrix();
|
---|
100 | return;
|
---|
101 | }
|
---|
102 |
|
---|
103 | void H_AbstractBeamLine::add(H_OpticalElement & newElement) {
|
---|
104 | /// @param newElement is added to the beamline
|
---|
105 | // H_OpticalElement * el = new H_OpticalElement(newElement);
|
---|
106 | // elements.push_back(el);
|
---|
107 | elements.push_back(&newElement);
|
---|
108 | float a = newElement.getS()+newElement.getLength();
|
---|
109 | if (a > beam_length) {
|
---|
110 | beam_length = a;
|
---|
111 | if(VERBOSE) cout<<"<H_AbstractBeamLine> WARNING : element ("<< newElement.getName()<<") too far away. The beam length has been extended to "<< beam_length << ". "<<endl;
|
---|
112 | }
|
---|
113 | calcSequence();
|
---|
114 | calcMatrix();
|
---|
115 | }
|
---|
116 |
|
---|
117 | const TMatrix H_AbstractBeamLine::getBeamMatrix() const {
|
---|
118 | return beam_mat;
|
---|
119 | }
|
---|
120 |
|
---|
121 | const TMatrix H_AbstractBeamLine::getBeamMatrix(const float eloss,const float p_mass, const float p_charge) {
|
---|
122 |
|
---|
123 | vector<H_OpticalElement*>::iterator element_i;
|
---|
124 | TMatrix calc_mat(MDIM,MDIM);
|
---|
125 |
|
---|
126 | // initialization
|
---|
127 | calc_mat.UnitMatrix();
|
---|
128 |
|
---|
129 | // multiplies the matrix of each beam's element
|
---|
130 | // and add each product matrix to the list of matrices.
|
---|
131 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
132 | calc_mat *= (*element_i)->getMatrix(eloss,p_mass,p_charge);
|
---|
133 | }
|
---|
134 | return calc_mat;
|
---|
135 | }
|
---|
136 |
|
---|
137 | const TMatrix H_AbstractBeamLine::getPartialMatrix(const string& elname, const float eloss, const float p_mass, const float p_charge) {
|
---|
138 |
|
---|
139 | vector<H_OpticalElement*>::iterator element_i;
|
---|
140 | TMatrix calc_mat(MDIM,MDIM);
|
---|
141 |
|
---|
142 | calc_mat.UnitMatrix();
|
---|
143 |
|
---|
144 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
145 | calc_mat *= (*element_i)->getMatrix(eloss,p_mass,p_charge);
|
---|
146 | if(elname==(*element_i)->getName()) {
|
---|
147 | return calc_mat;
|
---|
148 | }
|
---|
149 | }
|
---|
150 | cout<<"<H_AbstractBeamLine> Element "<<elname<<" desn't exist. Returning full beam matrix"<<endl;
|
---|
151 | return calc_mat;
|
---|
152 | }
|
---|
153 |
|
---|
154 | const TMatrix H_AbstractBeamLine::getPartialMatrix(const unsigned int element_position) const {
|
---|
155 | //const int N = (element_position<0)?0:(( (element_position)>elements.size()-1)?elements.size()-1:element_position);
|
---|
156 | const int N = (element_position>elements.size()-1)?elements.size()-1:element_position;
|
---|
157 | return *(matrices.begin()+N); // //for optimization of the code :same as return &matrices[N];
|
---|
158 | }
|
---|
159 |
|
---|
160 | const TMatrix H_AbstractBeamLine::getPartialMatrix(const H_OpticalElement * element) const{
|
---|
161 | // returns the transport matrix to transport until the end of the specified element
|
---|
162 | // !!! 2 elements should never have the same name in "elements" !!!
|
---|
163 |
|
---|
164 | vector<H_OpticalElement*>::const_iterator element_i;
|
---|
165 | vector<TMatrix>::const_iterator matrix_i;
|
---|
166 | TMatrix calc_mat(MDIM,MDIM);
|
---|
167 |
|
---|
168 | // parses the list of optical elements and find the searched one
|
---|
169 | for(element_i = elements.begin(),matrix_i = matrices.begin(); element_i < elements.end(); element_i++, matrix_i++) {
|
---|
170 | if(element->getName() == (*element_i)->getName()) {
|
---|
171 | // element has been found
|
---|
172 | calc_mat = *matrix_i;
|
---|
173 | }
|
---|
174 | }
|
---|
175 | return calc_mat;
|
---|
176 | }
|
---|
177 |
|
---|
178 | H_OpticalElement * H_AbstractBeamLine::getElement(const unsigned int element_position) {
|
---|
179 | const unsigned int N = (element_position>elements.size())?elements.size():element_position;
|
---|
180 | return *(elements.begin()+N);//for optimization of the code :same as return &elements[N];
|
---|
181 | }
|
---|
182 |
|
---|
183 | H_OpticalElement * H_AbstractBeamLine::getElement(const unsigned int element_position) const {
|
---|
184 | const unsigned int N = (element_position>elements.size())?elements.size():element_position;
|
---|
185 | return *(elements.begin()+N);//for optimization of the code :same as return &elements[N];
|
---|
186 | }
|
---|
187 |
|
---|
188 |
|
---|
189 | H_OpticalElement * H_AbstractBeamLine::getElement(const string& el_name) {
|
---|
190 | for(unsigned int i=0; i < elements.size(); i++) {
|
---|
191 | if( (*(elements.begin()+i))->getName() == el_name )
|
---|
192 | return *(elements.begin()+i);
|
---|
193 | } // if found -> return ; else : not found at all !
|
---|
194 | cout<<"<H_AbstractBeamLine> Element "<<el_name<<" not found"<<endl;
|
---|
195 | return *(elements.begin()+1);
|
---|
196 | }
|
---|
197 |
|
---|
198 | H_OpticalElement * H_AbstractBeamLine::getElement(const string& el_name) const {
|
---|
199 | for(unsigned int i=0; i < elements.size(); i++) {
|
---|
200 | if( (*(elements.begin()+i))->getName() == el_name)
|
---|
201 | return *(elements.begin()+i);
|
---|
202 | } // if found -> return ; else : not found at all !
|
---|
203 | cout<<"<H_AbstractBeamLine> Element "<<el_name<<" not found"<<endl;
|
---|
204 | return *(elements.begin()+1);
|
---|
205 | }
|
---|
206 |
|
---|
207 | void H_AbstractBeamLine::printProperties() const {
|
---|
208 | vector<H_OpticalElement*>::const_iterator element_i;
|
---|
209 | cout << "Pointeurs des elements du faisceau" << endl;
|
---|
210 | for (element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
211 | cout << (int)(element_i-elements.begin()) << "\t" << (*element_i)->getName() << "\t" << (*element_i)->getS() << endl;
|
---|
212 | }
|
---|
213 | return;
|
---|
214 | }
|
---|
215 |
|
---|
216 | void H_AbstractBeamLine::showElements() const{
|
---|
217 | vector<H_OpticalElement*>::const_iterator element_i;
|
---|
218 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
219 | (*element_i)->printProperties();
|
---|
220 | }
|
---|
221 | cout << "Beam length = " << beam_length << endl;
|
---|
222 | cout << "Number of elements (including drifts) = " << getNumberOfElements() << endl;
|
---|
223 | return;
|
---|
224 | }
|
---|
225 |
|
---|
226 | void H_AbstractBeamLine::showElements(const int type_el) const{
|
---|
227 | vector<H_OpticalElement*>::const_iterator element_i;
|
---|
228 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
229 | if ((*element_i)->getType()==type_el)
|
---|
230 | (*element_i)->printProperties();
|
---|
231 | }
|
---|
232 | return;
|
---|
233 | }
|
---|
234 |
|
---|
235 | void H_AbstractBeamLine::showMatrix() const {
|
---|
236 | cout << "Transport matrix for the whole beam : " << endl;
|
---|
237 | cout << "(x,x',...) = (x*,x'*,...) M " <<endl;
|
---|
238 | printMatrix(beam_mat);
|
---|
239 | return;
|
---|
240 | }
|
---|
241 |
|
---|
242 | void H_AbstractBeamLine::showMatrices() const{
|
---|
243 | // prints the list of all transport matrices, from the whole beam.
|
---|
244 |
|
---|
245 | vector<TMatrix>::const_iterator matrix_i;
|
---|
246 | vector<H_OpticalElement*>::const_iterator element_i;
|
---|
247 | TMatrix temp(MDIM,MDIM);
|
---|
248 |
|
---|
249 | for(matrix_i = matrices.begin(), element_i = elements.begin(); matrix_i < matrices.end(); matrix_i++, element_i++) {
|
---|
250 | temp = *matrix_i;
|
---|
251 | cout << "Matrix for transport until s=" << (*element_i)->getS() + (*element_i)->getLength() << "m (" << (*element_i)->getName() << "). " << endl;
|
---|
252 | printMatrix(temp);
|
---|
253 | cout << endl;
|
---|
254 | }
|
---|
255 | return ;
|
---|
256 | }
|
---|
257 |
|
---|
258 | void H_AbstractBeamLine::calcSequence() {
|
---|
259 | // reorders the elements, computes the drifts;
|
---|
260 |
|
---|
261 | vector<H_OpticalElement*> temp_elements;
|
---|
262 | vector<H_OpticalElement*>::iterator element_i;
|
---|
263 | // element_i is a pointer to elements[i]
|
---|
264 |
|
---|
265 | if(elements.size()==1) { return; }
|
---|
266 |
|
---|
267 | // getting rid of drifts before calculating
|
---|
268 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
269 | if((*element_i)->getType() == DRIFT) {delete (*element_i); elements.erase(element_i); }
|
---|
270 | }
|
---|
271 |
|
---|
272 | // ordering the elements in position
|
---|
273 | sort(elements.begin(),elements.end(),ordering());
|
---|
274 | // inserting the drifts before the other elements
|
---|
275 | float current_pos = 0;
|
---|
276 | float drift_length=0;
|
---|
277 |
|
---|
278 | for(element_i=elements.begin(); element_i < elements.end(); element_i++) {
|
---|
279 | drift_length = (*element_i)->getS() - current_pos;
|
---|
280 | if(drift_length>0) {
|
---|
281 | H_Drift *dr = new H_Drift(current_pos,drift_length);
|
---|
282 | temp_elements.push_back(dr);
|
---|
283 | }
|
---|
284 | temp_elements.push_back(*element_i);
|
---|
285 | current_pos = (*element_i)->getS() + (*element_i)->getLength();
|
---|
286 | }
|
---|
287 |
|
---|
288 | //adding the last drift
|
---|
289 | drift_length = beam_length - current_pos;
|
---|
290 | if (drift_length>0) {
|
---|
291 | H_Drift *dr = new H_Drift(current_pos,drift_length);
|
---|
292 | temp_elements.push_back(dr);
|
---|
293 | }
|
---|
294 |
|
---|
295 | // cleaning : avoid some memory leaks
|
---|
296 | elements.clear();
|
---|
297 |
|
---|
298 | for(element_i=temp_elements.begin(); element_i < temp_elements.end(); element_i++) {
|
---|
299 | elements.push_back(*element_i);
|
---|
300 | }
|
---|
301 | }
|
---|
302 |
|
---|
303 | void H_AbstractBeamLine::calcMatrix() {
|
---|
304 | // computes the transport matrix for the beam upto here...
|
---|
305 | vector<H_OpticalElement*>::iterator element_i;
|
---|
306 | TMatrix calc_mat(MDIM,MDIM);
|
---|
307 |
|
---|
308 | // initialization
|
---|
309 | matrices.clear();
|
---|
310 | calc_mat.UnitMatrix();
|
---|
311 |
|
---|
312 | // multiplies the matrix of each beam's element
|
---|
313 | // and add each product matrix to the list of matrices.
|
---|
314 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
315 | calc_mat *= (*element_i)->getMatrix();
|
---|
316 | matrices.push_back(calc_mat);
|
---|
317 | }
|
---|
318 |
|
---|
319 | beam_mat.ResizeTo(MDIM,MDIM);
|
---|
320 | beam_mat = calc_mat;
|
---|
321 | return;
|
---|
322 | }
|
---|
323 |
|
---|
324 | float qh(float k) {
|
---|
325 | float beta = (log((float)10.0))/0.05;
|
---|
326 | // put (std::log((float)10.0)) instead of log(10) to avoid compilation errors
|
---|
327 | return 0.8*(1-exp(-beta*fabs(k)));
|
---|
328 | }
|
---|
329 |
|
---|
330 | float dh(float k) {
|
---|
331 | float psi = (log((float)10.0))/0.002;
|
---|
332 | // put (std::log((float)10.0)) instead of log(10) to avoid compilation errors
|
---|
333 | return 0.8*(1-exp(-psi*fabs(k)));
|
---|
334 | }
|
---|
335 |
|
---|
336 | void H_AbstractBeamLine::draw(const float xmin, const float ymin, const float xmax, const float ymax) const{
|
---|
337 | gROOT->SetStyle("Plain");
|
---|
338 | TLegend* leg = new TLegend(xmin,ymin,xmax,ymax,"");
|
---|
339 | leg->SetBorderSize(1);
|
---|
340 | leg->SetFillColor(kWhite);
|
---|
341 | TBox* b1 = new TBox();
|
---|
342 | TBox* b2 = new TBox(0,0,10,10);
|
---|
343 | TBox* b3 = new TBox(0,0,0,0);
|
---|
344 | TBox* b4 = new TBox(0,0,0,0);
|
---|
345 | TBox* b5 = new TBox(0,0,0,0);
|
---|
346 | TBox* b6 = new TBox(0,0,0,0);
|
---|
347 | TBox* b7 = new TBox(0,0,0,0);
|
---|
348 | b1->SetFillColor(RDIPOLE);
|
---|
349 | b2->SetFillColor(SDIPOLE);
|
---|
350 | b3->SetFillColor(VQUADRUPOLE);
|
---|
351 | b4->SetFillColor(HQUADRUPOLE);
|
---|
352 | b5->SetFillColor(HKICKER);
|
---|
353 | b6->SetFillColor(VKICKER);
|
---|
354 | b7->SetFillColor(RCOLLIMATOR);
|
---|
355 | leg->AddEntry(b1,"R-Dipole");
|
---|
356 | leg->AddEntry(b2,"S-Dipole");
|
---|
357 | leg->AddEntry(b3,"V-Quadrupole");
|
---|
358 | leg->AddEntry(b4,"H-Quadrupole");
|
---|
359 | leg->AddEntry(b5,HKICKERNAME);
|
---|
360 | leg->AddEntry(b6,VKICKERNAME);
|
---|
361 | leg->AddEntry(b7,"RCollimator");
|
---|
362 | leg->Draw();
|
---|
363 | /* TLine* l1 = new TLine(0.05,0.5,0.95,0.5);
|
---|
364 | TLine* l2 = new TLine(0.1,0.1,0.1,0.9);
|
---|
365 | TLine* l3 = new TLine(0.9,0.1,0.9,0.9);
|
---|
366 | TPaveLabel* p1 = new TPaveLabel(0.05,0.5,0.1,0.6,"IP");
|
---|
367 | TPaveLabel* p2 = new TPaveLabel(0.9,0.5,0.95,0.6,"RP");
|
---|
368 | TGaxis* a1 = new TGaxis(0.1,0.1,0.9,0.1,0,beam_length);
|
---|
369 | a1->SetLabelSize(0.08);
|
---|
370 | p1->SetBorderSize(1);
|
---|
371 | p2->SetBorderSize(1);
|
---|
372 | p1->SetFillColor(0);
|
---|
373 | p2->SetFillColor(0);
|
---|
374 | l1->Draw();
|
---|
375 | l2->Draw();
|
---|
376 | l3->Draw();
|
---|
377 | p1->Draw();
|
---|
378 | p2->Draw();
|
---|
379 | float x1,x2,y1,y2;
|
---|
380 | vector<TPaveLabel*> boxes;
|
---|
381 | vector<H_OpticalElement*>::const_iterator element_i;
|
---|
382 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
383 | x1 = 0.1 + ((*element_i)->getS()/beam_length)*0.8;
|
---|
384 | x2 = x1 + ((*element_i)->getLength()/beam_length)*0.8;
|
---|
385 | if((*element_i)->getType()>5) {
|
---|
386 | y1 = 0.3;
|
---|
387 | y2 = 0.7;
|
---|
388 | }
|
---|
389 | else if((*element_i)->getType()>3) {
|
---|
390 | y1 = 0.5 - qh((*element_i)->getK()*(*element_i)->getLength())/2.;
|
---|
391 | y2 = 0.5 + qh((*element_i)->getK()*(*element_i)->getLength())/2.;
|
---|
392 | } else {
|
---|
393 | y1 = 0.5 - dh((*element_i)->getK()*(*element_i)->getLength())/2.;
|
---|
394 | y2 = 0.5 + dh((*element_i)->getK()*(*element_i)->getLength())/2.;
|
---|
395 | }
|
---|
396 | TPaveLabel* cur_box = new TPaveLabel(x1,y1,x2,y2,"");
|
---|
397 | cur_box->SetFillStyle(1);
|
---|
398 | cur_box->SetFillColor(((int)(*element_i)->getType()));
|
---|
399 | cur_box->SetBorderSize(1);
|
---|
400 | if((*element_i)->getType()!=DRIFT) boxes.push_back(cur_box);
|
---|
401 | }
|
---|
402 | vector<TPaveLabel*>::iterator box_i;
|
---|
403 | for(box_i = boxes.begin(); box_i < boxes.end(); box_i++) {
|
---|
404 | (*box_i)->Draw();
|
---|
405 | }
|
---|
406 | a1->Draw();
|
---|
407 | */
|
---|
408 | return;
|
---|
409 | }
|
---|
410 |
|
---|
411 | void H_AbstractBeamLine::drawX(const float a_min, const float a_max, const float scale) const{
|
---|
412 | /// @param a_min defines the size of the drawing
|
---|
413 | /// @param a_max defines the size of the drawing
|
---|
414 | /// @param scale allows to multiply the drawing, i.e. changing the units
|
---|
415 | const int N = getNumberOfElements();
|
---|
416 | for(int i=0;i<N;i++) {
|
---|
417 | float height = fabs(a_max);
|
---|
418 | float meight = fabs(a_min);
|
---|
419 | float size = (height>meight)?meight:height;
|
---|
420 | float middle = getElement(i)->getX()*URAD*scale;
|
---|
421 | if(getElement(i)->getType()!=DRIFT) getElement(i)->draw(middle+size/2.,middle-size/2.);
|
---|
422 | }
|
---|
423 | }
|
---|
424 |
|
---|
425 | void H_AbstractBeamLine::drawY(const float a_min, const float a_max) const{
|
---|
426 | /// @param a_min defines the size of the drawing
|
---|
427 | /// @param a_max defines the size of the drawing
|
---|
428 | const int N = getNumberOfElements();
|
---|
429 | for(int i=0;i<N;i++) {
|
---|
430 | float height = fabs(a_max);
|
---|
431 | float meight = fabs(a_min);
|
---|
432 | float size = (height>meight)?meight:height;
|
---|
433 | float middle = getElement(i)->getY()*URAD;
|
---|
434 | if(getElement(i)->getType()!=DRIFT) getElement(i)->draw(middle+size/2.,middle-size/2.);
|
---|
435 | }
|
---|
436 | }
|
---|
437 |
|
---|
438 | void H_AbstractBeamLine::moveElement(const string& name, const float new_s) {
|
---|
439 | /// @param name identifies the element to move
|
---|
440 | /// @param new_s is where to put it
|
---|
441 | vector<H_OpticalElement*>::iterator element_i;
|
---|
442 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
443 | if(name==(*element_i)->getName()) { (*element_i)->setS(new_s); }
|
---|
444 | }
|
---|
445 |
|
---|
446 | calcSequence();
|
---|
447 | calcMatrix();
|
---|
448 | return;
|
---|
449 | }
|
---|
450 |
|
---|
451 | void H_AbstractBeamLine::alignElement(const string& name, const float disp_x, const float disp_y) {
|
---|
452 | /// @param name identifies the element to move
|
---|
453 | /// @param disp_x identifies the displacement to add in x [\f$ \mu m \f$]
|
---|
454 | /// @param disp_y identifies the displacement to add in y [\f$ \mu m \f$]
|
---|
455 | vector<H_OpticalElement*>::iterator element_i;
|
---|
456 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
457 | if(name==(*element_i)->getName()) {
|
---|
458 | (*element_i)->setX((*element_i)->getX()+disp_x);
|
---|
459 | (*element_i)->setY((*element_i)->getY()+disp_y);
|
---|
460 | return ;
|
---|
461 | }
|
---|
462 | }
|
---|
463 | cout<<"<H_AbstractBeamLine> WARNING : Element "<<name<<" not found."<<endl;
|
---|
464 | return;
|
---|
465 | }
|
---|
466 |
|
---|
467 | void H_AbstractBeamLine::tiltElement(const string& name, const float ang_x, const float ang_y) {
|
---|
468 | /// @param name identifies the element to move
|
---|
469 | /// @param ang_x identifies the angle to add in x
|
---|
470 | /// @param ang_y identifies the angle to add in y
|
---|
471 | vector<H_OpticalElement*>::iterator element_i;
|
---|
472 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
473 | if(name==(*element_i)->getName()) {
|
---|
474 | (*element_i)->setTX((*element_i)->getTX()+ang_x);
|
---|
475 | (*element_i)->setTY((*element_i)->getTY()+ang_y);
|
---|
476 | return ;
|
---|
477 | }
|
---|
478 | }
|
---|
479 | cout<<"<H_AbstractBeamLine> WARNING : Element "<<name<<" not found."<<endl;
|
---|
480 | return;
|
---|
481 | }
|
---|
482 |
|
---|
483 | void H_AbstractBeamLine::offsetElements(const float start, const float offset) {
|
---|
484 | /// @param start After this s [m] coordinate, all elements will be offset.
|
---|
485 | /// @param offset In meters
|
---|
486 |
|
---|
487 | extern bool relative_energy;
|
---|
488 | if(!relative_energy) {
|
---|
489 | vector<H_OpticalElement*>::iterator element_i;
|
---|
490 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
491 | if((*element_i)->getS() > start ) {
|
---|
492 | (*element_i)->setX(offset);
|
---|
493 | }
|
---|
494 | }
|
---|
495 | }
|
---|
496 | }
|
---|
497 |
|
---|
498 | TGraph * H_AbstractBeamLine::getBetaX() const{
|
---|
499 | const int N = elements.size();
|
---|
500 | float * s = new float[N], * b = new float[N], temp;
|
---|
501 | int i=0, n=N;
|
---|
502 |
|
---|
503 | vector<H_OpticalElement*>::const_iterator element_i;
|
---|
504 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
505 | temp=(*element_i)->getBetaX();
|
---|
506 | if (temp !=0) {
|
---|
507 | b[i] = (*element_i)->getBetaX();
|
---|
508 | s[i] = (*element_i)->getS();
|
---|
509 | i++;
|
---|
510 | n=i;
|
---|
511 | }
|
---|
512 | }
|
---|
513 |
|
---|
514 | TGraph * betax = new TGraph(n,s,b);
|
---|
515 | betax->SetLineColor(1);
|
---|
516 | betax->SetLineStyle(2);
|
---|
517 | delete [] s;
|
---|
518 | delete [] b;
|
---|
519 | return betax;
|
---|
520 | }
|
---|
521 |
|
---|
522 | TGraph * H_AbstractBeamLine::getBetaY() const{
|
---|
523 | const int N = elements.size();
|
---|
524 | float * s = new float[N], * b = new float[N], temp;
|
---|
525 | int i=0, n=N;
|
---|
526 |
|
---|
527 | vector<H_OpticalElement*>::const_iterator element_i;
|
---|
528 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
529 | temp=(*element_i)->getBetaY();
|
---|
530 | if (temp !=0) {
|
---|
531 | b[i] = (*element_i)->getBetaY();
|
---|
532 | s[i] = (*element_i)->getS();
|
---|
533 | i++;
|
---|
534 | n=i;
|
---|
535 | }
|
---|
536 | }
|
---|
537 |
|
---|
538 | TGraph * betay = new TGraph(n,s,b);
|
---|
539 | betay->SetLineColor(2);
|
---|
540 | betay->SetLineStyle(2);
|
---|
541 | delete [] s;
|
---|
542 | delete [] b;
|
---|
543 | return betay;
|
---|
544 | }
|
---|
545 |
|
---|
546 | TGraph * H_AbstractBeamLine::getDX() const{
|
---|
547 | const int N = elements.size();
|
---|
548 | float * s = new float[N], * d = new float[N], temp;
|
---|
549 | int i=0, n=N;
|
---|
550 |
|
---|
551 | vector<H_OpticalElement*>::const_iterator element_i;
|
---|
552 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
553 | temp=(*element_i)->getDX();
|
---|
554 | if (temp !=0) {
|
---|
555 | d[i] = (*element_i)->getDX();
|
---|
556 | s[i] = (*element_i)->getS();
|
---|
557 | i++;
|
---|
558 | n=i;
|
---|
559 | }
|
---|
560 | }
|
---|
561 |
|
---|
562 | TGraph * dispx = new TGraph(n,s,d);
|
---|
563 | dispx->SetLineColor(8);
|
---|
564 | dispx->SetLineStyle(2);
|
---|
565 | delete [] s;
|
---|
566 | delete [] d;
|
---|
567 | return dispx;
|
---|
568 | }
|
---|
569 |
|
---|
570 | TGraph * H_AbstractBeamLine::getDY() const{
|
---|
571 | const int N = elements.size();
|
---|
572 | float * s = new float[N], * d = new float[N], temp;
|
---|
573 | int i=0, n=N;
|
---|
574 |
|
---|
575 | vector<H_OpticalElement*>::const_iterator element_i;
|
---|
576 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
577 | temp=(*element_i)->getDY();
|
---|
578 | if (temp !=0) {
|
---|
579 | d[i] = (*element_i)->getDY();
|
---|
580 | s[i] = (*element_i)->getS();
|
---|
581 | i++;
|
---|
582 | n=i;
|
---|
583 | }
|
---|
584 | }
|
---|
585 |
|
---|
586 | TGraph * dispy = new TGraph(n,s,d);
|
---|
587 | dispy->SetLineColor(kBlue);
|
---|
588 | dispy->SetLineStyle(2);
|
---|
589 | delete [] s;
|
---|
590 | delete [] d;
|
---|
591 | return dispy;
|
---|
592 | }
|
---|
593 |
|
---|
594 |
|
---|
595 | TGraph * H_AbstractBeamLine::getRelX() const{
|
---|
596 | const int N = elements.size();
|
---|
597 | float * s = new float[N], * r = new float[N], temp;
|
---|
598 | int i=0, n=N;
|
---|
599 |
|
---|
600 | vector<H_OpticalElement*>::const_iterator element_i;
|
---|
601 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
602 | temp=(*element_i)->getRelX();
|
---|
603 | if((*element_i)->getType() != DRIFT) {
|
---|
604 | r[i] = (*element_i)->getRelX();
|
---|
605 | s[i] = (*element_i)->getS();
|
---|
606 | i++;
|
---|
607 | n=i;
|
---|
608 | }
|
---|
609 | }
|
---|
610 |
|
---|
611 | TGraph * relx = new TGraph(n,s,r);
|
---|
612 | relx->SetLineColor(kBlack);
|
---|
613 | relx->SetMarkerStyle(kOpenSquare);
|
---|
614 | relx->SetMarkerSize(0.6);
|
---|
615 | relx->SetLineStyle(2);
|
---|
616 | delete [] s;
|
---|
617 | delete [] r;
|
---|
618 | return relx;
|
---|
619 | }
|
---|
620 |
|
---|
621 | TGraph * H_AbstractBeamLine::getRelY() const{
|
---|
622 | const int N = elements.size();
|
---|
623 | float * s = new float[N], * r = new float[N], temp;
|
---|
624 | int i=0, n=N;
|
---|
625 |
|
---|
626 | vector<H_OpticalElement*>::const_iterator element_i;
|
---|
627 | for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
|
---|
628 | temp=(*element_i)->getRelY();
|
---|
629 | if((*element_i)->getType() != DRIFT) {
|
---|
630 | r[i] = (*element_i)->getRelY();
|
---|
631 | s[i] = (*element_i)->getS();
|
---|
632 | i++;
|
---|
633 | n=i;
|
---|
634 | }
|
---|
635 | }
|
---|
636 |
|
---|
637 | TGraph * rely = new TGraph(n,s,r);
|
---|
638 | rely->SetLineColor(kRed);
|
---|
639 | rely->SetMarkerStyle(kOpenSquare);
|
---|
640 | rely->SetMarkerSize(0.6);
|
---|
641 | rely->SetLineStyle(2);
|
---|
642 | delete [] s;
|
---|
643 | delete [] r;
|
---|
644 | return rely;
|
---|
645 | }
|
---|
646 |
|
---|