301 MsgStream log(
msgSvc(), name());
302 log << MSG::INFO <<
" tof " << endreq;
307 double offset=0, t_quality=0, tOffset_b=0, tOffset_e=0;
308 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};
310 int idtof_mrpc,idmatch_mrpc[3][19]={0},idmatch_emc_mrpc[3][19]={0},tofid_emc_mrpc[2]={0};
312 int ntot=0,nmat=0,in=-1,out=-1, emcflag1=0, emcflag2=0, tof_flag=0;
double bunchtime=
m_bunchtime_MC;
313 double meant[15]={0.},adc[15]={0.},
momentum[15]={0.},r_endtof[10]={0.};
314 double ttof[30]={0.},helztof[30]={0.0},mcztof=0.0,forevtime=0.0,backevtime=0.0,meantev[200]={0.},meantevup[200]={0.0},meantevdown[200]={0.0};
315 double t0forward=0,t0backward=0,t0forward_trk=0,t0backward_trk=0;
316 double t0forward_add=0,t0backward_add=0,t_Est=-999;
317 double cor_evtime=0.;
318 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.};
320 double r_endtof_mrpc[10]={0.},ttof_mrpc[30]={0.},helztof_mrpc[30]={0.0},helpath_mrpc[19]={0.}, helz_mrpc[19]={0.},abmom2_mrpc[19]={0.};
321 double pt_mrpc[19]={0.},dr_mrpc[19]={0.},dz_mrpc[19]={0.}, phi_mrpc[19]={0.},tanl_mrpc[19]={0.};
323 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;
324 double sum_EstimeMdc=0,sum_EstimeMdcMC=0;
325 int nbunch=0,tEstFlag=0,
runNo=0;
326 double helpath[88]={0.},helz[88]={0.},abmom2[88]={0.};
327 double help[15]={0.}, abp2[15]={0.};
328 double pt[88]={0.},dr[88]={0.},dz[88]={0.};
329 double phi[88]={0.},tanl[88]={0.};
330 double mcTestime=0,trigtiming=0;
331 double tdiffeast[2][88]={0.};
332 double tdiffwest[2][88]={0.};
333 double mean_tdc_btof[2][88]={0.}, mean_tdc_etof[3][48]={0.};
336 double Testime_fzisan= -999.;
337 int TestimeFlag_fzisan= -999;
338 double TestimeQuality_fzisan= -999.;
339 double Tof_t0Arr[500]={-999.};
344 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
346 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
347 return StatusCode::FAILURE;
349 log << MSG::INFO <<
"EsTimeAlg: retrieved event: " << eventHeader->eventNumber() <<
" run: " << eventHeader->runNumber() << endreq;
350 int eventNo=eventHeader->eventNumber();
351 runNo=eventHeader->runNumber();
371 if(
m_evtNo==1 && m_pass[0]%1000 ==0){
372 cout<<
"------------------- Events-----------------: "<<m_pass[0]<<endl;
374 if(
m_debug==4) cout<<
"m_userawtime: "<<m_userawtime<<endl;
375 if(
m_debug==4) cout<<
"EstTofCalibSvc est flag: "<<tofCaliSvc->
ValidInfo()<<endl;
378 log << MSG::ERROR <<
"EstTof Calibration Const is Invalid! " << endreq;
379 return StatusCode::FAILURE;
384 SmartDataPtr<RecEsTimeCol> aRecestimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
385 if (!aRecestimeCol || aRecestimeCol->size()==0) {
386 if(
m_debug==4) log << MSG::INFO <<
"Could not find RecEsTimeCol from fzsian" << endreq;
388 RecEsTimeCol::iterator it_evt = aRecestimeCol->begin();
389 for(; it_evt!=aRecestimeCol->end(); it_evt++){
390 Testime_fzisan = (*it_evt)->getTest();
391 TestimeFlag_fzisan = (*it_evt)->getStat();
392 TestimeQuality_fzisan = (*it_evt)->getQuality();
394 log << MSG::INFO <<
"fzisan : Test = "<<(*it_evt)->getTest()
395 <<
", Status = "<<(*it_evt)->getStat() <<endreq;
397 if(
m_ntupleflag && m_tuple2) g_Testime_fzisan = Testime_fzisan;
401 std::string fullPath =
"/Calib/EsTimeCal";
402 SmartDataPtr<CalibData::EsTimeCalibData> TEst(m_pCalibDataSvc, fullPath);
403 if(!TEst){ cout<<
"ERROR EsTimeCalibData"<<endl;}
405 int no = TEst->getTestCalibConstNo();
410 log<<MSG::INFO<<
"offset barrel t0="<< TEst->getToffsetb()
411 <<
", offset endcap t0="<< TEst->getToffsete()
412 <<
", bunch time ="<<TEst->getBunchTime()
414 tOffset_b=TEst->getToffsetb();
415 tOffset_e=TEst->getToffsete();
416 bunchtime=TEst->getBunchTime();
443 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
444 if (!mcParticleCol) {
445 log << MSG::INFO<<
"Could not find McParticle" << endreq;
448 McParticleCol::iterator iter_mc = mcParticleCol->begin();
453 for (;iter_mc != mcParticleCol->end(); iter_mc++, digiId++) {
454 int statusFlags = (*iter_mc)->statusFlags();
455 int pid = (*iter_mc)->particleProperty();
458 <<
" MC ParticleId = " << pid
459 <<
" statusFlags = " << statusFlags
460 <<
" PrimaryParticle = " <<(*iter_mc)->primaryParticle()
463 g_theta0MC[ntrkMC] = (*iter_mc)->initialFourMomentum().theta();
464 g_phi0MC[ntrkMC] = (*iter_mc)->initialFourMomentum().phi();
465 g_pxMC[ntrkMC] = (*iter_mc)->initialFourMomentum().px()/1000;
466 g_pyMC[ntrkMC] = (*iter_mc)->initialFourMomentum().py()/1000;
467 g_pzMC[ntrkMC] = (*iter_mc)->initialFourMomentum().pz()/1000;
468 g_ptMC[ntrkMC] = sqrt(((*iter_mc)->initialFourMomentum().px())*((*iter_mc)->initialFourMomentum().px())+((*iter_mc)->initialFourMomentum().py())*((*iter_mc)->initialFourMomentum().py()))/1000;
471 if(m_particleTable->particle( pid )) charge = m_particleTable->particle( pid )->charge();
472 }
else if ( pid <0 ) {
473 if(m_particleTable->particle( -pid )) {
474 charge = m_particleTable->particle( -pid )->charge();
478 log << MSG::WARNING <<
"wrong particle id, please check data" <<endreq;
481 <<
"MC ParticleId = " << pid <<
" charge = " << charge
483 if(charge !=0 &&
abs(
cos((*iter_mc)->initialFourMomentum().theta()))<0.93){
486 if(((*iter_mc)->primaryParticle())&&
m_ntupleflag && m_tuple2){
487 g_mcTestime=(*iter_mc)->initialPosition().t();
488 mcTestime=(*iter_mc)->initialPosition().t();
494 if (
m_debug) cout<<
"bunchtime: "<<bunchtime<<endl;
511 SmartDataPtr<RecMdcTrackCol> newtrkCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
512 if (!newtrkCol || newtrkCol->size()==0) {
513 log << MSG::INFO<<
"Could not find RecMdcTrackCol" << endreq;
515 log << MSG::INFO <<
"Begin to check RecMdcTrackCol"<<endreq;
516 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
517 for( ; iter_trk != newtrkCol->end(); iter_trk++){
518 log << MSG::DEBUG <<
"retrieved MDC track:"
519 <<
" Track Id: " << (*iter_trk)->trackId()
520 <<
" Phi0: " << (*iter_trk)->helix(0)
521 <<
" kappa: " << (*iter_trk)->helix(2)
522 <<
" Tanl: " << (*iter_trk)->helix(4)
523 <<
" Phi terminal: "<< (*iter_trk)->getFiTerm()
525 <<
"Number of hits: "<< (*iter_trk)->getNhits()
526 <<
" Number of stereo hits " << (*iter_trk)->nster()
528 double kappa = (*iter_trk)->helix(2);
529 double tanl = (*iter_trk)->helix(4);
530 momentum[ntot] = 1./fabs(kappa) * sqrt(1.+tanl*tanl);
531 if((*iter_trk)->helix(3)>50.0)
continue;
539 SmartDataPtr<RecEmcShowerCol> aShowerCol(eventSvc(),
"/Event/Recon/RecEmcShowerCol");
540 if (!aShowerCol || aShowerCol->size()==0) {
541 log << MSG::WARNING <<
"Could not find RecEmcShowerCol" << endreq;
544 RecEmcShowerCol::iterator iShowerCol=aShowerCol->begin();
545 for(;iShowerCol!=aShowerCol->end();iShowerCol++,emctrk++){
547 phiemc_rec[emctrk]=(*iShowerCol)->position().phi();
548 thetaemc_rec[emctrk]=(*iShowerCol)->position().theta();
549 energy_rec[emctrk]=(*iShowerCol)->energy();
550 xemc_rec[emctrk]=(*iShowerCol)->x();
551 yemc_rec[emctrk]=(*iShowerCol)->y();
552 zemc_rec[emctrk]=(*iShowerCol)->z();
553 module[emctrk]=(*iShowerCol)->module();
556 for(
int i=0; i<2; i++){
559 double fi_endtof = atan2(yemc_rec[i],xemc_rec[i] );
560 if (fi_endtof<0) fi_endtof=2*3.141593+fi_endtof;
562 int Tofid = (int)(fi_endtof/(3.141593/44));
563 if(Tofid>87) Tofid=Tofid-88;
565 idmatch_emc[1][Tofid]=1;
568 int Tofid =(int)(fi_endtof/(3.141593/24));
569 if( Tofid>47) Tofid=Tofid-48;
571 if(module[i]==2) idmatch_emc[2][Tofid]=1;
572 if(module[i]==0) idmatch_emc[0][Tofid]=1;
578 double fi_endtof_mrpc = atan2(yemc_rec[i],xemc_rec[i])-3.141592654/2.;
579 if(fi_endtof_mrpc<0) fi_endtof_mrpc += 2*3.141592654;
581 int mrpc_moduleId=((int)(fi_endtof_mrpc/(3.141593/18)))+1;
582 if(mrpc_moduleId%2==0){mrpc_moduleId=mrpc_moduleId/2;}
583 else {mrpc_moduleId=(mrpc_moduleId+1)/2;}
584 if(zemc_rec[i]>0) {(mrpc_moduleId -= 19); mrpc_moduleId=mrpc_moduleId*(-1);}
586 tofid_emc_mrpc[i]= mrpc_moduleId;
587 if(module[i]==2){ idmatch_emc_mrpc[2][mrpc_moduleId]=1;}
588 if(module[i]==0){ idmatch_emc_mrpc[0][mrpc_moduleId]=1;}
599 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
600 for(
int idfztrk=0; iter_trk != newtrkCol->end(); iter_trk++,idfztrk++){
602 mdcftrk[0] = (*iter_trk)->helix(0);
603 mdcftrk[1] = (*iter_trk)->helix(1);
604 mdcftrk[2] =-(*iter_trk)->helix(2);
605 mdcftrk[3] = (*iter_trk)->helix(3);
606 mdcftrk[4] = (*iter_trk)->helix(4);
616 double z_emc = EmcHit.
Z_emc;
618 double phiemc_ext = EmcHit.
phi_emc;
620 for(
int t=0;
t<emctrk;
t++){
621 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))){
622 if((energy_rec[
t])>=(0.85*
momentum[idfztrk]))
623 particleId[idfztrk]=1;
628 if(particleId[idfztrk]!=1){
630 SmartDataPtr<RecMdcDedxCol> newdedxCol(eventSvc(),
"/Event/Recon/RecMdcDedxCol");
631 if (!newdedxCol || newdedxCol->size()==0) {
632 log << MSG::WARNING<<
"Could not find RecMdcDedxCol" << endreq;
635 RecMdcDedxCol::iterator it_dedx = newdedxCol->begin();
636 for(
int npid=0; it_dedx != newdedxCol->end(); it_dedx++,npid++) {
637 log << MSG::INFO <<
"retrieved MDC dE/dx: "
638 <<
"dEdx Id: " << (*it_dedx)->trackId()
639 <<
" particle Id: "<< (*it_dedx)->particleType() <<endreq;
640 if((*it_dedx)->particleType() ==
proton){
643 if(
m_debug==4) cout<<
"dedx pid: "<<particleId[npid]<<endl;
659 if(tofpart < 0)
continue;
661 idtof = TofHit.
Tofid;
665 tofid_helix[idfztrk] = TofHit.
Tofid;
666 log << MSG::INFO <<
"helix to tof hit part, Id: "<<tofpart<<
" , "<< idtof <<endreq;
667 if(
m_debug ==4) cout <<
"helix to tof hit part, Id: "<<tofpart<<
" , "<< idtof <<endl;
668 if (idtof>=0 && idtof<=87 ) {
671 if(idtof_mrpc>0 && idtof_mrpc<19) idmatch_mrpc[tofpart][idtof_mrpc]=1;
672 if(idtof_mrpc>0 && idtof_mrpc<19) helpath_mrpc[idtof_mrpc] = TofHit.
Pathl;
673 if(idtof_mrpc>0 && idtof_mrpc<19) helz_mrpc[idtof_mrpc] = TofHit.
Z_tof;
675 idmatch[tofpart][idtof]= 1;
676 helpath[idtof]= TofHit.
Pathl;
677 helz[idtof] = TofHit.
Z_tof;
678 double abmom = 1./fabs(TofHit.
Kappa) * sqrt(1.+TofHit.
Tanl*TofHit.
Tanl);
680 if(abmom<0.1)
continue;
681 abmom2[idtof] = abmom*abmom;
683 if(idtof_mrpc>0 && idtof_mrpc<19) abmom2_mrpc[idtof_mrpc] = abmom*abmom;
685 pt[idtof] = 1./fabs(TofHit.
Kappa);
686 dr[idtof] = TofHit.
Dr;
687 dz[idtof] = TofHit.
Dz;
688 phi[idtof] = TofHit.
Phi0;
689 tanl[idtof] = TofHit.
Tanl;
691 helztof[idfztrk] = helz[idtof];
694 if(idtof_mrpc>0 && idtof_mrpc<19) pt_mrpc[idtof_mrpc] = 1./fabs(TofHit.
Kappa);
695 if(idtof_mrpc>0 && idtof_mrpc<19) dr_mrpc[idtof_mrpc] = TofHit.
Dr;
696 if(idtof_mrpc>0 && idtof_mrpc<19) dz_mrpc[idtof_mrpc] = TofHit.
Dz;
697 if(idtof_mrpc>0 && idtof_mrpc<19) phi_mrpc[idtof_mrpc] = TofHit.
Phi0;
698 if(idtof_mrpc>0 && idtof_mrpc<19) tanl_mrpc[idtof_mrpc] = TofHit.
Tanl;
699 if(idtof_mrpc>0 && idtof_mrpc<19) r_endtof_mrpc[idfztrk]= TofHit.
r_endtof;
700 if(idtof_mrpc>0 && idtof_mrpc<19) helztof_mrpc[idfztrk] = helz_mrpc[idtof_mrpc];
720 if(particleId[idfztrk] == 1){
721 ttof[idfztrk] = sqrt(
ELMAS2/abmom2[idtof]+1)* helpath[idtof]/
VLIGHT;
722 if(idtof_mrpc>0 && idtof_mrpc<19)
724 ttof_mrpc[idfztrk]=sqrt(
ELMAS2/abmom2_mrpc[idtof_mrpc]+1)* helpath_mrpc[idtof_mrpc]/
VLIGHT;
730 else if (particleId[idfztrk] == 5){
732 if(idtof_mrpc>0 && idtof_mrpc<19)
734 ttof_mrpc[idfztrk]=sqrt(
PROTONMAS2/abmom2_mrpc[idtof_mrpc]+1)* helpath_mrpc[idtof_mrpc]/
VLIGHT;
741 ttof[idfztrk] = sqrt(
PIMAS2/abmom2[idtof]+1)* helpath[idtof]/
VLIGHT;
742 if(idtof_mrpc>0 && idtof_mrpc<19)
744 ttof_mrpc[idfztrk]=sqrt(
PIMAS2/abmom2_mrpc[idtof_mrpc]+1)* helpath_mrpc[idtof_mrpc]/
VLIGHT;
752 ttof[idfztrk] = sqrt(
MUMAS2/abmom2[idtof]+1)* helpath[idtof]/
VLIGHT;
753 if(idtof_mrpc>0 && idtof_mrpc<19)
755 ttof_mrpc[idfztrk]=sqrt(
MUMAS2/abmom2_mrpc[idtof_mrpc]+1)* helpath_mrpc[idtof_mrpc]/
VLIGHT;
764 g_abmom[idfztrk] = abmom;
765 g_ttof[idfztrk] = ttof[idfztrk];
776 SmartDataPtr<TofMcHitCol> tofmcHitCol(eventSvc(),
"/Event/MC/TofMcHitCol");
778 log << MSG::ERROR<<
"Could not find McParticle" << endreq;
782 TofMcHitCol::iterator iter_mctof = tofmcHitCol->begin();
784 for (;iter_mctof !=tofmcHitCol->end(); iter_mctof++, digiId++) {
786 <<
" TofMcHit Flight Time = " << (*iter_mctof)->getFlightTime()
787 <<
" zPosition = " << ((*iter_mctof)->getPositionZ())/10
788 <<
" xPosition = " <<((*iter_mctof)->getPositionX())/10
789 <<
" yPosition = " <<((*iter_mctof)->getPositionY())/10
799 for(TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++) {
800 int barrelid=(*iter2)->barrel();
803 if((*iter2)->barrel()){
804 tofid = (*iter2)->tofId();
805 layerid = (*iter2)->layer();
806 if(layerid==1) tofid=tofid-88;
807 if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times() ==1 ){
808 double ftdc= (*iter2)->tdc1();
809 double btdc= (*iter2)->tdc2();
810 mean_tdc_btof[layerid][tofid]=(ftdc+btdc)/2;
812 else if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times() >1){
813 double ftdc= (*iter2)->tdc1();
814 double btdc= (*iter2)->tdc2();
815 mean_tdc_btof[layerid][tofid]=(ftdc+btdc)/2;
819 tofid = (*iter2)->tofId();
820 if(tofid<48) barrelid=0;
821 if(tofid>47) barrelid=2;
822 if(barrelid==2) tofid=tofid-48;
824 if((*iter2)->times() ==1){
825 double ftdc= (*iter2)->tdc();
826 mean_tdc_etof[barrelid][tofid]=ftdc;
828 else if(((*iter2)->times() >1) && ((*iter2)->times() <5)){
829 double ftdc= (*iter2)->tdc();
830 mean_tdc_etof[barrelid][tofid]=ftdc;
835 double difftof_b=100, difftof_e=100;
836 int tofid1=tofid_emc[0];
837 int tofid2=tofid_emc[1];
838 for(
int i=0; i<2; i++){
839 for(
int m=0; m<2; m++){
840 for(
int j=-2; j<3; j++){
841 for(
int k=-2; k<3; k++){
848 if(mean_tdc_btof[i][p]==0 || mean_tdc_btof[m][
q]==0)
continue;
849 double difftof_b_temp = mean_tdc_btof[i][p]-mean_tdc_btof[m][
q];
850 if(
abs(difftof_b_temp)<
abs(difftof_b )) difftof_b =difftof_b_temp;
873 for(
int i=-1; i<2; i++){
874 for(
int j=-1; j<2; j++){
881 if( mean_tdc_etof[0][m] && mean_tdc_etof[2][
n]){
882 double difftof_e_temp= mean_tdc_etof[0][m]-mean_tdc_etof[2][
n];
883 if(
abs(difftof_e_temp) <
abs(difftof_e)) difftof_e= difftof_e_temp;
902 TofDataVector::iterator iter2 = tofDigiVec.begin();
906 unsigned int barrelid;
907 unsigned int layerid;
911 for (;iter2 != tofDigiVec.end(); iter2++, digiId++){
912 log << MSG::INFO <<
"TOF digit No: " << digiId << endreq;
913 barrelid=(*iter2)->barrel();
914 if((*iter2)->barrel()==0)
continue;
919 if(!( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times() ==1 ))
continue;
920 tofid = (*iter2)->tofId();
921 layerid = (*iter2)->layer();
922 if(layerid==1) tofid=tofid-88;
925 <<
" barrelid = "<<barrelid
926 <<
" layerid = "<<layerid
927 <<
" ForwordADC = "<<(*iter2)->adc1()
928 <<
" ForwordTDC = "<<(*iter2)->tdc1()
929 <<
" BackwordADC = "<<(*iter2)->adc2()
930 <<
" BackwordTDC = "<<(*iter2)->tdc2()
933 double ftdc= (*iter2)->tdc1()-tdiffeast[layerid][tofid];
934 double btdc= (*iter2)->tdc2()-tdiffwest[layerid][tofid];
935 if(
m_debug==4) cout<<
"barrel 1 ::layer, barrel, tofid, ftdc, btdc: "<<layerid<<
" , "<<barrelid<<
" , "<<tofid<<
" , "<<ftdc<<
" , "<<btdc<<endl;
936 double fadc= (*iter2)->adc1();
937 double badc= (*iter2)->adc2();
938 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
939 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
940 double ztof = fabs((ftdc-btdc)/2)*17.7 , ztof2 = ztof*ztof;
942 double mean_tdc = 0.5*(btdc+ftdc);
973 static bool HparCut=
true;
978 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
980 for(
int i=0;i<=ntot;i++){
982 if(ttof[i]!=0 && ftdc>0){
985 if(tofid_helix[i] == tofid ||(tofid_helix[i] == idptof)){
987 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
991 cor_evtime= ttof[i] + (238/2 - helztof[i])*0.069 ;
992 if (optCosmic && tofid<44) {
993 backevtime = -ttof[i] + (115 + helztof[i])*0.0566 + 12.;
994 forevtime = -ttof[i] + (115 - helztof[i])*0.0566 + 12.;
995 meantevup[ntofup]=(backevtime+forevtime)/2;
999 backevtime = ttof[i] + (115 + helztof[i])*0.0566 + 12.;
1000 forevtime = ttof[i] + (115 - helztof[i])*0.0566 + 12.;
1001 meantevdown[ntofdown]=(backevtime+forevtime)/2;
1005 if(!(*iter2)->adc1() || !(*iter2)->adc2() || m_userawtime){
1006 t0forward_trk = ftdc - forevtime ;
1007 t0backward_trk = btdc - backevtime ;
1010 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
1011 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
1012 if (optCosmic && tofid<44) {
1013 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())+ttof[i];
1014 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())+ttof[i];
1017 if(t0forward_trk<-3 || t0backward_trk<-3 || fabs(t0forward_trk-t0backward_trk)>15.0)
continue;
1018 if(!
m_TofOpt&& nmatch_barrel!=0 && fabs((t0forward_trk+t0backward_trk)/2-(t0backward_add+t0forward_add)/2/nmatch_barrel)>11)
continue;
1019 if(
m_debug ==4 ) cout<<
" t0forward_trk, t0backward_trk: "<<t0forward_trk<<
" , "<<t0backward_trk<<endl;
1022 g_t0for[nmatch1] = t0forward_trk ;
1023 g_t0back[nmatch2] = t0backward_trk ;
1024 g_meantdc=(ftdc+btdc)/2;
1025 if(tofid<44) g_ntofup1++;
1028 meantev[nmatch]=(backevtime+forevtime)/2;
1029 t0forward_add += t0forward_trk;
1030 t0backward_add += t0backward_trk;
1031 if(nmatch>499)
break;
1032 Tof_t0Arr[nmatch]=(t0forward_trk+t0backward_trk)/2.0;
1041 if(nmatch_barrel==0){
1042 for(
int i=0;i<=ntot;i++){
1043 if(ttof[i]!=0 && ftdc>0){
1044 if( (tofid_helix[i] == idntof )){
1046 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
1048 cor_evtime= ttof[i] + (238/2 - helztof[i])*0.069 ;
1049 if (optCosmic && tofid<44) {
1050 backevtime = -ttof[i] + (115 + helztof[i])*0.0566 + 12.;
1051 forevtime = -ttof[i] + (115 - helztof[i])*0.0566 + 12.;
1052 meantevup[ntofup]=(backevtime+forevtime)/2;
1056 backevtime = ttof[i] + (115 + helztof[i])*0.0566 + 12.;
1057 forevtime = ttof[i] + (115 - helztof[i])*0.0566 + 12.;
1058 meantevdown[ntofdown]=(backevtime+forevtime)/2;
1062 if( !(*iter2)->adc1() || !(*iter2)->adc2() || m_userawtime){
1063 t0forward_trk = ftdc - forevtime ;
1064 t0backward_trk = btdc - backevtime ;
1067 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
1068 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
1069 if (optCosmic && tofid<44) {
1070 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())+ttof[i];
1071 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())+ttof[i];
1074 if(t0forward_trk<-3 || t0backward_trk<-3 || fabs(t0forward_trk-t0backward_trk)>15.0)
continue;
1075 if(!
m_TofOpt&&nmatch_barrel!=0 && fabs((t0forward_trk+t0backward_trk)/2-(t0backward_add+t0forward_add)/2/nmatch_barrel)>11)
continue;
1076 if(
m_debug ==4 ) cout<<
" t0forward_trk, t0backward_trk: "<<t0forward_trk<<
" , "<<t0backward_trk<<endl;
1078 g_t0for[nmatch1] = t0forward_trk ;
1079 g_t0back[nmatch2] = t0backward_trk ;
1080 g_meantdc=(ftdc+btdc)/2;
1082 meantev[nmatch]=(backevtime+forevtime)/2;
1083 t0forward_add += t0forward_trk;
1084 t0backward_add += t0backward_trk;
1085 if(nmatch>499)
break;
1086 Tof_t0Arr[nmatch]=(t0forward_trk+t0backward_trk)/2.0;
1103 if(nmatch_barrel != 0 ){
1105 g_t0barrelTof=( t0forward_add/nmatch_barrel + t0backward_add/nmatch_barrel)/2;
1111 if(nmatch_barrel==0){
1115 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
1116 log << MSG::INFO <<
"TOF digit No: " << digiId << endreq;
1117 barrelid=(*iter2)->barrel();
1118 if((*iter2)->barrel()==0)
continue;
1122 if(((*iter2)->quality() & 0x5) ==0x5 && (*iter2)->times() >1 ){
1123 tofid = (*iter2)->tofId();
1124 layerid = (*iter2)->layer();
1125 if(layerid==1) tofid=tofid-88;
1127 <<
" TofId = "<<tofid
1128 <<
" barrelid = "<<barrelid
1129 <<
" layerid = "<<layerid
1130 <<
" ForwordADC = "<<(*iter2)->adc1()
1131 <<
" ForwordTDC = "<<(*iter2)->tdc1()
1133 double ftdc= (*iter2)->tdc1()-tdiffeast[layerid][tofid];
1134 double btdc= (*iter2)->tdc2()-tdiffwest[layerid][tofid];
1135 double fadc= (*iter2)->adc1();
1136 double badc= (*iter2)->adc2();
1137 if(
m_debug==4) cout<<
"barrel 2 ::layer, barrel, tofid, ftdc, btdc: "<<layerid<<
" , "<<barrelid<<
" , "<<tofid<<
" , "<<ftdc<<
" , "<<btdc<<endl;
1138 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
1139 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
1140 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
1141 for(
int i=0;i<=ntot;i++){
1143 if(ttof[i]!=0 && ftdc>0){
1146 if(tofid_helix[i] == tofid ||(tofid_helix[i] == idptof)||(tofid_helix[i] == idntof)){
1148 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
1152 cor_evtime= ttof[i] + (238/2 - helztof[i])*0.069 ;
1153 if (optCosmic && tofid<44) {
1154 backevtime = -ttof[i] + (115 + helztof[i])*0.0566 + 12.;
1155 forevtime = -ttof[i] + (115 - helztof[i])*0.0566 + 12.;
1156 meantevup[ntofup]=(backevtime+forevtime)/2;
1160 backevtime = ttof[i] + (115 + helztof[i])*0.0566 + 12.;
1161 forevtime = ttof[i] + (115 - helztof[i])*0.0566 + 12.;
1162 meantevdown[ntofdown]=(backevtime+forevtime)/2;
1166 if(!(*iter2)->adc1() || !(*iter2)->adc2() || m_userawtime){
1167 t0forward_trk = ftdc - forevtime ;
1168 t0backward_trk = btdc - backevtime ;
1171 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
1172 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
1173 if (optCosmic && tofid<44) {
1174 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())+ttof[i];
1175 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())+ttof[i];
1179 if(t0forward_trk<-3 || t0backward_trk<-3 || fabs(t0forward_trk-t0backward_trk)>15.0)
continue;
1180 if(!
m_TofOpt&&nmatch_barrel!=0 && fabs((t0forward_trk+t0backward_trk)/2-(t0backward_add+t0forward_add)/2/nmatch_barrel)>11)
continue;
1181 if(
m_debug == 4) cout<<
"t0forward_trk, t0backward_trk: "<<t0forward_trk<<
" , "<<t0backward_trk<<endl;
1184 g_t0for[nmatch1] = t0forward_trk ;
1185 g_t0back[nmatch2] = t0backward_trk ;
1186 g_meantdc=(ftdc+btdc)/2;
1187 if(tofid<44) g_ntofup1++;
1190 meantev[nmatch]=(backevtime+forevtime)/2;
1191 t0forward_add += t0forward_trk;
1192 t0backward_add += t0backward_trk;
1193 if(nmatch>499)
break;
1194 Tof_t0Arr[nmatch]=(t0forward_trk+t0backward_trk)/2.0;
1207 if(nmatch_barrel) tof_flag=2;
1209 if(ntot==0 || nmatch_barrel==0) {
1210 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
1211 log << MSG::INFO <<
"TOF digit No: " << digiId << endreq;
1212 barrelid=(*iter2)->barrel();
1213 if((*iter2)->barrel()==0)
continue;
1216 if(((*iter2)->quality() & 0x5) ==0x5 && (*iter2)->times() ==1 ){
1217 tofid = (*iter2)->tofId();
1218 layerid = (*iter2)->layer();
1219 if(layerid==1) tofid=tofid-88;
1221 <<
" TofId = "<<tofid
1222 <<
" barrelid = "<<barrelid
1223 <<
" layerid = "<<layerid
1224 <<
" ForwordADC = "<<(*iter2)->adc1()
1225 <<
" ForwordTDC = "<<(*iter2)->tdc1()
1227 double ftdc= (*iter2)->tdc1();
1228 double btdc= (*iter2)->tdc2();
1229 double fadc= (*iter2)->adc1();
1230 double badc= (*iter2)->adc2();
1231 if(
m_debug==4) cout<<
"barrel 3 ::layer, barrel, tofid, ftdc, btdc: "<<layerid<<
" , "<<barrelid<<
" , "<<tofid<<
" , "<<ftdc<<
" , "<<btdc<<endl;
1232 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
1233 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
1234 for(
int i=0; i<2; i++){
1235 if(tofid_emc[i] == tofid || tofid_emc[i] == idptof || tofid_emc[i] == idntof){
1236 if(zemc_rec[0]||zemc_rec[1]){
1237 if(tofid ==tofid_emc[i] || tofid_emc[i]==idntof || tofid_emc[i]==idptof){
1238 if(ftdc>2000.|| module[i]!=1)
continue;
1239 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;
1240 if(optCosmic==1 && tofid<44){
1241 backevtime = -ttof[i] + (115 + zemc_rec[i])*0.0566 + 12.;
1242 forevtime = -ttof[i] + (115 - zemc_rec[i])*0.0566 + 12.;
1243 meantevup[ntofup]=(backevtime+forevtime)/2;
1247 backevtime = ttof[i] + (115 + zemc_rec[i])*0.0566 + 12.;
1248 forevtime = ttof[i] + (115 - zemc_rec[i])*0.0566 + 12.;
1249 meantevdown[ntofdown]=(backevtime+forevtime)/2;
1252 if( !(*iter2)->adc1() || !(*iter2)->adc2() || m_userawtime){
1253 t0forward_trk=ftdc-forevtime;
1254 t0backward_trk=btdc-backevtime;
1257 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
1258 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
1259 if (optCosmic && tofid<44) {
1260 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())+ttof[i];
1261 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())+ttof[i];
1266 if(t0forward_trk<-1 || t0backward_trk<-1 || fabs(t0forward_trk-t0backward_trk)>15.0)
continue;
1267 if(!
m_TofOpt&&nmatch_barrel!=0 && fabs((t0forward_trk+t0backward_trk)/2-(t0backward_add+t0forward_add)/2/nmatch_barrel)>11)
continue;
1268 if(
m_debug == 4) cout<<
"t0forward_trk, t0backward_trk: "<<t0forward_trk<<
" , "<<t0backward_trk<<endl;
1269 meantev[nmatch]=(backevtime+forevtime)/2;
1270 t0forward_add += t0forward_trk;
1271 t0backward_add += t0backward_trk;
1272 if(nmatch>499)
break;
1273 Tof_t0Arr[nmatch]=(t0forward_trk+t0backward_trk)/2.0;
1284 if(nmatch_barrel) tof_flag=3;
1286 if(nmatch_barrel != 0 ){
1287 t0forward = t0forward_add/nmatch_barrel;
1288 t0backward = t0backward_add/nmatch_barrel;
1295 if(t_Est<0) t_Est=0;
1296 if(tof_flag==1) tEstFlag=111;
1297 else if(tof_flag==2) tEstFlag=121;
1298 else if(tof_flag==3) tEstFlag=131;
1301 t_Est=(t0forward+t0backward)/2;
1302 if(tof_flag==1) tEstFlag=211;
1303 else if(tof_flag==2) tEstFlag=221;
1304 else if(tof_flag==3) tEstFlag=231;
1306 if(
m_ntupleflag && m_tuple2) g_meant0=(t0forward+t0backward)/2;
1315 if(nmatch_barrel==0){
1316 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
1317 log << MSG::INFO <<
"TOF digit No: " << digiId << endreq;
1318 barrelid=(*iter2)->barrel();
1319 if((*iter2)->barrel()==0)
continue;
1322 if(((*iter2)->quality() & 0x5) ==0x4){
1323 tofid = (*iter2)->tofId();
1324 layerid = (*iter2)->layer();
1325 if(layerid==1) tofid=tofid-88;
1327 <<
" TofId = "<<tofid
1328 <<
" barrelid = "<<barrelid
1329 <<
" layerid = "<<layerid
1330 <<
" ForwordADC = "<<(*iter2)->adc1()
1331 <<
" ForwordTDC = "<<(*iter2)->tdc1()
1334 double ftdc= (*iter2)->tdc1()-tdiffeast[layerid][tofid];
1335 double fadc= (*iter2)->adc1();
1336 if(
m_debug==4) cout<<
"barrel 4 ::layer, barrel, tofid, ftdc: "<<layerid<<
" , "<<barrelid<<
" , "<<tofid<<
" , "<<ftdc<<endl;
1337 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
1338 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
1340 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
1341 for(
int i=0;i<=ntot;i++){
1342 if(ttof[i]!=0 && ftdc>0){
1343 if(tofid_helix[i] == tofid ||(tofid_helix[i] == idptof) || (tofid_helix[i] == idntof)){
1344 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
1348 cor_evtime= ttof[i] + (238/2 - helztof[i])*0.069 ;
1349 if (optCosmic && tofid<44) {
1350 forevtime = -ttof[i] + (115 - helztof[i])*0.0566 + 12.;
1351 meantevup[ntofup]=forevtime;
1355 forevtime = ttof[i] + (115 - helztof[i])*0.0566 + 12.;
1356 meantevdown[ntofdown]=forevtime;
1360 if(!(*iter2)->adc1() || m_userawtime){
1361 t0forward_trk = ftdc - forevtime ;
1364 t0forward_trk = tofCaliSvc->
BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
1366 if(t0forward_trk<-1)
continue;
1367 if(!
m_TofOpt&&nmatch_barrel_1!=0 && fabs((t0forward_trk)-(t0forward_add)/nmatch_barrel_1)>11)
continue;
1368 if(
m_debug == 4) cout<<
"t0forward_trk: "<<t0forward_trk<<endl;
1371 g_t0for[nmatch1] = t0forward_trk ;
1373 if(tofid<44) g_ntofup1++;
1376 meantev[nmatch]=forevtime;
1377 t0forward_add += t0forward_trk;
1379 if(nmatch>499)
break;
1380 Tof_t0Arr[nmatch]=t0forward_trk;
1392 else if(((*iter2)->quality() & 0x5) ==0x1){
1393 tofid = (*iter2)->tofId();
1394 layerid = (*iter2)->layer();
1395 if(layerid==1) tofid=tofid-88;
1397 <<
" TofId = "<<tofid
1398 <<
" barrelid = "<<barrelid
1399 <<
" layerid = "<<layerid
1400 <<
" BackwordADC = "<<(*iter2)->adc2()
1401 <<
" BackwordTDC = "<<(*iter2)->tdc2()
1404 double btdc= (*iter2)->tdc2()-tdiffwest[layerid][tofid];
1405 if(
m_debug==4) cout<<
"barrel 5 ::layer, barrel, tofid, btdc: "<<layerid<<
" , "<<barrelid<<
" , "<<tofid<<
" , "<<btdc<<endl;
1406 double badc= (*iter2)->adc2();
1407 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
1408 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
1409 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
1411 for(
int i=0;i<=ntot;i++){
1412 if(ttof[i]!=0 && btdc>0){
1413 if((tofid_helix[i] == tofid) || (tofid_helix[i] == idntof) ||(tofid_helix[i] == idptof)){
1414 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
1417 cor_evtime= ttof[i] + (238/2 - helztof[i])*0.069 ;
1418 if (optCosmic && tofid<44) {
1419 backevtime = -ttof[i] + (115 + helztof[i])*0.0566 + 12.;
1420 meantevup[ntofup]=backevtime;
1424 backevtime = ttof[i] + (115 + helztof[i])*0.0566 + 12.;
1425 meantevdown[ntofdown]=backevtime;
1429 if(!(*iter2)->adc2() || m_userawtime){
1430 t0backward_trk = btdc - backevtime ;
1433 t0backward_trk = tofCaliSvc->
BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
1435 if(t0backward_trk<-1)
continue;
1436 if(!
m_TofOpt&&nmatch_barrel_2!=0 && fabs((t0backward_trk)-(t0backward_add)/nmatch_barrel_2)>11)
continue;
1437 if(
m_debug == 4) cout<<
"t0backward_trk: "<<t0backward_trk<<endl;
1440 g_t0back[nmatch2] = t0backward_trk ;
1442 if(tofid<44) g_ntofup1++;
1445 meantev[nmatch]=backevtime;
1446 t0backward_add += t0backward_trk;
1447 if(nmatch>499)
break;
1448 Tof_t0Arr[nmatch]=t0backward_trk;
1461 if(nmatch_barrel_1 != 0 ){
1462 t0forward = t0forward_add/nmatch_barrel_1;
1469 if(t_Est<0) t_Est=0;
1478 if(nmatch_barrel_2 != 0 ){
1479 t0backward = t0backward_add/nmatch_barrel_2;
1486 if(t_Est<0) t_Est=0;
1501 if(nmatch_barrel==0){
1502 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
1503 log << MSG::INFO <<
"TOF digit No: " << digiId << endreq;
1505 barrelid=(*iter2)->barrel();
1506 if((*iter2)->barrel()!=0)
continue;
1509 if((*iter2)->times()!=1)
continue;
1510 tofid = (*iter2)->tofId();
1519 if(tofid<48) barrelid=0;
1520 if(tofid>47) barrelid=2;
1521 if(barrelid==2) tofid=tofid-48;
1532 <<
" is_mrpc = " << is_mrpc
1533 <<
" TofId = "<<tofid
1534 <<
" barrelid = "<<barrelid
1536 <<
" ForwordADC = "<< (*iter2)->adc()
1537 <<
" ForwordTDC = "<< (*iter2)->tdc()
1539 double ftdc= (*iter2)->tdc();
1540 double fadc= (*iter2)->adc();
1541 if(
m_debug ==4) cout<<
"endcap::single hit,barrelid,tofid,tdc: "<<barrelid<<
" , "<<tofid<<
" , "<<ftdc<<endl;
1546 int idptof = ((tofid-1) == -1) ? 47 : tofid-1;
1547 int idntof = ((tofid+1) == 48) ? 0 : tofid+1;
1550 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
1551 for(
int i=0;i<=ntot;i++){
1552 if(ttof[i]!=0 && ftdc>0 && ftdc<2000.){
1553 if((tofid_helix[i] == tofid) ||(tofid_helix[i] == idntof) ||(tofid_helix[i] == idptof)){
1556 if(r_endtof[i]>=41 && r_endtof[i]<=90){
1558 if (optCosmic && (tofid<24||(tofid>48&&tofid<71)))
1560 forevtime = -ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;
1561 meantevup[ntofup]=forevtime;
1565 forevtime = ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;
1566 meantevdown[ntofdown]=forevtime;
1569 if(! (*iter2)->adc() || m_userawtime){
1570 t0forward_trk=ftdc-forevtime;
1573 t0forward_trk = tofCaliSvc->
ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
1575 if(!
m_TofOpt&& nmatch_end!=0 &&
abs(t0forward_trk-t0forward_add/nmatch_end)>9)
continue;
1576 meantev[nmatch]=forevtime;
1577 t0forward_add += t0forward_trk;
1578 if(nmatch>499)
break;
1579 Tof_t0Arr[nmatch]=t0forward_trk;
1585 else if(barrelid == 2 ){
1586 if(r_endtof[i]>=41 && r_endtof[i]<=90){
1589 if (optCosmic && ((tofid>24&&tofid<48)||tofid>71))
1590 { forevtime = -ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;
1591 meantevup[ntofup]=forevtime;
1595 forevtime = ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;
1596 meantevdown[ntofdown]=forevtime;
1600 if( ! (*iter2)->adc() || m_userawtime){
1601 t0forward_trk=ftdc-forevtime;
1604 t0forward_trk = tofCaliSvc->
ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
1606 if(t0forward_trk<-1.)
continue;
1607 if( !
m_TofOpt&&nmatch_end!=0 &&
abs(t0forward_trk-t0forward_add/nmatch_end)>9)
continue;
1608 t0forward_add += t0forward_trk;
1610 if(nmatch>499)
break;
1611 Tof_t0Arr[nmatch]=t0forward_trk;
1612 meantev[nmatch]=forevtime/2;
1617 if(
m_debug ==4) cout<<
"t0forward_trk: "<<t0forward_trk<<endl;
1624 else if(is_mrpc==
true)
1626 int idptof = ((tofid-1) == 0) ? 18 : tofid-1;
1628 int idntof = ((tofid+1) == 19) ? 1 : tofid+1;
1633 if(idmatch_mrpc[barrelid][tofid]==1 || idmatch_mrpc[barrelid][idptof]==1 || idmatch_mrpc[barrelid][idntof]==1 || idmatch_mrpc[barrelid][idstof]==1){
1634 for(
int i=0;i<=ntot;i++){
1635 if(ttof_mrpc[i]!=0 && ftdc>0 && ftdc<2000.){
1636 if((tofid_helix[i] == tofid) ||(tofid_helix[i] == idntof) ||(tofid_helix[i] == idptof)){
1640 if(r_endtof_mrpc[i]>=41 && r_endtof_mrpc[i]<=90){
1642 forevtime = ttof_mrpc[i];
1644 t0forward_trk=ftdc-forevtime;
1648 if( nmatch_end!=0 &&
abs(t0forward_trk-t0forward_add/nmatch_end)>9)
continue;
1649 t0forward_add += t0forward_trk;
1651 if(nmatch>499)
break;
1652 Tof_t0Arr[nmatch]=t0forward_trk;
1660 else if(barrelid == 2 ){
1661 if(r_endtof[i]>=41 && r_endtof[i]<=90){
1664 forevtime = ttof_mrpc[i];
1666 t0forward_trk=ftdc-forevtime;
1672 if(t0forward_trk<-1.)
continue;
1673 if( nmatch_end!=0 &&
abs(t0forward_trk-t0forward_add/nmatch_end)>9)
continue;
1674 t0forward_add += t0forward_trk;
1676 if(nmatch>499)
break;
1677 Tof_t0Arr[nmatch]=t0forward_trk;
1692 if(nmatch_end) tof_flag=5;
1695 if((nmatch_barrel==0 && nmatch_end==0)){
1696 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
1697 barrelid=(*iter2)->barrel();
1698 if((*iter2)->barrel()!=0)
continue;
1699 if((*iter2)->times()!=1)
continue;
1700 tofid = (*iter2)->tofId();
1708 if(tofid<48) barrelid=0;
1709 if(tofid>47) barrelid=2;
1710 if(barrelid==2) tofid=tofid-48;
1724 double ftdc= (*iter2)->tdc();
1725 double fadc= (*iter2)->adc();
1729 <<
" is_mrpc = " << is_mrpc
1730 <<
" TofId = "<<tofid
1731 <<
" barrelid = "<<barrelid
1732 <<
" ADC = "<< (*iter2)->adc()
1733 <<
" TDC = "<< (*iter2)->tdc()
1739 int idptof = ((tofid-1) == -1) ? 47 : tofid-1;
1740 int idntof = ((tofid+1) == 48) ? 0 : tofid+1;
1743 if(idmatch_emc[barrelid][tofid]==1||idmatch_emc[barrelid][idptof]==1||idmatch_emc[barrelid][idntof]==1){
1745 for(
int i=0; i<2; i++){
1746 if(zemc_rec[0]||zemc_rec[1]){
1747 if(tofid ==tofid_emc[i] || tofid_emc[i]==idntof || tofid_emc[i]==idptof){
1748 if(ftdc>2000.||module[i]==1)
continue;
1750 r_endtof[i]=sqrt(xemc_rec[i]*xemc_rec[i]+yemc_rec[i]*yemc_rec[i]);
1751 if (optCosmic && ((tofid>24&&tofid<48)||tofid>71))
1753 forevtime = -ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;
1754 meantevup[ntofup]=forevtime;
1758 forevtime = ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;
1759 meantevdown[ntofdown]=forevtime;
1763 if(!(*iter2)->adc() || m_userawtime){
1764 t0forward_trk=ftdc-forevtime;
1767 t0forward_trk = tofCaliSvc->
ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
1768 if(
m_debug ==4) cout<<
"emc flag t0forward_trk: "<<t0forward_trk<<endl;
1770 if(t0forward_trk<-1.)
continue;
1771 if(!
m_TofOpt&& nmatch_end!=0 &&
abs(t0forward_trk-t0forward_add/nmatch_end)>9)
continue;
1772 meantev[nmatch]=forevtime;
1773 t0forward_add += t0forward_trk;
1775 if(nmatch>499)
break;
1776 Tof_t0Arr[nmatch]=t0forward_trk;
1786 else if(is_mrpc==
true)
1789 int idptof = ((tofid-1) == 0) ? 18 : tofid-1;
1791 int idntof = ((tofid+1) == 19) ? 1 : tofid+1;
1795 if(idmatch_emc_mrpc[barrelid][tofid]==1||idmatch_emc_mrpc[barrelid][idptof]==1||idmatch_emc_mrpc[barrelid][idntof]==1){
1797 for(
int i=0; i<2; i++){
1798 if(zemc_rec[0]||zemc_rec[1]){
1799 if(tofid ==tofid_emc_mrpc[i] || tofid_emc_mrpc[i]==idntof || tofid_emc_mrpc[i]==idptof){
1800 if(ftdc>2000.||module[i]==1)
continue;
1802 r_endtof_mrpc[i]=sqrt(xemc_rec[i]*xemc_rec[i]+yemc_rec[i]*yemc_rec[i]);
1805 forevtime = ttof_mrpc[i];
1806 t0forward_trk=ftdc-forevtime;
1808 if(t0forward_trk<-1.)
continue;
1809 if( nmatch_end!=0 &&
abs(t0forward_trk-t0forward_add/nmatch_end)>9)
continue;
1810 t0forward_add += t0forward_trk;
1812 if(nmatch>499)
break;
1813 Tof_t0Arr[nmatch]=t0forward_trk;
1827 if(nmatch_end) tof_flag=5;
1830 if(nmatch_barrel ==0 && nmatch_end ==0){
1831 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
1832 log << MSG::INFO <<
"TOF digit No: " << digiId << endreq;
1834 barrelid=(*iter2)->barrel();
1835 if((*iter2)->barrel()!=0)
continue;
1838 if( (*iter2)->times()>1 && (*iter2)->times()<5 ){
1839 tofid = (*iter2)->tofId();
1846 if(tofid<48) barrelid=0;
1847 if(tofid>47) barrelid=2;
1848 if(barrelid==2) tofid=tofid-48;
1863 <<
" TofId = "<<tofid
1864 <<
" barrelid = "<<barrelid
1866 <<
" ForwordADC = "<< (*iter2)->adc()
1867 <<
" ForwordTDC = "<< (*iter2)->tdc()
1869 double ftdc= (*iter2)->tdc();
1870 if(
m_debug ==4) cout<<
"endcap::multi hit,barrelid,tofid,tdc: "<<barrelid<<
" , "<<tofid<<
" , "<<ftdc<<endl;
1871 double fadc= (*iter2)->adc();
1875 int idptof = ((tofid-1) == -1) ? 47 : tofid-1;
1876 int idntof = ((tofid+1) == 48) ? 0 : tofid+1;
1879 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
1880 for(
int i=0;i<=ntot;i++){
1881 if(ttof[i]!=0 && ftdc>0){
1882 if((tofid_helix[i] == tofid) ||(tofid_helix[i] == idntof) ||(tofid_helix[i] == idptof)){
1885 if(r_endtof[i]>=41 && r_endtof[i]<=90){
1887 if (optCosmic && (tofid<24||(tofid>48&&tofid<71)))
1888 { forevtime = -ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;
1889 meantevup[ntofup]=forevtime;
1893 forevtime = ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;
1894 meantevdown[ntofdown]=forevtime;
1898 if(!(*iter2)->adc() || m_userawtime){
1899 t0forward_trk=ftdc-forevtime;
1902 t0forward_trk = tofCaliSvc->
ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
1904 if(!
m_TofOpt&& nmatch_end!=0 &&
abs(t0forward_trk-t0forward_add/nmatch_end)>9)
continue;
1905 meantev[nmatch]=forevtime;
1906 t0forward_add += t0forward_trk;
1908 if(nmatch>499)
break;
1909 Tof_t0Arr[nmatch]=t0forward_trk;
1914 else if(barrelid == 2 ){
1915 if(r_endtof[i]>=41 && r_endtof[i]<=90){
1918 if (optCosmic && ((tofid>24&&tofid<48)||tofid>71))
1920 forevtime = -ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;
1921 meantevup[ntofup]=forevtime;
1925 forevtime = ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;
1926 meantevdown[ntofdown]=forevtime;
1930 if(!(*iter2)->adc() || m_userawtime){
1931 t0forward_trk=ftdc-forevtime;
1934 t0forward_trk = tofCaliSvc->
ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
1936 if(t0forward_trk<-1.)
continue;
1937 if(!
m_TofOpt&& nmatch_end!=0 &&
abs(t0forward_trk-t0forward_add/nmatch_end)>9)
continue;
1938 meantev[nmatch]=forevtime;
1939 t0forward_add += t0forward_trk;
1941 if(nmatch>499)
break;
1942 Tof_t0Arr[nmatch]=t0forward_trk;
1947 if(
m_debug == 4 ) cout<<
"t0forward_trk: "<<t0forward_trk<<endl;
1953 else if(is_mrpc==
true)
1956 int idptof = ((tofid-1) == 0) ? 18 : tofid-1;
1958 int idntof = ((tofid+1) == 19) ? 1 : tofid+1;
1962 if(idmatch_mrpc[barrelid][tofid]==1||idmatch_mrpc[barrelid][idptof]==1||idmatch_mrpc[barrelid][idntof]==1){
1964 for(
int i=0;i<=ntot;i++){
1965 if(ttof_mrpc[i]!=0 && ftdc>0){
1966 if((tofid_helix[i] == tofid) ||(tofid_helix[i] == idntof) ||(tofid_helix[i] == idptof)){
1968 if(r_endtof_mrpc[i]>=41 && r_endtof_mrpc[i]<=90){
1971 forevtime = ttof_mrpc[i];
1972 t0forward_trk=ftdc-forevtime;
1973 if( nmatch_end!=0 &&
abs(t0forward_trk-t0forward_add/nmatch_end)>9)
continue;
1974 t0forward_add += t0forward_trk;
1976 if(nmatch>499)
break;
1977 Tof_t0Arr[nmatch]=t0forward_trk;
1985 else if(barrelid == 2 ){
1986 if(r_endtof[i]>=41 && r_endtof[i]<=90){
1987 forevtime = ttof_mrpc[i];
1989 t0forward_trk=ftdc-forevtime;
1991 if(t0forward_trk<-1.)
continue;
1992 if( nmatch_end!=0 &&
abs(t0forward_trk-t0forward_add/nmatch_end)>9)
continue;
1995 t0forward_add += t0forward_trk;
1996 if(nmatch>499)
break;
1997 Tof_t0Arr[nmatch]=t0forward_trk;
2014 if(nmatch_end) tof_flag=7;
2017 g_nmatchbarrel=nmatch_barrel;
2018 g_nmatchbarrel_1=nmatch_barrel_1;
2019 g_nmatchbarrel_2=nmatch_barrel_2;
2020 g_nmatchend=nmatch_end;
2024 t0forward = t0forward_add/nmatch_end;
2048 if(t_Est<0) t_Est=0;
2049 if(tof_flag==5) tEstFlag=151;
2050 else if(tof_flag==7) tEstFlag=171;
2051 if(emcflag2==1) tEstFlag=161;
2063 if(tof_flag==5) tEstFlag=251;
2064 else if(tof_flag==7) tEstFlag=271;
2065 if(emcflag2==1) tEstFlag=261;
2071 double t0_comp=-999;
2074 if(nmatch_barrel==0 && nmatch_end==0 &&
m_flag==1){
2075 double mhit[43][300]={0.};
2076 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc(),
"/Event/Digi/MdcDigiCol");
2078 log << MSG::INFO<<
"Could not find MDC digi" << endreq;
2079 return StatusCode::FAILURE;
2083 StatusCode sc = service(
"MdcGeomSvc", mdcGeomSvc);
2084 if (sc != StatusCode::SUCCESS) {
2085 return StatusCode::FAILURE;
2088 MdcDigiCol::iterator iter1 = mdcDigiCol->begin();
2094 for (;iter1 != mdcDigiCol->end(); iter1++, digiId++) {
2095 mdcId = (*iter1)->identify();
2100 mhit[layerId][wireId]-=1.28*(mdcGeomSvc->
Layer(layerId)->Radius())/299.8;
2102 mdcGeomSvc->
Wire(layerId,wireId);
2108 int Iused[43][300]={0},tmp=0;
2109 bool Lpat,Lpat11,Lpat12,Lpat2,Lpat31,Lpat32;
2110 double t0_all=0,t0_mean=0;
2113 double phi[4]={0.},corr[4]={0.},driftt[4]={0.};
2115 double mchisq=50000;
2118 for(
int i=5;i<10;i++){
2120 double T1=0.5*0.1*(mdcGeomSvc->
Layer(4*i+0)->PCSiz())/0.004;
2121 double T2=0.5*0.1*(mdcGeomSvc->
Layer(4*i+1)->PCSiz())/0.004;
2122 double T3=0.5*0.1*(mdcGeomSvc->
Layer(4*i+2)->PCSiz())/0.004;
2123 double T4=0.5*0.1*(mdcGeomSvc->
Layer(4*i+3)->PCSiz())/0.004;
2124 r[0]=(mdcGeomSvc->
Layer(4*i+0)->Radius())*0.1;
2125 r[1]=(mdcGeomSvc->
Layer(4*i+1)->Radius())*0.1;
2126 r[2]=(mdcGeomSvc->
Layer(4*i+2)->Radius())*0.1;
2127 r[3]=(mdcGeomSvc->
Layer(4*i+3)->Radius())*0.1;
2128 double r0=r[0]-r[1]-(r[2]-r[1])/2;
2129 double r1=-(r[2]-r[1])/2;
2130 double r2=(r[2]-r[1])/2;
2131 double r3=r[3]-r[2]+(r[2]-r[1])/2;
2133 for(
int j=0;j<mdcGeomSvc->
Layer(i*4+3)->NCell();j++){
2137 if(Icp<0) Icp=mdcGeomSvc->
Layer(i*4+3)->
NCell();
2139 Lpat=(mhit[4*i][j]!=0) && (mhit[4*i][Icp]==0) &&( mhit[4*i][j+1]==0) && (Iused[4*i][j]==0);
2144 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);
2145 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);
2146 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);
2147 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);
2148 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);
2150 if(Lpat11 && Lpat2 && Lpat31 ){
2156 double t_i = mhit[4*i+0][j]+mhit[4*i+2][j];
2157 double t_j = mhit[4*i+1][j]+mhit[4*i+3][j];
2161 double r_2k= r0*r0+r1*r1+r2*r2+r3*r3;
2162 double rt_i = r0*mhit[4*i+0][j]+r2*mhit[4*i+2][j];
2163 double rt_j = r1*mhit[4*i+1][j]+r3*mhit[4*i+3][j];
2164 double rl_j = r1*T2+r3*T4;
2166 double deno= 4*r_2k-2*(r_i*r_i+r_j*r_j);
2169 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;
2170 double Pb= 0.25*(t_i-t_j+l_j-(r_i+r_j) * Pa);
2171 double Ang=fabs(90.-fabs(atan(Pa)*180./3.141593));
2173 t0_all+= (-0.25*((r_i-r_j)*Pa-t_i-t_j+l_j));
2176 for(
int t0c=0;t0c<17;t0c+=8){
2177 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);
2187 for(
int tmpT0=0;tmpT0<17;tmpT0+=8){
2188 driftt[0]=mhit[4*i+0][j]-tmpT0;
2189 driftt[1]=mhit[4*i+1][j]-tmpT0;
2190 driftt[2]=mhit[4*i+2][j]-tmpT0;
2191 driftt[3]=mhit[4*i+3][j]-tmpT0;
2193 phi[0]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4)->NCell())+2*3.14159265/(mdcGeomSvc->
Layer(i*4+1)->NCell())/2;
2194 phi[1]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4+1)->NCell());
2195 phi[2]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4+2)->NCell())+2*3.14159265/(mdcGeomSvc->
Layer(i*4+1)->NCell())/2;
2196 phi[3]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4+3)->NCell());
2197 phi[0]-=ambig*driftt[0]*0.004/r[0];
2198 phi[1]+=ambig*driftt[1]*0.004/r[1];
2199 phi[2]-=ambig*driftt[2]*0.004/r[2];
2200 phi[3]+=ambig*driftt[3]*0.004/r[3];
2201 double s1, sx, sy, sxx, sxy;
2202 double delinv, denom;
2211 s1 = sx = sy = sxx = sxy = 0.0;
2213 for (
int ihit = 0; ihit < 4; ihit++) {
2214 weight = 1. / (sigma * sigma);
2217 sy += phi[ihit] *
weight;
2218 sxx +=
x[ihit] * (
x[ihit] *
weight);
2219 sxy += phi[ihit] * (
x[ihit] *
weight);
2221 double resid[4]={0.};
2223 denom = s1 * sxx - sx * sx;
2224 delinv = (denom == 0.0) ? 1.e20 : 1. / denom;
2225 double intercept = (sy * sxx - sx * sxy) * delinv;
2226 double slope = (s1 * sxy - sx * sy) * delinv;
2229 for (
int ihit = 0; ihit < 4; ihit++) {
2230 resid[ihit] = ( phi[ihit] - intercept - slope *
x[ihit] );
2231 chisq += resid[ihit] * resid[ihit]/(sigma*sigma) ;
2239 if(Lpat12 && Lpat2 && Lpat32){
2241 Iused[4*i+1][j+1]=1;
2243 Iused[4*i+3][j+1]=1;
2245 double t_i = mhit[4*i+0][j]+mhit[4*i+2][j];
2246 double t_j = mhit[4*i+1][j+1]+mhit[4*i+3][j+1];
2250 double r_2k= r0*r0+r1*r1+r2*r2+r3*r3;
2251 double rt_i = r0*mhit[4*i+0][j]+r2*mhit[4*i+2][j];
2252 double rt_j = r1*mhit[4*i+1][j+1]+r3*mhit[4*i+3][j+1];
2253 double rl_j = r1*T2+r3*T4;
2254 double deno= 4*r_2k-2*(r_i*r_i+r_j*r_j);
2257 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;
2258 double Pb= 0.25*(t_i-t_j+l_j-(r_i+r_j) * Pa);
2259 double Ang=fabs(90.-fabs(atan(Pa)*180./3.141593));
2260 t0_all+= (-0.25*((r_i-r_j)*Pa-t_i-t_j+l_j));
2264 for(
int t0c=0;t0c<17;t0c+=8){
2265 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);
2276 for(
int tmpT0=0;tmpT0<17;tmpT0+=8){
2277 driftt[0]=mhit[4*i+0][j]-tmpT0;
2278 driftt[1]=mhit[4*i+1][j+1]-tmpT0;
2279 driftt[2]=mhit[4*i+2][j]-tmpT0;
2280 driftt[3]=mhit[4*i+3][j+1]-tmpT0;
2282 phi[0]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4)->NCell())+2*3.14159265/(mdcGeomSvc->
Layer(i*4+1)->NCell())/2;
2283 phi[1]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4+1)->NCell());
2284 phi[2]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4+2)->NCell())+2*3.14159265/(mdcGeomSvc->
Layer(i*4+1)->NCell())/2;
2285 phi[3]=j*2*3.14159265/(mdcGeomSvc->
Layer(i*4+3)->NCell());
2286 phi[0]-=ambig*driftt[0]*0.004/r[0];
2287 phi[1]+=ambig*driftt[1]*0.004/r[1];
2288 phi[2]-=ambig*driftt[2]*0.004/r[2];
2289 phi[3]+=ambig*driftt[3]*0.004/r[3];
2290 double s1, sx, sy, sxx, sxy;
2291 double delinv, denom;
2300 s1 = sx = sy = sxx = sxy = 0.0;
2302 for (
int ihit = 0; ihit < 4; ihit++) {
2303 weight = 1. / (sigma * sigma);
2306 sy += phi[ihit] *
weight;
2307 sxx +=
x[ihit] * (
x[ihit] *
weight);
2308 sxy += phi[ihit] * (
x[ihit] *
weight);
2310 double resid[4]={0.};
2312 denom = s1 * sxx - sx * sx;
2313 delinv = (denom == 0.0) ? 1.e20 : 1. / denom;
2314 double intercept = (sy * sxx - sx * sxy) * delinv;
2315 double slope = (s1 * sxy - sx * sy) * delinv;
2318 for (
int ihit = 0; ihit < 4; ihit++) {
2319 resid[ihit] = ( phi[ihit] - intercept - slope *
x[ihit] );
2320 chisq += resid[ihit] * resid[ihit]/(sigma*sigma) ;
2338 t_Est=T0 + tOffset_b;
2345 if(nmatch_barrel==0 && nmatch_end==0 && nmatch_barrel_1==0&&nmatch_barrel_2==0&&m_mdcCalibFunSvc&&
m_flag==2){
2347 log << MSG::INFO <<
" mdc " << endreq;
2367 double t0_minus_TDC[
MXWIRE];
2370 double Mdc_t0Arr[500];
2384 SmartDataPtr<RecMdcTrackCol> newtrkCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
2385 if (!newtrkCol || newtrkCol->size()==0) {
2386 log << MSG::INFO<<
"Could not find RecMdcTrackCol" << endreq;
2387 return StatusCode::SUCCESS;
2389 log << MSG::INFO <<
"Begin to check RecMdcTrackCol"<<endreq;
2391 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
2393 for(
int tempntrack=0; iter_trk != newtrkCol->end(); iter_trk++,tempntrack++) {
2394 log << MSG::DEBUG <<
"retrieved MDC track:"
2395 <<
" Track Id: " << (*iter_trk)->trackId()
2396 <<
" Dr: " <<(*iter_trk)->helix(0)
2397 <<
" Phi0: " << (*iter_trk)->helix(1)
2398 <<
" kappa: " << (*iter_trk)->helix(2)
2399 <<
" Dz: " << (*iter_trk)->helix(3)
2400 <<
" Tanl: " << (*iter_trk)->helix(4)
2401 <<
" Phi terminal: "<< (*iter_trk)->getFiTerm()
2403 <<
"Number of hits: "<< (*iter_trk)->getNhits()
2404 <<
" Number of stereo hits " << (*iter_trk)->nster()
2411 a[0] = (*iter_trk)->helix(0);
2412 a[1] = (*iter_trk)->helix(1);
2413 a[2] = (*iter_trk)->helix(2);
2414 a[3] = (*iter_trk)->helix(3);
2415 a[4] = (*iter_trk)->helix(4);
2421 double kappa =
abs(a[2]);
2422 double dirmag = sqrt(1. + a[4]*a[4]);
2424 double mom =
abs(dirmag/kappa);
2425 double beta=mom/sqrt(mom*mom+
PIMAS2);
2426 if (particleId[tempntrack]== 1) { beta=mom/sqrt(mom*mom+
ELMAS2);}
2427 if(particleId[tempntrack]== 5) { beta=mom/sqrt(mom*mom+
PROTONMAS2);}
2430 Helix helix0(pivot0,a);
2431 double rho = helix0.
radius();
2432 double unit_s =
abs(rho * dirmag);
2439 if( xc==0.0 && yc==0.0 )
continue;
2441 double direction =1.;
2444 if(phi> 0. && phi <=
M_PI) direction=-1.;
2448 StatusCode sc = service(
"MdcGeomSvc", mdcGeomSvc);
2451 double m_vp[43]={0.}, m_zst[43]={0.};
2452 for(
int lay=0; lay<43; lay++){
2457 if(lay < 8) m_vp[lay] = 220.0;
2458 else m_vp[lay] = 240.0;
2460 if( 0 == (lay % 2) ){
2468 log << MSG::DEBUG <<
"hitList of this track:" << endreq;
2469 HitRefVec gothits = (*iter_trk)->getVecHits();
2470 HitRefVec::iterator it_gothit = gothits.begin();
2471 for( ; it_gothit != gothits.end(); it_gothit++){
2473 log << MSG::DEBUG <<
"hits Id: "<<(*it_gothit)->getId()
2474 <<
" hits MDC layerId wireId " <<
MdcID::layer((*it_gothit)->getMdcId())
2477 <<
" hits TDC " <<(*it_gothit)->getTdc()
2482 double tdc=(*it_gothit)->getTdc() ;
2484 double trkchi2=(*iter_trk)->chi2();
2485 if(trkchi2>100)
continue;
2486 double hitChi2=(*it_gothit)->getChisqAdd();
2487 HepVector helix_par = (*iter_trk)->helix();
2488 HepSymMatrix helixErr=(*iter_trk)->err();
2490 if((layer>=8&&layer<=19) ||(layer>=36&&layer<=42)){
2506 if(Estparam.
MDC_Inner()==0 && layer <=3)
continue;
2508 double xw = GeoRef->
Forward().x()/10;
2509 double yw = GeoRef->
Forward().y()/10;
2512 helix0.
pivot(pivot1);
2513 double zw=helix0.
a()[3];
2516 double dphi = (-xc*(xw-xc)-yc*(yw-yc)) /
2517 sqrt((xc*xc+yc*yc)*((xw-xc)*(xw-xc)+(yw-yc)*(yw-yc)));
2519 double pathtof =
abs(unit_s * dphi);
2521 toft = pathtof/
VLIGHT/beta;
2531 if (zw <(GeoRef->
Forward().z())/10) zw =(GeoRef->
Forward().z())/10;
2533 double slant = GeoRef ->
Slant();
2550 pos[0]=xw; pos[1]=yw;
2557 dist=(m_mdcUtilitySvc->
doca(layer, wid, helix_par, helixErr))*10.0;
2562 if(dist> 0.4*(mdcGeomSvc->
Layer(layer))->PCSiz())
continue;
2584 double entrance=(*it_gothit)->getEntra();
2585 driftt = m_mdcCalibFunSvc->
distToDriftTime(dist, layer, wid,lr,entrance);
2589 T0_cal=m_mdcCalibFunSvc->
getT0(layer, wid)+m_mdcCalibFunSvc->
getTimeWalk(layer,tdc);
2592 double zprop = fabs(zw - m_zst[layer]);
2593 double tp = zprop / m_vp[layer];
2595 if(driftt>tdc)
continue;
2596 double difft=tdc-driftt-toft-tp-T0_cal;
2597 if(ndriftt>=500)
break;
2598 if(
difft<-10)
continue;
2599 Mdc_t0Arr[ndriftt]=
difft;
2601 sum_EstimeMdc=sum_EstimeMdc+
difft;
2612 double tev= -t0_minus_TDC[wid]+ driftt;
2613 if(Estparam.
MDC_Tof() !=0) tev += direction*toft;
2614 if(Estparam.
MDC_Prop()!=0) tev += prop;
2620 tev_ax[nhits_ax-1]=tev;
2622 if(Estparam.
MDC_Debug()!=0) log << MSG::INFO <<
"*** tev ***" <<tev <<endreq;
2623 double driftt_mea = t0_minus_TDC[wid];
2625 if(
abs(driftt - driftt_mea)<75.) {
2628 if(Estparam.
MDC_Debug()!=0) log << MSG::INFO <<
"*** tev2 ***" <<tev <<endreq;
2633 else if(((layer>=4&&layer<=7)||(layer>=20&&layer<=35))&&
m_useSw){
2636 StatusCode sc = service(
"MdcGeomSvc", mdcGeomSvc);
2642 double bx= GeoRef->
Backward().x()/10;
2643 double by= GeoRef->
Backward().y()/10;
2644 double bz= GeoRef->
Backward().z()/10;
2645 double fx= GeoRef->
Forward().x()/10;
2646 double fy= GeoRef->
Forward().y()/10;
2647 double fz= GeoRef->
Forward().z()/10;
2654 Hep3Vector wire = (CLHEP::Hep3Vector)bck - (CLHEP::Hep3Vector)fwd;
2657 HepPoint3D try2 = (helix0.
x(0).z() - bck.z())/ wire.z() * wire + bck;
2659 HepPoint3D try3 = (helix0.
x(0).z() - bck.z())/ wire.z() * wire + bck;
2662 double xh = helix0.
x(0.).x();
2663 double yh = helix0.
x(0.).y();
2664 double z = helix0.
x(0.).z();
2667 double dphi = (-xc*(xh-xc)-yc*(yh-yc)) /
2668 sqrt((xc*xc+yc*yc)*((xh-xc)*(xh-xc)+(yh-yc)*(yh-yc)));
2670 double pathtof =
abs(unit_s * dphi);
2672 toft = pathtof/
VLIGHT/beta;
2684 double slant = GeoRef->
Slant();
2700 double xw = fx + (bx-fx)/(bz-fz)*(z-fz);
2701 double yw = fy + (by-fy)/(bz-fz)*(z-fz);
2704 helix0.
pivot(pivot1);
2706 double zw=helix0.
a()[3];
2714 pos[0]=xw; pos[1]=yw;
2721 dist=(m_mdcUtilitySvc->
doca(layer, wid, helix_par, helixErr))*10.0;
2726 if(dist> 0.4*(mdcGeomSvc->
Layer(layer))->PCSiz())
continue;
2746 double entrance=(*it_gothit)->getEntra();
2747 driftt = m_mdcCalibFunSvc->
distToDriftTime(dist, layer, wid,lr,entrance);
2751 T0_cal=m_mdcCalibFunSvc->
getT0(layer, wid)+m_mdcCalibFunSvc->
getTimeWalk(layer,tdc);
2754 double zprop = fabs(zw - m_zst[layer]);
2755 double tp = zprop / m_vp[layer];
2757 if(driftt>tdc)
continue;
2758 double difft=tdc-driftt-toft-tp-T0_cal;
2759 if(
difft<-10)
continue;
2760 if(ndriftt>=500)
break;
2761 Mdc_t0Arr[ndriftt]=
difft;
2765 sum_EstimeMdc=sum_EstimeMdc+
difft;
2771 double tev= -t0_minus_TDC[wid]+ driftt;
2772 if(Estparam.
MDC_Tof() !=0) tev += direction*toft;
2773 if(Estparam.
MDC_Prop()!=0) tev += prop;
2781 tev_st[nhits_st-1]= tev;
2783 if(Estparam.
MDC_Debug()!=0) log << MSG::INFO <<
"*** tev_st ***" <<tev <<endreq;
2784 double driftt_mea = t0_minus_TDC[wid];
2786 if(
abs(driftt - driftt_mea) <75.) {
2789 if(Estparam.
MDC_Debug()!=0) log << MSG::INFO <<
"*** tev_st2 ***" <<tev <<endreq;
2801 sum_EstimeMdc=Opt_new(Mdc_t0Arr,ndriftt,400.0);
2803 else { sum_EstimeMdc= sum_EstimeMdc/ndriftt;}
2804 if(
m_ntupleflag && m_tuple2) g_EstimeMdc=sum_EstimeMdc;
2805 t_Est=sum_EstimeMdc + tOffset_b;
2806 if(t_Est<0) t_Est=0;
2809 nbunch=((int)(t_Est-offset))/bunchtime;
2811 if((t_Est-offset-nbunch*bunchtime)>(bunchtime/2)) nbunch=nbunch+1;
2812 t_Est=nbunch*bunchtime+offset + tOffset_b;
2823 t_Est=sum_EstimeMdc;
2832 if((!
m_beforrec) && (Testime_fzisan != t_Est) ){
2833 if(tEstFlag==211) tEstFlag=213;
2834 if(tEstFlag==212) tEstFlag=216;
2835 if(tEstFlag==111) tEstFlag=113;
2836 if(tEstFlag==112) tEstFlag=116;
2840 StatusCode scStoreTds = storeTDS(t_Est,tEstFlag,t_quality);
2841 if (scStoreTds!=StatusCode::SUCCESS){
return scStoreTds; }
2842 }
else if(!optCosmic){
2843 StatusCode scStoreTds = storeTDS(t_Est,tEstFlag,t_quality);
2844 if (scStoreTds!=StatusCode::SUCCESS){
return scStoreTds; }
2851 double segTest = Testime_fzisan + tOffset_b;
2852 int segFlag = TestimeFlag_fzisan;
2853 double segQuality = TestimeQuality_fzisan;
2854 StatusCode scStoreTds = storeTDS(segTest,segFlag,segQuality);
2855 if (scStoreTds!=StatusCode::SUCCESS){
return scStoreTds; }
2861 SmartDataPtr<RecEsTimeCol> arecestimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
2862 if (!arecestimeCol) {
2863 if(
m_debug==4) log << MSG::WARNING <<
"Could not find RecEsTimeCol" << endreq;
2864 return( StatusCode::SUCCESS);
2866 RecEsTimeCol::iterator iter_evt = arecestimeCol->begin();
2867 for(; iter_evt!=arecestimeCol->end(); iter_evt++){
2869 <<
"Test = "<<(*iter_evt)->getTest()
2870 <<
", Status = "<<(*iter_evt)->getStat()
2873 g_Testime=(*iter_evt)->getTest();
2880 for(g_ntofdown=0;g_ntofdown<ntofdown;g_ntofdown++){ g_meantevdown[g_ntofdown]=meantevdown[g_ntofdown];}
2881 for(g_ntofup=0;g_ntofup<ntofup;g_ntofup++){ g_meantevup[g_ntofup]=meantevup[g_ntofup];}
2882 g_nmatch_tot=nmatch;
2885 StatusCode status = m_tuple2->write();
2886 if (!status.isSuccess()) {
2887 log << MSG::ERROR <<
"Can't fill ntuple!" << endreq;
2891 for(g_nmatch=0;g_nmatch<nmatch;g_nmatch++)
2893 g_meantev[g_nmatch]=meantev[g_nmatch];
2895 StatusCode status = m_tuple9->write();
2896 if (!status.isSuccess()) {
2897 log << MSG::ERROR <<
"Can't fill ntuple!" << endreq;
2901 return StatusCode::SUCCESS;