308 {
309
310 MsgStream log(
msgSvc(), name() );
311 log << MSG::INFO << " tof " << endmsg;
312
313
314 static const EstParameter Estparam;
315 double offset = 0, t_quality = 0, tOffset_b = 0, tOffset_e = 0;
316 int idtof, tofid_helix[30] = { -9 }, idmatch[3][88] = { 0 }, idmatch_emc[3][88] = { 0 },
317 idt[15] = { 0 }, particleId[30] = { 0 }, tofid_emc[2] = { 0 }, module[20] = { 0 };
318 int idetf, etfid_helix[30] = { -9 }, idetfmatch[3][36] = { -9 },
319 idmatch_etf_emc[3][36] = { 0 }, etfid_emc[2] = { 0 };
320 int ntot = 0, in = -1, out = -1, emcflag1 = 0, emcflag2 = 0, tof_flag = 0;
322 double meant[15] = { 0. }, adc[15] = { 0. },
momentum[15] = { 0. }, r_endtof[15] = { 0. };
323 double ttof[30] = { 0. }, helztof[30] = { 0.0 }, mcztof = 0.0, forevtime = 0.0,
324 backevtime = 0.0, meantev[500] = { 0. }, meantevup[500] = { 0.0 },
325 meantevdown[500] = { 0.0 };
326 double t0forward = 0, t0backward = 0, t0forward_trk = 0, t0backward_trk = 0;
327 double t0forward_add = 0, t0backward_add = 0, t_Est = -999;
328 double thetaemc_rec[20] = { 0. }, phiemc_rec[20] = { 0. }, energy_rec[20] = { 0. },
329 xemc_rec[20] = { 0. }, yemc_rec[20] = { 0. }, zemc_rec[20] = { 0. };
330 double r_endetf[30] = { 0. }, tetf[30] = { 0. }, helzetf[30] = { 0. },
331 helpathetf[36] = { 0. }, abmom2etf[36] = { 0. };
332
333 int nmatch1 = 0, nmatch2 = 0, nmatch_barrel = 0, nmatch_end = 0, nmatch_mdc = 0,
334 nmatch_barrel_1 = 0, nmatch_barrel_2 = 0, nmatch = 0, ntofup = 0, ntofdown = 0;
335 double sum_EstimeMdc = 0, sum_EstimeMdcMC = 0;
336 int nbunch = 0, tEstFlag = 0,
runNo = 0;
337 double helpath[88] = { 0. }, helz[88] = { 0. }, abmom2[88] = { 0. };
338 double mcTestime = 0, trigtiming = 0;
339 double mean_tdc_btof[2][88] = { 0. }, mean_tdc_etof[3][48] = { 0. },
340 mean_tdc_etf[3][36][12] = { 0. };
343 double Testime_fzisan = -999.;
344 int TestimeFlag_fzisan = -999;
345 double TestimeQuality_fzisan = -999.;
346 double Tof_t0Arr[500] = { -999. };
347
348 bool useEtofScin = (
m_phase < 3 );
349 bool useEtofMRPC = (
m_phase > 2 );
350
351
352 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
353 if ( !eventHeader )
354 {
355 log << MSG::FATAL << "Could not find Event Header" << endmsg;
356 return StatusCode::FAILURE;
357 }
358 int eventNo = eventHeader->eventNumber();
359 runNo = eventHeader->runNumber();
360 log << MSG::INFO <<
"EsTimeAlg: retrieved event: " <<
eventNo <<
" run: " <<
runNo
361 << endmsg;
362
364 {
367 }
369 {
375 }
377
380 {
383 }
385 {
388 }
390 {
393 }
395 {
398 }
400 {
403 }
405 {
408 }
410 {
413 }
415 {
418 }
420 {
421 g_bunchtime = 8;
422 g_t0offset_b = 2.0;
423 g_t0offset_e = 2.0;
424 }
425
426 m_pass[0]++;
427 if (
m_evtNo == 1 && m_pass[0] % 1000 == 0 )
428 { cout << "------------------- Events-----------------: " << m_pass[0] << endl; }
429 if (
m_debug == 4 ) cout <<
"m_userawtime: " << m_userawtime << endl;
430 if (
m_debug == 4 ) cout <<
"EstTofCalibSvc est flag: " << tofCaliSvc->ValidInfo() << endl;
431
432 if ( tofCaliSvc->chooseConstants(
runNo,
eventNo ) == StatusCode::FAILURE )
433 {
434 log << MSG::ERROR << "EstTof Calibration Const is NOT correct! " << endmsg;
435 return StatusCode::FAILURE;
436 }
438 {
439 log << MSG::ERROR << "EstTof Calibration Const is Invalid! " << endmsg;
440 return StatusCode::FAILURE;
441 }
442 if ( tofCaliSvc->ValidInfo() == 0 ||
m_userawtime_opt == 1 ) m_userawtime = 1;
443 else m_userawtime = 0;
444
445 SmartDataPtr<RecEsTimeCol> aRecestimeCol( eventSvc(), "/Event/Recon/RecEsTimeCol" );
446 if ( !aRecestimeCol || aRecestimeCol->size() == 0 )
447 {
449 log << MSG::INFO << "Could not find RecEsTimeCol from fzsian" << endmsg;
450 }
451 else
452 {
453 RecEsTimeCol::iterator it_evt = aRecestimeCol->begin();
454 for ( ; it_evt != aRecestimeCol->end(); it_evt++ )
455 {
456 Testime_fzisan = ( *it_evt )->getTest();
457 TestimeFlag_fzisan = ( *it_evt )->getStat();
458 TestimeQuality_fzisan = ( *it_evt )->getQuality();
459
460 log << MSG::INFO << "fzisan : Test = " << ( *it_evt )->getTest()
461 << ", Status = " << ( *it_evt )->getStat() << endmsg;
462
463 if (
m_ntupleflag && m_tuple2 ) g_Testime_fzisan = Testime_fzisan;
464 }
465 }
466
467 static std::string fullPath = "/Calib/EsTimeCal";
468 SmartDataPtr<CalibData::EsTimeCalibData> TEst( m_pCalibDataSvc, fullPath );
469 if ( !TEst ) { cout << "ERROR EsTimeCalibData" << endl; }
470 else
471 {
472 int no = TEst->getTestCalibConstNo();
473
474
475
476
477
478 unsigned int inumber = 0;
479 unsigned int calibNo = TEst->getSize();
480 if ( calibNo > 1 )
481 {
482 for ( unsigned int i = 0; i < calibNo; i++, inumber++ )
483 {
484 if ( ( TEst->getRunTo( i ) != -1 ) && ( TEst->getRunTo( i ) < TEst->getRunFrom( i ) ) )
485 {
486 log << MSG::ERROR << "EsTimeCal -- The " << inumber
487 << "th calibration constatns is ABNORMAL! Run From is LARGER than RUN To!"
488 << endmsg;
489 return StatusCode::FAILURE;
490 }
491 if ( ( TEst->getRunFrom( i ) == TEst->getRunTo( i ) ) &&
492 ( TEst->getEventFrom( i ) != -1 ) && ( TEst->getEventTo( i ) != -1 ) &&
493 ( TEst->getEventFrom( i ) > TEst->getEventTo( i ) ) )
494 {
495 log << MSG::ERROR << "EsTimeCal -- The " << inumber
496 << "th calibration constatns is ABNORMAL! Event From is LARGER than Event To!"
497 << endmsg;
498 return StatusCode::FAILURE;
499 }
500 }
501
502 inumber = 0;
503 bool filled = false;
504 for ( unsigned int i = 0; i < calibNo; i++, inumber++ )
505 {
506 int runFrom = TEst->getRunFrom( i );
507 int runTo = TEst->getRunTo( i );
508 int eventFrom = TEst->getEventFrom( i );
509 int eventTo = TEst->getEventTo( i );
510 if ( (
runNo == runFrom ) && ( ( eventFrom == -1 ) || (
eventNo >= eventFrom ) ) )
511 {
512 if ( (
runNo < runTo ) ||
513 ( (
runNo == runTo ) && ( ( eventTo == -1 ) || (
eventNo <= eventTo ) ) ) )
514 {
515 filled = true;
516 break;
517 }
518 }
519 if (
runNo > runFrom )
520 {
521 if ( (
runNo < runTo ) ||
522 ( (
runNo == runTo ) && ( ( eventTo == -1 ) || (
eventNo <= eventTo ) ) ) )
523 {
524 filled = true;
525 break;
526 }
527 }
528 }
529 if ( !filled )
530 {
531 log << MSG::ERROR <<
"EsTimeCal -- For run number:" <<
runNo
532 << ", NO suitable calibration constant is found!" << endmsg;
533 return StatusCode::FAILURE;
534 }
535 }
536
537 log << MSG::INFO << "offset barrel t0=" << TEst->getToffsetb( inumber )
538 << ", offset endcap t0=" << TEst->getToffsete( inumber )
539 << ", bunch time =" << TEst->getBunchTime( inumber ) << endmsg;
540 tOffset_b = TEst->getToffsetb( inumber );
541 tOffset_e = TEst->getToffsete( inumber );
542 bunchtime = TEst->getBunchTime( inumber );
543 }
544
545 if ( m_userawtime )
546 {
547 tOffset_b = 0;
548 tOffset_e = 0;
549 }
550 else
551 {
556 }
557
560
562
563
564 int digiId;
566 {
567 SmartDataPtr<McParticleCol> mcParticleCol( eventSvc(), "/Event/MC/McParticleCol" );
568 if ( !mcParticleCol ) { log << MSG::INFO << "Could not find McParticle" << endmsg; }
569 else
570 {
571 McParticleCol::iterator iter_mc = mcParticleCol->begin();
572 digiId = 0;
573 ntrkMC = 0;
574 int charge = 0;
575
576 for ( ; iter_mc != mcParticleCol->end(); iter_mc++, digiId++ )
577 {
578 int statusFlags = ( *iter_mc )->statusFlags();
579 int pid = ( *iter_mc )->particleProperty();
580 log << MSG::INFO << " MC ParticleId = " << pid << " statusFlags = " << statusFlags
581 << " PrimaryParticle = " << ( *iter_mc )->primaryParticle() << endmsg;
583 {
584 g_theta0MC[ntrkMC] = ( *iter_mc )->initialFourMomentum().theta();
585 g_phi0MC[ntrkMC] = ( *iter_mc )->initialFourMomentum().phi();
586 g_pxMC[ntrkMC] = ( *iter_mc )->initialFourMomentum().px() / 1000;
587 g_pyMC[ntrkMC] = ( *iter_mc )->initialFourMomentum().py() / 1000;
588 g_pzMC[ntrkMC] = ( *iter_mc )->initialFourMomentum().pz() / 1000;
589 g_ptMC[ntrkMC] = sqrt( ( ( *iter_mc )->initialFourMomentum().px() ) *
590 ( ( *iter_mc )->initialFourMomentum().px() ) +
591 ( ( *iter_mc )->initialFourMomentum().py() ) *
592 ( ( *iter_mc )->initialFourMomentum().py() ) ) /
593 1000;
594 }
595 if ( pid > 0 )
596 {
597 if ( m_particleTable->particle( pid ) )
598 charge = m_particleTable->particle( pid )->charge();
599 }
600 else if ( pid < 0 )
601 {
602 if ( m_particleTable->particle( -pid ) )
603 {
604 charge = m_particleTable->particle( -pid )->charge();
605 charge *= -1;
606 }
607 }
608 else { log << MSG::WARNING << "wrong particle id, please check data" << endmsg; }
609 log << MSG::DEBUG << "MC ParticleId = " << pid << " charge = " << charge << endmsg;
610 if ( charge != 0 &&
abs(
cos( ( *iter_mc )->initialFourMomentum().theta() ) ) < 0.93 )
611 { ntrkMC++; }
612 if ( ( ( *iter_mc )->primaryParticle() ) &&
m_ntupleflag && m_tuple2 )
613 {
614 g_mcTestime = ( *iter_mc )->initialPosition().t();
615 mcTestime = ( *iter_mc )->initialPosition().t();
616 }
617 }
619 }
620 }
621 if (
m_debug ) cout <<
"bunchtime: " << bunchtime << endl;
622
623 SmartDataPtr<RecMdcTrackCol> newtrkCol( eventSvc(), "/Event/Recon/RecMdcTrackCol" );
624 if ( !newtrkCol || newtrkCol->size() == 0 )
625 { log << MSG::INFO << "Could not find RecMdcTrackCol" << endmsg; }
626 else
627 {
628 log << MSG::INFO << "Begin to check RecMdcTrackCol" << endmsg;
629 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
630 for ( ; iter_trk != newtrkCol->end(); iter_trk++ )
631 {
632 log << MSG::DEBUG << "retrieved MDC track:"
633 << " Track Id: " << ( *iter_trk )->trackId()
634 << " Phi0: " << ( *iter_trk )->helix( 0 ) << " kappa: " << ( *iter_trk )->helix( 2 )
635 << " Tanl: " << ( *iter_trk )->helix( 4 )
636 << " Phi terminal: " << ( *iter_trk )->getFiTerm() << endmsg
637 << "Number of hits: " << ( *iter_trk )->getNhits() << " Number of stereo hits "
638 << ( *iter_trk )->nster() << endmsg;
639 double kappa = ( *iter_trk )->helix( 2 );
640 double tanl = ( *iter_trk )->helix( 4 );
641 if ( ( *iter_trk )->helix( 3 ) > 50.0 ) continue;
642 ntot++;
643 if ( ntot > 14 ) break;
644 momentum[ntot] = 1. / fabs( kappa ) * sqrt( 1. + tanl * tanl );
645 }
646 }
647
648
649 int emctrk = 0;
650 SmartDataPtr<RecEmcShowerCol> aShowerCol( eventSvc(), "/Event/Recon/RecEmcShowerCol" );
651 if ( !aShowerCol || aShowerCol->size() == 0 )
652 { log << MSG::WARNING << "Could not find RecEmcShowerCol" << endmsg; }
653 else
654 {
655 RecEmcShowerCol::iterator iShowerCol = aShowerCol->begin();
656 for ( ; iShowerCol != aShowerCol->end(); iShowerCol++, emctrk++ )
657 {
658 if ( emctrk > 19 ) break;
659 phiemc_rec[emctrk] = ( *iShowerCol )->position().phi();
660 thetaemc_rec[emctrk] = ( *iShowerCol )->position().theta();
661 energy_rec[emctrk] = ( *iShowerCol )->energy();
662 xemc_rec[emctrk] = ( *iShowerCol )->x();
663 yemc_rec[emctrk] = ( *iShowerCol )->y();
664 zemc_rec[emctrk] = ( *iShowerCol )->z();
665 module[emctrk] = ( *iShowerCol )->module();
666 }
667 }
668 for ( int i = 0; i < 2; i++ )
669 {
670 double fi_endtof = atan2( yemc_rec[i], xemc_rec[i] );
671 if ( fi_endtof < 0 ) { fi_endtof = 2 * 3.141593 + fi_endtof; }
672 if ( module[i] == 1 )
673 {
674 int Tofid = (int)( fi_endtof / ( 3.141593 / 44 ) );
675 if ( Tofid > 87 ) Tofid = Tofid - 88;
676 tofid_emc[i] = Tofid;
677 idmatch_emc[1][Tofid] = 1;
678 }
679 else
680 {
681 if ( useEtofScin )
682 {
683 int Tofid = (int)( fi_endtof / ( 3.141593 / 24 ) );
684 if ( Tofid > 47 ) Tofid = Tofid - 48;
685 tofid_emc[i] = Tofid;
686 if ( module[i] == 2 ) idmatch_emc[2][Tofid] = 1;
687 if ( module[i] == 0 ) idmatch_emc[0][Tofid] = 1;
688 }
689 if ( useEtofMRPC )
690 {
691 int Tofid = (int)( fi_endtof / ( 3.141593 / 18 ) );
692 if ( Tofid > 35 ) Tofid = Tofid - 36;
693 etfid_emc[i] = Tofid;
694 if ( module[i] == 2 ) idmatch_etf_emc[2][Tofid] = 1;
695 if ( module[i] == 0 ) idmatch_etf_emc[0][Tofid] = 1;
696 }
697 }
698 }
699
700 ntrk = 0;
701 if ( ntot > 0 )
702 {
703 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
704 for ( int idfztrk = 0; iter_trk != newtrkCol->end(); iter_trk++, idfztrk++ )
705 {
706 double mdcftrk[5];
707 mdcftrk[0] = ( *iter_trk )->helix( 0 );
708 mdcftrk[1] = ( *iter_trk )->helix( 1 );
709 mdcftrk[2] = -( *iter_trk )->helix( 2 );
710 mdcftrk[3] = ( *iter_trk )->helix( 3 );
711 mdcftrk[4] = ( *iter_trk )->helix( 4 );
712
713 if ( optCosmic == 0 )
714 {
715 Emc_helix EmcHit;
716
718
719
720
721 if ( EmcHit.
Emc_Get( sqrt(
RCEMC2 ), idfztrk, mdcftrk ) > 0 )
722 {
723 double z_emc = EmcHit.
Z_emc;
725 double phiemc_ext = EmcHit.
phi_emc;
726
727 double kappa = ( *iter_trk )->helix( 2 );
728 double tanl = ( *iter_trk )->helix( 4 );
729 double _momentum = 1. / fabs( kappa ) * sqrt( 1. + tanl * tanl );
730 for (
int t = 0;
t < emctrk;
t++ )
731 {
732 if ( ( thetaemc_ext >= ( thetaemc_rec[
t] - 0.1 ) ) &&
733 ( thetaemc_ext <= ( thetaemc_rec[
t] + 0.1 ) ) &&
734 ( phiemc_ext >= ( phiemc_rec[
t] - 0.1 ) ) &&
735 ( phiemc_ext <= ( phiemc_rec[
t] + 0.1 ) ) )
736 {
737 if ( ( energy_rec[
t] ) >= ( 0.85 * _momentum ) ) particleId[idfztrk] = 1;
738 }
739 }
740 }
741
742 if ( particleId[idfztrk] != 1 )
743 {
744
745 SmartDataPtr<RecMdcDedxCol> newdedxCol( eventSvc(), "/Event/Recon/RecMdcDedxCol" );
746 if ( !newdedxCol || newdedxCol->size() == 0 )
747 { log << MSG::WARNING << "Could not find RecMdcDedxCol" << endmsg; }
748 else
749 {
750 RecMdcDedxCol::iterator it_dedx = newdedxCol->begin();
751 for ( int npid = 0; it_dedx != newdedxCol->end(); it_dedx++, npid++ )
752 {
753 log << MSG::INFO << "retrieved MDC dE/dx: "
754 << "dEdx Id: " << ( *it_dedx )->trackId()
755 << " particle Id: " << ( *it_dedx )->particleType() << endmsg;
756 if ( ( *it_dedx )->particleType() ==
proton ) { particleId[npid] = 5; }
757 if (
m_debug == 4 ) cout <<
"dedx pid: " << particleId[npid] << endl;
758 }
759 }
760 }
761 }
762
763 idtof = -100;
764 idetf = -100;
765 TofFz_helix TofHit;
766
767
769
770
773
775 if ( tofpart < 0 ) continue;
776
777
778 bool useBarrelScin = ( tofpart == 1 );
779 bool useEndcapScin = ( ( tofpart == 0 || tofpart == 2 ) &&
780 useEtofScin );
781 bool useEndcapMRPC = ( ( tofpart == 0 || tofpart == 2 ) &&
782 useEtofMRPC );
783
784 if ( useBarrelScin || useEndcapScin )
785 {
786 idtof = TofHit.
Tofid;
787 tofid_helix[idfztrk] = TofHit.
Tofid;
788 }
789 if ( useEndcapMRPC )
790 {
791 idetf = TofHit.
Etfid;
792 etfid_helix[idfztrk] = TofHit.
Etfid;
793 }
794
795 log << MSG::INFO << "helix to tof hit part: " << tofpart << " tof id: " << idtof
796 << " etf id:" << idetf << endmsg;
798 cout << "helix to tof hit part, Id: " << tofpart << " , " << idtof << endl;
799 if ( ( useBarrelScin && idtof >= 0 && idtof <= 87 ) ||
800 ( useEndcapScin && idtof >= 0 && idtof <= 47 ) ||
801 ( useEndcapMRPC && idetf >= 0 && idetf <= 35 ) )
802 {
803
804 double abmom = 0.0;
805 if ( useEndcapMRPC )
806 {
807 idetfmatch[tofpart][idetf] = 1;
808 helpathetf[idetf] = TofHit.
Path_etf;
809 helz[idetf] = TofHit.
Z_etf;
810 abmom = 1. / fabs( TofHit.
Kappa ) * sqrt( 1. + TofHit.
Tanl * TofHit.
Tanl );
811 if ( abmom < 0.1 ) continue;
812 abmom2etf[idetf] = abmom * abmom;
813 r_endetf[idfztrk] = TofHit.
r_etf;
814 helzetf[idfztrk] = helz[idetf];
815 }
816
817 if ( useBarrelScin || useEndcapScin )
818 {
819 idmatch[tofpart][idtof] = 1;
820 helpath[idtof] = TofHit.
Pathl;
821 helz[idtof] = TofHit.
Z_tof;
822 abmom = 1. / fabs( TofHit.
Kappa ) * sqrt( 1. + TofHit.
Tanl * TofHit.
Tanl );
823 if ( abmom < 0.1 ) continue;
824 abmom2[idtof] = abmom * abmom;
825 r_endtof[idfztrk] = TofHit.
r_endtof;
826 helztof[idfztrk] = helz[idtof];
827 }
828
830 {
831 cout << "Scintillator info trk number=" << idfztrk << " tofpart=" << tofpart
832 << " idtof=" << idtof << " helpath=" << helpath[idtof]
833 << " helz=" << helz[idtof] << " abmom=" << abmom2[idtof]
834 << " r=" << r_endtof[idfztrk] << " helztof=" << helz[idtof] << endl;
835 cout << "MRPC info trk number=" << idfztrk << " tofpart=" << tofpart
836 << " idetf=" << idetf << " helpath=" << helpathetf[idetf]
837 << " helz=" << helzetf[idetf] << " abmom=" << abmom2etf[idetf]
838 << " r=" << r_endetf[idfztrk] << " helztof=" << helzetf[idetf] << endl;
839 }
840
841 double vel = 1.0e-6;
842 if ( optCosmic == 0 )
843 {
844
845 if ( useEndcapMRPC )
846 {
847 if ( particleId[idfztrk] == 1 )
848 {
849 tetf[idfztrk] =
850 sqrt(
ELMAS2 / abmom2etf[idetf] + 1 ) * helpathetf[idetf] /
VLIGHT;
852 }
853 else if ( particleId[idfztrk] == 5 )
854 {
855 tetf[idfztrk] =
858 }
859 else
860 {
861 tetf[idfztrk] =
862 sqrt(
PIMAS2 / abmom2etf[idetf] + 1 ) * helpathetf[idetf] /
VLIGHT;
864 }
865 }
866
867 if ( useBarrelScin || useEndcapScin )
868 {
869 if ( particleId[idfztrk] == 1 )
870 {
871 ttof[idfztrk] = sqrt(
ELMAS2 / abmom2[idtof] + 1 ) * helpath[idtof] /
VLIGHT;
873 }
874 else if ( particleId[idfztrk] == 5 )
875 {
876 ttof[idfztrk] = sqrt(
PROTONMAS2 / abmom2[idtof] + 1 ) * helpath[idtof] /
VLIGHT;
878 }
879 else
880 {
881 ttof[idfztrk] = sqrt(
PIMAS2 / abmom2[idtof] + 1 ) * helpath[idtof] /
VLIGHT;
883 }
884 }
885 }
886 else
887 {
888
889 if ( useEndcapMRPC )
890 {
891 tetf[idfztrk] = sqrt(
MUMAS2 / abmom2etf[idetf] + 1 ) * helpathetf[idetf] /
VLIGHT;
893 }
894
895 if ( useBarrelScin || useEndcapMRPC )
896 {
897 ttof[idfztrk] = sqrt(
MUMAS2 / abmom2[idtof] + 1 ) * helpath[idtof] /
VLIGHT;
899 }
900 }
901
903 {
904 g_vel[idfztrk] = vel;
905 g_abmom[idfztrk] = abmom;
906 if ( useEndcapMRPC ) { g_ttof[idfztrk] = tetf[idfztrk]; }
907 if ( useBarrelScin || useEndcapScin ) { g_ttof[idfztrk] = ttof[idfztrk]; }
908 g_pid[idfztrk] = particleId[idfztrk];
909 }
910 }
911 ntrk++;
912 }
914 }
915
916
917
919 {
920 SmartDataPtr<TofMcHitCol> tofmcHitCol( eventSvc(), "/Event/MC/TofMcHitCol" );
921 if ( !tofmcHitCol )
922 {
923 log << MSG::ERROR << "Could not find McParticle" << endmsg;
924
925 }
926 else
927 {
928 TofMcHitCol::iterator iter_mctof = tofmcHitCol->begin();
929
930 for ( ; iter_mctof != tofmcHitCol->end(); iter_mctof++, digiId++ )
931 {
932 log << MSG::INFO << " TofMcHit Flight Time = " << ( *iter_mctof )->getFlightTime()
933 << " zPosition = " << ( ( *iter_mctof )->getPositionZ() ) / 10
934 << " xPosition = " << ( ( *iter_mctof )->getPositionX() ) / 10
935 << " yPosition = " << ( ( *iter_mctof )->getPositionY() ) / 10 << endmsg;
936 }
937 }
938 }
939
940
941 TofDataVector tofDigiVec = m_rawDataProviderSvc->tofDataVectorEstime();
942
943 for ( TofDataVector::iterator iter2 = tofDigiVec.begin(); iter2 != tofDigiVec.end();
944 iter2++ )
945 {
946 int barrelid;
947 int layerid;
948 int tofid;
949 int strip;
950
951 if ( !( ( *iter2 )->is_mrpc() ) )
952 {
953 if ( ( *iter2 )->barrel() )
954 {
955 barrelid = 1;
956 tofid = ( *iter2 )->tofId();
957 layerid = ( *iter2 )->layer();
958 if ( layerid == 1 ) tofid = tofid - 88;
959 if ( ( ( *iter2 )->quality() & 0x5 ) == 0x5 && ( *iter2 )->times() == 1 )
960 {
961 double ftdc = ( *iter2 )->tdc1();
962 double btdc = ( *iter2 )->tdc2();
963 mean_tdc_btof[layerid][tofid] = ( ftdc + btdc ) / 2;
964 }
965 else if ( ( ( *iter2 )->quality() & 0x5 ) == 0x5 && ( *iter2 )->times() > 1 )
966 {
967 double ftdc = ( *iter2 )->tdc1();
968 double btdc = ( *iter2 )->tdc2();
969 mean_tdc_btof[layerid][tofid] = ( ftdc + btdc ) / 2;
970 }
971 }
972 else
973 {
974 tofid = ( *iter2 )->tofId();
975 if ( tofid < 48 ) barrelid = 0;
976 if ( tofid > 47 ) barrelid = 2;
977 if ( barrelid == 2 ) tofid = tofid - 48;
978
979 if ( ( *iter2 )->times() == 1 )
980 {
981 double ftdc = ( *iter2 )->tdc();
982 mean_tdc_etof[barrelid][tofid] = ftdc;
983 }
984 else if ( ( ( *iter2 )->times() > 1 ) && ( ( *iter2 )->times() < 5 ) )
985 {
986 double ftdc = ( *iter2 )->tdc();
987 mean_tdc_etof[barrelid][tofid] = ftdc;
988 }
989 }
990 }
991 else
992 {
993 tofid = ( *iter2 )->tofId();
994 strip = ( *iter2 )->strip();
995 if ( tofid < 36 ) barrelid = 0;
996 if ( tofid > 35 ) barrelid = 2;
997 if ( barrelid == 2 ) tofid = tofid - 36;
998 if ( ( ( *iter2 )->quality() & 0x5 ) == 0x5 && ( *iter2 )->times() == 1 )
999 {
1000 double ftdc = ( *iter2 )->tdc1();
1001 double btdc = ( *iter2 )->tdc2();
1002 mean_tdc_etf[barrelid][tofid][strip] = ( ftdc + btdc ) / 2;
1003 }
1004 else if ( ( ( *iter2 )->quality() & 0x5 ) == 0x5 && ( *iter2 )->times() > 1 )
1005 {
1006 double ftdc = ( *iter2 )->tdc1();
1007 double btdc = ( *iter2 )->tdc2();
1008 mean_tdc_etf[barrelid][tofid][strip] = ( ftdc + btdc ) / 2;
1009 }
1010 }
1011 }
1012
1013 double difftof_b = 100, difftof_e = 100;
1014 int tofid1 = tofid_emc[0];
1015 int tofid2 = tofid_emc[1];
1016 if ( module[0] == 1 && module[1] == 1 )
1017 {
1018 for ( int i = 0; i < 2; i++ )
1019 {
1020 for ( int m = 0; m < 2; m++ )
1021 {
1022 for ( int j = -2; j < 3; j++ )
1023 {
1024 for ( int k = -2; k < 3; k++ )
1025 {
1026 int p = tofid1 + j;
1028 if ( p < 0 ) p = p + 88;
1029 if ( p > 87 ) p = p - 88;
1030 if (
q < 0 )
q =
q + 88;
1031 if (
q > 87 )
q =
q + 88;
1032 if ( mean_tdc_btof[i][p] == 0 || mean_tdc_btof[m][
q] == 0 )
continue;
1033 double difftof_b_temp = mean_tdc_btof[i][p] - mean_tdc_btof[m][
q];
1034 if (
abs( difftof_b_temp ) <
abs( difftof_b ) ) difftof_b = difftof_b_temp;
1035 if (
m_ntupleflag && m_tuple2 ) g_difftof_b = difftof_b;
1036 }
1037 }
1038 }
1039 }
1040 }
1041
1042 if ( useEtofMRPC )
1043 {
1044 if ( module[0] != 1 && module[1] != 1 )
1045 {
1046 tofid1 = etfid_emc[0];
1047 tofid2 = etfid_emc[1];
1048 for ( int i = -1; i < 2; i++ )
1049 {
1050 for ( int j = -1; j < 2; j++ )
1051 {
1052 int m = tofid1 + i;
1054 if ( m < 0 ) m = 36 + m;
1055 if ( m > 35 ) m = m - 36;
1056 if (
n < 0 )
n = 36 +
n;
1057 if (
n > 35 )
n =
n - 36;
1058 if ( mean_tdc_etf[0][m] && mean_tdc_etf[2][
n] )
1059 {
1060 double difftof_e_temp = mean_tdc_etf[0][m] - mean_tdc_etf[2][
n];
1061 if (
abs( difftof_e_temp ) <
abs( difftof_e ) ) difftof_e = difftof_e_temp;
1062 if (
m_ntupleflag && m_tuple2 ) g_difftof_e = difftof_e;
1063 }
1064 }
1065 }
1066 }
1067 }
1068
1069 if ( useEtofScin )
1070 {
1071 if ( module[0] != 1 && module[1] != 1 )
1072 {
1073 for ( int i = -1; i < 2; i++ )
1074 {
1075 for ( int j = -1; j < 2; j++ )
1076 {
1077 int m = tofid1 + i;
1079 if ( m < 0 ) m = 48 + m;
1080 if ( m > 47 ) m = m - 48;
1081 if (
n < 0 )
n = 48 +
n;
1082 if (
n > 47 )
n =
n - 48;
1083 if ( mean_tdc_etof[0][m] && mean_tdc_etof[2][
n] )
1084 {
1085 double difftof_e_temp = mean_tdc_etof[0][m] - mean_tdc_etof[2][
n];
1086 if (
abs( difftof_e_temp ) <
abs( difftof_e ) ) difftof_e = difftof_e_temp;
1087 if (
m_ntupleflag && m_tuple2 ) g_difftof_e = difftof_e;
1088 }
1089 }
1090 }
1091 }
1092 }
1093
1095 else optCosmic = 0;
1096
1097 digiId = 0;
1098 unsigned int tofid;
1099 unsigned int barrelid;
1100 unsigned int layerid;
1101 t0forward_add = 0;
1102 t0backward_add = 0;
1103 TofDataVector::iterator iter2 = tofDigiVec.begin();
1104 for ( ; iter2 != tofDigiVec.end(); iter2++, digiId++ )
1105 {
1106 log << MSG::INFO << "TOF digit No: " << digiId << endmsg;
1107 barrelid = ( *iter2 )->barrel();
1108 if ( ( *iter2 )->barrel() == 0 ) continue;
1109 if ( ( ( *iter2 )->quality() & 0x5 ) == 0x5 && ( *iter2 )->times() == 1 )
1110 {
1111 tofid = ( *iter2 )->tofId();
1112 layerid = ( *iter2 )->layer();
1113 if ( layerid == 1 ) tofid = tofid - 88;
1114 log << MSG::INFO << " TofId = " << tofid << " barrelid = " << barrelid
1115 << " layerid = " << layerid << " ForwordADC = " << ( *iter2 )->adc1()
1116 << " ForwordTDC = " << ( *iter2 )->tdc1()
1117 << " BackwordADC = " << ( *iter2 )->adc2()
1118 << " BackwordTDC = " << ( *iter2 )->tdc2() << endmsg;
1119
1120 double ftdc = ( *iter2 )->tdc1();
1121 double btdc = ( *iter2 )->tdc2();
1123 cout << "barrel 1 ::layer, barrel, tofid, ftdc, btdc: " << layerid << " , " << barrelid
1124 << " , " << tofid << " , " << ftdc << " , " << btdc << endl;
1125 double fadc = ( *iter2 )->adc1();
1126 double badc = ( *iter2 )->adc2();
1127 int idptof = ( ( tofid - 1 ) == -1 ) ? 87 : tofid - 1;
1128 int idntof = ( ( tofid + 1 ) == 88 ) ? 0 : tofid + 1;
1129 double ztof = fabs( ( ftdc - btdc ) / 2 ) * 17.7, ztof2 = ztof * ztof;
1130 double mean_tdc = 0.5 * ( btdc + ftdc );
1132
1133 if ( idmatch[barrelid][tofid] == 1 || idmatch[barrelid][idptof] == 1 ||
1134 idmatch[barrelid][idntof] == 1 )
1135 {
1136 for ( int i = 0; i < ntot; i++ )
1137 {
1138 if ( ttof[i] != 0 && ftdc > 0 )
1139 {
1140 if ( ( tofid_helix[i] == tofid ) || ( tofid_helix[i] == idntof ) ||
1141 ( tofid_helix[i] == idptof ) )
1142 {
1143 if ( barrelid == 1 && helztof[i] < 117 && helztof[i] > -117 )
1144 {
1145 if ( optCosmic && tofid < 44 )
1146 {
1147 backevtime = -ttof[i] + ( 115 + helztof[i] ) * 0.0566 + 12.;
1148 forevtime = -ttof[i] + ( 115 - helztof[i] ) * 0.0566 + 12.;
1149 meantevup[ntofup] = ( backevtime + forevtime ) / 2;
1150 ntofup++;
1151 }
1152 else
1153 {
1154 backevtime = ttof[i] + ( 115 + helztof[i] ) * 0.0566 + 12.;
1155 forevtime = ttof[i] + ( 115 - helztof[i] ) * 0.0566 + 12.;
1156 meantevdown[ntofdown] = ( backevtime + forevtime ) / 2;
1157 ntofdown++;
1158 }
1159 if ( ( *iter2 )->adc1() < 0.0 || ( *iter2 )->adc2() < 0.0 || m_userawtime )
1160 {
1161 t0forward_trk = ftdc - forevtime;
1162 t0backward_trk = btdc - backevtime;
1163 }
1164 else
1165 {
1166 t0forward_trk = tofCaliSvc->BTime1( ( *iter2 )->adc1(), ( *iter2 )->tdc1(),
1167 helztof[i], ( *iter2 )->tofId() ) -
1168 ttof[i];
1169 t0backward_trk = tofCaliSvc->BTime2( ( *iter2 )->adc2(), ( *iter2 )->tdc2(),
1170 helztof[i], ( *iter2 )->tofId() ) -
1171 ttof[i];
1172 if ( optCosmic && tofid < 44 )
1173 {
1174 t0forward_trk = tofCaliSvc->BTime1( ( *iter2 )->adc1(), ( *iter2 )->tdc1(),
1175 helztof[i], ( *iter2 )->tofId() ) +
1176 ttof[i];
1177 t0backward_trk =
1178 tofCaliSvc->BTime2( ( *iter2 )->adc2(), ( *iter2 )->tdc2(), helztof[i],
1179 ( *iter2 )->tofId() ) +
1180 ttof[i];
1181 }
1182 }
1183
1184 if ( t0forward_trk < -3 || t0backward_trk < -3 ||
1185 fabs( t0forward_trk - t0backward_trk ) > 15.0 )
1186 continue;
1187 if ( !
m_TofOpt && nmatch_barrel != 0 &&
1188 fabs( ( t0forward_trk + t0backward_trk ) / 2 -
1189 ( t0backward_add + t0forward_add ) / 2 / nmatch_barrel ) > 11 )
1190 continue;
1192 cout << " t0forward_trk, t0backward_trk: " << t0forward_trk << " , "
1193 << t0backward_trk << endl;
1195 {
1196 g_t0for[nmatch1] = t0forward_trk;
1197 g_t0back[nmatch2] = t0backward_trk;
1198 g_meantdc = ( ftdc + btdc ) / 2;
1199 if ( tofid < 44 ) g_ntofup1++;
1200 else g_ntofdown1++;
1201 }
1202 t0forward_add += t0forward_trk;
1203 t0backward_add += t0backward_trk;
1204 if ( nmatch > 499 ) break;
1205 meantev[nmatch] = ( backevtime + forevtime ) / 2;
1206 Tof_t0Arr[nmatch] = ( t0forward_trk + t0backward_trk ) / 2.0;
1207 nmatch++;
1208 nmatch1 = nmatch1 + 1;
1209 nmatch2 = nmatch2 + 1;
1210 nmatch_barrel++;
1211 }
1212 }
1213 }
1214 }
1215 }
1216 }
1217 }
1218
1219 if ( nmatch_barrel != 0 )
1220 {
1222 { g_t0barrelTof = ( t0forward_add / nmatch_barrel + t0backward_add / nmatch_barrel ) / 2; }
1223 tof_flag = 1;
1224 t_quality = 1;
1225 }
1226
1227 if ( nmatch_barrel == 0 )
1228 {
1229 digiId = 0;
1230 t0forward_add = 0;
1231 t0backward_add = 0;
1232 for ( TofDataVector::iterator iter2 = tofDigiVec.begin(); iter2 != tofDigiVec.end();
1233 iter2++, digiId++ )
1234 {
1235 log << MSG::INFO << "TOF digit No: " << digiId << endmsg;
1236 barrelid = ( *iter2 )->barrel();
1237 if ( ( *iter2 )->barrel() == 0 ) continue;
1238 if ( ( ( *iter2 )->quality() & 0x5 ) == 0x5 && ( *iter2 )->times() > 1 )
1239 {
1240 tofid = ( *iter2 )->tofId();
1241 layerid = ( *iter2 )->layer();
1242 if ( layerid == 1 ) tofid = tofid - 88;
1243 log << MSG::INFO << " TofId = " << tofid << " barrelid = " << barrelid
1244 << " layerid = " << layerid << " ForwordADC = " << ( *iter2 )->adc1()
1245 << " ForwordTDC = " << ( *iter2 )->tdc1() << endmsg;
1246 double ftdc = ( *iter2 )->tdc1();
1247 double btdc = ( *iter2 )->tdc2();
1248 double fadc = ( *iter2 )->adc1();
1249 double badc = ( *iter2 )->adc2();
1251 cout << "barrel 2 ::layer, barrel, tofid, ftdc, btdc: " << layerid << " , "
1252 << barrelid << " , " << tofid << " , " << ftdc << " , " << btdc << endl;
1253 int idptof = ( ( tofid - 1 ) == -1 ) ? 87 : tofid - 1;
1254 int idntof = ( ( tofid + 1 ) == 88 ) ? 0 : tofid + 1;
1255 if ( idmatch[barrelid][tofid] == 1 || idmatch[barrelid][idptof] == 1 ||
1256 idmatch[barrelid][idntof] == 1 )
1257 {
1258 for ( int i = 0; i < ntot; i++ )
1259 {
1260 if ( ttof[i] != 0 && ftdc > 0 )
1261 {
1262 if ( tofid_helix[i] == tofid || ( tofid_helix[i] == idptof ) ||
1263 ( tofid_helix[i] == idntof ) )
1264 {
1265 if ( barrelid == 1 && helztof[i] < 117 && helztof[i] > -117 )
1266 {
1267 if ( optCosmic && tofid < 44 )
1268 {
1269 backevtime = -ttof[i] + ( 115 + helztof[i] ) * 0.0566 + 12.;
1270 forevtime = -ttof[i] + ( 115 - helztof[i] ) * 0.0566 + 12.;
1271 meantevup[ntofup] = ( backevtime + forevtime ) / 2;
1272 ntofup++;
1273 }
1274 else
1275 {
1276 backevtime = ttof[i] + ( 115 + helztof[i] ) * 0.0566 + 12.;
1277 forevtime = ttof[i] + ( 115 - helztof[i] ) * 0.0566 + 12.;
1278 meantevdown[ntofdown] = ( backevtime + forevtime ) / 2;
1279 ntofdown++;
1280 }
1281 if ( ( *iter2 )->adc1() < 0.0 || ( *iter2 )->adc2() < 0.0 || m_userawtime )
1282 {
1283 t0forward_trk = ftdc - forevtime;
1284 t0backward_trk = btdc - backevtime;
1285 }
1286 else
1287 {
1288 t0forward_trk = tofCaliSvc->BTime1( ( *iter2 )->adc1(), ( *iter2 )->tdc1(),
1289 helztof[i], ( *iter2 )->tofId() ) -
1290 ttof[i];
1291 t0backward_trk =
1292 tofCaliSvc->BTime2( ( *iter2 )->adc2(), ( *iter2 )->tdc2(), helztof[i],
1293 ( *iter2 )->tofId() ) -
1294 ttof[i];
1295 if ( optCosmic && tofid < 44 )
1296 {
1297 t0forward_trk =
1298 tofCaliSvc->BTime1( ( *iter2 )->adc1(), ( *iter2 )->tdc1(),
1299 helztof[i], ( *iter2 )->tofId() ) +
1300 ttof[i];
1301 t0backward_trk =
1302 tofCaliSvc->BTime2( ( *iter2 )->adc2(), ( *iter2 )->tdc2(),
1303 helztof[i], ( *iter2 )->tofId() ) +
1304 ttof[i];
1305 }
1306 }
1307
1308 if ( t0forward_trk < -3 || t0backward_trk < -3 ||
1309 fabs( t0forward_trk - t0backward_trk ) > 15.0 )
1310 continue;
1311 if ( !
m_TofOpt && nmatch_barrel != 0 &&
1312 fabs( ( t0forward_trk + t0backward_trk ) / 2 -
1313 ( t0backward_add + t0forward_add ) / 2 / nmatch_barrel ) > 11 )
1314 continue;
1316 cout << "t0forward_trk, t0backward_trk: " << t0forward_trk << " , "
1317 << t0backward_trk << endl;
1319 {
1320 g_t0for[nmatch1] = t0forward_trk;
1321 g_t0back[nmatch2] = t0backward_trk;
1322 g_meantdc = ( ftdc + btdc ) / 2;
1323 if ( tofid < 44 ) g_ntofup1++;
1324 else g_ntofdown1++;
1325 }
1326 t0forward_add += t0forward_trk;
1327 t0backward_add += t0backward_trk;
1328 if ( nmatch > 499 ) break;
1329 meantev[nmatch] = ( backevtime + forevtime ) / 2;
1330 Tof_t0Arr[nmatch] = ( t0forward_trk + t0backward_trk ) / 2.0;
1331 nmatch++;
1332 nmatch1 = nmatch1 + 1;
1333 nmatch2 = nmatch2 + 1;
1334 nmatch_barrel++;
1335 }
1336 }
1337 }
1338 }
1339 }
1340 }
1341 }
1342 if ( nmatch_barrel ) tof_flag = 2;
1343 }
1344
1345 if ( ntot == 0 || nmatch_barrel == 0 )
1346 {
1347 for ( TofDataVector::iterator iter2 = tofDigiVec.begin(); iter2 != tofDigiVec.end();
1348 iter2++, digiId++ )
1349 {
1350 log << MSG::INFO << "TOF digit No: " << digiId << endmsg;
1351 barrelid = ( *iter2 )->barrel();
1352 if ( ( *iter2 )->barrel() == 0 ) continue;
1353 if ( ( ( *iter2 )->quality() & 0x5 ) == 0x5 && ( *iter2 )->times() == 1 )
1354 {
1355 tofid = ( *iter2 )->tofId();
1356 layerid = ( *iter2 )->layer();
1357 if ( layerid == 1 ) tofid = tofid - 88;
1358 log << MSG::INFO << " TofId = " << tofid << " barrelid = " << barrelid
1359 << " layerid = " << layerid << " ForwordADC = " << ( *iter2 )->adc1()
1360 << " ForwordTDC = " << ( *iter2 )->tdc1() << endmsg;
1361 double ftdc = ( *iter2 )->tdc1();
1362 double btdc = ( *iter2 )->tdc2();
1363 double fadc = ( *iter2 )->adc1();
1364 double badc = ( *iter2 )->adc2();
1366 cout << "barrel 3 ::layer, barrel, tofid, ftdc, btdc: " << layerid << " , "
1367 << barrelid << " , " << tofid << " , " << ftdc << " , " << btdc << endl;
1368 int idptof = ( ( tofid - 1 ) == -1 ) ? 87 : tofid - 1;
1369 int idntof = ( ( tofid + 1 ) == 88 ) ? 0 : tofid + 1;
1370 for ( int i = 0; i < 2; i++ )
1371 {
1372 if ( tofid_emc[i] == tofid || tofid_emc[i] == idptof || tofid_emc[i] == idntof )
1373 {
1374 if ( zemc_rec[0] || zemc_rec[1] )
1375 {
1376 if ( tofid == tofid_emc[i] || tofid_emc[i] == idntof || tofid_emc[i] == idptof )
1377 {
1378 if ( ftdc > 2000. || module[i] != 1 ) continue;
1380 sqrt( xemc_rec[i] * xemc_rec[i] + yemc_rec[i] * yemc_rec[i] +
1381 zemc_rec[i] * zemc_rec[i] ) /
1383 if ( optCosmic == 1 && tofid < 44 )
1384 {
1385 backevtime = -ttof[i] + ( 115 + zemc_rec[i] ) * 0.0566 + 12.;
1386 forevtime = -ttof[i] + ( 115 - zemc_rec[i] ) * 0.0566 + 12.;
1387 meantevup[ntofup] = ( backevtime + forevtime ) / 2;
1388 ntofup++;
1389 }
1390 else
1391 {
1392 backevtime = ttof[i] + ( 115 + zemc_rec[i] ) * 0.0566 + 12.;
1393 forevtime = ttof[i] + ( 115 - zemc_rec[i] ) * 0.0566 + 12.;
1394 meantevdown[ntofdown] = ( backevtime + forevtime ) / 2;
1395 ntofdown++;
1396 }
1397 if ( ( *iter2 )->adc1() < 0.0 || ( *iter2 )->adc2() < 0.0 || m_userawtime )
1398 {
1399 t0forward_trk = ftdc - forevtime;
1400 t0backward_trk = btdc - backevtime;
1401 }
1402 else
1403 {
1404 t0forward_trk = tofCaliSvc->BTime1( ( *iter2 )->adc1(), ( *iter2 )->tdc1(),
1405 helztof[i], ( *iter2 )->tofId() ) -
1406 ttof[i];
1407 t0backward_trk = tofCaliSvc->BTime2( ( *iter2 )->adc2(), ( *iter2 )->tdc2(),
1408 helztof[i], ( *iter2 )->tofId() ) -
1409 ttof[i];
1410 if ( optCosmic && tofid < 44 )
1411 {
1412 t0forward_trk = tofCaliSvc->BTime1( ( *iter2 )->adc1(), ( *iter2 )->tdc1(),
1413 helztof[i], ( *iter2 )->tofId() ) +
1414 ttof[i];
1415 t0backward_trk =
1416 tofCaliSvc->BTime2( ( *iter2 )->adc2(), ( *iter2 )->tdc2(), helztof[i],
1417 ( *iter2 )->tofId() ) +
1418 ttof[i];
1419 }
1420 }
1421
1422 if ( t0forward_trk < -1 || t0backward_trk < -1 ||
1423 fabs( t0forward_trk - t0backward_trk ) > 15.0 )
1424 continue;
1425 if ( !
m_TofOpt && nmatch_barrel != 0 &&
1426 fabs( ( t0forward_trk + t0backward_trk ) / 2 -
1427 ( t0backward_add + t0forward_add ) / 2 / nmatch_barrel ) > 11 )
1428 continue;
1430 cout << "t0forward_trk, t0backward_trk: " << t0forward_trk << " , "
1431 << t0backward_trk << endl;
1432 t0forward_add += t0forward_trk;
1433 t0backward_add += t0backward_trk;
1434 if ( nmatch > 499 ) break;
1435 meantev[nmatch] = ( backevtime + forevtime ) / 2;
1436 Tof_t0Arr[nmatch] = ( t0forward_trk + t0backward_trk ) / 2.0;
1437 nmatch++;
1438 nmatch_barrel++;
1439 emcflag1 = 1;
1440 }
1441 }
1442 }
1443 }
1444 }
1445 }
1446 if ( nmatch_barrel ) tof_flag = 3;
1447 }
1448
1449 if ( nmatch_barrel != 0 )
1450 {
1451 t0forward = t0forward_add / nmatch_barrel;
1452 t0backward = t0backward_add / nmatch_barrel;
1453 if ( optCosmic == 0 )
1454 {
1456 {
1457 t_Est = EST_Trimmer( Opt_new( Tof_t0Arr, nmatch,
m_TofOpt_Cut ), tOffset_b,
1459 }
1460 else
1461 t_Est = EST_Trimmer( ( t0forward + t0backward ) / 2, tOffset_b,
toffset_rawtime,
1463 if ( t_Est < 0 ) t_Est = 0;
1464 if ( tof_flag == 1 ) tEstFlag = 111;
1465 else if ( tof_flag == 2 ) tEstFlag = 121;
1466 else if ( tof_flag == 3 ) tEstFlag = 131;
1467 }
1468 if ( optCosmic )
1469 {
1470 t_Est = ( t0forward + t0backward ) / 2;
1471 if ( tof_flag == 1 ) tEstFlag = 211;
1472 else if ( tof_flag == 2 ) tEstFlag = 221;
1473 else if ( tof_flag == 3 ) tEstFlag = 231;
1474 }
1475 if (
m_ntupleflag && m_tuple2 ) g_meant0 = ( t0forward + t0backward ) / 2;
1476 }
1477
1478 digiId = 0;
1479 t0forward_add = 0;
1480 t0backward_add = 0;
1481
1482 if ( nmatch_barrel == 0 )
1483 {
1484 for ( TofDataVector::iterator iter2 = tofDigiVec.begin(); iter2 != tofDigiVec.end();
1485 iter2++, digiId++ )
1486 {
1487 log << MSG::INFO << "TOF digit No: " << digiId << endmsg;
1488 barrelid = ( *iter2 )->barrel();
1489 if ( ( *iter2 )->barrel() == 0 ) continue;
1490 if ( ( ( *iter2 )->quality() & 0x5 ) == 0x4 )
1491 {
1492 tofid = ( *iter2 )->tofId();
1493 layerid = ( *iter2 )->layer();
1494 if ( layerid == 1 ) tofid = tofid - 88;
1495 log << MSG::INFO << " TofId = " << tofid << " barrelid = " << barrelid
1496 << " layerid = " << layerid << " ForwordADC = " << ( *iter2 )->adc1()
1497 << " ForwordTDC = " << ( *iter2 )->tdc1() << endmsg;
1498
1499 double ftdc = ( *iter2 )->tdc1();
1500 double fadc = ( *iter2 )->adc1();
1502 cout << "barrel 4 ::layer, barrel, tofid, ftdc: " << layerid << " , " << barrelid
1503 << " , " << tofid << " , " << ftdc << endl;
1504 int idptof = ( ( tofid - 1 ) == -1 ) ? 87 : tofid - 1;
1505 int idntof = ( ( tofid + 1 ) == 88 ) ? 0 : tofid + 1;
1506 if ( idmatch[barrelid][tofid] == 1 || idmatch[barrelid][idptof] == 1 ||
1507 idmatch[barrelid][idntof] == 1 )
1508 {
1509 for ( int i = 0; i < ntot; i++ )
1510 {
1511 if ( ttof[i] != 0 && ftdc > 0 )
1512 {
1513 if ( tofid_helix[i] == tofid || ( tofid_helix[i] == idptof ) ||
1514 ( tofid_helix[i] == idntof ) )
1515 {
1516 if ( barrelid == 1 && helztof[i] < 117 && helztof[i] > -117 )
1517 {
1518 if ( optCosmic && tofid < 44 )
1519 {
1520 forevtime = -ttof[i] + ( 115 - helztof[i] ) * 0.0566 + 12.;
1521 meantevup[ntofup] = forevtime;
1522 ntofup++;
1523 }
1524 else
1525 {
1526 forevtime = ttof[i] + ( 115 - helztof[i] ) * 0.0566 + 12.;
1527 meantevdown[ntofdown] = forevtime;
1528 ntofdown++;
1529 }
1530 if ( ( *iter2 )->adc1() < 0.0 || m_userawtime )
1531 { t0forward_trk = ftdc - forevtime; }
1532 else
1533 {
1534 t0forward_trk = tofCaliSvc->BTime1( ( *iter2 )->adc1(), ( *iter2 )->tdc1(),
1535 helztof[i], ( *iter2 )->tofId() ) -
1536 ttof[i];
1537 }
1538
1539 if ( t0forward_trk < -1 ) continue;
1540 if ( !
m_TofOpt && nmatch_barrel_1 != 0 &&
1541 fabs( ( t0forward_trk ) - ( t0forward_add ) / nmatch_barrel_1 ) > 11 )
1542 continue;
1543 if (
m_debug == 4 ) cout <<
"t0forward_trk: " << t0forward_trk << endl;
1545 {
1546 g_t0for[nmatch1] = t0forward_trk;
1547 g_meantdc = ftdc;
1548 if ( tofid < 44 ) g_ntofup1++;
1549 else g_ntofdown1++;
1550 }
1551 t0forward_add += t0forward_trk;
1552
1553 if ( nmatch > 499 ) break;
1554 meantev[nmatch] = forevtime;
1555 Tof_t0Arr[nmatch] = t0forward_trk;
1556 nmatch++;
1557 nmatch1++;
1558 nmatch_barrel_1++;
1559 }
1560 }
1561 }
1562 }
1563 }
1564 }
1565 else if ( ( ( *iter2 )->quality() & 0x5 ) == 0x1 )
1566 {
1567 tofid = ( *iter2 )->tofId();
1568 layerid = ( *iter2 )->layer();
1569 if ( layerid == 1 ) tofid = tofid - 88;
1570 log << MSG::INFO << " TofId = " << tofid << " barrelid = " << barrelid
1571 << " layerid = " << layerid << " BackwordADC = " << ( *iter2 )->adc2()
1572 << " BackwordTDC = " << ( *iter2 )->tdc2() << endmsg;
1573
1574 double btdc = ( *iter2 )->tdc2();
1576 cout << "barrel 5 ::layer, barrel, tofid, btdc: " << layerid << " , " << barrelid
1577 << " , " << tofid << " , " << btdc << endl;
1578 double badc = ( *iter2 )->adc2();
1579 int idptof = ( ( tofid - 1 ) == -1 ) ? 87 : tofid - 1;
1580 int idntof = ( ( tofid + 1 ) == 88 ) ? 0 : tofid + 1;
1581 if ( idmatch[barrelid][tofid] == 1 || idmatch[barrelid][idptof] == 1 ||
1582 idmatch[barrelid][idntof] == 1 )
1583 {
1584 for ( int i = 0; i < ntot; i++ )
1585 {
1586 if ( ttof[i] != 0 && btdc > 0 )
1587 {
1588 if ( ( tofid_helix[i] == tofid ) || ( tofid_helix[i] == idntof ) ||
1589 ( tofid_helix[i] == idptof ) )
1590 {
1591 if ( barrelid == 1 && helztof[i] < 117 && helztof[i] > -117 )
1592 {
1593 if ( optCosmic && tofid < 44 )
1594 {
1595 backevtime = -ttof[i] + ( 115 + helztof[i] ) * 0.0566 + 12.;
1596 meantevup[ntofup] = backevtime;
1597 ntofup++;
1598 }
1599 else
1600 {
1601 backevtime = ttof[i] + ( 115 + helztof[i] ) * 0.0566 + 12.;
1602 meantevdown[ntofdown] = backevtime;
1603 ntofdown++;
1604 }
1605
1606 if ( ( *iter2 )->adc2() < 0.0 || m_userawtime )
1607 { t0backward_trk = btdc - backevtime; }
1608 else
1609 {
1610 t0backward_trk =
1611 tofCaliSvc->BTime2( ( *iter2 )->adc2(), ( *iter2 )->tdc2(), helztof[i],
1612 ( *iter2 )->tofId() ) -
1613 ttof[i];
1614 }
1615
1616 if ( t0backward_trk < -1 ) continue;
1617 if ( !
m_TofOpt && nmatch_barrel_2 != 0 &&
1618 fabs( ( t0backward_trk ) - ( t0backward_add ) / nmatch_barrel_2 ) > 11 )
1619 continue;
1620 if (
m_debug == 4 ) cout <<
"t0backward_trk: " << t0backward_trk << endl;
1622 {
1623 g_t0back[nmatch2] = t0backward_trk;
1624 g_meantdc = btdc;
1625 if ( tofid < 44 ) g_ntofup1++;
1626 else g_ntofdown1++;
1627 }
1628 t0backward_add += t0backward_trk;
1629 if ( nmatch > 499 ) break;
1630 meantev[nmatch] = backevtime;
1631 Tof_t0Arr[nmatch] = t0backward_trk;
1632 nmatch++;
1633 nmatch2++;
1634 nmatch_barrel_2++;
1635 }
1636 }
1637 }
1638 }
1639 }
1640 }
1641 }
1642 }
1643 if ( nmatch_barrel_1 != 0 )
1644 {
1645 t0forward = t0forward_add / nmatch_barrel_1;
1646 if ( optCosmic == 0 )
1647 {
1649 {
1650 t_Est = EST_Trimmer( Opt_new( Tof_t0Arr, nmatch,
m_TofOpt_Cut ), tOffset_b,
1652 }
1654 if ( t_Est < 0 ) t_Est = 0;
1655 tEstFlag = 141;
1656 }
1657 else
1658 {
1659 t_Est = t0forward;
1660 tEstFlag = 241;
1661 }
1663 }
1664 if ( nmatch_barrel_2 != 0 )
1665 {
1666 t0backward = t0backward_add / nmatch_barrel_2;
1667 if ( optCosmic == 0 )
1668 {
1670 {
1671 t_Est = EST_Trimmer( Opt_new( Tof_t0Arr, nmatch,
m_TofOpt_Cut ), tOffset_b,
1673 }
1675 if ( t_Est < 0 ) t_Est = 0;
1676 tEstFlag = 141;
1677 }
1678 else
1679 {
1680 t_Est = t0backward;
1681 tEstFlag = 241;
1682 }
1684 }
1685
1686 digiId = 0;
1687 t0forward_add = 0;
1688 t0backward_add = 0;
1689 if ( nmatch_barrel == 0 )
1690 {
1691 for ( TofDataVector::iterator iter2 = tofDigiVec.begin(); iter2 != tofDigiVec.end();
1692 iter2++, digiId++ )
1693 {
1694 log << MSG::INFO << "TOF digit No: " << digiId << endmsg;
1695 barrelid = ( *iter2 )->barrel();
1696 if ( ( *iter2 )->barrel() != 0 ) continue;
1697 if ( ( *iter2 )->times() != 1 ) continue;
1698 tofid = ( *iter2 )->tofId();
1699
1700 if ( !( ( *iter2 )->is_mrpc() ) )
1701 {
1702 if ( tofid < 48 ) { barrelid = 0; }
1703 if ( tofid > 47 ) { barrelid = 2; }
1704 if ( barrelid == 2 ) { tofid = tofid - 48; }
1705 }
1706
1707 else if ( ( *iter2 )->is_mrpc() )
1708 {
1709 if ( (
TofID::endcap( Identifier( ( *iter2 )->identify() ) ) ) == 0 ) { barrelid = 0; }
1710 else if ( (
TofID::endcap( Identifier( ( *iter2 )->identify() ) ) ) == 1 )
1711 { barrelid = 2; }
1712 if ( barrelid == 2 ) { tofid = tofid - 36; }
1713 }
1714
1715 log << MSG::INFO << " is_mrpc = " << ( *iter2 )->is_mrpc() << " TofId = " << tofid
1716 << " barrelid = " << barrelid << endmsg << " ForwordADC = " << ( *iter2 )->adc()
1717 << " ForwordTDC = " << ( *iter2 )->tdc() << endmsg;
1718 double ftdc = ( *iter2 )->tdc();
1719 double fadc = ( *iter2 )->adc();
1721 cout << "endcap::single hit,barrelid,tofid,tdc: " << barrelid << " , " << tofid
1722 << " , " << ftdc << endl;
1723
1724
1725 if ( !( ( *iter2 )->is_mrpc() ) && useEtofScin )
1726 {
1727 int idptof = ( ( tofid - 1 ) == -1 ) ? 47 : tofid - 1;
1728 int idntof = ( ( tofid + 1 ) == 48 ) ? 0 : tofid + 1;
1729
1730 if ( idmatch[barrelid][tofid] == 1 || idmatch[barrelid][idptof] == 1 ||
1731 idmatch[barrelid][idntof] == 1 )
1732 {
1733 for ( int i = 0; i < ntot; i++ )
1734 {
1735 if ( ttof[i] != 0 && ftdc > 0 && ftdc < 2000. )
1736 {
1737 if ( ( tofid_helix[i] == tofid ) || ( tofid_helix[i] == idntof ) ||
1738 ( tofid_helix[i] == idptof ) )
1739 {
1740 if ( barrelid == 0 || barrelid == 2 )
1741 {
1742 if ( r_endtof[i] >= 41 && r_endtof[i] <= 90 )
1743 {
1744 if ( optCosmic && ( tofid < 24 || ( tofid > 48 && tofid < 71 ) ) )
1745 {
1746 forevtime = -ttof[i] + r_endtof[i] * 0.09 + 12.2;
1747 meantevup[ntofup] = forevtime;
1748 ntofup++;
1749 }
1750 else
1751 {
1752 forevtime = ttof[i] + r_endtof[i] * 0.09 + 12.2;
1753 meantevdown[ntofdown] = forevtime;
1754 ntofdown++;
1755 }
1756 if ( ( *iter2 )->adc() < 0.0 || m_userawtime )
1757 { t0forward_trk = ftdc - forevtime; }
1758 else
1759 {
1760 t0forward_trk = tofCaliSvc->ETime( ( *iter2 )->adc(), ( *iter2 )->tdc(),
1761 r_endtof[i], ( *iter2 )->tofId() ) -
1762 ttof[i];
1763 }
1764
1765 if ( t0forward_trk < -1. ) continue;
1766 if ( !
m_TofOpt && nmatch_end != 0 &&
1767 fabs( t0forward_trk - t0forward_add / nmatch_end ) > 9 )
1768 continue;
1769 t0forward_add += t0forward_trk;
1770 if ( nmatch > 499 ) break;
1771 Tof_t0Arr[nmatch] = t0forward_trk;
1772 meantev[nmatch] = forevtime / 2;
1773 nmatch++;
1774 nmatch_end++;
1775 }
1776 }
1777 }
1778 if (
m_debug == 4 ) { cout <<
"t0forward_trk:" << t0forward_trk << endl; }
1779 }
1780 }
1781 }
1782 }
1783
1784 if ( ( *iter2 )->is_mrpc() && useEtofMRPC )
1785 {
1786 if ( ( ( *iter2 )->quality() & 0x5 ) != 0x5 ) continue;
1787 double btdc = ( *iter2 )->tdc2();
1788 double badc = ( *iter2 )->adc2();
1789 int idptof = ( ( tofid - 1 ) == -1 ) ? 35 : tofid - 1;
1790 int idntof = ( ( tofid + 1 ) == 36 ) ? 0 : tofid + 1;
1791
1792 if ( idetfmatch[barrelid][tofid] == 1 || idetfmatch[barrelid][idptof] == 1 ||
1793 idetfmatch[barrelid][idntof] == 1 )
1794 {
1795 for ( int i = 0; i < ntot; i++ )
1796 {
1797 if ( tetf[i] != 0 && ftdc > 0 && ftdc < 2000. )
1798 {
1799 if ( etfid_helix[i] == tofid || etfid_helix[i] == idntof ||
1800 etfid_helix[i] == idptof )
1801 {
1802 if ( barrelid == 0 || barrelid == 2 )
1803 {
1804 if ( r_endetf[i] >= 41 && r_endetf[i] <= 90 )
1805 {
1806 if ( optCosmic && ( tofid < 18 || ( tofid > 35 && tofid < 54 ) ) )
1807 {
1808 forevtime = -tetf[i] + 17.7;
1809 meantevup[ntofup] = forevtime;
1810 ntofup++;
1811 }
1812 else
1813 {
1814 forevtime = tetf[i] + 17.7;
1815 meantevdown[ntofdown] = forevtime;
1816 ntofdown++;
1817 }
1818 if ( m_userawtime )
1819 {
1820 double fbtdc = ( ftdc + btdc ) / 2.0;
1821 if ( ftdc > 0 && btdc < 0 ) { fbtdc = ftdc; }
1822 else if ( ftdc < 0 && btdc > 0 ) { fbtdc = btdc; }
1823 else if ( ftdc < 0 && btdc < 0 ) continue;
1824 t0forward_trk = fbtdc - forevtime;
1825 }
1826 else
1827 {
1828 t0forward_trk =
1829 tofCaliSvc->EtfTime( ( *iter2 )->tdc1(), ( *iter2 )->tdc2(),
1830 ( *iter2 )->tofId(), ( *iter2 )->strip() ) -
1831 tetf[i];
1832 }
1833
1834 if ( t0forward_trk < -1 ) continue;
1835 if (
m_TofOpt && nmatch_end != 0 &&
1836 fabs( t0forward_trk - t0forward_add / nmatch_end ) > 9 )
1837 continue;
1838 if (
m_debug == 4 ) { cout <<
"t0forward_trk:" << t0forward_trk << endl; }
1839 t0forward_add += t0forward_trk;
1840 if ( nmatch > 499 ) break;
1841 Tof_t0Arr[nmatch] = t0forward_trk;
1842 meantev[nmatch] = forevtime;
1843 nmatch++;
1844 nmatch_end++;
1845 }
1846 }
1847 }
1848 }
1849 }
1850 }
1851 }
1852 }
1853 if ( nmatch_end ) { tof_flag = 5; }
1854 }
1855
1856 if ( nmatch_barrel == 0 && nmatch_end == 0 )
1857 {
1858 for ( TofDataVector::iterator iter2 = tofDigiVec.begin(); iter2 != tofDigiVec.end();
1859 iter2++, digiId++ )
1860 {
1861 barrelid = ( *iter2 )->barrel();
1862 if ( ( *iter2 )->barrel() != 0 ) continue;
1863 if ( ( *iter2 )->times() != 1 ) continue;
1864 tofid = ( *iter2 )->tofId();
1865
1866 if ( !( ( *iter2 )->is_mrpc() ) )
1867 {
1868 if ( tofid < 48 ) { barrelid = 0; }
1869 if ( tofid > 47 ) { barrelid = 2; }
1870 if ( barrelid == 2 ) { tofid = tofid - 48; }
1871 }
1872
1873 else if ( ( *iter2 )->is_mrpc() )
1874 {
1875 if ( (
TofID::endcap( Identifier( ( *iter2 )->identify() ) ) ) == 0 ) { barrelid = 0; }
1876 else if ( (
TofID::endcap( Identifier( ( *iter2 )->identify() ) ) ) == 1 )
1877 { barrelid = 2; }
1878 if ( barrelid == 2 ) { tofid = tofid - 36; }
1879 }
1880
1881 log << MSG::INFO << " is_mrpc = " << ( *iter2 )->is_mrpc() << " TofId = " << tofid
1882 << " barrelid = " << barrelid << endmsg << " ForwordADC = " << ( *iter2 )->adc()
1883 << " ForwordTDC = " << ( *iter2 )->tdc() << endmsg;
1884 double ftdc = ( *iter2 )->tdc();
1885 double fadc = ( *iter2 )->adc();
1887 cout << "endcap::single hit,barrelid,tofid,tdc: " << barrelid << " , " << tofid
1888 << " , " << ftdc << endl;
1889
1890
1891 if ( !( ( *iter2 )->is_mrpc() ) && useEtofScin )
1892 {
1893 int idptof = ( ( tofid - 1 ) == -1 ) ? 47 : tofid - 1;
1894 int idntof = ( ( tofid + 1 ) == 48 ) ? 0 : tofid + 1;
1895 for ( int i = 0; i < 2; i++ )
1896 {
1897 if ( zemc_rec[0] || zemc_rec[1] )
1898 {
1899 if ( tofid == tofid_emc[i] || tofid_emc[i] == idntof || tofid_emc[i] == idptof )
1900 {
1901 if ( ftdc > 2000. || module[i] == 1 ) continue;
1902 ttof[i] =
1904 sqrt( xemc_rec[i] * xemc_rec[i] + yemc_rec[i] * yemc_rec[i] + 133 * 133 ) /
1906 r_endtof[i] = sqrt( xemc_rec[i] * xemc_rec[i] + yemc_rec[i] * yemc_rec[i] );
1907 if ( optCosmic && ( tofid < 24 || ( tofid > 48 && tofid < 71 ) ) )
1908 {
1909 forevtime = -ttof[i] + r_endtof[i] * 0.09 + 12.2;
1910 meantevup[ntofup] = forevtime;
1911 ntofup++;
1912 }
1913 else
1914 {
1915 forevtime = ttof[i] + r_endtof[i] * 0.09 + 12.2;
1916 meantevdown[ntofdown] = forevtime;
1917 ntofdown++;
1918 }
1919 if ( ( *iter2 )->adc() < 0.0 || m_userawtime )
1920 { t0forward_trk = ftdc - forevtime; }
1921 else
1922 {
1923 t0forward_trk = tofCaliSvc->ETime( ( *iter2 )->adc(), ( *iter2 )->tdc(),
1924 r_endtof[i], ( *iter2 )->tofId() ) -
1925 ttof[i];
1927 cout << "emc flag t0forward_trk: " << t0forward_trk << endl;
1928 }
1929
1930 if ( t0forward_trk < -1. ) continue;
1931 if ( !
m_TofOpt && nmatch_end != 0 &&
1932 fabs( t0forward_trk - t0forward_add / nmatch_end ) > 9 )
1933 continue;
1934 t0forward_add += t0forward_trk;
1935 if ( nmatch > 499 ) break;
1936 meantev[nmatch] = forevtime;
1937 Tof_t0Arr[nmatch] = t0forward_trk;
1938 nmatch++;
1939 nmatch_end++;
1940 emcflag2 = 1;
1941 }
1942 }
1943 }
1944 }
1945
1946 if ( ( *iter2 )->is_mrpc() && useEtofMRPC )
1947 {
1948 double btdc = ( *iter2 )->tdc2();
1949 double badc = ( *iter2 )->adc2();
1950 int idptof = ( ( tofid - 1 ) == -1 ) ? 35 : tofid - 1;
1951 int idntof = ( ( tofid + 1 ) == 36 ) ? 0 : tofid + 1;
1952 for ( int i = 0; i < 2; i++ )
1953 {
1954 if ( zemc_rec[0] || zemc_rec[1] )
1955 {
1956 if ( tofid == etfid_emc[i] || etfid_emc[i] == idntof || etfid_emc[i] == idptof )
1957 {
1958
1959 if ( ftdc > 2000. || module[i] == 1 ) continue;
1960 tetf[i] =
1962 sqrt( xemc_rec[i] * xemc_rec[i] + yemc_rec[i] * yemc_rec[i] + 133 * 133 ) /
1964 r_endetf[i] = sqrt( xemc_rec[i] * xemc_rec[i] + yemc_rec[i] * yemc_rec[i] );
1965 if ( optCosmic && ( tofid < 18 || ( tofid > 35 && tofid < 54 ) ) )
1966 {
1967 forevtime = -tetf[i] + 17.7;
1968 meantevup[ntofup] = forevtime;
1969 ntofup++;
1970 }
1971 else
1972 {
1973 forevtime = tetf[i] + 17.7;
1974 meantevdown[ntofdown] = forevtime;
1975 ntofdown++;
1976 }
1977
1978 if ( m_userawtime )
1979 {
1980 double fbtdc = ( ftdc + btdc ) / 2.0;
1981 if ( ftdc > 0 && btdc < 0 ) { fbtdc = ftdc; }
1982 else if ( ftdc < 0 && btdc > 0 ) { fbtdc = btdc; }
1983 else if ( ftdc < 0 && btdc < 0 ) continue;
1984 t0forward_trk = fbtdc - forevtime;
1985 }
1986 else
1987 {
1988 t0forward_trk =
1989 tofCaliSvc->EtfTime( ( *iter2 )->tdc1(), ( *iter2 )->tdc2(),
1990 ( *iter2 )->tofId(), ( *iter2 )->strip() ) -
1991 tetf[i];
1992 }
1993
1994 if ( t0forward_trk < -1 ) continue;
1995 if ( !
m_TofOpt && nmatch_end != 0 &&
1996 fabs( t0forward_trk - t0forward_add / nmatch_end ) > 9 )
1997 continue;
1998 if (
m_debug == 4 ) { cout <<
"t0forward_trk:" << t0forward_trk << endl; }
1999 t0forward_add += t0forward_trk;
2000 if ( nmatch > 499 ) break;
2001 Tof_t0Arr[nmatch] = t0forward_trk;
2002 nmatch++;
2003 nmatch_end++;
2004 emcflag2 = 1;
2005 }
2006 }
2007 }
2008 }
2009 }
2010 if ( nmatch_end ) { tof_flag = 5; }
2011 }
2012
2013 if ( nmatch_barrel == 0 && nmatch_end == 0 )
2014 {
2015 for ( TofDataVector::iterator iter2 = tofDigiVec.begin(); iter2 != tofDigiVec.end();
2016 iter2++, digiId++ )
2017 {
2018 log << MSG::INFO << "TOF digit No: " << digiId << endmsg;
2019 barrelid = ( *iter2 )->barrel();
2020 if ( ( *iter2 )->barrel() != 0 ) continue;
2021 if ( ( *iter2 )->times() > 1 && ( *iter2 )->times() < 5 )
2022 {
2023 tofid = ( *iter2 )->tofId();
2024
2025 if ( !( ( *iter2 )->is_mrpc() ) )
2026 {
2027 if ( tofid < 48 ) { barrelid = 0; }
2028 if ( tofid > 47 ) { barrelid = 2; }
2029 if ( barrelid == 2 ) { tofid = tofid - 48; }
2030 }
2031
2032 else if ( ( *iter2 )->is_mrpc() )
2033 {
2034 if ( (
TofID::endcap( Identifier( ( *iter2 )->identify() ) ) ) == 0 )
2035 { barrelid = 0; }
2036 else if ( (
TofID::endcap( Identifier( ( *iter2 )->identify() ) ) ) == 1 )
2037 { barrelid = 2; }
2038 if ( barrelid == 2 ) { tofid = tofid - 36; }
2039 }
2040 log << MSG::INFO << " TofId = " << tofid << " barrelid = " << barrelid << endmsg
2041 << " ForwordADC = " << ( *iter2 )->adc() << " ForwordTDC = " << ( *iter2 )->tdc()
2042 << endmsg;
2043 double ftdc = ( *iter2 )->tdc();
2044 double fadc = ( *iter2 )->adc();
2046 {
2047 cout << "endcap::multi hit,barrelid,tofid,tdc: " << barrelid << " , " << tofid
2048 << " , " << ftdc << endl;
2049 }
2050
2051
2052 if ( !( ( *iter2 )->is_mrpc() ) && useEtofScin )
2053 {
2054 int idptof = ( ( tofid - 1 ) == -1 ) ? 47 : tofid - 1;
2055 int idntof = ( ( tofid + 1 ) == 48 ) ? 0 : tofid + 1;
2056
2057 if ( idmatch[barrelid][tofid] == 1 || idmatch[barrelid][idptof] == 1 ||
2058 idmatch[barrelid][idntof] == 1 )
2059 {
2060 for ( int i = 0; i < ntot; i++ )
2061 {
2062 if ( ttof[i] != 0 && ftdc > 0 )
2063 {
2064 if ( ( tofid_helix[i] == tofid ) || ( tofid_helix[i] == idntof ) ||
2065 ( tofid_helix[i] == idptof ) )
2066 {
2067 if ( barrelid == 0 || barrelid == 2 )
2068 {
2069 if ( r_endtof[i] >= 41 && r_endtof[i] <= 90 )
2070 {
2071 if ( optCosmic && ( tofid < 24 || ( tofid > 48 && tofid < 71 ) ) )
2072 {
2073 forevtime = -ttof[i] + r_endtof[i] * 0.09 + 12.2;
2074 meantevup[ntofup] = forevtime;
2075 ntofup++;
2076 }
2077 else
2078 {
2079 forevtime = ttof[i] + r_endtof[i] * 0.09 + 12.2;
2080 meantevdown[ntofdown] = forevtime;
2081 ntofdown++;
2082 }
2083 if ( ( *iter2 )->adc() < 0.0 || m_userawtime )
2084 { t0forward_trk = ftdc - forevtime; }
2085 else
2086 {
2087 t0forward_trk =
2088 tofCaliSvc->ETime( ( *iter2 )->adc(), ( *iter2 )->tdc(),
2089 r_endtof[i], ( *iter2 )->tofId() ) -
2090 ttof[i];
2091 }
2092
2093 if ( t0forward_trk < -1. ) continue;
2094 if ( !
m_TofOpt && nmatch_end != 0 &&
2095 fabs( t0forward_trk - t0forward_add / nmatch_end ) > 9 )
2096 continue;
2097 t0forward_add += t0forward_trk;
2098 if ( nmatch > 499 ) break;
2099 meantev[nmatch] = forevtime;
2100 Tof_t0Arr[nmatch] = t0forward_trk;
2101 nmatch++;
2102 nmatch_end++;
2103 }
2104 }
2105 if (
m_debug == 4 ) { cout <<
"t0forward_trk:" << t0forward_trk << endl; }
2106 }
2107 }
2108 }
2109 }
2110 }
2111
2112 if ( ( *iter2 )->is_mrpc() && useEtofMRPC )
2113 {
2114 double btdc = ( *iter2 )->tdc2();
2115 double badc = ( *iter2 )->adc2();
2116 int idptof = ( ( tofid - 1 ) == -1 ) ? 35 : tofid - 1;
2117 int idntof = ( ( tofid + 1 ) == 36 ) ? 0 : tofid + 1;
2118
2119 if ( idetfmatch[barrelid][tofid] == 1 || idetfmatch[barrelid][idptof] == 1 ||
2120 idetfmatch[barrelid][idntof] == 1 )
2121 {
2122 for ( int i = 0; i < ntot; i++ )
2123 {
2124 if ( tetf[i] != 0 && ftdc > 0 && ftdc < 2000. )
2125 {
2126 if ( etfid_helix[i] == tofid || etfid_helix[i] == idntof ||
2127 etfid_helix[i] == idptof )
2128 {
2129 if ( barrelid == 0 || barrelid == 2 )
2130 {
2131 if ( r_endetf[i] >= 41 && r_endetf[i] <= 90 )
2132 {
2133 if ( optCosmic && ( tofid < 18 || ( tofid > 35 && tofid < 54 ) ) )
2134 {
2135 forevtime = -tetf[i] + 17.7;
2136 meantevup[ntofup] = forevtime;
2137 ntofup++;
2138 }
2139 else
2140 {
2141 forevtime = tetf[i] + 17.7;
2142 meantevdown[ntofdown] = forevtime;
2143 ntofdown++;
2144 }
2145 if ( m_userawtime )
2146 {
2147 double fbtdc = ( ftdc + btdc ) / 2.0;
2148 if ( ftdc > 0 && btdc < 0 ) { fbtdc = ftdc; }
2149 else if ( ftdc < 0 && btdc > 0 ) { fbtdc = btdc; }
2150 else if ( ftdc < 0 && btdc < 0 ) continue;
2151 t0forward_trk = fbtdc - forevtime;
2152 }
2153 else
2154 {
2155 t0forward_trk =
2156 tofCaliSvc->EtfTime( ( *iter2 )->tdc1(), ( *iter2 )->tdc2(),
2157 ( *iter2 )->tofId(), ( *iter2 )->strip() ) -
2158 tetf[i];
2159 }
2160
2161 if ( t0forward_trk < -1 ) continue;
2162 if ( !
m_TofOpt && nmatch_end != 0 &&
2163 fabs( t0forward_trk - t0forward_add / nmatch_end ) > 9 )
2164 continue;
2166 { cout << "t0forward_trk:" << t0forward_trk << endl; }
2167 t0forward_add += t0forward_trk;
2168 if ( nmatch > 499 ) break;
2169 Tof_t0Arr[nmatch] = t0forward_trk;
2170 meantev[nmatch] = forevtime;
2171 nmatch++;
2172 nmatch_end++;
2173 }
2174 }
2175 }
2176 }
2177 }
2178 }
2179 }
2180 }
2181 }
2182 if ( nmatch_end ) { tof_flag = 7; }
2183 }
2184
2186 {
2187 g_nmatchbarrel = nmatch_barrel;
2188 g_nmatchbarrel_1 = nmatch_barrel_1;
2189 g_nmatchbarrel_2 = nmatch_barrel_2;
2190 g_nmatchend = nmatch_end;
2191 }
2192
2193 if ( nmatch_end != 0 )
2194 {
2195 t0forward = t0forward_add / nmatch_end;
2196 if ( optCosmic == 0 )
2197 {
2199 {
2200 t_Est = EST_Trimmer( Opt_new( Tof_t0Arr, nmatch,
m_TofOpt_Cut ), tOffset_e,
2202 }
2203 else
2204 {
2205 t_Est =
2207 }
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225 if ( t_Est < 0 ) t_Est = 0;
2226 if ( tof_flag == 5 ) tEstFlag = 151;
2227 else if ( tof_flag == 7 ) tEstFlag = 171;
2228 if ( emcflag2 == 1 ) tEstFlag = 161;
2229
2230
2231
2232
2233
2234
2235
2236
2237 }
2238 if ( optCosmic )
2239 {
2240 t_Est = t0forward;
2241 if ( tof_flag == 5 ) tEstFlag = 251;
2242 else if ( tof_flag == 7 ) tEstFlag = 271;
2243 if ( emcflag2 == 1 ) tEstFlag = 261;
2244 }
2246 }
2247
2248 double t0_comp = -999;
2249 double T0 = -999;
2250
2251 if ( nmatch_barrel == 0 && nmatch_end == 0 &&
m_flag == 1 )
2252 {
2253 double mhit[43][300] = { 0. };
2254 SmartDataPtr<MdcDigiCol> mdcDigiCol( eventSvc(), "/Event/Digi/MdcDigiCol" );
2255 if ( !mdcDigiCol )
2256 {
2257 log << MSG::INFO << "Could not find MDC digi" << endmsg;
2258 return StatusCode::FAILURE;
2259 }
2260
2261 IMdcGeomSvc* mdcGeomSvc;
2262 StatusCode sc = service( "MdcGeomSvc", mdcGeomSvc );
2263 if ( sc != StatusCode::SUCCESS ) { return StatusCode::FAILURE; }
2264
2265 MdcDigiCol::iterator iter1 = mdcDigiCol->begin();
2266 digiId = 0;
2267 Identifier mdcId;
2268 int layerId;
2269 int wireId;
2270
2271 for ( ; iter1 != mdcDigiCol->end(); iter1++, digiId++ )
2272 {
2273 mdcId = ( *iter1 )->identify();
2276
2278 mhit[layerId][wireId] -= 1.28 * ( mdcGeomSvc->
Layer( layerId )->Radius() ) / 299.8;
2279
2280 mdcGeomSvc->
Wire( layerId, wireId );
2281
2282 double tof;
2283
2284 }
2285
2286 int Iused[43][300] = { 0 }, tmp = 0;
2287 bool Lpat, Lpat11, Lpat12, Lpat2, Lpat31, Lpat32;
2288 double t0_all = 0, t0_mean = 0;
2289 double r[4] = { 0. };
2290 double chi2 = 999.0;
2291 double phi[4] = { 0. }, corr[4] = { 0. }, driftt[4] = { 0. };
2292 double ambig = 1;
2293 double mchisq = 50000;
2294
2295
2296 for ( int i = 5; i < 10; i++ )
2297 {
2298
2299 double T1 = 0.5 * 0.1 * ( mdcGeomSvc->
Layer( 4 * i + 0 )->PCSiz() ) / 0.004;
2300 double T2 = 0.5 * 0.1 * ( mdcGeomSvc->
Layer( 4 * i + 1 )->PCSiz() ) / 0.004;
2301 double T3 = 0.5 * 0.1 * ( mdcGeomSvc->
Layer( 4 * i + 2 )->PCSiz() ) / 0.004;
2302 double T4 = 0.5 * 0.1 * ( mdcGeomSvc->
Layer( 4 * i + 3 )->PCSiz() ) / 0.004;
2303 r[0] = ( mdcGeomSvc->
Layer( 4 * i + 0 )->Radius() ) * 0.1;
2304 r[1] = ( mdcGeomSvc->
Layer( 4 * i + 1 )->Radius() ) * 0.1;
2305 r[2] = ( mdcGeomSvc->
Layer( 4 * i + 2 )->Radius() ) * 0.1;
2306 r[3] = ( mdcGeomSvc->
Layer( 4 * i + 3 )->Radius() ) * 0.1;
2307 double r0 = r[0] - r[1] - ( r[2] - r[1] ) / 2;
2308 double r1 = -( r[2] - r[1] ) / 2;
2309 double r2 = ( r[2] - r[1] ) / 2;
2310 double r3 = r[3] - r[2] + ( r[2] - r[1] ) / 2;
2311
2312 for (
int j = 0; j < mdcGeomSvc->
Layer( i * 4 + 3 )->NCell(); j++ )
2313 {
2314
2315 int Icp = 0;
2316 Icp = j - 1;
2317 if ( Icp < 0 ) Icp = mdcGeomSvc->
Layer( i * 4 + 3 )->
NCell();
2318
2319 Lpat = ( mhit[4 * i][j] != 0 ) && ( mhit[4 * i][Icp] == 0 ) &&
2320 ( mhit[4 * i][j + 1] == 0 ) && ( Iused[4 * i][j] == 0 );
2321 if ( Lpat )
2322 {
2323 Lpat11 = ( mhit[4 * i + 1][Icp] == 0 ) && ( Iused[4 * i + 1][j] == 0 ) &&
2324 ( mhit[4 * i + 1][j] != 0 ) && ( mhit[4 * i + 1][j + 1] == 0 );
2325 Lpat12 = ( mhit[4 * i + 1][j] == 0 ) && ( Iused[4 * i + 1][j + 1] == 0 ) &&
2326 ( mhit[4 * i + 1][j + 1] != 0 ) && ( mhit[4 * i + 1][j + 2] == 0 );
2327 Lpat2 = ( mhit[4 * i + 2][Icp] == 0 ) && ( Iused[4 * i + 2][j] == 0 ) &&
2328 ( mhit[4 * i + 2][j] != 0 ) && ( mhit[4 * i + 2][j + 1] == 0 );
2329 Lpat31 = ( mhit[4 * i + 3][Icp] == 0 ) && ( Iused[4 * i + 3][j] == 0 ) &&
2330 ( mhit[4 * i + 3][j] != 0 ) && ( mhit[4 * i + 3][j + 1] == 0 );
2331 Lpat32 = ( mhit[4 * i + 3][j] == 0 ) && ( Iused[4 * i + 3][j + 1] == 0 ) &&
2332 ( mhit[4 * i + 3][j + 1] != 0 ) && ( mhit[4 * i + 3][j + 2] == 0 );
2333
2334 if ( Lpat11 && Lpat2 && Lpat31 )
2335 {
2336
2337 Iused[4 * i + 0][j] = 1;
2338 Iused[4 * i + 1][j] = 1;
2339 Iused[4 * i + 2][j] = 1;
2340 Iused[4 * i + 3][j] = 1;
2341 double t_i = mhit[4 * i + 0][j] + mhit[4 * i + 2][j];
2342 double t_j = mhit[4 * i + 1][j] + mhit[4 * i + 3][j];
2343 double l_j = T2 + T4;
2344 double r_i = r0 + r2;
2345 double r_j = r1 + r3;
2346 double r_2k = r0 * r0 + r1 * r1 + r2 * r2 + r3 * r3;
2347 double rt_i = r0 * mhit[4 * i + 0][j] + r2 * mhit[4 * i + 2][j];
2348 double rt_j = r1 * mhit[4 * i + 1][j] + r3 * mhit[4 * i + 3][j];
2349 double rl_j = r1 * T2 + r3 * T4;
2350
2351 double deno = 4 * r_2k - 2 * ( r_i * r_i + r_j * r_j );
2352
2353 if ( deno != 0 )
2354 {
2355 double Pa = ( 4 * ( rt_i - rt_j + rl_j ) - ( t_i + t_j - l_j ) * ( r_i - r_j ) -
2356 ( t_i - t_j + l_j ) * ( r_i + r_j ) ) /
2357 deno;
2358 double Pb = 0.25 * ( t_i - t_j + l_j - ( r_i + r_j ) * Pa );
2359 double Ang = fabs( 90. - fabs( atan( Pa ) * 180. / 3.141593 ) );
2360
2361 t0_all += ( -0.25 * ( ( r_i - r_j ) * Pa - t_i - t_j + l_j ) );
2362
2363 double chi2_tmp;
2364 for ( int t0c = 0; t0c < 17; t0c += 8 )
2365 {
2366 chi2_tmp = ( mhit[4 * i + 0][j] - t0c - r0 * Pa - Pb ) *
2367 ( mhit[4 * i + 0][j] - t0c - r0 * Pa - Pb ) +
2368 ( T2 - mhit[4 * i + 1][j] + t0c - r1 * Pa - Pb ) *
2369 ( T2 - mhit[4 * i + 1][j] + t0c - r1 * Pa - Pb ) +
2370 ( mhit[4 * i + 2][j] - t0c - r2 * Pa - Pb ) *
2371 ( mhit[4 * i + 2][j] - t0c - r2 * Pa - Pb ) +
2372 ( T4 - mhit[4 * i + 3][j] + t0c - r3 * Pa - Pb ) *
2373 ( T4 - mhit[4 * i + 3][j] + t0c - r3 * Pa - Pb );
2374 if ( chi2_tmp < chi2 )
2375 {
2376 chi2 = chi2_tmp;
2377 t0_comp = t0c;
2378 }
2379 }
2380 tmp += 1;
2381 }
2382
2383
2384 for ( int tmpT0 = 0; tmpT0 < 17; tmpT0 += 8 )
2385 {
2386 driftt[0] = mhit[4 * i + 0][j] - tmpT0;
2387 driftt[1] = mhit[4 * i + 1][j] - tmpT0;
2388 driftt[2] = mhit[4 * i + 2][j] - tmpT0;
2389 driftt[3] = mhit[4 * i + 3][j] - tmpT0;
2390
2391 phi[0] = j * 2 * 3.14159265 / ( mdcGeomSvc->
Layer( i * 4 )->NCell() ) +
2392 2 * 3.14159265 / ( mdcGeomSvc->
Layer( i * 4 + 1 )->NCell() ) / 2;
2393 phi[1] = j * 2 * 3.14159265 / ( mdcGeomSvc->
Layer( i * 4 + 1 )->NCell() );
2394 phi[2] = j * 2 * 3.14159265 / ( mdcGeomSvc->
Layer( i * 4 + 2 )->NCell() ) +
2395 2 * 3.14159265 / ( mdcGeomSvc->
Layer( i * 4 + 1 )->NCell() ) / 2;
2396 phi[3] = j * 2 * 3.14159265 / ( mdcGeomSvc->
Layer( i * 4 + 3 )->NCell() );
2397 phi[0] -= ambig * driftt[0] * 0.004 / r[0];
2398 phi[1] += ambig * driftt[1] * 0.004 / r[1];
2399 phi[2] -= ambig * driftt[2] * 0.004 / r[2];
2400 phi[3] += ambig * driftt[3] * 0.004 / r[3];
2401 double s1, sx, sy, sxx, sxy;
2402 double delinv, denom;
2404 double sigma;
2410 sigma = 0.12;
2411 s1 = sx = sy = sxx = sxy = 0.0;
2412 double chisq = 0.0;
2413 for ( int ihit = 0; ihit < 4; ihit++ )
2414 {
2415 weight = 1. / ( sigma * sigma );
2418 sy += phi[ihit] *
weight;
2419 sxx +=
x[ihit] * (
x[ihit] *
weight );
2420 sxy += phi[ihit] * (
x[ihit] *
weight );
2421 }
2422 double resid[4] = { 0. };
2423
2424 denom = s1 * sxx - sx * sx;
2425 delinv = ( denom == 0.0 ) ? 1.e20 : 1. / denom;
2426 double intercept = ( sy * sxx - sx * sxy ) * delinv;
2427 double slope = ( s1 * sxy - sx * sy ) * delinv;
2428
2429
2430 for ( int ihit = 0; ihit < 4; ihit++ )
2431 {
2432 resid[ihit] = ( phi[ihit] - intercept - slope *
x[ihit] );
2433 chisq += resid[ihit] * resid[ihit] / ( sigma * sigma );
2434 }
2435 if ( chisq < mchisq )
2436 {
2437 mchisq = chisq;
2438 T0 = tmpT0;
2439 }
2440 }
2441 }
2442 if ( Lpat12 && Lpat2 && Lpat32 )
2443 {
2444 Iused[4 * i + 0][j] = 1;
2445 Iused[4 * i + 1][j + 1] = 1;
2446 Iused[4 * i + 2][j] = 1;
2447 Iused[4 * i + 3][j + 1] = 1;
2448
2449 double t_i = mhit[4 * i + 0][j] + mhit[4 * i + 2][j];
2450 double t_j = mhit[4 * i + 1][j + 1] + mhit[4 * i + 3][j + 1];
2451 double l_j = T2 + T4;
2452 double r_i = r0 + r2;
2453 double r_j = r1 + r3;
2454 double r_2k = r0 * r0 + r1 * r1 + r2 * r2 + r3 * r3;
2455 double rt_i = r0 * mhit[4 * i + 0][j] + r2 * mhit[4 * i + 2][j];
2456 double rt_j = r1 * mhit[4 * i + 1][j + 1] + r3 * mhit[4 * i + 3][j + 1];
2457 double rl_j = r1 * T2 + r3 * T4;
2458 double deno = 4 * r_2k - 2 * ( r_i * r_i + r_j * r_j );
2459
2460 if ( deno != 0 )
2461 {
2462 double Pa = ( 4 * ( rt_i - rt_j + rl_j ) - ( t_i + t_j - l_j ) * ( r_i - r_j ) -
2463 ( t_i - t_j + l_j ) * ( r_i + r_j ) ) /
2464 deno;
2465 double Pb = 0.25 * ( t_i - t_j + l_j - ( r_i + r_j ) * Pa );
2466 double Ang = fabs( 90. - fabs( atan( Pa ) * 180. / 3.141593 ) );
2467 t0_all += ( -0.25 * ( ( r_i - r_j ) * Pa - t_i - t_j + l_j ) );
2468 tmp += 1;
2469 double chi2_tmp;
2470
2471 for ( int t0c = 0; t0c < 17; t0c += 8 )
2472 {
2473 chi2_tmp = ( mhit[4 * i + 0][j] - t0c - r0 * Pa - Pb ) *
2474 ( mhit[4 * i + 0][j] - t0c - r0 * Pa - Pb ) +
2475 ( T2 - mhit[4 * i + 1][j + 1] + t0c - r1 * Pa - Pb ) *
2476 ( T2 - mhit[4 * i + 1][j + 1] + t0c - r1 * Pa - Pb ) +
2477 ( mhit[4 * i + 2][j] - t0c - r2 * Pa - Pb ) *
2478 ( mhit[4 * i + 2][j] - t0c - r2 * Pa - Pb ) +
2479 ( T4 - mhit[4 * i + 3][j + 1] + t0c - r3 * Pa - Pb ) *
2480 ( T4 - mhit[4 * i + 3][j + 1] + t0c - r3 * Pa - Pb );
2481
2482 if ( chi2_tmp < chi2 )
2483 {
2484 chi2 = chi2_tmp;
2485 t0_comp = t0c;
2486 }
2487 }
2488 }
2489
2490
2491
2492 for ( int tmpT0 = 0; tmpT0 < 17; tmpT0 += 8 )
2493 {
2494 driftt[0] = mhit[4 * i + 0][j] - tmpT0;
2495 driftt[1] = mhit[4 * i + 1][j + 1] - tmpT0;
2496 driftt[2] = mhit[4 * i + 2][j] - tmpT0;
2497 driftt[3] = mhit[4 * i + 3][j + 1] - tmpT0;
2498
2499 phi[0] = j * 2 * 3.14159265 / ( mdcGeomSvc->
Layer( i * 4 )->NCell() ) +
2500 2 * 3.14159265 / ( mdcGeomSvc->
Layer( i * 4 + 1 )->NCell() ) / 2;
2501 phi[1] = j * 2 * 3.14159265 / ( mdcGeomSvc->
Layer( i * 4 + 1 )->NCell() );
2502 phi[2] = j * 2 * 3.14159265 / ( mdcGeomSvc->
Layer( i * 4 + 2 )->NCell() ) +
2503 2 * 3.14159265 / ( mdcGeomSvc->
Layer( i * 4 + 1 )->NCell() ) / 2;
2504 phi[3] = j * 2 * 3.14159265 / ( mdcGeomSvc->
Layer( i * 4 + 3 )->NCell() );
2505 phi[0] -= ambig * driftt[0] * 0.004 / r[0];
2506 phi[1] += ambig * driftt[1] * 0.004 / r[1];
2507 phi[2] -= ambig * driftt[2] * 0.004 / r[2];
2508 phi[3] += ambig * driftt[3] * 0.004 / r[3];
2509 double s1, sx, sy, sxx, sxy;
2510 double delinv, denom;
2512 double sigma;
2518 sigma = 0.12;
2519 s1 = sx = sy = sxx = sxy = 0.0;
2520 double chisq = 0.0;
2521 for ( int ihit = 0; ihit < 4; ihit++ )
2522 {
2523 weight = 1. / ( sigma * sigma );
2526 sy += phi[ihit] *
weight;
2527 sxx +=
x[ihit] * (
x[ihit] *
weight );
2528 sxy += phi[ihit] * (
x[ihit] *
weight );
2529 }
2530 double resid[4] = { 0. };
2531
2532 denom = s1 * sxx - sx * sx;
2533 delinv = ( denom == 0.0 ) ? 1.e20 : 1. / denom;
2534 double intercept = ( sy * sxx - sx * sxy ) * delinv;
2535 double slope = ( s1 * sxy - sx * sy ) * delinv;
2536
2537
2538 for ( int ihit = 0; ihit < 4; ihit++ )
2539 {
2540 resid[ihit] = ( phi[ihit] - intercept - slope *
x[ihit] );
2541 chisq += resid[ihit] * resid[ihit] / ( sigma * sigma );
2542 }
2543
2544 if ( chisq < mchisq )
2545 {
2546 mchisq = chisq;
2547 T0 = tmpT0;
2548 }
2549 }
2550 }
2551 }
2552 }
2553 }
2554
2555 if ( tmp != 0 ) { t0_mean = t0_all / tmp; }
2557
2558 t_Est = T0 + tOffset_b;
2559 tEstFlag = 2;
2560 }
2562 {
2563 g_t0 = t0_comp;
2564 g_T0 = T0;
2565 }
2566 if ( nmatch_barrel == 0 && nmatch_end == 0 && nmatch_barrel_1 == 0 && nmatch_barrel_2 == 0 &&
2567 m_mdcCalibFunSvc &&
m_flag == 2 )
2568 {
2569
2570 log << MSG::INFO << " mdc " << endmsg;
2571
2572#define MXWIRE 6860
2573#define MXTKHIT 6860
2574#define MXTRK 15
2575
2576
2577 int nhits_ax = 0;
2578 int nhits_ax2 = 0;
2579 int nhits_st = 0;
2580 int nhits_st2 = 0;
2581
2585 double toft;
2586 double prop;
2587 double t0_minus_TDC[
MXWIRE];
2588
2589 double T0_cal = -230;
2590 double Mdc_t0Arr[500];
2591
2592 int expmc = 1;
2593 double scale = 1.;
2594 int expno, runno;
2595 ndriftt = 0;
2596
2597
2598
2599
2601
2602
2603 if ( !newtrkCol || newtrkCol->size() == 0 )
2604 {
2605 log << MSG::INFO << "Could not find RecMdcTrackCol" << endmsg;
2606 return StatusCode::SUCCESS;
2607 }
2608 log << MSG::INFO << "Begin to check RecMdcTrackCol" << endmsg;
2609
2610 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
2611
2612 for ( int tempntrack = 0; iter_trk != newtrkCol->end(); iter_trk++, tempntrack++ )
2613 {
2614 log << MSG::DEBUG << "retrieved MDC track:"
2615 << " Track Id: " << ( *iter_trk )->trackId() << " Dr: " << ( *iter_trk )->helix( 0 )
2616 << " Phi0: " << ( *iter_trk )->helix( 1 ) << " kappa: " << ( *iter_trk )->helix( 2 )
2617 << " Dz: " << ( *iter_trk )->helix( 3 ) << " Tanl: " << ( *iter_trk )->helix( 4 )
2618 << " Phi terminal: " << ( *iter_trk )->getFiTerm() << endmsg
2619 << "Number of hits: " << ( *iter_trk )->getNhits() << " Number of stereo hits "
2620 << ( *iter_trk )->nster() << endmsg;
2621
2622
2624 HepVector a( 5, 0 );
2625
2626 a[0] = ( *iter_trk )->helix( 0 );
2627 a[1] = ( *iter_trk )->helix( 1 );
2628 a[2] = ( *iter_trk )->helix( 2 );
2629 a[3] = ( *iter_trk )->helix( 3 );
2630 a[4] = ( *iter_trk )->helix( 4 );
2631
2632
2634 abs( a[4] ) > 500. )
2635 continue;
2636
2637 double phi0 = a[1];
2638 double kappa =
abs( a[2] );
2639 double dirmag = sqrt( 1. + a[4] * a[4] );
2640
2641 double mom =
abs( dirmag / kappa );
2642 double beta = mom / sqrt( mom * mom +
PIMAS2 );
2643 if ( particleId[tempntrack] == 1 ) { beta = mom / sqrt( mom * mom +
ELMAS2 ); }
2644 if ( particleId[tempntrack] == 5 ) { beta = mom / sqrt( mom * mom +
PROTONMAS2 ); }
2645
2646
2647 Helix helix0( pivot0, a );
2648 double rho = helix0.radius();
2649 double unit_s =
abs( rho * dirmag );
2650
2651 helix0.ignoreErrorMatrix();
2653 double xc = hcen( 0 );
2654 double yc = hcen( 1 );
2655
2656 if ( xc == 0.0 && yc == 0.0 ) continue;
2657
2658 double direction = 1.;
2659 if ( optCosmic != 0 )
2660 {
2661 double phi = atan2( helix0.momentum( 0. ).y(), helix0.momentum( 0. ).x() );
2662 if ( phi > 0. && phi <=
M_PI ) direction = -1.;
2663 }
2664
2665 IMdcGeomSvc* mdcGeomSvc;
2666 StatusCode sc = service( "MdcGeomSvc", mdcGeomSvc );
2667 double zeast;
2668 double zwest;
2669 double m_vp[43] = { 0. }, m_zst[43] = { 0. };
2670 for ( int lay = 0; lay < 43; lay++ )
2671 {
2672 zwest = mdcGeomSvc->
Wire( lay, 0 )->
Forward().z();
2674
2675
2676 if ( lay < 8 ) m_vp[lay] = 220.0;
2677 else m_vp[lay] = 240.0;
2678
2679 if ( 0 == ( lay % 2 ) )
2680 {
2681 m_zst[lay] = zwest;
2682 }
2683 else
2684 {
2685 m_zst[lay] = zeast;
2686 }
2687 }
2688
2689
2690 log << MSG::DEBUG << "hitList of this track:" << endmsg;
2691 HitRefVec gothits = ( *iter_trk )->getVecHits();
2692 HitRefVec::iterator it_gothit = gothits.begin();
2693 for ( ; it_gothit != gothits.end(); it_gothit++ )
2694 {
2695
2696 log << MSG::DEBUG << "hits Id: " << ( *it_gothit )->getId()
2697 <<
" hits MDC layerId wireId " <<
MdcID::layer( ( *it_gothit )->getMdcId() )
2698 <<
" " <<
MdcID::wire( ( *it_gothit )->getMdcId() ) << endmsg <<
" hits TDC "
2699 << ( *it_gothit )->getTdc() << endmsg;
2700
2701 int layer =
MdcID::layer( ( *it_gothit )->getMdcId() );
2702 int wid =
MdcID::wire( ( *it_gothit )->getMdcId() );
2703 double tdc = ( *it_gothit )->getTdc();
2704
2705
2706 double trkchi2 = ( *iter_trk )->chi2();
2707 if ( trkchi2 > 100 ) continue;
2708 double hitChi2 = ( *it_gothit )->getChisqAdd();
2709 HepVector helix_par = ( *iter_trk )->helix();
2710 HepSymMatrix helixErr = ( *iter_trk )->err();
2711
2712 if ( ( layer >= 8 && layer <= 19 ) || ( layer >= 36 && layer <= 42 ) )
2713 {
2714
2715
2716
2717
2718 const MdcGeoWire* GeoRef = mdcGeomSvc->
Wire( layer, wid );
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729 if ( Estparam.
MDC_Inner() == 0 && layer <= 3 )
continue;
2730
2731 double xw = GeoRef->
Forward().x() / 10;
2732 double yw = GeoRef->
Forward().y() / 10;
2733
2735 helix0.pivot( pivot1 );
2736 double zw = helix0.a()[3];
2737
2738
2739 double dphi = ( -xc * ( xw - xc ) - yc * ( yw - yc ) ) /
2740 sqrt( ( xc * xc + yc * yc ) *
2741 ( ( xw - xc ) * ( xw - xc ) + ( yw - yc ) * ( yw - yc ) ) );
2742 dphi = acos( dphi );
2743 double pathtof =
abs( unit_s * dphi );
2744 if ( kappa != 0 ) { toft = pathtof /
VLIGHT / beta; }
2745 else { toft = pathtof /
VLIGHT; }
2746
2747
2748
2749
2750
2751 if ( zw > ( GeoRef->
Backward().z() ) / 10 ) zw = ( GeoRef->
Backward().z() ) / 10;
2752 if ( zw < ( GeoRef->
Forward().z() ) / 10 ) zw = ( GeoRef->
Forward().z() ) / 10;
2753
2754 double slant = GeoRef->
Slant();
2756
2757 double Tw = 0;
2758
2759
2760
2761
2762
2763 double driftt;
2764 double dummy;
2765 int lr = 2;
2766
2767 double p[3];
2768 p[0] = helix0.momentum( 0. ).x();
2769 p[1] = helix0.momentum( 0. ).y();
2770 double pos[2];
2771 pos[0] = xw;
2772 pos[1] = yw;
2774
2775
2776
2777 double dist = 0.;
2778
2779 dist = ( m_mdcUtilitySvc->doca( layer, wid, helix_par, helixErr ) ) * 10.0;
2780
2781 if ( dist < 0. ) lr = 1;
2782 else lr = 0;
2783 dist = fabs( dist );
2784 if ( dist > 0.4 * ( mdcGeomSvc->
Layer( layer ) )->PCSiz() )
continue;
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802 int idummy;
2803
2805 else
2806 {
2807 double entrance = ( *it_gothit )->getEntra();
2808 driftt = m_mdcCalibFunSvc->distToDriftTime( dist, layer, wid, lr, entrance );
2809 }
2811 {
2812 T0_cal = m_mdcCalibFunSvc->getT0( layer, wid ) +
2813 m_mdcCalibFunSvc->getTimeWalk( layer, tdc );
2814 }
2815
2816 double zprop = fabs( zw - m_zst[layer] );
2817 double tp = zprop / m_vp[layer];
2818
2819 if ( driftt > tdc ) continue;
2820 double difft = tdc - driftt - toft - tp - T0_cal;
2821 if ( ndriftt >= 500 ) break;
2822 if (
difft < -10 )
continue;
2823 Mdc_t0Arr[ndriftt] =
difft;
2824
2825
2826 sum_EstimeMdc = sum_EstimeMdc +
difft;
2827 ndriftt++;
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837 double tev = -t0_minus_TDC[wid] + driftt;
2838 if ( Estparam.
MDC_Tof() != 0 ) tev += direction * toft;
2839 if ( Estparam.
MDC_Prop() != 0 ) tev += prop;
2840
2841
2842
2843
2844 nhits_ax++;
2845 tev_ax[nhits_ax - 1] = tev;
2846
2847 if ( Estparam.
MDC_Debug() != 0 ) log << MSG::INFO <<
"*** tev ***" << tev << endmsg;
2848 double driftt_mea = t0_minus_TDC[wid];
2849
2850 if (
abs( driftt - driftt_mea ) < 75. )
2851 {
2852
2853 nhits_ax2++;
2855 log << MSG::INFO << "*** tev2 ***" << tev << endmsg;
2856 }
2857 }
2858
2859
2860 else if ( ( ( layer >= 4 && layer <= 7 ) || ( layer >= 20 && layer <= 35 ) ) &&
2862 {
2863
2864 IMdcGeomSvc* mdcGeomSvc;
2865 StatusCode sc = service( "MdcGeomSvc", mdcGeomSvc );
2866 const MdcGeoWire* GeoRef = mdcGeomSvc->
Wire( layer, wid );
2867
2868
2869
2870
2871 double bx = GeoRef->
Backward().x() / 10;
2872 double by = GeoRef->
Backward().y() / 10;
2873 double bz = GeoRef->
Backward().z() / 10;
2874 double fx = GeoRef->
Forward().x() / 10;
2875 double fy = GeoRef->
Forward().y() / 10;
2876 double fz = GeoRef->
Forward().z() / 10;
2877
2878
2879
2880
2881
2884
2885 Hep3Vector wire = (CLHEP::Hep3Vector)bck - (CLHEP::Hep3Vector)fwd;
2887 helix0.pivot( try1 );
2888 HepPoint3D try2 = ( helix0.x( 0 ).z() - bck.z() ) / wire.z() * wire + bck;
2889 helix0.pivot( try2 );
2890 HepPoint3D try3 = ( helix0.x( 0 ).z() - bck.z() ) / wire.z() * wire + bck;
2891 helix0.pivot( try3 );
2892
2893 double xh = helix0.x( 0. ).x();
2894 double yh = helix0.x( 0. ).y();
2895 double z = helix0.x( 0. ).z();
2896
2897
2898 double dphi = ( -xc * ( xh - xc ) - yc * ( yh - yc ) ) /
2899 sqrt( ( xc * xc + yc * yc ) *
2900 ( ( xh - xc ) * ( xh - xc ) + ( yh - yc ) * ( yh - yc ) ) );
2901 dphi = acos( dphi );
2902 double pathtof =
abs( unit_s * dphi );
2903 if ( kappa != 0 ) { toft = pathtof /
VLIGHT / beta; }
2904 else { toft = pathtof /
VLIGHT; }
2905
2906
2907
2908 if ( z != 9999. )
2909 {
2910
2911 if ( z < fz ) z = fz;
2912
2913 if ( z > bz ) z = bz;
2914 double slant = GeoRef->
Slant();
2916 }
2917 else { prop = 0.; }
2918
2919
2920 double Tw = 0;
2921
2922
2923
2924
2925
2926 double driftt = 0;
2927 double dummy;
2928
2929 double xw = fx + ( bx - fx ) / ( bz - fz ) * ( z - fz );
2930 double yw = fy + ( by - fy ) / ( bz - fz ) * ( z - fz );
2931
2933 helix0.pivot( pivot1 );
2934
2935 double zw = helix0.a()[3];
2936
2937 int lr = 2;
2938
2939 double p[3];
2940 p[0] = helix0.momentum( 0. ).x();
2941 p[1] = helix0.momentum( 0. ).y();
2942 double pos[2];
2943 pos[0] = xw;
2944 pos[1] = yw;
2946
2947
2948
2949 double dist = 0.;
2950
2951 dist = ( m_mdcUtilitySvc->doca( layer, wid, helix_par, helixErr ) ) * 10.0;
2952
2953 if ( dist < 0. ) lr = 1;
2954 else lr = 0;
2955 dist = fabs( dist );
2956 if ( dist > 0.4 * ( mdcGeomSvc->
Layer( layer ) )->PCSiz() )
continue;
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2975 else
2976 {
2977 double entrance = ( *it_gothit )->getEntra();
2978 driftt = m_mdcCalibFunSvc->distToDriftTime( dist, layer, wid, lr, entrance );
2979 }
2981 {
2982 T0_cal = m_mdcCalibFunSvc->getT0( layer, wid ) +
2983 m_mdcCalibFunSvc->getTimeWalk( layer, tdc );
2984 }
2985
2986 double zprop = fabs( zw - m_zst[layer] );
2987 double tp = zprop / m_vp[layer];
2988
2989 if ( driftt > tdc ) continue;
2990 double difft = tdc - driftt - toft - tp - T0_cal;
2991 if (
difft < -10 )
continue;
2992 if ( ndriftt >= 500 ) break;
2993 Mdc_t0Arr[ndriftt] =
difft;
2994
2995
2996
2997 sum_EstimeMdc = sum_EstimeMdc +
difft;
2998 ndriftt++;
2999
3000
3001
3002 double tev = -t0_minus_TDC[wid] + driftt;
3003 if ( Estparam.
MDC_Tof() != 0 ) tev += direction * toft;
3004 if ( Estparam.
MDC_Prop() != 0 ) tev += prop;
3005
3006
3007
3008
3009
3010
3011 nhits_st++;
3012 tev_st[nhits_st - 1] = tev;
3013
3015 log << MSG::INFO << "*** tev_st ***" << tev << endmsg;
3016 double driftt_mea = t0_minus_TDC[wid];
3017
3018 if (
abs( driftt - driftt_mea ) < 75. )
3019 {
3020
3021 nhits_st2++;
3023 log << MSG::INFO << "*** tev_st2 ***" << tev << endmsg;
3024 }
3025 }
3026
3027 }
3028 nmatch_mdc++;
3029 }
3030
3031 if (
m_ntupleflag && m_tuple2 ) g_nmatchmdc = nmatch_mdc;
3032 if ( ndriftt != 0 )
3033 {
3034 if (
m_mdcopt ) { sum_EstimeMdc = Opt_new( Mdc_t0Arr, ndriftt, 400.0 ); }
3035 else { sum_EstimeMdc = sum_EstimeMdc / ndriftt; }
3036 if (
m_ntupleflag && m_tuple2 ) g_EstimeMdc = sum_EstimeMdc;
3037 t_Est = sum_EstimeMdc + tOffset_b;
3038 if ( t_Est < 0 ) t_Est = 0;
3039 if ( optCosmic == 0 )
3040 {
3041 tEstFlag = 102;
3042 nbunch = ( (int)( t_Est - offset ) ) / bunchtime;
3043
3044 if ( ( t_Est - offset - nbunch * bunchtime ) > ( bunchtime / 2 ) ) nbunch = nbunch + 1;
3045 t_Est = nbunch * bunchtime + offset + tOffset_b;
3046
3047
3048
3049
3050
3051
3052
3053 }
3054 if ( optCosmic )
3055 {
3056 t_Est = sum_EstimeMdc;
3057 tEstFlag = 202;
3058 }
3059 }
3061 }
3062
3063 if ( t_Est != -999 )
3064 {
3065
3066 if ( ( !
m_beforrec ) && ( Testime_fzisan != t_Est ) )
3067 {
3068 if ( tEstFlag == 211 ) tEstFlag = 213;
3069 if ( tEstFlag == 212 ) tEstFlag = 216;
3070 if ( tEstFlag == 111 ) tEstFlag = 113;
3071 if ( tEstFlag == 112 ) tEstFlag = 116;
3072 }
3073
3074 if ( optCosmic )
3075 {
3076 StatusCode scStoreTds = storeTDS( t_Est, tEstFlag, t_quality );
3077 if ( scStoreTds != StatusCode::SUCCESS ) { return scStoreTds; }
3078 }
3079 else if ( !optCosmic )
3080 {
3081 StatusCode scStoreTds = storeTDS( t_Est, tEstFlag, t_quality );
3082 if ( scStoreTds != StatusCode::SUCCESS ) { return scStoreTds; }
3083 }
3084 }
3085 else
3086 {
3087
3089 {
3090
3091
3092 double segTest = Testime_fzisan + tOffset_b;
3093 int segFlag = TestimeFlag_fzisan;
3094 double segQuality = TestimeQuality_fzisan;
3095 StatusCode scStoreTds = storeTDS( segTest, segFlag, segQuality );
3096 if ( scStoreTds != StatusCode::SUCCESS ) { return scStoreTds; }
3097 }
3098 }
3099
3100
3101
3102 SmartDataPtr<RecEsTimeCol> arecestimeCol( eventSvc(), "/Event/Recon/RecEsTimeCol" );
3103 if ( !arecestimeCol )
3104 {
3105 if (
m_debug == 4 ) log << MSG::WARNING <<
"Could not find RecEsTimeCol" << endmsg;
3106 return ( StatusCode::SUCCESS );
3107 }
3108 RecEsTimeCol::iterator iter_evt = arecestimeCol->begin();
3109 for ( ; iter_evt != arecestimeCol->end(); iter_evt++ )
3110 {
3111 log << MSG::INFO << "Test = " << ( *iter_evt )->getTest()
3112 << ", Status = " << ( *iter_evt )->getStat() << endmsg;
3113 if (
m_ntupleflag && m_tuple2 ) { g_Testime = ( *iter_evt )->getTest(); }
3114
3115 }
3116
3118 {
3119 if ( m_tuple2 )
3120 {
3121 for ( g_ntofdown = 0; g_ntofdown < ntofdown; g_ntofdown++ )
3122 { g_meantevdown[g_ntofdown] = meantevdown[g_ntofdown]; }
3123 for ( g_ntofup = 0; g_ntofup < ntofup; g_ntofup++ )
3124 { g_meantevup[g_ntofup] = meantevup[g_ntofup]; }
3125 g_nmatch_tot = nmatch;
3126 m_estFlag = tEstFlag;
3127 m_estTime = t_Est;
3128 StatusCode status = m_tuple2->write();
3129 if ( !status.isSuccess() ) { log << MSG::ERROR << "Can't fill ntuple!" << endmsg; }
3130 }
3131 if ( m_tuple9 )
3132 {
3133 for ( g_nmatch = 0; g_nmatch < nmatch; g_nmatch++ )
3134 { g_meantev[g_nmatch] = meantev[g_nmatch]; }
3135 StatusCode status = m_tuple9->write();
3136 if ( !status.isSuccess() ) { log << MSG::ERROR << "Can't fill ntuple!" << endmsg; }
3137 }
3138 }
3139 return StatusCode::SUCCESS;
3140}
**********INTEGER nmxhep !maximum number of particles DOUBLE PRECISION vhep INTEGER jdahep COMMON hepevt $ !serial number $ !number of particles $ !status code $ !particle ident KF $ !parent particles $ !childreen particles $ !four momentum
HepGeom::Point3D< double > HepPoint3D
std::vector< TofData * > TofDataVector
double cos(const BesAngle a)
SmartRefVector< RecMdcHit > HitRefVec
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
*********Class see also m_nmax DOUBLE PRECISION m_MasPhot DOUBLE PRECISION m_phsu DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_r2 DOUBLE PRECISION m_WtMass INTEGER m_nmax INTEGER m_Nevgen INTEGER m_IsFSR INTEGER m_MarTot *COMMON c_KarFin $ !Output file $ !Event serial number $ !alpha QED at Thomson limit $ !minimum energy at CMS for remooval $ !infrared dimensionless $ !dummy photon IR regulator $ !crude photon multiplicity enhancement factor *EVENT $ !MC crude volume of PhhSpace *Sfactors $ !YFS formfactor IR part only $ !YFS formfactor non IR finite part $ !mass weight
int Emc_Get(double, int, double[])
void pathlCut(double pathl_max)
double ztofCutmin() const
double ztofCutmax() const
virtual const MdcGeoLayer *const Layer(unsigned id)=0
virtual const MdcGeoWire *const Wire(unsigned id)=0
HepPoint3D Forward(void) const
HepPoint3D Backward(void) const
static int layer(const Identifier &id)
Values of different levels (failure returns 0).
static int wire(const Identifier &id)
static double MdcTime(int timeChannel)
static double TofTime(unsigned int timeChannel)
int TofFz_Get(double, int, double[])
void ztofCut(double ztof_min, double ztof_max)
void pathlCut(double pathl_max)
static int endcap(const Identifier &id)