Changeset 3c40083 in git for external/Hector/H_RectEllipticAperture.cc
- Timestamp:
- Apr 16, 2014, 3:56:14 PM (11 years ago)
- Branches:
- ImprovedOutputFile, Timing, dual_readout, llp, master
- Children:
- 64a4950
- Parents:
- f6b9fec
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
external/Hector/H_RectEllipticAperture.cc
rf6b9fec r3c40083 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_RectEllipticAperture.cc … … 27 20 28 21 // ROOT #includes 29 #include "TPolyLine.h" 22 //#include "TEllipse.h" 23 //#include "TPave.h" 30 24 31 25 // local #includes … … 33 27 using namespace std; 34 28 35 H_RectEllipticAperture::H_RectEllipticAperture(const float l, const float h, const float L, const float H, const float posx, const float posy) :H_Aperture(RECTELLIPSE,((l==0)?L:l),((h==0)?H:h),L,H,posx,posy) {36 /// @param l, h, L, Hare the geometrical parameters of the rect-ellipse shape29 H_RectEllipticAperture::H_RectEllipticAperture(const float x1, const float x2, const float x3, const float x4, const float posx, const float posy) :H_Aperture(RECTELLIPSE,((x1==0)?x3:x1),((x2==0)?x4:x2),x3,x4,posx,posy) { 30 /// @param x1, x2, x3, x4 are the geometrical parameters of the rect-ellipse shape 37 31 /// @param posx, posy defines the (x,y) of the center of the shape 32 type= RECTELLIPSE; 38 33 } 39 34 40 H_RectEllipticAperture* H_RectEllipticAperture::clone() const { 41 return new H_RectEllipticAperture(x1,x2,x3,x4,fx,fy); 42 } 43 44 45 TPolyLine * rectellipse(const float a_e = 2, const float b_e = 1, const float a_r = 1, const float b_r = 2, const float center_x = 0, const float center_y =0) { 46 const int n = 20; // number of points per segment 47 const int N = 4*n; // there are 4 segments 48 float x[N+1], y[N+1]; 49 50 if(a_e>a_r) { 51 // a rectellipse has 4 segments 52 // 1) upper one 53 for (int i=0; i<n; i++) { 54 x[i] = -a_r + i*(2*a_r)/(float)n; 55 y[i] = b_e * sqrt(1-pow(x[i]/a_e,2)); 56 } 57 58 // 2) right vertical segment 59 // upper right corner 60 const float y2 = b_e * sqrt(1-pow(a_r/a_e,2)); 61 // lower right corner 62 const float y3 = -b_e * sqrt(1-pow(a_r/a_e,2)); 63 for (int i=n; i<2*n; i++) { 64 x[i] = a_r; 65 y[i] = y2 - (i-n)*(2*y2)/(float)n; 66 } 67 68 // 3) lower side 69 for (int i=2*n; i<3*n; i++) { 70 x[i] = a_r - (i-2*n)*(2*a_r)/(float)n; 71 y[i] = -b_e * sqrt(1-pow(x[i]/a_e,2)); 72 } 73 74 // 4) left vertical segment 75 // lower left corner 76 const float y4 = y3; 77 for (int i=3*n; i<4*n; i++) { 78 x[i] = -a_r; 79 y[i] = y4 + (i-3*n)*(2*y2)/(float)n; 80 } 81 } else { 82 // 1) upper one : flat 83 const float x1 = -a_e * sqrt(1-pow(b_r/b_e,2)); 84 const float x2 = -x1; 85 for (int i=0; i<n; i++) { 86 y[i] = b_r; 87 x[i] = x1 + i * (x2-x1)/(float)n; 88 } 89 90 // 2) right curved border 91 for (int i=n; i<2*n; i++) { 92 y[i] = b_r - (i-n) * (2*b_r)/(float)n; 93 x[i] = a_e * sqrt(1-pow(y[i]/b_e,2)); 94 } 95 96 // 3) lower side : flat 97 for (int i=2*n; i<3*n; i++) { 98 y[i] = -b_r; 99 x[i] = x2 - (i-2*n) * (2*x2)/(float)n; 100 } 101 102 // 4) left curved border 103 for (int i=3*n; i<4*n; i++) { 104 y[i] = -b_r + (i-3*n) * (2*b_r)/(float)n; 105 x[i] = -a_e * sqrt(1-pow(y[i]/b_e,2)); 106 } 107 } 108 109 // closing the polyline 110 x[N] = x[0]; 111 y[N] = y[0]; 112 113 // shifting the center 114 for (int i=0; i<N+1; i++) { 115 x[i] += center_x; 116 y[i] += center_y; 117 } 118 119 return new TPolyLine(N+1,x,y); 120 } 121 122 123 void H_RectEllipticAperture::draw(const float scale) const { 124 TPolyLine * re = rectellipse(x3*scale, x4*scale, x1*scale, x2*scale, fx*scale, fy*scale); 125 re->SetLineColor(39); 126 re->SetLineWidth(2); 127 re->Draw("l"); 35 void H_RectEllipticAperture::draw() const { 36 /* TEllipse* te = new TEllipse(fx,fy,x3,x4); 37 TPave* tp = new TPave(fx-x1,fy-x2,fx+x1,fy+x2,1); 38 te->SetLineColor(2); 39 te->SetFillColor(2); 40 te->SetFillStyle(3004); 41 te->Draw(); 42 tp->SetLineColor(2); 43 tp->SetFillColor(2); 44 tp->SetFillStyle(3005); 45 tp->Draw(); 128 46 return; 47 */ 129 48 } 130 49 … … 133 52 } 134 53 135 std::ostream& operator<< (std::ostream& os, const H_RectEllipticAperture& ap){136 os << "Aperture shape:" << ap.aptypestring << ", parameters " << ap.x1 <<", "<< ap.x2 <<", "<< ap.x3 <<", "<< ap.x4<< endl;137 os << " \t Center : " << ap.fx <<", "<< ap.fy<<endl;138 return os;54 void H_RectEllipticAperture::printProperties() const { 55 cout << "Aperture shape:" << getTypeString() << ", parameters " <<x1<<", "<<x2<<", "<<x3<<", "<<x4<< endl; 56 cout << " \t Center : "<<fx<<", "<<fy<<endl; 57 return; 139 58 }
Note:
See TracChangeset
for help on using the changeset viewer.