[180] | 1 | #include "elementBeam.h" |
---|
[236] | 2 | #include "beam2Moments.h" |
---|
[180] | 3 | #include "mixedTools.h" |
---|
| 4 | |
---|
| 5 | elementBeam::elementBeam() : abstractElement() { |
---|
[287] | 6 | setDefaultValues(); |
---|
| 7 | setDefaults(); |
---|
| 8 | elementName_ = nomdElements("beam"); |
---|
| 9 | nbParam_ = elementName_.getElementNbParameters(); |
---|
| 10 | parametersString_ = new string[nbParam_+1]; |
---|
| 11 | // transportOk_ = true; |
---|
[418] | 12 | // registerAcceptableSoftware(nomDeLogiciel::transport, TBoolOk); |
---|
[180] | 13 | } |
---|
| 14 | |
---|
| 15 | elementBeam::~elementBeam() {;} |
---|
| 16 | |
---|
| 17 | void elementBeam::setDefaultValues() { |
---|
[418] | 18 | defaultSpecificName_ = "beam"; |
---|
[287] | 19 | xDef_ = 0.0; |
---|
| 20 | xpDef_ = 0.0; |
---|
| 21 | yDef_ = 0.0; |
---|
| 22 | ypDef_ = 0.0; |
---|
| 23 | dlDef_ = 0.0; |
---|
| 24 | delDef_ = 0.0; |
---|
| 25 | p0Def_ = 0.0; |
---|
| 26 | } |
---|
[180] | 27 | |
---|
[287] | 28 | void elementBeam::setDefaults() { |
---|
[418] | 29 | specificName_ = defaultSpecificName_; |
---|
[180] | 30 | x_ = xDef_; |
---|
| 31 | xp_ = xpDef_; |
---|
| 32 | y_ = yDef_; |
---|
| 33 | yp_ = ypDef_; |
---|
| 34 | dl_ = dlDef_; |
---|
| 35 | del_ = delDef_; |
---|
| 36 | p0_ = p0Def_; |
---|
[287] | 37 | } |
---|
[180] | 38 | |
---|
[243] | 39 | |
---|
[180] | 40 | string* elementBeam::getParametersString() const { |
---|
[287] | 41 | int compteur = -1; |
---|
| 42 | parametersString_[++compteur] = mixedTools::intToString(nbParam_); |
---|
[418] | 43 | parametersString_[++compteur] = specificName_; |
---|
[287] | 44 | parametersString_[++compteur] = mixedTools::doubleToString(x_); |
---|
| 45 | parametersString_[++compteur] = mixedTools::doubleToString(xp_); |
---|
| 46 | parametersString_[++compteur] = mixedTools::doubleToString(y_); |
---|
| 47 | parametersString_[++compteur] = mixedTools::doubleToString(yp_); |
---|
| 48 | parametersString_[++compteur] = mixedTools::doubleToString(dl_); |
---|
| 49 | parametersString_[++compteur] = mixedTools::doubleToString(del_); |
---|
| 50 | parametersString_[++compteur] = mixedTools::doubleToString(p0_); |
---|
| 51 | if ( compteur != nbParam_ ) { |
---|
| 52 | cerr << " elementBeam::getParametersString() : ERROR nr pf parameters doesnt match " << endl; |
---|
| 53 | return NULL; |
---|
| 54 | } |
---|
| 55 | return parametersString_; |
---|
[180] | 56 | } |
---|
| 57 | |
---|
[418] | 58 | |
---|
| 59 | |
---|
| 60 | |
---|
[180] | 61 | void elementBeam::setParametersString(string* param) { |
---|
[287] | 62 | if ( param == NULL ) |
---|
[180] | 63 | { |
---|
[287] | 64 | cerr << " elementBeam::setParametersString parameters empty parameter set"; |
---|
| 65 | return; |
---|
[180] | 66 | } |
---|
[287] | 67 | int compteur = -1; |
---|
| 68 | int nbparam = atoi(param[++compteur].c_str()); |
---|
| 69 | if ( nbparam != nbParam_ ) |
---|
[180] | 70 | { |
---|
[287] | 71 | cerr << " elementBeam::setParametersString parameters do not match for a BEAM"; |
---|
| 72 | return; |
---|
[180] | 73 | } |
---|
[287] | 74 | |
---|
[418] | 75 | specificName_ = param[++compteur]; |
---|
[287] | 76 | x_ = atof(param[++compteur].c_str()); |
---|
| 77 | xp_ = atof(param[++compteur].c_str()); |
---|
| 78 | y_ = atof(param[++compteur].c_str()); |
---|
| 79 | yp_ = atof(param[++compteur].c_str()); |
---|
| 80 | dl_ = atof(param[++compteur].c_str()); |
---|
| 81 | del_ = atof(param[++compteur].c_str()); |
---|
| 82 | p0_ = atof(param[++compteur].c_str()); |
---|
[180] | 83 | } |
---|
| 84 | |
---|
[418] | 85 | // string elementBeam::parmelaOutputFlow() const |
---|
| 86 | // { |
---|
| 87 | // ostringstream sortie; |
---|
| 88 | // cout << " BEAM sortie parmela non programmee " << endl; |
---|
| 89 | // return sortie.str(); |
---|
| 90 | // } |
---|
[180] | 91 | |
---|
[418] | 92 | // string elementBeam::transportOutputFlow() const { |
---|
| 93 | // ostringstream sortie; |
---|
| 94 | // beam2Moments moments(x_, xp_, y_, yp_, dl_, del_); |
---|
| 95 | // cout << " elementBeam::transportOutputFlow(), p0 = " << p0_ << endl; |
---|
| 96 | // sortie << specificName_ << ":" << moments.writeToTransportInput(p0_) << endl; |
---|
| 97 | // return sortie.str(); |
---|
| 98 | // } |
---|
[180] | 99 | |
---|
| 100 | string elementBeam::FileOutputFlow() const { |
---|
| 101 | ostringstream sortie; |
---|
[181] | 102 | // sortie << elementName_.getElementType() << endl; |
---|
[418] | 103 | sortie << elementName_.getGenericLabel() << endl; |
---|
| 104 | sortie << specificName_ << endl; |
---|
[180] | 105 | sortie << x_ << " " << xp_ << " " << y_ << " " << yp_ << endl; |
---|
| 106 | sortie << dl_ << " " << del_ << " " << p0_ << endl; |
---|
[287] | 107 | cout << " elementBeam::FileOutputFlow, p0 = " << p0_ << endl; |
---|
[180] | 108 | return sortie.str(); |
---|
[287] | 109 | } |
---|
[180] | 110 | |
---|
[418] | 111 | vector< pair<string, vector<string> > > elementBeam::parametersToSoftware () const { |
---|
| 112 | vector< pair<string, vector<string> > > sortie; |
---|
| 113 | sortie.push_back( pair<string, vector<string> >("labelsGenericSpecific", vector<string>() ) ); |
---|
| 114 | sortie.back().second.push_back(elementName_.getGenericLabel()); |
---|
| 115 | sortie.back().second.push_back(specificName_); |
---|
| 116 | sortie.push_back( pair<string, vector<string> >("transverseCoordinates", vector<string>() ) ); |
---|
| 117 | sortie.back().second.push_back(mixedTools::doubleToString(x_)); |
---|
| 118 | sortie.back().second.push_back(mixedTools::doubleToString(xp_)); |
---|
| 119 | sortie.back().second.push_back(mixedTools::doubleToString(y_)); |
---|
| 120 | sortie.back().second.push_back(mixedTools::doubleToString(xp_)); |
---|
| 121 | sortie.push_back( pair<string, vector<string> >("longitudinalCoordinates", vector<string>() ) ); |
---|
| 122 | sortie.back().second.push_back(mixedTools::doubleToString(dl_)); |
---|
| 123 | sortie.back().second.push_back(mixedTools::doubleToString(del_)); |
---|
| 124 | sortie.push_back( pair<string, vector<string> >("momentum", vector<string>() ) ); |
---|
| 125 | sortie.back().second.push_back(mixedTools::doubleToString(p0_)); |
---|
| 126 | return sortie; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | |
---|
[180] | 130 | void elementBeam::elementBeam::FileInput(ifstream& ifs) { |
---|
[418] | 131 | ifs >> specificName_; |
---|
[287] | 132 | ifs >> x_ >> xp_ >> y_ >> yp_; |
---|
| 133 | ifs >> dl_ >> del_ >> p0_; |
---|
| 134 | cout << " elementBeam::FileFileInput, p0 = " << p0_ << endl; |
---|
| 135 | lenghtElem_ = getLenghtOfElement(); |
---|
[180] | 136 | cout << " elementBeam::FileInput calcule longueur = " << lenghtElem_ << endl; |
---|
| 137 | } |
---|
[287] | 138 | |
---|
| 139 | |
---|
| 140 | string elementBeam::print() { |
---|
| 141 | string txt = ""; |
---|
[418] | 142 | txt += specificName_; |
---|
[287] | 143 | txt += "\n 1/2 horizontal beam extend rms (cm) : "; |
---|
| 144 | txt += mixedTools::doubleToString(x_); |
---|
| 145 | txt += "\n 1/2 horizontal beam divergence rms (mrad) : "; |
---|
| 146 | txt += mixedTools::doubleToString(xp_); |
---|
| 147 | txt += "\n1/2 vertical beam extend rms (cm) : "; |
---|
| 148 | txt += mixedTools::doubleToString(y_); |
---|
| 149 | txt += "\n1/2 horizontal beam divergence rms (mrad) : "; |
---|
| 150 | txt += mixedTools::doubleToString(yp_); |
---|
| 151 | txt += "\n1/2 longitudinal beam extend rms (cm) : "; |
---|
| 152 | txt += mixedTools::doubleToString(dl_); |
---|
| 153 | txt += "\n1/2 momentum spread rms (mrad) : "; |
---|
| 154 | txt += mixedTools::doubleToString(del_); |
---|
| 155 | txt += "\nmomentum of the central trajectory (GeV/c) : "; |
---|
| 156 | txt += mixedTools::doubleToString(p0_); |
---|
| 157 | |
---|
| 158 | return txt; |
---|
| 159 | } |
---|