15#include "TrkReco/TConformalFinder0.h"
16#include "TrkReco/TCircle.h"
17#include "TrkReco/THistogram.h"
18#include "TrkReco/TMDCUtil.h"
19#include "TrkReco/TMDCWire.h"
20#include "TrkReco/TMDCWireHit.h"
21#include "TrkReco/TMDCWireHitMC.h"
22#include "TrkReco/TMLink.h"
23#include "TrkReco/TSegment0.h"
24#include "TrkReco/TTrack.h"
26#include "TrkReco/Range.h"
31 float stereoZ4,
float stereoChisq3,
float stereoChisq4,
32 float stereoMaxSigma,
unsigned fittingCorrections,
33 float salvageLevel,
bool cosmic )
39 _fraction( fraction ) {
42 _trackSelector.nLinks( 4 );
43 _trackSelector.nSuperLayers( 2 );
44 _trackSelector.minPt( 0.05 );
45 _trackSelector.maxImpact( 100. );
46 _trackSelector.maxSigma( maxSigma );
47 _trackSelector.nLinksStereo( 3 );
48 _trackSelector.maxDistance( 30. );
51 if ( cosmic ) _builder =
new TBuilderCosmic(
"cosmic builder", salvageLevel );
53 _builder =
new TBuilder0(
"conformal builder", stereoZ3, stereoZ4, stereoChisq3,
54 stereoChisq4, stereoMaxSigma, fittingCorrections, salvageLevel );
57 _builder->trackSelector( _trackSelector );
66 if ( msg.find(
"state" ) != std::string::npos )
68 std::cout <<
"#axialConfPos=" << _axialConfLinks.length();
69 std::cout <<
",#stereoConfPos=" << _stereoConfLinks.length();
74 HepAListDeleteAll( _axialConfLinks );
75 HepAListDeleteAll( _stereoConfLinks );
76 _unusedAxialConfLinks.removeAll();
77 _unusedStereoConfLinks.removeAll();
78 _goodAxialConfLinks.removeAll();
79 HepAListDeleteAll( _circles );
87 unsigned nHits = hits.length();
90 for (
unsigned i = 0; i < nHits; i++ )
96 HepPoint3D cp( 2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0. );
98 links.append(
new TMLink( 0, h, cp ) );
103 for (
unsigned i = 0; i < nHits; i++ )
107 HepPoint3D cp( 2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0. );
108 links.append(
new TMLink( 0, h, cp ) );
116 unsigned nHits = hits.length();
119 for (
unsigned i = 0; i < nHits; i++ )
124 const double r = 0.5 * ( h->
drift( 0 ) + h->
drift( 1 ) );
125 HepPoint3D cp( 2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0. );
128 HepPoint3D cp2( 2. * p.x() / ( p.mag2() - r * r ), 2. * p.y() / ( p.mag2() - r * r ),
131 double cDrift = 2. * r / ( p.mag2() - r * r );
133 links.append(
new TMLink( 0, h, cp, cp2, cDrift ) );
138 for (
unsigned i = 0; i < nHits; i++ )
143 const double r = 0.5 * ( h->
drift( 0 ) + h->
drift( 1 ) );
144 HepPoint3D cp( 2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0. );
148 HepPoint3D cp2( 2. * p.x() / ( p.mag2() - r * r ), 2. * p.y() / ( p.mag2() - r * r ),
151 double cDrift = 2. * r / ( p.mag2() - r * r );
153 links.append(
new TMLink( 0, h, cp, cp2, cDrift ) );
162 unsigned nHits = hits.length();
165 for (
unsigned i = 0; i < nHits; i++ )
169 HepPoint3D cp( 2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0. );
170 double r = log( cp.mag() ) + 4.;
171 double phi = atan2( cp.y(), cp.x() ) +
M_PI;
173 links.append(
new TMLink( 0, h, cpt ) );
178 for (
unsigned i = 0; i < nHits; i++ )
182 HepPoint3D cp( 2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0. );
183 double r = log( cp.mag() ) + 4.;
184 double phi = atan2( cp.y(), cp.x() ) +
M_PI;
186 links.append(
new TMLink( 0, h, cpt ) );
195 unsigned n = list.length();
196 if (
n == 0 )
return list;
198#ifdef TRKRECO_DEBUG_DETAIL
206 for (
unsigned i = 0; i <
n; i++ )
211 if ( newClusters.length() == 0 )
217 list.append( newClusters );
218 splitted.append( c );
219#ifdef TRKRECO_DEBUG_DETAIL
220 c->
dump(
"hits",
" " );
221 std::cout <<
" ... splitted as" << std::endl;
222 for (
unsigned j = 0; j < newClusters.length(); j++ )
224 std::cout <<
" " << j <<
" : ";
225 newClusters[j]->dump(
"hits" );
229 list.remove( splitted );
230 HepAListDeleteAll( splitted );
232#ifdef TRKRECO_DEBUG_DETAIL
245 unsigned n = list.length();
246 if (
n == 0 )
return list;
248#ifdef TRKRECO_DEBUG_DETAIL
255 for (
unsigned i = 0; i <
n; i++ )
260 if ( (
type == 1 ) || (
type == 2 ) )
262 c->
dump(
"hits mc",
" " );
267#ifdef TRKRECO_DEBUG_DETAIL
277 const TTrack& track )
const {
284 if ( track.
links().length() == 0 )
286#ifdef TRKRECO_DEBUG_DETAIL
287 std::cout <<
"TConformalFinder0::findCloseHits !!! ";
288 std::cout <<
" no links found in a track : This should not be happened";
289 std::cout << std::endl;
298 float dRcut[11] = { 4.3, 6.5, 0., 0., 0., 7.5, 8.0, 9.5, 11.0, 0., 0. };
302 double xInnerWire = track.
links()[0]->wire()->xyPosition().x();
303 double yInnerWire = track.
links()[0]->wire()->xyPosition().y();
304 unsigned nall = links.length();
305 for (
unsigned j = 0; j < nall; j++ )
307 TMLink&
t = *links[j];
308 const TMDCWire&
w = *
t.wire();
310 double Rmag2 = X.mag2();
311 double DR = fabs( sqrt( Rmag2 ) - fabs( R0 ) );
314 if ( DR < dRcut[
w.superLayerId()] &&
315 ( xInnerWire *
w.xyPosition().x() + yInnerWire *
w.xyPosition().y() ) > 0. )
316 { list.append(
t ); }
326 double minAngle = 0.80;
327 double maxDistance = 0.3;
332 unsigned n = candidates.length();
333 double minDistance = 999.;
334 TSegment0* best = NULL;
335 for (
unsigned j = 0; j <
n; j++ )
337 TSegment0* current = candidates[j];
338 if ( current->
nLinks() < 2 )
continue;
341#ifdef TRKRECO_DEBUG_DETAIL
342 current->
dump(
"vector hits mc",
" " );
343 std::cout <<
" angle=" << angle;
344 if ( angle < minAngle ) std::cout << std::endl;
349 if ( angle < minAngle )
continue;
351 float distance = base.
distance( *current );
352 if ( distance < minDistance )
354 minDistance = distance;
357#ifdef TRKRECO_DEBUG_DETAIL
358 std::cout <<
",dist=" << distance << std::endl;
370 unsigned n = list.length();
371 TSegment0* best = NULL;
373 for (
unsigned j = 0; j <
n; j++ )
375 TSegment0* c = list[j];
377 unsigned nOk =
t.testByApproach( c->
links(), _trackSelector.maxSigma() );
388#ifdef TRKRECO_DEBUG_DETAIL
389 std::cout <<
" ... appending a cluster" << std::endl;
390 best->
dump(
"hits mc",
" " );
392 AList<TMLink> links( best->
links() );
393 t.appendByApproach( links, _trackSelector.maxSigma() );
401TConformalFinder0::findClusterLink(
TSegment0& base,
404#ifdef TRKRECO_DEBUG_DETAIL
405 std::cout <<
name() <<
" ... finding cluster linkage" << std::endl;
406 if ( base.
links().length() == 0 )
407 std::cout <<
name() <<
" !!! base doesn't have any TMLink." << std::endl;
408 std::cout <<
"... base cluster" << std::endl;
409 base.
dump(
"cluster hits mc",
" ->" );
413 AList<TSegment0> seeds;
414 seeds.append( base );
418 unsigned outerMost = ( base.
links() )[0]->wire()->axialStereoLayerId() / 4;
421 int next = outerMost;
422 TSegment0* last = &base;
426 const AList<TSegment0>& candidates = list[
next];
427 if ( candidates.length() == 0 )
continue;
429#ifdef TRKRECO_DEBUG_DETAIL
430 std::cout <<
"... clusters in super layer " <<
next << std::endl;
434 TSegment0* best = findBestLink( *last, candidates );
437 seeds.append( best );
439#ifdef TRKRECO_DEBUG_DETAIL
440 std::cout <<
" ->Best is ";
441 std::cout << best->
position() <<
" ";
442 best->
dump(
"hits mc" );
452 for (
unsigned i = 0; i < list.length(); i++ )
454 const AList<TMLink>& tmp = list[i]->links();
455 unsigned n = tmp.length();
456 for (
unsigned j = 0; j <
n; j++ )
458 if ( tmp[j]->hit()->track() )
continue;
459 links.append( tmp[j] );
463 TTrack*
t = _builder->buildRphi( links );
470 double maxDistance )
const {
475 int rotation = ( center.cross( track.
links()[0]->xyPosition() ).z() > 0. ) ? 1 : -1;
477#ifdef TRKRECO_DEBUG_DETAIL
478 std::cout <<
name() <<
" ... finding close clusters:maxDistance=";
479 std::cout << maxDistance << std::endl;
480 std::cout <<
" radius,center,rotation=" << radius <<
",";
481 std::cout << center <<
"," << rotation << std::endl;
485 AList<TSegment0> close;
486 unsigned n = list.length();
487 for (
unsigned i = 0; i <
n; i++ )
489 TSegment0& c = *list[i];
493 unsigned m = c.
links().length();
494 for (
unsigned j = 0; j < m; j++ ) { position += c.
links()[j]->xyPosition(); }
495 position *= 1. / double( m );
497#ifdef TRKRECO_DEBUG_DETAIL
498 c.
dump(
"cluster hits mc",
" " );
499 std::cout <<
" position=" << position;
500 std::cout <<
",diff=" << ( position - center ).mag() - radius << std::endl;
504 if ( ( diff.mag() - radius ) < maxDistance )
508 int direction = ( center.cross( position ).z() > 0. ) ? 1 : -1;
509 if ( direction == rotation ) close.append( c );
513#ifdef TRKRECO_DEBUG_DETAIL
514 std::cout <<
" found clusters" << std::endl;
515 for (
unsigned i = 0; i < close.length(); i++ ) { close[i]->dump(
"hits mc",
" " ); }
522#ifdef TRKRECO_DEBUG_DETAIL
523 std::cout <<
name() <<
" ... appending clusters remained" << std::endl;
524 std::cout <<
" clusters to be tested : " << std::endl;
525 for (
unsigned i = 0; i < list.length(); i++ )
526 { list[i]->dump(
"cluster hits mc",
" " ); }
529 unsigned n = list.length();
530 if (
n == 0 )
return;
532 AList<TSegment0> closer;
533 closer.append( findCloseClusters( track, list, 1. ) );
535#ifdef TRKRECO_DEBUG_DETAIL
536 std::cout <<
" found clusters" << std::endl;
537 for (
unsigned i = 0; i < closer.length(); i++ )
538 { closer[i]->dump(
"cluster hits mc",
" " ); }
541 if ( closer.length() == 0 )
return;
544 AList<TMLink> candidates;
545 for (
unsigned i = 0; i <
n; i++ ) candidates.append( closer[i]->links() );
546 _builder->appendClusters( track, candidates );
549 for (
unsigned i = 0; i <
n; i++ )
551 closer[i]->TTrackBase::remove( track.
links() );
552 if ( closer[i]->nLinks() == 0 ) list.remove( closer[i] );
563 std::cout <<
name() <<
" ... processing" << std::endl;
564 std::cout <<
" axialHits=" << axialHits.length();
565 std::cout <<
",stereoHits=" << stereoHits.length();
566 std::cout <<
",tracks=" << tracks.length();
567 std::cout << std::endl;
570 std::cout <<
name() <<
" ... conformal transformation0" << std::endl;
576 _unusedAxialConfLinks.append( _axialConfLinks );
577 _unusedStereoConfLinks.append( _stereoConfLinks );
581 unusedConfLinks.append( _axialConfLinks );
582 unusedConfLinks.append( _stereoConfLinks );
586 if (
debugLevel() > 1 ) std::cout <<
name() <<
" ... selecting good hits" << std::endl;
590 int nLinks = _axialConfLinks.length();
591 for (
unsigned i = 0; i < nLinks; i++ )
593 TMLink* l = _axialConfLinks[i];
597 goodHits.append( l );
600 standardFinding( goodHits, unusedConfLinks, _fraction );
603 specialFinding( goodHits, unusedConfLinks, _fraction );
608 std::cout <<
name() <<
" ... processed : ";
609 std::cout <<
"good hits=" << goodHits.length();
610 std::cout <<
",tracks=" << _tracks.length();
611 std::cout << std::endl;
614 tracks.append( _tracks );
620#ifdef TRKRECO_DEBUG_DETAIL
621 std::cout <<
name() <<
" ... standard finding with salvage : given hits :";
622 Dump( list,
"sort" );
629 for (
unsigned i = 0; i < 5; i++ )
631 segmentList[i] = *segments[i];
632 original[i] = *segments[i];
638#ifdef TRKRECO_DEBUG_DETAIL
639 for (
unsigned i = 0; i < 5; i++ )
641 std::cout <<
"... clusters in super layer " << i << std::endl;
642 for (
unsigned j = 0; j < segmentList[i].length(); j++ )
644 segmentList[i][j]->dump(
"",
" " );
645 segmentList[i][j]->dump(
"hits mc",
" " );
651 AList<TSegment0> retryList;
652 AList<TTrack> salvageList;
653 unsigned outerMost = 4;
657 while ( TSegment0* base = segmentList[outerMost][0] )
661 AList<TSegment0> clusters = findClusterLink( *base, segmentList );
664 TTrack*
t = makeTrack( clusters );
667 retryList.append( base );
668 segmentList[outerMost].remove( base );
674 double f = float(
t->nCores() ) / float(
NCoreLinks( clusters ) );
677#ifdef TRKRECO_DEBUG_DETAIL
678 std::cout <<
"... fraction too low:" <<
f << std::endl;
679 std::cout <<
" used cores=" <<
t->nCores();
680 std::cout <<
", candidate cores=" <<
NCoreLinks( clusters );
681 std::cout <<
" ... retry later" << std::endl;
683 retryList.append( base );
684 segmentList[outerMost].remove( base );
690 appendClusters2( *
t, retryList );
692#ifdef TRKRECO_DEBUG_DETAIL
693 std::cout <<
name() <<
" ... 2D result :" << std::endl;
694 t->dump(
"detail",
" " );
700 { ts = _builder->buildStereo( *
t, findCloseHits( _unusedStereoConfLinks, *
t ) ); }
705#ifdef TRKRECO_DEBUG_DETAIL
706 std::cout <<
"... failed to make a track 3D" << std::endl;
708 retryList.append( base );
709 segmentList[outerMost].remove( base );
724 const AList<TMLink>& usedLinks =
t->links();
725 list.remove( usedLinks );
726 unusedLinks.remove( usedLinks );
727 _unusedStereoConfLinks.remove( usedLinks );
728 for (
unsigned i = 0; i <= outerMost; i++ ) segmentList[i].remove( clusters );
733 std::cout <<
name() <<
" ... track # " << _tracks.length() - 1;
734 std::cout <<
" found" << std::endl;
735 t->dump(
"detail",
" " );
744 for (
unsigned i = 0; i < 5; i++ )
746 HepAListDeleteAll( original[i] );
753#ifdef TRKRECO_DEBUG_DETAIL
754 std::cout <<
name() <<
" ... standard finding with salvage : given hits :";
755 Dump( list,
"sort" );
759 AList<AList<TSegment0>> segments =
findSegments( list );
760 AList<TSegment0> segmentList[5];
761 AList<TSegment0> original[5];
762 for (
unsigned i = 0; i < 5; i++ )
764 segmentList[i] = *segments[i];
765 original[i] = *segments[i];
768#ifdef TRKRECO_DEBUG_DETAIL
769 for (
unsigned i = 0; i < 5; i++ )
771 std::cout <<
"... clusters in super layer " << i << std::endl;
772 for (
unsigned j = 0; j < segmentList[i].length(); j++ )
774 segmentList[i][j]->dump(
"",
" " );
775 segmentList[i][j]->dump(
"hits mc",
" " );
781 AList<TSegment0> retryList;
782 unsigned outerMost = 4;
786 while ( TSegment0* base = segmentList[outerMost][0] )
790 AList<TSegment0> clusters = findClusterLink( *base, segmentList );
795 if ( clusters.length() < 2 )
797 segmentList[outerMost].remove( base );
802 TTrack*
t = makeTrack( clusters );
805 clusters.remove( clusters.last() );
811 double f = float(
t->nCores() ) / float(
NCoreLinks( clusters ) );
814#ifdef TRKRECO_DEBUG_DETAIL
815 std::cout <<
"... fraction too low:" <<
f << std::endl;
816 std::cout <<
" retry later" << std::endl;
819 clusters.remove( clusters.last() );
824 appendClusters2( *
t, retryList );
830 { ts = _builder->buildStereo( *
t, findCloseHits( _unusedStereoConfLinks, *
t ) ); }
835 clusters.remove( clusters.last() );
850 const AList<TMLink>& usedLinks =
t->links();
851 list.remove( usedLinks );
852 unusedLinks.remove( usedLinks );
853 _unusedStereoConfLinks.remove( usedLinks );
854 for (
unsigned i = 0; i <= outerMost; i++ ) segmentList[i].remove( clusters );
859 std::cout <<
name() <<
" ... track # " << _tracks.length() - 1;
860 std::cout <<
" found" << std::endl;
861 t->dump(
"detail",
" " );
870 for (
unsigned i = 0; i < 5; i++ )
872 HepAListDeleteAll( original[i] );
880#ifdef TRKRECO_DEBUG_DETAIL
881 std::cout <<
name() <<
" ... finding segments : given hits =" << std::endl;
887 unsigned n = in.length();
888 for (
unsigned i = 0; i <
n; i++ )
902 for (
unsigned i = 0; i < 5; i++ )
904 hist[i]->
fillX( links[i] );
HepGeom::Vector3D< double > HepVector3D
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
const HepPoint3D ORIGIN
Constants.
#define WireHitConformalFinder
void Dump(const CAList< TMLink > &links, const std::string &message=std::string(""), const std::string &prefix=std::string(""))
dumps TMLinks.
unsigned NCoreLinks(const CAList< TSegment > &list)
returns # of core links in segments.
#define TrackOldConformalFinder
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
double radius(void) const
returns radious of helix.
A class to build a track.
A class to build a cosmic track.
virtual int debugLevel(void) const
returns debug level.
virtual void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
TFinderBase()
Constructor.
A class for a histogram used in tracking.
AList< TSegment0 > clusters0(void) const
returns an AList<TSegment0> of clusters.
void fillX(const AList< TMLink > &links)
fills with hits.
float drift(unsigned) const
returns drift distance.
const HepPoint3D & xyPosition(void) const
returns drift time
unsigned axialStereoLayerId(void) const
returns id of axial or stereo id.
A class to relate TMDCWireHit and TTrack objects.
const TMDCWireHit * hit(void) const
returns a pointer to a hit.
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.
AList< TSegment0 > split(void) const
const HepVector3D & direction(void) const
returns direction.
const HepPoint3D & position(void) const
returns position.
unsigned clusterType(void) const
const AList< TMLink > & links(unsigned mask=0) const
unsigned nLinks(unsigned mask=0) const
returns # of masked TMLinks assigned to this track object.
A class to represent a track in tracking.
void assign(unsigned maskForWireHit)
assigns wire hits to this track.
const Helix & helix(void) const
returns helix parameter.