/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/TofRec/TofRec-00-04-46/src/TofTrack.cxx

Go to the documentation of this file.
00001 #include "Identifier/Identifier.h"
00002 #include "Identifier/TofID.h"
00003 #include "TofCaliSvc/ITofCaliSvc.h"
00004 #include "DstEvent/TofHitStatus.h"
00005 #include "TofRec/TofConstants.h"
00006 #include "TofRec/TofTrack.h"
00007 
00008 extern ITofCaliSvc*  tofCaliSvc;
00009 
00010 TofTrack::TofTrack( int run, int event ) {
00011   m_run = run;
00012   m_event = event;
00013   m_trackId = -1;
00014   m_tofTrackId = -1;
00015   m_id1 = -9;
00016   m_id2 = -9;
00017   m_istrip1 = -9;
00018   m_istrip2 = -9;
00019   m_hitCase = NoHit;
00020   m_momentum = -99.0;
00021   m_path  = 0.0;
00022   m_path1 = 0.0;
00023   m_path2 = 0.0;
00024   m_zrhit1 = 99.0;
00025   m_errzr1 = 99.0;
00026   m_zrhit2 = 99.0;
00027   m_errzr2 = 99.0;
00028   m_xhit1  = 99.0;
00029   m_yhit1  = 99.0;
00030   m_xhit2  = 99.0;
00031   m_yhit2  = 99.0;
00032   for( unsigned int i=0; i<5; i++ ) {
00033     m_kal[i]  = -1;
00034     m_zr1[i]  = 99.0;
00035     m_zr2[i]  = 99.0;
00036     m_ezr1[i] = 99.0;
00037     m_ezr2[i] = 99.0;
00038   }
00039   if( m_tofData1.size()>0 ) {
00040     m_tofData1.clear();
00041   }
00042   if( m_tofData2.size()>0 ) {
00043     m_tofData2.clear();
00044   }
00045   if( m_tofData3.size()>0 ) {
00046     m_tofData3.clear();
00047   }
00048   if( m_tofData4.size()>0 ) {
00049     m_tofData4.clear();
00050   }
00051   m_quality1 = 0;
00052   m_quality2 = 0;
00053   m_quality  = 10;
00054 
00055   m_delStrip1 = 20;
00056   m_delStrip2 = 20;
00057 
00058   m_tofId1 = -9;
00059   m_tofId2 = -9;
00060   m_strip1 = -9;
00061   m_strip2 = -9;
00062 
00063   m_ph11  = -99.0;
00064   m_ph12  = -99.0;
00065   m_ph21  = -99.0;
00066   m_ph22  = -99.0;
00067   m_ph1   = -99.0;
00068   m_ph2   = -99.0;
00069   m_ph    = -99.0;
00070 
00071   for( unsigned int i=0; i<5; i++ ) {
00072     m_tof11[i]  = 0.0;
00073     m_tof12[i]  = 0.0;
00074     m_tof21[i]  = 0.0;
00075     m_tof22[i]  = 0.0;
00076     m_tof1[i]   = 0.0;
00077     m_tof2[i]   = 0.0;
00078     m_tof[i]    = 0.0;
00079   }
00080 
00081   m_sigma11 = -99.0;
00082   m_sigma12 = -99.0;
00083   m_sigma21 = -99.0;
00084   m_sigma22 = -99.0;
00085   m_sigma1  = -99.0;
00086   m_sigma2  = -99.0;
00087   m_sigma   = -99.0;
00088 
00089   m_qch1  = -99.0;
00090   m_qch2  = -99.0;
00091   m_qch3  = -99.0;
00092   m_qch4  = -99.0;
00093   m_adc1  = -99.0;
00094   m_adc2  = -99.0;
00095   m_adc3  = -99.0;
00096   m_adc4  = -99.0;
00097   m_tdc1  = -99.0;
00098   m_tdc2  = -99.0;
00099   m_tdc3  = -99.0;
00100   m_tdc4  = -99.0;
00101 
00102   for( unsigned int i=0; i<5; i++ ) {
00103     m_texpInner[i] = -99.0;
00104     m_texpOuter[i] = -99.0;
00105     m_texp[i] = -99.0;
00106   }
00107 
00108   m_ztdc1 = -99.0;
00109   m_ztdc2 = -99.0;
00110   m_zadc1 = -99.0;
00111   m_zadc2 = -99.0;
00112 
00113   m_estime = -99.0;
00114   m_tdiff1  = -99.0;
00115   m_tdiff2  = -99.0;
00116 
00117   m_flag  = 0;
00118 
00119   return;
00120 }
00121 
00122 
00123 TofTrack::~TofTrack() {
00124   if( m_tofData1.size()>0 ) {
00125     m_tofData1.clear();
00126   }
00127   if( m_tofData2.size()>0 ) {
00128     m_tofData2.clear();
00129   }
00130   if( m_tofData3.size()>0 ) {
00131     m_tofData3.clear();
00132   }
00133   if( m_tofData4.size()>0 ) {
00134     m_tofData4.clear();
00135   }
00136   return;
00137 }
00138 
00139 //------- setExtTrack ----------------------------------------------
00140 //  get information from RecExtTrackCol
00141 //  tofId1(), tofId2(), hitCase(),
00142 //  p(), path1(), path2(), zrhit1(), zrhit2(), errz1(), errz2()
00143 //  quality() = 3 ( no hit )
00144 //
00145 void TofTrack::setExtTrack( RecExtTrack* extTrack, double costheta, double p[5], int kal[5], double t0, int t0Stat ) {
00146 
00147   m_estime = t0;
00148   m_t0Stat = t0Stat;
00149 
00150   int tofId1 = extTrack->tof1VolumeNumber();
00151   int tofId2 = extTrack->tof2VolumeNumber();
00152 
00153   int iExist1 = -1;
00154   int iExist2 = -1;
00155   if( tofId1<0 ) {
00156     if( extTrack->tof1VolumeNumber(3)>-1 ) {
00157       iExist1 = 3;
00158     }
00159     else if( extTrack->tof1VolumeNumber(1)>-1 ) {
00160       iExist1 = 1;
00161     }
00162     else if( extTrack->tof1VolumeNumber(4)>-1 ) {
00163       iExist1 = 4;
00164     }
00165     else if( extTrack->tof1VolumeNumber(0)>-1 ) {
00166       iExist1 = 0;
00167     }
00168     if( iExist1!=-1 ) {
00169       tofId1 = extTrack->tof1VolumeNumber(iExist1);
00170     }
00171   }
00172   if( tofId2<0 ) {
00173     if( extTrack->tof2VolumeNumber(3)>-1 ) {
00174       iExist2 = 3;
00175     }
00176     else if( extTrack->tof2VolumeNumber(1)>-1 ) {
00177       iExist2 = 1;
00178     }
00179     else if( extTrack->tof2VolumeNumber(4)>-1 ) {
00180       iExist2 = 4;
00181     }
00182     else if( extTrack->tof2VolumeNumber(0)>-1 ) {
00183       iExist2 = 0;
00184     }
00185     if( iExist2!=-1 ) {
00186       tofId2 = extTrack->tof2VolumeNumber(iExist2);
00187     }
00188   }
00189   if( iExist1 == -1 ) { iExist1 = 2; }
00190   if( iExist2 == -1 ) { iExist2 = 2; }
00191   
00192   m_barrel = 3;
00193   if( tofId1>=0 && tofId1<=87 ) {
00194     m_id1 = tofId1;
00195     m_barrel = 1;
00196     m_hitCase = InnerLayer;
00197   }
00198   else if( tofId1>=176 && tofId1<=223 ) {
00199     m_id1 = tofId1 - 176 + 48;
00200     m_barrel = 2;
00201     m_hitCase = WestEndcap;
00202     if( costheta>0.0 ) {
00203       m_id1 = -9;
00204       m_barrel = 3;
00205       m_hitCase = NoHit;
00206     }
00207   }
00208   else if( tofId1>=224 && tofId1<=271 ) { 
00209     m_id1 = tofId1 - 176 - 48;
00210     m_barrel = 0;
00211     m_hitCase = EastEndcap;
00212     if( costheta<0.0 ) {
00213       m_id1 = -9;
00214       m_barrel = 3;
00215       m_hitCase = NoHit;
00216     }
00217   }
00218   else if( tofId1>=272 && tofId1<=1135 ) { 
00219     m_id1 = tofId1 - 176 - 96;
00220     m_istrip1 = m_id1%12;
00221     m_id1 = m_id1/12;
00222     if( tofId1>=272 && tofId1<=703 ) {
00223       if( costheta>0.0 ) {
00224         m_barrel = 4;
00225         m_hitCase = EastEndcapMRPC;
00226       }
00227       else {
00228         m_id1 = -9;
00229         m_istrip1 = -9;
00230       }
00231     }
00232     else if( tofId1>=704 && tofId1<=1135 ) { 
00233       if( costheta<0.0 ) {
00234         m_barrel = 5;
00235         m_hitCase = WestEndcapMRPC;
00236       }
00237       else {
00238         m_id1 = -9;
00239         m_istrip1 = -9;
00240       }
00241     }
00242   }
00243   else {
00244     m_barrel = 3;
00245     m_hitCase = NoHit;
00246   }
00247 
00248   if( tofId2>=88 && tofId2<=175 ) {
00249     m_id2 = tofId2;
00250     m_barrel = 1;
00251     if( m_hitCase == InnerLayer ) {
00252       m_hitCase = DoubleLayer;
00253     }
00254     else if( m_hitCase==NoHit ) {
00255       m_hitCase = OuterLayer;
00256     }
00257   }
00258   else if( tofId2>=272 && tofId2<=1135 ) { 
00259     m_id2 = tofId2 - 176 - 96;
00260     m_istrip2 = m_id2%12;
00261     m_id2 = m_id2/12;
00262     if( m_hitCase==EastEndcapMRPC || m_hitCase==WestEndcapMRPC || m_hitCase==NoHit ) {
00263       if( tofId2>=272 && tofId2<=703 ) {
00264         if( costheta>0.0 ) {
00265           m_barrel = 4;
00266           m_hitCase = EastEndcapMRPC;
00267         }
00268         else {
00269           m_id2 = -9;
00270           m_istrip2 = -9;
00271         }
00272       }
00273       else if( tofId2>=704 && tofId2<=1135 ) { 
00274         if( costheta<0.0 ) {
00275           m_barrel = 5;
00276           m_hitCase = WestEndcapMRPC;
00277         }
00278         else {
00279           m_id2 = -9;
00280           m_istrip2 = -9;
00281         }
00282       }
00283     }
00284   }
00285 
00286   m_trackId = extTrack->trackId();
00287 
00288   m_momentum = extTrack->tof1Momentum().r();
00289   if( !( tofId1>=272 && tofId1<=1135 ) && ( m_hitCase == EastEndcapMRPC || m_hitCase == WestEndcapMRPC )  ){
00290     m_momentum = extTrack->tof2Momentum().r();
00291   }
00292 
00293   if( m_hitCase == InnerLayer || m_hitCase == DoubleLayer || m_hitCase == EastEndcap || m_hitCase == WestEndcap || ( ( m_hitCase == EastEndcapMRPC || m_hitCase == WestEndcapMRPC ) && ( tofId1>=272 && tofId1<=1135 ) ) ) {
00294     m_path1  = extTrack->tof1Path(iExist1);
00295     m_theta1 = extTrack->tof1Momentum(iExist1).rho()/extTrack->tof1Momentum(iExist1).r();
00296     m_phi1   = extTrack->tof1Position(iExist1).phi();
00297     for( unsigned int i=0; i<5; i++ ) {
00298       m_texpInner[i] = extTrack->tof1(i);
00299       if( fabs(m_texpInner[i]+99.0)<1.0e-6 ) {
00300         double beta = p[iExist1]/sqrt(p[iExist1]*p[iExist1]+mass[iExist1]*mass[iExist1]);
00301         double betaNew = p[i]/sqrt(p[i]*p[i]+mass[i]*mass[i]);
00302         m_texpInner[i] = beta*extTrack->tof1(iExist1)/betaNew;
00303       }
00304     }
00305     if( m_hitCase == InnerLayer || m_hitCase == DoubleLayer ) {
00306       m_xhit1  = extTrack->tof1Position(iExist1).x();
00307       m_yhit1  = extTrack->tof1Position(iExist1).y();
00308       m_zrhit1 = extTrack->tof1Position(iExist1).z();
00309       m_errzr1 = extTrack->tof1PosSigmaAlongZ(iExist1);
00310       for( unsigned int i=0; i<5; i++ ) {
00311         m_zr1[i]  = extTrack->tof1Position(i).z();
00312         m_ezr1[i] = extTrack->tof1PosSigmaAlongZ(i); 
00313         if( fabs(m_zr1[i]+99.0)<1.0e-6 ) {
00314           m_zr1[i]  = m_zrhit1;
00315           m_ezr1[i] = m_errzr1;
00316         }
00317       }
00318     }
00319     else if( m_hitCase == EastEndcap || m_hitCase == WestEndcap ) {
00320       m_xhit1  = extTrack->tof1Position(iExist1).x();
00321       m_yhit1  = extTrack->tof1Position(iExist1).y();
00322       m_zrhit1 = extTrack->tof1Position(iExist1).rho();
00323       m_errzr1 = sqrt( extTrack->tof1PosSigmaAlongX(iExist1)*extTrack->tof1PosSigmaAlongX(iExist1) + extTrack->tof1PosSigmaAlongY(iExist1)*extTrack->tof1PosSigmaAlongY(iExist1) );
00324       for( unsigned int i=0; i<5; i++ ) {
00325         m_zr1[i]  = extTrack->tof1Position(i).rho();
00326         m_ezr1[i] = sqrt( extTrack->tof1PosSigmaAlongX(i)*extTrack->tof1PosSigmaAlongX(i) + extTrack->tof1PosSigmaAlongY(i)*extTrack->tof1PosSigmaAlongY(i) ); 
00327         if( fabs(m_zr1[i]+99.0)<1.0e-6 ) {
00328           m_zr1[i]  = m_zrhit1;
00329           m_ezr1[i] = m_errzr1;
00330         }
00331       }
00332     }
00333     else if( ( m_hitCase == EastEndcapMRPC || m_hitCase == WestEndcapMRPC ) && ( tofId1>=272 && tofId1<=1135 ) ) { 
00334       m_xhit1  = extTrack->tof1Position(iExist1).x();
00335       m_yhit1  = extTrack->tof1Position(iExist1).z();
00336       m_zrhit1 = extTrack->tof1Position(iExist1).x();
00337       m_errzr1 = extTrack->tof1PosSigmaAlongX(iExist1);
00338       for( unsigned int i=0; i<5; i++ ) {
00339         m_zr1[i]  = extTrack->tof1Position(i).x();
00340         m_ezr1[i] = extTrack->tof1PosSigmaAlongX(i);
00341         if( fabs(m_zr1[i]+99.0)<1.0e-6 ) {
00342           m_zr1[i]  = m_zrhit1;
00343           m_ezr1[i] = m_errzr1;
00344         }
00345       }
00346     }
00347   }
00348 
00349   if( m_hitCase == OuterLayer || m_hitCase == DoubleLayer || ( ( m_hitCase == EastEndcapMRPC || m_hitCase == WestEndcapMRPC ) && ( tofId2>=272 && tofId2<=1135 ) ) ) {
00350     m_path2  = extTrack->tof2Path(iExist2);
00351     m_theta2 = extTrack->tof2Momentum(iExist2).rho()/extTrack->tof2Momentum(iExist2).r();
00352     m_phi2   = extTrack->tof2Position(iExist2).phi();
00353     for( unsigned int i=0; i<5; i++ ) {
00354       m_texpOuter[i] = extTrack->tof2(i);
00355       if( fabs(m_texpOuter[i]+99.0)<1.0e-6 ) {
00356         double beta = p[iExist2]/sqrt(p[iExist2]*p[iExist2]+mass[iExist2]*mass[iExist2]);
00357         double betaNew = p[i]/sqrt(p[i]*p[i]+mass[i]*mass[i]);
00358         m_texpOuter[i] = beta*extTrack->tof2(iExist2)/betaNew;
00359       }
00360     }
00361     if( m_hitCase == OuterLayer || m_hitCase == DoubleLayer ) {
00362       m_xhit2  = extTrack->tof2Position(iExist2).x();
00363       m_yhit2  = extTrack->tof2Position(iExist2).y();
00364       m_zrhit2 = extTrack->tof2Position(iExist2).z();
00365       m_errzr2 = extTrack->tof2PosSigmaAlongZ(iExist2);
00366       for( unsigned int i=0; i<5; i++ ) {
00367         m_zr2[i]  = extTrack->tof2Position(i).z();
00368         m_ezr2[i] = extTrack->tof2PosSigmaAlongZ(i); 
00369         if( fabs(m_zr2[i]+99.0)<1.0e-6 ) {
00370           m_zr2[i]  = m_zrhit2;
00371           m_ezr2[i] = m_errzr2;
00372         }
00373       }
00374     }
00375     else if( ( m_hitCase == EastEndcapMRPC || m_hitCase == WestEndcapMRPC ) && ( tofId2>=272 && tofId2<=1135 ) ) { 
00376       m_xhit2  = extTrack->tof2Position(iExist2).x();
00377       m_yhit2  = extTrack->tof2Position(iExist2).z();
00378       m_zrhit2 = extTrack->tof2Position(iExist2).x();
00379       m_errzr2 = extTrack->tof2PosSigmaAlongX(iExist2);
00380       for( unsigned int i=0; i<5; i++ ) {
00381         m_zr2[i]  = extTrack->tof2Position(i).x();
00382         m_ezr2[i] = extTrack->tof2PosSigmaAlongX(i);
00383         if( fabs(m_zr2[i]+99.0)<1.0e-6 ) {
00384           m_zr2[i]  = m_zrhit2;
00385           m_ezr2[i] = m_errzr2;
00386         }
00387       }
00388     }
00389   }
00390 
00391   if( m_hitCase == NoHit ) { m_quality = 11; }
00392 
00393   for( unsigned int i=0; i<5; i++ ) {
00394     m_kal[i] = kal[i];
00395   }
00396 
00397   return;
00398 }
00399 
00400 
00401 //------- get Multi hit  ----------------------------------------------
00402 //  get Multi-hit of one TOF Counter
00403 //
00404 void TofTrack::getMultiHit( TofTrack*& track ) {
00405   if( m_hitCase == InnerLayer || m_hitCase == OuterLayer || m_hitCase == DoubleLayer ) {
00406 
00407     if( ( m_hitCase==InnerLayer || m_hitCase==DoubleLayer ) && ( track->hitCase()==InnerLayer || track->hitCase()==DoubleLayer ) ) {
00408       if( ( abs(m_id1-track->id1())<=1 ) || ( m_id1==0 && track->id1()==87 ) || ( m_id1==87 && track->id1()==0 ) ) {
00409         track->setQuality1( ( track->quality1() | 0x400 ) );
00410         m_quality1 = ( m_quality1 | 0x400 );    
00411       }
00412     }
00413 
00414     if( ( m_hitCase==OuterLayer || m_hitCase==DoubleLayer ) && ( track->hitCase()==OuterLayer || track->hitCase()==DoubleLayer ) ) {
00415       if( ( abs(m_id2-track->id2())<=1 ) || ( m_id2==88 && track->id2()==175 ) || ( m_id2==175 && track->id2()==88 ) ) {
00416         track->setQuality2( ( track->quality2() | 0x400 ) );
00417         m_quality2 = ( m_quality2 | 0x400 );    
00418       }
00419     }
00420 
00421   }
00422   else if( m_hitCase == EastEndcap ) {
00423     if( track->hitCase()==EastEndcap ) {
00424       if( ( abs(m_id1-track->id1())<=1 ) || ( m_id1==0 && track->id1()==47 ) || ( m_id1==47 && track->id1()==0 ) ) {
00425         track->setQuality1( ( track->quality1() | 0x400 ) );
00426         m_quality1 = ( m_quality1 | 0x400 );    
00427       } 
00428     }
00429   }
00430   else if( m_hitCase == WestEndcap ) {
00431     if( track->hitCase()==WestEndcap ) {
00432       if( ( abs(m_id1-track->id1())<=1 ) || ( m_id1==48 && track->id1()==95 ) || ( m_id1==95 && track->id1()==48 ) ) {
00433         track->setQuality1( ( track->quality1() | 0x400 ) );
00434         m_quality1 = ( m_quality1 | 0x400 );    
00435       } 
00436     }
00437   }
00438   if( m_hitCase == EastEndcapMRPC || m_hitCase == WestEndcapMRPC ) {
00439     if( ( m_hitCase==EastEndcapMRPC && track->hitCase()==EastEndcapMRPC ) || ( m_hitCase==WestEndcapMRPC && track->hitCase()==WestEndcapMRPC ) ) {
00440       if( m_id1>=0 ) {
00441         if( ( m_id1==track->id1() ) && abs(m_istrip1-track->strip1())<=1 ) {
00442           track->setQuality1( ( track->quality1() | 0x400 ) );
00443           m_quality1 = ( m_quality1 | 0x400 );
00444         }
00445       }
00446       if( m_id2>=0 ) {
00447         if( ( m_id2==track->id2() ) && abs(m_istrip2-track->strip2())<=1 ) {
00448           track->setQuality1( ( track->quality1() | 0x400 ) );
00449           m_quality1 = ( m_quality1 | 0x400 );
00450         }
00451       }
00452     }
00453   }
00454 
00455   return;
00456 }
00457 
00458 
00459 //------- setTofData  --------------------------------------------
00460 //  do TOF hits and extrapolated track match
00461 //  tofTrackId(), tofMod1(), tofMod2()
00462 //  quality() = 3 ( no hit )
00463 //
00464 void TofTrack::setTofData( TofDataMap tofDataMap ) {
00465 
00466   if( m_hitCase == NoHit ) return;
00467 
00468   unsigned int identify[11];
00469   unsigned int count[11];
00470   for( unsigned int i=0; i<11; i++ ) {
00471     identify[i] = 0x0000c000;
00472     count[i] = 0;
00473   }
00474   unsigned int countTot1 = 0;
00475   unsigned int countTot2 = 0;
00476 
00477   if( ( ( m_hitCase == InnerLayer ) || ( m_hitCase == DoubleLayer ) ) && ( m_id1 > -1 ) ) {
00478     int tofid0 = m_id1;
00479     identify[0] = TofID::getIntID( 1, 0, tofid0, 0 );
00480     count[0] = tofDataMap.count( identify[0] );
00481     int tofid1 = tofid0 - 1;
00482     if( tofid1 == -1 ) { tofid1 = 87; }
00483     identify[1] = TofID::getIntID( 1, 0, tofid1, 0 );
00484     count[1] = tofDataMap.count( identify[1] );
00485     int tofid2 = tofid0 + 1;
00486     if( tofid2 == 88 ) { tofid2 = 0; }
00487     identify[2] = TofID::getIntID( 1, 0, tofid2, 0 );
00488     count[2] = tofDataMap.count( identify[2] );
00489   }
00490 
00491   if( ( ( m_hitCase == EastEndcap ) || ( m_hitCase == WestEndcap ) )&& ( m_id1 > -1 ) ) {
00492     unsigned int whichEndcap = 0;
00493     int tofid0 = m_id1;
00494     if( m_hitCase == WestEndcap ) {
00495       whichEndcap = 2;
00496       tofid0 = m_id1 - 48;
00497     }
00498     identify[0] = TofID::getIntID( whichEndcap, 0, tofid0, 0 );
00499     count[0] = tofDataMap.count( identify[0] );
00500     int tofid1 = tofid0 - 1;
00501     if( tofid1 == -1 ) { tofid1 = 47; }
00502     identify[1] = TofID::getIntID( whichEndcap, 0, tofid1, 0 );
00503     count[1] = tofDataMap.count( identify[1] );
00504     int tofid2 = tofid0 + 1;
00505     if( tofid2 == 48 ) { tofid2 = 0; }
00506     identify[2] = TofID::getIntID( whichEndcap, 0, tofid2, 0 );
00507     count[2] = tofDataMap.count( identify[2] );
00508   }
00509 
00510   if( ( ( m_hitCase == EastEndcapMRPC ) || ( m_hitCase == WestEndcapMRPC ) ) && ( ( m_id1 > -1 ) && ( m_istrip1 > -1 ) ) ) {
00511     IterTofDataMap iter = tofDataMap.begin();
00512     for( ; iter != tofDataMap.end(); iter++ ) {
00513       Identifier iden = TofID::cell_id( (*iter).first );
00514       if( TofID::is_mrpc( iden ) ) {
00515         TofData* tof = (*iter).second;
00516         if( m_id1 == tof->tofId() && abs( m_istrip1 - tof->strip() )<=abs(m_delStrip1) ) {
00517           m_delStrip1 = m_istrip1 - tof->strip();
00518         }
00519         if( ( abs( m_id1 - tof->tofId() )==1 || ( m_id1==0 && tof->tofId()==35 ) || ( m_id1==35 && tof->tofId()==0 ) || ( m_id1==36 && tof->tofId()==71 ) || ( m_id1==71 && tof->tofId()==36 ) ) && abs( m_istrip1 - tof->strip() )<=abs(m_delStrip1) ) {
00520           m_delStrip2 = m_istrip1 - tof->strip();
00521         }
00522       }
00523     }
00524 
00525     unsigned int whichEndcap = 0;
00526     int tofid0 = m_id1;
00527     if( m_hitCase == WestEndcapMRPC ) {
00528       whichEndcap = 1;
00529       tofid0 = m_id1 - 36;
00530     }
00531     int strip0 = m_istrip1;
00532     int strip1 = strip0 - 1;
00533     int strip2 = strip0 + 1;
00534     int strip3 = strip0 - 2;
00535     int strip4 = strip0 + 2;
00536     int tofid1 = tofid0 - 1;
00537     if( tofid1 == -1 ) { tofid1 = 35; }
00538     int tofid2 = tofid0 + 1;
00539     if( tofid2 == 36 ) { tofid2 = 0; }
00540 
00541     identify[0] = TofID::getIntID( 3, whichEndcap, tofid0, strip0, 0 );
00542     count[0]    = tofDataMap.count( identify[0] );
00543     identify[5] = TofID::getIntID( 3, whichEndcap, tofid1, strip0, 0 );
00544     count[5]    = tofDataMap.count( identify[5] );
00545     identify[6] = TofID::getIntID( 3, whichEndcap, tofid2, strip0, 0 );
00546     count[6]    = tofDataMap.count( identify[6] );
00547 
00548     if( strip1 == -1 ) {
00549       count[1] = 0;
00550       count[7] = 0;
00551       count[9] = 0;
00552     }
00553     else {
00554       identify[1] = TofID::getIntID( 3, whichEndcap, tofid0, strip1, 0 );
00555       count[1]    = tofDataMap.count( identify[1] );
00556       identify[7] = TofID::getIntID( 3, whichEndcap, tofid1, strip1, 0 );
00557       count[7]    = tofDataMap.count( identify[7] );
00558       identify[9] = TofID::getIntID( 3, whichEndcap, tofid2, strip1, 0 );
00559       count[9]    = tofDataMap.count( identify[9] );
00560     }
00561 
00562     if( strip2 == 12 ) {
00563       count[2] = 0;
00564       count[8] = 0;
00565       count[10] = 0;
00566     }
00567     else {
00568       identify[2] = TofID::getIntID( 3, whichEndcap, tofid0, strip2, 0 );
00569       count[2]    = tofDataMap.count( identify[2] );
00570       identify[8] = TofID::getIntID( 3, whichEndcap, tofid1, strip2, 0 );
00571       count[8]    = tofDataMap.count( identify[8] );
00572       identify[10] = TofID::getIntID( 3, whichEndcap, tofid2, strip2, 0 );
00573       count[10]    = tofDataMap.count( identify[10] );
00574     }
00575     if( strip3 == -1 || strip3 == -2 ) { count[3] = 0; }
00576     else {
00577       identify[3] = TofID::getIntID( 3, whichEndcap, tofid0, strip3, 0 );
00578       count[3] = tofDataMap.count( identify[3] );
00579     }
00580     if( strip4 == 12 || strip4 == 13 ) { count[4] = 0; }
00581     else {
00582       identify[4] = TofID::getIntID( 3, whichEndcap, tofid0, strip4, 0 );
00583       count[4] = tofDataMap.count( identify[4] );
00584     }
00585   }
00586 
00587   for( unsigned int i=0; i<11; i++ ) {
00588     if( count[i] > 0 ) {
00589       pair< IterTofDataMap, IterTofDataMap > range = tofDataMap.equal_range( identify[i] );
00590       IterTofDataMap iter = range.first;
00591       for( unsigned int j=0; j<count[i]; j++,iter++ ) {
00592         if( i==0 ) {
00593           tofDataAnalysis( (*iter).second, 1 );
00594         }
00595         else if( i==1 || i==2 ) {
00596           tofDataAnalysis( (*iter).second, 2 );
00597         }
00598         else {
00599           tofDataAnalysis( (*iter).second, 3 );
00600         }
00601       }
00602     }
00603     countTot1 = countTot1 + count[i];
00604   }
00605 
00606   if( countTot1 == 0 ) {
00607     if( m_hitCase == DoubleLayer ) {
00608       m_hitCase = OuterLayer;
00609     }
00610     else if( ( m_hitCase == EastEndcapMRPC ) || ( m_hitCase == WestEndcapMRPC ) ) {
00611     }
00612     else {
00613       m_hitCase = NoHit; 
00614       m_quality = 12;
00615     }
00616   }
00617 
00618 
00619   for( unsigned int i=0; i<11; i++ ) {
00620     identify[i] = 0x0000c000;
00621     count[i] = 0;
00622   }
00623   if( ( ( m_hitCase == OuterLayer ) || ( m_hitCase == DoubleLayer ) ) && ( m_id2 > 87 ) ) {
00624     int tofid0 = m_id2 - 88;
00625     identify[0] = TofID::getIntID( 1, 1, tofid0, 0 );
00626     count[0] = tofDataMap.count( identify[0] );
00627     int tofid1 = tofid0 - 1;
00628     if( tofid1 == -1 ) { tofid1 = 87; }
00629     identify[1] = TofID::getIntID( 1, 1, tofid1, 0 );
00630     count[1] = tofDataMap.count( identify[1] );
00631     int tofid2 = tofid0 + 1;
00632     if( tofid2 == 88 ) { tofid2 = 0; }
00633     identify[2] = TofID::getIntID( 1, 1, tofid2, 0 );
00634     count[2] = tofDataMap.count( identify[2] );
00635 
00636     for( unsigned int i=0; i<3; i++ ) {
00637       if( count[i] > 0 ) {
00638         pair< IterTofDataMap, IterTofDataMap > range = tofDataMap.equal_range( identify[i] );
00639         IterTofDataMap iter = range.first;
00640         for( unsigned int j=0; j<count[i]; j++,iter++ ) {
00641           if( i==0 ) {
00642             tofDataAnalysis( (*iter).second, 3 );
00643           }
00644           else {
00645             tofDataAnalysis( (*iter).second, 4 );
00646           }
00647         }
00648       }
00649       countTot2 = countTot2 + count[i];
00650     }
00651 
00652     if( countTot2 == 0 ) {
00653       if( m_hitCase != DoubleLayer ) {
00654         m_hitCase = NoHit; 
00655         m_quality = 12;
00656       }
00657       else {
00658         m_hitCase = InnerLayer;
00659       }
00660     }
00661   }
00662 
00663   if( ( ( m_hitCase == EastEndcapMRPC ) || ( m_hitCase == WestEndcapMRPC ) ) && ( ( m_id2 > -1 ) && ( m_istrip2 > -1 ) ) ) {
00664     IterTofDataMap iter = tofDataMap.begin();
00665     for( ; iter != tofDataMap.end(); iter++ ) {
00666       Identifier iden = TofID::cell_id( (*iter).first );
00667       if( TofID::is_mrpc( iden ) ) {
00668         TofData* tof = (*iter).second;
00669         if( m_id2 == tof->tofId() && abs( m_istrip2 - tof->strip() )<=abs(m_delStrip1) ) {
00670           m_delStrip1 = m_istrip2 - tof->strip();
00671         }
00672         if( ( abs( m_id2 - tof->tofId() )==1 || ( m_id2==0 && tof->tofId()==35 ) || ( m_id2==35 && tof->tofId()==0 ) || ( m_id2==36 && tof->tofId()==71 ) || ( m_id2==71 && tof->tofId()==36 ) ) && abs( m_istrip2 - tof->strip() )<=abs(m_delStrip2) ) {
00673           m_delStrip2 = m_istrip2 - tof->strip();
00674         }
00675       }
00676     }
00677 
00678     unsigned int whichEndcap = 0;
00679     int tofid0 = m_id2;
00680     if( m_hitCase == WestEndcapMRPC ) {
00681       whichEndcap = 1;
00682       tofid0 = m_id2 - 36;
00683     }
00684     int strip0 = m_istrip2;
00685     int strip1 = strip0 - 1;
00686     int strip2 = strip0 + 1;
00687     int strip3 = strip0 - 2;
00688     int strip4 = strip0 + 2;
00689     int tofid1 = tofid0 - 1;
00690     if( tofid1 == -1 ) { tofid1 = 35; }
00691     int tofid2 = tofid0 + 1;
00692     if( tofid2 == 36 ) { tofid2 = 0; }
00693 
00694     identify[0] = TofID::getIntID( 3, whichEndcap, tofid0, strip0, 0 );
00695     count[0]    = tofDataMap.count( identify[0] );
00696     identify[5] = TofID::getIntID( 3, whichEndcap, tofid1, strip0, 0 );
00697     count[5]    = tofDataMap.count( identify[5] );
00698     identify[6] = TofID::getIntID( 3, whichEndcap, tofid2, strip0, 0 );
00699     count[6]    = tofDataMap.count( identify[6] );
00700 
00701     if( strip1 == -1 ) {
00702       count[1] = 0;
00703       count[7] = 0;
00704       count[9] = 0;
00705     }
00706     else {
00707       identify[1] = TofID::getIntID( 3, whichEndcap, tofid0, strip1, 0 );
00708       count[1]    = tofDataMap.count( identify[1] );
00709       identify[7] = TofID::getIntID( 3, whichEndcap, tofid1, strip1, 0 );
00710       count[7]    = tofDataMap.count( identify[7] );
00711       identify[9] = TofID::getIntID( 3, whichEndcap, tofid2, strip1, 0 );
00712       count[9]    = tofDataMap.count( identify[9] );
00713     }
00714 
00715     if( strip2 == 12 ) {
00716       count[2] = 0;
00717       count[8] = 0;
00718       count[10] = 0;
00719     }
00720     else {
00721       identify[2] = TofID::getIntID( 3, whichEndcap, tofid0, strip2, 0 );
00722       count[2]    = tofDataMap.count( identify[2] );
00723       identify[8] = TofID::getIntID( 3, whichEndcap, tofid1, strip2, 0 );
00724       count[8]    = tofDataMap.count( identify[8] );
00725       identify[10] = TofID::getIntID( 3, whichEndcap, tofid2, strip2, 0 );
00726       count[10]    = tofDataMap.count( identify[10] );
00727     }
00728     if( strip3 == -1 || strip3 == -2 ) { count[3] = 0; }
00729     else {
00730       identify[3] = TofID::getIntID( 3, whichEndcap, tofid0, strip3, 0 );
00731       count[3] = tofDataMap.count( identify[3] );
00732     }
00733     if( strip4 == 12 || strip4 == 13 ) { count[4] = 0; }
00734     else {
00735       identify[4] = TofID::getIntID( 3, whichEndcap, tofid0, strip4, 0 );
00736       count[4] = tofDataMap.count( identify[4] );
00737     }
00738 
00739     for( unsigned int i=0; i<11; i++ ) {
00740       if( count[i] > 0 ) {
00741         pair< IterTofDataMap, IterTofDataMap > range = tofDataMap.equal_range( identify[i] );
00742         IterTofDataMap iter = range.first;
00743         for( unsigned int j=0; j<count[i]; j++,iter++ ) {
00744           if( i==0 ) {
00745             tofDataAnalysis( (*iter).second, 4 );
00746           }
00747           else if( i==1 || i==2 ) {
00748             tofDataAnalysis( (*iter).second, 5 );
00749           }
00750           else {
00751             tofDataAnalysis( (*iter).second, 6 );
00752           }
00753         }
00754       }
00755       countTot2 = countTot2 + count[i];
00756     }
00757   }
00758 
00759   if( countTot1==0 && countTot2==0 ) {
00760     m_hitCase = NoHit; 
00761     m_quality = 12;
00762   }
00763 
00764   return;
00765 }
00766 
00767 
00768 //------- tofDataAnalysis ----------------------------------------
00769 // analysis tof data
00770 //
00771 void TofTrack::tofDataAnalysis( TofData* tof, unsigned int iflag ) {
00772 
00773   unsigned int qual = tof->quality();
00774 
00775   if( ( qual & 0x10 ) == 0 ) {
00776     qual = ( qual | 0x10 );     // zadc, ztdc unmatched, and track matched
00777     if( tof->barrel() || tof->is_mrpc() ) {  // Barrel, Endcap has been done
00778       if( ( tof->quality() == 0x7 ) || ( tof->quality() == 0xd ) ) {
00779         qual = ( qual | 0x20 );                       // lost one Q
00780       }
00781       
00782       if( ( tof->quality() == 0xb ) || ( tof->quality() == 0xe ) ) {
00783         qual = ( qual | 0x40 );                       // lost one T
00784       }
00785       
00786       if( ( tof->quality() == 0x3 ) || ( tof->quality() == 0xc ) ) {
00787         qual = ( qual | 0x80 );                       // single end
00788       }
00789     }
00790     if( tof->barrel() ) {
00791       if( ( tof->quality() & 0x5 ) == 0x5 ) {
00792         double ztdc = tofCaliSvc->ZTDC( tof->tdc1(), tof->tdc2(), tof->tofId() );
00793         tof->setZTdc( ztdc );
00794       }
00795 
00796       if( ( tof->quality() & 0xa ) == 0xa ) {
00797         double zadc = tofCaliSvc->ZADC( tof->adc1(), tof->adc2(), tof->tofId() );
00798         tof->setZAdc( zadc );
00799       }
00800     }
00801     if( tof->is_mrpc() ) {
00802       if( ( tof->quality() & 0x5 ) == 0x5 ) {
00803         double ztdc = tofCaliSvc->EtfZTDC( tof->tdc1(), tof->tdc2(), tof->tofId(), tof->strip()  );
00804         tof->setZTdc( ztdc );
00805       }
00806     }
00807     tof->setQuality( qual );
00808   }
00809 
00810   if( iflag == 1 )      { m_tofData1.push_back( tof ); }
00811   else if( iflag == 2 ) { m_tofData2.push_back( tof ); }
00812   else if( iflag == 3 ) { m_tofData3.push_back( tof ); }
00813   else if( iflag == 4 ) { m_tofData4.push_back( tof ); }
00814   else if( iflag == 5 ) { m_tofData5.push_back( tof ); }
00815   else if( iflag == 6 ) { m_tofData6.push_back( tof ); }
00816   else {
00817     cout << "TofRec::TofTrack::TofDataAnalylsis: the Flag should be 1-4, out of the Range!" << endl;
00818   }
00819 
00820   return;
00821 }
00822 
00823 
00824 //------- match --------------------------------------------------
00825 // Tof Data - Extrapolated Track Match
00826 //
00827 void TofTrack::match( bool forCalibration, std::vector<int> deadId, std::vector<TofTrack*>*& tofTrackVec ) {
00828 
00829   if( m_hitCase == NoHit ) return;
00830 
00831   if( m_hitCase == InnerLayer ) {
00832     findTofDataBarrel( m_tofData1, m_tofData2, m_zrhit1, 1, tofTrackVec );
00833     if( ( m_quality1 & 0x10 ) == 0 ) { m_hitCase = NoHit; }
00834   }
00835   else if( m_hitCase == OuterLayer ) {
00836     findTofDataBarrel( m_tofData3, m_tofData4, m_zrhit2, 2, tofTrackVec );
00837     if( ( m_quality2 & 0x10 ) == 0 ) { m_hitCase = NoHit; }
00838   }
00839   else if( m_hitCase == DoubleLayer ) {
00840     findTofDataBarrel( m_tofData1, m_tofData2, m_zrhit1, 1, tofTrackVec );
00841     if( ( m_quality1 & 0x10 ) == 0 ) { m_hitCase = OuterLayer; }
00842     findTofDataBarrel( m_tofData3, m_tofData4, m_zrhit2, 2, tofTrackVec );
00843     if( ( m_quality2 & 0x10 ) == 0 ) {
00844       if( m_hitCase == DoubleLayer ) {
00845         m_hitCase = InnerLayer;
00846       }
00847       else if( m_hitCase == OuterLayer ) {
00848         m_hitCase = NoHit;
00849       }
00850       else {
00851         cout << "TofRec::TofTrack::match: 2- Impossible!" << endl;
00852       }
00853     }
00854   }
00855   else if( ( m_hitCase == EastEndcap ) || ( m_hitCase == WestEndcap ) ) {
00856     findTofDataEndcap( m_tofData1, m_tofData2, m_zr1 );
00857   }
00858   else if( ( m_hitCase == EastEndcapMRPC ) || ( m_hitCase == WestEndcapMRPC ) ) {
00859     findEtfData( m_tofData1, m_tofData2, m_tofData3, m_zrhit1, 1 );
00860     findEtfData( m_tofData4, m_tofData5, m_tofData6, m_zrhit2, 2 );
00861   }
00862   else {
00863     cout << "TofRec::TofTrack::match: 1- Impossible!" << endl; 
00864   }
00865 
00866   if( forCalibration ) {
00867     // set Data Sample for Calibration, double layer, only one hit for counter, T and Q.
00868     if( m_hitCase == DoubleLayer ) {
00869       if( ( ( m_quality1 & 0xf ) == 0xf ) && ( ( m_quality2 & 0xf ) == 0xf ) ) {
00870         m_quality1 = ( m_quality1 | 0x800 );        // Calibration Sample
00871         m_quality2 = ( m_quality2 | 0x800 );        // Calibration Sample
00872       }
00873       else {
00874         std::vector<int>::iterator iter = deadId.begin();
00875         for( ; iter != deadId.end(); iter++ ) {
00876           Identifier iden = Identifier(*iter);
00877           int barrel = TofID::barrel_ec(iden);
00878           int layer  = TofID::layer(iden);
00879           int tofId  = TofID::phi_module(iden);
00880           int east   = TofID::end(iden);
00881           if( barrel == 1 ) {
00882             if( layer==0 ) {
00883               if( m_tofId1 == tofId ) {
00884                 if( ( m_quality2 & 0xf ) == 0xf ) {
00885                   if( ( ( east == 0 ) && ( ( m_quality1 & 0xf ) == 0x3 ) ) || ( ( east == 1 ) && ( ( m_quality1 & 0xf ) == 0xc ) ) ) {
00886                     m_quality1 = ( m_quality1 | 0x800 );
00887                     m_quality2 = ( m_quality2 | 0x800 );
00888 
00889                   }
00890                 }
00891               }
00892             }
00893             else if( layer == 1 ) {
00894               if( m_tofId2 == (tofId+88) ) {
00895                 if( ( m_quality1 & 0xf ) == 0xf ) {
00896                   if( ( ( east == 0 ) && ( ( m_quality2 & 0xf ) == 0x3 ) ) || ( ( east == 1 ) && ( ( m_quality2 & 0xf ) == 0xc ) ) ) {
00897                     m_quality1 = ( m_quality1 | 0x800 );
00898                     m_quality2 = ( m_quality2 | 0x800 );
00899                   }
00900                 }
00901               }
00902             }
00903           }
00904         }
00905       }
00906     }
00907     // set Data Sample for Calibration, only one hit for counter, T and Q.
00908     else if( m_hitCase == InnerLayer ) {
00909       if( ( m_quality1 & 0xf ) == 0xf ) {
00910         m_quality1 = ( m_quality1 | 0x800 );        // Calibration Sample
00911       }
00912       else {
00913         std::vector<int>::iterator iter = deadId.begin();
00914         for( ; iter != deadId.end(); iter++ ) {
00915           Identifier iden = Identifier(*iter);
00916           int barrel = TofID::barrel_ec(iden);
00917           int layer  = TofID::layer(iden);
00918           int tofId  = TofID::phi_module(iden);
00919           int east   = TofID::end(iden);
00920           if( barrel == 1 ) {
00921             if( layer==0 ) {
00922               if( m_tofId1 == tofId ) {
00923                 if( ( ( east == 0 ) && ( ( m_quality1 & 0xf ) == 0x3 ) ) || ( ( east == 1 ) && ( ( m_quality1 & 0xf ) == 0xc ) ) ) {
00924                   m_quality1 = ( m_quality1 | 0x800 );
00925                 }
00926               }
00927             }
00928           }
00929         }
00930       }
00931     }
00932 
00933     // set Data Sample for Calibration, only one hit for counter, T and Q.
00934     if( ( ( m_hitCase == EastEndcap ) || ( m_hitCase == WestEndcap ) ) && ( ( m_quality1 & 0xf ) == 0xc ) ) {
00935       m_quality1 = ( m_quality1 | 0x800 );        // Calibration Sample
00936     }
00937 
00938     // set Data Sample for Calibration.
00939     if( ( m_hitCase == EastEndcapMRPC ) || ( m_hitCase == WestEndcapMRPC ) ) {
00940       if( ( ( m_quality1 & 0xf000 ) == 0x1000 ) || ( ( m_quality1 & 0xf000 ) == 0x2000 ) ) { 
00941         if( ( m_quality1 & 0xf ) == 0xf ) {
00942           m_quality1 = ( m_quality1 | 0x800 );        // Calibration Sample
00943         }
00944       }
00945       if( ( ( m_quality2 & 0xf000 ) == 0x1000 ) || ( ( m_quality2 & 0xf000 ) == 0x2000 ) ) { 
00946         if( ( m_quality2 & 0xf ) == 0xf ) {
00947           m_quality2 = ( m_quality2 | 0x800 );        // Calibration Sample
00948         }
00949       }
00950     }
00951 
00952   }
00953 
00954   return;
00955 }
00956 
00957 
00958 //------- findTofDataBarrel ----------------------------------------
00959 // find the right TOF information in TOF data vector 
00960 //      of the exact TOF ID and of the neighbor
00961 //
00962 void TofTrack::findTofDataBarrel( std::vector<TofData*> tofDataVec1, std::vector<TofData*> tofDataVec2, double zrhit, unsigned int iflag, std::vector<TofTrack*>*& tofTrackVec ) {
00963 
00964   unsigned int qual = 0xf;
00965   TofData* tof = 0;
00966   if( tofDataVec2.size() == 0 ) {
00967     if( tofDataVec1.size() == 0 ) {
00968       qual = 0;
00969     }
00970     else if( tofDataVec1.size() == 1 ) {
00971       std::vector<TofData*>::iterator iter1 = tofDataVec1.begin();
00972       tof = (*iter1);
00973       qual = 0x1;
00974     }
00975     else if( tofDataVec1.size() > 1 ) {
00976       tof= chooseTofData( tofDataVec1, zrhit ); 
00977       qual = 0x2;
00978     }
00979     else {
00980       cout << "TofRec::TofTrack::findTofDataBarrel: 1- Impossible!" << endl;
00981     }
00982   }
00983   else if( ( tofDataVec2.size() == 1 ) ) {
00984     if( tofDataVec1.size() == 0 ) {
00985       std::vector<TofData*>::iterator iter2 = tofDataVec2.begin();
00986       tof = (*iter2);
00987       qual = 0x4;
00988     }
00989     else if( tofDataVec1.size() == 1 ) {
00990       std::vector<TofData*>::iterator iter1 = tofDataVec1.begin();
00991       if( ((*iter1)->quality()&0x1ff)==0x01f && abs((*iter1)->ztdc()-zrhit)<ztdc_Cut ) {
00992         tof = (*iter1);
00993       }
00994       else {
00995         std::vector<TofData*>::iterator iter2 = tofDataVec2.begin();
00996         tof = compareTofData( (*iter1), (*iter2), zrhit );
00997       }
00998       qual = 0x5;
00999     }
01000     else if( tofDataVec1.size() > 1 ) {
01001       TofData* tofData1 = chooseTofData( tofDataVec1, zrhit ); 
01002       if( (tofData1->quality()&0x1ff)==0x01f && abs(tofData1->ztdc()-zrhit)<ztdc_Cut ) {
01003         tof = tofData1;
01004       }
01005       else {
01006         std::vector<TofData*>::iterator iter2 = tofDataVec2.begin();
01007         tof = compareTofData( tofData1, (*iter2), zrhit );
01008       }
01009       qual = 0x6;
01010     }
01011     else {
01012       cout << "TofRec::TofTrack::findTofDataBarrel: 2- Impossible!" << endl;
01013     }
01014   }
01015   else if( ( tofDataVec2.size() > 1 ) ) {
01016     if( tofDataVec1.size() == 0 ) {
01017       tof = chooseTofData( tofDataVec2, zrhit );
01018       qual = 0x8;
01019     }
01020     else if( tofDataVec1.size() == 1 ) {
01021       std::vector<TofData*>::iterator iter1 = tofDataVec1.begin();
01022       if( ((*iter1)->quality()&0x1ff)==0x01f && abs((*iter1)->ztdc()-zrhit)<ztdc_Cut ) {
01023         tof = (*iter1);
01024       }
01025       else {
01026         TofData* tofData2 = chooseTofData( tofDataVec2, zrhit ); 
01027         tof = compareTofData( (*iter1), tofData2, zrhit );
01028       }
01029       qual = 0x9;
01030     }
01031     else if( tofDataVec1.size() > 1 ) {
01032       TofData* tofData1 = chooseTofData( tofDataVec1, zrhit ); 
01033       if( (tofData1->quality()&0x1ff)==0x01f && abs(tofData1->ztdc()-zrhit)<ztdc_Cut ) {
01034         tof = tofData1;
01035       }
01036       else {
01037         TofData* tofData2 = chooseTofData( tofDataVec2, zrhit ); 
01038         tof = compareTofData( tofData1, tofData2, zrhit );
01039       }
01040       qual = 0xa;
01041     }
01042     else {
01043       cout << "TofRec::TofTrack::findTofDataBarrel: 3- Impossible!" << endl;
01044     }
01045   }
01046 
01047   if( qual != 0 ) {
01048     if( !(tof->used()) ) {
01049       getTofData( tof, iflag );
01050     }
01051     else {
01052       bool z1=false,  z2=false;
01053       bool zc1=false, zc2=false;
01054       TofTrack* track=0;
01055       if( iflag==1 ) {
01056         z1  = ( abs( m_zrhit1 - tof->ztdc() ) < ztdc_Cut );
01057         zc1 = ( m_zrhit1 > tof->ztdc() );
01058         std::vector<TofTrack*>::iterator iter = tofTrackVec->begin(); 
01059         for( ; iter!=tofTrackVec->end(); iter++ ) {
01060           if( (*iter)->hitCase()!=InnerLayer && (*iter)->hitCase()!=DoubleLayer ) continue;
01061           if( tof->tofId()==(*iter)->tofId1() ) {
01062             track = (*iter);
01063             z2    = ( abs( (*iter)->zrhit1() - tof->ztdc() ) < ztdc_Cut );
01064             zc2   = ( (*iter)->zrhit1() > tof->ztdc() );
01065           }
01066         }
01067       }
01068       else if( iflag==2 ) {
01069         z1  = ( abs( m_zrhit2 - tof->ztdc() ) < ztdc_Cut );
01070         zc1 = ( m_zrhit2 > tof->ztdc() );
01071         std::vector<TofTrack*>::iterator iter = tofTrackVec->begin(); 
01072         for( ; iter!=tofTrackVec->end(); iter++ ) {
01073           if( (*iter)->hitCase()!=OuterLayer && (*iter)->hitCase()!=DoubleLayer ) continue;
01074           if( tof->tofId()==(*iter)->tofId2() ) {
01075             track = (*iter);
01076             z2    = ( abs( (*iter)->zrhit2() - tof->ztdc() ) < ztdc_Cut );
01077             zc2   = ( (*iter)->zrhit2() > tof->ztdc() );
01078           }
01079         }
01080       }
01081       
01082       if( ( z1 && z2 )||( (!z1) && (!z2) ) ) {
01083         if( zc1 && !zc2 ) {
01084           getTofDataEast( tof, iflag );
01085           track->getTofDataWest( tof, iflag );
01086         }
01087         else if( !zc1 && zc2 ) {
01088           getTofDataWest( tof, iflag );
01089           track->getTofDataEast( tof, iflag );
01090         }
01091       }
01092       else if( z1 && !z2 ) {
01093         getTofData( tof, iflag );
01094         track->getTofDataNohit( iflag );
01095       }
01096       else if( !z1 && z2 ) {
01097         qual = 0;
01098       }
01099     }
01100   }
01101 
01102   if( qual == 0 ) {
01103     if( ( iflag == 1 ) || ( iflag == 3 ) ) {
01104       m_quality1 = ( m_quality1 | 0x300 );
01105     }
01106     else if( iflag == 2 ) {
01107       m_quality2 = ( m_quality2 | 0x300 );
01108     }
01109     else {
01110       cout << "TofRec::TofTrack::findTofDataBarrel: the 1- IFLAG is Out of Range!" << endl;
01111     }
01112   }
01113   else {
01114     qual = ( qual << 12 );
01115     if( ( iflag == 1 ) || ( iflag == 3 ) ) {
01116       m_quality1 = ( m_quality1 | qual );
01117     }
01118     else if( iflag == 2 ) {
01119       m_quality2 = ( m_quality2 | qual );
01120     }
01121     else {
01122       cout << "TofRec::TofTrack::findTofDataBarrel: the 2- IFLAG is Out of Range!" << endl;
01123     }
01124   }
01125 
01126   return;
01127 }
01128 
01129 
01130 //------- chooseTofData -------------------------------------------
01131 // choose the most possible TofData from TofDataVector
01132 // ZTDC, ZADC, SingleEnd/NoQ/NoT are jugded.
01133 //
01134 TofData* TofTrack::chooseTofData( std::vector<TofData*> tofDataVec, double zrhit ) {
01135   if( tofDataVec.size() == 0 ) {
01136     cout << "TofRec::TofTrack::ChooseTofData: Size of TofData Vector is Zero!" << endl;
01137     return 0;
01138   }
01139   std::vector<TofData*>::iterator igood = tofDataVec.begin();
01140   if( tofDataVec.size() > 1 ) {
01141     double deltaZ = 1000.0;
01142     std::vector<TofData*>::iterator iter  = tofDataVec.begin();
01143     // ZTDC compare
01144     for( ; iter != tofDataVec.end(); iter++ ) {
01145       if( ( (*iter)->quality() & 0x5 ) == 0x5 ) {
01146         if( abs( (*iter)->ztdc() - zrhit ) < deltaZ ) {
01147           deltaZ = abs( (*iter)->ztdc() - zrhit );
01148           igood = iter;
01149         }
01150       }
01151     }
01152     // ZADC compare
01153     if( deltaZ > 999.0 ) {
01154       iter  = tofDataVec.begin();
01155       for( ; iter != tofDataVec.end(); iter++ ) {
01156         if( ( (*iter)->quality() & 0xa ) == 0xa ) {
01157           if( abs( (*iter)->zadc() - zrhit ) < deltaZ ) {
01158             deltaZ = abs( (*iter)->zadc() - zrhit );
01159             igood = iter;
01160           }
01161         }
01162       }
01163     }
01164     // Max Q
01165     if( deltaZ > 999.0 ) {
01166       unsigned int ibad = 0xf0;
01167       iter  = tofDataVec.begin();
01168       for( ; iter != tofDataVec.end(); iter++ ) {
01169         if( ( (*iter)->quality() & 0xf0 ) < ibad ) {
01170           igood = iter;
01171           ibad = ( (*iter)->quality() & 0xf0 );
01172         }
01173         else if( ( (*iter)->quality() & 0xf0 ) == ibad ) {
01174           if( ( (*iter)->adc1() + (*iter)->adc2() ) > ( (*igood)->adc1() + (*igood)->adc2() ) ) {
01175             igood = iter;
01176             ibad = ( (*iter)->quality() & 0xf0 );
01177           }
01178         }
01179       }
01180     }
01181   }
01182 
01183   return (*igood);
01184 }
01185 
01186 
01187 //------- compareTofData -------------------------------------------
01188 // choose the most possible TofData from TofDataVector
01189 // ZTDC, ZADC, SingleEnd/NoQ/NoT are jugded.
01190 //
01191 TofData* TofTrack::compareTofData( TofData* tofData1, TofData* tofData2, double zrhit ) {
01192   TofData* tof = tofData1;
01193   // ZTDC compare
01194   if( abs(tofData1->ztdc() - zrhit ) > abs(tofData2->ztdc() - zrhit ) ) {
01195     // SingleEnd/NoT/NoQ compare
01196     if( ( tofData1->quality() & 0xf0 ) >= ( tofData1->quality() & 0xf0 ) ) {
01197       // QDC compare
01198       //        if( ( tofData1->adc1() + tofData1->adc2() ) < ( tofData2->adc1() + tofData2->adc2() ) ) {
01199       tof = tofData2;
01200       //        }
01201     }
01202     //    }
01203   }
01204 
01205   return tof;
01206 }
01207 
01208 
01209 //------- findTofDataEndcap --------------------------------------
01210 // find the right TOF information in TOF data vector 
01211 //      of the exact TOF ID and of the neighbor
01212 //
01213 void TofTrack::findTofDataEndcap( std::vector<TofData*> tofDataVec1, std::vector<TofData*> tofDataVec2, double zr1[5] ) {
01214 
01215   unsigned int iflag = 3;
01216   unsigned int qual = 0xf;
01217 
01218   if( tofDataVec2.size() == 0 ) {
01219     if( tofDataVec1.size() == 0 ) {
01220       qual = 0;
01221     }
01222     else if( tofDataVec1.size() == 1 ) {
01223       std::vector<TofData*>::iterator iter1 = tofDataVec1.begin();
01224       getTofData( (*iter1), iflag );
01225       qual = 0x1;
01226     }
01227     else if( tofDataVec1.size() > 1 ) {
01228       getTofData( chooseTofDataEndcap( tofDataVec1, zr1 ), iflag ); 
01229       qual = 0x2;
01230     }
01231     else {
01232       cout << "TofRec::TofTrack::findTofDataEndcap: 1- Impossible!" << endl;
01233     }
01234   }
01235   else if( ( tofDataVec2.size() == 1 ) ) {
01236     if( tofDataVec1.size() == 0 ) {
01237       std::vector<TofData*>::iterator iter2 = tofDataVec2.begin();
01238       getTofData( (*iter2), iflag );
01239       qual = 0x4;
01240     }
01241     else if( tofDataVec1.size() == 1 ) {
01242       std::vector<TofData*>::iterator iter1 = tofDataVec1.begin();
01243       std::vector<TofData*>::iterator iter2 = tofDataVec2.begin();
01244       getTofData( compareTofDataEndcap( (*iter1), (*iter2) ), iflag );
01245       qual = 0x5;
01246     }
01247     else if( tofDataVec1.size() > 1 ) {
01248       TofData* tofData1 = chooseTofDataEndcap( tofDataVec1, zr1 ); 
01249       std::vector<TofData*>::iterator iter2 = tofDataVec2.begin();
01250       getTofData( compareTofDataEndcap( tofData1, (*iter2) ), iflag );
01251       qual = 0x6;
01252     }
01253     else {
01254       cout << "TofRec::TofTrack::findTofDataBarrel: 2- Impossible!" << endl;
01255     }
01256   }
01257   else if( ( tofDataVec2.size() > 1 ) ) {
01258     if( tofDataVec1.size() == 0 ) {
01259       getTofData( chooseTofDataEndcap( tofDataVec2, zr1 ), iflag ); 
01260       qual = 0x8;
01261     }
01262     else if( tofDataVec1.size() == 1 ) {
01263       std::vector<TofData*>::iterator iter1 = tofDataVec1.begin();
01264       TofData* tofData2 = chooseTofDataEndcap( tofDataVec2, zr1 ); 
01265       getTofData( compareTofDataEndcap( (*iter1), tofData2 ), iflag );
01266       qual = 0x9;
01267     }
01268     else if( tofDataVec1.size() > 1 ) {
01269       TofData* tofData1 = chooseTofDataEndcap( tofDataVec1, zr1 ); 
01270       TofData* tofData2 = chooseTofDataEndcap( tofDataVec2, zr1 ); 
01271       getTofData( compareTofDataEndcap( tofData1, tofData2 ), iflag );
01272       qual = 0xa;
01273     }
01274     else {
01275       cout << "TofRec::TofTrack::findTofDataBarrel: 3- Impossible!" << endl;
01276     }
01277   }
01278 
01279   if( qual == 0 ) {
01280     m_quality1 = ( m_quality1 | 0x300 );
01281   }
01282   else {
01283     qual = ( qual << 12 );
01284     m_quality1 = ( m_quality1 | qual );
01285   }
01286 
01287   return;
01288 }
01289 
01290 
01291 //------- chooseTofDataEndcap --------------------------------
01292 // choose the most possible TofData from TofDataVector
01293 //
01294 TofData* TofTrack::chooseTofDataEndcap( std::vector<TofData*> tofDataVec, double zr1[5] ) {
01295   if( tofDataVec.size() == 0 ) {
01296     cout << "TofRec::TofTrack::ChooseTofData: Size of TofData Vector is Zero!" << endl;
01297     return 0;
01298   }
01299   std::vector<TofData*>::iterator igood = tofDataVec.begin();
01300   if( tofDataVec.size() > 1 ) {
01301     bool multihit = false;
01302     std::vector<TofData*>::iterator iter  = tofDataVec.begin();
01303     for( ; iter != tofDataVec.end(); iter++ ) {
01304       if( (*iter)->qtimes1()>1 ) { multihit = true; }
01305     }
01306     iter = tofDataVec.begin();
01307     if( multihit ) {
01308       double tcorr     = -999.0;
01309       double deltaTMin = 999.0;
01310       for( ; iter != tofDataVec.end(); iter++ ) {
01311         tcorr = tofCaliSvc->ETime( (*iter)->adc(), (*iter)->tdc()-m_estime, zr1[2], (*iter)->tofId() );
01312         for( unsigned int i=0; i<5; i++ ) {
01313           if( abs(tcorr-m_texpInner[i]) < deltaTMin ) {
01314             deltaTMin = abs(tcorr-m_texpInner[i]);
01315             igood     = iter;
01316           }
01317         }
01318       }
01319     }
01320     else {
01321       double maxQ = 0.0;
01322       for( ; iter != tofDataVec.end(); iter++ ) {
01323         if( (*iter)->adc() > maxQ ) {
01324           maxQ  = (*iter)->adc();
01325           igood = iter;
01326         }
01327       }
01328     }
01329   }
01330   return (*igood);
01331 } 
01332 
01333 
01334 //------- compareTofDataEndcap -------------------------------
01335 // choose the most possible TofData from TofDataVector
01336 //
01337 TofData* TofTrack::compareTofDataEndcap( TofData* tofData1, TofData* tofData2 ) {
01338   TofData* tof = tofData1;
01339   if( tof->adc() < tofData2->adc() ) {
01340     tof = tofData2;
01341   }
01342   return tof;
01343 }
01344 
01345 
01346 //------- findTofDataEtf --------------------------------------
01347 // find the right TOF information in TOF data vector 
01348 //      of the exact TOF ID and of the neighbor
01349 //
01350 void TofTrack::findEtfData( std::vector<TofData*> tofDataVec1, std::vector<TofData*> tofDataVec2, std::vector<TofData*> tofDataVec3, double zrhit, unsigned int iflag ) {
01351 
01352   TofData *tof1 = 0;
01353   TofData *tof2 = 0;
01354   TofData *tof3 = 0;
01355 
01356   bool findSignal = false;
01357 
01358   if( tofDataVec1.size()==0 && tofDataVec2.size()==0 && tofDataVec3.size()==0 ) {
01359     if( iflag == 1 ) {
01360       m_quality1 = ( m_quality1 | 0x300 );
01361     }
01362     else if( iflag == 2 ) {
01363       m_quality2 = ( m_quality2 | 0x300 );
01364     }
01365   }
01366   else {
01367     if( tofDataVec1.size()>0 ) {
01368       tof1 = chooseEtfData1( tofDataVec1, zrhit );
01369       if( ( tof1->quality() & 0xf ) == 0xf ) {
01370         getEtfData( tof1, iflag, 1 );
01371         findSignal = true;
01372       }
01373     }
01374     if( !findSignal && tofDataVec2.size() > 0 ) {
01375       tof2 = chooseEtfData1( tofDataVec2, zrhit );
01376       if( ( tof2->quality() & 0xf ) == 0xf ) {
01377         getEtfData( tof2, iflag, 2 );
01378         findSignal = true;
01379       }
01380     }
01381     if( !findSignal && tofDataVec3.size() > 0 ) {
01382       tof3 = chooseEtfData2( tofDataVec3, zrhit );
01383       if( ( tof3->quality() & 0xf ) == 0xf ) {
01384         getEtfData( tof3, iflag, 3 );
01385         findSignal = true;
01386       }
01387     }
01388     if( !findSignal && tofDataVec1.size()>0 ) {
01389       if( ( ( tof1->quality() & 0xf ) == 0xc ) || ( ( tof1->quality() & 0xf ) == 0x3 ) )  {
01390         getEtfData( tof1, iflag, 4 );
01391         findSignal = true;
01392       }
01393     }
01394     if( !findSignal && tofDataVec2.size() > 0 ) {
01395       if( ( ( tof2->quality() & 0xf ) == 0xc ) || ( ( tof2->quality() & 0xf ) == 0x3 ) )  {
01396         getEtfData( tof2, iflag, 5 );
01397         findSignal = true;
01398       }
01399     }
01400     if( !findSignal && tofDataVec3.size() > 0 ) {
01401       if( ( ( tof3->quality() & 0xf ) == 0xc ) || ( ( tof3->quality() & 0xf ) == 0x3 ) )  {
01402         getEtfData( tof3, iflag, 6 );
01403         findSignal = true;
01404       }
01405     }
01406     if( findSignal ) {
01407       if( iflag == 1 ) {
01408         m_quality1 = ( m_quality1 | 0x300 );
01409       }
01410       else if( iflag == 2 ) {
01411         m_quality2 = ( m_quality2 | 0x300 );
01412       }
01413     }
01414   }
01415 
01416   return;
01417 }
01418 
01419 //------- chooseEtfData -------------------------------
01420 // choose the most possible TofData from TofDataVector
01421 //
01422 TofData* TofTrack::chooseEtfData1( std::vector<TofData*> tofDataVec, double zrhit ) {
01423   if( tofDataVec.size() == 0 ) {
01424     return 0;
01425   }
01426   std::vector<TofData*>::iterator igood = tofDataVec.begin();
01427   if( tofDataVec.size() == 1 ) {
01428     return (*igood);
01429   }
01430   else if( tofDataVec.size() > 1 ) {
01431     double deltaZ = 1000.0;
01432     std::vector<TofData*>::iterator iter  = tofDataVec.begin();
01433     for( ; iter != tofDataVec.end(); iter++ ) {
01434       if( ( (*iter)->quality() & 0xf ) == 0xf ) {
01435         if( abs( (*iter)->ztdc() - zrhit ) < deltaZ ) {
01436           deltaZ = abs( (*iter)->ztdc() - zrhit );
01437           igood = iter;
01438         }
01439       }
01440     }
01441     // Max Q
01442     if( deltaZ > 999.0 ) {
01443       double maxQ = -1;
01444       iter  = tofDataVec.begin();
01445       for( ; iter != tofDataVec.end(); iter++ ) {
01446         if( ( (*iter)->quality() & 0xc ) == 0xc ) {
01447           if( (*iter)->adc1() > maxQ ) {
01448             maxQ =  (*iter)->adc1();
01449             igood = iter;
01450           }
01451         }
01452         else if( ( (*iter)->quality() & 0x3 ) == 0x3 ) {
01453           if( (*iter)->adc2() > maxQ ) {
01454             maxQ =  (*iter)->adc2();
01455             igood = iter;
01456           }
01457         }
01458       }
01459     }
01460   }
01461 
01462   return (*igood);
01463 }
01464 
01465 //------- chooseEtfData -------------------------------
01466 // choose the most possible TofData from TofDataVector
01467 //
01468 TofData* TofTrack::chooseEtfData2( std::vector<TofData*> tofDataVec, double zrhit ) {
01469   if( tofDataVec.size() == 0 ) {
01470     return 0;
01471   }
01472   std::vector<TofData*>::iterator igood = tofDataVec.begin();
01473   if( tofDataVec.size() == 1 ) {
01474     return (*igood);
01475   }
01476   else if( tofDataVec.size() > 1 ) {
01477     double maxQ = -1;
01478     std::vector<TofData*>::iterator iter = tofDataVec.begin();
01479     for( ; iter != tofDataVec.end(); iter++ ) {
01480       if( ( (*iter)->quality() & 0xc ) == 0xc ) {
01481         if( (*iter)->adc1() > maxQ ) {
01482           maxQ =  (*iter)->adc1();
01483           igood = iter;
01484         }
01485       }
01486       else if( ( (*iter)->quality() & 0x3 ) == 0x3 ) {
01487         if( (*iter)->adc2() > maxQ ) {
01488           maxQ =  (*iter)->adc2();
01489           igood = iter;
01490         }
01491       }
01492     }
01493   }
01494 
01495   return (*igood);
01496 }
01497 
01498 //------- getTofData -----------------------------------------
01499 // set Tof Data of Inner / Outer Layer Barrel TOF and Endcap TOF
01500 //
01501 void TofTrack::getTofData( TofData* tof, unsigned int iflag ) {
01502 
01503   if( iflag == 1 ) { 
01504     m_tofId1   = tof->tofId();
01505     m_strip1   = tof->strip();
01506     if( tofCaliSvc->QElec() ) {
01507       m_qch1   = tof->qtc1();  
01508     }
01509     else {
01510       m_qch1   = tof->adcChannelEast();
01511     }
01512     m_adc1     = tof->adc1();
01513     m_tdc1     = tof->tdc1();
01514     if( tofCaliSvc->QElec() ) {
01515       m_qch2   = tof->qtc2();  
01516     }
01517     else {
01518       m_qch2   = tof->adcChannelWest();
01519     }
01520     m_adc2     = tof->adc2();
01521     m_tdc2     = tof->tdc2();
01522     m_ztdc1    = tof->ztdc();
01523     m_zadc1    = tof->zadc();
01524     m_quality1 = ( m_quality1 | ( 0x1f & tof->quality() ) );
01525     if( ( ( tof->quality() & 0x5 ) != 0x5 ) || ( ( ( tof->quality() & 0x5 ) == 0x5 ) && ( abs( tof->ztdc() - m_zrhit1 ) > ztdc_Cut ) ) ) { 
01526       m_quality1 = ( m_quality1 | 0x100 );
01527     }
01528     if( ( ( tof->quality() & 0xa ) != 0xa ) || ( ( ( tof->quality() & 0xa ) == 0xa ) && ( abs( tof->zadc() - m_zrhit1 ) > zadc_Cut ) ) ) { 
01529       m_quality1 = ( m_quality1 | 0x200 );
01530     }
01531   }
01532   else if( iflag == 2 ) {
01533     m_tofId2   = tof->tofId();
01534     m_strip2   = tof->strip();
01535     if( tofCaliSvc->QElec() ) {
01536       m_qch3   = tof->qtc1();  
01537     }
01538     else {
01539       m_qch3   = tof->adcChannelEast();
01540     }
01541     m_adc3     = tof->adc1();
01542     m_tdc3     = tof->tdc1();
01543     if( tofCaliSvc->QElec() ) {
01544       m_qch4   = tof->qtc2();  
01545     }
01546     else {
01547       m_qch4   = tof->adcChannelWest();
01548     }
01549     m_adc4     = tof->adc2();
01550     m_tdc4     = tof->tdc2();
01551     m_ztdc2    = tof->ztdc();
01552     m_zadc2    = tof->zadc();
01553     m_quality2 = ( m_quality2 | ( 0x1f & tof->quality() ) );
01554     if( ( ( tof->quality() & 0x5 ) != 0x5 ) || ( ( ( tof->quality() & 0x5 ) == 0x5 ) && ( abs( tof->ztdc() - m_zrhit2 ) > ztdc_Cut ) ) ) { 
01555       m_quality2 = ( m_quality2 | 0x100 );
01556     }
01557     if( ( ( tof->quality() & 0xa ) != 0xa ) || ( ( ( tof->quality() & 0xa ) == 0xa ) && ( abs( tof->zadc() - m_zrhit2 ) > zadc_Cut ) ) ) { 
01558       m_quality2 = ( m_quality2 | 0x200 );
01559     }
01560   }
01561   else if( iflag == 3 ) {
01562     m_tofId1   = tof->tofId();
01563     if( tofCaliSvc->QElec() ) {
01564       m_qch1   = tof->qtc();  
01565     }
01566     else {
01567       m_qch1   = tof->adcChannel();
01568     }
01569     m_adc1     = tof->adc();
01570     m_tdc1     = tof->tdc();
01571     m_quality1 = ( m_quality1 | ( 0x1f & tof->quality() ) );
01572     m_quality1 = ( m_quality1 | 0x300 );
01573   }
01574   else {
01575     cout << "TofRec::TofTrack::getTofData: Flag which sign the Barrel/Endcap or Inner/Outer is wrong! Please check it!" << endl;
01576   }
01577   tof->setUsed();
01578   return;
01579 }
01580 
01581 
01582 //------- getTofDataEast ------------------------------------
01583 // set Tof Data of Inner / Outer Layer Barrel TOF and Endcap TOF
01584 //
01585 void TofTrack::getTofDataEast( TofData* tof, unsigned int iflag ) {
01586 
01587   if( iflag == 1 ) { 
01588     m_tofId1   = tof->tofId();
01589     m_strip1   = tof->strip();
01590     if( tofCaliSvc->QElec() ) {
01591       m_qch1   = tof->qtc1();  
01592     }
01593     else {
01594       m_qch1   = tof->adcChannelEast();
01595     }
01596     m_adc1     = tof->adc1();
01597     m_tdc1     = tof->tdc1();
01598     m_qch2     = -999.0;
01599     m_adc2     = -999.0;
01600     m_tdc2     = -999.0;
01601     m_ztdc1    = tof->ztdc();
01602     m_zadc1    = tof->zadc();
01603     m_quality1 = ( ( m_quality1 & 0xfffffff0 ) | ( 0x1c & tof->quality() ) );
01604     if( ( ( tof->quality() & 0x5 ) != 0x5 ) || ( ( ( tof->quality() & 0x5 ) == 0x5 ) && ( abs( tof->ztdc() - m_zrhit1 ) > ztdc_Cut ) ) ) { 
01605       m_quality1 = ( m_quality1 | 0x100 );
01606     }
01607     if( ( ( tof->quality() & 0xa ) != 0xa ) || ( ( ( tof->quality() & 0xa ) == 0xa ) && ( abs( tof->zadc() - m_zrhit1 ) > zadc_Cut ) ) ) { 
01608       m_quality1 = ( m_quality1 | 0x200 );
01609     }
01610   }
01611   else if( iflag == 2 ) {
01612     m_tofId2   = tof->tofId();
01613     if( tofCaliSvc->QElec() ) {
01614       m_qch3   = tof->qtc1();  
01615     }
01616     else {
01617       m_qch3   = tof->adcChannelEast();
01618     }
01619     m_adc3     = tof->adc1();
01620     m_tdc3     = tof->tdc1();
01621     m_qch4     = -999.0;
01622     m_adc4     = -999.0;
01623     m_tdc4     = -999.0;
01624     m_ztdc2    = tof->ztdc();
01625     m_zadc2    = tof->zadc();
01626     m_quality2 = ( ( m_quality2 & 0xfffffff0 ) | ( 0x1c & tof->quality() ) );
01627     if( ( ( tof->quality() & 0x5 ) != 0x5 ) || ( ( ( tof->quality() & 0x5 ) == 0x5 ) && ( abs( tof->ztdc() - m_zrhit2 ) > ztdc_Cut ) ) ) { 
01628       m_quality2 = ( m_quality2 | 0x100 );
01629     }
01630     if( ( ( tof->quality() & 0xa ) != 0xa ) || ( ( ( tof->quality() & 0xa ) == 0xa ) && ( abs( tof->zadc() - m_zrhit2 ) > zadc_Cut ) ) ) { 
01631       m_quality2 = ( m_quality2 | 0x200 );
01632     }
01633   }
01634   else {
01635     cout << "TofRec::TofTrack::getTofDataEast: Flag which sign the Barrel/Endcap or Inner/Outer is wrong! Please check it!" << endl;
01636   }
01637   tof->setUsed();
01638   return;
01639 }
01640 
01641 
01642 //------- getTofDataWest ------------------------------------
01643 // set Tof Data of Inner / Outer Layer Barrel TOF and Endcap TOF
01644 //
01645 void TofTrack::getTofDataWest( TofData* tof, unsigned int iflag ) {
01646 
01647   if( iflag == 1 ) { 
01648     m_tofId1   = tof->tofId();
01649     m_strip1   = tof->strip();
01650     m_qch1     = -999.0;
01651     m_adc1     = -999.0;
01652     m_tdc1     = -999.0;
01653     if( tofCaliSvc->QElec() ) {
01654       m_qch2   = tof->qtc2();  
01655     }
01656     else {
01657       m_qch2   = tof->adcChannelWest();
01658     }
01659     m_adc2     = tof->adc2();
01660     m_tdc2     = tof->tdc2();
01661     m_ztdc1    = tof->ztdc();
01662     m_zadc1    = tof->zadc();
01663     m_quality1 = ( ( m_quality1 & 0xfffffff0 ) | ( 0x13 & tof->quality() ) );
01664     if( ( ( tof->quality() & 0x5 ) != 0x5 ) || ( ( ( tof->quality() & 0x5 ) == 0x5 ) && ( abs( tof->ztdc() - m_zrhit1 ) > ztdc_Cut ) ) ) { 
01665       m_quality1 = ( m_quality1 | 0x100 );
01666     }
01667     if( ( ( tof->quality() & 0xa ) != 0xa ) || ( ( ( tof->quality() & 0xa ) == 0xa ) && ( abs( tof->zadc() - m_zrhit1 ) > zadc_Cut ) ) ) { 
01668       m_quality1 = ( m_quality1 | 0x200 );
01669     }
01670   }
01671   else if( iflag == 2 ) {
01672     m_tofId2   = tof->tofId();
01673     m_qch3     = -999.0;
01674     m_adc3     = -999.0;
01675     m_tdc3     = -999.0;
01676     if( tofCaliSvc->QElec() ) {
01677       m_qch4   = tof->qtc2();  
01678     }
01679     else {
01680       m_qch4   = tof->adcChannelWest();
01681     }
01682     m_adc4     = tof->adc2();
01683     m_tdc4     = tof->tdc2();
01684     m_ztdc2    = tof->ztdc();
01685     m_zadc2    = tof->zadc();
01686     m_quality2 = ( ( m_quality2 & 0xfffffff0 ) | ( 0x13 & tof->quality() ) );
01687     if( ( ( tof->quality() & 0x5 ) != 0x5 ) || ( ( ( tof->quality() & 0x5 ) == 0x5 ) && ( abs( tof->ztdc() - m_zrhit2 ) > ztdc_Cut ) ) ) { 
01688       m_quality2 = ( m_quality2 | 0x100 );
01689     }
01690     if( ( ( tof->quality() & 0xa ) != 0xa ) || ( ( ( tof->quality() & 0xa ) == 0xa ) && ( abs( tof->zadc() - m_zrhit2 ) > zadc_Cut ) ) ) { 
01691       m_quality2 = ( m_quality2 | 0x200 );
01692     }
01693   }
01694   else {
01695     cout << "TofRec::TofTrack::getTofDataWest: Flag which sign the Barrel/Endcap or Inner/Outer is wrong! Please check it!" << endl;
01696   }
01697   tof->setUsed();
01698   return;
01699 }
01700 
01701 
01702 //------- getTofData -----------------------------------------
01703 // set Tof Data of Inner / Outer Layer Barrel TOF and Endcap TOF
01704 //
01705 void TofTrack::getTofDataNohit( unsigned int iflag ) {
01706 
01707   if( iflag == 1 ) { 
01708     m_tofId1   = -99;
01709     m_strip1   = -99;
01710     m_qch1     = -999.0;
01711     m_adc1     = -999.0;
01712     m_tdc1     = -999.0;
01713     m_qch2     = -999.0;
01714     m_adc2     = -999.0;
01715     m_tdc2     = -999.0;
01716     m_ztdc1    = -999.0;
01717     m_zadc1    = -999.0;
01718     m_quality1 = ( m_quality1 & 0x700 );
01719     if( m_hitCase == InnerLayer ) { m_hitCase = NoHit; }
01720     else if( m_hitCase == DoubleLayer ) { m_hitCase = OuterLayer; }
01721   }
01722   else if( iflag == 2 ) {
01723     m_tofId2   = -99;
01724     m_qch3     = -999.0;
01725     m_adc3     = -999.0;
01726     m_tdc3     = -999.0;
01727     m_qch4     = -999.0;
01728     m_adc4     = -999.0;
01729     m_tdc4     = -999.0;
01730     m_ztdc2    = -999.0;
01731     m_zadc2    = -999.0;
01732     m_quality2 = ( m_quality2 & 0x700 );
01733     if( m_hitCase == OuterLayer ) { m_hitCase = NoHit; }
01734     else if( m_hitCase == DoubleLayer ) { m_hitCase = InnerLayer; }
01735   }
01736   else {
01737     cout << "TofRec::TofTrack::getTofData: Flag which sign the Barrel/Endcap or Inner/Outer is wrong! Please check it!" << endl;
01738   }
01739 
01740   return;
01741 }
01742 
01743 
01744 //------- getTofData -----------------------------------------
01745 // set Tof Data of MRPC Endcap TOF
01746 //
01747 void TofTrack::getEtfData( TofData* tof, unsigned int iflag, unsigned int qual ) {
01748 
01749   if( iflag == 1 && tof->tofId() != m_id2 ) {
01750     m_tofId1   = tof->tofId();
01751     m_strip1   = tof->strip();
01752     m_qch1     = tof->adcChannelEast();
01753     m_adc1     = tof->adc1();
01754     m_tdc1     = tof->tdc1();
01755     m_qch2     = tof->adcChannelWest();
01756     m_adc2     = tof->adc2();
01757     m_tdc2     = tof->tdc2();
01758     m_ztdc1    = tof->ztdc();
01759     m_zadc1    = tof->zadc();
01760     m_quality1 = ( m_quality1 | ( 0x1f & tof->quality() ) );
01761     if( ( ( tof->quality() & 0x5 ) != 0x5 ) || ( ( ( tof->quality() & 0x5 ) == 0x5 ) && ( abs( tof->ztdc() - m_zrhit1 ) > ztdc_Cut ) ) ) { 
01762       m_quality1 = ( m_quality1 | 0x100 );
01763     }
01764     if( ( ( tof->quality() & 0xa ) != 0xa ) || ( ( ( tof->quality() & 0xa ) == 0xa ) && ( abs( tof->zadc() - m_zrhit1 ) > zadc_Cut ) ) ) { 
01765       m_quality1 = ( m_quality1 | 0x200 );
01766     }
01767     m_quality1 = ( m_quality1 | ( qual << 12 ) );
01768     tof->setUsed();
01769   }
01770   else if( iflag == 2 && tof->tofId() != m_id1 ) {
01771     m_tofId2   = tof->tofId();
01772     m_strip2   = tof->strip();
01773     m_qch3     = tof->adcChannelEast();
01774     m_adc3     = tof->adc1();
01775     m_tdc3     = tof->tdc1();
01776     m_qch4     = tof->adcChannelWest();
01777     m_adc4     = tof->adc2();
01778     m_tdc4     = tof->tdc2();
01779     m_ztdc2    = tof->ztdc();
01780     m_zadc2    = tof->zadc();
01781     m_quality2 = ( m_quality2 | ( 0x1f & tof->quality() ) );
01782     if( ( ( tof->quality() & 0x5 ) != 0x5 ) || ( ( ( tof->quality() & 0x5 ) == 0x5 ) && ( abs( tof->ztdc() - m_zrhit2 ) > ztdc_Cut ) ) ) { 
01783       m_quality2 = ( m_quality2 | 0x100 );
01784     }
01785     if( ( ( tof->quality() & 0xa ) != 0xa ) || ( ( ( tof->quality() & 0xa ) == 0xa ) && ( abs( tof->zadc() - m_zrhit2 ) > zadc_Cut ) ) ) { 
01786       m_quality2 = ( m_quality2 | 0x200 );
01787     }
01788     m_quality2 = ( m_quality2 | ( qual << 12 ) );
01789     tof->setUsed();
01790   }
01791 
01792   return;
01793 }
01794 
01795 
01796 //------- setCalibration() ----------------------------------------
01797 //  get calibration constants 
01798 //  ph11() - ph22(), tof11() -- tof22()
01799 //  ph1() ph2() ph(), tof1() tof2() tof()
01800 //
01801 void TofTrack::setCalibration() {
01802 
01803   bool barrel = ( ( m_hitCase == InnerLayer ) || ( m_hitCase == OuterLayer ) || ( m_hitCase == DoubleLayer ) );
01804   bool endcap = ( ( m_hitCase == EastEndcap ) || ( m_hitCase == WestEndcap ) );
01805   bool endcapMRPC = ( ( m_hitCase == EastEndcapMRPC ) || ( m_hitCase == WestEndcapMRPC ) );
01806 
01807   bool innerEast  = ( ( m_quality1 & 0xc ) == 0xc );
01808   bool innerWest  = ( ( m_quality1 & 0x3 ) == 0x3 );
01809   bool outerEast  = ( ( m_quality2 & 0xc ) == 0xc );
01810   bool outerWest  = ( ( m_quality2 & 0x3 ) == 0x3 );
01811   bool innerLayer = ( ( m_quality1 & 0xf ) == 0xf );
01812   bool outerLayer = ( ( m_quality2 & 0xf ) == 0xf );
01813 
01814   bool endcapData = ( ( m_quality1 & 0xc ) == 0xc );
01815 
01816   if( m_hitCase == DoubleLayer ) {
01817     for( unsigned int i=0; i<5; i++ ) {
01818       m_texp[i] = tofCaliSvc->BTimeCluster( m_texpInner[i], m_texpOuter[i], m_zr1[i], m_zr2[i], m_tofId1, m_tofId2 );
01819     }
01820     m_path    =  tofCaliSvc->BTimeCluster( m_path1, m_path2, m_zrhit1, m_zrhit2, m_tofId1, m_tofId2 );
01821   }
01822 
01823   if( barrel ) {
01824     if( innerEast ) {
01825       for( unsigned int i=0; i<5; i++ ) {
01826         m_tof11[i] = tofCaliSvc->BTime1( m_adc1, m_tdc1-m_estime, m_zr1[i], m_tofId1, m_estime );
01827       }
01828       m_sigma11 = tofCaliSvc->BSigma1( m_zrhit1, m_tofId1 );
01829       m_ph11 = m_adc1;
01830     }
01831     
01832     if( innerWest ) {
01833       for( unsigned int i=0; i<5; i++ ) {
01834         m_tof12[i] = tofCaliSvc->BTime2( m_adc2, m_tdc2-m_estime, m_zr1[i], m_tofId1, m_estime );
01835       }
01836       m_sigma12 = tofCaliSvc->BSigma2( m_zrhit1, m_tofId1 );
01837       m_ph12 = m_adc2;
01838     }
01839 
01840     if( innerLayer ) {
01841       for( unsigned int i=0; i<5; i++ ) {
01842         m_tof1[i]  = tofCaliSvc->BTimeCounter( m_tof11[i], m_tof12[i], m_zr1[i], m_tofId1 );
01843       }
01844       m_sigma1  = tofCaliSvc->BSigmaCounter( m_zrhit1, m_tofId1 );
01845       m_ph1  = tofCaliSvc->BPulseHeight( m_adc1, m_adc2, m_zrhit1, m_theta1, m_tofId1 );
01846     }
01847 
01848     if( outerEast ) {
01849       for( unsigned int i=0; i<5; i++ ) {
01850         m_tof21[i] = tofCaliSvc->BTime1( m_adc3, m_tdc3-m_estime, m_zr2[i], m_tofId2, m_estime );
01851       }
01852       m_sigma21 = tofCaliSvc->BSigma1( m_zrhit2, m_tofId2 );
01853       m_ph21 = m_adc3;
01854     }
01855 
01856     if( outerWest ) {
01857       for( unsigned int i=0; i<5; i++ ) {
01858         m_tof22[i] = tofCaliSvc->BTime2( m_adc4, m_tdc4-m_estime, m_zr2[i], m_tofId2, m_estime );
01859       }
01860       m_sigma22 = tofCaliSvc->BSigma2( m_zrhit2, m_tofId2 );
01861       m_ph22 = m_adc4;
01862     }
01863 
01864     if( outerLayer ) {
01865       for( unsigned int i=0; i<5; i++ ) {
01866         m_tof2[i]  = tofCaliSvc->BTimeCounter( m_tof21[i], m_tof22[i], m_zr2[i], m_tofId2 );
01867       }
01868       m_sigma2  = tofCaliSvc->BSigmaCounter( m_zrhit2, m_tofId2 );
01869       m_ph2  = tofCaliSvc->BPulseHeight( m_adc3, m_adc4, m_zrhit2, m_theta2, m_tofId2 );
01870     }
01871 
01872     if( innerLayer && outerLayer ) {
01873       for( unsigned int i=0; i<5; i++ ) {
01874         m_tof[i] = tofCaliSvc->BTimeCluster( m_tof1[i], m_tof2[i], m_zr1[i], m_zr2[i], m_tofId1, m_tofId2 );
01875       }
01876       m_sigma = tofCaliSvc->BSigmaCluster( m_zrhit1, m_zrhit2, m_tofId1, m_tofId2 );
01877       m_ph    = tofCaliSvc->BTimeCluster( m_ph1, m_ph2, m_zrhit1, m_zrhit2, m_tofId1, m_tofId2 );
01878     }
01879   }
01880 
01881   if( endcap ) {
01882     if( endcapData ) {
01883       for( unsigned int i=0; i<5; i++ ) {
01884         m_tof11[i] = tofCaliSvc->ETime( m_adc1, m_tdc1-m_estime, m_zr1[i], m_tofId1 );
01885       }
01886       m_sigma11 = tofCaliSvc->ESigma( m_zrhit1, m_tofId1 );
01887       m_ph11  = tofCaliSvc->EPulseHeight( m_adc1, m_zrhit1, m_theta1, m_tofId1 );
01888       m_quality = 1;
01889       if( (m_quality1&0xa000)!=0 ) { m_quality = 4; }
01890     }
01891   }
01892 
01893   if( endcapMRPC ) {
01894     if( innerEast ) {
01895       if( m_tofId1>-1 ) {
01896         for( unsigned int i=0; i<5; i++ ) {
01897           if( m_run > 0 ) {
01898             m_tof11[i] = tofCaliSvc->EtfTime1( m_adc1, m_tdc1-m_estime, m_zr1[i], m_tofId1, m_strip1, m_estime );
01899           }
01900           else {
01901             m_tof11[i] = tofCaliSvc->EtfTimeMC1( m_adc1, m_tdc1-m_estime, m_zr1[i], m_tofId1, m_strip1, m_estime );
01902           }
01903         }
01904         m_ph11 = m_adc1;
01905       }
01906     }
01907     if( innerWest ) {
01908       if( m_tofId1>-1 ) {
01909         for( unsigned int i=0; i<5; i++ ) {
01910           if( m_run > 0 ) {
01911             m_tof12[i] = tofCaliSvc->EtfTime2( m_adc2, m_tdc2-m_estime, m_zr1[i], m_tofId1, m_strip1, m_estime );
01912           }
01913           else {
01914             m_tof12[i] = tofCaliSvc->EtfTimeMC2( m_adc2, m_tdc2-m_estime, m_zr1[i], m_tofId1, m_strip1, m_estime );
01915           }
01916         }
01917         m_ph12 = m_adc2;
01918       }
01919     }
01920     if( outerEast ) {
01921       if( m_tofId2>-1 ) {
01922         for( unsigned int i=0; i<5; i++ ) {
01923           if( m_run > 0 ) {
01924             m_tof21[i] = tofCaliSvc->EtfTime1( m_adc3, m_tdc3-m_estime, m_zr2[i], m_tofId2, m_strip2, m_estime );
01925           }
01926           else {
01927             m_tof21[i] = tofCaliSvc->EtfTimeMC1( m_adc3, m_tdc3-m_estime, m_zr2[i], m_tofId2, m_strip2, m_estime );
01928           }
01929         }
01930         m_ph21 = m_adc3;
01931       }
01932     }
01933     if( outerWest ) {
01934       if( m_tofId2>-1 ) {
01935         for( unsigned int i=0; i<5; i++ ) {
01936           if( m_run > 0 ) {
01937             m_tof22[i] = tofCaliSvc->EtfTime2( m_adc4, m_tdc4-m_estime, m_zr2[i], m_tofId2, m_strip2, m_estime );
01938           }
01939           else {
01940             m_tof22[i] = tofCaliSvc->EtfTimeMC2( m_adc4, m_tdc4-m_estime, m_zr2[i], m_tofId2, m_strip2, m_estime );
01941           }
01942         }
01943         m_ph22 = m_adc4;
01944       }
01945     }
01946     if( innerLayer ) {
01947       if( m_tofId1>-1 ) {
01948         m_tof1[0] = tofCaliSvc->EtfTime( m_tof11[0], m_tof12[0] );
01949         //      if( m_run > 0 ) {
01950         //        m_tof1[0] = tofCaliSvc->EtfTime( m_adc1, m_adc2, m_tdc1-m_estime, m_tdc2-m_estime, m_tofId1, m_strip1, m_estime );
01951         //      }
01952         //      else {
01953         //        m_tof1[0] = tofCaliSvc->EtfTimeMC( m_adc1, m_adc2, m_tdc1-m_estime, m_tdc2-m_estime, m_tofId1, m_strip1, m_estime );
01954         //        m_tof1[0] = tofCaliSvc->EtfTime( m_tof11[0], m_tof12[0] );
01955         //      }
01956         for( unsigned int i=1; i<5; i++ ) {
01957           m_tof1[i] = m_tof1[0];
01958         }
01959         m_ph1 = ( m_adc1 + m_adc2 )/2.0;
01960       }
01961     }
01962     if( outerLayer ) {
01963       if( m_tofId2>-1 ) {
01964         m_tof2[0] = tofCaliSvc->EtfTime( m_tof21[0], m_tof22[0] );
01965         //      if( m_run > 0 ) {
01966         //        m_tof2[0] = tofCaliSvc->EtfTime( m_adc3, m_adc4, m_tdc3-m_estime, m_tdc4-m_estime, m_tofId2, m_strip2, m_estime );
01967         //      }
01968         //      else {
01969         //        m_tof2[0] = tofCaliSvc->EtfTimeMC( m_adc3, m_adc4, m_tdc3-m_estime, m_tdc4-m_estime, m_tofId2, m_strip2, m_estime );
01970         //      }
01971         for( unsigned int i=1; i<5; i++ ) {
01972           m_tof2[i] = m_tof2[0];
01973         }
01974         m_ph2 = ( m_adc3 + m_adc4 )/2.0;
01975       }
01976     }
01977   }
01978 
01979   // set Quality of Barrel TOF
01980   if( barrel ) {
01981 
01982     // double layer
01983     if( innerLayer && outerLayer ) {
01984       m_quality = 1;
01985     }
01986     else {
01987       // single layer
01988       if( innerLayer || outerLayer ) {
01989         m_quality = 2;
01990       }
01991       else {
01992         // single-end of one layer
01993         if( innerEast || innerWest || outerEast || outerWest ) {
01994           m_quality = 3;
01995         }
01996       }
01997     }
01998 
01999     // multi-hit
02000     if( ( (m_quality1&0xa000)!=0 ) || ( (m_quality2&0xa000)!=0 ) ) {
02001       m_quality = m_quality + 3;
02002     }
02003 
02004     // ztdc and extrapolated zhit is not matched
02005     if( ( (m_quality1&0x100)==0x100 ) || ( (m_quality2&0x100)==0x100 ) ) {
02006       if( ( m_quality == 1 ) || ( m_quality == 4 ) ) { m_quality = 7; }
02007       else if( ( m_quality == 2 ) || ( m_quality == 5 ) ) { m_quality = 8; }
02008       else if( ( m_quality == 3 ) || ( m_quality == 6 ) ) { m_quality = 9; }
02009       else {
02010         cout << "TofRec::TofTrack::setCalibration: Impossible!" << endl;
02011       }
02012     }
02013 
02014   }
02015 
02016   return;
02017 }
02018 
02019 
02020 //------- convert2RecTofTrackCol() -----------------------------------
02021 //  generate RecTofTrackCol
02022 // 
02023 void TofTrack::convert2RecTofTrackCol( RecTofTrackCol* recTofTrackCol ) {
02024 
02025   bool barrel = ( ( m_hitCase == InnerLayer ) || ( m_hitCase == OuterLayer ) || ( m_hitCase == DoubleLayer ) );
02026 
02027   bool innerEast = ( ( m_quality1 & 0xc ) == 0xc );
02028   bool innerWest = ( ( m_quality1 & 0x3 ) == 0x3 );
02029   bool outerEast = ( ( m_quality2 & 0xc ) == 0xc );
02030   bool outerWest = ( ( m_quality2 & 0x3 ) == 0x3 );
02031 
02032   if( barrel ) {
02033 
02034     if( innerEast ) {
02035       RecTofTrack* atrack11 = new RecTofTrack;
02036       buildRecTofTrack( atrack11, 11 );            // innerlayer east readout
02037       TofHitStatus* hitStatus11 = new TofHitStatus;
02038       if( innerWest ) {
02039         hitStatus11->setBarrelReadout( 1, true );  // innerlayer east readout
02040       }
02041       else {
02042         if( m_hitCase == InnerLayer ) {
02043           hitStatus11->setBarrelCluster( 11 );     // innerlayer east cluster
02044         }
02045         else if( m_hitCase == DoubleLayer ) {
02046           if( outerEast && outerWest ) {
02047             hitStatus11->setBarrelCounter( 11 );   // innerlayer east counter
02048           }
02049           else {
02050             hitStatus11->setBarrelCluster( 11 );   // innerlayer east cluster
02051           }
02052         }
02053         else {
02054           cout << "TofRec::TofTrack:convert2RecTofTrackCol: 11- Impossible!" << endl;
02055         }
02056       }
02057       atrack11->setStatus( hitStatus11->value() );
02058       delete hitStatus11;
02059       recTofTrackCol->push_back( atrack11 );
02060     }
02061 
02062     if( innerWest ) {
02063       RecTofTrack* atrack12 = new RecTofTrack;
02064       buildRecTofTrack( atrack12, 12 );            // innerlayer west readout
02065       TofHitStatus* hitStatus12 = new TofHitStatus;
02066       if( innerEast ) {
02067         hitStatus12->setBarrelReadout( 1, false ); // innerlayer west
02068       }
02069       else {
02070         if( m_hitCase == InnerLayer ) {
02071           hitStatus12->setBarrelCluster( 12 );     // innerlayer west cluster
02072         }
02073         else if( m_hitCase == DoubleLayer ) {
02074           if( outerEast && outerWest ) {
02075             hitStatus12->setBarrelCounter( 12 );   // innerlayer west counter
02076           }
02077           else {
02078             hitStatus12->setBarrelCluster( 12 );   // innerlayer west cluster
02079           }
02080         }
02081         else {
02082           cout << "TofRec::TofTrack:convert2RecTofTrackCol: 12- Impossible!" << endl;
02083         }
02084       }
02085       atrack12->setStatus( hitStatus12->value() );
02086       delete hitStatus12;
02087       recTofTrackCol->push_back( atrack12 );
02088     }
02089 
02090     if( innerEast && innerWest ) {
02091       RecTofTrack* atrack1  = new RecTofTrack;
02092       buildRecTofTrack( atrack1, 1 );             // innerlayer counter
02093       TofHitStatus* hitStatus1 = new TofHitStatus;
02094       if( m_hitCase == InnerLayer ) {
02095         hitStatus1->setBarrelCluster( 1 );        // innerlayer cluster and counter
02096       }
02097       else if( m_hitCase == DoubleLayer ) {
02098         if( outerEast && outerWest ) {
02099           hitStatus1->setBarrelCounter( 1 );      // innerlayer counter
02100         }
02101         else {
02102           hitStatus1->setBarrelCluster( 1 );      // innerlayer cluster and counter
02103         }
02104       }
02105       else {
02106         cout << "TofRec::TofTrack:convert2RecTofTrackCol: 1- Impossible!" << endl;
02107       }
02108       atrack1->setStatus( hitStatus1->value() );
02109       delete hitStatus1;
02110       recTofTrackCol->push_back( atrack1 );
02111     }
02112 
02113     if( outerEast ) {
02114       RecTofTrack* atrack21 = new RecTofTrack;
02115       buildRecTofTrack( atrack21, 21 );           // outerlayer east readout
02116       TofHitStatus* hitStatus21 = new TofHitStatus;
02117       if( outerWest ) {
02118         hitStatus21->setBarrelReadout( 2, true ); // outerlayer east readout
02119       }
02120       else {
02121         if( m_hitCase == OuterLayer ) {
02122           hitStatus21->setBarrelCluster( 21 );    // outerlayer east cluster
02123         }
02124         else if( m_hitCase == DoubleLayer ) {
02125           if( innerEast || innerWest ) {
02126             hitStatus21->setBarrelCounter( 21 );  // outerlayer east counter
02127           }
02128           //      else {
02129           //        hitStatus21->setBarrelCluster( 21 );  // outerlayer east cluster
02130           //      }
02131         }
02132         else {
02133           cout << "TofRec::TofTrack:convert2RecTofTrackCol: 21- Impossible!" << endl;
02134         }
02135       }
02136       atrack21->setStatus( hitStatus21->value() );
02137       delete hitStatus21;
02138       recTofTrackCol->push_back( atrack21 );
02139     }
02140 
02141     if( outerWest ) {
02142       RecTofTrack* atrack22 = new RecTofTrack;
02143       buildRecTofTrack( atrack22, 22 );            // outerlayer west readout
02144       TofHitStatus* hitStatus22 = new TofHitStatus;
02145       if( outerEast ) {
02146         hitStatus22->setBarrelReadout( 2, false ); // outerlayer west readout
02147       }
02148       else {
02149         if( m_hitCase == OuterLayer ) {
02150           hitStatus22->setBarrelCluster( 22 );     // outerlayer west cluster
02151         }
02152         else if( m_hitCase == DoubleLayer ) {
02153           if( innerEast || innerWest ) {
02154             hitStatus22->setBarrelCounter( 22 );   // outerlayer west counter
02155           }
02156           //      else {
02157           //        hitStatus22->setBarrelCluster( 22 );   // outerlayer west cluster
02158           //      }
02159         }
02160         else {
02161           cout << "TofRec::TofTrack:convert2RecTofTrackCol: 22- Impossible!" << endl;
02162         }
02163       }
02164       atrack22->setStatus( hitStatus22->value() );
02165       delete hitStatus22;
02166       recTofTrackCol->push_back( atrack22 );
02167     }
02168 
02169     if( outerEast && outerWest ) {
02170       RecTofTrack* atrack2  = new RecTofTrack;
02171       buildRecTofTrack( atrack2, 2 );             // outerlayer counter
02172       TofHitStatus* hitStatus2 = new TofHitStatus;
02173       if( m_hitCase == OuterLayer ) {
02174         hitStatus2->setBarrelCluster( 2 );        // outerlayer cluster and counter
02175       }
02176       else if( m_hitCase == DoubleLayer ) {
02177         if( innerEast && innerWest ) {
02178           hitStatus2->setBarrelCounter( 2 );      // outerlayer counter
02179         }
02180         else {
02181           hitStatus2->setBarrelCluster( 2 );      // outerlayer cluster and counter
02182         }
02183       }
02184       else {
02185         cout << "TofRec::TofTrack:convert2RecTofTrackCol: 2- Impossible!" << endl;
02186       }
02187       atrack2->setStatus( hitStatus2->value() );
02188       delete hitStatus2;
02189       recTofTrackCol->push_back( atrack2 );
02190     }
02191 
02192     if( innerEast && innerWest && outerEast && outerWest ) {
02193       RecTofTrack* atrack  = new RecTofTrack;
02194       buildRecTofTrack( atrack, 0 );              // doublelayer cluster
02195       TofHitStatus* hitStatus = new TofHitStatus;
02196       hitStatus->setBarrelCluster( 3 );           // doublelayer cluster
02197       atrack->setStatus( hitStatus->value() );
02198       delete hitStatus;
02199       recTofTrackCol->push_back( atrack );
02200     }
02201 
02202   }
02203 
02204   if( ( m_hitCase == EastEndcap ) || ( m_hitCase == WestEndcap ) ) {
02205     RecTofTrack* atrack = new RecTofTrack;
02206     buildRecTofTrack( atrack, 11 );               // eastendcap counter
02207     TofHitStatus* hitStatus = new TofHitStatus;
02208     if( m_hitCase == EastEndcap ) {
02209       hitStatus->setEndcapCluster( true );        // east endcap cluster counter readout
02210     }
02211     else if( m_hitCase == WestEndcap ) {
02212       hitStatus->setEndcapCluster( false );       // west endcap cluster counter readout
02213     }
02214     else {
02215       cout << "TofRec::TofTrack:convert2RecTofTrackCol: endcap- Impossible!" << endl;
02216     }
02217     atrack->setStatus( hitStatus->value() );
02218     delete hitStatus;
02219     recTofTrackCol->push_back( atrack );
02220   }
02221 
02222   if( ( m_hitCase == EastEndcapMRPC ) || ( m_hitCase == WestEndcapMRPC ) ) {
02223 
02224     if( innerEast || innerWest ) {
02225 
02226       if( innerEast ) {
02227         RecTofTrack* atrack1 = new RecTofTrack;
02228         buildRecTofTrack( atrack1, 11 );            // mrpc east readout
02229         TofHitStatus* hitStatus1 = new TofHitStatus;
02230         if( innerWest ) {
02231           hitStatus1->setMRPCReadout( true );       // mrpc east readout
02232         }
02233         else {
02234           hitStatus1->setMRPCCluster( false, true ); // mrpc east cluster
02235         }
02236         atrack1->setStatus( hitStatus1->value() );
02237         delete hitStatus1;
02238         recTofTrackCol->push_back( atrack1 );
02239       }
02240       
02241       if( innerWest ) {
02242         RecTofTrack* atrack2 = new RecTofTrack;
02243         buildRecTofTrack( atrack2, 12 );            // mrpc west readout
02244         TofHitStatus* hitStatus2 = new TofHitStatus;
02245         if( innerEast ) {
02246           hitStatus2->setMRPCReadout( false );      // mrpc west readout
02247         }
02248         else {
02249           hitStatus2->setMRPCCluster( false, false ); // mrpc east cluster
02250         }
02251         atrack2->setStatus( hitStatus2->value() );
02252         delete hitStatus2;
02253         recTofTrackCol->push_back( atrack2 );
02254       }
02255       
02256       if( innerEast && innerWest ) {
02257         RecTofTrack* atrack = new RecTofTrack;
02258         buildRecTofTrack( atrack, 1 );                // mrpc east readout
02259         TofHitStatus* hitStatus = new TofHitStatus;
02260         if( m_hitCase == EastEndcapMRPC ) {
02261           hitStatus->setMRPCCluster( true, true ); // mrpc east cluster
02262         }
02263         else {
02264           hitStatus->setMRPCCluster( true, false );// mrpc west cluster
02265         }
02266         atrack->setStatus( hitStatus->value() );
02267         delete hitStatus;
02268         recTofTrackCol->push_back( atrack );
02269       }
02270 
02271     }
02272     else {
02273 
02274       if( outerEast ) {
02275         RecTofTrack* atrack1 = new RecTofTrack;
02276         buildRecTofTrack( atrack1, 21 );            // mrpc east readout
02277         TofHitStatus* hitStatus1 = new TofHitStatus;
02278         if( outerWest ) {
02279           hitStatus1->setMRPCReadout( true );       // mrpc east readout
02280         }
02281         else {
02282           hitStatus1->setMRPCCluster( false, true ); // mrpc east cluster
02283         }
02284         atrack1->setStatus( hitStatus1->value() );
02285         delete hitStatus1;
02286         recTofTrackCol->push_back( atrack1 );
02287       }
02288       
02289       if( outerWest ) {
02290         RecTofTrack* atrack2 = new RecTofTrack;
02291         buildRecTofTrack( atrack2, 22 );            // mrpc west readout
02292         TofHitStatus* hitStatus2 = new TofHitStatus;
02293         if( outerEast ) {
02294           hitStatus2->setMRPCReadout( false );      // mrpc west readout
02295         }
02296         else {
02297           hitStatus2->setMRPCCluster( false, false ); // mrpc east cluster
02298         }
02299         atrack2->setStatus( hitStatus2->value() );
02300         delete hitStatus2;
02301         recTofTrackCol->push_back( atrack2 );
02302       }
02303       
02304       if( outerEast && outerWest ) {
02305         RecTofTrack* atrack = new RecTofTrack;
02306         buildRecTofTrack( atrack, 2 );                // mrpc east readout
02307         TofHitStatus* hitStatus = new TofHitStatus;
02308         if( m_hitCase == EastEndcapMRPC ) {
02309           hitStatus->setMRPCCluster( true, true ); // mrpc east cluster
02310         }
02311         else {
02312           hitStatus->setMRPCCluster( true, false );// mrpc west cluster
02313         }
02314         atrack->setStatus( hitStatus->value() );
02315         delete hitStatus;
02316         recTofTrackCol->push_back( atrack );
02317       }
02318 
02319     }
02320 
02321   }    
02322 
02323   if( m_hitCase == NoHit ) {
02324     RecTofTrack* atrack = new RecTofTrack;
02325     buildRecTofTrack( atrack, 3 );            // no hit
02326     TofHitStatus* hitStatus = new TofHitStatus;
02327     hitStatus->setNoHit();                    // no hit
02328     atrack->setStatus( hitStatus->value() );
02329     delete hitStatus;
02330     recTofTrackCol->push_back( atrack );
02331   }
02332 
02333   return;
02334 }
02335 
02336 
02337 
02338 void TofTrack::buildRecTofTrack( RecTofTrack* track, int layerorend ) {
02339 
02340   track->setTofTrackID( m_tofTrackId );
02341   track->setTrackID( m_trackId );
02342 
02343   track->setErrTof( 0.0 );
02344   track->setBeta( 0.0 );
02345 
02346   double sigma[6];
02347   for( int i=0; i<6; i++ ) {
02348     sigma[i]   = 0.0;
02349   }
02350   track->setSigma( sigma );
02351   track->setQuality( m_quality );
02352   track->setT0( m_estime );
02353   track->setErrT0( 0.0 );
02354   track->setPhi( 9999.0 );
02355   track->setErrPhi( 9999.0 );
02356   track->setEnergy( 9999.0 );
02357   track->setErrEnergy( 9999.0 );
02358 
02359   if( ( layerorend == 11 ) || ( layerorend == 12 ) || ( layerorend == 1 ) ) {
02360     if( m_strip1<0 ) {
02361       track->setTofID( m_tofId1 );    // scintillator
02362     }
02363     else {
02364       track->setTofID( 12*m_tofId1+m_strip1 );    // MRPC
02365     }
02366     track->setPath( m_path1 );
02367     track->setZrHit( m_zrhit1 );
02368     track->setErrZ( m_errzr1 );
02369     track->setTexp( m_texpInner );
02370 
02371     setRecTofTrack( track, layerorend );
02372   }
02373 
02374   if( ( layerorend==21 ) || ( layerorend==22 ) || ( layerorend==2 ) ) {
02375     if( m_strip2<0 ) {
02376       track->setTofID( m_tofId2 );    // scintillator
02377     }
02378     else {
02379       track->setTofID( 12*m_tofId2+m_strip2 );    // MRPC
02380     }
02381     track->setPath( m_path2 );
02382     track->setZrHit( m_zrhit2 );
02383     track->setErrZ( m_errzr2 );
02384     track->setTexp( m_texpOuter );
02385 
02386     setRecTofTrack( track, layerorend );
02387   }
02388 
02389   if( layerorend==0 ) {
02390     track->setTofID( m_tofId1 );
02391     track->setPath( m_path2 );
02392     track->setZrHit( m_zrhit2 );
02393     track->setErrZ( m_errzr2 );
02394     track->setTexp( m_texp );
02395 
02396     setRecTofTrack( track, layerorend );
02397   }
02398 
02399   if( layerorend == 3 ) {
02400     if( m_strip1<0 ) {
02401       track->setTofID( m_id1 );                // scintillator
02402     }
02403     else {
02404       track->setTofID( 12*m_id1 + m_strip1 );   // mrpc
02405     }
02406     track->setPath( m_path1 );
02407     track->setZrHit( m_zrhit1 );
02408     track->setErrZ( m_errzr1 );
02409     track->setTexp( m_texpInner );
02410   }
02411 
02412   return;
02413 }
02414 
02415 
02416 void TofTrack::setRecTofTrack( RecTofTrack* track, int layerorend ) {
02417 
02418   double toffset[6];
02419   for( unsigned int i=0; i<6; i++ ) {
02420     toffset[i] = 0.0;
02421   }
02422 
02423   if( layerorend == 0 ) {   // cluster or double layer hit
02424     track->setPh( m_ph );
02425     track->setTof( m_tof[0] );
02426     track->setSigmaElectron( m_sigma );
02427     for( unsigned int i=0; i<5; i++ ) {
02428       toffset[i] = m_tof[0] - m_tof[i];
02429     }
02430     track->setToffset( toffset );
02431     track->setBeta( m_path/m_tof[0]/30.0 );
02432   }
02433   else if( layerorend == 1 ) { // inner layer
02434     track->setPh( m_ph1 );
02435     track->setTof( m_tof1[0] );
02436     track->setSigmaElectron( m_sigma1 );
02437     for( unsigned int i=0; i<5; i++ ) {
02438       toffset[i] = m_tof1[0] - m_tof1[i];
02439     }
02440     track->setToffset( toffset );
02441     track->setBeta( m_path1/m_tof1[0]/30.0 );
02442   }
02443   else if( layerorend == 2 ) { // outer layer
02444     track->setPh( m_ph2 );
02445     track->setTof( m_tof2[0] );
02446     track->setSigmaElectron( m_sigma2 );
02447     for( unsigned int i=0; i<5; i++ ) {
02448       toffset[i] = m_tof2[0] - m_tof2[i];
02449     }
02450     track->setToffset( toffset );
02451     track->setBeta( m_path2/m_tof2[0]/30.0 );
02452   }
02453   else if( layerorend == 11 ) { // inner layer east end readout
02454     track->setPh( m_ph11 );
02455     track->setTof( m_tof11[0] );
02456     track->setSigmaElectron( m_sigma11 );
02457     for( unsigned int i=0; i<5; i++ ) {
02458       toffset[i] = m_tof11[0] - m_tof11[i];
02459     }
02460     track->setToffset( toffset );
02461     track->setBeta( m_path1/m_tof11[0]/30.0 );
02462   }
02463   else if( layerorend == 12 ) { // inner layer west end readout
02464     track->setPh( m_ph12 );
02465     track->setTof( m_tof12[0] );
02466     track->setSigmaElectron( m_sigma12 );
02467     for( unsigned int i=0; i<5; i++ ) {
02468       toffset[i] = m_tof12[0] - m_tof12[i];
02469     }
02470     track->setToffset( toffset );
02471     track->setBeta( m_path1/m_tof12[0]/30.0 );
02472   }
02473   else if( layerorend == 21 ) { // outer layer east end readout
02474     track->setPh( m_ph21 );
02475     track->setTof( m_tof21[0] );
02476     track->setSigmaElectron( m_sigma21 );
02477     for( unsigned int i=0; i<5; i++ ) {
02478       toffset[i] = m_tof21[0] - m_tof21[i];
02479     }
02480     track->setToffset( toffset );
02481     track->setBeta( m_path2/m_tof21[0]/30.0 );
02482   }
02483   else if( layerorend == 22 ) { // outer layer west end readout
02484     track->setPh( m_ph22 );
02485     track->setTof( m_tof22[0] );
02486     track->setSigmaElectron( m_sigma22 );
02487     for( unsigned int i=0; i<5; i++ ) {
02488       toffset[i] = m_tof22[0] - m_tof22[i];
02489     }
02490     track->setToffset( toffset );
02491     track->setBeta( m_path2/m_tof22[0]/30.0 );
02492   }
02493   else{
02494     cout << "TofRec TofTrack::SetRecTofTrack  layerorend = " << layerorend << endl;
02495   }
02496   return;
02497 }
02498 
02499 
02500 void TofTrack::convert2RecBTofCalHitColBarrel( int runNumber, int eventNumber, RecBTofCalHitCol* btofCalHitCol, std::string calibData ) {
02501 
02502   if( ( m_quality1 & 0x800 ) == 0x800 ) {
02503 
02504     RecBTofCalHit* ahit = new RecBTofCalHit;
02505     ahit->setRun( runNumber );
02506     ahit->setEvent( eventNumber );
02507     ahit->setMod( m_tofId1 );
02508     ahit->setQual( m_hitCase );
02509     ahit->setdZHit( 1 );
02510 
02511     for( int i=0; i<5; i++ ) {
02512       ahit->setTpred( i, m_texpInner[i] );
02513     }
02514     if( calibData == "Dimu" ) {
02515       ahit->setTpred( m_texpInner[1] );
02516       ahit->setZHit( m_zr1[1] );
02517       //      ahit->setdZHit( m_ezr1[1] );
02518     }
02519     else {
02520       ahit->setTpred( m_texpInner[0] );
02521       ahit->setZHit( m_zr1[0] );
02522       //      ahit->setdZHit( m_ezr1[0] );
02523     }
02524 
02525     ahit->setTdc1( m_tdc1-m_estime );
02526     ahit->setTdc2( m_tdc2-m_estime );
02527     ahit->setAdc1( m_adc1 );
02528     ahit->setAdc2( m_adc2 );
02529     //  ahit->setZHit( m_zrhit1 );
02530     //  ahit->setdZHit( m_errzr1 );
02531     ahit->setDeltaPhi( m_estime );
02532     ahit->setsinTheta( m_theta1 );
02533     ahit->setP( m_momentum );
02534     ahit->setQ( m_ph1 );
02535     ahit->setPath( m_path1 );
02536 
02537     btofCalHitCol->push_back( ahit );
02538 
02539     if( ( m_quality2 & 0x800 ) == 0x800 ) {
02540 
02541       RecBTofCalHit* bhit = new RecBTofCalHit;
02542       bhit->setRun( runNumber );
02543       bhit->setEvent( eventNumber );
02544       bhit->setMod( m_tofId2 );
02545       bhit->setQual( m_hitCase );
02546       bhit->setdZHit( 1 );
02547 
02548       for( int i=0; i<5; i++ ) {
02549         bhit->setTpred( i, m_texpOuter[i] );
02550       }
02551       if( calibData == "Dimu" ) {
02552         bhit->setTpred( m_texpOuter[1] );
02553         bhit->setZHit( m_zr2[1] );
02554         //      bhit->setdZHit( m_ezr2[1] );
02555       }
02556       else {
02557         bhit->setTpred( m_texpOuter[0] );
02558         bhit->setZHit( m_zr2[0] );
02559         //      bhit->setdZHit( m_ezr2[0] );
02560       }
02561 
02562       bhit->setTdc1( m_tdc3-m_estime );
02563       bhit->setTdc2( m_tdc4-m_estime );
02564       bhit->setAdc1( m_adc3 );
02565       bhit->setAdc2( m_adc4 );
02566       //  bhit->setZHit( m_zrhit2 );
02567       //  bhit->setdZHit( m_errzr2 );
02568       bhit->setDeltaPhi( m_estime );
02569       bhit->setsinTheta( m_theta2 );
02570       bhit->setP( m_momentum );
02571       bhit->setQ( m_ph2 );
02572       bhit->setPath( m_path2 );
02573 
02574       ahit->setnext(bhit);
02575 
02576       btofCalHitCol->push_back( bhit );
02577 
02578     }
02579   }
02580 
02581   return;
02582 }
02583 
02584 
02585 void TofTrack::convert2RecETofCalHitCol( int runNumber, int eventNumber, RecETofCalHitCol* etofCalHitCol, std::string calibData ) {
02586 
02587   if( ( m_quality1 & 0x800 ) != 0x800 ) return;
02588 
02589   RecETofCalHit* chit = new RecETofCalHit;
02590   chit->setRun( runNumber );
02591   chit->setEvent( eventNumber );
02592   chit->setMod( m_tofId1 );
02593   chit->setQual( m_hitCase );
02594 
02595   for( int i=0; i<5; i++ ) {
02596     chit->setTpred( i, m_texpInner[i] );
02597   }
02598   if( calibData == "Dimu" ) {
02599     chit->setTpred( m_texpInner[1] );
02600     chit->setRHit( m_zr1[1] );
02601     chit->setdRHit( m_ezr1[1] );
02602   }
02603   else {
02604     chit->setTpred( m_texpInner[0] );
02605     chit->setRHit( m_zr1[0] );
02606     chit->setdRHit( m_ezr1[0] );
02607   }
02608 
02609   chit->setTdc( m_tdc1-m_estime );
02610   chit->setAdc( m_adc1 );
02611   //  chit->setRHit( m_zrhit1 );
02612   //  chit->setdRHit( m_errzr1 );
02613   chit->setDeltaPhi( m_estime );
02614   chit->setcosTheta( m_theta1 );
02615   chit->setQ( m_ph1 );
02616   chit->setP( m_momentum );
02617   chit->setPath( m_path1 );
02618 
02619   etofCalHitCol->push_back( chit );
02620 
02621   return;
02622 }
02623 
02624 
02625 void TofTrack::convert2RecBTofCalHitColETF( int runNumber, int eventNumber, RecBTofCalHitCol* btofCalHitCol, std::string calibData ) {
02626 
02627   if( ( m_quality1 & 0x800 ) == 0x800 ) {
02628 
02629     RecBTofCalHit* ahit = new RecBTofCalHit;
02630     ahit->setRun( runNumber );
02631     ahit->setEvent( eventNumber );
02632     ahit->setMod( m_tofId1 );
02633     ahit->setQual( m_hitCase );
02634     ahit->setdZHit( 0 );
02635     
02636     for( int i=0; i<5; i++ ) {
02637       ahit->setTpred( i, m_texpInner[i] );
02638     }
02639     if( calibData == "Dimu" ) {
02640       ahit->setTpred( m_texpInner[1] );
02641       ahit->setZHit( m_zr1[1] );
02642     }
02643     else {
02644       ahit->setTpred( m_texpInner[0] );
02645       ahit->setZHit( m_zr1[0] );
02646     }
02647     
02648     ahit->setTdc1( m_tdc1-m_estime );
02649     ahit->setTdc2( m_tdc2-m_estime );
02650     ahit->setAdc1( m_adc1 );
02651     ahit->setAdc2( m_adc2 );
02652     ahit->setDeltaPhi( m_estime );
02653     ahit->setsinTheta( m_strip1 );
02654     ahit->setP( m_momentum );
02655     ahit->setQ( m_ph1 );
02656     ahit->setPath( m_path1 );
02657     
02658     btofCalHitCol->push_back( ahit );
02659   }
02660 
02661   if( ( m_quality2 & 0x800 ) == 0x800 ) {
02662 
02663     RecBTofCalHit* bhit = new RecBTofCalHit;
02664     bhit->setRun( runNumber );
02665     bhit->setEvent( eventNumber );
02666     bhit->setMod( m_tofId2 );
02667     bhit->setQual( m_hitCase );
02668     bhit->setdZHit( 0 );
02669     
02670     for( int i=0; i<5; i++ ) {
02671       bhit->setTpred( i, m_texpOuter[i] );
02672     }
02673     if( calibData == "Dimu" ) {
02674       bhit->setTpred( m_texpOuter[1] );
02675       bhit->setZHit( m_zr2[1] );
02676     }
02677     else {
02678       bhit->setTpred( m_texpOuter[0] );
02679       bhit->setZHit( m_zr2[0] );
02680     }
02681     
02682     bhit->setTdc1( m_tdc3-m_estime );
02683     bhit->setTdc2( m_tdc4-m_estime );
02684     bhit->setAdc1( m_adc3 );
02685     bhit->setAdc2( m_adc4 );
02686     bhit->setDeltaPhi( m_estime );
02687     bhit->setsinTheta( m_strip2 );
02688     bhit->setP( m_momentum );
02689     bhit->setQ( m_ph2 );
02690     bhit->setPath( m_path2 );
02691     
02692     btofCalHitCol->push_back( bhit );
02693   }
02694 
02695   return;
02696 }
02697 
02698 
02699 // set Quality using quality1 and quality2
02700 void qualityAnalysis() {
02701   
02702   return;
02703 }

Generated on Tue Nov 29 23:14:11 2016 for BOSS_7.0.2 by  doxygen 1.4.7