/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/KalFitAlg/KalFitAlg-00-07-55-p03/src/KalFitTrack2.cxx

Go to the documentation of this file.
00001 #include "KalFitAlg/KalFitAlg.h"
00002 #include "KalFitAlg/KalFitTrack.h"
00003 #include "KalFitAlg/KalFitWire.h"
00004 //#include "EvTimeEvent/RecEsTime.h"
00005 #include "GaudiKernel/MsgStream.h"
00006 #include "GaudiKernel/Bootstrap.h"
00007 #include "MagneticField/MagneticFieldSvc.h"
00008 #include "GaudiKernel/ISvcLocator.h"
00009 #include "GaudiKernel/IDataProviderSvc.h"
00010 #include "GaudiKernel/SmartDataPtr.h"
00011 #include "GaudiKernel/Algorithm.h"
00012 #include "MdcRawEvent/MdcDigi.h"
00013 #include "RawEvent/RawDataUtil.h"
00014 #include "EventModel/Event.h"
00015 #include "Identifier/MdcID.h"
00016 #include "Identifier/Identifier.h"
00017 #include "CLHEP/Matrix/SymMatrix.h"
00018 
00019 double KalFitTrack::EventT0_ = 0.;
00020 HepSymMatrix KalFitTrack::initMatrix_(5,0);
00021 const MdcCalibFunSvc* KalFitTrack::CalibFunSvc_ = 0;
00022 const IMagneticFieldSvc* KalFitTrack::MFSvc_ = 0;
00023 IMdcGeomSvc* KalFitTrack::iGeomSvc_ = 0;
00024 MdcDigiCol* KalFitTrack::mdcDigiCol_ = 0;
00025 int KalFitTrack::tprop_ = 1;
00026 
00027 
00028 //KalFitAlg* alg; 
00029 //IDataProviderSvc* eventSvc = alg->eventDataService();
00030 /* SmartDataPtr<MdcDigiCol> mdcDigiCol(alg->eventSvc(),"/Event/Digi/MdcDigiCol");
00031    if (!mdcDigiCol) {
00032    log << MSG::ERROR << "Could not find event in MdcDigiCol" << endreq;
00033    return( StatusCode::FAILURE);
00034    }
00035  */
00036 
00037 void KalFitTrack::setInitMatrix(HepSymMatrix m)
00038 { 
00039         initMatrix_ = m;
00040 }
00041 
00042 HepSymMatrix KalFitTrack::getInitMatrix() const
00043 {
00044         return initMatrix_ ;
00045 }
00046 
00047 void  KalFitTrack::setT0(double eventstart ) 
00048 {
00049         //------------------set  event  start time-----------
00050 
00051         EventT0_ = eventstart;
00052         if(debug_ == 4) {
00053                 std::cout<<"in function KalFitTrack::setT0(...), EventT0_ = "<<EventT0_<<std::endl;
00054         }
00055 }
00056 
00057 double  KalFitTrack::getT0(void ) const 
00058 {
00059         //------------------get  event  start time-----------
00060 
00061         if(debug_ == 4) {
00062                 std::cout<<"in function KalFitTrack::getT0 ( ), EventT0_ = "<<EventT0_<<std::endl;   
00063         }                                                                             
00064         return EventT0_ ;
00065 }
00066 
00067 //
00068 /*   double KalFitTrack::get_T0(void) const
00069      {
00070      return 0;
00071      }
00072  */
00073 
00074 double KalFitTrack::getDriftTime(KalFitHitMdc& hitmdc , double toftime) const
00075 {
00076         const double vinner = 220.0e8; // cm/s
00077         const double vouter = 240.0e8; // cm/s
00078 
00079         int layerid = hitmdc.wire().layer().layerId();
00080         double zhit = (hitmdc.rechitptr())->getZhit();
00081         const KalFitWire* wire = &(hitmdc.wire());
00082         HepPoint3D fPoint = wire->fwd();
00083         HepPoint3D bPoint = wire->bck();
00084 
00085         // unit is centimeter
00086         double wireLen = (fPoint-bPoint).x()*(fPoint-bPoint).x()+(fPoint-bPoint).y()*(fPoint-bPoint).y()+(fPoint-bPoint).z()*(fPoint-bPoint).z();
00087         wireLen = sqrt(wireLen);
00088         double wireZLen = fabs(fPoint.z() - bPoint.z());
00089         double tp = 0.;
00090         double vp = 0.;
00091         // west readout  
00092         if(0==layerid%2){
00093                 // inner chamber
00094                 if(layerid<8){
00095                         vp = vinner;
00096                 }
00097                 else {
00098                         vp = vouter;
00099                 } 
00100                 tp = wireLen*fabs(zhit - bPoint.z())/wireZLen/vp; 
00101         }
00102 
00103         // east readout  
00104         if(1==layerid%2){
00105                 // inner chamber
00106                 if(layerid<8){
00107                         vp = vinner;
00108                 }
00109                 else {
00110                         vp = vouter;
00111                 }
00112                 tp = wireLen*fabs(zhit - fPoint.z())/wireZLen/vp;
00113         }
00114 
00115         // s to ns
00116         tp = 1.0e9*tp;
00117 
00118         if(0==tprop_) tp = 0.;
00119 
00120         //std::cout<<"propogation time: "<<tp<<std::endl;
00121 
00122         int wireid = hitmdc.wire().geoID();
00123         double drifttime1(0.);
00124         double drifttime2(0.);
00125         double drifttime3(0.);
00126 
00127         MdcDigiCol::iterator iter = mdcDigiCol_->begin();       
00128         for(; iter != mdcDigiCol_->end(); iter++ ) {
00129                 if((*iter)->identify() == (hitmdc.rechitptr())->getMdcId()) break;
00130         }
00131         //double t0 = get_T0();
00132         // see the code of wulh in /Mdc/MdcCalibFunSvc/MdcCalibFunSvc/MdcCalibFunSvc.h,
00133         // double getT0(int wireid) const { return m_t0[wireid]; }
00134 
00135         //double getTimeWalk(int layid, double Q) const ;
00136         double Q = RawDataUtil::MdcCharge((*iter)->getChargeChannel()); 
00137         double timewalk = CalibFunSvc_->getTimeWalk(layerid, Q);
00138 
00139         if(debug_ == 4) { 
00140                 std::cout<<"CalibFunSvc_->getTimeWalk, timewalk ="<<timewalk<<std::endl;
00141         } 
00142 
00143         double timeoffset = CalibFunSvc_->getT0(wireid);
00144         if(debug_ == 4) {
00145                 std::cout<<"CalibFunSvc_->getT0, timeoffset ="<<timeoffset<<std::endl;
00146         } 
00147 
00148         double eventt0 = getT0(); 
00149 
00150         if(debug_ == 4) {
00151                 std::cout<<"the Event T0 we get in the function getDriftTime(...) is "<<eventt0<<std::endl;
00152         }
00153 
00154         // this tdc value come from MdcRecHit assigned by zhangyao
00155         double tdctime1 = hitmdc.tdc();
00156         double tdctime2(0.);
00157         double tdctime3(0.);
00158 
00159         if(debug_ == 4) {
00160                 std::cout<<"tdctime1 be here is .."<<tdctime1<<std::endl; 
00161         }
00162 
00163         // this tdc value come from MdcDigiCol time channel
00164         // attention, if we use the iter like this: for(MdcDigiCol::iterator iter = mdcDigiCol_->begin(); iter != mdcDigiCol_->end(); iter++) it cannot pass the gmake , throw an error !
00165         if(debug_ == 4) {
00166                 //  std::cout<<"the size of the mdcDigiCol_ is "<<mdcDigiCol_.size()<<std::endl;
00167         }
00168         // MdcDigiCol::iterator iter = mdcDigiCol_->begin();       
00169         // for(; iter != mdcDigiCol_->end(); iter++ ) {
00170         //       if((*iter)->identify() == (hitmdc.rechitptr())->getMdcId()) break;
00171         //  }
00172         if(debug_ == 4) { 
00173                 std::cout<<"the time channel be here is .."<<(*iter)->getTimeChannel()<<std::endl;
00174         }
00175         tdctime2 = RawDataUtil::MdcTime((*iter)->getTimeChannel());
00176         tdctime3 = hitmdc.rechitptr()->getTdc();
00177         drifttime1 = tdctime1 - eventt0 - toftime - timewalk -timeoffset - tp;
00178         drifttime2 = tdctime2 - eventt0 - toftime - timewalk -timeoffset - tp;
00179         drifttime3 = tdctime3 - eventt0 - toftime - timewalk -timeoffset - tp;
00180         if(debug_ == 4 ) {
00181                 std::cout<<"we now compare the three kind of tdc , the tdc get from timeChannel() is "<<tdctime2<<" the tdc get from KalFitHitMdc is "<<tdctime1<<" the tdc from MdcRecHit is "<<tdctime3<<" the drifttime1 is ..."<<drifttime1<<" the drifttime 2 is ..."<<drifttime2<<" the drifttime3 is ..."<<drifttime3<<std::endl;
00182         }
00183         //return drifttime3;
00184         //return drifttime1;
00185         if(drifttime_choice_ == 0)
00186                 return drifttime2;
00187         if(drifttime_choice_ == 1)
00188                 // use the driftT caluculated by track-finding
00189                 return hitmdc.rechitptr()->getDriftT(); 
00190 }
00191 
00192 
00193 // attention , the unit of the driftdist is mm
00194 double KalFitTrack::getDriftDist(KalFitHitMdc& hitmdc, double drifttime, int lr) const
00195 {
00196         int layerid = hitmdc.wire().layer().layerId();
00197         int  cellid = MdcID::wire(hitmdc.rechitptr()->getMdcId());
00198         if(debug_ == 4 ){
00199                 std::cout<<"the cellid is .."<<cellid<<std::endl;
00200         } 
00201         double entrangle = hitmdc.rechitptr()->getEntra();
00202 
00203         //std::cout<<" entrangle: "<<entrangle<<std::endl;
00204 
00205         return CalibFunSvc_->driftTimeToDist(drifttime, layerid, cellid,  lr, entrangle);
00206 }
00207 
00208 // attention , the unit of the sigma is mm
00209 double  KalFitTrack::getSigma(KalFitHitMdc& hitmdc, double tanlam, int lr, double dist) const
00210 { 
00211         int layerid = hitmdc.wire().layer().layerId();
00212         double entrangle = hitmdc.rechitptr()->getEntra();
00213         //  double tanlam = hitmdc.rechitptr()->getTanl();
00214         double z = hitmdc.rechitptr()->getZhit();
00215         double Q = hitmdc.rechitptr()->getAdc();
00216         //std::cout<<" the driftdist  before getsigma is "<<dist<<" the layer is"<<layerid<<std::endl;
00217         //cout<<"layerid, lr, dist, entrangle, tanlam, z , Q = "<<layerid<<", "<<lr<<", "<<dist<<", "<<entrangle<<", "<<tanlam<<", "<<z<<", "<<Q<<endl;//wangll
00218         double temp = CalibFunSvc_->getSigma(layerid, lr, dist, entrangle, tanlam, z , Q );
00219         //std::cout<<" the sigma is "<<temp<<std::endl;
00220         return temp;
00221 }
00222 
00223 void KalFitTrack::setMdcCalibFunSvc(const MdcCalibFunSvc*  calibsvc)
00224 {
00225         CalibFunSvc_ = calibsvc;
00226 }
00227 
00228 void KalFitTrack::setMagneticFieldSvc(IMagneticFieldSvc* mf)
00229 {
00230         /*ISvcLocator* svcLocator = Gaudi::svcLocator();
00231           StatusCode sc = svcLocator->service("MagneticFieldSvc",MFSvc_);
00232           if (sc.isFailure()){
00233           std::cout << "Could not load MagneticFieldSvc!" << std::endl;
00234           }*/
00235         MFSvc_ = mf;
00236         if(MFSvc_==0) cout<<"KalFitTrack2:: Could not load MagneticFieldSvc!"<<endl;
00237 } 
00238 
00239 void KalFitTrack::setIMdcGeomSvc(IMdcGeomSvc*  igeomsvc)
00240 {
00241         iGeomSvc_ = igeomsvc;
00242 }
00243 
00244 void KalFitTrack::setMdcDigiCol(MdcDigiCol*  digicol)
00245 {
00246         mdcDigiCol_ = digicol;
00247 }
00248 

Generated on Tue Nov 29 23:13:24 2016 for BOSS_7.0.2 by  doxygen 1.4.7