1 | #include "elementRfgun.h" |
---|
2 | |
---|
3 | #include "mathematicalTools.h" |
---|
4 | #include "PhysicalConstants.h" |
---|
5 | #include "mixedTools.h" |
---|
6 | |
---|
7 | |
---|
8 | elementRfgun::elementRfgun() : abstractElement() |
---|
9 | { |
---|
10 | setDefaultValues(); |
---|
11 | setDefaults(); |
---|
12 | elementName_ = nomdElements("rfgun"); |
---|
13 | nbParam_ = elementName_.getElementNbParameters(); |
---|
14 | parametersString_ = new string[nbParam_+1]; |
---|
15 | // parmelaOk_ = true; |
---|
16 | // registerAcceptableSoftware(nomDeLogiciel::parmela, TBoolOk); |
---|
17 | // registerAcceptableSoftware(nomDeLogiciel::generator, TBoolOk); |
---|
18 | } |
---|
19 | |
---|
20 | void elementRfgun::setDefaultValues() |
---|
21 | { |
---|
22 | defaultSpecificName_ = "rfgun"; |
---|
23 | defaultPhaseStep_ = 1.0; |
---|
24 | defaultNmacrop_ = 0; |
---|
25 | defaultSigma_t_ = 0.0; |
---|
26 | defaultSigma_r_ = 0.0; |
---|
27 | defaultEmit_x_ = 0.0; |
---|
28 | defaultEmit_y_ = 0.0; |
---|
29 | defaultE_cin_ = 0.0; |
---|
30 | defaultSigma_E_ = 0.0; |
---|
31 | // defaultNb_true_particles_ = 1.0; |
---|
32 | defaultTotalCharge_ = 0.0; |
---|
33 | } |
---|
34 | |
---|
35 | void elementRfgun::setDefaults() |
---|
36 | { |
---|
37 | specificName_ = defaultSpecificName_; |
---|
38 | phaseStep_ = defaultPhaseStep_; |
---|
39 | nmacrop_ = defaultNmacrop_; |
---|
40 | sigma_t_ = defaultSigma_t_; |
---|
41 | sigma_r_ = defaultSigma_r_ ; |
---|
42 | emit_x_ = defaultEmit_x_; |
---|
43 | emit_y_ = defaultEmit_y_; |
---|
44 | E_cin_ = defaultE_cin_; |
---|
45 | sigma_E_ = defaultSigma_E_; |
---|
46 | // nb_true_particles_ = defaultNb_true_particles_ ; |
---|
47 | totalCharge_ = defaultTotalCharge_; |
---|
48 | } |
---|
49 | |
---|
50 | string* elementRfgun::getParametersString() const |
---|
51 | { |
---|
52 | int compteur = -1; |
---|
53 | parametersString_[++compteur] = mixedTools::intToString(nbParam_); |
---|
54 | parametersString_[++compteur] = specificName_; |
---|
55 | parametersString_[++compteur] = mixedTools::intToString(nmacrop_); |
---|
56 | parametersString_[++compteur] = mixedTools::doubleToString(sigma_t_); |
---|
57 | parametersString_[++compteur] = mixedTools::doubleToString(sigma_r_); |
---|
58 | parametersString_[++compteur] = mixedTools::doubleToString(emit_x_); |
---|
59 | parametersString_[++compteur] = mixedTools::doubleToString(emit_y_); |
---|
60 | parametersString_[++compteur] = mixedTools::doubleToString(E_cin_); |
---|
61 | parametersString_[++compteur] = mixedTools::doubleToString(sigma_E_); |
---|
62 | parametersString_[++compteur] = mixedTools::doubleToString(totalCharge_); |
---|
63 | return parametersString_; |
---|
64 | } |
---|
65 | |
---|
66 | void elementRfgun::setParametersString(string* param) |
---|
67 | { |
---|
68 | if ( param == NULL ) { |
---|
69 | cerr << " elementRfgun::setParametersString parameters empty parameter set"; |
---|
70 | return; |
---|
71 | } |
---|
72 | int compteur = -1; |
---|
73 | int nbparam = atoi(param[++compteur].c_str()); |
---|
74 | if ( nbparam != nbParam_ ) { |
---|
75 | cerr << " elementRfgun::setParametersString parameters do not match for a DRIFT"; |
---|
76 | return; |
---|
77 | } |
---|
78 | |
---|
79 | specificName_ = param[++compteur]; |
---|
80 | nmacrop_ = atoi(param[++compteur].c_str()); |
---|
81 | sigma_t_ = atof(param[++compteur].c_str()); |
---|
82 | sigma_r_ = atof(param[++compteur].c_str()); |
---|
83 | emit_x_ = atof(param[++compteur].c_str()); |
---|
84 | emit_y_ = atof(param[++compteur].c_str()); |
---|
85 | E_cin_ = atof(param[++compteur].c_str()); |
---|
86 | sigma_E_ = atof(param[++compteur].c_str()); |
---|
87 | totalCharge_ = atof(param[++compteur].c_str()); |
---|
88 | } |
---|
89 | |
---|
90 | // string elementRfgun::parmelaOutputFlow() const |
---|
91 | // { |
---|
92 | // ostringstream sortie; |
---|
93 | // // on prend les troncatures tmax et rmax à 3 sigmas |
---|
94 | // sortie << "INPUT 10 /np=" << nmacrop_ << " /sigt=" << sigma_t_ << endl; |
---|
95 | // sortie << " /tmax=" << 3.3*sigma_t_ << " /sigr=" << sigma_r_ << endl; |
---|
96 | // sortie << " /rmax=" << 3.0*sigma_r_ << " /W0=" << E_cin_ << " /dw0=" << sigma_E_ << endl; |
---|
97 | // sortie << " /dwt=" << phaseStep_ << " /ran=2" << endl; |
---|
98 | |
---|
99 | // // on doit entrer le nb vrai de part. (avec signe moins) |
---|
100 | |
---|
101 | |
---|
102 | // sortie << "SCHEFF /beami=" << -fabs(totalCharge_)/ELECTRONANOCOULOMB << " /nprog=2 /point=-1.7" << endl; |
---|
103 | |
---|
104 | // return sortie.str(); |
---|
105 | // } |
---|
106 | |
---|
107 | // string elementRfgun::generatorOutputFlow() const { |
---|
108 | // ostringstream sortie; |
---|
109 | // sortie << "Ipart=" << nmacrop_ << endl; |
---|
110 | |
---|
111 | // sortie << "Probe=.True." << endl; |
---|
112 | // sortie << "Noise_reduc=.T" << endl; |
---|
113 | // sortie << "Cathode=.T." << endl; |
---|
114 | // sortie << "Q_total=" << totalCharge_ << endl; |
---|
115 | // sortie << "Ref_zpos=0.0" << endl; |
---|
116 | // sortie << "Ref_clock=0.0" << endl; |
---|
117 | // sortie << "Ref_Ekin=" << E_cin_ << endl; // tjs en MeV |
---|
118 | // sortie << "Dist_z='g'" << endl; |
---|
119 | // sortie << "sig_clock=" << 1.0e-3*sigma_t_ << endl; // passage de ps en ns |
---|
120 | // sortie << "Dist_pz='g', sig_Ekin=" << 1000.*sigma_E_ << ", emit_z=0.0 , cor_Ekin=0.0 " << endl; // passage en keV |
---|
121 | // sortie << "Dist_x='gauss', sig_x=" << 10.*sigma_r_ << endl; // passage en mm |
---|
122 | // sortie << "Dist_px='g', Nemit_x=" << emit_x_ << ", cor_px=0.0" << endl; |
---|
123 | // sortie << "Dist_y='gauss', sig_y=" << 10.*sigma_r_ << endl; // passage en mm |
---|
124 | // sortie << "Dist_py='g', Nemit_y=" << emit_y_ << ", cor_py=0.0" << endl; |
---|
125 | // return sortie.str(); |
---|
126 | // } |
---|
127 | |
---|
128 | string elementRfgun::FileOutputFlow() const |
---|
129 | { |
---|
130 | ostringstream sortie; |
---|
131 | // on prend les troncatures tmax et rmax à 3 sigmas |
---|
132 | // sortie << elementName_.getElementType() << endl; |
---|
133 | sortie << elementName_.getGenericLabel() << endl; |
---|
134 | sortie << specificName_ << endl; |
---|
135 | sortie << nmacrop_ << " " << sigma_t_ << " " << sigma_r_ << endl; |
---|
136 | sortie << emit_x_ << " " << emit_y_ << endl; |
---|
137 | sortie << E_cin_ << " " << sigma_E_ << endl; |
---|
138 | sortie << phaseStep_ << " " << totalCharge_ << endl; |
---|
139 | return sortie.str(); |
---|
140 | } |
---|
141 | |
---|
142 | vector< pair<string, vector<string> > > elementRfgun::parametersToSoftware () const |
---|
143 | { |
---|
144 | vector< pair<string, vector<string> > > sortie; |
---|
145 | sortie.push_back( pair<string, vector<string> >("labelsGenericSpecific", vector<string>() ) ); |
---|
146 | sortie.back().second.push_back(elementName_.getGenericLabel()); |
---|
147 | sortie.back().second.push_back(specificName_); |
---|
148 | sortie.push_back( pair<string, vector<string> >("nbMacroparticles", vector<string>() ) ); |
---|
149 | sortie.back().second.push_back(mixedTools::intToString(nmacrop_)); |
---|
150 | sortie.push_back( pair<string, vector<string> >("sigmasTR", vector<string>() ) ); |
---|
151 | sortie.back().second.push_back(mixedTools::doubleToString(sigma_t_)); |
---|
152 | sortie.back().second.push_back(mixedTools::doubleToString(sigma_r_)); |
---|
153 | sortie.push_back( pair<string, vector<string> >("emittancesXY", vector<string>() ) ); |
---|
154 | sortie.back().second.push_back(mixedTools::doubleToString(emit_x_)); |
---|
155 | sortie.back().second.push_back(mixedTools::doubleToString(emit_y_)); |
---|
156 | sortie.push_back( pair<string, vector<string> >("kineticE", vector<string>() ) ); |
---|
157 | sortie.back().second.push_back(mixedTools::doubleToString(E_cin_)); |
---|
158 | sortie.back().second.push_back(mixedTools::doubleToString(sigma_E_)); |
---|
159 | sortie.push_back( pair<string, vector<string> >("phaseStep", vector<string>() ) ); |
---|
160 | sortie.back().second.push_back(mixedTools::doubleToString(phaseStep_)); |
---|
161 | sortie.push_back( pair<string, vector<string> >("totalCharge", vector<string>() ) ); |
---|
162 | sortie.back().second.push_back(mixedTools::doubleToString(totalCharge_)); |
---|
163 | return sortie; |
---|
164 | } |
---|
165 | |
---|
166 | void elementRfgun::FileInput(ifstream& ifs) |
---|
167 | { |
---|
168 | ifs >> specificName_; |
---|
169 | ifs >> nmacrop_ >> sigma_t_ >> sigma_r_; |
---|
170 | ifs >> emit_x_ >> emit_y_; |
---|
171 | ifs >> E_cin_ >> sigma_E_; |
---|
172 | ifs >> phaseStep_ >> totalCharge_; |
---|
173 | } |
---|
174 | |
---|
175 | string elementRfgun::print() |
---|
176 | { |
---|
177 | string txt = ""; |
---|
178 | txt += specificName_; |
---|
179 | txt += "\ntotal charge : "; |
---|
180 | txt += mixedTools::doubleToString(totalCharge_); |
---|
181 | txt += "\nsigma_t (ps) : "; |
---|
182 | txt += mixedTools::doubleToString(sigma_t_); |
---|
183 | txt += "\nsigma_r (cm) : "; |
---|
184 | txt += mixedTools::doubleToString(sigma_r_); |
---|
185 | txt += "\nemittance x (pi.mm.mrad) : "; |
---|
186 | txt += mixedTools::doubleToString(emit_x_); |
---|
187 | txt += "\nemittance y (pi.mm.mrad) : "; |
---|
188 | txt += mixedTools::doubleToString(emit_y_); |
---|
189 | txt += "\ninitial kinetic energy (MeV) : "; |
---|
190 | txt += mixedTools::doubleToString(E_cin_); |
---|
191 | txt += "\nsigma_Ecin (MeV) : "; |
---|
192 | txt += mixedTools::doubleToString(sigma_E_); |
---|
193 | txt += "\ntrue number of part. in beam : "; |
---|
194 | txt += mixedTools::boolToString(nmacrop_); |
---|
195 | return txt; |
---|
196 | } |
---|
197 | |
---|
198 | void elementRfgun::InputRep(UAPNode* root) |
---|
199 | { |
---|
200 | UAPNode* ele = root->addChild("element"); |
---|
201 | ele->addAttribute("name",specificName_); |
---|
202 | |
---|
203 | UAPNode* node = ele->addChild("comment"); |
---|
204 | node->addAttribute("type","RFgun"); |
---|
205 | node->addAttribute("text","to simulate emission from a photocathode"); |
---|
206 | |
---|
207 | node = ele->addChild("beam"); |
---|
208 | node->addChild("particle")->addAttribute("type","ELECTRON"); |
---|
209 | string txt = ""; |
---|
210 | txt = mixedTools::intToString(nmacrop_); |
---|
211 | node->addChild("n_particles")->addAttribute("design",txt); |
---|
212 | txt = mixedTools::doubleToString(sigma_t_); |
---|
213 | node->addChild("sig_t")->addAttribute("design",txt); |
---|
214 | txt = mixedTools::doubleToString(emit_x_); |
---|
215 | node->addChild("emittance_a")->addAttribute("design",txt); |
---|
216 | txt = mixedTools::doubleToString(emit_y_); |
---|
217 | node->addChild("emittance_b")->addAttribute("design",txt); |
---|
218 | txt = mixedTools::doubleToString(E_cin_); |
---|
219 | txt = mixedTools::doubleToString(E_cin_); |
---|
220 | node->addChild("total_energy")->addAttribute("design",txt); |
---|
221 | txt = mixedTools::doubleToString(sigma_E_); |
---|
222 | node->addChild("sig_e")->addAttribute("design",txt); |
---|
223 | txt = mixedTools::doubleToString(totalCharge_); |
---|
224 | node->addChild("particle_charge")->addAttribute("design",txt); |
---|
225 | |
---|
226 | // gaussian radial profile |
---|
227 | txt = mixedTools::doubleToString(sigma_r_); |
---|
228 | ele->addChild("sigma_r")->addAttribute("value",txt); |
---|
229 | // integration step size (specific to Parmela) |
---|
230 | txt = mixedTools::doubleToString(phaseStep_); |
---|
231 | ele->addChild("phaseStep")->addAttribute("value",txt); |
---|
232 | } |
---|
233 | |
---|