CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
TofCalibration.cxx
Go to the documentation of this file.
2#include "TDirectory.h"
3#include "TFile.h"
4#include "TStyle.h"
5#include <iostream>
6#include <ios>
7#include <fstream>
8
9using namespace CLHEP;
10
11TofCalibration::TofCalibration( const int npar ):Npar(npar) {
12 X = HepVector(Npar,0);
13 m_name = string("calibration");
14}
15
17 std::vector<TH1F*>::iterator iter = histograms.begin();
18 for( ; iter != histograms.end(); iter++ ) {
19 delete (*iter);
20 }
21 histograms.clear();
22 m_result.clear();
23}
24
25
26void TofCalibration::calculate( RecordSet*& data, unsigned int icounter ) {
27
28 std::cout << setiosflags(ios::left) << setw(10) << icounter << setw(8) << data->size() << setw(30) << name() << std::endl;
29
30 if( data->size() <= 0 ) {
31 for( int i=0; i<X.num_row(); i++ ) {
32 X[i] = 1.0;
33 }
34 }
35 else {
36 std::vector<Record*>::iterator iter = data->begin();
37 for( ; iter!=data->end(); iter++ ) {
38 calculate_record( (*iter), icounter );
39 }
40
41 calculate_result( icounter );
42 }
43
44 return;
45}
46
47
48void TofCalibration::fillTxt( const char* file ) {
49 std::ofstream out(file,ios::out);
50 if( out ) {
51 std::vector<HepVector>::iterator it;
52 for( it=m_result.begin(); it!=m_result.end(); it++ ) {
53 // for( unsigned int i=0; i<(*it).num_row(); i++ ) {
54 for( unsigned int i=0; i<Npar2; i++ ) {
55 out << (*it)[i] << " ";
56 }
57 out << std::endl;
58 }
59 out.close();
60 }
61 else{
62 cerr << "error when open file " << file << " for write in " << name() << "::fillTxt()" << std::endl;
63 cout << "print all parameters to srceen: in total " << m_result.size() << " items" << std::endl;
64 std::vector<HepVector>::iterator it;
65 for( it=m_result.begin(); it!=m_result.end(); it++ ) {
66 // for( unsigned int i=0; i<(*it).num_row(); i++ ) {
67 for( unsigned int i=0; i<Npar2; i++ ) {
68 cout << (*it)[i] << " ";
69 }
70 cout << std::endl;
71 }
72 }
73
74 return;
75}
76
77
78void TofCalibration::fillRoot( const char* file, bool isbarrel ) {
79
80 unsigned int ncounter = 1;
81 if( isbarrel ) {
82 ncounter = NBarrel;
83 }
84 else {
85 ncounter = NEndcap;
86 }
87
88 unsigned int nhist = histograms.size();
89 if( nhist != (ncounter*nHistPerCounter + nHistogram) ) {
90 std::cout<<" tofcalgsec::TofCalibration: the number of histograms is NOT integral number of times of counter number!"<<std::endl;
91 exit(0);
92 }
93 unsigned int ngraph = graphs.size();
94 if( ngraph != (ncounter*nGraphPerCounter + nGraph) ) {
95 std::cout<<" tofcalgsec::TofCalibration: the number of histograms is NOT integral number of times of counter number!"<<std::endl;
96 exit(0);
97 }
98
99 TFile f(file,"RECREATE");
100
101 gStyle->SetOptFit(1111);
102 gStyle->SetOptStat(1111);
103 gStyle->SetLabelSize(0.03,"x");
104 gStyle->SetLabelSize(0.03,"y");
105
106 char dirname[256];
107 if( nHistPerCounter>1 ) {
108 std::vector<TH1F*>::iterator iter = histograms.begin();
109 for( unsigned int i=0; i<ncounter; i++ ) {
110 sprintf( dirname, "tofid%i", i );
111 TDirectory* cdresult = f.mkdir( dirname );
112 cdresult->cd();
113
114 for( unsigned int i=0; i<nHistPerCounter; i++ ) {
115 (*(iter+i))->Write();
116 }
118 }
119 }
120 else {
121 sprintf( dirname, "tofid" );
122 TDirectory* cdresult = f.mkdir( dirname );
123 cdresult->cd();
124
125 std::vector<TH1F*>::iterator iter = histograms.begin();
126 for( ; iter != histograms.end(); iter++ ) {
127 (*iter)->Write();
128 }
129 }
130
131 f.Close();
132
133 return;
134}
135
TTree * data
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
std::vector< Record * > RecordSet
Definition: TofDataSet.h:89
const unsigned int NBarrel
Definition: TofDataSet.h:12
const unsigned int NEndcap
Definition: TofDataSet.h:13
TofCalibration(const int npar)
virtual void calculate_record(const Record *r, unsigned int icounter)=0
virtual const string & name() const
std::vector< TGraph * > graphs
unsigned int nHistPerCounter
virtual void calculate(RecordSet *&data, unsigned int icounter)
unsigned int Npar2
unsigned int nHistogram
std::vector< HepVector > m_result
unsigned int nGraphPerCounter
void fillRoot(const char *file, bool isbarrel)
std::vector< TH1F * > histograms
virtual void calculate_result(unsigned int icounter)=0
void fillTxt(const char *file)
unsigned int nGraph