Ignore:
Timestamp:
Dec 21, 2012, 5:30:31 PM (12 years ago)
Author:
touze
Message:

embryon d'histo... à completer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Interface_Web/trunk/pspaWT/src/particleBeam.cc

    r222 r224  
    519519    }
    520520}
     521
     522void particleBeam::histogramme(vector<double>&xcor,vector<int>& hist,int& cnts)
     523{
     524  double gammin= GRAND;
     525  double gammax= -gammin;
     526  double Emoy= 0.0;
     527  double ecatyp= 0.0;
     528
     529  for (unsigned int k = 0; k < goodPartic_.size(); k++)
     530    {
     531      double gamma = goodPartic_.at(k).getGamma();
     532      double EMev = (gamma-1.0)*ERESTMeV;
     533      if (gamma < gammin) gammin = gamma;
     534      else if (gamma > gammax) gammax = gamma;
     535      Emoy += EMev;
     536      ecatyp += EMev*EMev;
     537    }
     538
     539  double sum= (float)goodPartic_.size();
     540  Emoy /= sum;
     541  ecatyp /= sum;
     542  ecatyp = sqrt(abs(ecatyp-Emoy*Emoy));
     543
     544  double Emin = (gammin-1.0)*ERESTMeV;
     545  double Emax = (gammax-1.0)*ERESTMeV;
     546  cout << "energie cinetique -moyenne " << Emoy << " Mev " << "-mini " << Emin << " Mev " << "-maxi " << Emax << " Mev " << "ecart type " << ecatyp*1000.0 << " Kev" << endl;
     547
     548  vector<double> Eshf;
     549  for (unsigned int k = 0; k < goodPartic_.size(); k++)
     550    {
     551      double gamma = goodPartic_.at(k).getGamma();
     552      double EMev = (gamma-1.0)*ERESTMeV;
     553      Eshf.push_back(EMev-Emoy);
     554    }
     555
     556  //////////////////////////////////////////////////////////////////////////////
     557 
     558  // demi fenetre en energie, et pas de l'histogramme
     559  double hfene= max(3.*ecatyp-Emoy,Emoy-3.*ecatyp);
     560  double hpas = hfene/50.;
     561
     562  cout << "demi fenetre " << hfene << ", hpas= " << hpas << endl;
     563
     564  double vmin = -hfene;
     565  double dfen = 2.*hfene;
     566  int ihist = dfen/hpas;
     567  double phist = ihist*hpas;
     568  double dpas = hpas-(dfen-phist);
     569  if(dpas <= hpas*1.e-03) {
     570    ihist++;
     571    phist= ihist*hpas;
     572  }
     573  double vmax= vmin+hpas*ihist;
     574 
     575  cout << "'xAxisNumberOfBins= " << ihist <<", xAxisMinimum= " << vmin << ", xAxisMaximum= " << vmax << ", NParticules= " << Eshf.size() << ", phist " << phist << endl;
     576
     577  xcor= vector<double>(ihist);
     578  for (unsigned i = 0; i < ihist; ++i) {
     579    xcor[i]= vmin+i*hpas;
     580  }
     581
     582  hist= vector<int>(ihist,0);
     583  for (unsigned i = 0; i < Eshf.size(); ++i) {
     584    double var= Eshf[i]-vmin;
     585    if(var < 0 || var >= phist) cout<<"out of range "<<var<<", ("<< i<<")"<< endl;
     586    int k= var/hpas;
     587    int kk= (int)floor(var/hpas);
     588    if(i%20 == 0) cout<<"v("<<i<<")= " <<var<<" ["<<k<<"-"<<kk<<"], "<<endl;
     589    hist[kk]++;
     590  }
     591
     592  cnts= 0;
     593  for (unsigned i = 0; i < ihist; ++i) {
     594    if(hist.at(i) > 0) cnts++;
     595    cout<<"("<<xcor.at(i)<<","<<hist.at(i)<<") ";
     596  }
     597  cout<< " ... cnts=  " << cnts << endl;
     598}
Note: See TracChangeset for help on using the changeset viewer.