BOSS 7.1.0
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/EtfCal.h"
18#include "TofCaliSvc/TofInfoCal.h"
19#include "GaudiKernel/Kernel.h"
20#include "GaudiKernel/IInterface.h"
21#include "GaudiKernel/StatusCode.h"
22#include "GaudiKernel/SvcFactory.h"
23#include "GaudiKernel/MsgStream.h"
24#include "TMath.h"
25#include <math.h>
26#include <iostream>
27#include <fstream>
28#include "GaudiKernel/IIncidentSvc.h"
29#include "GaudiKernel/Incident.h"
30#include "GaudiKernel/IIncidentListener.h"
31#include "GaudiKernel/IDataProviderSvc.h"
32#include "GaudiKernel/Service.h"
33#include "GaudiKernel/MsgStream.h"
34#include "GaudiKernel/SmartDataPtr.h"
38#include "GaudiKernel/DataSvc.h"
39
40using namespace std;
41
42// static double radius_Inner = 81.35;
43// static double radius_Outer = 87.05;
44
45DECLARE_COMPONENT(TofCaliSvc)
46
47TofCaliSvc::TofCaliSvc( const std::string& name, ISvcLocator* svcloc ) : base_class(name, svcloc)
48//TofCaliSvc::TofCaliSvc( const std::string& name, ISvcLocator* svcloc ) : Service(name, svcloc) {
49{ declareProperty("Run",m_run=1);
50 m_sequence = 0;
51}
52
53/*StatusCode TofCaliSvc::queryInterface (const InterfaceID& riid, void** ppvInterface ) {
54 if ( IID_ITofCaliSvc.versionMatch(riid) ) {
55 *ppvInterface = static_cast<ITofCaliSvc*> (this);
56 } else {
57 return Service::queryInterface(riid, ppvInterface) ;
58 }
59 return StatusCode::SUCCESS;
60}*/
61
62StatusCode TofCaliSvc::initialize ( ) {
63 m_hasbeeninitialized=false;
64 m_sequence = 0;
65
66 MsgStream log(msgSvc(), name());
67 log << MSG::INFO << name() << ": Start of run initialisation" << endreq;
68
69 StatusCode sc = Service::initialize();
70 if ( sc.isFailure() ) return sc;
71
72 IIncidentSvc* incsvc;
73 sc = service("IncidentSvc", incsvc);
74 int priority = 100;
75 if( sc.isSuccess() ){
76 incsvc -> addListener(this, "NewRun", priority);
77 }
78
79 StatusCode scc;
80
81 log<<MSG::INFO << "setProperties()" << endreq;
82 scc = service("CalibDataSvc", m_pCalibDataSvc, true);
83 if ( !scc.isSuccess() ) {
84 log<<MSG::ERROR<<"Could not get IDataProviderSvc interface of CalibXmlCnvSvc"<<endreq;
85 return scc;
86 } else {
87 log << MSG::DEBUG<< "Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"<<endreq;
88 }
89 // Get properties from the JobOptionsSvc
90 scc = setProperties();
91
92 return sc;
93}
94
95StatusCode TofCaliSvc::finalize ( ) {
96 MsgStream log(msgSvc(), name());
97 log << MSG::INFO << name() << ": End of Run" << endreq;
98 return StatusCode::SUCCESS;
99}
100
102 for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) { delete (*it1); }
103 fBTofCal.clear();
104 for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) { delete (*it2); }
105 fETofCal.clear();
106
107 if( fEtfCal.size()!=0 ) {
108 for(vector<EtfCal*>::iterator it5 = fEtfCal.begin(); it5 != fEtfCal.end(); it5++) { delete (*it5); }
109 fEtfCal.clear();
110 }
111 if( fEtfBunchCal.size()!=0 ) {
112 for(vector<EtfBunchCal*>::iterator it6 = fEtfBunchCal.begin(); it6 != fEtfBunchCal.end(); it6++) { delete (*it6); }
113 fEtfBunchCal.clear();
114 }
115 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) { delete (*it3); }
116 fBTofCommonCal.clear();
117 for(vector<TofInfoCal*>::iterator it4 = fTofInfoCal.begin(); it4 != fTofInfoCal.end(); it4++) { delete (*it4); }
118 fTofInfoCal.clear();
119 return;
120}
121
122StatusCode TofCaliSvc::FillfromDatabase(){
123
124 MsgStream log(msgSvc(), name());
125 std::string fullPath = "/Calib/TofCal";
126 log << MSG::INFO<<" Tof calib fullPath = "<<fullPath<< endreq;
127
128 SmartDataPtr<CalibData::TofCalibData> test(m_pCalibDataSvc, fullPath);
129 if(!test){
130 log << MSG::FATAL << "TofCaliSvc could not find TofCalibData in TCDS!!" << endreq;
131 return StatusCode::FAILURE;
132 }
133
134 for(vector<BTofCal*>::iterator it1 = fBTofCal.begin(); it1 != fBTofCal.end(); it1++) { delete (*it1); }
135 fBTofCal.clear();
136 for(vector<ETofCal*>::iterator it2 = fETofCal.begin(); it2 != fETofCal.end(); it2++) { delete (*it2); }
137 fETofCal.clear();
138 if( fEtfCal.size()!=0 ) {
139 for(vector<EtfCal*>::iterator it5 = fEtfCal.begin(); it5 != fEtfCal.end(); it5++) { delete (*it5); }
140 fEtfCal.clear();
141 }
142 if( fEtfBunchCal.size()!=0 ) {
143 for(vector<EtfBunchCal*>::iterator it6 = fEtfBunchCal.begin(); it6 != fEtfBunchCal.end(); it6++) { delete (*it6); }
144 fEtfBunchCal.clear();
145 }
146 for(vector<BTofCommonCal*>::iterator it3 = fBTofCommonCal.begin(); it3 != fBTofCommonCal.end(); it3++) { delete (*it3); }
147 fBTofCommonCal.clear();
148 for(vector<TofInfoCal*>::iterator it4 = fTofInfoCal.begin(); it4 != fTofInfoCal.end(); it4++) { delete (*it4); }
149 fTofInfoCal.clear();
150
151 unsigned int ibSize = test->getBTofSize();
152 unsigned int ibcomSize = test->getBTofComSize();
153 unsigned int ieSize = test->getETofSize();
154 unsigned int ietfSize = test->getEtfSize();
155 ietfSize = ietfSize/12;
156 unsigned int ietfBSize = test->getEtfBunchSize();
157 unsigned int iinfoSize = test->getTofInfoSize();
158
159 for(int ib=0;ib<ibSize;ib++){
160 BTofCal* btof = new BTofCal;
161 for( int j=0; j<static_cast<int>(nBarAtten); j++ ) {
162 btof->setAtten(j,test->getBTofAtten(ib,j));
163 }
164 for( int j=0; j<static_cast<int>(nBarSpeed); j++ ) {
165 btof->setVeff(j,test->getBTofSpeed(ib,j));
166 }
167 for( int j=0; j<static_cast<int>(nBarPar); j++){
168 btof->setP1(j,test->getBTofPleft(ib,j));
169 btof->setP2(j,test->getBTofPright(ib,j));
170 }
171 for( int j=0; j<static_cast<int>(nBarParOff); j++){
172 btof->setPOff1_bunch0(j,test->getBTofPoffleft_bunch0(ib,j));
173 btof->setPOff2_bunch0(j,test->getBTofPoffright_bunch0(ib,j));
174 btof->setPOff1_bunch1(j,test->getBTofPoffleft_bunch1(ib,j));
175 btof->setPOff2_bunch1(j,test->getBTofPoffright_bunch1(ib,j));
176 btof->setPOff1_bunch2(j,test->getBTofPoffleft_bunch2(ib,j));
177 btof->setPOff2_bunch2(j,test->getBTofPoffright_bunch2(ib,j));
178 btof->setPOff1_bunch3(j,test->getBTofPoffleft_bunch3(ib,j));
179 btof->setPOff2_bunch3(j,test->getBTofPoffright_bunch3(ib,j));
180 }
181 for( int j=0; j<static_cast<int>(nBarSigma); j++){
182 btof->setFPLeft(j,test->getBTofFleft(ib,j));
183 btof->setFPRight(j,test->getBTofFright(ib,j));
184 }
185 for( int j=0; j<static_cast<int>(nBarSigCnt); j++){
186 btof->setFPCounter(j,test->getBTofFcounter(ib,j));
187 }
188
189 fBTofCal.push_back(btof);
190 }
191
192 for(int ie=0;ie<ieSize;ie++){
193 ETofCal* etof= new ETofCal;
194 for( int j=0; j<static_cast<int>(nEndAtten); j++ ) {
195 etof->setAtten(j,test->getETofAtten(ie,j));
196 }
197 for( int j=0; j<static_cast<int>(nEndSpeed); j++ ) {
198 etof->setVeff(j,test->getETofSpeed(ie,j));
199 }
200 for( int j=0; j<static_cast<int>(nEndPar); j++ ) {
201 etof->setP(j,test->getETofP(ie,j));
202 }
203 for( int j=0; j<static_cast<int>(nEndSigma); j++ ) {
204 etof->setFPCounter(j,test->getETofFP(ie,j));
205 }
206 fETofCal.push_back(etof);
207 }
208
209 for(int ietf=0;ietf<ietfSize;ietf++) {
210 for(int jetf=0;jetf<12;jetf++) {
211 EtfCal* etf= new EtfCal;
212 for( int k=0; k<static_cast<int>(nEtfSpeed); k++ ) {
213 etf->setVeff(k,test->getEtfSpeed(ietf,jetf,k));
214 }
215 for( int k=0; k<static_cast<int>(nEtfPar); k++ ) {
216 etf->setP( k,test->getEtfPcombine(ietf,jetf,k));
217 etf->setP1(k,test->getEtfPleft(ietf,jetf,k));
218 etf->setP2(k,test->getEtfPright(ietf,jetf,k));
219 }
220 fEtfCal.push_back(etf);
221 }
222 }
223
224 for( int ietfb=0;ietfb<ietfBSize;ietfb++ ) {
225 EtfBunchCal* etfbunch= new EtfBunchCal;
226 for( int k=0; k<static_cast<int>(nEtfBunch); k++ ) {
227 etfbunch->setBunchP(k,test->getEtfPBunch(ietfb,k));
228 }
229 fEtfBunchCal.push_back(etfbunch);
230 }
231
232 for( int ibcom=0; ibcom<ibcomSize; ibcom++ ) {
233 BTofCommonCal* bcomtof = new BTofCommonCal;
234 for(int j=0; j<static_cast<int>(nBarOffset); j++) {
235 bcomtof->setOffset( j, test->getBTofOffset(ibcom, j) );
236 }
237 for(int j=0; j<static_cast<int>(nBarSigCor); j++) {
238 bcomtof->setSigmaCorr( j, test->getBTofSigmaCorr(ibcom,j) );
239 }
240 fBTofCommonCal.push_back(bcomtof);
241 }
242
243
244 for( int iinfo=0; iinfo<iinfoSize; iinfo++ ) {
245 TofInfoCal* tofinfo = new TofInfoCal;
246 tofinfo->setRunBegin( test->getRunBegin( iinfo ) );
247 tofinfo->setRunEnd( test->getRunEnd( iinfo ) );
248 tofinfo->setVersion( test->getVersion( iinfo ) );
249 tofinfo->setQCorr( test->getQCorr( iinfo ) );
250 tofinfo->setQElec( test->getQElec( iinfo ) );
251 tofinfo->setMisLable( test->getMisLable( iinfo ) );
252 for( unsigned int j=0; j<5; j++ ) {
253 tofinfo->setBrEast( j, test->getBrEast(iinfo, j) );
254 tofinfo->setBrWest( j, test->getBrWest(iinfo, j) );
255 if( (test->getVersion(iinfo))<=8 ) { // useless
256 tofinfo->setEndcap( j, test->getEndcap(iinfo, j) );
257 }
258 else {
259 tofinfo->setEtf( j, test->getEndcap(iinfo, j) );
260 }
261 }
262 tofinfo->setRunFrom( test->getRunFrom( iinfo ) );
263 tofinfo->setRunTo( test->getRunTo( iinfo ) );
264 tofinfo->setEventFrom( test->getEventFrom( iinfo ) );
265 tofinfo->setEventTo( test->getEventTo( iinfo ) );
266 fTofInfoCal.push_back(tofinfo);
267 }
268
269 return StatusCode::SUCCESS;
270}
271
272
273StatusCode TofCaliSvc::chooseConstants(int run, int event ) {
274
275 MsgStream log(msgSvc(), name());
276
277 m_sequence = 0;
278 bool filled = false;
279 unsigned int inumber = 0;
280
281 std::vector<TofInfoCal*>::iterator it = fTofInfoCal.begin();
282 if( (*it)->getRunFrom() == -1 ) {
283 if( fTofInfoCal.size() == 1 ) {
284 log << MSG::INFO << "TofCaliSvc::chooseConstants() -- Run From is equal to -1! The ONLY TOF calibration constants are used!" << endreq;
285 return StatusCode::SUCCESS;
286 }
287 else {
288 log << MSG::ERROR << "TofCaliSvc::chooseConstants() -- Run From is equal to -1! The NUMBER of calibration constants are NOT equal to 1!" << endreq;
289 return StatusCode::FAILURE;
290 }
291 }
292
293 for( ; it!= fTofInfoCal.end(); it++, inumber++ ) {
294 if( ( (*it)->getRunTo() != -1 ) && ( (*it)->getRunTo() < (*it)->getRunFrom() ) ) {
295 log << MSG::ERROR << "TofCaliSvc::chooseConstants() -- The " << inumber << "th calibration constatns is ABNORMAL! Run From is LARGER than RUN To!" << endreq;
296 return StatusCode::FAILURE;
297 }
298 if( ( (*it)->getRunFrom() == (*it)->getRunTo() ) && ( (*it)->getEventFrom() != -1 ) && ( (*it)->getEventTo() != -1 ) && ( (*it)->getEventFrom() > (*it)->getEventTo() ) ) {
299 log << MSG::ERROR << "TofCaliSvc::chooseConstants() -- The " << inumber << "th calibration constatns is ABNORMAL! Event From is LARGER than Event To!" << endreq;
300 return StatusCode::FAILURE;
301 }
302 }
303
304 it = fTofInfoCal.begin();
305 inumber = 0;
306 for( ; it!= fTofInfoCal.end(); it++, inumber++ ) {
307 int runFrom = (*it)->getRunFrom();
308 int runTo = (*it)->getRunTo();
309 int eventFrom = (*it)->getEventFrom();
310 int eventTo = (*it)->getEventTo();
311 if( ( run == runFrom ) && ( ( eventFrom == -1 ) || ( event >= eventFrom ) ) ) {
312 if( ( run < runTo ) || ( ( run == runTo ) && ( ( eventTo == -1 ) || ( event <= eventTo ) ) ) ) {
313 filled = true;
314 break;
315 }
316 }
317 if( run > runFrom ) {
318 if( ( run < runTo ) || ( ( run == runTo ) && ( ( eventTo == -1 ) || ( event <= eventTo ) ) ) ) {
319 filled = true;
320 break;
321 }
322 }
323 }
324
325 if( filled ) {
326 m_sequence = inumber;
327 return StatusCode::SUCCESS;
328 }
329 else {
330 log << MSG::ERROR << "TofCaliSvc::chooseConstants() -- The event with run number " << run << " and event number " << event << " is NOT suitable for this group of calibration constants" << endreq;
331 return StatusCode::FAILURE;
332 }
333
334 return StatusCode::SUCCESS;
335}
336
337
338const double TofCaliSvc::BTDelay1(unsigned id) {
339 double tdelay = 0.0;
340 if( id < 176 ) {
341 tdelay = fBTofCal[176*m_sequence+id]->getP1(0);
342 }
343 else {
344 MsgStream log(msgSvc(), name());
345 log<<MSG::ERROR<<"TofCaliSvc::BTDelay1() -- Wrong TOFID is provided! ID = "<<id<<endreq;
346 }
347 return tdelay;
348}
349
350
351const double TofCaliSvc::BTDelay2(unsigned id) {
352 double tdelay = 0.0;
353 if( id < 176 ) {
354 tdelay = fBTofCal[176*m_sequence+id]->getP2(0);
355 }
356 else {
357 MsgStream log(msgSvc(), name());
358 log<<MSG::ERROR<<"TofCaliSvc::BTDelay2() -- Wrong TOFID is provided! ID = "<<id<<endreq;
359 }
360 return tdelay;
361}
362
363
364const double TofCaliSvc::ETDelay(unsigned id) {
365 double tdelay = 0.0;
366 if( id < 96 ) {
367 tdelay = fETofCal[96*m_sequence+id]->getP(0);
368 }
369 else {
370 MsgStream log(msgSvc(), name());
371 log<<MSG::ERROR<<"TofCaliSvc::ETDelay() -- Wrong TOFID is provided! ID = "<<id<<endreq;
372 }
373 return tdelay;
374}
375
376
377const double TofCaliSvc::BTCorr1(double ADC,double z,unsigned id){
378 MsgStream log(msgSvc(), name());
379
380 double p1[nBarPar];
381 for( int i=0; i<static_cast<int>(nBarPar); i++ ) {
382 p1[i]=fBTofCal[176*m_sequence+id]->getP1(i);
383 }
384
385 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;
386
387 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;
388
389 return tcorr1;
390}
391
392
393const double TofCaliSvc::BTCorr2(double ADC,double z,unsigned id){
394 MsgStream log(msgSvc(), name());
395
396 double p2[nBarPar];
397 for( int i=0; i<static_cast<int>(nBarPar); i++ ) {
398 p2[i]=fBTofCal[176*m_sequence+id]->getP2(i);
399 }
400
401 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;
402
403 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;
404
405 return tcorr2;
406}
407
408
409const double TofCaliSvc::BTCorrOffset1(double z,unsigned id,double t0){
410 MsgStream log(msgSvc(), name());
411
412 int numBunch = fTofInfoCal[m_sequence]->getRunEnd();
413 int whichBunch = (static_cast<int>(t0/(12000./499.8/(numBunch*1.0))+0.1))%numBunch;
414
415 double poff1[nBarParOff];
416 if( whichBunch==0 ) {
417 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
418 poff1[i]=fBTofCal[176*m_sequence+id]->getPOff1_bunch0(i);
419 }
420 }
421 else if( whichBunch==1 ) {
422 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
423 poff1[i]=fBTofCal[176*m_sequence+id]->getPOff1_bunch1(i);
424 }
425 }
426 else if( whichBunch==2 ) {
427 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
428 poff1[i]=fBTofCal[176*m_sequence+id]->getPOff1_bunch2(i);
429 }
430 }
431 else if( whichBunch==3 ) {
432 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
433 poff1[i]=fBTofCal[176*m_sequence+id]->getPOff1_bunch3(i);
434 }
435 }
436
437 double tCorrOffset1 = 0.0;
438 if( z>=0.0 ) {
439 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;
440 }
441 else {
442 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;
443 }
444
445 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;
446
447 return tCorrOffset1;
448}
449
450
451const double TofCaliSvc::BTCorrOffset2(double z,unsigned id,double t0){
452 MsgStream log(msgSvc(), name());
453
454 int numBunch = fTofInfoCal[m_sequence]->getRunEnd();
455 int whichBunch = (static_cast<int>(t0/(12000./499.8/(numBunch*1.0))+0.1))%numBunch;
456
457 double poff2[nBarParOff];
458 if( whichBunch==0 ) {
459 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
460 poff2[i]=fBTofCal[176*m_sequence+id]->getPOff2_bunch0(i);
461 }
462 }
463 else if( whichBunch==1 ) {
464 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
465 poff2[i]=fBTofCal[176*m_sequence+id]->getPOff2_bunch1(i);
466 }
467 }
468 else if( whichBunch==2 ) {
469 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
470 poff2[i]=fBTofCal[176*m_sequence+id]->getPOff2_bunch2(i);
471 }
472 }
473 else if( whichBunch==3 ) {
474 for( int i=0; i<static_cast<int>(nBarParOff); i++ ) {
475 poff2[i]=fBTofCal[176*m_sequence+id]->getPOff2_bunch3(i);
476 }
477 }
478
479 double tCorrOffset2 = 0.0;
480 if( z>=0.0 ) {
481 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;
482 }
483 else {
484 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;
485 }
486
487 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;
488
489 return tCorrOffset2;
490}
491
492
493const double TofCaliSvc::TOffset() {
494 double toffset = fBTofCommonCal[m_sequence]->getOffset(0);
495 return toffset;
496}
497
498
499const double TofCaliSvc::BTime1(double ADC,double TDC,double z,unsigned id,double t0){
500 MsgStream log(msgSvc(), name());
501
502 double tcorr1 = BTCorr1( ADC, z, id );
503 double tcorr2 = BTCorrOffset1( z, id, t0);
504 double tcorr3 = fBTofCommonCal[m_sequence]->getOffset(0);
505
506 log << MSG::DEBUG << "BTime1 id =" << id << " tcorr=" << tcorr1 << " toffset=" << tcorr2 << " total offset=" << tcorr3 << endreq;
507
508 double time = TDC - tcorr1 - tcorr2 - tcorr3;
509
510 if(time<0.) {
511 log<<MSG::WARNING<<"TofCaliSvc::BTime1() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" z = "<<z<<" ID = "<<id<<endreq;
512 }
513 return time;
514}
515
516
517const double TofCaliSvc::BTime2(double ADC,double TDC,double z,unsigned id, double t0){
518 MsgStream log(msgSvc(), name());
519
520 double tcorr1 = BTCorr2( ADC, z, id );
521 double tcorr2 = BTCorrOffset2( z, id ,t0);
522 double tcorr3 = fBTofCommonCal[m_sequence]->getOffset(0);
523
524 log << MSG::DEBUG << "BTime2 id =" << id << " tcorr=" << tcorr1 << " toffset=" << tcorr2 << " total offset=" << tcorr3 << endreq;
525
526 double time = TDC - tcorr1 - tcorr2 - tcorr3;
527
528 if(time<0.) {
529 log<<MSG::WARNING<<"TofCaliSvc::BTime2() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" z = "<<z<<" ID = "<<id<<endreq;
530 }
531 return time;
532}
533
534
535/*
536const double TofCaliSvc::BTime(double tleft,double tright,double z,unsigned id){
537 for(int i=0;i<4;i++)
538 m_w[i]=fBTofCal[176*m_sequence+id]->getW(i);
539 double f1=m_w[0]+m_w[1]*z+m_w[2]*z*z;
540 double f2=1-f1;
541 double wt=f1*tleft+f2*tright+m_w[3];
542 if(wt<0.) {
543 MsgStream log(msgSvc(), name());
544 log<<MSG::WARNING<<"TofCaliSvc::BTime() -- A minus time is given : "<<wt <<" [Input] TDC1 = "<<tleft<<" TDC2 = "<<tright<<" z = "<<z<<" ID = "<<id<<endreq;
545 }
546
547 return wt;
548}
549*/
550
551
552const double TofCaliSvc::BTimeCounter(double tleft,double tright,double z,unsigned id){
553
554 double sigmaCorr = fBTofCommonCal[m_sequence]->getSigmaCorr(0);
555 double sigmaCorr2 = sigmaCorr*sigmaCorr;
556
557 double sigmaLeft = BSigma1( z, id );
558 double sigmaLeft2 = sigmaLeft*sigmaLeft;
559 double sigmaRight = BSigma2( z, id );
560 double sigmaRight2 = sigmaRight*sigmaRight;
561
562 double fraction = ( sigmaRight2 - sigmaCorr2 )/( sigmaLeft2 + sigmaRight2 - 2.0*sigmaCorr2);
563
564 double wt=fraction*tleft + (1.0-fraction)*tright;
565 if(wt<0.) {
566 MsgStream log(msgSvc(), name());
567 log<<MSG::WARNING<<"TofCaliSvc::BTimeCounter() -- A minus time is given : "<<wt <<" [Input] z = "<<z<<" ID = "<<id<<endreq;
568 }
569
570 return wt;
571}
572
573const double TofCaliSvc::BTimeCluster(double tlayer1,double tlayer2,double z1,double z2,unsigned id1, unsigned id2){
574
575 double sigmaCorr = fBTofCommonCal[m_sequence]->getSigmaCorr(0);
576 double sigmaCorr2 = sigmaCorr*sigmaCorr;
577
578 double sigmaInner = BSigmaCounter( z1, id1 );
579 double sigmaInner2 = sigmaInner*sigmaInner;
580 double sigmaOuter = BSigmaCounter( z2, id2 );
581 double sigmaOuter2 = sigmaOuter*sigmaOuter;
582
583 double fraction = ( sigmaOuter2 - sigmaCorr2 )/( sigmaInner2 + sigmaOuter2 - 2.0*sigmaCorr2);
584
585 double wt=fraction*tlayer1 + (1.0-fraction)*tlayer2;
586 if(wt<0.) {
587 MsgStream log(msgSvc(), name());
588 log<<MSG::WARNING<<"TofCaliSvc::BTimeCluster() -- A minus time is given : "<<wt <<" [Input] z1 = "<<z1<<" [Input] z2 = "<<z2<<" ID1 = "<< id1 << " ID2=" << id2 << endreq;
589 }
590 return wt;
591}
592
593
594const double TofCaliSvc::BSigma1(double z, unsigned id) {
595 MsgStream log(msgSvc(), name());
596
597 double fpleft[nBarSigma];
598 for( int i=0; i<static_cast<int>(nBarSigma); i++ ) {
599 fpleft[i]=fBTofCal[176*m_sequence+id]->getFPLeft(i);
600 }
601
602 log << MSG::DEBUG << "BSigma1 id =" << id << " 1=" << fpleft[0] << " 2=" << fpleft[1] << " 3=" << fpleft[2] << " 4=" << fpleft[3] << " 5=" << fpleft[4] << endreq;
603
604 double sigmaLeft = fpleft[0] + fpleft[1]*z + fpleft[2]*z*z + fpleft[3]*z*z*z + fpleft[4]*z*z*z*z;
605
606 return sigmaLeft;
607}
608
609
610const double TofCaliSvc::BSigma2(double z, unsigned id) {
611 MsgStream log(msgSvc(), name());
612
613 double fpright[nBarSigma];
614 for( int i=0; i<static_cast<int>(nBarSigma); i++ ) {
615 fpright[i]=fBTofCal[176*m_sequence+id]->getFPRight(i);
616 }
617
618 log << MSG::DEBUG << "BSigma2 id =" << id << " 1=" << fpright[0] << " 2=" << fpright[1] << " 3=" << fpright[2] << " 4=" << fpright[3] << " 5=" << fpright[4] << endreq;
619
620 double sigmaRight = fpright[0] + fpright[1]*z + fpright[2]*z*z + fpright[3]*z*z*z + fpright[4]*z*z*z*z;
621
622 return sigmaRight;
623}
624
625
626const double TofCaliSvc::BSigmaCounter(double z, unsigned id) {
627 MsgStream log(msgSvc(), name());
628
629 double fplayer[nBarSigCnt];
630 for( int i=0; i<static_cast<int>(nBarSigCnt); i++ ) {
631 fplayer[i]=fBTofCal[176*m_sequence+id]->getFPCounter(i);
632 }
633
634 log << MSG::DEBUG << "BSigmaCounter id =" << id << " 1=" << fplayer[0] << " 2=" << fplayer[1] << " 3=" << fplayer[2] << " 4=" << fplayer[3] << " 5=" << fplayer[4] << endreq;
635
636 double sigma = fplayer[0] + fplayer[1]*z + fplayer[2]*z*z + fplayer[3]*z*z*z + fplayer[4]*z*z*z*z;
637
638 return sigma;
639}
640
641
642const double TofCaliSvc::BSigmaCluster(double z1, double z2, unsigned id1, unsigned id2) {
643 double sigmaInner = BSigmaCounter(z1, id1);
644 double sigmaInner2 = sigmaInner*sigmaInner;
645 double sigmaOuter = BSigmaCounter(z2, id2);
646 double sigmaOuter2 = sigmaOuter*sigmaOuter;
647 double sigmaCorr = fBTofCommonCal[m_sequence]->getSigmaCorr(0);
648 double sigmaCorr2 = sigmaCorr*sigmaCorr;
649 double sigma = (sigmaInner2*sigmaOuter2-sigmaCorr2*sigmaCorr2)/(sigmaInner2+sigmaOuter2-2.0*sigmaCorr2);
650 sigma = sqrt(sigma);
651 return sigma;
652}
653
654
655const double TofCaliSvc::ETime(double ADC,double TDC,double rHit,unsigned id){
656 MsgStream log(msgSvc(), name());
657
658 double p[nEndPar];
659 for( int i=0; i<static_cast<int>(nEndPar); i++ ) {
660 p[i]=fETofCal[96*m_sequence+id]->getP(i);
661 }
662
663 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;
664
665 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);
666
667 if(time<0.) {
668 MsgStream log(msgSvc(), name());
669 log<<MSG::WARNING<<"TofCaliSvc::ETime() -- A minus time is given : "<< time <<" [Input] ADC = "<<ADC<<" TDC = "<<TDC<<" r = "<< rHit <<" ID = "<<id<<endreq;
670 }
671
672 return time;
673}
674
675
676const double TofCaliSvc::ESigma(double r, unsigned id) {
677 MsgStream log(msgSvc(), name());
678
679 double fp[nEndSigma];
680 for( int i=0; i<static_cast<int>(nEndSigma); i++) {
681 fp[i]=fETofCal[96*m_sequence+id]->getFPCounter(i);
682 }
683
684 log << MSG::DEBUG << "ESigma id =" << id << " 1=" << fp[0] << " 2=" << fp[1] << " 3=" << fp[2] << endreq;
685
686 double sigma = fp[0] + fp[1]*r + fp[2]*r*r;
687
688 return sigma;
689}
690
691
692const double TofCaliSvc::EtfTime(double ADC1,double ADC2,double TDC1,double TDC2,unsigned id,unsigned int strip,double t0){
693 MsgStream log(msgSvc(), name());
694
695 double q = (ADC1+ADC2)/2.0;
696 double t = (TDC1+TDC2)/2.0;
697
698 double p[nEtfPar];
699 for( int i=0; i<static_cast<int>(nEtfPar); i++ ) {
700 p[i]=fEtfCal[72*12*m_sequence+12*id+strip]->getP(i);
701 }
702
703 double tcorr = p[0]
704 + p[1]/TMath::Sqrt(q)
705 + p[2]/q
706 + p[3]*q
707 + p[4]*q*q
708 + p[5]*q*q*q
709 + p[6]*q*q*q*q;
710 double time = t - tcorr;
711
712 int numBunch = fTofInfoCal[m_sequence]->getRunEnd();
713 int ibunch = (static_cast<int>(t0/(12000./499.8/(numBunch*1.0))+0.1))%numBunch;
714 double pbunch = EtfBunchP(ibunch);
715
716 time = time - pbunch;
717
718 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 << " t0=" << t0 << " pbunch=" << pbunch << " time=" << time << endreq;
719
720 return time;
721}
722
723
724const double TofCaliSvc::EtfTime1(double ADC,double TDC,double z,unsigned id,unsigned int strip,double t0){
725 MsgStream log(msgSvc(), name());
726
727 double p1[nEtfPar];
728 for( int i=0; i<static_cast<int>(nEtfPar); i++ ) {
729 p1[i]=fEtfCal[72*12*m_sequence+12*id+strip]->getP1(i);
730 }
731
732 double tcorr1 = p1[0]
733 + p1[1]/TMath::Sqrt(ADC)
734 + p1[2]*ADC
735 + p1[3]*ADC*ADC
736 + p1[4]*ADC*ADC*ADC
737 + p1[5]*ADC*ADC*ADC*ADC
738 + p1[6]*z/TMath::Sqrt(ADC)
739 + p1[7]/ADC
740 + p1[8]*z/ADC
741 + p1[9]*z*ADC
742 + p1[10]*z
743 + p1[11]*z*z
744 + p1[12]*z*z*z;
745 double time1 = TDC - tcorr1;
746
747 int numBunch = fTofInfoCal[m_sequence]->getRunEnd();
748 int ibunch = (static_cast<int>(t0/(12000./499.8/(numBunch*1.0))+0.1))%numBunch;
749 double pbunch = EtfBunchP(ibunch);
750
751 time1 = time1 - pbunch;
752
753 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 << " t0=" << t0 << " pbunch=" << pbunch << " time1=" << time1 << endreq;
754
755 return time1;
756}
757
758
759const double TofCaliSvc::EtfTime2(double ADC,double TDC,double z,unsigned id,unsigned int strip,double t0){
760 MsgStream log(msgSvc(), name());
761
762 double p2[nEtfPar];
763 for( int i=0; i<static_cast<int>(nEtfPar); i++ ) {
764 p2[i]=fEtfCal[72*12*m_sequence+12*id+strip]->getP2(i);
765 }
766
767 double tcorr2 = p2[0]
768 + p2[1]/TMath::Sqrt(ADC)
769 + p2[2]*ADC
770 + p2[3]*ADC*ADC
771 + p2[4]*ADC*ADC*ADC
772 + p2[5]*ADC*ADC*ADC*ADC
773 + p2[6]*z/TMath::Sqrt(ADC)
774 + p2[7]/ADC
775 + p2[8]*z/ADC
776 + p2[9]*z*ADC
777 + p2[10]*z
778 + p2[11]*z*z
779 + p2[12]*z*z*z;
780 double time2 = TDC - tcorr2;
781
782 int numBunch = fTofInfoCal[m_sequence]->getRunEnd();
783 int ibunch = (static_cast<int>(t0/(12000./499.8/(numBunch*1.0))+0.1))%numBunch;
784 double pbunch = EtfBunchP(ibunch);
785
786 time2 = time2 - pbunch;
787
788 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 << " t0=" << t0 << " pbunch=" << pbunch << " time2=" << time2 << endreq;
789
790 return time2;
791}
792
793
794const double TofCaliSvc::EtfTimeMC(double ADC1,double ADC2,double TDC1,double TDC2,unsigned id,unsigned int strip,double t0){
795 MsgStream log(msgSvc(), name());
796
797 double q = (ADC1+ADC2)/2.0;
798 double t = (TDC1+TDC2)/2.0;
799
800 double p[nEtfPar];
801 for( int i=0; i<static_cast<int>(nEtfPar); i++ ) {
802 p[i]=fEtfCal[72*12*m_sequence+12*id+strip]->getP(i);
803 }
804
805 double tcorr = p[0] + p[1]/TMath::Sqrt(q);
806 double time = t - tcorr;
807
808 log << MSG::DEBUG << "EtfTime module =" << id << " strip=" << strip << " 1=" << p[0] << " 2=" << p[1] << " tcorr=" << tcorr << " t0=" << t0 << " time=" << time << endreq;
809
810 return time;
811}
812
813
814const double TofCaliSvc::EtfTimeMC1(double ADC,double TDC,double z,unsigned id,unsigned int strip,double t0){
815 MsgStream log(msgSvc(), name());
816
817 double p1[nEtfPar];
818 for( int i=0; i<static_cast<int>(nEtfPar); i++ ) {
819 p1[i]=fEtfCal[72*12*m_sequence+12*id+strip]->getP1(i);
820 }
821
822 double tcorr1 = p1[0] + p1[1]/TMath::Sqrt(ADC) + p1[2]*z;
823 double time1 = TDC - tcorr1;
824
825 log << MSG::DEBUG << "EtfTime1 module =" << id << " strip=" << strip << " 1=" << p1[0] << " 2=" << p1[1] << " 3=" << p1[2] << " tcorr=" << tcorr1 << " t0=" << t0 << " time1=" << time1 << endreq;
826
827 return time1;
828}
829
830
831const double TofCaliSvc::EtfTimeMC2(double ADC,double TDC,double z,unsigned id,unsigned int strip,double t0){
832 MsgStream log(msgSvc(), name());
833
834 double p2[nEtfPar];
835 for( int i=0; i<static_cast<int>(nEtfPar); i++ ) {
836 p2[i]=fEtfCal[72*12*m_sequence+12*id+strip]->getP2(i);
837 }
838
839 double tcorr2 = p2[0] + p2[1]/TMath::Sqrt(ADC) + p2[2]*z;
840 double time2 = TDC - tcorr2;
841
842 log << MSG::DEBUG << "EtfTime2 module =" << id << " strip=" << strip << " 1=" << p2[0] << " 2=" << p2[1] << " 3=" << p2[2] << " tcorr=" << tcorr2 << " t0=" << t0 << " time2=" << time2 << endreq;
843
844 return time2;
845}
846
847
848const double TofCaliSvc::EtfTime(double tleft,double tright){
849 MsgStream log(msgSvc(), name());
850
851 double time = (tleft+tright)/2.0;
852 log << MSG::DEBUG << "EtfTime tleft=" << tleft << " tright=" << tright << " time=" << time << endreq;
853
854 return time;
855}
856
857
858const double TofCaliSvc::EtfBunchP(int index){
859 MsgStream log(msgSvc(), name());
860
861 double pbunch = 0.0;
862 if( fEtfBunchCal.size()>0 && index>=0 && index<4 ) {
863 pbunch=fEtfBunchCal[m_sequence]->getBunchP(index);
864 }
865
866 return pbunch;
867}
868
869
870const double TofCaliSvc::BPulseHeight1( double ADC, double zHit, double sint, unsigned int id ) {
871 double length = 230.0;
872 double A = 1.0;
873 double Latten = fBTofCal[176*m_sequence+id]->getAtten(0);
874 double q0 = ADC*sint*TMath::Exp((0.5*length-zHit)/Latten)/A;
875 return q0;
876}
877
878
879const double TofCaliSvc::BPulseHeight2( double ADC, double zHit, double sint, unsigned int id ) {
880 double length = 230.0;
881 double A = 1.0;
882 double Latten = fBTofCal[176*m_sequence+id]->getAtten(0);
883 double q0 = ADC*sint*TMath::Exp((0.5*length+zHit)/Latten)/A;
884 return q0;
885}
886
887
888const double TofCaliSvc::BPulseHeight( double ADC1, double ADC2, double zHit, double sint, unsigned int id ) {
889 double length = 230.0;
890 double Latten = fBTofCal[176*m_sequence+id]->getAtten(0);
891 double gainRatio = fBTofCal[176*m_sequence+id]->getAtten(1);
892 double A2 = fBTofCal[176*m_sequence+id]->getAtten(2);
893 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)) );
894 return q;
895}
896
897
898const double TofCaliSvc::BPh( double ADC1, double ADC2, double zHit, unsigned int id ) {
899 double length = 230.0;
900 double Latten = fBTofCal[176*m_sequence+id]->getAtten(0);
901 double gainRatio = fBTofCal[176*m_sequence+id]->getAtten(1);
902 double q = ( ADC1*TMath::Exp((0.5*length-zHit)/Latten)+ADC2*TMath::Exp((0.5*length+zHit)/Latten) )/(1.0+TMath::Exp(gainRatio));
903 return q;
904}
905
906
907const double TofCaliSvc::EPulseHeight( double ADC, double rHit, double cost, unsigned int id ) {
908 double length = 44.5;
909 double a0 = fETofCal[96*m_sequence+id]->getAtten(0);
910 double a1 = fETofCal[96*m_sequence+id]->getAtten(1);
911 double a2 = fETofCal[96*m_sequence+id]->getAtten(2);
912 double a3 = fETofCal[96*m_sequence+id]->getAtten(3);
913
914 double q0 = ADC*fabs(cost)*TMath::Exp(-(a1*(rHit-length)+a2*(rHit-length)*(rHit-length)))/a3;
915
916 return q0;
917}
918
919
920const double TofCaliSvc::EPh( double ADC, double rHit, unsigned int id ) {
921 double length = 44.5;
922 double a0 = fETofCal[96*m_sequence+id]->getAtten(0);
923 double a1 = fETofCal[96*m_sequence+id]->getAtten(1);
924 double a2 = fETofCal[96*m_sequence+id]->getAtten(2);
925 double q0 = ADC*TMath::Exp(-(a0+a1*(rHit-length)+a2*(rHit-length)*(rHit-length)));
926 return q0;
927}
928
929
930const double TofCaliSvc::getQ0(unsigned id){
931 return fBTofCal[176*m_sequence+id]->getAtten(3);
932}
933
934
935const double TofCaliSvc::BVeff(unsigned id){
936 if(id<176){
937 return fBTofCal[176*m_sequence+id]->getVeff(0);
938 }else{
939 std::cout<<"bad id="<<id<<std::endl;
940 return 0.;}
941}
942
943
944const double TofCaliSvc::BAtten(unsigned id){
945 if( id > 175 ) return -1;
946 return fBTofCal[176*m_sequence+id]->getAtten(0);
947}
948
949const double TofCaliSvc::BGainForward(unsigned id){
950 if( id > 175 ) return -1;
951 double gainRatio = fBTofCal[176*m_sequence+id]->getAtten(1);
952 double A2 = fBTofCal[176*m_sequence+id]->getAtten(2);
953 double A1 = A2*TMath::Exp(gainRatio);
954 return A1;
955}
956
957const double TofCaliSvc::BGainBackward(unsigned id){
958 if( id > 175 ) return -1;
959 return fBTofCal[176*m_sequence+id]->getAtten(2);
960}
961
962const double TofCaliSvc::EVeff(unsigned id){
963 if( id > 175 ) return -1;
964 return fETofCal[96*m_sequence+id]->getVeff(0);
965}
966
967const double TofCaliSvc::EtfVeff(unsigned int id, unsigned int strip){
968 if(id<72 && strip<12){
969 return fEtfCal[72*12*m_sequence+12*id+strip]->getVeff(0);
970 }else{
971 std::cout<<"bad id="<<id<<" strip="<<strip<<std::endl;
972 return 0.;
973 }
974}
975
976
977const double TofCaliSvc::ZTDC(double tleft, double tright, unsigned id) {
978 double ztdc = -1000.0;
979 if( id > 175 ) return ztdc;
980 double veff = fBTofCal[176*m_sequence+id]->getVeff(0);
981 double delay = fBTofCal[176*m_sequence+id]->getVeff(1);
982 ztdc = 0.5*veff*(tright-tleft-delay);
983 return ztdc;
984}
985
986const double TofCaliSvc::ZTDC1(double tright, unsigned id, double z) {
987 double tleft = -1000.0;
988 if( id > 175 ) return tleft;
989 if( tright < -900.0 ) return tleft;
990 double veff = fBTofCal[176*m_sequence+id]->getVeff(0);
991 double delay = fBTofCal[176*m_sequence+id]->getVeff(1);
992 tleft = tright-delay-2.0*z/veff;
993 return tleft;
994}
995
996const double TofCaliSvc::ZTDC2(double tleft, unsigned id, double z) {
997 double tright = -1000.0;
998 if( id > 175 ) return tright;
999 if( tleft < -900.0 ) return tright;
1000 double veff = fBTofCal[176*m_sequence+id]->getVeff(0);
1001 double delay = fBTofCal[176*m_sequence+id]->getVeff(1);
1002 tright = tleft+delay+2.0*z/veff;
1003 return tright;
1004}
1005
1006const double TofCaliSvc::ZADC(double qleft, double qright, unsigned id) {
1007 double zadc = -1000.0;
1008 if( id > 175 ) return zadc;
1009 if( qright < 1.0e-6 ) return zadc;
1010 double ldecay = fBTofCal[176*m_sequence+id]->getAtten(0);
1011 double a1overa2 = fBTofCal[176*m_sequence+id]->getAtten(1);
1012 double q1overq2 = log(qleft/qright);
1013 zadc = 0.5*ldecay*( q1overq2 - a1overa2 );
1014 return zadc;
1015}
1016
1017const double TofCaliSvc::ZADC1(double qright, unsigned id, double z) {
1018 double qleft = -1000.0;
1019 if( id > 175 ) return qleft;
1020 if( qright < 1.0e-6 ) return qleft;
1021 double ldecay = fBTofCal[176*m_sequence+id]->getAtten(0);
1022 double a1overa2 = fBTofCal[176*m_sequence+id]->getAtten(1);
1023 double q1overq2 = 2.0*z/ldecay + a1overa2;
1024 qleft = qright*exp(q1overq2);
1025 return qleft;
1026}
1027
1028const double TofCaliSvc::ZADC2(double qleft, unsigned id, double z) {
1029 double qright = -1000.0;
1030 if( id > 175 ) return qright;
1031 if( qleft < 1.0e-6 ) return qright;
1032 double ldecay = fBTofCal[176*m_sequence+id]->getAtten(0);
1033 double a1overa2 = fBTofCal[176*m_sequence+id]->getAtten(1);
1034 double q1overq2 = 2.0*z/ldecay + a1overa2;
1035 qright = qleft*exp(-q1overq2);
1036 return qright;
1037}
1038
1039const double TofCaliSvc::EtfZTDC(double tleft, double tright, unsigned id, unsigned int strip) {
1040 double ztdc = -1000.0;
1041 if( id>71 || strip>11 ) return ztdc;
1042 double delay = fEtfCal[72*12*m_sequence+12*id+strip]->getVeff(0);
1043 double veff = fEtfCal[72*12*m_sequence+12*id+strip]->getVeff(1);
1044 ztdc = (tright-tleft-delay)/veff;
1045 return ztdc;
1046}
1047
1048
1049const double TofCaliSvc::EAtten(unsigned id){
1050 if( id > 95 ) return -1;
1051 return fETofCal[96*m_sequence+id]->getAtten(0);
1052}
1053
1054const double TofCaliSvc::EGain(unsigned id){
1055 if( id > 95 ) return -1;
1056 return fETofCal[96*m_sequence+id]->getAtten(1);
1057}
1058
1060 return fTofInfoCal[m_sequence]->getRunBegin();
1061}
1062
1064 return fTofInfoCal[m_sequence]->getRunEnd();
1065}
1066
1068 return fTofInfoCal[m_sequence]->getVersion();
1069}
1070
1072 return fTofInfoCal[m_sequence]->getQCorr();
1073}
1074
1076 return fTofInfoCal[m_sequence]->getQElec();
1077}
1078
1080 return fTofInfoCal[m_sequence]->getMisLable();
1081}
1082
1083const int TofCaliSvc::BrEast(unsigned int im) {
1084 return fTofInfoCal[m_sequence]->getBrEast(im);
1085}
1086
1087const int TofCaliSvc::BrWest(unsigned int im) {
1088 return fTofInfoCal[m_sequence]->getBrWest(im);
1089}
1090
1091const int TofCaliSvc::Endcap(unsigned int im) {
1092 return fTofInfoCal[m_sequence]->getEndcap(im);
1093}
1094
1095const int TofCaliSvc::Etf(unsigned int im) {
1096 return fTofInfoCal[m_sequence]->getEndcap(im);
1097}
1098
1099BTofCal* TofCaliSvc::BTof(unsigned id) const{
1100 return fBTofCal[176*m_sequence+id];
1101}
1102
1103ETofCal* TofCaliSvc::ETof(unsigned id) const{
1104 return fETofCal[96*m_sequence+id];
1105}
1106
1107EtfCal* TofCaliSvc::EtfTof(unsigned id) const{
1108 return fEtfCal[72*12*m_sequence+id];
1109}
1110
1112 return fBTofCommonCal[m_sequence];
1113}
1114
1116 return fTofInfoCal[m_sequence];
1117}
1118
1120 std::cout<<"Now We can get the TOF Calibtration Service"<<std::endl;
1121 std::cout<<"Barrel TOF Counter Number = "<<fBTofCal.size()<<std::endl;
1122 std::cout<<"Endcap TOF Counter Number = "<<fETofCal.size()<<std::endl;
1123
1124 cout<<"The O Barrel TOF PMT1 p1[0] is"<<" "<<BTof(0)->getP1(0)<<endl;
1125 cout<<"The 0 Barrel TOF PMT1 p1[1] is"<<" "<<BTof(0)->getP1(1)<<endl;
1126 cout<<"The 0 Barrel TOF veff is"<<" "<<BTof(0)->getVeff(0)<<endl;
1127 // cout<<"The 22rd Endcap TOF PMT veff is"<<" "<<ETof(22)->getVeff()<<endl;
1128}
1129
1130void TofCaliSvc::handle(const Incident& inc){
1131 MsgStream log( messageService(), name() );
1132 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
1133
1134 if ( inc.type() == "NewRun" ){
1135 log << MSG::DEBUG << "New Run" << endreq;
1136 // if(!m_hasbeeninitialized){
1137
1138 StatusCode sc= FillfromDatabase();
1139 if(sc.isSuccess()){
1140 m_hasbeeninitialized=true;
1141 }
1142 // }
1143 }
1144}
std::string test
Definition: CalibModel.cxx:43
TTree * sigma
Double_t time
EvtComplex exp(const EvtComplex &c)
Definition: EvtComplex.hh:252
****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 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
IMessageSvc * msgSvc()
TTree * t
Definition: binning.cxx:23
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)
void setFPCounter(int idx, double fp3)
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)
void setAtten(int idx, double atten)
void setBunchP(int idx, double pbunch)
Definition: EtfBunchCal.h:15
void setVeff(int idx, double veff)
const double BTimeCounter(double tleft, double tright, double z, unsigned int id)
Definition: TofCaliSvc.cxx:552
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)
Definition: TofCaliSvc.cxx:870
const double BPh(double ADC1, double ADC2, double zHit, unsigned int id)
Definition: TofCaliSvc.cxx:898
const int RunBegin()
const double ZTDC2(double tleft, unsigned int id, double z)
Definition: TofCaliSvc.cxx:996
const double BPulseHeight2(double ADC, double zHit, double sint, unsigned int id)
Definition: TofCaliSvc.cxx:879
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)
Definition: TofCaliSvc.cxx:573
const double EPh(double ADC, double rHit, unsigned int id)
Definition: TofCaliSvc.cxx:920
const double ZTDC1(double tright, unsigned int id, double z)
Definition: TofCaliSvc.cxx:986
TofInfoCal * TofInfo() const
const double BPulseHeight(double ADC1, double ADC2, double zHit, double sint, unsigned int id)
Definition: TofCaliSvc.cxx:888
const int QCorr()
const int BrEast(unsigned int No)
const double BGainForward(unsigned int id)
Definition: TofCaliSvc.cxx:949
const int Etf(unsigned int No)
const double EtfBunchP(int index)
Definition: TofCaliSvc.cxx:858
const double BTCorrOffset2(double zHit, unsigned int id, double t0)
Definition: TofCaliSvc.cxx:451
const double BTime2(double ADC, double TDC, double zHit, unsigned int id, double t0)
Definition: TofCaliSvc.cxx:517
const double EPulseHeight(double ADC, double rHit, double cost, unsigned int id)
Definition: TofCaliSvc.cxx:907
const double BSigma1(double zHit, unsigned int id)
Definition: TofCaliSvc.cxx:594
const double BAtten(unsigned int id)
Definition: TofCaliSvc.cxx:944
virtual StatusCode finalize()
Definition: TofCaliSvc.cxx:95
const double EtfTimeMC(double ADC1, double ADC2, double TDC1, double TDC2, unsigned int id, unsigned int strip, double t0)
Definition: TofCaliSvc.cxx:794
const double BSigma2(double zHit, unsigned int id)
Definition: TofCaliSvc.cxx:610
const double EtfTime1(double ADC, double TDC, double zHit, unsigned int id, unsigned int strip, double t0)
Definition: TofCaliSvc.cxx:724
StatusCode chooseConstants(int run, int number)
Definition: TofCaliSvc.cxx:273
const double BTime1(double ADC, double TDC, double zHit, unsigned int id, double t0)
Definition: TofCaliSvc.cxx:499
BTofCal * BTof(unsigned int id) const
const double ETime(double ADC, double TDC, double rHit, unsigned int id)
Definition: TofCaliSvc.cxx:655
const double BTCorrOffset1(double zHit, unsigned int id, double t0)
Definition: TofCaliSvc.cxx:409
const double EtfTimeMC1(double ADC, double TDC, double zHit, unsigned int id, unsigned int strip, double t0)
Definition: TofCaliSvc.cxx:814
const double EtfTimeMC2(double ADC, double TDC, double zHit, unsigned int id, unsigned int strip, double t0)
Definition: TofCaliSvc.cxx:831
const double EtfTime2(double ADC, double TDC, double zHit, unsigned int id, unsigned int strip, double t0)
Definition: TofCaliSvc.cxx:759
const double BSigmaCluster(double zHit1, double zHit2, unsigned int id1, unsigned int id2)
Definition: TofCaliSvc.cxx:642
const double EtfVeff(unsigned int id, unsigned int strip)
Definition: TofCaliSvc.cxx:967
const double ZADC1(double qright, unsigned int id, double z)
virtual StatusCode initialize()
Definition: TofCaliSvc.cxx:62
const double BGainBackward(unsigned int id)
Definition: TofCaliSvc.cxx:957
const double BVeff(unsigned int id)
Definition: TofCaliSvc.cxx:935
const double ESigma(double rHit, unsigned int id)
Definition: TofCaliSvc.cxx:676
const int Version()
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)
Definition: TofCaliSvc.cxx:930
const int BrWest(unsigned int No)
const int RunEnd()
const double ZTDC(double tleft, double tright, unsigned int id)
Definition: TofCaliSvc.cxx:977
const double ETDelay(unsigned int id)
Definition: TofCaliSvc.cxx:364
const double EVeff(unsigned int id)
Definition: TofCaliSvc.cxx:962
const double TOffset()
Definition: TofCaliSvc.cxx:493
const double EAtten(unsigned int id)
const int Endcap(unsigned int No)
const double BTCorr2(double ADC, double zHit, unsigned int id)
Definition: TofCaliSvc.cxx:393
const int QElec()
BTofCommonCal * BTofCommon() const
const double BTCorr1(double ADC, double zHit, unsigned int id)
Definition: TofCaliSvc.cxx:377
void handle(const Incident &)
const double BTDelay1(unsigned int id)
Definition: TofCaliSvc.cxx:338
const double BTDelay2(unsigned int id)
Definition: TofCaliSvc.cxx:351
EtfCal * EtfTof(unsigned int id) const
ETofCal * ETof(unsigned int id) const
const double BSigmaCounter(double zHit, unsigned int id)
Definition: TofCaliSvc.cxx:626
double * p2
Definition: qcdloop1.h:76