BOSS 7.0.1
BESIII Offline Software System
Loading...
Searching...
No Matches
EstTofCaliSvc.cxx
Go to the documentation of this file.
1//********************************************************
2//
3// Class: EstTofCaliSvc
4// Sun Shengsen <[email protected]>
5//
6// Description:
7// This service is used to get Tof Calibrarion constants
8// from DataBase and do the Tof data reconstruction.
9//
10//*********************************************************
11#include "EstTofCaliSvc/EstTofCaliSvc.h"
12#include "EstTofCaliSvc/BTofCal.h"
13#include "EstTofCaliSvc/BTofCommonCal.h"
14#include "EstTofCaliSvc/ETofCal.h"
15#include "EstTofCaliSvc/EtfCal.h"
16#include "GaudiKernel/Kernel.h"
17#include "GaudiKernel/IInterface.h"
18#include "GaudiKernel/StatusCode.h"
19#include "GaudiKernel/SvcFactory.h"
20#include "GaudiKernel/MsgStream.h"
21#include "TMath.h"
22#include <math.h>
23#include <iostream>
24#include <fstream>
25#include "GaudiKernel/IIncidentSvc.h"
26#include "GaudiKernel/Incident.h"
27#include "GaudiKernel/IIncidentListener.h"
28#include "GaudiKernel/IDataProviderSvc.h"
29#include "GaudiKernel/Service.h"
30#include "GaudiKernel/MsgStream.h"
31#include "GaudiKernel/SmartDataPtr.h"
32#include "CalibData/Tof/TofCalibData.h"
33#include "CalibData/Tof/bTofCalibBase.h"
34#include "CalibData/CalibModel.h"
35#include "GaudiKernel/DataSvc.h"
36
37using namespace std;
38
39// static double radius_Inner = 81.35;
40// static double radius_Outer = 87.05;
41
42EstTofCaliSvc::EstTofCaliSvc( const std::string& name, ISvcLocator* svcloc ) : Service(name, svcloc) {
43 declareProperty("Run",m_run=1);
44}
45
46StatusCode EstTofCaliSvc::queryInterface (const InterfaceID& riid, void** ppvInterface ){
47
48 if ( IID_IEstTofCaliSvc.versionMatch(riid) ) {
49 *ppvInterface = static_cast<IEstTofCaliSvc*> (this);
50 } else {
51 return Service::queryInterface(riid, ppvInterface) ;
52 }
53 return StatusCode::SUCCESS;
54}
55
57 m_hasbeeninitialized=false;
58 m_st=false;
59
60 MsgStream log(msgSvc(), name());
61 log << MSG::INFO << name() << ": Start of run initialisation" << endreq;
62
63 StatusCode sc = Service::initialize();
64 if ( sc.isFailure() ) return sc;
65
66 IIncidentSvc* incsvc;
67 sc = service("IncidentSvc", incsvc);
68 int priority = 100;
69 if( sc.isSuccess() ){
70 incsvc -> addListener(this, "NewRun", priority);
71 }
72
73 StatusCode scc;
74
75 log<<MSG::INFO << "setProperties()" << endreq;
76 scc = service("CalibDataSvc", m_pCalibDataSvc, true);
77 if ( !scc.isSuccess() ) {
78 log<<MSG::ERROR<<"Could not get IDataProviderSvc interface of CalibXmlCnvSvc"<<endreq;
79 return scc;
80 } else {
81 log << MSG::DEBUG<< "Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"<<endreq;
82 }
83 // Get properties from the JobOptionsSvc
84 scc = setProperties();
85
86 return sc;
87}
88
90 MsgStream log(msgSvc(), name());
91 log << MSG::INFO << name() << ": End of Run" << endreq;
92 return StatusCode::SUCCESS;
93}
94
96 for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) { delete (*it1); }
97 fBTofCal.clear();
98 for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) { delete (*it2); }
99 fETofCal.clear();
100 if( fEtfCal.size()!=0 ) {
101 for(vector<EtfCal*>::iterator it5 = fEtfCal.begin(); it5 != fEtfCal.end(); it5++) { delete (*it5); }
102 fEtfCal.clear();
103 }
104 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) { delete (*it3); }
105 fBTofCommonCal.clear();
106 return;
107}
108StatusCode EstTofCaliSvc::FillfromDatabase(){
109
110 MsgStream log(msgSvc(), name());
111 std::string fullPath = "/Calib/EstTofCal";
112 log << MSG::INFO<<" Tof calib fullPath = "<<fullPath<< endreq;
113 SmartDataPtr<CalibData::TofCalibData> test(m_pCalibDataSvc, fullPath);
114 if(!test){
115 log << MSG::FATAL << "EstTofCaliSvc could not find TofCalibData in TCDS!!" << endreq;
116 m_st=false;
117 return StatusCode::FAILURE;
118 }
119
120 m_st=true;
121
122 for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) { delete (*it1); }
123 fBTofCal.clear();
124 for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) { delete (*it2); }
125 fETofCal.clear();
126 if( fEtfCal.size()!=0 ) {
127 for(vector<EtfCal*>::iterator it5 = fEtfCal.begin(); it5 != fEtfCal.end(); it5++) { delete (*it5); }
128 fEtfCal.clear();
129 }
130 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) { delete (*it3); }
131 fBTofCommonCal.clear();
132
133 for(int ib =0;ib<176;ib++){
134 BTofCal* btof = new BTofCal;
135 for(int i=0;i<static_cast<int>(nBarPar);i++){
136 btof->setP1(i,test->getBTofPleft(ib,i));
137 btof->setP2(i,test->getBTofPright(ib,i));
138 }
139 fBTofCal.push_back(btof);
140 }
141
142 for(int ie=0;ie<96;ie++){
143 ETofCal* etof= new ETofCal;
144 for(int i=0;i<static_cast<int>(nEndPar);i++){
145 etof->setP(i,test->getETofP(ie,i));
146 }
147 fETofCal.push_back(etof);
148 }
149
150 for(int ietf=0;ietf<72;ietf++) {
151 for(int jetf=0;jetf<12;jetf++) {
152 EtfCal* etf= new EtfCal;
153 for( int k=0; k<static_cast<int>(nEtfPar); k++ ) {
154 etf->setP( k,test->getEtfPcombine(ietf,jetf,k));
155 etf->setP1(k,test->getEtfPleft(ietf,jetf,k));
156 etf->setP2(k,test->getEtfPright(ietf,jetf,k));
157 }
158 fEtfCal.push_back(etf);
159 }
160 }
161
162 BTofCommonCal* bcomtof = new BTofCommonCal;
163 for(int i=0; i<static_cast<int>(nBarOffset); i++) {
164 bcomtof->setOffset( i, test->getBTofOffset(i) );
165 }
166 fBTofCommonCal.push_back(bcomtof);
167
168 return StatusCode::SUCCESS;
169
170}
171
172
173const double EstTofCaliSvc::BTCorr1(double ADC,double z,unsigned id){
174 MsgStream log(msgSvc(), name());
175
176 double p1[nBarPar];
177 for( int i=0; i<static_cast<int>(nBarPar); i++ ) {
178 p1[i]=fBTofCal[id]->getP1(i);
179 }
180
181 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;
182
183 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;
184
185 return tcorr1;
186}
187
188
189const double EstTofCaliSvc::BTCorr2(double ADC,double z,unsigned id){
190 MsgStream log(msgSvc(), name());
191
192 double p2[nBarPar];
193 for( int i=0; i<static_cast<int>(nBarPar); i++ ) {
194 p2[i]=fBTofCal[id]->getP2(i);
195 }
196
197 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;
198
199 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;
200
201 return tcorr2;
202}
203
204
206 double toffset = fBTofCommonCal[0]->getOffset(0);
207 return toffset;
208}
209
210
211const double EstTofCaliSvc::BTime1(double ADC,double TDC,double z,unsigned id){
212 MsgStream log(msgSvc(), name());
213
214 double tcorr1 = BTCorr1( ADC, z, id );
215 double tcorr3 = fBTofCommonCal[0]->getOffset(0);
216
217 log << MSG::DEBUG << "BTime1 id =" << id << " tcorr=" << tcorr1 << " total offset=" << tcorr3 << endreq;
218
219 double time = TDC - tcorr1 - tcorr3;
220
221 if(time<0.) {
222 log<<MSG::WARNING<<"TofCaliSvc::BTime1() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" z = "<<z<<" ID = "<<id<<endreq;
223 }
224 return time;
225}
226
227
228const double EstTofCaliSvc::BTime2(double ADC,double TDC,double z,unsigned id){
229 MsgStream log(msgSvc(), name());
230
231 double tcorr1 = BTCorr2( ADC, z, id );
232 double tcorr3 = fBTofCommonCal[0]->getOffset(0);
233
234 log << MSG::DEBUG << "BTime2 id =" << id << " tcorr=" << tcorr1 << " total offset=" << tcorr3 << endreq;
235
236 double time = TDC - tcorr1 - tcorr3;
237
238 if(time<0.) {
239 log<<MSG::WARNING<<"TofCaliSvc::BTime2() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" z = "<<z<<" ID = "<<id<<endreq;
240 }
241 return time;
242}
243
244
245const double EstTofCaliSvc::ETime(double ADC,double TDC,double rHit,unsigned id){
246 MsgStream log(msgSvc(), name());
247
248 double p[nEndPar];
249 for( int i=0; i<static_cast<int>(nEndPar); i++ ) {
250 p[i]=fETofCal[id]->getP(i);
251 }
252
253 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;
254
255 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);
256
257 if(time<0.) {
258 log<<MSG::WARNING<<"TofCaliSvc::ETime() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" r = "<< rHit <<" ID = "<<id<<endreq;
259 }
260
261 return time;
262}
263
264
265const double EstTofCaliSvc::EtfTime(double ADC1,double ADC2,double TDC1,double TDC2,unsigned id,unsigned int strip){
266 MsgStream log(msgSvc(), name());
267
268 double q = (ADC1+ADC2)/2.0;
269 double t = (TDC1+TDC2)/2.0;
270
271 double p[nEtfPar];
272 for( int i=0; i<static_cast<int>(nEtfPar); i++ ) {
273 p[i]=fEtfCal[12*id+strip]->getP(i);
274 }
275
276 double tcorr = p[0]
277 + p[1]/TMath::Sqrt(q)
278 + p[2]/q
279 + p[3]*q
280 + p[4]*q*q
281 + p[5]*q*q*q
282 + p[6]*q*q*q*q;
283 double time = t - tcorr;
284
285 log << MSG::DEBUG << "EtfTime module =" << id << " strip=" << strip << " 1=" << p[0] << " 2=" << p[1] << " 3=" << p[2] << " 4=" << p[3] << " 5=" << p[4] << " 6=" << p[5] << " 7=" << p[6] << " 8=" << p[7] << " 9=" << p[8] << " tcorr=" << tcorr << " time=" << time << endreq;
286 if( time<0.) {
287 log<<MSG::WARNING<<"TofCaliSvc::EtfTime() -- A minus time is given : "<< time <<" [Input] ADC1 = "<<ADC1<<" ADC2 = "<<ADC2<<" TDC1 = "<<TDC1<<" TDC2 = "<<TDC2<<" ID = "<<id<<" Strip = "<<strip<<endreq;
288 }
289
290 return time;
291}
292
293
294const double EstTofCaliSvc::EtfTime1(double ADC,double TDC,double z,unsigned id,unsigned int strip){
295 MsgStream log(msgSvc(), name());
296
297 double p1[nEtfPar];
298 for( int i=0; i<static_cast<int>(nEtfPar); i++ ) {
299 p1[i]=fEtfCal[12*id+strip]->getP1(i);
300 }
301
302 double tcorr1 = p1[0]
303 + p1[1]/TMath::Sqrt(ADC)
304 + p1[2]*ADC
305 + p1[3]*ADC*ADC
306 + p1[4]*ADC*ADC*ADC
307 + p1[5]*ADC*ADC*ADC*ADC
308 + p1[6]*z/TMath::Sqrt(ADC)
309 + p1[7]/ADC
310 + p1[8]*z/ADC
311 + p1[9]*z*ADC
312 + p1[10]*z
313 + p1[11]*z*z
314 + p1[12]*z*z*z;
315 double time1 = TDC - tcorr1;
316
317 log << MSG::DEBUG << "EtfTime1 module =" << id << " strip=" << strip << " 1=" << p1[0] << " 2=" << p1[1] << " 3=" << p1[2] << " 4=" << p1[3] << " 5=" << p1[4] << " 6=" << p1[5] << " 7=" << p1[6] << " 8=" << p1[7] << " 9=" << p1[8] << " tcorr=" << tcorr1 << " time1=" << time1 << endreq;
318 if( time1<0.) {
319 log<<MSG::WARNING<<"TofCaliSvc::EtfTime1() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" z = "<<z<<" ID = "<<id<<" Strip = "<<strip<<endreq;
320 }
321
322 return time1;
323}
324
325
326const double EstTofCaliSvc::EtfTime2(double ADC,double TDC,double z,unsigned id,unsigned int strip){
327 MsgStream log(msgSvc(), name());
328
329 double p2[nEtfPar];
330 for( int i=0; i<static_cast<int>(nEtfPar); i++ ) {
331 p2[i]=fEtfCal[12*id+strip]->getP2(i);
332 }
333
334 double tcorr2 = p2[0]
335 + p2[1]/TMath::Sqrt(ADC)
336 + p2[2]*ADC
337 + p2[3]*ADC*ADC
338 + p2[4]*ADC*ADC*ADC
339 + p2[5]*ADC*ADC*ADC*ADC
340 + p2[6]*z/TMath::Sqrt(ADC)
341 + p2[7]/ADC
342 + p2[8]*z/ADC
343 + p2[9]*z*ADC
344 + p2[10]*z
345 + p2[11]*z*z
346 + p2[12]*z*z*z;
347 double time2 = TDC - tcorr2;
348
349 log << MSG::DEBUG << "EtfTime2 module =" << id << " strip=" << strip << " 1=" << p2[0] << " 2=" << p2[1] << " 3=" << p2[2] << " 4=" << p2[3] << " 5=" << p2[4] << " 6=" << p2[5] << " 7=" << p2[6] << " 8=" << p2[7] << " 9=" << p2[8] << " tcorr=" << tcorr2 << " time2=" << time2 << endreq;
350 if( time2<0.) {
351 log<<MSG::WARNING<<"TofCaliSvc::EtfTime2() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" z = "<<z<<" ID = "<<id<<" Strip = "<<strip<<endreq;
352 }
353
354 return time2;
355}
356
357
358const double EstTofCaliSvc::EtfTime(double TDC1,double TDC2,unsigned id,unsigned int strip){
359 MsgStream log(msgSvc(), name());
360
361 double time = -99;
362 double t, tcorr;
363
364 if( TDC1>0 && TDC2>0 ) {
365 t = (TDC1+TDC2)/2.0;
366 tcorr = fEtfCal[12*id+strip]->getP(0);
367 time = t - tcorr;
368 log << MSG::DEBUG << "EtfTime module =" << id << " strip=" << strip << " t1=" << TDC1 << " t2=" << TDC2 << " combine const=" << tcorr << " time=" << time << endreq;
369 }
370 else if( TDC1>0 && TDC2<0 ) {
371 t = TDC1;
372 tcorr = fEtfCal[12*id+strip]->getP1(0);
373 time = t - tcorr;
374 log << MSG::DEBUG << "EtfTime module =" << id << " strip=" << strip << " t1=" << TDC1 << " left const=" << tcorr << " time=" << time << endreq;
375 }
376 else if( TDC1<0 && TDC2>0 ) {
377 t = TDC2;
378 tcorr = fEtfCal[12*id+strip]->getP2(0);
379 time = t - tcorr;
380 log << MSG::DEBUG << "EtfTime module =" << id << " strip=" << strip << " t2=" << TDC2 << " right const=" << tcorr << " time=" << time << endreq;
381 }
382
383 if( time<0.) {
384 log<<MSG::WARNING<<"TofCaliSvc::EtfTime() -- A minus time is given : "<< time <<" [Input] TDC1 = "<<TDC1<<" TDC2 = "<<TDC2<<" ID = "<<id<<" Strip = "<<strip<<endreq;
385 }
386
387 return time;
388}
389
390
391BTofCal* EstTofCaliSvc::BTof(unsigned id) const{
392 return fBTofCal[id];
393}
394
395ETofCal* EstTofCaliSvc::ETof(unsigned id) const{
396 return fETofCal[id];
397}
398
399EtfCal* EstTofCaliSvc::EtfTof(unsigned id) const{
400 return fEtfCal[id];
401}
402
404 return fBTofCommonCal[0];
405}
406
408 std::cout<<"Now We can get the TOF Calibtration Service"<<std::endl;
409 std::cout<<"Barrel TOF Counter Number = "<<fBTofCal.size()<<std::endl;
410 std::cout<<"Endcap TOF Counter Number = "<<fETofCal.size()<<std::endl;
411
412 cout<<"The O Barrel TOF PMT1 p1[0] is"<<" "<<BTof(0)->getP1(0)<<endl;
413 cout<<"The 0 Barrel TOF PMT1 p1[1] is"<<" "<<BTof(0)->getP1(1)<<endl;
414}
415
416void EstTofCaliSvc::handle(const Incident& inc){
417 MsgStream log( messageService(), name() );
418 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
419
420 if ( inc.type() == "NewRun" ){
421 log << MSG::DEBUG << "New Run" << endreq;
422 // if(!m_hasbeeninitialized){
423 StatusCode sc= FillfromDatabase();
424 if(sc.isSuccess()){
425 m_hasbeeninitialized=true;
426 }
427 // }
428 }
429}
std::string test
Definition: CalibModel.cxx:43
Double_t time
****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
Definition: KKsem.h:33
const unsigned int nBarOffset
const unsigned int nEndPar
const unsigned int nEtfPar
const unsigned int nBarPar
virtual StatusCode initialize()
ETofCal * ETof(unsigned id) const
void handle(const Incident &)
virtual StatusCode finalize()
BTofCal * BTof(unsigned id) const
const double ETime(double ADC, double TDC, double rHit, unsigned int id)
const double TOffset()
const double EtfTime1(double ADC, double TDC, double zHit, unsigned int id, unsigned int strip)
const double EtfTime2(double ADC, double TDC, double zHit, unsigned int id, unsigned int strip)
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
const double BTime2(double ADC, double TDC, double zHit, unsigned id)
EstTofCaliSvc(const std::string &name, ISvcLocator *svcloc)
EtfCal * EtfTof(unsigned int id) const
const double BTime1(double ADC, double TDC, double zHit, unsigned id)
const double BTCorr1(double ADC, double zHit, unsigned int id)
const double BTCorr2(double ADC, double zHit, unsigned int id)
const double EtfTime(double ADC1, double ADC2, double TDC1, double TDC2, unsigned int id, unsigned int strip)
BTofCommonCal * BTofCommon() const
int t()
Definition: t.c:1