13#include "TrkReco/TSegment0.h"
14#include "TrkReco/TMDCUtil.h"
15#include "TrkReco/TMDCWire.h"
16#include "TrkReco/TMDCWireHit.h"
17#include "TrkReco/TMLink.h"
18#include "TrkReco/TTrack.h"
20#include "TrkReco/Range.h"
52 if ( msg ==
"" ) def =
true;
54 if ( def || msg.find(
"cluster" ) != std::string::npos ||
55 msg.find(
"detail" ) != std::string::npos )
58 std::cout <<
"#links=" <<
_links.length();
59 std::cout <<
"(" << _innerWidth <<
"," << _outerWidth <<
":";
60 std::cout <<
clusterType() <<
")," << _nDual <<
"," << _duality <<
",";
61 std::cout << _angle << std::endl;
63 if ( def || msg.find(
"vector" ) != std::string::npos ||
64 msg.find(
"detail" ) != std::string::npos )
67 std::cout <<
"pos" << _position <<
","
68 <<
"dir" << _direction;
69 std::cout << std::endl;
81 if (
_links.length() == 0 )
return;
83 _innerMostLayer =
_links[0]->wire()->layerId();
84 _outerMostLayer = _innerMostLayer;
85 for (
unsigned i = 1; i <
_links.length(); i++ )
87 unsigned id =
_links[i]->wire()->layerId();
88 if (
id < _innerMostLayer ) _innerMostLayer = id;
89 else if (
id > _outerMostLayer ) _outerMostLayer = id;
91 _nLayer = _outerMostLayer - _innerMostLayer + 1;
93 double centerX =
_links[0]->position().x();
98 for (
unsigned i = 0; i <
_links.length(); i++ )
101 double diff = tmp.x() - centerX;
102 if ( diff >
M_PI ) { tmp.setX( centerX - 2. *
M_PI + diff ); }
103 else if ( diff < -
M_PI ) { tmp.setX( centerX + 2. *
M_PI + diff ); }
107 unsigned id =
_links[i]->wire()->layerId();
108 if (
id == _innerMostLayer )
112 _inners.append(
_links[i] );
114 if (
id == _outerMostLayer )
118 _outers.append(
_links[i] );
121 _innerWidth =
Width( _inners );
122 _outerWidth =
Width( _outers );
123 _position *= ( 1. / (float)
_links.length() );
125 inner *= ( 1. / (float)nInner );
126 outer *= ( 1. / (float)nOuter );
127 _direction = ( inner - outer ).
unit();
134 if ( dir.x() >
M_PI ) dir.setX( dir.x() - 2. *
M_PI );
135 else if ( dir.x() < -
M_PI ) dir.setX( 2. *
M_PI + dir.x() );
137 float radial = fabs( _direction.dot( dir ) );
138 float radial2 = radial * radial;
140 return ( dir.mag2() - radial2 ) > 0.0 ? sqrt( dir.mag2() - radial2 ) : 0.;
145 if ( dir.x() >
M_PI ) dir.setX( dir.x() - 2. *
M_PI );
146 else if ( dir.x() < -
M_PI ) dir.setX( 2. *
M_PI + dir.x() );
148 float radial = fabs(
v.unit().dot( dir ) );
149 float radial2 = radial * radial;
151 return ( dir.mag2() - radial2 ) > 0.0 ? sqrt( dir.mag2() - radial2 ) : 0.;
155#ifdef TRKRECO_DEBUG_DETAIL
158 std::cout <<
"TSegment0::range !!! bad arguments:min,max=";
159 std::cout <<
min <<
"," <<
max << std::endl;
164 if (
n == 0 )
return Range( 0., 0. );
169 for (
unsigned i = 0; i <
n; i++ )
171 double x =
_links[i]->position().x();
177 if ( !found )
return Range( 0., 0. );
179#ifdef TRKRECO_DEBUG_DETAIL
183 double distanceR = 0.;
184 double distanceL = 0.;
185 double distanceMax =
max -
min;
186 for (
unsigned i = 0; i <
n; i++ )
188 double x =
_links[i]->position().x();
191 double distance0, distance1;
194 distance0 = x - center;
195 distance1 = distanceMax - distance0;
199 distance1 = center - x;
200 distance0 = distanceMax - distance1;
203 if ( distance0 < distance1 )
205 if ( distance0 > distanceR ) distanceR = distance0;
209 if ( distance1 > distanceL ) distanceL = distance1;
212#ifdef TRKRECO_DEBUG_DETAIL
223 double right = center + distanceR;
224 double left = center - distanceL;
226 return Range( left, right );
229void TSegment0::updateType(
void )
const {
241 if ( ( _innerWidth < fat ) && ( _outerWidth < fat ) )
246 if ( _nLayer > tall ) _clusterType = 2;
251 else if ( _outerWidth < fat )
258 else if ( _innerWidth < fat )
268 for (
unsigned i = _innerMostLayer; i <= _outerMostLayer; i++ )
272 for (
unsigned j = 0; j <
_links.length(); j++ )
273 if (
_links[j]->wire()->layerId() == i )
287 if ( space ) _clusterType = 6;
297#ifdef TRKRECO_DEBUG_DETAIL
298 std::cout <<
" ... splitting : type=" <<
t << std::endl;
300 if (
t == 0 )
return list;
305 if ( _nDual > 2 && _duality > 0.7 )
return splitDual();
308 else if (
t == 1 )
return list;
309 else if (
t == 7 )
return list;
312 else if (
t == 6 )
return splitParallel();
315 else if (
t > 4 )
return splitComplicated();
327 if (
t == 3 ) corners = &_outers;
328 else corners = &_inners;
330 for (
unsigned i = 0; i < corners->length(); i++ )
331 corner += ( *corners )[i]->wire()->xyPosition();
332 corner *= 1. / (float)corners->length();
333 seeds[0].append( *corners );
334 seeds[1].append( *corners );
338 if (
t == 3 )
links = &_inners;
339 else links = &_outers;
343 for (
unsigned i = 0; i < 2; i++ )
345 edgePos[i] = edge[i]->wire()->xyPosition();
346 v[i] = ( edgePos[i] - corner ).
unit();
348 seeds[0].append( edge[0] );
349 seeds[1].append( edge[1] );
351#ifdef TRKRECO_DEBUG_DETAIL
352 std::cout <<
" corner:" << corner << std::endl;
353 std::cout <<
" edge:" << edgePos[0] <<
"(";
354 std::cout << edge[0]->wire()->layerId() <<
"-";
355 std::cout << edge[0]->wire()->localId() <<
")";
356 std::cout <<
v[0] << std::endl;
358 std::cout << edgePos[1] <<
"(";
359 std::cout << edge[1]->wire()->layerId() <<
"-";
360 std::cout << edge[1]->wire()->localId() <<
")";
361 std::cout <<
v[1] << std::endl;
366 for (
unsigned i = 0; i <
n; i++ )
369 if ( edge.member( l ) )
continue;
370 if ( corners->member( l ) )
continue;
373 double p2 = p.mag2();
376 for (
unsigned j = 0; j < 2; j++ )
378 dist[j] =
v[j].dot( p );
379 double d2 = dist[j] * dist[j];
380 dist[j] = (
p2 - d2 ) > 0. ? sqrt(
p2 - d2 ) : 0.;
382 if ( dist[0] < dist[1] ) seeds[0].append( l );
383 else seeds[1].append( l );
385#ifdef TRKRECO_DEBUG_DETAIL
386 std::cout <<
" p:" << p << std::endl;
388 std::cout << l->
wire()->
localId() <<
":" << dist[0];
389 std::cout <<
"," << dist[1] << std::endl;
393 AList<TSegment0> list;
394 for (
unsigned i = 0; i < 2; i++ )
396 if ( seeds[i].length() )
399 AList<TSegment0> ncx = nc->
split();
400 if ( ncx.length() == 0 )
418 AList<TSegment0> newClusters;
419 AList<TMLink> goodHits;
421 for (
unsigned i = 0; i <
n; i++ )
423 const TMDCWireHit* h =
_links[i]->hit();
424 unsigned state = h->
state();
429 goodHits.append(
_links[i] );
431 if ( goodHits.length() == 0 )
return newClusters;
435 AList<TMLink> original(
_links );
436 while ( goodHits.length() )
440 TMLink* seed = goodHits.last();
441 const TMDCWire* wire = seed->
wire();
442 unsigned localId = wire->
localId();
444 unsigned nn =
_links.length();
445 for (
unsigned i = 0; i < nn; i++ )
448 const TMDCWire*
w =
t->wire();
451 if (
abs( (
int)
w->localId() - (
int)localId ) < 2 ) used.append(
t );
454#ifdef TRKRECO_DEBUG_DETAIL
455 std::cout <<
" seed is " << seed->
wire()->
name() << std::endl;
457 for (
unsigned i = 0; i < used.length(); i++ )
458 { std::cout << used[i]->wire()->name() <<
","; }
459 std::cout << std::endl;
463 if ( used.length() == 0 )
continue;
464 if ( used.length() ==
nLinks() )
return newClusters;
466 AList<TSegment0> cx = c->
split();
467 if ( cx.length() == 0 )
470 newClusters.append( c );
474 newClusters.append( cx );
477 goodHits.remove( used );
478 original.remove( used );
482 if ( ( original.length() ) && ( original.length() <
nLinks() ) )
485 AList<TSegment0> cx = c->
split();
486 if ( cx.length() == 0 )
489 newClusters.append( c );
493 newClusters.append( cx );
502 AList<TMLink> seeds[2];
503 AList<TSegment0> newClusters;
504 for (
unsigned i = _innerMostLayer; i <= _outerMostLayer; i++ )
507 AList<TMLink> outerList =
Edges( list );
509#ifdef TRKRECO_DEBUG_DETAIL
510 if ( outerList.length() != 2 )
512 std::cout <<
"TSegment0::splitParallel !!! ";
513 std::cout <<
"This is not a parallel cluster" << std::endl;
517 seeds[0].append( outerList[0] );
518 seeds[1].append( outerList[1] );
519 if ( list.length() == 2 )
continue;
521 const TMDCWire& wire0 = *outerList[0]->wire();
522 const TMDCWire& wire1 = *outerList[1]->wire();
523 for (
unsigned k = 0; k < list.length(); k++ )
526 if (
t == outerList[0] )
continue;
527 if (
t == outerList[1] )
continue;
531 seeds[0].append(
t );
532 else seeds[1].append(
t );
536 if ( ( seeds[0].length() ) && ( seeds[0].length() <
nLinks() ) )
539 AList<TSegment0> c0x = c0->
split();
542 newClusters.append( c0x );
548 newClusters.append( c0 );
552 if ( ( seeds[1].length() ) && ( seeds[1].length() <
nLinks() ) )
555 AList<TSegment0> c1x = c1->
split();
558 newClusters.append( c1x );
564 newClusters.append( c1 );
571void TSegment0::updateDuality(
void )
const {
575 for (
unsigned i = _innerMostLayer; i <= _outerMostLayer; i++ )
578 if ( i == _innerMostLayer )
580 for (
unsigned j = 0; j < list.length(); j++ )
x[0] += list[j]->hit()->xyPosition();
581 x[0] *= 1. / double( list.length() );
583 else if ( i == _outerMostLayer )
585 for (
unsigned j = 0; j < list.length(); j++ )
x[1] += list[j]->hit()->xyPosition();
586 x[1] *= 1. / double( list.length() );
589 if ( list.length() == 2 )
591 if (
Width( list ) != 2 )
continue;
592 const TMDCWireHit* h0 = list[0]->hit();
593 const TMDCWireHit* h1 = list[1]->hit();
601 if ( _nDual > 0 ) _duality /= float( _nDual );
602 _angle = (
x[1] -
x[0] ).
unit().dot(
x[0].
unit() );
606#ifdef TRKRECO_DEBUG_DETAIL
607 std::cout <<
" TSegment0::splitDual called" << std::endl;
609 AList<TMLink> seeds[2];
610 AList<TMLink> unknown;
611 for (
unsigned i = _innerMostLayer; i <= _outerMostLayer; i++ )
615 if ( list.length() == 2 )
617 if (
Width( list ) == 2 )
619 seeds[0].append( list[0] );
620 seeds[1].append( list[1] );
624 unknown.append( list );
627 if ( unknown.length() > 0 )
629#ifdef TRKRECO_DEBUG_DETAIL
630 if ( seeds[0].length() == 0 )
631 std::cout <<
"TSegment0::splitDual !!! no TMLink for seed 0" << std::endl;
632 if ( seeds[1].length() == 0 )
633 std::cout <<
"TSegment0::splitDual !!! no TMLink for seed 1" << std::endl;
635 const HepPoint3D& p0 = seeds[0][0]->xyPosition();
637 HepVector3D v0 = ( seeds[0].last()->xyPosition() - p0 ).unit();
638 HepVector3D v1 = ( seeds[1].last()->xyPosition() -
p1 ).unit();
640 for (
unsigned i = 0; i < unknown.length(); i++ )
642 TMLink*
t = unknown[i];
644 double d0 = ( x0 - ( x0.dot( v0 ) * v0 ) ).mag();
646 double d1 = ( x1 - ( x1.dot( v0 ) * v0 ) ).mag();
648 if ( d0 < d1 ) seeds[0].append(
t );
649 else seeds[1].append(
t );
653 AList<TSegment0> newClusters;
654 newClusters.append(
new TSegment0( seeds[0] ) );
655 newClusters.append(
new TSegment0( seeds[1] ) );
661 if ( _clusterType == 0 )
return 0;
662 if ( _nDual == 0 )
return 0;
666 for (
unsigned i = _innerMostLayer; i <= _outerMostLayer; i++ )
670 if ( list.length() == 1 ) { seeds.append( list[0] ); }
671 else if ( list.length() == 2 )
673 if (
Width( list ) > 1 )
679 if (
distance > 0.5 ) duals.append( list );
680#ifdef TRKRECO_DEBUG_DETAIL
688 else if ( list.length() == 0 ) {
continue; }
689#ifdef TRKRECO_DEBUG_DETAIL
692 std::cout <<
"TSegment0::solveDualHits !!! this is not expected 2";
693 std::cout << std::endl;
694 this->
dump(
"cluster hits mc",
" " );
700 if ( seeds.length() < 2 )
return -1;
702 const HepPoint3D& p = outers[0]->xyPosition();
704 unsigned n = duals.length() / 2;
705 for (
unsigned i = 0; i <
n; i++ )
707 TMLink* t0 = duals[i * 2 + 0];
708 TMLink* t1 = duals[i * 2 + 1];
711 double d0 = ( x0 - ( x0.dot(
v ) *
v ) ).mag();
712 double d1 = ( x1 - ( x1.dot(
v ) *
v ) ).mag();
713 if ( d0 < d1 )
_links.remove( t1 );
831 unsigned nList = list.length();
832 for (
unsigned i = 0; i < nList; i++ )
835 for (
unsigned j = 0; j < links.length(); j++ )
837 unsigned state = links[j]->hit()->state();
849 unsigned n = links.length();
850 for (
unsigned i = 0; i <
n; i++ )
852 if ( trackLinks.hasMember( links[i] ) ) a.append( links[i] );
HepGeom::Vector3D< double > HepVector3D
HepGeom::Point3D< double > HepPoint3D
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per saves r n generator level $ !Flag for chat level in !Latex Output unit
const HepPoint3D ORIGIN
Constants.
#define WireHitContinuous
#define WireHitPatternLeft
#define WireHitPatternRight
AList< TMLink > Edges(const AList< TMLink > &)
unsigned Width(const AList< TMLink > &)
AList< TMLink > InOut(const AList< TMLink > &)
AList< TMLink > SameLayer(const AList< TMLink > &list, const TMLink &a)
returns links which are in the same layer as 'a' or 'id'.
int SortByWireId(const void *a, const void *b)
Sorter.
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
HepGeom::Point3D< double > HepPoint3D
HepGeom::Vector3D< double > HepVector3D
unsigned NCoreLinks(const CAList< TSegment0 > &list)
returns # of core links in segments.
AList< TMLink > Links(const TSegment0 &s, const TTrack &t)
returns AList of TMLink used for a track.
to specify 1-dim region or range by two floats
unsigned state(void) const
returns state.
float drift(unsigned) const
returns drift distance.
const HepPoint3D & xyPosition(void) const
returns drift time
unsigned localId(void) const
returns local id in a wire layer.
unsigned layerId(void) const
returns layer id.
const HepPoint3D & xyPosition(void) const
returns middle position of a wire. z componet is 0.
int localIdDifference(const TMDCWire &) const
returns local id difference.
std::string name(void) const
returns name.
A class to relate TMDCWireHit and TTrack objects.
const HepPoint3D & xyPosition(void) const
returns middle position of a wire. z componet is 0.
const TMDCWire *const wire(void) const
returns a pointer to a wire.
A class to relate TMDCWireHit and TTrack objects.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
double distance(const TSegment0 &) const
calculates distance between two clusters. Smaller value indicates closer.
Range rangeX(double min, double max) const
returns Range of x-coordinate of TMLinks.
AList< TSegment0 > split(void) const
virtual ~TSegment0()
Destructor.
const HepPoint3D & position(void) const
returns position.
unsigned clusterType(void) const
virtual void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
const AList< TMLink > & links(unsigned mask=0) const
unsigned nLinks(unsigned mask=0) const
returns # of masked TMLinks assigned to this track object.
void update(void) const
update cache.
A class to represent a track in tracking.