11#include "EstTofCaliSvc/EstTofCaliSvc.h"
12#include "EstTofCaliSvc/BTofCal.h"
13#include "EstTofCaliSvc/BTofCommonCal.h"
14#include "EstTofCaliSvc/ETofCal.h"
15#include "EstTofCaliSvc/EtfCal.h"
16#include "GaudiKernel/Kernel.h"
17#include "GaudiKernel/IInterface.h"
18#include "GaudiKernel/StatusCode.h"
19#include "GaudiKernel/SvcFactory.h"
20#include "GaudiKernel/MsgStream.h"
25#include "GaudiKernel/IIncidentSvc.h"
26#include "GaudiKernel/Incident.h"
27#include "GaudiKernel/IIncidentListener.h"
28#include "GaudiKernel/IDataProviderSvc.h"
29#include "GaudiKernel/Service.h"
30#include "GaudiKernel/MsgStream.h"
31#include "GaudiKernel/SmartDataPtr.h"
32#include "CalibData/Tof/TofCalibData.h"
33#include "CalibData/Tof/bTofCalibBase.h"
34#include "CalibData/CalibModel.h"
35#include "GaudiKernel/DataSvc.h"
43 declareProperty(
"Run",m_run=1);
48 if ( IID_IEstTofCaliSvc.versionMatch(riid) ) {
51 return Service::queryInterface(riid, ppvInterface) ;
53 return StatusCode::SUCCESS;
57 m_hasbeeninitialized=
false;
60 MsgStream log(
msgSvc(), name());
61 log << MSG::INFO << name() <<
": Start of run initialisation" << endreq;
63 StatusCode sc = Service::initialize();
64 if ( sc.isFailure() )
return sc;
67 sc = service(
"IncidentSvc", incsvc);
70 incsvc -> addListener(
this,
"NewRun", priority);
75 log<<MSG::INFO <<
"setProperties()" << endreq;
76 scc = service(
"CalibDataSvc", m_pCalibDataSvc,
true);
77 if ( !scc.isSuccess() ) {
78 log<<MSG::ERROR<<
"Could not get IDataProviderSvc interface of CalibXmlCnvSvc"<<endreq;
81 log << MSG::DEBUG<<
"Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"<<endreq;
84 scc = setProperties();
90 MsgStream log(
msgSvc(), name());
91 log << MSG::INFO << name() <<
": End of Run" << endreq;
92 return StatusCode::SUCCESS;
96 for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) {
delete (*it1); }
98 for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) {
delete (*it2); }
100 if( fEtfCal.size()!=0 ) {
101 for(vector<EtfCal*>::iterator it5 = fEtfCal.begin(); it5 != fEtfCal.end(); it5++) {
delete (*it5); }
104 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) {
delete (*it3); }
105 fBTofCommonCal.clear();
108StatusCode EstTofCaliSvc::FillfromDatabase(){
110 MsgStream log(
msgSvc(), name());
111 std::string fullPath =
"/Calib/EstTofCal";
112 log << MSG::INFO<<
" Tof calib fullPath = "<<fullPath<< endreq;
113 SmartDataPtr<CalibData::TofCalibData>
test(m_pCalibDataSvc, fullPath);
115 log << MSG::FATAL <<
"EstTofCaliSvc could not find TofCalibData in TCDS!!" << endreq;
117 return StatusCode::FAILURE;
122 for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) {
delete (*it1); }
124 for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) {
delete (*it2); }
126 if( fEtfCal.size()!=0 ) {
127 for(vector<EtfCal*>::iterator it5 = fEtfCal.begin(); it5 != fEtfCal.end(); it5++) {
delete (*it5); }
130 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) {
delete (*it3); }
131 fBTofCommonCal.clear();
133 for(
int ib =0;ib<176;ib++){
135 for(
int i=0;i<static_cast<int>(
nBarPar);i++){
137 btof->
setP2(i,
test->getBTofPright(ib,i));
139 fBTofCal.push_back(btof);
142 for(
int ie=0;ie<96;ie++){
144 for(
int i=0;i<static_cast<int>(
nEndPar);i++){
147 fETofCal.push_back(etof);
150 for(
int ietf=0;ietf<72;ietf++) {
151 for(
int jetf=0;jetf<12;jetf++) {
153 for(
int k=0; k<static_cast<int>(
nEtfPar); k++ ) {
154 etf->
setP( k,
test->getEtfPcombine(ietf,jetf,k));
155 etf->
setP1(k,
test->getEtfPleft(ietf,jetf,k));
156 etf->
setP2(k,
test->getEtfPright(ietf,jetf,k));
158 fEtfCal.push_back(etf);
163 for(
int i=0; i<static_cast<int>(
nBarOffset); i++) {
166 fBTofCommonCal.push_back(bcomtof);
168 return StatusCode::SUCCESS;
174 MsgStream log(
msgSvc(), name());
177 for(
int i=0; i<static_cast<int>(
nBarPar); i++ ) {
178 p1[i]=fBTofCal[id]->getP1(i);
181 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;
183 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;
190 MsgStream log(
msgSvc(), name());
193 for(
int i=0; i<static_cast<int>(
nBarPar); i++ ) {
194 p2[i]=fBTofCal[id]->getP2(i);
197 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;
199 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;
206 double toffset = fBTofCommonCal[0]->getOffset(0);
212 MsgStream log(
msgSvc(), name());
214 double tcorr1 =
BTCorr1( ADC, z,
id );
215 double tcorr3 = fBTofCommonCal[0]->getOffset(0);
217 log << MSG::DEBUG <<
"BTime1 id =" <<
id <<
" tcorr=" << tcorr1 <<
" total offset=" << tcorr3 << endreq;
219 double time = TDC - tcorr1 - tcorr3;
222 log<<MSG::WARNING<<
"TofCaliSvc::BTime1() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" z = "<<z<<
" ID = "<<
id<<endreq;
229 MsgStream log(
msgSvc(), name());
231 double tcorr1 =
BTCorr2( ADC, z,
id );
232 double tcorr3 = fBTofCommonCal[0]->getOffset(0);
234 log << MSG::DEBUG <<
"BTime2 id =" <<
id <<
" tcorr=" << tcorr1 <<
" total offset=" << tcorr3 << endreq;
236 double time = TDC - tcorr1 - tcorr3;
239 log<<MSG::WARNING<<
"TofCaliSvc::BTime2() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" z = "<<z<<
" ID = "<<
id<<endreq;
246 MsgStream log(
msgSvc(), name());
249 for(
int i=0; i<static_cast<int>(
nEndPar); i++ ) {
250 p[i]=fETofCal[id]->getP(i);
253 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;
255 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);
258 log<<MSG::WARNING<<
"TofCaliSvc::ETime() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" r = "<< rHit <<
" ID = "<<
id<<endreq;
265const double EstTofCaliSvc::EtfTime(
double ADC1,
double ADC2,
double TDC1,
double TDC2,
unsigned id,
unsigned int strip){
266 MsgStream log(
msgSvc(), name());
268 double q = (ADC1+ADC2)/2.0;
269 double t = (TDC1+TDC2)/2.0;
272 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
273 p[i]=fEtfCal[12*
id+strip]->getP(i);
277 + p[1]/TMath::Sqrt(
q)
283 double time =
t - tcorr;
285 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;
287 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;
295 MsgStream log(
msgSvc(), name());
298 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
299 p1[i]=fEtfCal[12*
id+strip]->getP1(i);
302 double tcorr1 = p1[0]
303 + p1[1]/TMath::Sqrt(ADC)
307 + p1[5]*ADC*ADC*ADC*ADC
308 + p1[6]*z/TMath::Sqrt(ADC)
315 double time1 = TDC - tcorr1;
317 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;
319 log<<MSG::WARNING<<
"TofCaliSvc::EtfTime1() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" z = "<<z<<
" ID = "<<
id<<
" Strip = "<<strip<<endreq;
327 MsgStream log(
msgSvc(), name());
330 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
331 p2[i]=fEtfCal[12*
id+strip]->getP2(i);
334 double tcorr2 = p2[0]
335 + p2[1]/TMath::Sqrt(ADC)
339 + p2[5]*ADC*ADC*ADC*ADC
340 + p2[6]*z/TMath::Sqrt(ADC)
347 double time2 = TDC - tcorr2;
349 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;
351 log<<MSG::WARNING<<
"TofCaliSvc::EtfTime2() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" z = "<<z<<
" ID = "<<
id<<
" Strip = "<<strip<<endreq;
359 MsgStream log(
msgSvc(), name());
364 if( TDC1>0 && TDC2>0 ) {
366 tcorr = fEtfCal[12*
id+strip]->getP(0);
368 log << MSG::DEBUG <<
"EtfTime module =" <<
id <<
" strip=" << strip <<
" t1=" << TDC1 <<
" t2=" << TDC2 <<
" combine const=" << tcorr <<
" time=" <<
time << endreq;
370 else if( TDC1>0 && TDC2<0 ) {
372 tcorr = fEtfCal[12*
id+strip]->getP1(0);
374 log << MSG::DEBUG <<
"EtfTime module =" <<
id <<
" strip=" << strip <<
" t1=" << TDC1 <<
" left const=" << tcorr <<
" time=" <<
time << endreq;
376 else if( TDC1<0 && TDC2>0 ) {
378 tcorr = fEtfCal[12*
id+strip]->getP2(0);
380 log << MSG::DEBUG <<
"EtfTime module =" <<
id <<
" strip=" << strip <<
" t2=" << TDC2 <<
" right const=" << tcorr <<
" time=" <<
time << endreq;
384 log<<MSG::WARNING<<
"TofCaliSvc::EtfTime() -- A minus time is given : "<<
time <<
" [Input] TDC1 = "<<TDC1<<
" TDC2 = "<<TDC2<<
" ID = "<<
id<<
" Strip = "<<strip<<endreq;
404 return fBTofCommonCal[0];
408 std::cout<<
"Now We can get the TOF Calibtration Service"<<std::endl;
409 std::cout<<
"Barrel TOF Counter Number = "<<fBTofCal.size()<<std::endl;
410 std::cout<<
"Endcap TOF Counter Number = "<<fETofCal.size()<<std::endl;
412 cout<<
"The O Barrel TOF PMT1 p1[0] is"<<
" "<<
BTof(0)->
getP1(0)<<endl;
413 cout<<
"The 0 Barrel TOF PMT1 p1[1] is"<<
" "<<
BTof(0)->
getP1(1)<<endl;
417 MsgStream log( messageService(), name() );
418 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
420 if ( inc.type() ==
"NewRun" ){
421 log << MSG::DEBUG <<
"New Run" << endreq;
423 StatusCode sc= FillfromDatabase();
425 m_hasbeeninitialized=
true;
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
const unsigned int nBarOffset
const unsigned int nEndPar
const unsigned int nEtfPar
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
const double ETime(double ADC, double TDC, double rHit, unsigned int id)
const double EtfTime1(double ADC, double TDC, double zHit, unsigned int id, unsigned int strip)
const double EtfTime2(double ADC, double TDC, double zHit, unsigned int id, unsigned int strip)
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
const double BTime2(double ADC, double TDC, double zHit, unsigned id)
EstTofCaliSvc(const std::string &name, ISvcLocator *svcloc)
EtfCal * EtfTof(unsigned int id) const
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)
const double EtfTime(double ADC1, double ADC2, double TDC1, double TDC2, unsigned int id, unsigned int strip)
BTofCommonCal * BTofCommon() const
void setP1(int idx, double p1)
void setP(int idx, double p)
void setP2(int idx, double p2)