BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TMLink.cxx
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: TMLink.cxx,v 1.15 2011/10/08 01:56:15 maoh Exp $
3//-----------------------------------------------------------------------------
4// Filename : TMLink.cc
5// Section : Tracking
6// Owner : Yoshi Iwasaki
7// Email : yoshihito.iwasaki@kek.jp
8//-----------------------------------------------------------------------------
9// Description : A class to relate TMDCWireHit and TTrack objects.
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11//-----------------------------------------------------------------------------
12
13#include "TrkReco/TMLink.h"
14#include "CLHEP/Alist/ConstAList.h"
15#include "TrkReco/TMDCUtil.h"
16#include "TrkReco/TMDCWireHit.h"
17#include "TrkReco/TMDCWireHitMC.h"
18#include "TrkReco/TTrackHEP.h"
19
20// zangsl 040518 : move inlined function here
21const TMDCWire* const TMLink::wire( void ) const {
22 if ( _hit ) return _hit->wire();
23 return NULL;
24}
25
26const HepPoint3D& TMLink::xyPosition( void ) const { return _hit->wire()->xyPosition(); }
27// zangsl 040518 end
28
29/*TMLink::TMLink(TTrack * t, const TMDCWireHit * h, const HepPoint3D & p)
30: _track(t),
31 _hit(h),
32 _dPhi(0),
33 _leftRight(0),
34 _pull(0),
35 _position(p),
36 _link(0),
37 _fit2D(0) {
38// _usecathode(0) {
39 if (h) {
40 _drift[0] = h->drift(0);
41 _drift[1] = h->drift(1);
42 _dDrift[0] = h->dDrift(0);
43 _dDrift[1] = h->dDrift(1);
44 }
45 else {
46 _drift[0] = 0.;
47 _drift[1] = 0.;
48 _dDrift[0] = 0.;
49 _dDrift[1] = 0.;
50 }
51
52 for (unsigned i = 0; i < 6; ++i)
53 _neighbor[i] = NULL;
54 for (unsigned i = 0; i < 4; ++i)
55 _arcZ[i];
56
57 if (h) {
58 _onTrack = _onWire = h->xyPosition();
59 }
60}
61*/
62// for Tsf
63TMLink::TMLink( TTrack* t, const TMDCWireHit* h, const HepPoint3D& p, const HepPoint3D& d,
64 double dr )
65 : _track( t )
66 , _hit( h )
67 , _dPhi( 0 )
68 , _leftRight( 0 )
69 , _pull( 0 )
70 , _position( p )
71 , _positionD( d )
72 , _link( 0 )
73 , _fit2D( 0 )
74 , _tsfTag( 0 ) {
75 if ( h )
76 {
77 _cDrift[0] = dr; // after conformal transformation.
78 _cDrift[1] = dr;
79 _drift[0] = h->drift( 0 );
80 _drift[1] = h->drift( 1 );
81 _dDrift[0] = h->dDrift( 0 );
82 _dDrift[1] = h->dDrift( 1 );
83 }
84 else
85 {
86 _cDrift[0] = 0.;
87 _cDrift[1] = 0.;
88 _drift[0] = 0.;
89 _drift[1] = 0.;
90 _dDrift[0] = 0.;
91 _dDrift[1] = 0.;
92 }
93
94 for ( unsigned i = 0; i < 6; ++i ) _neighbor[i] = NULL;
95 for ( unsigned i = 0; i < 4; ++i ) _arcZ[i];
96
97 if ( h ) { _onTrack = _onWire = h->xyPosition(); }
98}
99
101 : _track( l._track )
102 , _hit( l._hit )
103 , _onTrack( l._onTrack )
104 , _onWire( l._onWire )
105 , _position( l._position )
106 , _positionD( l._positionD )
107 , _dPhi( l._dPhi )
108 , _leftRight( l._leftRight )
109 , _pull( l._pull )
110 , _link( l._link )
111 , _distance( l._distance )
112 ,
113 // addition by matsu ( 1999/07/05 )
114 // _mclust(l._mclust ),
115 // _usecathode(l._usecathode ),
116 // end of addition
117 _fit2D( l._fit2D )
118 , _tsfTag( l._tsfTag ) {
119 _drift[0] = l._drift[0];
120 _drift[1] = l._drift[1];
121 _dDrift[0] = l._dDrift[0];
122 _dDrift[1] = l._dDrift[1];
123 _cDrift[0] = l._cDrift[0];
124 _cDrift[1] = l._cDrift[1];
125 for ( unsigned i = 0; i < 6; ++i ) _neighbor[i] = l._neighbor[i];
126 for ( unsigned i = 0; i < 4; ++i ) _arcZ[i] = l._arcZ[i];
127}
128
130
131void TMLink::dump( const std::string& msg, const std::string& pre ) const {
132 std::cout << pre;
133 if ( _track ) std::cout << "track#=,";
134 if ( _hit ) { _hit->dump( msg ); }
135}
136
137unsigned NLayers( const AList<TMLink>& list ) {
138 unsigned l0 = 0;
139 unsigned l1 = 0;
140 unsigned n = list.length();
141 for ( unsigned i = 0; i < n; i++ )
142 {
143 unsigned id = list[i]->wire()->layerId();
144 if ( id < 32 ) l0 |= ( 1 << id );
145 else l1 |= ( 1 << ( id - 32 ) );
146 }
147
148 unsigned l = 0;
149 for ( unsigned i = 0; i < 32; i++ )
150 {
151 if ( l0 & ( 1 << i ) ) ++l;
152 if ( l1 & ( 1 << i ) ) ++l;
153 }
154 return l;
155}
156
157void NHits( const AList<TMLink>& links, unsigned nHits[43] ) {
158 for ( unsigned i = 0; i < 43; i++ ) nHits[i] = 0;
159 unsigned nLinks = links.length();
160 for ( unsigned i = 0; i < nLinks; i++ ) ++nHits[links[i]->wire()->layerId()];
161}
162
163void NHitsSuperLayer( const AList<TMLink>& links, unsigned nHits[11] ) {
164 for ( unsigned i = 0; i < 11; i++ ) nHits[i] = 0;
165 unsigned nLinks = links.length();
166 for ( unsigned i = 0; i < nLinks; i++ ) ++nHits[links[i]->wire()->superLayerId()];
167}
168
169void Dump( const CAList<TMLink>& links, const std::string& msg, const std::string& pre ) {
170 bool mc = ( msg.find( "mc" ) != std::string::npos );
171 bool pull = ( msg.find( "pull" ) != std::string::npos );
172 bool flag = ( msg.find( "flag" ) != std::string::npos );
173 bool sort = ( msg.find( "sort" ) != std::string::npos );
174 bool stereo = ( msg.find( "stereo" ) != std::string::npos );
175 bool detail = ( msg.find( "detail" ) != std::string::npos );
176 bool pos = ( msg.find( "position" ) != std::string::npos );
177 if ( detail ) mc = pull = flag = sort = true;
178
179 CAList<TMLink> tmp = links;
180 if ( sort ) tmp.sort( SortByWireId );
181 unsigned n = tmp.length();
182 unsigned nForFit = 0;
183#define MCC_MAX 1000
184 unsigned MCC0[MCC_MAX];
185 unsigned MCC1[MCC_MAX];
186 for ( unsigned i = 0; i < MCC_MAX; i++ )
187 {
188 MCC0[i] = 0;
189 MCC1[i] = 0;
190 }
191 bool MCCOverFlow = false;
192
193 std::cout << pre;
194 for ( unsigned i = 0; i < n; i++ )
195 {
196 const TMLink& l = *tmp[i];
197 std::cout << l.wire()->name();
198
199 double a = l.pull();
200 unsigned mcId = 0;
201 if ( mc )
202 if ( l.hit()->mc() )
203 if ( l.hit()->mc()->hep() ) mcId = l.hit()->mc()->hep()->id();
204 if ( pull ) { std::cout << "[" << a << "]"; }
205 if ( mc )
206 {
207 std::cout << "(" << mcId << ")";
208 if ( mcId < MCC_MAX )
209 {
210 ++MCC0[mcId];
211 if ( l.hit()->state() & WireHitFittingValid )
212 {
213 if ( !( l.hit()->state() & WireHitInvalidForFit ) ) ++MCC1[mcId];
214 }
215 }
216 else { MCCOverFlow = true; }
217 }
218 if ( flag )
219 {
220 if ( l.hit()->state() & WireHitFindingValid ) std::cout << "o";
221 if ( l.hit()->state() & WireHitFittingValid )
222 {
223 std::cout << "+";
224 if ( !( l.hit()->state() & WireHitInvalidForFit ) ) ++nForFit;
225 }
226 if ( l.hit()->state() & WireHitInvalidForFit ) std::cout << "x";
227 }
228 if ( stereo ) { std::cout << "{" << l.leftRight() << "," << l.zStatus() << "}"; }
229 if ( pos ) { std::cout << ",pos=" << l.position(); }
230 std::cout << ",";
231 }
232 std::cout << " " << n << " l(s)";
233 if ( flag ) std::cout << ", fv " << nForFit << " l(s)";
234 if ( mc )
235 {
236 unsigned nMC = 0;
237 std::cout << ", mc";
238 for ( unsigned i = 0; i < MCC_MAX; i++ )
239 {
240 if ( MCC0[i] > 0 )
241 {
242 ++nMC;
243 std::cout << i << ":" << MCC0[i] << ",";
244 }
245 }
246 std::cout << " total " << nMC << " contributions";
247 if ( flag )
248 {
249 nMC = 0;
250 std::cout << ", fv mc";
251 for ( unsigned i = 0; i < MCC_MAX; i++ )
252 {
253 if ( MCC1[i] > 0 )
254 {
255 ++nMC;
256 std::cout << i << ":" << MCC1[i] << ",";
257 }
258 }
259 std::cout << " total " << nMC << " contributions";
260 }
261
262 if ( MCCOverFlow ) std::cout << "(counter overflow)";
263 }
264 std::cout << std::endl;
265}
266
267void Dump( const TMLink& link, const std::string& msg, const std::string& pre ) {
268 CAList<TMLink> tmp;
269 tmp.append( link );
270 Dump( tmp, msg, pre );
271}
272
273unsigned NStereoHits( const AList<TMLink>& links ) {
274 unsigned nLinks = links.length();
275 unsigned n = 0;
276 for ( unsigned i = 0; i < nLinks; i++ )
277 if ( links[i]->wire()->stereo() ) ++n;
278 return n;
279}
280
281unsigned NAxialHits( const AList<TMLink>& links ) {
282 unsigned nLinks = links.length();
283 unsigned n = 0;
284 for ( unsigned i = 0; i < nLinks; i++ )
285 if ( links[i]->wire()->axial() ) ++n;
286 return n;
287}
288
291 unsigned n = links.length();
292 for ( unsigned i = 0; i < n; i++ )
293 {
294 if ( links[i]->wire()->axial() ) a.append( links[i] );
295 }
296 return a;
297}
298
301 unsigned n = links.length();
302 for ( unsigned i = 0; i < n; i++ )
303 {
304 if ( !links[i]->wire()->axial() ) a.append( links[i] );
305 }
306 return a;
307}
308
310 unsigned n = a.length();
311 unsigned minId = 9999;
312 TMLink* t = 0;
313 for ( unsigned i = 0; i < n; i++ )
314 {
315 unsigned id = a[i]->wire()->id();
316 if ( id < minId )
317 {
318 minId = id;
319 t = a[i];
320 }
321 }
322 return t;
323}
324
326 unsigned n = a.length();
327 unsigned maxId = 0;
328 TMLink* t = 0;
329 for ( unsigned i = 0; i < n; i++ )
330 {
331 unsigned id = a[i]->wire()->id();
332 if ( id > maxId )
333 {
334 maxId = id;
335 t = a[i];
336 }
337 }
338 return t;
339}
340
341void SeparateCores( const AList<TMLink>& input, AList<TMLink>& cores,
342 AList<TMLink>& nonCores ) {
343 unsigned n = input.length();
344 for ( unsigned i = 0; i < n; i++ )
345 {
346 TMLink& t = *input[i];
347 const TMDCWireHit& h = *t.hit();
348 if ( h.state() & WireHitFittingValid ) cores.append( t );
349 else nonCores.append( t );
350 }
351}
352
355 unsigned n = input.length();
356 for ( unsigned i = 0; i < n; i++ )
357 {
358 TMLink& t = *input[i];
359 const TMDCWireHit& h = *t.hit();
360 if ( h.state() & WireHitFittingValid ) a.append( t );
361 }
362 return a;
363}
364
365#if defined( __GNUG__ )
366int SortByWireId( const TMLink** a, const TMLink** b ) {
367 if ( ( *a )->wire()->id() > ( *b )->wire()->id() ) return 1;
368 else if ( ( *a )->wire()->id() == ( *b )->wire()->id() ) return 0;
369 else return -1;
370}
371
372int SortByX( const TMLink** a, const TMLink** b ) {
373 if ( ( *a )->position().x() > ( *b )->position().x() ) return 1;
374 else if ( ( *a )->position().x() == ( *b )->position().x() ) return 0;
375 else return -1;
376}
377
378#else
379extern "C" int SortByWireId( const void* av, const void* bv ) {
380 const TMLink** a( (const TMLink**)av );
381 const TMLink** b( (const TMLink**)bv );
382 if ( ( *a )->wire()->id() > ( *b )->wire()->id() ) return 1;
383 else if ( ( *a )->wire()->id() == ( *b )->wire()->id() ) return 0;
384 else return -1;
385}
386
387extern "C" int SortByX( const void* av, const void* bv ) {
388 const TMLink** a( (const TMLink**)av );
389 const TMLink** b( (const TMLink**)bv );
390 if ( ( *a )->position().x() > ( *b )->position().x() ) return 1;
391 else if ( ( *a )->position().x() == ( *b )->position().x() ) return 0;
392 else return -1;
393}
394
395#endif
396
397unsigned Width( const AList<TMLink>& list ) {
398 unsigned n = list.length();
399 if ( n < 2 ) return n;
400
401 const TMDCWire* w = list[0]->wire();
402 unsigned nWires = w->layer()->nWires();
403 unsigned center = w->localId();
404
405#ifdef TRKRECO_DEBUG_DETAIL
406 unsigned sId = w->superLayerId();
407#endif
408
409 unsigned left = 0;
410 unsigned right = 0;
411 for ( unsigned i = 1; i < n; i++ )
412 {
413 w = list[i]->wire();
414 unsigned id = w->localId();
415
416 unsigned distance0, distance1;
417 if ( id > center )
418 {
419 distance0 = id - center;
420 distance1 = nWires - distance0;
421 }
422 else
423 {
424 distance1 = center - id;
425 distance0 = nWires - distance1;
426 }
427
428 if ( distance0 < distance1 )
429 {
430 if ( distance0 > right ) right = distance0;
431 }
432 else
433 {
434 if ( distance1 > left ) left = distance1;
435 }
436
437#ifdef TRKRECO_DEBUG_DETAIL
438 if ( w->superLayerId() != sId )
439 std::cout << "::width !!! super layer assumption violation" << std::endl;
440#endif
441 }
442
443 return right + left + 1;
444}
445
448
449 unsigned n = list.length();
450 if ( n < 2 ) return a;
451 else if ( n == 2 ) return list;
452
453 const TMDCWire* w = list[0]->wire();
454 unsigned nWires = w->layer()->nWires();
455 unsigned center = w->localId();
456
457 unsigned left = 0;
458 unsigned right = 0;
459 TMLink* leftL = list[0];
460 TMLink* rightL = list[0];
461 for ( unsigned i = 1; i < n; i++ )
462 {
463 w = list[i]->wire();
464 unsigned id = w->localId();
465
466 unsigned distance0, distance1;
467 if ( id > center )
468 {
469 distance0 = id - center;
470 distance1 = nWires - distance0;
471 }
472 else
473 {
474 distance1 = center - id;
475 distance0 = nWires - distance1;
476 }
477
478 if ( distance0 < distance1 )
479 {
480 if ( distance0 > right )
481 {
482 right = distance0;
483 rightL = list[i];
484 }
485 }
486 else
487 {
488 if ( distance1 > left )
489 {
490 left = distance1;
491 leftL = list[i];
492 }
493 }
494 }
495
496 a.append( leftL );
497 a.append( rightL );
498 return a;
499}
500
501AList<TMLink> SameLayer( const AList<TMLink>& list, const TMLink& a ) {
502 AList<TMLink> same;
503 unsigned id = a.wire()->layerId();
504 unsigned n = list.length();
505 for ( unsigned i = 0; i < n; i++ )
506 {
507 if ( list[i]->wire()->layerId() == id ) same.append( list[i] );
508 }
509 return same;
510}
511
513 AList<TMLink> same;
514 unsigned id = a.wire()->superLayerId();
515 unsigned n = list.length();
516 for ( unsigned i = 0; i < n; i++ )
517 {
518 if ( list[i]->wire()->superLayerId() == id ) same.append( list[i] );
519 }
520 return same;
521}
522
523AList<TMLink> SameLayer( const AList<TMLink>& list, unsigned id ) {
524 AList<TMLink> same;
525 unsigned n = list.length();
526 for ( unsigned i = 0; i < n; i++ )
527 {
528 if ( list[i]->wire()->layerId() == id ) same.append( list[i] );
529 }
530 return same;
531}
532
533AList<TMLink> SameSuperLayer( const AList<TMLink>& list, unsigned id ) {
534 AList<TMLink> same;
535 unsigned n = list.length();
536 for ( unsigned i = 0; i < n; i++ )
537 {
538 if ( list[i]->wire()->superLayerId() == id ) same.append( list[i] );
539 }
540 return same;
541}
542
544 AList<TMLink> inners;
545 AList<TMLink> outers;
546 unsigned n = list.length();
547 unsigned innerMostLayer = 999;
548 unsigned outerMostLayer = 0;
549 for ( unsigned i = 0; i < n; i++ )
550 {
551 unsigned id = list[i]->wire()->layerId();
552 if ( id < innerMostLayer ) innerMostLayer = id;
553 else if ( id > outerMostLayer ) outerMostLayer = id;
554 }
555 for ( unsigned i = 0; i < n; i++ )
556 {
557 unsigned id = list[i]->wire()->layerId();
558 if ( id == innerMostLayer ) inners.append( list[i] );
559 else if ( id == outerMostLayer ) outers.append( list[i] );
560 }
561 inners.append( outers );
562 return inners;
563}
564
565unsigned SuperLayer( const AList<TMLink>& list ) {
566 unsigned sl = 0;
567 unsigned n = list.length();
568 for ( unsigned i = 0; i < n; i++ ) sl |= ( 1 << ( list[i]->wire()->superLayerId() ) );
569 return sl;
570}
571
572unsigned SuperLayer( const AList<TMLink>& links, unsigned minN ) {
573 unsigned n = links.length();
574 unsigned nHits[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
575 for ( unsigned i = 0; i < n; i++ ) ++nHits[links[i]->wire()->superLayerId()];
576 unsigned sl = 0;
577 for ( unsigned i = 0; i < 11; i++ )
578 if ( nHits[i] >= minN ) sl |= ( 1 << i );
579 return sl;
580}
581
582unsigned NSuperLayers( const AList<TMLink>& list ) {
583 unsigned l0 = 0;
584 unsigned n = list.length();
585 for ( unsigned i = 0; i < n; i++ )
586 {
587 unsigned id = list[i]->wire()->superLayerId();
588 l0 |= ( 1 << id );
589 }
590
591 unsigned l = 0;
592 for ( unsigned i = 0; i < 11; i++ )
593 {
594 if ( l0 & ( 1 << i ) ) ++l;
595 }
596 return l;
597}
598
599unsigned NSuperLayers( const AList<TMLink>& links, unsigned minN ) {
600 unsigned n = links.length();
601 unsigned nHits[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
602 for ( unsigned i = 0; i < n; i++ ) ++nHits[links[i]->wire()->superLayerId()];
603 unsigned sl = 0;
604 for ( unsigned i = 0; i < 11; i++ )
605 if ( nHits[i] >= minN ) ++sl;
606 return sl;
607}
608
609unsigned NMissingAxialSuperLayers( const AList<TMLink>& links ) {
610 unsigned n = links.length();
611 // Liuqg, change the following to BES. unsigned nHits[6] = {0, 0, 0, 0, 0, 0};
612 unsigned nHits[5] = { 0, 0, 0, 0, 0 };
613 for ( unsigned i = 0; i < n; i++ )
614 if ( links[i]->wire()->axial() ) ++nHits[links[i]->wire()->axialStereoLayerId() / 4];
615 unsigned j = 0;
616 while ( nHits[j] == 0 ) ++j;
617 unsigned nMissing = 0;
618 unsigned nMax = 0;
619 for ( unsigned i = j; i < 5; i++ )
620 {
621 if ( nHits[i] == 0 ) ++nMissing;
622 else
623 {
624 if ( nMax < nMissing ) nMax = nMissing;
625 nMissing = 0;
626 }
627 }
628 return nMax;
629}
630
631const TTrackHEP& Links2HEP( const AList<TMLink>& links ) {
632 const TTrackHEP* best = NULL;
633 const AList<TTrackHEP>& list = TTrackHEP::list();
634 unsigned nHep = list.length();
635
636 if ( !nHep ) return *best;
637
638 unsigned* N = (unsigned*)malloc( nHep * sizeof( unsigned ) );
639 for ( unsigned i = 0; i < nHep; i++ ) N[i] = 0;
640
641 for ( unsigned i = 0; i < links.length(); i++ )
642 {
643 const TMLink& l = *links[i];
644 const TTrackHEP& hep = *l.hit()->mc()->hep();
645 for ( unsigned j = 0; j < nHep; j++ )
646 if ( list[j] == &hep ) ++N[j];
647 }
648
649 unsigned nMax = 0;
650 for ( unsigned i = 0; i < nHep; i++ )
651 {
652 if ( N[i] > nMax )
653 {
654 best = list[i];
655 nMax = N[i];
656 }
657 }
658
659 return *best;
660}
661
662/*
663double
664TMLink::DriftTime(double _tof,double z) const {
665 double tprop = 0.;
666 double _vprop = (_layer<8) ? Constants::vpropInner : Constants::vpropOuter;
667 if (0 == _layer%2){
668 tprop = (0.5*_zlen + z)/_vprop; //odd
669 }else{
670 tprop = (0.5*_zlen - z)/_vprop; //even
671 }
672 double driftT;
673 driftT = fabs(_rawTime - _T0Walk -1.e9*tof - tprop);
674
675 //std::cout<< "lay "<<_layer<<" cell "<<_wire<<" zhit "<<z<<" tprop "<<tprop << std::endl;
676 return driftT;
677}
678*/
const Int_t n
double w
const TTrackHEP *const hep(void) const
returns a pointer to a GEN_HEPEVT.
float dDrift(unsigned) const
returns drift distance error.
float drift(unsigned) const
returns drift distance.
const HepPoint3D & xyPosition(void) const
returns drift time
const TMDCWireHitMC *const mc(void) const
returns a pointer to TMDCWireHitMC.
unsigned layerId(void) const
returns layer id.
unsigned superLayerId(void) const
returns super layer id.
std::string name(void) const
returns name.
A class to represent a GEN_HEPEVT particle in tracking.
unsigned id(void) const
returns an id started from 0.
static const AList< TTrackHEP > & list(void)
returns a list of TTrackHEP's.
Definition TTrackHEP.cxx:70
A class to represent a track in tracking.
int t()
Definition t.c:1