00001 #include "KalFitAlg/KalFitAlg.h"
00002 #include "KalFitAlg/KalFitTrack.h"
00003 #include "KalFitAlg/KalFitWire.h"
00004
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
00029
00030
00031
00032
00033
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
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
00060
00061 if(debug_ == 4) {
00062 std::cout<<"in function KalFitTrack::getT0 ( ), EventT0_ = "<<EventT0_<<std::endl;
00063 }
00064 return EventT0_ ;
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074 double KalFitTrack::getDriftTime(KalFitHitMdc& hitmdc , double toftime) const
00075 {
00076 const double vinner = 220.0e8;
00077 const double vouter = 240.0e8;
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
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
00092 if(0==layerid%2){
00093
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
00104 if(1==layerid%2){
00105
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
00116 tp = 1.0e9*tp;
00117
00118 if(0==tprop_) tp = 0.;
00119
00120
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
00132
00133
00134
00135
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
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
00164
00165 if(debug_ == 4) {
00166
00167 }
00168
00169
00170
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
00184
00185 if(drifttime_choice_ == 0)
00186 return drifttime2;
00187 if(drifttime_choice_ == 1)
00188
00189 return hitmdc.rechitptr()->getDriftT();
00190 }
00191
00192
00193
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
00204
00205 return CalibFunSvc_->driftTimeToDist(drifttime, layerid, cellid, lr, entrangle);
00206 }
00207
00208
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
00214 double z = hitmdc.rechitptr()->getZhit();
00215 double Q = hitmdc.rechitptr()->getAdc();
00216
00217
00218 double temp = CalibFunSvc_->getSigma(layerid, lr, dist, entrangle, tanlam, z , Q );
00219
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
00231
00232
00233
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