1 | #include "elementBeam.h" |
---|
2 | #include "beam2Moments.h" |
---|
3 | #include "mixedTools.h" |
---|
4 | |
---|
5 | elementBeam::elementBeam() : abstractElement() |
---|
6 | { |
---|
7 | setDefaultValues(); |
---|
8 | setDefaults(); |
---|
9 | elementName_ = nomdElements("beam"); |
---|
10 | nbParam_ = elementName_.getElementNbParameters(); |
---|
11 | parametersString_ = new string[nbParam_+1]; |
---|
12 | // transportOk_ = true; |
---|
13 | // registerAcceptableSoftware(nomDeLogiciel::transport, TBoolOk); |
---|
14 | } |
---|
15 | |
---|
16 | elementBeam::~elementBeam() {;} |
---|
17 | |
---|
18 | void elementBeam::setDefaultValues() |
---|
19 | { |
---|
20 | defaultSpecificName_ = "beam"; |
---|
21 | xDef_ = 0.0; |
---|
22 | xpDef_ = 0.0; |
---|
23 | yDef_ = 0.0; |
---|
24 | ypDef_ = 0.0; |
---|
25 | dlDef_ = 0.0; |
---|
26 | delDef_ = 0.0; |
---|
27 | p0Def_ = 0.0; |
---|
28 | } |
---|
29 | |
---|
30 | void elementBeam::setDefaults() |
---|
31 | { |
---|
32 | specificName_ = defaultSpecificName_; |
---|
33 | x_ = xDef_; |
---|
34 | xp_ = xpDef_; |
---|
35 | y_ = yDef_; |
---|
36 | yp_ = ypDef_; |
---|
37 | dl_ = dlDef_; |
---|
38 | del_ = delDef_; |
---|
39 | p0_ = p0Def_; |
---|
40 | } |
---|
41 | |
---|
42 | string* elementBeam::getParametersString() const |
---|
43 | { |
---|
44 | int compteur = -1; |
---|
45 | parametersString_[++compteur] = mixedTools::intToString(nbParam_); |
---|
46 | parametersString_[++compteur] = specificName_; |
---|
47 | parametersString_[++compteur] = mixedTools::doubleToString(x_); |
---|
48 | parametersString_[++compteur] = mixedTools::doubleToString(xp_); |
---|
49 | parametersString_[++compteur] = mixedTools::doubleToString(y_); |
---|
50 | parametersString_[++compteur] = mixedTools::doubleToString(yp_); |
---|
51 | parametersString_[++compteur] = mixedTools::doubleToString(dl_); |
---|
52 | parametersString_[++compteur] = mixedTools::doubleToString(del_); |
---|
53 | parametersString_[++compteur] = mixedTools::doubleToString(p0_); |
---|
54 | if ( compteur != nbParam_ ) { |
---|
55 | cerr << " elementBeam::getParametersString() : ERROR nr pf parameters doesnt match " << endl; |
---|
56 | return NULL; |
---|
57 | } |
---|
58 | return parametersString_; |
---|
59 | } |
---|
60 | |
---|
61 | void elementBeam::setParametersString(string* param) |
---|
62 | { |
---|
63 | if ( param == NULL ) { |
---|
64 | cerr << " elementBeam::setParametersString parameters empty parameter set"; |
---|
65 | return; |
---|
66 | } |
---|
67 | int compteur = -1; |
---|
68 | int nbparam = atoi(param[++compteur].c_str()); |
---|
69 | if ( nbparam != nbParam_ ) { |
---|
70 | cerr << " elementBeam::setParametersString parameters do not match for a BEAM"; |
---|
71 | return; |
---|
72 | } |
---|
73 | |
---|
74 | specificName_ = param[++compteur]; |
---|
75 | x_ = atof(param[++compteur].c_str()); |
---|
76 | xp_ = atof(param[++compteur].c_str()); |
---|
77 | y_ = atof(param[++compteur].c_str()); |
---|
78 | yp_ = atof(param[++compteur].c_str()); |
---|
79 | dl_ = atof(param[++compteur].c_str()); |
---|
80 | del_ = atof(param[++compteur].c_str()); |
---|
81 | p0_ = atof(param[++compteur].c_str()); |
---|
82 | } |
---|
83 | |
---|
84 | // string elementBeam::parmelaOutputFlow() const |
---|
85 | // { |
---|
86 | // ostringstream sortie; |
---|
87 | // cout << " BEAM sortie parmela non programmee " << endl; |
---|
88 | // return sortie.str(); |
---|
89 | // } |
---|
90 | |
---|
91 | // string elementBeam::transportOutputFlow() const { |
---|
92 | // ostringstream sortie; |
---|
93 | // beam2Moments moments(x_, xp_, y_, yp_, dl_, del_); |
---|
94 | // cout << " elementBeam::transportOutputFlow(), p0 = " << p0_ << endl; |
---|
95 | // sortie << specificName_ << ":" << moments.writeToTransportInput(p0_) << endl; |
---|
96 | // return sortie.str(); |
---|
97 | // } |
---|
98 | |
---|
99 | // string elementBeam::FileOutputFlow() const |
---|
100 | // { |
---|
101 | // ostringstream sortie; |
---|
102 | // // sortie << elementName_.getElementType() << endl; |
---|
103 | // sortie << elementName_.getGenericLabel() << endl; |
---|
104 | // sortie << specificName_ << endl; |
---|
105 | // sortie << x_ << " " << xp_ << " " << y_ << " " << yp_ << endl; |
---|
106 | // sortie << dl_ << " " << del_ << " " << p0_ << endl; |
---|
107 | // cout << " elementBeam::FileOutputFlow, p0 = " << p0_ << endl; |
---|
108 | // return sortie.str(); |
---|
109 | // } |
---|
110 | |
---|
111 | vector< pair<string, vector<string> > > elementBeam::parametersToSoftware () const |
---|
112 | { |
---|
113 | vector< pair<string, vector<string> > > sortie; |
---|
114 | sortie.push_back( pair<string, vector<string> >("labelsGenericSpecific", vector<string>() ) ); |
---|
115 | sortie.back().second.push_back(elementName_.getGenericLabel()); |
---|
116 | sortie.back().second.push_back(specificName_); |
---|
117 | sortie.push_back( pair<string, vector<string> >("transverseCoordinates", vector<string>() ) ); |
---|
118 | sortie.back().second.push_back(mixedTools::doubleToString(x_)); |
---|
119 | sortie.back().second.push_back(mixedTools::doubleToString(xp_)); |
---|
120 | sortie.back().second.push_back(mixedTools::doubleToString(y_)); |
---|
121 | sortie.back().second.push_back(mixedTools::doubleToString(xp_)); |
---|
122 | sortie.push_back( pair<string, vector<string> >("longitudinalCoordinates", vector<string>() ) ); |
---|
123 | sortie.back().second.push_back(mixedTools::doubleToString(dl_)); |
---|
124 | sortie.back().second.push_back(mixedTools::doubleToString(del_)); |
---|
125 | sortie.push_back( pair<string, vector<string> >("momentum", vector<string>() ) ); |
---|
126 | sortie.back().second.push_back(mixedTools::doubleToString(p0_)); |
---|
127 | return sortie; |
---|
128 | } |
---|
129 | |
---|
130 | // void elementBeam::FileInput(ifstream& ifs) |
---|
131 | // { |
---|
132 | // ifs >> specificName_; |
---|
133 | // ifs >> x_ >> xp_ >> y_ >> yp_; |
---|
134 | // ifs >> dl_ >> del_ >> p0_; |
---|
135 | // cout << " elementBeam::FileFileInput, p0 = " << p0_ << endl; |
---|
136 | // lenghtElem_ = getLenghtOfElement(); |
---|
137 | // cout << " elementBeam::FileInput calcule longueur = " << lenghtElem_ << endl; |
---|
138 | // } |
---|
139 | |
---|
140 | void elementBeam::FileAMLInput(UAPNode* entree) |
---|
141 | { |
---|
142 | // if ( !entree ) return; |
---|
143 | // string nonGenerique; |
---|
144 | // AMLtools::readAMLParameterAttribut(*iter, "description", "type", nonGenerique); |
---|
145 | // if ( nonGenerique != elementName_.getGenericLabel() ) { |
---|
146 | // cout << " elementBeam::FileAMLInput ERREUR d'element : " << nonGenerique << " ? attendu : " << elementName_.getGenericLabel() << endl; |
---|
147 | // return; |
---|
148 | // } |
---|
149 | |
---|
150 | if ( !checkAMLelementGenericName(entree) ) return; |
---|
151 | UAPNode* faisceau = entree->getChildByName("beam"); |
---|
152 | if ( !faisceau ) { |
---|
153 | cout << " elementBeam::FileAMLInput ERREUR pas de noeud AML <beam> : " << endl; |
---|
154 | return; |
---|
155 | } |
---|
156 | AMLtools::readAMLParameterAttribut(faisceau, "11", "design", x_); |
---|
157 | AMLtools::readAMLParameterAttribut(faisceau, "22", "design", xp_); |
---|
158 | AMLtools::readAMLParameterAttribut(faisceau, "33", "design", y_); |
---|
159 | AMLtools::readAMLParameterAttribut(faisceau, "44", "design", yp_); |
---|
160 | AMLtools::readAMLParameterAttribut(faisceau, "55", "design", dl_); |
---|
161 | AMLtools::readAMLParameterAttribut(faisceau, "66", "design", del_); |
---|
162 | AMLtools::readAMLParameterAttribut(faisceau, "pc", "design", p0_); |
---|
163 | lenghtElem_ = getLenghtOfElement(); |
---|
164 | cout << " elementBeam::FileAMLInput calcule longueur = " << lenghtElem_ << endl; |
---|
165 | } |
---|
166 | |
---|
167 | |
---|
168 | |
---|
169 | string elementBeam::print() |
---|
170 | { |
---|
171 | string txt = ""; |
---|
172 | txt += specificName_; |
---|
173 | txt += "\n 1/2 horizontal beam extend rms (cm) : "; |
---|
174 | txt += mixedTools::doubleToString(x_); |
---|
175 | txt += "\n 1/2 horizontal beam divergence rms (mrad) : "; |
---|
176 | txt += mixedTools::doubleToString(xp_); |
---|
177 | txt += "\n1/2 vertical beam extend rms (cm) : "; |
---|
178 | txt += mixedTools::doubleToString(y_); |
---|
179 | txt += "\n1/2 horizontal beam divergence rms (mrad) : "; |
---|
180 | txt += mixedTools::doubleToString(yp_); |
---|
181 | txt += "\n1/2 longitudinal beam extend rms (cm) : "; |
---|
182 | txt += mixedTools::doubleToString(dl_); |
---|
183 | txt += "\n1/2 momentum spread rms (mrad) : "; |
---|
184 | txt += mixedTools::doubleToString(del_); |
---|
185 | txt += "\nmomentum of the central trajectory (GeV/c) : "; |
---|
186 | txt += mixedTools::doubleToString(p0_); |
---|
187 | return txt; |
---|
188 | } |
---|
189 | |
---|
190 | void elementBeam::InputRep(UAPNode* root) |
---|
191 | { |
---|
192 | // UAPNode* ele = root->addChild("element"); |
---|
193 | // ele->addAttribute("name",specificName_); |
---|
194 | UAPNode* ele = setAMLelementHeader(root); |
---|
195 | |
---|
196 | UAPNode* node = ele->addChild("beam"); |
---|
197 | |
---|
198 | // je fixe le type de particule, plus tard on pourra donner le choix |
---|
199 | node->addChild("particle")->addAttribute("type","ELECTRON"); |
---|
200 | |
---|
201 | // matrice 6X6 |
---|
202 | UAPNode* snode = node->addChild("sigma_matrix"); |
---|
203 | string txt = ""; |
---|
204 | txt = mixedTools::doubleToString(x_); |
---|
205 | snode->addChild("11")->addAttribute("design",txt); |
---|
206 | txt = mixedTools::doubleToString(xp_); |
---|
207 | snode->addChild("22")->addAttribute("design",txt); |
---|
208 | txt = mixedTools::doubleToString(y_); |
---|
209 | snode->addChild("33")->addAttribute("design",txt); |
---|
210 | txt = mixedTools::doubleToString(yp_); |
---|
211 | snode->addChild("44")->addAttribute("design",txt); |
---|
212 | txt = mixedTools::doubleToString(dl_); |
---|
213 | snode->addChild("55")->addAttribute("design",txt); |
---|
214 | txt = mixedTools::doubleToString(del_); |
---|
215 | snode->addChild("66")->addAttribute("design",txt); |
---|
216 | |
---|
217 | // momentum of the central trajectory (GeV/c) |
---|
218 | txt = mixedTools::doubleToString(p0_); |
---|
219 | node->addChild("pc")->addAttribute("design",txt); |
---|
220 | } |
---|