/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Tof/tofcalgsec/tofcalgsec-00-02-21/src/TofCalib.cxx

Go to the documentation of this file.
00001 #include "tofcalgsec/TofCalib.h"
00002 #include <iostream>
00003 #include <ios>
00004 #include <fstream>
00005 
00006 using namespace CLHEP;
00007 
00008 void TofCalib::reset() {
00009   F = HepMatrix(Npar,Npar,0);
00010   Y = HepVector(Npar,0);
00011   X = HepVector(Npar,0);
00012   funcs  = HepVector(Npar,0);
00013   return;
00014 }
00015 
00016 
00017 void TofCalib::calculate( RecordSet*& data, unsigned int icounter ) {
00018 
00019   std::cout << setiosflags(ios::left) << setw(10) << icounter << setw(8) << data->size() << setw(30) << name() << std::endl;
00020 
00021   if( data->size() <= 0 ) {
00022     X = HepVector(Npar,1.0);
00023   }
00024   else {
00025     std::vector<Record*>::iterator iter = data->begin();
00026     for( ; iter!=data->end(); iter++ ) {
00027       calculate_funcs( (*iter) );
00028       for( int i=0; i<F.num_col(); i++ ) {
00029         for( int j=0; j<F.num_col(); j++ ) {
00030           F[i][j]+=funcs[i]*funcs[j];
00031         }
00032       }
00033       
00034       calculate_y( (*iter) );
00035       for( int k=0; k<Y.num_row(); k++ ) {
00036         Y[k]+=y*funcs[k];
00037       }
00038     }
00039 
00040     //    if( abs(F.determinant())>0. ) {
00041     if( abs(F[0][0])>0. ) {
00042       X = (qr_solve(F,Y));
00043     }
00044     else {
00045       X = HepVector(Npar,1.0);    // one side has no data
00046     }
00047   }
00048 
00049   m_result.push_back(X);
00050 
00051   updateData( data );
00052 
00053   return;
00054 }
00055 
00056 
00057 void TofCalib::fillTxt( const char* file ) {
00058   std::ofstream out(file,ios::out);
00059   if( out ) {
00060     std::vector<HepVector>::iterator it;
00061     for( it=m_result.begin(); it!=m_result.end(); it++ ) {
00062       for( int i=0; i<(*it).num_row(); i++ ) {
00063         out << (*it)[i] << " ";
00064       }
00065       out << std::endl;
00066     }
00067     out.close();
00068   }
00069   else{
00070     cerr << "error when open file " << file << " for write in " << name() << "::fillTxt()" << std::endl;
00071     cout << "print all parameters to srceen: in total " << m_result.size() << " items" << std::endl;
00072     std::vector<HepVector>::iterator it;
00073     for( it=m_result.begin(); it!=m_result.end(); it++ ) {
00074       for( int i=0; i<(*it).num_row(); i++ ) {
00075         cout << (*it)[i] << " ";
00076       }
00077       cout << std::endl;
00078     }
00079   }
00080 
00081   return;
00082 }

Generated on Tue Nov 29 23:14:36 2016 for BOSS_7.0.2 by  doxygen 1.4.7