BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcHit.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: MdcHit.cxx,v 1.37 2012/08/13 00:01:16 zhangy Exp $
4//
5// Description:
6// Class Implementation |MdcHit|
7//
8// Environment:
9// Software developed for the BESIII Detector at the BEPCII
10//
11// Author List:
12// S. Schaffner - Original
13// A. Snyder - Mods
14// S. Sen Feb 17 1998 New digi()->MCPtr() references
15//
16// Copyright Information:
17// Copyright (C) 1996 SLAC
18//
19// History:
20// Migration for BESIII MDC
21//
22//------------------------------------------------------------------------
23
24#include "MdcData/MdcHit.h"
25#include "Identifier/MdcID.h"
26#include "RawEvent/RawDataUtil.h"
27#include "TrkBase/TrkHitOnTrk.h"
28#include "TrkBase/TrkRecoTrk.h"
29
30bool MdcHit::m_cosmicFit = false;
31bool MdcHit::m_countPropTime = true;
32
33MdcHit::MdcHit( const MdcDigi*& aDigi, const MdcDetector*& det )
34 : TrkFundHit(), _digiPtr( aDigi ), _geomPtr( det ) {
35 _digiPtr = aDigi;
36 _geomPtr = det;
37 assert( _digiPtr != NULL );
38 assert( _geomPtr != NULL );
39 _id = aDigi->identify();
40 _layerPtr = det->Layer( _id );
41 _wirePtr = det->Wire( _id );
42 assert( _layerPtr != NULL );
43 assert( _wirePtr != NULL );
44 m_mdcCalibFunSvc = NULL;
45 _layer = MdcID::layer( _id );
46 _wire = MdcID::wire( _id );
47 _iTdc = _digiPtr->getTimeChannel();
48 _iAdc = _digiPtr->getChargeChannel();
49 _rawTime = RawDataUtil::MdcTime( _iTdc );
50 _charge = RawDataUtil::MdcCharge( _iAdc );
51 _rmid = _wirePtr->rMid();
52 _zlen = _layerPtr->zLength();
53 _phi = _wirePtr->phi();
54 _cosphi = cos( _phi );
55 _sinphi = sin( _phi );
56 _status = 0;
57}
58
59MdcHit::MdcHit( const MdcHit& other )
60 : TrkFundHit()
61 , _digiPtr( other._digiPtr )
62 , _geomPtr( other._geomPtr )
63 , _layerPtr( other._layerPtr )
64 , _wirePtr( other._wirePtr )
65 , _id( other._id )
66 , _layer( other._layer )
67 , _wire( other._wire )
68 , _iTdc( other._iTdc )
69 , _iAdc( other._iAdc )
70 , _rawTime( other._rawTime )
71 , _charge( other._charge )
72 , _rmid( other._rmid )
73 , _zlen( other._zlen )
74 , _phi( other._phi )
75 , _cosphi( other._cosphi )
76 , _sinphi( other._sinphi )
77 , _status( other._status )
78 , _T0Walk( other._T0Walk ) {
79 m_mdcCalibFunSvc = other.m_mdcCalibFunSvc;
80}
81
83 if ( &other != this )
84 {
85 _digiPtr = other._digiPtr;
86 _geomPtr = other._geomPtr;
87 _layerPtr = other._layerPtr;
88 _wirePtr = other._wirePtr;
89 m_mdcCalibFunSvc = other.m_mdcCalibFunSvc;
90 _id = other._id;
91 _layer = other._layer;
92 _wire = other._wire;
93 _iTdc = other._iTdc;
94 _iAdc = other._iAdc;
95 _rawTime = other._rawTime;
96 _charge = other._charge;
97 _digiPtr = other._digiPtr;
98 _rmid = other._rmid;
99 _zlen = other._zlen;
100 _phi = other._phi;
101 _cosphi = other._cosphi;
102 _sinphi = other._sinphi;
103 _status = other._status;
104 _T0Walk = other._T0Walk;
105 }
106 return *this;
107}
108
109// Destructor
111 // This is ugly and inefficient. This, along with the rest of
112 // the hitList mess, should be cleaned up by handling the
113 // association in an external map
114
115 // Not written as a loop because removeHit() modifies TrkFundHit::_hitList
116 short count = 0;
117 while ( nUsedHits() > count )
118 {
119 bool removed = _hitList[count]->parentTrack()->hits()->removeHit( this );
120 if ( !removed ) count++;
121 }
122}
123
124bool MdcHit::operator==( const MdcHit& rhs ) const { return ( this == &rhs ); }
125
126void MdcHit::print( ostream& o ) const {
127 o << "(" << _layer << "," << _wire << "," << digi()->getTrackIndex() << ")";
128}
129
130void MdcHit::printAll( ostream& o ) const {
131 o << "Hit:(" << _layer << "," << _wire << ") x:" << x() << " y:" << y()
132 << " rt:" << rawTime() << " dt:" << driftTime( 0.0, 0 ) << " dd:" << driftDist( 0.0, 1 )
133 << endl;
134}
135
137 m_mdcCalibFunSvc = calibSvc;
138 _T0Walk = m_mdcCalibFunSvc->getT0( _layer, _wire ) +
139 m_mdcCalibFunSvc->getTimeWalk( _layer, _iAdc );
140}
141
142double MdcHit::driftTime( double tof, double z ) const {
143 // t prop
144 double tprop = 0.;
145 if ( m_countPropTime ) { tprop = m_mdcCalibFunSvc->getTprop( _layer, z * 10. ); }
146
147 // tof in s, driftTime in ns, _T0Walk in ns
148 double driftT = _rawTime - _T0Walk - 1.e9 * tof - tprop;
149
150 // if(driftT >10000)
151 // std::cout<< "driftTime ("<<_layer<<","<<_wire<<") dt "<<driftT<<" rawTime "<<_rawTime<<" z
152 // "<<z<<" tprop "<<tprop
153 // <<" t0walk "<<_T0Walk<<" tof "<<1.e9*tof<< std::endl;//yzhang debug
154 return driftT;
155}
156
157double MdcHit::driftDist( double tof, int ambig, double entranceAngle, double /*dipAngle*/,
158 double z ) const {
159 double driftD;
160 // drift time ns, layer id begin with 0, entrance angle rads,
161 // lr ambig: wire ambig 1,-1,0 -> Calib 0,1,2
162 int lrCalib = 2;
163 if ( ambig == 1 ) lrCalib = 0;
164 else if ( ambig == -1 ) lrCalib = 1;
165
166 // tof in s, driftDist in cm, dirftTime in ns
167 if ( fabs( z ) > 150. || fabs( driftTime( tof, z ) ) > 1500. ) { return 9999.; }
168 driftD = 0.1 * m_mdcCalibFunSvc->driftTimeToDist( driftTime( tof, z ), _layer, _wire,
169 lrCalib, entranceAngle ); // to cm
170 // std::cout<<"driftDist "<<"("<<_layer <<","<<_wire <<") dd "<<driftD<<" dt
171 // "<<driftTime(tof,z) <<" lr "<<lrCalib <<" eAng "<<entranceAngle <<" tof "<<tof*1.e9<<" z
172 // "<<z <<" t0walk "<<_T0Walk<<" rawT "<<_rawTime <<" tprop "<< _rawTime - driftTime(tof,z)-
173 // _T0Walk-1.e9*tof<<std::endl;
174
175 if ( abs( driftD ) < Constants::epsilon ) driftD = 0.00001;
176 return driftD;
177}
178
179double MdcHit::driftDist( double bunchTime, int ambig ) const {
180 return driftDist( bunchTime + crudeTof(), ambig, 0., 0., 0. );
181}
182
183double MdcHit::sigma( double driftdist, int ambig, double entranceAngle, double dipAngle,
184 double z ) const {
185 double sig = 9999.;
186
187#ifdef MDCPATREC_RESLAYER
188 if ( _layer == m_resLayer )
189 {
190 // give a huge sigma to skip this layer when fit track
191 return 9999.;
192 }
193#endif
194 // if(fabs(z)>150. || driftdist==9999. ) {
195 // return 9999.;
196 // }
197 if ( m_mdcCalibFunSvc )
198 {
199 // layid begin with 0, entrance angle in rads,
200 // distance: cm ->Calib mm //z: cm -> Calib mm
201 // Q: MonteCalo eV -> Calib fC FIXME
202 // lr ambig: wire ambig 1,-1,0 -> Calib 0,1,2
203 int lrCalib = 2;
204 if ( ambig == 1 ) lrCalib = 0;
205 else if ( ambig == -1 ) lrCalib = 1;
206
207 // std::cout<<"layer "<<_layer<< " lrCalib "<< lrCalib<< " driftdist "<< driftdist << "
208 // eAngle "<<entranceAngle
209 //<<" tan(dipAngle) "<<tan(dipAngle)<< " z "<<z <<" iAdc "<<_iAdc<<std::endl;
210 sig = 0.1 * m_mdcCalibFunSvc->getSigma( _layer, lrCalib, driftdist * 10., entranceAngle,
211 tan( dipAngle ), z * 10.,
212 _iAdc ); // Calib special resolution mm -> cm
213
214 if ( fabs( sig ) < Constants::epsilon ) { sig = 999.; }
215 // if(sig<=0){
216 // std::cout<<__FILE__<<" "<<__LINE__ <<" sigma "<<sig
217 //<<" layer "<<_layer <<" lrCalib "<<lrCalib <<" driftdist "<<driftdist*10
218 //<<" eAngle "<<entranceAngle<<" dipAngle "<<(dipAngle) <<" tanl "<<tan(dipAngle)
219 //<<" z "<<z <<" iAdc "<<_iAdc <<std::endl;
220 // }
221 }
222 // if (_layer<4) sig /=5.;//yzhang TEST 2011-05-27
223 return sig;
224}
225
226double MdcHit::sigma( double driftdist, int ambig ) const {
227 return sigma( driftdist, ambig, 0., 0., 0. ); // cm
228}
229
231 return layer()->makeHitTrajInGlobalCoords( wirenumber(), 0.0 );
232}
233
234extern ostream& operator<<( ostream& o, const MdcHit& hit ) {
235 hit.print( o );
236 return o;
237}
DOUBLE_PRECISION count[3]
ostream & operator<<(ostream &o, const MdcHit &hit)
Definition MdcHit.cxx:234
MdcHit(const MdcDigi *&digi, const MdcDetector *&det)
Definition MdcHit.cxx:33
void print(std::ostream &o) const
virtual ~MdcHit()
Definition MdcHit.cxx:110
const IMdcCalibFunSvc * calibSvc() const
bool operator==(const MdcHit &) const
Definition MdcHit.cxx:124
double driftTime(double tof, double z) const
Definition MdcHit.cxx:142
double sigma(double, int, double, double, double) const
Definition MdcHit.cxx:183
MdcHit & operator=(const MdcHit &)
Definition MdcHit.cxx:82
const Trajectory * hitTraj() const
Definition MdcHit.cxx:230
double driftDist(double, int, double, double, double) const
Definition MdcHit.cxx:157
void setCalibSvc(const IMdcCalibFunSvc *calibSvc)
Definition MdcHit.cxx:136
void printAll(std::ostream &o) const
static int layer(const Identifier &id)
Values of different levels (failure returns 0).
Definition MdcID.cxx:47
static int wire(const Identifier &id)
Definition MdcID.cxx:52
const Trajectory * makeHitTrajInGlobalCoords(int wire, double z=0) const
Definition MdcLayer.cxx:90
static double MdcTime(int timeChannel)
static double MdcCharge(int chargeChannel)
virtual Identifier identify() const
Definition RawData.cxx:15
int getTrackIndex() const
Definition RawData.cxx:38
int nUsedHits() const