17#include "GaudiKernel/Kernel.h"
18#include "GaudiKernel/IInterface.h"
19#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"
36#include "GaudiKernel/DataSvc.h"
44 declareProperty(
"Run",m_run=1);
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 if( fEtfCal.size()!=0 ) {
102 for(vector<EtfCal*>::iterator it5 = fEtfCal.begin(); it5 != fEtfCal.end(); it5++) {
delete (*it5); }
105 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) {
delete (*it3); }
106 fBTofCommonCal.clear();
107 for(vector<TofInfoCal*>::iterator it4 = fTofInfoCal.begin(); it4 != fTofInfoCal.end(); it4++) {
delete (*it4); }
111StatusCode EstTofCaliSvc::FillfromDatabase(){
113 MsgStream log(
msgSvc(), name());
114 std::string fullPath =
"/Calib/EstTofCal";
115 log << MSG::INFO<<
" Tof calib fullPath = "<<fullPath<< endreq;
116 SmartDataPtr<CalibData::TofCalibData>
test(m_pCalibDataSvc, fullPath);
118 log << MSG::FATAL <<
"EstTofCaliSvc could not find TofCalibData in TCDS!!" << endreq;
120 return StatusCode::FAILURE;
125 for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) {
delete (*it1); }
127 for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) {
delete (*it2); }
129 if( fEtfCal.size()!=0 ) {
130 for(vector<EtfCal*>::iterator it5 = fEtfCal.begin(); it5 != fEtfCal.end(); it5++) {
delete (*it5); }
133 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) {
delete (*it3); }
134 fBTofCommonCal.clear();
135 for(vector<TofInfoCal*>::iterator it4 = fTofInfoCal.begin(); it4 != fTofInfoCal.end(); it4++) {
delete (*it4); }
138 unsigned int ibSize =
test->getBTofSize();
139 unsigned int ibcomSize =
test->getBTofComSize();
140 unsigned int ieSize =
test->getETofSize();
141 unsigned int ietfSize =
test->getEtfSize();
142 ietfSize = ietfSize/12;
143 unsigned int iinfoSize =
test->getTofInfoSize();
145 for(
int ib=0;ib<ibSize;ib++){
147 for(
int j=0; j<static_cast<int>(
nBarPar); j++){
149 btof->
setP2(j,
test->getBTofPright(ib,j));
151 fBTofCal.push_back(btof);
154 for(
int ie=0;ie<ieSize;ie++){
156 for(
int i=0;i<static_cast<int>(
nEndPar);i++){
159 fETofCal.push_back(etof);
162 for(
int ietf=0;ietf<ietfSize;ietf++) {
163 for(
int jetf=0;jetf<12;jetf++) {
165 for(
int k=0; k<static_cast<int>(
nEtfPar); k++ ) {
166 etf->
setP( k,
test->getEtfPcombine(ietf,jetf,k));
167 etf->
setP1(k,
test->getEtfPleft(ietf,jetf,k));
168 etf->
setP2(k,
test->getEtfPright(ietf,jetf,k));
170 fEtfCal.push_back(etf);
174 for(
int ibcom=0; ibcom<ibcomSize; ibcom++ ) {
176 for(
int i=0; i<static_cast<int>(
nBarOffset); i++) {
179 fBTofCommonCal.push_back(bcomtof);
182 for(
int iinfo=0; iinfo<iinfoSize; iinfo++ ) {
188 fTofInfoCal.push_back(tofinfo);
191 return StatusCode::SUCCESS;
198 MsgStream log(
msgSvc(), name());
202 unsigned int inumber = 0;
203 std::vector<TofInfoCal*>::iterator it = fTofInfoCal.begin();
204 if( (*it)->getRunFrom() == -1 ) {
205 if( fTofInfoCal.size() == 1 ) {
206 log << MSG::INFO <<
"EstTofCaliSvc::chooseConstants() -- Run From is equal to -1! The ONLY TOF calibration constants are used!" << endreq;
207 return StatusCode::SUCCESS;
210 log << MSG::ERROR <<
"EstTofCaliSvc::chooseConstants() -- Run From is equal to -1! The NUMBER of calibration constants are NOT equal to 1!" << endreq;
211 return StatusCode::FAILURE;
215 for( ; it!= fTofInfoCal.end(); it++, inumber++ ) {
216 if( ( (*it)->getRunTo() != -1 ) && ( (*it)->getRunTo() < (*it)->getRunFrom() ) ) {
217 log << MSG::ERROR <<
"EstTofCaliSvc::chooseConstants() -- The " << inumber <<
"th calibration constatns is ABNORMAL! Run From is LARGER than RUN To!" << endreq;
218 return StatusCode::FAILURE;
220 if( ( (*it)->getRunFrom() == (*it)->getRunTo() ) && ( (*it)->getEventFrom() != -1 ) && ( (*it)->getEventTo() != -1 ) && ( (*it)->getEventFrom() > (*it)->getEventTo() ) ) {
221 log << MSG::ERROR <<
"EstTofCaliSvc::chooseConstants() -- The " << inumber <<
"th calibration constatns is ABNORMAL! Event From is LARGER than Event To!" << endreq;
222 return StatusCode::FAILURE;
226 it = fTofInfoCal.begin();
228 for( ; it!= fTofInfoCal.end(); it++, inumber++ ) {
229 int runFrom = (*it)->getRunFrom();
230 int runTo = (*it)->getRunTo();
231 int eventFrom = (*it)->getEventFrom();
232 int eventTo = (*it)->getEventTo();
233 if( ( run == runFrom ) && ( ( eventFrom == -1 ) || ( event >= eventFrom ) ) ) {
234 if( ( run < runTo ) || ( ( run == runTo ) && ( ( eventTo == -1 ) || ( event <= eventTo ) ) ) ) {
239 if( run > runFrom ) {
240 if( ( run < runTo ) || ( ( run == runTo ) && ( ( eventTo == -1 ) || ( event <= eventTo ) ) ) ) {
248 m_sequence = inumber;
251 log << MSG::ERROR <<
"EstTofCaliSvc::chooseConstants() -- The event with run number " << run <<
" and event number " <<
event <<
" is NOT suitable for this group of calibration constants"
253 return StatusCode::FAILURE;
256 return StatusCode::SUCCESS;
261 MsgStream log(
msgSvc(), name());
264 for(
int i=0; i<static_cast<int>(
nBarPar); i++ ) {
265 p1[i]=fBTofCal[176*m_sequence+id]->getP1(i);
268 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;
270 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;
277 MsgStream log(
msgSvc(), name());
280 for(
int i=0; i<static_cast<int>(
nBarPar); i++ ) {
281 p2[i]=fBTofCal[176*m_sequence+id]->getP2(i);
284 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;
286 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;
293 double toffset = fBTofCommonCal[m_sequence]->getOffset(0);
299 MsgStream log(
msgSvc(), name());
301 double tcorr1 =
BTCorr1( ADC, z,
id );
302 double tcorr3 = fBTofCommonCal[m_sequence]->getOffset(0);
304 log << MSG::DEBUG <<
"BTime1 id =" <<
id <<
" tcorr=" << tcorr1 <<
" total offset=" << tcorr3 << endreq;
306 double time = TDC - tcorr1 - tcorr3;
309 log<<MSG::WARNING<<
"TofCaliSvc::BTime1() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" z = "<<z<<
" ID = "<<
id<<endreq;
316 MsgStream log(
msgSvc(), name());
318 double tcorr1 =
BTCorr2( ADC, z,
id );
319 double tcorr3 = fBTofCommonCal[m_sequence]->getOffset(0);
321 log << MSG::DEBUG <<
"BTime2 id =" <<
id <<
" tcorr=" << tcorr1 <<
" total offset=" << tcorr3 << endreq;
323 double time = TDC - tcorr1 - tcorr3;
326 log<<MSG::WARNING<<
"TofCaliSvc::BTime2() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" z = "<<z<<
" ID = "<<
id<<endreq;
333 MsgStream log(
msgSvc(), name());
336 for(
int i=0; i<static_cast<int>(
nEndPar); i++ ) {
337 p[i]=fETofCal[96*m_sequence+id]->getP(i);
340 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;
342 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);
345 log<<MSG::WARNING<<
"TofCaliSvc::ETime() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" r = "<< rHit <<
" ID = "<<
id<<endreq;
352const double EstTofCaliSvc::EtfTime(
double ADC1,
double ADC2,
double TDC1,
double TDC2,
unsigned id,
unsigned int strip){
353 MsgStream log(
msgSvc(), name());
355 double q = (ADC1+ADC2)/2.0;
356 double t = (TDC1+TDC2)/2.0;
359 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
360 p[i]=fEtfCal[72*12*m_sequence+12*
id+strip]->getP(i);
364 + p[1]/TMath::Sqrt(
q)
370 double time =
t - tcorr;
372 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;
374 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;
382 MsgStream log(
msgSvc(), name());
385 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
386 p1[i]=fEtfCal[72*12*m_sequence+12*
id+strip]->getP1(i);
389 double tcorr1 =
p1[0]
390 +
p1[1]/TMath::Sqrt(ADC)
394 +
p1[5]*ADC*ADC*ADC*ADC
395 +
p1[6]*z/TMath::Sqrt(ADC)
402 double time1 = TDC - tcorr1;
404 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;
406 log<<MSG::WARNING<<
"TofCaliSvc::EtfTime1() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" z = "<<z<<
" ID = "<<
id<<
" Strip = "<<strip<<endreq;
414 MsgStream log(
msgSvc(), name());
417 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
418 p2[i]=fEtfCal[72*12*m_sequence+12*
id+strip]->getP2(i);
421 double tcorr2 =
p2[0]
422 +
p2[1]/TMath::Sqrt(ADC)
426 +
p2[5]*ADC*ADC*ADC*ADC
427 +
p2[6]*z/TMath::Sqrt(ADC)
434 double time2 = TDC - tcorr2;
436 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;
438 log<<MSG::WARNING<<
"TofCaliSvc::EtfTime2() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" z = "<<z<<
" ID = "<<
id<<
" Strip = "<<strip<<endreq;
446 MsgStream log(
msgSvc(), name());
451 if( TDC1>0 && TDC2>0 ) {
453 tcorr = fEtfCal[72*12*m_sequence+12*
id+strip]->getP(0);
455 log << MSG::DEBUG <<
"EtfTime module =" <<
id <<
" strip=" << strip <<
" t1=" << TDC1 <<
" t2=" << TDC2 <<
" combine const=" << tcorr <<
" time=" <<
time << endreq;
457 else if( TDC1>0 && TDC2<0 ) {
459 tcorr = fEtfCal[72*12*m_sequence+12*
id+strip]->getP1(0);
461 log << MSG::DEBUG <<
"EtfTime module =" <<
id <<
" strip=" << strip <<
" t1=" << TDC1 <<
" left const=" << tcorr <<
" time=" <<
time << endreq;
463 else if( TDC1<0 && TDC2>0 ) {
465 tcorr = fEtfCal[72*12*m_sequence+12*
id+strip]->getP2(0);
467 log << MSG::DEBUG <<
"EtfTime module =" <<
id <<
" strip=" << strip <<
" t2=" << TDC2 <<
" right const=" << tcorr <<
" time=" <<
time << endreq;
471 log<<MSG::WARNING<<
"TofCaliSvc::EtfTime() -- A minus time is given : "<<
time <<
" [Input] TDC1 = "<<TDC1<<
" TDC2 = "<<TDC2<<
" ID = "<<
id<<
" Strip = "<<strip<<endreq;
479 return fBTofCal[176*m_sequence+id];
483 return fETofCal[96*m_sequence+id];
487 return fEtfCal[72*12*m_sequence+id];
491 return fBTofCommonCal[m_sequence];
496 return fTofInfoCal[m_sequence];
501 std::cout<<
"Now We can get the TOF Calibtration Service"<<std::endl;
502 std::cout<<
"Barrel TOF Counter Number = "<<fBTofCal.size()<<std::endl;
503 std::cout<<
"Endcap TOF Counter Number = "<<fETofCal.size()<<std::endl;
505 cout<<
"The O Barrel TOF PMT1 p1[0] is"<<
" "<<
BTof(0)->
getP1(0)<<endl;
506 cout<<
"The 0 Barrel TOF PMT1 p1[1] is"<<
" "<<
BTof(0)->
getP1(1)<<endl;
510 MsgStream log( messageService(), name() );
511 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
513 if ( inc.type() ==
"NewRun" ){
514 log << MSG::DEBUG <<
"New Run" << endreq;
516 StatusCode sc= FillfromDatabase();
518 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)
StatusCode chooseConstants(int run, int number)
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)
const double BTime2(double ADC, double TDC, double zHit, unsigned id)
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)
TofInfoCal * TofInfo() const
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)
void setEventTo(int evtTo)
void setRunFrom(int runFrom)
void setEventFrom(int evtFrom)