BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Hough3D.cxx
Go to the documentation of this file.
1#include "Hough3D.h"
2int Hough3D::m_debug = 0;
3vector<MdcHit*> vec_for_clean;
4vector<TrkRecoTrk*> vectrk_for_clean;
8// double Hough3D::m_dropTrkDrCut=1;
9// double Hough3D::m_dropTrkDzCut=10;
10double Hough3D::m_dropTrkDrCut = 1; // no limit of dr dz
11double Hough3D::m_dropTrkDzCut = 10;
13double Hough3D::m_dropTrkChi2Cut = 99999;
14double Hough3D::m_dropTrkChi2NdfCut = 99999;
15
17 //_m_gm = MdcDetector::instance(0);
18}
19Hough3D::Hough3D( const Hough3D& other ) {
20 _circleR = other._circleR;
21 _circleX = other._circleX;
22 _circleY = other._circleY;
23 _charge = other._charge;
24 _d0 = other._d0;
25 _phi0 = other._phi0;
26 _omega = other._omega;
27 _tanl = other._tanl;
28 _z0 = other._z0;
29
30 _pt = other._pt;
31 _pz = other._pz;
32 _p = other._p;
33 _nfit = other._nfit;
34 _bunchT0 = other._bunchT0;
35 _chi2_aver = other._chi2_aver;
36 _m_gm = other._m_gm;
37 _recHitVec = other._recHitVec;
38 vec_mdcHit = other.vec_mdcHit;
39}
40
41Hough3D::Hough3D( const Hough2D& hough2D, recHitCol hitCol, double bunchtime, double tanl,
42 double z0 )
43 : _tanl( tanl ), _z0( z0 ) {
44 //_m_gm = MdcDetector::instance(0);
45 _circleR = hough2D.getCirR();
46 _circleX = hough2D.getCirX();
47 _circleY = hough2D.getCirY();
48 _d0 = hough2D.getD0();
49 _phi0 = hough2D.getPhi0();
50 _omega = hough2D.getOmega();
51 _charge = hough2D.getCharge();
52 _bunchT0 = bunchtime;
53 _recHitVec = hitCol;
54 _pt = 0;
55 _p = 0;
56 _pz = 0;
57 _nfit = 0;
58 newTrack = NULL;
59}
60Hough3D::Hough3D( const Hough2D& hough2D, recHitCol hitCol, double bunchtime, double tanl,
61 double z0, const vector<MdcHit*>* mdchit )
62 : _tanl( tanl ), _z0( z0 ), vec_mdcHit( mdchit ) {
63 //_m_gm = MdcDetector::instance(0);
64 _circleR = hough2D.getCirR();
65 _circleX = hough2D.getCirX();
66 _circleY = hough2D.getCirY();
67 _d0 = hough2D.getD0();
68 _phi0 = hough2D.getPhi0();
69 _omega = hough2D.getOmega();
70 _charge = hough2D.getCharge();
71 _bunchT0 = bunchtime;
72 _recHitVec = hitCol;
73 _pt = 0;
74 _p = 0;
75 _pz = 0;
76 _nfit = 0;
77 newTrack = NULL;
78}
79
81 if ( _charge == -1 )
82 {
83 // cout<<" charge -1 "<<endl;
84 // _d0=-_d0;
85 // _omega=-1.*fabs(_omega);
86 }
87 if ( _charge == 1 )
88 {
89 // cout<<" charge +1 "<<endl;
90 // _d0=_d0;
91 // _omega=1.*fabs(_omega);
92 //_phi0=_phi0-M_PI;
93 }
94
95 // outerHit(); // delete 4 hit in a wire for kalman
96
97 TrkExchangePar tt( _d0, _phi0, _omega, _z0, _tanl );
98 if ( m_debug > 0 )
99 cout << "q d0 phi0 omega: " << _charge << " " << _d0 << " " << _phi0 << " " << _omega
100 << " " << _tanl << " " << _z0 << endl;
101 TrkHelixMaker helixfactory;
102 float chisum = 0.;
103 newTrack = helixfactory.makeTrack( tt, chisum, *_context, _bunchT0 );
104 // vectrk_for_clean.push_back(newTrack);
105 bool permitFlips = true;
106 bool lPickHits = true;
107 helixfactory.setFlipAndDrop( *newTrack, permitFlips, lPickHits );
108 TrkHitList* trkHitList = newTrack->hits();
109 int digiId = 0;
110 std::vector<HoughRecHit>::iterator iter = _recHitVec.begin();
111 for ( ; iter != _recHitVec.end(); iter++, digiId++ )
112 {
113 if ( ( *iter ).getflag() != 0 ) continue;
114 // if( (*iter)->calDriftDist(_bunchT0,0)>0.8) continue;
115 // if( (*iter)->driftTime(_bunchT0,0)>800) continue;
116 // cout<<"rechit dist time "<<(*iter).calDriftDist(_bunchT0,0)<<"
117 // "<<(*iter).driftTime(_bunchT0,0)<<endl;
118
119 const MdcDigi* aDigi = ( *iter ).digi();
120 MdcHit* hit = nullptr; // add initialize 25-05-15
121 // compare
122 vector<MdcHit*>::const_iterator iter_digi = ( *vec_mdcHit ).begin();
123 for ( ; iter_digi != ( *vec_mdcHit ).end(); iter_digi++ )
124 {
125 if ( ( *iter_digi )->digi() == ( *iter ).digi() ) { hit = ( *iter_digi ); }
126 }
127 Identifier id = aDigi->identify();
128 int layer = MdcID::layer( id );
129 int wire = MdcID::wire( id );
131 hit->setCountPropTime( true );
132 // new fltLen and ambig
133 int newAmbig = 0;
134 // calc. position of this point
135 MdcRecoHitOnTrack temp( *hit, newAmbig, _bunchT0 * 1.e9 ); // m_bunchT0 nano second here
136 MdcHitOnTrack* newhot = &temp;
137 double flight;
138 double z_flight;
139 // if( layer<8 ) flight = sqrt(
140 // ((*iter).getsPos())*((*iter).getsPos())+((*iter).getzPos())*((*iter).getzPos())) ;
141 // if( layer<8 ) flight =(*iter).getsPos();
142 flight = ( *iter ).getRet().second;
143 double distoTrack = ( *iter ).getDisToTrack();
144 // if( layer<8 ) newhot->setFltLen( (*iter).getsPos()); //caculate by mc
145 // else newhot->setFltLen( (*iter).getRet().second); //caculate by mc
146 newhot->setFltLen( flight );
147 // if(layer==18) continue;
148
149 int use_in3d = 1;
150 // if(hit->driftDist(_bunchT0,0)>1.0) use_in3d=0;
151 if ( hit->driftTime( _bunchT0, 0 ) > 1000 ) use_in3d = 0;
152 // if(m_debug>0) cout<<"flt : "<<(*iter).getsPos()<<endl;
153 if ( m_debug > 0 ) cout << "flt : " << flight << endl;
154 if ( m_debug > 0 )
155 std::cout << " (" << layer << "," << wire << ",rt " << hit->rawTime() << ",dt "
156 << hit->driftTime( _bunchT0, 0 ) << ") T0 "
157 << _mdcCalibFunSvc->getT0( layer, wire ) << " timewalk "
158 << _mdcCalibFunSvc->getTimeWalk( layer, aDigi->getChargeChannel() )
159 << "dist: " << hit->driftDist( _bunchT0, 0 ) << " disToTrk " << distoTrack
160 << " use?: " << use_in3d << endl;
161 // if(hit->driftTime(_bunchT0,0)>800) continue;
162 if ( use_in3d == 0 ) continue;
163 trkHitList->appendHot( newhot );
164 }
165 if ( m_debug > 0 ) newTrack->printAll( std::cout );
166
167 TrkHitList* qhits = newTrack->hits();
168 TrkErrCode err = qhits->fit();
169 const TrkFit* newFit = newTrack->fitResult();
170 int nActiveHit = newTrack->hots()->nActive();
171 int fit_stat = false;
172 double chi2 = -999.;
173 if ( !newFit || ( newFit->nActive() < 5 ) || err.failure() != 0 )
174 {
175 // if (!newFit )
176 if ( m_debug > 0 )
177 {
178 cout << " global 3d fit failed ";
179 if ( newFit ) cout << " nAct " << newFit->nActive();
180 cout << "ERR1 failure =" << err.failure() << endl;
181 fit_stat = 0;
182 }
183 }
184 else
185 {
186 TrkExchangePar par = newFit->helix( 0. );
187 if ( abs( 1 / ( par.omega() ) ) > 0.03 )
188 {
189 fit_stat = 1;
190 chi2 = newFit->chisq();
191 }
192 else
193 {
194 fit_stat = 0;
195 chi2 = -999;
196 }
197
198 bool badQuality = false;
199 if ( fabs( chi2 ) > m_qualityFactor * m_dropTrkChi2Cut )
200 {
201 if ( m_debug > 0 )
202 {
203 std::cout << __FILE__ << " " << __LINE__ << " drop track by chi2 " << chi2 << " > "
204 << m_qualityFactor << " * " << m_dropTrkChi2Cut << std::endl;
205 }
206 badQuality = 1;
207 }
208 if ( fabs( par.d0() ) > m_qualityFactor * m_dropTrkDrCut )
209 {
210 if ( m_debug > 0 )
211 {
212 std::cout << __FILE__ << " " << __LINE__ << " drop track by d0 " << par.d0() << " > "
213 << m_qualityFactor << " * " << m_dropTrkDrCut << std::endl;
214 }
215 badQuality = 1;
216 }
217 if ( fabs( par.z0() ) > m_qualityFactor * m_dropTrkDzCut )
218 {
219 if ( m_debug > 0 )
220 {
221 std::cout << __FILE__ << " " << __LINE__ << " drop track by z0 " << par.z0() << " > "
222 << m_qualityFactor << " * " << m_dropTrkDzCut << std::endl;
223 }
224 badQuality = 1;
225 }
226 if ( ( fabs( chi2 ) / qhits->nHit() ) > m_qualityFactor * m_dropTrkChi2NdfCut )
227 {
228 if ( m_debug > 0 )
229 {
230 std::cout << __FILE__ << " " << __LINE__ << " drop track by chi2/ndf"
231 << ( fabs( chi2 ) / qhits->nHit() ) << " > " << m_qualityFactor << " * "
232 << m_dropTrkChi2NdfCut << std::endl;
233 }
234 badQuality = 1;
235 }
236 if ( nActiveHit <= m_dropTrkNhitCut )
237 {
238 if ( m_debug > 0 )
239 {
240 std::cout << __FILE__ << " " << __LINE__ << " drop track by nhit" << nActiveHit
241 << " <= " << m_dropTrkNhitCut << std::endl;
242 }
243 badQuality = 1;
244 }
245 // badQuality = false; //not delete track in this stage
246 if ( badQuality ) fit_stat = 0;
247 }
248 if ( fit_stat != 1 )
249 {
250 delete newTrack;
251 vectrk_for_clean.pop_back();
252 }
253 if ( fit_stat == 1 )
254 {
255 if ( m_debug > 0 )
256 {
257 cout << " global 3d fit success" << endl;
258 cout << __FILE__ << __LINE__ << "AFTER fit 3d " << endl;
259 newTrack->print( std::cout );
260 }
261 TrkExchangePar par = newFit->helix( 0. );
262 _d0 = par.d0();
263 _phi0 = par.phi0();
264 _omega = par.omega();
265 _tanl = par.tanDip();
266 _z0 = par.z0();
267
268 _circleR = _charge / par.omega();
269 _circleX = sin( par.phi0() ) * ( par.d0() + 1 / par.omega() ) *
270 -1.; // z axis verse,x_babar = -x_belle
271 _circleY = -1. * cos( par.phi0() ) * ( par.d0() + 1 / par.omega() ) * -1; //???
272 double pxy = fabs( _circleR / 333.567 );
273 double pz = pxy * par.tanDip();
274 double pxyz = _charge * sqrt( pxy * pxy + pz * pz );
275 _pt = pxy;
276 _pz = pz;
277 _p = pxyz;
278 if ( m_debug > 0 )
279 {
280 cout << " circle after globle 3d: "
281 << "(" << _circleX << "," << _circleY << "," << _circleR << ")" << endl;
282 cout << "pt_rec: " << _pt << endl;
283 cout << "pz_rec: " << _pz << endl;
284 cout << "p_rec: " << _p << endl;
285 }
286
287 int nfit3d = 0;
288 if ( m_debug > 0 ) cout << " hot list:" << endl;
289 TrkHotList::hot_iterator hotIter = qhits->hotList().begin();
290 int lay = ( (MdcHit*)( hotIter->hit() ) )->layernumber();
291 int wir = ( (MdcHit*)( hotIter->hit() ) )->wirenumber();
292 while ( hotIter != qhits->hotList().end() )
293 {
294 if ( m_debug > 0 )
295 {
296 cout << "(" << ( (MdcHit*)( hotIter->hit() ) )->layernumber() << ","
297 << ( (MdcHit*)( hotIter->hit() ) )->wirenumber() << ":" << hotIter->isActive()
298 << ") ";
299 }
300 // cout << "nuse "<<hotIter->hit()->nUsedHits()<<endl;
301 if ( hotIter->isActive() == 1 ) nfit3d++;
302 hotIter++;
303 }
304 _nfit = nfit3d;
305 }
306 _chi2_aver = chi2 / _nfit;
307 // for(int i=0;i<t_hitCol.size();i++){
308 // delete t_hitCol[i];
309 // }
310 if ( m_debug > 0 ) cout << " in 3D fit number of Active hits : " << _nfit << endl;
311 return fit_stat;
312}
313
315 cout << " print hough3d " << endl;
316 cout << "par: " << _d0 << " " << _phi0 << " " << _omega << " " << _tanl << " " << _z0
317 << endl;
318}
319
320bool less_layer_3D( const int& a, const int& b ) { return a < b; }
321
323 for ( int ihit = 0; ihit < _recHitVec.size(); ihit++ )
324 {
325 if ( _recHitVec[ihit].calDriftDist( _bunchT0, 0 ) > 0.8 ||
326 _recHitVec[ihit].driftTime( _bunchT0, 0 ) > 800 )
327 _recHitVec[ihit].setflag( -5 ); // flag -5 time or drift
328 }
329
330 vector<int> vec_layer_num[43];
331 for ( int ilay = 0; ilay < 43; ilay++ )
332 {
333 for ( int ihit = 0; ihit < _recHitVec.size(); ihit++ )
334 {
335 if ( _recHitVec[ihit].getLayerId() == ilay && _recHitVec[ihit].getflag() == 0 )
336 { vec_layer_num[ilay].push_back( _recHitVec[ihit].getWireId() ); }
337 }
338 std::sort( vec_layer_num[ilay].begin(), vec_layer_num[ilay].end(), less_layer_3D );
339 if ( vec_layer_num[ilay].size() < 4 ) continue;
340 for ( int j = 0; j < vec_layer_num[ilay].size(); j++ )
341 {
342 // if( (vec_layer_num[ilay][j]+1 == vec_layer_num[ilay][j+1]) &&
343 //(vec_layer_num[ilay][j+1]+1 ==
344 // vec_layer_num[ilay][j+2]) && (vec_layer_num[ilay][j+2]+1 == vec_layer_num[ilay][j+3])
345 // ) {
346 for ( int jhit = 0; jhit < _recHitVec.size(); jhit++ )
347 {
348 if ( ( ilay == _recHitVec[jhit].getLayerId() ) &&
349 ( vec_layer_num[ilay][j] == _recHitVec[jhit].getWireId() ) )
350 { _recHitVec[jhit].setflag( -1 ); }
351 }
352 //}
353 }
354 }
355}
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
vector< TrkRecoTrk * > vectrk_for_clean
Definition Hough3D.cxx:4
vector< MdcHit * > vec_for_clean
Definition Hough3D.cxx:3
bool less_layer_3D(const int &a, const int &b)
Definition Hough3D.cxx:320
vector< TrkRecoTrk * > vectrk_for_clean
Definition Hough3D.cxx:4
std::vector< HoughRecHit > recHitCol
Definition Hough3D.h:21
double getD0() const
Definition Hough2D.h:36
double getCirR() const
Definition Hough2D.h:35
double getOmega() const
Definition Hough2D.h:38
double getCirX() const
Definition Hough2D.h:33
double getCirY() const
Definition Hough2D.h:34
double getPhi0() const
Definition Hough2D.h:37
int getCharge() const
Definition Hough2D.h:39
void print()
Definition Hough3D.cxx:314
static double m_dropTrkDzCut
Definition Hough3D.h:79
static double m_dropTrkNhitCut
Definition Hough3D.h:80
static int m_debug
Definition Hough3D.h:72
int fit()
Definition Hough3D.cxx:80
static TrkContextEv * _context
Definition Hough3D.h:73
void outerHit()
Definition Hough3D.cxx:322
static double m_dropTrkDrCut
Definition Hough3D.h:78
static const IMdcCalibFunSvc * _mdcCalibFunSvc
Definition Hough3D.h:74
Hough3D()
Definition Hough3D.cxx:16
static double m_dropTrkChi2NdfCut
Definition Hough3D.h:81
static double m_dropTrkChi2Cut
Definition Hough3D.h:77
static int m_qualityFactor
Definition Hough3D.h:76
double driftTime(double tof, double z) const
Definition MdcHit.cxx:142
double driftDist(double, int, double, double, double) const
Definition MdcHit.cxx:157
void setCalibSvc(const IMdcCalibFunSvc *calibSvc)
Definition MdcHit.cxx:136
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
virtual Identifier identify() const
Definition RawData.cxx:15
unsigned int getChargeChannel() const
Definition RawData.cxx:35
virtual double chisq() const =0
virtual int nActive() const =0
virtual TrkExchangePar helix(double fltL) const =0
TrkErrCode fit()
TrkHitOnTrk * appendHot(const TrkHitOnTrk *theHot)
const TrkHotList & hotList() const
TrkHitOnTrkIter< TrkHotList::const_iterator_traits > hot_iterator
bool setFlipAndDrop(TrkRecoTrk &, bool allowFlips, bool allowDrops) const
TrkRecoTrk * makeTrack(const TrkExchangePar &helix, const double chi2, const TrkContext &, double trackT0) const