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

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

mise a jour des manipulations de faisceau

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