144 {
145
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
154 for( ;
iter != m_tofDataMap.end();
iter++ ) {
155 delete (*iter).second;
156 }
157 m_tofDataMap.clear();
158 }
159
160 std::string evtDataSvc_name("EventDataSvc");
161 if(isGaudiThreaded(
m_name)){
162 evtDataSvc_name += getGaudiThreadIDfromName(
m_name);
163 }
164
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
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
183 bool mc = ( m_run < 0 ) ?
true:
false;
185 qCorr = qCorr && (!mc);
188 misLable = ( !mc && misLable );
189
190 int identmp = -1;
191 vector<int> deadId;
192 for( unsigned int i=0; i<5; i++ ) {
194 if( identmp != 0x2fffffff ) {
195 deadId.push_back( identmp );
196 }
198 if( identmp != 0x2fffffff ) {
199 deadId.push_back( identmp );
200 }
201 }
202 for( unsigned int i=0; i<500; i++ ) {
204 if( identmp == 0x2fffffff ) break;
205 else { deadId.push_back( identmp ); }
206 }
207
208
209 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc,"/Event/Digi/TofDigiCol");
210 if( !tofDigiCol ) {
211 log << MSG::WARNING << "TofRawDataProvider::tofDataMapFull: Could not find Tof Digi Data!" << endreq;
212 return;
213 }
214
215 int qnumber = 0;
216 int tnumber = 0;
217
218 std::vector<Adc*> chargeVec;
219 std::vector<Tdc*> timeVec;
220
221 TofDigiCol::iterator
iter = tofDigiCol->begin();
222 for( ;
iter != tofDigiCol->end();
iter++ ) {
224 unsigned int iden_value = iden.
get_value();
225
226 bool sameId = false;
227 vector<int>::iterator iter_dead = deadId.begin();
228 for( ; iter_dead != deadId.end(); iter_dead++ ) {
229 if( iden_value == (*iter_dead) ) {
230 sameId = true;
231 break;
232 }
233 }
234 if( sameId ) {
235 if( mc ) { continue; }
236 else {
237 std::string bore;
238 int layertmp = -1;
239 int tofidtmp = -1;
241 bore = string("Barrel");
244 }
246 bore=string("East Endcap");
248 }
250 bore=string("West Endcap");
252 }
254 bore=string("ETF(MRPC)");
255 tofidtmp = TofID::module(iden);
256 }
257
258
259 }
260 }
261
263
264 unsigned int overflow = (*iter)->getOverflow();
265 if(
TofID::is_scin(iden) && ( ( overflow & 0xfe000000 ) == 0xfe000000 ) )
continue;
266
267
268
269
270
271
272
274
275 if( ( iden_value & 0x2fffffe0 ) == 0x2000c800 ) {
276 iden_value = 0x2000c900 + ( iden_value & 0x1f );
278 }
279
280 if( ( iden_value & 0x2fffffe0 ) == 0x2000c820 ) {
281 iden_value = 0x2000c8e0 + ( iden_value & 0x1f );
283 }
284 }
285
286
287
288
289
290 bool multiQ = ( ( overflow & 0x8 ) != 0 );
291 bool multiT = ( ( overflow & 0x4 ) != 0 );
292
293 unsigned int tdcChannel = (*iter)->getTimeChannel();
294 unsigned int adcChannel = (*iter)->getChargeChannel();
296 adcChannel = ( adcChannel | 0x80000 );
297 }
298
299 if( (adcChannel&0x7fffffff) != 0x7fffffff ) {
303
304
305
307 adcChannel += 0x18000;
308 }
309
310
312 qnumber++;
314 chargeVec.push_back( adc );
315 }
316
317 if( tdcChannel != 0x7fffffff ) {
319
320
321
323 tdcChannel += 0x18000;
324 }
325
326
328 tnumber++;
330 timeVec.push_back( tdc );
331 }
332
333 if( multiT || multiQ ) {
334 TofDigiCol::iterator iter_next =
iter + 1;
335 if( iter_next != tofDigiCol->end() ) {
336 unsigned int idenNext_value = ((*iter_next)->identify()).get_value();
337 if( iden_value == idenNext_value ) continue;
338 }
339 }
340
341 qnumber = 0;
342 tnumber = 0;
343
344 std::vector<PmtData*> pmtDataVec;
346 std::vector<Tdc*>::iterator iter_t = timeVec.begin();
347 for( ; iter_t != timeVec.end(); iter_t++ ) {
348 int tclock = (*iter_t)->clock();
352 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
353 for( ; iter_q != chargeVec.end(); iter_q++ ) {
354 if( (*iter_q)->times() != -1 ) { continue; }
355 int qclock = (*iter_q)->clock();
356 if(
abs(tclock-qclock)<2 ) {
357 if( ( pmt->
quality() & 0x2 ) != 0 ) {
358 if( (*iter_q)->value() > pmt->
adc() ) {
361 }
362 }
363 else {
365 }
366 }
367 }
368 pmtDataVec.push_back( pmt );
369 }
370
371 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
372 for( ; iter_q != chargeVec.end(); iter_q++ ) {
373 if( (*iter_q)->times() != -1 ) { continue; }
377 pmtDataVec.push_back( pmt );
378 }
379
380 }
381
383 std::vector<Tdc*>::iterator iter_t = timeVec.begin();
384 for( ; iter_t != timeVec.end(); iter_t++ ) {
385 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
386 for( ; iter_q != chargeVec.end(); iter_q++ ) {
387 if( ( (*iter_q)->qtc() - (*iter_t)->value() ) >
totForward && ( (*iter_q)->qtc() - (*iter_t)->value() ) <
totBackward ) {
392 pmtDataVec.push_back( pmt );
393 }
394 }
395 if( (*iter_t)->times() == -1 ) {
398 pmtDataVec.push_back( pmt );
399 }
400 }
401
402 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
403 for( ; iter_q != chargeVec.end(); iter_q++ ) {
404 if( (*iter_q)->times() != -1 ) { continue; }
408 pmtDataVec.push_back( pmt );
409 }
410
411 }
412
413 chargeVec.clear();
414 timeVec.clear();
415
416 unsigned int iden_value_key = (iden_value & 0xfffffffe );
419
422 if( ( barrel_ec == 0 ) || ( barrel_ec == 2 ) ) {
423 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
424 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
426 if( misLable ) {
428 if( barrel_ec==2 && tofid==42 ) {
430 iden_value_key = iden91;
432 }
433 if( barrel_ec==2 && tofid==43 ) {
435 iden_value_key = iden90;
437 }
438 }
442 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
443 }
444 }
445 else if( barrel_ec == 1 ) {
446 unsigned int count = m_tofDataMap.count( iden_value_key );
448 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
449 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
452 if( end == 0 ) {
454 }
455 else {
457 }
459 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
460 }
461 }
462 else {
463 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMap.equal_range( iden_value_key );
464 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
465 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
466 bool used = false;
468 for(
unsigned int tofDataNumber = 0; tofDataNumber <
count; tofDataNumber++,
iter++ ) {
469
470 bool matched = false;
471 if( end == 0 ) {
472 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) {
473 if( ( ((*iter).second)->quality() & 0x1 ) != 0 ) {
474 double time1 = (*iter_pmt)->tdc();
475 double time2 = ((*iter).second)->tdc2();
477 }
478 else {
479 if( ( ((*iter).second)->quality() & 0x2 ) != 0 ) {
480 double time1 = (*iter_pmt)->tclock();
481 double time2 = (*iter_pmt)->qclock();
482 double time3 = ((*iter).second)->qclock2();
484 }
485 }
486 }
487 else {
488 if( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) {
489 if( ( ((*iter).second)->quality() & 0x1 ) != 0 ) {
490 if( ( ( ((*iter).second)->quality() & 0x2 ) != 0 ) ) {
491 double time1 = (*iter_pmt)->qclock();
492 double time2 = ((*iter).second)->tclock2();
493 double time3 = ((*iter).second)->qclock2();
495 }
496 }
497 else {
498 if( ( ( ((*iter).second)->quality() & 0x2 ) != 0 ) ) {
499 double time1 = (*iter_pmt)->qclock();
500 double time2 = ((*iter).second)->qclock2();
502 }
503 }
504 }
505 }
506
507 if( matched ) {
508 used = true;
509 if( ( ( (*iter).second)->quality() & 0xc ) == 0 ) {
510 ((*iter).second)->setForward( (*iter_pmt) );
511 }
512 else {
518 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
519 }
520 }
521
522 }
523 else {
524 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) {
525 if( ( ((*iter).second)->quality() & 0x4 ) != 0 ) {
526 double time1 = (*iter_pmt)->tdc();
527 double time2 = ((*iter).second)->tdc1();
529 }
530 else {
531 if( ( ((*iter).second)->quality() & 0x8 ) != 0 ) {
532 double time1 = (*iter_pmt)->tclock();
533 double time2 = (*iter_pmt)->qclock();
534 double time3 = ((*iter).second)->qclock1();
536 }
537 }
538 }
539 else {
540 if( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) {
541 if( ( ((*iter).second)->quality() & 0x4 ) != 0 ) {
542 if( ( ( ((*iter).second)->quality() & 0x8 ) != 0 ) ) {
543 double time1 = (*iter_pmt)->qclock();
544 double time2 = ((*iter).second)->tclock1();
545 double time3 = ((*iter).second)->qclock1();
547 }
548 else {
549 }
550 }
551 else {
552 if( ( ( ((*iter).second)->quality() & 0x8 ) != 0 ) ) {
553 double time1 = (*iter_pmt)->qclock();
554 double time2 = ((*iter).second)->qclock1();
556 }
557 }
558 }
559 }
560
561 if( matched ) {
562 used = true;
563 if( ( ( (*iter).second)->quality() & 0x3 ) == 0 ) {
564 ((*iter).second)->setBackward( (*iter_pmt) );
565 }
566 else {
569 tof->
setForward( ((*iter).second)->forward() );
572 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
573 }
574 }
575 }
576 }
577
578 if( ! used ) {
581 if( end == 0 ) {
583 }
584 else {
586 }
588 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
589 }
590 }
591 }
592 }
593 }
594
596
598 int tofid = TofID::module( iden );
601
602 unsigned int count = m_tofDataMap.count( iden_value_key );
604 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
605 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
608 if( end == 0 ) {
610 }
611 else {
613 }
615 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
616 }
617 }
618 else {
619 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMap.equal_range( iden_value_key );
620 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
621 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
622 bool used = false;
624 for(
unsigned int tofDataNumber = 0; tofDataNumber <
count; tofDataNumber++,
iter++ ) {
625 bool matched = false;
626 if( end == 0 ) {
627 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) {
628 if( ( ((*iter).second)->quality() & 0x1 ) != 0 ) {
629 double time1 = (*iter_pmt)->tdc();
630 double time2 = ((*iter).second)->tdc2();
632 if( endcap==0 && tofid==13 && strip==5 ) { matched = (
abs(time1-time2)<(100+
timeDiffMRPC) ); }
633 }
634 }
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667 if( matched ) {
668 used = true;
669 if( ( ( (*iter).second)->quality() & 0xc ) == 0 ) {
670 ((*iter).second)->setForward( (*iter_pmt) );
671 }
672 else {
678 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
679 }
680 }
681 }
682 else {
683 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) {
684 if( ( ((*iter).second)->quality() & 0x4 ) != 0 ) {
685 double time1 = (*iter_pmt)->tdc();
686 double time2 = ((*iter).second)->tdc1();
688 if( endcap==0 && tofid==13 && strip==5 ) { matched = (
abs(time1-time2)<(100+
timeDiffMRPC) ); }
689 }
690 }
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723 if( matched ) {
724 used = true;
725 if( ( ( (*iter).second)->quality() & 0x3 ) == 0 ) {
726 ((*iter).second)->setBackward( (*iter_pmt) );
727 }
728 else {
731 tof->
setForward( ((*iter).second)->forward() );
734 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
735 }
736 }
737 }
738 }
739
740 if( ! used ) {
743 if( end == 0 ) {
745 }
746 else {
748 }
750 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
751 }
752 }
753 }
754 }
755
756 pmtDataVec.clear();
757
758 }
759
760 return;
761
762}
const double timeDiffMRPC
void setValue(Identifier identify, int value)
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 StatusCode chooseConstants(int run, int event)=0
virtual const int Endcap(unsigned int No)=0
value_type get_value() const
void setIdentify(unsigned int iden)
unsigned int quality() const
void setForward(PmtData *pmt)
void setTMatched(bool tmatched)
void setBackward(PmtData *pmt)
void setIdentify(Identifier identify)
static int endcap(const Identifier &id)
static int strip(const Identifier &id)
static bool is_scin(const Identifier &id)
static int end(const Identifier &id)
static bool is_barrel(const Identifier &id)
Test for barrel.
static int phi_module(const Identifier &id)
static int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
static value_type getIntID(int barrel_ec, int layer, int phi_module, int end)
static int layer(const Identifier &id)
void setNumber(int number)