Changeset 224 in PSPA


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

embryon d'histo... à completer

Location:
Interface_Web/trunk/pspaWT
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Interface_Web/trunk/pspaWT/include/GWt_pspaApplication.h

    r200 r224  
    9292 bool removeExtensionFromConfigName(string& config);
    9393
     94 void dessinerHistogramme();
     95
    9496 public :
    9597
  • Interface_Web/trunk/pspaWT/include/particleBeam.h

    r222 r224  
    110110  virtual bool FileInput(ifstream& ifs);
    111111
    112 
     112  void histogramme(vector<double>&xcor,vector<int>& hist,int& cnts);
    113113};
    114114
  • Interface_Web/trunk/pspaWT/src/GWt_pspaApplication.cc

    r223 r224  
    246246  dessin->addWidget(okEnv);
    247247 okEnv->clicked().connect(this, &PspaApplication::dessinerEnveloppe);
     248
     249 /////////////////////////////////////////////////////////////////////
     250 dessin->addWidget(new WText(" histogramme :  "));
     251 WPushButton* okHisto = new WPushButton("histogramme");
     252 dessin->addWidget(okHisto);
     253 okHisto->clicked().connect(this,&PspaApplication::dessinerHistogramme);
     254 /////////////////////////////////////////////////////////////////////
    248255
    249256  toto_ = new WContainerWidget();
     
    905912    return test;
    906913}
     914
     915/////////////////////////
     916//   c'est un embryon d'histogramme
     917
     918void PspaApplication::dessinerHistogramme()
     919{
     920  // pour mon test : histo en energie
     921  toto_->clear();
     922
     923  GWt_dialog* pourVoir= new GWt_dialog("histogramme",toto_,false);
     924  pourVoir->setMinimumSize(400,400);
     925  pourVoir->setClosable(true);
     926  pourVoir->show();
     927
     928
     929  particleBeam* beam = dtmanage_->getDiagnosticBeam(1);
     930  vector<double> xcor;
     931  vector<int> hist;
     932  int cnts;
     933  beam->histogramme(xcor,hist,cnts);
     934
     935  cout<<"xcor.size()= "<<xcor.size()<<", hist.size()= "<<hist.size()<<endl;
     936
     937  //////////////////////////////////////////////////////////////////////////////////
     938
     939  WContainerWidget *w = toto_;
     940  int nbpts= xcor.size()+cnts+1;
     941  WStandardItemModel *model = new WStandardItemModel(nbpts,2,w);
     942  model->setHeaderData(1, WString("energie"));
     943
     944  int j= 0;
     945  if(hist[0] > 0) {
     946    model->setData(j,0,xcor[0]);
     947    model->setData(j,1,hist[0]);
     948    j++;
     949  }
     950  model->setData(j,0,xcor[0]);
     951  model->setData(j,1,hist[0]);
     952  j++;
     953  for (int i = 1; i < nbpts; ++i) {
     954    if(hist[i] == 0) {
     955      if(hist[i-1] > 0) {
     956        model->setData(j,0,xcor[i]);
     957        model->setData(j,1,hist[i-1]);
     958        j++;
     959      }
     960      model->setData(j,0,xcor[i]);
     961      model->setData(j,1,hist[i]);
     962      j++;
     963    }
     964    if(hist[i] > 0) {
     965      model->setData(j,0,xcor[i]);
     966      model->setData(j,1,hist[i-1]);
     967      j++;
     968      model->setData(j,0,xcor[i]);
     969      model->setData(j,1,hist[i]);
     970      j++;
     971    } 
     972  }
     973 
     974  WCartesianChart *chart = new WCartesianChart(w);
     975  chart->setTitle("Histogramme");
     976  chart->setModel(model);        // set the model
     977  chart->setXSeriesColumn(0);    // set the column that holds the categories
     978  chart->setLegendEnabled(true); // enable the legend
     979
     980   // Provide space for the X and Y axis and title.
     981  chart->setPlotAreaPadding(200, Right);
     982  chart->setPlotAreaPadding(80, Left);
     983  chart->setPlotAreaPadding(40, Top | Bottom);
     984
     985  chart->setType(ScatterPlot);
     986 
     987  WAxis& axis = chart->axis(XAxis);
     988  axis.setLabelFormat("%.1f");
     989  axis.setGridLinesEnabled(true);
     990  chart->axis(Y1Axis).setGridLinesEnabled(true);
     991
     992  WDataSeries s(1, LineSeries);
     993  chart->addSeries(s);
     994 
     995
     996  chart->resize(800, 400);
     997
     998  chart->setMargin(10, Top | Bottom);
     999  chart->setMargin(WLength::Auto, Left | Right);
     1000
     1001  LegendLocation location = LegendOutside;
     1002  Side side = Right;
     1003  AlignmentFlag alignment = AlignMiddle;
     1004  chart->setLegendLocation(location, side, alignment);
     1005  chart->setLegendStyle(chart->legendFont(), WPen(black), WBrush(WColor(0xFF, 0xFA, 0xE5)));
     1006 }
  • 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.