Changeset 1365 in svn for trunk/external/Hector/H_BeamLine.cc
- Timestamp:
- Apr 16, 2014, 3:56:14 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/external/Hector/H_BeamLine.cc
r1360 r1365 1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 * * 3 * --<--<-- A fast simulator --<--<-- * 4 * / --<--<-- of particle --<--<-- * 5 * ----HECTOR----< * 6 * \ -->-->-- transport through -->-->-- * 7 * -->-->-- generic beamlines -->-->-- * 8 * * 9 * JINST 2:P09005 (2007) * 10 * X Rouby, J de Favereau, K Piotrzkowski (CP3) * 11 * http://www.fynu.ucl.ac.be/hector.html * 12 * * 13 * Center for Cosmology, Particle Physics and Phenomenology * 14 * Universite catholique de Louvain * 15 * Louvain-la-Neuve, Belgium * 16 * * 17 * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 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 */ 18 11 19 12 /// \file H_BeamLine.cc … … 24 17 #include <fstream> 25 18 #include <sstream> 26 #include <cstdlib>27 19 28 20 // local #includes … … 47 39 // are opposite to Wille's. See fill() for more details. 48 40 49 H_BeamLine::H_BeamLine(): H_AbstractBeamLine(), 50 direction(1), ips(0), ipx(0), ipy(0), iptx(0), ipty(0) { 51 } 52 53 H_BeamLine::H_BeamLine(const int si, const float length) : H_AbstractBeamLine(length), 54 direction((si >= abs(si)) ? 1 : -1), ips(0), ipx(0), ipy(0), iptx(0), ipty(0) { 55 } 56 57 H_BeamLine::H_BeamLine(const H_BeamLine& beam) : H_AbstractBeamLine(beam), 58 direction(beam.direction), ips(beam.ips), ipx(beam.ipx), ipy(beam.ipy), iptx(beam.iptx), ipty(beam.ipty) { 59 } 60 61 H_BeamLine& H_BeamLine::operator=(const H_BeamLine& beam) { 62 if(this==&beam) return *this; 63 H_AbstractBeamLine::operator=(beam); // call the mother's operator= 41 H_BeamLine::H_BeamLine(const int si, const float length) : H_AbstractBeamLine(length){ 42 direction = (si >= abs(si)) ? 1 : -1; 43 ips=0; 44 ipx=0; 45 ipy=0; 46 iptx=0; 47 ipty=0; 48 } 49 50 H_BeamLine::H_BeamLine(const H_BeamLine& beam) : H_AbstractBeamLine(beam) { 64 51 direction = beam.direction; 65 52 ips = beam.ips; … … 68 55 iptx = beam.iptx; 69 56 ipty = beam.ipty; 57 } 58 59 H_BeamLine& H_BeamLine::operator=(const H_BeamLine& beam) { 60 if(this==&beam) return *this; 61 direction = beam.direction; 62 ips = beam.ips; 63 ipx = beam.ipx; 64 ipy = beam.ipy; 65 iptx = beam.iptx; 66 ipty = beam.ipty; 70 67 return *this; 71 68 } 72 69 73 void H_BeamLine::findIP(const string& filename, const string& ipname) { 70 void H_BeamLine::findIP(const string filename) { 71 findIP(filename,"IP5"); 72 return; 73 } 74 75 void H_BeamLine::findIP(const string filename, const string ipname) { 74 76 // searches for the IP position in the extended table. 75 77 ifstream tabfile(filename.c_str()); 76 if (! tabfile.is_open()) cout << " <H_BeamLine>ERROR: I Can't open \"" << filename << "\"" << endl;78 if (! tabfile.is_open()) cout << "\t ERROR: I Can't open \"" << filename << "\"" << endl; 77 79 bool found = false; 78 80 int N_col=0; … … 112 114 } // while (!eof) 113 115 114 if (!found) cout << " <H_BeamLine>ERROR ! IP not found." << endl;116 if (!found) cout << "\t ERROR ! IP not found." << endl; 115 117 tabfile.close(); 116 118 } … … 125 127 } 126 128 127 128 void H_BeamLine::fill(const string& filename, const int dir, const string& ipname) { 129 void H_BeamLine::fill(const string filename) { 130 fill(filename,1,"IP5"); 131 return; 132 } 133 134 135 void H_BeamLine::fill(const string filename, const int dir, const string ipname) { 129 136 string headers[40]; // table of all column headers 130 137 int header_type[40]; // table of all column types 131 138 findIP(filename,ipname); 132 139 ifstream tabfile(filename.c_str()); 133 if (! tabfile.is_open()) cout << " <H_BeamLine>ERROR: I Can't open \"" << filename << "\"" << endl;140 if (! tabfile.is_open()) cout << "\t ERROR: I Can't open \"" << filename << "\"" << endl; 134 141 if(VERBOSE) { 135 142 cout<<"Using file : "<< filename <<" in the "<<((direction>0)?"positive":"negative")<<" direction."<<endl; … … 187 194 } 188 195 196 ap = 0; //init 197 if(e.aper_1 !=0 || e.aper_2 !=0 || e.aper_3 !=0 || e.aper_4 != 0) { 198 e.aper_1 *= URAD; 199 e.aper_2 *= URAD; 200 e.aper_3 *= URAD; 201 e.aper_4 *= URAD; // in [m] in the tables ! 202 203 if(strstr(e.apertype.c_str(),"RECTELLIPSE")) ap = new H_RectEllipticAperture(e.aper_1,e.aper_2,e.aper_3,e.aper_4,0,0); 204 else if(strstr(e.apertype.c_str(),"CIRCLE")) ap = new H_CircularAperture(e.aper_1,0,0); 205 else if(strstr(e.apertype.c_str(),"RECTANGLE")) ap = new H_RectangularAperture(e.aper_1,e.aper_2,0,0); 206 else if(strstr(e.apertype.c_str(),"ELLIPSE")) ap = new H_EllipticAperture(e.aper_1,e.aper_2,0,0); 207 } 208 189 209 if(el!=0) { 190 ap = 0; //init 191 if(e.aper_1 !=0 || e.aper_2 !=0 || e.aper_3 !=0 || e.aper_4 != 0) { 192 e.aper_1 *= URAD; 193 e.aper_2 *= URAD; 194 e.aper_3 *= URAD; 195 e.aper_4 *= URAD; // in [m] in the tables ! 196 197 if(strstr(e.apertype.c_str(),"RECTELLIPSE")) 198 ap = new H_RectEllipticAperture(e.aper_1,e.aper_2,e.aper_3,e.aper_4,0,0); 199 else if(strstr(e.apertype.c_str(),"CIRCLE")) 200 ap = new H_CircularAperture(e.aper_1,0,0); 201 else if(strstr(e.apertype.c_str(),"RECTANGLE")) 202 ap = new H_RectangularAperture(e.aper_1,e.aper_2,0,0); 203 else if(strstr(e.apertype.c_str(),"ELLIPSE")) 204 ap = new H_EllipticAperture(e.aper_1,e.aper_2,0,0); 210 if (direction<0) { 211 el->setBetaX(e.betx); 212 el->setBetaY(e.bety); 213 el->setDX(e.dx); 214 el->setDY(e.dy); 215 el->setRelX(e.x); 216 el->setRelY(e.y); 217 } else { 218 el->setBetaX(previous_betax); 219 el->setBetaY(previous_betay); 220 el->setDX(previous_dx); 221 el->setDY(previous_dy); 222 el->setRelX(previous_x); 223 el->setRelY(previous_y); 224 } 225 if(ap!=0) { 226 el->setAperture(ap); 227 // delete ap; // ap deleted in H_AbstractBeamLine::~H_AbstractBeamLine 205 228 } 206 229 207 if (direction<0) { 208 el->setBetaX(e.betx); el->setBetaY(e.bety); 209 el->setDX(e.dx); el->setDY(e.dy); 210 el->setRelX(e.x); el->setRelY(e.y); 211 } else { 212 el->setBetaX(previous_betax); el->setBetaY(previous_betay); 213 el->setDX(previous_dx); el->setDY(previous_dy); 214 el->setRelX(previous_x); el->setRelY(previous_y); 215 } 216 if(ap!=0) { 217 el->setAperture(ap); 218 delete ap; 219 // if memory is allocated, i.e. if ap!=0, 220 // it wont be deallocated in H_OpticalElement::~H_OpticalElement 221 // ap should then be deleted here 222 } // memory leak-free! 223 224 /// Parses all the elements from the beginning of the file, 225 /// but only keeps the ones from the IP till the desired length 226 if(e.s>=0 && e.s<beam_length) add(el); 227 else { delete el;} 228 // NB : if "el" is added to the beamline, it will be 229 // deleted by H_AbstractBeamLine::~H_AbstractBeamLine 230 // Otherwise, it should be deleted explicitly 231 230 /// Parses all the elements, but only keeps the ones from the IP till the desired length 231 if(e.s>=0 && e.s<beam_length) add(*el); 232 233 // delete el; // el deleted in H_AbstractBeamLine::~H_AbstractBeamLine 232 234 } // if(el!=0) 233 235 } // if (found)
Note:
See TracChangeset
for help on using the changeset viewer.