BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
TofCalib.cxx
Go to the documentation of this file.
1#include "tofcalgsec/TofCalib.h"
2#include <iostream>
3#include <ios>
4#include <fstream>
5
6using namespace CLHEP;
7
9 F = HepMatrix(Npar,Npar,0);
10 Y = HepVector(Npar,0);
11 X = HepVector(Npar,0);
12 funcs = HepVector(Npar,0);
13 return;
14}
15
16
17void TofCalib::calculate( RecordSet*& data, unsigned int icounter ) {
18
19 std::cout << setiosflags(ios::left) << setw(10) << icounter << setw(8) << data->size() << setw(30) << name() << std::endl;
20
21 if( data->size() <= 0 ) {
22 X = HepVector(Npar,1.0);
23 }
24 else {
25 std::vector<Record*>::iterator iter = data->begin();
26 for( ; iter!=data->end(); iter++ ) {
28 for( int i=0; i<F.num_col(); i++ ) {
29 for( int j=0; j<F.num_col(); j++ ) {
30 F[i][j]+=funcs[i]*funcs[j];
31 }
32 }
33
34 calculate_y( (*iter) );
35 for( int k=0; k<Y.num_row(); k++ ) {
36 Y[k]+=y*funcs[k];
37 }
38 }
39
40 // if( abs(F.determinant())>0. ) {
41 if( abs(F[0][0])>0. ) {
42 X = (qr_solve(F,Y));
43 }
44 else {
45 X = HepVector(Npar,1.0); // one side has no data
46 }
47 }
48
49 m_result.push_back(X);
50
52
53 return;
54}
55
56
57void TofCalib::fillTxt( const char* file ) {
58 std::ofstream out(file,ios::out);
59 if( out ) {
60 std::vector<HepVector>::iterator it;
61 for( it=m_result.begin(); it!=m_result.end(); it++ ) {
62 for( int i=0; i<(*it).num_row(); i++ ) {
63 out << (*it)[i] << " ";
64 }
65 out << std::endl;
66 }
67 out.close();
68 }
69 else{
70 cerr << "error when open file " << file << " for write in " << name() << "::fillTxt()" << std::endl;
71 cout << "print all parameters to srceen: in total " << m_result.size() << " items" << std::endl;
72 std::vector<HepVector>::iterator it;
73 for( it=m_result.begin(); it!=m_result.end(); it++ ) {
74 for( int i=0; i<(*it).num_row(); i++ ) {
75 cout << (*it)[i] << " ";
76 }
77 cout << std::endl;
78 }
79 }
80
81 return;
82}
char * file
Definition: DQA_TO_DB.cxx:15
TTree * data
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
std::vector< Record * > RecordSet
virtual void calculate_y(const Record *r)=0
virtual void calculate(RecordSet *&data, unsigned int icounter)
Definition: TofCalib.cxx:17
void fillTxt(const char *file)
Definition: TofCalib.cxx:57
void reset()
Definition: TofCalib.cxx:8
virtual const string & name() const
virtual void updateData(RecordSet *&data)=0
virtual void calculate_funcs(const Record *r)=0