1#include "tofcalgsec/calib_barrel_sigma.h"
5static double singleEndFunc(
double *x,
double *par) {
13static double doubleEndFunc(
double *x,
double *par)
16 double f = par[0]*pow(xx,2)/sqrt(pow(
barrelRadius,2)+pow(xx,2))+par[1]+par[2]*pow(xx,2);
43 numGraphs = numGraphs + (*iter);
46 cout <<
"tofcalgsec::calib_barrel_sigma: the number of Graphs is NOT reasonable!!!" << endl;
50 m_name = string(
"calib_barrel_sigma");
53 const double tbegin = -1.5;
54 const double tend = 1.5;
58 for(
unsigned int i=0; i<
NBarrel; i++ ) {
60 for(
unsigned int j=0; j<
nKind; j++ ) {
62 if( j==0 ) { sprintf( hname,
"tleft-id%i-z%i", i, k); }
63 else if( j==1 ) { sprintf( hname,
"tright-id%i-z%i", i, k); }
64 else if( j==2 ) { sprintf( hname,
"t0-id%i-z%i", i, k); }
65 else if( j==3 ) { sprintf( hname,
"tplus-id%i-z%i", i, k); }
66 else if( j==4 ) { sprintf( hname,
"tminus-id%i-z%i", i, k); }
67 m_histograms.push_back(
new TH1F( hname, hname, tbin, tbegin, tend ) );
69 m_fitresult.push_back( HepVector(
nParSigma,0) );
78 zpos[i] =
zbegin + ( i+0.5 )*zstep;
79 zposerr[i] = 0.5*zstep;
94 std::cout << setiosflags(ios::left) << setw(10) << icounter << setw(8) <<
data->size() << setw(30) <<
name() << std::endl;
96 if(
data->size() > 0 ) {
97 std::vector<Record*>::iterator
iter =
data->begin();
99 fillRecord( (*
iter), icounter );
102 fitHistogram( icounter );
103 fillGraph( icounter );
104 fitGraph( icounter );
106 if(
data->size() > 0 ) {
107 std::vector<Record*>::iterator
iter =
data->begin();
109 updateData( (*
iter), icounter );
110 fillRecordT0( (*
iter), icounter );
113 fitHistogramT0( icounter );
114 fillGraphT0( icounter );
115 fitGraphT0( icounter );
121void calib_barrel_sigma::fillRecord(
const Record* r,
unsigned int icounter ) {
123 double zhit = r->
zrhit();
124 if( zhit<zbegin || zhit>
zend )
return;
125 int zbin =
static_cast<int>((zhit-
zbegin)/zstep);
126 if( zbin<0 ) { zbin = 0; }
128 cout <<
"tofcalgsec::calib_barrel_sigma:fillRecord: zhit is out of range, zhit=" << zhit <<
" zbin=" << zbin << endl;
143void calib_barrel_sigma::fitHistogram(
unsigned int icounter ) {
144 TF1* g =
new TF1(
"g",
"gaus");
149 std::vector<HepVector>::iterator iter2 = m_fitresult.begin() + icounter*
nKind*
nBinPerCounter;
150 for(
unsigned int i=0; i<
nKind; i++ ) {
153 (*iter1)->Fit( g,
"Q");
154 (*iter2)[0] = g->GetParameter(1);
155 (*iter2)[1] = g->GetParError(1);
156 (*iter2)[2] = g->GetParameter(2);
157 (*iter2)[3] = g->GetParError(2);
169void calib_barrel_sigma::fillGraph(
unsigned int icounter ) {
171 char gname1[256], gname2[256];
179 std::vector<double> toffset, toffseterr;
180 std::vector<double> tsigma, tsigmaerr;
186 unsigned int number = 0;
188 for(
unsigned int j=0; j<
nKind; j++ ) {
191 toffset[k] = (*(
iter+number))[0];
192 toffseterr[k] = (*(
iter+number))[1];
195 sprintf( gname1,
"offset-tofid-%i", icounter );
197 m_graphs.push_back(
new TGraphErrors(
nBinPerCounter, &zpos[0], &toffset[0], &zposerr[0], &toffseterr[0]) );
202 std::vector<TGraphErrors*>::iterator itgraph =
m_graphs.end() - 1;
203 (*itgraph)->SetTitle(gname1);
204 (*itgraph)->SetMarkerSize(1.5);
206 (*itgraph)->SetMarkerStyle(20);
207 (*itgraph)->SetMarkerColor(2);
208 (*itgraph)->SetMaximum( 0.15 );
209 (*itgraph)->SetMinimum(-0.15 );
211 else if( j==1 || j==4 ) {
212 (*itgraph)->SetMarkerStyle(21);
213 (*itgraph)->SetMarkerColor(4);
216 (*itgraph)->SetMarkerStyle(4);
217 (*itgraph)->SetMarkerColor(2);
221 for(
unsigned int j=0; j<
nKind; j++ ) {
224 tsigma[k] = (*(
iter+number))[2];
225 tsigmaerr[k] = (*(
iter+number))[3];
228 sprintf( gname2,
"sigma-tofid-%i", icounter );
230 m_graphs.push_back(
new TGraphErrors(
nBinPerCounter, &zpos[0], &tsigma[0], &zposerr[0], &tsigmaerr[0]) );
235 std::vector<TGraphErrors*>::iterator itgraph =
m_graphs.end() - 1;
236 (*itgraph)->SetTitle(gname2);
237 (*itgraph)->SetMarkerSize(1.5);
239 (*itgraph)->SetMarkerStyle(20);
240 (*itgraph)->SetMarkerColor(2);
241 (*itgraph)->SetMaximum( 0.3 );
242 (*itgraph)->SetMinimum( 0.0 );
244 else if( j==1 || j==4 ) {
245 (*itgraph)->SetMarkerStyle(21);
246 (*itgraph)->SetMarkerColor(4);
249 (*itgraph)->SetMarkerStyle(4);
250 (*itgraph)->SetMarkerColor(2);
257 double sigMinus = (*(
iter+number))[2];
259 double sigErrMinus = (*(
iter+number))[3];
260 tsigma[k] = sqrt( sigPlus*sigPlus - sigMinus*sigMinus );
261 tsigmaerr[k] = sqrt( sigErrPlus*sigErrPlus + sigErrMinus*sigErrMinus );
263 sprintf( gname2,
"sigma-tofid-%i", icounter );
264 m_graphs.push_back(
new TGraphErrors(
nBinPerCounter, &zpos[0], &tsigma[0], &zposerr[0], &tsigmaerr[0]) );
265 std::vector<TGraphErrors*>::iterator itgraph =
m_graphs.end() - 1;
266 (*itgraph)->SetTitle(gname2);
267 (*itgraph)->SetMarkerSize(1.5);
268 (*itgraph)->SetMarkerStyle(4);
269 (*itgraph)->SetMarkerColor(2);
275void calib_barrel_sigma::fitGraph(
unsigned int icounter ) {
277 TF1* fsingle =
new TF1(
"fsingle",
"pol4");
278 fsingle->SetLineColor(1);
279 fsingle->SetLineWidth(1);
282 std::vector<TGraphErrors*>::iterator itgraph =
m_graphs.begin() + icounter*
nGraphTotalSigma + (*itnumber) + (*(itnumber+1));
284 (*itgraph)->Fit(
"fsingle",
"Q",
"",
zbegin,
zend );
286 for(
unsigned int i=0; i<5; i++ ) {
287 X[i] = fsingle->GetParameter(i);
289 (*(itgraph+1))->Fit(
"fsingle",
"Q",
"",
zbegin,
zend );
290 for(
unsigned int i=0; i<5; i++ ) {
291 X[i+5] = fsingle->GetParameter(i);
294 std::vector<HepVector>::iterator
iter =
m_result.begin() + icounter;
301void calib_barrel_sigma::updateData(
Record* r,
unsigned int icounter ) {
302 double zhit = r->
zrhit();
303 double t1 = r->
tleft();
306 double par1[5], par2[5];
307 std::vector<HepVector>::iterator
iter =
m_result.begin() + icounter;
308 for(
unsigned int i=0; i<5; i++ ) {
309 par1[i] = (*iter)[i];
310 par2[i] = (*iter)[i+5];
313 double tsigma1 = par1[0]+par1[1]*zhit+par1[2]*pow(zhit,2)+par1[3]*pow(zhit,3) + par1[4]*pow(zhit,4);
314 double tsigma2 = par2[0]+par2[1]*zhit+par2[2]*pow(zhit,2)+par2[3]*pow(zhit,3) + par2[4]*pow(zhit,4);
317 double weight1 = (tsigma2*tsigma2-tc*tc)/(tsigma1*tsigma1+tsigma2*tsigma2-2.0*tc*tc);
318 double weight2 = (tsigma1*tsigma1-tc*tc)/(tsigma1*tsigma1+tsigma2*tsigma2-2.0*tc*tc);
319 double t0 = weight1*t1 + weight2*t2;
327void calib_barrel_sigma::fillRecordT0(
const Record* r,
unsigned int icounter ) {
328 double zhit = r->
zrhit();
329 if( zhit<zbegin || zhit>
zend )
return;
330 int zbin =
static_cast<int>((zhit-
zbegin)/zstep);
331 if( zbin<0 ) { zbin = 0; }
333 cout <<
"tofcalgsec::calib_barrel_sigma:fillRecordT0: zhit is out of range, zhit=" << zhit <<
" zbin=" << zbin << endl;
339 (*(
iter+number))->Fill( r->
t0() );
345void calib_barrel_sigma::fitHistogramT0(
unsigned int icounter ) {
346 TF1* g =
new TF1(
"g",
"gaus");
352 for(
unsigned int j=0; j<
nBinPerCounter; j++, iter1++, iter2++ ) {
353 (*iter1)->Fit( g,
"Q");
354 (*iter2)[0] = g->GetParameter(1);
355 (*iter2)[1] = g->GetParError(1);
356 (*iter2)[2] = g->GetParameter(2);
357 (*iter2)[3] = g->GetParError(2);
364void calib_barrel_sigma::fillGraphT0(
unsigned int icounter ) {
365 char gname1[256], gname2[256];
373 std::vector<double> toffset, toffseterr;
374 std::vector<double> tsigma, tsigmaerr;
382 toffset[k] = (*(
iter+k))[0];
383 toffseterr[k] = (*(
iter+k))[1];
384 tsigma[k] = (*(
iter+k))[2];
385 tsigmaerr[k] = (*(
iter+k))[3];
388 sprintf( gname1,
"offset-tofid-%i", icounter );
391 (*itgraph)->SetPoint( i, zpos[i], toffset[i] );
392 (*itgraph)->SetPointError( i, zposerr[i], toffseterr[i] );
395 sprintf( gname2,
"sigma-tofid-%i", icounter );
398 (*itgraph)->SetPoint( i, zpos[i], tsigma[i] );
399 (*itgraph)->SetPointError( i, zposerr[i], tsigmaerr[i] );
406void calib_barrel_sigma::fitGraphT0(
unsigned int icounter ) {
409 TF1 *fdouble =
new TF1(
"fdouble",
"pol4",
zbegin,
zend );
410 fdouble->SetLineColor(1);
411 fdouble->SetLineWidth(1);
414 std::vector<TGraphErrors*>::iterator itgraph =
m_graphs.begin() + icounter*
nGraphTotalSigma + (*itnumber) + (*(itnumber+1)) + 2;
415 (*itgraph)->Fit(
"fdouble",
"Q",
"",
zbegin,
zend );
417 std::vector<HepVector>::iterator
iter =
m_result.begin() + icounter;
418 (*iter)[10] = fdouble->GetParameter(0);
419 (*iter)[11] = fdouble->GetParameter(1);
420 (*iter)[12] = fdouble->GetParameter(2);
421 (*iter)[13] = fdouble->GetParameter(3);
422 (*iter)[14] = fdouble->GetParameter(4);
const double barrelRadius
std::vector< Record * > RecordSet
const unsigned int NBarrel
const int nGraphTotalSigma
std::vector< string > CanvasPerCounterName
std::vector< TH1F * > m_histograms
unsigned int nBinPerCounter
unsigned int nCanvasPerCounter
unsigned int nHistPerCounter
const string & name() const
std::vector< HepVector > m_result
std::vector< TGraphErrors * > m_graphs
std::vector< unsigned int > nGraphPerCanvasPerCounter
calib_barrel_sigma(const unsigned int nzbin)
void calculate(RecordSet *&data, unsigned int icounter)