/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Tof/tofcalgsec/tofcalgsec-00-02-21/src/calib_etf_bunch.cxx

Go to the documentation of this file.
00001 #include "tofcalgsec/calib_etf_bunch.h"
00002 #include "TF1.h"
00003 
00004 calib_etf_bunch::calib_etf_bunch( const unsigned int nbunch ):TofCalibFit( true, nParEtfBunch ) {
00005 
00006   nKind          = nbunch;
00007   nBinPerCounter = 3;
00008 
00009   nHistPerCounter   = 0;
00010   nCanvasPerCounter = 0;
00011   nHistogram      = nKind*nBinPerCounter;
00012   nCanvas         = 8;
00013   CanvasName.push_back( static_cast<string>("Offset-bunch0") );
00014   CanvasName.push_back( static_cast<string>("Offset-bunch1") );  
00015   CanvasName.push_back( static_cast<string>("Offset-bunch2") );
00016   CanvasName.push_back( static_cast<string>("Offset-bunch3") );  
00017   CanvasName.push_back( static_cast<string>("Sigma-bunch0") );  
00018   CanvasName.push_back( static_cast<string>("Sigma-bunch1") );  
00019   CanvasName.push_back( static_cast<string>("Sigma-bunch2") );  
00020   CanvasName.push_back( static_cast<string>("Sigma-bunch3") );  
00021 
00022   nGraphPerCanvas.push_back(1);
00023   nGraphPerCanvas.push_back(1);
00024   nGraphPerCanvas.push_back(1);
00025   nGraphPerCanvas.push_back(1);
00026   nGraphPerCanvas.push_back(1);
00027   nGraphPerCanvas.push_back(1);
00028   nGraphPerCanvas.push_back(1);
00029   nGraphPerCanvas.push_back(1);
00030 
00031   int numGraphs = 0;
00032   std::vector<unsigned int>::iterator iter = nGraphPerCanvas.begin();
00033   for( ; iter!=nGraphPerCanvas.end(); iter++ ) {
00034     numGraphs = numGraphs + (*iter);
00035   }
00036   if( numGraphs != nGraphTotalBunch ) {
00037     cout << "tofcalgsec::calib_barrel_common: the number of Graphs is NOT reasonable!!!" << endl;
00038     exit(0);
00039   }
00040 
00041   m_name = string("calib_etf_bunch");
00042 
00043   const int tbin   = 160;
00044   const double tbegin = -0.8;
00045   const double tend   =  0.8;
00046 
00047   char hname[256];
00048   // histograms
00049   for( unsigned int j=0; j<nKind; j++ ) {
00050     for( unsigned int k=0; k<nBinPerCounter; k++ ) {
00051       if( k==0 )      { sprintf( hname, "tleft-bunch%i",  j); }
00052       else if( k==1 ) { sprintf( hname, "tright-bunch%i", j); }
00053       else if( k==2 ) { sprintf( hname, "tcombine-bunch%i", j); }
00054       m_fitresult.push_back( HepVector( nParEtfBunch,0 ) );
00055       m_histograms.push_back( new TH1F( hname, hname, tbin, tbegin, tend ) );
00056     }
00057   }
00058   m_fitresult.push_back( HepVector( nParEtfBunch,0 ) );
00059 
00060   modpos.resize( nBinPerCounter );
00061   modposerr.resize( nBinPerCounter );
00062   for( unsigned int i=0; i<nBinPerCounter; i++ ) {
00063     modpos[i] = 1.0*i;
00064     modposerr[i] = 0.5;
00065   }
00066 
00067   return;
00068 }
00069 
00070 
00071 calib_etf_bunch::~calib_etf_bunch() {
00072   m_fitresult.clear();
00073   modpos.clear();
00074   modposerr.clear();
00075 }
00076 
00077 
00078 void calib_etf_bunch::calculate( RecordSet*& data, unsigned int icounter ) {
00079 
00080   std::cout << setiosflags(ios::left) << setw(10) << icounter << setw(8) << data->size() << setw(30) << name() << std::endl;
00081 
00082   if( data->size() > 0 ) {
00083     std::vector<Record*>::iterator iter = data->begin();
00084     for( ; iter!=data->end(); iter++ ) {
00085       fillRecord( (*iter) );
00086     }
00087   }
00088 
00089   if( icounter==(NEtf*NStrip-1) ) {
00090     fitHistogram();
00091     fillGraph();
00092     fitGraph();
00093   }
00094 
00095   return;
00096 }
00097 
00098 
00099 void calib_etf_bunch::fillRecord( const Record* r ) {
00100   double t0 = r->phi();
00101   int    ibunch = static_cast<int>(t0/(8.0*12000./499.8/8./4. )+0.1)%4;
00102 
00103   if( ibunch<0 || ibunch>int(nBinPerCounter) ) return;
00104 
00105   std::vector<TH1F*>::iterator iter = m_histograms.begin();
00106   (*(iter+nBinPerCounter*ibunch+0))->Fill( r->tleft() );
00107   (*(iter+nBinPerCounter*ibunch+1))->Fill( r->tright() );
00108   (*(iter+nBinPerCounter*ibunch+2))->Fill( r->t0() );
00109 
00110   return;
00111 }
00112 
00113 
00114 void calib_etf_bunch::fitHistogram() {
00115   TF1* g = new TF1("g", "gaus");
00116   g->SetLineColor(2);
00117   g->SetLineWidth(1);
00118 
00119   std::vector<TH1F*>::iterator     iter1 = m_histograms.begin();
00120   std::vector<HepVector>::iterator iter2 = m_fitresult.begin();
00121   for( ; iter1!=m_histograms.end(); iter1++, iter2++ ) {
00122     (*iter1)->Fit( g, "Q");
00123     (*iter2)[0] = g->GetParameter(1);
00124     (*iter2)[1] = g->GetParError(1);
00125     (*iter2)[2] = g->GetParameter(2);
00126     (*iter2)[3] = g->GetParError(2);
00127   }
00128 
00129   return;
00130 }
00131 
00132 
00133 void calib_etf_bunch::fillGraph() {
00134 
00135   char gname1[256], gname2[256];
00136   TH1F *gra[nGraphTotalBunch];
00137 
00138   // 8canvas all counter,
00139   //   1. offset of tleft, tright and tcombine of bunch0  ---  gra[0]
00140   //   2. offset of tleft, tright and tcombine of bunch1  ---  gra[1]
00141   //   3. offset of tleft, tright and tcombine of bunch2  ---  gra[2]
00142   //   4. offset of tleft, tright and tcombine of bunch3  ---  gra[3]
00143   //   5. sigma  of tleft, tright and tcombine of bunch0  ---  gra[4]
00144   //   6. sigma  of tleft, tright and tcombine of bunch1  ---  gra[5]
00145   //   7. sigma  of tleft, tright and tcombine of bunch2  ---  gra[6]
00146   //   8. sigma  of tleft, tright and tcombine of bunch3  ---  gra[7]
00147 
00148 
00149   std::vector<double> toffset, toffseterr;
00150   std::vector<double> tsigma, tsigmaerr;
00151   toffset.resize( nBinPerCounter );
00152   toffseterr.resize( nBinPerCounter );
00153   tsigma.resize( nBinPerCounter );
00154   tsigmaerr.resize( nBinPerCounter );
00155 
00156   unsigned int number = 0;
00157   std::vector<HepVector>::iterator iter = m_fitresult.begin();
00158   for( unsigned int j=0; j<nKind; j++ ) {
00159     sprintf( gname1, "bunch%i-offset", j );
00160     sprintf( gname2, "bunch%i-sigma", j );
00161 
00162     gra[j] = new TH1F( gname1, gname1, nBinPerCounter, -0.5, 2.5 );
00163     gra[j+nKind] = new TH1F( gname2, gname2, nBinPerCounter, -0.5, 2.5 );
00164 
00165     for( unsigned int k=0; k<nBinPerCounter; k++ ) {
00166       number = j*nBinPerCounter + k;
00167       toffset[k]    = (*(iter+number))[0];
00168       toffseterr[k] = (*(iter+number))[1];
00169       tsigma[k]     = (*(iter+number))[2];
00170       tsigmaerr[k]  = (*(iter+number))[3];
00171       gra[j]->SetBinContent( k+1, toffset[k]    );
00172       gra[j]->SetBinError(   k+1, toffseterr[k] );
00173       gra[j+nKind]->SetBinContent( k+1, tsigma[k]    );
00174       gra[j+nKind]->SetBinError(   k+1, tsigmaerr[k] );
00175     }
00176   }
00177 
00178   for( int j=0; j<nGraphTotalBunch; j++, j++ ) {
00179     gra[j]->SetMarkerSize(1.5);
00180     gra[j]->SetMarkerStyle(20);
00181     gra[j]->SetMarkerColor(2);
00182     m_graphs.push_back( gra[j] );
00183 
00184     gra[j+1]->SetMarkerSize(1.5);
00185     gra[j+1]->SetMarkerStyle(21);
00186     gra[j+1]->SetMarkerColor(4);
00187     m_graphs.push_back( gra[j+1] );
00188   }
00189 
00190   return;
00191 }
00192 
00193 
00194 void calib_etf_bunch::fitGraph() {
00195   TF1* p0 = new TF1("p0", "pol0");
00196   p0->SetLineColor(1);
00197   p0->SetLineWidth(1);
00198 
00199   X = HepVector( 2, 0 );
00200   std::vector<TH1F*>::iterator iter=m_graphs.begin();
00201   for( int i=0; i<nParEtfBunch; i++ ) {
00202     (*(iter+i))->Fit( "p0", "Q" );
00203     X[0] = p0->GetParameter(0);
00204     X[1] = p0->GetParError(0);
00205     m_result.push_back( X );
00206   }
00207 
00208   return;
00209 }

Generated on Tue Nov 29 23:14:36 2016 for BOSS_7.0.2 by  doxygen 1.4.7