44 numGraphs = numGraphs + (*iter);
47 cout <<
"tofcalgsec::calib_barrel_sigma: the number of Graphs is NOT reasonable!!!" << endl;
51 m_name = string(
"calib_barrel_sigma");
54 const double tbegin = -1.5;
55 const double tend = 1.5;
59 for(
unsigned int i=0; i<
NBarrel; i++ ) {
61 for(
unsigned int j=0; j<
nKind; j++ ) {
63 if( j==0 ) {
sprintf( hname,
"tleft-id%i-z%i", i, k); }
64 else if( j==1 ) {
sprintf( hname,
"tright-id%i-z%i", i, k); }
65 else if( j==2 ) {
sprintf( hname,
"t0-id%i-z%i", i, k); }
66 else if( j==3 ) {
sprintf( hname,
"tplus-id%i-z%i", i, k); }
67 else if( j==4 ) {
sprintf( hname,
"tminus-id%i-z%i", i, k); }
68 m_histograms.push_back(
new TH1F( hname, hname, tbin, tbegin, tend ) );
70 m_fitresult.push_back( HepVector(
nParSigma,0) );
79 zpos[i] =
zbegin + ( i+0.5 )*zstep;
80 zposerr[i] = 0.5*zstep;
95 std::cout << setiosflags(ios::left) << setw(10) << icounter << setw(8) <<
data->size() << setw(30) <<
name() << std::endl;
97 if(
data->size() > 0 ) {
98 std::vector<Record*>::iterator
iter =
data->begin();
100 fillRecord( (*
iter), icounter );
103 fitHistogram( icounter );
104 fillGraph( icounter );
105 fitGraph( icounter );
107 if(
data->size() > 0 ) {
108 std::vector<Record*>::iterator
iter =
data->begin();
110 updateData( (*
iter), icounter );
111 fillRecordT0( (*
iter), icounter );
114 fitHistogramT0( icounter );
115 fillGraphT0( icounter );
116 fitGraphT0( icounter );
122void calib_barrel_sigma::fillRecord(
const Record* r,
unsigned int icounter ) {
124 double zhit = r->
zrhit();
125 if( zhit<zbegin || zhit>
zend )
return;
126 int zbin =
static_cast<int>((zhit-
zbegin)/zstep);
127 if( zbin<0 ) { zbin = 0; }
129 cout <<
"tofcalgsec::calib_barrel_sigma:fillRecord: zhit is out of range, zhit=" << zhit <<
" zbin=" << zbin << endl;
144void calib_barrel_sigma::fitHistogram(
unsigned int icounter ) {
145 TF1* g =
new TF1(
"g",
"gaus");
150 std::vector<HepVector>::iterator iter2 = m_fitresult.begin() + icounter*
nKind*
nBinPerCounter;
151 for(
unsigned int i=0; i<
nKind; i++ ) {
154 (*iter1)->Fit( g,
"Q");
155 (*iter2)[0] = g->GetParameter(1);
156 (*iter2)[1] = g->GetParError(1);
157 (*iter2)[2] = g->GetParameter(2);
158 (*iter2)[3] = g->GetParError(2);
170void calib_barrel_sigma::fillGraph(
unsigned int icounter ) {
172 char gname1[256], gname2[256];
180 std::vector<double> toffset, toffseterr;
181 std::vector<double> tsigma, tsigmaerr;
187 unsigned int number = 0;
189 for(
unsigned int j=0; j<
nKind; j++ ) {
190 if( j==0 ) {
sprintf( gname1,
"tleft-offset-tofid-%i", icounter ); }
191 else if( j==1 ) {
sprintf( gname1,
"tright-offset-tofid-%i", icounter ); }
192 else if( j==2 ) {
sprintf( gname1,
"t0-offset-tofid-%i", icounter ); }
193 else if( j==3 ) {
sprintf( gname1,
"tplus-offset-tofid-%i", icounter ); }
194 else if( j==4 ) {
sprintf( gname1,
"tminus-offset-tofid-%i", icounter ); }
197 std::vector<TH1F*>::iterator itgraph =
m_graphs.end() - 1;
201 toffset[k] = (*(
iter+number))[0];
202 toffseterr[k] = (*(
iter+number))[1];
203 (*itgraph)->SetBinContent( k+1, toffset[k] );
204 (*itgraph)->SetBinError( k+1, toffseterr[k] );
206 (*itgraph)->SetMarkerSize(1.5);
208 (*itgraph)->SetMarkerStyle(20);
209 (*itgraph)->SetMarkerColor(2);
210 (*itgraph)->SetMaximum( 0.15 );
211 (*itgraph)->SetMinimum(-0.15 );
213 else if( j==1 || j==4 ) {
214 (*itgraph)->SetMarkerStyle(21);
215 (*itgraph)->SetMarkerColor(4);
218 (*itgraph)->SetMarkerStyle(4);
219 (*itgraph)->SetMarkerColor(2);
223 for(
unsigned int j=0; j<
nKind; j++ ) {
224 if( j==0 ) {
sprintf( gname2,
"tleft-sigma-tofid-%i", icounter ); }
225 else if( j==1 ) {
sprintf( gname2,
"tright-sigma-tofid-%i", icounter ); }
226 else if( j==2 ) {
sprintf( gname2,
"t0-sigma-tofid-%i", icounter ); }
227 else if( j==3 ) {
sprintf( gname2,
"tplus-sigma-tofid-%i", icounter ); }
228 else if( j==4 ) {
sprintf( gname2,
"tminus-sigma-tofid-%i", icounter ); }
230 std::vector<TH1F*>::iterator itgraph =
m_graphs.end() - 1;
234 tsigma[k] = (*(
iter+number))[2];
235 tsigmaerr[k] = (*(
iter+number))[3];
236 (*itgraph)->SetBinContent( k+1, tsigma[k] );
237 (*itgraph)->SetBinError( k+1, tsigmaerr[k] );
239 (*itgraph)->SetMarkerSize(1.5);
241 (*itgraph)->SetMarkerStyle(20);
242 (*itgraph)->SetMarkerColor(2);
243 (*itgraph)->SetMaximum( 0.3 );
244 (*itgraph)->SetMinimum( 0.0 );
246 else if( j==1 || j==4 ) {
247 (*itgraph)->SetMarkerStyle(21);
248 (*itgraph)->SetMarkerColor(4);
251 (*itgraph)->SetMarkerStyle(4);
252 (*itgraph)->SetMarkerColor(2);
256 sprintf( gname2,
"sigma-tofid-%i", icounter );
258 std::vector<TH1F*>::iterator itgraph =
m_graphs.end() - 1;
262 double sigMinus = (*(
iter+number))[2];
264 double sigErrMinus = (*(
iter+number))[3];
265 tsigma[k] = sqrt( sigPlus*sigPlus - sigMinus*sigMinus );
266 tsigmaerr[k] = sqrt( sigErrPlus*sigErrPlus + sigErrMinus*sigErrMinus );
267 (*itgraph)->SetBinContent( k+1, tsigma[k] );
268 (*itgraph)->SetBinError( k+1, tsigmaerr[k] );
270 (*itgraph)->SetMarkerSize(1.5);
271 (*itgraph)->SetMarkerStyle(4);
272 (*itgraph)->SetMarkerColor(2);
278void calib_barrel_sigma::fitGraph(
unsigned int icounter ) {
280 TF1* fsingle =
new TF1(
"fsingle",
"pol4");
281 fsingle->SetLineColor(1);
282 fsingle->SetLineWidth(1);
285 std::vector<TH1F*>::iterator itgraph =
m_graphs.begin() + icounter*
nGraphTotalSigma + (*itnumber) + (*(itnumber+1));
287 fsingle->SetParameter( 0, 0.14 );
288 fsingle->SetParameter( 1, -4.0e-4 );
289 (*itgraph)->Fit(
"fsingle",
"QR",
"",
zbegin,
zend );
291 for(
unsigned int i=0; i<5; i++ ) {
292 X[i] = fsingle->GetParameter(i);
295 fsingle->SetParameter( 0, 0.14 );
296 fsingle->SetParameter( 1, 4.0e-4 );
297 (*(itgraph+1))->Fit(
"fsingle",
"QR",
"",
zbegin,
zend );
298 for(
unsigned int i=0; i<5; i++ ) {
299 X[i+5] = fsingle->GetParameter(i);
302 std::vector<HepVector>::iterator
iter =
m_result.begin() + icounter;
309void calib_barrel_sigma::updateData(
Record* r,
unsigned int icounter ) {
310 double zhit = r->
zrhit();
311 double t1 = r->
tleft();
314 double par1[5], par2[5];
315 std::vector<HepVector>::iterator
iter =
m_result.begin() + icounter;
316 for(
unsigned int i=0; i<5; i++ ) {
317 par1[i] = (*iter)[i];
318 par2[i] = (*iter)[i+5];
321 double tsigma1 = par1[0]+par1[1]*zhit+par1[2]*pow(zhit,2)+par1[3]*pow(zhit,3) + par1[4]*pow(zhit,4);
322 double tsigma2 = par2[0]+par2[1]*zhit+par2[2]*pow(zhit,2)+par2[3]*pow(zhit,3) + par2[4]*pow(zhit,4);
325 double weight1 = (tsigma2*tsigma2-tc*tc)/(tsigma1*tsigma1+tsigma2*tsigma2-2.0*tc*tc);
326 double weight2 = (tsigma1*tsigma1-tc*tc)/(tsigma1*tsigma1+tsigma2*tsigma2-2.0*tc*tc);
327 double t0 = weight1*t1 + weight2*t2;
335void calib_barrel_sigma::fillRecordT0(
const Record* r,
unsigned int icounter ) {
336 double zhit = r->
zrhit();
337 if( zhit<zbegin || zhit>
zend )
return;
338 int zbin =
static_cast<int>((zhit-
zbegin)/zstep);
339 if( zbin<0 ) { zbin = 0; }
341 cout <<
"tofcalgsec::calib_barrel_sigma:fillRecordT0: zhit is out of range, zhit=" << zhit <<
" zbin=" << zbin << endl;
347 (*(
iter+number))->Fill( r->
t0() );
353void calib_barrel_sigma::fitHistogramT0(
unsigned int icounter ) {
354 TF1* g =
new TF1(
"g",
"gaus");
360 for(
unsigned int j=0; j<
nBinPerCounter; j++, iter1++, iter2++ ) {
361 (*iter1)->Fit( g,
"Q");
362 (*iter2)[0] = g->GetParameter(1);
363 (*iter2)[1] = g->GetParError(1);
364 (*iter2)[2] = g->GetParameter(2);
365 (*iter2)[3] = g->GetParError(2);
372void calib_barrel_sigma::fillGraphT0(
unsigned int icounter ) {
373 char gname1[256], gname2[256];
381 std::vector<double> toffset, toffseterr;
382 std::vector<double> tsigma, tsigmaerr;
390 toffset[k] = (*(
iter+k))[0];
391 toffseterr[k] = (*(
iter+k))[1];
392 tsigma[k] = (*(
iter+k))[2];
393 tsigmaerr[k] = (*(
iter+k))[3];
396 sprintf( gname1,
"offset-tofid-%i", icounter );
401 (*itgraph)->SetBinContent( i+1, toffset[i] );
402 (*itgraph)->SetBinError( i+1, toffseterr[i] );
405 sprintf( gname2,
"sigma-tofid-%i", icounter );
410 (*itgraph)->SetBinContent( i+1, tsigma[i] );
411 (*itgraph)->SetBinError( i+1, tsigmaerr[i] );
418void calib_barrel_sigma::fitGraphT0(
unsigned int icounter ) {
421 TF1 *fdouble =
new TF1(
"fdouble",
"pol4",
zbegin,
zend );
422 fdouble->SetLineColor(1);
423 fdouble->SetLineWidth(1);
426 std::vector<TH1F*>::iterator itgraph =
m_graphs.begin() + icounter*
nGraphTotalSigma + (*itnumber) + (*(itnumber+1)) + 2;
427 (*itgraph)->Fit(
"fdouble",
"Q",
"",
zbegin,
zend );
429 std::vector<HepVector>::iterator
iter =
m_result.begin() + icounter;
430 (*iter)[10] = fdouble->GetParameter(0);
431 (*iter)[11] = fdouble->GetParameter(1);
432 (*iter)[12] = fdouble->GetParameter(2);
433 (*iter)[13] = fdouble->GetParameter(3);
434 (*iter)[14] = fdouble->GetParameter(4);
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)
std::vector< Record * > RecordSet
const unsigned int NBarrel
const int nGraphTotalSigma
std::vector< HepVector > m_result
std::vector< TH1F * > m_histograms
unsigned int nBinPerCounter
std::vector< unsigned int > nGraphPerCanvasPerCounter
unsigned int nCanvasPerCounter
unsigned int nHistPerCounter
const string & name() const
std::vector< TH1F * > m_graphs
std::vector< string > CanvasPerCounterName
calib_barrel_sigma(const unsigned int nzbin)
void calculate(RecordSet *&data, unsigned int icounter)