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"
22 if ( _hit )
return _hit->wire();
79 _drift[0] = h->
drift( 0 );
80 _drift[1] = h->
drift( 1 );
81 _dDrift[0] = h->
dDrift( 0 );
82 _dDrift[1] = h->
dDrift( 1 );
94 for (
unsigned i = 0; i < 6; ++i ) _neighbor[i] = NULL;
95 for (
unsigned i = 0; i < 4; ++i ) _arcZ[i];
97 if ( h ) { _onTrack = _onWire = h->
xyPosition(); }
103 , _onTrack( l._onTrack )
104 , _onWire( l._onWire )
105 , _position( l._position )
106 , _positionD( l._positionD )
108 , _leftRight( l._leftRight )
111 , _distance( l._distance )
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];
131void TMLink::dump(
const std::string& msg,
const std::string& pre )
const {
133 if ( _track ) std::cout <<
"track#=,";
134 if ( _hit ) { _hit->dump( msg ); }
140 unsigned n = list.length();
141 for (
unsigned i = 0; i <
n; i++ )
143 unsigned id = list[i]->wire()->layerId();
144 if (
id < 32 ) l0 |= ( 1 << id );
145 else l1 |= ( 1 << (
id - 32 ) );
149 for (
unsigned i = 0; i < 32; i++ )
151 if ( l0 & ( 1 << i ) ) ++l;
152 if ( l1 & ( 1 << i ) ) ++l;
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()];
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()];
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 );
181 unsigned n = tmp.length();
182 unsigned nForFit = 0;
186 for (
unsigned i = 0; i <
MCC_MAX; i++ )
191 bool MCCOverFlow =
false;
194 for (
unsigned i = 0; i <
n; i++ )
196 const TMLink& l = *tmp[i];
204 if ( pull ) { std::cout <<
"[" << a <<
"]"; }
207 std::cout <<
"(" << mcId <<
")";
216 else { MCCOverFlow =
true; }
228 if ( stereo ) { std::cout <<
"{" << l.
leftRight() <<
"," << l.
zStatus() <<
"}"; }
229 if ( pos ) { std::cout <<
",pos=" << l.
position(); }
232 std::cout <<
" " <<
n <<
" l(s)";
233 if (
flag ) std::cout <<
", fv " << nForFit <<
" l(s)";
238 for (
unsigned i = 0; i <
MCC_MAX; i++ )
243 std::cout << i <<
":" << MCC0[i] <<
",";
246 std::cout <<
" total " << nMC <<
" contributions";
250 std::cout <<
", fv mc";
251 for (
unsigned i = 0; i <
MCC_MAX; i++ )
256 std::cout << i <<
":" << MCC1[i] <<
",";
259 std::cout <<
" total " << nMC <<
" contributions";
262 if ( MCCOverFlow ) std::cout <<
"(counter overflow)";
264 std::cout << std::endl;
267void Dump(
const TMLink& link,
const std::string& msg,
const std::string& pre ) {
270 Dump( tmp, msg, pre );
274 unsigned nLinks = links.length();
276 for (
unsigned i = 0; i < nLinks; i++ )
277 if ( links[i]->wire()->stereo() ) ++
n;
282 unsigned nLinks = links.length();
284 for (
unsigned i = 0; i < nLinks; i++ )
285 if ( links[i]->wire()->axial() ) ++
n;
291 unsigned n = links.length();
292 for (
unsigned i = 0; i <
n; i++ )
294 if ( links[i]->wire()->axial() ) a.append( links[i] );
301 unsigned n = links.length();
302 for (
unsigned i = 0; i <
n; i++ )
304 if ( !links[i]->wire()->axial() ) a.append( links[i] );
310 unsigned n = a.length();
311 unsigned minId = 9999;
313 for (
unsigned i = 0; i <
n; i++ )
315 unsigned id = a[i]->wire()->id();
326 unsigned n = a.length();
329 for (
unsigned i = 0; i <
n; i++ )
331 unsigned id = a[i]->wire()->id();
343 unsigned n = input.length();
344 for (
unsigned i = 0; i <
n; i++ )
349 else nonCores.append(
t );
355 unsigned n = input.length();
356 for (
unsigned i = 0; i <
n; i++ )
365#if defined( __GNUG__ )
367 if ( ( *a )->wire()->id() > ( *b )->wire()->id() )
return 1;
368 else if ( ( *a )->wire()->id() == ( *b )->wire()->id() )
return 0;
373 if ( ( *a )->position().x() > ( *b )->position().x() )
return 1;
374 else if ( ( *a )->position().x() == ( *b )->position().x() )
return 0;
382 if ( ( *a )->wire()->id() > ( *b )->wire()->id() )
return 1;
383 else if ( ( *a )->wire()->id() == ( *b )->wire()->id() )
return 0;
387extern "C" int SortByX(
const void* av,
const void* bv ) {
390 if ( ( *a )->position().x() > ( *b )->position().x() )
return 1;
391 else if ( ( *a )->position().x() == ( *b )->position().x() )
return 0;
398 unsigned n = list.length();
399 if (
n < 2 )
return n;
402 unsigned nWires =
w->layer()->nWires();
403 unsigned center =
w->localId();
405#ifdef TRKRECO_DEBUG_DETAIL
406 unsigned sId =
w->superLayerId();
411 for (
unsigned i = 1; i <
n; i++ )
414 unsigned id =
w->localId();
416 unsigned distance0, distance1;
419 distance0 =
id - center;
420 distance1 = nWires - distance0;
424 distance1 = center - id;
425 distance0 = nWires - distance1;
428 if ( distance0 < distance1 )
430 if ( distance0 > right ) right = distance0;
434 if ( distance1 > left ) left = distance1;
437#ifdef TRKRECO_DEBUG_DETAIL
438 if (
w->superLayerId() != sId )
439 std::cout <<
"::width !!! super layer assumption violation" << std::endl;
443 return right + left + 1;
449 unsigned n = list.length();
450 if (
n < 2 )
return a;
451 else if (
n == 2 )
return list;
454 unsigned nWires =
w->layer()->nWires();
455 unsigned center =
w->localId();
461 for (
unsigned i = 1; i <
n; i++ )
464 unsigned id =
w->localId();
466 unsigned distance0, distance1;
469 distance0 =
id - center;
470 distance1 = nWires - distance0;
474 distance1 = center - id;
475 distance0 = nWires - distance1;
478 if ( distance0 < distance1 )
480 if ( distance0 > right )
488 if ( distance1 > left )
504 unsigned n = list.length();
505 for (
unsigned i = 0; i <
n; i++ )
507 if ( list[i]->wire()->layerId() ==
id ) same.append( list[i] );
515 unsigned n = list.length();
516 for (
unsigned i = 0; i <
n; i++ )
518 if ( list[i]->wire()->superLayerId() ==
id ) same.append( list[i] );
525 unsigned n = list.length();
526 for (
unsigned i = 0; i <
n; i++ )
528 if ( list[i]->wire()->layerId() ==
id ) same.append( list[i] );
535 unsigned n = list.length();
536 for (
unsigned i = 0; i <
n; i++ )
538 if ( list[i]->wire()->superLayerId() ==
id ) same.append( list[i] );
546 unsigned n = list.length();
547 unsigned innerMostLayer = 999;
548 unsigned outerMostLayer = 0;
549 for (
unsigned i = 0; i <
n; i++ )
551 unsigned id = list[i]->wire()->layerId();
552 if (
id < innerMostLayer ) innerMostLayer = id;
553 else if (
id > outerMostLayer ) outerMostLayer = id;
555 for (
unsigned i = 0; i <
n; i++ )
557 unsigned id = list[i]->wire()->layerId();
558 if (
id == innerMostLayer ) inners.append( list[i] );
559 else if (
id == outerMostLayer ) outers.append( list[i] );
561 inners.append( outers );
567 unsigned n = list.length();
568 for (
unsigned i = 0; i <
n; i++ ) sl |= ( 1 << ( list[i]->wire()->superLayerId() ) );
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()];
577 for (
unsigned i = 0; i < 11; i++ )
578 if ( nHits[i] >= minN ) sl |= ( 1 << i );
584 unsigned n = list.length();
585 for (
unsigned i = 0; i <
n; i++ )
587 unsigned id = list[i]->wire()->superLayerId();
592 for (
unsigned i = 0; i < 11; i++ )
594 if ( l0 & ( 1 << i ) ) ++l;
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()];
604 for (
unsigned i = 0; i < 11; i++ )
605 if ( nHits[i] >= minN ) ++sl;
610 unsigned n = links.length();
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];
616 while ( nHits[j] == 0 ) ++j;
617 unsigned nMissing = 0;
619 for (
unsigned i = j; i < 5; i++ )
621 if ( nHits[i] == 0 ) ++nMissing;
624 if ( nMax < nMissing ) nMax = nMissing;
634 unsigned nHep = list.length();
636 if ( !nHep )
return *best;
638 unsigned* N = (
unsigned*)malloc( nHep *
sizeof(
unsigned ) );
639 for (
unsigned i = 0; i < nHep; i++ ) N[i] = 0;
641 for (
unsigned i = 0; i < links.length(); i++ )
643 const TMLink& l = *links[i];
645 for (
unsigned j = 0; j < nHep; j++ )
646 if ( list[j] == &hep ) ++N[j];
650 for (
unsigned i = 0; i < nHep; i++ )
#define WireHitFindingValid
#define WireHitFittingValid
#define WireHitInvalidForFit
int SortByWireId(const void *a, const void *b)
Sorter.
HepGeom::Point3D< double > HepPoint3D
AList< TMLink > StereoHits(const AList< TMLink > &links)
returns stereo hits.
unsigned Width(const AList< TMLink > &list)
AList< TMLink > InOut(const AList< TMLink > &list)
AList< TMLink > SameSuperLayer(const AList< TMLink > &list, const TMLink &a)
returns links which are in the same super layer as 'a' or 'id'.
unsigned NAxialHits(const AList< TMLink > &links)
returns # of axial hits.
int SortByX(const void *av, const void *bv)
AList< TMLink > Edges(const AList< TMLink > &list)
unsigned SuperLayer(const AList< TMLink > &list)
returns super layer pattern.
const TTrackHEP & Links2HEP(const AList< TMLink > &links)
returns TTrackHEP
TMLink * OuterMost(const AList< TMLink > &a)
int SortByWireId(const void *av, const void *bv)
Sorter.
AList< TMLink > AxialHits(const AList< TMLink > &links)
returns axial hits.
TMLink * InnerMost(const AList< TMLink > &a)
returns the inner(outer)-most link.
void NHitsSuperLayer(const AList< TMLink > &links, unsigned nHits[11])
returns # of hits per super layer.
unsigned NSuperLayers(const AList< TMLink > &list)
returns # of layers.
AList< TMLink > Cores(const AList< TMLink > &input)
unsigned NLayers(const AList< TMLink > &list)
returns # of layers.
unsigned NStereoHits(const AList< TMLink > &links)
returns # of stereo hits.
AList< TMLink > SameLayer(const AList< TMLink > &list, const TMLink &a)
returns links which are in the same layer as 'a' or 'id'.
unsigned NMissingAxialSuperLayers(const AList< TMLink > &links)
void NHits(const AList< TMLink > &links, unsigned nHits[43])
void Dump(const CAList< TMLink > &links, const std::string &msg, const std::string &pre)
dumps TMLinks.
void SeparateCores(const AList< TMLink > &input, AList< TMLink > &cores, AList< TMLink > &nonCores)
separate cores and non-cores.
const TTrackHEP *const hep(void) const
returns a pointer to a GEN_HEPEVT.
unsigned state(void) const
returns state.
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.
A class to represent a wire in MDC.
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 relate TMDCWireHit and TTrack objects.
virtual ~TMLink()
Destructor.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
const HepPoint3D & xyPosition(void) const
returns middle position of a wire. z componet is 0.
unsigned leftRight(void) const
returns left-right. 0:left, 1:right, 2:wire
int zStatus(void) const
returns stauts of stereo hit
const TMDCWireHit * hit(void) const
returns a pointer to a hit.
double pull(void) const
returns pull.
const HepPoint3D & position(void) const
returns position.
const TMDCWire *const wire(void) const
returns a pointer to a wire.
TMLink(TTrack *track=0, const TMDCWireHit *hit=0, const HepPoint3D &position=HepPoint3D(), const HepPoint3D &positionD=HepPoint3D(), const double=0.0)
Constructor.
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.
A class to represent a track in tracking.