13#include "TofCaliSvc/BTofCal.h"
14#include "TofCaliSvc/BTofCommonCal.h"
15#include "TofCaliSvc/ETofCal.h"
16#include "TofCaliSvc/EtfCal.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"
38#include "GaudiKernel/DataSvc.h"
49{ declareProperty(
"Run",m_run=1);
63 m_hasbeeninitialized=
false;
66 MsgStream log(
msgSvc(), name());
67 log << MSG::INFO << name() <<
": Start of run initialisation" << endreq;
69 StatusCode sc = Service::initialize();
70 if ( sc.isFailure() )
return sc;
73 sc = service(
"IncidentSvc", incsvc);
76 incsvc -> addListener(
this,
"NewRun", priority);
81 log<<MSG::INFO <<
"setProperties()" << endreq;
82 scc = service(
"CalibDataSvc", m_pCalibDataSvc,
true);
83 if ( !scc.isSuccess() ) {
84 log<<MSG::ERROR<<
"Could not get IDataProviderSvc interface of CalibXmlCnvSvc"<<endreq;
87 log << MSG::DEBUG<<
"Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"<<endreq;
90 scc = setProperties();
96 MsgStream log(
msgSvc(), name());
97 log << MSG::INFO << name() <<
": End of Run" << endreq;
98 return StatusCode::SUCCESS;
102 for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) {
delete (*it1); }
104 for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) {
delete (*it2); }
107 if( fEtfCal.size()!=0 ) {
108 for(vector<EtfCal*>::iterator it5 = fEtfCal.begin(); it5 != fEtfCal.end(); it5++) {
delete (*it5); }
111 if( fEtfBunchCal.size()!=0 ) {
112 for(vector<EtfBunchCal*>::iterator it6 = fEtfBunchCal.begin(); it6 != fEtfBunchCal.end(); it6++) {
delete (*it6); }
113 fEtfBunchCal.clear();
115 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) {
delete (*it3); }
116 fBTofCommonCal.clear();
117 for(vector<TofInfoCal*>::iterator it4 = fTofInfoCal.begin(); it4 != fTofInfoCal.end(); it4++) {
delete (*it4); }
122StatusCode TofCaliSvc::FillfromDatabase(){
124 MsgStream log(
msgSvc(), name());
125 std::string fullPath =
"/Calib/TofCal";
126 log << MSG::INFO<<
" Tof calib fullPath = "<<fullPath<< endreq;
128 SmartDataPtr<CalibData::TofCalibData>
test(m_pCalibDataSvc, fullPath);
130 log << MSG::FATAL <<
"TofCaliSvc could not find TofCalibData in TCDS!!" << endreq;
131 return StatusCode::FAILURE;
134 for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) {
delete (*it1); }
136 for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) {
delete (*it2); }
138 if( fEtfCal.size()!=0 ) {
139 for(vector<EtfCal*>::iterator it5 = fEtfCal.begin(); it5 != fEtfCal.end(); it5++) {
delete (*it5); }
142 if( fEtfBunchCal.size()!=0 ) {
143 for(vector<EtfBunchCal*>::iterator it6 = fEtfBunchCal.begin(); it6 != fEtfBunchCal.end(); it6++) {
delete (*it6); }
144 fEtfBunchCal.clear();
146 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) {
delete (*it3); }
147 fBTofCommonCal.clear();
148 for(vector<TofInfoCal*>::iterator it4 = fTofInfoCal.begin(); it4 != fTofInfoCal.end(); it4++) {
delete (*it4); }
151 unsigned int ibSize =
test->getBTofSize();
152 unsigned int ibcomSize =
test->getBTofComSize();
153 unsigned int ieSize =
test->getETofSize();
154 unsigned int ietfSize =
test->getEtfSize();
155 ietfSize = ietfSize/12;
156 unsigned int ietfBSize =
test->getEtfBunchSize();
157 unsigned int iinfoSize =
test->getTofInfoSize();
159 for(
int ib=0;ib<ibSize;ib++){
161 for(
int j=0; j<static_cast<int>(
nBarAtten); j++ ) {
164 for(
int j=0; j<static_cast<int>(
nBarSpeed); j++ ) {
167 for(
int j=0; j<static_cast<int>(
nBarPar); j++){
169 btof->
setP2(j,
test->getBTofPright(ib,j));
171 for(
int j=0; j<static_cast<int>(
nBarParOff); j++){
181 for(
int j=0; j<static_cast<int>(
nBarSigma); j++){
185 for(
int j=0; j<static_cast<int>(
nBarSigCnt); j++){
189 fBTofCal.push_back(btof);
192 for(
int ie=0;ie<ieSize;ie++){
194 for(
int j=0; j<static_cast<int>(
nEndAtten); j++ ) {
197 for(
int j=0; j<static_cast<int>(
nEndSpeed); j++ ) {
200 for(
int j=0; j<static_cast<int>(
nEndPar); j++ ) {
203 for(
int j=0; j<static_cast<int>(
nEndSigma); j++ ) {
206 fETofCal.push_back(etof);
209 for(
int ietf=0;ietf<ietfSize;ietf++) {
210 for(
int jetf=0;jetf<12;jetf++) {
212 for(
int k=0; k<static_cast<int>(
nEtfSpeed); k++ ) {
215 for(
int k=0; k<static_cast<int>(
nEtfPar); k++ ) {
216 etf->
setP( k,
test->getEtfPcombine(ietf,jetf,k));
217 etf->
setP1(k,
test->getEtfPleft(ietf,jetf,k));
218 etf->
setP2(k,
test->getEtfPright(ietf,jetf,k));
220 fEtfCal.push_back(etf);
224 for(
int ietfb=0;ietfb<ietfBSize;ietfb++ ) {
226 for(
int k=0; k<static_cast<int>(
nEtfBunch); k++ ) {
229 fEtfBunchCal.push_back(etfbunch);
232 for(
int ibcom=0; ibcom<ibcomSize; ibcom++ ) {
234 for(
int j=0; j<static_cast<int>(
nBarOffset); j++) {
237 for(
int j=0; j<static_cast<int>(
nBarSigCor); j++) {
240 fBTofCommonCal.push_back(bcomtof);
244 for(
int iinfo=0; iinfo<iinfoSize; iinfo++ ) {
252 for(
unsigned int j=0; j<5; j++ ) {
255 if( (
test->getVersion(iinfo))<=8 ) {
259 tofinfo->
setEtf( j,
test->getEndcap(iinfo, j) );
266 fTofInfoCal.push_back(tofinfo);
269 return StatusCode::SUCCESS;
275 MsgStream log(
msgSvc(), name());
279 unsigned int inumber = 0;
281 std::vector<TofInfoCal*>::iterator it = fTofInfoCal.begin();
282 if( (*it)->getRunFrom() == -1 ) {
283 if( fTofInfoCal.size() == 1 ) {
284 log << MSG::INFO <<
"TofCaliSvc::chooseConstants() -- Run From is equal to -1! The ONLY TOF calibration constants are used!" << endreq;
285 return StatusCode::SUCCESS;
288 log << MSG::ERROR <<
"TofCaliSvc::chooseConstants() -- Run From is equal to -1! The NUMBER of calibration constants are NOT equal to 1!" << endreq;
289 return StatusCode::FAILURE;
293 for( ; it!= fTofInfoCal.end(); it++, inumber++ ) {
294 if( ( (*it)->getRunTo() != -1 ) && ( (*it)->getRunTo() < (*it)->getRunFrom() ) ) {
295 log << MSG::ERROR <<
"TofCaliSvc::chooseConstants() -- The " << inumber <<
"th calibration constatns is ABNORMAL! Run From is LARGER than RUN To!" << endreq;
296 return StatusCode::FAILURE;
298 if( ( (*it)->getRunFrom() == (*it)->getRunTo() ) && ( (*it)->getEventFrom() != -1 ) && ( (*it)->getEventTo() != -1 ) && ( (*it)->getEventFrom() > (*it)->getEventTo() ) ) {
299 log << MSG::ERROR <<
"TofCaliSvc::chooseConstants() -- The " << inumber <<
"th calibration constatns is ABNORMAL! Event From is LARGER than Event To!" << endreq;
300 return StatusCode::FAILURE;
304 it = fTofInfoCal.begin();
306 for( ; it!= fTofInfoCal.end(); it++, inumber++ ) {
307 int runFrom = (*it)->getRunFrom();
308 int runTo = (*it)->getRunTo();
309 int eventFrom = (*it)->getEventFrom();
310 int eventTo = (*it)->getEventTo();
311 if( ( run == runFrom ) && ( ( eventFrom == -1 ) || ( event >= eventFrom ) ) ) {
312 if( ( run < runTo ) || ( ( run == runTo ) && ( ( eventTo == -1 ) || ( event <= eventTo ) ) ) ) {
317 if( run > runFrom ) {
318 if( ( run < runTo ) || ( ( run == runTo ) && ( ( eventTo == -1 ) || ( event <= eventTo ) ) ) ) {
326 m_sequence = inumber;
327 return StatusCode::SUCCESS;
330 log << MSG::ERROR <<
"TofCaliSvc::chooseConstants() -- The event with run number " << run <<
" and event number " <<
event <<
" is NOT suitable for this group of calibration constants" << endreq;
331 return StatusCode::FAILURE;
334 return StatusCode::SUCCESS;
341 tdelay = fBTofCal[176*m_sequence+id]->getP1(0);
344 MsgStream log(
msgSvc(), name());
345 log<<MSG::ERROR<<
"TofCaliSvc::BTDelay1() -- Wrong TOFID is provided! ID = "<<
id<<endreq;
354 tdelay = fBTofCal[176*m_sequence+id]->getP2(0);
357 MsgStream log(
msgSvc(), name());
358 log<<MSG::ERROR<<
"TofCaliSvc::BTDelay2() -- Wrong TOFID is provided! ID = "<<
id<<endreq;
367 tdelay = fETofCal[96*m_sequence+id]->getP(0);
370 MsgStream log(
msgSvc(), name());
371 log<<MSG::ERROR<<
"TofCaliSvc::ETDelay() -- Wrong TOFID is provided! ID = "<<
id<<endreq;
378 MsgStream log(
msgSvc(), name());
381 for(
int i=0; i<static_cast<int>(
nBarPar); i++ ) {
382 p1[i]=fBTofCal[176*m_sequence+id]->getP1(i);
385 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;
387 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;
394 MsgStream log(
msgSvc(), name());
397 for(
int i=0; i<static_cast<int>(
nBarPar); i++ ) {
398 p2[i]=fBTofCal[176*m_sequence+id]->getP2(i);
401 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;
403 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;
410 MsgStream log(
msgSvc(), name());
412 int numBunch = fTofInfoCal[m_sequence]->getRunEnd();
413 int whichBunch = (
static_cast<int>(t0/(12000./499.8/(numBunch*1.0))+0.1))%numBunch;
416 if( whichBunch==0 ) {
417 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
418 poff1[i]=fBTofCal[176*m_sequence+id]->getPOff1_bunch0(i);
421 else if( whichBunch==1 ) {
422 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
423 poff1[i]=fBTofCal[176*m_sequence+id]->getPOff1_bunch1(i);
426 else if( whichBunch==2 ) {
427 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
428 poff1[i]=fBTofCal[176*m_sequence+id]->getPOff1_bunch2(i);
431 else if( whichBunch==3 ) {
432 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
433 poff1[i]=fBTofCal[176*m_sequence+id]->getPOff1_bunch3(i);
437 double tCorrOffset1 = 0.0;
439 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;
442 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;
445 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;
452 MsgStream log(
msgSvc(), name());
454 int numBunch = fTofInfoCal[m_sequence]->getRunEnd();
455 int whichBunch = (
static_cast<int>(t0/(12000./499.8/(numBunch*1.0))+0.1))%numBunch;
458 if( whichBunch==0 ) {
459 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
460 poff2[i]=fBTofCal[176*m_sequence+id]->getPOff2_bunch0(i);
463 else if( whichBunch==1 ) {
464 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
465 poff2[i]=fBTofCal[176*m_sequence+id]->getPOff2_bunch1(i);
468 else if( whichBunch==2 ) {
469 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
470 poff2[i]=fBTofCal[176*m_sequence+id]->getPOff2_bunch2(i);
473 else if( whichBunch==3 ) {
474 for(
int i=0; i<static_cast<int>(
nBarParOff); i++ ) {
475 poff2[i]=fBTofCal[176*m_sequence+id]->getPOff2_bunch3(i);
479 double tCorrOffset2 = 0.0;
481 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;
484 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;
487 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;
494 double toffset = fBTofCommonCal[m_sequence]->getOffset(0);
500 MsgStream log(
msgSvc(), name());
502 double tcorr1 =
BTCorr1( ADC, z,
id );
504 double tcorr3 = fBTofCommonCal[m_sequence]->getOffset(0);
506 log << MSG::DEBUG <<
"BTime1 id =" <<
id <<
" tcorr=" << tcorr1 <<
" toffset=" << tcorr2 <<
" total offset=" << tcorr3 << endreq;
508 double time = TDC - tcorr1 - tcorr2 - tcorr3;
511 log<<MSG::WARNING<<
"TofCaliSvc::BTime1() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" z = "<<z<<
" ID = "<<
id<<endreq;
518 MsgStream log(
msgSvc(), name());
520 double tcorr1 =
BTCorr2( ADC, z,
id );
522 double tcorr3 = fBTofCommonCal[m_sequence]->getOffset(0);
524 log << MSG::DEBUG <<
"BTime2 id =" <<
id <<
" tcorr=" << tcorr1 <<
" toffset=" << tcorr2 <<
" total offset=" << tcorr3 << endreq;
526 double time = TDC - tcorr1 - tcorr2 - tcorr3;
529 log<<MSG::WARNING<<
"TofCaliSvc::BTime2() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" z = "<<z<<
" ID = "<<
id<<endreq;
554 double sigmaCorr = fBTofCommonCal[m_sequence]->getSigmaCorr(0);
555 double sigmaCorr2 = sigmaCorr*sigmaCorr;
557 double sigmaLeft =
BSigma1( z,
id );
558 double sigmaLeft2 = sigmaLeft*sigmaLeft;
559 double sigmaRight =
BSigma2( z,
id );
560 double sigmaRight2 = sigmaRight*sigmaRight;
562 double fraction = ( sigmaRight2 - sigmaCorr2 )/( sigmaLeft2 + sigmaRight2 - 2.0*sigmaCorr2);
564 double wt=fraction*tleft + (1.0-fraction)*tright;
566 MsgStream log(
msgSvc(), name());
567 log<<MSG::WARNING<<
"TofCaliSvc::BTimeCounter() -- A minus time is given : "<<wt <<
" [Input] z = "<<z<<
" ID = "<<
id<<endreq;
575 double sigmaCorr = fBTofCommonCal[m_sequence]->getSigmaCorr(0);
576 double sigmaCorr2 = sigmaCorr*sigmaCorr;
579 double sigmaInner2 = sigmaInner*sigmaInner;
581 double sigmaOuter2 = sigmaOuter*sigmaOuter;
583 double fraction = ( sigmaOuter2 - sigmaCorr2 )/( sigmaInner2 + sigmaOuter2 - 2.0*sigmaCorr2);
585 double wt=fraction*tlayer1 + (1.0-fraction)*tlayer2;
587 MsgStream log(
msgSvc(), name());
588 log<<MSG::WARNING<<
"TofCaliSvc::BTimeCluster() -- A minus time is given : "<<wt <<
" [Input] z1 = "<<z1<<
" [Input] z2 = "<<z2<<
" ID1 = "<< id1 <<
" ID2=" << id2 << endreq;
595 MsgStream log(
msgSvc(), name());
598 for(
int i=0; i<static_cast<int>(
nBarSigma); i++ ) {
599 fpleft[i]=fBTofCal[176*m_sequence+id]->getFPLeft(i);
602 log << MSG::DEBUG <<
"BSigma1 id =" <<
id <<
" 1=" << fpleft[0] <<
" 2=" << fpleft[1] <<
" 3=" << fpleft[2] <<
" 4=" << fpleft[3] <<
" 5=" << fpleft[4] << endreq;
604 double sigmaLeft = fpleft[0] + fpleft[1]*z + fpleft[2]*z*z + fpleft[3]*z*z*z + fpleft[4]*z*z*z*z;
611 MsgStream log(
msgSvc(), name());
614 for(
int i=0; i<static_cast<int>(
nBarSigma); i++ ) {
615 fpright[i]=fBTofCal[176*m_sequence+id]->getFPRight(i);
618 log << MSG::DEBUG <<
"BSigma2 id =" <<
id <<
" 1=" << fpright[0] <<
" 2=" << fpright[1] <<
" 3=" << fpright[2] <<
" 4=" << fpright[3] <<
" 5=" << fpright[4] << endreq;
620 double sigmaRight = fpright[0] + fpright[1]*z + fpright[2]*z*z + fpright[3]*z*z*z + fpright[4]*z*z*z*z;
627 MsgStream log(
msgSvc(), name());
630 for(
int i=0; i<static_cast<int>(
nBarSigCnt); i++ ) {
631 fplayer[i]=fBTofCal[176*m_sequence+id]->getFPCounter(i);
634 log << MSG::DEBUG <<
"BSigmaCounter id =" <<
id <<
" 1=" << fplayer[0] <<
" 2=" << fplayer[1] <<
" 3=" << fplayer[2] <<
" 4=" << fplayer[3] <<
" 5=" << fplayer[4] << endreq;
636 double sigma = fplayer[0] + fplayer[1]*z + fplayer[2]*z*z + fplayer[3]*z*z*z + fplayer[4]*z*z*z*z;
644 double sigmaInner2 = sigmaInner*sigmaInner;
646 double sigmaOuter2 = sigmaOuter*sigmaOuter;
647 double sigmaCorr = fBTofCommonCal[m_sequence]->getSigmaCorr(0);
648 double sigmaCorr2 = sigmaCorr*sigmaCorr;
649 double sigma = (sigmaInner2*sigmaOuter2-sigmaCorr2*sigmaCorr2)/(sigmaInner2+sigmaOuter2-2.0*sigmaCorr2);
656 MsgStream log(
msgSvc(), name());
659 for(
int i=0; i<static_cast<int>(
nEndPar); i++ ) {
660 p[i]=fETofCal[96*m_sequence+id]->getP(i);
663 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;
665 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);
668 MsgStream log(
msgSvc(), name());
669 log<<MSG::WARNING<<
"TofCaliSvc::ETime() -- A minus time is given : "<<
time <<
" [Input] ADC = "<<ADC<<
" TDC = "<<TDC<<
" r = "<< rHit <<
" ID = "<<
id<<endreq;
677 MsgStream log(
msgSvc(), name());
680 for(
int i=0; i<static_cast<int>(
nEndSigma); i++) {
681 fp[i]=fETofCal[96*m_sequence+id]->getFPCounter(i);
684 log << MSG::DEBUG <<
"ESigma id =" <<
id <<
" 1=" << fp[0] <<
" 2=" << fp[1] <<
" 3=" << fp[2] << endreq;
686 double sigma = fp[0] + fp[1]*r + fp[2]*r*r;
692const double TofCaliSvc::EtfTime(
double ADC1,
double ADC2,
double TDC1,
double TDC2,
unsigned id,
unsigned int strip,
double t0){
693 MsgStream log(
msgSvc(), name());
695 double q = (ADC1+ADC2)/2.0;
696 double t = (TDC1+TDC2)/2.0;
699 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
700 p[i]=fEtfCal[72*12*m_sequence+12*
id+strip]->getP(i);
704 + p[1]/TMath::Sqrt(
q)
710 double time =
t - tcorr;
712 int numBunch = fTofInfoCal[m_sequence]->getRunEnd();
713 int ibunch = (
static_cast<int>(t0/(12000./499.8/(numBunch*1.0))+0.1))%numBunch;
718 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;
725 MsgStream log(
msgSvc(), name());
728 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
729 p1[i]=fEtfCal[72*12*m_sequence+12*
id+strip]->getP1(i);
732 double tcorr1 = p1[0]
733 + p1[1]/TMath::Sqrt(ADC)
737 + p1[5]*ADC*ADC*ADC*ADC
738 + p1[6]*z/TMath::Sqrt(ADC)
745 double time1 = TDC - tcorr1;
747 int numBunch = fTofInfoCal[m_sequence]->getRunEnd();
748 int ibunch = (
static_cast<int>(t0/(12000./499.8/(numBunch*1.0))+0.1))%numBunch;
751 time1 = time1 - pbunch;
753 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;
760 MsgStream log(
msgSvc(), name());
763 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
764 p2[i]=fEtfCal[72*12*m_sequence+12*
id+strip]->getP2(i);
767 double tcorr2 =
p2[0]
768 +
p2[1]/TMath::Sqrt(ADC)
772 +
p2[5]*ADC*ADC*ADC*ADC
773 +
p2[6]*z/TMath::Sqrt(ADC)
780 double time2 = TDC - tcorr2;
782 int numBunch = fTofInfoCal[m_sequence]->getRunEnd();
783 int ibunch = (
static_cast<int>(t0/(12000./499.8/(numBunch*1.0))+0.1))%numBunch;
786 time2 = time2 - pbunch;
788 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;
794const double TofCaliSvc::EtfTimeMC(
double ADC1,
double ADC2,
double TDC1,
double TDC2,
unsigned id,
unsigned int strip,
double t0){
795 MsgStream log(
msgSvc(), name());
797 double q = (ADC1+ADC2)/2.0;
798 double t = (TDC1+TDC2)/2.0;
801 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
802 p[i]=fEtfCal[72*12*m_sequence+12*
id+strip]->getP(i);
805 double tcorr = p[0] + p[1]/TMath::Sqrt(
q);
806 double time =
t - tcorr;
808 log << MSG::DEBUG <<
"EtfTime module =" <<
id <<
" strip=" << strip <<
" 1=" << p[0] <<
" 2=" << p[1] <<
" tcorr=" << tcorr <<
" t0=" << t0 <<
" time=" <<
time << endreq;
815 MsgStream log(
msgSvc(), name());
818 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
819 p1[i]=fEtfCal[72*12*m_sequence+12*
id+strip]->getP1(i);
822 double tcorr1 = p1[0] + p1[1]/TMath::Sqrt(ADC) + p1[2]*z;
823 double time1 = TDC - tcorr1;
825 log << MSG::DEBUG <<
"EtfTime1 module =" <<
id <<
" strip=" << strip <<
" 1=" << p1[0] <<
" 2=" << p1[1] <<
" 3=" << p1[2] <<
" tcorr=" << tcorr1 <<
" t0=" << t0 <<
" time1=" << time1 << endreq;
832 MsgStream log(
msgSvc(), name());
835 for(
int i=0; i<static_cast<int>(
nEtfPar); i++ ) {
836 p2[i]=fEtfCal[72*12*m_sequence+12*
id+strip]->getP2(i);
839 double tcorr2 =
p2[0] +
p2[1]/TMath::Sqrt(ADC) +
p2[2]*z;
840 double time2 = TDC - tcorr2;
842 log << MSG::DEBUG <<
"EtfTime2 module =" <<
id <<
" strip=" << strip <<
" 1=" <<
p2[0] <<
" 2=" <<
p2[1] <<
" 3=" <<
p2[2] <<
" tcorr=" << tcorr2 <<
" t0=" << t0 <<
" time2=" << time2 << endreq;
849 MsgStream log(
msgSvc(), name());
851 double time = (tleft+tright)/2.0;
852 log << MSG::DEBUG <<
"EtfTime tleft=" << tleft <<
" tright=" << tright <<
" time=" <<
time << endreq;
859 MsgStream log(
msgSvc(), name());
862 if( fEtfBunchCal.size()>0 && index>=0 && index<4 ) {
863 pbunch=fEtfBunchCal[m_sequence]->getBunchP(index);
871 double length = 230.0;
873 double Latten = fBTofCal[176*m_sequence+id]->getAtten(0);
874 double q0 = ADC*sint*TMath::Exp((0.5*length-zHit)/Latten)/A;
880 double length = 230.0;
882 double Latten = fBTofCal[176*m_sequence+id]->getAtten(0);
883 double q0 = ADC*sint*TMath::Exp((0.5*length+zHit)/Latten)/A;
889 double length = 230.0;
890 double Latten = fBTofCal[176*m_sequence+id]->getAtten(0);
891 double gainRatio = fBTofCal[176*m_sequence+id]->getAtten(1);
892 double A2 = fBTofCal[176*m_sequence+id]->getAtten(2);
893 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)) );
898const double TofCaliSvc::BPh(
double ADC1,
double ADC2,
double zHit,
unsigned int id ) {
899 double length = 230.0;
900 double Latten = fBTofCal[176*m_sequence+id]->getAtten(0);
901 double gainRatio = fBTofCal[176*m_sequence+id]->getAtten(1);
902 double q = ( ADC1*TMath::Exp((0.5*length-zHit)/Latten)+ADC2*TMath::Exp((0.5*length+zHit)/Latten) )/(1.0+TMath::Exp(gainRatio));
908 double length = 44.5;
909 double a0 = fETofCal[96*m_sequence+id]->getAtten(0);
910 double a1 = fETofCal[96*m_sequence+id]->getAtten(1);
911 double a2 = fETofCal[96*m_sequence+id]->getAtten(2);
912 double a3 = fETofCal[96*m_sequence+id]->getAtten(3);
914 double q0 = ADC*fabs(cost)*TMath::Exp(-(a1*(rHit-length)+a2*(rHit-length)*(rHit-length)))/a3;
921 double length = 44.5;
922 double a0 = fETofCal[96*m_sequence+id]->getAtten(0);
923 double a1 = fETofCal[96*m_sequence+id]->getAtten(1);
924 double a2 = fETofCal[96*m_sequence+id]->getAtten(2);
925 double q0 = ADC*TMath::Exp(-(a0+a1*(rHit-length)+a2*(rHit-length)*(rHit-length)));
931 return fBTofCal[176*m_sequence+id]->getAtten(3);
937 return fBTofCal[176*m_sequence+id]->getVeff(0);
939 std::cout<<
"bad id="<<
id<<std::endl;
945 if(
id > 175 )
return -1;
946 return fBTofCal[176*m_sequence+id]->getAtten(0);
950 if(
id > 175 )
return -1;
951 double gainRatio = fBTofCal[176*m_sequence+id]->getAtten(1);
952 double A2 = fBTofCal[176*m_sequence+id]->getAtten(2);
953 double A1 = A2*TMath::Exp(gainRatio);
958 if(
id > 175 )
return -1;
959 return fBTofCal[176*m_sequence+id]->getAtten(2);
963 if(
id > 175 )
return -1;
964 return fETofCal[96*m_sequence+id]->getVeff(0);
968 if(
id<72 && strip<12){
969 return fEtfCal[72*12*m_sequence+12*
id+strip]->getVeff(0);
971 std::cout<<
"bad id="<<
id<<
" strip="<<strip<<std::endl;
978 double ztdc = -1000.0;
979 if(
id > 175 )
return ztdc;
980 double veff = fBTofCal[176*m_sequence+id]->getVeff(0);
981 double delay = fBTofCal[176*m_sequence+id]->getVeff(1);
982 ztdc = 0.5*veff*(tright-tleft-delay);
987 double tleft = -1000.0;
988 if(
id > 175 )
return tleft;
989 if( tright < -900.0 )
return tleft;
990 double veff = fBTofCal[176*m_sequence+id]->getVeff(0);
991 double delay = fBTofCal[176*m_sequence+id]->getVeff(1);
992 tleft = tright-delay-2.0*z/veff;
997 double tright = -1000.0;
998 if(
id > 175 )
return tright;
999 if( tleft < -900.0 )
return tright;
1000 double veff = fBTofCal[176*m_sequence+id]->getVeff(0);
1001 double delay = fBTofCal[176*m_sequence+id]->getVeff(1);
1002 tright = tleft+delay+2.0*z/veff;
1007 double zadc = -1000.0;
1008 if(
id > 175 )
return zadc;
1009 if( qright < 1.0e-6 )
return zadc;
1010 double ldecay = fBTofCal[176*m_sequence+id]->getAtten(0);
1011 double a1overa2 = fBTofCal[176*m_sequence+id]->getAtten(1);
1012 double q1overq2 = log(qleft/qright);
1013 zadc = 0.5*ldecay*( q1overq2 - a1overa2 );
1018 double qleft = -1000.0;
1019 if(
id > 175 )
return qleft;
1020 if( qright < 1.0e-6 )
return qleft;
1021 double ldecay = fBTofCal[176*m_sequence+id]->getAtten(0);
1022 double a1overa2 = fBTofCal[176*m_sequence+id]->getAtten(1);
1023 double q1overq2 = 2.0*z/ldecay + a1overa2;
1024 qleft = qright*
exp(q1overq2);
1029 double qright = -1000.0;
1030 if(
id > 175 )
return qright;
1031 if( qleft < 1.0e-6 )
return qright;
1032 double ldecay = fBTofCal[176*m_sequence+id]->getAtten(0);
1033 double a1overa2 = fBTofCal[176*m_sequence+id]->getAtten(1);
1034 double q1overq2 = 2.0*z/ldecay + a1overa2;
1035 qright = qleft*
exp(-q1overq2);
1040 double ztdc = -1000.0;
1041 if(
id>71 || strip>11 )
return ztdc;
1042 double delay = fEtfCal[72*12*m_sequence+12*
id+strip]->getVeff(0);
1043 double veff = fEtfCal[72*12*m_sequence+12*
id+strip]->getVeff(1);
1044 ztdc = (tright-tleft-delay)/veff;
1050 if(
id > 95 )
return -1;
1051 return fETofCal[96*m_sequence+id]->getAtten(0);
1055 if(
id > 95 )
return -1;
1056 return fETofCal[96*m_sequence+id]->getAtten(1);
1060 return fTofInfoCal[m_sequence]->getRunBegin();
1064 return fTofInfoCal[m_sequence]->getRunEnd();
1068 return fTofInfoCal[m_sequence]->getVersion();
1072 return fTofInfoCal[m_sequence]->getQCorr();
1076 return fTofInfoCal[m_sequence]->getQElec();
1080 return fTofInfoCal[m_sequence]->getMisLable();
1084 return fTofInfoCal[m_sequence]->getBrEast(im);
1088 return fTofInfoCal[m_sequence]->getBrWest(im);
1092 return fTofInfoCal[m_sequence]->getEndcap(im);
1096 return fTofInfoCal[m_sequence]->getEndcap(im);
1100 return fBTofCal[176*m_sequence+id];
1104 return fETofCal[96*m_sequence+id];
1108 return fEtfCal[72*12*m_sequence+id];
1112 return fBTofCommonCal[m_sequence];
1116 return fTofInfoCal[m_sequence];
1120 std::cout<<
"Now We can get the TOF Calibtration Service"<<std::endl;
1121 std::cout<<
"Barrel TOF Counter Number = "<<fBTofCal.size()<<std::endl;
1122 std::cout<<
"Endcap TOF Counter Number = "<<fETofCal.size()<<std::endl;
1124 cout<<
"The O Barrel TOF PMT1 p1[0] is"<<
" "<<
BTof(0)->
getP1(0)<<endl;
1125 cout<<
"The 0 Barrel TOF PMT1 p1[1] is"<<
" "<<
BTof(0)->
getP1(1)<<endl;
1126 cout<<
"The 0 Barrel TOF veff is"<<
" "<<
BTof(0)->
getVeff(0)<<endl;
1131 MsgStream log( messageService(), name() );
1132 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
1134 if ( inc.type() ==
"NewRun" ){
1135 log << MSG::DEBUG <<
"New Run" << endreq;
1138 StatusCode sc= FillfromDatabase();
1140 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)
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)
StatusCode chooseConstants(int run, int number)
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
ETofCal * ETof(unsigned int id) const
const double BSigmaCounter(double zHit, unsigned int id)
void setEventTo(int evtTo)
void setRunFrom(int runFrom)
void setVersion(int version)
void setMisLable(int mis)
void setEventFrom(int evtFrom)
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)