source: PSPA/Interface_Web/trunk/pspaWT/sources/controler/src/particleBeam.cc @ 435

Last change on this file since 435 was 435, checked in by lemeur, 11 years ago

corrections traces (divisions par 0)

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