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