13#include "GaudiKernel/DataSvc.h"
14#include "GaudiKernel/IDataProviderSvc.h"
15#include "GaudiKernel/IIncidentListener.h"
16#include "GaudiKernel/IIncidentSvc.h"
17#include "GaudiKernel/IInterface.h"
18#include "GaudiKernel/Incident.h"
19#include "GaudiKernel/Kernel.h"
20#include "GaudiKernel/MsgStream.h"
21#include "GaudiKernel/Service.h"
22#include "GaudiKernel/SmartDataPtr.h"
23#include "GaudiKernel/StatusCode.h"
29#include "CalibData/CalibModel.h"
30#include "CalibData/Tof/TofCalibData.h"
31#include "CalibData/Tof/bTofCalibBase.h"
32#include "Identifier/TofID.h"
43 : base_class( name, svcloc )
47 declareProperty(
"Run", m_run = 1 );
52 m_hasbeeninitialized =
false;
55 MsgStream log(
msgSvc(), name() );
56 log << MSG::INFO << name() <<
": Start of run initialisation" << endmsg;
58 StatusCode sc = Service::initialize();
59 if ( sc.isFailure() )
return sc;
62 sc = service(
"IncidentSvc", incsvc );
64 if ( sc.isSuccess() ) { incsvc->addListener(
this,
"NewRun", priority ); }
68 log << MSG::INFO <<
"setProperties()" << endmsg;
69 scc = service(
"CalibDataSvc", m_pCalibDataSvc,
true );
70 if ( !scc.isSuccess() )
72 log << MSG::ERROR <<
"Could not get IDataProviderSvc interface of CalibXmlCnvSvc"
77 { log << MSG::DEBUG <<
"Retrieved IDataProviderSvc interface of CalibXmlCnvSvc" << endmsg; }
85 MsgStream log(
msgSvc(), name() );
86 log << MSG::INFO << name() <<
": End of Run" << endmsg;
87 return StatusCode::SUCCESS;
90StatusCode TofCaliSvc::FillfromDatabase() {
92 MsgStream log(
msgSvc(), name() );
93 std::string fullPath =
"/Calib/TofCal";
94 log << MSG::INFO <<
" Tof calib fullPath = " << fullPath << endmsg;
96 SmartDataPtr<CalibData::TofCalibData>
test( m_pCalibDataSvc, fullPath );
99 log << MSG::FATAL <<
"TofCaliSvc could not find TofCalibData in TCDS!!" << endmsg;
100 return StatusCode::FAILURE;
106 fEtfBunchCal.clear();
107 fBTofCommonCal.clear();
110 unsigned int ibSize =
test->getBTofSize();
111 unsigned int ibcomSize =
test->getBTofComSize();
112 unsigned int ieSize =
test->getETofSize();
113 unsigned int ietfSize =
test->getEtfSize();
114 ietfSize = ietfSize / 12;
115 unsigned int ietfBSize =
test->getEtfBunchSize();
116 unsigned int iinfoSize =
test->getTofInfoSize();
118 for (
int ib = 0; ib < ibSize; ib++ )
121 for (
int j = 0; j < static_cast<int>(
nBarAtten ); j++ )
123 for (
int j = 0; j < static_cast<int>(
nBarSpeed ); j++ )
124 { btof.
setVeff( j,
test->getBTofSpeed( ib, j ) ); }
125 for (
int j = 0; j < static_cast<int>(
nBarPar ); j++ )
127 btof.
setP1( j,
test->getBTofPleft( ib, j ) );
128 btof.
setP2( j,
test->getBTofPright( ib, j ) );
130 for (
int j = 0; j < static_cast<int>(
nBarParOff ); j++ )
141 for (
int j = 0; j < static_cast<int>(
nBarSigma ); j++ )
146 for (
int j = 0; j < static_cast<int>(
nBarSigCnt ); j++ )
149 fBTofCal.push_back( btof );
152 for (
int ie = 0; ie < ieSize; ie++ )
155 for (
int j = 0; j < static_cast<int>(
nEndAtten ); j++ )
157 for (
int j = 0; j < static_cast<int>(
nEndSpeed ); j++ )
158 { etof.
setVeff( j,
test->getETofSpeed( ie, j ) ); }
159 for (
int j = 0; j < static_cast<int>(
nEndPar ); j++ )
160 { etof.
setP( j,
test->getETofP( ie, j ) ); }
161 for (
int j = 0; j < static_cast<int>(
nEndSigma ); j++ )
163 fETofCal.push_back( etof );
166 for (
int ietf = 0; ietf < ietfSize; ietf++ )
168 for (
int jetf = 0; jetf < 12; jetf++ )
171 for (
int k = 0; k < static_cast<int>(
nEtfSpeed ); k++ )
172 { etf.
setVeff( k,
test->getEtfSpeed( ietf, jetf, k ) ); }
173 for (
int k = 0; k < static_cast<int>(
nEtfPar ); k++ )
175 etf.
setP( k,
test->getEtfPcombine( ietf, jetf, k ) );
176 etf.
setP1( k,
test->getEtfPleft( ietf, jetf, k ) );
177 etf.
setP2( k,
test->getEtfPright( ietf, jetf, k ) );
179 fEtfCal.push_back( etf );
183 for (
int ietfb = 0; ietfb < ietfBSize; ietfb++ )
185 EtfBunchCal etfbunch;
186 for (
int k = 0; k < static_cast<int>(
nEtfBunch ); k++ )
188 fEtfBunchCal.push_back( etfbunch );
191 for (
int ibcom = 0; ibcom < ibcomSize; ibcom++ )
193 BTofCommonCal bcomtof;
194 for (
int j = 0; j < static_cast<int>(
nBarOffset ); j++ )
196 for (
int j = 0; j < static_cast<int>(
nBarSigCor ); j++ )
198 fBTofCommonCal.push_back( bcomtof );
201 for (
int iinfo = 0; iinfo < iinfoSize; iinfo++ )
210 unsigned int iEtfDeadChannel = 0;
211 for (
unsigned int j = 0; j < 5; j++ )
215 if ( (
test->getVersion( iinfo ) ) == 0 )
223 if (
test->getEndcap( iinfo, j ) == 1 )
229 for (
int istrip = 5; istrip < 12; istrip++ )
237 else if (
test->getEndcap( iinfo, j ) == 2 )
242 else if (
test->getEndcap( iinfo, j ) == 3 )
244 for (
int itofid = 12; itofid < 24; itofid++ )
246 for (
int istrip = 0; istrip < 12; istrip++ )
255 else if (
test->getEndcap( iinfo, j ) == 4 )
257 for (
int istrip = 0; istrip < 12; istrip++ )
265 else if (
test->getEndcap( iinfo, j ) == 5 )
267 for (
int istrip = 0; istrip < 12; istrip++ )
275 else if (
test->getEndcap( iinfo, j ) == 6 )
277 for (
int istrip = 1; istrip < 6; istrip++ )
289 fTofInfoCal.push_back( tofinfo );
292 return StatusCode::SUCCESS;
297 MsgStream log(
msgSvc(), name() );
301 unsigned int inumber = 0;
303 std::vector<TofInfoCal>::iterator it = fTofInfoCal.begin();
304 if ( ( *it ).getRunFrom() == -1 )
306 if ( fTofInfoCal.size() == 1 )
309 <<
"TofCaliSvc::chooseConstants() -- Run From is equal to -1! The ONLY TOF "
310 "calibration constants are used!"
312 return StatusCode::SUCCESS;
317 <<
"TofCaliSvc::chooseConstants() -- Run From is equal to -1! The NUMBER of "
318 "calibration constants are NOT "
322 return StatusCode::FAILURE;
326 for ( ; it != fTofInfoCal.end(); it++, inumber++ )
328 if ( ( ( *it ).getRunTo() != -1 ) && ( ( *it ).getRunTo() < ( *it ).getRunFrom() ) )
330 log << MSG::ERROR <<
"TofCaliSvc::chooseConstants() -- The " << inumber
331 <<
"th calibration constatns is ABNORMAL! Run From is LARGER than RUN To!" << endmsg;
332 return StatusCode::FAILURE;
334 if ( ( ( *it ).getRunFrom() == ( *it ).getRunTo() ) && ( ( *it ).getEventFrom() != -1 ) &&
335 ( ( *it ).getEventTo() != -1 ) && ( ( *it ).getEventFrom() > ( *it ).getEventTo() ) )
337 log << MSG::ERROR <<
"TofCaliSvc::chooseConstants() -- The " << inumber
338 <<
"th calibration constatns is ABNORMAL! Event From is LARGER than Event To!"
340 return StatusCode::FAILURE;
344 it = fTofInfoCal.begin();
346 for ( ; it != fTofInfoCal.end(); it++, inumber++ )
348 int runFrom = ( *it ).getRunFrom();
349 int runTo = ( *it ).getRunTo();
350 int eventFrom = ( *it ).getEventFrom();
351 int eventTo = ( *it ).getEventTo();
352 if ( ( run == runFrom ) && ( ( eventFrom == -1 ) || ( event >= eventFrom ) ) )
354 if ( ( run < runTo ) ||
355 ( ( run == runTo ) && ( ( eventTo == -1 ) || ( event <= eventTo ) ) ) )
363 if ( ( run < runTo ) ||
364 ( ( run == runTo ) && ( ( eventTo == -1 ) || ( event <= eventTo ) ) ) )
374 m_sequence = inumber;
375 return StatusCode::SUCCESS;
379 log << MSG::ERROR <<
"TofCaliSvc::chooseConstants() -- The event with run number " << run
380 <<
" and event number " <<
event
381 <<
" is NOT suitable for this group of calibration constants" << endmsg;
382 return StatusCode::FAILURE;
385 return StatusCode::SUCCESS;
390 if (
id < 176 ) { tdelay = fBTofCal[176 * m_sequence + id].getP1( 0 ); }
393 MsgStream log(
msgSvc(), name() );
394 log << MSG::ERROR <<
"TofCaliSvc::BTDelay1() -- Wrong TOFID is provided! ID = " <<
id
402 if (
id < 176 ) { tdelay = fBTofCal[176 * m_sequence + id].getP2( 0 ); }
405 MsgStream log(
msgSvc(), name() );
406 log << MSG::ERROR <<
"TofCaliSvc::BTDelay2() -- Wrong TOFID is provided! ID = " <<
id
414 if (
id < 96 ) { tdelay = fETofCal[96 * m_sequence + id].getP( 0 ); }
417 MsgStream log(
msgSvc(), name() );
418 log << MSG::ERROR <<
"TofCaliSvc::ETDelay() -- Wrong TOFID is provided! ID = " <<
id
425 MsgStream log(
msgSvc(), name() );
428 for (
int i = 0; i < static_cast<int>(
nBarPar ); i++ )
429 {
p1[i] = fBTofCal[176 * m_sequence + id].getP1( i ); }
431 log << MSG::DEBUG <<
"BTCorr1 id =" <<
id <<
" 1=" <<
p1[0] <<
" 2=" <<
p1[1]
432 <<
" 3=" <<
p1[2] <<
" 4=" <<
p1[3] <<
" 5=" <<
p1[4] <<
" 6=" <<
p1[5] <<
" 7=" <<
p1[6]
433 <<
" 8=" <<
p1[7] <<
" 9=" <<
p1[8] << endmsg;
435 double tcorr1 =
p1[0] +
p1[1] / TMath::Sqrt( ADC ) +
p1[2] * z / TMath::Sqrt( ADC ) +
436 p1[3] / ADC +
p1[4] * z +
p1[5] * z * z +
p1[6] * z * z * z;
442 MsgStream log(
msgSvc(), name() );
445 for (
int i = 0; i < static_cast<int>(
nBarPar ); i++ )
446 {
p2[i] = fBTofCal[176 * m_sequence + id].getP2( i ); }
448 log << MSG::DEBUG <<
"BTCorr2 id =" <<
id <<
" 1=" <<
p2[0] <<
" 2=" <<
p2[1]
449 <<
" 3=" <<
p2[2] <<
" 4=" <<
p2[3] <<
" 5=" <<
p2[4] <<
" 6=" <<
p2[5] <<
" 7=" <<
p2[6]
450 <<
" 8=" <<
p2[7] <<
" 9=" <<
p2[8] << endmsg;
452 double tcorr2 =
p2[0] +
p2[1] / TMath::Sqrt( ADC ) +
p2[2] * z / TMath::Sqrt( ADC ) +
453 p2[3] / ADC +
p2[4] * z +
p2[5] * z * z +
p2[6] * z * z * z;
459 MsgStream log(
msgSvc(), name() );
461 int numBunch = fTofInfoCal[m_sequence].getRunEnd();
463 (
static_cast<int>( t0 / ( 12000. / 499.8 / ( numBunch * 1.0 ) ) + 0.1 ) ) % numBunch;
466 if ( whichBunch == 0 )
468 for (
int i = 0; i < static_cast<int>(
nBarParOff ); i++ )
469 { poff1[i] = fBTofCal[176 * m_sequence + id].getPOff1_bunch0( i ); }
471 else if ( whichBunch == 1 )
473 for (
int i = 0; i < static_cast<int>(
nBarParOff ); i++ )
474 { poff1[i] = fBTofCal[176 * m_sequence + id].getPOff1_bunch1( i ); }
476 else if ( whichBunch == 2 )
478 for (
int i = 0; i < static_cast<int>(
nBarParOff ); i++ )
479 { poff1[i] = fBTofCal[176 * m_sequence + id].getPOff1_bunch2( i ); }
481 else if ( whichBunch == 3 )
483 for (
int i = 0; i < static_cast<int>(
nBarParOff ); i++ )
484 { poff1[i] = fBTofCal[176 * m_sequence + id].getPOff1_bunch3( i ); }
487 double tCorrOffset1 = 0.0;
490 tCorrOffset1 = poff1[0] + poff1[1] * z + poff1[2] * z * z + poff1[3] * z * z * z +
491 poff1[4] * z * z * z * z + poff1[5] * z * z * z * z * z +
492 poff1[6] * z * z * z * z * z * z;
496 tCorrOffset1 = poff1[10] + poff1[11] * z + poff1[12] * z * z + poff1[13] * z * z * z +
497 poff1[14] * z * z * z * z + poff1[15] * z * z * z * z * z +
498 poff1[16] * z * z * z * z * z * z;
501 log << MSG::DEBUG <<
"BTCorrOff1 id =" <<
id <<
" bunch number=" << whichBunch
502 <<
" TCorrOffset1=" << tCorrOffset1 <<
" 1=" << poff1[0] <<
" 2=" << poff1[1]
503 <<
" 3=" << poff1[2] <<
" 4=" << poff1[3] <<
" 5=" << poff1[4] <<
" 6=" << poff1[5]
504 <<
" 7=" << poff1[6] <<
" 8=" << poff1[7] <<
" 9=" << poff1[8] << endmsg;
510 MsgStream log(
msgSvc(), name() );
512 int numBunch = fTofInfoCal[m_sequence].getRunEnd();
514 (
static_cast<int>( t0 / ( 12000. / 499.8 / ( numBunch * 1.0 ) ) + 0.1 ) ) % numBunch;
517 if ( whichBunch == 0 )
519 for (
int i = 0; i < static_cast<int>(
nBarParOff ); i++ )
520 { poff2[i] = fBTofCal[176 * m_sequence + id].getPOff2_bunch0( i ); }
522 else if ( whichBunch == 1 )
524 for (
int i = 0; i < static_cast<int>(
nBarParOff ); i++ )
525 { poff2[i] = fBTofCal[176 * m_sequence + id].getPOff2_bunch1( i ); }
527 else if ( whichBunch == 2 )
529 for (
int i = 0; i < static_cast<int>(
nBarParOff ); i++ )
530 { poff2[i] = fBTofCal[176 * m_sequence + id].getPOff2_bunch2( i ); }
532 else if ( whichBunch == 3 )
534 for (
int i = 0; i < static_cast<int>(
nBarParOff ); i++ )
535 { poff2[i] = fBTofCal[176 * m_sequence + id].getPOff2_bunch3( i ); }
538 double tCorrOffset2 = 0.0;
541 tCorrOffset2 = poff2[0] + poff2[1] * z + poff2[2] * z * z + poff2[3] * z * z * z +
542 poff2[4] * z * z * z * z + poff2[5] * z * z * z * z * z +
543 poff2[6] * z * z * z * z * z * z;
547 tCorrOffset2 = poff2[10] + poff2[11] * z + poff2[12] * z * z + poff2[13] * z * z * z +
548 poff2[14] * z * z * z * z + poff2[15] * z * z * z * z * z +
549 poff2[16] * z * z * z * z * z * z;
552 log << MSG::DEBUG <<
"BTCorrOff2 id =" <<
id <<
" bunch number=" << whichBunch
553 <<
" TCorrOffset2=" << tCorrOffset2 <<
" 1=" << poff2[0] <<
" 2=" << poff2[1]
554 <<
" 3=" << poff2[2] <<
" 4=" << poff2[3] <<
" 5=" << poff2[4] <<
" 6=" << poff2[5]
555 <<
" 7=" << poff2[6] <<
" 8=" << poff2[7] <<
" 9=" << poff2[8] << endmsg;
561 double toffset = fBTofCommonCal[m_sequence].getOffset( 0 );
566 MsgStream log(
msgSvc(), name() );
568 double tcorr1 =
BTCorr1( ADC, z,
id );
570 double tcorr3 = fBTofCommonCal[m_sequence].getOffset( 0 );
572 log << MSG::DEBUG <<
"BTime1 id =" <<
id <<
" tcorr=" << tcorr1 <<
" toffset=" << tcorr2
573 <<
" total offset=" << tcorr3 << endmsg;
575 double time = TDC - tcorr1 - tcorr2 - tcorr3;
579 log << MSG::WARNING <<
"TofCaliSvc::BTime1() -- A minus time is given : " <<
time
580 <<
" [Input] ADC = " << ADC <<
" TDC = " << TDC <<
" z = " << z <<
" ID = " <<
id
587 MsgStream log(
msgSvc(), name() );
589 double tcorr1 =
BTCorr2( ADC, z,
id );
591 double tcorr3 = fBTofCommonCal[m_sequence].getOffset( 0 );
593 log << MSG::DEBUG <<
"BTime2 id =" <<
id <<
" tcorr=" << tcorr1 <<
" toffset=" << tcorr2
594 <<
" total offset=" << tcorr3 << endmsg;
596 double time = TDC - tcorr1 - tcorr2 - tcorr3;
600 log << MSG::WARNING <<
"TofCaliSvc::BTime2() -- A minus time is given : " <<
time
601 <<
" [Input] ADC = " << ADC <<
" TDC = " << TDC <<
" z = " << z <<
" ID = " <<
id
627 double sigmaCorr = fBTofCommonCal[m_sequence].getSigmaCorr( 0 );
628 double sigmaCorr2 = sigmaCorr * sigmaCorr;
630 double sigmaLeft =
BSigma1( z,
id );
631 double sigmaLeft2 = sigmaLeft * sigmaLeft;
632 double sigmaRight =
BSigma2( z,
id );
633 double sigmaRight2 = sigmaRight * sigmaRight;
636 ( sigmaRight2 - sigmaCorr2 ) / ( sigmaLeft2 + sigmaRight2 - 2.0 * sigmaCorr2 );
638 double wt = fraction * tleft + ( 1.0 - fraction ) * tright;
641 MsgStream log(
msgSvc(), name() );
642 log << MSG::WARNING <<
"TofCaliSvc::BTimeCounter() -- A minus time is given : " << wt
643 <<
" [Input] z = " << z <<
" ID = " <<
id << endmsg;
650 unsigned id1,
unsigned id2 ) {
652 double sigmaCorr = fBTofCommonCal[m_sequence].getSigmaCorr( 0 );
653 double sigmaCorr2 = sigmaCorr * sigmaCorr;
656 double sigmaInner2 = sigmaInner * sigmaInner;
658 double sigmaOuter2 = sigmaOuter * sigmaOuter;
661 ( sigmaOuter2 - sigmaCorr2 ) / ( sigmaInner2 + sigmaOuter2 - 2.0 * sigmaCorr2 );
663 double wt = fraction * tlayer1 + ( 1.0 - fraction ) * tlayer2;
666 MsgStream log(
msgSvc(), name() );
667 log << MSG::WARNING <<
"TofCaliSvc::BTimeCluster() -- A minus time is given : " << wt
668 <<
" [Input] z1 = " << z1 <<
" [Input] z2 = " << z2 <<
" ID1 = " << id1
669 <<
" ID2=" << id2 << endmsg;
675 MsgStream log(
msgSvc(), name() );
678 for (
int i = 0; i < static_cast<int>(
nBarSigma ); i++ )
679 { fpleft[i] = fBTofCal[176 * m_sequence + id].getFPLeft( i ); }
681 log << MSG::DEBUG <<
"BSigma1 id =" <<
id <<
" 1=" << fpleft[0] <<
" 2=" << fpleft[1]
682 <<
" 3=" << fpleft[2] <<
" 4=" << fpleft[3] <<
" 5=" << fpleft[4] << endmsg;
684 double sigmaLeft = fpleft[0] + fpleft[1] * z + fpleft[2] * z * z + fpleft[3] * z * z * z +
685 fpleft[4] * z * z * z * z;
691 MsgStream log(
msgSvc(), name() );
694 for (
int i = 0; i < static_cast<int>(
nBarSigma ); i++ )
695 { fpright[i] = fBTofCal[176 * m_sequence + id].getFPRight( i ); }
697 log << MSG::DEBUG <<
"BSigma2 id =" <<
id <<
" 1=" << fpright[0] <<
" 2=" << fpright[1]
698 <<
" 3=" << fpright[2] <<
" 4=" << fpright[3] <<
" 5=" << fpright[4] << endmsg;
700 double sigmaRight = fpright[0] + fpright[1] * z + fpright[2] * z * z +
701 fpright[3] * z * z * z + fpright[4] * z * z * z * z;
707 MsgStream log(
msgSvc(), name() );
710 for (
int i = 0; i < static_cast<int>(
nBarSigCnt ); i++ )
711 { fplayer[i] = fBTofCal[176 * m_sequence + id].getFPCounter( i ); }
713 log << MSG::DEBUG <<
"BSigmaCounter id =" <<
id <<
" 1=" << fplayer[0]
714 <<
" 2=" << fplayer[1] <<
" 3=" << fplayer[2] <<
" 4=" << fplayer[3]
715 <<
" 5=" << fplayer[4] << endmsg;
717 double sigma = fplayer[0] + fplayer[1] * z + fplayer[2] * z * z + fplayer[3] * z * z * z +
718 fplayer[4] * z * z * z * z;
725 double sigmaInner2 = sigmaInner * sigmaInner;
727 double sigmaOuter2 = sigmaOuter * sigmaOuter;
728 double sigmaCorr = fBTofCommonCal[m_sequence].getSigmaCorr( 0 );
729 double sigmaCorr2 = sigmaCorr * sigmaCorr;
730 double sigma = ( sigmaInner2 * sigmaOuter2 - sigmaCorr2 * sigmaCorr2 ) /
731 ( sigmaInner2 + sigmaOuter2 - 2.0 * sigmaCorr2 );
732 sigma = sqrt( sigma );
737 MsgStream log(
msgSvc(), name() );
740 for (
int i = 0; i < static_cast<int>(
nEndPar ); i++ )
741 { p[i] = fETofCal[96 * m_sequence + id].getP( i ); }
743 log << MSG::DEBUG <<
"ETime id =" <<
id <<
" 1=" << p[0] <<
" 2=" << p[1] <<
" 3=" << p[2]
744 <<
" 4=" << p[3] <<
" 5=" << p[4] <<
" 6=" << p[5] <<
" 7=" << p[6] << endmsg;
746 double time = TDC - ( p[0] + p[1] / TMath::Sqrt( ADC ) + p[2] / ADC + p[3] * ADC +
747 p[4] * rHit + p[5] * rHit * rHit + p[6] * rHit * rHit * rHit );
751 MsgStream log(
msgSvc(), name() );
752 log << MSG::WARNING <<
"TofCaliSvc::ETime() -- A minus time is given : " <<
time
753 <<
" [Input] ADC = " << ADC <<
" TDC = " << TDC <<
" r = " << rHit <<
" ID = " <<
id
761 MsgStream log(
msgSvc(), name() );
764 for (
int i = 0; i < static_cast<int>(
nEndSigma ); i++ )
765 { fp[i] = fETofCal[96 * m_sequence + id].getFPCounter( i ); }
767 log << MSG::DEBUG <<
"ESigma id =" <<
id <<
" 1=" << fp[0] <<
" 2=" << fp[1]
768 <<
" 3=" << fp[2] << endmsg;
770 double sigma = fp[0] + fp[1] * r + fp[2] * r * r;
776 unsigned id,
unsigned int strip,
double t0 ) {
777 MsgStream log(
msgSvc(), name() );
779 double q = ( ADC1 + ADC2 ) / 2.0;
780 double t = ( TDC1 + TDC2 ) / 2.0;
783 for (
int i = 0; i < static_cast<int>(
nEtfPar ); i++ )
784 { p[i] = fEtfCal[72 * 12 * m_sequence + 12 *
id + strip].getP( i ); }
786 double tcorr = p[0] + p[1] / TMath::Sqrt(
q ) + p[2] /
q + p[3] *
q + p[4] *
q *
q +
787 p[5] *
q *
q *
q + p[6] *
q *
q *
q *
q;
788 double time =
t - tcorr;
790 int numBunch = fTofInfoCal[m_sequence].getRunEnd();
792 (
static_cast<int>( t0 / ( 12000. / 499.8 / ( numBunch * 1.0 ) ) + 0.1 ) ) % numBunch;
797 log << MSG::DEBUG <<
"EtfTime module =" <<
id <<
" strip=" << strip <<
" 1=" << p[0]
798 <<
" 2=" << p[1] <<
" 3=" << p[2] <<
" 4=" << p[3] <<
" 5=" << p[4] <<
" 6=" << p[5]
799 <<
" 7=" << p[6] <<
" 8=" << p[7] <<
" 9=" << p[8] <<
" tcorr=" << tcorr
800 <<
" t0=" << t0 <<
" pbunch=" << pbunch <<
" time=" <<
time << endmsg;
806 unsigned int strip,
double t0 ) {
807 MsgStream log(
msgSvc(), name() );
810 for (
int i = 0; i < static_cast<int>(
nEtfPar ); i++ )
811 {
p1[i] = fEtfCal[72 * 12 * m_sequence + 12 *
id + strip].getP1( i ); }
813 double tcorr1 =
p1[0] +
p1[1] / TMath::Sqrt( ADC ) +
p1[2] * ADC +
p1[3] * ADC * ADC +
814 p1[4] * ADC * ADC * ADC +
p1[5] * ADC * ADC * ADC * ADC +
815 p1[6] * z / TMath::Sqrt( ADC ) +
p1[7] / ADC +
p1[8] * z / ADC +
816 p1[9] * z * ADC +
p1[10] * z +
p1[11] * z * z +
p1[12] * z * z * z;
817 double time1 = TDC - tcorr1;
819 int numBunch = fTofInfoCal[m_sequence].getRunEnd();
821 (
static_cast<int>( t0 / ( 12000. / 499.8 / ( numBunch * 1.0 ) ) + 0.1 ) ) % numBunch;
824 time1 = time1 - pbunch;
826 log << MSG::DEBUG <<
"EtfTime1 module =" <<
id <<
" strip=" << strip <<
" 1=" <<
p1[0]
827 <<
" 2=" <<
p1[1] <<
" 3=" <<
p1[2] <<
" 4=" <<
p1[3] <<
" 5=" <<
p1[4] <<
" 6=" <<
p1[5]
828 <<
" 7=" <<
p1[6] <<
" 8=" <<
p1[7] <<
" 9=" <<
p1[8] <<
" tcorr=" << tcorr1
829 <<
" t0=" << t0 <<
" pbunch=" << pbunch <<
" time1=" << time1 << endmsg;
835 unsigned int strip,
double t0 ) {
836 MsgStream log(
msgSvc(), name() );
839 for (
int i = 0; i < static_cast<int>(
nEtfPar ); i++ )
840 {
p2[i] = fEtfCal[72 * 12 * m_sequence + 12 *
id + strip].getP2( i ); }
842 double tcorr2 =
p2[0] +
p2[1] / TMath::Sqrt( ADC ) +
p2[2] * ADC +
p2[3] * ADC * ADC +
843 p2[4] * ADC * ADC * ADC +
p2[5] * ADC * ADC * ADC * ADC +
844 p2[6] * z / TMath::Sqrt( ADC ) +
p2[7] / ADC +
p2[8] * z / ADC +
845 p2[9] * z * ADC +
p2[10] * z +
p2[11] * z * z +
p2[12] * z * z * z;
846 double time2 = TDC - tcorr2;
848 int numBunch = fTofInfoCal[m_sequence].getRunEnd();
850 (
static_cast<int>( t0 / ( 12000. / 499.8 / ( numBunch * 1.0 ) ) + 0.1 ) ) % numBunch;
853 time2 = time2 - pbunch;
855 log << MSG::DEBUG <<
"EtfTime2 module =" <<
id <<
" strip=" << strip <<
" 1=" <<
p2[0]
856 <<
" 2=" <<
p2[1] <<
" 3=" <<
p2[2] <<
" 4=" <<
p2[3] <<
" 5=" <<
p2[4] <<
" 6=" <<
p2[5]
857 <<
" 7=" <<
p2[6] <<
" 8=" <<
p2[7] <<
" 9=" <<
p2[8] <<
" tcorr=" << tcorr2
858 <<
" t0=" << t0 <<
" pbunch=" << pbunch <<
" time2=" << time2 << endmsg;
864 unsigned id,
unsigned int strip,
double t0 ) {
865 MsgStream log(
msgSvc(), name() );
867 double q = ( ADC1 + ADC2 ) / 2.0;
868 double t = ( TDC1 + TDC2 ) / 2.0;
871 for (
int i = 0; i < static_cast<int>(
nEtfPar ); i++ )
872 { p[i] = fEtfCal[72 * 12 * m_sequence + 12 *
id + strip].getP( i ); }
874 double tcorr = p[0] + p[1] / TMath::Sqrt(
q );
875 double time =
t - tcorr;
877 log << MSG::DEBUG <<
"EtfTime module =" <<
id <<
" strip=" << strip <<
" 1=" << p[0]
878 <<
" 2=" << p[1] <<
" tcorr=" << tcorr <<
" t0=" << t0 <<
" time=" <<
time
885 unsigned int strip,
double t0 ) {
886 MsgStream log(
msgSvc(), name() );
889 for (
int i = 0; i < static_cast<int>(
nEtfPar ); i++ )
890 {
p1[i] = fEtfCal[72 * 12 * m_sequence + 12 *
id + strip].getP1( i ); }
892 double tcorr1 =
p1[0] +
p1[1] / TMath::Sqrt( ADC ) +
p1[2] * z;
893 double time1 = TDC - tcorr1;
895 log << MSG::DEBUG <<
"EtfTime1 module =" <<
id <<
" strip=" << strip <<
" 1=" <<
p1[0]
896 <<
" 2=" <<
p1[1] <<
" 3=" <<
p1[2] <<
" tcorr=" << tcorr1 <<
" t0=" << t0
897 <<
" time1=" << time1 << endmsg;
903 unsigned int strip,
double t0 ) {
904 MsgStream log(
msgSvc(), name() );
907 for (
int i = 0; i < static_cast<int>(
nEtfPar ); i++ )
908 {
p2[i] = fEtfCal[72 * 12 * m_sequence + 12 *
id + strip].getP2( i ); }
910 double tcorr2 =
p2[0] +
p2[1] / TMath::Sqrt( ADC ) +
p2[2] * z;
911 double time2 = TDC - tcorr2;
913 log << MSG::DEBUG <<
"EtfTime2 module =" <<
id <<
" strip=" << strip <<
" 1=" <<
p2[0]
914 <<
" 2=" <<
p2[1] <<
" 3=" <<
p2[2] <<
" tcorr=" << tcorr2 <<
" t0=" << t0
915 <<
" time2=" << time2 << endmsg;
921 MsgStream log(
msgSvc(), name() );
923 double time = ( tleft + tright ) / 2.0;
924 log << MSG::DEBUG <<
"EtfTime tleft=" << tleft <<
" tright=" << tright <<
" time=" <<
time
931 MsgStream log(
msgSvc(), name() );
934 if ( fEtfBunchCal.size() > 0 && index >= 0 && index < 4 )
935 { pbunch = fEtfBunchCal[m_sequence].getBunchP( index ); }
942 double length = 230.0;
944 double Latten = fBTofCal[176 * m_sequence + id].getAtten( 0 );
945 double q0 = ADC * sint * TMath::Exp( ( 0.5 * length - zHit ) / Latten ) / A;
951 double length = 230.0;
953 double Latten = fBTofCal[176 * m_sequence + id].getAtten( 0 );
954 double q0 = ADC * sint * TMath::Exp( ( 0.5 * length + zHit ) / Latten ) / A;
960 double length = 230.0;
961 double Latten = fBTofCal[176 * m_sequence + id].getAtten( 0 );
962 double gainRatio = fBTofCal[176 * m_sequence + id].getAtten( 1 );
963 double A2 = fBTofCal[176 * m_sequence + id].getAtten( 2 );
964 double q = ( ADC1 * sint * TMath::Exp( ( 0.5 * length - zHit ) / Latten ) +
965 ADC2 * sint * TMath::Exp( ( 0.5 * length + zHit ) / Latten ) ) /
966 ( A2 * ( 1.0 + TMath::Exp( gainRatio ) ) );
970const double TofCaliSvc::BPh(
double ADC1,
double ADC2,
double zHit,
unsigned int id ) {
971 double length = 230.0;
972 double Latten = fBTofCal[176 * m_sequence + id].getAtten( 0 );
973 double gainRatio = fBTofCal[176 * m_sequence + id].getAtten( 1 );
974 double q = ( ADC1 * TMath::Exp( ( 0.5 * length - zHit ) / Latten ) +
975 ADC2 * TMath::Exp( ( 0.5 * length + zHit ) / Latten ) ) /
976 ( 1.0 + TMath::Exp( gainRatio ) );
982 double length = 44.5;
983 double a0 = fETofCal[96 * m_sequence + id].getAtten( 0 );
984 double a1 = fETofCal[96 * m_sequence + id].getAtten( 1 );
985 double a2 = fETofCal[96 * m_sequence + id].getAtten( 2 );
986 double a3 = fETofCal[96 * m_sequence + id].getAtten( 3 );
990 TMath::Exp( -( a1 * ( rHit - length ) + a2 * ( rHit - length ) * ( rHit - length ) ) ) /
997 double length = 44.5;
998 double a0 = fETofCal[96 * m_sequence + id].getAtten( 0 );
999 double a1 = fETofCal[96 * m_sequence + id].getAtten( 1 );
1000 double a2 = fETofCal[96 * m_sequence + id].getAtten( 2 );
1001 double q0 = ADC * TMath::Exp( -(
a0 + a1 * ( rHit - length ) +
1002 a2 * ( rHit - length ) * ( rHit - length ) ) );
1007 return fBTofCal[176 * m_sequence + id].getAtten( 3 );
1011 if (
id < 176 ) {
return fBTofCal[176 * m_sequence + id].getVeff( 0 ); }
1014 std::cout <<
"bad id=" <<
id << std::endl;
1020 if (
id > 175 )
return -1;
1021 return fBTofCal[176 * m_sequence + id].getAtten( 0 );
1025 if (
id > 175 )
return -1;
1026 double gainRatio = fBTofCal[176 * m_sequence + id].getAtten( 1 );
1027 double A2 = fBTofCal[176 * m_sequence + id].getAtten( 2 );
1028 double A1 = A2 * TMath::Exp( gainRatio );
1033 if (
id > 175 )
return -1;
1034 return fBTofCal[176 * m_sequence + id].getAtten( 2 );
1038 if (
id > 175 )
return -1;
1039 return fETofCal[96 * m_sequence + id].getVeff( 0 );
1043 if (
id < 72 && strip < 12 )
1044 {
return fEtfCal[72 * 12 * m_sequence + 12 *
id + strip].getVeff( 0 ); }
1047 std::cout <<
"bad id=" <<
id <<
" strip=" << strip << std::endl;
1053 double ztdc = -1000.0;
1054 if (
id > 175 )
return ztdc;
1055 double veff = fBTofCal[176 * m_sequence + id].getVeff( 0 );
1056 double delay = fBTofCal[176 * m_sequence + id].getVeff( 1 );
1057 ztdc = 0.5 * veff * ( tright - tleft - delay );
1062 double tleft = -1000.0;
1063 if (
id > 175 )
return tleft;
1064 if ( tright < -900.0 )
return tleft;
1065 double veff = fBTofCal[176 * m_sequence + id].getVeff( 0 );
1066 double delay = fBTofCal[176 * m_sequence + id].getVeff( 1 );
1067 tleft = tright - delay - 2.0 * z / veff;
1072 double tright = -1000.0;
1073 if (
id > 175 )
return tright;
1074 if ( tleft < -900.0 )
return tright;
1075 double veff = fBTofCal[176 * m_sequence + id].getVeff( 0 );
1076 double delay = fBTofCal[176 * m_sequence + id].getVeff( 1 );
1077 tright = tleft + delay + 2.0 * z / veff;
1082 double zadc = -1000.0;
1083 if (
id > 175 )
return zadc;
1084 if ( qright < 1.0e-6 )
return zadc;
1085 double ldecay = fBTofCal[176 * m_sequence + id].getAtten( 0 );
1086 double a1overa2 = fBTofCal[176 * m_sequence + id].getAtten( 1 );
1087 double q1overq2 = log( qleft / qright );
1088 zadc = 0.5 * ldecay * ( q1overq2 - a1overa2 );
1093 double qleft = -1000.0;
1094 if (
id > 175 )
return qleft;
1095 if ( qright < 1.0e-6 )
return qleft;
1096 double ldecay = fBTofCal[176 * m_sequence + id].getAtten( 0 );
1097 double a1overa2 = fBTofCal[176 * m_sequence + id].getAtten( 1 );
1098 double q1overq2 = 2.0 * z / ldecay + a1overa2;
1099 qleft = qright *
exp( q1overq2 );
1104 double qright = -1000.0;
1105 if (
id > 175 )
return qright;
1106 if ( qleft < 1.0e-6 )
return qright;
1107 double ldecay = fBTofCal[176 * m_sequence + id].getAtten( 0 );
1108 double a1overa2 = fBTofCal[176 * m_sequence + id].getAtten( 1 );
1109 double q1overq2 = 2.0 * z / ldecay + a1overa2;
1110 qright = qleft *
exp( -q1overq2 );
1115 unsigned int strip ) {
1116 double ztdc = -1000.0;
1117 if (
id > 71 || strip > 11 )
return ztdc;
1118 double delay = fEtfCal[72 * 12 * m_sequence + 12 *
id + strip].getVeff( 0 );
1119 double veff = fEtfCal[72 * 12 * m_sequence + 12 *
id + strip].getVeff( 1 );
1120 ztdc = ( tright - tleft - delay ) / veff;
1125 if (
id > 95 )
return -1;
1126 return fETofCal[96 * m_sequence + id].getAtten( 0 );
1130 if (
id > 95 )
return -1;
1131 return fETofCal[96 * m_sequence + id].getAtten( 1 );
1147 return fTofInfoCal[m_sequence].getBrEast( im );
1151 return fTofInfoCal[m_sequence].getBrWest( im );
1155 return fTofInfoCal[m_sequence].getEndcap( im );
1159 return fTofInfoCal[m_sequence].getEndcap( im );
1163 return &fBTofCal[176 * m_sequence + id];
1167 return &fETofCal[96 * m_sequence + id];
1171 return &fEtfCal[72 * 12 * m_sequence + id];
1179 std::cout <<
"Now We can get the TOF Calibtration Service" << std::endl;
1180 std::cout <<
"Barrel TOF Counter Number = " << fBTofCal.size() << std::endl;
1181 std::cout <<
"Endcap TOF Counter Number = " << fETofCal.size() << std::endl;
1183 cout <<
"The O Barrel TOF PMT1 p1[0] is"
1184 <<
" " <<
BTof( 0 )->
getP1( 0 ) << endl;
1185 cout <<
"The 0 Barrel TOF PMT1 p1[1] is"
1186 <<
" " <<
BTof( 0 )->
getP1( 1 ) << endl;
1187 cout <<
"The 0 Barrel TOF veff is"
1193 MsgStream log(
msgSvc(), name() );
1194 log << MSG::DEBUG <<
"handle: " << inc.type() << endmsg;
1196 if ( inc.type() ==
"NewRun" )
1198 log << MSG::DEBUG <<
"New Run" << endmsg;
1201 StatusCode sc = FillfromDatabase();
1202 if ( sc.isSuccess() ) { m_hasbeeninitialized =
true; }
DECLARE_COMPONENT(BesBdkRc)
character *LEPTONflag integer iresonances real zeta5 real a0
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 idx, 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 BTofCommonCal * BTofCommon() const
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)
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)
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 EtfCal * EtfTof(unsigned int id) const
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 TofInfoCal * TofInfo() const
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)
const BTofCal * BTof(unsigned int id) const
const double BTCorr1(double ADC, double zHit, unsigned int id)
void handle(const Incident &)
const ETofCal * ETof(unsigned int id) const
const double BTDelay1(unsigned int id)
const double BTDelay2(unsigned int id)
TofCaliSvc(const std::string &name, ISvcLocator *svcloc)
const double BSigmaCounter(double zHit, unsigned int id)
static value_type getIntID(int barrel_ec, int layer, int phi_module, int end)
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)