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