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