11#include "EstTofCaliSvc/EstTofCaliSvc.h"
12#include "EstTofCaliSvc/BTofCal.h"
13#include "EstTofCaliSvc/BTofCommonCal.h"
14#include "EstTofCaliSvc/ETofCal.h"
16#include "GaudiKernel/Kernel.h"
17#include "GaudiKernel/IInterface.h"
18#include "GaudiKernel/StatusCode.h"
20#include "GaudiKernel/SvcFactory.h"
21#include "GaudiKernel/MsgStream.h"
26#include "GaudiKernel/IIncidentSvc.h"
27#include "GaudiKernel/Incident.h"
28#include "GaudiKernel/IIncidentListener.h"
29#include "GaudiKernel/IDataProviderSvc.h"
30#include "GaudiKernel/Service.h"
31#include "GaudiKernel/MsgStream.h"
32#include "GaudiKernel/SmartDataPtr.h"
33#include "CalibData/Tof/TofCalibData.h"
34#include "CalibData/Tof/bTofCalibBase.h"
35#include "CalibData/CalibModel.h"
36#include "GaudiKernel/DataSvc.h"
44 declareProperty(
"Run",m_run=1);
49 if ( IID_IEstTofCaliSvc.versionMatch(riid) ) {
52 return Service::queryInterface(riid, ppvInterface) ;
54 return StatusCode::SUCCESS;
58 m_hasbeeninitialized=
false;
61 MsgStream log(
msgSvc(), name());
62 log << MSG::INFO << name() <<
": Start of run initialisation" << endreq;
64 StatusCode sc = Service::initialize();
65 if ( sc.isFailure() )
return sc;
68 sc = service(
"IncidentSvc", incsvc);
71 incsvc -> addListener(
this,
"NewRun", priority);
76 log<<MSG::INFO <<
"setProperties()" << endreq;
77 scc = service(
"CalibDataSvc", m_pCalibDataSvc,
true);
78 if ( !scc.isSuccess() ) {
79 log<<MSG::ERROR<<
"Could not get IDataProviderSvc interface of CalibXmlCnvSvc"<<endreq;
82 log << MSG::DEBUG<<
"Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"<<endreq;
85 scc = setProperties();
91 MsgStream log(
msgSvc(), name());
92 log << MSG::INFO << name() <<
": End of Run" << endreq;
93 return StatusCode::SUCCESS;
97 for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) {
delete (*it1); }
99 for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) {
delete (*it2); }
101 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) {
delete (*it3); }
102 fBTofCommonCal.clear();
105StatusCode EstTofCaliSvc::FillfromDatabase(){
107 MsgStream log(
msgSvc(), name());
108 std::string fullPath =
"/Calib/EstTofCal";
109 log << MSG::INFO<<
" Tof calib fullPath = "<<fullPath<< endreq;
110 SmartDataPtr<CalibData::TofCalibData>
test(m_pCalibDataSvc, fullPath);
112 log << MSG::FATAL <<
"EstTofCaliSvc could not find TofCalibData in TCDS!!" << endreq;
114 return StatusCode::FAILURE;
119 for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) {
delete (*it1); }
121 for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) {
delete (*it2); }
123 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) {
delete (*it3); }
124 fBTofCommonCal.clear();
126 for(
int ib =0;ib<176;ib++){
128 for(
int i=0;i<static_cast<int>(
nBarPar);i++){
130 btof->
setP2(i,
test->getBTofPright(ib,i));
136 fBTofCal.push_back(btof);
139 for(
int ie=0;ie<96;ie++){
141 for(
int i=0;i<static_cast<int>(
nEndPar);i++){
144 fETofCal.push_back(etof);
148 for(
int i=0; i<static_cast<int>(
nBarOffset); i++) {
151 fBTofCommonCal.push_back(bcomtof);
153 return StatusCode::SUCCESS;
159 MsgStream log(
msgSvc(), name());
162 for(
int i=0; i<static_cast<int>(
nBarPar); i++ ) {
163 p1[i]=fBTofCal[id]->getP1(i);
166 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;
168 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;
175 MsgStream log(
msgSvc(), name());
178 for(
int i=0; i<static_cast<int>(
nBarPar); i++ ) {
179 p2[i]=fBTofCal[id]->getP2(i);
182 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;
184 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;
235 double toffset = fBTofCommonCal[0]->getOffset(0);
241 MsgStream log(
msgSvc(), name());
243 double tcorr1 =
BTCorr1( ADC, z,
id );
245 double tcorr3 = fBTofCommonCal[0]->getOffset(0);
248 log << MSG::DEBUG <<
"BTime1 id =" <<
id <<
" tcorr=" << tcorr1 <<
" total offset=" << tcorr3 << endreq;
251 double time = TDC - tcorr1 - tcorr3;
254 log<<MSG::WARNING<<
"TofCaliSvc::BTime1() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" z = "<<z<<
" ID = "<<
id<<endreq;
261 MsgStream log(
msgSvc(), name());
263 double tcorr1 =
BTCorr2( ADC, z,
id );
265 double tcorr3 = fBTofCommonCal[0]->getOffset(0);
268 log << MSG::DEBUG <<
"BTime2 id =" <<
id <<
" tcorr=" << tcorr1 <<
" total offset=" << tcorr3 << endreq;
271 double time = TDC - tcorr1 - tcorr3;
274 log<<MSG::WARNING<<
"TofCaliSvc::BTime2() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" z = "<<z<<
" ID = "<<
id<<endreq;
281 MsgStream log(
msgSvc(), name());
284 for(
int i=0; i<static_cast<int>(
nEndPar); i++ ) {
285 p[i]=fETofCal[id]->getP(i);
288 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;
290 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);
293 MsgStream log(
msgSvc(), name());
294 log<<MSG::WARNING<<
"TofCaliSvc::ETime() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" r = "<< rHit <<
" ID = "<<
id<<endreq;
310 return fBTofCommonCal[0];
314 std::cout<<
"Now We can get the TOF Calibtration Service"<<std::endl;
315 std::cout<<
"Barrel TOF Counter Number = "<<fBTofCal.size()<<std::endl;
316 std::cout<<
"Endcap TOF Counter Number = "<<fETofCal.size()<<std::endl;
318 cout<<
"The O Barrel TOF PMT1 p1[0] is"<<
" "<<
BTof(0)->
getP1(0)<<endl;
319 cout<<
"The 0 Barrel TOF PMT1 p1[1] is"<<
" "<<
BTof(0)->
getP1(1)<<endl;
323 MsgStream log( messageService(), name() );
324 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
326 if ( inc.type() ==
"NewRun" ){
327 log << MSG::DEBUG <<
"New Run" << endreq;
329 StatusCode sc= FillfromDatabase();
331 m_hasbeeninitialized=
true;
const unsigned int nBarOffset
const unsigned int nEndPar
const unsigned int nBarPar
double getP1(int idx) const
void setP1(int idx, double p1)
void setP2(int idx, double p2)
void setOffset(int idx, double offset)
void setP(int i, double p)
virtual StatusCode initialize()
ETofCal * ETof(unsigned id) const
void handle(const Incident &)
virtual StatusCode finalize()
BTofCal * BTof(unsigned id) const
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
const double BTime2(double ADC, double TDC, double zHit, unsigned id)
const double ETime(double ADC, double TDC, double rHit, unsigned id)
EstTofCaliSvc(const std::string &name, ISvcLocator *svcloc)
const double BTime1(double ADC, double TDC, double zHit, unsigned id)
const double BTCorr1(double ADC, double zHit, unsigned int id)
const double BTCorr2(double ADC, double zHit, unsigned int id)
BTofCommonCal * BTofCommon() const