00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "TrkReco/TMDCUtil.h"
00016 #include "TrkReco/TMDCWire.h"
00017 #include "TrkReco/TMDCWireHit.h"
00018 #include "TrkReco/TMDCWireHitMC.h"
00019 #include "TrkReco/TConformalFinder0.h"
00020 #include "TrkReco/TMLink.h"
00021 #include "TrkReco/THistogram.h"
00022 #include "TrkReco/TCircle.h"
00023 #include "TrkReco/TTrack.h"
00024 #include "TrkReco/TSegment0.h"
00025
00026 #include "TrkReco/Range.h"
00027
00028 std::string
00029 TConformalFinder0::version(void) const {
00030 return "1.63";
00031 }
00032
00033 TConformalFinder0::TConformalFinder0(float maxSigma,
00034 float fraction,
00035 float stereoZ3,
00036 float stereoZ4,
00037 float stereoChisq3,
00038 float stereoChisq4,
00039 float stereoMaxSigma,
00040 unsigned fittingCorrections,
00041 float salvageLevel,
00042 bool cosmic)
00043 : TFinderBase(),
00044 _builder(0),
00045 _doStereo(true),
00046 _doSalvage(true),
00047 _fraction(fraction) {
00048
00049
00050 _trackSelector.nLinks(4);
00051 _trackSelector.nSuperLayers(2);
00052 _trackSelector.minPt(0.05);
00053 _trackSelector.maxImpact(100.);
00054 _trackSelector.maxSigma(maxSigma);
00055 _trackSelector.nLinksStereo(3);
00056 _trackSelector.maxDistance(30.);
00057
00058
00059 if (cosmic) _builder = new TBuilderCosmic("cosmic builder", salvageLevel);
00060 else _builder = new TBuilder0("conformal builder",
00061 stereoZ3,
00062 stereoZ4,
00063 stereoChisq3,
00064 stereoChisq4,
00065 stereoMaxSigma,
00066 fittingCorrections,
00067 salvageLevel);
00068
00069
00070 _builder->trackSelector(_trackSelector);
00071 }
00072
00073 TConformalFinder0::~TConformalFinder0() {
00074 delete _builder;
00075 }
00076
00077 void
00078 TConformalFinder0::dump(const std::string & msg, const std::string & pre) const {
00079 std::cout << pre;
00080 TFinderBase::dump(msg);
00081 std::cout << pre;
00082 if (msg.find("state") != std::string::npos) {
00083 std::cout << "#axialConfPos=" << _axialConfLinks.length();
00084 std::cout << ",#stereoConfPos=" << _stereoConfLinks.length();
00085 }
00086 }
00087
00088 void
00089 TConformalFinder0::clear(void) {
00090 HepAListDeleteAll(_axialConfLinks);
00091 HepAListDeleteAll(_stereoConfLinks);
00092 _unusedAxialConfLinks.removeAll();
00093 _unusedStereoConfLinks.removeAll();
00094 _goodAxialConfLinks.removeAll();
00095 HepAListDeleteAll(_circles);
00096 _tracks.removeAll();
00097 }
00098
00099 void
00100 TConformalFinder0::conformalTransformation(const HepPoint3D & center,
00101 const AList<TMDCWireHit> & hits,
00102 AList<TMLink> & links) {
00103
00104 unsigned nHits = hits.length();
00105 if (center == ORIGIN) {
00106 for (unsigned i = 0; i < nHits; i++) {
00107 TMDCWireHit * h = hits[i];
00108 const HepPoint3D & p = h->xyPosition();
00109
00110
00111 HepPoint3D cp(2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0.);
00112
00113 links.append(new TMLink(0, h, cp));
00114 }
00115 }
00116 else {
00117 for (unsigned i = 0; i < nHits; i++) {
00118 TMDCWireHit * h = hits[i];
00119 HepPoint3D p(h->xyPosition() - center);
00120 HepPoint3D cp(2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0.);
00121 links.append(new TMLink(0, h, cp));
00122 }
00123 }
00124 }
00125
00126 void
00127 TConformalFinder0::conformalTransformationDriftCircle(const HepPoint3D & center,
00128 const AList<TMDCWireHit> & hits,
00129 AList<TMLink> & links) {
00130 unsigned nHits = hits.length();
00131 if (center == ORIGIN) {
00132 for (unsigned i = 0; i < nHits; i++) {
00133 TMDCWireHit * h = hits[i];
00134 const HepPoint3D & p = h->xyPosition();
00135
00136 const double r = 0.5*(h->drift(0) + h->drift(1));
00137 HepPoint3D cp(2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0.);
00138
00139 HepPoint3D cp2(2. * p.x() / (p.mag2() - r*r), 2. * p.y() / (p.mag2() - r*r), 0.);
00140
00141 double cDrift = 2. * r / (p.mag2() - r*r);
00142
00143 links.append(new TMLink(0, h, cp, cp2, cDrift));
00144 }
00145 }
00146 else {
00147 for (unsigned i = 0; i < nHits; i++) {
00148 TMDCWireHit * h = hits[i];
00149 HepPoint3D p(h->xyPosition() - center);
00150
00151 const double r = 0.5*(h->drift(0) + h->drift(1));
00152 HepPoint3D cp(2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0.);
00153
00154
00155 HepPoint3D cp2(2. * p.x() / (p.mag2() - r*r), 2. * p.y() / (p.mag2() - r*r), 0.);
00156
00157 double cDrift = 2. * r / (p.mag2() - r*r);
00158
00159 links.append(new TMLink(0, h, cp, cp2, cDrift));
00160 }
00161 }
00162 }
00163
00164 void
00165 TConformalFinder0::conformalTransformationRphi(const HepPoint3D & center,
00166 const AList<TMDCWireHit> & hits,
00167 AList<TMLink> & links) {
00168
00169 unsigned nHits = hits.length();
00170 if (center == ORIGIN) {
00171 for (unsigned i = 0; i < nHits; i++) {
00172 TMDCWireHit * h = hits[i];
00173 const HepPoint3D & p = h->xyPosition();
00174 HepPoint3D cp(2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0.);
00175 double r = log(cp.mag()) + 4.;
00176 double phi = atan2(cp.y(), cp.x()) + M_PI;
00177 HepPoint3D cpt(phi, r, 0.);
00178 links.append(new TMLink(0, h, cpt));
00179 }
00180 }
00181 else {
00182 for (unsigned i = 0; i < nHits; i++) {
00183 TMDCWireHit * h = hits[i];
00184 HepPoint3D p(h->xyPosition() - center);
00185 HepPoint3D cp(2. * p.x() / p.mag2(), 2. * p.y() / p.mag2(), 0.);
00186 double r = log(cp.mag()) + 4.;
00187 double phi = atan2(cp.y(), cp.x()) + M_PI;
00188 HepPoint3D cpt(phi, r, 0.);
00189 links.append(new TMLink(0, h, cpt));
00190 }
00191 }
00192 }
00193
00194 AList<TSegment0>
00195 TConformalFinder0::findClusters(const THistogram & hist) const {
00196
00197
00198 AList<TSegment0> list = hist.clusters0();
00199 unsigned n = list.length();
00200 if (n == 0) return list;
00201
00202 #ifdef TRKRECO_DEBUG_DETAIL
00203
00204
00205
00206 #endif
00207
00208
00209 AList<TSegment0> splitted;
00210 for (unsigned i = 0; i < n; i++) {
00211 TSegment0 * c = list[i];
00212
00213 AList<TSegment0> newClusters = c->split();
00214 if (newClusters.length() == 0) {
00215 c->solveDualHits();
00216 continue;
00217 }
00218
00219 list.append(newClusters);
00220 splitted.append(c);
00221 #ifdef TRKRECO_DEBUG_DETAIL
00222 c->dump("hits", " ");
00223 std::cout << " ... splitted as" << std::endl;
00224 for (unsigned j = 0; j < newClusters.length(); j++) {
00225 std::cout << " " << j << " : ";
00226 newClusters[j]->dump("hits");
00227 }
00228 #endif
00229 }
00230 list.remove(splitted);
00231 HepAListDeleteAll(splitted);
00232
00233 #ifdef TRKRECO_DEBUG_DETAIL
00234
00235
00236
00237 #endif
00238
00239 return list;
00240 }
00241
00242 AList<TSegment0>
00243 TConformalFinder0::findClusters2(const THistogram & hist) const {
00244
00245
00246 AList<TSegment0> list = hist.clusters0();
00247 unsigned n = list.length();
00248 if (n == 0) return list;
00249
00250 #ifdef TRKRECO_DEBUG_DETAIL
00251
00252
00253
00254 #endif
00255
00256
00257 for (unsigned i = 0; i < n; i++) {
00258 TSegment0 * c = list[i];
00259 unsigned type = c->clusterType();
00260
00261 if ((type == 1) || (type == 2)) {
00262 c->dump("hits mc", " ");
00263 c->solveDualHits();
00264 }
00265 }
00266
00267 #ifdef TRKRECO_DEBUG_DETAIL
00268
00269
00270
00271 #endif
00272
00273 return list;
00274 }
00275
00276 AList<TMLink>
00277 TConformalFinder0::findCloseHits(const AList<TMLink> & links,
00278 const TTrack & track) const {
00279
00280
00281
00282 AList<TMLink> list;
00283
00284
00285 if (track.links().length() == 0) {
00286 #ifdef TRKRECO_DEBUG_DETAIL
00287 std::cout << "TConformalFinder0::findCloseHits !!! ";
00288 std::cout << " no links found in a track : This should not be happened";
00289 std::cout << std::endl;
00290 #endif
00291
00292 return list;
00293 }
00294
00295
00296
00297
00298 float dRcut[11] = {4.3, 6.5, 0., 0., 0., 7.5, 8.0, 9.5, 11.0, 0., 0.};
00299
00300
00301 double R0 = track.helix().curv();
00302 double xInnerWire = track.links()[0]->wire()->xyPosition().x();
00303 double yInnerWire = track.links()[0]->wire()->xyPosition().y();
00304 unsigned nall = links.length();
00305 for (unsigned j = 0; j < nall; j++) {
00306 TMLink & t = * links[j];
00307 const TMDCWire & w = * t.wire();
00308 HepVector3D X = w.xyPosition() - track.helix().center();
00309 double Rmag2 = X.mag2();
00310 double DR = fabs(sqrt(Rmag2) - fabs(R0));
00311 t.zStatus(-10);
00312 t.zPair(0);
00313 if (DR < dRcut[w.superLayerId()] &&
00314 (xInnerWire*w.xyPosition().x()+yInnerWire*w.xyPosition().y())>0.){
00315 list.append(t);
00316 }
00317 }
00318
00319
00320 return list;
00321 }
00322
00323 TSegment0 *
00324 TConformalFinder0::findBestLink(const TSegment0 & base,
00325 const AList<TSegment0> & candidates) const {
00326
00327 double minAngle = 0.80;
00328 double maxDistance = 0.3;
00329
00330
00331
00332
00333 unsigned n = candidates.length();
00334 double minDistance = 999.;
00335 TSegment0 * best = NULL;
00336 for (unsigned j = 0; j < n; j++) {
00337 TSegment0 * current = candidates[j];
00338 if (current->nLinks() < 2) continue;
00339
00340 float angle = base.direction().dot(current->direction());
00341 #ifdef TRKRECO_DEBUG_DETAIL
00342 current->dump("vector hits mc", " ");
00343 std::cout << " angle=" << angle;
00344 if (angle < minAngle) std::cout << std::endl;
00345 #endif
00346
00347
00348
00349 if (angle < minAngle) continue;
00350
00351 float distance = base.distance(* current);
00352 if (distance < minDistance) {
00353 minDistance = distance;
00354 best = current;
00355 }
00356 #ifdef TRKRECO_DEBUG_DETAIL
00357 std::cout << ",dist=" << distance << std::endl;
00358 #endif
00359 }
00360
00361
00362 return best;
00363
00364 }
00365
00366 TSegment0 *
00367 TConformalFinder0::appendCluster(TTrack & t, AList<TSegment0> & list) const {
00368
00369
00370 unsigned n = list.length();
00371 TSegment0 * best = NULL;
00372 unsigned nBest = 0;
00373 for (unsigned j = 0; j < n; j++) {
00374 TSegment0 * c = list[j];
00375
00376 unsigned nOk = t.testByApproach(c->links(),
00377 _trackSelector.maxSigma());
00378 if (nOk > nBest) {
00379 nBest = nOk;
00380 best = c;
00381 }
00382 }
00383
00384
00385 if (best) {
00386 #ifdef TRKRECO_DEBUG_DETAIL
00387 std::cout << " ... appending a cluster" << std::endl;
00388 best->dump("hits mc", " ");
00389 #endif
00390 AList<TMLink> links(best->links());
00391 t.appendByApproach(links, _trackSelector.maxSigma());
00392 return best;
00393 }
00394
00395 return NULL;
00396 }
00397
00398 AList<TSegment0>
00399 TConformalFinder0::findClusterLink(TSegment0 & base,
00400 const AList<TSegment0> * const list) const {
00401
00402 #ifdef TRKRECO_DEBUG_DETAIL
00403 std::cout << name() << " ... finding cluster linkage" << std::endl;
00404 if (base.links().length() == 0)
00405 std::cout << name() << " !!! base doesn't have any TMLink." << std::endl;
00406 std::cout << "... base cluster" << std::endl;
00407 base.dump("cluster hits mc", " ->");
00408 #endif
00409
00410
00411 AList<TSegment0> seeds;
00412 seeds.append(base);
00413
00414
00415
00416 unsigned outerMost = (base.links())[0]->wire()->axialStereoLayerId() / 4;
00417
00418
00419 int next = outerMost;
00420 TSegment0 * last = & base;
00421 while (next) {
00422 --next;
00423 const AList<TSegment0> & candidates = list[next];
00424 if (candidates.length() == 0) continue;
00425
00426 #ifdef TRKRECO_DEBUG_DETAIL
00427 std::cout << "... clusters in super layer " << next << std::endl;
00428 #endif
00429
00430
00431 TSegment0 * best = findBestLink(* last, candidates);
00432 if (best != NULL) {
00433 seeds.append(best);
00434 last = best;
00435 #ifdef TRKRECO_DEBUG_DETAIL
00436 std::cout << " ->Best is ";
00437 std::cout << best->position() << " ";
00438 best->dump("hits mc");
00439 #endif
00440 }
00441 }
00442
00443 return seeds;
00444 }
00445
00446 TTrack *
00447 TConformalFinder0::makeTrack(const AList<TSegment0> & list) const {
00448 AList<TMLink> links;
00449 for (unsigned i = 0; i < list.length(); i++) {
00450 const AList<TMLink> & tmp = list[i]->links();
00451 unsigned n = tmp.length();
00452 for (unsigned j = 0; j < n; j++) {
00453 if (tmp[j]->hit()->track()) continue;
00454 links.append(tmp[j]);
00455 }
00456 }
00457
00458 TTrack * t = _builder->buildRphi(links);
00459
00460 return t;
00461 }
00462
00463 AList<TSegment0>
00464 TConformalFinder0::findCloseClusters(const TTrack & track,
00465 const AList<TSegment0> & list,
00466 double maxDistance) const {
00467
00468
00469 double radius = fabs(track.helix().radius());
00470 const HepPoint3D & center = track.helix().center();
00471 int rotation =
00472 (center.cross(track.links()[0]->xyPosition()).z() > 0.) ? 1 : -1;
00473
00474 #ifdef TRKRECO_DEBUG_DETAIL
00475 std::cout << name() << " ... finding close clusters:maxDistance=";
00476 std::cout << maxDistance << std::endl;
00477 std::cout << " radius,center,rotation=" << radius << ",";
00478 std::cout << center << "," << rotation << std::endl;
00479 #endif
00480
00481
00482 AList<TSegment0> close;
00483 unsigned n = list.length();
00484 for (unsigned i = 0; i < n; i++) {
00485 TSegment0 & c = * list[i];
00486
00487
00488 HepPoint3D position(ORIGIN);
00489 unsigned m = c.links().length();
00490 for (unsigned j = 0; j < m; j++) {
00491 position += c.links()[j]->xyPosition();
00492 }
00493 position *= 1. / double(m);
00494
00495 #ifdef TRKRECO_DEBUG_DETAIL
00496 c.dump("cluster hits mc", " ");
00497 std::cout << " position=" << position;
00498 std::cout << ",diff=" << (position - center).mag() - radius << std::endl;
00499 #endif
00500
00501 HepVector3D diff = position - center;
00502 if ((diff.mag() - radius) < maxDistance) {
00503
00504
00505 int direction = (center.cross(position).z() > 0.) ? 1 : -1;
00506 if (direction == rotation) close.append(c);
00507 }
00508 }
00509
00510 #ifdef TRKRECO_DEBUG_DETAIL
00511 std::cout << " found clusters" << std::endl;
00512 for (unsigned i = 0; i < close.length(); i++) {
00513 close[i]->dump("hits mc", " ");
00514 }
00515 #endif
00516 return close;
00517 }
00518
00519 void
00520 TConformalFinder0::appendClusters2(TTrack & track,
00521 AList<TSegment0> & list) const {
00522
00523 #ifdef TRKRECO_DEBUG_DETAIL
00524 std::cout << name() << " ... appending clusters remained" << std::endl;
00525 std::cout << " clusters to be tested : " << std::endl;
00526 for (unsigned i = 0; i < list.length(); i++) {
00527 list[i]->dump("cluster hits mc", " ");
00528 }
00529 #endif
00530
00531 unsigned n = list.length();
00532 if (n == 0) return;
00533
00534 AList<TSegment0> closer;
00535 closer.append(findCloseClusters(track, list, 1.));
00536
00537 #ifdef TRKRECO_DEBUG_DETAIL
00538 std::cout << " found clusters" << std::endl;
00539 for (unsigned i = 0; i < closer.length(); i++) {
00540 closer[i]->dump("cluster hits mc", " ");
00541 }
00542 #endif
00543 n = closer.length();
00544 if (closer.length() == 0) return;
00545
00546
00547 AList<TMLink> candidates;
00548 for (unsigned i = 0; i < n; i++)
00549 candidates.append(closer[i]->links());
00550 _builder->appendClusters(track, candidates);
00551
00552
00553 for (unsigned i = 0; i < n; i++) {
00554 closer[i]->TTrackBase::remove(track.links());
00555 if (closer[i]->nLinks() == 0) list.remove(closer[i]);
00556 }
00557 }
00558
00559 int
00560 TConformalFinder0::doit(const AList<TMDCWireHit> & axialHits,
00561 const AList<TMDCWireHit> & stereoHits,
00562 AList<TTrack> & tracks,
00563 AList<TTrack> &) {
00564
00565
00566 if (debugLevel()) {
00567 std::cout << name() << " ... processing" << std::endl;
00568 std::cout << " axialHits=" << axialHits.length();
00569 std::cout << ",stereoHits=" << stereoHits.length();
00570 std::cout << ",tracks=" << tracks.length();
00571 std::cout << std::endl;
00572
00573 if (debugLevel() > 1)
00574 std::cout << name() << " ... conformal transformation0" << std::endl;
00575 }
00576
00577
00578 conformalTransformationRphi(ORIGIN, axialHits, _axialConfLinks);
00579 conformalTransformationRphi(ORIGIN, stereoHits, _stereoConfLinks);
00580 _unusedAxialConfLinks.append(_axialConfLinks);
00581 _unusedStereoConfLinks.append(_stereoConfLinks);
00582 AList<TMLink> unusedConfLinks;
00583 if (_doSalvage) {
00584 unusedConfLinks.append(_axialConfLinks);
00585 unusedConfLinks.append(_stereoConfLinks);
00586 }
00587
00588
00589 if (debugLevel() > 1)
00590 std::cout << name() << " ... selecting good hits" << std::endl;
00591
00592
00593 AList<TMLink> goodHits;
00594 int nLinks = _axialConfLinks.length();
00595 for (unsigned i = 0; i < nLinks; i++) {
00596 TMLink * l = _axialConfLinks[i];
00597 const TMDCWireHit & h = * l->hit();
00598
00599
00600 goodHits.append(l);
00601 }
00602
00603 standardFinding(goodHits, unusedConfLinks, _fraction);
00604
00605
00606 specialFinding(goodHits, unusedConfLinks, _fraction);
00607
00608
00609 if (debugLevel()) {
00610 std::cout << name() << " ... processed : ";
00611 std::cout << "good hits=" << goodHits.length();
00612 std::cout << ",tracks=" << _tracks.length();
00613 std::cout << std::endl;
00614 }
00615
00616 tracks.append(_tracks);
00617 return 0;
00618 }
00619
00620 void
00621 TConformalFinder0::standardFinding(AList<TMLink> & list,
00622 AList<TMLink> & unusedLinks,
00623 double fraction) {
00624 #ifdef TRKRECO_DEBUG_DETAIL
00625 std::cout << name() << " ... standard finding with salvage : given hits :";
00626 Dump(list, "sort");
00627 #endif
00628
00629
00630 AList< AList<TSegment0> > segments = findSegments(list);
00631 AList<TSegment0> segmentList[5];
00632 AList<TSegment0> original[5];
00633 for (unsigned i = 0; i < 5; i++) {
00634 segmentList[i] = * segments[i];
00635 original[i] = * segments[i];
00636
00637
00638
00639 }
00640
00641 #ifdef TRKRECO_DEBUG_DETAIL
00642 for (unsigned i = 0; i < 5; i++) {
00643 std::cout << "... clusters in super layer " << i << std::endl;
00644 for (unsigned j = 0; j < segmentList[i].length(); j++) {
00645 segmentList[i][j]->dump("", " ");
00646 segmentList[i][j]->dump("hits mc", " ");
00647 }
00648 }
00649 #endif
00650
00651
00652 AList<TSegment0> retryList;
00653 AList<TTrack> salvageList;
00654 unsigned outerMost = 4;
00655 while (outerMost) {
00656
00657 while (TSegment0 * base = segmentList[outerMost][0]) {
00658
00659
00660 AList<TSegment0> clusters = findClusterLink(* base, segmentList);
00661
00662
00663 TTrack * t = makeTrack(clusters);
00664 if (t == NULL) {
00665 retryList.append(base);
00666 segmentList[outerMost].remove(base);
00667 continue;
00668 }
00669
00670
00671
00672 double f = float(t->nCores()) / float(NCoreLinks(clusters));
00673 if (f < fraction) {
00674 #ifdef TRKRECO_DEBUG_DETAIL
00675 std::cout << "... fraction too low:" << f << std::endl;
00676 std::cout << " used cores=" << t->nCores();
00677 std::cout << ", candidate cores=" << NCoreLinks(clusters);
00678 std::cout << " ... retry later" << std::endl;
00679 #endif
00680 retryList.append(base);
00681 segmentList[outerMost].remove(base);
00682 delete t;
00683 continue;
00684 }
00685
00686
00687 appendClusters2(* t, retryList);
00688
00689 #ifdef TRKRECO_DEBUG_DETAIL
00690 std::cout << name() << " ... 2D result :" << std::endl;
00691 t->dump("detail", " ");
00692 #endif
00693
00694
00695 TTrack * ts = t;
00696 if (_doStereo) {
00697 ts = _builder->buildStereo(* t,
00698 findCloseHits(_unusedStereoConfLinks, * t));
00699 }
00700
00701
00702 if (! ts) {
00703 #ifdef TRKRECO_DEBUG_DETAIL
00704 std::cout << "... failed to make a track 3D" << std::endl;
00705 #endif
00706 retryList.append(base);
00707 segmentList[outerMost].remove(base);
00708 delete t;
00709 continue;
00710 }
00711
00712
00713
00714
00715
00716 t->assign(WireHitConformalFinder);
00717 t->finder(TrackOldConformalFinder);
00718
00719 _tracks.append(t);
00720
00721
00722 const AList<TMLink> & usedLinks = t->links();
00723 list.remove(usedLinks);
00724 unusedLinks.remove(usedLinks);
00725 _unusedStereoConfLinks.remove(usedLinks);
00726 for (unsigned i = 0; i <= outerMost; i++)
00727 segmentList[i].remove(clusters);
00728
00729
00730 if (debugLevel() > 1) {
00731 std::cout << name() << " ... track # " << _tracks.length() - 1;
00732 std::cout << " found" << std::endl;
00733 t->dump("detail", " ");
00734 }
00735 }
00736
00737
00738 --outerMost;
00739 }
00740
00741
00742 for (unsigned i = 0; i < 5; i++) {
00743 HepAListDeleteAll(original[i]);
00744 delete segments[i];
00745 }
00746 }
00747
00748 void
00749 TConformalFinder0::specialFinding(AList<TMLink> & list,
00750 AList<TMLink> & unusedLinks,
00751 double fraction) {
00752 #ifdef TRKRECO_DEBUG_DETAIL
00753 std::cout << name() << " ... standard finding with salvage : given hits :";
00754 Dump(list, "sort");
00755 #endif
00756
00757
00758 AList< AList<TSegment0> > segments = findSegments(list);
00759 AList<TSegment0> segmentList[5];
00760 AList<TSegment0> original[5];
00761 for (unsigned i = 0; i < 5; i++) {
00762 segmentList[i] = * segments[i];
00763 original[i] = * segments[i];
00764 }
00765
00766 #ifdef TRKRECO_DEBUG_DETAIL
00767 for (unsigned i = 0; i < 5; i++) {
00768 std::cout << "... clusters in super layer " << i << std::endl;
00769 for (unsigned j = 0; j < segmentList[i].length(); j++) {
00770 segmentList[i][j]->dump("", " ");
00771 segmentList[i][j]->dump("hits mc", " ");
00772 }
00773 }
00774 #endif
00775
00776
00777 AList<TSegment0> retryList;
00778 unsigned outerMost = 4;
00779 while (outerMost) {
00780
00781 while (TSegment0 * base = segmentList[outerMost][0]) {
00782
00783
00784 AList<TSegment0> clusters = findClusterLink(* base, segmentList);
00785
00786 again:;
00787
00788
00789 if (clusters.length() < 2) {
00790 segmentList[outerMost].remove(base);
00791 continue;
00792 }
00793
00794
00795 TTrack * t = makeTrack(clusters);
00796 if (t == NULL) {
00797 clusters.remove(clusters.last());
00798 goto again;
00799 }
00800
00801
00802
00803 double f = float(t->nCores()) / float(NCoreLinks(clusters));
00804 if (f < fraction) {
00805 #ifdef TRKRECO_DEBUG_DETAIL
00806 std::cout << "... fraction too low:" << f << std::endl;
00807 std::cout << " retry later" << std::endl;
00808 #endif
00809 delete t;
00810 clusters.remove(clusters.last());
00811 goto again;
00812 }
00813
00814
00815 appendClusters2(* t, retryList);
00816
00817
00818
00819 TTrack * ts = t;
00820 if (_doStereo) {
00821 ts = _builder->buildStereo(* t,
00822 findCloseHits(_unusedStereoConfLinks, * t));
00823 }
00824
00825
00826 if (! ts) {
00827 clusters.remove(clusters.last());
00828 delete t;
00829 goto again;
00830 }
00831
00832
00833
00834
00835
00836 t->assign(WireHitConformalFinder);
00837 t->finder(TrackOldConformalFinder);
00838
00839 _tracks.append(t);
00840
00841
00842 const AList<TMLink> & usedLinks = t->links();
00843 list.remove(usedLinks);
00844 unusedLinks.remove(usedLinks);
00845 _unusedStereoConfLinks.remove(usedLinks);
00846 for (unsigned i = 0; i <= outerMost; i++)
00847 segmentList[i].remove(clusters);
00848
00849
00850 if (debugLevel() > 1) {
00851 std::cout << name() << " ... track # " << _tracks.length() - 1;
00852 std::cout << " found" << std::endl;
00853 t->dump("detail", " ");
00854 }
00855 }
00856
00857
00858 --outerMost;
00859 }
00860
00861
00862 for (unsigned i = 0; i < 5; i++) {
00863 HepAListDeleteAll(original[i]);
00864 delete segments[i];
00865 }
00866 }
00867
00868 AList< AList<TSegment0> >
00869 TConformalFinder0::findSegments(const AList<TMLink> & in) const {
00870 AList< AList<TSegment0> > a;
00871
00872 #ifdef TRKRECO_DEBUG_DETAIL
00873 std::cout << name() << " ... finding segments : given hits =" << std::endl;
00874 Dump(in, "sort");
00875 #endif
00876
00877
00878 AList<TMLink> links[5];
00879 unsigned n = in.length();
00880 for (unsigned i = 0; i < n; i++) {
00881 TMLink & l = * in[i];
00882
00883 links[l.wire()->axialStereoLayerId()/4].append(l);
00884 }
00885
00886
00887 THistogram * hist[5];
00888 hist[0] = new THistogram(76);
00889 hist[1] = new THistogram(100);
00890 hist[2] = new THistogram(128);
00891 hist[3] = new THistogram(256);
00892 hist[4] = new THistogram(288);
00893 for (unsigned i = 0; i < 5; i++) {
00894 hist[i]->fillX(links[i]);
00895 AList<TSegment0> * b = new AList<TSegment0>();
00896 a.append(b);
00897 b->append(findClusters(* hist[i]));
00898 delete hist[i];
00899 }
00900
00901 return a;
00902 }