BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
calib_etf_bunch.cxx
Go to the documentation of this file.
1#include "tofcalgsec/calib_etf_bunch.h"
2#include "TF1.h"
3
5
6 nKind = nbunch;
8
12 nCanvas = 8;
13 CanvasName.push_back( static_cast<string>("Offset-bunch0") );
14 CanvasName.push_back( static_cast<string>("Offset-bunch1") );
15 CanvasName.push_back( static_cast<string>("Offset-bunch2") );
16 CanvasName.push_back( static_cast<string>("Offset-bunch3") );
17 CanvasName.push_back( static_cast<string>("Sigma-bunch0") );
18 CanvasName.push_back( static_cast<string>("Sigma-bunch1") );
19 CanvasName.push_back( static_cast<string>("Sigma-bunch2") );
20 CanvasName.push_back( static_cast<string>("Sigma-bunch3") );
21
22 nGraphPerCanvas.push_back(1);
23 nGraphPerCanvas.push_back(1);
24 nGraphPerCanvas.push_back(1);
25 nGraphPerCanvas.push_back(1);
26 nGraphPerCanvas.push_back(1);
27 nGraphPerCanvas.push_back(1);
28 nGraphPerCanvas.push_back(1);
29 nGraphPerCanvas.push_back(1);
30
31 int numGraphs = 0;
32 std::vector<unsigned int>::iterator iter = nGraphPerCanvas.begin();
33 for( ; iter!=nGraphPerCanvas.end(); iter++ ) {
34 numGraphs = numGraphs + (*iter);
35 }
36 if( numGraphs != nGraphTotalBunch ) {
37 cout << "tofcalgsec::calib_barrel_common: the number of Graphs is NOT reasonable!!!" << endl;
38 exit(0);
39 }
40
41 m_name = string("calib_etf_bunch");
42
43 const int tbin = 160;
44 const double tbegin = -0.8;
45 const double tend = 0.8;
46
47 char hname[256];
48 // histograms
49 for( unsigned int j=0; j<nKind; j++ ) {
50 for( unsigned int k=0; k<nBinPerCounter; k++ ) {
51 if( k==0 ) { sprintf( hname, "tleft-bunch%i", j); }
52 else if( k==1 ) { sprintf( hname, "tright-bunch%i", j); }
53 else if( k==2 ) { sprintf( hname, "tcombine-bunch%i", j); }
54 m_fitresult.push_back( HepVector( nParEtfBunch,0 ) );
55 m_histograms.push_back( new TH1F( hname, hname, tbin, tbegin, tend ) );
56 }
57 }
58 m_fitresult.push_back( HepVector( nParEtfBunch,0 ) );
59
60 modpos.resize( nBinPerCounter );
61 modposerr.resize( nBinPerCounter );
62 for( unsigned int i=0; i<nBinPerCounter; i++ ) {
63 modpos[i] = 1.0*i;
64 modposerr[i] = 0.5;
65 }
66
67 return;
68}
69
70
72 m_fitresult.clear();
73 modpos.clear();
74 modposerr.clear();
75}
76
77
78void calib_etf_bunch::calculate( RecordSet*& data, unsigned int icounter ) {
79
80 std::cout << setiosflags(ios::left) << setw(10) << icounter << setw(8) << data->size() << setw(30) << name() << std::endl;
81
82 if( data->size() > 0 ) {
83 std::vector<Record*>::iterator iter = data->begin();
84 for( ; iter!=data->end(); iter++ ) {
85 fillRecord( (*iter) );
86 }
87 }
88
89 if( icounter==(NEtf*NStrip-1) ) {
90 fitHistogram();
91 fillGraph();
92 fitGraph();
93 }
94
95 return;
96}
97
98
99void calib_etf_bunch::fillRecord( const Record* r ) {
100 double t0 = r->phi();
101 int ibunch = static_cast<int>(t0/(8.0*12000./499.8/8./4. )+0.1)%4;
102
103 if( ibunch<0 || ibunch>int(nBinPerCounter) ) return;
104
105 std::vector<TH1F*>::iterator iter = m_histograms.begin();
106 (*(iter+nBinPerCounter*ibunch+0))->Fill( r->tleft() );
107 (*(iter+nBinPerCounter*ibunch+1))->Fill( r->tright() );
108 (*(iter+nBinPerCounter*ibunch+2))->Fill( r->t0() );
109
110 return;
111}
112
113
114void calib_etf_bunch::fitHistogram() {
115 TF1* g = new TF1("g", "gaus");
116 g->SetLineColor(2);
117 g->SetLineWidth(1);
118
119 std::vector<TH1F*>::iterator iter1 = m_histograms.begin();
120 std::vector<HepVector>::iterator iter2 = m_fitresult.begin();
121 for( ; iter1!=m_histograms.end(); iter1++, iter2++ ) {
122 (*iter1)->Fit( g, "Q");
123 (*iter2)[0] = g->GetParameter(1);
124 (*iter2)[1] = g->GetParError(1);
125 (*iter2)[2] = g->GetParameter(2);
126 (*iter2)[3] = g->GetParError(2);
127 }
128
129 return;
130}
131
132
133void calib_etf_bunch::fillGraph() {
134
135 char gname1[256], gname2[256];
136 TH1F *gra[nGraphTotalBunch];
137
138 // 8canvas all counter,
139 // 1. offset of tleft, tright and tcombine of bunch0 --- gra[0]
140 // 2. offset of tleft, tright and tcombine of bunch1 --- gra[1]
141 // 3. offset of tleft, tright and tcombine of bunch2 --- gra[2]
142 // 4. offset of tleft, tright and tcombine of bunch3 --- gra[3]
143 // 5. sigma of tleft, tright and tcombine of bunch0 --- gra[4]
144 // 6. sigma of tleft, tright and tcombine of bunch1 --- gra[5]
145 // 7. sigma of tleft, tright and tcombine of bunch2 --- gra[6]
146 // 8. sigma of tleft, tright and tcombine of bunch3 --- gra[7]
147
148
149 std::vector<double> toffset, toffseterr;
150 std::vector<double> tsigma, tsigmaerr;
151 toffset.resize( nBinPerCounter );
152 toffseterr.resize( nBinPerCounter );
153 tsigma.resize( nBinPerCounter );
154 tsigmaerr.resize( nBinPerCounter );
155
156 unsigned int number = 0;
157 std::vector<HepVector>::iterator iter = m_fitresult.begin();
158 for( unsigned int j=0; j<nKind; j++ ) {
159 sprintf( gname1, "bunch%i-offset", j );
160 sprintf( gname2, "bunch%i-sigma", j );
161
162 gra[j] = new TH1F( gname1, gname1, nBinPerCounter, -0.5, 2.5 );
163 gra[j+nKind] = new TH1F( gname2, gname2, nBinPerCounter, -0.5, 2.5 );
164
165 for( unsigned int k=0; k<nBinPerCounter; k++ ) {
166 number = j*nBinPerCounter + k;
167 toffset[k] = (*(iter+number))[0];
168 toffseterr[k] = (*(iter+number))[1];
169 tsigma[k] = (*(iter+number))[2];
170 tsigmaerr[k] = (*(iter+number))[3];
171 gra[j]->SetBinContent( k+1, toffset[k] );
172 gra[j]->SetBinError( k+1, toffseterr[k] );
173 gra[j+nKind]->SetBinContent( k+1, tsigma[k] );
174 gra[j+nKind]->SetBinError( k+1, tsigmaerr[k] );
175 }
176 }
177
178 for( int j=0; j<nGraphTotalBunch; j++, j++ ) {
179 gra[j]->SetMarkerSize(1.5);
180 gra[j]->SetMarkerStyle(20);
181 gra[j]->SetMarkerColor(2);
182 m_graphs.push_back( gra[j] );
183
184 gra[j+1]->SetMarkerSize(1.5);
185 gra[j+1]->SetMarkerStyle(21);
186 gra[j+1]->SetMarkerColor(4);
187 m_graphs.push_back( gra[j+1] );
188 }
189
190 return;
191}
192
193
194void calib_etf_bunch::fitGraph() {
195 TF1* p0 = new TF1("p0", "pol0");
196 p0->SetLineColor(1);
197 p0->SetLineWidth(1);
198
199 X = HepVector( 2, 0 );
200 std::vector<TH1F*>::iterator iter=m_graphs.begin();
201 for( int i=0; i<nParEtfBunch; i++ ) {
202 (*(iter+i))->Fit( "p0", "Q" );
203 X[0] = p0->GetParameter(0);
204 X[1] = p0->GetParError(0);
205 m_result.push_back( X );
206 }
207
208 return;
209}
TTree * data
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
std::vector< Record * > RecordSet
void calculate(RecordSet *&data, unsigned int ibunch)
calib_etf_bunch(const unsigned int nbunch)