BOSS 6.6.4.p03
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//*********************************************************
15// #include "EstTofCaliSvc/TofInfoCal.h"
16#include "GaudiKernel/Kernel.h"
17#include "GaudiKernel/IInterface.h"
18#include "GaudiKernel/StatusCode.h"
19//#include "GaudiKernel/ISvcFactory.h"
20#include "GaudiKernel/SvcFactory.h"
21#include "GaudiKernel/MsgStream.h"
22#include "TMath.h"
23#include <math.h>
24#include <iostream>
25#include <fstream>
26#include "GaudiKernel/IIncidentSvc.h"
27#include "GaudiKernel/Incident.h"
28#include "GaudiKernel/IIncidentListener.h"
29#include "GaudiKernel/IDataProviderSvc.h"
30#include "GaudiKernel/Service.h"
31#include "GaudiKernel/MsgStream.h"
32#include "GaudiKernel/SmartDataPtr.h"
36#include "GaudiKernel/DataSvc.h"
37
38using namespace std;
39
40// static double radius_Inner = 81.35;
41// static double radius_Outer = 87.05;
42
43EstTofCaliSvc::EstTofCaliSvc( const std::string& name, ISvcLocator* svcloc ) : Service(name, svcloc) {
44 declareProperty("Run",m_run=1);
45}
46
47StatusCode EstTofCaliSvc::queryInterface (const InterfaceID& riid, void** ppvInterface ){
48
49 if ( IID_IEstTofCaliSvc.versionMatch(riid) ) {
50 *ppvInterface = static_cast<IEstTofCaliSvc*> (this);
51 } else {
52 return Service::queryInterface(riid, ppvInterface) ;
53 }
54 return StatusCode::SUCCESS;
55}
56
58 m_hasbeeninitialized=false;
59 m_st=false;
60
61 MsgStream log(msgSvc(), name());
62 log << MSG::INFO << name() << ": Start of run initialisation" << endreq;
63
64 StatusCode sc = Service::initialize();
65 if ( sc.isFailure() ) return sc;
66
67 IIncidentSvc* incsvc;
68 sc = service("IncidentSvc", incsvc);
69 int priority = 100;
70 if( sc.isSuccess() ){
71 incsvc -> addListener(this, "NewRun", priority);
72 }
73
74 StatusCode scc;
75
76 log<<MSG::INFO << "setProperties()" << endreq;
77 scc = service("CalibDataSvc", m_pCalibDataSvc, true);
78 if ( !scc.isSuccess() ) {
79 log<<MSG::ERROR<<"Could not get IDataProviderSvc interface of CalibXmlCnvSvc"<<endreq;
80 return scc;
81 } else {
82 log << MSG::DEBUG<< "Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"<<endreq;
83 }
84 // Get properties from the JobOptionsSvc
85 scc = setProperties();
86
87 return sc;
88}
89
91 MsgStream log(msgSvc(), name());
92 log << MSG::INFO << name() << ": End of Run" << endreq;
93 return StatusCode::SUCCESS;
94}
95
97 for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) { delete (*it1); }
98 fBTofCal.clear();
99 for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) { delete (*it2); }
100 fETofCal.clear();
101 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) { delete (*it3); }
102 fBTofCommonCal.clear();
103 return;
104}
105StatusCode EstTofCaliSvc::FillfromDatabase(){
106
107 MsgStream log(msgSvc(), name());
108 std::string fullPath = "/Calib/EstTofCal";
109 log << MSG::INFO<<" Tof calib fullPath = "<<fullPath<< endreq;
110 SmartDataPtr<CalibData::TofCalibData> test(m_pCalibDataSvc, fullPath);
111 if(!test){
112 log << MSG::FATAL << "EstTofCaliSvc could not find TofCalibData in TCDS!!" << endreq;
113 m_st=false;
114 return StatusCode::FAILURE;
115 }
116
117 m_st=true;
118
119 for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) { delete (*it1); }
120 fBTofCal.clear();
121 for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) { delete (*it2); }
122 fETofCal.clear();
123 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) { delete (*it3); }
124 fBTofCommonCal.clear();
125
126 for(int ib =0;ib<176;ib++){
127 BTofCal* btof = new BTofCal;
128 for(int i=0;i<static_cast<int>(nBarPar);i++){
129 btof->setP1(i,test->getBTofPleft(ib,i));
130 btof->setP2(i,test->getBTofPright(ib,i));
131 }
132 // for( int j=0; j<static_cast<int>(nBarParOff); j++){
133 // btof->setPOff1(j,test->getBTofPoffleft(ib,j));
134 // btof->setPOff2(j,test->getBTofPoffright(ib,j));
135 // }
136 fBTofCal.push_back(btof);
137 }
138
139 for(int ie=0;ie<96;ie++){
140 ETofCal* etof= new ETofCal;
141 for(int i=0;i<static_cast<int>(nEndPar);i++){
142 etof->setP(i,test->getETofP(ie,i));
143 }
144 fETofCal.push_back(etof);
145 }
146
147 BTofCommonCal* bcomtof = new BTofCommonCal;
148 for(int i=0; i<static_cast<int>(nBarOffset); i++) {
149 bcomtof->setOffset( i, test->getBTofOffset(i) );
150 }
151 fBTofCommonCal.push_back(bcomtof);
152
153 return StatusCode::SUCCESS;
154
155}
156
157
158const double EstTofCaliSvc::BTCorr1(double ADC,double z,unsigned id){
159 MsgStream log(msgSvc(), name());
160
161 double p1[nBarPar];
162 for( int i=0; i<static_cast<int>(nBarPar); i++ ) {
163 p1[i]=fBTofCal[id]->getP1(i);
164 }
165
166 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;
167
168 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;
169
170 return tcorr1;
171}
172
173
174const double EstTofCaliSvc::BTCorr2(double ADC,double z,unsigned id){
175 MsgStream log(msgSvc(), name());
176
177 double p2[nBarPar];
178 for( int i=0; i<static_cast<int>(nBarPar); i++ ) {
179 p2[i]=fBTofCal[id]->getP2(i);
180 }
181
182 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;
183
184 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;
185
186 return tcorr2;
187}
188
189/*
190const double EstTofCaliSvc::BTCorrOffset1(double z,unsigned id){
191 MsgStream log(msgSvc(), name());
192
193 double poff1[nBarParOff];
194 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
195 poff1[i]=fBTofCal[id]->getPOff1(i);
196 }
197
198 log << MSG::DEBUG << "BTCorrOff1 id =" << id << " 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;
199
200 double tCorrOffset1 = 0.0;
201 if( z>=0.0 ) {
202 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;
203 }
204 else {
205 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;
206 }
207
208 return tCorrOffset1;
209}
210
211
212const double EstTofCaliSvc::BTCorrOffset2(double z,unsigned id){
213 MsgStream log(msgSvc(), name());
214
215 double poff2[nBarParOff];
216 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
217 poff2[i]=fBTofCal[id]->getPOff2(i);
218 }
219
220 log << MSG::DEBUG << "BTCorrOff2 id =" << id << " 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;
221
222 double tCorrOffset2 = 0.0;
223 if( z>=0.0 ) {
224 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;
225 }
226 else {
227 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;
228 }
229
230 return tCorrOffset2;
231}
232*/
233
235 double toffset = fBTofCommonCal[0]->getOffset(0);
236 return toffset;
237}
238
239
240const double EstTofCaliSvc::BTime1(double ADC,double TDC,double z,unsigned id){
241 MsgStream log(msgSvc(), name());
242
243 double tcorr1 = BTCorr1( ADC, z, id );
244 // double tcorr2 = BTCorrOffset1( z, id );
245 double tcorr3 = fBTofCommonCal[0]->getOffset(0);
246
247 // log << MSG::DEBUG << "BTime1 id =" << id << " tcorr=" << tcorr1 << " toffset=" << tcorr2 << " total offset=" << tcorr3 << endreq;
248 log << MSG::DEBUG << "BTime1 id =" << id << " tcorr=" << tcorr1 << " total offset=" << tcorr3 << endreq;
249
250 // double time = TDC - tcorr1 - tcorr2 - tcorr3;
251 double time = TDC - tcorr1 - tcorr3;
252
253 if(time<0.) {
254 log<<MSG::WARNING<<"TofCaliSvc::BTime1() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" z = "<<z<<" ID = "<<id<<endreq;
255 }
256 return time;
257}
258
259
260const double EstTofCaliSvc::BTime2(double ADC,double TDC,double z,unsigned id){
261 MsgStream log(msgSvc(), name());
262
263 double tcorr1 = BTCorr2( ADC, z, id );
264 // double tcorr2 = BTCorrOffset2( z, id );
265 double tcorr3 = fBTofCommonCal[0]->getOffset(0);
266
267 // log << MSG::DEBUG << "BTime2 id =" << id << " tcorr=" << tcorr1 << " toffset=" << tcorr2 << " total offset=" << tcorr3 << endreq;
268 log << MSG::DEBUG << "BTime2 id =" << id << " tcorr=" << tcorr1 << " total offset=" << tcorr3 << endreq;
269
270 // double time = TDC - tcorr1 - tcorr2 - tcorr3;
271 double time = TDC - tcorr1 - tcorr3;
272
273 if(time<0.) {
274 log<<MSG::WARNING<<"TofCaliSvc::BTime2() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" z = "<<z<<" ID = "<<id<<endreq;
275 }
276 return time;
277}
278
279
280const double EstTofCaliSvc::ETime(double ADC,double TDC,double rHit,unsigned id){
281 MsgStream log(msgSvc(), name());
282
283 double p[nEndPar];
284 for( int i=0; i<static_cast<int>(nEndPar); i++ ) {
285 p[i]=fETofCal[id]->getP(i);
286 }
287
288 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;
289
290 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);
291
292 if(time<0.) {
293 MsgStream log(msgSvc(), name());
294 log<<MSG::WARNING<<"TofCaliSvc::ETime() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" r = "<< rHit <<" ID = "<<id<<endreq;
295 }
296
297 return time;
298}
299
300
301BTofCal* EstTofCaliSvc::BTof(unsigned id) const{
302 return fBTofCal[id];
303}
304
305ETofCal* EstTofCaliSvc::ETof(unsigned id) const{
306 return fETofCal[id];
307}
308
310 return fBTofCommonCal[0];
311}
312
314 std::cout<<"Now We can get the TOF Calibtration Service"<<std::endl;
315 std::cout<<"Barrel TOF Counter Number = "<<fBTofCal.size()<<std::endl;
316 std::cout<<"Endcap TOF Counter Number = "<<fETofCal.size()<<std::endl;
317
318 cout<<"The O Barrel TOF PMT1 p1[0] is"<<" "<<BTof(0)->getP1(0)<<endl;
319 cout<<"The 0 Barrel TOF PMT1 p1[1] is"<<" "<<BTof(0)->getP1(1)<<endl;
320}
321
322void EstTofCaliSvc::handle(const Incident& inc){
323 MsgStream log( messageService(), name() );
324 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
325
326 if ( inc.type() == "NewRun" ){
327 log << MSG::DEBUG << "New Run" << endreq;
328 // if(!m_hasbeeninitialized){
329 StatusCode sc= FillfromDatabase();
330 if(sc.isSuccess()){
331 m_hasbeeninitialized=true;
332 }
333 // }
334 }
335}
std::string test
Definition: CalibModel.cxx:43
Double_t time
const unsigned int nBarOffset
const unsigned int nEndPar
const unsigned int nBarPar
IMessageSvc * msgSvc()
virtual StatusCode initialize()
ETofCal * ETof(unsigned id) const
void handle(const Incident &)
virtual StatusCode finalize()
BTofCal * BTof(unsigned id) const
const double TOffset()
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
const double BTime2(double ADC, double TDC, double zHit, unsigned id)
const double ETime(double ADC, double TDC, double rHit, unsigned id)
EstTofCaliSvc(const std::string &name, ISvcLocator *svcloc)
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)
BTofCommonCal * BTofCommon() const