308 {
309
310 MsgStream log(
msgSvc(), name());
311 log << MSG::INFO << " tof " << endreq;
312
313
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} ,idt[15]={0},particleId[30]={0}, tofid_emc[2]={0}, module[20]={0};
317 int idetf, etfid_helix[30]={-9}, idetfmatch[3][36]={-9}, idmatch_etf_emc[3][36]={0}, etfid_emc[2]={0};
318 int ntot=0,in=-1,out=-1, emcflag1=0, emcflag2=0, tof_flag=0;
double bunchtime=
m_bunchtime_MC;
319 double meant[15]={0.},adc[15]={0.},
momentum[15]={0.},r_endtof[15]={0.};
320 double ttof[30]={0.},helztof[30]={0.0},mcztof=0.0,forevtime=0.0,backevtime=0.0,meantev[500]={0.},meantevup[500]={0.0},meantevdown[500]={0.0};
321 double t0forward=0,t0backward=0,t0forward_trk=0,t0backward_trk=0;
322 double t0forward_add=0,t0backward_add=0,t_Est=-999;
323 double thetaemc_rec[20]={0.},phiemc_rec[20]={0.},energy_rec[20]={0.},xemc_rec[20]={0.},yemc_rec[20]={0.},zemc_rec[20]={0.};
324 double r_endetf[30]={0.}, tetf[30]={0.}, helzetf[30]={0.}, helpathetf[36]={0.}, abmom2etf[36]={0.};
325
326 int nmatch1=0,nmatch2=0,nmatch_barrel=0,nmatch_end=0,nmatch_mdc=0, nmatch_barrel_1=0, nmatch_barrel_2=0,nmatch=0,ntofup=0,ntofdown=0;
327 double sum_EstimeMdc=0,sum_EstimeMdcMC=0;
328 int nbunch=0,tEstFlag=0,
runNo=0;
329 double helpath[88]={0.},helz[88]={0.},abmom2[88]={0.};
330 double mcTestime=0,trigtiming=0;
331 double mean_tdc_btof[2][88]={0.}, mean_tdc_etof[3][48]={0.}, mean_tdc_etf[3][36][12]={0.};
334 double Testime_fzisan= -999.;
335 int TestimeFlag_fzisan= -999;
336 double TestimeQuality_fzisan= -999.;
337 double Tof_t0Arr[500]={-999.};
338
339 bool useEtofScin = (
m_phase<3 );
340 bool useEtofMRPC = (
m_phase>2 );
341
342
343 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
344 if (!eventHeader) {
345 log << MSG::FATAL << "Could not find Event Header" << endreq;
346 return StatusCode::FAILURE;
347 }
348 int eventNo=eventHeader->eventNumber();
349 runNo=eventHeader->runNumber();
350 log << MSG::INFO <<
"EsTimeAlg: retrieved event: " <<
eventNo <<
" run: " <<
runNo << endreq;
351
359 }
361
372 g_bunchtime=8;
373 g_t0offset_b=2.0;
374 g_t0offset_e=2.0;
375 }
376
377 m_pass[0]++;
378 if(
m_evtNo==1 && m_pass[0]%1000 ==0){
379 cout<<"------------------- Events-----------------: "<<m_pass[0]<<endl;
380 }
381 if(
m_debug==4) cout<<
"m_userawtime: "<<m_userawtime<<endl;
382 if(
m_debug==4) cout<<
"EstTofCalibSvc est flag: "<<tofCaliSvc->
ValidInfo()<<endl;
383
385 log << MSG::ERROR << "EstTof Calibration Const is NOT correct! " << endreq;
386 return StatusCode:: FAILURE;
387 }
389 {
390 log << MSG::ERROR << "EstTof Calibration Const is Invalid! " << endreq;
391 return StatusCode::FAILURE;
392 }
394 else m_userawtime=0;
395
396 SmartDataPtr<RecEsTimeCol> aRecestimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
397 if (!aRecestimeCol || aRecestimeCol->size()==0) {
398 if(
m_debug==4) log << MSG::INFO <<
"Could not find RecEsTimeCol from fzsian" << endreq;
399 }else{
400 RecEsTimeCol::iterator it_evt = aRecestimeCol->begin();
401 for(; it_evt!=aRecestimeCol->end(); it_evt++){
402 Testime_fzisan = (*it_evt)->getTest();
403 TestimeFlag_fzisan = (*it_evt)->getStat();
404 TestimeQuality_fzisan = (*it_evt)->getQuality();
405
406 log << MSG::INFO << "fzisan : Test = "<<(*it_evt)->getTest()
407 << ", Status = "<<(*it_evt)->getStat() <<endreq;
408
409 if(
m_ntupleflag && m_tuple2) g_Testime_fzisan = Testime_fzisan;
410 }
411 }
412
413 static std::string fullPath = "/Calib/EsTimeCal";
414 SmartDataPtr<CalibData::EsTimeCalibData> TEst(m_pCalibDataSvc, fullPath);
415 if(!TEst){ cout<<"ERROR EsTimeCalibData"<<endl;}
416 else{
417 int no = TEst->getTestCalibConstNo();
418
419
420
421
422
423 unsigned int inumber = 0;
424 unsigned int calibNo = TEst->getSize();
425 if( calibNo > 1 ) {
426 for( unsigned int i=0; i<calibNo; i++, inumber++ ) {
427 if( ( TEst->getRunTo(i) != -1 ) && ( TEst->getRunTo(i) < TEst->getRunFrom(i) ) ) {
428 log << MSG::ERROR << "EsTimeCal -- The " << inumber << "th calibration constatns is ABNORMAL! Run From is LARGER than RUN To!" << endreq;
429 return StatusCode::FAILURE;
430 }
431 if( ( TEst->getRunFrom(i) == TEst->getRunTo(i) ) && ( TEst->getEventFrom(i) != -1 ) && ( TEst->getEventTo(i) != -1 ) && ( TEst->getEventFrom(i) > TEst->getEventTo(i) ) ) {
432 log << MSG::ERROR << "EsTimeCal -- The " << inumber << "th calibration constatns is ABNORMAL! Event From is LARGER than Event To!" << endreq;
433 return StatusCode::FAILURE;
434 }
435 }
436
437 inumber = 0;
438 bool filled = false;
439 for( unsigned int i=0; i<calibNo; i++, inumber++ ) {
440 int runFrom = TEst->getRunFrom(i);
441 int runTo = TEst->getRunTo(i);
442 int eventFrom = TEst->getEventFrom(i);
443 int eventTo = TEst->getEventTo(i);
444 if( (
runNo == runFrom ) && ( ( eventFrom == -1 ) || (
eventNo >= eventFrom ) ) ) {
445 if( (
runNo < runTo ) || ( (
runNo == runTo ) && ( ( eventTo == -1 ) || (
eventNo <= eventTo ) ) ) ) {
446 filled = true;
447 break;
448 }
449 }
450 if(
runNo > runFrom ) {
451 if( (
runNo < runTo ) || ( (
runNo == runTo ) && ( ( eventTo == -1 ) || (
eventNo <= eventTo ) ) ) ) {
452 filled = true;
453 break;
454 }
455 }
456 }
457 if( !filled ) {
458 log << MSG::ERROR <<
"EsTimeCal -- For run number:" <<
runNo <<
", NO suitable calibration constant is found!" << endreq;
459 return StatusCode::FAILURE;
460 }
461 }
462
463 log<<MSG::INFO<<"offset barrel t0="<< TEst->getToffsetb(inumber)
464 <<", offset endcap t0="<< TEst->getToffsete(inumber)
465 <<", bunch time ="<<TEst->getBunchTime(inumber)
466 <<endreq;
467 tOffset_b = TEst->getToffsetb(inumber);
468 tOffset_e = TEst->getToffsete(inumber);
469 bunchtime = TEst->getBunchTime(inumber);
470 }
471
472 if(m_userawtime) {
473 tOffset_b=0;
474 tOffset_e=0;
475 }
476 else
477 {
482 }
483
485 {
487 }
488
490
491
492 int digiId;
494 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),"/Event/MC/McParticleCol");
495 if (!mcParticleCol) {
496 log << MSG::INFO<< "Could not find McParticle" << endreq;
497 }
498 else{
499 McParticleCol::iterator iter_mc = mcParticleCol->begin();
500 digiId = 0;
501 ntrkMC = 0;
503
504 for (;iter_mc != mcParticleCol->end(); iter_mc++, digiId++) {
505 int statusFlags = (*iter_mc)->statusFlags();
506 int pid = (*iter_mc)->particleProperty();
507 log << MSG::INFO
508 << " MC ParticleId = " << pid
509 << " statusFlags = " << statusFlags
510 << " PrimaryParticle = " <<(*iter_mc)->primaryParticle()
511 << endreq;
513 g_theta0MC[ntrkMC] = (*iter_mc)->initialFourMomentum().theta();
514 g_phi0MC[ntrkMC] = (*iter_mc)->initialFourMomentum().phi();
515 g_pxMC[ntrkMC] = (*iter_mc)->initialFourMomentum().px()/1000;
516 g_pyMC[ntrkMC] = (*iter_mc)->initialFourMomentum().py()/1000;
517 g_pzMC[ntrkMC] = (*iter_mc)->initialFourMomentum().pz()/1000;
518 g_ptMC[ntrkMC] = sqrt(((*iter_mc)->initialFourMomentum().px())*((*iter_mc)->initialFourMomentum().px())+((*iter_mc)->initialFourMomentum().py())*((*iter_mc)->initialFourMomentum().py()))/1000;
519 }
520 if( pid >0 ) {
521 if(m_particleTable->particle( pid ))
charge = m_particleTable->particle( pid )->charge();
522 } else if ( pid <0 ) {
523 if(m_particleTable->particle( -pid )) {
524 charge = m_particleTable->particle( -pid )->charge();
526 }
527 } else {
528 log << MSG::WARNING << "wrong particle id, please check data" <<endreq;
529 }
530 log << MSG::DEBUG
531 <<
"MC ParticleId = " << pid <<
" charge = " <<
charge
532 << endreq;
533 if(
charge !=0 &&
abs(
cos((*iter_mc)->initialFourMomentum().theta()))<0.93){
534 ntrkMC++;
535 }
536 if(((*iter_mc)->primaryParticle())&&
m_ntupleflag && m_tuple2){
537 g_mcTestime=(*iter_mc)->initialPosition().t();
538 mcTestime=(*iter_mc)->initialPosition().t();
539 }
540 }
542 }
543 }
544 if (
m_debug) cout<<
"bunchtime: "<<bunchtime<<endl;
545
546 SmartDataPtr<RecMdcTrackCol> newtrkCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
547 if (!newtrkCol || newtrkCol->size()==0) {
548 log << MSG::INFO<< "Could not find RecMdcTrackCol" << endreq;
549 } else{
550 log << MSG::INFO << "Begin to check RecMdcTrackCol"<<endreq;
551 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
552 for( ; iter_trk != newtrkCol->end(); iter_trk++){
553 log << MSG::DEBUG << "retrieved MDC track:"
554 << " Track Id: " << (*iter_trk)->trackId()
555 << " Phi0: " << (*iter_trk)->helix(0)
556 << " kappa: " << (*iter_trk)->helix(2)
557 << " Tanl: " << (*iter_trk)->helix(4)
558 << " Phi terminal: "<< (*iter_trk)->getFiTerm()
559 << endreq
560 << "Number of hits: "<< (*iter_trk)->getNhits()
561 << " Number of stereo hits " << (*iter_trk)->nster()
562 << endreq;
563 double kappa = (*iter_trk)->helix(2);
564 double tanl = (*iter_trk)->helix(4);
565 if((*iter_trk)->helix(3)>50.0) continue;
566 ntot++;
567 if (ntot>14) break;
568 momentum[ntot] = 1./fabs(kappa) * sqrt(1.+tanl*tanl);
569 }
570 }
571
572
573 int emctrk=0;
574 SmartDataPtr<RecEmcShowerCol> aShowerCol(eventSvc(),"/Event/Recon/RecEmcShowerCol");
575 if (!aShowerCol || aShowerCol->size()==0) {
576 log << MSG::WARNING << "Could not find RecEmcShowerCol" << endreq;
577 } else{
578 RecEmcShowerCol::iterator iShowerCol=aShowerCol->begin();
579 for(;iShowerCol!=aShowerCol->end();iShowerCol++,emctrk++){
580 if(emctrk>19) break;
581 phiemc_rec[emctrk]=(*iShowerCol)->position().phi();
582 thetaemc_rec[emctrk]=(*iShowerCol)->position().theta();
583 energy_rec[emctrk]=(*iShowerCol)->energy();
584 xemc_rec[emctrk]=(*iShowerCol)->x();
585 yemc_rec[emctrk]=(*iShowerCol)->y();
586 zemc_rec[emctrk]=(*iShowerCol)->z();
587 module[emctrk]=(*iShowerCol)->module();
588 }
589 }
590 for(int i=0; i<2; i++){
591 double fi_endtof = atan2(yemc_rec[i],xemc_rec[i] );
592 if( fi_endtof<0 ) { fi_endtof=2*3.141593+fi_endtof; }
593 if( module[i]==1 ) {
594 int Tofid = (int)(fi_endtof/(3.141593/44));
595 if(Tofid>87) Tofid=Tofid-88;
596 tofid_emc[i]=Tofid;
597 idmatch_emc[1][Tofid]=1;
598 }
599 else{
600 if( useEtofScin ) {
601 int Tofid =(int)(fi_endtof/(3.141593/24));
602 if( Tofid>47) Tofid=Tofid-48;
603 tofid_emc[i]= Tofid;
604 if(module[i]==2) idmatch_emc[2][Tofid]=1;
605 if(module[i]==0) idmatch_emc[0][Tofid]=1;
606 }
607 if( useEtofMRPC ) {
608 int Tofid = (int)(fi_endtof/(3.141593/18));
609 if( Tofid>35) Tofid=Tofid-36;
610 etfid_emc[i]= Tofid;
611 if(module[i]==2) idmatch_etf_emc[2][Tofid]=1;
612 if(module[i]==0) idmatch_etf_emc[0][Tofid]=1;
613 }
614 }
615 }
616
617 ntrk=0;
618 if (ntot > 0) {
619 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
620 for( int idfztrk=0; iter_trk != newtrkCol->end(); iter_trk++,idfztrk++){
621 double mdcftrk[5];
622 mdcftrk[0] = (*iter_trk)->helix(0);
623 mdcftrk[1] = (*iter_trk)->helix(1);
624 mdcftrk[2] =-(*iter_trk)->helix(2);
625 mdcftrk[3] = (*iter_trk)->helix(3);
626 mdcftrk[4] = (*iter_trk)->helix(4);
627
628 if(optCosmic==0){
630
632
633
634
636 double z_emc = EmcHit.
Z_emc;
638 double phiemc_ext = EmcHit.
phi_emc;
639
640 double kappa = (*iter_trk)->helix(2);
641 double tanl = (*iter_trk)->helix(4);
642 double _momentum = 1./fabs(kappa) * sqrt(1.+tanl*tanl);
643 for(
int t=0;
t<emctrk;
t++){
644 if((thetaemc_ext>=(thetaemc_rec[
t]-0.1)) && (thetaemc_ext<=(thetaemc_rec[
t]+0.1)) && (phiemc_ext>=(phiemc_rec[
t]-0.1)) && (phiemc_ext<=(phiemc_rec[
t]+0.1))){
645 if((energy_rec[
t])>=(0.85*_momentum))
646 particleId[idfztrk]=1;
647 }
648 }
649 }
650
651 if(particleId[idfztrk]!=1){
652
653 SmartDataPtr<RecMdcDedxCol> newdedxCol(eventSvc(),"/Event/Recon/RecMdcDedxCol");
654 if (!newdedxCol || newdedxCol->size()==0) {
655 log << MSG::WARNING<< "Could not find RecMdcDedxCol" << endreq;
656 }
657 else{
658 RecMdcDedxCol::iterator it_dedx = newdedxCol->begin();
659 for( int npid=0; it_dedx != newdedxCol->end(); it_dedx++,npid++) {
660 log << MSG::INFO << "retrieved MDC dE/dx: "
661 << "dEdx Id: " << (*it_dedx)->trackId()
662 << " particle Id: "<< (*it_dedx)->particleType() <<endreq;
663 if((*it_dedx)->particleType() ==
proton){
664 particleId[npid]= 5;
665 }
666 if(
m_debug==4) cout<<
"dedx pid: "<<particleId[npid]<<endl;
667 }
668 }
669 }
670 }
671
672 idtof = -100;
673 idetf = -100;
675
676
678
679
681
683 if(tofpart < 0) continue;
684
685
686 bool useBarrelScin = ( tofpart==1 );
687 bool useEndcapScin = ( ( tofpart==0 || tofpart==2 ) && useEtofScin );
688 bool useEndcapMRPC = ( ( tofpart==0 || tofpart==2 ) && useEtofMRPC );
689
690 if( useBarrelScin || useEndcapScin ) {
691 idtof = TofHit.
Tofid;
692 tofid_helix[idfztrk] = TofHit.
Tofid;
693 }
694 if( useEndcapMRPC ) {
695 idetf = TofHit.
Etfid;
696 etfid_helix[idfztrk] = TofHit.
Etfid;
697 }
698
699 log << MSG::INFO << "helix to tof hit part: "<<tofpart<<" tof id: "<< idtof << " etf id:" << idetf << endreq;
700 if(
m_debug==4 ) cout <<
"helix to tof hit part, Id: "<<tofpart<<
" , "<< idtof <<endl;
701 if( ( useBarrelScin && idtof>=0 && idtof<=87 ) || ( useEndcapScin && idtof>=0 && idtof<=47 ) || ( useEndcapMRPC && idetf>=0 && idetf<=35 ) ) {
702
703 double abmom = 0.0;
704 if( useEndcapMRPC ) {
705 idetfmatch[tofpart][idetf]= 1;
707 helz[idetf] = TofHit.
Z_etf;
708 abmom = 1./fabs(TofHit.
Kappa) * sqrt(1.+TofHit.
Tanl*TofHit.
Tanl);
709 if(abmom<0.1) continue;
710 abmom2etf[idetf] = abmom*abmom;
711 r_endetf[idfztrk]= TofHit.
r_etf;
712 helzetf[idfztrk] = helz[idetf];
713 }
714
715 if( useBarrelScin || useEndcapScin ) {
716 idmatch[tofpart][idtof] = 1;
717 helpath[idtof] = TofHit.
Pathl;
718 helz[idtof] = TofHit.
Z_tof;
719 abmom = 1./fabs(TofHit.
Kappa) * sqrt(1.+TofHit.
Tanl*TofHit.
Tanl);
720 if(abmom<0.1) continue;
721 abmom2[idtof] = abmom*abmom;
723 helztof[idfztrk] = helz[idtof];
724 }
725
727 cout << "Scintillator info trk number=" << idfztrk << " tofpart=" << tofpart << " idtof=" << idtof << " helpath=" << helpath[idtof] << " helz=" << helz[idtof] << " abmom=" << abmom2[idtof] << " r=" << r_endtof[idfztrk] << " helztof=" << helz[idtof] << endl;
728 cout << "MRPC info trk number=" << idfztrk << " tofpart=" << tofpart << " idetf=" << idetf << " helpath=" << helpathetf[idetf] << " helz=" << helzetf[idetf] << " abmom=" << abmom2etf[idetf] << " r=" << r_endetf[idfztrk] << " helztof=" << helzetf[idetf] << endl;
729 }
730
731 double vel = 1.0e-6;
732 if( optCosmic==0 ) {
733
734 if( useEndcapMRPC ) {
735 if( particleId[idfztrk] == 1 ) {
736 tetf[idfztrk] = sqrt(
ELMAS2/abmom2etf[idetf]+1)* helpathetf[idetf]/
VLIGHT;
738 }
739 else if( particleId[idfztrk] == 5 ) {
740 tetf[idfztrk] = sqrt(
PROTONMAS2/abmom2etf[idetf]+1)* helpathetf[idetf]/
VLIGHT;
742 }
743 else {
744 tetf[idfztrk] = sqrt(
PIMAS2/abmom2etf[idetf]+1)* helpathetf[idetf]/
VLIGHT;
746 }
747 }
748
749 if( useBarrelScin || useEndcapScin ) {
750 if( particleId[idfztrk] == 1 ) {
751 ttof[idfztrk] = sqrt(
ELMAS2/abmom2[idtof]+1)* helpath[idtof]/
VLIGHT;
753 }
754 else if( particleId[idfztrk] == 5 ) {
757 }
758 else {
759 ttof[idfztrk] = sqrt(
PIMAS2/abmom2[idtof]+1)* helpath[idtof]/
VLIGHT;
761 }
762 }
763
764 }
765 else{
766
767 if( useEndcapMRPC ) {
768 tetf[idfztrk] = sqrt(
MUMAS2/abmom2etf[idetf]+1)* helpathetf[idetf]/
VLIGHT;
770 }
771
772 if( useBarrelScin || useEndcapMRPC ) {
773 ttof[idfztrk] = sqrt(
MUMAS2/abmom2[idtof]+1)* helpath[idtof]/
VLIGHT;
775 }
776 }
777
779 g_vel[idfztrk] = vel;
780 g_abmom[idfztrk] = abmom;
781 if( useEndcapMRPC ) {
782 g_ttof[idfztrk] = tetf[idfztrk];
783 }
784 if( useBarrelScin || useEndcapScin ) {
785 g_ttof[idfztrk] = ttof[idfztrk];
786 }
787 g_pid[idfztrk] = particleId[idfztrk];
788 }
789 }
790 ntrk++;
791 }
793 }
794
795
796
798 SmartDataPtr<TofMcHitCol> tofmcHitCol(eventSvc(),"/Event/MC/TofMcHitCol");
799 if (!tofmcHitCol) {
800 log << MSG::ERROR<< "Could not find McParticle" << endreq;
801
802 }
803 else{
804 TofMcHitCol::iterator iter_mctof = tofmcHitCol->begin();
805
806 for (;iter_mctof !=tofmcHitCol->end(); iter_mctof++, digiId++) {
807 log << MSG::INFO
808 << " TofMcHit Flight Time = " << (*iter_mctof)->getFlightTime()
809 << " zPosition = " << ((*iter_mctof)->getPositionZ())/10
810 << " xPosition = " <<((*iter_mctof)->getPositionX())/10
811 << " yPosition = " <<((*iter_mctof)->getPositionY())/10
812 << endreq;
813 }
814 }
815 }
816
817
819
820 for(TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++) {
821 int barrelid;
822 int layerid;
823 int tofid;
824 int strip;
825
826 if( !( (*iter2)->is_mrpc() ) ) {
827 if( (*iter2)->barrel() ) {
828 barrelid = 1;
829 tofid = (*iter2)->tofId();
830 layerid = (*iter2)->layer();
831 if(layerid==1) tofid=tofid-88;
832 if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times()==1 ) {
833 double ftdc = (*iter2)->tdc1();
834 double btdc = (*iter2)->tdc2();
835 mean_tdc_btof[layerid][tofid]=(ftdc+btdc)/2;
836 }
837 else if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times()>1 ) {
838 double ftdc = (*iter2)->tdc1();
839 double btdc = (*iter2)->tdc2();
840 mean_tdc_btof[layerid][tofid]=(ftdc+btdc)/2;
841 }
842 }
843 else{
844 tofid = (*iter2)->tofId();
845 if(tofid<48) barrelid=0;
846 if(tofid>47) barrelid=2;
847 if(barrelid==2) tofid=tofid-48;
848
849 if((*iter2)->times()==1){
850 double ftdc= (*iter2)->tdc();
851 mean_tdc_etof[barrelid][tofid]=ftdc;
852 }
853 else if(((*iter2)->times()>1) && ((*iter2)->times()<5)){
854 double ftdc= (*iter2)->tdc();
855 mean_tdc_etof[barrelid][tofid]=ftdc;
856 }
857 }
858 }
859 else {
860 tofid = (*iter2)->tofId();
861 strip = (*iter2)->strip();
862 if( tofid<36 ) barrelid=0;
863 if( tofid>35 ) barrelid=2;
864 if(barrelid==2) tofid=tofid-36;
865 if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times()==1 ) {
866 double ftdc = (*iter2)->tdc1();
867 double btdc = (*iter2)->tdc2();
868 mean_tdc_etf[barrelid][tofid][strip]=(ftdc+btdc)/2;
869 }
870 else if( ((*iter2)->quality()&0x5)==0x5 && (*iter2)->times()>1 ) {
871 double ftdc = (*iter2)->tdc1();
872 double btdc = (*iter2)->tdc2();
873 mean_tdc_etf[barrelid][tofid][strip]=(ftdc+btdc)/2;
874 }
875 }
876 }
877
878 double difftof_b=100, difftof_e=100;
879 int tofid1=tofid_emc[0];
880 int tofid2=tofid_emc[1];
881 if( module[0]==1 && module[1]==1 ) {
882 for(int i=0; i<2; i++){
883 for(int m=0; m<2; m++){
884 for(int j=-2; j<3; j++){
885 for(int k=-2; k<3; k++){
886 int p=tofid1+j;
888 if(p<0) p=p+88;
889 if(p>87) p=p-88;
892 if(mean_tdc_btof[i][p]==0 || mean_tdc_btof[m][
q]==0)
continue;
893 double difftof_b_temp = mean_tdc_btof[i][p]-mean_tdc_btof[m][
q];
894 if(
abs(difftof_b_temp)<
abs(difftof_b )) difftof_b =difftof_b_temp;
896 }
897 }
898 }
899 }
900 }
901
902 if( useEtofMRPC ) {
903 if( module[0]!=1 && module[1]!=1 ) {
904 tofid1 = etfid_emc[0];
905 tofid2 = etfid_emc[1];
906 for(int i=-1; i<2; i++){
907 for(int j=-1; j<2; j++){
908 int m=tofid1+i;
910 if(m<0) m=36+m;
911 if(m>35) m=m-36;
914 if( mean_tdc_etf[0][m] && mean_tdc_etf[2][
n]){
915 double difftof_e_temp= mean_tdc_etf[0][m]-mean_tdc_etf[2][
n];
916 if(
abs(difftof_e_temp) <
abs(difftof_e)) difftof_e= difftof_e_temp;
918 }
919 }
920 }
921 }
922 }
923
924 if( useEtofScin ) {
925 if( module[0]!=1 && module[1]!=1 ) {
926 for(int i=-1; i<2; i++){
927 for(int j=-1; j<2; j++){
928 int m=tofid1+i;
930 if(m<0) m=48+m;
931 if(m>47) m=m-48;
934 if( mean_tdc_etof[0][m] && mean_tdc_etof[2][
n]){
935 double difftof_e_temp= mean_tdc_etof[0][m]-mean_tdc_etof[2][
n];
936 if(
abs(difftof_e_temp) <
abs(difftof_e)) difftof_e= difftof_e_temp;
938 }
939 }
940 }
941 }
942 }
943
945 else optCosmic=0;
946
947 digiId = 0;
948 unsigned int tofid;
949 unsigned int barrelid;
950 unsigned int layerid;
951 t0forward_add = 0;
952 t0backward_add = 0;
953 TofDataVector::iterator iter2 = tofDigiVec.begin();
954 for (;iter2 != tofDigiVec.end(); iter2++, digiId++){
955 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
956 barrelid=(*iter2)->barrel();
957 if((*iter2)->barrel()==0) continue;
958 if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times()==1 ) {
959 tofid = (*iter2)->tofId();
960 layerid = (*iter2)->layer();
961 if(layerid==1) tofid=tofid-88;
962 log<< MSG::INFO
963 <<" TofId = "<<tofid
964 <<" barrelid = "<<barrelid
965 <<" layerid = "<<layerid
966 <<" ForwordADC = "<<(*iter2)->adc1()
967 <<" ForwordTDC = "<<(*iter2)->tdc1()
968 <<" BackwordADC = "<<(*iter2)->adc2()
969 <<" BackwordTDC = "<<(*iter2)->tdc2()
970 << endreq;
971
972 double ftdc = (*iter2)->tdc1();
973 double btdc = (*iter2)->tdc2();
974 if(
m_debug==4) cout<<
"barrel 1 ::layer, barrel, tofid, ftdc, btdc: "<<layerid<<
" , "<<barrelid<<
" , "<<tofid<<
" , "<<ftdc<<
" , "<<btdc<<endl;
975 double fadc = (*iter2)->adc1();
976 double badc = (*iter2)->adc2();
977 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
978 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
979 double ztof = fabs((ftdc-btdc)/2)*17.7 , ztof2 = ztof*ztof;
980 double mean_tdc = 0.5*(btdc+ftdc);
982
983 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
984 for(int i=0;i<ntot;i++){
985 if(ttof[i]!=0 && ftdc>0){
986 if((tofid_helix[i] == tofid) || (tofid_helix[i] == idntof) ||(tofid_helix[i] == idptof)) {
987 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
988 if (optCosmic && tofid<44) {
989 backevtime = -ttof[i] + (115 + helztof[i])*0.0566 + 12.;
990 forevtime = -ttof[i] + (115 - helztof[i])*0.0566 + 12.;
991 meantevup[ntofup]=(backevtime+forevtime)/2;
992 ntofup++;
993 }
994 else{
995 backevtime = ttof[i] + (115 + helztof[i])*0.0566 + 12.;
996 forevtime = ttof[i] + (115 - helztof[i])*0.0566 + 12.;
997 meantevdown[ntofdown]=(backevtime+forevtime)/2;
998 ntofdown++;
999 }
1000 if( (*iter2)->adc1()<0.0 || (*iter2)->adc2()<0.0 || m_userawtime){
1001 t0forward_trk = ftdc - forevtime ;
1002 t0backward_trk = btdc - backevtime ;
1003 }
1004 else{
1005 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
1006 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
1007 if (optCosmic && tofid<44) {
1008 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())+ttof[i];
1009 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())+ttof[i];
1010 }
1011 }
1012
1013 if(t0forward_trk<-3 || t0backward_trk<-3 || fabs(t0forward_trk-t0backward_trk)>15.0) continue;
1014 if(!
m_TofOpt&& nmatch_barrel!=0 && fabs((t0forward_trk+t0backward_trk)/2-(t0backward_add+t0forward_add)/2/nmatch_barrel)>11)
continue;
1015 if(
m_debug ==4 ) cout<<
" t0forward_trk, t0backward_trk: "<<t0forward_trk<<
" , "<<t0backward_trk<<endl;
1017 g_t0for[nmatch1] = t0forward_trk ;
1018 g_t0back[nmatch2] = t0backward_trk ;
1019 g_meantdc=(ftdc+btdc)/2;
1020 if(tofid<44) g_ntofup1++;
1021 else g_ntofdown1++;
1022 }
1023 t0forward_add += t0forward_trk;
1024 t0backward_add += t0backward_trk;
1025 if(nmatch>499) break;
1026 meantev[nmatch]=(backevtime+forevtime)/2;
1027 Tof_t0Arr[nmatch]=(t0forward_trk+t0backward_trk)/2.0;
1028 nmatch++;
1029 nmatch1=nmatch1+1;
1030 nmatch2=nmatch2+1;
1031 nmatch_barrel++;
1032 }
1033 }
1034 }
1035 }
1036 }
1037 }
1038 }
1039
1040 if(nmatch_barrel != 0 ){
1042 g_t0barrelTof=( t0forward_add/nmatch_barrel + t0backward_add/nmatch_barrel)/2;
1043 }
1044 tof_flag = 1;
1045 t_quality=1;
1046 }
1047
1048 if(nmatch_barrel==0){
1049 digiId = 0;
1050 t0forward_add = 0;
1051 t0backward_add = 0;
1052 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
1053 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
1054 barrelid=(*iter2)->barrel();
1055 if((*iter2)->barrel()==0) continue;
1056 if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times()>1 ) {
1057 tofid = (*iter2)->tofId();
1058 layerid = (*iter2)->layer();
1059 if(layerid==1) tofid=tofid-88;
1060 log<< MSG::INFO
1061 <<" TofId = "<<tofid
1062 <<" barrelid = "<<barrelid
1063 <<" layerid = "<<layerid
1064 <<" ForwordADC = "<<(*iter2)->adc1()
1065 <<" ForwordTDC = "<<(*iter2)->tdc1()
1066 <<endreq;
1067 double ftdc= (*iter2)->tdc1();
1068 double btdc= (*iter2)->tdc2();
1069 double fadc= (*iter2)->adc1();
1070 double badc= (*iter2)->adc2();
1071 if(
m_debug==4) cout<<
"barrel 2 ::layer, barrel, tofid, ftdc, btdc: "<<layerid<<
" , "<<barrelid<<
" , "<<tofid<<
" , "<<ftdc<<
" , "<<btdc<<endl;
1072 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
1073 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
1074 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
1075 for(int i=0;i<ntot;i++){
1076 if(ttof[i]!=0 && ftdc>0){
1077 if(tofid_helix[i] == tofid ||(tofid_helix[i] == idptof)||(tofid_helix[i] == idntof)){
1078 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
1079 if (optCosmic && tofid<44) {
1080 backevtime = -ttof[i] + (115 + helztof[i])*0.0566 + 12.;
1081 forevtime = -ttof[i] + (115 - helztof[i])*0.0566 + 12.;
1082 meantevup[ntofup]=(backevtime+forevtime)/2;
1083 ntofup++;
1084 }
1085 else{
1086 backevtime = ttof[i] + (115 + helztof[i])*0.0566 + 12.;
1087 forevtime = ttof[i] + (115 - helztof[i])*0.0566 + 12.;
1088 meantevdown[ntofdown]=(backevtime+forevtime)/2;
1089 ntofdown++;
1090 }
1091 if( (*iter2)->adc1()<0.0 || (*iter2)->adc2()<0.0 || m_userawtime){
1092 t0forward_trk = ftdc - forevtime ;
1093 t0backward_trk = btdc - backevtime ;
1094 }
1095 else{
1096 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
1097 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
1098 if (optCosmic && tofid<44) {
1099 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())+ttof[i];
1100 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())+ttof[i];
1101 }
1102 }
1103
1104 if(t0forward_trk<-3 || t0backward_trk<-3 || fabs(t0forward_trk-t0backward_trk)>15.0) continue;
1105 if(!
m_TofOpt&&nmatch_barrel!=0 && fabs((t0forward_trk+t0backward_trk)/2-(t0backward_add+t0forward_add)/2/nmatch_barrel)>11)
continue;
1106 if(
m_debug == 4) cout<<
"t0forward_trk, t0backward_trk: "<<t0forward_trk<<
" , "<<t0backward_trk<<endl;
1108 g_t0for[nmatch1] = t0forward_trk ;
1109 g_t0back[nmatch2] = t0backward_trk ;
1110 g_meantdc=(ftdc+btdc)/2;
1111 if(tofid<44) g_ntofup1++;
1112 else g_ntofdown1++;
1113 }
1114 t0forward_add += t0forward_trk;
1115 t0backward_add += t0backward_trk;
1116 if(nmatch>499) break;
1117 meantev[nmatch]=(backevtime+forevtime)/2;
1118 Tof_t0Arr[nmatch]=(t0forward_trk+t0backward_trk)/2.0;
1119 nmatch++;
1120 nmatch1=nmatch1+1;
1121 nmatch2=nmatch2+1;
1122 nmatch_barrel++;
1123 }
1124 }
1125 }
1126 }
1127 }
1128 }
1129 }
1130 if(nmatch_barrel) tof_flag=2;
1131 }
1132
1133 if(ntot==0 || nmatch_barrel==0) {
1134 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
1135 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
1136 barrelid=(*iter2)->barrel();
1137 if((*iter2)->barrel()==0) continue;
1138 if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times()==1 ) {
1139 tofid = (*iter2)->tofId();
1140 layerid = (*iter2)->layer();
1141 if(layerid==1) tofid=tofid-88;
1142 log<< MSG::INFO
1143 <<" TofId = "<<tofid
1144 <<" barrelid = "<<barrelid
1145 <<" layerid = "<<layerid
1146 <<" ForwordADC = "<<(*iter2)->adc1()
1147 <<" ForwordTDC = "<<(*iter2)->tdc1()
1148 <<endreq;
1149 double ftdc= (*iter2)->tdc1();
1150 double btdc= (*iter2)->tdc2();
1151 double fadc= (*iter2)->adc1();
1152 double badc= (*iter2)->adc2();
1153 if(
m_debug==4) cout<<
"barrel 3 ::layer, barrel, tofid, ftdc, btdc: "<<layerid<<
" , "<<barrelid<<
" , "<<tofid<<
" , "<<ftdc<<
" , "<<btdc<<endl;
1154 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
1155 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
1156 for(int i=0; i<2; i++){
1157 if(tofid_emc[i] == tofid || tofid_emc[i] == idptof || tofid_emc[i] == idntof){
1158 if(zemc_rec[0]||zemc_rec[1]){
1159 if(tofid ==tofid_emc[i] || tofid_emc[i]==idntof || tofid_emc[i]==idptof){
1160 if(ftdc>2000.|| module[i]!=1) continue;
1161 ttof[i]= sqrt(
ELMAS2/(
m_ebeam*
m_ebeam)+1)* sqrt(xemc_rec[i]*xemc_rec[i]+yemc_rec[i]*yemc_rec[i]+zemc_rec[i]*zemc_rec[i])/
VLIGHT;
1162 if(optCosmic==1 && tofid<44){
1163 backevtime = -ttof[i] + (115 + zemc_rec[i])*0.0566 + 12.;
1164 forevtime = -ttof[i] + (115 - zemc_rec[i])*0.0566 + 12.;
1165 meantevup[ntofup]=(backevtime+forevtime)/2;
1166 ntofup++;
1167 }
1168 else{
1169 backevtime = ttof[i] + (115 + zemc_rec[i])*0.0566 + 12.;
1170 forevtime = ttof[i] + (115 - zemc_rec[i])*0.0566 + 12.;
1171 meantevdown[ntofdown]=(backevtime+forevtime)/2;
1172 ntofdown++;
1173 }
1174 if( (*iter2)->adc1()<0.0 || (*iter2)->adc2()<0.0 || m_userawtime){
1175 t0forward_trk=ftdc-forevtime;
1176 t0backward_trk=btdc-backevtime;
1177 }
1178 else{
1179 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
1180 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
1181 if (optCosmic && tofid<44) {
1182 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())+ttof[i];
1183 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())+ttof[i];
1184 }
1185 }
1186
1187 if(t0forward_trk<-1 || t0backward_trk<-1 || fabs(t0forward_trk-t0backward_trk)>15.0) continue;
1188 if(!
m_TofOpt&&nmatch_barrel!=0 && fabs((t0forward_trk+t0backward_trk)/2-(t0backward_add+t0forward_add)/2/nmatch_barrel)>11)
continue;
1189 if(
m_debug == 4) cout<<
"t0forward_trk, t0backward_trk: "<<t0forward_trk<<
" , "<<t0backward_trk<<endl;
1190 t0forward_add += t0forward_trk;
1191 t0backward_add += t0backward_trk;
1192 if(nmatch>499) break;
1193 meantev[nmatch]=(backevtime+forevtime)/2;
1194 Tof_t0Arr[nmatch]=(t0forward_trk+t0backward_trk)/2.0;
1195 nmatch++;
1196 nmatch_barrel++;
1197 emcflag1=1;
1198 }
1199 }
1200 }
1201 }
1202 }
1203 }
1204 if(nmatch_barrel) tof_flag=3;
1205 }
1206
1207 if( nmatch_barrel != 0 ) {
1208 t0forward = t0forward_add/nmatch_barrel;
1209 t0backward = t0backward_add/nmatch_barrel;
1210 if(optCosmic==0){
1212 {
1214 }
1216 if(t_Est<0) t_Est=0;
1217 if(tof_flag==1) tEstFlag=111;
1218 else if(tof_flag==2) tEstFlag=121;
1219 else if(tof_flag==3) tEstFlag=131;
1220 }
1221 if(optCosmic){
1222 t_Est=(t0forward+t0backward)/2;
1223 if(tof_flag==1) tEstFlag=211;
1224 else if(tof_flag==2) tEstFlag=221;
1225 else if(tof_flag==3) tEstFlag=231;
1226 }
1227 if(
m_ntupleflag && m_tuple2) g_meant0=(t0forward+t0backward)/2;
1228 }
1229
1230
1231 digiId = 0;
1232 t0forward_add = 0;
1233 t0backward_add = 0;
1234
1235 if(nmatch_barrel==0){
1236 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
1237 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
1238 barrelid=(*iter2)->barrel();
1239 if((*iter2)->barrel()==0) continue;
1240 if(((*iter2)->quality() & 0x5) ==0x4){
1241 tofid = (*iter2)->tofId();
1242 layerid = (*iter2)->layer();
1243 if(layerid==1) tofid=tofid-88;
1244 log<< MSG::INFO
1245 <<" TofId = "<<tofid
1246 <<" barrelid = "<<barrelid
1247 <<" layerid = "<<layerid
1248 <<" ForwordADC = "<<(*iter2)->adc1()
1249 <<" ForwordTDC = "<<(*iter2)->tdc1()
1250 <<endreq;
1251
1252 double ftdc= (*iter2)->tdc1();
1253 double fadc= (*iter2)->adc1();
1254 if(
m_debug==4) cout<<
"barrel 4 ::layer, barrel, tofid, ftdc: "<<layerid<<
" , "<<barrelid<<
" , "<<tofid<<
" , "<<ftdc<<endl;
1255 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
1256 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
1257 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
1258 for(int i=0;i<ntot;i++){
1259 if(ttof[i]!=0 && ftdc>0){
1260 if(tofid_helix[i] == tofid ||(tofid_helix[i] == idptof) || (tofid_helix[i] == idntof)){
1261 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
1262 if (optCosmic && tofid<44) {
1263 forevtime = -ttof[i] + (115 - helztof[i])*0.0566 + 12.;
1264 meantevup[ntofup]=forevtime;
1265 ntofup++;
1266 }
1267 else{
1268 forevtime = ttof[i] + (115 - helztof[i])*0.0566 + 12.;
1269 meantevdown[ntofdown]=forevtime;
1270 ntofdown++;
1271 }
1272 if( (*iter2)->adc1()<0.0 || m_userawtime){
1273 t0forward_trk = ftdc - forevtime ;
1274 }
1275 else{
1276 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
1277 }
1278
1279 if(t0forward_trk<-1) continue;
1280 if(!
m_TofOpt&&nmatch_barrel_1!=0 && fabs((t0forward_trk)-(t0forward_add)/nmatch_barrel_1)>11)
continue;
1281 if(
m_debug == 4) cout<<
"t0forward_trk: "<<t0forward_trk<<endl;
1283 g_t0for[nmatch1] = t0forward_trk ;
1284 g_meantdc=ftdc;
1285 if(tofid<44) g_ntofup1++;
1286 else g_ntofdown1++;
1287 }
1288 t0forward_add += t0forward_trk;
1289
1290 if(nmatch>499) break;
1291 meantev[nmatch]=forevtime;
1292 Tof_t0Arr[nmatch]=t0forward_trk;
1293 nmatch++;
1294 nmatch1++;
1295 nmatch_barrel_1++;
1296 }
1297 }
1298 }
1299 }
1300 }
1301 }
1302 else if(((*iter2)->quality() & 0x5) ==0x1){
1303 tofid = (*iter2)->tofId();
1304 layerid = (*iter2)->layer();
1305 if(layerid==1) tofid=tofid-88;
1306 log<< MSG::INFO
1307 <<" TofId = "<<tofid
1308 <<" barrelid = "<<barrelid
1309 <<" layerid = "<<layerid
1310 <<" BackwordADC = "<<(*iter2)->adc2()
1311 <<" BackwordTDC = "<<(*iter2)->tdc2()
1312 << endreq;
1313
1314 double btdc= (*iter2)->tdc2();
1315 if(
m_debug==4) cout<<
"barrel 5 ::layer, barrel, tofid, btdc: "<<layerid<<
" , "<<barrelid<<
" , "<<tofid<<
" , "<<btdc<<endl;
1316 double badc= (*iter2)->adc2();
1317 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
1318 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
1319 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
1320 for(int i=0;i<ntot;i++){
1321 if(ttof[i]!=0 && btdc>0){
1322 if((tofid_helix[i] == tofid) || (tofid_helix[i] == idntof) ||(tofid_helix[i] == idptof)){
1323 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
1324 if (optCosmic && tofid<44) {
1325 backevtime = -ttof[i] + (115 + helztof[i])*0.0566 + 12.;
1326 meantevup[ntofup]=backevtime;
1327 ntofup++;
1328 }
1329 else{
1330 backevtime = ttof[i] + (115 + helztof[i])*0.0566 + 12.;
1331 meantevdown[ntofdown]=backevtime;
1332 ntofdown++;
1333 }
1334
1335 if( (*iter2)->adc2()<0.0 || m_userawtime){
1336 t0backward_trk = btdc - backevtime ;
1337 }
1338 else{
1339 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
1340 }
1341
1342 if(t0backward_trk<-1) continue;
1343 if(!
m_TofOpt&&nmatch_barrel_2!=0 && fabs((t0backward_trk)-(t0backward_add)/nmatch_barrel_2)>11)
continue;
1344 if(
m_debug == 4) cout<<
"t0backward_trk: "<<t0backward_trk<<endl;
1346 g_t0back[nmatch2] = t0backward_trk ;
1347 g_meantdc=btdc;
1348 if(tofid<44) g_ntofup1++;
1349 else g_ntofdown1++;
1350 }
1351 t0backward_add += t0backward_trk;
1352 if(nmatch>499) break;
1353 meantev[nmatch]=backevtime;
1354 Tof_t0Arr[nmatch]=t0backward_trk;
1355 nmatch++;
1356 nmatch2++;
1357 nmatch_barrel_2++;
1358 }
1359 }
1360 }
1361 }
1362 }
1363 }
1364 }
1365 }
1366 if(nmatch_barrel_1 != 0 ){
1367 t0forward = t0forward_add/nmatch_barrel_1;
1368 if(optCosmic==0){
1370 {
1372 }
1374 if(t_Est<0) t_Est=0;
1375 tEstFlag=141;
1376 }
1377 else{
1378 t_Est=t0forward;
1379 tEstFlag=241;
1380 }
1382 }
1383 if(nmatch_barrel_2 != 0 ){
1384 t0backward = t0backward_add/nmatch_barrel_2;
1385 if(optCosmic==0){
1387 {
1389 }
1391 if(t_Est<0) t_Est=0;
1392 tEstFlag=141;
1393 }
1394 else{
1395 t_Est=t0backward;
1396 tEstFlag=241;
1397 }
1399 }
1400
1401 digiId = 0;
1402 t0forward_add = 0;
1403 t0backward_add = 0;
1404 if(nmatch_barrel==0){
1405 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
1406 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
1407 barrelid=(*iter2)->barrel();
1408 if((*iter2)->barrel()!=0) continue;
1409 if((*iter2)->times()!=1) continue;
1410 tofid = (*iter2)->tofId();
1411
1412 if( !( (*iter2)->is_mrpc() ) ) {
1413 if( tofid<48 ) { barrelid=0; }
1414 if( tofid>47 ) { barrelid=2; }
1415 if( barrelid==2 ) { tofid=tofid-48; }
1416 }
1417
1418 else if( (*iter2)->is_mrpc() ) {
1421 if( barrelid==2 ) { tofid=tofid-36; }
1422 }
1423
1424 log<< MSG::INFO
1425 <<" is_mrpc = " << (*iter2)->is_mrpc()
1426 <<" TofId = "<< tofid
1427 <<" barrelid = "<< barrelid
1428 <<endreq
1429 <<" ForwordADC = "<< (*iter2)->adc()
1430 <<" ForwordTDC = "<< (*iter2)->tdc()
1431 << endreq;
1432 double ftdc= (*iter2)->tdc();
1433 double fadc= (*iter2)->adc();
1434 if(
m_debug ==4) cout<<
"endcap::single hit,barrelid,tofid,tdc: "<<barrelid<<
" , "<<tofid<<
" , "<<ftdc<<endl;
1435
1436
1437 if( !( (*iter2)->is_mrpc() ) && useEtofScin ) {
1438 int idptof = ((tofid-1) == -1) ? 47 : tofid-1;
1439 int idntof = ((tofid+1) == 48) ? 0 : tofid+1;
1440
1441 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
1442 for(int i=0;i<ntot;i++){
1443 if(ttof[i]!=0 && ftdc>0 && ftdc<2000.){
1444 if((tofid_helix[i] == tofid) ||(tofid_helix[i] == idntof) ||(tofid_helix[i] == idptof)){
1445 if( barrelid==0 || barrelid==2 ){
1446 if( r_endtof[i]>=41 && r_endtof[i]<=90 ) {
1447 if( optCosmic && ( tofid<24 || ( tofid>48 && tofid<71 ) ) ) {
1448 forevtime = -ttof[i] + r_endtof[i]*0.09 + 12.2;
1449 meantevup[ntofup] = forevtime;
1450 ntofup++;
1451 }
1452 else {
1453 forevtime = ttof[i] + r_endtof[i]*0.09 + 12.2;
1454 meantevdown[ntofdown] = forevtime;
1455 ntofdown++;
1456 }
1457 if( (*iter2)->adc()<0.0 || m_userawtime){
1458 t0forward_trk = ftdc - forevtime;
1459 }
1460 else{
1461 t0forward_trk = tofCaliSvc->
ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
1462 }
1463
1464 if(t0forward_trk<-1.) continue;
1465 if( !
m_TofOpt && nmatch_end!=0 && fabs( t0forward_trk - t0forward_add/nmatch_end)>9 )
continue;
1466 t0forward_add += t0forward_trk;
1467 if(nmatch>499) break;
1468 Tof_t0Arr[nmatch]=t0forward_trk;
1469 meantev[nmatch]=forevtime/2;
1470 nmatch++;
1471 nmatch_end++;
1472 }
1473 }
1474 }
1475 if(
m_debug==4 ) { cout <<
"t0forward_trk:" << t0forward_trk << endl; }
1476 }
1477 }
1478 }
1479 }
1480
1481 if( (*iter2)->is_mrpc() && useEtofMRPC ) {
1482 if( ((*iter2)->quality() & 0x5)!=0x5 ) continue;
1483 double btdc= (*iter2)->tdc2();
1484 double badc= (*iter2)->adc2();
1485 int idptof = ((tofid-1) == -1) ? 35 : tofid-1;
1486 int idntof = ((tofid+1) == 36) ? 0 : tofid+1;
1487
1488 if( idetfmatch[barrelid][tofid]==1 || idetfmatch[barrelid][idptof]==1 || idetfmatch[barrelid][idntof]==1 ) {
1489 for( int i=0; i<ntot; i++ ) {
1490 if( tetf[i]!=0 && ftdc>0 && ftdc<2000.) {
1491 if( etfid_helix[i]==tofid || etfid_helix[i]==idntof || etfid_helix[i] == idptof ) {
1492 if( barrelid==0 || barrelid==2 ) {
1493 if( r_endetf[i]>=41 && r_endetf[i]<=90 ) {
1494 if( optCosmic && ( tofid<18 || ( tofid>35 && tofid<54 ) ) ) {
1495 forevtime = -tetf[i] + 17.7;
1496 meantevup[ntofup] = forevtime;
1497 ntofup++;
1498 }
1499 else {
1500 forevtime = tetf[i] + 17.7;
1501 meantevdown[ntofdown] = forevtime;
1502 ntofdown++;
1503 }
1504 if( m_userawtime ) {
1505 double fbtdc = ( ftdc + btdc )/2.0;
1506 if( ftdc>0 && btdc<0 ) { fbtdc = ftdc; }
1507 else if( ftdc<0 && btdc>0 ) { fbtdc = btdc; }
1508 else if( ftdc<0 && btdc<0 ) continue;
1509 t0forward_trk = fbtdc - forevtime;
1510 }
1511 else {
1512 t0forward_trk = tofCaliSvc->
EtfTime( (*iter2)->tdc1(), (*iter2)->tdc2(), (*iter2)->tofId(), (*iter2)->strip() )-tetf[i];
1513 }
1514
1515 if( t0forward_trk<-1 ) continue;
1516 if(
m_TofOpt && nmatch_end!=0 && fabs(t0forward_trk-t0forward_add/nmatch_end)>9 )
continue;
1517 if(
m_debug == 4 ) { cout <<
"t0forward_trk:" << t0forward_trk << endl; }
1518 t0forward_add += t0forward_trk;
1519 if(nmatch>499) break;
1520 Tof_t0Arr[nmatch] = t0forward_trk;
1521 meantev[nmatch] = forevtime;
1522 nmatch++;
1523 nmatch_end++;
1524 }
1525 }
1526 }
1527 }
1528 }
1529 }
1530 }
1531 }
1532 if( nmatch_end ) { tof_flag=5; }
1533 }
1534
1535 if( nmatch_barrel==0 && nmatch_end==0 ) {
1536 for( TofDataVector::iterator iter2 = tofDigiVec.begin(); iter2 != tofDigiVec.end(); iter2++, digiId++ ) {
1537 barrelid=(*iter2)->barrel();
1538 if( (*iter2)->barrel()!=0 ) continue;
1539 if( (*iter2)->times()!=1 ) continue;
1540 tofid = (*iter2)->tofId();
1541
1542 if( !( (*iter2)->is_mrpc() ) ) {
1543 if( tofid<48 ) { barrelid=0; }
1544 if( tofid>47 ) { barrelid=2; }
1545 if( barrelid==2 ) { tofid=tofid-48; }
1546 }
1547
1548 else if( (*iter2)->is_mrpc() ) {
1551 if( barrelid==2 ) { tofid=tofid-36; }
1552 }
1553
1554 log<< MSG::INFO
1555 <<" is_mrpc = " << (*iter2)->is_mrpc()
1556 <<" TofId = "<< tofid
1557 <<" barrelid = "<< barrelid
1558 <<endreq
1559 <<" ForwordADC = "<< (*iter2)->adc()
1560 <<" ForwordTDC = "<< (*iter2)->tdc()
1561 << endreq;
1562 double ftdc= (*iter2)->tdc();
1563 double fadc= (*iter2)->adc();
1564 if(
m_debug ==4) cout<<
"endcap::single hit,barrelid,tofid,tdc: "<<barrelid<<
" , "<<tofid<<
" , "<<ftdc<<endl;
1565
1566
1567 if( !( (*iter2)->is_mrpc() ) && useEtofScin ) {
1568 int idptof = ((tofid-1) == -1) ? 47 : tofid-1;
1569 int idntof = ((tofid+1) == 48) ? 0 : tofid+1;
1570 for( int i=0; i<2; i++ ) {
1571 if( zemc_rec[0] || zemc_rec[1] ) {
1572 if( tofid==tofid_emc[i] || tofid_emc[i]==idntof || tofid_emc[i]==idptof ) {
1573 if( ftdc>2000. || module[i]==1 ) continue;
1575 r_endtof[i]=sqrt(xemc_rec[i]*xemc_rec[i]+yemc_rec[i]*yemc_rec[i]);
1576 if( optCosmic && ( tofid<24 || ( tofid>48 && tofid<71 ) ) ) {
1577 forevtime = -ttof[i] + r_endtof[i]*0.09 + 12.2;
1578 meantevup[ntofup] = forevtime;
1579 ntofup++;
1580 }
1581 else {
1582 forevtime = ttof[i] + r_endtof[i]*0.09 + 12.2;
1583 meantevdown[ntofdown] = forevtime;
1584 ntofdown++;
1585 }
1586 if( (*iter2)->adc()<0.0 || m_userawtime){
1587 t0forward_trk = ftdc - forevtime;
1588 }
1589 else{
1590 t0forward_trk = tofCaliSvc->
ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
1591 if(
m_debug ==4) cout<<
"emc flag t0forward_trk: "<<t0forward_trk<<endl;
1592 }
1593
1594 if( t0forward_trk<-1.) continue;
1595 if( !
m_TofOpt && nmatch_end!=0 && fabs( t0forward_trk - t0forward_add/nmatch_end)>9 )
continue;
1596 t0forward_add += t0forward_trk;
1597 if(nmatch>499) break;
1598 meantev[nmatch] = forevtime;
1599 Tof_t0Arr[nmatch] = t0forward_trk;
1600 nmatch++;
1601 nmatch_end++;
1602 emcflag2=1;
1603 }
1604 }
1605 }
1606 }
1607
1608 if( (*iter2)->is_mrpc() && useEtofMRPC ) {
1609 double btdc= (*iter2)->tdc2();
1610 double badc= (*iter2)->adc2();
1611 int idptof = ((tofid-1) == -1) ? 35 : tofid-1;
1612 int idntof = ((tofid+1) == 36) ? 0 : tofid+1;
1613 for( int i=0; i<2; i++ ) {
1614 if( zemc_rec[0] || zemc_rec[1] ) {
1615 if( tofid==etfid_emc[i] || etfid_emc[i]==idntof || etfid_emc[i]==idptof ) {
1616
1617 if( ftdc>2000.|| module[i]==1 ) continue;
1619 r_endetf[i] = sqrt(xemc_rec[i]*xemc_rec[i]+yemc_rec[i]*yemc_rec[i]);
1620 if( optCosmic && ( tofid<18 || ( tofid>35 && tofid<54 ) ) ) {
1621 forevtime = -tetf[i] + 17.7;
1622 meantevup[ntofup] = forevtime;
1623 ntofup++;
1624 }
1625 else {
1626 forevtime = tetf[i] + 17.7;
1627 meantevdown[ntofdown] = forevtime;
1628 ntofdown++;
1629 }
1630
1631 if( m_userawtime ) {
1632 double fbtdc = ( ftdc + btdc )/2.0;
1633 if( ftdc>0 && btdc<0 ) { fbtdc = ftdc; }
1634 else if( ftdc<0 && btdc>0 ) { fbtdc = btdc; }
1635 else if( ftdc<0 && btdc<0 ) continue;
1636 t0forward_trk = fbtdc - forevtime;
1637 }
1638 else {
1639 t0forward_trk = tofCaliSvc->
EtfTime( (*iter2)->tdc1(), (*iter2)->tdc2(), (*iter2)->tofId(), (*iter2)->strip() )-tetf[i];
1640 }
1641
1642 if( t0forward_trk<-1 ) continue;
1643 if( !
m_TofOpt && nmatch_end!=0 && fabs( t0forward_trk - t0forward_add/nmatch_end)>9 )
continue;
1644 if(
m_debug==4 ) { cout <<
"t0forward_trk:" << t0forward_trk << endl; }
1645 t0forward_add += t0forward_trk;
1646 if(nmatch>499) break;
1647 Tof_t0Arr[nmatch]=t0forward_trk;
1648 nmatch++;
1649 nmatch_end++;
1650 emcflag2=1;
1651 }
1652 }
1653 }
1654 }
1655 }
1656 if( nmatch_end ) { tof_flag=5; }
1657 }
1658
1659 if( nmatch_barrel==0 && nmatch_end==0 ) {
1660 for( TofDataVector::iterator iter2 = tofDigiVec.begin(); iter2 != tofDigiVec.end(); iter2++, digiId++ ) {
1661 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
1662 barrelid = (*iter2)->barrel();
1663 if( (*iter2)->barrel()!=0 ) continue;
1664 if( (*iter2)->times()>1 && (*iter2)->times()<5 ) {
1665 tofid = (*iter2)->tofId();
1666
1667 if( !( (*iter2)->is_mrpc() ) ) {
1668 if( tofid<48 ) { barrelid=0; }
1669 if( tofid>47 ) { barrelid=2; }
1670 if( barrelid==2 ) { tofid=tofid-48; }
1671 }
1672
1673 else if( (*iter2)->is_mrpc() ) {
1676 if( barrelid==2 ) { tofid=tofid-36; }
1677 }
1678 log<< MSG::INFO
1679 <<" TofId = "<<tofid
1680 <<" barrelid = "<<barrelid
1681 <<endreq
1682 <<" ForwordADC = "<< (*iter2)->adc()
1683 <<" ForwordTDC = "<< (*iter2)->tdc()
1684 << endreq;
1685 double ftdc = (*iter2)->tdc();
1686 double fadc = (*iter2)->adc();
1687 if(
m_debug==4 ) { cout <<
"endcap::multi hit,barrelid,tofid,tdc: " << barrelid <<
" , " << tofid <<
" , " << ftdc << endl; }
1688
1689
1690 if( !( (*iter2)->is_mrpc() ) && useEtofScin ) {
1691 int idptof = ((tofid-1) == -1) ? 47 : tofid-1;
1692 int idntof = ((tofid+1) == 48) ? 0 : tofid+1;
1693
1694 if( idmatch[barrelid][tofid]==1 || idmatch[barrelid][idptof]==1 || idmatch[barrelid][idntof]==1 ) {
1695 for( int i=0; i<ntot; i++ ) {
1696 if( ttof[i]!=0 && ftdc>0 ) {
1697 if( (tofid_helix[i]==tofid) || (tofid_helix[i]==idntof) || (tofid_helix[i]==idptof) ) {
1698 if( barrelid==0 || barrelid==2 ) {
1699 if( r_endtof[i]>=41 && r_endtof[i]<=90 ) {
1700 if( optCosmic && ( tofid<24 || ( tofid>48 && tofid<71 ) ) ) {
1701 forevtime = -ttof[i] + r_endtof[i]*0.09 + 12.2;
1702 meantevup[ntofup]=forevtime;
1703 ntofup++;
1704 }
1705 else{
1706 forevtime = ttof[i] + r_endtof[i]*0.09 + 12.2;
1707 meantevdown[ntofdown]=forevtime;
1708 ntofdown++;
1709 }
1710 if( (*iter2)->adc()<0.0 || m_userawtime){
1711 t0forward_trk=ftdc-forevtime;
1712 }
1713 else{
1714 t0forward_trk = tofCaliSvc->
ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
1715 }
1716
1717 if( t0forward_trk<-1.) continue;
1718 if( !
m_TofOpt && nmatch_end!=0 && fabs( t0forward_trk - t0forward_add/nmatch_end)>9 )
continue;
1719 t0forward_add += t0forward_trk;
1720 if( nmatch>499 ) break;
1721 meantev[nmatch] = forevtime;
1722 Tof_t0Arr[nmatch] = t0forward_trk;
1723 nmatch++;
1724 nmatch_end++;
1725 }
1726 }
1727 if(
m_debug==4 ) { cout <<
"t0forward_trk:" << t0forward_trk << endl; }
1728 }
1729 }
1730 }
1731 }
1732 }
1733
1734 if( (*iter2)->is_mrpc() && useEtofMRPC ) {
1735 double btdc= (*iter2)->tdc2();
1736 double badc= (*iter2)->adc2();
1737 int idptof = ((tofid-1) == -1) ? 35 : tofid-1;
1738 int idntof = ((tofid+1) == 36) ? 0 : tofid+1;
1739
1740 if( idetfmatch[barrelid][tofid]==1 || idetfmatch[barrelid][idptof]==1 || idetfmatch[barrelid][idntof]==1 ) {
1741 for( int i=0; i<ntot; i++ ) {
1742 if( tetf[i]!=0 && ftdc>0 && ftdc<2000.) {
1743 if( etfid_helix[i]==tofid || etfid_helix[i]==idntof || etfid_helix[i] == idptof ) {
1744 if( barrelid==0 || barrelid==2 ) {
1745 if( r_endetf[i]>=41 && r_endetf[i]<=90 ) {
1746 if( optCosmic && ( tofid<18 || ( tofid>35 && tofid<54 ) ) ) {
1747 forevtime = -tetf[i] + 17.7;
1748 meantevup[ntofup] = forevtime;
1749 ntofup++;
1750 }
1751 else {
1752 forevtime = tetf[i] + 17.7;
1753 meantevdown[ntofdown] = forevtime;
1754 ntofdown++;
1755 }
1756 if( m_userawtime ) {
1757 double fbtdc = ( ftdc + btdc )/2.0;
1758 if( ftdc>0 && btdc<0 ) { fbtdc = ftdc; }
1759 else if( ftdc<0 && btdc>0 ) { fbtdc = btdc; }
1760 else if( ftdc<0 && btdc<0 ) continue;
1761 t0forward_trk = fbtdc - forevtime;
1762 }
1763 else {
1764 t0forward_trk = tofCaliSvc->
EtfTime( (*iter2)->tdc1(), (*iter2)->tdc2(), (*iter2)->tofId(), (*iter2)->strip() )-tetf[i];
1765 }
1766
1767 if( t0forward_trk<-1 ) continue;
1768 if( !
m_TofOpt && nmatch_end!=0 && fabs( t0forward_trk - t0forward_add/nmatch_end )>9 )
continue;
1769 if(
m_debug == 4 ) { cout <<
"t0forward_trk:" << t0forward_trk << endl; }
1770 t0forward_add += t0forward_trk;
1771 if(nmatch>499) break;
1772 Tof_t0Arr[nmatch] = t0forward_trk;
1773 meantev[nmatch] = forevtime;
1774 nmatch++;
1775 nmatch_end++;
1776 }
1777 }
1778 }
1779 }
1780 }
1781 }
1782 }
1783 }
1784 }
1785 if( nmatch_end ) { tof_flag=7; }
1786 }
1787
1789 g_nmatchbarrel = nmatch_barrel;
1790 g_nmatchbarrel_1 = nmatch_barrel_1;
1791 g_nmatchbarrel_2 = nmatch_barrel_2;
1792 g_nmatchend = nmatch_end;
1793 }
1794
1795 if( nmatch_end !=0 ) {
1796 t0forward = t0forward_add/nmatch_end;
1797 if( optCosmic==0 ) {
1800 }
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819 if(t_Est<0) t_Est=0;
1820 if(tof_flag==5) tEstFlag=151;
1821 else if(tof_flag==7) tEstFlag=171;
1822 if(emcflag2==1) tEstFlag=161;
1823
1824
1825
1826
1827
1828
1829
1830
1831 }
1832 if( optCosmic ) {
1833 t_Est=t0forward;
1834 if(tof_flag==5) tEstFlag=251;
1835 else if(tof_flag==7) tEstFlag=271;
1836 if(emcflag2==1) tEstFlag=261;
1837 }
1839 }
1840
1841 double t0_comp=-999;
1842 double T0=-999;
1843
1844 if(nmatch_barrel==0 && nmatch_end==0 &&
m_flag==1){
1845 double mhit[43][300]={0.};
1846 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc(),"/Event/Digi/MdcDigiCol");
1847 if (!mdcDigiCol) {
1848 log << MSG::INFO<< "Could not find MDC digi" << endreq;
1849 return StatusCode::FAILURE;
1850 }
1851
1853 StatusCode sc = service("MdcGeomSvc", mdcGeomSvc);
1854 if (sc != StatusCode::SUCCESS) {
1855 return StatusCode::FAILURE;
1856 }
1857
1858 MdcDigiCol::iterator iter1 = mdcDigiCol->begin();
1859 digiId = 0;
1861 int layerId;
1862 int wireId;
1863
1864 for (;iter1 != mdcDigiCol->end(); iter1++, digiId++) {
1865 mdcId = (*iter1)->identify();
1868
1870 mhit[layerId][wireId]-=1.28*(mdcGeomSvc->
Layer(layerId)->Radius())/299.8;
1871
1872 mdcGeomSvc->
Wire(layerId,wireId);
1873
1874 double tof;
1875
1876 }
1877
1878 int Iused[43][300]={0},tmp=0;
1879 bool Lpat,Lpat11,Lpat12,Lpat2,Lpat31,Lpat32;
1880 double t0_all=0,t0_mean=0;
1881 double r[4]={0.};
1882 double chi2=999.0;
1883 double phi[4]={0.},corr[4]={0.},driftt[4]={0.};
1884 double ambig=1;
1885 double mchisq=50000;
1886
1887
1888 for(int i=5;i<10;i++){
1889
1890 double T1=0.5*0.1*(mdcGeomSvc->
Layer(4*i+0)->PCSiz())/0.004;
1891 double T2=0.5*0.1*(mdcGeomSvc->
Layer(4*i+1)->PCSiz())/0.004;
1892 double T3=0.5*0.1*(mdcGeomSvc->
Layer(4*i+2)->PCSiz())/0.004;
1893 double T4=0.5*0.1*(mdcGeomSvc->
Layer(4*i+3)->PCSiz())/0.004;
1894 r[0]=(mdcGeomSvc->
Layer(4*i+0)->Radius())*0.1;
1895 r[1]=(mdcGeomSvc->
Layer(4*i+1)->Radius())*0.1;
1896 r[2]=(mdcGeomSvc->
Layer(4*i+2)->Radius())*0.1;
1897 r[3]=(mdcGeomSvc->
Layer(4*i+3)->Radius())*0.1;
1898 double r0=r[0]-r[1]-(r[2]-r[1])/2;
1899 double r1=-(r[2]-r[1])/2;
1900 double r2=(r[2]-r[1])/2;
1901 double r3=r[3]-r[2]+(r[2]-r[1])/2;
1902
1903 for(
int j=0;j<mdcGeomSvc->
Layer(i*4+3)->NCell();j++){
1904
1905 int Icp=0;
1906 Icp=j-1;
1907 if(Icp<0) Icp=mdcGeomSvc->
Layer(i*4+3)->
NCell();
1908
1909 Lpat=(mhit[4*i][j]!=0) && (mhit[4*i][Icp]==0) &&( mhit[4*i][j+1]==0) && (Iused[4*i][j]==0);
1910 if(Lpat){
1911 Lpat11=(mhit[4*i+1][Icp]==0)&&(Iused[4*i+1][j]==0)&&(mhit[4*i+1][j]!=0)&&(mhit[4*i+1][j+1]==0);
1912 Lpat12=(mhit[4*i+1][j]==0)&&(Iused[4*i+1][j+1]==0)&&(mhit[4*i+1][j+1]!=0)&&(mhit[4*i+1][j+2]==0);
1913 Lpat2=(mhit[4*i+2][Icp]==0)&&(Iused[4*i+2][j]==0)&&(mhit[4*i+2][j]!=0)&&(mhit[4*i+2][j+1]==0);
1914 Lpat31=(mhit[4*i+3][Icp]==0)&&(Iused[4*i+3][j]==0)&&(mhit[4*i+3][j]!=0)&&(mhit[4*i+3][j+1]==0);
1915 Lpat32=(mhit[4*i+3][j]==0)&&(Iused[4*i+3][j+1]==0)&&(mhit[4*i+3][j+1]!=0)&&(mhit[4*i+3][j+2]==0);
1916
1917 if(Lpat11 && Lpat2 && Lpat31 ){
1918
1919 Iused[4*i+0][j]=1;
1920 Iused[4*i+1][j]=1;
1921 Iused[4*i+2][j]=1;
1922 Iused[4*i+3][j]=1;
1923 double t_i = mhit[4*i+0][j]+mhit[4*i+2][j];
1924 double t_j = mhit[4*i+1][j]+mhit[4*i+3][j];
1925 double l_j = T2+T4;
1926 double r_i = r0+r2;
1927 double r_j = r1+r3;
1928 double r_2k= r0*r0+r1*r1+r2*r2+r3*r3;
1929 double rt_i = r0*mhit[4*i+0][j]+r2*mhit[4*i+2][j];
1930 double rt_j = r1*mhit[4*i+1][j]+r3*mhit[4*i+3][j];
1931 double rl_j = r1*T2+r3*T4;
1932
1933 double deno= 4*r_2k-2*(r_i*r_i+r_j*r_j);
1934
1935 if (deno!=0){
1936 double Pa=(4*(rt_i-rt_j+rl_j)-(t_i+t_j-l_j)*(r_i-r_j)-(t_i-t_j+l_j)*(r_i+r_j))/deno;
1937 double Pb= 0.25*(t_i-t_j+l_j-(r_i+r_j) * Pa);
1938 double Ang=fabs(90.-fabs(atan(Pa)*180./3.141593));
1939
1940 t0_all+= (-0.25*((r_i-r_j)*Pa-t_i-t_j+l_j));
1941
1942 double chi2_tmp;
1943 for(int t0c=0;t0c<17;t0c+=8){
1944 chi2_tmp=(mhit[4*i+0][j]-t0c-r0 * Pa-Pb)*(mhit[4*i+0][j]-t0c-r0 * Pa-Pb)+(T2-mhit[4*i+1][j]+t0c-r1 * Pa-Pb)*(T2-mhit[4*i+1][j]+t0c-r1 * Pa-Pb)+(mhit[4*i+2][j]-t0c-r2 * Pa-Pb)*(mhit[4*i+2][j]-t0c-r2 * Pa-Pb) + (T4-mhit[4*i+3][j]+t0c-r3 * Pa-Pb)*(T4-mhit[4*i+3][j]+t0c-r3 * Pa-Pb);
1945 if(chi2_tmp<chi2){
1946 chi2=chi2_tmp;
1947 t0_comp=t0c;
1948 }
1949 }
1950 tmp+=1;
1951 }
1952
1953
1954 for(int tmpT0=0;tmpT0<17;tmpT0+=8){
1955 driftt[0]=mhit[4*i+0][j]-tmpT0;
1956 driftt[1]=mhit[4*i+1][j]-tmpT0;
1957 driftt[2]=mhit[4*i+2][j]-tmpT0;
1958 driftt[3]=mhit[4*i+3][j]-tmpT0;
1959
1960 phi[0]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4)->NCell())+2*3.14159265/(mdcGeomSvc->
Layer(i*4+1)->NCell())/2;
1961 phi[1]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4+1)->NCell());
1962 phi[2]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4+2)->NCell())+2*3.14159265/(mdcGeomSvc->
Layer(i*4+1)->NCell())/2;
1963 phi[3]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4+3)->NCell());
1964 phi[0]-=ambig*driftt[0]*0.004/r[0];
1965 phi[1]+=ambig*driftt[1]*0.004/r[1];
1966 phi[2]-=ambig*driftt[2]*0.004/r[2];
1967 phi[3]+=ambig*driftt[3]*0.004/r[3];
1968 double s1, sx, sy, sxx, sxy;
1969 double delinv, denom;
1978 s1 = sx = sy = sxx = sxy = 0.0;
1979 double chisq = 0.0;
1980 for (int ihit = 0; ihit < 4; ihit++) {
1984 sy += phi[ihit] *
weight;
1985 sxx +=
x[ihit] * (
x[ihit] *
weight);
1986 sxy += phi[ihit] * (
x[ihit] *
weight);
1987 }
1988 double resid[4]={0.};
1989
1990 denom = s1 * sxx - sx * sx;
1991 delinv = (denom == 0.0) ? 1.e20 : 1. / denom;
1992 double intercept = (sy * sxx - sx * sxy) * delinv;
1993 double slope = (s1 * sxy - sx * sy) * delinv;
1994
1995
1996 for (int ihit = 0; ihit < 4; ihit++) {
1997 resid[ihit] = ( phi[ihit] - intercept -
slope *
x[ihit] );
1998 chisq += resid[ihit] * resid[ihit]/(
sigma*
sigma) ;
1999 }
2000 if(chisq<mchisq){
2001 mchisq=chisq;
2002 T0=tmpT0;
2003 }
2004 }
2005 }
2006 if(Lpat12 && Lpat2 && Lpat32){
2007 Iused[4*i+0][j]=1;
2008 Iused[4*i+1][j+1]=1;
2009 Iused[4*i+2][j]=1;
2010 Iused[4*i+3][j+1]=1;
2011
2012 double t_i = mhit[4*i+0][j]+mhit[4*i+2][j];
2013 double t_j = mhit[4*i+1][j+1]+mhit[4*i+3][j+1];
2014 double l_j = T2+T4;
2015 double r_i = r0+r2;
2016 double r_j = r1+r3;
2017 double r_2k= r0*r0+r1*r1+r2*r2+r3*r3;
2018 double rt_i = r0*mhit[4*i+0][j]+r2*mhit[4*i+2][j];
2019 double rt_j = r1*mhit[4*i+1][j+1]+r3*mhit[4*i+3][j+1];
2020 double rl_j = r1*T2+r3*T4;
2021 double deno= 4*r_2k-2*(r_i*r_i+r_j*r_j);
2022
2023 if (deno!=0){
2024 double Pa=(4*(rt_i-rt_j+rl_j)-(t_i+t_j-l_j)*(r_i-r_j)-(t_i-t_j+l_j)*(r_i+r_j))/deno;
2025 double Pb= 0.25*(t_i-t_j+l_j-(r_i+r_j) * Pa);
2026 double Ang=fabs(90.-fabs(atan(Pa)*180./3.141593));
2027 t0_all+= (-0.25*((r_i-r_j)*Pa-t_i-t_j+l_j));
2028 tmp+=1;
2029 double chi2_tmp;
2030
2031 for(int t0c=0;t0c<17;t0c+=8){
2032 chi2_tmp=(mhit[4*i+0][j]-t0c-r0 * Pa-Pb)*(mhit[4*i+0][j]-t0c-r0 * Pa-Pb)+(T2-mhit[4*i+1][j+1]+t0c-r1 * Pa-Pb)*(T2-mhit[4*i+1][j+1]+t0c-r1 * Pa-Pb)+(mhit[4*i+2][j]-t0c-r2 * Pa-Pb)*(mhit[4*i+2][j]-t0c-r2 * Pa-Pb) + (T4-mhit[4*i+3][j+1]+t0c-r3 * Pa-Pb)*(T4-mhit[4*i+3][j+1]+t0c-r3 * Pa-Pb);
2033
2034 if(chi2_tmp<chi2){
2035 chi2=chi2_tmp;
2036 t0_comp=t0c;
2037 }
2038 }
2039 }
2040
2041
2042
2043 for(int tmpT0=0;tmpT0<17;tmpT0+=8){
2044 driftt[0]=mhit[4*i+0][j]-tmpT0;
2045 driftt[1]=mhit[4*i+1][j+1]-tmpT0;
2046 driftt[2]=mhit[4*i+2][j]-tmpT0;
2047 driftt[3]=mhit[4*i+3][j+1]-tmpT0;
2048
2049 phi[0]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4)->NCell())+2*3.14159265/(mdcGeomSvc->
Layer(i*4+1)->NCell())/2;
2050 phi[1]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4+1)->NCell());
2051 phi[2]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4+2)->NCell())+2*3.14159265/(mdcGeomSvc->
Layer(i*4+1)->NCell())/2;
2052 phi[3]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4+3)->NCell());
2053 phi[0]-=ambig*driftt[0]*0.004/r[0];
2054 phi[1]+=ambig*driftt[1]*0.004/r[1];
2055 phi[2]-=ambig*driftt[2]*0.004/r[2];
2056 phi[3]+=ambig*driftt[3]*0.004/r[3];
2057 double s1, sx, sy, sxx, sxy;
2058 double delinv, denom;
2067 s1 = sx = sy = sxx = sxy = 0.0;
2068 double chisq = 0.0;
2069 for (int ihit = 0; ihit < 4; ihit++) {
2073 sy += phi[ihit] *
weight;
2074 sxx +=
x[ihit] * (
x[ihit] *
weight);
2075 sxy += phi[ihit] * (
x[ihit] *
weight);
2076 }
2077 double resid[4]={0.};
2078
2079 denom = s1 * sxx - sx * sx;
2080 delinv = (denom == 0.0) ? 1.e20 : 1. / denom;
2081 double intercept = (sy * sxx - sx * sxy) * delinv;
2082 double slope = (s1 * sxy - sx * sy) * delinv;
2083
2084
2085 for (int ihit = 0; ihit < 4; ihit++) {
2086 resid[ihit] = ( phi[ihit] - intercept -
slope *
x[ihit] );
2087 chisq += resid[ihit] * resid[ihit]/(
sigma*
sigma) ;
2088 }
2089
2090 if(chisq<mchisq){
2091 mchisq=chisq;
2092 T0=tmpT0;
2093 }
2094 }
2095 }
2096 }
2097 }
2098 }
2099
2100 if(tmp!=0){
2101 t0_mean=t0_all/tmp;
2102 }
2104
2105 t_Est=T0 + tOffset_b;
2106 tEstFlag=2;
2107 }
2109 g_t0=t0_comp;
2110 g_T0=T0;
2111 }
2112 if(nmatch_barrel==0 && nmatch_end==0 && nmatch_barrel_1==0&&nmatch_barrel_2==0&&m_mdcCalibFunSvc&&
m_flag==2){
2113
2114 log << MSG::INFO << " mdc " << endreq;
2115
2116#define MXWIRE 6860
2117#define MXTKHIT 6860
2118#define MXTRK 15
2119
2120
2121 int nhits_ax = 0;
2122 int nhits_ax2 = 0;
2123 int nhits_st = 0;
2124 int nhits_st2 = 0;
2125
2129 double toft;
2130 double prop;
2131 double t0_minus_TDC[
MXWIRE];
2132
2133 double T0_cal=-230;
2134 double Mdc_t0Arr[500];
2135
2136 int expmc=1;
2137 double scale=1.;
2138 int expno, runno;
2139 ndriftt=0;
2140
2141
2142
2143
2146 }
2147
2148
2149 if (!newtrkCol || newtrkCol->size()==0) {
2150 log << MSG::INFO<< "Could not find RecMdcTrackCol" << endreq;
2151 return StatusCode::SUCCESS;
2152 }
2153 log << MSG::INFO << "Begin to check RecMdcTrackCol"<<endreq;
2154
2155 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
2156
2157 for( int tempntrack=0; iter_trk != newtrkCol->end(); iter_trk++,tempntrack++) {
2158 log << MSG::DEBUG << "retrieved MDC track:"
2159 << " Track Id: " << (*iter_trk)->trackId()
2160 << " Dr: " <<(*iter_trk)->helix(0)
2161 << " Phi0: " << (*iter_trk)->helix(1)
2162 << " kappa: " << (*iter_trk)->helix(2)
2163 << " Dz: " << (*iter_trk)->helix(3)
2164 << " Tanl: " << (*iter_trk)->helix(4)
2165 << " Phi terminal: "<< (*iter_trk)->getFiTerm()
2166 << endreq
2167 << "Number of hits: "<< (*iter_trk)->getNhits()
2168 << " Number of stereo hits " << (*iter_trk)->nster()
2169 << endreq;
2170
2171
2173 HepVector a(5,0);
2174
2175 a[0] = (*iter_trk)->helix(0);
2176 a[1] = (*iter_trk)->helix(1);
2177 a[2] = (*iter_trk)->helix(2);
2178 a[3] = (*iter_trk)->helix(3);
2179 a[4] = (*iter_trk)->helix(4);
2180
2181
2183
2184 double phi0 = a[1];
2185 double kappa =
abs(a[2]);
2186 double dirmag = sqrt(1. + a[4]*a[4]);
2187
2188 double mom =
abs(dirmag/kappa);
2189 double beta=mom/sqrt(mom*mom+
PIMAS2);
2190 if (particleId[tempntrack]== 1) { beta=mom/sqrt(mom*mom+
ELMAS2);}
2191 if(particleId[tempntrack]== 5) { beta=mom/sqrt(mom*mom+
PROTONMAS2);}
2192
2193
2194 Helix helix0(pivot0,a);
2195 double rho = helix0.radius();
2196 double unit_s =
abs(rho * dirmag);
2197
2198 helix0.ignoreErrorMatrix();
2200 double xc= hcen(0);
2201 double yc= hcen(1);
2202
2203 if( xc==0.0 && yc==0.0 ) continue;
2204
2205 double direction =1.;
2206 if(optCosmic!=0) {
2207 double phi = atan2(helix0.momentum(0.).y(),helix0.momentum(0.).x());
2208 if(phi> 0. && phi <=
M_PI) direction=-1.;
2209 }
2210
2212 StatusCode sc = service("MdcGeomSvc", mdcGeomSvc);
2213 double zeast;
2214 double zwest;
2215 double m_vp[43]={0.}, m_zst[43]={0.};
2216 for(int lay=0; lay<43; lay++){
2219
2220
2221 if(lay < 8) m_vp[lay] = 220.0;
2222 else m_vp[lay] = 240.0;
2223
2224 if( 0 == (lay % 2) ){
2225 m_zst[lay] = zwest;
2226 } else{
2227 m_zst[lay] = zeast;
2228 }
2229 }
2230
2231
2232 log << MSG::DEBUG << "hitList of this track:" << endreq;
2233 HitRefVec gothits = (*iter_trk)->getVecHits();
2234 HitRefVec::iterator it_gothit = gothits.begin();
2235 for( ; it_gothit != gothits.end(); it_gothit++){
2236
2237 log << MSG::DEBUG << "hits Id: "<<(*it_gothit)->getId()
2238 <<
" hits MDC layerId wireId " <<
MdcID::layer((*it_gothit)->getMdcId())
2240 << endreq
2241 << " hits TDC " <<(*it_gothit)->getTdc()
2242 << endreq;
2243
2246 double tdc=(*it_gothit)->getTdc() ;
2247
2248 double trkchi2=(*iter_trk)->chi2();
2249 if(trkchi2>100)continue;
2250 double hitChi2=(*it_gothit)->getChisqAdd();
2251 HepVector helix_par = (*iter_trk)->helix();
2252 HepSymMatrix helixErr=(*iter_trk)->err();
2253
2254 if((layer>=8&&layer<=19) ||(layer>=36&&layer<=42)){
2255
2256
2257
2258
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270 if(Estparam.
MDC_Inner()==0 && layer <=3)
continue;
2271
2272 double xw = GeoRef->
Forward().x()/10;
2273 double yw = GeoRef->
Forward().y()/10;
2274
2276 helix0.pivot(pivot1);
2277 double zw=helix0.a()[3];
2278
2279
2280 double dphi = (-xc*(xw-xc)-yc*(yw-yc)) /
2281 sqrt((xc*xc+yc*yc)*((xw-xc)*(xw-xc)+(yw-yc)*(yw-yc)));
2282 dphi = acos(dphi);
2283 double pathtof =
abs(unit_s * dphi);
2284 if (kappa!=0) {
2285 toft = pathtof/
VLIGHT/beta;
2286 } else {
2288 }
2289
2290
2291
2292
2293
2295 if (zw <(GeoRef->
Forward().z())/10) zw =(GeoRef->
Forward().z())/10;
2296
2297 double slant = GeoRef ->
Slant();
2299
2300 double Tw = 0;
2301
2302
2303
2304
2305
2306 double driftt;
2307 double dummy;
2308 int lr=2;
2309
2310 double p[3];
2311 p[0]=helix0.momentum(0.).x();
2312 p[1]=helix0.momentum(0.).y();
2313 double pos[2];
2314 pos[0]=xw; pos[1]=yw;
2316
2317
2318
2319 double dist = 0.;
2320
2321 dist=(m_mdcUtilitySvc->
doca(layer, wid, helix_par, helixErr))*10.0;
2322
2323 if(dist<0.) lr=1;
2324 else lr=0;
2325 dist=fabs(dist);
2326 if(dist> 0.4*(mdcGeomSvc->
Layer(layer))->PCSiz())
continue;
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344 int idummy;
2345
2347 else {
2348 double entrance=(*it_gothit)->getEntra();
2349 driftt = m_mdcCalibFunSvc->
distToDriftTime(dist, layer, wid,lr,entrance);
2350 }
2352 {
2353 T0_cal=m_mdcCalibFunSvc->
getT0(layer, wid)+m_mdcCalibFunSvc->
getTimeWalk(layer,tdc);
2354 }
2355
2356 double zprop = fabs(zw - m_zst[layer]);
2357 double tp = zprop / m_vp[layer];
2358
2359 if(driftt>tdc) continue;
2360 double difft=tdc-driftt-toft-tp-T0_cal;
2361 if(ndriftt>=500) break;
2362 if(
difft<-10)
continue;
2363 Mdc_t0Arr[ndriftt]=
difft;
2364
2365 sum_EstimeMdc=sum_EstimeMdc+
difft;
2366 ndriftt++;
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376 double tev= -t0_minus_TDC[wid]+ driftt;
2377 if(Estparam.
MDC_Tof() !=0) tev += direction*toft;
2378 if(Estparam.
MDC_Prop()!=0) tev += prop;
2379
2380
2381
2382
2383 nhits_ax++;
2384 tev_ax[nhits_ax-1]=tev;
2385
2386 if(Estparam.
MDC_Debug()!=0) log << MSG::INFO <<
"*** tev ***" <<tev <<endreq;
2387 double driftt_mea = t0_minus_TDC[wid];
2388
2389 if(
abs(driftt - driftt_mea)<75.) {
2390
2391 nhits_ax2++;
2392 if(Estparam.
MDC_Debug()!=0) log << MSG::INFO <<
"*** tev2 ***" <<tev <<endreq;
2393 }
2394 }
2395
2396
2397 else if(((layer>=4&&layer<=7)||(layer>=20&&layer<=35))&&
m_useSw){
2398
2400 StatusCode sc = service("MdcGeomSvc", mdcGeomSvc);
2402
2403
2404
2405
2406 double bx= GeoRef->
Backward().x()/10;
2407 double by= GeoRef->
Backward().y()/10;
2408 double bz= GeoRef->
Backward().z()/10;
2409 double fx= GeoRef->
Forward().x()/10;
2410 double fy= GeoRef->
Forward().y()/10;
2411 double fz= GeoRef->
Forward().z()/10;
2412
2413
2414
2417
2418 Hep3Vector wire = (CLHEP::Hep3Vector)bck - (CLHEP::Hep3Vector)fwd;
2420 helix0.pivot(try1);
2421 HepPoint3D try2 = (helix0.x(0).z() - bck.z())/ wire.z() * wire + bck;
2422 helix0.pivot(try2);
2423 HepPoint3D try3 = (helix0.x(0).z() - bck.z())/ wire.z() * wire + bck;
2424 helix0.pivot(try3);
2425
2426 double xh = helix0.x(0.).x();
2427 double yh = helix0.x(0.).y();
2428 double z = helix0.x(0.).z();
2429
2430
2431 double dphi = (-xc*(xh-xc)-yc*(yh-yc)) /
2432 sqrt((xc*xc+yc*yc)*((xh-xc)*(xh-xc)+(yh-yc)*(yh-yc)));
2433 dphi = acos(dphi);
2434 double pathtof =
abs(unit_s * dphi);
2435 if (kappa!=0) {
2436 toft = pathtof/
VLIGHT/beta;
2437 } else {
2439 }
2440
2441
2442
2443 if (z != 9999.) {
2444
2445 if(z < fz ) z = fz;
2446
2447 if(z > bz ) z = bz;
2448 double slant = GeoRef->
Slant();
2450 } else {
2451 prop = 0.;
2452 }
2453
2454
2455 double Tw = 0;
2456
2457
2458
2459
2460
2461 double driftt=0;
2462 double dummy;
2463
2464 double xw = fx + (bx-fx)/(bz-fz)*(z-fz);
2465 double yw = fy + (by-fy)/(bz-fz)*(z-fz);
2466
2468 helix0.pivot(pivot1);
2469
2470 double zw=helix0.a()[3];
2471
2472 int lr=2;
2473
2474 double p[3];
2475 p[0]=helix0.momentum(0.).x();
2476 p[1]=helix0.momentum(0.).y();
2477 double pos[2];
2478 pos[0]=xw; pos[1]=yw;
2480
2481
2482
2483 double dist=0.;
2484
2485 dist=(m_mdcUtilitySvc->
doca(layer, wid, helix_par, helixErr))*10.0;
2486
2487 if(dist<0.) lr=1;
2488 else lr=0;
2489 dist=fabs(dist);
2490 if(dist> 0.4*(mdcGeomSvc->
Layer(layer))->PCSiz())
continue;
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2509 else {
2510 double entrance=(*it_gothit)->getEntra();
2511 driftt = m_mdcCalibFunSvc->
distToDriftTime(dist, layer, wid,lr,entrance);
2512 }
2514 {
2515 T0_cal=m_mdcCalibFunSvc->
getT0(layer, wid)+m_mdcCalibFunSvc->
getTimeWalk(layer,tdc);
2516 }
2517
2518 double zprop = fabs(zw - m_zst[layer]);
2519 double tp = zprop / m_vp[layer];
2520
2521 if(driftt>tdc) continue;
2522 double difft=tdc-driftt-toft-tp-T0_cal;
2523 if(
difft<-10)
continue;
2524 if(ndriftt>=500) break;
2525 Mdc_t0Arr[ndriftt]=
difft;
2526
2527
2528
2529 sum_EstimeMdc=sum_EstimeMdc+
difft;
2530 ndriftt++;
2531
2532
2533
2534 double tev= -t0_minus_TDC[wid]+ driftt;
2535 if(Estparam.
MDC_Tof() !=0) tev += direction*toft;
2536 if(Estparam.
MDC_Prop()!=0) tev += prop;
2537
2538
2539
2540
2541
2542
2543 nhits_st++;
2544 tev_st[nhits_st-1]= tev;
2545
2546 if(Estparam.
MDC_Debug()!=0) log << MSG::INFO <<
"*** tev_st ***" <<tev <<endreq;
2547 double driftt_mea = t0_minus_TDC[wid];
2548
2549 if(
abs(driftt - driftt_mea) <75.) {
2550
2551 nhits_st2++;
2552 if(Estparam.
MDC_Debug()!=0) log << MSG::INFO <<
"*** tev_st2 ***" <<tev <<endreq;
2553 }
2554 }
2555
2556 }
2557 nmatch_mdc++;
2558 }
2559
2560
2562 if(ndriftt!=0){
2564 sum_EstimeMdc=Opt_new(Mdc_t0Arr,ndriftt,400.0);
2565 }
2566 else { sum_EstimeMdc= sum_EstimeMdc/ndriftt;}
2567 if(
m_ntupleflag && m_tuple2) g_EstimeMdc=sum_EstimeMdc;
2568 t_Est=sum_EstimeMdc + tOffset_b;
2569 if(t_Est<0) t_Est=0;
2570 if(optCosmic==0){
2571 tEstFlag=102;
2572 nbunch=((int)(t_Est-offset))/bunchtime;
2573
2574 if((t_Est-offset-nbunch*bunchtime)>(bunchtime/2)) nbunch=nbunch+1;
2575 t_Est=nbunch*bunchtime+offset + tOffset_b;
2576
2577
2578
2579
2580
2581
2582
2583 }
2584 if(optCosmic){
2585 t_Est=sum_EstimeMdc;
2586 tEstFlag=202;
2587 }
2588 }
2590 }
2591
2592 if(t_Est!=-999){
2593
2594 if((!
m_beforrec) && (Testime_fzisan != t_Est) ){
2595 if(tEstFlag==211) tEstFlag=213;
2596 if(tEstFlag==212) tEstFlag=216;
2597 if(tEstFlag==111) tEstFlag=113;
2598 if(tEstFlag==112) tEstFlag=116;
2599 }
2600
2601 if( optCosmic ){
2602 StatusCode scStoreTds = storeTDS(t_Est,tEstFlag,t_quality);
2603 if (scStoreTds!=StatusCode::SUCCESS){ return scStoreTds; }
2604 }else if(!optCosmic){
2605 StatusCode scStoreTds = storeTDS(t_Est,tEstFlag,t_quality);
2606 if (scStoreTds!=StatusCode::SUCCESS){ return scStoreTds; }
2607 }
2608 }else{
2609
2611
2612
2613 double segTest = Testime_fzisan + tOffset_b;
2614 int segFlag = TestimeFlag_fzisan;
2615 double segQuality = TestimeQuality_fzisan;
2616 StatusCode scStoreTds = storeTDS(segTest,segFlag,segQuality);
2617 if (scStoreTds!=StatusCode::SUCCESS){ return scStoreTds; }
2618 }
2619 }
2620
2621
2622
2623 SmartDataPtr<RecEsTimeCol> arecestimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
2624 if (!arecestimeCol) {
2625 if(
m_debug==4) log << MSG::WARNING <<
"Could not find RecEsTimeCol" << endreq;
2626 return( StatusCode::SUCCESS);
2627 }
2628 RecEsTimeCol::iterator iter_evt = arecestimeCol->begin();
2629 for(; iter_evt!=arecestimeCol->end(); iter_evt++){
2630 log << MSG::INFO
2631 << "Test = "<<(*iter_evt)->getTest()
2632 << ", Status = "<<(*iter_evt)->getStat()
2633 <<endreq;
2635 g_Testime=(*iter_evt)->getTest();
2636 }
2637
2638 }
2639
2641 if(m_tuple2){
2642 for(g_ntofdown=0;g_ntofdown<ntofdown;g_ntofdown++){ g_meantevdown[g_ntofdown]=meantevdown[g_ntofdown];}
2643 for(g_ntofup=0;g_ntofup<ntofup;g_ntofup++){ g_meantevup[g_ntofup]=meantevup[g_ntofup];}
2644 g_nmatch_tot=nmatch;
2645 m_estFlag=tEstFlag;
2646 m_estTime=t_Est;
2647 StatusCode status = m_tuple2->write();
2648 if (!status.isSuccess()) {
2649 log << MSG::ERROR << "Can't fill ntuple!" << endreq;
2650 }
2651 }
2652 if(m_tuple9){
2653 for(g_nmatch=0;g_nmatch<nmatch;g_nmatch++)
2654 {
2655 g_meantev[g_nmatch]=meantev[g_nmatch];
2656 }
2657 StatusCode status = m_tuple9->write();
2658 if (!status.isSuccess()) {
2659 log << MSG::ERROR << "Can't fill ntuple!" << endreq;
2660 }
2661 }
2662 }
2663 return StatusCode::SUCCESS;
2664}
double cos(const BesAngle a)
**********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
****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
SmartRefVector< RecMdcHit > HitRefVec
std::vector< TofData * > TofDataVector
int Emc_Get(double, int, double[])
void pathlCut(double pathl_max)
double ztofCutmin() const
double ztofCutmax() const
virtual const double BTime1(double ADC, double TDC, double zHit, unsigned id)=0
virtual const double BTime2(double ADC, double TDC, double zHit, unsigned id)=0
virtual StatusCode chooseConstants(int run, int event)=0
virtual const double ETime(double ADC, double TDC, double rHit, unsigned id)=0
virtual const double EtfTime(double ADC1, double ADC2, double TDC1, double TDC2, unsigned int id, unsigned int strip)=0
virtual const bool ValidInfo()=0
virtual const MdcGeoLayer *const Layer(unsigned id)=0
virtual const MdcGeoWire *const Wire(unsigned id)=0
virtual TofDataVector & tofDataVectorEstime()=0
double distToDriftTime(double dist, int layid, int cellid, int lr, double entrance=0.0) const
double getT0(int layid, int cellid) const
double getTimeWalk(int layid, double Q) const
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)
double doca(int layer, int cell, const HepVector helix, const HepSymMatrix errMat, bool passCellRequired=true, bool doSag=true) const
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)