CGEM BOSS 6.6.5.i
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"
14#include "Identifier/TofID.h"
15#include "TofRawEvent/TofDigi.h"
20
22
23#include <cmath>
24// tianhl for mt
25#include "GaudiKernel/ThreadGaudi.h"
26// tianhl for mt
27
28using namespace std;
29
33
38
39
41 RawDataProviderBase( name ),
42 m_hasFilled(0)
43{}
44
45
47 IterTofDataMap iter = m_tofDataMap.begin();
48 for( ; iter != m_tofDataMap.end(); iter++ ) {
49 delete (*iter).second;
50 }
51 m_tofDataMap.clear();
52
53 m_tofDataMapOnline.clear();
54 m_tofDataVectorOnline.clear();
55 m_tofDataMapEstime.clear();
56 m_tofDataVectorEstime.clear();
57 m_tofDataMapTof.clear();
58 m_tofDataVectorTof.clear();
59 m_tofDataMapEmc.clear();
60 m_tofDataVectorEmc.clear();
61
62 return;
63}
64
65
66StatusCode TofRawDataProvider::initialize( bool mode, ISvcLocator* pSvcLoc, IMessageSvc* pMsg ) {
67 MsgStream log( m_msgSvc, m_name );
68 RawDataProviderBase::initialize( pSvcLoc,pMsg );
69
70 //Get TOF Calibtration Service
71 StatusCode scc = m_svcLocator->service("TofCaliSvc", tofCaliSvc);
72 if (scc == StatusCode::SUCCESS) {
73 log << MSG::INFO << "TofRec Get Calibration Service Sucessfully!" << endreq;
74 } else if(!mode) {
75 log << MSG::ERROR << "TofRec Get Calibration Service Failed !" << endreq;
76 return StatusCode::FAILURE;
77 }
78
79 //Get TOF Q Correction Service
80 StatusCode scq = m_svcLocator->service("TofQCorrSvc", tofQCorrSvc);
81 if (scq == StatusCode::SUCCESS) {
82 log << MSG::INFO << "TofRec Get Q Correction Service Sucessfully!" << endreq;
83 } else if(!mode){
84 log << MSG::ERROR << "TofRec Get Q Correction Service Failed !" << endreq;
85 return StatusCode::FAILURE;
86 }
87
88 //Get TOF Q Electronics Saturation Service
89 StatusCode sce = m_svcLocator->service("TofQElecSvc", tofQElecSvc);
90 if (sce == StatusCode::SUCCESS) {
91 log << MSG::INFO << "TofRec Get Q Electronics Calibration Service Sucessfully!" << endreq;
92 } else if(!mode){
93 log << MSG::ERROR << "TofRec Get Q Electronics Calibration Service Failed !" << endreq;
94 return StatusCode::FAILURE;
95 }
96
97 return StatusCode::SUCCESS;
98}
99
100
101void TofRawDataProvider::handle(const Incident& inc){
102 MsgStream log( m_msgSvc, m_name );
103 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
104 if ( inc.type() == "BeginEvent" ){
105 log << MSG::DEBUG << "Begin Event" << endreq;
106 IterTofDataMap iter = m_tofDataMap.begin();
107 for( ; iter != m_tofDataMap.end(); iter++ ) {
108 delete (*iter).second;
109 }
110 IterTofDataMap iterOnline = m_tofDataMapOnline.begin();
111 for( ; iterOnline != m_tofDataMapOnline.end(); iterOnline++ ) {
112 delete (*iterOnline).second;
113 }
114 m_tofDataMap.clear();
115 m_tofDataMapOnline.clear();
116 m_tofDataVectorOnline.clear();
117 m_tofDataMapEstime.clear();
118 m_tofDataVectorEstime.clear();
119 m_tofDataMapTof.clear();
120 m_tofDataVectorTof.clear();
121 m_tofDataMapEmc.clear();
122 m_tofDataVectorEmc.clear();
123
124 m_hasFilled = false;
125 }
126 return;
127}
128
129
130// tofDataMapFull includes all possible combinations.
132
133 MsgStream log(m_msgSvc, m_name);
134 log << MSG::INFO << "TofRawDataProvider::tofDataMapFull()" << endreq;
135
136 if( !m_tofDataMap.empty() ) {
137
138 log << MSG::WARNING << "TofRawDataProvider::tofDataMapFull: m_tofDataMap is NOT empty!" << endreq;
139
140 IterTofDataMap iter = m_tofDataMap.begin();
141 for( ; iter != m_tofDataMap.end(); iter++ ) {
142 delete (*iter).second;
143 }
144 m_tofDataMap.clear();
145 }
146 // tianhl for mt
147 std::string evtDataSvc_name("EventDataSvc");
148 if(isGaudiThreaded(m_name)){
149 evtDataSvc_name += getGaudiThreadIDfromName(m_name);
150 }
151 // tianhl for mt
152
153 IDataProviderSvc* eventSvc;
154 StatusCode sc = m_svcLocator->service( evtDataSvc_name.c_str(),eventSvc, true );
155 if( !sc.isSuccess() ) {
156 log << MSG::FATAL << "TofRawDataProvider::tofDataMapFull: ERROR Could not load EventDataSvc" << endreq;
157 return;
158 }
159
160 // Event Header
161 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc,"/Event/EventHeader");
162 if( !eventHeader ) {
163 log << MSG::FATAL << "TofRawDataProvider could not find Event Header!" << endreq;
164 return;
165 }
166 int run = eventHeader->runNumber();
167
168 bool mc = ( run < 0 ) ? true:false;
169 bool qCorr = bool( tofCaliSvc->QCorr() );
170 qCorr = qCorr && (!mc);
171 bool qElec = bool( tofCaliSvc->QElec() );
172 bool misLable = bool( tofCaliSvc->MisLable() );
173 misLable = ( !mc && misLable );
174 vector<int> deadId;
175
176 int identmp = -1;
177 for( unsigned int i=0; i<5; i++ ) {
178 identmp = tofCaliSvc->BrEast(i);
179 //std::cout << "TofRawDataProvider DeadID: identmp_breast " << identmp << std::endl;
180 if( identmp != 0x2fffffff ) {
181 //std::cout << "TofRawDataProvider deadid pushback " << identmp << std::endl;
182 deadId.push_back( identmp );
183 }
184 identmp = tofCaliSvc->BrWest(i);
185 //std::cout << "TofRawDataProvider DeadID: identmp_brwest " << identmp << std::endl;
186
187 if( identmp != 0x2fffffff ) {
188 //std::cout << "TofRawDataProvider deadid pushback " << identmp << std::endl;
189 deadId.push_back( identmp );
190 }
191 identmp = tofCaliSvc->Endcap(i);
192 //std::cout << "TofRawDataProvider DeadID: identmp_endcap " << identmp << std::endl;
193 if( identmp != 0x2fffffff ) {
194 //std::cout << "TofRawDataProvider deadid pushback " << identmp << std::endl;
195 deadId.push_back( identmp );
196 }
197 }
198
199 // get TDS data in a common class
200 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc,"/Event/Digi/TofDigiCol");
201 if( !tofDigiCol ) {
202 log << MSG::WARNING << "TofRawDataProvider::tofDataMapFull: Could not find Tof Digi Data!" << endreq;
203 return;
204 }
205
206 int qnumber = 0;
207 int tnumber = 0;
208
209 std::vector<Adc*> chargeVec;
210 std::vector<Tdc*> timeVec;
211
212
213
214
215 TofDigiCol::iterator iter = tofDigiCol->begin();
216
217for( ; iter != tofDigiCol->end(); iter++ ) {
218
219
220
221 Identifier iden_help = (*iter)->identify();
222 int barrel_ec_help = TofID::barrel_ec(iden_help);
223
224
225 if(barrel_ec_help == 0 || barrel_ec_help ==1 || barrel_ec_help==2) // barrel tof or old endcap
226 {
227
228 unsigned int overflow = (*iter)->getOverflow();
229 // electronics error message
230
231
232 if( ( overflow & 0xfe000000 ) == 0xfe000000 )
233 {
234 continue;
235 }
236
237 // overflow 0x 1 1 1 1 1 1
238 // no Q T / multi Q T / overflow Q T
239
240 bool multiQ = ( ( overflow & 0x8 ) != 0 );
241 bool multiT = ( ( overflow & 0x4 ) != 0 );
242
243 Identifier iden = (*iter)->identify();
244
245 unsigned int iden_value = iden.get_value();
246
247
248
249
250 bool sameId = false;
251 vector<int>::iterator iter_dead = deadId.begin();
252 for( ; iter_dead != deadId.end(); iter_dead++ ) {
253 if( iden_value == (*iter_dead) ) {
254 sameId = true;
255 break;
256 }
257 }
258 if( sameId ) {
259 if( mc ) { continue; }
260 else {
261 log << MSG::ERROR << "TofRawDataProvider::tofDataMapFull: Dead Channel Number is not Correct, please check TOF Calibration Constants!" << endreq;
262 }
263 }
264
265
266 int barrel_ec = TofID::barrel_ec(iden);
267 int id = TofID::phi_module(iden);
268 int end = TofID::end(iden);
269
270
271
272 if( ( barrel_ec != 1 ) && ( end == 1 ) ) continue;
273 // TofDigiCol 48 and 96 for luminocity
274 if( ( barrel_ec != 1 ) && ( id == 48 ) ) continue;
275
276 unsigned int tdcChannel = (*iter)->getTimeChannel();
277 unsigned int adcChannel = (*iter)->getChargeChannel();
278
279
280
281
282 if( ( overflow & 0x2 ) != 0 )
283 {
284 adcChannel = ( adcChannel | 0x80000 );
285 }
286
287 if( (adcChannel&0x7fffffff) != 0x7fffffff ) {
288
289 Adc* adc = new Adc;
290 if( qCorr ) adc->setCorr();
291 if( qElec ) adc->setElec();
292
293 adc->setValue( adcChannel );
294 qnumber++;
295 adc->setNumber( qnumber );
296 chargeVec.push_back( adc );
297 }
298
299
300
301 if( tdcChannel != 0x7fffffff ) {
302 Tdc* tdc = new Tdc;
303 tdc->setValue( tdcChannel );
304 tnumber++;
305 tdc->setNumber( tnumber );
306 timeVec.push_back( tdc );
307 }
308
309
310
311 if( multiT || multiQ ) {
312 TofDigiCol::iterator iter_next = iter + 1;
313 if( iter_next != tofDigiCol->end() ) {
314 unsigned int idenNext_value = ((*iter_next)->identify()).get_value();
315 if( iden_value == idenNext_value ) continue;
316 }
317 }
318
319
320
321 qnumber = 0;
322 tnumber = 0;
323
324 std::vector<PmtData*> pmtDataVec;
325 std::vector<Tdc*>::iterator iter_t = timeVec.begin();
326 for( ; iter_t != timeVec.end(); iter_t++ ) {
327 int tclock = (*iter_t)->clock();
328 PmtData* pmt = new PmtData;
329 pmt->setTdc( (*iter_t) );
330
331 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
332 for( ; iter_q != chargeVec.end(); iter_q++ ) {
333 int qclock = (*iter_q)->clock();
334
335 if( abs(tclock-qclock)<2 ) {
336 if( ( pmt->quality() & 0x2 ) != 0 ) { // pmt has Q
337 if( (*iter_q)->value() > pmt->adc() ) {
338 pmt->qtimesmm();
339 pmt->setAdc( (*iter_q) );
340
341
342 }
343 }//close pmt has q
344 else { // pmt has no Q
345 pmt->setAdc( (*iter_q) );
346 }
347 }
348 }
349 pmtDataVec.push_back( pmt );
350 }
351
352
353
354 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
355 for( ; iter_q != chargeVec.end(); iter_q++ ) {
356 //cout << "(*iter_q)->times() " << (*iter_q)->times() <<endl;
357 if( (*iter_q)->times() != -1 )
358 {
359 continue;
360 }
361
362 //cout << "Hallo Hier, d.h. times() von charge !=-1 und barrel_ec ist "<< barrel_ec_help <<endl;
363 PmtData* pmt = new PmtData;
364 pmt->setAdc( (*iter_q) );
365 pmtDataVec.push_back( pmt );
366 }
367
368
369 //std::cout << "TofRawDataProvider old chargeVec.size() " << chargeVec.size() << std::endl;
370 //std::cout << "TofRawDataProvider old timeVec.size() " << timeVec.size() << std::endl;
371 chargeVec.clear();
372 timeVec.clear();
373
374 unsigned int iden_value_key = (iden_value & 0xfffffffe );
375 if( ( barrel_ec == 0 ) || ( barrel_ec == 2 ) ) {
376 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
377 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
378 TofData* tof = new TofData;
379 if( misLable ) {
380 tof->setMisLable();
381
382 if( barrel_ec==2 && id==42 ) {
383 unsigned int iden91 = TofID::getIntID( 2, 0, 91-48, 0 );
384
385 iden_value_key = iden91;
386 }
387
388 if( barrel_ec==2 && id==43 ) {
389 unsigned int iden90 = TofID::getIntID( 2, 0, 90-48, 0 );
390 iden_value_key = iden90;
391 }
392
393 }
394
395
396 tof->setIdentify( iden );
397 tof->setForward( (*iter_pmt) );
398 tof->setTMatched( true );
399 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
400 }
401 }
402 else if( barrel_ec == 1 ) { //super
403 unsigned int count = m_tofDataMap.count( iden_value_key );
404 if( count == 0 ) {
405 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
406 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
407 TofData* tof = new TofData;
408 tof->setIdentify( iden );
409 if( end == 0 ) {
410 tof->setForward( (*iter_pmt) );
411 }
412 else {
413 tof->setBackward( (*iter_pmt) );
414 }
415 tof->setTMatched( true );
416
417 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
418 }
419 }
420 else {
421 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMap.equal_range( iden_value_key );
422 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
423 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
424 bool used = false;
425 IterTofDataMap iter = range.first;
426 for( unsigned int tofDataNumber = 0; tofDataNumber < count; tofDataNumber++, iter++ ) {
427 bool matched = false;
428 if( end == 0 ) { // east, forward
429 if( ( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x1 ) != 0 ) ) { // has east and west time
430 double time1 = (*iter_pmt)->tdc();
431 double time2 = ((*iter).second)->tdc2();
432 matched = ( abs(time1-time2)<timeDiff );
433 }
434 else if( ( ( (*iter_pmt)->quality() & 0x1 ) == 0 ) && ( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x1 ) != 0 ) ) { // has east charge and west time
435 double time1 = (*iter_pmt)->qclock();
436 double time2 = ((*iter).second)->tclock2();
437 double time3 = ((*iter).second)->qclock2();
438 matched = ( ( abs(time1-time2)<=tClockDiff ) || ( abs(time1-time3)<=tClockDiff ) );
439 }
440 else if( ( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x1 ) == 0 ) && ( ( ((*iter).second)->quality() & 0x2 ) != 0 ) ) { // has east time and west charge
441 double time1 = (*iter_pmt)->tclock();
442 double time2 = (*iter_pmt)->qclock();
443 double time3 = ((*iter).second)->qclock2();
444 matched = ( ( abs(time1-time3)<=tClockDiff ) || ( abs(time2-time3)<=tClockDiff ) );
445 }
446 else if( ( ( (*iter_pmt)->quality() & 0x1 ) == 0 ) && ( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x1 ) == 0 ) && ( ( ((*iter).second)->quality() & 0x2 ) != 0 ) ) { // has east and west charge
447 double time1 = (*iter_pmt)->qclock();
448 double time2 = ((*iter).second)->qclock2();
449 matched = ( abs(time1-time2)<=tClockDiff );
450 }
451
452 if( matched ) {
453 used = true;
454 if( ( ( (*iter).second)->quality() & 0xc ) == 0 ) {
455 ((*iter).second)->setForward( (*iter_pmt) );
456 }
457 else {
458 TofData* tof = new TofData;
459 tof->setIdentify( iden );
460 tof->setForward( (*iter_pmt) );
461 tof->setBackward( ((*iter).second)->backward() );
462
463 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
464 }
465 }
466
467 }//close if(end==0)
468 else { // west, backward
469 if( ( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x4 ) != 0 ) ) { // has west and east time
470 double time1 = (*iter_pmt)->tdc();
471 double time2 = ((*iter).second)->tdc1();
472 matched = ( abs(time1-time2)<timeDiff );
473 }
474 else if( ( ( (*iter_pmt)->quality() & 0x1 ) == 0 ) && ( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x4 ) != 0 ) ) { // has west charge and east time
475 double time1 = (*iter_pmt)->qclock();
476 double time2 = ((*iter).second)->tclock1();
477 double time3 = ((*iter).second)->qclock1();
478 matched = ( ( abs(time1-time2)<=tClockDiff ) || ( abs(time1-time3)<=tClockDiff ) );
479 }
480 else if( ( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x4 ) == 0 ) && ( ( ((*iter).second)->quality() & 0x8 ) != 0 ) ) { // has east time and west charge
481 double time1 = (*iter_pmt)->tclock();
482 double time2 = (*iter_pmt)->qclock();
483 double time3 = ((*iter).second)->qclock1();
484 matched = ( ( abs(time1-time3)<=tClockDiff ) || ( abs(time2-time3)<=tClockDiff ) );
485 }
486 else if( ( ( (*iter_pmt)->quality() & 0x1 ) == 0 ) && ( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x4 ) == 0 ) && ( ( ((*iter).second)->quality() & 0x8 ) != 0 ) ) { // has east and west charge
487 double time1 = (*iter_pmt)->qclock();
488 double time2 = ((*iter).second)->qclock1();
489 matched = ( abs(time1-time2)<=tClockDiff );
490 }
491
492 if( matched ) {
493 used = true;
494 if( ( ( (*iter).second)->quality() & 0x3 ) == 0 ) {
495 ((*iter).second)->setBackward( (*iter_pmt) );
496 if( ( ( ((*iter).second)->quality() & 0x5 )==0x5 ) || ( ( ( ((*iter).second)->quality() & 0x5 )==0x4 ) && ( ((*iter).second)->ttimes1()==1 ) ) || ( ( ( ((*iter).second)->quality() & 0x5 )==0x1 ) && ( ((*iter).second)->ttimes2()==1 ) ) ) {
497 ((*iter).second)->setTMatched( true );
498 }
499 else {
500 ((*iter).second)->setTMatched( false );
501 }
502 }
503 else {
504 TofData* tof = new TofData;
505 tof->setIdentify( iden );
506 tof->setForward( ((*iter).second)->forward() );
507 tof->setBackward( (*iter_pmt) );
508 if( ( ( tof->quality() & 0x5 )==0x5 ) || ( ( ( tof->quality() & 0x5 )==0x4 ) && ( tof->ttimes1()==1 ) ) || ( ( ( tof->quality() & 0x5 )==0x1 ) && ( tof->ttimes2()==1 ) ) ) {
509 tof->setTMatched( true );
510 }
511 else {
512 tof->setTMatched( false );
513 }
514 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
515 }
516 }
517 }
518 }
519 if( ! used ) {
520 TofData* tof = new TofData;
521 tof->setIdentify( iden );
522 if( end == 0 ) {
523 tof->setForward( (*iter_pmt) );
524 }
525 else {
526 tof->setBackward( (*iter_pmt) );
527 }
528 tof->setTMatched( true );
529 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
530 }
531 }
532 }
533 }
534
535 pmtDataVec.clear();
536
537 }//close if for barrel/old tof
538
539
540 else if(barrel_ec_help==3 || barrel_ec_help==4 || barrel_ec_help==5 || barrel_ec_help==6)//We treat the new MRPC endcap here!
541 {
542
543
544
545
546 //////////////////////////////////////////////////////
547 //// IMPORTANT ///
548 /// We use the same datastructure as the olf tof, ///
549 /// even if we do not have PMTs and so on ///
550 //////////////////////////////////////////////////////
551
552
553 Identifier iden = (*iter)->identify();
554
555 unsigned int iden_value = iden.get_value();
556
557 int barrel_ec = TofID::barrel_ec(iden);
558 int id = TofID::phi_module(iden);
559 int end = TofID::end(iden);
560
561
562 unsigned int tdcChannel = (*iter)->getTimeChannel();
563 unsigned int tdc2Channel = (*iter)->getChargeChannel();
564
565
566 double time_of_flight = RawDataUtil::TofTime(tdcChannel);
567 unsigned int pulse_length_channel_without_correction = tdc2Channel-tdcChannel;
568
569 double correction_ta= mrpcCaliSvc->Time_Amplitude_Correction(tdcChannel,tdc2Channel);
570 if(correction_ta<0) continue;//Charge is not enough -> Noise!
571
572 time_of_flight=time_of_flight - correction_ta/1000.; //Divide by 1000 to convert in ns
573 tdcChannel = RawDataUtil::TofTimeChannel(time_of_flight); //This is the correceted time of flight. All further calcualtion are performed with the corrected version.
574
575 //Store HIt information: The time of the first hit is stored in the "TDC" the lenght of the pulse in the "ADC", as the pulse length correspond to charge
576
577 Adc* adc = new Adc;
578 if( qCorr ) adc->setCorr(); //qCorr =0 for MC
579 if( qElec ) adc->setElec(); //qElec= 1 for MC
580
581
582 adc->setValue_mrpc( pulse_length_channel_without_correction,(tdcChannel & 0x07e000) ); //We store the length of the pulse into the ADC information as it corresponds to the charge! The other part is the clock information
583
584 qnumber++;
585 adc->setNumber(qnumber);//old stuff ?????
586
587
588 Tdc* tdc = new Tdc;
589 tdc->setValue( tdcChannel );
590 tnumber++;
591
592 tdc->setNumber( tnumber );//old stuff ?????
593
594
595 qnumber = 0;
596 tnumber = 0;
597
598 //Store the ADC and TDC information into a PMT
599 PmtData* pmt = new PmtData;
600 pmt->setTdc(tdc);
601 pmt->setAdc(adc);
602
603
604 chargeVec.clear();//old stuff
605 timeVec.clear();//old stuff
606
607
608
609 //Store this data into the TOFDATAMAP !
610 unsigned int iden_value_key_mrpc = (iden_value & 0xffffffff ); //The MRPC needs the last bit!
611
612 TofData* tof = new TofData;
613 if( misLable ) { tof->setMisLable(); }
614 tof->setIdentify( iden );
615 tof->setForward( pmt );
616 tof->setTMatched( true );//Sof far only MC data -> Match is true
617
618
619
620 m_tofDataMap.insert( make_pair( iden_value_key_mrpc, tof ) );
621
622
623
624
625
626 }//close else if new endcap.
627
628
629
630}//close for loop
631
632
633
634 return;
635
636}//close tofDataMapFull
637
638
639// onlineMode only T is combined, no Q reserved
641
642 MsgStream log(m_msgSvc, m_name);
643 log << MSG::INFO << "TofRawDataProvider::tofDataMapOnlineMode()" << endreq;
644
645 if( ! m_tofDataMapOnline.empty() ) {
646 if(control){
647 IterTofDataMap iter = m_tofDataMapOnline.begin();
648 for( ; iter != m_tofDataMapOnline.end(); iter++ ) {
649 delete (*iter).second;
650 }
651 m_tofDataMapOnline.clear();
652 }
653 else return m_tofDataMapOnline;
654 }
655 // tianhl for mt
656 std::string evtDataSvc_name("EventDataSvc");
657 if(isGaudiThreaded(m_name)){
658 evtDataSvc_name += getGaudiThreadIDfromName(m_name);
659 }
660 // tianhl for mt
661
662 IDataProviderSvc* eventSvc;
663 StatusCode sc = m_svcLocator->service( evtDataSvc_name.c_str(), eventSvc, true );
664 if( !sc.isSuccess() ) {
665 log << MSG::FATAL << "TofRawDataProvider::tofDataMapOnlineMode(): ERROR Could not load EventDataSvc" << endreq;
666 return m_tofDataMapOnline;
667 }
668
669 // get TDS data in a common class
670 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc,"/Event/Digi/TofDigiCol");
671 if( !tofDigiCol ) {
672 log << MSG::WARNING << "TofRawDataProvider::tofDataMapOnlineMode(): Could not find Tof Digi Data!" << endreq;
673 return m_tofDataMapOnline;
674 }
675
676 TofDigiCol::iterator iter = tofDigiCol->begin();
677 for( ; iter != tofDigiCol->end(); iter++ ) {
678 unsigned int overflow = (*iter)->getOverflow();
679 if( ( overflow & 0xfe000000 ) == 0xfe000000 ) continue;
680 // overflow 0x 1 1 1 1 1 1
681 // no Q T / multi Q T / overflow Q T
682
683 bool noT = ( ( overflow & 0x10 ) != 0 );
684 // bool multiQ = ( ( overflow & 0x8 ) != 0 );
685 // bool multiT = ( ( overflow & 0x4 ) != 0 );
686 if( noT ) continue;
687
688 Identifier iden = (*iter)->identify();
689 unsigned int iden_value = iden.get_value();
690 int barrel_ec = TofID::barrel_ec(iden);
691 int id = TofID::phi_module(iden);
692 int end = TofID::end(iden);
693 if( ( barrel_ec != 1 ) && ( end == 1 ) ) continue;
694 if( ( barrel_ec != 1 ) && ( id == 48 ) ) continue;
695
696 unsigned int tdcChannel = (*iter)->getTimeChannel();
697 if( tdcChannel == 0x7fffffff ) continue;
698
699 Tdc* tdc = new Tdc;
700 tdc->setValue( tdcChannel );
701 PmtData* pmt = new PmtData;
702 pmt->setTdc( tdc );
703
704 unsigned int iden_value_key = ( iden_value & 0xfffffffe );
705
706 if( barrel_ec == 0 || barrel_ec == 2 ) {
707 TofData* tof = new TofData;
708 tof->setIdentify( iden );
709 tof->setForward( pmt );
710 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
711 }
712 else if( barrel_ec == 1 ) {
713 unsigned int count = m_tofDataMapOnline.count( iden_value_key );
714
715 if( count == 0 ) {
716 TofData* tof = new TofData;
717 tof->setIdentify( iden );
718 if( end == 0 ) {
719 tof->setForward( pmt );
720 }
721 else {
722 tof->setBackward( pmt );
723 }
724 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
725 }
726 else {
727 bool used = false;
728 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMapOnline.equal_range( iden_value_key );
729 IterTofDataMap iter = range.first;
730 for( unsigned int i=0; i<count; i++, iter++ ) {
731 if( ( end == 0 ) && ( ( ( (*iter).second)->quality() & 0x1 ) != 0 ) ) {
732 double time1 = pmt->tdc();
733 double time2 = ((*iter).second)->tdc2();
734 if( abs(time1-time2)<timeDiff ) {
735 used = true;
736 if( ( ( (*iter).second)->quality() & 0x4 ) == 0 ) {
737 ((*iter).second)->setForward( pmt );
738 }
739 else {
740 TofData* tof = new TofData;
741 tof->setIdentify( iden );
742 tof->setForward( pmt );
743 tof->setBackward( ((*iter).second)->backward() );
744 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
745 }
746 }
747 }
748 else if( ( end == 1 ) && ( ( ((*iter).second)->quality() & 0x4 ) != 0 ) ) {
749 double time1 = ((*iter).second)->tdc1();
750 double time2 = pmt->tdc();
751
752 if( abs(time1-time2)<timeDiff ) {
753 used = true;
754 if( ( ( (*iter).second)->quality() & 0x1 ) == 0 ) {
755 ((*iter).second)->setBackward( pmt );
756 }
757 else {
758 TofData* tof = new TofData;
759 tof->setIdentify( iden );
760 tof->setForward( ((*iter).second)->forward() );
761 tof->setBackward( pmt );
762 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
763 }
764 }
765 }
766 }
767 if( ! used ) {
768 TofData* tof = new TofData;
769 tof->setIdentify( iden );
770 if( end == 0 ) {
771 tof->setForward( pmt );
772 }
773 else {
774 tof->setBackward( pmt );
775 }
776 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
777 }
778 }
779 }
780 }
781
782 return m_tofDataMapOnline;
783
784}
785
786
788
789 MsgStream log(m_msgSvc, m_name);
790 log << MSG::INFO << "TofRawDataProvider::tofDataVectorOnlineMode()" << endreq;
791
792 if( m_tofDataVectorOnline.size() != 0 ) {
793 if(!control) return m_tofDataVectorOnline;
794 else m_tofDataVectorOnline.clear();
795 }
797 IterTofDataMap iter = tofRawDataMap.begin();
798 for( ; iter != tofRawDataMap.end(); iter++ ) {
799 m_tofDataVectorOnline.push_back( iter->second );
800 }
801
802 return m_tofDataVectorOnline;
803}
804
805
806// Event Start Time, only Time is required.
808
809 if( !m_hasFilled ) {
811 m_hasFilled = true;
812 }
813
814 if( !m_tofDataMapEstime.empty() ) {
815 m_tofDataMapEstime.clear();
816 }
817
818 IterTofDataMap iter = m_tofDataMap.begin();
819 for( ; iter != m_tofDataMap.end(); iter++ ) {
820 if( ( ( ((*iter).second)->quality() & 0x5 ) != 0 ) && ((*iter).second)->tmatched() ) {
821 m_tofDataMapEstime.insert( make_pair( (*iter).first, (*iter).second ) );
822 }
823 }
824
825 iter = m_tofDataMapEstime.begin();
826 while( iter != m_tofDataMapEstime.end() ) {
827 unsigned int iden_value = (*iter).first;
828 unsigned int count = m_tofDataMapEstime.count( iden_value );
829 for( unsigned int i=0; i != count; i++, iter++ ) {
830 ((*iter).second)->setTimes( count );
831 }
832 }
833
834 return m_tofDataMapEstime;
835}
836
837
839 if( m_tofDataVectorEstime.size() != 0 ) return m_tofDataVectorEstime;
840
843 for( ; iter != tofDataMapEstime.end(); iter++ ) {
844 m_tofDataVectorEstime.push_back( iter->second );
845 }
846 return m_tofDataVectorEstime;
847}
848
849
850// TOF reconstruction, both time and charge are required
852
853 if( !m_hasFilled ) {
855 m_hasFilled = true;
856 }
857
858 if( !m_tofDataMapTof.empty() ) {
859 m_tofDataMapTof.clear();
860 }
861
862 IterTofDataMap iter = m_tofDataMap.begin();
863 for( ; iter != m_tofDataMap.end(); iter++ ) {
864 if( ( ( ((*iter).second)->quality() & 0xc ) == 0xc ) || ( ( ((*iter).second)->quality() & 0x3 ) == 0x3 ) ) {
865
866 if( estime > 1.0e-6 ) {
867 double tdc1 = ((*iter).second)->tdc1();
868 double tdc2 = ((*iter).second)->tdc2();
869 bool forward = ( ( ( estime - tdc1 ) < timeBackward ) && ( ( tdc1 - estime ) < timeForward ) );
870 bool backward = ( ( ( estime - tdc2 ) < timeBackward ) && ( ( tdc2 - estime ) < timeForward ) );
871
872 //std::cout << "TofRawDataProvider tdc1: " << tdc1 << std::endl;
873 //std::cout << "TofRawDataProvider tdc2: " << tdc1<< std::endl;
874 //std::cout << "TofRawDataProvider (est - tdc1) | (tdc1 - est): " << estime - tdc1 << " | " << tdc1 - estime<< std::endl;
875 //std::cout << "TofRawDataProvider (est - tdc2) | (tdc2 - est): " << estime - tdc2 << " | " << tdc2 - estime<< std::endl;
876 //std::cout << "TofRawDataProvider bool (est - tdc1)< 24 && (tdc1 - est)<120: " << forward << std::endl;
877 //std::cout << "TofRawDataProvider bool (est - tdc2)< 24 && (tdc2 - est)<120: " << backward << std::endl;
878 if( !forward && !backward ) continue;
879
880
881 }
882
883 m_tofDataMapTof.insert( make_pair( (*iter).first, (*iter).second ) );
884 }
885 }
886
887 iter = m_tofDataMapTof.begin();
888 while( iter != m_tofDataMapTof.end() ) {
889 unsigned int iden_value = (*iter).first;
890 unsigned int count = m_tofDataMapTof.count( iden_value );
891 for( unsigned int i=0; i != count; i++, iter++ ) {
892 ((*iter).second)->setTimes( count );
893 }
894 }
895
896 return m_tofDataMapTof;
897}
898
899
901 if( m_tofDataVectorTof.size() != 0 ) {
902 m_tofDataVectorTof.clear();
903 }
904
907 for( ; iter != tofDataMapTof.end(); iter++ ) {
908 m_tofDataVectorTof.push_back( iter->second );
909 }
910 return m_tofDataVectorTof;
911}
912
913
914// EMC reconstruction, only charge are required
916
917 if( !m_hasFilled ) {
919 m_hasFilled = true;
920 }
921
922 if( !m_tofDataMapEmc.empty() ) {
923 m_tofDataMapEmc.clear();
924 }
925
926 IterTofDataMap iter = m_tofDataMap.begin();
927 for( ; iter != m_tofDataMap.end(); iter++ ) {
928 if( ( ((*iter).second)->quality() & 0xa ) != 0 ) {
929
930 if( estime > 1.0e-6 ) {
931 int t0clock = static_cast<int>(estime/24.0);
932 int clock1 = ((*iter).second)->qclock1();
933 int clock2 = ((*iter).second)->qclock2();
934 bool forward = ( ( ( t0clock - clock1 ) < tClockBackward ) && ( ( clock1 - t0clock ) < tClockForward ) );
935 bool backward = ( ( ( t0clock - clock2 ) < tClockBackward ) && ( ( clock2 - t0clock ) < tClockForward ) );
936 if( !forward && !backward ) continue;
937 }
938
939 m_tofDataMapEmc.insert( make_pair( (*iter).first, (*iter).second ) );
940 }
941 }
942
943 iter = m_tofDataMapEmc.begin();
944 while( iter != m_tofDataMapEmc.end() ) {
945 unsigned int iden_value = (*iter).first;
946 unsigned int count = m_tofDataMapEmc.count( iden_value );
947 for( unsigned int i=0; i != count; i++, iter++ ) {
948 ((*iter).second)->setTimes( count );
949 }
950 }
951
952 return m_tofDataMapEmc;
953}
954
955
957 if( m_tofDataVectorEmc.size() != 0 ) {
958 m_tofDataVectorEmc.clear();
959 }
960
963 for( ; iter != tofDataMapEmc.end(); iter++ ) {
964 m_tofDataVectorEmc.push_back( iter->second );
965 }
966 return m_tofDataVectorEmc;
967}
double abs(const EvtComplex &c)
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
ITofQElecSvc * tofQElecSvc
ITofQCorrSvc * tofQCorrSvc
std::multimap< unsigned int, TofData * > TofDataMap
Definition TofData.h:244
std::vector< TofData * > TofDataVector
Definition TofData.h:247
std::multimap< unsignedint, TofData * >::iterator IterTofDataMap
Definition TofData.h:245
ITofQElecSvc * tofQElecSvc
ITofQCorrSvc * tofQCorrSvc
ITofCaliSvc * tofCaliSvc
const double tClockBackward
const double tClockForward
const double timeDiff
const double timeForward
const double tClockDiff
const double timeBackward
Definition TofData.h:43
void setElec()
Definition TofData.h:48
void setCorr()
Definition TofData.h:47
void setValue_mrpc(int value, int clock)
Definition TofData.cxx:77
void setValue(int value)
Definition TofData.cxx:85
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
value_type get_value() const
Definition Identifier.h:163
double Time_Amplitude_Correction(unsigned int tdcChannel, unsigned int tdc2Channel)
void setAdc(Adc *adc)
Definition TofData.cxx:398
double tdc()
Definition TofData.cxx:270
void qtimesmm()
Definition TofData.cxx:308
double adc()
Definition TofData.cxx:238
void setTdc(Tdc *tdc)
Definition TofData.cxx:408
unsigned int quality() const
Definition TofData.h:88
StatusCode initialize(ISvcLocator *svcLoc=0, IMessageSvc *pMsg=0)
static unsigned int TofTimeChannel(double time)
Definition RawDataUtil.h:70
static double TofTime(unsigned int timeChannel)
Definition RawDataUtil.h:69
Definition TofData.h:63
void setValue(int value)
Definition TofData.cxx:48
unsigned int quality() const
Definition TofData.h:170
int ttimes1()
Definition TofData.cxx:760
void setForward(PmtData *pmt)
Definition TofData.cxx:907
void setTMatched(bool tmatched)
Definition TofData.h:207
void setBackward(PmtData *pmt)
Definition TofData.cxx:926
int ttimes2()
Definition TofData.cxx:778
void setIdentify(Identifier identify)
Definition TofData.cxx:503
void setMisLable()
Definition TofData.h:201
static int end(const Identifier &id)
Definition TofID.cxx:129
static int phi_module(const Identifier &id)
Definition TofID.cxx:117
static int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
Definition TofID.cxx:95
static value_type getIntID(int barrel_ec, int layer, int phi_module, int end)
Definition TofID.cxx:200
TofDataMap & tofDataMapTof(double estime=0.0)
void handle(const Incident &)
TofDataVector & tofDataVectorTof(double estime=0.0)
MrpcCalibSvc * mrpcCaliSvc
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)
void setNumber(int number)
Definition TofData.h:26