Changeset 362 in PSPA for Interface_Web/trunk/pspaWT/sources/controler/src
- Timestamp:
- Mar 5, 2013, 11:48:58 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Interface_Web/trunk/pspaWT/sources/controler/src/particleBeam.cc
r356 r362 510 510 } 511 511 512 void particleBeam::histogramme(int iabs,vector<double>&xcor,vector<int>& hist,int& cnts,double out[3]) 513 { 514 vector<double> vshf; 515 preparationDesHistogrammes(iabs,vshf,out); 516 remplissageDesHistogrammes(out,vshf,xcor,hist,cnts); 517 518 // sortie pour la legende: out[0]= entries, out[1]= mean, out[2]= std deviation 519 if(iabs < 3) { 520 out[1] *= 1.0 ; // en m ? 521 out[2] *= 1000.0; //mm 522 } else { 523 out[1] *= EREST_MeV ; //MeV 524 out[2] *= EREST_keV; //KeV 525 } 526 } 527 528 void particleBeam::preparationDesHistogrammes(int index,vector<double>& vshf,double out[3]) 529 { 530 double vmin= GRAND; 531 double vmax= -vmin; 532 double vmoy= 0.0; 533 double ecatyp= 0.0; 534 535 double sum= (float)goodPartic_.size(); 536 if(index < 3) 537 { 538 // collecte d'une coordonnee x(index= 0), y(index= 1) ou z(index= 2) des particules 539 for (unsigned int k = 0; k < goodPartic_.size(); k++) { 540 double val = goodPartic_.at(k).getPosition().getComponent(index); 541 if (val < vmin) vmin = val; 542 else if (val > vmax) vmax = val; 543 vmoy += val; 544 ecatyp += val*val; 545 } 546 547 out[0]= sum; 548 vmoy /= sum; 549 out[1]= vmoy; 550 ecatyp /= sum; 551 ecatyp = sqrt(abs(ecatyp-vmoy*vmoy)); 552 out[2]= ecatyp; 553 } 554 else 555 { 556 // collecte de l'energie acquise par les particules 557 for (unsigned int k = 0; k < goodPartic_.size(); k++) { 558 double gamma = goodPartic_.at(k).getGamma(); 559 if (gamma < vmin) vmin = gamma; 560 else if (gamma > vmax) vmax = gamma; 561 double val = gamma-1.0; 562 vmoy += val; 563 ecatyp += val*val; 564 } 565 566 out[0]= sum; 567 vmoy /= sum; 568 out[1]= vmoy; 569 ecatyp /= sum; 570 ecatyp = sqrt(abs(ecatyp-vmoy*vmoy)); 571 out[2]= ecatyp; 572 } 573 574 if(index == 0) { 575 cout << "position X -moyenne " << vmoy << " m " << "-mini " << vmin << " m " << "-maxi " << vmax << " m " << "ecart type " << ecatyp*1000.0 << " mm" << endl; 576 } else if(index == 1) { 577 cout << "position Y -moyenne " << vmoy << " m " << "-mini " << vmin << " m " << "-maxi " << vmax << " m " << "ecart type " << ecatyp*1000.0 << " mm" << endl; 578 } else if(index == 2) { 579 cout << "position Z -moyenne " << vmoy << " m " << "-mini " << vmin << " m " << "-maxi " << vmax << " m " << "ecart type " << ecatyp*1000.0 << " mm" << endl; 580 } else { 581 double gmin = vmin-1.0; 582 double gmax = vmax-1.0; 583 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; 584 } 585 586 //pouVoir: autre maniere de calculer l'ecart-type 587 double stdev= 0.0; 588 589 if(!vshf.empty()) vshf.clear(); 590 vshf.resize(goodPartic_.size()); 591 if(index < 3) 592 { 593 for (unsigned int k = 0; k < goodPartic_.size(); k++) { 594 double val = goodPartic_.at(k).getPosition().getComponent(index); 595 vshf[k]= val-vmoy; 596 stdev += vshf[k]*vshf[k]; 597 } 598 } 599 else 600 { 601 for (unsigned int k = 0; k < goodPartic_.size(); k++) { 602 double gamma = goodPartic_.at(k).getGamma(); 603 double val = gamma-1.0; 604 vshf[k]= val-vmoy; 605 stdev += vshf[k]*vshf[k]; 606 } 607 } 608 609 stdev /= sum; 610 stdev = sqrt(stdev); 611 cout << "stdev " << stdev << ", ecatyp " << ecatyp << ", diff " << stdev-ecatyp << endl; 612 } 613 614 void particleBeam::remplissageDesHistogrammes(double out[3],vector<double>vshf,vector<double>&xcor,vector<int>& hist,int& cnts) 615 { 616 // recupere la moyenne et l'ecart-type 617 double vmoy= out[1]; 618 double ecatyp= out[2]; 619 620 // demi fenetre hfene= max(3.*ecatyp-vmoy,vmoy-3.*ecatyp); 621 double hfene= 3.*ecatyp; 622 // et pas de l'histogramme 623 double hpas = hfene/25.; 624 625 cout << "demi fenetre " << hfene << ", hpas= " << hpas << endl; 626 627 double vmin = -hfene; 628 double dfen = 2.*hfene; 629 int ihist = dfen/hpas; 630 double phist = ihist*hpas; 631 double dpas = hpas-(dfen-phist); 632 if(dpas <= hpas*1.e-03) { 633 ihist++; 634 phist= ihist*hpas; 635 } 636 double vmax= vmin+hpas*ihist; 637 638 cout << "'xAxisNumberOfBins= " << ihist <<", xAxisMinimum= " << vmin << ", xAxisMaximum= " << vmax << ", NParticules= " << vshf.size() << ", phist " << phist << endl; 639 640 if(!xcor.empty()) xcor.clear(); 641 xcor.resize(ihist); 642 for (int i = 0; i < ihist; ++i) { 643 644 // on gradue l'abscisse en pourcents 645 xcor[i]= 100.*( vmin+i*hpas )/vmoy; 646 } 647 648 if(!hist.empty()) hist.clear(); 649 hist.resize(ihist,0); 650 for (unsigned i = 0; i < vshf.size(); ++i) { 651 double var= vshf[i]-vmin; 652 if(var < 0 ) { 653 cout<<"lesser that the minimum "<<var<<", ("<< i<<")"<< endl; 654 hist[0]++; 655 } 656 657 if(var >= phist) { 658 cout<<"greater that the maximum "<<var<<", ("<< i<<")"<< endl; 659 hist[ihist-1]++; 660 } 661 662 int kk= (int)floor(var/hpas); 663 hist[kk]++; 664 } 665 666 cnts= 0; 667 for (int i = 0; i < ihist; ++i) { 668 if(hist.at(i) > 0) cnts++; 669 } 670 cout<< " ... cnts= " << cnts << endl; 671 } 672 512 673 void particleBeam::histogramme(vector<double>&xcor,vector<int>& hist,int& cnts,double out[3]) 513 674 {
Note: See TracChangeset
for help on using the changeset viewer.