BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
HoughHit.cxx
Go to the documentation of this file.
1#include "HoughHit.h"
2#include "GaudiKernel/ISvcLocator.h"
3#include "GaudiKernel/StatusCode.h"
4#include "HoughGlobal.h"
5#include "Identifier/MdcID.h"
6#include "MdcGeomSvc/IMdcGeomSvc.h"
7#include "MdcGeomSvc/MdcGeoLayer.h"
8#include "MdcGeomSvc/MdcGeoWire.h"
9#include "RawEvent/RawDataUtil.h"
10#include <assert.h>
11
12const IMdcCalibFunSvc* HoughHit::_calibPtr = NULL;
13IMdcGeomSvc* HoughHit::_mdcGeomSvc = NULL;
14double HoughHit::_bunchTime;
15int HoughHit::_npart = 360;
16// MdcDetector* HoughHit::_det=NULL;
17
19 _det = Global::m_gm;
20 _digiPtr = NULL;
21 _layerPtr = NULL;
22 _wirePtr = NULL;
23}
24HoughHit::HoughHit( const MdcDigi* const aDigi ) {
25 _det = Global::m_gm;
26 _digiPtr = aDigi;
27 _id = aDigi->identify();
28 _layer = MdcID::layer( _id );
29 _wire = MdcID::wire( _id );
30 _layerPtr = _det->Layer( _id );
31 _wirePtr = _det->Wire( _id );
32 _rawTime = RawDataUtil::MdcTime( _digiPtr->getTimeChannel() );
33 _charge = _digiPtr->getChargeChannel();
34 _driftTime = driftTime();
35 _driftDist = calDriftDist( _bunchTime, 0 );
36 _slayerType = slayerType( _layer );
37 _lr = 0;
38 _rmid = _wirePtr->rMid();
39
40 assert( _mdcGeomSvc != NULL );
41 const MdcGeoWire* wire = _mdcGeomSvc->Wire( _layer, _wire );
42 assert( wire != NULL );
43 HepPoint3D eastP = wire->Backward() / 10.;
44 HepPoint3D westP = wire->Forward() / 10.;
45 _eastPoint = eastP;
46 _westPoint = westP;
47 _midPoint = ( eastP + westP ) / 2.;
48
49 _type = MIDPOINT;
50 conformalTrans( _midPoint.x(), _midPoint.y(), _driftDist );
51}
52
54 : _digiPtr( other._digiPtr )
55 , _det( other._det )
56 , _layerPtr( other._layerPtr )
57 , _wirePtr( other._wirePtr )
58 , _id( other._id )
59 , _layer( other._layer )
60 , _wire( other._wire )
61 , _rawTime( other._rawTime )
62 , _charge( other._charge )
63 , _eastPoint( other._eastPoint )
64 , _westPoint( other._westPoint )
65 , _midPoint( other._midPoint )
66 , _u( other._u )
67 , _v( other._v )
68 , _type( other._type )
69 , _detectorType( other._detectorType )
70 , _rmid( other._rmid )
71 , _slayerType( other._slayerType )
72 , _cirlist( other._cirlist )
73 , _style( other._style )
74 , _driftTime( other._driftTime )
75 , _driftDist( other._driftDist )
76 , CF_drift( other.CF_drift )
77 , vec_cfcir( other.vec_cfcir )
78 ,
79 // truth
80 _truthU( other._truthU )
81 , _truthV( other._truthV )
82 , _truthR( other._truthR )
83 , _truthlr( other._truthlr )
84 , _truthPoint( other._truthPoint )
85 , _truthDrift( other._truthDrift )
86 , _deltad( other._deltad )
87 , _flightLength( other._flightLength ) {}
88
90 _digiPtr = ( other._digiPtr );
91 _det = ( other._det );
92 _layerPtr = ( other._layerPtr );
93 _wirePtr = ( other._wirePtr );
94 _id = ( other._id );
95 _layer = ( other._layer );
96 _wire = ( other._wire );
97 _rawTime = ( other._rawTime );
98 _charge = ( other._charge );
99 _eastPoint = ( other._eastPoint );
100 _westPoint = ( other._westPoint );
101 _midPoint = ( other._midPoint );
102 _u = ( other._u );
103 _v = ( other._v );
104 _type = ( other._type );
105 _detectorType = ( other._detectorType );
106 _rmid = ( other._rmid );
107 _slayerType = ( other._slayerType );
108 _cirlist = ( other._cirlist );
109 _style = ( other._style );
110 _driftTime = ( other._driftTime );
111 _driftDist = ( other._driftDist );
112 CF_drift = ( other.CF_drift );
113 vec_cfcir = ( other.vec_cfcir );
114 // truth
115 _truthU = ( other._truthU );
116 _truthV = ( other._truthV );
117 _truthR = ( other._truthR );
118 _truthlr = ( other._truthlr );
119 _truthDrift = ( other._truthDrift );
120 _truthPoint = ( other._truthPoint );
121 _deltad = ( other._deltad );
122 _flightLength = ( other._flightLength );
123
124 return *this;
125}
126
127void HoughHit::setTruthInfo( const MdcMcHit*& aMcHit ) {
128 if ( !aMcHit ) return;
129 _truthDrift = aMcHit->getDriftDistance() / 10.; // mm to cm
130 _truthPoint.setX( aMcHit->getPositionX() / 10. ); // mm to cm
131 _truthPoint.setY( aMcHit->getPositionY() / 10. );
132 _truthPoint.setZ( aMcHit->getPositionZ() / 10. );
133
134 int mcLR = aMcHit->getPositionFlag();
135 // if (mcLR == 0) mcLR = -1;//FIXME
136 // for truth reserve from digi
137 if ( mcLR == 1 ) mcLR = -1; //
138 if ( mcLR == 0 ) mcLR = 1; //
139 _truthId = aMcHit->getTrackIndex();
140 _truthlr = mcLR;
141
142 // fix
143 _truthU = getConformal_u( _truthPoint.x(), _truthPoint.y(), _truthDrift );
144 _truthV = getConformal_v( _truthPoint.y(), _truthPoint.x(), _truthDrift );
145 _truthR = getConformal_r( _truthPoint.x(), _truthPoint.y(), _truthDrift );
146
147 // std::cout<<__FILE__<<" "<<_layer<<","<<_wire<<" "<<_truthId<<" truth "<<_truthPoint<<"
148 // truthU
149 // "<<_truthU<<std::endl;
150
151 _type = DIGIWITHTRUTH;
152}
153
154void HoughHit::conformalTrans( double x, double y, double r ) {
155 _u = 2 * x / ( x * x + y * y - r * r );
156 _v = 2 * y / ( x * x + y * y - r * r );
157 CF_drift = 2 * r / ( x * x + y * y - r * r );
158}
159
160double HoughHit::getConformal_u( double x, double y, double r ) {
161 return 2 * x / ( x * x + y * y - r * r );
162}
163double HoughHit::getConformal_v( double x, double y, double r ) {
164 return 2 * x / ( x * x + y * y - r * r );
165}
166double HoughHit::getConformal_r( double x, double y, double r ) {
167 return 2 * r / ( x * x + y * y - r * r );
168}
169
170double HoughHit::driftTime() const {
171 double tprop = _calibPtr->getTprop( _layer, 0 );
172 double T0Walk =
173 _calibPtr->getT0( _layer, _wire ) + _calibPtr->getTimeWalk( _layer, _charge );
174 // tof in ns, driftTime in ns, _T0Walk in ns
175 double driftT = _rawTime - T0Walk - 1.e9 * _bunchTime - tprop;
176 return driftT;
177}
178double HoughHit::driftTime( double tof, double z ) const {
179 double tprop = _calibPtr->getTprop( _layer, z * 10. );
180 double T0Walk =
181 _calibPtr->getT0( _layer, _wire ) + _calibPtr->getTimeWalk( _layer, _charge );
182 // tof in ns, driftTime in ns, _T0Walk in ns
183 double driftT = _rawTime - T0Walk - 1.e9 * tof - tprop;
184
185 return driftT;
186}
187
188double HoughHit::calDriftDist( double bunchTime, int ambig ) const {
189
190 // double crudeTof = 0; //FIXME
191 return calDriftDist( bunchTime + crudeTof(), ambig, 0., 0., 0. );
192}
193
194double HoughHit::calDriftDist( double tof, int ambig, double entranceAngle,
195 double /*dipAngle*/, double z ) const {
196
197 double driftD;
198 // drift time ns, layer id begin with 0, entrance angle rads,
199 // lr ambig: wire ambig 1,-1,0 -> Calib 0,1,2
200 int lrCalib = 2;
201 if ( ambig == 1 ) lrCalib = 0;
202 else if ( ambig == -1 ) lrCalib = 1;
203
204 // tof in s, driftDist in cm, dirftTime in ns
205 if ( fabs( z ) > 150. || fabs( driftTime( tof, z ) ) > 1500. ) { return 9999.; }
206 driftD = 0.1 * _calibPtr->driftTimeToDist( driftTime( tof, z ), _layer, _wire, lrCalib,
207 entranceAngle ); // to cm
208 // std::cout<<"driftDist "<<"("<<_layer <<","<<_wire <<") dd "<<driftD<<" dt
209 // "<<driftTime(tof,z) <<" lr "<<lrCalib <<" eAng "<<entranceAngle <<" tof "<<tof*1.e9<<" z
210 // "<<z <<" t0walk "<<_T0Walk<<" rawT "<<_rawTime <<" tprop "<< _rawTime - driftTime(tof,z)-
211 // _T0Walk-1.e9*tof<<std::endl;
212
213 if ( abs( driftD ) < 0.00001 ) driftD = 0.00001;
214 return driftD;
215}
216
217void HoughHit::print() const {
218 std::cout << "(" << _layer << "," << _wire << ") " << std::endl;
219}
220
221void HoughHit::printAll() const {
222 std::cout << "(" << _layer << "," << _wire << ") id " << this->digi()->getTrackIndex()
223 << " xyz " << _midPoint << endl;
224}
226 std::cout << "(" << _layer << "," << _wire << ") truth " << _truthId << " xyz "
227 << _truthPoint << " uv " << _truthU << "," << _truthV << ") "
228 << " cir list " << _cirlist << " ambig " << _truthlr << std::endl;
229}
230
232 // get nominal shift cell of this layer
233 double nomShift = _mdcGeomSvc->Layer( layer )->nomShift();
234
235 if ( nomShift > 0 ) return 1;
236 else if ( nomShift < 0 ) return -1;
237 else return 0;
238
239 return -999;
240}
241
242// calcu drift cir
243void HoughHit::makeCir( int n, double phi_begin, double phi_last, double r ) {
244 vec_cfcir.clear();
245 vector<CFCir>().swap( vec_cfcir );
246 for ( int i = 0; i < n; i++ )
247 {
248 double phi_slice = ( phi_last - phi_begin ) / n;
249 double phi = phi_begin + ( 1 / 2. + i ) * phi_slice;
250 double x = _u + r * cos( phi );
251 double y = _v + r * sin( phi );
252 vec_cfcir.push_back( CFCir( x, y, phi, n, _u, _v, r ) );
253 }
254}
const Int_t n
@ DIGIWITHTRUTH
Definition HoughGlobal.h:18
@ MIDPOINT
Definition HoughGlobal.h:18
HepGeom::Point3D< double > HepPoint3D
Definition HoughHit.h:18
Definition CFCir.h:3
double getPositionZ() const
Definition MdcMcHit.cxx:47
int getPositionFlag() const
Definition MdcMcHit.cxx:56
unsigned int getTrackIndex() const
Definition MdcMcHit.cxx:38
double getDriftDistance() const
Definition MdcMcHit.cxx:50
double getPositionX() const
Definition MdcMcHit.cxx:41
double getPositionY() const
Definition MdcMcHit.cxx:44
void printTruth() const
Definition HoughHit.cxx:225
const MdcDigi * digi() const
Definition HoughHit.h:53
void conformalTrans(double x, double y, double r)
Definition HoughHit.cxx:154
double driftTime() const
Definition HoughHit.cxx:170
static int _npart
Definition HoughHit.h:48
const MdcLayer * layer() const
Definition HoughHit.h:63
void printAll() const
Definition HoughHit.cxx:221
void print() const
Definition HoughHit.cxx:217
void makeCir(int n, double phi_begin, double phi_last, double r)
Definition HoughHit.cxx:243
void setTruthInfo(const MdcMcHit *&mcHit)
Definition HoughHit.cxx:127
int slayerType(int layer)
Definition HoughHit.cxx:231
double getConformal_v(double, double, double)
Definition HoughHit.cxx:163
double calDriftDist(double, int, double, double, double) const
Definition HoughHit.cxx:194
double getConformal_r(double, double, double)
Definition HoughHit.cxx:166
const MdcSWire * wire() const
Definition HoughHit.h:64
HoughHit & operator=(const HoughHit &other)
Definition HoughHit.cxx:89
double getConformal_u(double, double, double)
Definition HoughHit.cxx:160
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
static double MdcTime(int timeChannel)
virtual Identifier identify() const
Definition RawData.cxx:15
int getTrackIndex() const
Definition RawData.cxx:38
const MdcDetector * m_gm