BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
TofRawDataProvider.cxx
Go to the documentation of this file.
1#include "GaudiKernel/Kernel.h"
2#include "GaudiKernel/IInterface.h"
3#include "GaudiKernel/IIncidentSvc.h"
4#include "GaudiKernel/Incident.h"
5#include "GaudiKernel/IIncidentListener.h"
6#include "GaudiKernel/StatusCode.h"
7#include "GaudiKernel/SvcFactory.h"
8#include "GaudiKernel/MsgStream.h"
9#include "GaudiKernel/IDataProviderSvc.h"
10#include "GaudiKernel/SmartDataPtr.h"
11#include "GaudiKernel/DataSvc.h"
12#include "EventModel/EventHeader.h"
13#include "Identifier/Identifier.h"
14#include "Identifier/TofID.h"
15#include "TofRawEvent/TofDigi.h"
16#include "TofCaliSvc/ITofCaliSvc.h"
17#include "TofQCorrSvc/ITofQCorrSvc.h"
18#include "TofQElecSvc/ITofQElecSvc.h"
19#include "DetVerSvc/IDetVerSvc.h"
20#include "RawDataProviderSvc/TofRawDataProvider.h"
21
22#include "RawEvent/RawDataUtil.h"
23
24#include <cmath>
25// tianhl for mt
26#include "GaudiKernel/ThreadGaudi.h"
27// tianhl for mt
28
29using namespace std;
30
35
38 m_hasFilled(0)
39{}
40
41
43 RawDataProviderBase( name ),
44 m_hasFilled(0)
45{}
46
47
49 IterTofDataMap iter = m_tofDataMap.begin();
50 for( ; iter != m_tofDataMap.end(); iter++ ) {
51 delete (*iter).second;
52 }
53 m_tofDataMap.clear();
54
55 m_tofDataMapOnline.clear();
56 m_tofDataVectorOnline.clear();
57 m_tofDataMapEstime.clear();
58 m_tofDataVectorEstime.clear();
59 m_tofDataMapTof.clear();
60 m_tofDataVectorTof.clear();
61 m_tofDataMapEmc.clear();
62 m_tofDataVectorEmc.clear();
63
64 return;
65}
66
67
68StatusCode TofRawDataProvider::initialize( bool mode, ISvcLocator* pSvcLoc, IMessageSvc* pMsg ) {
69 MsgStream log( m_msgSvc, m_name );
70 RawDataProviderBase::initialize( pSvcLoc,pMsg );
71
72 // Get Detector Version Service
73 StatusCode sc_det = m_svcLocator->service("DetVerSvc", detVerSvc);
74 if( sc_det == StatusCode::SUCCESS ) {
75 log << MSG::INFO << "TofRawDataProvider Get Detector Version Service Sucessfully!" << endreq;
76 }
77 else {
78 log << MSG::ERROR << "TofRawDataProvider Can NOT Retrieve DetVerSvc instance" << endreq;
79 return StatusCode::FAILURE;
80 }
81
82 //Get TOF Calibtration Service
83 StatusCode scc = m_svcLocator->service("TofCaliSvc", tofCaliSvc);
84 if( scc == StatusCode::SUCCESS ) {
85 log << MSG::INFO << "TofRec Get Calibration Service Sucessfully!" << endreq;
86 }
87 else if(!mode) {
88 log << MSG::ERROR << "TofRec Get Calibration Service Failed !" << endreq;
89 return StatusCode::FAILURE;
90 }
91
92 //Get TOF Q Correction Service
93 StatusCode scq = m_svcLocator->service("TofQCorrSvc", tofQCorrSvc);
94 if (scq == StatusCode::SUCCESS) {
95 log << MSG::INFO << "TofRec Get Q Correction Service Sucessfully!" << endreq;
96 } else if(!mode){
97 log << MSG::ERROR << "TofRec Get Q Correction Service Failed !" << endreq;
98 return StatusCode::FAILURE;
99 }
100
101 //Get TOF Q Electronics Saturation Service
102 StatusCode sce = m_svcLocator->service("TofQElecSvc", tofQElecSvc);
103 if (sce == StatusCode::SUCCESS) {
104 log << MSG::INFO << "TofRec Get Q Electronics Calibration Service Sucessfully!" << endreq;
105 } else if(!mode){
106 log << MSG::ERROR << "TofRec Get Q Electronics Calibration Service Failed !" << endreq;
107 return StatusCode::FAILURE;
108 }
109
110 return StatusCode::SUCCESS;
111}
112
113
114void TofRawDataProvider::handle(const Incident& inc){
115 MsgStream log( m_msgSvc, m_name );
116 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
117 if ( inc.type() == "BeginEvent" ){
118 log << MSG::DEBUG << "Begin Event" << endreq;
119 IterTofDataMap iter = m_tofDataMap.begin();
120 for( ; iter != m_tofDataMap.end(); iter++ ) {
121 delete (*iter).second;
122 }
123 IterTofDataMap iterOnline = m_tofDataMapOnline.begin();
124 for( ; iterOnline != m_tofDataMapOnline.end(); iterOnline++ ) {
125 delete (*iterOnline).second;
126 }
127 m_tofDataMap.clear();
128 m_tofDataMapOnline.clear();
129 m_tofDataVectorOnline.clear();
130 m_tofDataMapEstime.clear();
131 m_tofDataVectorEstime.clear();
132 m_tofDataMapTof.clear();
133 m_tofDataVectorTof.clear();
134 m_tofDataMapEmc.clear();
135 m_tofDataVectorEmc.clear();
136
137 m_hasFilled = false;
138 }
139 return;
140}
141
142
143// tofDataMapFull includes all possible combinations.
145
146 MsgStream log(m_msgSvc, m_name);
147 log << MSG::INFO << "TofRawDataProvider::tofDataMapFull()" << endreq;
148
149 if( !m_tofDataMap.empty() ) {
150
151 log << MSG::WARNING << "TofRawDataProvider::tofDataMapFull: m_tofDataMap is NOT empty!" << endreq;
152
153 IterTofDataMap iter = m_tofDataMap.begin();
154 for( ; iter != m_tofDataMap.end(); iter++ ) {
155 delete (*iter).second;
156 }
157 m_tofDataMap.clear();
158 }
159 // tianhl for mt
160 std::string evtDataSvc_name("EventDataSvc");
161 if(isGaudiThreaded(m_name)){
162 evtDataSvc_name += getGaudiThreadIDfromName(m_name);
163 }
164 // tianhl for mt
165
166 IDataProviderSvc* eventSvc;
167 StatusCode sc = m_svcLocator->service( evtDataSvc_name.c_str(),eventSvc, true );
168 if( !sc.isSuccess() ) {
169 log << MSG::FATAL << "TofRawDataProvider::tofDataMapFull: ERROR Could not load EventDataSvc" << endreq;
170 return;
171 }
172
173 // Event Header
174 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc,"/Event/EventHeader");
175 if( !eventHeader ) {
176 log << MSG::FATAL << "TofRawDataProvider could not find Event Header!" << endreq;
177 return;
178 }
179 m_run = eventHeader->runNumber();
180 m_event = eventHeader->eventNumber();
181
182 bool mc = ( m_run < 0 ) ? true:false;
183 bool qCorr = bool( tofCaliSvc->QCorr() );
184 qCorr = qCorr && (!mc);
185 bool qElec = bool( tofCaliSvc->QElec() );
186 bool misLable = bool( tofCaliSvc->MisLable() );
187 misLable = ( !mc && misLable );
188
189 int identmp = -1;
190 vector<int> deadId;
191 for( unsigned int i=0; i<5; i++ ) {
192 identmp = tofCaliSvc->BrEast(i);
193 if( identmp != 0x2fffffff ) {
194 deadId.push_back( identmp );
195 }
196 identmp = tofCaliSvc->BrWest(i);
197 if( identmp != 0x2fffffff ) {
198 deadId.push_back( identmp );
199 }
200 identmp = tofCaliSvc->Endcap(i);
201 if( identmp != 0x2fffffff ) {
202 deadId.push_back( identmp );
203 }
204 }
205
206 // get TDS data in a common class
207 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc,"/Event/Digi/TofDigiCol");
208 if( !tofDigiCol ) {
209 log << MSG::WARNING << "TofRawDataProvider::tofDataMapFull: Could not find Tof Digi Data!" << endreq;
210 return;
211 }
212
213 int qnumber = 0;
214 int tnumber = 0;
215
216 std::vector<Adc*> chargeVec;
217 std::vector<Tdc*> timeVec;
218
219 TofDigiCol::iterator iter = tofDigiCol->begin();
220 for( ; iter != tofDigiCol->end(); iter++ ) {
221 Identifier iden = (*iter)->identify();
222 unsigned int iden_value = iden.get_value();
223
224 bool sameId = false;
225 vector<int>::iterator iter_dead = deadId.begin();
226 for( ; iter_dead != deadId.end(); iter_dead++ ) {
227 if( iden_value == (*iter_dead) ) {
228 sameId = true;
229 break;
230 }
231 }
232 if( sameId ) {
233 if( mc ) { continue; }
234 else {
235 std::string bore;
236 if( (TofID::barrel_ec(iden))==1 ) { bore=string("Barrel");}
237 else if( (TofID::barrel_ec(iden))==0 ) { bore=string("East Endcap"); }
238 else if( (TofID::barrel_ec(iden))==2 ) { bore=string("West Endcap"); }
239 else if( (TofID::barrel_ec(iden))==3 ) { bore=string("ETF(MRPC)"); }
240
241 log << MSG::ERROR << "TofRawDataProvider::tofDataMapFull: Dead Channel Number is not Correct, please check TOF Calibration Constants! " << bore << endreq;
242 }
243 }
244
245 if( TofID::is_scin(iden) && !(TofID::is_barrel(iden) ) && (TofID::end(iden))==1 ) continue;
246
247 unsigned int overflow = (*iter)->getOverflow();
248 if( TofID::is_scin(iden) && ( ( overflow & 0xfe000000 ) == 0xfe000000 ) ) continue;
249
250
251 // if( ( m_detVerSvc->phase() == 1 ) && TofID::is_mrpc( iden ) ) continue;
252 // if( ( m_detVerSvc->phase() >= 3 ) && TofID::is_scin( iden ) && !( TofID::is_barrel( iden ) ) ) continue;;
253
254 // for 150203 data, 92Scin + 2MRPC
255 // if( !mc && ( m_detVerSvc->phase() == 2 ) && TofID::is_mrpc( iden ) ) {
256 if( m_run>=40203 && m_run<=43253 && TofID::is_mrpc( iden ) ) {
257 // ETF Module 36 ==> 44
258 if( ( iden_value & 0x2fffffe0 ) == 0x2000c800 ) {
259 iden_value = 0x2000c900 + ( iden_value & 0x1f );
260 iden = Identifier( iden_value );
261 }
262 // ETF Module 37 ==> 43
263 if( ( iden_value & 0x2fffffe0 ) == 0x2000c820 ) {
264 iden_value = 0x2000c8e0 + ( iden_value & 0x1f );
265 iden = Identifier( iden_value );
266 }
267 }
268 // end 150203 data
269
270 // overflow 0x 1 1 1 1 1 1
271 // no Q T / multi Q T / overflow Q T
272
273 bool multiQ = ( ( overflow & 0x8 ) != 0 );
274 bool multiT = ( ( overflow & 0x4 ) != 0 );
275
276 unsigned int tdcChannel = (*iter)->getTimeChannel();
277 unsigned int adcChannel = (*iter)->getChargeChannel();
278 if( TofID::is_scin(iden) && ( ( overflow & 0x2 ) != 0 ) ) {
279 adcChannel = ( adcChannel | 0x80000 );
280 }
281
282 if( (adcChannel&0x7fffffff) != 0x7fffffff ) {
283 Adc* adc = new Adc;
284 if( qCorr ) adc->setCorr();
285 if( qElec ) adc->setElec();
286
287 // for 150203 data, 92Scin + 2MRPC
288 // if( !mc && ( m_detVerSvc->phase() == 2 ) && TofID::is_mrpc( iden ) ) {
289 if( m_run>=40203 && m_run<=43253 && TofID::is_mrpc( iden ) ) {
290 adcChannel += 0x18000;
291 }
292 // end 150203 data
293
294 adc->setValue( iden, adcChannel );
295 qnumber++;
296 adc->setNumber( qnumber );
297 chargeVec.push_back( adc );
298 }
299
300 if( tdcChannel != 0x7fffffff ) {
301 Tdc* tdc = new Tdc;
302
303 // for 150203 data, 92Scin + 2MRPC
304 // if( !mc && ( m_detVerSvc->phase(0 == 2 ) && TofID::is_mrpc( iden ) ) {
305 if( m_run>=40203 && m_run<=43253 && TofID::is_mrpc( iden ) ) {
306 tdcChannel += 0x18000;
307 }
308 // end 150203 data
309
310 tdc->setValue( tdcChannel );
311 tnumber++;
312 tdc->setNumber( tnumber );
313 timeVec.push_back( tdc );
314 }
315
316 if( multiT || multiQ ) {
317 TofDigiCol::iterator iter_next = iter + 1;
318 if( iter_next != tofDigiCol->end() ) {
319 unsigned int idenNext_value = ((*iter_next)->identify()).get_value();
320 if( iden_value == idenNext_value ) continue;
321 }
322 }
323
324 qnumber = 0;
325 tnumber = 0;
326
327 std::vector<PmtData*> pmtDataVec;
328 if( TofID::is_scin( iden ) ) {
329 std::vector<Tdc*>::iterator iter_t = timeVec.begin();
330 for( ; iter_t != timeVec.end(); iter_t++ ) {
331 int tclock = (*iter_t)->clock();
332 PmtData* pmt = new PmtData;
333 pmt->setIdentify( iden.get_value() );
334 pmt->setTdc( (*iter_t) );
335 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
336 for( ; iter_q != chargeVec.end(); iter_q++ ) {
337 if( (*iter_q)->times() != -1 ) { continue; }
338 int qclock = (*iter_q)->clock();
339 if( abs(tclock-qclock)<2 ) {
340 if( ( pmt->quality() & 0x2 ) != 0 ) { // pmt has Q
341 if( (*iter_q)->value() > pmt->adc() ) {
342 pmt->qtimesmm();
343 pmt->setAdc( (*iter_q) );
344 }
345 }
346 else { // pmt has no Q
347 pmt->setAdc( (*iter_q) );
348 }
349 }
350 }
351 pmtDataVec.push_back( pmt );
352 }
353
354 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
355 for( ; iter_q != chargeVec.end(); iter_q++ ) {
356 if( (*iter_q)->times() != -1 ) { continue; }
357 PmtData* pmt = new PmtData;
358 pmt->setIdentify( iden.get_value() );
359 pmt->setAdc( (*iter_q) );
360 pmtDataVec.push_back( pmt );
361 }
362
363 }
364
365 if( TofID::is_mrpc( iden ) ) {
366 std::vector<Tdc*>::iterator iter_t = timeVec.begin();
367 for( ; iter_t != timeVec.end(); iter_t++ ) {
368 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
369 for( ; iter_q != chargeVec.end(); iter_q++ ) {
370 if( ( (*iter_q)->qtc() - (*iter_t)->value() ) > totForward && ( (*iter_q)->qtc() - (*iter_t)->value() ) < totBackward ) {
371 PmtData* pmt = new PmtData;
372 pmt->setIdentify( iden.get_value() );
373 pmt->setTdc( (*iter_t) );
374 pmt->setAdc( (*iter_q) );
375 pmtDataVec.push_back( pmt );
376 }
377 }
378 if( (*iter_t)->times() == -1 ) {
379 PmtData* pmt = new PmtData;
380 pmt->setTdc( (*iter_t) );
381 pmtDataVec.push_back( pmt );
382 }
383 }
384
385 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
386 for( ; iter_q != chargeVec.end(); iter_q++ ) {
387 if( (*iter_q)->times() != -1 ) { continue; }
388 PmtData* pmt = new PmtData;
389 pmt->setIdentify( iden.get_value() );
390 pmt->setAdc( (*iter_q) );
391 pmtDataVec.push_back( pmt );
392 }
393
394 }
395
396 chargeVec.clear();
397 timeVec.clear();
398
399 unsigned int iden_value_key = (iden_value & 0xfffffffe );
400 if( TofID::is_scin( iden ) ) {
401 int barrel_ec = TofID::barrel_ec( iden );
402 // int layer = TofID::layer( iden );
403 int tofid = TofID::phi_module( iden );
404 int end = TofID::end( iden );
405 if( ( barrel_ec == 0 ) || ( barrel_ec == 2 ) ) {
406 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
407 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
408 TofData* tof = new TofData;
409 if( misLable ) {
410 tof->setMisLable();
411 if( barrel_ec==2 && tofid==42 ) {
412 unsigned int iden91 = TofID::getIntID( 2, 0, 91-48, 0 );
413 iden_value_key = iden91;
414 iden = TofID::cell_id( iden91 );
415 }
416 if( barrel_ec==2 && tofid==43 ) {
417 unsigned int iden90 = TofID::getIntID( 2, 0, 90-48, 0 );
418 iden_value_key = iden90;
419 iden = TofID::cell_id( iden90 );
420 }
421 }
422 tof->setIdentify( iden );
423 tof->setForward( (*iter_pmt) );
424 tof->setTMatched( true );
425 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
426 }
427 }
428 else if( barrel_ec == 1 ) {
429 unsigned int count = m_tofDataMap.count( iden_value_key );
430 if( count == 0 ) {
431 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
432 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
433 TofData* tof = new TofData;
434 tof->setIdentify( iden );
435 if( end == 0 ) {
436 tof->setForward( (*iter_pmt) );
437 }
438 else {
439 tof->setBackward( (*iter_pmt) );
440 }
441 tof->setTMatched( true );
442 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
443 }
444 }
445 else {
446 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMap.equal_range( iden_value_key );
447 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
448 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
449 bool used = false;
450 IterTofDataMap iter = range.first;
451 for( unsigned int tofDataNumber = 0; tofDataNumber < count; tofDataNumber++, iter++ ) {
452
453 bool matched = false;
454 if( end == 0 ) { // east, forward
455 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) { // pmt has east time
456 if( ( ((*iter).second)->quality() & 0x1 ) != 0 ) { // tofmap has west time
457 double time1 = (*iter_pmt)->tdc();
458 double time2 = ((*iter).second)->tdc2();
459 matched = ( abs(time1-time2)<timeDiff );
460 }
461 else { // tofmap has no west time
462 if( ( ((*iter).second)->quality() & 0x2 ) != 0 ) { // tofmap has no west time, but west charge
463 double time1 = (*iter_pmt)->tclock();
464 double time2 = (*iter_pmt)->qclock();
465 double time3 = ((*iter).second)->qclock2();
466 matched = ( ( abs(time1-time3)<=tClockDiff ) || ( abs(time2-time3)<=tClockDiff ) );
467 }
468 }
469 }
470 else { // pmt has no east time
471 if( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) { // pmt has no east time, but east charge
472 if( ( ((*iter).second)->quality() & 0x1 ) != 0 ) { // tofmap has west time
473 if( ( ( ((*iter).second)->quality() & 0x2 ) != 0 ) ) { // tofmap has west time and west charge
474 double time1 = (*iter_pmt)->qclock();
475 double time2 = ((*iter).second)->tclock2();
476 double time3 = ((*iter).second)->qclock2();
477 matched = ( ( abs(time1-time2)<=tClockDiff ) || ( abs(time1-time3)<=tClockDiff ) );
478 }
479 }
480 else { // tofmap has no west time, but west charge
481 if( ( ( ((*iter).second)->quality() & 0x2 ) != 0 ) ) {
482 double time1 = (*iter_pmt)->qclock();
483 double time2 = ((*iter).second)->qclock2();
484 matched = ( abs(time1-time2)<=tClockDiff );
485 }
486 }
487 }
488 }
489
490 if( matched ) {
491 used = true;
492 if( ( ( (*iter).second)->quality() & 0xc ) == 0 ) {
493 ((*iter).second)->setForward( (*iter_pmt) );
494 }
495 else {
496 TofData* tof = new TofData;
497 tof->setIdentify( iden );
498 tof->setForward( (*iter_pmt) );
499 tof->setBackward( ((*iter).second)->backward() );
500 tof->setTMatched( true );
501 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
502 }
503 }
504
505 } // end east, forward
506 else { // west, backward
507 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) { // pmt has west time
508 if( ( ((*iter).second)->quality() & 0x4 ) != 0 ) { // tofmap has east time
509 double time1 = (*iter_pmt)->tdc();
510 double time2 = ((*iter).second)->tdc1();
511 matched = ( abs(time1-time2)<timeDiff );
512 }
513 else { // tofmap has no east time
514 if( ( ((*iter).second)->quality() & 0x8 ) != 0 ) { // tofmap has no east time, but east charge
515 double time1 = (*iter_pmt)->tclock();
516 double time2 = (*iter_pmt)->qclock();
517 double time3 = ((*iter).second)->qclock1();
518 matched = ( ( abs(time1-time3)<=tClockDiff ) || ( abs(time2-time3)<=tClockDiff ) );
519 }
520 }
521 }
522 else { // pmt has no west time
523 if( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) { // pmt has no west time, but west charge
524 if( ( ((*iter).second)->quality() & 0x4 ) != 0 ) { // tofmap has east time
525 if( ( ( ((*iter).second)->quality() & 0x8 ) != 0 ) ) { // tofmap has east time and east charge
526 double time1 = (*iter_pmt)->qclock();
527 double time2 = ((*iter).second)->tclock1();
528 double time3 = ((*iter).second)->qclock1();
529 matched = ( ( abs(time1-time2)<=tClockDiff ) || ( abs(time1-time3)<=tClockDiff ) );
530 }
531 else {
532 }
533 }
534 else { // tofmap has no west time, but west charge
535 if( ( ( ((*iter).second)->quality() & 0x8 ) != 0 ) ) {
536 double time1 = (*iter_pmt)->qclock();
537 double time2 = ((*iter).second)->qclock1();
538 matched = ( abs(time1-time2)<=tClockDiff );
539 }
540 }
541 }
542 }
543
544 if( matched ) {
545 used = true;
546 if( ( ( (*iter).second)->quality() & 0x3 ) == 0 ) {
547 ((*iter).second)->setBackward( (*iter_pmt) );
548 }
549 else {
550 TofData* tof = new TofData;
551 tof->setIdentify( iden );
552 tof->setForward( ((*iter).second)->forward() );
553 tof->setBackward( (*iter_pmt) );
554 tof->setTMatched( true );
555 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
556 }
557 }
558 }
559 }
560
561 if( ! used ) {
562 TofData* tof = new TofData;
563 tof->setIdentify( iden );
564 if( end == 0 ) {
565 tof->setForward( (*iter_pmt) );
566 }
567 else {
568 tof->setBackward( (*iter_pmt) );
569 }
570 tof->setTMatched( true );
571 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
572 }
573 }
574 }
575 }
576 }
577 // mrpc endcap tof
578 if( TofID::is_mrpc( iden ) ) {
579 // int barrel_ec = TofID::barrel_ec( iden );
580 int endcap = TofID::endcap( iden );
581 int tofid = TofID::module( iden );
582 int strip = TofID::strip( iden );
583 int end = TofID::end( iden );
584
585 unsigned int count = m_tofDataMap.count( iden_value_key );
586 if( count == 0 ) {
587 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
588 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
589 TofData* tof = new TofData;
590 tof->setIdentify( iden );
591 if( end == 0 ) {
592 tof->setForward( (*iter_pmt) );
593 }
594 else {
595 tof->setBackward( (*iter_pmt) );
596 }
597 tof->setTMatched( true );
598 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
599 }
600 }
601 else {
602 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMap.equal_range( iden_value_key );
603 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
604 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
605 bool used = false;
606 IterTofDataMap iter = range.first;
607 for( unsigned int tofDataNumber = 0; tofDataNumber < count; tofDataNumber++, iter++ ) {
608 bool matched = false;
609 if( end == 0 ) { // east, forward
610 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) { // pmt has east time
611 if( ( ((*iter).second)->quality() & 0x1 ) != 0 ) { // tofmap has west time
612 double time1 = (*iter_pmt)->tdc();
613 double time2 = ((*iter).second)->tdc2();
614 matched = ( abs(time1-time2)<timeDiffMRPC );
615 if( endcap==0 && tofid==13 && strip==5 ) { matched = ( abs(time1-time2)<(100+timeDiffMRPC) ); }
616 }
617 }
618 /*
619 else {
620 if( ( ((*iter).second)->quality() & 0x2 ) != 0 ) {
621 double time1 = (*iter_pmt)->tdc();
622 double time2 = ((*iter).second)->qtc2();
623 matched = ( abs(time1-time2)<timeDiffMRPC );
624 }
625 }
626 }
627 else {
628 if( ( ((*iter).second)->quality() & 0x1 ) != 0 ) {
629 double time1 = (*iter_pmt)->qtc();
630 double time2 = ((*iter).second)->tdc2();
631 matched = ( abs(time1-time2)<timeDiffMRPC );
632 }
633 else {
634 if( ( ((*iter).second)->quality() & 0x2 ) != 0 ) {
635 double time1 = (*iter_pmt)->qtc();
636 double time2 = ((*iter).second)->qtc2();
637 matched = ( abs(time1-time2)<timeDiffMRPC );
638 }
639 }
640 }
641
642 if( ( (*iter_pmt)->quality() & 0x3 ) == 0x3 ) { // pmt has east time
643 if( ( ((*iter).second)->quality() & 0x3 ) == 0x3 ) { // tofmap has west time
644 double time1 = (*iter_pmt)->tdc();
645 double time2 = ((*iter).second)->tdc2();
646 matched = ( abs(time1-time2)<timeDiffMRPC );
647 }
648 }
649 */
650 if( matched ) {
651 used = true;
652 if( ( ( (*iter).second)->quality() & 0xc ) == 0 ) {
653 ((*iter).second)->setForward( (*iter_pmt) );
654 }
655 else {
656 TofData* tof = new TofData;
657 tof->setIdentify( iden );
658 tof->setForward( (*iter_pmt) );
659 tof->setBackward( ((*iter).second)->backward() );
660 tof->setTMatched( true );
661 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
662 }
663 }
664 } // end east, forward
665 else { // west, backward
666 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) { // pmt has west time
667 if( ( ((*iter).second)->quality() & 0x4 ) != 0 ) { // tofmap has east time
668 double time1 = (*iter_pmt)->tdc();
669 double time2 = ((*iter).second)->tdc1();
670 matched = ( abs(time1-time2)<timeDiffMRPC );
671 if( endcap==0 && tofid==13 && strip==5 ) { matched = ( abs(time1-time2)<(100+timeDiffMRPC) ); }
672 }
673 }
674 /*
675 else {
676 if( ( ((*iter).second)->quality() & 0x8 ) != 0 ) {
677 double time1 = (*iter_pmt)->tdc();
678 double time2 = ((*iter).second)->qtc1();
679 matched = ( abs(time1-time2)<timeDiffMRPC );
680 }
681 }
682 }
683 else {
684 if( ( ((*iter).second)->quality() & 0x4 ) != 0 ) {
685 double time1 = (*iter_pmt)->qtc();
686 double time2 = ((*iter).second)->tdc1();
687 matched = ( abs(time1-time2)<timeDiffMRPC );
688 }
689 else {
690 if( ( ((*iter).second)->quality() & 0x8 ) != 0 ) {
691 double time1 = (*iter_pmt)->qtc();
692 double time2 = ((*iter).second)->qtc1();
693 matched = ( abs(time1-time2)<timeDiffMRPC );
694 }
695 }
696 }
697
698 if( ( (*iter_pmt)->quality() & 0x3 ) == 0x3 ) { // pmt has west time
699 if( ( ((*iter).second)->quality() & 0xc ) == 0xc ) { // tofmap has east time
700 double time1 = (*iter_pmt)->tdc();
701 double time2 = ((*iter).second)->tdc1();
702 matched = ( abs(time1-time2)<timeDiffMRPC );
703 }
704 }
705 */
706 if( matched ) {
707 used = true;
708 if( ( ( (*iter).second)->quality() & 0x3 ) == 0 ) {
709 ((*iter).second)->setBackward( (*iter_pmt) );
710 }
711 else {
712 TofData* tof = new TofData;
713 tof->setIdentify( iden );
714 tof->setForward( ((*iter).second)->forward() );
715 tof->setBackward( (*iter_pmt) );
716 tof->setTMatched( true );
717 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
718 }
719 }
720 }
721 }
722
723 if( ! used ) {
724 TofData* tof = new TofData;
725 tof->setIdentify( iden );
726 if( end == 0 ) {
727 tof->setForward( (*iter_pmt) );
728 }
729 else {
730 tof->setBackward( (*iter_pmt) );
731 }
732 tof->setTMatched( true );
733 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
734 }
735 }
736 }
737 }
738
739 pmtDataVec.clear();
740
741 }
742
743 return;
744
745}//close tofDataMapFull
746
747
748// onlineMode only T is combined, no Q reserved
750
751 MsgStream log(m_msgSvc, m_name);
752 log << MSG::INFO << "TofRawDataProvider::tofDataMapOnlineMode()" << endreq;
753
754 if( ! m_tofDataMapOnline.empty() ) {
755 if(control){
756 IterTofDataMap iter = m_tofDataMapOnline.begin();
757 for( ; iter != m_tofDataMapOnline.end(); iter++ ) {
758 delete (*iter).second;
759 }
760 m_tofDataMapOnline.clear();
761 }
762 else return m_tofDataMapOnline;
763 }
764 // tianhl for mt
765 std::string evtDataSvc_name("EventDataSvc");
766 if(isGaudiThreaded(m_name)){
767 evtDataSvc_name += getGaudiThreadIDfromName(m_name);
768 }
769 // tianhl for mt
770
771 IDataProviderSvc* eventSvc;
772 StatusCode sc = m_svcLocator->service( evtDataSvc_name.c_str(), eventSvc, true );
773 if( !sc.isSuccess() ) {
774 log << MSG::FATAL << "TofRawDataProvider::tofDataMapOnlineMode(): ERROR Could not load EventDataSvc" << endreq;
775 return m_tofDataMapOnline;
776 }
777
778 // get TDS data in a common class
779 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc,"/Event/Digi/TofDigiCol");
780 if( !tofDigiCol ) {
781 log << MSG::WARNING << "TofRawDataProvider::tofDataMapOnlineMode(): Could not find Tof Digi Data!" << endreq;
782 return m_tofDataMapOnline;
783 }
784
785 TofDigiCol::iterator iter = tofDigiCol->begin();
786 for( ; iter != tofDigiCol->end(); iter++ ) {
787 unsigned int overflow = (*iter)->getOverflow();
788 if( ( overflow & 0xfe000000 ) == 0xfe000000 ) continue;
789 // overflow 0x 1 1 1 1 1 1
790 // no Q T / multi Q T / overflow Q T
791
792 bool noT = ( ( overflow & 0x10 ) != 0 );
793 // bool multiQ = ( ( overflow & 0x8 ) != 0 );
794 // bool multiT = ( ( overflow & 0x4 ) != 0 );
795 if( noT ) continue;
796
797 Identifier iden = (*iter)->identify();
798 unsigned int iden_value = iden.get_value();
799 int barrel_ec = TofID::barrel_ec(iden);
800 int id = TofID::phi_module(iden);
801 int end = TofID::end(iden);
802
803 unsigned int tdcChannel = (*iter)->getTimeChannel();
804 if( tdcChannel == 0x7fffffff ) continue;
805
806 Tdc* tdc = new Tdc;
807 tdc->setValue( tdcChannel );
808 PmtData* pmt = new PmtData;
809 pmt->setTdc( tdc );
810
811 unsigned int iden_value_key = ( iden_value & 0xfffffffe );
812 if( barrel_ec == 0 || barrel_ec == 2 ) {
813 TofData* tof = new TofData;
814 tof->setIdentify( iden );
815 tof->setForward( pmt );
816 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
817 }
818 else if( barrel_ec == 1 || barrel_ec == 3 ) {
819 unsigned int count = m_tofDataMapOnline.count( iden_value_key );
820
821 if( count == 0 ) {
822 TofData* tof = new TofData;
823 tof->setIdentify( iden );
824 if( end == 0 ) {
825 tof->setForward( pmt );
826 }
827 else {
828 tof->setBackward( pmt );
829 }
830 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
831 }
832 else {
833 bool used = false;
834 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMapOnline.equal_range( iden_value_key );
835 IterTofDataMap iter = range.first;
836 for( unsigned int i=0; i<count; i++, iter++ ) {
837 if( ( end == 0 ) && ( ( ( (*iter).second)->quality() & 0x1 ) != 0 ) ) {
838 double time1 = pmt->tdc();
839 double time2 = ((*iter).second)->tdc2();
840 if( ( TofID::is_scin( iden ) && abs(time1-time2)<timeDiff ) || ( TofID::is_mrpc( iden ) && abs(time1-time2)<timeDiffMRPC ) ) {
841 used = true;
842 if( ( ( (*iter).second)->quality() & 0x4 ) == 0 ) {
843 ((*iter).second)->setForward( pmt );
844 }
845 else {
846 TofData* tof = new TofData;
847 tof->setIdentify( iden );
848 tof->setForward( pmt );
849 tof->setBackward( ((*iter).second)->backward() );
850 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
851 }
852 }
853 }
854 else if( ( end == 1 ) && ( ( ((*iter).second)->quality() & 0x4 ) != 0 ) ) {
855 double time1 = ((*iter).second)->tdc1();
856 double time2 = pmt->tdc();
857
858 if( ( TofID::is_scin( iden ) && abs(time1-time2)<timeDiff ) || ( TofID::is_mrpc( iden ) && abs(time1-time2)<timeDiffMRPC ) ) {
859 used = true;
860 if( ( ( (*iter).second)->quality() & 0x1 ) == 0 ) {
861 ((*iter).second)->setBackward( pmt );
862 }
863 else {
864 TofData* tof = new TofData;
865 tof->setIdentify( iden );
866 tof->setForward( ((*iter).second)->forward() );
867 tof->setBackward( pmt );
868 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
869 }
870 }
871 }
872 }
873 if( ! used ) {
874 TofData* tof = new TofData;
875 tof->setIdentify( iden );
876 if( end == 0 ) {
877 tof->setForward( pmt );
878 }
879 else {
880 tof->setBackward( pmt );
881 }
882 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
883 }
884 }
885 }
886 }
887
888 return m_tofDataMapOnline;
889
890}
891
892
894
895 MsgStream log(m_msgSvc, m_name);
896 log << MSG::INFO << "TofRawDataProvider::tofDataVectorOnlineMode()" << endreq;
897
898 if( m_tofDataVectorOnline.size() != 0 ) {
899 if(!control) return m_tofDataVectorOnline;
900 else m_tofDataVectorOnline.clear();
901 }
903 IterTofDataMap iter = tofRawDataMap.begin();
904 for( ; iter != tofRawDataMap.end(); iter++ ) {
905 m_tofDataVectorOnline.push_back( iter->second );
906 }
907
908 return m_tofDataVectorOnline;
909}
910
911
912// Event Start Time, only Time is required.
914
915 if( !m_hasFilled ) {
917 m_hasFilled = true;
918 }
919
920 if( !m_tofDataMapEstime.empty() ) {
921 m_tofDataMapEstime.clear();
922 }
923
924 IterTofDataMap iter = m_tofDataMap.begin();
925 for( ; iter != m_tofDataMap.end(); iter++ ) {
926 if( ( ( ((*iter).second)->quality() & 0x5 ) != 0 ) && ((*iter).second)->tmatched() ) {
927 m_tofDataMapEstime.insert( make_pair( (*iter).first, (*iter).second ) );
928 }
929 }
930
931 iter = m_tofDataMapEstime.begin();
932 while( iter != m_tofDataMapEstime.end() ) {
933 unsigned int iden_value = (*iter).first;
934 unsigned int count = m_tofDataMapEstime.count( iden_value );
935 for( unsigned int i=0; i != count; i++, iter++ ) {
936 ((*iter).second)->setTimes( count );
937 }
938 }
939
940 return m_tofDataMapEstime;
941}
942
943
945 if( m_tofDataVectorEstime.size() != 0 ) return m_tofDataVectorEstime;
946
949 for( ; iter != tofDataMapEstime.end(); iter++ ) {
950 m_tofDataVectorEstime.push_back( iter->second );
951 }
952 return m_tofDataVectorEstime;
953}
954
955
956// TOF reconstruction, both time and charge are required
958
959 if( !m_hasFilled ) {
961 m_hasFilled = true;
962 }
963
964 if( !m_tofDataMapTof.empty() ) {
965 m_tofDataMapTof.clear();
966 }
967
968 IterTofDataMap iter = m_tofDataMap.begin();
969 for( ; iter != m_tofDataMap.end(); iter++ ) {
970 if( ( ( ((*iter).second)->quality() & 0xc ) == 0xc ) || ( ( ((*iter).second)->quality() & 0x3 ) == 0x3 ) ) {
971 if( estime > 1.0e-6 ) {
972 double tdc1 = ((*iter).second)->tdc1();
973 double tdc2 = ((*iter).second)->tdc2();
974 bool forward = ( ( ( estime - tdc1 ) < timeBackward ) && ( ( tdc1 - estime ) < timeForward ) );
975 bool backward = ( ( ( estime - tdc2 ) < timeBackward ) && ( ( tdc2 - estime ) < timeForward ) );
976 if( TofID::is_mrpc( TofID::cell_id((*iter).first) ) && m_run>=43680 && m_run<43809 ) {
977 double offset = -264.0;
978 forward = ( ( ( estime - tdc1 ) < ( timeBackward - offset ) ) && ( ( tdc1 - estime ) < ( timeForward + offset ) ) );
979 backward = ( ( ( estime - tdc2 ) < ( timeBackward + offset ) ) && ( ( tdc2 - estime ) < ( timeForward + offset ) ) );
980 }
981 if( !forward && !backward ) continue;
982 }
983 m_tofDataMapTof.insert( make_pair( (*iter).first, (*iter).second ) );
984 }
985 }
986
987 iter = m_tofDataMapTof.begin();
988 while( iter != m_tofDataMapTof.end() ) {
989 unsigned int iden_value = (*iter).first;
990 unsigned int count = m_tofDataMapTof.count( iden_value );
991 for( unsigned int i=0; i != count; i++, iter++ ) {
992 ((*iter).second)->setTimes( count );
993 }
994 }
995
996 return m_tofDataMapTof;
997}
998
999
1001 if( m_tofDataVectorTof.size() != 0 ) {
1002 m_tofDataVectorTof.clear();
1003 }
1004
1007 for( ; iter != tofDataMapTof.end(); iter++ ) {
1008 m_tofDataVectorTof.push_back( iter->second );
1009 }
1010 return m_tofDataVectorTof;
1011}
1012
1013
1014// EMC reconstruction, only charge are required
1016
1017 if( !m_hasFilled ) {
1019 m_hasFilled = true;
1020 }
1021
1022 if( !m_tofDataMapEmc.empty() ) {
1023 m_tofDataMapEmc.clear();
1024 }
1025
1026 IterTofDataMap iter = m_tofDataMap.begin();
1027 for( ; iter != m_tofDataMap.end(); iter++ ) {
1028 if( ( ((*iter).second)->quality() & 0xa ) != 0 ) {
1029
1030 if( estime > 1.0e-6 ) {
1031 int t0clock = static_cast<int>(estime/24.0);
1032 int clock1 = ((*iter).second)->qclock1();
1033 int clock2 = ((*iter).second)->qclock2();
1034 bool forward = ( ( ( t0clock - clock1 ) < tClockBackward ) && ( ( clock1 - t0clock ) < tClockForward ) );
1035 bool backward = ( ( ( t0clock - clock2 ) < tClockBackward ) && ( ( clock2 - t0clock ) < tClockForward ) );
1036 if( TofID::is_mrpc( TofID::cell_id((*iter).first) ) && m_run>=43680 && m_run<43809 ) {
1037 double offset = -11.0;
1038 forward = ( ( ( t0clock - clock1 ) < ( tClockBackward -offset ) ) && ( ( clock1 - t0clock ) < ( tClockForward + offset ) ) );
1039 backward = ( ( ( t0clock - clock2 ) < ( tClockBackward - offset ) ) && ( ( clock2 - t0clock ) < ( tClockForward + offset ) ) );
1040 }
1041 if( !forward && !backward ) continue;
1042 }
1043
1044 m_tofDataMapEmc.insert( make_pair( (*iter).first, (*iter).second ) );
1045 }
1046 }
1047
1048 iter = m_tofDataMapEmc.begin();
1049 while( iter != m_tofDataMapEmc.end() ) {
1050 unsigned int iden_value = (*iter).first;
1051 unsigned int count = m_tofDataMapEmc.count( iden_value );
1052 for( unsigned int i=0; i != count; i++, iter++ ) {
1053 ((*iter).second)->setTimes( count );
1054 }
1055 }
1056
1057 return m_tofDataMapEmc;
1058}
1059
1060
1062 if( m_tofDataVectorEmc.size() != 0 ) {
1063 m_tofDataVectorEmc.clear();
1064 }
1065
1068 for( ; iter != tofDataMapEmc.end(); iter++ ) {
1069 m_tofDataVectorEmc.push_back( iter->second );
1070 }
1071 return m_tofDataVectorEmc;
1072}
std::multimap< unsignedint, TofData * >::iterator IterTofDataMap
DOUBLE_PRECISION count[3]
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
ITofQElecSvc * tofQElecSvc
ITofQCorrSvc * tofQCorrSvc
ITofQElecSvc * tofQElecSvc
IDetVerSvc * detVerSvc
ITofQCorrSvc * tofQCorrSvc
ITofCaliSvc * tofCaliSvc
void setValue(Identifier identify, int value)
Definition: TofData.cxx:77
virtual const int BrWest(unsigned int No)=0
virtual const int QElec()=0
virtual const int BrEast(unsigned int No)=0
virtual const int QCorr()=0
virtual const int MisLable()=0
virtual const int Endcap(unsigned int No)=0
void setAdc(Adc *adc)
Definition: TofData.cxx:468
double tdc()
Definition: TofData.cxx:340
void qtimesmm()
Definition: TofData.cxx:378
double adc()
Definition: TofData.cxx:293
void setTdc(Tdc *tdc)
Definition: TofData.cxx:478
StatusCode initialize(ISvcLocator *svcLoc=0, IMessageSvc *pMsg=0)
void setValue(int value)
Definition: TofData.cxx:49
void setForward(PmtData *pmt)
Definition: TofData.cxx:983
void setBackward(PmtData *pmt)
Definition: TofData.cxx:1001
void setIdentify(Identifier identify)
Definition: TofData.cxx:577
static int endcap(const Identifier &id)
Definition: TofID.cxx:124
static int strip(const Identifier &id)
Definition: TofID.cxx:136
static Identifier cell_id(int barrel_ec, int layer, int phi_module, int end)
For a single crystal.
Definition: TofID.cxx:143
static bool is_scin(const Identifier &id)
Definition: TofID.cxx:102
static int end(const Identifier &id)
Definition: TofID.cxx:79
static bool is_barrel(const Identifier &id)
Test for barrel.
Definition: TofID.cxx:49
static bool is_mrpc(const Identifier &id)
Definition: TofID.cxx:113
static int phi_module(const Identifier &id)
Definition: TofID.cxx:73
static int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
Definition: TofID.cxx:61
static value_type getIntID(int barrel_ec, int layer, int phi_module, int end)
Definition: TofID.cxx:178
static int module(const Identifier &id)
Definition: TofID.cxx:130
TofDataMap & tofDataMapTof(double estime=0.0)
void handle(const Incident &)
TofDataVector & tofDataVectorTof(double estime=0.0)
TofDataMap & tofDataMapOnlineMode(uint32_t control=1)
TofDataMap & tofDataMapEstime()
TofDataVector & tofDataVectorEmc(double estime=0.0)
TofDataVector & tofDataVectorEstime()
TofDataVector & tofDataVectorOnlineMode(uint32_t control=1)
StatusCode initialize(bool mode=false, ISvcLocator *svcLoc=0, IMessageSvc *pMsg=0)
TofDataMap & tofDataMapEmc(double estime=0.0)