1 | |
---|
2 | #include "particleBeam.h" |
---|
3 | #include "mathematicalConstants.h" |
---|
4 | #include "PhysicalConstants.h" |
---|
5 | #include "mathematicalTools.h" |
---|
6 | #include "mixedTools.h" |
---|
7 | |
---|
8 | #include <stdio.h> |
---|
9 | #include <algorithm> |
---|
10 | #include <sstream> |
---|
11 | |
---|
12 | using namespace std; |
---|
13 | |
---|
14 | particleBeam::particleBeam() { |
---|
15 | P0Transport_ = 0.0; |
---|
16 | particleRepresentationOk_ = false; |
---|
17 | momentRepresentationOk_ = false; |
---|
18 | } |
---|
19 | |
---|
20 | void particleBeam::clear() { |
---|
21 | goodPartic_.clear(); |
---|
22 | rij_.raz(); |
---|
23 | P0Transport_ = 0.0; |
---|
24 | particleRepresentationOk_ = false; |
---|
25 | momentRepresentationOk_ = false; |
---|
26 | } |
---|
27 | |
---|
28 | int particleBeam::getNbParticles() const { |
---|
29 | return goodPartic_.size(); |
---|
30 | } |
---|
31 | |
---|
32 | const beam2Moments& particleBeam::getTransportMoments() const { |
---|
33 | return rij_; |
---|
34 | } |
---|
35 | |
---|
36 | double particleBeam::getSigmaTransportij(unsigned indexI, unsigned indexJ) { |
---|
37 | if ( indexI > 5 || indexJ > 5 ) { |
---|
38 | cerr << " particleBeam::getSigmaTransportij() indices out of range " << endl; |
---|
39 | return 0.0; |
---|
40 | } |
---|
41 | if ( !momentRepresentationOk_ ) { |
---|
42 | cerr << " particleBeam::getSigmaTransportij() beam is not in moment representation " << endl; |
---|
43 | return 0.0; |
---|
44 | } |
---|
45 | if ( indexI >= indexJ ) { |
---|
46 | return ( rij_.getMatrix().at(indexI) ).at(indexJ); |
---|
47 | } else { |
---|
48 | return ( rij_.getMatrix().at(indexJ) ).at(indexI); |
---|
49 | } |
---|
50 | |
---|
51 | } |
---|
52 | |
---|
53 | double particleBeam::getUnnormalizedEmittanceX() { |
---|
54 | double r = getSigmaTransportij(1,0); |
---|
55 | double rac = (1 - r*r); |
---|
56 | if ( rac <= 0.0 ) { |
---|
57 | return 0.0; |
---|
58 | } |
---|
59 | rac = sqrt(1 - r*r); |
---|
60 | return dimensionalFactorFromTransportToGraphics(0)*getSigmaTransportij(0,0) * getSigmaTransportij(1,1) * rac; // en pi.mm.mrad |
---|
61 | } |
---|
62 | |
---|
63 | double particleBeam::getUnnormalizedTranspPhaseSpaceArea(unsigned TranspIndexAbs, unsigned TranspIndexOrd) { |
---|
64 | if ( TranspIndexAbs == TranspIndexOrd ) return 0.0; |
---|
65 | double r = getSigmaTransportij(TranspIndexAbs,TranspIndexOrd); |
---|
66 | double rac = (1 - r*r); |
---|
67 | if ( rac <= 0.0 ) { |
---|
68 | return 0.0; |
---|
69 | } |
---|
70 | rac = sqrt(1 - r*r); |
---|
71 | return dimensionalFactorFromTransportToGraphics(TranspIndexAbs)*getSigmaTransportij(TranspIndexAbs,TranspIndexAbs) * |
---|
72 | dimensionalFactorFromTransportToGraphics(TranspIndexOrd)*getSigmaTransportij(TranspIndexOrd,TranspIndexOrd) * rac; // en pi.mm.mrad |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | |
---|
77 | double particleBeam::getP0Transport() const { |
---|
78 | return P0Transport_; |
---|
79 | } |
---|
80 | |
---|
81 | double particleBeam::referenceKineticEnergyMeV() const { |
---|
82 | if ( particleRepresentationOk_ ) { |
---|
83 | return (referenceParticle_.getGamma() -1.) * EREST_MeV; |
---|
84 | } else { |
---|
85 | double P0Norm = 1000.0 * P0Transport_ / EREST_MeV; |
---|
86 | double gamma = sqrt(1.0 + P0Norm * P0Norm); |
---|
87 | return (gamma - 1.0) * EREST_MeV; |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | void particleBeam::set2Moments(beam2Moments& moments) { |
---|
92 | rij_ = moments; |
---|
93 | momentRepresentationOk_ = true; |
---|
94 | } |
---|
95 | |
---|
96 | void particleBeam::setWithParticles(vector<double>& centroid, bareParticle& referencePart, vector<bareParticle>& particles) { |
---|
97 | cout << " particleBeam::setWithParticles taille vect. part. " << particles.size() << endl; |
---|
98 | centroid_.clear(); |
---|
99 | centroid_ = centroid; |
---|
100 | referenceParticle_ = referencePart; |
---|
101 | goodPartic_.clear(); |
---|
102 | goodPartic_ = particles; |
---|
103 | cout << " particleBeam::setWithParticles taille vect. part. ENREGISTRE " << goodPartic_.size() << endl; |
---|
104 | particleRepresentationOk_ = true; |
---|
105 | } |
---|
106 | |
---|
107 | bool particleBeam::particleRepresentationOk() const { |
---|
108 | return particleRepresentationOk_; |
---|
109 | } |
---|
110 | bool particleBeam::momentRepresentationOk() const { |
---|
111 | return momentRepresentationOk_; |
---|
112 | } |
---|
113 | |
---|
114 | void particleBeam::addParticle( bareParticle p) |
---|
115 | { |
---|
116 | goodPartic_.push_back(p); |
---|
117 | } |
---|
118 | |
---|
119 | const vector<bareParticle>& particleBeam::getParticleVector() const |
---|
120 | { |
---|
121 | return goodPartic_; |
---|
122 | } |
---|
123 | |
---|
124 | vector<bareParticle>& particleBeam::getParticleVector() |
---|
125 | { |
---|
126 | return goodPartic_; |
---|
127 | } |
---|
128 | |
---|
129 | void particleBeam::getVariance(double& varx, double& vary, double& varz) const { |
---|
130 | unsigned int k; |
---|
131 | double x,y,z; |
---|
132 | double xav = 0.; |
---|
133 | double yav = 0.; |
---|
134 | double zav = 0.; |
---|
135 | double xavsq = 0.; |
---|
136 | double yavsq = 0.; |
---|
137 | double zavsq = 0.; |
---|
138 | |
---|
139 | TRIDVECTOR pos; |
---|
140 | |
---|
141 | |
---|
142 | for ( k = 0 ; k < goodPartic_.size(); k++) { |
---|
143 | pos = goodPartic_.at(k).getPosition(); |
---|
144 | pos.getComponents(x,y,z); |
---|
145 | // partic_[k].getXYZ(x,y,z); |
---|
146 | xav += x; |
---|
147 | xavsq += x*x; |
---|
148 | yav += y; |
---|
149 | yavsq += y*y; |
---|
150 | zav += z; |
---|
151 | zavsq += z*z; |
---|
152 | } |
---|
153 | |
---|
154 | double aginv = double (goodPartic_.size()); |
---|
155 | aginv = 1.0/aginv; |
---|
156 | |
---|
157 | varx = aginv * ( xavsq - xav*xav*aginv ); |
---|
158 | vary = aginv * ( yavsq - yav*yav*aginv ); |
---|
159 | varz = aginv * ( zavsq - zav*zav*aginv ); |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | void particleBeam::printAllXYZ() const { |
---|
164 | cout << " dump du faisceau : " << endl; |
---|
165 | cout << goodPartic_.size() << " particules " << endl; |
---|
166 | unsigned int k; |
---|
167 | for ( k = 0 ; k < goodPartic_.size(); k++) |
---|
168 | { |
---|
169 | double xx,yy,zz; |
---|
170 | goodPartic_.at(k).getPosition().getComponents(xx,yy,zz); |
---|
171 | double betgamx, betgamy, betgamz; |
---|
172 | goodPartic_.at(k).getBetaGamma().getComponents(betgamx, betgamy, betgamz); |
---|
173 | cout << " part. numero " << k << " x= " << xx << " y= " << yy << " z= " << zz << " betgamx= " << betgamx << " betgamy= " << betgamy << " betgamz= " << betgamz << endl; |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | |
---|
179 | void particleBeam::Zrange(double& zmin, double& zmax) const { |
---|
180 | double z; |
---|
181 | zmin = GRAND; |
---|
182 | zmax = -zmin; |
---|
183 | |
---|
184 | unsigned int k; |
---|
185 | for ( k = 0 ; k < goodPartic_.size(); k++) |
---|
186 | { |
---|
187 | z = goodPartic_.at(k).getZ(); |
---|
188 | if ( z < zmin ) zmin = z; |
---|
189 | else if ( z > zmax) zmax = z; |
---|
190 | } |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | string particleBeam::FileOutputFlow() const { |
---|
196 | ostringstream sortie; |
---|
197 | unsigned int k; |
---|
198 | for ( k = 0 ; k < goodPartic_.size(); k++) |
---|
199 | { |
---|
200 | sortie << goodPartic_.at(k).FileOutputFlow() << endl; |
---|
201 | } |
---|
202 | sortie << endl; |
---|
203 | return sortie.str(); |
---|
204 | } |
---|
205 | |
---|
206 | bool particleBeam::FileInput( ifstream& ifs) { |
---|
207 | bool test = true; |
---|
208 | string dum1, dum2; |
---|
209 | double dummy; |
---|
210 | if ( !( ifs >> dum1 >> dum2 >> dummy) ) return false; |
---|
211 | |
---|
212 | bareParticle pp; |
---|
213 | while ( pp.FileInput(ifs) ) |
---|
214 | { |
---|
215 | addParticle( pp); |
---|
216 | } |
---|
217 | return test; |
---|
218 | } |
---|
219 | |
---|
220 | void particleBeam::buildMomentRepresentation() { |
---|
221 | |
---|
222 | unsigned k,j,m; |
---|
223 | double auxj, auxm; |
---|
224 | if ( !particleRepresentationOk_) |
---|
225 | { |
---|
226 | cerr << " particleBeam::buildMomentRepresentation() vecteur de particules invalide" << endl; |
---|
227 | return; |
---|
228 | } |
---|
229 | |
---|
230 | cout << " buildMomentRepresentation " << endl; |
---|
231 | // printAllXYZ(); |
---|
232 | |
---|
233 | double gref = referenceParticle_.getGamma() - 1.0; |
---|
234 | double P_reference_MeV_sur_c = sqrt( gref*(gref+2) ); |
---|
235 | |
---|
236 | cout << " gref = " << gref << " P_reference_MeV_sur_c = " << P_reference_MeV_sur_c << endl; |
---|
237 | |
---|
238 | |
---|
239 | // initialisation des moments |
---|
240 | razDesMoments(); |
---|
241 | |
---|
242 | // accumulation |
---|
243 | TRIDVECTOR pos; |
---|
244 | TRIDVECTOR begam; |
---|
245 | double gamma; |
---|
246 | double begamz; |
---|
247 | double g; |
---|
248 | double PMeVsc; |
---|
249 | double del; |
---|
250 | vector<double> part(6, 0.0); |
---|
251 | |
---|
252 | vector< vector<double> >& matrice = rij_.getMatrix(); |
---|
253 | |
---|
254 | |
---|
255 | for (k=0; k < goodPartic_.size(); k++) { |
---|
256 | gamma = goodPartic_.at(k).getGamma(); |
---|
257 | pos = goodPartic_.at(k).getPosition(); |
---|
258 | begam= goodPartic_.at(k).getBetaGamma(); |
---|
259 | begamz = begam.getComponent(2); |
---|
260 | g = gamma -1.0; |
---|
261 | PMeVsc = sqrt( g*(g+2) ); |
---|
262 | del = 100.0 * ( PMeVsc - P_reference_MeV_sur_c ) / P_reference_MeV_sur_c ; // en % |
---|
263 | |
---|
264 | part[0] = pos.getComponent(0); |
---|
265 | part[1] = begam.getComponent(0)/begamz; |
---|
266 | part[2] = pos.getComponent(1); |
---|
267 | part[3] = begam.getComponent(1)/begamz; |
---|
268 | part[4] = pos.getComponent(2); |
---|
269 | part[5] = del; |
---|
270 | |
---|
271 | for ( j = 0; j < 6; j++) { |
---|
272 | auxj = part.at(j) - centroid_.at(j); |
---|
273 | for (m=0; m <= j; m++) |
---|
274 | { |
---|
275 | auxm = part.at(m) - centroid_.at(m); |
---|
276 | |
---|
277 | ( matrice.at(j) ).at(m) += auxj*auxm; |
---|
278 | // ( rij_transportMoments_.at(j) ).at(m) += auxj*auxm; |
---|
279 | |
---|
280 | |
---|
281 | // cout << " j= " << j << " m= " << m << " rjm= " << ( rij_transportMoments_.at(j) ).at(m) << endl; |
---|
282 | } |
---|
283 | } |
---|
284 | } |
---|
285 | |
---|
286 | |
---|
287 | // moyenne |
---|
288 | double facmoy = 1.0/double( goodPartic_.size() ); |
---|
289 | for ( j = 0; j < 6; j++) { |
---|
290 | ( matrice.at(j) ).at(j) = sqrt(( matrice.at(j) ).at(j) * facmoy ); |
---|
291 | } |
---|
292 | |
---|
293 | for ( j = 0; j < 6; j++) { |
---|
294 | auxj = ( matrice.at(j) ).at(j); |
---|
295 | for (m=0; m < j; m++) { |
---|
296 | auxm = ( matrice.at(m) ).at(m); |
---|
297 | ( matrice.at(j) ).at(m) *= facmoy/(auxj * auxm); |
---|
298 | } |
---|
299 | } |
---|
300 | |
---|
301 | ////////////////// si C21 = 1 , transport plante ! a voir ////////// |
---|
302 | cout << " valeur initiale de C21: " << ( matrice.at(1) ).at(0) << endl; |
---|
303 | if ( ( matrice.at(1) ).at(0) >0.999999 ) { |
---|
304 | ( matrice.at(1) ).at(0) = 0.999999; |
---|
305 | cout << " j'ai fait la correction C21: " << ( matrice.at(1) ).at(0) << endl; |
---|
306 | } |
---|
307 | |
---|
308 | |
---|
309 | // les longueurs sont en cm |
---|
310 | // les angles en radians, on passe en mrad; |
---|
311 | |
---|
312 | double uniteAngle = 1.0e+3; |
---|
313 | ( matrice.at(1) ).at(1) *= uniteAngle; |
---|
314 | ( matrice.at(3) ).at(3) *= uniteAngle; |
---|
315 | P0Transport_ = 1.0e-3*EREST_MeV*P_reference_MeV_sur_c; |
---|
316 | |
---|
317 | // cout << " buildmomentrepresentation impression des moments " << endl; |
---|
318 | // impressionDesMoments(); |
---|
319 | |
---|
320 | momentRepresentationOk_ = true; |
---|
321 | } |
---|
322 | |
---|
323 | void particleBeam::impressionDesMoments() const { |
---|
324 | rij_.impression(); |
---|
325 | } |
---|
326 | |
---|
327 | void particleBeam::razDesMoments() { |
---|
328 | rij_.raz(); |
---|
329 | } |
---|
330 | |
---|
331 | |
---|
332 | // void particleBeam::readTransportMoments(ifstream& inp) { |
---|
333 | // rij_.readFromTransportOutput(inp); |
---|
334 | // } |
---|
335 | |
---|
336 | // void particleBeam::readTransportMoments(stringstream& inp) { |
---|
337 | // rij_.readFromTransportOutput(inp); |
---|
338 | // } |
---|
339 | |
---|
340 | double particleBeam::getXmaxRms() { |
---|
341 | if ( !momentRepresentationOk_ ) buildMomentRepresentation(); |
---|
342 | return ( rij_.getMatrix().at(0) ).at(0); |
---|
343 | // return ( rij_transportMoments_.at(0) ).at(0); |
---|
344 | } |
---|
345 | |
---|
346 | |
---|
347 | void particleBeam::particlesPhaseSpaceData(vector<double>& xcor, vector<double>& ycor, vector<string>& legende, string namex, string namey) { |
---|
348 | |
---|
349 | unsigned indexAbs, indexOrd; |
---|
350 | indexAbs = pspaCoorIndexFromString(namex); |
---|
351 | indexOrd = pspaCoorIndexFromString(namey); |
---|
352 | |
---|
353 | particlesPhaseSpaceComponent(xcor, indexAbs); |
---|
354 | particlesPhaseSpaceComponent(ycor, indexOrd); |
---|
355 | legende.clear(); |
---|
356 | legende.push_back( "phase space " + namex + "," + namey); |
---|
357 | legende.push_back( "particle number : " + mixedTools::intToString(getNbParticles())); |
---|
358 | } |
---|
359 | |
---|
360 | // renvoie (dans le vecteur coord) la liste des coordonnées d'index 'index' : |
---|
361 | // index = 0 , 1, 2 -> x,y,z |
---|
362 | // index = 3,4 -> x' = betax/betaz , y' = betay/betaz |
---|
363 | // index = 5 -> Ec : energie cinetique |
---|
364 | void particleBeam::particlesPhaseSpaceComponent(vector<double>& coord, unsigned index) |
---|
365 | { |
---|
366 | if ( !particleRepresentationOk_ ) return; |
---|
367 | |
---|
368 | coord.clear(); |
---|
369 | coord.resize(goodPartic_.size(), 0.0 ); |
---|
370 | cout << " particleBeam::particlesPhaseSpaceComponent index = " << index << endl; |
---|
371 | |
---|
372 | if ( index <= 2 ) { |
---|
373 | for (unsigned i = 0; i < goodPartic_.size(); ++i) { |
---|
374 | coord.at(i) = 10.*goodPartic_.at(i).getPosition().getComponent(index); // en mm |
---|
375 | } |
---|
376 | return; |
---|
377 | } |
---|
378 | |
---|
379 | if ( index > 2 && index < 5 ) { |
---|
380 | for (unsigned i = 0; i < goodPartic_.size(); ++i) { |
---|
381 | double begamz = goodPartic_.at(i).getBetaGamma().getComponent(2); |
---|
382 | if ( begamz != 0.0) { |
---|
383 | coord.at(i) = 1000.*goodPartic_.at(i).getBetaGamma().getComponent(index - 3)/begamz; // milliradians |
---|
384 | } else { |
---|
385 | coord.at(i) = 0.0; |
---|
386 | } |
---|
387 | } |
---|
388 | return; |
---|
389 | } |
---|
390 | |
---|
391 | if ( index == 5 ) { |
---|
392 | double gamma0 = referenceParticle_.getGamma(); |
---|
393 | if ( gamma0 == 0.0 ) return; |
---|
394 | for (unsigned i = 0; i < goodPartic_.size(); ++i) { |
---|
395 | coord.at(i) = 100.*(goodPartic_.at(i).getGamma() - gamma0)/gamma0; // en % |
---|
396 | } |
---|
397 | return; |
---|
398 | } |
---|
399 | } |
---|
400 | |
---|
401 | unsigned particleBeam::indexFromPspaToTransport(unsigned index) const { |
---|
402 | cout << " indexFromPspaToTransport entree : " << index << endl; |
---|
403 | switch ( index ) { |
---|
404 | case 0 : return 0; // x |
---|
405 | case 1 : return 2; // y |
---|
406 | case 2 : return 4; // z -> l |
---|
407 | case 3 : return 1; // xp |
---|
408 | case 4 : return 3; // yp |
---|
409 | case 5 : return 5; // de/E |
---|
410 | default : { |
---|
411 | cout << " particleBeam::indexFromPspaToTransport : coordinate index ERROR inital index : "<< index << endl; |
---|
412 | return 99; |
---|
413 | } |
---|
414 | } |
---|
415 | } |
---|
416 | |
---|
417 | unsigned particleBeam::pspaCoorIndexFromString(string nameCoor) const { |
---|
418 | if ( nameCoor == "x" ) { |
---|
419 | return 0; |
---|
420 | } else if ( nameCoor == "y" ) { |
---|
421 | return 1; |
---|
422 | } else if ( nameCoor == "dz" ) { |
---|
423 | return 2; |
---|
424 | } else if ( nameCoor == "xp" ) { |
---|
425 | return 3; |
---|
426 | } else if ( nameCoor == "yp" ) { |
---|
427 | return 4; |
---|
428 | } else if ( nameCoor == "dE/E" ) { |
---|
429 | return 5; |
---|
430 | } else { |
---|
431 | return 99; |
---|
432 | } |
---|
433 | } |
---|
434 | |
---|
435 | unsigned particleBeam::transportCoorIndexFromString(string nameCoor) const { |
---|
436 | if ( nameCoor == "x" ) { |
---|
437 | return 0; |
---|
438 | } else if ( nameCoor == "y" ) { |
---|
439 | return 2; |
---|
440 | } else if ( nameCoor == "dz" ) { |
---|
441 | return 4; |
---|
442 | } else if ( nameCoor == "xp" ) { |
---|
443 | return 1; |
---|
444 | } else if ( nameCoor == "yp" ) { |
---|
445 | return 3; |
---|
446 | } else if ( nameCoor == "dE/E" ) { |
---|
447 | return 5; |
---|
448 | } else { |
---|
449 | return 99; |
---|
450 | } |
---|
451 | } |
---|
452 | |
---|
453 | //void particleBeam::donneesDessinEllipse(vector<double>& xcor, vector<double>& ycor, vector<string>& legende, unsigned indexAbs, unsigned indexOrd) { |
---|
454 | |
---|
455 | void particleBeam::donneesDessinEllipse(vector<double>& xcor, vector<double>& ycor, vector<string>& legende, string namex, string namey) { |
---|
456 | int k; |
---|
457 | double x,y; |
---|
458 | if ( !momentRepresentationOk_ ) buildMomentRepresentation(); |
---|
459 | |
---|
460 | // if ( !momentRepresentationOk_ ) return; |
---|
461 | |
---|
462 | unsigned indexAbs, indexOrd; |
---|
463 | |
---|
464 | |
---|
465 | // index TRANSPORT |
---|
466 | indexAbs = transportCoorIndexFromString(namex); |
---|
467 | indexOrd = transportCoorIndexFromString(namey); |
---|
468 | cout << " namex= " << namex << " indexAbs= " << indexAbs << " namey= " << namey << " indexOrd= " << indexOrd << endl; |
---|
469 | if ( indexAbs > 5 || indexOrd > 5 ) return; |
---|
470 | |
---|
471 | xcor.clear(); |
---|
472 | ycor.clear(); |
---|
473 | |
---|
474 | |
---|
475 | |
---|
476 | double dimensionalFactorX, dimensionalFactorY; // to mm, if necessary |
---|
477 | dimensionalFactorX = dimensionalFactorFromTransportToGraphics(indexAbs); |
---|
478 | dimensionalFactorY = dimensionalFactorFromTransportToGraphics(indexOrd); |
---|
479 | |
---|
480 | |
---|
481 | |
---|
482 | legende.clear(); |
---|
483 | // if ( indexAbs == 0 && indexOrd == 1 ) { |
---|
484 | string namx = transportVariableName(indexAbs); |
---|
485 | string namy = transportVariableName(indexOrd); |
---|
486 | double em = getUnnormalizedTranspPhaseSpaceArea(indexAbs,indexOrd) ; |
---|
487 | string emitt = mixedTools::doubleToString(getUnnormalizedTranspPhaseSpaceArea(indexAbs,indexOrd)); |
---|
488 | string xmax = namx + "max= "; |
---|
489 | string valXmax = mixedTools::doubleToString(dimensionalFactorX*getSigmaTransportij(indexAbs,indexAbs)); |
---|
490 | string ymax = namy + "max= "; |
---|
491 | string valYmax = mixedTools::doubleToString(dimensionalFactorY*getSigmaTransportij(indexOrd,indexOrd)); // mm |
---|
492 | string correl = " correlation "; |
---|
493 | string valCorrel = mixedTools::doubleToString(getSigmaTransportij(1,0)); |
---|
494 | string xunit = graphicTransportUnitName(indexAbs); |
---|
495 | string yunit = graphicTransportUnitName(indexOrd); |
---|
496 | legende.push_back( "emittance" + namx + "," + namy + ": " + emitt + " pi." + xunit + "." + yunit); |
---|
497 | legende.push_back( xmax + valXmax + xunit); |
---|
498 | legende.push_back( ymax + valYmax + yunit); |
---|
499 | // } else { |
---|
500 | // legende.push_back(" text of legend not yet programmed "); |
---|
501 | // } |
---|
502 | |
---|
503 | cout << " index x" << indexAbs << " index y " << indexOrd << endl; |
---|
504 | double xm = dimensionalFactorX*( rij_.getMatrix().at(indexAbs) ).at(indexAbs); |
---|
505 | double ym = dimensionalFactorY*( rij_.getMatrix().at(indexOrd) ).at(indexOrd); |
---|
506 | double r; |
---|
507 | if ( indexOrd > indexAbs ) { |
---|
508 | r = ( rij_.getMatrix().at(indexOrd) ).at(indexAbs); |
---|
509 | } else { |
---|
510 | r = ( rij_.getMatrix().at(indexAbs) ).at(indexOrd); |
---|
511 | } |
---|
512 | |
---|
513 | cout << " racs11= " << xm << " racs22= " << ym << " r12= " << r << endl; |
---|
514 | |
---|
515 | |
---|
516 | int nbintv = 50; |
---|
517 | if ( xm == 0.0 ) return; |
---|
518 | double pas = 2.0 * xm / nbintv; |
---|
519 | |
---|
520 | // cout << " r= " << r << endl; |
---|
521 | double rac = (1 - r*r); |
---|
522 | if ( rac > 0.0 ) |
---|
523 | { |
---|
524 | cout << " cas rac > " << endl; |
---|
525 | rac = sqrt(1 - r*r); |
---|
526 | double alpha = -r / rac; |
---|
527 | double beta = xm / ( ym * rac); |
---|
528 | // double gamma = ym / ( xm * rac ); |
---|
529 | double epsil = xm * ym * rac; |
---|
530 | double fac1 = -1.0 / ( beta * beta); |
---|
531 | double fac2 = epsil/beta; |
---|
532 | double fac3 = -alpha/beta; |
---|
533 | double aux; |
---|
534 | for ( k=0; k < nbintv; k++) |
---|
535 | { |
---|
536 | x = -xm + k*pas; |
---|
537 | aux = fac1 * x * x + fac2; |
---|
538 | // cout << " aux2= " << aux << endl; |
---|
539 | if ( aux <= 0.0 ) |
---|
540 | { |
---|
541 | aux = 0.0; |
---|
542 | } |
---|
543 | else aux = sqrt(aux); |
---|
544 | |
---|
545 | // y = fac3*x; |
---|
546 | y = fac3*x + aux; |
---|
547 | xcor.push_back(x); |
---|
548 | ycor.push_back(y); |
---|
549 | } |
---|
550 | |
---|
551 | for ( k=0; k <= nbintv; k++) |
---|
552 | { |
---|
553 | x = xm - k*pas; |
---|
554 | aux = fac1 * x * x + fac2; |
---|
555 | if ( aux <= 0.0 ) |
---|
556 | { |
---|
557 | aux = 0.0; |
---|
558 | } |
---|
559 | else aux = sqrt(aux); |
---|
560 | // y = fac3*x; |
---|
561 | y = fac3*x - aux; |
---|
562 | xcor.push_back(x); |
---|
563 | ycor.push_back(y); |
---|
564 | } |
---|
565 | } |
---|
566 | else |
---|
567 | // cas degenere |
---|
568 | { |
---|
569 | cout << " cas degenere " << endl; |
---|
570 | double fac = ym/xm; |
---|
571 | for ( k=0; k < nbintv; k++) |
---|
572 | { |
---|
573 | x = -xm + k*pas; |
---|
574 | y = fac*x; |
---|
575 | xcor.push_back(x); |
---|
576 | ycor.push_back(y); |
---|
577 | } |
---|
578 | |
---|
579 | } |
---|
580 | } |
---|
581 | |
---|
582 | void particleBeam::histogramme(unsigned int iabs,vector<double>& xcor,vector<int>& hist,double out[3]) |
---|
583 | { |
---|
584 | // out[0]= nbre de particules, out[1]= moyenne, out[2]= ecart-type |
---|
585 | vector<double> vshf; |
---|
586 | particlesPhaseSpaceComponent(vshf,iabs); |
---|
587 | histogramInitialize(iabs,vshf,out); |
---|
588 | histogramPacking(out[2],vshf,xcor,hist); |
---|
589 | |
---|
590 | if(iabs == 5) { |
---|
591 | out[1] *= EREST_MeV; // moyenne en MeV |
---|
592 | out[2] *= EREST_keV; // ecart-type en KeV |
---|
593 | } |
---|
594 | } |
---|
595 | |
---|
596 | void particleBeam::histogramInitialize(unsigned int index,vector<double>& vshf,double out[3]) |
---|
597 | { |
---|
598 | double vmin= GRAND; |
---|
599 | double vmax= -vmin; |
---|
600 | double vmoy= 0.0; |
---|
601 | double ecatyp= 0.0; |
---|
602 | |
---|
603 | for (unsigned int k = 0; k < goodPartic_.size(); k++) { |
---|
604 | if (vshf[k] < vmin) vmin = vshf[k]; |
---|
605 | else if (vshf[k] > vmax) vmax = vshf[k]; |
---|
606 | vmoy += vshf[k]; |
---|
607 | ecatyp += vshf[k]*vshf[k]; |
---|
608 | } |
---|
609 | |
---|
610 | double sum= (float)goodPartic_.size(); |
---|
611 | out[0]= sum; |
---|
612 | vmoy /= sum; |
---|
613 | out[1]= vmoy; |
---|
614 | ecatyp /= sum; |
---|
615 | ecatyp = sqrt(abs(ecatyp-vmoy*vmoy)); |
---|
616 | out[2]= ecatyp; |
---|
617 | |
---|
618 | if(index == 0) { |
---|
619 | cout << "position x -moyenne " << vmoy << " cm " << "-mini " << vmin << " cm " << "-maxi " << vmax << " cm " << "ecart type " << ecatyp << " cm" << endl; |
---|
620 | } |
---|
621 | if(index == 1) { |
---|
622 | cout << "position y -moyenne " << vmoy << " cm " << "-mini " << vmin << " cm " << "-maxi " << vmax << " cm " << "ecart type " << ecatyp << " cm" << endl; |
---|
623 | } |
---|
624 | if(index == 2) { |
---|
625 | cout << "position z -moyenne " << vmoy << " cm " << "-mini " << vmin << " cm " << "-maxi " << vmax << " cm " << "ecart type " << ecatyp << " cm" << endl; |
---|
626 | } |
---|
627 | if(index == 3) { |
---|
628 | cout << "divergence xp -moyenne " << vmoy << " mrad " << "-mini " << vmin << " mrad " << "-maxi " << vmax << " mrad " << "ecart type " << ecatyp << " mrad" << endl; |
---|
629 | } |
---|
630 | if(index == 4) { |
---|
631 | cout << "divergence yp -moyenne " << vmoy << " mrad " << "-mini " << vmin << " mrad " << "-maxi " << vmax << " mrad " << "ecart type " << ecatyp << " mrad" << endl; |
---|
632 | } |
---|
633 | if(index == 5) { |
---|
634 | double gmin = vmin-1.0; |
---|
635 | double gmax = vmax-1.0; |
---|
636 | cout << "energie cinetique -moyenne " << vmoy*EREST_MeV << " Mev " << "-mini " << gmin*EREST_MeV << " Mev " << "-maxi " << gmax*EREST_MeV << " Mev " << "ecart type " << ecatyp*EREST_MeV << " Kev" << endl; |
---|
637 | } |
---|
638 | |
---|
639 | for (unsigned int k = 0; k < goodPartic_.size(); k++) { |
---|
640 | vshf[k] -= vmoy; |
---|
641 | } |
---|
642 | } |
---|
643 | |
---|
644 | void particleBeam::histogramPacking(double ecatyp,vector<double>vshf,vector<double>&xcor,vector<int>& hist) |
---|
645 | { |
---|
646 | // demi fenetre hfene= max(3.*ecatyp-vmoy,vmoy-3.*ecatyp); |
---|
647 | double hfene= 3.*ecatyp; |
---|
648 | // et pas de l'histogramme |
---|
649 | double hpas = hfene/25.; |
---|
650 | |
---|
651 | cout << "demi fenetre " << hfene << ", hpas= " << hpas << endl; |
---|
652 | |
---|
653 | double vmin = -hfene; |
---|
654 | double dfen = 2.*hfene; |
---|
655 | int ihist = dfen/hpas; |
---|
656 | double phist = ihist*hpas; |
---|
657 | double dpas = hpas-(dfen-phist); |
---|
658 | if(dpas <= hpas*1.e-03) { |
---|
659 | ihist++; |
---|
660 | phist= ihist*hpas; |
---|
661 | } |
---|
662 | double vmax= vmin+hpas*ihist; |
---|
663 | |
---|
664 | cout << "xAxisNumberOfBins= " << ihist <<", xAxisMinimum= " << vmin << ", xAxisMaximum= " << vmax << ", NParticules= " << vshf.size() << ", phist " << phist << endl; |
---|
665 | |
---|
666 | if(!xcor.empty()) xcor.clear(); |
---|
667 | xcor.resize(ihist+1); |
---|
668 | for (int i = 0; i <= ihist; ++i) { |
---|
669 | xcor[i] = vmin+i*hpas; |
---|
670 | } |
---|
671 | |
---|
672 | ///////////////////////////////////// |
---|
673 | |
---|
674 | if(!hist.empty()) hist.clear(); |
---|
675 | hist.resize(ihist,0); |
---|
676 | for (unsigned int i = 0; i < vshf.size(); ++i) { |
---|
677 | double var= vshf[i]-vmin; |
---|
678 | if(var < 0 ) { |
---|
679 | cout<<"lesser that the minimum "<<var<<", ("<< i<<")"<< endl; |
---|
680 | hist.at(0)++; |
---|
681 | } else if(var >= phist) { |
---|
682 | cout<<"greater that the maximum "<<var<<", ("<< i<<")"<< endl; |
---|
683 | hist.at(ihist-1)++; |
---|
684 | } else { |
---|
685 | int kk= (int)floor(var/hpas); |
---|
686 | hist.at(kk)++; |
---|
687 | } |
---|
688 | } |
---|
689 | } |
---|
690 | |
---|