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 }
202 if( identmp != 0x2fffffff ) {
203 deadId.push_back( identmp );
204 }
205 }
206
207
208 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc,"/Event/Digi/TofDigiCol");
209 if( !tofDigiCol ) {
210 log << MSG::WARNING << "TofRawDataProvider::tofDataMapFull: Could not find Tof Digi Data!" << endreq;
211 return;
212 }
213
214 int qnumber = 0;
215 int tnumber = 0;
216
217 std::vector<Adc*> chargeVec;
218 std::vector<Tdc*> timeVec;
219
220 TofDigiCol::iterator
iter = tofDigiCol->begin();
221 for( ;
iter != tofDigiCol->end();
iter++ ) {
223 unsigned int iden_value = iden.
get_value();
224
225 bool sameId = false;
226 vector<int>::iterator iter_dead = deadId.begin();
227 for( ; iter_dead != deadId.end(); iter_dead++ ) {
228 if( iden_value == (*iter_dead) ) {
229 sameId = true;
230 break;
231 }
232 }
233 if( sameId ) {
234 if( mc ) { continue; }
235 else {
236 std::string bore;
241
242 log << MSG::ERROR << "TofRawDataProvider::tofDataMapFull: Dead Channel Number is not Correct, please check TOF Calibration Constants! " << bore << endreq;
243 }
244 }
245
247
248 unsigned int overflow = (*iter)->getOverflow();
249 if(
TofID::is_scin(iden) && ( ( overflow & 0xfe000000 ) == 0xfe000000 ) )
continue;
250
251
252
253
254
255
256
258
259 if( ( iden_value & 0x2fffffe0 ) == 0x2000c800 ) {
260 iden_value = 0x2000c900 + ( iden_value & 0x1f );
262 }
263
264 if( ( iden_value & 0x2fffffe0 ) == 0x2000c820 ) {
265 iden_value = 0x2000c8e0 + ( iden_value & 0x1f );
267 }
268 }
269
270
271
272
273
274 bool multiQ = ( ( overflow & 0x8 ) != 0 );
275 bool multiT = ( ( overflow & 0x4 ) != 0 );
276
277 unsigned int tdcChannel = (*iter)->getTimeChannel();
278 unsigned int adcChannel = (*iter)->getChargeChannel();
280 adcChannel = ( adcChannel | 0x80000 );
281 }
282
283 if( (adcChannel&0x7fffffff) != 0x7fffffff ) {
287
288
289
291 adcChannel += 0x18000;
292 }
293
294
296 qnumber++;
298 chargeVec.push_back( adc );
299 }
300
301 if( tdcChannel != 0x7fffffff ) {
303
304
305
307 tdcChannel += 0x18000;
308 }
309
310
312 tnumber++;
314 timeVec.push_back( tdc );
315 }
316
317 if( multiT || multiQ ) {
318 TofDigiCol::iterator iter_next =
iter + 1;
319 if( iter_next != tofDigiCol->end() ) {
320 unsigned int idenNext_value = ((*iter_next)->identify()).get_value();
321 if( iden_value == idenNext_value ) continue;
322 }
323 }
324
325 qnumber = 0;
326 tnumber = 0;
327
328 std::vector<PmtData*> pmtDataVec;
330 std::vector<Tdc*>::iterator iter_t = timeVec.begin();
331 for( ; iter_t != timeVec.end(); iter_t++ ) {
332 int tclock = (*iter_t)->clock();
336 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
337 for( ; iter_q != chargeVec.end(); iter_q++ ) {
338 if( (*iter_q)->times() != -1 ) { continue; }
339 int qclock = (*iter_q)->clock();
340 if(
abs(tclock-qclock)<2 ) {
341 if( ( pmt->
quality() & 0x2 ) != 0 ) {
342 if( (*iter_q)->value() > pmt->
adc() ) {
345 }
346 }
347 else {
349 }
350 }
351 }
352 pmtDataVec.push_back( pmt );
353 }
354
355 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
356 for( ; iter_q != chargeVec.end(); iter_q++ ) {
357 if( (*iter_q)->times() != -1 ) { continue; }
361 pmtDataVec.push_back( pmt );
362 }
363
364 }
365
367 std::vector<Tdc*>::iterator iter_t = timeVec.begin();
368 for( ; iter_t != timeVec.end(); iter_t++ ) {
369 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
370 for( ; iter_q != chargeVec.end(); iter_q++ ) {
371 if( ( (*iter_q)->qtc() - (*iter_t)->value() ) >
totForward && ( (*iter_q)->qtc() - (*iter_t)->value() ) <
totBackward ) {
376 pmtDataVec.push_back( pmt );
377 }
378 }
379 if( (*iter_t)->times() == -1 ) {
382 pmtDataVec.push_back( pmt );
383 }
384 }
385
386 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
387 for( ; iter_q != chargeVec.end(); iter_q++ ) {
388 if( (*iter_q)->times() != -1 ) { continue; }
392 pmtDataVec.push_back( pmt );
393 }
394
395 }
396
397 chargeVec.clear();
398 timeVec.clear();
399
400 unsigned int iden_value_key = (iden_value & 0xfffffffe );
403
406 if( ( barrel_ec == 0 ) || ( barrel_ec == 2 ) ) {
407 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
408 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
410 if( misLable ) {
412 if( barrel_ec==2 && tofid==42 ) {
414 iden_value_key = iden91;
416 }
417 if( barrel_ec==2 && tofid==43 ) {
419 iden_value_key = iden90;
421 }
422 }
426 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
427 }
428 }
429 else if( barrel_ec == 1 ) {
430 unsigned int count = m_tofDataMap.count( iden_value_key );
432 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
433 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
436 if( end == 0 ) {
438 }
439 else {
441 }
443 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
444 }
445 }
446 else {
447 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMap.equal_range( iden_value_key );
448 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
449 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
450 bool used = false;
452 for(
unsigned int tofDataNumber = 0; tofDataNumber <
count; tofDataNumber++,
iter++ ) {
453
454 bool matched = false;
455 if( end == 0 ) {
456 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) {
457 if( ( ((*iter).second)->quality() & 0x1 ) != 0 ) {
458 double time1 = (*iter_pmt)->tdc();
459 double time2 = ((*iter).second)->tdc2();
461 }
462 else {
463 if( ( ((*iter).second)->quality() & 0x2 ) != 0 ) {
464 double time1 = (*iter_pmt)->tclock();
465 double time2 = (*iter_pmt)->qclock();
466 double time3 = ((*iter).second)->qclock2();
468 }
469 }
470 }
471 else {
472 if( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) {
473 if( ( ((*iter).second)->quality() & 0x1 ) != 0 ) {
474 if( ( ( ((*iter).second)->quality() & 0x2 ) != 0 ) ) {
475 double time1 = (*iter_pmt)->qclock();
476 double time2 = ((*iter).second)->tclock2();
477 double time3 = ((*iter).second)->qclock2();
479 }
480 }
481 else {
482 if( ( ( ((*iter).second)->quality() & 0x2 ) != 0 ) ) {
483 double time1 = (*iter_pmt)->qclock();
484 double time2 = ((*iter).second)->qclock2();
486 }
487 }
488 }
489 }
490
491 if( matched ) {
492 used = true;
493 if( ( ( (*iter).second)->quality() & 0xc ) == 0 ) {
494 ((*iter).second)->setForward( (*iter_pmt) );
495 }
496 else {
502 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
503 }
504 }
505
506 }
507 else {
508 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) {
509 if( ( ((*iter).second)->quality() & 0x4 ) != 0 ) {
510 double time1 = (*iter_pmt)->tdc();
511 double time2 = ((*iter).second)->tdc1();
513 }
514 else {
515 if( ( ((*iter).second)->quality() & 0x8 ) != 0 ) {
516 double time1 = (*iter_pmt)->tclock();
517 double time2 = (*iter_pmt)->qclock();
518 double time3 = ((*iter).second)->qclock1();
520 }
521 }
522 }
523 else {
524 if( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) {
525 if( ( ((*iter).second)->quality() & 0x4 ) != 0 ) {
526 if( ( ( ((*iter).second)->quality() & 0x8 ) != 0 ) ) {
527 double time1 = (*iter_pmt)->qclock();
528 double time2 = ((*iter).second)->tclock1();
529 double time3 = ((*iter).second)->qclock1();
531 }
532 else {
533 }
534 }
535 else {
536 if( ( ( ((*iter).second)->quality() & 0x8 ) != 0 ) ) {
537 double time1 = (*iter_pmt)->qclock();
538 double time2 = ((*iter).second)->qclock1();
540 }
541 }
542 }
543 }
544
545 if( matched ) {
546 used = true;
547 if( ( ( (*iter).second)->quality() & 0x3 ) == 0 ) {
548 ((*iter).second)->setBackward( (*iter_pmt) );
549 }
550 else {
553 tof->
setForward( ((*iter).second)->forward() );
556 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
557 }
558 }
559 }
560 }
561
562 if( ! used ) {
565 if( end == 0 ) {
567 }
568 else {
570 }
572 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
573 }
574 }
575 }
576 }
577 }
578
580
585
586 unsigned int count = m_tofDataMap.count( iden_value_key );
588 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
589 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
592 if( end == 0 ) {
594 }
595 else {
597 }
599 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
600 }
601 }
602 else {
603 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMap.equal_range( iden_value_key );
604 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
605 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
606 bool used = false;
608 for(
unsigned int tofDataNumber = 0; tofDataNumber <
count; tofDataNumber++,
iter++ ) {
609 bool matched = false;
610 if( end == 0 ) {
611 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) {
612 if( ( ((*iter).second)->quality() & 0x1 ) != 0 ) {
613 double time1 = (*iter_pmt)->tdc();
614 double time2 = ((*iter).second)->tdc2();
616 if( endcap==0 && tofid==13 && strip==5 ) { matched = (
abs(time1-time2)<(100+
timeDiffMRPC) ); }
617 }
618 }
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651 if( matched ) {
652 used = true;
653 if( ( ( (*iter).second)->quality() & 0xc ) == 0 ) {
654 ((*iter).second)->setForward( (*iter_pmt) );
655 }
656 else {
662 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
663 }
664 }
665 }
666 else {
667 if( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) {
668 if( ( ((*iter).second)->quality() & 0x4 ) != 0 ) {
669 double time1 = (*iter_pmt)->tdc();
670 double time2 = ((*iter).second)->tdc1();
672 if( endcap==0 && tofid==13 && strip==5 ) { matched = (
abs(time1-time2)<(100+
timeDiffMRPC) ); }
673 }
674 }
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707 if( matched ) {
708 used = true;
709 if( ( ( (*iter).second)->quality() & 0x3 ) == 0 ) {
710 ((*iter).second)->setBackward( (*iter_pmt) );
711 }
712 else {
715 tof->
setForward( ((*iter).second)->forward() );
718 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
719 }
720 }
721 }
722 }
723
724 if( ! used ) {
727 if( end == 0 ) {
729 }
730 else {
732 }
734 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
735 }
736 }
737 }
738 }
739
740 pmtDataVec.clear();
741
742 }
743
744 return;
745
746}
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 module(const Identifier &id)
void setNumber(int number)