/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Tof/EstTofCaliSvc/EstTofCaliSvc-00-00-10/src/EstTofCaliSvc.cxx

Go to the documentation of this file.
00001 //********************************************************
00002 //
00003 //  Class: EstTofCaliSvc 
00004 //  Sun Shengsen <sunss@ihep.ac.cn>
00005 //  
00006 //  Description:
00007 //     This service is used to get Tof Calibrarion constants
00008 //     from DataBase and do the Tof data reconstruction.
00009 //
00010 //*********************************************************
00011 #include "EstTofCaliSvc/EstTofCaliSvc.h"
00012 #include "EstTofCaliSvc/BTofCal.h"
00013 #include "EstTofCaliSvc/BTofCommonCal.h"
00014 #include "EstTofCaliSvc/ETofCal.h"
00015 #include "EstTofCaliSvc/EtfCal.h"
00016 #include "GaudiKernel/Kernel.h"
00017 #include "GaudiKernel/IInterface.h"
00018 #include "GaudiKernel/StatusCode.h"
00019 #include "GaudiKernel/SvcFactory.h"
00020 #include "GaudiKernel/MsgStream.h"
00021 #include "TMath.h"
00022 #include <math.h>
00023 #include <iostream>
00024 #include <fstream>
00025 #include "GaudiKernel/IIncidentSvc.h"
00026 #include "GaudiKernel/Incident.h"
00027 #include "GaudiKernel/IIncidentListener.h"
00028 #include "GaudiKernel/IDataProviderSvc.h"
00029 #include "GaudiKernel/Service.h"
00030 #include "GaudiKernel/MsgStream.h"
00031 #include "GaudiKernel/SmartDataPtr.h"
00032 #include "CalibData/Tof/TofCalibData.h"
00033 #include "CalibData/Tof/bTofCalibBase.h"
00034 #include "CalibData/CalibModel.h"
00035 #include "GaudiKernel/DataSvc.h"
00036 
00037 using namespace std;
00038 
00039 // static double radius_Inner =   81.35;
00040 // static double radius_Outer =   87.05;
00041   
00042 EstTofCaliSvc::EstTofCaliSvc( const std::string& name, ISvcLocator* svcloc ) : Service(name, svcloc) {
00043   declareProperty("Run",m_run=1);
00044 }
00045 
00046 StatusCode EstTofCaliSvc::queryInterface (const InterfaceID& riid, void** ppvInterface ){
00047   
00048   if ( IID_IEstTofCaliSvc.versionMatch(riid) ) { 
00049     *ppvInterface = static_cast<IEstTofCaliSvc*> (this); 
00050   } else { 
00051     return Service::queryInterface(riid, ppvInterface) ; 
00052   }
00053   return StatusCode::SUCCESS;
00054 }
00055 
00056 StatusCode EstTofCaliSvc::initialize ( ) {
00057   m_hasbeeninitialized=false;
00058   m_st=false;
00059 
00060   MsgStream log(msgSvc(), name());
00061   log << MSG::INFO << name() << ": Start of run initialisation" << endreq;
00062   
00063   StatusCode sc = Service::initialize();
00064   if ( sc.isFailure() ) return sc;
00065 
00066   IIncidentSvc* incsvc;
00067   sc = service("IncidentSvc", incsvc);
00068   int priority = 100;
00069   if( sc.isSuccess() ){
00070     incsvc -> addListener(this, "NewRun", priority);
00071   }
00072 
00073   StatusCode scc;
00074   
00075   log<<MSG::INFO << "setProperties()" << endreq;
00076   scc = service("CalibDataSvc", m_pCalibDataSvc, true);
00077   if ( !scc.isSuccess() ) {
00078     log<<MSG::ERROR<<"Could not get IDataProviderSvc interface of CalibXmlCnvSvc"<<endreq;
00079     return scc;
00080   } else {
00081     log << MSG::DEBUG<< "Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"<<endreq;
00082   }
00083   // Get properties from the JobOptionsSvc
00084   scc = setProperties();
00085   
00086   return sc;
00087 }  
00088   
00089 StatusCode EstTofCaliSvc::finalize ( ) {
00090   MsgStream log(msgSvc(), name());
00091   log << MSG::INFO << name() << ": End of Run" << endreq;
00092   return StatusCode::SUCCESS;
00093 }
00094 
00095 EstTofCaliSvc::~EstTofCaliSvc(){
00096   for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) { delete (*it1); }
00097   fBTofCal.clear();
00098   for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) { delete (*it2); }
00099   fETofCal.clear();
00100   if( fEtfCal.size()!=0 ) {
00101     for(vector<EtfCal*>::iterator it5 = fEtfCal.begin(); it5 != fEtfCal.end(); it5++) { delete (*it5); }
00102     fEtfCal.clear();
00103   }
00104   for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) { delete (*it3); }
00105   fBTofCommonCal.clear();
00106   return;
00107 }
00108 StatusCode EstTofCaliSvc::FillfromDatabase(){
00109 
00110   MsgStream log(msgSvc(), name());    
00111   std::string fullPath = "/Calib/EstTofCal";
00112   log << MSG::INFO<<" Tof calib fullPath = "<<fullPath<< endreq;
00113   SmartDataPtr<CalibData::TofCalibData> test(m_pCalibDataSvc, fullPath);
00114   if(!test){
00115     log << MSG::FATAL << "EstTofCaliSvc could not find TofCalibData in TCDS!!" << endreq;
00116     m_st=false;    
00117     return StatusCode::FAILURE;
00118   }       
00119 
00120   m_st=true;
00121 
00122   for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) { delete (*it1); }
00123   fBTofCal.clear();
00124   for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) { delete (*it2); }
00125   fETofCal.clear();
00126   if( fEtfCal.size()!=0 ) {
00127     for(vector<EtfCal*>::iterator it5 = fEtfCal.begin(); it5 != fEtfCal.end(); it5++) { delete (*it5); }
00128     fEtfCal.clear();
00129   }
00130   for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) { delete (*it3); }
00131   fBTofCommonCal.clear();
00132 
00133   for(int ib =0;ib<176;ib++){
00134     BTofCal* btof = new BTofCal;
00135     for(int i=0;i<static_cast<int>(nBarPar);i++){
00136       btof->setP1(i,test->getBTofPleft(ib,i));
00137       btof->setP2(i,test->getBTofPright(ib,i));
00138     }
00139     fBTofCal.push_back(btof);
00140   }       
00141 
00142   for(int ie=0;ie<96;ie++){
00143     ETofCal* etof= new ETofCal;
00144     for(int i=0;i<static_cast<int>(nEndPar);i++){
00145       etof->setP(i,test->getETofP(ie,i));
00146     }
00147     fETofCal.push_back(etof);
00148   }
00149 
00150   for(int ietf=0;ietf<72;ietf++) {
00151     for(int jetf=0;jetf<12;jetf++) {
00152       EtfCal* etf= new EtfCal;
00153       for( int k=0; k<static_cast<int>(nEtfPar); k++ ) {
00154         etf->setP( k,test->getEtfPcombine(ietf,jetf,k));
00155         etf->setP1(k,test->getEtfPleft(ietf,jetf,k));
00156         etf->setP2(k,test->getEtfPright(ietf,jetf,k));
00157       }
00158       fEtfCal.push_back(etf);
00159     }
00160   }
00161 
00162   BTofCommonCal* bcomtof = new BTofCommonCal;
00163   for(int i=0; i<static_cast<int>(nBarOffset); i++) {
00164     bcomtof->setOffset( i, test->getBTofOffset(i) );
00165   }
00166   fBTofCommonCal.push_back(bcomtof);
00167 
00168   return StatusCode::SUCCESS;
00169 
00170 }
00171 
00172 
00173 const double EstTofCaliSvc::BTCorr1(double ADC,double z,unsigned id){
00174   MsgStream log(msgSvc(), name());    
00175 
00176   double p1[nBarPar];
00177   for( int i=0; i<static_cast<int>(nBarPar); i++ ) {
00178     p1[i]=fBTofCal[id]->getP1(i);
00179   }
00180 
00181   log << MSG::DEBUG << "BTCorr1   id =" << id  << "  1=" << p1[0] << " 2=" << p1[1] << " 3=" << p1[2] << " 4=" << p1[3]  << " 5=" << p1[4] << " 6=" << p1[5] << " 7=" << p1[6] << " 8=" << p1[7] << " 9=" << p1[8] << endreq;
00182 
00183   double tcorr1 = p1[0] + p1[1]/TMath::Sqrt(ADC) + p1[2]*z/TMath::Sqrt(ADC) + p1[3]/ADC + p1[4]*z + p1[5]*z*z + p1[6]*z*z*z;
00184 
00185   return tcorr1;
00186 }
00187 
00188 
00189 const double EstTofCaliSvc::BTCorr2(double ADC,double z,unsigned id){
00190   MsgStream log(msgSvc(), name());    
00191 
00192   double p2[nBarPar];
00193   for( int i=0; i<static_cast<int>(nBarPar); i++ ) {
00194     p2[i]=fBTofCal[id]->getP2(i);
00195   }
00196 
00197   log << MSG::DEBUG << "BTCorr2   id =" << id  << "  1=" << p2[0] << " 2=" << p2[1] << " 3=" << p2[2] << " 4=" << p2[3]  << " 5=" << p2[4] << " 6=" << p2[5] << " 7=" << p2[6] << " 8=" << p2[7] << " 9=" << p2[8] << endreq;
00198 
00199   double tcorr2 = p2[0] + p2[1]/TMath::Sqrt(ADC) + p2[2]*z/TMath::Sqrt(ADC) + p2[3]/ADC + p2[4]*z + p2[5]*z*z + p2[6]*z*z*z;
00200 
00201   return tcorr2;
00202 }
00203 
00204 
00205 const double EstTofCaliSvc::TOffset() {
00206   double toffset = fBTofCommonCal[0]->getOffset(0);
00207   return toffset;
00208 }
00209 
00210 
00211 const double EstTofCaliSvc::BTime1(double ADC,double TDC,double z,unsigned id){
00212   MsgStream log(msgSvc(), name());    
00213 
00214   double tcorr1 = BTCorr1( ADC, z, id );
00215   double tcorr3 = fBTofCommonCal[0]->getOffset(0);
00216 
00217   log << MSG::DEBUG << "BTime1   id =" << id  << "  tcorr=" << tcorr1 << "  total offset=" << tcorr3 << endreq;
00218 
00219   double time = TDC - tcorr1 - tcorr3;
00220 
00221   if(time<0.) {
00222     log<<MSG::WARNING<<"TofCaliSvc::BTime1() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" z = "<<z<<" ID = "<<id<<endreq;
00223   }
00224   return time;     
00225 }
00226 
00227 
00228 const double EstTofCaliSvc::BTime2(double ADC,double TDC,double z,unsigned id){
00229   MsgStream log(msgSvc(), name());    
00230 
00231   double tcorr1 = BTCorr2( ADC, z, id );
00232   double tcorr3 = fBTofCommonCal[0]->getOffset(0);
00233 
00234   log << MSG::DEBUG << "BTime2   id =" << id  << "  tcorr=" << tcorr1 << "  total offset=" << tcorr3 << endreq;
00235 
00236   double time = TDC - tcorr1 - tcorr3;
00237 
00238   if(time<0.) {
00239     log<<MSG::WARNING<<"TofCaliSvc::BTime2() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" z = "<<z<<" ID = "<<id<<endreq;
00240   }
00241   return time;     
00242 }
00243 
00244 
00245 const double EstTofCaliSvc::ETime(double ADC,double TDC,double rHit,unsigned id){
00246   MsgStream log(msgSvc(), name());
00247 
00248   double p[nEndPar];
00249   for( int i=0; i<static_cast<int>(nEndPar); i++ ) {
00250     p[i]=fETofCal[id]->getP(i);
00251   }
00252 
00253   log << MSG::DEBUG << "ETime   id =" << id  << "  1=" << p[0] << " 2=" << p[1] << " 3=" << p[2] << " 4=" << p[3]  << " 5=" << p[4] << " 6=" << p[5] << " 7=" << p[6] << endreq;
00254 
00255   double time=TDC-(p[0]+p[1]/TMath::Sqrt(ADC)+p[2]/ADC+p[3]*ADC+p[4]*rHit+p[5]*rHit*rHit+p[6]*rHit*rHit*rHit);
00256 
00257   if(time<0.) {
00258     log<<MSG::WARNING<<"TofCaliSvc::ETime() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" r = "<< rHit <<" ID = "<<id<<endreq;
00259   }
00260 
00261   return time;
00262 }
00263 
00264 
00265 const double EstTofCaliSvc::EtfTime(double ADC1,double ADC2,double TDC1,double TDC2,unsigned id,unsigned int strip){
00266   MsgStream log(msgSvc(), name());    
00267 
00268   double q = (ADC1+ADC2)/2.0;
00269   double t = (TDC1+TDC2)/2.0;
00270 
00271   double p[nEtfPar];
00272   for( int i=0; i<static_cast<int>(nEtfPar); i++ ) {
00273     p[i]=fEtfCal[12*id+strip]->getP(i);
00274   }
00275 
00276   double tcorr = p[0] 
00277                + p[1]/TMath::Sqrt(q)
00278                + p[2]/q
00279                + p[3]*q
00280                + p[4]*q*q
00281                + p[5]*q*q*q
00282                + p[6]*q*q*q*q;
00283   double time = t - tcorr;
00284 
00285   log << MSG::DEBUG << "EtfTime   module =" << id  << " strip=" << strip << "  1=" << p[0] << " 2=" << p[1] << " 3=" << p[2] << " 4=" << p[3]  << " 5=" << p[4] << " 6=" << p[5] << " 7=" << p[6] << " 8=" << p[7] << " 9=" << p[8] << " tcorr=" << tcorr << " time=" << time << endreq;
00286   if( time<0.) {
00287     log<<MSG::WARNING<<"TofCaliSvc::EtfTime() -- A minus time is given : "<< time <<" [Input] ADC1 = "<<ADC1<<" ADC2 = "<<ADC2<<" TDC1 = "<<TDC1<<" TDC2 = "<<TDC2<<" ID = "<<id<<" Strip = "<<strip<<endreq;
00288   }
00289 
00290   return time;
00291 }
00292 
00293 
00294 const double EstTofCaliSvc::EtfTime1(double ADC,double TDC,double z,unsigned id,unsigned int strip){
00295   MsgStream log(msgSvc(), name());    
00296 
00297   double p1[nEtfPar];
00298   for( int i=0; i<static_cast<int>(nEtfPar); i++ ) {
00299     p1[i]=fEtfCal[12*id+strip]->getP1(i);
00300   }
00301 
00302   double tcorr1 = p1[0] 
00303                 + p1[1]/TMath::Sqrt(ADC)
00304                 + p1[2]*ADC
00305                 + p1[3]*ADC*ADC
00306                 + p1[4]*ADC*ADC*ADC
00307                 + p1[5]*ADC*ADC*ADC*ADC
00308                 + p1[6]*z/TMath::Sqrt(ADC)
00309                 + p1[7]/ADC
00310                 + p1[8]*z/ADC
00311                 + p1[9]*z*ADC
00312                 + p1[10]*z
00313                 + p1[11]*z*z
00314                 + p1[12]*z*z*z;
00315   double time1 = TDC - tcorr1;
00316 
00317   log << MSG::DEBUG << "EtfTime1   module =" << id  << " strip=" << strip << "  1=" << p1[0] << " 2=" << p1[1] << " 3=" << p1[2] << " 4=" << p1[3]  << " 5=" << p1[4] << " 6=" << p1[5] << " 7=" << p1[6] << " 8=" << p1[7] << " 9=" << p1[8] << " tcorr=" << tcorr1 << " time1=" << time1 << endreq;
00318   if( time1<0.) {
00319     log<<MSG::WARNING<<"TofCaliSvc::EtfTime1() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" z = "<<z<<" ID = "<<id<<" Strip = "<<strip<<endreq;
00320   }
00321 
00322   return time1;
00323 }
00324 
00325 
00326 const double EstTofCaliSvc::EtfTime2(double ADC,double TDC,double z,unsigned id,unsigned int strip){
00327   MsgStream log(msgSvc(), name());    
00328 
00329   double p2[nEtfPar];
00330   for( int i=0; i<static_cast<int>(nEtfPar); i++ ) {
00331     p2[i]=fEtfCal[12*id+strip]->getP2(i);
00332   }
00333 
00334   double tcorr2 = p2[0]
00335                 + p2[1]/TMath::Sqrt(ADC)
00336                 + p2[2]*ADC
00337                 + p2[3]*ADC*ADC
00338                 + p2[4]*ADC*ADC*ADC
00339                 + p2[5]*ADC*ADC*ADC*ADC
00340                 + p2[6]*z/TMath::Sqrt(ADC)
00341                 + p2[7]/ADC
00342                 + p2[8]*z/ADC
00343                 + p2[9]*z*ADC
00344                 + p2[10]*z
00345                 + p2[11]*z*z
00346                 + p2[12]*z*z*z;
00347   double time2 = TDC - tcorr2;
00348 
00349   log << MSG::DEBUG << "EtfTime2   module =" << id  << " strip=" << strip << "  1=" << p2[0] << " 2=" << p2[1] << " 3=" << p2[2] << " 4=" << p2[3]  << " 5=" << p2[4] << " 6=" << p2[5] << " 7=" << p2[6] << " 8=" << p2[7] << " 9=" << p2[8] << " tcorr=" << tcorr2 << " time2=" << time2 << endreq;
00350   if( time2<0.) {
00351     log<<MSG::WARNING<<"TofCaliSvc::EtfTime2() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" z = "<<z<<" ID = "<<id<<" Strip = "<<strip<<endreq;
00352   }
00353 
00354   return time2;
00355 }
00356 
00357 
00358 const double EstTofCaliSvc::EtfTime(double TDC1,double TDC2,unsigned id,unsigned int strip){
00359   MsgStream log(msgSvc(), name());    
00360 
00361   double time = -99;
00362   double t, tcorr;
00363 
00364   if( TDC1>0 && TDC2>0 ) {
00365     t = (TDC1+TDC2)/2.0;
00366     tcorr = fEtfCal[12*id+strip]->getP(0);
00367     time = t - tcorr;
00368     log << MSG::DEBUG << "EtfTime   module =" << id  << " strip=" << strip << " t1=" << TDC1 << " t2=" << TDC2 << "  combine const=" << tcorr << " time=" << time << endreq;
00369   }
00370   else if( TDC1>0 && TDC2<0 ) {
00371     t = TDC1;
00372     tcorr =  fEtfCal[12*id+strip]->getP1(0);
00373     time = t - tcorr;
00374     log << MSG::DEBUG << "EtfTime   module =" << id  << " strip=" << strip << " t1=" << TDC1 << "  left const=" << tcorr << " time=" << time << endreq;
00375   }
00376   else if( TDC1<0 && TDC2>0 ) {
00377     t = TDC2;
00378     tcorr =  fEtfCal[12*id+strip]->getP2(0);
00379     time = t - tcorr;
00380     log << MSG::DEBUG << "EtfTime   module =" << id  << " strip=" << strip << " t2=" << TDC2 << "  right const=" << tcorr << " time=" << time << endreq;
00381   }
00382 
00383   if( time<0.) {
00384     log<<MSG::WARNING<<"TofCaliSvc::EtfTime() -- A minus time is given : "<< time <<" [Input]  TDC1 = "<<TDC1<<" TDC2 = "<<TDC2<<" ID = "<<id<<" Strip = "<<strip<<endreq;
00385   }
00386 
00387   return time;
00388 }
00389 
00390 
00391 BTofCal* EstTofCaliSvc::BTof(unsigned id) const{
00392   return  fBTofCal[id];
00393 }
00394 
00395 ETofCal* EstTofCaliSvc::ETof(unsigned id) const{
00396   return  fETofCal[id];
00397 }    
00398 
00399 EtfCal* EstTofCaliSvc::EtfTof(unsigned id) const{
00400   return  fEtfCal[id];
00401 }    
00402 
00403 BTofCommonCal* EstTofCaliSvc::BTofCommon() const{
00404   return  fBTofCommonCal[0];
00405 }
00406         
00407 void EstTofCaliSvc::Dump(){
00408   std::cout<<"Now We can get the TOF Calibtration Service"<<std::endl;
00409   std::cout<<"Barrel TOF Counter Number = "<<fBTofCal.size()<<std::endl;
00410   std::cout<<"Endcap TOF Counter Number = "<<fETofCal.size()<<std::endl;
00411 
00412   cout<<"The O  Barrel TOF PMT1 p1[0]  is"<<" "<<BTof(0)->getP1(0)<<endl; 
00413   cout<<"The 0  Barrel TOF PMT1 p1[1]  is"<<" "<<BTof(0)->getP1(1)<<endl; 
00414 }
00415 
00416 void EstTofCaliSvc::handle(const Incident& inc){
00417   MsgStream log( messageService(), name() );
00418   log << MSG::DEBUG << "handle: " << inc.type() << endreq;
00419 
00420   if ( inc.type() == "NewRun" ){
00421     log << MSG::DEBUG << "New Run" << endreq;
00422     //    if(!m_hasbeeninitialized){
00423     StatusCode sc= FillfromDatabase();
00424     if(sc.isSuccess()){
00425       m_hasbeeninitialized=true;
00426     }
00427     //    }
00428   }
00429 }

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