00001 #include "BDSAcceleratorComponent.hh"
00002 #include "BDSAcceleratorModel.hh"
00003 #include "BDSBeamline.hh"
00004 #include "BDSGlobalConstants.hh"
00005 #include "BDSGeometryInterface.hh"
00006
00007 #include <fstream>
00008 #include <iomanip>
00009 #include <iostream>
00010 #include <ctime>
00011 #include <string>
00012
00013 using std::setw;
00014
00015 BDSGeometryInterface::BDSGeometryInterface(G4String filename):
00016 itsFileName(filename)
00017 {}
00018
00019 BDSGeometryInterface::~BDSGeometryInterface()
00020 {}
00021
00022 void BDSGeometryInterface::Optics()
00023 {
00024 std::ofstream optics;
00025
00026 G4cout << "Generating Optics file to: " << itsFileName << " ..." << G4endl;
00027
00028 optics.open(itsFileName);
00029
00030 time_t currenttime;
00031 time(¤ttime);
00032 std::string timestring = asctime(localtime(¤ttime));
00033 timestring = timestring.substr(0,timestring.size()-1);
00034
00035 optics << "### BDSIM output - created "<< timestring << G4endl;
00036 optics << std::left
00037 << setw(15) << "Type "
00038 << setw(40) << "Name "
00039 << setw(15) << "Length[m] "
00040 << setw(15) << "S[m] "
00041 << setw(15) << "Angle[rad] "
00042 << setw(15) << "K1[m^-2] "
00043 << setw(15) << "K2[m^-3] "
00044 << setw(15) << "K3[m^-4] "
00045 << setw(15) << "TILT "
00046 << setw(15) << "AperX[m] "
00047 << setw(15) << "AperY[m] "
00048 << setw(15) << "Aper_Type "
00049 << G4endl;
00050
00051 BDSBeamline* beamline = BDSAcceleratorModel::Instance()->GetFlatBeamline();
00052 BDSBeamlineIterator it = beamline->begin();
00053 for(; it != beamline->end(); ++it)
00054 {
00055 BDSAcceleratorComponent* thecurrentitem = (*it)->GetAcceleratorComponent();
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 optics.setf(std::ios::fixed, std::ios::floatfield);
00070 optics.setf(std::ios::showpoint);
00071
00072 optics.precision(8);
00073
00074 optics << std::left
00075 << setw(15) << thecurrentitem->GetType() << " "
00076 << setw(40) << thecurrentitem->GetName() << " "
00077 << setw(15) << thecurrentitem->GetChordLength()/CLHEP::m << " "
00078 << setw(15) << (*it)->GetSPositionMiddle()/CLHEP::m << " "
00079 << setw(15) << thecurrentitem->GetAngle() << " " << G4endl;
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 }
00094 optics.close();
00095
00096 }
00097
00098
00099 void BDSGeometryInterface::Survey()
00100 {
00101 std::ofstream survey;
00102
00103 G4cout << "Generating Survey: " << itsFileName << " ..." << G4endl;
00104
00105 survey.open(itsFileName);
00106
00107 time_t currenttime;
00108 time(¤ttime);
00109 std::string timestring = asctime(localtime(¤ttime));
00110 timestring = timestring.substr(0,timestring.size()-1);
00111
00112 survey << "### BDSIM output - created "<< timestring << G4endl;
00113 survey << std::left
00114 << setw(15) << "Type " << " "
00115 << setw(40) << "Name " << " "
00116 << setw(12) << "SStart[m] " << " "
00117 << setw(12) << "SMid[m] " << " "
00118 << setw(12) << "SEnd[m] " << " "
00119 << setw(12) << "Chord_len[m]" << " "
00120 << setw(12) << "Arc_len[m] " << " "
00121 << setw(12) << "X[m] " << " "
00122 << setw(12) << "Y[m] " << " "
00123 << setw(12) << "Z[m] " << " "
00124 << setw(12) << "Phi[rad] " << " "
00125 << setw(12) << "Theta[rad] " << " "
00126 << setw(12) << "Psi[rad] " << " "
00127 << setw(12) << "AperX[m] " << " "
00128 << setw(12) << "AperY[m] " << " "
00129 << setw(8) << "Aper_Type " << " "
00130 << setw(12) << "Angle[rad] " << " "
00131 << setw(12) << "K1[m^-2] " << " "
00132 << setw(12) << "K2[m^-3] " << " "
00133 << setw(12) << "K3[m^-4] " << " "
00134 << G4endl;
00135
00136 BDSBeamline* beamline = BDSAcceleratorModel::Instance()->GetFlatBeamline();
00137 BDSBeamlineIterator it = beamline->begin();
00138 for(; it != beamline->end(); ++it)
00139 {
00140 BDSAcceleratorComponent* thecurrentitem = (*it)->GetAcceleratorComponent();
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 G4RotationMatrix* rm = (*it)->GetRotationMiddle();
00153 G4double phi = rm->getPhi();
00154 G4double theta = rm->getTheta();
00155 G4double psi = rm->getPsi();
00156
00157 survey.setf(std::ios::fixed, std::ios::floatfield);
00158 survey.setf(std::ios::showpoint);
00159
00160 survey.precision(7);
00161
00162 G4double sStart = (*it)->GetSPositionStart() /CLHEP::m;
00163 G4double sMiddle = (*it)->GetSPositionMiddle()/CLHEP::m;
00164 G4double sEnd = (*it)->GetSPositionEnd() /CLHEP::m;
00165 G4ThreeVector pos = (*it)->GetPositionMiddle();
00166
00167 survey << std::left << std::setprecision(6) << std::fixed
00168 << setw(15) << thecurrentitem->GetType() << " "
00169 << setw(40) << thecurrentitem->GetName() << " "
00170 << setw(12) << sStart << " "
00171 << setw(12) << sMiddle << " "
00172 << setw(12) << sEnd << " "
00173 << setw(12) << thecurrentitem->GetChordLength()/CLHEP::m << " "
00174 << setw(12) << thecurrentitem->GetArcLength()/CLHEP::m << " "
00175 << setw(12) << pos.x()/CLHEP::m << " "
00176 << setw(12) << pos.y()/CLHEP::m << " "
00177 << setw(12) << pos.z()/CLHEP::m << " "
00178 << setw(12) << phi/CLHEP::radian << " "
00179 << setw(12) << theta/CLHEP::radian << " "
00180 << setw(12) << psi/CLHEP::radian << " " << G4endl;
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 }
00191 survey << "### Total length = " << beamline->GetTotalChordLength()/CLHEP::m << "m" << G4endl;
00192 survey << "### Total arc length = " << beamline->GetTotalArcLength()/CLHEP::m << "m" << G4endl;
00193 survey.close();
00194 }