12#include "TofCaliSvc/TofCaliSvc.h"
13#include "TofCaliSvc/BTofCal.h"
14#include "TofCaliSvc/BTofCommonCal.h"
15#include "TofCaliSvc/ETofCal.h"
16#include "TofCaliSvc/EtfCal.h"
17#include "TofCaliSvc/EtfBunchCal.h"
18#include "TofCaliSvc/TofInfoCal.h"
19#include "GaudiKernel/Kernel.h"
20#include "GaudiKernel/IInterface.h"
21#include "GaudiKernel/StatusCode.h"
22#include "GaudiKernel/SvcFactory.h"
23#include "GaudiKernel/MsgStream.h"
28#include "GaudiKernel/IIncidentSvc.h"
29#include "GaudiKernel/Incident.h"
30#include "GaudiKernel/IIncidentListener.h"
31#include "GaudiKernel/IDataProviderSvc.h"
32#include "GaudiKernel/Service.h"
33#include "GaudiKernel/MsgStream.h"
34#include "GaudiKernel/SmartDataPtr.h"
35#include "CalibData/Tof/TofCalibData.h"
36#include "CalibData/Tof/bTofCalibBase.h"
37#include "CalibData/CalibModel.h"
38#include "GaudiKernel/DataSvc.h"
46 declareProperty(
"Run",m_run=1);
50 if ( IID_ITofCaliSvc.versionMatch(riid) ) {
53 return Service::queryInterface(riid, ppvInterface) ;
55 return StatusCode::SUCCESS;
59 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); }
102 if( fEtfCal.size()!=0 ) {
103 for(vector<EtfCal*>::iterator it5 = fEtfCal.begin(); it5 != fEtfCal.end(); it5++) {
delete (*it5); }
106 if( fEtfBunchCal.size()!=0 ) {
107 for(vector<EtfBunchCal*>::iterator it6 = fEtfBunchCal.begin(); it6 != fEtfBunchCal.end(); it6++) {
delete (*it6); }
108 fEtfBunchCal.clear();
110 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) {
delete (*it3); }
111 fBTofCommonCal.clear();
112 for(vector<TofInfoCal*>::iterator it4 = fTofInfoCal.begin(); it4 != fTofInfoCal.end(); it4++) {
delete (*it4); }
117StatusCode TofCaliSvc::FillfromDatabase(){
119 MsgStream log(
msgSvc(), name());
120 std::string fullPath =
"/Calib/TofCal";
121 log << MSG::INFO<<
" Tof calib fullPath = "<<fullPath<< endreq;
122 SmartDataPtr<CalibData::TofCalibData>
test(m_pCalibDataSvc, fullPath);
124 log << MSG::FATAL <<
"TofCaliSvc could not find TofCalibData in TCDS!!" << endreq;
125 return StatusCode::FAILURE;
128 for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) {
delete (*it1); }
130 for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) {
delete (*it2); }
132 if( fEtfCal.size()!=0 ) {
133 for(vector<EtfCal*>::iterator it5 = fEtfCal.begin(); it5 != fEtfCal.end(); it5++) {
delete (*it5); }
136 if( fEtfBunchCal.size()!=0 ) {
137 for(vector<EtfBunchCal*>::iterator it6 = fEtfBunchCal.begin(); it6 != fEtfBunchCal.end(); it6++) {
delete (*it6); }
138 fEtfBunchCal.clear();
140 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) {
delete (*it3); }
141 fBTofCommonCal.clear();
142 for(vector<TofInfoCal*>::iterator it4 = fTofInfoCal.begin(); it4 != fTofInfoCal.end(); it4++) {
delete (*it4); }
145 for(
int ib=0;ib<176;ib++){
147 for(
int j=0; j<static_cast<int>(
nBarAtten); j++ ) {
150 for(
int j=0; j<static_cast<int>(
nBarSpeed); j++ ) {
153 for(
int j=0; j<static_cast<int>(
nBarPar); j++){
155 btof->
setP2(j,
test->getBTofPright(ib,j));
157 for(
int j=0; j<static_cast<int>(
nBarParOff); j++){
167 for(
int j=0; j<static_cast<int>(
nBarSigma); j++){
171 for(
int j=0; j<static_cast<int>(
nBarSigCnt); j++){
175 fBTofCal.push_back(btof);
178 for(
int ie=0;ie<96;ie++){
180 for(
int j=0; j<static_cast<int>(
nEndAtten); j++ ) {
183 for(
int j=0; j<static_cast<int>(
nEndSpeed); j++ ) {
186 for(
int j=0; j<static_cast<int>(
nEndPar); j++ ) {
189 for(
int j=0; j<static_cast<int>(
nEndSigma); j++ ) {
192 fETofCal.push_back(etof);
195 for(
int ietf=0;ietf<72;ietf++) {
196 for(
int jetf=0;jetf<12;jetf++) {
198 for(
int k=0; k<static_cast<int>(
nEtfSpeed); k++ ) {
201 for(
int k=0; k<static_cast<int>(
nEtfPar); k++ ) {
202 etf->
setP( k,
test->getEtfPcombine(ietf,jetf,k));
203 etf->
setP1(k,
test->getEtfPleft(ietf,jetf,k));
204 etf->
setP2(k,
test->getEtfPright(ietf,jetf,k));
206 fEtfCal.push_back(etf);
211 for(
int k=0; k<static_cast<int>(
nEtfBunch); k++ ) {
214 fEtfBunchCal.push_back(etfbunch);
217 for(
int i=0; i<static_cast<int>(
nBarOffset); i++) {
220 for(
int i=0; i<static_cast<int>(
nBarSigCor); i++) {
223 fBTofCommonCal.push_back(bcomtof);
232 for(
unsigned int i=0; i<5; i++ ) {
235 if( (
test->getVersion())<=8 ) {
242 fTofInfoCal.push_back(tofinfo);
244 return StatusCode::SUCCESS;
251 tdelay = fBTofCal[id]->getP1(0);
254 MsgStream log(
msgSvc(), name());
255 log<<MSG::ERROR<<
"TofCaliSvc::BTDelay1() -- Wrong TOFID is provided! ID = "<<
id<<endreq;
264 tdelay = fBTofCal[id]->getP2(0);
267 MsgStream log(
msgSvc(), name());
268 log<<MSG::ERROR<<
"TofCaliSvc::BTDelay2() -- Wrong TOFID is provided! ID = "<<
id<<endreq;
277 tdelay = fETofCal[id]->getP(0);
280 MsgStream log(
msgSvc(), name());
281 log<<MSG::ERROR<<
"TofCaliSvc::ETDelay() -- Wrong TOFID is provided! ID = "<<
id<<endreq;
288 MsgStream log(
msgSvc(), name());
291 for(
int i=0; i<static_cast<int>(
nBarPar); i++ ) {
292 p1[i]=fBTofCal[id]->getP1(i);
295 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;
297 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;
304 MsgStream log(
msgSvc(), name());
307 for(
int i=0; i<static_cast<int>(
nBarPar); i++ ) {
308 p2[i]=fBTofCal[id]->getP2(i);
311 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;
313 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;
320 MsgStream log(
msgSvc(), name());
322 int numBunch = fTofInfoCal[0]->getRunEnd();
323 int whichBunch = (
static_cast<int>(t0/(12000./499.8/(numBunch*1.0))+0.1))%numBunch;
326 if( whichBunch==0 ) {
327 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
328 poff1[i]=fBTofCal[id]->getPOff1_bunch0(i);
331 else if( whichBunch==1 ) {
332 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
333 poff1[i]=fBTofCal[id]->getPOff1_bunch1(i);
336 else if( whichBunch==2 ) {
337 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
338 poff1[i]=fBTofCal[id]->getPOff1_bunch2(i);
341 else if( whichBunch==3 ) {
342 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
343 poff1[i]=fBTofCal[id]->getPOff1_bunch3(i);
347 double tCorrOffset1 = 0.0;
349 tCorrOffset1 = poff1[0] + poff1[1]*z + poff1[2]*z*z + poff1[3]*z*z*z + poff1[4]*z*z*z*z + poff1[5]*z*z*z*z*z + poff1[6]*z*z*z*z*z*z;
352 tCorrOffset1 = poff1[10] + poff1[11]*z + poff1[12]*z*z + poff1[13]*z*z*z + poff1[14]*z*z*z*z + poff1[15]*z*z*z*z*z + poff1[16]*z*z*z*z*z*z;
355 log << MSG::DEBUG <<
"BTCorrOff1 id =" <<
id <<
" bunch number=" << whichBunch <<
" TCorrOffset1=" << tCorrOffset1 <<
" 1=" << poff1[0] <<
" 2=" << poff1[1] <<
" 3=" << poff1[2] <<
" 4=" << poff1[3] <<
" 5=" << poff1[4] <<
" 6=" << poff1[5] <<
" 7=" << poff1[6] <<
" 8=" << poff1[7] <<
" 9=" << poff1[8] << endreq;
362 MsgStream log(
msgSvc(), name());
364 int numBunch = fTofInfoCal[0]->getRunEnd();
365 int whichBunch = (
static_cast<int>(t0/(12000./499.8/(numBunch*1.0))+0.1))%numBunch;
368 if( whichBunch==0 ) {
369 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
370 poff2[i]=fBTofCal[id]->getPOff2_bunch0(i);
373 else if( whichBunch==1 ) {
374 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
375 poff2[i]=fBTofCal[id]->getPOff2_bunch1(i);
378 else if( whichBunch==2 ) {
379 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
380 poff2[i]=fBTofCal[id]->getPOff2_bunch2(i);
383 else if( whichBunch==3 ) {
384 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
385 poff2[i]=fBTofCal[id]->getPOff2_bunch3(i);
389 double tCorrOffset2 = 0.0;
391 tCorrOffset2 = poff2[0] + poff2[1]*z + poff2[2]*z*z + poff2[3]*z*z*z + poff2[4]*z*z*z*z + poff2[5]*z*z*z*z*z + poff2[6]*z*z*z*z*z*z;
394 tCorrOffset2 = poff2[10] + poff2[11]*z + poff2[12]*z*z + poff2[13]*z*z*z + poff2[14]*z*z*z*z + poff2[15]*z*z*z*z*z + poff2[16]*z*z*z*z*z*z;
397 log << MSG::DEBUG <<
"BTCorrOff2 id =" <<
id <<
" bunch number=" << whichBunch <<
" TCorrOffset2=" << tCorrOffset2 <<
" 1=" << poff2[0] <<
" 2=" << poff2[1] <<
" 3=" << poff2[2] <<
" 4=" << poff2[3] <<
" 5=" << poff2[4] <<
" 6=" << poff2[5] <<
" 7=" << poff2[6] <<
" 8=" << poff2[7] <<
" 9=" << poff2[8] << endreq;
404 double toffset = fBTofCommonCal[0]->getOffset(0);
410 MsgStream log(
msgSvc(), name());
412 double tcorr1 =
BTCorr1( ADC, z,
id );
414 double tcorr3 = fBTofCommonCal[0]->getOffset(0);
416 log << MSG::DEBUG <<
"BTime1 id =" <<
id <<
" tcorr=" << tcorr1 <<
" toffset=" << tcorr2 <<
" total offset=" << tcorr3 << endreq;
418 double time = TDC - tcorr1 - tcorr2 - tcorr3;
421 log<<MSG::WARNING<<
"TofCaliSvc::BTime1() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" z = "<<z<<
" ID = "<<
id<<endreq;
427const double TofCaliSvc::BTime2(
double ADC,
double TDC,
double z,
unsigned id,
double t0){
428 MsgStream log(
msgSvc(), name());
430 double tcorr1 =
BTCorr2( ADC, z,
id );
432 double tcorr3 = fBTofCommonCal[0]->getOffset(0);
434 log << MSG::DEBUG <<
"BTime2 id =" <<
id <<
" tcorr=" << tcorr1 <<
" toffset=" << tcorr2 <<
" total offset=" << tcorr3 << endreq;
436 double time = TDC - tcorr1 - tcorr2 - tcorr3;
439 log<<MSG::WARNING<<
"TofCaliSvc::BTime2() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" z = "<<z<<
" ID = "<<
id<<endreq;
464 double sigmaCorr = fBTofCommonCal[0]->getSigmaCorr(0);
465 double sigmaCorr2 = sigmaCorr*sigmaCorr;
467 double sigmaLeft =
BSigma1( z,
id );
468 double sigmaLeft2 = sigmaLeft*sigmaLeft;
469 double sigmaRight =
BSigma2( z,
id );
470 double sigmaRight2 = sigmaRight*sigmaRight;
472 double fraction = ( sigmaRight2 - sigmaCorr2 )/( sigmaLeft2 + sigmaRight2 - 2.0*sigmaCorr2);
474 double wt=fraction*tleft + (1.0-fraction)*tright;
476 MsgStream log(
msgSvc(), name());
477 log<<MSG::WARNING<<
"TofCaliSvc::BTimeCounter() -- A minus time is given : "<<wt <<
" [Input] z = "<<z<<
" ID = "<<
id<<endreq;
485 double sigmaCorr = fBTofCommonCal[0]->getSigmaCorr(0);
486 double sigmaCorr2 = sigmaCorr*sigmaCorr;
489 double sigmaInner2 = sigmaInner*sigmaInner;
491 double sigmaOuter2 = sigmaOuter*sigmaOuter;
493 double fraction = ( sigmaOuter2 - sigmaCorr2 )/( sigmaInner2 + sigmaOuter2 - 2.0*sigmaCorr2);
495 double wt=fraction*tlayer1 + (1.0-fraction)*tlayer2;
497 MsgStream log(
msgSvc(), name());
498 log<<MSG::WARNING<<
"TofCaliSvc::BTimeCluster() -- A minus time is given : "<<wt <<
" [Input] z1 = "<<z1<<
" [Input] z2 = "<<z2<<
" ID1 = "<< id1 <<
" ID2=" << id2 << endreq;
505 MsgStream log(
msgSvc(), name());
508 for(
int i=0; i<static_cast<int>(
nBarSigma); i++ ) {
509 fpleft[i]=fBTofCal[id]->getFPLeft(i);
512 log << MSG::DEBUG <<
"BSigma1 id =" <<
id <<
" 1=" << fpleft[0] <<
" 2=" << fpleft[1] <<
" 3=" << fpleft[2] <<
" 4=" << fpleft[3] <<
" 5=" << fpleft[4] << endreq;
514 double sigmaLeft = fpleft[0] + fpleft[1]*z + fpleft[2]*z*z + fpleft[3]*z*z*z + fpleft[4]*z*z*z*z;
521 MsgStream log(
msgSvc(), name());
524 for(
int i=0; i<static_cast<int>(
nBarSigma); i++ ) {
525 fpright[i]=fBTofCal[id]->getFPRight(i);
528 log << MSG::DEBUG <<
"BSigma2 id =" <<
id <<
" 1=" << fpright[0] <<
" 2=" << fpright[1] <<
" 3=" << fpright[2] <<
" 4=" << fpright[3] <<
" 5=" << fpright[4] << endreq;
530 double sigmaRight = fpright[0] + fpright[1]*z + fpright[2]*z*z + fpright[3]*z*z*z + fpright[4]*z*z*z*z;
537 MsgStream log(
msgSvc(), name());
540 for(
int i=0; i<static_cast<int>(
nBarSigCnt); i++ ) {
541 fplayer[i]=fBTofCal[id]->getFPCounter(i);
544 log << MSG::DEBUG <<
"BSigmaCounter id =" <<
id <<
" 1=" << fplayer[0] <<
" 2=" << fplayer[1] <<
" 3=" << fplayer[2] <<
" 4=" << fplayer[3] <<
" 5=" << fplayer[4] << endreq;
546 double sigma = fplayer[0] + fplayer[1]*z + fplayer[2]*z*z + fplayer[3]*z*z*z + fplayer[4]*z*z*z*z;
554 double sigmaInner2 = sigmaInner*sigmaInner;
556 double sigmaOuter2 = sigmaOuter*sigmaOuter;
557 double sigmaCorr = fBTofCommonCal[0]->getSigmaCorr(0);
558 double sigmaCorr2 = sigmaCorr*sigmaCorr;
559 double sigma = (sigmaInner2*sigmaOuter2-sigmaCorr2*sigmaCorr2)/(sigmaInner2+sigmaOuter2-2.0*sigmaCorr2);
566 MsgStream log(
msgSvc(), name());
569 for(
int i=0; i<static_cast<int>(
nEndPar); i++ ) {
570 p[i]=fETofCal[id]->getP(i);
573 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;
575 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);
578 MsgStream log(
msgSvc(), name());
579 log<<MSG::WARNING<<
"TofCaliSvc::ETime() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" r = "<< rHit <<
" ID = "<<
id<<endreq;
587 MsgStream log(
msgSvc(), name());
590 for(
int i=0; i<static_cast<int>(
nEndSigma); i++) {
591 fp[i]=fETofCal[id]->getFPCounter(i);
594 log << MSG::DEBUG <<
"ESigma id =" <<
id <<
" 1=" << fp[0] <<
" 2=" << fp[1] <<
" 3=" << fp[2] << endreq;
596 double sigma = fp[0] + fp[1]*r + fp[2]*r*r;
602const double TofCaliSvc::EtfTime(
double ADC1,
double ADC2,
double TDC1,
double TDC2,
unsigned id,
unsigned int strip,
double t0){
603 MsgStream log(
msgSvc(), name());
605 double q = (ADC1+ADC2)/2.0;
606 double t = (TDC1+TDC2)/2.0;
609 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
610 p[i]=fEtfCal[12*
id+strip]->getP(i);
614 + p[1]/TMath::Sqrt(
q)
620 double time =
t - tcorr;
622 int ibunch =
static_cast<int>(t0/(8.0*12000./499.8/8./4. )+0.1)%4;
627 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 <<
" t0=" << t0 <<
" pbunch=" << pbunch <<
" time=" <<
time << endreq;
633const double TofCaliSvc::EtfTime1(
double ADC,
double TDC,
double z,
unsigned id,
unsigned int strip,
double t0){
634 MsgStream log(
msgSvc(), name());
637 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
638 p1[i]=fEtfCal[12*
id+strip]->getP1(i);
641 double tcorr1 = p1[0]
642 + p1[1]/TMath::Sqrt(ADC)
646 + p1[5]*ADC*ADC*ADC*ADC
647 + p1[6]*z/TMath::Sqrt(ADC)
654 double time1 = TDC - tcorr1;
656 int ibunch =
static_cast<int>(t0/(8.0*12000./499.8/8./4. )+0.1)%4;
659 time1 = time1 - pbunch;
661 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 <<
" t0=" << t0 <<
" pbunch=" << pbunch <<
" time1=" << time1 << endreq;
667const double TofCaliSvc::EtfTime2(
double ADC,
double TDC,
double z,
unsigned id,
unsigned int strip,
double t0){
668 MsgStream log(
msgSvc(), name());
671 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
672 p2[i]=fEtfCal[12*
id+strip]->getP2(i);
675 double tcorr2 = p2[0]
676 + p2[1]/TMath::Sqrt(ADC)
680 + p2[5]*ADC*ADC*ADC*ADC
681 + p2[6]*z/TMath::Sqrt(ADC)
688 double time2 = TDC - tcorr2;
690 int ibunch =
static_cast<int>(t0/(8.0*12000./499.8/8./4. )+0.1)%4;
693 time2 = time2 - pbunch;
695 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 <<
" t0=" << t0 <<
" pbunch=" << pbunch <<
" time2=" << time2 << endreq;
701const double TofCaliSvc::EtfTimeMC(
double ADC1,
double ADC2,
double TDC1,
double TDC2,
unsigned id,
unsigned int strip,
double t0){
702 MsgStream log(
msgSvc(), name());
704 double q = (ADC1+ADC2)/2.0;
705 double t = (TDC1+TDC2)/2.0;
708 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
709 p[i]=fEtfCal[12*
id+strip]->getP(i);
712 double tcorr = p[0] + p[1]/TMath::Sqrt(
q);
713 double time =
t - tcorr;
715 log << MSG::DEBUG <<
"EtfTime module =" <<
id <<
" strip=" << strip <<
" 1=" << p[0] <<
" 2=" << p[1] <<
" tcorr=" << tcorr <<
" t0=" << t0 <<
" time=" <<
time << endreq;
721const double TofCaliSvc::EtfTimeMC1(
double ADC,
double TDC,
double z,
unsigned id,
unsigned int strip,
double t0){
722 MsgStream log(
msgSvc(), name());
725 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
726 p1[i]=fEtfCal[12*
id+strip]->getP1(i);
729 double tcorr1 = p1[0] + p1[1]/TMath::Sqrt(ADC) + p1[2]*z;
730 double time1 = TDC - tcorr1;
732 log << MSG::DEBUG <<
"EtfTime1 module =" <<
id <<
" strip=" << strip <<
" 1=" << p1[0] <<
" 2=" << p1[1] <<
" 3=" << p1[2] <<
" tcorr=" << tcorr1 <<
" t0=" << t0 <<
" time1=" << time1 << endreq;
738const double TofCaliSvc::EtfTimeMC2(
double ADC,
double TDC,
double z,
unsigned id,
unsigned int strip,
double t0){
739 MsgStream log(
msgSvc(), name());
742 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
743 p2[i]=fEtfCal[12*
id+strip]->getP2(i);
746 double tcorr2 = p2[0] + p2[1]/TMath::Sqrt(ADC) + p2[2]*z;
747 double time2 = TDC - tcorr2;
749 log << MSG::DEBUG <<
"EtfTime2 module =" <<
id <<
" strip=" << strip <<
" 1=" << p2[0] <<
" 2=" << p2[1] <<
" 3=" << p2[2] <<
" tcorr=" << tcorr2 <<
" t0=" << t0 <<
" time2=" << time2 << endreq;
756 MsgStream log(
msgSvc(), name());
758 double time = (tleft+tright)/2.0;
759 log << MSG::DEBUG <<
"EtfTime tleft=" << tleft <<
" tright=" << tright <<
" time=" <<
time << endreq;
766 MsgStream log(
msgSvc(), name());
769 if( fEtfBunchCal.size()>0 && index>=0 && index<4 ) {
770 pbunch=fEtfBunchCal[0]->getBunchP(index);
778 double length = 230.0;
780 double Latten = fBTofCal[id]->getAtten(0);
781 double q0 = ADC*sint*TMath::Exp((0.5*length-zHit)/Latten)/A;
787 double length = 230.0;
789 double Latten = fBTofCal[id]->getAtten(0);
790 double q0 = ADC*sint*TMath::Exp((0.5*length+zHit)/Latten)/A;
796 double length = 230.0;
797 double Latten = fBTofCal[id]->getAtten(0);
798 double gainRatio = fBTofCal[id]->getAtten(1);
799 double A2 = fBTofCal[id]->getAtten(2);
800 double q = ( ADC1*sint*TMath::Exp((0.5*length-zHit)/Latten)+ADC2*sint*TMath::Exp((0.5*length+zHit)/Latten) )/( A2*(1.0+TMath::Exp(gainRatio)) );
805const double TofCaliSvc::BPh(
double ADC1,
double ADC2,
double zHit,
unsigned int id ) {
806 double length = 230.0;
807 double Latten = fBTofCal[id]->getAtten(0);
808 double gainRatio = fBTofCal[id]->getAtten(1);
809 double q = ( ADC1*TMath::Exp((0.5*length-zHit)/Latten)+ADC2*TMath::Exp((0.5*length+zHit)/Latten) )/(1.0+TMath::Exp(gainRatio));
815 double length = 44.5;
816 double a0 = fETofCal[id]->getAtten(0);
817 double a1 = fETofCal[id]->getAtten(1);
818 double a2 = fETofCal[id]->getAtten(2);
819 double a3 = fETofCal[id]->getAtten(3);
821 double q0 = ADC*fabs(cost)*TMath::Exp(-(a1*(rHit-length)+a2*(rHit-length)*(rHit-length)))/a3;
828 double length = 44.5;
829 double a0 = fETofCal[id]->getAtten(0);
830 double a1 = fETofCal[id]->getAtten(1);
831 double a2 = fETofCal[id]->getAtten(2);
832 double q0 = ADC*TMath::Exp(-(a0+a1*(rHit-length)+a2*(rHit-length)*(rHit-length)));
838 return fBTofCal[id]->getAtten(3);
844 return fBTofCal[id]->getVeff(0);
846 std::cout<<
"bad id="<<
id<<std::endl;
852 if(
id > 175 )
return -1;
853 return fBTofCal[id]->getAtten(0);
857 if(
id > 175 )
return -1;
858 double gainRatio = fBTofCal[id]->getAtten(1);
859 double A2 = fBTofCal[id]->getAtten(2);
860 double A1 = A2*TMath::Exp(gainRatio);
865 if(
id > 175 )
return -1;
866 return fBTofCal[id]->getAtten(2);
870 if(
id > 175 )
return -1;
871 return fETofCal[id]->getVeff(0);
875 if(
id<72 && strip<12){
876 return fEtfCal[12*
id+strip]->getVeff(0);
878 std::cout<<
"bad id="<<
id<<
" strip="<<strip<<std::endl;
885 double ztdc = -1000.0;
886 if(
id > 175 )
return ztdc;
887 double veff = fBTofCal[id]->getVeff(0);
888 double delay = fBTofCal[id]->getVeff(1);
889 ztdc = 0.5*veff*(tright-tleft-delay);
894 double tleft = -1000.0;
895 if(
id > 175 )
return tleft;
896 if( tright < -900.0 )
return tleft;
897 double veff = fBTofCal[id]->getVeff(0);
898 double delay = fBTofCal[id]->getVeff(1);
899 tleft = tright-delay-2.0*z/veff;
904 double tright = -1000.0;
905 if(
id > 175 )
return tright;
906 if( tleft < -900.0 )
return tright;
907 double veff = fBTofCal[id]->getVeff(0);
908 double delay = fBTofCal[id]->getVeff(1);
909 tright = tleft+delay+2.0*z/veff;
914 double zadc = -1000.0;
915 if(
id > 175 )
return zadc;
916 if( qright < 1.0e-6 )
return zadc;
917 double ldecay = fBTofCal[id]->getAtten(0);
918 double a1overa2 = fBTofCal[id]->getAtten(1);
919 double q1overq2 = log(qleft/qright);
920 zadc = 0.5*ldecay*( q1overq2 - a1overa2 );
925 double qleft = -1000.0;
926 if(
id > 175 )
return qleft;
927 if( qright < 1.0e-6 )
return qleft;
928 double ldecay = fBTofCal[id]->getAtten(0);
929 double a1overa2 = fBTofCal[id]->getAtten(1);
930 double q1overq2 = 2.0*z/ldecay + a1overa2;
931 qleft = qright*
exp(q1overq2);
936 double qright = -1000.0;
937 if(
id > 175 )
return qright;
938 if( qleft < 1.0e-6 )
return qright;
939 double ldecay = fBTofCal[id]->getAtten(0);
940 double a1overa2 = fBTofCal[id]->getAtten(1);
941 double q1overq2 = 2.0*z/ldecay + a1overa2;
942 qright = qleft*
exp(-q1overq2);
946const double TofCaliSvc::EtfZTDC(
double tleft,
double tright,
unsigned id,
unsigned int strip) {
947 double ztdc = -1000.0;
948 if(
id>71 || strip>11 )
return ztdc;
949 double delay = fEtfCal[12*
id+strip]->getVeff(0);
950 double veff = fEtfCal[12*
id+strip]->getVeff(1);
951 ztdc = (tright-tleft-delay)/veff;
957 if(
id > 95 )
return -1;
958 return fETofCal[id]->getAtten(0);
962 if(
id > 95 )
return -1;
963 return fETofCal[id]->getAtten(1);
967 return fTofInfoCal[0]->getRunBegin();
971 return fTofInfoCal[0]->getRunEnd();
975 return fTofInfoCal[0]->getVersion();
979 return fTofInfoCal[0]->getQCorr();
983 return fTofInfoCal[0]->getQElec();
987 return fTofInfoCal[0]->getMisLable();
991 return fTofInfoCal[0]->getBrEast(im);
995 return fTofInfoCal[0]->getBrWest(im);
999 return fTofInfoCal[0]->getEndcap(im);
1003 return fTofInfoCal[0]->getEndcap(im);
1007 return fBTofCal[id];
1011 return fETofCal[id];
1019 return fBTofCommonCal[0];
1023 return fTofInfoCal[0];
1027 std::cout<<
"Now We can get the TOF Calibtration Service"<<std::endl;
1028 std::cout<<
"Barrel TOF Counter Number = "<<fBTofCal.size()<<std::endl;
1029 std::cout<<
"Endcap TOF Counter Number = "<<fETofCal.size()<<std::endl;
1031 cout<<
"The O Barrel TOF PMT1 p1[0] is"<<
" "<<
BTof(0)->
getP1(0)<<endl;
1032 cout<<
"The 0 Barrel TOF PMT1 p1[1] is"<<
" "<<
BTof(0)->
getP1(1)<<endl;
1033 cout<<
"The 0 Barrel TOF veff is"<<
" "<<
BTof(0)->
getVeff(0)<<endl;
1038 MsgStream log( messageService(), name() );
1039 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
1041 if ( inc.type() ==
"NewRun" ){
1042 log << MSG::DEBUG <<
"New Run" << endreq;
1044 StatusCode sc= FillfromDatabase();
1046 m_hasbeeninitialized=
true;
EvtComplex exp(const EvtComplex &c)
****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 nBarParOff
const unsigned int nEndPar
const unsigned int nEtfPar
const unsigned int nBarPar
const unsigned int nBarSigma
const unsigned int nEndSigma
const unsigned int nBarSigCor
const unsigned int nEndSpeed
const unsigned int nEtfSpeed
const unsigned int nEtfBunch
const unsigned int nBarSpeed
const unsigned int nEndAtten
const unsigned int nBarAtten
const unsigned int nBarSigCnt
void setPOff1_bunch0(int idx, double poff1_bunch0)
void setPOff2_bunch1(int idx, double poff2_bunch1)
void setPOff1_bunch2(int idx, double poff1_bunch2)
void setAtten(int idx, double atten)
double getP1(int idx) const
void setFPCounter(int idx, double fp3)
void setPOff1_bunch3(int idx, double poff1_bunch3)
void setP1(int idx, double p1)
void setP2(int idx, double p2)
void setVeff(int idx, double veff)
void setPOff2_bunch2(int idx, double poff2_bunch2)
void setPOff2_bunch3(int idx, double poff2_bunch3)
double getVeff(int idx) const
void setFPRight(int idx, double fp2)
void setFPLeft(int idx, double fp1)
void setPOff2_bunch0(int idx, double poff2_bunch0)
void setPOff1_bunch1(int idx, double poff1_bunch1)
void setSigmaCorr(int idx, double sigmac)
void setOffset(int idx, double offset)
void setVeff(int idx, double veff)
void setP(int i, double p)
void setFPCounter(int idx, double fp)
void setAtten(int idx, double atten)
void setBunchP(int idx, double pbunch)
void setP1(int idx, double p1)
void setVeff(int idx, double veff)
void setP(int idx, double p)
void setP2(int idx, double p2)
const double BTimeCounter(double tleft, double tright, double z, unsigned int id)
const double ZADC(double qleft, double qright, unsigned int id)
const double EtfTime(double ADC1, double ADC2, double TDC1, double TDC2, unsigned int id, unsigned int strip, double t0)
const double BPulseHeight1(double ADC, double zHit, double sint, unsigned int id)
const double BPh(double ADC1, double ADC2, double zHit, unsigned int id)
const double ZTDC2(double tleft, unsigned int id, double z)
const double BPulseHeight2(double ADC, double zHit, double sint, unsigned int id)
const double EGain(unsigned int id)
const double BTimeCluster(double tlayer1, double tlayer2, double z1, double z2, unsigned int id1, unsigned int id2)
const double EPh(double ADC, double rHit, unsigned int id)
const double ZTDC1(double tright, unsigned int id, double z)
TofInfoCal * TofInfo() const
const double BPulseHeight(double ADC1, double ADC2, double zHit, double sint, unsigned int id)
const int BrEast(unsigned int No)
const double BGainForward(unsigned int id)
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
const int Etf(unsigned int No)
const double EtfBunchP(int index)
const double BTCorrOffset2(double zHit, unsigned int id, double t0)
const double BTime2(double ADC, double TDC, double zHit, unsigned int id, double t0)
const double EPulseHeight(double ADC, double rHit, double cost, unsigned int id)
const double BSigma1(double zHit, unsigned int id)
const double BAtten(unsigned int id)
virtual StatusCode finalize()
const double EtfTimeMC(double ADC1, double ADC2, double TDC1, double TDC2, unsigned int id, unsigned int strip, double t0)
const double BSigma2(double zHit, unsigned int id)
const double EtfTime1(double ADC, double TDC, double zHit, unsigned int id, unsigned int strip, double t0)
const double BTime1(double ADC, double TDC, double zHit, unsigned int id, double t0)
BTofCal * BTof(unsigned int id) const
const double ETime(double ADC, double TDC, double rHit, unsigned int id)
const double BTCorrOffset1(double zHit, unsigned int id, double t0)
const double EtfTimeMC1(double ADC, double TDC, double zHit, unsigned int id, unsigned int strip, double t0)
const double EtfTimeMC2(double ADC, double TDC, double zHit, unsigned int id, unsigned int strip, double t0)
const double EtfTime2(double ADC, double TDC, double zHit, unsigned int id, unsigned int strip, double t0)
const double BSigmaCluster(double zHit1, double zHit2, unsigned int id1, unsigned int id2)
const double EtfVeff(unsigned int id, unsigned int strip)
const double ZADC1(double qright, unsigned int id, double z)
virtual StatusCode initialize()
const double BGainBackward(unsigned int id)
const double BVeff(unsigned int id)
const double ESigma(double rHit, unsigned int id)
const double EtfZTDC(double tleft, double tright, unsigned int id, unsigned int strip)
const double ZADC2(double qleft, unsigned int id, double z)
const double getQ0(unsigned int id)
const int BrWest(unsigned int No)
const double ZTDC(double tleft, double tright, unsigned int id)
const double ETDelay(unsigned int id)
const double EVeff(unsigned int id)
const double EAtten(unsigned int id)
const int Endcap(unsigned int No)
const double BTCorr2(double ADC, double zHit, unsigned int id)
BTofCommonCal * BTofCommon() const
const double BTCorr1(double ADC, double zHit, unsigned int id)
void handle(const Incident &)
const double BTDelay1(unsigned int id)
const double BTDelay2(unsigned int id)
EtfCal * EtfTof(unsigned int id) const
TofCaliSvc(const std::string &name, ISvcLocator *svcloc)
ETofCal * ETof(unsigned int id) const
const double BSigmaCounter(double zHit, unsigned int id)
void setVersion(int version)
void setMisLable(int mis)
void setEtf(unsigned int i, int id4)
void setRunBegin(int run1)
void setBrEast(unsigned int i, int id1)
void setBrWest(unsigned int i, int id2)
void setEndcap(unsigned int i, int id3)