11#include "GaudiKernel/DataSvc.h"
12#include "GaudiKernel/IDataProviderSvc.h"
13#include "GaudiKernel/IIncidentListener.h"
14#include "GaudiKernel/IIncidentSvc.h"
15#include "GaudiKernel/IInterface.h"
16#include "GaudiKernel/Incident.h"
17#include "GaudiKernel/Kernel.h"
18#include "GaudiKernel/MsgStream.h"
19#include "GaudiKernel/Service.h"
20#include "GaudiKernel/SmartDataPtr.h"
21#include "GaudiKernel/StatusCode.h"
27#include "CalibData/CalibModel.h"
28#include "CalibData/Tof/TofCalibData.h"
29#include "CalibData/Tof/bTofCalibBase.h"
31#include "EstTofCaliSvc/EstBTofCal.h"
32#include "EstTofCaliSvc/EstBTofCommonCal.h"
33#include "EstTofCaliSvc/EstETofCal.h"
34#include "EstTofCaliSvc/EstEtfCal.h"
35#include "EstTofCaliSvc/EstTofInfoCal.h"
45 : base_class( name, svcloc ) {
46 declareProperty(
"Run", m_run = 1 );
50 m_hasbeeninitialized =
false;
53 MsgStream log(
msgSvc(), name() );
54 log << MSG::INFO << name() <<
": Start of run initialisation" << endmsg;
56 StatusCode sc = Service::initialize();
57 if ( sc.isFailure() )
return sc;
60 sc = service(
"IncidentSvc", incsvc );
62 if ( sc.isSuccess() ) { incsvc->addListener(
this,
"NewRun", priority ); }
66 log << MSG::INFO <<
"setProperties()" << endmsg;
67 scc = service(
"CalibDataSvc", m_pCalibDataSvc,
true );
68 if ( !scc.isSuccess() )
70 log << MSG::ERROR <<
"Could not get IDataProviderSvc interface of CalibXmlCnvSvc"
75 { log << MSG::DEBUG <<
"Retrieved IDataProviderSvc interface of CalibXmlCnvSvc" << endmsg; }
83 MsgStream log(
msgSvc(), name() );
84 log << MSG::INFO << name() <<
": End of Run" << endmsg;
85 return StatusCode::SUCCESS;
89 for (
auto it : fBTofCal )
95 for (
auto it : fETofCal )
101 if ( fEtfCal.size() != 0 )
103 for (
auto it : fEtfCal )
110 for (
auto it : fBTofCommonCal )
114 fBTofCommonCal.clear();
116 for (
auto it : fTofInfoCal )
124StatusCode EstTofCaliSvc::FillfromDatabase() {
126 MsgStream log(
msgSvc(), name() );
127 std::string fullPath =
"/Calib/EstTofCal";
128 log << MSG::INFO <<
" Tof calib fullPath = " << fullPath << endmsg;
129 SmartDataPtr<CalibData::TofCalibData>
test( m_pCalibDataSvc, fullPath );
132 log << MSG::FATAL <<
"EstTofCaliSvc could not find TofCalibData in TCDS!!" << endmsg;
134 return StatusCode::FAILURE;
139 for (
auto it : fBTofCal )
145 for (
auto it : fETofCal )
151 if ( fEtfCal.size() != 0 )
153 for (
auto it : fEtfCal )
160 for (
auto it : fBTofCommonCal )
164 fBTofCommonCal.clear();
166 for (
auto it : fTofInfoCal )
172 unsigned int ibSize =
test->getBTofSize();
173 unsigned int ibcomSize =
test->getBTofComSize();
174 unsigned int ieSize =
test->getETofSize();
175 unsigned int ietfSize =
test->getEtfSize();
176 ietfSize = ietfSize / 12;
177 unsigned int iinfoSize =
test->getTofInfoSize();
179 for (
int ib = 0; ib < ibSize; ib++ )
181 EstBTofCal* btof =
new EstBTofCal;
184 btof->
setP1( j,
test->getBTofPleft( ib, j ) );
185 btof->
setP2( j,
test->getBTofPright( ib, j ) );
187 fBTofCal.push_back( btof );
190 for (
int ie = 0; ie < ieSize; ie++ )
192 EstETofCal* etof =
new EstETofCal;
194 fETofCal.push_back( etof );
197 for (
int ietf = 0; ietf < ietfSize; ietf++ )
199 for (
int jetf = 0; jetf < 12; jetf++ )
201 EstEtfCal* etf =
new EstEtfCal;
204 etf->
setP( k,
test->getEtfPcombine( ietf, jetf, k ) );
205 etf->
setP1( k,
test->getEtfPleft( ietf, jetf, k ) );
206 etf->
setP2( k,
test->getEtfPright( ietf, jetf, k ) );
208 fEtfCal.push_back( etf );
212 for (
int ibcom = 0; ibcom < ibcomSize; ibcom++ )
214 EstBTofCommonCal* bcomtof =
new EstBTofCommonCal;
216 { bcomtof->
setOffset( i,
test->getBTofOffset( ibcom, i ) ); }
217 fBTofCommonCal.push_back( bcomtof );
220 for (
int iinfo = 0; iinfo < iinfoSize; iinfo++ )
222 EstTofInfoCal* tofinfo =
new EstTofInfoCal;
227 fTofInfoCal.push_back( tofinfo );
230 return StatusCode::SUCCESS;
235 MsgStream log(
msgSvc(), name() );
240 if ( fTofInfoCal[0]->getRunFrom() == -1 )
242 if ( fTofInfoCal.size() == 1 )
245 <<
"EstTofCaliSvc::chooseConstants() -- Run From is equal to -1! The ONLY TOF "
246 "calibration constants are used!"
248 return StatusCode::SUCCESS;
253 <<
"EstTofCaliSvc::chooseConstants() -- Run From is equal to -1! The NUMBER of "
254 "calibration constants are NOT "
257 return StatusCode::FAILURE;
261 for (
int i = 0; i < fTofInfoCal.size(); i++ )
263 auto element = fTofInfoCal[i];
264 if ( element->getRunTo() != -1 && element->getRunTo() < element->getRunFrom() )
266 log << MSG::ERROR <<
"EstTofCaliSvc::chooseConstants() -- The " << i
267 <<
"th calibration constatns is ABNORMAL! Run From is LARGER than RUN To!" << endmsg;
268 return StatusCode::FAILURE;
271 if ( element->getRunFrom() == element->getRunTo() && element->getEventFrom() != -1 &&
272 element->getEventTo() != -1 && element->getEventFrom() > element->getEventTo() )
274 log << MSG::ERROR <<
"EstTofCaliSvc::chooseConstants() -- The " << i
275 <<
"th calibration constatns is ABNORMAL! Event From is LARGER than Event To!"
277 return StatusCode::FAILURE;
281 unsigned int inumber = 0;
282 for ( ; inumber < fTofInfoCal.size(); inumber++ )
284 auto element = fTofInfoCal[inumber];
285 int runFrom = element->getRunFrom();
286 int runTo = element->getRunTo();
287 int eventFrom = element->getEventFrom();
288 int eventTo = element->getEventTo();
289 if ( ( run == runFrom ) && ( ( eventFrom == -1 ) || ( event >= eventFrom ) ) )
291 if ( ( run < runTo ) ||
292 ( ( run == runTo ) && ( ( eventTo == -1 ) || ( event <= eventTo ) ) ) )
300 if ( ( run < runTo ) ||
301 ( ( run == runTo ) && ( ( eventTo == -1 ) || ( event <= eventTo ) ) ) )
309 if ( filled ) { m_sequence = inumber; }
312 log << MSG::ERROR <<
"EstTofCaliSvc::chooseConstants() -- The event with run number "
313 << run <<
" and event number " <<
event
314 <<
" is NOT suitable for this group of calibration constants" << endmsg;
315 return StatusCode::FAILURE;
318 return StatusCode::SUCCESS;
322 MsgStream log(
msgSvc(), name() );
325 for (
int i = 0; i < static_cast<int>(
EstNBarPar ); i++ )
326 {
p1[i] = fBTofCal[176 * m_sequence + id]->getP1( i ); }
328 log << MSG::DEBUG <<
"BTCorr1 id =" <<
id <<
" 1=" <<
p1[0] <<
" 2=" <<
p1[1]
329 <<
" 3=" <<
p1[2] <<
" 4=" <<
p1[3] <<
" 5=" <<
p1[4] <<
" 6=" <<
p1[5] <<
" 7=" <<
p1[6]
330 <<
" 8=" <<
p1[7] <<
" 9=" <<
p1[8] << endmsg;
332 double tcorr1 =
p1[0] +
p1[1] / TMath::Sqrt( ADC ) +
p1[2] * z / TMath::Sqrt( ADC ) +
333 p1[3] / ADC +
p1[4] * z +
p1[5] * z * z +
p1[6] * z * z * z;
339 MsgStream log(
msgSvc(), name() );
342 for (
int i = 0; i < static_cast<int>(
EstNBarPar ); i++ )
343 {
p2[i] = fBTofCal[176 * m_sequence + id]->getP2( i ); }
345 log << MSG::DEBUG <<
"BTCorr2 id =" <<
id <<
" 1=" <<
p2[0] <<
" 2=" <<
p2[1]
346 <<
" 3=" <<
p2[2] <<
" 4=" <<
p2[3] <<
" 5=" <<
p2[4] <<
" 6=" <<
p2[5] <<
" 7=" <<
p2[6]
347 <<
" 8=" <<
p2[7] <<
" 9=" <<
p2[8] << endmsg;
349 double tcorr2 =
p2[0] +
p2[1] / TMath::Sqrt( ADC ) +
p2[2] * z / TMath::Sqrt( ADC ) +
350 p2[3] / ADC +
p2[4] * z +
p2[5] * z * z +
p2[6] * z * z * z;
356 double toffset = fBTofCommonCal[m_sequence]->getOffset( 0 );
361 MsgStream log(
msgSvc(), name() );
363 double tcorr1 =
BTCorr1( ADC, z,
id );
365 double tcorr3 = fBTofCommonCal[m_sequence]->getOffset( 0 );
367 log << MSG::DEBUG <<
"BTime1 id =" <<
id <<
" tcorr=" << tcorr1
368 <<
" total offset=" << tcorr3 << endmsg;
370 double time = TDC - tcorr1 - tcorr3;
374 log << MSG::WARNING <<
"TofCaliSvc::BTime1() -- A minus time is given : " <<
time
375 <<
" [Input] ADC = " << ADC <<
" TDC = " << TDC <<
" z = " << z <<
" ID = " <<
id
382 MsgStream log(
msgSvc(), name() );
384 double tcorr1 =
BTCorr2( ADC, z,
id );
386 double tcorr3 = fBTofCommonCal[m_sequence]->getOffset( 0 );
388 log << MSG::DEBUG <<
"BTime2 id =" <<
id <<
" tcorr=" << tcorr1
389 <<
" total offset=" << tcorr3 << endmsg;
391 double time = TDC - tcorr1 - tcorr3;
395 log << MSG::WARNING <<
"TofCaliSvc::BTime2() -- A minus time is given : " <<
time
396 <<
" [Input] ADC = " << ADC <<
" TDC = " << TDC <<
" z = " << z <<
" ID = " <<
id
403 MsgStream log(
msgSvc(), name() );
406 for (
int i = 0; i < static_cast<int>(
EstNEndPar ); i++ )
407 { p[i] = fETofCal[96 * m_sequence + id]->getP( i ); }
409 log << MSG::DEBUG <<
"ETime id =" <<
id <<
" 1=" << p[0] <<
" 2=" << p[1] <<
" 3=" << p[2]
410 <<
" 4=" << p[3] <<
" 5=" << p[4] <<
" 6=" << p[5] <<
" 7=" << p[6] << endmsg;
412 double time = TDC - ( p[0] + p[1] / TMath::Sqrt( ADC ) + p[2] / ADC + p[3] * ADC +
413 p[4] * rHit + p[5] * rHit * rHit + p[6] * rHit * rHit * rHit );
417 log << MSG::WARNING <<
"TofCaliSvc::ETime() -- A minus time is given : " <<
time
418 <<
" [Input] ADC = " << ADC <<
" TDC = " << TDC <<
" r = " << rHit <<
" ID = " <<
id
426 unsigned id,
unsigned int strip ) {
427 MsgStream log(
msgSvc(), name() );
429 double q = ( ADC1 + ADC2 ) / 2.0;
430 double t = ( TDC1 + TDC2 ) / 2.0;
433 for (
int i = 0; i < static_cast<int>(
EstNEtfPar ); i++ )
434 { p[i] = fEtfCal[72 * 12 * m_sequence + 12 *
id + strip]->getP( i ); }
436 double tcorr = p[0] + p[1] / TMath::Sqrt(
q ) + p[2] /
q + p[3] *
q + p[4] *
q *
q +
437 p[5] *
q *
q *
q + p[6] *
q *
q *
q *
q;
438 double time =
t - tcorr;
440 log << MSG::DEBUG <<
"EtfTime module =" <<
id <<
" strip=" << strip <<
" 1=" << p[0]
441 <<
" 2=" << p[1] <<
" 3=" << p[2] <<
" 4=" << p[3] <<
" 5=" << p[4] <<
" 6=" << p[5]
442 <<
" 7=" << p[6] <<
" 8=" << p[7] <<
" 9=" << p[8] <<
" tcorr=" << tcorr
443 <<
" time=" <<
time << endmsg;
446 log << MSG::WARNING <<
"TofCaliSvc::EtfTime() -- A minus time is given : " <<
time
447 <<
" [Input] ADC1 = " << ADC1 <<
" ADC2 = " << ADC2 <<
" TDC1 = " << TDC1
448 <<
" TDC2 = " << TDC2 <<
" ID = " <<
id <<
" Strip = " << strip << endmsg;
455 unsigned int strip ) {
456 MsgStream log(
msgSvc(), name() );
459 for (
int i = 0; i < static_cast<int>(
EstNEtfPar ); i++ )
460 {
p1[i] = fEtfCal[72 * 12 * m_sequence + 12 *
id + strip]->getP1( i ); }
462 double tcorr1 =
p1[0] +
p1[1] / TMath::Sqrt( ADC ) +
p1[2] * ADC +
p1[3] * ADC * ADC +
463 p1[4] * ADC * ADC * ADC +
p1[5] * ADC * ADC * ADC * ADC +
464 p1[6] * z / TMath::Sqrt( ADC ) +
p1[7] / ADC +
p1[8] * z / ADC +
465 p1[9] * z * ADC +
p1[10] * z +
p1[11] * z * z +
p1[12] * z * z * z;
466 double time1 = TDC - tcorr1;
468 log << MSG::DEBUG <<
"EtfTime1 module =" <<
id <<
" strip=" << strip <<
" 1=" <<
p1[0]
469 <<
" 2=" <<
p1[1] <<
" 3=" <<
p1[2] <<
" 4=" <<
p1[3] <<
" 5=" <<
p1[4] <<
" 6=" <<
p1[5]
470 <<
" 7=" <<
p1[6] <<
" 8=" <<
p1[7] <<
" 9=" <<
p1[8] <<
" tcorr=" << tcorr1
471 <<
" time1=" << time1 << endmsg;
474 log << MSG::WARNING <<
"TofCaliSvc::EtfTime1() -- A minus time is given : " <<
time
475 <<
" [Input] ADC = " << ADC <<
" TDC = " << TDC <<
" z = " << z <<
" ID = " <<
id
476 <<
" Strip = " << strip << endmsg;
483 unsigned int strip ) {
484 MsgStream log(
msgSvc(), name() );
487 for (
int i = 0; i < static_cast<int>(
EstNEtfPar ); i++ )
488 {
p2[i] = fEtfCal[72 * 12 * m_sequence + 12 *
id + strip]->getP2( i ); }
490 double tcorr2 =
p2[0] +
p2[1] / TMath::Sqrt( ADC ) +
p2[2] * ADC +
p2[3] * ADC * ADC +
491 p2[4] * ADC * ADC * ADC +
p2[5] * ADC * ADC * ADC * ADC +
492 p2[6] * z / TMath::Sqrt( ADC ) +
p2[7] / ADC +
p2[8] * z / ADC +
493 p2[9] * z * ADC +
p2[10] * z +
p2[11] * z * z +
p2[12] * z * z * z;
494 double time2 = TDC - tcorr2;
496 log << MSG::DEBUG <<
"EtfTime2 module =" <<
id <<
" strip=" << strip <<
" 1=" <<
p2[0]
497 <<
" 2=" <<
p2[1] <<
" 3=" <<
p2[2] <<
" 4=" <<
p2[3] <<
" 5=" <<
p2[4] <<
" 6=" <<
p2[5]
498 <<
" 7=" <<
p2[6] <<
" 8=" <<
p2[7] <<
" 9=" <<
p2[8] <<
" tcorr=" << tcorr2
499 <<
" time2=" << time2 << endmsg;
502 log << MSG::WARNING <<
"TofCaliSvc::EtfTime2() -- A minus time is given : " <<
time
503 <<
" [Input] ADC = " << ADC <<
" TDC = " << TDC <<
" z = " << z <<
" ID = " <<
id
504 <<
" Strip = " << strip << endmsg;
511 unsigned int strip ) {
512 MsgStream log(
msgSvc(), name() );
517 if ( TDC1 > 0 && TDC2 > 0 )
519 t = ( TDC1 + TDC2 ) / 2.0;
520 tcorr = fEtfCal[72 * 12 * m_sequence + 12 *
id + strip]->getP( 0 );
522 log << MSG::DEBUG <<
"EtfTime module =" <<
id <<
" strip=" << strip <<
" t1=" << TDC1
523 <<
" t2=" << TDC2 <<
" combine const=" << tcorr <<
" time=" <<
time << endmsg;
525 else if ( TDC1 > 0 && TDC2 < 0 )
528 tcorr = fEtfCal[72 * 12 * m_sequence + 12 *
id + strip]->getP1( 0 );
530 log << MSG::DEBUG <<
"EtfTime module =" <<
id <<
" strip=" << strip <<
" t1=" << TDC1
531 <<
" left const=" << tcorr <<
" time=" <<
time << endmsg;
533 else if ( TDC1 < 0 && TDC2 > 0 )
536 tcorr = fEtfCal[72 * 12 * m_sequence + 12 *
id + strip]->getP2( 0 );
538 log << MSG::DEBUG <<
"EtfTime module =" <<
id <<
" strip=" << strip <<
" t2=" << TDC2
539 <<
" right const=" << tcorr <<
" time=" <<
time << endmsg;
544 log << MSG::WARNING <<
"TofCaliSvc::EtfTime() -- A minus time is given : " <<
time
545 <<
" [Input] TDC1 = " << TDC1 <<
" TDC2 = " << TDC2 <<
" ID = " <<
id
546 <<
" Strip = " << strip << endmsg;
553 return fBTofCal[176 * m_sequence + id];
559 return fEtfCal[72 * 12 * m_sequence + id];
567 std::cout <<
"Now We can get the TOF Calibtration Service" << std::endl;
568 std::cout <<
"Barrel TOF Counter Number = " << fBTofCal.size() << std::endl;
569 std::cout <<
"Endcap TOF Counter Number = " << fETofCal.size() << std::endl;
571 cout <<
"The O Barrel TOF PMT1 p1[0] is"
573 cout <<
"The 0 Barrel TOF PMT1 p1[1] is"
578 MsgStream log(
msgSvc(), name() );
579 log << MSG::DEBUG <<
"handle: " << inc.type() << endmsg;
581 if ( inc.type() ==
"NewRun" )
583 log << MSG::DEBUG <<
"New Run" << endmsg;
584 StatusCode sc = FillfromDatabase();
585 if ( sc.isSuccess() ) { m_hasbeeninitialized =
true; }
DECLARE_COMPONENT(BesBdkRc)
const unsigned int EstNBarPar
const unsigned int EstNBarOffset
const unsigned int EstNEndPar
const unsigned int EstNEtfPar
****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
void setP2(int idx, double p2)
double getP1(int idx) const
void setP1(int idx, double p1)
void setOffset(int idx, double offset)
void setP(int i, double p)
void setP(int idx, double p)
void setP1(int idx, double p1)
void setP2(int idx, double p2)
EstBTofCommonCal * BTofCommon() const
virtual StatusCode initialize()
void handle(const Incident &)
virtual StatusCode finalize()
StatusCode chooseConstants(int run, int number)
const double BTCorr1(double ADC, double zHit, unsigned id)
const double EtfTime1(double ADC, double TDC, double zHit, unsigned id, unsigned int strip)
EstTofInfoCal * TofInfo() const
const double BTime2(double ADC, double TDC, double zHit, unsigned id)
EstEtfCal * EtfTof(unsigned int id) const
const double ETime(double ADC, double TDC, double rHit, unsigned id)
EstBTofCal * BTof(unsigned id) const
EstTofCaliSvc(const std::string &name, ISvcLocator *svcloc)
const double BTime1(double ADC, double TDC, double zHit, unsigned id)
const double BTCorr2(double ADC, double zHit, unsigned id)
const double EtfTime(double ADC1, double ADC2, double TDC1, double TDC2, unsigned id, unsigned int strip)
EstETofCal * ETof(unsigned id) const
const double EtfTime2(double ADC, double TDC, double zHit, unsigned id, unsigned int strip)
void setEventTo(int evtTo)
void setEventFrom(int evtFrom)
void setRunFrom(int runFrom)