15#include "TrkReco/TMDCUtil.h"
16#include "TrkReco/TMDCWire.h"
17#include "TrkReco/TMDCWireHit.h"
18#include "TrkReco/TMDCWireHitMC.h"
19#include "TrkReco/TConformalFinder0.h"
20#include "TrkReco/TMLink.h"
21#include "TrkReco/THistogram.h"
22#include "TrkReco/TCircle.h"
23#include "TrkReco/TTrack.h"
24#include "TrkReco/TSegment0.h"
26#include "TrkReco/Range.h"
40 unsigned fittingCorrections,
52 _trackSelector.
minPt(0.05);
59 if (cosmic) _builder =
new TBuilderCosmic(
"cosmic builder", salvageLevel);
60 else _builder =
new TBuilder0(
"conformal builder",
82 if (msg.find(
"state") != std::string::npos) {
83 std::cout <<
"#axialConfPos=" << _axialConfLinks.length();
84 std::cout <<
",#stereoConfPos=" << _stereoConfLinks.length();
90 HepAListDeleteAll(_axialConfLinks);
91 HepAListDeleteAll(_stereoConfLinks);
92 _unusedAxialConfLinks.removeAll();
93 _unusedStereoConfLinks.removeAll();
94 _goodAxialConfLinks.removeAll();
95 HepAListDeleteAll(_circles);
104 unsigned nHits = hits.length();
106 for (
unsigned i = 0; i < nHits; i++) {
111 HepPoint3D cp(2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0.);
113 links.append(
new TMLink(0, h, cp));
117 for (
unsigned i = 0; i < nHits; i++) {
120 HepPoint3D cp(2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0.);
121 links.append(
new TMLink(0, h, cp));
130 unsigned nHits = hits.length();
132 for (
unsigned i = 0; i < nHits; i++) {
136 const double r = 0.5*(h->
drift(0) + h->
drift(1));
137 HepPoint3D cp(2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0.);
139 HepPoint3D cp2(2. * p.x() / (p.mag2() - r*r), 2. * p.y() / (p.mag2() - r*r), 0.);
141 double cDrift = 2. * r / (p.mag2() - r*r);
143 links.append(
new TMLink(0, h, cp, cp2, cDrift));
147 for (
unsigned i = 0; i < nHits; i++) {
151 const double r = 0.5*(h->
drift(0) + h->
drift(1));
152 HepPoint3D cp(2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0.);
155 HepPoint3D cp2(2. * p.x() / (p.mag2() - r*r), 2. * p.y() / (p.mag2() - r*r), 0.);
157 double cDrift = 2. * r / (p.mag2() - r*r);
159 links.append(
new TMLink(0, h, cp, cp2, cDrift));
169 unsigned nHits = hits.length();
171 for (
unsigned i = 0; i < nHits; i++) {
174 HepPoint3D cp(2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0.);
175 double r = log(cp.mag()) + 4.;
176 double phi = atan2(cp.y(), cp.x()) +
M_PI;
178 links.append(
new TMLink(0, h, cpt));
182 for (
unsigned i = 0; i < nHits; i++) {
185 HepPoint3D cp(2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0.);
186 double r = log(cp.mag()) + 4.;
187 double phi = atan2(cp.y(), cp.x()) +
M_PI;
189 links.append(
new TMLink(0, h, cpt));
199 unsigned n = list.length();
200 if (
n == 0)
return list;
202#ifdef TRKRECO_DEBUG_DETAIL
210 for (
unsigned i = 0; i <
n; i++) {
214 if (newClusters.length() == 0) {
219 list.append(newClusters);
221#ifdef TRKRECO_DEBUG_DETAIL
222 c->
dump(
"hits",
" ");
223 std::cout <<
" ... splitted as" << std::endl;
224 for (
unsigned j = 0; j < newClusters.length(); j++) {
225 std::cout <<
" " << j <<
" : ";
226 newClusters[j]->dump(
"hits");
230 list.remove(splitted);
231 HepAListDeleteAll(splitted);
233#ifdef TRKRECO_DEBUG_DETAIL
247 unsigned n = list.length();
248 if (
n == 0)
return list;
250#ifdef TRKRECO_DEBUG_DETAIL
257 for (
unsigned i = 0; i <
n; i++) {
261 if ((type == 1) || (type == 2)) {
262 c->
dump(
"hits mc",
" ");
267#ifdef TRKRECO_DEBUG_DETAIL
278 const TTrack & track)
const {
285 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++) {
309 double Rmag2 = X.mag2();
310 double DR = fabs(sqrt(Rmag2) - fabs(R0));
324TConformalFinder0::findBestLink(
const TSegment0 & base,
327 double minAngle = 0.80;
328 double maxDistance = 0.3;
333 unsigned n = candidates.length();
334 double minDistance = 999.;
336 for (
unsigned j = 0; j <
n; 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) {
353 minDistance = distance;
356#ifdef TRKRECO_DEBUG_DETAIL
357 std::cout <<
",dist=" << distance << std::endl;
370 unsigned n = list.length();
373 for (
unsigned j = 0; j <
n; j++) {
376 unsigned nOk =
t.testByApproach(c->
links(),
386#ifdef TRKRECO_DEBUG_DETAIL
387 std::cout <<
" ... appending a cluster" << std::endl;
388 best->
dump(
"hits mc",
" ");
391 t.appendByApproach(links, _trackSelector.
maxSigma());
399TConformalFinder0::findClusterLink(
TSegment0 & base,
402#ifdef TRKRECO_DEBUG_DETAIL
403 std::cout <<
name() <<
" ... finding cluster linkage" << std::endl;
404 if (base.
links().length() == 0)
405 std::cout <<
name() <<
" !!! base doesn't have any TMLink." << std::endl;
406 std::cout <<
"... base cluster" << std::endl;
407 base.
dump(
"cluster hits mc",
" ->");
416 unsigned outerMost = (base.
links())[0]->wire()->axialStereoLayerId() / 4;
419 int next = outerMost;
424 if (candidates.length() == 0)
continue;
426#ifdef TRKRECO_DEBUG_DETAIL
427 std::cout <<
"... clusters in super layer " <<
next << std::endl;
431 TSegment0 * best = findBestLink(* last, candidates);
435#ifdef TRKRECO_DEBUG_DETAIL
436 std::cout <<
" ->Best is ";
437 std::cout << best->
position() <<
" ";
438 best->
dump(
"hits mc");
449 for (
unsigned i = 0; i < list.length(); i++) {
451 unsigned n = tmp.length();
452 for (
unsigned j = 0; j <
n; j++) {
453 if (tmp[j]->hit()->track())
continue;
454 links.append(tmp[j]);
464TConformalFinder0::findCloseClusters(
const TTrack & track,
466 double maxDistance)
const {
472 (center.cross(track.
links()[0]->xyPosition()).z() > 0.) ? 1 : -1;
474#ifdef TRKRECO_DEBUG_DETAIL
475 std::cout <<
name() <<
" ... finding close clusters:maxDistance=";
476 std::cout << maxDistance << std::endl;
477 std::cout <<
" radius,center,rotation=" << radius <<
",";
478 std::cout << center <<
"," << rotation << std::endl;
483 unsigned n = list.length();
484 for (
unsigned i = 0; i <
n; i++) {
489 unsigned m = c.
links().length();
490 for (
unsigned j = 0; j < m; j++) {
491 position += c.
links()[j]->xyPosition();
493 position *= 1. / double(m);
495#ifdef TRKRECO_DEBUG_DETAIL
496 c.
dump(
"cluster hits mc",
" ");
497 std::cout <<
" position=" << position;
498 std::cout <<
",diff=" << (position - center).mag() - radius << std::endl;
502 if ((diff.mag() - radius) < maxDistance) {
505 int direction = (center.cross(position).z() > 0.) ? 1 : -1;
506 if (direction == rotation) close.append(c);
510#ifdef TRKRECO_DEBUG_DETAIL
511 std::cout <<
" found clusters" << std::endl;
512 for (
unsigned i = 0; i < close.length(); i++) {
513 close[i]->dump(
"hits mc",
" ");
520TConformalFinder0::appendClusters2(
TTrack & track,
523#ifdef TRKRECO_DEBUG_DETAIL
524 std::cout <<
name() <<
" ... appending clusters remained" << std::endl;
525 std::cout <<
" clusters to be tested : " << std::endl;
526 for (
unsigned i = 0; i < list.length(); i++) {
527 list[i]->dump(
"cluster hits mc",
" ");
531 unsigned n = list.length();
535 closer.append(findCloseClusters(track, list, 1.));
537#ifdef TRKRECO_DEBUG_DETAIL
538 std::cout <<
" found clusters" << std::endl;
539 for (
unsigned i = 0; i < closer.length(); i++) {
540 closer[i]->dump(
"cluster hits mc",
" ");
544 if (closer.length() == 0)
return;
548 for (
unsigned i = 0; i <
n; i++)
549 candidates.append(closer[i]->links());
553 for (
unsigned i = 0; i <
n; i++) {
554 closer[i]->TTrackBase::remove(track.
links());
555 if (closer[i]->nLinks() == 0) list.remove(closer[i]);
567 std::cout <<
name() <<
" ... processing" << std::endl;
568 std::cout <<
" axialHits=" << axialHits.length();
569 std::cout <<
",stereoHits=" << stereoHits.length();
570 std::cout <<
",tracks=" << tracks.length();
571 std::cout << std::endl;
574 std::cout <<
name() <<
" ... conformal transformation0" << std::endl;
580 _unusedAxialConfLinks.append(_axialConfLinks);
581 _unusedStereoConfLinks.append(_stereoConfLinks);
584 unusedConfLinks.append(_axialConfLinks);
585 unusedConfLinks.append(_stereoConfLinks);
590 std::cout <<
name() <<
" ... selecting good hits" << std::endl;
594 int nLinks = _axialConfLinks.length();
595 for (
unsigned i = 0; i < nLinks; i++) {
596 TMLink * l = _axialConfLinks[i];
603 standardFinding(goodHits, unusedConfLinks, _fraction);
606 specialFinding(goodHits, unusedConfLinks, _fraction);
610 std::cout <<
name() <<
" ... processed : ";
611 std::cout <<
"good hits=" << goodHits.length();
612 std::cout <<
",tracks=" << _tracks.length();
613 std::cout << std::endl;
616 tracks.append(_tracks);
624#ifdef TRKRECO_DEBUG_DETAIL
625 std::cout <<
name() <<
" ... standard finding with salvage : given hits :";
633 for (
unsigned i = 0; i < 5; i++) {
634 segmentList[i] = * segments[i];
635 original[i] = * segments[i];
641#ifdef TRKRECO_DEBUG_DETAIL
642 for (
unsigned i = 0; i < 5; i++) {
643 std::cout <<
"... clusters in super layer " << i << std::endl;
644 for (
unsigned j = 0; j < segmentList[i].length(); j++) {
645 segmentList[i][j]->dump(
"",
" ");
646 segmentList[i][j]->dump(
"hits mc",
" ");
654 unsigned outerMost = 4;
657 while (
TSegment0 * base = segmentList[outerMost][0]) {
663 TTrack *
t = makeTrack(clusters);
665 retryList.append(base);
666 segmentList[outerMost].remove(base);
672 double f = float(
t->nCores()) / float(
NCoreLinks(clusters));
674#ifdef TRKRECO_DEBUG_DETAIL
675 std::cout <<
"... fraction too low:" << f << std::endl;
676 std::cout <<
" used cores=" <<
t->nCores();
677 std::cout <<
", candidate cores=" <<
NCoreLinks(clusters);
678 std::cout <<
" ... retry later" << std::endl;
680 retryList.append(base);
681 segmentList[outerMost].remove(base);
687 appendClusters2(*
t, retryList);
689#ifdef TRKRECO_DEBUG_DETAIL
690 std::cout <<
name() <<
" ... 2D result :" << std::endl;
691 t->dump(
"detail",
" ");
698 findCloseHits(_unusedStereoConfLinks, *
t));
703#ifdef TRKRECO_DEBUG_DETAIL
704 std::cout <<
"... failed to make a track 3D" << std::endl;
706 retryList.append(base);
707 segmentList[outerMost].remove(base);
723 list.remove(usedLinks);
724 unusedLinks.remove(usedLinks);
725 _unusedStereoConfLinks.remove(usedLinks);
726 for (
unsigned i = 0; i <= outerMost; i++)
727 segmentList[i].remove(clusters);
731 std::cout <<
name() <<
" ... track # " << _tracks.length() - 1;
732 std::cout <<
" found" << std::endl;
733 t->dump(
"detail",
" ");
742 for (
unsigned i = 0; i < 5; i++) {
743 HepAListDeleteAll(original[i]);
752#ifdef TRKRECO_DEBUG_DETAIL
753 std::cout <<
name() <<
" ... standard finding with salvage : given hits :";
761 for (
unsigned i = 0; i < 5; i++) {
762 segmentList[i] = * segments[i];
763 original[i] = * segments[i];
766#ifdef TRKRECO_DEBUG_DETAIL
767 for (
unsigned i = 0; i < 5; i++) {
768 std::cout <<
"... clusters in super layer " << i << std::endl;
769 for (
unsigned j = 0; j < segmentList[i].length(); j++) {
770 segmentList[i][j]->dump(
"",
" ");
771 segmentList[i][j]->dump(
"hits mc",
" ");
778 unsigned outerMost = 4;
781 while (
TSegment0 * base = segmentList[outerMost][0]) {
789 if (clusters.length() < 2) {
790 segmentList[outerMost].remove(base);
795 TTrack *
t = makeTrack(clusters);
797 clusters.remove(clusters.last());
803 double f = float(
t->nCores()) / float(
NCoreLinks(clusters));
805#ifdef TRKRECO_DEBUG_DETAIL
806 std::cout <<
"... fraction too low:" << f << std::endl;
807 std::cout <<
" retry later" << std::endl;
810 clusters.remove(clusters.last());
815 appendClusters2(*
t, retryList);
822 findCloseHits(_unusedStereoConfLinks, *
t));
827 clusters.remove(clusters.last());
843 list.remove(usedLinks);
844 unusedLinks.remove(usedLinks);
845 _unusedStereoConfLinks.remove(usedLinks);
846 for (
unsigned i = 0; i <= outerMost; i++)
847 segmentList[i].remove(clusters);
851 std::cout <<
name() <<
" ... track # " << _tracks.length() - 1;
852 std::cout <<
" found" << std::endl;
853 t->dump(
"detail",
" ");
862 for (
unsigned i = 0; i < 5; i++) {
863 HepAListDeleteAll(original[i]);
872#ifdef TRKRECO_DEBUG_DETAIL
873 std::cout <<
name() <<
" ... finding segments : given hits =" << std::endl;
879 unsigned n = in.length();
880 for (
unsigned i = 0; i <
n; i++) {
893 for (
unsigned i = 0; i < 5; i++) {
894 hist[i]->
fillX(links[i]);
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.
TTrack * buildRphi(const AList< TMLink > &) const
builds a r/phi track from TMLinks or from Segments.
const TMSelector & trackSelector(void) const
returns a track selector.
virtual TTrack * buildStereo(TTrack &track, const AList< TMLink > &) const
appends stereo hits to a track.
void appendClusters(TTrack &track, const AList< TMLink > &) const
appends TMLinks in a list.
A class to build a cosmic track.
A virtual class for a track finder in tracking.
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.
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
A class to represent a wire in MDC.
unsigned axialStereoLayerId(void) const
returns id of axial or stereo id.
const HepPoint3D & xyPosition(void) const
returns middle position of a wire. z componet is 0.
unsigned superLayerId(void) const
returns super layer 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.
double maxDistance(void) const
returns max. distance required for stereo hits.
unsigned nSuperLayers(void) const
returns min. # of super layers required.
double maxImpact(void) const
returns max. impact(2D) required.
unsigned nLinks(void) const
returns min. # of hits(TMLinks) requried.
double maxSigma(void) const
returns max. sigma for each TMLink.
unsigned nLinksStereo(void) const
returns min. # of stereo hits(TMLinks) requried.
double minPt(void) const
returns min. pt required.
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
returns a list of sub TSegments in this cluster. If cluster type is 1, 2, or 7, no cluster is returne...
const HepVector3D & direction(void) const
returns direction.
const HepPoint3D & position(void) const
returns position.
unsigned clusterType(void) const
returns cluster type. 0:empty, 1:short line, 2:long line, 3:V shage(from outside),...
const AList< TMLink > & links(unsigned mask=0) const
returns a list of masked TMLinks assigned to this track. 'mask' will be applied if mask is not 0.
unsigned nLinks(unsigned mask=0) const
returns # of masked TMLinks assigned to this track object.
A class to represent a track in tracking.
const Helix & helix(void) const
returns helix parameter.