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

Go to the documentation of this file.
00001 #include "tofcalgsec/calib_endcap_sigma.h"
00002 #include "TF1.h"
00003 
00004 calib_endcap_sigma::calib_endcap_sigma( const unsigned int nrbin ):TofCalibFit( false, nEndcapSigma ) {
00005 
00006   nKind          = 1;    // 0:tleft
00007   nBinPerCounter = nrbin;
00008 
00009   nHistPerCounter   = nKind*nBinPerCounter;
00010   nCanvasPerCounter = 2;
00011   CanvasPerCounterName.push_back( static_cast<string>("Endcap-offset") );  
00012   CanvasPerCounterName.push_back( static_cast<string>("Endcap-sigma") );  
00013 
00014   nGraphPerCanvasPerCounter.push_back(1);
00015   nGraphPerCanvasPerCounter.push_back(1);
00016 
00017   nHistogram      = 0;
00018   nCanvas         = 0;
00019 
00020   int numGraphs = 0;
00021   std::vector<unsigned int>::iterator iter = nGraphPerCanvasPerCounter.begin();
00022   for( ; iter!=nGraphPerCanvasPerCounter.end(); iter++ ) {
00023     numGraphs = numGraphs + (*iter);
00024   }
00025   if( numGraphs != nGraphEcSigma ) {
00026     cout << "tofcalgsec::calib_endcap_sigma: the number of Graphs is NOT reasonable!!!" << endl;
00027     exit(0);
00028   }
00029 
00030   m_name = string("calib_endcap_sigma");
00031 
00032   const int tbin   = 150;
00033   const double tbegin = -1.5;
00034   const double tend   =  1.5;
00035 
00036   // histograms per counter
00037   char hname[256];
00038   for( unsigned int i=0; i<NEndcap; i++ ) {
00039     m_result.push_back( HepVector(nEndcapSigma,0) );
00040     for( unsigned int j=0; j<nKind; j++ ) {
00041       for( unsigned int k=0; k<nBinPerCounter; k++ ) {
00042         sprintf( hname, "tleft-tofid%i-r%i",  i, k);
00043         m_histograms.push_back( new TH1F( hname, hname, tbin, tbegin, tend ) );
00044 
00045         m_fitresult.push_back( HepVector(nParEcSigma,0) );
00046       }
00047     }
00048   }
00049 
00050   rpos.resize( nBinPerCounter );
00051   rposerr.resize( nBinPerCounter );
00052   rstep = ( rend - rbegin )/nBinPerCounter;
00053   for( unsigned int i=0; i<nBinPerCounter; i++ ) {
00054     rpos[i] = rbegin + ( i+0.5 )*rstep;
00055     rposerr[i] = 0.5*rstep;
00056   }
00057 
00058 }
00059 
00060 
00061 calib_endcap_sigma::~calib_endcap_sigma() {
00062   m_fitresult.clear();
00063   rpos.clear();
00064   rposerr.clear();
00065 }
00066 
00067 
00068 void calib_endcap_sigma::calculate( RecordSet*& data, unsigned int icounter ) {
00069 
00070   std::cout << setiosflags(ios::left) << setw(10) << icounter << setw(8) << data->size() << setw(30) << name() << std::endl;
00071 
00072   if( data->size() > 0 ) {
00073     std::vector<Record*>::iterator iter = data->begin();
00074     for( ; iter!=data->end(); iter++ ) {
00075       fillRecord( (*iter), icounter );
00076     }
00077   }
00078   fitHistogram( icounter );
00079   fillGraph( icounter );
00080   fitGraph( icounter );
00081 
00082   return;
00083 }
00084 
00085 
00086 void calib_endcap_sigma::fillRecord( const Record* r, unsigned int icounter ) {
00087 
00088   double rhit = r->zrhit();
00089   if( rhit<rbegin || rhit>rend ) return;
00090   int rbin = static_cast<int>((rhit-rbegin)/rstep);
00091   if( rbin<0 ) { rbin = 0; }
00092   else if( rbin>static_cast<int>(nBinPerCounter-1) ) {
00093     cout << "tofcalgsec::calib_endcap_sigma:fillRecord: rhit is out of range, rhit=" << rhit << " rbin=" << rbin << endl;
00094     return;
00095   }
00096 
00097   std::vector<TH1F*>::iterator iter = m_histograms.begin() + icounter*nKind*nBinPerCounter + rbin;
00098   (*iter)->Fill( r->tleft() );
00099 
00100   return;
00101 }
00102 
00103 
00104 void calib_endcap_sigma::fitHistogram( unsigned int icounter ) {
00105   TF1* g = new TF1("g", "gaus");
00106   g->SetLineColor(2);
00107   g->SetLineWidth(1);
00108 
00109   std::vector<TH1F*>::iterator     iter1 = m_histograms.begin() + icounter*nKind*nBinPerCounter;
00110   std::vector<HepVector>::iterator iter2 = m_fitresult.begin() + icounter*nKind*nBinPerCounter;
00111   for( unsigned int j=0; j<nBinPerCounter; j++, iter1++, iter2++ ) {
00112     (*iter1)->Fit( g, "Q");
00113     (*iter2)[0] = g->GetParameter(1);
00114     (*iter2)[1] = g->GetParError(1);
00115     (*iter2)[2] = g->GetParameter(2);
00116     (*iter2)[3] = g->GetParError(2);
00117   }
00118 
00119   return;
00120 
00121 }
00122 
00123 
00124 void calib_endcap_sigma::fillGraph( unsigned int icounter ) {
00125 
00126   char gname1[256], gname2[256];
00127 
00128   // fill graphs per counter
00129   // 4 canvas per counter,
00130   //   1. offset of tleft vs z 
00131   //   2. sigma  of tleft vs z
00132   std::vector<double> toffset, toffseterr;
00133   std::vector<double> tsigma, tsigmaerr;
00134   toffset.resize( nBinPerCounter );
00135   toffseterr.resize( nBinPerCounter );
00136   tsigma.resize( nBinPerCounter );
00137   tsigmaerr.resize( nBinPerCounter );
00138 
00139   std::vector<HepVector>::iterator iter = m_fitresult.begin() + icounter*nKind*nBinPerCounter;
00140   for( unsigned int k=0; k<nBinPerCounter; k++ ) {
00141     toffset[k]    = (*(iter+k))[0];
00142     toffseterr[k] = (*(iter+k))[1];
00143     tsigma[k]     = (*(iter+k))[2];
00144     tsigmaerr[k]  = (*(iter+k))[3];
00145   }
00146 
00147   sprintf( gname1, "endcap-offset-tofid-%i", icounter );
00148   m_graphs.push_back( new TH1F( gname1, gname1, nBinPerCounter, rbegin, rend ) );
00149   std::vector<TH1F*>::iterator itgraph = m_graphs.end() - 1;
00150   (*itgraph)->SetMarkerSize(1.5);
00151   (*itgraph)->SetMarkerStyle(20);
00152   (*itgraph)->SetMarkerColor(2);
00153   for( unsigned int k=0; k<nBinPerCounter; k++ ) {
00154     (*itgraph)->SetBinContent( k+1, toffset[k]    );
00155     (*itgraph)->SetBinError(   k+1, toffseterr[k] );
00156   }
00157 
00158   sprintf( gname2, "endcap-sigma-tofid-%i", icounter );
00159   m_graphs.push_back( new TH1F( gname2, gname2, nBinPerCounter, rbegin, rend ) );
00160   itgraph = m_graphs.end() - 1;
00161   (*itgraph)->SetMarkerSize(1.5);
00162   (*itgraph)->SetMarkerStyle(21);
00163   (*itgraph)->SetMarkerColor(4);
00164   for( unsigned int k=0; k<nBinPerCounter; k++ ) {
00165     (*itgraph)->SetBinContent( k+1, tsigma[k]    );
00166     (*itgraph)->SetBinError(   k+1, tsigmaerr[k] );
00167   }
00168 
00169   return;
00170 }
00171 
00172 
00173 void calib_endcap_sigma::fitGraph( unsigned int icounter ) {
00174 
00175   TF1* p2 = new TF1("p2", "pol2", rbegin, rend );
00176 
00177   //  std::vector<unsigned int>::iterator itnumber = nGraphPerCanvasPerCounter.begin();
00178   std::vector<TH1F*>::iterator itgraph = m_graphs.begin() + icounter*nGraphEcSigma + 1;
00179 
00180   (*itgraph)->Fit( "p2", "Q" );
00181   X = HepVector( m_npar, 0 );
00182   X[0] = p2->GetParameter(0);
00183   X[1] = p2->GetParameter(1);
00184   X[2] = p2->GetParameter(2);
00185 
00186   std::vector<HepVector>::iterator iter = m_result.begin() + icounter;
00187   (*iter) = X;
00188 
00189   return;
00190 }

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