00270 {
00271
00272 MsgStream log(msgSvc(), name());
00273 log << MSG::INFO << " tof " << endreq;
00274
00275
00276 EstParameter Estparam;
00277 double calmdc_par_=0;
00278 double offset=0, t_quality=0, offset_dt=0, offset_dt_end=0, tOffset_b=0, tOffset_e=0;
00279 int idtof , tofid_helix[30],idmatch[3][88]={0},idmatch_emc[3][88]={0} ,idt[15]={0},particleId[30]={0}, tofid_emc[2]={0}, module[20]={0};
00280 int ntot=0,nmat=0,in=-1,out=-1, emcflag1=0, emcflag2=0, tof_flag=0, bunchtime=8;
00281 double meant[15]={0.},adc[15]={0.}, momentum[15]={0.},r_endtof[10]={0.};
00282 double ttof[30]={0.},helztof[30],mcztof,forevtime,backevtime;
00283 double t0forward=0,t0backward=0,t0forward_trk=0,t0backward_trk=0;
00284 double t0forward_add=0,t0backward_add=0,t_Est=-999;
00285 double cor_evtime,corev[15],tmp_time=0.;
00286 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.};
00287 int nmatch1=0,nmatch2=0,nmatch_barrel=0,nmatch_end=0,nmatch_mdc=0, nmatch_barrel_1=0, nmatch_barrel_2=0;
00288 double sum_EstimeMdc=0,sum_EstimeMdcMC=0;
00289 int nbunch=0,tEstFlag=0, runNo=0;
00290 double helpath[88]={0.},helz[88]={0.},abmom2[88]={0.};
00291 double help[15]={0.}, abp2[15]={0.};
00292 double pt[88]={0.},dr[88]={0.},dz[88]={0.};
00293 double phi[88]={0.},tanl[88]={0.};
00294 double mcTestime=0,trigtiming=0;
00295 double tdiffeast[2][88]={0.};
00296 double tdiffwest[2][88]={0.};
00297 double mean_tdc_btof[2][88]={0.}, mean_tdc_etof[3][48]={0.};
00298 int optCosmic=m_optCosmic;
00299 double Testime_fzisan= -999.;
00300 int TestimeFlag_fzisan= -999;
00301 double TestimeQuality_fzisan= -999.;
00302 double toffset_rawtime=0, toffset_rawtime_e=0;
00303
00304
00305
00306 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
00307 if (!eventHeader) {
00308 log << MSG::FATAL << "Could not find Event Header" << endreq;
00309 return StatusCode::FAILURE;
00310 }
00311 log << MSG::INFO << "EsTimeAlg: retrieved event: " << eventHeader->eventNumber() << " run: " << eventHeader->runNumber() << endreq;
00312 int eventNo=eventHeader->eventNumber();
00313 runNo=eventHeader->runNumber();
00314 if(m_ntupleflag && m_tuple2){g_runNo=runNo; g_eventNo=eventNo;}
00315 if(runNo<0) { offset_dt=0; offset_dt_end=0;}
00316 if(runNo>0 && runNo<5336) offset_dt=5.8;
00317 if(runNo>5462 && runNo<5466){ offset_dt=1.6; offset_dt_end=0.4;}
00318 if(runNo>5538 && runNo<5920){ offset_dt=-0.2; offset_dt_end=-1.2;}
00319 if(runNo>5924 && runNo<6322){ offset_dt=-0.2; offset_dt_end=-0.1;}
00320 if(runNo>6400 && runNo<6423){ offset_dt=-2.4; offset_dt_end=-1.9;}
00321 if(runNo>6514 && runNo<6668){ offset_dt=0; offset_dt_end=3.4;}
00322 if(runNo>6667 && runNo<6715){ offset_dt=4; offset_dt_end=7.2;}
00323 if(runNo>6715 && runNo<6720){ offset_dt=8; offset_dt_end=7.5;}
00324 if(runNo>6879 && runNo<6909){ offset_dt=0.2; offset_dt_end=-0.1;}
00325 if(runNo>6909) { offset_dt=0; offset_dt_end=0;}
00326 if(m_ntupleflag && m_tuple3){
00327 g_bunchtime=8;
00328 g_t0offset_b=2.0;
00329 g_t0offset_e=2.0;
00330 }
00331
00332 m_pass[0]++;
00333 if(m_evtNo==1 && m_pass[0]%1000 ==0){
00334 cout<<"------------------- Events-----------------: "<<m_pass[0]<<endl;
00335 }
00336 if(m_debug==4) cout<<"m_userawtime: "<<m_userawtime<<endl;
00337 if(m_debug==4) cout<<"EstTofCalibSvc est flag: "<<tofCaliSvc->ValidInfo()<<endl;
00338 if(tofCaliSvc->ValidInfo()==0) m_userawtime=1;
00339 else m_userawtime=0;
00340
00341 SmartDataPtr<RecEsTimeCol> aRecestimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
00342 if (!aRecestimeCol || aRecestimeCol->size()==0) {
00343 if(m_debug==4) log << MSG::INFO << "Could not find RecEsTimeCol from fzsian" << endreq;
00344 }else{
00345 RecEsTimeCol::iterator it_evt = aRecestimeCol->begin();
00346 for(; it_evt!=aRecestimeCol->end(); it_evt++){
00347 Testime_fzisan = (*it_evt)->getTest();
00348 TestimeFlag_fzisan = (*it_evt)->getStat();
00349 TestimeQuality_fzisan = (*it_evt)->getQuality();
00350
00351 log << MSG::INFO << "fzisan : Test = "<<(*it_evt)->getTest()
00352 << ", Status = "<<(*it_evt)->getStat() <<endreq;
00353
00354 if(m_ntupleflag && m_tuple2) g_Testime_fzisan = Testime_fzisan;
00355 }}
00356
00357
00358 std::string fullPath = "/Calib/EsTimeCal";
00359 SmartDataPtr<CalibData::EsTimeCalibData> TEst(m_pCalibDataSvc, fullPath);
00360 if(!TEst){ cout<<"ERROR EsTimeCalibData"<<endl;}
00361 else{
00362 int no = TEst->getTestCalibConstNo();
00363
00364
00365
00366
00367 log<<MSG::INFO<<"offset barrel t0="<< TEst->getToffsetb()
00368 <<", offset endcap t0="<< TEst->getToffsete()
00369 <<", bunch time ="<<TEst->getBunchTime()
00370 <<endreq;
00371 tOffset_b=TEst->getToffsetb();
00372 tOffset_e=TEst->getToffsete();
00373 bunchtime=TEst->getBunchTime();
00374 }
00375 if(m_userawtime) {
00376 toffset_rawtime=1.6;
00377 toffset_rawtime_e=5.6;
00378 tOffset_b=0;
00379 tOffset_e=0;
00380 }
00381
00382 int digiId;
00383
00384 if(runNo<0){
00385 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),"/Event/MC/McParticleCol");
00386 if (!mcParticleCol) {
00387 log << MSG::WARNING<< "Could not find McParticle" << endreq;
00388 }
00389 else{
00390 McParticleCol::iterator iter_mc = mcParticleCol->begin();
00391 digiId = 0;
00392 ntrkMC = 0;
00393 int charge = 0;
00394
00395 for (;iter_mc != mcParticleCol->end(); iter_mc++, digiId++) {
00396 int statusFlags = (*iter_mc)->statusFlags();
00397 int pid = (*iter_mc)->particleProperty();
00398
00399 log << MSG::INFO
00400 << " MC ParticleId = " << pid
00401 << " statusFlags = " << statusFlags
00402 << " PrimaryParticle = " <<(*iter_mc)->primaryParticle()
00403 << endreq;
00404 if(m_ntupleflag && m_tuple2){
00405 g_theta0MC[ntrkMC] = (*iter_mc)->initialFourMomentum().theta();
00406 g_phi0MC[ntrkMC] = (*iter_mc)->initialFourMomentum().phi();
00407 g_pxMC[ntrkMC] = (*iter_mc)->initialFourMomentum().px()/1000;
00408 g_pyMC[ntrkMC] = (*iter_mc)->initialFourMomentum().py()/1000;
00409 g_pzMC[ntrkMC] = (*iter_mc)->initialFourMomentum().pz()/1000;
00410 g_ptMC[ntrkMC] = sqrt(((*iter_mc)->initialFourMomentum().px())*((*iter_mc)->initialFourMomentum().px())+((*iter_mc)->initialFourMomentum().py())*((*iter_mc)->initialFourMomentum().py()))/1000;
00411 }
00412 if( pid >0 ) {
00413 if(m_particleTable->particle( pid )) charge = m_particleTable->particle( pid )->charge();
00414 } else if ( pid <0 ) {
00415 if(m_particleTable->particle( -pid )) {
00416 charge = m_particleTable->particle( -pid )->charge();
00417 charge *= -1;
00418 }
00419 } else {
00420 log << MSG::WARNING << "wrong particle id, please check data" <<endreq;
00421 }
00422 log << MSG::DEBUG
00423 << "MC ParticleId = " << pid << " charge = " << charge
00424 << endreq;
00425 if(charge !=0 && abs(cos((*iter_mc)->initialFourMomentum().theta()))<0.93){
00426 ntrkMC++;
00427 }
00428 if(((*iter_mc)->primaryParticle())&& m_ntupleflag && m_tuple2){
00429 g_mcTestime=(*iter_mc)->initialPosition().t();
00430 mcTestime=(*iter_mc)->initialPosition().t();
00431 }
00432 }
00433 if(m_ntupleflag && m_tuple2) g_ntrkMC = ntrkMC;
00434 }
00435 }
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452 SmartDataPtr<RecMdcTrackCol> newtrkCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
00453 if (!newtrkCol || newtrkCol->size()==0) {
00454 log << MSG::WARNING<< "Could not find RecMdcTrackCol" << endreq;
00455 } else{
00456 log << MSG::INFO << "Begin to check RecMdcTrackCol"<<endreq;
00457 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
00458 for( ; iter_trk != newtrkCol->end(); iter_trk++){
00459 log << MSG::DEBUG << "retrieved MDC track:"
00460 << " Track Id: " << (*iter_trk)->trackId()
00461 << " Phi0: " << (*iter_trk)->helix(0)
00462 << " kappa: " << (*iter_trk)->helix(2)
00463 << " Tanl: " << (*iter_trk)->helix(4)
00464 << " Phi terminal: "<< (*iter_trk)->getFiTerm()
00465 << endreq
00466 << "Number of hits: "<< (*iter_trk)->getNhits()
00467 << " Number of stereo hits " << (*iter_trk)->nster()
00468 << endreq;
00469 double kappa = (*iter_trk)->helix(2);
00470 double tanl = (*iter_trk)->helix(4);
00471 momentum[ntot] = 1./fabs(kappa) * sqrt(1.+tanl*tanl);
00472 if((*iter_trk)->helix(3)>50.0) continue;
00473 ntot++;
00474 if (ntot>15) break;
00475 }
00476 }
00477
00478 int emctrk=0;
00480 SmartDataPtr<RecEmcShowerCol> aShowerCol(eventSvc(),"/Event/Recon/RecEmcShowerCol");
00481 if (!aShowerCol || aShowerCol->size()==0) {
00482 log << MSG::WARNING << "Could not find RecEmcShowerCol" << endreq;
00483 } else{
00484
00485 RecEmcShowerCol::iterator iShowerCol=aShowerCol->begin();
00486 for(;iShowerCol!=aShowerCol->end();iShowerCol++,emctrk++){
00487 if(emctrk>20) break;
00488 phiemc_rec[emctrk]=(*iShowerCol)->position().phi();
00489 thetaemc_rec[emctrk]=(*iShowerCol)->position().theta();
00490 energy_rec[emctrk]=(*iShowerCol)->energy();
00491 xemc_rec[emctrk]=(*iShowerCol)->x();
00492 yemc_rec[emctrk]=(*iShowerCol)->y();
00493 zemc_rec[emctrk]=(*iShowerCol)->z();
00494 module[emctrk]=(*iShowerCol)->module();
00495 }
00496 }
00497 for(int i=0; i<2; i++){
00498
00499
00500 double fi_endtof = atan2(yemc_rec[i],xemc_rec[i] );
00501 if (fi_endtof<0) fi_endtof=2*3.141593+fi_endtof;
00502 if(module[i] ==1){
00503 int Tofid = (int)(fi_endtof/(3.141593/44));
00504 if(Tofid>87) Tofid=Tofid-88;
00505 tofid_emc[i]=Tofid;
00506 idmatch_emc[1][Tofid]=1;
00507 }
00508 else{
00509 int Tofid =(int)(fi_endtof/(3.141593/24));
00510 if( Tofid>47) Tofid=Tofid-48;
00511 tofid_emc[i]= Tofid;
00512 if(module[i]==2) idmatch_emc[2][Tofid]=1;
00513 if(module[i]==0) idmatch_emc[0][Tofid]=1;
00514 }
00515 }
00517
00518
00519 ntrk=0;
00520 if (ntot > 0) {
00521 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
00522 for( int idfztrk=0; iter_trk != newtrkCol->end(); iter_trk++,idfztrk++){
00523 double mdcftrk[5];
00524 mdcftrk[0] = (*iter_trk)->helix(0);
00525 mdcftrk[1] = (*iter_trk)->helix(1);
00526 mdcftrk[2] =-(*iter_trk)->helix(2);
00527 mdcftrk[3] = (*iter_trk)->helix(3);
00528 mdcftrk[4] = (*iter_trk)->helix(4);
00529
00530 if(optCosmic==0){
00531 Emc_helix EmcHit;
00532
00533 EmcHit.pathlCut(Estparam.pathlCut());
00534
00535
00536
00537 if (EmcHit.Emc_Get(sqrt(RCEMC2),idfztrk,mdcftrk) > 0){
00538 double z_emc = EmcHit.Z_emc;
00539 double thetaemc_ext= EmcHit.theta_emc;
00540 double phiemc_ext = EmcHit.phi_emc;
00541
00542 for(int t=0; t<emctrk;t++){
00543 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))){
00544 if((energy_rec[t])>=(0.85*momentum[idfztrk]))
00545 particleId[idfztrk]=1;
00546 }
00547 }
00548 }
00549
00550 if(particleId[idfztrk]!=1){
00551
00552 SmartDataPtr<RecMdcDedxCol> newdedxCol(eventSvc(),"/Event/Recon/RecMdcDedxCol");
00553 if (!newdedxCol || newdedxCol->size()==0) {
00554 log << MSG::WARNING << "Could not find RecMdcDedxCol" << endreq;
00555 }
00556 else{
00557 RecMdcDedxCol::iterator it_dedx = newdedxCol->begin();
00558 for( int npid=0; it_dedx != newdedxCol->end(); it_dedx++,npid++) {
00559 log << MSG::INFO << "retrieved MDC dE/dx: "
00560 << "dEdx Id: " << (*it_dedx)->trackId()
00561 << " particle Id: "<< (*it_dedx)->particleId() <<endreq;
00562 if((*it_dedx)->particleId()==5){
00563 particleId[npid]= 5;
00564 }
00565 if(m_debug==4) cout<<"dedx pid: "<<particleId[npid]<<endl;
00566 }
00567 }
00568 }
00569 }
00570 idtof=-100;
00571 TofFz_helix TofHit;
00572
00573
00574 TofHit.pathlCut(Estparam.pathlCut());
00575
00576
00577 TofHit.ztofCut(Estparam.ztofCutmin(),Estparam.ztofCutmax());
00578
00579 int tofpart=TofHit.TofFz_Get(sqrt(RCTOF2),idfztrk,mdcftrk);
00580 if(tofpart < 0) continue;
00581
00582 idtof = TofHit.Tofid;
00583 tofid_helix[idfztrk] = TofHit.Tofid;
00584 log << MSG::INFO << "helix to tof hit part, Id: "<<tofpart<<" , "<< idtof <<endreq;
00585 if(m_debug ==4) cout << "helix to tof hit part, Id: "<<tofpart<<" , "<< idtof <<endl;
00586 if (idtof>=0 && idtof<=87 ) {
00587
00588 idmatch[tofpart][idtof]= 1;
00589 helpath[idtof]= TofHit.Pathl;
00590 helz[idtof] = TofHit.Z_tof;
00591 double abmom = 1./fabs(TofHit.Kappa) * sqrt(1.+TofHit.Tanl*TofHit.Tanl);
00592
00593 if(abmom<0.1) continue;
00594 abmom2[idtof] = abmom*abmom;
00595 pt[idtof] = 1./fabs(TofHit.Kappa);
00596 dr[idtof] = TofHit.Dr;
00597 dz[idtof] = TofHit.Dz;
00598 phi[idtof] = TofHit.Phi0;
00599 tanl[idtof] = TofHit.Tanl;
00600 r_endtof[idfztrk]= TofHit.r_endtof;
00601 helztof[idfztrk] = helz[idtof];
00602 if(optCosmic==0){
00603 if(particleId[idfztrk] == 1){
00604 ttof[idfztrk] = sqrt(ELMAS2/abmom2[idtof]+1)* helpath[idtof]/VLIGHT;
00605 double vel = VLIGHT/sqrt(ELMAS2/abmom2[idtof]+1);
00606 if(m_ntupleflag && m_tuple2) g_vel[idfztrk] = vel;
00607 }
00608 else if (particleId[idfztrk] == 5){
00609 ttof[idfztrk] = sqrt(PROTONMAS2/abmom2[idtof]+1)* helpath[idtof]/VLIGHT;
00610 double vel = VLIGHT/sqrt(PROTONMAS2/abmom2[idtof]+1);
00611 if(m_ntupleflag && m_tuple2) g_vel[idfztrk] = vel;
00612 }
00613 else{
00614 ttof[idfztrk] = sqrt(PIMAS2/abmom2[idtof]+1)* helpath[idtof]/VLIGHT;
00615 double vel = VLIGHT/sqrt(PIMAS2/abmom2[idtof]+1);
00616 if(m_ntupleflag && m_tuple2) g_vel[idfztrk] = vel;
00617 }
00618 }
00619 else{
00620 ttof[idfztrk] = sqrt(MUMAS2/abmom2[idtof]+1)* helpath[idtof]/VLIGHT;
00621 double vel = VLIGHT/sqrt(MUMAS2/abmom2[idtof]+1);
00622 if(m_ntupleflag && m_tuple2) g_vel[idfztrk] = vel;
00623 }
00624
00625 if(m_ntupleflag && m_tuple2){
00626 g_abmom[idfztrk] = abmom;
00627 g_ttof[idfztrk] = ttof[idfztrk];
00628 }
00629 }
00630 ntrk++;
00631 }
00632 if(m_ntupleflag && m_tuple2) g_ntrk= ntrk;
00633 }
00634
00635
00636
00637 if(runNo<0){
00638 SmartDataPtr<TofMcHitCol> tofmcHitCol(eventSvc(),"/Event/MC/TofMcHitCol");
00639 if (!tofmcHitCol) {
00640 log << MSG::ERROR << "Could not find McParticle" << endreq;
00641 return StatusCode::FAILURE;
00642 }
00643 TofMcHitCol::iterator iter_mctof = tofmcHitCol->begin();
00644
00645 for (;iter_mctof !=tofmcHitCol->end(); iter_mctof++, digiId++) {
00646 log << MSG::INFO
00647 << " TofMcHit Flight Time = " << (*iter_mctof)->getFlightTime()
00648 << " zPosition = " << ((*iter_mctof)->getPositionZ())/10
00649 << " xPosition = " <<((*iter_mctof)->getPositionX())/10
00650 << " yPosition = " <<((*iter_mctof)->getPositionY())/10
00651 << endreq;
00652 }
00653 }
00654
00657 TofDataVector tofDigiVec = m_rawDataProviderSvc->tofDataVectorEstime();
00658 if(tofDigiVec.size()==0) return StatusCode::SUCCESS;
00659 for(TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++) {
00660 int barrelid=(*iter2)->barrel();
00661 int layerid;
00662 int tofid;
00663 if((*iter2)->barrel()){
00664 tofid = (*iter2)->tofId();
00665 layerid = (*iter2)->layer();
00666 if(layerid==1) tofid=tofid-88;
00667 if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times() ==1 ){
00668 double ftdc= (*iter2)->tdc1();
00669 double btdc= (*iter2)->tdc2();
00670 mean_tdc_btof[layerid][tofid]=(ftdc+btdc)/2;
00671 }
00672 else if( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times() >1){
00673 double ftdc= (*iter2)->tdc1();
00674 double btdc= (*iter2)->tdc2();
00675 mean_tdc_btof[layerid][tofid]=(ftdc+btdc)/2;
00676 }
00677 }
00678 else{
00679 tofid = (*iter2)->tofId();
00680 if(tofid<48) barrelid=0;
00681 if(tofid>47) barrelid=2;
00682 if(barrelid==2) tofid=tofid-48;
00683
00684 if((*iter2)->times() ==1){
00685 double ftdc= (*iter2)->tdc();
00686 mean_tdc_etof[barrelid][tofid]=ftdc;
00687 }
00688 else if(((*iter2)->times() >1) && ((*iter2)->times() <5)){
00689 double ftdc= (*iter2)->tdc();
00690 mean_tdc_etof[barrelid][tofid]=ftdc;
00691 }
00692 }
00693 }
00694
00695 double difftof_b=100, difftof_e=100;
00696 int tofid1=tofid_emc[0];
00697 int tofid2=tofid_emc[1];
00698 for(int i=0; i<2; i++){
00699 for(int m=0; m<2; m++){
00700 for(int j=-2; j<3; j++){
00701 for(int k=-2; k<3; k++){
00702 int p=tofid1+j;
00703 int q=tofid2+k;
00704 if(p<0) p=p+88;
00705 if(p>87) p=p-88;
00706 if(q<0) q=q+88;
00707 if(q>87) q=q+88;
00708 if(mean_tdc_btof[i][p]==0 || mean_tdc_btof[m][q]==0) continue;
00709 double difftof_b_temp = mean_tdc_btof[i][p]-mean_tdc_btof[m][q];
00710 if(abs(difftof_b_temp)<abs(difftof_b )) difftof_b =difftof_b_temp;
00711 if(m_ntupleflag && m_tuple2) g_difftof_b=difftof_b;
00712 }
00713 }
00714 }
00715 }
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733 for(int i=-1; i<2; i++){
00734 for(int j=-1; j<2; j++){
00735 int m=tofid1+i;
00736 int n=tofid2+j;
00737 if(m<0) m=48+m;
00738 if(m>47) m=m-48;
00739 if(n<0) n=48+n;
00740 if(n>47) n=n-48;
00741 if( mean_tdc_etof[0][m] && mean_tdc_etof[2][n]){
00742 double difftof_e_temp= mean_tdc_etof[0][m]-mean_tdc_etof[2][n];
00743 if(abs(difftof_e_temp) < abs(difftof_e)) difftof_e= difftof_e_temp;
00744 if(m_ntupleflag && m_tuple2) g_difftof_e=difftof_e;
00745 }
00746 }
00747 }
00748 if((energy_rec[0]<0.9 && abs(difftof_b) <15 && abs(difftof_b)>4)&& (m_optCosmic==1) ) optCosmic=1;
00749 else optCosmic=0;
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761 TofDataVector::iterator iter2 = tofDigiVec.begin();
00762
00763 digiId = 0;
00764 unsigned int tofid;
00765 unsigned int barrelid;
00766 unsigned int layerid;
00767 t0forward_add = 0;
00768 t0backward_add = 0;
00769
00770 for (;iter2 != tofDigiVec.end(); iter2++, digiId++) {
00771 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
00772 barrelid=(*iter2)->barrel();
00773 if((*iter2)->barrel()==0) continue;
00774
00775
00776
00777
00778 if(!( ((*iter2)->quality() & 0x5)==0x5 && (*iter2)->times() ==1 )) continue;
00779 tofid = (*iter2)->tofId();
00780 layerid = (*iter2)->layer();
00781 if(layerid==1) tofid=tofid-88;
00782 log<< MSG::INFO
00783 <<" TofId = "<<tofid
00784 <<" barrelid = "<<barrelid
00785 <<" layerid = "<<layerid
00786 <<" ForwordADC = "<<(*iter2)->adc1()
00787 <<" ForwordTDC = "<<(*iter2)->tdc1()
00788 <<" BackwordADC = "<<(*iter2)->adc2()
00789 <<" BackwordTDC = "<<(*iter2)->tdc2()
00790 << endreq;
00791
00792 double ftdc= (*iter2)->tdc1()-tdiffeast[layerid][tofid];
00793 double btdc= (*iter2)->tdc2()-tdiffwest[layerid][tofid];
00794 if(m_debug==4) cout<<"barrel 1 ::layer, barrel, tofid, ftdc, btdc: "<<layerid<<" , "<<barrelid<<" , "<<tofid<<" , "<<ftdc<<" , "<<btdc<<endl;
00795 double fadc= (*iter2)->adc1();
00796 double badc= (*iter2)->adc2();
00797 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
00798 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
00799 double ztof = fabs((ftdc-btdc)/2)*17.7 , ztof2 = ztof*ztof;
00800 nmat++;
00801 double mean_tdc = 0.5*(btdc+ftdc);
00802 double cor_path = sqrt(RCTOF2+ztof2)/VLIGHT;
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832 static bool HparCut=true;
00833
00834
00835
00836
00837 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
00838
00839 for(int i=0;i<=ntot;i++){
00840
00841 if(ttof[i]!=0 && ftdc>0){
00842
00843
00844 if(tofid_helix[i] == tofid ||(tofid_helix[i] == idptof)){
00845
00846 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
00847
00848
00849
00850 cor_evtime= ttof[i] + (238/2 - helztof[i])*0.069 ;
00851 if (optCosmic && tofid<44) {
00852 backevtime = -ttof[i] + (115 + helztof[i])*0.0566 + 12.;
00853 forevtime = -ttof[i] + (115 - helztof[i])*0.0566 + 12.;
00854 if(m_ntupleflag && m_tuple2){
00855 g_ntofup++;
00856 g_meantevup=(backevtime+forevtime)/2;
00857 }
00858 }
00859 else{
00860 backevtime = ttof[i] + (115 + helztof[i])*0.0566 + 12.;
00861 forevtime = ttof[i] + (115 - helztof[i])*0.0566 + 12.;
00862 if(m_ntupleflag && m_tuple2){
00863 g_ntofdown++;
00864 g_meantevdown=(backevtime+forevtime)/2;
00865 }
00866 }
00867
00868 if(!(*iter2)->adc1() || !(*iter2)->adc2() || m_userawtime){
00869 t0forward_trk = ftdc - forevtime ;
00870 t0backward_trk = btdc - backevtime ;
00871 }
00872 else{
00873 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
00874 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
00875 if (optCosmic && tofid<44) {
00876 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())+ttof[i];
00877 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())+ttof[i];
00878 }
00879 }
00880 if(t0forward_trk<-3 || t0backward_trk<-3 || fabs(t0forward_trk-t0backward_trk)>15.0) continue;
00881 if( nmatch_barrel!=0 && fabs((t0forward_trk+t0backward_trk)/2-(t0backward_add+t0forward_add)/2/nmatch_barrel)>11) continue;
00882 if(m_debug ==4 ) cout<<" t0forward_trk, t0backward_trk: "<<t0forward_trk<<" , "<<t0backward_trk<<endl;
00883
00884 if(m_ntupleflag && m_tuple2){
00885 g_t0for[nmatch1] = t0forward_trk ;
00886 if(t0backward_trk>-100) g_t0back[nmatch2] = t0backward_trk ;
00887 g_meantdc=(ftdc+btdc)/2;
00888 if(tofid<44) g_ntofup1++;
00889 else g_ntofdown1++;
00890 }
00891 if(m_ntupleflag && m_tuple9){
00892 g_meantev=(backevtime+forevtime)/2;
00893 StatusCode status = m_tuple9->write();
00894 if (!status.isSuccess()) {
00895 log << MSG::ERROR << "Can't fill ntuple!" << endreq;
00896 }
00897 }
00898 t0forward_add += t0forward_trk;
00899 t0backward_add += t0backward_trk;
00900 nmatch1=nmatch1+1;
00901 nmatch2=nmatch2+1;
00902 nmatch_barrel++;
00903 }
00904 }
00905 }
00906 }
00907 if(nmatch_barrel==0){
00908 for(int i=0;i<=ntot;i++){
00909 if(ttof[i]!=0 && ftdc>0){
00910 if( (tofid_helix[i] == idntof )){
00911
00912 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
00913
00914 cor_evtime= ttof[i] + (238/2 - helztof[i])*0.069 ;
00915 if (optCosmic && tofid<44) {
00916 backevtime = -ttof[i] + (115 + helztof[i])*0.0566 + 12.;
00917 forevtime = -ttof[i] + (115 - helztof[i])*0.0566 + 12.;
00918 }
00919 else{
00920 backevtime = ttof[i] + (115 + helztof[i])*0.0566 + 12.;
00921 forevtime = ttof[i] + (115 - helztof[i])*0.0566 + 12.;
00922 }
00923
00924 if( !(*iter2)->adc1() || !(*iter2)->adc2() || m_userawtime){
00925 t0forward_trk = ftdc - forevtime ;
00926 t0backward_trk = btdc - backevtime ;
00927 }
00928 else{
00929 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
00930 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
00931 if (optCosmic && tofid<44) {
00932 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())+ttof[i];
00933 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())+ttof[i];
00934 }
00935 }
00936 if(t0forward_trk<-3 || t0backward_trk<-3 || fabs(t0forward_trk-t0backward_trk)>15.0) continue;
00937 if(nmatch_barrel!=0 && fabs((t0forward_trk+t0backward_trk)/2-(t0backward_add+t0forward_add)/2/nmatch_barrel)>11) continue;
00938 if(m_debug ==4 ) cout<<" t0forward_trk, t0backward_trk: "<<t0forward_trk<<" , "<<t0backward_trk<<endl;
00939 if(m_ntupleflag && m_tuple2){
00940 g_t0for[nmatch1] = t0forward_trk ;
00941 if(t0backward_trk>-100) g_t0back[nmatch2] = t0backward_trk ;
00942 g_meantdc=(ftdc+btdc)/2;
00943 }
00944 if(m_ntupleflag && m_tuple9){
00945 g_meantev=(backevtime+forevtime)/2;
00946 StatusCode status = m_tuple9->write();
00947 if (!status.isSuccess()) {
00948 log << MSG::ERROR << "Can't fill ntuple!" << endreq;
00949 }
00950 }
00951
00952 t0forward_add += t0forward_trk;
00953 t0backward_add += t0backward_trk;
00954 nmatch1=nmatch1+1;
00955 nmatch2=nmatch2+1;
00956 nmatch_barrel++;
00957 }
00958 }
00959 }
00960 }
00961 }
00962 }
00963
00964
00965
00966 }
00967
00968
00969 if(nmatch_barrel != 0 ){
00970 if(m_ntupleflag && m_tuple2){
00971 g_t0barrelTof=( t0forward_add/nmatch_barrel + t0backward_add/nmatch_barrel)/2;
00972 }
00973 tof_flag = 1;
00974 t_quality=1;
00975 }
00976
00977 if(nmatch_barrel==0){
00978 digiId = 0;
00979 t0forward_add = 0;
00980 t0backward_add = 0;
00981 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
00982 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
00983 barrelid=(*iter2)->barrel();
00984 if((*iter2)->barrel()==0) continue;
00985
00986
00987
00988 if(((*iter2)->quality() & 0x5) ==0x5 && (*iter2)->times() >1 ){
00989 tofid = (*iter2)->tofId();
00990 layerid = (*iter2)->layer();
00991 if(layerid==1) tofid=tofid-88;
00992 log<< MSG::INFO
00993 <<" TofId = "<<tofid
00994 <<" barrelid = "<<barrelid
00995 <<" layerid = "<<layerid
00996 <<" ForwordADC = "<<(*iter2)->adc1()
00997 <<" ForwordTDC = "<<(*iter2)->tdc1()
00998 <<endreq;
00999 double ftdc= (*iter2)->tdc1()-tdiffeast[layerid][tofid];
01000 double btdc= (*iter2)->tdc2()-tdiffwest[layerid][tofid];
01001 double fadc= (*iter2)->adc1();
01002 double badc= (*iter2)->adc2();
01003 if(m_debug==4) cout<<"barrel 2 ::layer, barrel, tofid, ftdc, btdc: "<<layerid<<" , "<<barrelid<<" , "<<tofid<<" , "<<ftdc<<" , "<<btdc<<endl;
01004 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
01005 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
01006 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
01007 for(int i=0;i<=ntot;i++){
01008
01009 if(ttof[i]!=0 && ftdc>0){
01010
01011
01012 if(tofid_helix[i] == tofid ||(tofid_helix[i] == idptof)||(tofid_helix[i] == idntof)){
01013
01014 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
01015
01016
01017
01018 cor_evtime= ttof[i] + (238/2 - helztof[i])*0.069 ;
01019 if (optCosmic && tofid<44) {
01020 backevtime = -ttof[i] + (115 + helztof[i])*0.0566 + 12.;
01021 forevtime = -ttof[i] + (115 - helztof[i])*0.0566 + 12.;
01022 if(m_ntupleflag && m_tuple2){
01023 g_ntofup++;
01024 g_meantevup=(backevtime+forevtime)/2;
01025 }
01026 }
01027 else{
01028 backevtime = ttof[i] + (115 + helztof[i])*0.0566 + 12.;
01029 forevtime = ttof[i] + (115 - helztof[i])*0.0566 + 12.;
01030 if(m_ntupleflag && m_tuple2){
01031 g_ntofdown++;
01032 g_meantevdown=(backevtime+forevtime)/2;
01033 }
01034 }
01035
01036 if(!(*iter2)->adc1() || !(*iter2)->adc2() || m_userawtime){
01037 t0forward_trk = ftdc - forevtime ;
01038 t0backward_trk = btdc - backevtime ;
01039 }
01040 else{
01041 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
01042 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
01043 if (optCosmic && tofid<44) {
01044 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())+ttof[i];
01045 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())+ttof[i];
01046 }
01047
01048 }
01049 if(t0forward_trk<-3 || t0backward_trk<-3 || fabs(t0forward_trk-t0backward_trk)>15.0) continue;
01050 if(nmatch_barrel!=0 && fabs((t0forward_trk+t0backward_trk)/2-(t0backward_add+t0forward_add)/2/nmatch_barrel)>11) continue;
01051 if(m_debug == 4) cout<<"t0forward_trk, t0backward_trk: "<<t0forward_trk<<" , "<<t0backward_trk<<endl;
01052
01053 if(m_ntupleflag && m_tuple2){
01054 g_t0for[nmatch1] = t0forward_trk ;
01055 if(t0backward_trk>-100) g_t0back[nmatch2] = t0backward_trk ;
01056 g_meantdc=(ftdc+btdc)/2;
01057 if(tofid<44) g_ntofup1++;
01058 else g_ntofdown1++;
01059 }
01060 if(m_ntupleflag && m_tuple9){
01061 g_meantev=(backevtime+forevtime)/2;
01062 StatusCode status = m_tuple9->write();
01063 if (!status.isSuccess()) {
01064 log << MSG::ERROR << "Can't fill ntuple!" << endreq;
01065 }
01066 }
01067 t0forward_add += t0forward_trk;
01068 t0backward_add += t0backward_trk;
01069 nmatch1=nmatch1+1;
01070 nmatch2=nmatch2+1;
01071 nmatch_barrel++;
01072
01073 }
01074 }
01075 }
01076 }
01077 }
01078 }
01079 }
01080 if(nmatch_barrel) tof_flag=2;
01081 }
01082 if(ntot==0 || nmatch_barrel==0) {
01083 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
01084 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
01085 barrelid=(*iter2)->barrel();
01086 if((*iter2)->barrel()==0) continue;
01087
01088
01089 if(((*iter2)->quality() & 0x5) ==0x5 && (*iter2)->times() ==1 ){
01090 tofid = (*iter2)->tofId();
01091 layerid = (*iter2)->layer();
01092 if(layerid==1) tofid=tofid-88;
01093 log<< MSG::INFO
01094 <<" TofId = "<<tofid
01095 <<" barrelid = "<<barrelid
01096 <<" layerid = "<<layerid
01097 <<" ForwordADC = "<<(*iter2)->adc1()
01098 <<" ForwordTDC = "<<(*iter2)->tdc1()
01099 <<endreq;
01100 double ftdc= (*iter2)->tdc1();
01101 double btdc= (*iter2)->tdc2();
01102 double fadc= (*iter2)->adc1();
01103 double badc= (*iter2)->adc2();
01104 if(m_debug==4) cout<<"barrel 3 ::layer, barrel, tofid, ftdc, btdc: "<<layerid<<" , "<<barrelid<<" , "<<tofid<<" , "<<ftdc<<" , "<<btdc<<endl;
01105 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
01106 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
01107 for(int i=0; i<2; i++){
01108 if(tofid_emc[i] == tofid || tofid_emc[i] == idptof || tofid_emc[i] == idntof){
01109 if(zemc_rec[0]||zemc_rec[1]){
01110 if(tofid ==tofid_emc[i] || tofid_emc[i]==idntof || tofid_emc[i]==idptof){
01111 if(ftdc>2000.|| module[i]!=1) continue;
01112 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;
01113 if(optCosmic==1 && tofid<44){
01114 backevtime = -ttof[i] + (115 + zemc_rec[i])*0.0566 + 12.;
01115 forevtime = -ttof[i] + (115 - zemc_rec[i])*0.0566 + 12.;
01116 }
01117 else{
01118 backevtime = ttof[i] + (115 + zemc_rec[i])*0.0566 + 12.;
01119 forevtime = ttof[i] + (115 - zemc_rec[i])*0.0566 + 12.;
01120 }
01121 if( !(*iter2)->adc1() || !(*iter2)->adc2() || m_userawtime){
01122 t0forward_trk=ftdc-forevtime;
01123 t0backward_trk=btdc-backevtime;
01124 }
01125 else{
01126 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
01127 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
01128 if (optCosmic && tofid<44) {
01129 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())+ttof[i];
01130 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())+ttof[i];
01131 }
01132
01133 }
01134
01135 if(t0forward_trk<-1 || t0backward_trk<-1 || fabs(t0forward_trk-t0backward_trk)>15.0) continue;
01136 if(nmatch_barrel!=0 && fabs((t0forward_trk+t0backward_trk)/2-(t0backward_add+t0forward_add)/2/nmatch_barrel)>11) continue;
01137 if(m_debug == 4) cout<<"t0forward_trk, t0backward_trk: "<<t0forward_trk<<" , "<<t0backward_trk<<endl;
01138 t0forward_add += t0forward_trk;
01139 t0backward_add += t0backward_trk;
01140 nmatch_barrel++;
01141
01142 emcflag1=1;
01143 }
01144 }
01145 }
01146 }
01147 }
01148 }
01149 if(nmatch_barrel) tof_flag=3;
01150 }
01151 if(nmatch_barrel != 0 ){
01152 t0forward = t0forward_add/nmatch_barrel;
01153 t0backward = t0backward_add/nmatch_barrel;
01154 if(optCosmic==0){
01155 if(runNo>0){
01156
01157 nbunch = (int)((t0forward+t0backward)/2- tOffset_b-toffset_rawtime)/bunchtime;
01158 if((int)((t0forward+t0backward)/2-tOffset_b-toffset_rawtime)% bunchtime>(bunchtime/2)) nbunch=nbunch+1;
01159 t_Est = nbunch * bunchtime + offset_dt + tOffset_b;
01160 if(tof_flag==1) tEstFlag=111;
01161 else if(tof_flag==2) tEstFlag=121;
01162 else if(tof_flag==3) tEstFlag=131;
01163 }
01164 else{
01165 nbunch=(int)((t0forward+t0backward)/2-offset)/8;
01166
01167 if(((int)((t0forward+t0backward)/2-offset))%8>4) nbunch=nbunch+1;
01168 t_Est=nbunch*8+offset+tOffset_b;
01169 if(t_Est<0) t_Est=0;
01170
01171 if(tof_flag==1) tEstFlag=111;
01172 else if(tof_flag==2) tEstFlag=121;
01173 else if(tof_flag==3) tEstFlag=131;
01174 }
01175 }
01176 if(optCosmic){
01177 t_Est=(t0forward+t0backward)/2;
01178 if(tof_flag==1) tEstFlag=211;
01179 else if(tof_flag==2) tEstFlag=221;
01180 else if(tof_flag==3) tEstFlag=231;
01181 }
01182 if(t0forward>-100 && t0backward>-100) { if(m_ntupleflag && m_tuple2) g_meant0=(t0forward+t0backward)/2;}
01183 }
01184
01185
01186
01187 digiId = 0;
01188 t0forward_add = 0;
01189 t0backward_add = 0;
01190
01191 if(nmatch_barrel==0){
01192 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
01193 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
01194 barrelid=(*iter2)->barrel();
01195 if((*iter2)->barrel()==0) continue;
01196
01197
01198 if(((*iter2)->quality() & 0x5) ==0x4){
01199 tofid = (*iter2)->tofId();
01200 layerid = (*iter2)->layer();
01201 if(layerid==1) tofid=tofid-88;
01202 log<< MSG::INFO
01203 <<" TofId = "<<tofid
01204 <<" barrelid = "<<barrelid
01205 <<" layerid = "<<layerid
01206 <<" ForwordADC = "<<(*iter2)->adc1()
01207 <<" ForwordTDC = "<<(*iter2)->tdc1()
01208 <<endreq;
01209
01210 double ftdc= (*iter2)->tdc1()-tdiffeast[layerid][tofid];
01211 double fadc= (*iter2)->adc1();
01212 if(m_debug==4) cout<<"barrel 4 ::layer, barrel, tofid, ftdc: "<<layerid<<" , "<<barrelid<<" , "<<tofid<<" , "<<ftdc<<endl;
01213 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
01214 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
01215
01216 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
01217 for(int i=0;i<=ntot;i++){
01218 if(ttof[i]!=0 && ftdc>0){
01219 if(tofid_helix[i] == tofid ||(tofid_helix[i] == idptof) || (tofid_helix[i] == idntof)){
01220 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
01221
01222
01223
01224 cor_evtime= ttof[i] + (238/2 - helztof[i])*0.069 ;
01225 if (optCosmic && tofid<44) {
01226 forevtime = -ttof[i] + (115 - helztof[i])*0.0566 + 12.;
01227 if(m_ntupleflag && m_tuple2){
01228 g_ntofup++;
01229 g_meantevup=forevtime;
01230 }
01231 }
01232 else{
01233 forevtime = ttof[i] + (115 - helztof[i])*0.0566 + 12.;
01234 if(m_ntupleflag && m_tuple2){
01235 g_ntofdown++;
01236 g_meantevdown=forevtime;
01237 }
01238 }
01239
01240 if(!(*iter2)->adc1() || m_userawtime){
01241 t0forward_trk = ftdc - forevtime ;
01242 }
01243 else{
01244 t0forward_trk = tofCaliSvc->BTime1((*iter2)->adc1(), (*iter2)->tdc1(),helztof[i], (*iter2)->tofId())-ttof[i];
01245 }
01246 if(t0forward_trk<-1) continue;
01247 if(nmatch_barrel_1!=0 && fabs((t0forward_trk)-(t0forward_add)/nmatch_barrel_1)>11) continue;
01248 if(m_debug == 4) cout<<"t0forward_trk: "<<t0forward_trk<<endl;
01249
01250 if(m_ntupleflag && m_tuple2){
01251 g_t0for[nmatch1] = t0forward_trk ;
01252 g_meantdc=ftdc;
01253 if(tofid<44) g_ntofup1++;
01254 else g_ntofdown1++;
01255 }
01256 if(m_ntupleflag && m_tuple9){
01257 g_meantev=forevtime;
01258 StatusCode status = m_tuple9->write();
01259 if (!status.isSuccess()) {
01260 log << MSG::ERROR << "Can't fill ntuple!" << endreq;
01261 }
01262 }
01263 t0forward_add += t0forward_trk;
01264
01265 nmatch_barrel_1++;
01266 }
01267 }
01268 }
01269 }
01270 }
01271 }
01272
01273
01274 else if(((*iter2)->quality() & 0x5) ==0x1){
01275 tofid = (*iter2)->tofId();
01276 layerid = (*iter2)->layer();
01277 if(layerid==1) tofid=tofid-88;
01278 log<< MSG::INFO
01279 <<" TofId = "<<tofid
01280 <<" barrelid = "<<barrelid
01281 <<" layerid = "<<layerid
01282 <<" BackwordADC = "<<(*iter2)->adc2()
01283 <<" BackwordTDC = "<<(*iter2)->tdc2()
01284 << endreq;
01285
01286 double btdc= (*iter2)->tdc2()-tdiffwest[layerid][tofid];
01287 if(m_debug==4) cout<<"barrel 5 ::layer, barrel, tofid, btdc: "<<layerid<<" , "<<barrelid<<" , "<<tofid<<" , "<<btdc<<endl;
01288 double badc= (*iter2)->adc2();
01289 int idptof = ((tofid-1) == -1) ? 87 : tofid-1;
01290 int idntof = ((tofid+1) == 88) ? 0 : tofid+1;
01291 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
01292
01293 for(int i=0;i<=ntot;i++){
01294 if(ttof[i]!=0 && btdc>0){
01295 if((tofid_helix[i] == tofid) || (tofid_helix[i] == idntof) ||(tofid_helix[i] == idptof)){
01296 if(barrelid==1 && helztof[i]<117 && helztof[i]>-117 ){
01297
01298
01299 cor_evtime= ttof[i] + (238/2 - helztof[i])*0.069 ;
01300 if (optCosmic && tofid<44) {
01301 backevtime = -ttof[i] + (115 + helztof[i])*0.0566 + 12.;
01302 if(m_ntupleflag && m_tuple2){
01303 g_ntofup++;
01304 g_meantevup=backevtime;
01305 }
01306 }
01307 else{
01308 backevtime = ttof[i] + (115 + helztof[i])*0.0566 + 12.;
01309 if(m_ntupleflag && m_tuple2){
01310 g_ntofdown++;
01311 g_meantevdown=backevtime;
01312 }
01313 }
01314
01315 if(!(*iter2)->adc2() || m_userawtime){
01316 t0backward_trk = btdc - backevtime ;
01317 }
01318 else{
01319 t0backward_trk = tofCaliSvc->BTime2((*iter2)->adc2(), (*iter2)->tdc2(),helztof[i], (*iter2)->tofId())-ttof[i];
01320 }
01321 if(t0backward_trk<-1) continue;
01322 if(nmatch_barrel_2!=0 && fabs((t0backward_trk)-(t0backward_add)/nmatch_barrel_2)>11) continue;
01323 if(m_debug == 4) cout<<"t0backward_trk: "<<t0backward_trk<<endl;
01324
01325 if(m_ntupleflag && m_tuple2){
01326 if(t0backward_trk>-100) g_t0back[nmatch2] = t0backward_trk ;
01327 g_meantdc=btdc;
01328 if(tofid<44) g_ntofup1++;
01329 else g_ntofdown1++;
01330 }
01331 if(m_ntupleflag && m_tuple9){
01332 g_meantev=backevtime;
01333 StatusCode status = m_tuple9->write();
01334 if (!status.isSuccess()) {
01335 log << MSG::ERROR << "Can't fill ntuple!" << endreq;
01336 }
01337 }
01338 t0backward_add += t0backward_trk;
01339 nmatch_barrel_2++;
01340
01341 }
01342 }
01343 }
01344 }
01345 }
01346 }
01347 }
01348 }
01349 if(nmatch_barrel_1 != 0 ){
01350 t0forward = t0forward_add/nmatch_barrel_1;
01351 if(optCosmic==0){
01352
01353 if(runNo>0)
01354 {
01355 nbunch = (int)(t0forward-tOffset_b-toffset_rawtime)/ bunchtime;
01356 if((int)(t0forward-tOffset_b-toffset_rawtime)% bunchtime > (bunchtime/2)) nbunch=nbunch+1;
01357 t_Est=nbunch * bunchtime + offset_dt + tOffset_b;
01358 tEstFlag=141;
01359 }
01360 else{
01361 nbunch = (int)(t0forward-tOffset_b-toffset_rawtime)/ 8.;
01362 if((int)(t0forward-tOffset_b-toffset_rawtime)% 8>4) nbunch=nbunch+1;
01363 t_Est=nbunch*8+offset+tOffset_b;
01364 tEstFlag=141;
01365 }
01366 }
01367 else{
01368 t_Est=t0forward;
01369 tEstFlag=241;
01370 }
01371 if(t0forward>-100 ) { if(m_ntupleflag && m_tuple2) g_meant0=t0forward;}
01372 }
01373 if(nmatch_barrel_2 != 0 ){
01374 t0backward = t0backward_add/nmatch_barrel_2;
01375 if(optCosmic==0){
01376
01377 if(runNo>0){
01378 nbunch = (int)(t0backward-tOffset_b-toffset_rawtime)/ bunchtime;
01379 if((int)(t0backward-tOffset_b-toffset_rawtime)% bunchtime > (bunchtime/2)) nbunch=nbunch+1;
01380 t_Est= nbunch * bunchtime + offset_dt + tOffset_b;
01381 tEstFlag=141;
01382 }
01383 else {
01384 nbunch = (int)(t0backward-tOffset_b-toffset_rawtime)/ 8.;
01385 if((int)(t0backward-tOffset_b-toffset_rawtime)% 8>4) nbunch=nbunch+1;
01386 t_Est=nbunch*8+offset+tOffset_b;
01387 tEstFlag=141;
01388 }
01389 }
01390 else{
01391 t_Est=t0backward;
01392 tEstFlag=241;
01393 }
01394 if(t0backward>-100 ) { if(m_ntupleflag && m_tuple2) g_meant0=t0backward;}
01395 }
01396
01397
01398 digiId = 0;
01399 t0forward_add = 0;
01400 t0backward_add = 0;
01401
01402 if(nmatch_barrel==0){
01403 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
01404 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
01405
01406 barrelid=(*iter2)->barrel();
01407 if((*iter2)->barrel()!=0) continue;
01408
01409
01410 if((*iter2)->times()!=1) continue;
01411 tofid = (*iter2)->tofId();
01412 if(tofid<48) barrelid=0;
01413 if(tofid>47) barrelid=2;
01414 if(barrelid==2) tofid=tofid-48;
01415
01416 log<< MSG::INFO
01417 <<" TofId = "<<tofid
01418 <<" barrelid = "<<barrelid
01419 <<endreq
01420 <<" ForwordADC = "<< (*iter2)->adc()
01421 <<" ForwordTDC = "<< (*iter2)->tdc()
01422 << endreq;
01423 double ftdc= (*iter2)->tdc();
01424 double fadc= (*iter2)->adc();
01425 if(m_debug ==4) cout<<"endcap::single hit,barrelid,tofid,tdc: "<<barrelid<<" , "<<tofid<<" , "<<ftdc<<endl;
01426
01427 int idptof = ((tofid-1) == -1) ? 47 : tofid-1;
01428 int idntof = ((tofid+1) == 48) ? 0 : tofid+1;
01429
01430
01431 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
01432 for(int i=0;i<=ntot;i++){
01433 if(ttof[i]!=0 && ftdc>0 && ftdc<2000.){
01434 if((tofid_helix[i] == tofid) ||(tofid_helix[i] == idntof) ||(tofid_helix[i] == idptof)){
01435
01436 if(barrelid == 0 ){
01437 if(r_endtof[i]>=41 && r_endtof[i]<=90){
01438
01439 forevtime = ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;
01440 if (optCosmic && (tofid<24||(tofid>48&&tofid<71))) { forevtime = -ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;}
01441 if(! (*iter2)->adc() || m_userawtime){
01442 t0forward_trk=ftdc-forevtime;
01443 }
01444 else{
01445 t0forward_trk = tofCaliSvc->ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
01446 }
01447 if( nmatch_end!=0 && abs(t0forward_trk-t0forward_add/nmatch_end)>9) continue;
01448 t0forward_add += t0forward_trk;
01449
01450 nmatch_end++;
01451 }
01452 }
01453 else if(barrelid == 2 ){
01454 if(r_endtof[i]>=41 && r_endtof[i]<=90){
01455
01456
01457 forevtime = ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;
01458 if (optCosmic && ((tofid>24&&tofid<48)||tofid>71)) { forevtime = -ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;}
01459
01460 if( ! (*iter2)->adc() || m_userawtime){
01461 t0forward_trk=ftdc-forevtime;
01462 }
01463 else{
01464 t0forward_trk = tofCaliSvc->ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
01465 }
01466 if(t0forward_trk<-1.) continue;
01467 if( nmatch_end!=0 && abs(t0forward_trk-t0forward_add/nmatch_end)>9) continue;
01468 t0forward_add += t0forward_trk;
01469
01470 nmatch_end++;
01471 }
01472 }
01473 if(m_debug ==4) cout<<"t0forward_trk: "<<t0forward_trk<<endl;
01474 }
01475 }
01476 }
01477 }
01478 }
01479 if(nmatch_end) tof_flag=5;
01480 }
01481
01482 if((nmatch_barrel==0 && nmatch_end==0)){
01483 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
01484 barrelid=(*iter2)->barrel();
01485 if((*iter2)->barrel()!=0) continue;
01486 if((*iter2)->times()!=1) continue;
01487 tofid = (*iter2)->tofId();
01488 if(tofid<48) barrelid=0;
01489 if(tofid>47) barrelid=2;
01490 if(barrelid==2) tofid=tofid-48;
01491
01492 double ftdc= (*iter2)->tdc();
01493 double fadc= (*iter2)->adc();
01494
01495 int idptof = ((tofid-1) == -1) ? 47 : tofid-1;
01496 int idntof = ((tofid+1) == 48) ? 0 : tofid+1;
01497 log<< MSG::INFO
01498 <<" TofId = "<<tofid
01499 <<" barrelid = "<<barrelid
01500 <<" ADC = "<< (*iter2)->adc()
01501 <<" TDC = "<< (*iter2)->tdc()
01502 << endreq;
01503 if(idmatch_emc[barrelid][tofid]==1||idmatch_emc[barrelid][idptof]==1||idmatch_emc[barrelid][idntof]==1){
01504
01505 for(int i=0; i<2; i++){
01506 if(zemc_rec[0]||zemc_rec[1]){
01507 if(tofid ==tofid_emc[i] || tofid_emc[i]==idntof || tofid_emc[i]==idptof){
01508 if(ftdc>2000.||module[i]==1) continue;
01509 ttof[i]= sqrt(ELMAS2/(m_ebeam*m_ebeam)+1)* sqrt(xemc_rec[i]*xemc_rec[i]+yemc_rec[i]*yemc_rec[i]+133*133)/VLIGHT;
01510 r_endtof[i]=sqrt(xemc_rec[i]*xemc_rec[i]+yemc_rec[i]*yemc_rec[i]);
01511 forevtime = ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;
01512
01513 if(!(*iter2)->adc() || m_userawtime){
01514 t0forward_trk=ftdc-forevtime;
01515 }
01516 else{
01517 t0forward_trk = tofCaliSvc->ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
01518 if(m_debug ==4) cout<<"emc flag t0forward_trk: "<<t0forward_trk<<endl;
01519 }
01520 if(t0forward_trk<-1.) continue;
01521 if( nmatch_end!=0 && abs(t0forward_trk-t0forward_add/nmatch_end)>9) continue;
01522 t0forward_add += t0forward_trk;
01523
01524 nmatch_end++;
01525 emcflag2=1;
01526 }
01527 }
01528 }
01529 }
01530 }
01531 if(nmatch_end) tof_flag=5;
01532 }
01533
01534 if(nmatch_barrel ==0 && nmatch_end ==0){
01535 for (TofDataVector::iterator iter2 = tofDigiVec.begin();iter2 != tofDigiVec.end(); iter2++, digiId++) {
01536 log << MSG::INFO << "TOF digit No: " << digiId << endreq;
01537
01538 barrelid=(*iter2)->barrel();
01539 if((*iter2)->barrel()!=0) continue;
01540
01541
01542 if( (*iter2)->times()>1 && (*iter2)->times()<5 ){
01543 tofid = (*iter2)->tofId();
01544 if(tofid<48) barrelid=0;
01545 if(tofid>47) barrelid=2;
01546 if(barrelid==2) tofid=tofid-48;
01547
01548 log<< MSG::INFO
01549 <<" TofId = "<<tofid
01550 <<" barrelid = "<<barrelid
01551 <<endreq
01552 <<" ForwordADC = "<< (*iter2)->adc()
01553 <<" ForwordTDC = "<< (*iter2)->tdc()
01554 << endreq;
01555 double ftdc= (*iter2)->tdc();
01556 if(m_debug ==4) cout<<"endcap::multi hit,barrelid,tofid,tdc: "<<barrelid<<" , "<<tofid<<" , "<<ftdc<<endl;
01557 double fadc= (*iter2)->adc();
01558
01559 int idptof = ((tofid-1) == -1) ? 47 : tofid-1;
01560 int idntof = ((tofid+1) == 48) ? 0 : tofid+1;
01561
01562
01563 if(idmatch[barrelid][tofid]==1||idmatch[barrelid][idptof]==1||idmatch[barrelid][idntof]==1){
01564 for(int i=0;i<=ntot;i++){
01565 if(ttof[i]!=0 && ftdc>0){
01566 if((tofid_helix[i] == tofid) ||(tofid_helix[i] == idntof) ||(tofid_helix[i] == idptof)){
01567
01568 if(barrelid == 0 ){
01569 if(r_endtof[i]>=41 && r_endtof[i]<=90){
01570
01571 forevtime = ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;
01572 if (optCosmic && (tofid<24||(tofid>48&&tofid<71))) { forevtime = -ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;}
01573
01574 if(!(*iter2)->adc() || m_userawtime){
01575 t0forward_trk=ftdc-forevtime;
01576 }
01577 else{
01578 t0forward_trk = tofCaliSvc->ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
01579 }
01580 if( nmatch_end!=0 && abs(t0forward_trk-t0forward_add/nmatch_end)>9) continue;
01581 t0forward_add += t0forward_trk;
01582
01583 nmatch_end++;
01584 }
01585 }
01586 else if(barrelid == 2 ){
01587 if(r_endtof[i]>=41 && r_endtof[i]<=90){
01588
01589 forevtime = ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;
01590 if (optCosmic && ((tofid>24&&tofid<48)||tofid>71)) { forevtime = -ttof[i]+ (r_endtof[i]-41)*0.07+ 11.7;}
01591
01592 if(!(*iter2)->adc() || m_userawtime){
01593 t0forward_trk=ftdc-forevtime;
01594 }
01595 else{
01596 t0forward_trk = tofCaliSvc->ETime((*iter2)->adc(), (*iter2)->tdc(),r_endtof[i], (*iter2)->tofId())-ttof[i];
01597 }
01598 if(t0forward_trk<-1.) continue;
01599 if( nmatch_end!=0 && abs(t0forward_trk-t0forward_add/nmatch_end)>9) continue;
01600 t0forward_add += t0forward_trk;
01601
01602 nmatch_end++;
01603 }
01604 }
01605 if(m_debug == 4 ) cout<<"t0forward_trk: "<<t0forward_trk<<endl;
01606 }
01607 }
01608 }
01609 }
01610 }
01611 }
01612 if(nmatch_end) tof_flag=7;
01613 }
01614 if(m_ntupleflag && m_tuple2){
01615 g_nmatchbarrel=nmatch_barrel;
01616 g_nmatchend=nmatch_end;
01617 }
01618
01619 if(nmatch_end !=0){
01620 t0forward = t0forward_add/nmatch_end;
01621 if(optCosmic==0){
01622 if(runNo>0){
01623
01624 nbunch = (int)(t0forward-tOffset_e-toffset_rawtime_e)/ bunchtime;
01625 if((int)(t0forward-tOffset_e-toffset_rawtime_e)% bunchtime > (bunchtime/2)) nbunch=nbunch+1;
01626 t_Est = nbunch * bunchtime + offset_dt_end + tOffset_e;
01627 if(tof_flag==5) tEstFlag=151;
01628 else if(tof_flag==7) tEstFlag=171;
01629 if(emcflag2==1) tEstFlag=161;
01630 }
01631 else{
01632 nbunch=(int)(t0forward-offset)/8;
01633
01634 if(((int)(t0forward-offset))%8>4) nbunch=nbunch+1;
01635 t_Est=nbunch*8+offset;
01636 if(t_Est<0) t_Est=0;
01637 if(tof_flag==5) tEstFlag=151;
01638 else if(tof_flag==7) tEstFlag=171;
01639 if(emcflag2==1) tEstFlag=161;
01640 }
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650 }
01651 if(optCosmic){
01652 t_Est=t0forward;
01653 if(tof_flag==5) tEstFlag=251;
01654 else if(tof_flag==7) tEstFlag=271;
01655 if(emcflag2==1) tEstFlag=261;
01656 }
01657 if(t0forward>-100) { if(m_ntupleflag && m_tuple2) g_meant0=t0forward;}
01658 }
01659
01660
01661 double t0_comp=-999;
01662 double T0=-999;
01663
01664 if(nmatch_barrel==0 && nmatch_end==0 && m_flag==1){
01665 double mhit[43][300]={0.};
01666 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc(),"/Event/Digi/MdcDigiCol");
01667 if (!mdcDigiCol) {
01668 log << MSG::ERROR << "Could not find MDC digi" << endreq;
01669 return StatusCode::FAILURE;
01670 }
01671
01672 IMdcGeomSvc* mdcGeomSvc;
01673 StatusCode sc = service("MdcGeomSvc", mdcGeomSvc);
01674 if (sc != StatusCode::SUCCESS) {
01675 return StatusCode::FAILURE;
01676 }
01677
01678 MdcDigiCol::iterator iter1 = mdcDigiCol->begin();
01679 digiId = 0;
01680 Identifier mdcId;
01681 int layerId;
01682 int wireId;
01683
01684 for (;iter1 != mdcDigiCol->end(); iter1++, digiId++) {
01685 mdcId = (*iter1)->identify();
01686 layerId = MdcID::layer(mdcId);
01687 wireId = MdcID::wire(mdcId);
01688
01689 mhit[layerId][wireId]=RawDataUtil::MdcTime((*iter1)->getTimeChannel());
01690 mhit[layerId][wireId]-=1.28*(mdcGeomSvc->Layer(layerId)->Radius())/299.8;
01691
01692 mdcGeomSvc->Wire(layerId,wireId);
01693
01694 double tof;
01695
01696 }
01697
01698 int Iused[43][300]={0},tmp=0;
01699 bool Lpat,Lpat11,Lpat12,Lpat2,Lpat31,Lpat32;
01700 double t0_all=0,t0_mean=0;
01701 double r[4]={0.};
01702 double chi2=999.0;
01703 double phi[4]={0.},corr[4]={0.},driftt[4]={0.};
01704 double ambig=1;
01705 double mchisq=50000;
01706
01707
01708 for(int i=5;i<10;i++){
01709
01710 double T1=0.5*0.1*(mdcGeomSvc->Layer(4*i+0)->PCSiz())/0.004;
01711 double T2=0.5*0.1*(mdcGeomSvc->Layer(4*i+1)->PCSiz())/0.004;
01712 double T3=0.5*0.1*(mdcGeomSvc->Layer(4*i+2)->PCSiz())/0.004;
01713 double T4=0.5*0.1*(mdcGeomSvc->Layer(4*i+3)->PCSiz())/0.004;
01714 r[0]=(mdcGeomSvc->Layer(4*i+0)->Radius())*0.1;
01715 r[1]=(mdcGeomSvc->Layer(4*i+1)->Radius())*0.1;
01716 r[2]=(mdcGeomSvc->Layer(4*i+2)->Radius())*0.1;
01717 r[3]=(mdcGeomSvc->Layer(4*i+3)->Radius())*0.1;
01718 double r0=r[0]-r[1]-(r[2]-r[1])/2;
01719 double r1=-(r[2]-r[1])/2;
01720 double r2=(r[2]-r[1])/2;
01721 double r3=r[3]-r[2]+(r[2]-r[1])/2;
01722
01723 for(int j=0;j<mdcGeomSvc->Layer(i*4+3)->NCell();j++){
01724
01725 int Icp=0;
01726 Icp=j-1;
01727 if(Icp<0) Icp=mdcGeomSvc->Layer(i*4+3)->NCell();
01728
01729 Lpat=(mhit[4*i][j]!=0) && (mhit[4*i][Icp]==0) &&( mhit[4*i][j+1]==0) && (Iused[4*i][j]==0);
01730 if(Lpat==1){
01731
01732 }
01733 if(Lpat){
01734 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);
01735 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);
01736 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);
01737 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);
01738 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);
01739
01740 if(Lpat11 && Lpat2 && Lpat31 ){
01741
01742 Iused[4*i+0][j]=1;
01743 Iused[4*i+1][j]=1;
01744 Iused[4*i+2][j]=1;
01745 Iused[4*i+3][j]=1;
01746 double t_i = mhit[4*i+0][j]+mhit[4*i+2][j];
01747 double t_j = mhit[4*i+1][j]+mhit[4*i+3][j];
01748 double l_j = T2+T4;
01749 double r_i = r0+r2;
01750 double r_j = r1+r3;
01751 double r_2k= r0*r0+r1*r1+r2*r2+r3*r3;
01752 double rt_i = r0*mhit[4*i+0][j]+r2*mhit[4*i+2][j];
01753 double rt_j = r1*mhit[4*i+1][j]+r3*mhit[4*i+3][j];
01754 double rl_j = r1*T2+r3*T4;
01755
01756 double deno= 4*r_2k-2*(r_i*r_i+r_j*r_j);
01757
01758 if (deno!=0){
01759 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;
01760 double Pb= 0.25*(t_i-t_j+l_j-(r_i+r_j) * Pa);
01761 double Ang=fabs(90.-fabs(atan(Pa)*180./3.141593));
01762
01763 t0_all+= (-0.25*((r_i-r_j)*Pa-t_i-t_j+l_j));
01764
01765 double chi2_tmp;
01766 for(int t0c=0;t0c<17;t0c+=8){
01767 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);
01768 if(chi2_tmp<chi2){
01769 chi2=chi2_tmp;
01770 t0_comp=t0c;
01771 }
01772 }
01773 tmp+=1;
01774 }
01775
01776
01777 for(int tmpT0=0;tmpT0<17;tmpT0+=8){
01778 driftt[0]=mhit[4*i+0][j]-tmpT0;
01779 driftt[1]=mhit[4*i+1][j]-tmpT0;
01780 driftt[2]=mhit[4*i+2][j]-tmpT0;
01781 driftt[3]=mhit[4*i+3][j]-tmpT0;
01782
01783 phi[0]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4)->NCell())+2*3.14159265/(mdcGeomSvc->Layer(i*4+1)->NCell())/2;
01784 phi[1]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4+1)->NCell());
01785 phi[2]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4+2)->NCell())+2*3.14159265/(mdcGeomSvc->Layer(i*4+1)->NCell())/2;
01786 phi[3]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4+3)->NCell());
01787 phi[0]-=ambig*driftt[0]*0.004/r[0];
01788 phi[1]+=ambig*driftt[1]*0.004/r[1];
01789 phi[2]-=ambig*driftt[2]*0.004/r[2];
01790 phi[3]+=ambig*driftt[3]*0.004/r[3];
01791 double s1, sx, sy, sxx, sxy;
01792 double delinv, denom;
01793 double weight;
01794 double sigma;
01795 double x[4];
01796 x[0]=r0;
01797 x[1]=r1;
01798 x[2]=r2;
01799 x[3]=r3;
01800 sigma=0.12;
01801 s1 = sx = sy = sxx = sxy = 0.0;
01802 double chisq = 0.0;
01803 for (int ihit = 0; ihit < 4; ihit++) {
01804 weight = 1. / (sigma * sigma);
01805 s1 += weight;
01806 sx += x[ihit] * weight;
01807 sy += phi[ihit] * weight;
01808 sxx += x[ihit] * (x[ihit] * weight);
01809 sxy += phi[ihit] * (x[ihit] * weight);
01810 }
01811 double resid[4]={0.};
01812
01813 denom = s1 * sxx - sx * sx;
01814 delinv = (denom == 0.0) ? 1.e20 : 1. / denom;
01815 double intercept = (sy * sxx - sx * sxy) * delinv;
01816 double slope = (s1 * sxy - sx * sy) * delinv;
01817
01818
01819 for (int ihit = 0; ihit < 4; ihit++) {
01820 resid[ihit] = ( phi[ihit] - intercept - slope * x[ihit] );
01821 chisq += resid[ihit] * resid[ihit]/(sigma*sigma) ;
01822 }
01823 if(chisq<mchisq){
01824 mchisq=chisq;
01825 T0=tmpT0;
01826 }
01827 }
01828 }
01829 if(Lpat12 && Lpat2 && Lpat32){
01830 Iused[4*i+0][j]=1;
01831 Iused[4*i+1][j+1]=1;
01832 Iused[4*i+2][j]=1;
01833 Iused[4*i+3][j+1]=1;
01834
01835 double t_i = mhit[4*i+0][j]+mhit[4*i+2][j];
01836 double t_j = mhit[4*i+1][j+1]+mhit[4*i+3][j+1];
01837 double l_j = T2+T4;
01838 double r_i = r0+r2;
01839 double r_j = r1+r3;
01840 double r_2k= r0*r0+r1*r1+r2*r2+r3*r3;
01841 double rt_i = r0*mhit[4*i+0][j]+r2*mhit[4*i+2][j];
01842 double rt_j = r1*mhit[4*i+1][j+1]+r3*mhit[4*i+3][j+1];
01843 double rl_j = r1*T2+r3*T4;
01844 double deno= 4*r_2k-2*(r_i*r_i+r_j*r_j);
01845
01846 if (deno!=0){
01847 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;
01848 double Pb= 0.25*(t_i-t_j+l_j-(r_i+r_j) * Pa);
01849 double Ang=fabs(90.-fabs(atan(Pa)*180./3.141593));
01850 t0_all+= (-0.25*((r_i-r_j)*Pa-t_i-t_j+l_j));
01851 tmp+=1;
01852 double chi2_tmp;
01853
01854 for(int t0c=0;t0c<17;t0c+=8){
01855 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);
01856
01857 if(chi2_tmp<chi2){
01858 chi2=chi2_tmp;
01859 t0_comp=t0c;
01860 }
01861 }
01862 }
01863
01864
01865
01866 for(int tmpT0=0;tmpT0<17;tmpT0+=8){
01867 driftt[0]=mhit[4*i+0][j]-tmpT0;
01868 driftt[1]=mhit[4*i+1][j+1]-tmpT0;
01869 driftt[2]=mhit[4*i+2][j]-tmpT0;
01870 driftt[3]=mhit[4*i+3][j+1]-tmpT0;
01871
01872 phi[0]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4)->NCell())+2*3.14159265/(mdcGeomSvc->Layer(i*4+1)->NCell())/2;
01873 phi[1]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4+1)->NCell());
01874 phi[2]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4+2)->NCell())+2*3.14159265/(mdcGeomSvc->Layer(i*4+1)->NCell())/2;
01875 phi[3]=j*2*3.14159265/(mdcGeomSvc->Layer(i*4+3)->NCell());
01876 phi[0]-=ambig*driftt[0]*0.004/r[0];
01877 phi[1]+=ambig*driftt[1]*0.004/r[1];
01878 phi[2]-=ambig*driftt[2]*0.004/r[2];
01879 phi[3]+=ambig*driftt[3]*0.004/r[3];
01880 double s1, sx, sy, sxx, sxy;
01881 double delinv, denom;
01882 double weight;
01883 double sigma;
01884 double x[4];
01885 x[0]=r0;
01886 x[1]=r1;
01887 x[2]=r2;
01888 x[3]=r3;
01889 sigma=0.12;
01890 s1 = sx = sy = sxx = sxy = 0.0;
01891 double chisq = 0.0;
01892 for (int ihit = 0; ihit < 4; ihit++) {
01893 weight = 1. / (sigma * sigma);
01894 s1 += weight;
01895 sx += x[ihit] * weight;
01896 sy += phi[ihit] * weight;
01897 sxx += x[ihit] * (x[ihit] * weight);
01898 sxy += phi[ihit] * (x[ihit] * weight);
01899 }
01900 double resid[4]={0.};
01901
01902 denom = s1 * sxx - sx * sx;
01903 delinv = (denom == 0.0) ? 1.e20 : 1. / denom;
01904 double intercept = (sy * sxx - sx * sxy) * delinv;
01905 double slope = (s1 * sxy - sx * sy) * delinv;
01906
01907
01908 for (int ihit = 0; ihit < 4; ihit++) {
01909 resid[ihit] = ( phi[ihit] - intercept - slope * x[ihit] );
01910 chisq += resid[ihit] * resid[ihit]/(sigma*sigma) ;
01911 }
01912
01913 if(chisq<mchisq){
01914 mchisq=chisq;
01915 T0=tmpT0;
01916 }
01917 }
01918 }
01919 }
01920 }
01921 }
01922
01923 if(tmp!=0){
01924 t0_mean=t0_all/tmp;
01925 }
01926 if(m_ntupleflag && m_tuple2) g_t0mean=t0_mean;
01927
01928 t_Est=T0 + tOffset_b;
01929 tEstFlag=2;
01930 }
01931 if(m_ntupleflag && m_tuple2){
01932 g_t0=t0_comp;
01933 g_T0=T0;
01934 }
01935 if(nmatch_barrel==0 && nmatch_end==0 && nmatch_barrel_1==0&&nmatch_barrel_2==0&&m_mdcCalibFunSvc&&m_flag==2){
01936
01937 log << MSG::INFO << " mdc " << endreq;
01938
01939 #define MXWIRE 6860
01940 #define MXTKHIT 6860
01941 #define MXTRK 15
01942
01943
01944 double VELPROP=33.33;
01945
01946
01947 int nhits_ax = 0;
01948 int nhits_ax2 = 0;
01949 int nhits_st = 0;
01950 int nhits_st2 = 0;
01951
01952 double tev_ax[MXTKHIT];
01953 double tev_st[MXTKHIT];
01954 double tevv[MXTKHIT];
01955 double toft;
01956 double prop;
01957 double t0_minus_TDC[MXWIRE];
01958
01959 double T0_cal=-230;
01960 double Mdc_t0Arr[500];
01961
01962 int expmc=1;
01963 double scale=1.;
01964 int expno, runno;
01965 ndriftt=0;
01966
01967
01968
01969
01970 if(ntot > MXTRK) {
01971 ntot=MXTRK;
01972 }
01973
01974 SmartDataPtr<RecMdcTrackCol> newtrkCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
01975 if (!newtrkCol || newtrkCol->size()==0) {
01976 log << MSG::ERROR << "Could not find RecMdcTrackCol" << endreq;
01977 return StatusCode::SUCCESS;
01978 }
01979 log << MSG::INFO << "Begin to check RecMdcTrackCol"<<endreq;
01980
01981 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
01982
01983 for( int tempntrack=0; iter_trk != newtrkCol->end(); iter_trk++,tempntrack++) {
01984 log << MSG::DEBUG << "retrieved MDC track:"
01985 << " Track Id: " << (*iter_trk)->trackId()
01986 << " Dr: " <<(*iter_trk)->helix(0)
01987 << " Phi0: " << (*iter_trk)->helix(1)
01988 << " kappa: " << (*iter_trk)->helix(2)
01989 << " Dz: " << (*iter_trk)->helix(3)
01990 << " Tanl: " << (*iter_trk)->helix(4)
01991 << " Phi terminal: "<< (*iter_trk)->getFiTerm()
01992 << endreq
01993 << "Number of hits: "<< (*iter_trk)->getNhits()
01994 << " Number of stereo hits " << (*iter_trk)->nster()
01995 << endreq;
01996
01997
01998 const HepPoint3D pivot0(0.,0.,0.);
01999 HepVector a(5,0);
02000
02001 a[0] = (*iter_trk)->helix(0);
02002 a[1] = (*iter_trk)->helix(1);
02003 a[2] = (*iter_trk)->helix(2);
02004 a[3] = (*iter_trk)->helix(3);
02005 a[4] = (*iter_trk)->helix(4);
02006
02007
02008 if (abs(a[0])>Estparam.MDC_drCut() || abs(a[3])>Estparam.MDC_dzCut() || abs(a[4])>500.) continue;
02009
02010 double phi0 = a[1];
02011 double kappa = abs(a[2]);
02012 double dirmag = sqrt(1. + a[4]*a[4]);
02013
02014 double mom = abs(dirmag/kappa);
02015 double beta=mom/sqrt(mom*mom+PIMAS2);
02016 if (particleId[tempntrack]== 1) { beta=mom/sqrt(mom*mom+ELMAS2);}
02017 if(particleId[tempntrack]== 5) { beta=mom/sqrt(mom*mom+PROTONMAS2);}
02018
02019
02020 Helix helix0(pivot0,a);
02021 double rho = helix0.radius();
02022 double unit_s = abs(rho * dirmag);
02023
02024 helix0.ignoreErrorMatrix();
02025 HepPoint3D hcen = helix0.center();
02026 double xc= hcen(0);
02027 double yc= hcen(1);
02028
02029 if( xc==0.0 && yc==0.0 ) continue;
02030
02031 double direction =1.;
02032 if(optCosmic!=0) {
02033 double phi = atan2(helix0.momentum(0.).y(),helix0.momentum(0.).x());
02034 if(phi> 0. && phi <= M_PI) direction=-1.;
02035 }
02036
02037 IMdcGeomSvc* mdcGeomSvc;
02038 StatusCode sc = service("MdcGeomSvc", mdcGeomSvc);
02039 double zeast;
02040 double zwest;
02041 double m_vp[43]={0.}, m_zst[43]={0.};
02042 for(int lay=0; lay<43; lay++){
02043 zwest = mdcGeomSvc->Wire(lay, 0)->Forward().z();
02044 zeast = mdcGeomSvc->Wire(lay, 0)->Backward().z();
02045
02046
02047 if(lay < 8) m_vp[lay] = 220.0;
02048 else m_vp[lay] = 240.0;
02049
02050 if( 0 == (lay % 2) ){
02051 m_zst[lay] = zwest;
02052 } else{
02053 m_zst[lay] = zeast;
02054 }
02055 }
02056
02057
02058 log << MSG::DEBUG << "hitList of this track:" << endreq;
02059 HitRefVec gothits = (*iter_trk)->getVecHits();
02060 HitRefVec::iterator it_gothit = gothits.begin();
02061 for( ; it_gothit != gothits.end(); it_gothit++){
02062
02063 log << MSG::DEBUG << "hits Id: "<<(*it_gothit)->getId()
02064 << " hits MDC layerId wireId " <<MdcID::layer((*it_gothit)->getMdcId())
02065 << " "<<MdcID::wire((*it_gothit)->getMdcId())
02066 << endreq
02067 << " hits TDC " <<(*it_gothit)->getTdc()
02068 << endreq;
02069
02070 int layer=MdcID::layer((*it_gothit)->getMdcId());
02071 int wid=MdcID::wire((*it_gothit)->getMdcId());
02072 double tdc=(*it_gothit)->getTdc() ;
02073
02074 double trkchi2=(*iter_trk)->chi2();
02075 if(trkchi2>100)continue;
02076 double hitChi2=(*it_gothit)->getChisqAdd();
02077 HepVector helix_par = (*iter_trk)->helix();
02078 HepSymMatrix helixErr=(*iter_trk)->err();
02079
02080 if((layer>=8&&layer<=19) ||(layer>=36&&layer<=42)){
02081
02083
02084
02085 const MdcGeoWire* GeoRef = mdcGeomSvc->Wire(layer,wid);
02086
02089
02090
02091
02092
02094
02095
02096 if(Estparam.MDC_Inner()==0 && layer <=3) continue;
02097
02098 double xw = GeoRef->Forward().x()/10;
02099 double yw = GeoRef->Forward().y()/10;
02100
02101 HepPoint3D pivot1(xw,yw,0.);
02102 helix0.pivot(pivot1);
02103 double zw=helix0.a()[3];
02104
02105
02106 double dphi = (-xc*(xw-xc)-yc*(yw-yc)) /
02107 sqrt((xc*xc+yc*yc)*((xw-xc)*(xw-xc)+(yw-yc)*(yw-yc)));
02108 dphi = acos(dphi);
02109 double pathtof = abs(unit_s * dphi);
02110 if (kappa!=0) {
02111 toft = pathtof/VLIGHT/beta;
02112 } else {
02113 toft = pathtof/VLIGHT;
02114 }
02115
02116
02119
02120 if (zw >(GeoRef->Backward().z())/10) zw =(GeoRef->Backward().z())/10;
02121 if (zw <(GeoRef->Forward().z())/10) zw =(GeoRef->Forward().z())/10;
02122
02123 double slant = GeoRef ->Slant();
02124 prop = zw / cos(slant) / VELPROP;
02125
02126 double Tw = 0;
02127
02128
02129
02130
02131
02132 double driftt;
02133 double dummy;
02134 int lr=1;
02135
02136 double p[3];
02137 p[0]=helix0.momentum(0.).x();
02138 p[1]=helix0.momentum(0.).y();
02139 double pos[2];
02140 pos[0]=xw; pos[1]=yw;
02141 double alpha;
02143
02144
02145 double dist = 0.;
02146 m_mdcCheckUtil = new MdcCheckUtil();
02147 dist=(m_mdcCheckUtil->doca(layer, wid, helix_par, helixErr))*10.0;
02148 if(dist<0.) lr=-1;
02149 dist=fabs(dist);
02150 if(dist> 0.4*(mdcGeomSvc->Layer(layer))->PCSiz()) continue;
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164
02165
02166
02167
02168 int idummy;
02169
02170 if(!m_useXT) {driftt = dist/Estparam.vdrift();}
02171 else {
02172 double entrance=(*it_gothit)->getEntra();
02173 driftt = m_mdcCalibFunSvc->distToDriftTime(dist, layer, wid,lr,entrance );
02174 }
02175 if(m_useT0cal)
02176 {
02177 T0_cal=m_mdcCalibFunSvc->getT0(layer, wid)+m_mdcCalibFunSvc->getTimeWalk(layer,tdc);
02178 }
02179
02180 double zprop = fabs(zw - m_zst[layer]);
02181 double tp = zprop / m_vp[layer];
02182
02183 if(driftt>tdc) continue;
02184 double difft=tdc-driftt-toft-tp-T0_cal;
02185 if(ndriftt>=500) break;
02186 if(difft<-10) continue;
02187 Mdc_t0Arr[ndriftt]=difft;
02188
02189 sum_EstimeMdc=sum_EstimeMdc+difft;
02190 ndriftt++;
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200 double tev= -t0_minus_TDC[wid]+ driftt;
02201 if(Estparam.MDC_Tof() !=0) tev += direction*toft;
02202 if(Estparam.MDC_Prop()!=0) tev += prop;
02204
02205
02206
02207 nhits_ax++;
02208 tev_ax[nhits_ax-1]=tev;
02209
02210 if(Estparam.MDC_Debug()!=0) log << MSG::INFO << "*** tev ***" <<tev <<endreq;
02211 double driftt_mea = t0_minus_TDC[wid];
02212
02213 if(abs(driftt - driftt_mea)<75.) {
02214
02215 nhits_ax2++;
02216 if(Estparam.MDC_Debug()!=0) log << MSG::INFO << "*** tev2 ***" <<tev <<endreq;
02217 }
02218 }
02219
02220
02221 else if(((layer>=4&&layer<=7)||(layer>=20&&layer<=35))&&m_useSw){
02222
02223 IMdcGeomSvc* mdcGeomSvc;
02224 StatusCode sc = service("MdcGeomSvc", mdcGeomSvc);
02225 const MdcGeoWire* GeoRef = mdcGeomSvc->Wire(layer,wid);
02226
02227
02229
02230 double bx= GeoRef->Backward().x()/10;
02231 double by= GeoRef->Backward().y()/10;
02232 double bz= GeoRef->Backward().z()/10;
02233 double fx= GeoRef->Forward().x()/10;
02234 double fy= GeoRef->Forward().y()/10;
02235 double fz= GeoRef->Forward().z()/10;
02236
02239 HepPoint3D fwd(fx,fy,fz);
02240 HepPoint3D bck(bx,by,bz);
02241
02242 Hep3Vector wire = (CLHEP::Hep3Vector)bck - (CLHEP::Hep3Vector)fwd;
02243 HepPoint3D try1=(fwd + bck) * .5;
02244 helix0.pivot(try1);
02245 HepPoint3D try2 = (helix0.x(0).z() - bck.z())/ wire.z() * wire + bck;
02246 helix0.pivot(try2);
02247 HepPoint3D try3 = (helix0.x(0).z() - bck.z())/ wire.z() * wire + bck;
02248 helix0.pivot(try3);
02249
02250 double xh = helix0.x(0.).x();
02251 double yh = helix0.x(0.).y();
02252 double z = helix0.x(0.).z();
02253
02254
02255 double dphi = (-xc*(xh-xc)-yc*(yh-yc)) /
02256 sqrt((xc*xc+yc*yc)*((xh-xc)*(xh-xc)+(yh-yc)*(yh-yc)));
02257 dphi = acos(dphi);
02258 double pathtof = abs(unit_s * dphi);
02259 if (kappa!=0) {
02260 toft = pathtof/VLIGHT/beta;
02261 } else {
02262 toft = pathtof/VLIGHT;
02263 }
02264
02265
02266
02267 if (z != 9999.) {
02268
02269 if(z < fz ) z = fz;
02270
02271 if(z > bz ) z = bz;
02272 double slant = GeoRef->Slant();
02273 prop = z / cos(slant) / VELPROP;
02274 } else {
02275 prop = 0.;
02276 }
02277
02278
02279 double Tw = 0;
02280
02281
02282
02283
02284
02285 double driftt=0;
02286 double dummy;
02287
02288 double xw = fx + (bx-fx)/(bz-fz)*(z-fz);
02289 double yw = fy + (by-fy)/(bz-fz)*(z-fz);
02290
02291 HepPoint3D pivot1(xw,yw,z);
02292 helix0.pivot(pivot1);
02293
02294 double zw=helix0.a()[3];
02295
02296 int lr=1;
02297
02298 double p[3];
02299 p[0]=helix0.momentum(0.).x();
02300 p[1]=helix0.momentum(0.).y();
02301 double pos[2];
02302 pos[0]=xw; pos[1]=yw;
02303 double alpha;
02305
02306
02307 double dist=0.;
02308 m_mdcCheckUtil = new MdcCheckUtil();
02309 dist=(m_mdcCheckUtil->doca(layer, wid, helix_par, helixErr))*10.0;
02310 if(dist<0.) lr=-1;
02311 dist=fabs(dist);
02312 if(dist> 0.4*(mdcGeomSvc->Layer(layer))->PCSiz()) continue;
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324
02325
02326
02327
02328
02329
02330 if(!m_useXT){driftt = dist/(Estparam.vdrift());}
02331 else {
02332 double entrance=(*it_gothit)->getEntra();
02333 driftt = m_mdcCalibFunSvc->distToDriftTime(dist, layer, wid,lr,entrance );
02334 }
02335 if(m_useT0cal)
02336 {
02337 T0_cal=m_mdcCalibFunSvc->getT0(layer, wid)+m_mdcCalibFunSvc->getTimeWalk(layer,tdc);
02338 }
02339
02340 double zprop = fabs(zw - m_zst[layer]);
02341 double tp = zprop / m_vp[layer];
02342
02343 if(driftt>tdc) continue;
02344 double difft=tdc-driftt-toft-tp-T0_cal;
02345 if(difft<-10) continue;
02346 if(ndriftt>=500) break;
02347 Mdc_t0Arr[ndriftt]=difft;
02348
02349
02350
02351 sum_EstimeMdc=sum_EstimeMdc+difft;
02352 ndriftt++;
02353
02354
02355
02356
02357 double tev= -t0_minus_TDC[wid]+ driftt;
02358 if(Estparam.MDC_Tof() !=0) tev += direction*toft;
02359 if(Estparam.MDC_Prop()!=0) tev += prop;
02361
02362
02363
02364
02365
02366 nhits_st++;
02367 tev_st[nhits_st-1]= tev;
02368
02369 if(Estparam.MDC_Debug()!=0) log << MSG::INFO << "*** tev_st ***" <<tev <<endreq;
02370 double driftt_mea = t0_minus_TDC[wid];
02371
02372 if(abs(driftt - driftt_mea) <75.) {
02373
02374 nhits_st2++;
02375 if(Estparam.MDC_Debug()!=0) log << MSG::INFO << "*** tev_st2 ***" <<tev <<endreq;
02376 }
02377 }
02378
02379 }
02380 nmatch_mdc++;
02381 }
02382
02383
02384 if(m_ntupleflag && m_tuple2) g_nmatchmdc = nmatch_mdc;
02385 if(ndriftt!=0){
02386 if(m_mdcopt) {
02387 sum_EstimeMdc=Opt_new(Mdc_t0Arr,ndriftt,400.0);
02388 }
02389 else { sum_EstimeMdc= sum_EstimeMdc/ndriftt;}
02390 if(m_ntupleflag && m_tuple2) g_EstimeMdc=sum_EstimeMdc;
02391 t_Est=sum_EstimeMdc + tOffset_b;
02392 if(t_Est<0) t_Est=0;
02393 if(optCosmic==0){
02394 tEstFlag=102;
02395
02396 if(runNo>0)
02397 {
02398 nbunch=((int)(t_Est-offset))/bunchtime;
02399 if(((int)(t_Est-offset))%bunchtime>bunchtime/2) nbunch=nbunch+1;
02400 t_Est=nbunch*bunchtime+offset + tOffset_b;
02401 }
02402 if(runNo<0)
02403 {
02404 nbunch=((int)(t_Est-offset))/8;
02405 if(((int)(t_Est-offset))%8>4 ) nbunch=nbunch+1;
02406 t_Est=nbunch*8+offset + tOffset_b;
02407 }
02408
02409
02410
02411
02412
02413
02414
02415
02416 }
02417 if(optCosmic){
02418 t_Est=sum_EstimeMdc;
02419 tEstFlag=202;
02420 }
02421 }
02422 if(m_ntupleflag && m_tuple2) g_ndriftt=ndriftt;
02423 }
02424
02425 if(t_Est!=-999){
02426
02427 if((!m_beforrec) && (Testime_fzisan != t_Est) ){
02428 if(tEstFlag==211) tEstFlag=213;
02429 if(tEstFlag==212) tEstFlag=216;
02430 if(tEstFlag==111) tEstFlag=113;
02431 if(tEstFlag==112) tEstFlag=116;
02432 }
02433
02434 if( optCosmic ){
02435 StatusCode scStoreTds = storeTDS(t_Est,tEstFlag,t_quality);
02436 if (scStoreTds!=StatusCode::SUCCESS){ return scStoreTds; }
02437 }else if(!optCosmic){
02438 StatusCode scStoreTds = storeTDS(t_Est,tEstFlag,t_quality);
02439 if (scStoreTds!=StatusCode::SUCCESS){ return scStoreTds; }
02440 }
02441 }else{
02442
02443 if(m_beforrec){
02444
02445
02446 double segTest = Testime_fzisan + tOffset_b;
02447 int segFlag = TestimeFlag_fzisan;
02448 double segQuality = TestimeQuality_fzisan;
02449 StatusCode scStoreTds = storeTDS(segTest,segFlag,segQuality);
02450 if (scStoreTds!=StatusCode::SUCCESS){ return scStoreTds; }
02451 }
02452 }
02453
02454
02455
02456 SmartDataPtr<RecEsTimeCol> arecestimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
02457 if (!arecestimeCol) {
02458 if(m_debug==4) log << MSG::WARNING << "Could not find RecEsTimeCol" << endreq;
02459 return( StatusCode::SUCCESS);
02460 }
02461 RecEsTimeCol::iterator iter_evt = arecestimeCol->begin();
02462 for(; iter_evt!=arecestimeCol->end(); iter_evt++){
02463 log << MSG::INFO
02464 << "Test = "<<(*iter_evt)->getTest()
02465 << ", Status = "<<(*iter_evt)->getStat()
02466 <<endreq;
02467 if(m_ntupleflag && m_tuple2){
02468 g_Testime=(*iter_evt)->getTest();
02469 }
02470
02471 }
02472
02473 if(m_ntupleflag){
02474 if(m_tuple2){
02475 m_estFlag=tEstFlag;
02476 m_estTime=t_Est;
02477 StatusCode status = m_tuple2->write();
02478 if (!status.isSuccess()) {
02479 log << MSG::ERROR << "Can't fill ntuple!" << endreq;
02480 }
02481 }
02482 }
02483 return StatusCode::SUCCESS;
02484 }