CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
TofCaliSvc.cxx
Go to the documentation of this file.
1//********************************************************
2//
3// BESIII Tof Reconstruction
4// Class: TofCaliSvc
5// Sun Shengsen <[email protected]>
6//
7// Description:
8// This service is used to get Tof Calibrarion constants
9// from DataBase and do the Tof data reconstruction.
10//
11//*********************************************************
13#include "TofCaliSvc/BTofCal.h"
14#include "TofCaliSvc/BTofCommonCal.h"
15#include "TofCaliSvc/ETofCal.h"
16#include "TofCaliSvc/TofInfoCal.h"
17#include "GaudiKernel/Kernel.h"
18#include "GaudiKernel/IInterface.h"
19#include "GaudiKernel/StatusCode.h"
20//#include "GaudiKernel/ISvcFactory.h"
21#include "GaudiKernel/SvcFactory.h"
22#include "GaudiKernel/MsgStream.h"
23#include "TMath.h"
24#include <math.h>
25#include <iostream>
26#include <fstream>
27#include "GaudiKernel/IIncidentSvc.h"
28#include "GaudiKernel/Incident.h"
29#include "GaudiKernel/IIncidentListener.h"
30#include "GaudiKernel/IDataProviderSvc.h"
31#include "GaudiKernel/Service.h"
32#include "GaudiKernel/MsgStream.h"
33#include "GaudiKernel/SmartDataPtr.h"
37#include "GaudiKernel/DataSvc.h"
38
39using namespace std;
40
41// static double radius_Inner = 81.35;
42// static double radius_Outer = 87.05;
43
44TofCaliSvc::TofCaliSvc( const std::string& name, ISvcLocator* svcloc ) : Service(name, svcloc) {
45 declareProperty("Run",m_run=1);
46}
47
48StatusCode TofCaliSvc::queryInterface (const InterfaceID& riid, void** ppvInterface ) {
49 if ( IID_ITofCaliSvc.versionMatch(riid) ) {
50 *ppvInterface = static_cast<ITofCaliSvc*> (this);
51 } else {
52 return Service::queryInterface(riid, ppvInterface) ;
53 }
54 return StatusCode::SUCCESS;
55}
56
57StatusCode TofCaliSvc::initialize ( ) {
58 m_hasbeeninitialized=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
89StatusCode TofCaliSvc::finalize ( ) {
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 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) { delete (*it3); }
101 fBTofCommonCal.clear();
102 for(vector<TofInfoCal*>::iterator it4 = fTofInfoCal.begin(); it4 != fTofInfoCal.end(); it4++) { delete (*it4); }
103 fTofInfoCal.clear();
104 return;
105}
106StatusCode TofCaliSvc::FillfromDatabase(){
107
108 MsgStream log(msgSvc(), name());
109 std::string fullPath = "/Calib/TofCal";
110 log << MSG::INFO<<" Tof calib fullPath = "<<fullPath<< endreq;
111 SmartDataPtr<CalibData::TofCalibData> test(m_pCalibDataSvc, fullPath);
112 if(!test){
113 log << MSG::FATAL << "TofCaliSvc could not find TofCalibData in TCDS!!" << endreq;
114 return StatusCode::FAILURE;
115 }
116
117 for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) { delete (*it1); }
118 fBTofCal.clear();
119 for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) { delete (*it2); }
120 fETofCal.clear();
121 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) { delete (*it3); }
122 fBTofCommonCal.clear();
123 for(vector<TofInfoCal*>::iterator it4 = fTofInfoCal.begin(); it4 != fTofInfoCal.end(); it4++) { delete (*it4); }
124 fTofInfoCal.clear();
125
126 for(int ib=0;ib<176;ib++){
127 BTofCal* btof = new BTofCal;
128 for( int j=0; j<static_cast<int>(nBarAtten); j++ ) {
129 btof->setAtten(j,test->getBTofAtten(ib,j));
130 }
131 for( int j=0; j<static_cast<int>(nBarSpeed); j++ ) {
132 btof->setVeff(j,test->getBTofSpeed(ib,j));
133 }
134 for( int j=0; j<static_cast<int>(nBarPar); j++){
135 btof->setP1(j,test->getBTofPleft(ib,j));
136 btof->setP2(j,test->getBTofPright(ib,j));
137 }
138 for( int j=0; j<static_cast<int>(nBarParOff); j++){
139 btof->setPOff1_bunch0(j,test->getBTofPoffleft_bunch0(ib,j));
140 btof->setPOff2_bunch0(j,test->getBTofPoffright_bunch0(ib,j));
141 btof->setPOff1_bunch1(j,test->getBTofPoffleft_bunch1(ib,j));
142 btof->setPOff2_bunch1(j,test->getBTofPoffright_bunch1(ib,j));
143 btof->setPOff1_bunch2(j,test->getBTofPoffleft_bunch2(ib,j));
144 btof->setPOff2_bunch2(j,test->getBTofPoffright_bunch2(ib,j));
145 btof->setPOff1_bunch3(j,test->getBTofPoffleft_bunch3(ib,j));
146 btof->setPOff2_bunch3(j,test->getBTofPoffright_bunch3(ib,j));
147 }
148 for( int j=0; j<static_cast<int>(nBarSigma); j++){
149 btof->setFPLeft(j,test->getBTofFleft(ib,j));
150 btof->setFPRight(j,test->getBTofFright(ib,j));
151 }
152 for( int j=0; j<static_cast<int>(nBarSigCnt); j++){
153 btof->setFPCounter(j,test->getBTofFcounter(ib,j));
154 }
155
156 fBTofCal.push_back(btof);
157 }
158
159 for(int ie=0;ie<96;ie++){
160 ETofCal* etof= new ETofCal;
161 for( int j=0; j<static_cast<int>(nEndAtten); j++ ) {
162 etof->setAtten(j,test->getETofAtten(ie,j));
163 }
164 for( int j=0; j<static_cast<int>(nEndSpeed); j++ ) {
165 etof->setVeff(j,test->getETofSpeed(ie,j));
166 }
167 for( int j=0; j<static_cast<int>(nEndPar); j++ ) {
168 etof->setP(j,test->getETofP(ie,j));
169 }
170 for( int j=0; j<static_cast<int>(nEndSigma); j++ ) {
171 etof->setFPCounter(j,test->getETofFP(ie,j));
172 }
173 fETofCal.push_back(etof);
174 }
175
176 BTofCommonCal* bcomtof = new BTofCommonCal;
177 for(int i=0; i<static_cast<int>(nBarOffset); i++) {
178 bcomtof->setOffset( i, test->getBTofOffset(i) );
179 }
180 for(int i=0; i<static_cast<int>(nBarSigCor); i++) {
181 bcomtof->setSigmaCorr( i, test->getBTofSigmaCorr(i) );
182 }
183 fBTofCommonCal.push_back(bcomtof);
184
185 TofInfoCal* tofinfo = new TofInfoCal;
186 tofinfo->setRunBegin( test->getRunBegin() );
187 tofinfo->setRunEnd( test->getRunEnd() );
188 tofinfo->setVersion( test->getVersion() );
189 tofinfo->setQCorr( test->getQCorr() );
190 tofinfo->setQElec( test->getQElec() );
191 tofinfo->setMisLable( test->getMisLable() );
192 for( unsigned int i=0; i<5; i++ ) {
193 tofinfo->setBrEast( i, test->getBrEast(i) );
194 tofinfo->setBrWest( i, test->getBrWest(i) );
195 tofinfo->setEndcap( i, test->getEndcap(i) );
196 }
197 fTofInfoCal.push_back(tofinfo);
198
199 return StatusCode::SUCCESS;
200
201}
202
203
204const double TofCaliSvc::BTDelay1(unsigned id) {
205 double tdelay = 0.0;
206 if( id < 176 ) {
207 tdelay = fBTofCal[id]->getP1(0);
208 }
209 else {
210 MsgStream log(msgSvc(), name());
211 log<<MSG::ERROR<<"TofCaliSvc::BTDelay1() -- Wrong TOFID is provided! ID = "<<id<<endreq;
212 }
213 return tdelay;
214}
215
216
217const double TofCaliSvc::BTDelay2(unsigned id) {
218 double tdelay = 0.0;
219 if( id < 176 ) {
220 tdelay = fBTofCal[id]->getP2(0);
221 }
222 else {
223 MsgStream log(msgSvc(), name());
224 log<<MSG::ERROR<<"TofCaliSvc::BTDelay2() -- Wrong TOFID is provided! ID = "<<id<<endreq;
225 }
226 return tdelay;
227}
228
229
230const double TofCaliSvc::ETDelay(unsigned id) {
231 double tdelay = 0.0;
232 if( id < 96 ) {
233 tdelay = fETofCal[id]->getP(0);
234 }
235 else {
236 MsgStream log(msgSvc(), name());
237 log<<MSG::ERROR<<"TofCaliSvc::ETDelay() -- Wrong TOFID is provided! ID = "<<id<<endreq;
238 }
239 return tdelay;
240}
241
242
243const double TofCaliSvc::BTCorr1(double ADC,double z,unsigned id){
244 MsgStream log(msgSvc(), name());
245
246 double p1[nBarPar];
247 for( int i=0; i<static_cast<int>(nBarPar); i++ ) {
248 p1[i]=fBTofCal[id]->getP1(i);
249 }
250
251 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;
252
253 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;
254
255 return tcorr1;
256}
257
258
259const double TofCaliSvc::BTCorr2(double ADC,double z,unsigned id){
260 MsgStream log(msgSvc(), name());
261
262 double p2[nBarPar];
263 for( int i=0; i<static_cast<int>(nBarPar); i++ ) {
264 p2[i]=fBTofCal[id]->getP2(i);
265 }
266
267 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;
268
269 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;
270
271 return tcorr2;
272}
273
274
275const double TofCaliSvc::BTCorrOffset1(double z,unsigned id,double t0){
276 MsgStream log(msgSvc(), name());
277
278 int numBunch = fTofInfoCal[0]->getRunEnd();
279 int whichBunch = (static_cast<int>(t0/(12000./499.8/(numBunch*1.0))+0.1))%numBunch;
280
281 double poff1[nBarParOff];
282 if( whichBunch==0 ) {
283 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
284 poff1[i]=fBTofCal[id]->getPOff1_bunch0(i);
285 }
286 }
287 else if( whichBunch==1 ) {
288 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
289 poff1[i]=fBTofCal[id]->getPOff1_bunch1(i);
290 }
291 }
292 else if( whichBunch==2 ) {
293 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
294 poff1[i]=fBTofCal[id]->getPOff1_bunch2(i);
295 }
296 }
297 else if( whichBunch==3 ) {
298 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
299 poff1[i]=fBTofCal[id]->getPOff1_bunch3(i);
300 }
301 }
302
303 double tCorrOffset1 = 0.0;
304 if( z>=0.0 ) {
305 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;
306 }
307 else {
308 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;
309 }
310
311 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;
312
313 return tCorrOffset1;
314}
315
316
317const double TofCaliSvc::BTCorrOffset2(double z,unsigned id,double t0){
318 MsgStream log(msgSvc(), name());
319
320 int numBunch = fTofInfoCal[0]->getRunEnd();
321 int whichBunch = (static_cast<int>(t0/(12000./499.8/(numBunch*1.0))+0.1))%numBunch;
322
323 double poff2[nBarParOff];
324 if( whichBunch==0 ) {
325 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
326 poff2[i]=fBTofCal[id]->getPOff2_bunch0(i);
327 }
328 }
329 else if( whichBunch==1 ) {
330 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
331 poff2[i]=fBTofCal[id]->getPOff2_bunch1(i);
332 }
333 }
334 else if( whichBunch==2 ) {
335 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
336 poff2[i]=fBTofCal[id]->getPOff2_bunch2(i);
337 }
338 }
339 else if( whichBunch==3 ) {
340 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
341 poff2[i]=fBTofCal[id]->getPOff2_bunch3(i);
342 }
343 }
344
345 double tCorrOffset2 = 0.0;
346 if( z>=0.0 ) {
347 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;
348 }
349 else {
350 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;
351 }
352
353 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;
354
355 return tCorrOffset2;
356}
357
358
359const double TofCaliSvc::TOffset() {
360 double toffset = fBTofCommonCal[0]->getOffset(0);
361 return toffset;
362}
363
364
365const double TofCaliSvc::BTime1(double ADC,double TDC,double z,unsigned id,double t0){
366 MsgStream log(msgSvc(), name());
367
368 double tcorr1 = BTCorr1( ADC, z, id );
369 double tcorr2 = BTCorrOffset1( z, id, t0);
370 double tcorr3 = fBTofCommonCal[0]->getOffset(0);
371
372 log << MSG::DEBUG << "BTime1 id =" << id << " tcorr=" << tcorr1 << " toffset=" << tcorr2 << " total offset=" << tcorr3 << endreq;
373
374 double time = TDC - tcorr1 - tcorr2 - tcorr3;
375
376 if(time<0.) {
377 log<<MSG::WARNING<<"TofCaliSvc::BTime1() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" z = "<<z<<" ID = "<<id<<endreq;
378 }
379 return time;
380}
381
382
383const double TofCaliSvc::BTime2(double ADC,double TDC,double z,unsigned id, double t0){
384 MsgStream log(msgSvc(), name());
385
386 double tcorr1 = BTCorr2( ADC, z, id );
387 double tcorr2 = BTCorrOffset2( z, id ,t0);
388 double tcorr3 = fBTofCommonCal[0]->getOffset(0);
389
390 log << MSG::DEBUG << "BTime2 id =" << id << " tcorr=" << tcorr1 << " toffset=" << tcorr2 << " total offset=" << tcorr3 << endreq;
391
392 double time = TDC - tcorr1 - tcorr2 - tcorr3;
393
394 if(time<0.) {
395 log<<MSG::WARNING<<"TofCaliSvc::BTime2() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" z = "<<z<<" ID = "<<id<<endreq;
396 }
397 return time;
398}
399
400
401/*
402const double TofCaliSvc::BTime(double tleft,double tright,double z,unsigned id){
403 for(int i=0;i<4;i++)
404 m_w[i]=fBTofCal[id]->getW(i);
405 double f1=m_w[0]+m_w[1]*z+m_w[2]*z*z;
406 double f2=1-f1;
407 double wt=f1*tleft+f2*tright+m_w[3];
408 if(wt<0.) {
409 MsgStream log(msgSvc(), name());
410 log<<MSG::WARNING<<"TofCaliSvc::BTime() -- A minus time is given : "<<wt <<" [Input] TDC1 = "<<tleft<<" TDC2 = "<<tright<<" z = "<<z<<" ID = "<<id<<endreq;
411 }
412
413 return wt;
414}
415*/
416
417
418const double TofCaliSvc::BTimeCounter(double tleft,double tright,double z,unsigned id){
419
420 double sigmaCorr = fBTofCommonCal[0]->getSigmaCorr(0);
421 double sigmaCorr2 = sigmaCorr*sigmaCorr;
422
423 double sigmaLeft = BSigma1( z, id );
424 double sigmaLeft2 = sigmaLeft*sigmaLeft;
425 double sigmaRight = BSigma2( z, id );
426 double sigmaRight2 = sigmaRight*sigmaRight;
427
428 double fraction = ( sigmaRight2 - sigmaCorr2 )/( sigmaLeft2 + sigmaRight2 - 2.0*sigmaCorr2);
429
430 double wt=fraction*tleft + (1.0-fraction)*tright;
431 if(wt<0.) {
432 MsgStream log(msgSvc(), name());
433 log<<MSG::WARNING<<"TofCaliSvc::BTimeCounter() -- A minus time is given : "<<wt <<" [Input] z = "<<z<<" ID = "<<id<<endreq;
434 }
435
436 return wt;
437}
438
439const double TofCaliSvc::BTimeCluster(double tlayer1,double tlayer2,double z1,double z2,unsigned id1, unsigned id2){
440
441 double sigmaCorr = fBTofCommonCal[0]->getSigmaCorr(0);
442 double sigmaCorr2 = sigmaCorr*sigmaCorr;
443
444 double sigmaInner = BSigmaCounter( z1, id1 );
445 double sigmaInner2 = sigmaInner*sigmaInner;
446 double sigmaOuter = BSigmaCounter( z2, id2 );
447 double sigmaOuter2 = sigmaOuter*sigmaOuter;
448
449 double fraction = ( sigmaOuter2 - sigmaCorr2 )/( sigmaInner2 + sigmaOuter2 - 2.0*sigmaCorr2);
450
451 double wt=fraction*tlayer1 + (1.0-fraction)*tlayer2;
452 if(wt<0.) {
453 MsgStream log(msgSvc(), name());
454 log<<MSG::WARNING<<"TofCaliSvc::BTimeCluster() -- A minus time is given : "<<wt <<" [Input] z1 = "<<z1<<" [Input] z2 = "<<z2<<" ID1 = "<< id1 << " ID2=" << id2 << endreq;
455 }
456 return wt;
457}
458
459
460const double TofCaliSvc::BSigma1(double z, unsigned id) {
461 MsgStream log(msgSvc(), name());
462
463 double fpleft[nBarSigma];
464 for( int i=0; i<static_cast<int>(nBarSigma); i++ ) {
465 fpleft[i]=fBTofCal[id]->getFPLeft(i);
466 }
467
468 log << MSG::DEBUG << "BSigma1 id =" << id << " 1=" << fpleft[0] << " 2=" << fpleft[1] << " 3=" << fpleft[2] << " 4=" << fpleft[3] << " 5=" << fpleft[4] << endreq;
469
470 double sigmaLeft = fpleft[0] + fpleft[1]*z + fpleft[2]*z*z + fpleft[3]*z*z*z + fpleft[4]*z*z*z*z;
471
472 return sigmaLeft;
473}
474
475
476const double TofCaliSvc::BSigma2(double z, unsigned id) {
477 MsgStream log(msgSvc(), name());
478
479 double fpright[nBarSigma];
480 for( int i=0; i<static_cast<int>(nBarSigma); i++ ) {
481 fpright[i]=fBTofCal[id]->getFPRight(i);
482 }
483
484 log << MSG::DEBUG << "BSigma2 id =" << id << " 1=" << fpright[0] << " 2=" << fpright[1] << " 3=" << fpright[2] << " 4=" << fpright[3] << " 5=" << fpright[4] << endreq;
485
486 double sigmaRight = fpright[0] + fpright[1]*z + fpright[2]*z*z + fpright[3]*z*z*z + fpright[4]*z*z*z*z;
487
488 return sigmaRight;
489}
490
491
492const double TofCaliSvc::BSigmaCounter(double z, unsigned id) {
493 MsgStream log(msgSvc(), name());
494
495 double fplayer[nBarSigCnt];
496 for( int i=0; i<static_cast<int>(nBarSigCnt); i++ ) {
497 fplayer[i]=fBTofCal[id]->getFPCounter(i);
498 }
499
500 log << MSG::DEBUG << "BSigmaCounter id =" << id << " 1=" << fplayer[0] << " 2=" << fplayer[1] << " 3=" << fplayer[2] << " 4=" << fplayer[3] << " 5=" << fplayer[4] << endreq;
501
502 double sigma = fplayer[0] + fplayer[1]*z + fplayer[2]*z*z + fplayer[3]*z*z*z + fplayer[4]*z*z*z*z;
503
504 return sigma;
505}
506
507
508const double TofCaliSvc::BSigmaCluster(double z1, double z2, unsigned id1, unsigned id2) {
509 double sigmaInner = BSigmaCounter(z1, id1);
510 double sigmaInner2 = sigmaInner*sigmaInner;
511 double sigmaOuter = BSigmaCounter(z2, id2);
512 double sigmaOuter2 = sigmaOuter*sigmaOuter;
513 double sigmaCorr = fBTofCommonCal[0]->getSigmaCorr(0);
514 double sigmaCorr2 = sigmaCorr*sigmaCorr;
515 double sigma = (sigmaInner2*sigmaOuter2-sigmaCorr2*sigmaCorr2)/(sigmaInner2+sigmaOuter2-2.0*sigmaCorr2);
516 sigma = sqrt(sigma);
517 return sigma;
518}
519
520
521const double TofCaliSvc::ETime(double ADC,double TDC,double rHit,unsigned id){
522 MsgStream log(msgSvc(), name());
523
524 double p[nEndPar];
525 for( int i=0; i<static_cast<int>(nEndPar); i++ ) {
526 p[i]=fETofCal[id]->getP(i);
527 }
528
529 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;
530
531 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);
532
533 if(time<0.) {
534 MsgStream log(msgSvc(), name());
535 log<<MSG::WARNING<<"TofCaliSvc::ETime() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" r = "<< rHit <<" ID = "<<id<<endreq;
536 }
537
538 return time;
539}
540
541
542const double TofCaliSvc::ESigma(double r, unsigned id) {
543 MsgStream log(msgSvc(), name());
544
545 double fp[nEndSigma];
546 for( int i=0; i<static_cast<int>(nEndSigma); i++) {
547 fp[i]=fETofCal[id]->getFPCounter(i);
548 }
549
550 log << MSG::DEBUG << "ESigma id =" << id << " 1=" << fp[0] << " 2=" << fp[1] << " 3=" << fp[2] << endreq;
551
552 double sigma = fp[0] + fp[1]*r + fp[2]*r*r;
553
554 return sigma;
555}
556
557
558const double TofCaliSvc::BPulseHeight1( double ADC, double zHit, double sint, unsigned int id ) {
559 double length = 230.0;
560 double A = 1.0;
561 double Latten = fBTofCal[id]->getAtten(0);
562 double q0 = ADC*sint*TMath::Exp((0.5*length-zHit)/Latten)/A;
563 return q0;
564}
565
566
567const double TofCaliSvc::BPulseHeight2( double ADC, double zHit, double sint, unsigned int id ) {
568 double length = 230.0;
569 double A = 1.0;
570 double Latten = fBTofCal[id]->getAtten(0);
571 double q0 = ADC*sint*TMath::Exp((0.5*length+zHit)/Latten)/A;
572 return q0;
573}
574
575
576const double TofCaliSvc::BPulseHeight( double ADC1, double ADC2, double zHit, double sint, unsigned int id ) {
577 double length = 230.0;
578 double Latten = fBTofCal[id]->getAtten(0);
579 double gainRatio = fBTofCal[id]->getAtten(1);
580 double A2 = fBTofCal[id]->getAtten(2);
581 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)) );
582 return q;
583}
584
585
586const double TofCaliSvc::BPh( double ADC1, double ADC2, double zHit, unsigned int id ) {
587 double length = 230.0;
588 double Latten = fBTofCal[id]->getAtten(0);
589 double gainRatio = fBTofCal[id]->getAtten(1);
590 double q = ( ADC1*TMath::Exp((0.5*length-zHit)/Latten)+ADC2*TMath::Exp((0.5*length+zHit)/Latten) )/(1.0+TMath::Exp(gainRatio));
591 return q;
592}
593
594
595const double TofCaliSvc::EPulseHeight( double ADC, double rHit, double cost, unsigned int id ) {
596 double length = 44.5;
597 double a0 = fETofCal[id]->getAtten(0);
598 double a1 = fETofCal[id]->getAtten(1);
599 double a2 = fETofCal[id]->getAtten(2);
600 double a3 = fETofCal[id]->getAtten(3);
601
602 double q0 = ADC*fabs(cost)*TMath::Exp(-(a1*(rHit-length)+a2*(rHit-length)*(rHit-length)))/a3;
603
604 return q0;
605}
606
607
608const double TofCaliSvc::EPh( double ADC, double rHit, unsigned int id ) {
609 double length = 44.5;
610 double a0 = fETofCal[id]->getAtten(0);
611 double a1 = fETofCal[id]->getAtten(1);
612 double a2 = fETofCal[id]->getAtten(2);
613 double q0 = ADC*TMath::Exp(-(a0+a1*(rHit-length)+a2*(rHit-length)*(rHit-length)));
614 return q0;
615}
616
617
618const double TofCaliSvc::getQ0(unsigned id){
619 return fBTofCal[id]->getAtten(3);
620}
621
622
623const double TofCaliSvc::BVeff(unsigned id){
624 if(id<176){
625 return fBTofCal[id]->getVeff(0);
626 }else{
627 std::cout<<"bad id="<<id<<std::endl;
628 return 0.;}
629}
630
631
632const double TofCaliSvc::BAtten(unsigned id){
633 if( id > 175 ) return -1;
634 return fBTofCal[id]->getAtten(0);
635}
636
637const double TofCaliSvc::BGainForward(unsigned id){
638 if( id > 175 ) return -1;
639 double gainRatio = fBTofCal[id]->getAtten(1);
640 double A2 = fBTofCal[id]->getAtten(2);
641 double A1 = A2*TMath::Exp(gainRatio);
642 return A1;
643}
644
645const double TofCaliSvc::BGainBackward(unsigned id){
646 if( id > 175 ) return -1;
647 return fBTofCal[id]->getAtten(2);
648}
649
650const double TofCaliSvc::EVeff(unsigned id){
651 if( id > 175 ) return -1;
652 return fETofCal[id]->getVeff(0);
653}
654
655const double TofCaliSvc::ZTDC(double tleft, double tright, unsigned id) {
656 double ztdc = -1000.0;
657 if( id > 175 ) return ztdc;
658 double veff = fBTofCal[id]->getVeff(0);
659 double delay = fBTofCal[id]->getVeff(1);
660 ztdc = 0.5*veff*(tright-tleft-delay);
661 return ztdc;
662}
663
664const double TofCaliSvc::ZTDC1(double tright, unsigned id, double z) {
665 double tleft = -1000.0;
666 if( id > 175 ) return tleft;
667 if( tright < -900.0 ) return tleft;
668 double veff = fBTofCal[id]->getVeff(0);
669 double delay = fBTofCal[id]->getVeff(1);
670 tleft = tright-delay-2.0*z/veff;
671 return tleft;
672}
673
674const double TofCaliSvc::ZTDC2(double tleft, unsigned id, double z) {
675 double tright = -1000.0;
676 if( id > 175 ) return tright;
677 if( tleft < -900.0 ) return tright;
678 double veff = fBTofCal[id]->getVeff(0);
679 double delay = fBTofCal[id]->getVeff(1);
680 tright = tleft+delay+2.0*z/veff;
681 return tright;
682}
683
684const double TofCaliSvc::ZADC(double qleft, double qright, unsigned id) {
685 double zadc = -1000.0;
686 if( id > 175 ) return zadc;
687 if( qright < 1.0e-6 ) return zadc;
688 double ldecay = fBTofCal[id]->getAtten(0);
689 double a1overa2 = fBTofCal[id]->getAtten(1);
690 double q1overq2 = log(qleft/qright);
691 zadc = 0.5*ldecay*( q1overq2 - a1overa2 );
692 return zadc;
693}
694
695const double TofCaliSvc::ZADC1(double qright, unsigned id, double z) {
696 double qleft = -1000.0;
697 if( id > 175 ) return qleft;
698 if( qright < 1.0e-6 ) return qleft;
699 double ldecay = fBTofCal[id]->getAtten(0);
700 double a1overa2 = fBTofCal[id]->getAtten(1);
701 double q1overq2 = 2.0*z/ldecay + a1overa2;
702 qleft = qright*exp(q1overq2);
703 return qleft;
704}
705
706const double TofCaliSvc::ZADC2(double qleft, unsigned id, double z) {
707 double qright = -1000.0;
708 if( id > 175 ) return qright;
709 if( qleft < 1.0e-6 ) return qright;
710 double ldecay = fBTofCal[id]->getAtten(0);
711 double a1overa2 = fBTofCal[id]->getAtten(1);
712 double q1overq2 = 2.0*z/ldecay + a1overa2;
713 qright = qleft*exp(-q1overq2);
714 return qright;
715}
716
717const double TofCaliSvc::EAtten(unsigned id){
718 if( id > 95 ) return -1;
719 return fETofCal[id]->getAtten(0);
720}
721
722const double TofCaliSvc::EGain(unsigned id){
723 if( id > 95 ) return -1;
724 return fETofCal[id]->getAtten(1);
725}
726
728 return fTofInfoCal[0]->getRunBegin();
729}
730
732 return fTofInfoCal[0]->getRunEnd();
733}
734
736 return fTofInfoCal[0]->getVersion();
737}
738
739const int TofCaliSvc::QCorr() {
740 return fTofInfoCal[0]->getQCorr();
741}
742
743const int TofCaliSvc::QElec() {
744 return fTofInfoCal[0]->getQElec();
745}
746
748 return fTofInfoCal[0]->getMisLable();
749}
750
751const int TofCaliSvc::BrEast(unsigned int im) {
752 return fTofInfoCal[0]->getBrEast(im);
753}
754
755const int TofCaliSvc::BrWest(unsigned int im) {
756 return fTofInfoCal[0]->getBrWest(im);
757}
758
759const int TofCaliSvc::Endcap(unsigned int im) {
760 return fTofInfoCal[0]->getEndcap(im);
761}
762
763BTofCal* TofCaliSvc::BTof(unsigned id) const{
764 return fBTofCal[id];
765}
766
767ETofCal* TofCaliSvc::ETof(unsigned id) const{
768 return fETofCal[id];
769}
770
772 return fBTofCommonCal[0];
773}
774
776 return fTofInfoCal[0];
777}
778
780 std::cout<<"Now We can get the TOF Calibtration Service"<<std::endl;
781 std::cout<<"Barrel TOF Counter Number = "<<fBTofCal.size()<<std::endl;
782 std::cout<<"Endcap TOF Counter Number = "<<fETofCal.size()<<std::endl;
783
784 cout<<"The O Barrel TOF PMT1 p1[0] is"<<" "<<BTof(0)->getP1(0)<<endl;
785 cout<<"The 0 Barrel TOF PMT1 p1[1] is"<<" "<<BTof(0)->getP1(1)<<endl;
786 cout<<"The 0 Barrel TOF veff is"<<" "<<BTof(0)->getVeff(0)<<endl;
787 // cout<<"The 22rd Endcap TOF PMT veff is"<<" "<<ETof(22)->getVeff()<<endl;
788}
789
790void TofCaliSvc::handle(const Incident& inc){
791 MsgStream log( messageService(), name() );
792 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
793
794 if ( inc.type() == "NewRun" ){
795 log << MSG::DEBUG << "New Run" << endreq;
796 // if(!m_hasbeeninitialized){
797 StatusCode sc= FillfromDatabase();
798 if(sc.isSuccess()){
799 m_hasbeeninitialized=true;
800 }
801 // }
802 }
803}
std::string test
double length
Double_t time
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
Definition KKsem.h:33
const unsigned int nBarOffset
const unsigned int nBarParOff
const unsigned int nEndPar
const unsigned int nBarPar
const unsigned int nBarSigma
const unsigned int nEndSigma
const unsigned int nBarSigCor
const unsigned int nEndSpeed
const unsigned int nBarSpeed
const unsigned int nEndAtten
const unsigned int nBarAtten
const unsigned int nBarSigCnt
IMessageSvc * msgSvc()
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 setPOff1_bunch3(int idx, double poff1_bunch3)
void setPOff2_bunch2(int idx, double poff2_bunch2)
void setPOff2_bunch3(int idx, double poff2_bunch3)
void setPOff2_bunch0(int idx, double poff2_bunch0)
void setPOff1_bunch1(int idx, double poff1_bunch1)
const double BTimeCounter(double tleft, double tright, double z, unsigned int id)
const double ZADC(double qleft, double qright, unsigned int id)
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 int RunBegin()
const double ZTDC2(double tleft, unsigned int id, double z)
const double BPulseHeight2(double ADC, double zHit, double sint, unsigned int id)
const int MisLable()
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 QCorr()
const int BrEast(unsigned int No)
const double BGainForward(unsigned int id)
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
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 BSigma2(double zHit, unsigned int id)
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 BSigmaCluster(double zHit1, double zHit2, unsigned int id1, unsigned int id2)
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 int Version()
const double ZADC2(double qleft, unsigned int id, double z)
const double getQ0(unsigned int id)
const int BrWest(unsigned int No)
const int RunEnd()
const double ZTDC(double tleft, double tright, unsigned int id)
const double ETDelay(unsigned int id)
const double EVeff(unsigned int id)
const double TOffset()
const double EAtten(unsigned int id)
const int Endcap(unsigned int No)
const double BTCorr2(double ADC, double zHit, unsigned int id)
const int QElec()
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)
TofCaliSvc(const std::string &name, ISvcLocator *svcloc)
ETofCal * ETof(unsigned int id) const
const double BSigmaCounter(double zHit, unsigned int id)