338 {
340
342
346 unsigned int nb_selected_hits(0);
348
349 std::vector<unsigned> selected_hits_index(r_selection.size());
350
351
352
353 std::vector<Amg::Vector3D>
w;
354 std::vector<double>
r;
355 std::vector<double> sigma2;
356 unsigned int counter1{0}, counter2{0}, counter3{0};
357 unsigned int max_cand_hits{0};
358
359 int max_cand_HOTs{0};
360
361 int nb_candidates;
362 std::vector<int> k_cand, l_cand;
363 std::vector<int> cand_case;
364 std::vector<int> nb_HOTs;
365 int candidate{0};
366 IndexSet aux_set;
367 std::vector<IndexSet> index_set;
368
369 std::vector<double> intercept;
370 MTStraightLine tangents[4];
371
372 MTStraightLine aux_track;
373 double aux_chi2;
376 MTStraightLine initial_track(r_segment.
position(), r_segment.
direction(), null, null);
377
379
381
386 << "Class QuasianalyticLineReconstruction, method fit: Vector with selected hits unequal to the number of hits on the segment! "
387 "The user selection will be ignored!"
389 r_selection.clear();
391 } else {
392 for (unsigned int k : r_selection) {
393 if (k == 0) { nb_selected_hits = nb_selected_hits + 1; }
394 }
395 }
396
398
400
403 initial_track = MTStraightLine(r_segment.
position(), dir, null, null);
404 }
405
407
408
410
411 if (nb_selected_hits < 3) {
413 log << MSG::WARNING <<
"Class QuasianalyticLineReconstruction, method fit: Too few hits for the track reconstructions!" <<
endmsg;
414 return false;
415 }
416
418
420
421
422 selected_hits.clear();
425 sigma2.clear();
426 selected_hits_index.clear();
427
428 counter2 = 0;
430
432 if (r_selection[k] == 1 ||
hit->sigmaDriftRadius() > 100.0) {
continue; }
433
434
435 selected_hits.push_back(
hit);
436 selected_hits_index.push_back(k);
438 r.push_back(std::abs(
hit->driftRadius()));
439 sigma2.push_back(
hit->sigma2DriftRadius());
440
441 if (sigma2[counter2] == 0) { sigma2[counter2] = std::pow(0.1 * CLHEP::mm, 2); }
442
443 counter2 = counter2 + 1;
444 }
445 nb_selected_hits = selected_hits.size();
446 if (nb_selected_hits < 3) return false;
448
450
451
452 max_cand_hits = 0;
453 max_cand_HOTs = 0;
454 nb_candidates = 0;
455
456 for (
unsigned int k = 0;
k < nb_selected_hits;
k++) {
457 for (
unsigned int l = k + 1;
l < nb_selected_hits;
l++) {
458
460 diff = difftime(end, start);
463 log << MSG::WARNING <<
"Class QuasianalyticLineReconstruction, method fit: time-out for track finding after " <<
m_time_out
465 return false;
466 }
467
468
469 for (unsigned int r_case = 1; r_case < 5; r_case++) {
470 tangents[r_case - 1] =
tangent(w[l],
r[l], sigma2[l], w[k],
r[k], sigma2[k], r_case);
471 }
472
473
474
475 for (unsigned int r_case = 1; r_case < 5; r_case++) {
477 counter1 = 0;
478 counter3 = 0;
480
481 for (
unsigned int n = 0;
n < nb_selected_hits;
n++) {
482 MTStraightLine aux_line(w[n], xhat, null, null);
483 if (std::abs(std::abs(tangents[r_case - 1].signDistFrom(aux_line)) -
r[n]) <
m_r_max) { counter3++; }
484 if (std::abs(std::abs(tangents[r_case - 1].signDistFrom(aux_line)) -
r[n]) <=
m_road_width) {
485 counter1 = counter1 + 1;
487 }
488 }
489 if (counter1 > 2) {
490 aux_set = IndexSet(counter1,
indices);
492 for (
int ca = 0;
ca < nb_candidates;
ca++) {
493 if (aux_set == index_set[ca] && std::abs(intercept[ca] - tangents[r_case - 1].b_x2()) <
m_road_width) {
495 break;
496 }
497 }
498 if (same) { continue; }
499 nb_candidates = nb_candidates + 1;
500 k_cand.push_back(k);
501 l_cand.push_back(l);
502 cand_case.push_back(r_case);
503 index_set.push_back(aux_set);
504 intercept.push_back(tangents[r_case - 1].b_x2());
505 nb_HOTs.push_back(counter3);
506 if (counter1 > max_cand_hits) { max_cand_hits = counter1; }
507 }
508 }
509 }
510 }
511
512
513
514
515
517 if (max_cand_hits < 3) { return false; }
518
519 candidate = 0;
520 for (
int ca = 0;
ca < nb_candidates;
ca++) {
521 if (index_set[ca].
size() < max_cand_hits) {
continue; }
522
523 aux_track =
track_candidate(index_set[ca], k_cand[ca], l_cand[ca], cand_case[ca], w,
r, sigma2, aux_chi2);
524 if (nb_HOTs[ca] >= max_cand_HOTs) {
525 max_cand_HOTs = nb_HOTs[
ca];
526 if (
chi2 == -1.0 ||
chi2 > aux_chi2) {
528 final_track = aux_track;
530 }
531 }
532 }
533
534 MdtHitVec final_track_hits(max_cand_hits);
535 for (
unsigned int k = 0;
k < max_cand_hits;
k++) { final_track_hits[
k] = selected_hits[index_set[candidate][
k]]; }
536
537
540 final_track = MTStraightLine(aux_pos, aux_dir, null, null);
541
542
543 if (std::isnan(
chi2)) {
chi2 = 1.0e6; }
545
546 std::vector<unsigned int> refit_hit_selection(r_selection.size(), 1);
547 for (
unsigned int k = 0;
k < max_cand_hits;
k++) { refit_hit_selection[selected_hits_index[index_set[candidate][
k]]] = 0; }
549
550
552 if (
m_nfitter.fit(r_segment, refit_hit_selection)) {
554 if (
dir.z() == 0.0) {
dir[2] = (1.0e-99); }
558 final_track = MTStraightLine(0.0, 0.0, aux_line.a_x2(), aux_line.b_x2(), 0.0, 0.0, a_err, b_err);
561 final_track = MTStraightLine(aux_pos, aux_dir, null, null);
562
564 for (
unsigned int k = 0;
k < max_cand_hits;
k++) {
565 MTStraightLine wire(
Amg::Vector3D(0.0, final_track_hits[k]->localPosition().
y(), final_track_hits[k]->localPosition().
z()),
566 xhat, null, null);
569 chi2 += std::pow(d -
r, 2) / final_track_hits[
k]->sigma2DriftRadius();
570 }
571 if (std::isnan(
chi2)) {
chi2 = 1.0e6; }
572
575 return true;
576 }
577 return false;
578 }
579
580
582 MdtCalibHitBase&
hit = *mdt_hit;
583
585
586 MTStraightLine aux_line(pos, xhat, null, null);
589
590 hit.setDistanceToTrack(dist, dist_err);
591 }
594
595 return true;
596}
std::vector< std::vector< int64_t > > indices
size_t size() const
Number of registered mappings.
void diff(const TrigCaloCluster &a, const TrigCaloCluster &b, std::map< std::string, double > &varChange)
bool m_refine_segment
flags
void sort()
sort the indices in ascending order
Amg::Vector3D directionVector() const
get the direction vector of the straight line
double b_x2() const
get the intercept of the straight line in the x2-x3 plane
double a_x2() const
get the slope of the straight line in the x2-x3 plane
Amg::Vector3D positionVector() const
get the position vector of the straight line
double b_x2_error() const
get the slope of the intercept of the straight line in the x2-x3 plane
void setUsedHits(const MdtHitVec &hits)
double signDistFrom(const MTStraightLine &h) const
get the signed distance of two lines (if both are parallel, dist>0)
double a_x2_error() const
get the error on the slope of the straight line in the x2-x3 plane
void setChi2(double chi2)
Cache the chi2.
void refineMdtSelection(const std::vector< unsigned int > &new_selection)
move trck hits to close hits
const Amg::Vector3D & direction() const
retrieve local direction of segment (on station level) retrieve the transformation from local chamber...
std::shared_ptr< MdtCalibHitBase > MdtHitPtr
typedef for a collection of MdtCalibHitBase s
unsigned int hitsOnTrack() const
retrieve the sum of all XxxCalibHits assigned to the MuonCalibSegment
const MdtHitVec & mdtHOT() const
retrieve the full set of MdtCalibHitBase s assigned to this segment
void set(double chi2, const Amg::Vector3D &pos, const Amg::Vector3D &dir)
const Amg::Vector3D & position() const
retrieve local position of segment (on station level)
MuonCalibSegment::MdtHitVec MdtHitVec
MTStraightLine tangent(const Amg::Vector3D &r_w1, const double r_r1, const double r_sigma12, const Amg::Vector3D &r_w2, const double r_r2, const double r_sigma22, const int &r_case) const
MuonCalibSegment::MdtHitPtr MdtHitPtr
MTStraightLine track_candidate(const IndexSet &r_index_set, const int &r_k_cand, const int &r_l_cand, const int &r_cand_case, const std::vector< Amg::Vector3D > &r_w, const std::vector< double > &r_r, const std::vector< double > &r_sigma2, double &r_chi2) const
double chi2(TH1 *h0, TH1 *h1)
Eigen::Matrix< double, 3, 1 > Vector3D
IMessageSvc * getMessageSvc(bool quiet=false)
time(flags, cells_name, *args, **kw)
l
Printing final latex table to .tex output file.