CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
calib_barrel_common.cxx
Go to the documentation of this file.
2#include "TF1.h"
3
5
6 nKind = 4;
7 nBinPerCounter = nzbin;
8
12 nCanvas = 4;
13 CanvasName.push_back( static_cast<string>("Offset") );
14 CanvasName.push_back( static_cast<string>("Offset-PlusMinus") );
15 CanvasName.push_back( static_cast<string>("Sigma") );
16 CanvasName.push_back( static_cast<string>("Sigma-TCorrelation") );
17 nGraphPerCanvas.push_back(2);
18 nGraphPerCanvas.push_back(2);
19 nGraphPerCanvas.push_back(2);
20 nGraphPerCanvas.push_back(3);
21
22 int numGraphs = 0;
23 std::vector<unsigned int>::iterator iter = nGraphPerCanvas.begin();
24 for( ; iter!=nGraphPerCanvas.end(); iter++ ) {
25 numGraphs = numGraphs + (*iter);
26 }
27 if( numGraphs != nGraphTotalCommon ) {
28 cout << "tofcalgsec::calib_barrel_common: the number of Graphs is NOT reasonable!!!" << endl;
29 exit(0);
30 }
31
32 m_name = string("calib_barrel_common");
33
34 const int tbin = 150;
35 const double tbegin = -1.5;
36 const double tend = 1.5;
37
38 char hname[256];
39 // histograms
40 for( unsigned int j=0; j<nKind; j++ ) {
41 for( unsigned int k=0; k<nBinPerCounter; k++ ) {
42 if( j==0 ) { sprintf( hname, "tleft-z%i", k); }
43 else if( j==1 ) { sprintf( hname, "tright-z%i", k); }
44 else if( j==2 ) { sprintf( hname, "tplus-z%i", k); }
45 else if( j==3 ) { sprintf( hname, "tminus-z%i", k); }
46 m_fitresult.push_back( HepVector( nParCommon,0 ) );
47 m_histograms.push_back( new TH1F( hname, hname, tbin, tbegin, tend ) );
48 }
49 }
50 sprintf( hname, "deltaT" );
51 m_fitresult.push_back( HepVector( nParCommon,0 ) );
52 m_histograms.push_back( new TH1F( hname, hname, tbin, tbegin, tend ) );
53
54 zpos.resize( nBinPerCounter );
55 zposerr.resize( nBinPerCounter );
56 zstep = ( zend - zbegin )/nBinPerCounter;
57 for( unsigned int i=0; i<nBinPerCounter; i++ ) {
58 zpos[i] = zbegin + ( i+0.5 )*zstep;
59 zposerr[i] = 0.5*zstep;
60 }
61
62}
63
64
66 m_fitresult.clear();
67 zpos.clear();
68 zposerr.clear();
69}
70
71
72void calib_barrel_common::calculate( RecordSet*& data, unsigned int icounter ) {
73
74 std::cout << setiosflags(ios::left) << setw(10) << icounter << setw(8) << data->size() << setw(30) << name() << std::endl;
75
76 if( data->size() > 0 ) {
77 std::vector<Record*>::iterator iter = data->begin();
78 for( ; iter!=data->end(); iter++ ) {
79 fillRecord( (*iter) );
80 }
81 }
82
83 if( icounter==(NBarrel-1) ) {
84 fitHistogram();
85 fillGraph();
86 fitGraph();
87 }
88
89 return;
90}
91
92
93
94void calib_barrel_common::fillRecord( const Record* r ) {
95 double zhit = r->zrhit();
96 if( zhit<zbegin || zhit>zend ) return;
97 int zbin = static_cast<int>((zhit-zbegin)/zstep);
98 if( ( zbin<0 ) || ( zbin>static_cast<int>(nBinPerCounter-1) ) ) {
99 cout << "tofcalgsec::calib_barrel_common: zhit is out of range, zhit=" << zhit << " zbin=" << zbin << endl;
100 return;
101 }
102
103 std::vector<TH1F*>::iterator iter = m_histograms.begin();
104 (*(iter+zbin))->Fill( r->tleft() );
105 (*(iter+nBinPerCounter+zbin))->Fill( r->tright() );
106 (*(iter+2*nBinPerCounter+zbin))->Fill( (r->tleft()+r->tright())/2.0 );
107 (*(iter+3*nBinPerCounter+zbin))->Fill( (r->tleft()-r->tright())/2.0 );
108 (*(iter+nKind*nBinPerCounter))->Fill( r->tleft() );
109 (*(iter+nKind*nBinPerCounter))->Fill( r->tright() );
110
111 return;
112}
113
114
115void calib_barrel_common::fitHistogram() {
116 TF1* g = new TF1("g", "gaus");
117 g->SetLineColor(2);
118 g->SetLineWidth(1);
119
120 std::vector<TH1F*>::iterator iter1 = m_histograms.begin();
121 std::vector<HepVector>::iterator iter2 = m_fitresult.begin();
122 for( ; iter1!=m_histograms.end(); iter1++, iter2++ ) {
123 (*iter1)->Fit( g, "Q");
124 (*iter2)[0] = g->GetParameter(1);
125 (*iter2)[1] = g->GetParError(1);
126 (*iter2)[2] = g->GetParameter(2);
127 (*iter2)[3] = g->GetParError(2);
128 }
129
130 iter2 = m_fitresult.end() - 1;
131 X[2] = (*iter2)[0];
132 X[3] = (*iter2)[1];
133
134 return;
135
136}
137
138
139void calib_barrel_common::fillGraph() {
140
141 char gname1[256], gname2[256];
142 TGraphErrors *gra[nGraphTotalCommon];
143
144 // 4 canvas all counter,
145 // 1. offset of tleft and tright vs z --- gra[0] and gra[1]
146 // 2. common of tleft and tright vs z --- gra[2] and gra[3]
147 // 3. offset of tplus and tminus vs z --- gra[4] and gra[5]
148 // 4. common of tplus, tminus and T_Correlation vs z
149 // --- gra[6], gra[7] and gra[8]
150
151 std::vector<double> toffset, toffseterr;
152 std::vector<double> tsigma, tsigmaerr;
153 toffset.resize( nBinPerCounter );
154 toffseterr.resize( nBinPerCounter );
155 tsigma.resize( nBinPerCounter );
156 tsigmaerr.resize( nBinPerCounter );
157
158 unsigned int number = 0;
159 std::vector<HepVector>::iterator iter = m_fitresult.begin();
160 for( unsigned int j=0; j<nKind; j++ ) {
161 for( unsigned int k=0; k<nBinPerCounter; k++ ) {
162 number = j*nBinPerCounter + k;
163 toffset[k] = (*(iter+number))[0];
164 toffseterr[k] = (*(iter+number))[1];
165 tsigma[k] = (*(iter+number))[2];
166 tsigmaerr[k] = (*(iter+number))[3];
167 }
168
169 sprintf( gname1, "Offset" );
170 gra[j] = new TGraphErrors( nBinPerCounter, &zpos[0], &toffset[0], &zposerr[0], &toffseterr[0]);
171 gra[j]->SetTitle(gname1);
172
173 sprintf( gname2, "Sigma" );
174 gra[j+4] = new TGraphErrors( nBinPerCounter, &zpos[0], &tsigma[0], &zposerr[0], &tsigmaerr[0]);
175 gra[j+4]->SetTitle(gname2);
176 }
177
178 for( unsigned int k=0; k<nBinPerCounter; k++ ) {
179 number = (nKind-1)*nBinPerCounter + k;
180 double sigPlus = (*(iter+number-nBinPerCounter))[2];
181 double sigMinus = (*(iter+number))[2];
182 double sigErrPlus = (*(iter+number-nBinPerCounter))[3];
183 double sigErrMinus = (*(iter+number))[3];
184 if( sigPlus>sigMinus ) {
185 tsigma[k] = sqrt( sigPlus*sigPlus - sigMinus*sigMinus );
186 }
187 else {
188 tsigma[k] = 0.0 - sqrt( sigMinus*sigMinus - sigPlus*sigPlus );
189 }
190 tsigmaerr[k] = sqrt( sigErrPlus*sigErrPlus + sigErrMinus*sigErrMinus );
191 }
192 gra[nGraphTotalCommon-1] = new TGraphErrors( nBinPerCounter, &zpos[0], &tsigma[0], &zposerr[0], &tsigmaerr[0]);
193
194 for( int j=0; j<nGraphTotalCommon; j++, j++ ) {
195 gra[j]->SetMarkerSize(1.5);
196 gra[j]->SetMarkerStyle(20);
197 gra[j]->SetMarkerColor(2);
198 if( j==4 ) {
199 gra[j]->SetMaximum( 0.22 );
200 gra[j]->SetMinimum( 0.07 );
201 }
202 else if( j==6 ) {
203 gra[j]->SetMaximum( 0.20 );
204 gra[j]->SetMinimum( -0.02 );
205 }
206 }
207 for( int j=1; j<nGraphTotalCommon; j++, j++ ) {
208 gra[j]->SetMarkerSize(1.5);
209 gra[j]->SetMarkerStyle(21);
210 gra[j]->SetMarkerColor(4);
211 }
212 gra[nGraphTotalCommon-1]->SetMarkerStyle(4);
213 gra[nGraphTotalCommon-1]->SetMarkerColor(6);
214
215 for( int j=0; j<nGraphTotalCommon; j++ ) {
216 m_graphs.push_back( gra[j] );
217 }
218
219 return;
220}
221
222
223void calib_barrel_common::fitGraph() {
224 TF1* p0 = new TF1("p0", "pol0");
225 p0->SetLineColor(1);
226 p0->SetLineWidth(1);
227
228 std::vector<TGraphErrors*>::iterator iter=m_graphs.end()-1;
229 (*iter)->Fit( "p0", "Q" );
230 X[0] = p0->GetParameter(0);
231 X[1] = p0->GetParError(0);
232
233 m_result.push_back( X );
234 return;
235}
TTree * data
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
const double zend
Definition TofCalibFit.h:15
const double zbegin
Definition TofCalibFit.h:14
const int nBarrelCommon
Definition TofCalibFit.h:21
std::vector< Record * > RecordSet
Definition TofDataSet.h:89
const unsigned int NBarrel
Definition TofDataSet.h:12
const int nParCommon
const int nGraphTotalCommon
double tleft() const
Definition TofDataSet.h:53
double tright() const
Definition TofDataSet.h:54
double zrhit() const
Definition TofDataSet.h:55
string m_name
Definition TofCalibFit.h:52
std::vector< HepVector > m_result
Definition TofCalibFit.h:57
unsigned int nCanvas
Definition TofCalibFit.h:49
std::vector< TH1F * > m_histograms
Definition TofCalibFit.h:55
unsigned int nBinPerCounter
Definition TofCalibFit.h:43
std::vector< TGraphErrors * > m_graphs
Definition TofCalibFit.h:56
unsigned int nKind
Definition TofCalibFit.h:42
unsigned int nCanvasPerCounter
Definition TofCalibFit.h:46
unsigned int nHistPerCounter
Definition TofCalibFit.h:45
const string & name() const
Definition TofCalibFit.h:29
HepVector X
Definition TofCalibFit.h:53
std::vector< unsigned int > nGraphPerCanvas
Definition TofCalibFit.h:50
std::vector< string > CanvasName
Definition TofCalibFit.h:61
unsigned int nHistogram
Definition TofCalibFit.h:48
calib_barrel_common(const unsigned int nzbin)
void calculate(RecordSet *&data, unsigned int icounter)