[3c40083] | 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 | */
|
---|
[5b822e5] | 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
|
---|
[3c40083] | 20 | //#include "TPaveLabel.h"
|
---|
[5b822e5] | 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
|
---|
[3c40083] | 29 | void H_OpticalElement::init(const string nameE, const int typeE, const double s, const double k, const double l, H_Aperture* the_app) {
|
---|
[5b822e5] | 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;
|
---|
[3c40083] | 42 | element_mat = new TMatrix(MDIM,MDIM);
|
---|
| 43 | setAperture(the_app);
|
---|
[5b822e5] | 44 |
|
---|
[3c40083] | 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; }
|
---|
[5b822e5] | 47 | betax =0;
|
---|
| 48 | betay =0;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
[3c40083] | 51 | H_OpticalElement::H_OpticalElement() {
|
---|
| 52 | H_Aperture* the_app = new H_Aperture();
|
---|
| 53 | init("",DRIFT,0.,0.,0.1,the_app);
|
---|
[5b822e5] | 54 | }
|
---|
| 55 |
|
---|
[3c40083] | 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);
|
---|
[5b822e5] | 59 | }
|
---|
| 60 |
|
---|
[3c40083] | 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);
|
---|
[5b822e5] | 63 | }
|
---|
| 64 |
|
---|
[3c40083] | 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);
|
---|
[5b822e5] | 67 | }
|
---|
| 68 |
|
---|
[3c40083] | 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);
|
---|
[5b822e5] | 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;
|
---|
[3c40083] | 87 | element_mat = new TMatrix(*(el.element_mat));
|
---|
| 88 | element_aperture = new H_Aperture(*(el.element_aperture));
|
---|
[5b822e5] | 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;
|
---|
[3c40083] | 98 | txpos = el.txpos;
|
---|
| 99 | typos = el.typos;
|
---|
[5b822e5] | 100 | betax = el.betax;
|
---|
| 101 | betay = el.betay;
|
---|
| 102 | type = el.type;
|
---|
| 103 | name = el.name;
|
---|
| 104 | typestring = el.typestring;
|
---|
[3c40083] | 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));
|
---|
[5b822e5] | 109 | return *this;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[3c40083] | 112 | void H_OpticalElement::setAperture(H_Aperture * ap) {
|
---|
| 113 | // element_aperture = const_cast<H_Aperture*>(ap);
|
---|
| 114 | element_aperture = ap;
|
---|
[5b822e5] | 115 | return;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[3c40083] | 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;
|
---|
[5b822e5] | 134 | }
|
---|
| 135 |
|
---|
| 136 | void H_OpticalElement::showMatrix() const {
|
---|
[3c40083] | 137 | printMatrix(element_mat);
|
---|
[5b822e5] | 138 | return;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | void H_OpticalElement::drawAperture() const {
|
---|
[3c40083] | 142 | element_aperture->draw();
|
---|
[5b822e5] | 143 | return;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[3c40083] | 146 | TMatrix H_OpticalElement::getMatrix() const {
|
---|
| 147 | return *element_mat;
|
---|
[5b822e5] | 148 | }
|
---|
| 149 |
|
---|
[3c40083] | 150 | TMatrix H_OpticalElement::getMatrix(const float eloss, const float p_mass, const float p_charge) const {
|
---|
[5b822e5] | 151 | setMatrix(eloss,p_mass,p_charge);
|
---|
[3c40083] | 152 | return *element_mat;
|
---|
[5b822e5] | 153 | }
|
---|
| 154 |
|
---|
| 155 | void H_OpticalElement::draw(const float meight, const float height) const{
|
---|
[3c40083] | 156 | /* /// @param meight is the minimal extend of the graph
|
---|
[5b822e5] | 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();
|
---|
[3c40083] | 167 | */
|
---|
[5b822e5] | 168 | }
|
---|
| 169 |
|
---|