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