00001 // Geometry Interface Class 00002 // ======================== 00003 // 00004 // A class of functions to output Geant4/Mokka/BDSIM parameters for elements 00005 // - to include geometry, optics, fields, etc. 00006 00007 #include "BDSGlobalConstants.hh" 00008 #include "BDSGeometryInterface.hh" 00009 #include "BDSAcceleratorComponent.hh" 00010 #include "BDSBeamline.hh" 00011 00012 using namespace std; 00013 00014 BDSGeometryInterface::BDSGeometryInterface(G4String filename): 00015 itsFileName(filename) 00016 {} 00017 00018 BDSGeometryInterface::~BDSGeometryInterface() 00019 {} 00020 00021 void BDSGeometryInterface::Optics() 00022 { 00023 ofstream optics; 00024 00025 G4cout << "Generating Optics file to: " << itsFileName << " ..." << G4endl; 00026 00027 optics.open(itsFileName); 00028 00029 optics << setw(10) << "Type" 00030 << setw(10) << "Name" 00031 << setw(10) << "Length[m]" 00032 << setw(10) << "S [m]" 00033 << setw(10) << "Angle[rad]" 00034 << setw(10) << "K1 [m^-2]" 00035 << setw(10) << "K2 [m^-3]" 00036 << setw(10) << "K3 [m^-4]" 00037 << setw(10) << "TILT" 00038 << setw(10) << "AperX [m]" 00039 << setw(10) << "AperY [m]" 00040 << setw(10) << "Aper_Type" 00041 << G4endl; 00042 00043 for(BDSBeamline::Instance()->first();!BDSBeamline::Instance()->isDone();BDSBeamline::Instance()->next()) 00044 { 00045 G4int aper_type; //1 = rect, 2 = circ, 3 = elispe 00046 if(BDSBeamline::Instance()->currentItem()->GetType() == "rcol" ) //RCOL 00047 aper_type=1; 00048 else if(BDSBeamline::Instance()->currentItem()->GetType() == "ecol") //ECOL 00049 { 00050 if(BDSBeamline::Instance()->currentItem()->GetAperX()==BDSBeamline::Instance()->currentItem()->GetAperY()) 00051 aper_type=2; 00052 else aper_type=3; 00053 } 00054 else aper_type=2; // circular is default 00055 00056 optics.setf(ios::fixed, ios::floatfield); 00057 optics.setf(ios::showpoint); 00058 00059 optics.precision(8); 00060 00061 optics << setw(10) 00062 << BDSBeamline::Instance()->currentItem()->GetType() << " " 00063 << BDSBeamline::Instance()->currentItem()->GetName() << " " 00064 << BDSBeamline::Instance()->currentItem()->GetLength()/m << " " 00065 << BDSBeamline::Instance()->positionS()/m << " " 00066 << BDSBeamline::Instance()->currentItem()->GetAngle() << " " 00067 << BDSBeamline::Instance()->currentItem()->GetK1() << " " 00068 << BDSBeamline::Instance()->currentItem()->GetK2() << " " 00069 << BDSBeamline::Instance()->currentItem()->GetK3() << " " 00070 << BDSBeamline::Instance()->currentItem()->GetTilt() << " " 00071 << BDSBeamline::Instance()->currentItem()->GetAperX()/m << " " 00072 << BDSBeamline::Instance()->currentItem()->GetAperY()/m << " " 00073 << aper_type << " " 00074 << G4endl; 00075 } 00076 optics.close(); 00077 00078 } 00079 00080 00081 void BDSGeometryInterface::Survey() 00082 { 00083 ofstream survey; 00084 00085 G4cout << "Generating Survey: " << itsFileName << " ..." << G4endl; 00086 00087 survey.open(itsFileName); 00088 survey << setw(10) << "Type" << " " 00089 << setw(10) << "Name" << " " 00090 << setw(10) << "Length[m]" << " " 00091 << setw(10) << "Arc len[m]" << " " 00092 << setw(10) << "X [m]" << " " 00093 << setw(10) << "Y [m]" << " " 00094 << setw(10) << "Z [m]" << " " 00095 << setw(10) << "Phi [rad]" << " " 00096 << setw(10) << "Theta [rad]" 00097 << setw(10) << "Psi [rad]" << " " 00098 << setw(10) << "AperX [m]" << " " 00099 << setw(10) << "AperY [m]" << " " 00100 << setw(10) << "Aper_Type" << " " 00101 << setw(10) << "Angle[rad]" << " " 00102 << setw(10) << "K1 [m^-2]" << " " 00103 << setw(10) << "K2 [m^-3]" << " " 00104 << setw(10) << "K3 [m^-4]" << " " 00105 00106 << G4endl; 00107 00108 G4double length(0.0); 00109 G4double arc_length(0.0); 00110 for(BDSBeamline::Instance()->first();!BDSBeamline::Instance()->isDone();BDSBeamline::Instance()->next()) 00111 { 00112 G4int aper_type; //1 = rect, 2 = circ, 3 = elispe 00113 if(BDSBeamline::Instance()->currentItem()->GetType() == 14 ) //RCOL 00114 aper_type=1; 00115 else if(BDSBeamline::Instance()->currentItem()->GetType() == 13) //ECOL 00116 if(BDSBeamline::Instance()->currentItem()->GetAperX()==BDSBeamline::Instance()->currentItem()->GetAperY()) 00117 aper_type=2; 00118 else aper_type=3; 00119 else aper_type=1; 00120 00121 G4double phi, theta, psi; 00122 if(BDSBeamline::Instance()->currentItem()->GetRotation()) 00123 { 00124 // sort out rounding errors where zz -> 1.000001, etc. 00125 if(fabs(BDSBeamline::Instance()->currentItem()->GetRotation()->zz())>1) 00126 { 00127 G4ThreeVector newZ = BDSBeamline::Instance()->currentItem()->GetRotation()->rowZ(); 00128 newZ.setZ(1.0); 00129 BDSBeamline::Instance()->currentItem()->GetRotation()->setRows(BDSBeamline::Instance()->currentItem()->GetRotation()->rowX(), 00130 BDSBeamline::Instance()->currentItem()->GetRotation()->rowY(), 00131 newZ); 00132 } 00133 00134 phi = BDSBeamline::Instance()->currentItem()->GetRotation()->getPhi(); 00135 theta = BDSBeamline::Instance()->currentItem()->GetRotation()->getTheta(); 00136 psi = BDSBeamline::Instance()->currentItem()->GetRotation()->getPsi(); 00137 00138 } 00139 else 00140 phi = theta = psi = 0.0; 00141 00142 survey.setf(ios::fixed, ios::floatfield); 00143 survey.setf(ios::showpoint); 00144 00145 survey.precision(7); 00146 00147 survey << setw(10) << BDSBeamline::Instance()->currentItem()->GetType() << " " 00148 << setw(10) << BDSBeamline::Instance()->currentItem()->GetName() << " " 00149 << setw(10) << BDSBeamline::Instance()->currentItem()->GetLength()/m << " " 00150 << setw(10) << BDSBeamline::Instance()->currentItem()->GetArcLength()/m << " " 00151 << setw(10) << BDSBeamline::Instance()->currentItem()->GetPosition().x()/m << " " 00152 << setw(10) << BDSBeamline::Instance()->currentItem()->GetPosition().y()/m << " " 00153 << setw(10) << BDSBeamline::Instance()->currentItem()->GetPosition().z()/m << " " 00154 << setw(10) << phi/radian << " " 00155 << setw(10) << theta/radian << " " 00156 << setw(10) << psi/radian << " " 00157 << setw(10) << BDSBeamline::Instance()->currentItem()->GetAperX()/m << " " 00158 << setw(10) << BDSBeamline::Instance()->currentItem()->GetAperY()/m << " " 00159 << setw(10) << aper_type << " " 00160 << setw(10) << BDSBeamline::Instance()->currentItem()->GetAngle() << " " 00161 << setw(10) << BDSBeamline::Instance()->currentItem()->GetK1() << " " 00162 << setw(10) << BDSBeamline::Instance()->currentItem()->GetK2() << " " 00163 << setw(10) << BDSBeamline::Instance()->currentItem()->GetK3() << " " 00164 << G4endl; 00165 length+=BDSBeamline::Instance()->currentItem()->GetLength()/m; 00166 arc_length+=BDSBeamline::Instance()->currentItem()->GetArcLength()/m; 00167 } 00168 survey << "Total length = " << length << "m" << G4endl; 00169 survey << "Total arc length = " << arc_length << "m" << G4endl; 00170 survey.close(); 00171 }