00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "MdcData/MdcHit.h"
00025 #include "TrkBase/TrkHitOnTrk.h"
00026 #include "TrkBase/TrkRecoTrk.h"
00027 #include "RawEvent/RawDataUtil.h"
00028 #include "Identifier/MdcID.h"
00029
00030 bool MdcHit::m_cosmicFit= false;
00031 bool MdcHit::m_countPropTime = true;
00032
00033 MdcHit::MdcHit( const MdcDigi*& aDigi, const MdcDetector*& det):
00034 TrkFundHit(), _digiPtr(aDigi), _geomPtr(det)
00035 {
00036 _digiPtr = aDigi;
00037 _geomPtr = det;
00038 assert( _digiPtr != NULL);
00039 assert( _geomPtr != NULL);
00040 _id = aDigi->identify();
00041 _layerPtr = det->Layer(_id);
00042 _wirePtr = det->Wire(_id);
00043 assert( _layerPtr != NULL);
00044 assert( _wirePtr != NULL);
00045 m_mdcCalibFunSvc = NULL;
00046 _layer = MdcID::layer(_id);
00047 _wire = MdcID::wire (_id);
00048 _iTdc = _digiPtr->getTimeChannel();
00049 _iAdc = _digiPtr->getChargeChannel();
00050 _rawTime = RawDataUtil::MdcTime(_iTdc);
00051 _charge = RawDataUtil::MdcCharge(_iAdc);
00052 _rmid = _wirePtr->rMid();
00053 _zlen = _layerPtr->zLength();
00054 _phi = _wirePtr->phi();
00055 _cosphi = cos(_phi);
00056 _sinphi = sin(_phi);
00057 _status = 0;
00058 }
00059
00060 MdcHit::MdcHit(const MdcHit& other) :
00061 TrkFundHit() , _digiPtr(other._digiPtr), _geomPtr(other._geomPtr),
00062 _layerPtr(other._layerPtr), _wirePtr(other._wirePtr), _id(other._id),
00063 _layer(other._layer), _wire(other._wire),
00064 _iTdc(other._iTdc), _iAdc(other._iAdc),
00065 _rawTime(other._rawTime), _charge(other._charge),
00066 _rmid(other._rmid), _zlen(other._zlen),
00067 _phi(other._phi), _cosphi(other._cosphi), _sinphi(other._sinphi),
00068 _status(other._status), _T0Walk(other._T0Walk)
00069 {
00070 m_mdcCalibFunSvc = other.m_mdcCalibFunSvc;
00071 }
00072
00073 MdcHit&
00074 MdcHit::operator = (const MdcHit& other) {
00075 if(&other != this){
00076 _digiPtr = other._digiPtr;
00077 _geomPtr = other._geomPtr;
00078 _layerPtr = other._layerPtr;
00079 _wirePtr = other._wirePtr;
00080 m_mdcCalibFunSvc = other.m_mdcCalibFunSvc;
00081 _id = other._id;
00082 _layer = other._layer;
00083 _wire = other._wire;
00084 _iTdc = other._iTdc;
00085 _iAdc = other._iAdc;
00086 _rawTime = other._rawTime;
00087 _charge = other._charge;
00088 _digiPtr = other._digiPtr;
00089 _rmid = other._rmid;
00090 _zlen = other._zlen;
00091 _phi = other._phi;
00092 _cosphi = other._cosphi;
00093 _sinphi = other._sinphi;
00094 _status = other._status;
00095 _T0Walk = other._T0Walk;
00096 }
00097 return *this;
00098 }
00099
00100
00101
00102 MdcHit::~MdcHit() {
00103
00104
00105
00106
00107
00108 short count = 0;
00109 while (nUsedHits() > count) {
00110 bool removed = _hitList[count]->parentTrack()->hits()->removeHit(this);
00111 if (!removed) count++;
00112 }
00113 }
00114
00115 bool
00116 MdcHit::operator==( const MdcHit& rhs ) const {
00117 return (this == &rhs);
00118 }
00119
00120 void
00121 MdcHit::print( ostream& o ) const {
00122 o << "(" << _layer << ","<< _wire <<","<<digi()->getTrackIndex()<<")";
00123 }
00124
00125 void
00126 MdcHit::printAll( ostream& o ) const {
00127 o << "Hit:(" << _layer << "," << _wire
00128 << ") x:" << x() << " y:" << y()
00129 << " rt:" << rawTime()
00130 << " dt:" <<driftTime(0.0,0)
00131 << " dd:" <<driftDist(0.0,1)
00132 << endl;
00133 }
00134
00135 void
00136 MdcHit::setCalibSvc(const MdcCalibFunSvc* calibSvc) {
00137 m_mdcCalibFunSvc = calibSvc;
00138 _T0Walk = m_mdcCalibFunSvc->getT0(_layer,_wire) + m_mdcCalibFunSvc->getTimeWalk(_layer, _iAdc);
00139 }
00140
00141 double
00142 MdcHit::driftTime(double tof, double z) const {
00143
00144 double tprop = 0.;
00145 if (m_countPropTime){ tprop = m_mdcCalibFunSvc->getTprop(_layer,z*10.); }
00146
00147
00148 double driftT = _rawTime - _T0Walk -1.e9*tof - tprop;
00149
00150
00151
00152 return driftT;
00153 }
00154
00155 double
00156 MdcHit::driftDist(double tof, int ambig, double entranceAngle,
00157 double , double z) const
00158 {
00159 double driftD;
00160
00161
00162 int lrCalib=2;
00163 if (ambig==1) lrCalib = 0;
00164 else if (ambig==-1) lrCalib = 1;
00165
00166
00167 if (fabs(z)>150. || fabs(driftTime(tof,z))>1500.){
00168 return 9999.;
00169 }
00170 driftD = 0.1 * m_mdcCalibFunSvc->driftTimeToDist(driftTime(tof,z),_layer,_wire,lrCalib,entranceAngle);
00171
00172
00173 if (abs(driftD)<Constants::epsilon) driftD = 0.00001;
00174 return driftD;
00175 }
00176
00177 double
00178 MdcHit::driftDist(double bunchTime, int ambig) const {
00179 return driftDist(bunchTime+crudeTof(), ambig, 0., 0., 0. );
00180 }
00181
00182
00183 double
00184 MdcHit::sigma(double driftdist, int ambig, double entranceAngle,
00185 double dipAngle, double z) const {
00186 double sig = 9999.;
00187
00188 #ifdef MDCPATREC_RESLAYER
00189 if (_layer == m_resLayer){
00190
00191 return 9999.;
00192 }
00193 #endif
00194
00195
00196
00197 if ( m_mdcCalibFunSvc ) {
00198
00199
00200
00201
00202 int lrCalib=2;
00203 if (ambig==1) lrCalib = 0;
00204 else if (ambig==-1) lrCalib = 1;
00205
00206
00207
00208 sig = 0.1 * m_mdcCalibFunSvc->getSigma(_layer,lrCalib,driftdist*10.,entranceAngle,
00209 tan(dipAngle),z*10.,_iAdc);
00210
00211 if(fabs(sig)<Constants::epsilon){
00212 sig = 999.;
00213 }
00214
00215
00216
00217
00218
00219
00220 }
00221
00222 return sig;
00223 }
00224
00225 double
00226 MdcHit::sigma(double driftdist, int ambig) const {
00227 return sigma(driftdist, ambig, 0., 0., 0.);
00228 }
00229
00230 const Trajectory*
00231 MdcHit::hitTraj() const {
00232 return layer()->makeHitTrajInGlobalCoords(wirenumber(),0.0);
00233 }
00234
00235 extern ostream&
00236 operator<<( ostream &o, const MdcHit& hit ) {
00237 hit.print(o);
00238 return o;
00239 }
00240