18#include "TDirectory.h"
26 declareInterface<IMuonHoughPatternTool>(
this);
44 for (
unsigned int hitid = 0; hitid < hitcontainer.
size(); ++hitid) { phihits += hitcontainer.
getMeasuresPhi(hitid); }
46 ATH_MSG_DEBUG(
"Cosmic event has more than 1000 phi hits: " << phihits <<
" event is not reconstructed!");
60 if (msgLevel(MSG::VERBOSE)) {
64 for (
unsigned int i = 0; i < hitcontainer.
size(); ++i) {
65 const std::shared_ptr<MuonHoughHit> hit = hitcontainer.
getHit(i);
66 ATH_MSG_VERBOSE(hit->getHitx() <<
" " << hit->getHity() <<
" " << hit->getHitz() <<
" " << hit->getMeasuresPhi() <<
" "
67 << hit->getWhichDetector() <<
" " << hit->getProbability() <<
" " << hit->getWeight() <<
" "
68 << hit->getAssociated());
90 std::unique_ptr<MuonHoughHitContainer> event_for_hough{
whichEventHough(id_number, event, weightmdt)};
91 std::unique_ptr<MuonHoughHitContainer> event_for_association{
whichEventAssociation(id_number, event)};
93 if (msgLevel(MSG::VERBOSE)) {
95 for (
unsigned int i = 0; i < event_for_hough->size(); ++i) {
96 const std::shared_ptr<MuonHoughHit> hit = event_for_hough->getHit(i);
97 ATH_MSG_VERBOSE(hit->getHitx() <<
" " << hit->getHity() <<
" " << hit->getHitz() <<
" " << hit->getMeasuresPhi() <<
" "
98 << hit->getWhichDetector() <<
" " << hit->getProbability() <<
" " << hit->getWeight() <<
" "
99 << hit->getAssociated());
102 ATH_MSG_VERBOSE(
"Size event association: " << event_for_association->size());
103 for (
unsigned int i = 0; i < event_for_association->size(); ++i) {
104 const std::shared_ptr<MuonHoughHit> hit = event_for_association->getHit(i);
105 ATH_MSG_VERBOSE(hit->getHitx() <<
" " << hit->getHity() <<
" " << hit->getHitz() <<
" " << hit->getMeasuresPhi() <<
" "
106 << hit->getWhichDetector() <<
" " << hit->getProbability() <<
" " << hit->getWeight() <<
" "
107 << hit->getAssociated());
110 ATH_MSG_DEBUG(
"size of event: " << event_for_association->size() <<
" id_number: " << id_number);
112 std::unique_ptr<MuonHoughTransformSteering> houghtransform{
whichHoughTransform(id_number)};
116 bool test_for_next_level =
true;
119 if (test_for_next_level) {
122 houghtransform->resetHisto();
123 ATH_MSG_DEBUG(
"fillHistos size hits not in patterns " << event_for_hough->size());
124 houghtransform->fill(*event_for_hough);
128 TDirectory* dir = gDirectory;
130 for (
int i = 0; i < histos.size(); ++i) {
131 const std::string hname =
"hough_call_" + std::to_string(
m_ncalls) +
"_hist_" + std::to_string(i);
132 histos.getHisto(i)->bookAndFillRootHistogram(hname)->Write();
139 test_for_next_level =
analyseHisto(id_number, level, event_for_association, houghtransform, houghpattern);
141 if (test_for_next_level) {
142 event_for_hough =
whichEventHough(id_number, *event_for_hough, weightmdt);
143 ATH_MSG_DEBUG(
"New event size for transform: " << event_for_hough->size());
155 m_file = std::make_unique<TFile>(
"HoughPattern.root",
"RECREATE");
180 return StatusCode::SUCCESS;
184 for (
unsigned int i = 0; i <
event.size(); ++i) {
185 std::shared_ptr<MuonHoughHit> hit =
event.getHit(i);
186 hit->setAssociated(
false);
199 return StatusCode::SUCCESS;
208 houghpattern.emplace_back(std::move(which_segment_vector));
213 houghpattern[i].emplace_back(std::move(level_vector));
216 houghpattern[i][lvl].emplace_back(
nullptr);
225 std::unique_ptr<MuonHoughTransformSteering>& houghtransform,
237 bool test_for_next_level =
false;
240 double numberofmaxima = 0;
246 for (
unsigned int maximum_number = 0; maximum_number < houghpatterns.size(); ++maximum_number) {
248 std::unique_ptr<MuonHoughPattern>& houghpattern = houghpatterns[maximum_number];
249 if (!houghpattern) {
continue; }
250 numberofmaxima = houghpattern->getMaximumHistogram();
251 ATH_MSG_DEBUG(
"id_number: " << id_number <<
" maximum_number: " << maximum_number <<
" size patternseg: " << houghpattern->size());
253 if (houghpattern->empty()) {
ATH_MSG_DEBUG(
"houghpattern==0"); }
256 if (houghpattern->size() < numberofmaxima) {
257 ATH_MSG_DEBUG(
"ERROR: houghpattern smaller than maximum, id: " << id_number <<
" houghpattern.size(): " << houghpattern->size()
258 <<
" numberofmaxima: " << numberofmaxima);
261 if (
m_printlevel >= 4) { houghpattern->printHoughPattern(); }
265 if (houghpattern->size() >= threshold_for_next_houghpattern) {
269 test_for_next_level =
hitsLeft(*event_to_analyse);
271 }
else if (maximum_number == 0) {
272 ATH_MSG_DEBUG(
"houghpattern too small for next level : " << level <<
" id: " << id_number);
276 ATH_MSG_DEBUG(
"Size of HoughPatterns: " << houghpattern->size());
277 houghpatterns_all[id_number][level][maximum_number] = std::move(houghpattern);
281 ATH_MSG_DEBUG(
" Test for next level: " << test_for_next_level);
283 return test_for_next_level;
288 int number_of_hits =
event.size();
289 for (
int hitid = 0; hitid < number_of_hits; ++hitid) {
290 if (!event.getHit(hitid)->getAssociated()) {
return true; }
296 int number_of_hits_left = 0;
297 int number_of_hits =
event.size();
299 for (
int hitid = 0; hitid < number_of_hits; ++hitid) { number_of_hits_left += !
event.getHit(hitid)->getAssociated(); }
305 return number_of_hits_left;
311 for (
unsigned int i = 0; i < houghpattern.size(); ++i) {
312 for (
unsigned int j = 0; j < houghpattern[i].size(); ++j) {
313 if (houghpattern[i][j]) {
315 ATH_MSG_VERBOSE(
"Hit in hough pattern found level " << i <<
" max " << j <<
"hitid: " << hit->getId());
325 double weight_trigger_hits = 1.;
326 double weight_mdt_hits = 1.;
331 weight_trigger_hits = 1 - (level - 1) * (1. / (
m_maximum_level + 0.0));
332 if (weight_trigger_hits > 1) weight_trigger_hits = 1.;
333 weight_mdt_hits = weight_trigger_hits;
342 weight_trigger_hits = 1.;
343 weight_mdt_hits = 1.;
346 weight_trigger_hits = 1.;
347 weight_mdt_hits = 1.;
350 weight_trigger_hits = 1.;
351 weight_mdt_hits = 0.75;
354 weight_trigger_hits = 0.75;
355 weight_mdt_hits = 0.5;
358 weight_trigger_hits = 0.5;
359 weight_mdt_hits = 0.25;
363 weight_trigger_hits = 0.5;
364 weight_mdt_hits = 0.25;
370 for (
unsigned int i = 0; i <
event.size(); ++i) {
371 std::shared_ptr<MuonHoughHit> hit =
event.getHit(i);
373 switch (technology) {
376 case MuonHough::TGC: hit->setWeight(hit->getOrigWeight() * weight_trigger_hits);
break;
377 case MuonHough::MDT: hit->setWeight(hit->getOrigWeight() * weight_mdt_hits);
break;
384 if (weightmdt < 0.5)
return;
386 for (
unsigned int i = 0; i <
event.size(); ++i) {
387 std::shared_ptr<MuonHoughHit> hit =
event.getHit(i);
391 double p_old = hit->getOrigWeight();
392 double p_calc = 0.25 * p_old * (1. - weightmdt);
393 double p_new = p_calc / (p_calc + weightmdt * (1 - p_old));
394 ATH_MSG_VERBOSE(
" MDT probability old " << p_old <<
" Recalculated " << p_new);
395 hit->setWeight(p_new);
406 for (
unsigned int i = 0; i < houghpattern1.
size(); ++i) {
407 while (j < houghpattern2.
size()) {
417 double percentage1 = (1.0 * overlap) / houghpattern1.
size();
418 double percentage2 = (1.0 * overlap) / houghpattern2.
size();
420 ATH_MSG_DEBUG(
"Percentage Overlap: " << percentage1 <<
" " << percentage2);
426 std::unique_ptr<MuonHoughHitContainer> event_to_analyse = std::make_unique<MuonHoughHitContainer>();
431 for (
unsigned int hitid = 0; hitid <
event.size(); ++hitid) {
432 std::shared_ptr<MuonHoughHit> hit =
event.getHit(hitid);
433 if (hit->getMeasuresPhi()) {
435 event_to_analyse->addHit(hit);
441 for (
unsigned int hitid = 0; hitid <
event.size(); ++hitid) {
442 std::shared_ptr<MuonHoughHit> hit =
event.getHit(hitid);
443 event_to_analyse->addHit(hit);
449 for (
unsigned int hitid = 0; hitid <
event.size(); ++hitid) {
450 std::shared_ptr<MuonHoughHit> hit =
event.getHit(hitid);
451 if (!hit->getMeasuresPhi()) {
453 event_to_analyse->addHit(hit);
460 for (
unsigned int hitid = 0; hitid <
event.size(); ++hitid) {
461 std::shared_ptr<MuonHoughHit> hit =
event.getHit(hitid);
463 if (!hit->getMeasuresPhi()) { event_to_analyse->addHit(hit); }
467 for (
unsigned int hitid = 0; hitid <
event.size(); ++hitid) {
468 std::shared_ptr<MuonHoughHit> hit =
event.getHit(hitid);
469 if (hit->getDetectorId() ==
MuonHough::RPC) { event_to_analyse->addHit(hit); }
474 for (
unsigned int hitid = 0; hitid <
event.size(); ++hitid) {
475 std::shared_ptr<MuonHoughHit> hit =
event.getHit(hitid);
476 if (hit->getDetectorId() ==
MuonHough::MDT) { event_to_analyse->addHit(hit); }
482 return event_to_analyse;
486 double weightmdt)
const {
487 ATH_MSG_DEBUG(
"whichEventHough::size of event: " << event.size());
488 std::unique_ptr<MuonHoughHitContainer> hits_not_in_patterns{
hitsNotInPattern(event, id_number)};
489 ATH_MSG_DEBUG(
"whichEventHough::hitsNotInPattern: " << hits_not_in_patterns->size());
490 std::unique_ptr<MuonHoughHitContainer> event_to_analyse = std::make_unique<MuonHoughHitContainer>();
495 for (
unsigned int hitid = 0; hitid < hits_not_in_patterns->size(); ++hitid) {
496 std::shared_ptr<MuonHoughHit> hit = hits_not_in_patterns->getHit(hitid);
497 if (hit->getMeasuresPhi() == 1) {
500 event_to_analyse->addHit(hit);
507 for (
unsigned int hitid = 0; hitid < hits_not_in_patterns->size(); ++hitid) {
508 std::shared_ptr<MuonHoughHit> hit = hits_not_in_patterns->getHit(hitid);
509 if (
hitThroughCut(hit, weightmdt)) { event_to_analyse->addHit(hit); }
515 for (
unsigned int hitid = 0; hitid < hits_not_in_patterns->size(); ++hitid) {
516 std::shared_ptr<MuonHoughHit> hit = hits_not_in_patterns->getHit(hitid);
518 if (hit->getMeasuresPhi() == 0) {
520 event_to_analyse->addHit(hit);
528 for (
unsigned int hitid = 0; hitid < hits_not_in_patterns->size(); ++hitid) {
529 if (hits_not_in_patterns->getDetectorId(hitid) ==
MuonHough::RPC) {
530 std::shared_ptr<MuonHoughHit> hit = hits_not_in_patterns->getHit(hitid);
531 if (hit->getMeasuresPhi() == 0) { event_to_analyse->addHit(hit); }
535 for (
unsigned int hitid = 0; hitid < hits_not_in_patterns->size(); ++hitid) {
536 if (hits_not_in_patterns->getDetectorId(hitid) ==
MuonHough::RPC) {
537 std::shared_ptr<MuonHoughHit> hit = hits_not_in_patterns->getHit(hitid);
538 event_to_analyse->addHit(hit);
544 for (
unsigned int hitid = 0; hitid < hits_not_in_patterns->size(); ++hitid) {
545 if (hits_not_in_patterns->getDetectorId(hitid) ==
MuonHough::MDT) {
546 std::shared_ptr<MuonHoughHit> hit = hits_not_in_patterns->getHit(hitid);
547 if (
hitThroughCut(hit, weightmdt)) { event_to_analyse->addHit(hit); }
554 return event_to_analyse;
558 std::unique_ptr<MuonHoughTransformer> houghtransformer;
577 nbins_angle =
static_cast<int>(detectorsize_angle_xy / stepsize_per_angle_xy);
578 houghtransformer = std::make_unique<MuonHoughTransformer_xy>(nbins, nbins_angle,
m_detectorsize_xy, detectorsize_angle_xy,
601 houghtransformer = std::make_unique<MuonHoughTransformer_rzcosmics>(
608 houghtransformer = std::make_unique<MuonHoughTransformer_CurvedAtACylinder>(
615 if (houghtransformer) {
622 ATH_MSG_DEBUG(
"NBins: " << nbins <<
" angle: " << nbins_angle);
626 return std::make_unique<MuonHoughTransformSteering>(std::move(houghtransformer));
636 return maxlevel_houghpattern;
640 int maxlevel = houghpattern[id_number].size();
642 while (maxlevel >= 1 && continu == 1) {
643 unsigned int maximum_number = 0;
645 while (continu && maximum_number < houghpattern[id_number][maxlevel - 1].size())
648 <<
"maxlevel_houghpattern: " << maxlevel <<
" id: " << id_number);
649 if (!houghpattern[id_number][maxlevel - 1][maximum_number]->
empty()) { continu =
false; }
655 if (continu) { maxlevel--; }
661 double z_true = coordsmaximum.first;
662 double theta_true = coordsmaximum.second;
671 double z_rec = z_true + z_cor;
672 double theta_rec = theta_true + theta_cor;
674 if (std::cos(theta_true) < 0) {
675 z_rec = z_true - z_cor;
676 theta_rec = theta_true - theta_cor;
679 coordsmaximum.first = z_rec;
680 coordsmaximum.second = theta_rec;
684 std::unique_ptr<MuonPrdPatternCollection> phipatterncollection = std::make_unique<MuonPrdPatternCollection>();
691 std::map<MuonHoughPattern*, int> mergedpatterns;
692 for (
unsigned int i = 0; i < phipatterns.size(); ++i) {
693 for (
unsigned int j = 0; j < phipatterns[i].size(); ++j) {
694 std::unique_ptr<MuonHoughPattern>& houghpattern = phipatterns[i][j];
695 if (!houghpattern)
continue;
696 mergedpatterns[houghpattern.get()] = 0;
703 for (
unsigned int i = 0; i < phipatterns.size(); ++i) {
704 for (
unsigned int j = 0; j < phipatterns[i].size(); ++j) {
705 std::unique_ptr<MuonHoughPattern>& houghpattern1 = phipatterns[i][j];
706 if (!houghpattern1)
continue;
708 ATH_MSG_DEBUG(
" patterns size before Merge " << phipatterns[i][j]->size());
709 for (
unsigned int k = i; k < phipatterns.size(); k++) {
710 for (
unsigned int l = 0; l < phipatterns[k].size(); l++) {
711 std::unique_ptr<MuonHoughPattern>& houghpattern2 = phipatterns[k][l];
712 if (!houghpattern2)
continue;
715 if (houghpattern1.get() == houghpattern2.get())
continue;
716 if (mergedpatterns[houghpattern1.get()] == 1)
continue;
717 if (mergedpatterns[houghpattern2.get()] == 1)
continue;
718 const double phi1 = houghpattern1->getEPhi();
719 const double phi2 = houghpattern2->getEPhi();
722 double dotprod = scphi1.
cs * scphi2.
cs + scphi1.
sn * scphi2.
sn;
725 else if (dotprod < -1.)
727 double psi = std::acos(dotprod);
728 const double the1 = houghpattern1->getETheta();
729 const double the2 = houghpattern2->getETheta();
732 dotprod = scthe1.
cs * scthe2.
cs + scthe1.
sn * scthe2.
sn;
735 else if (dotprod < -1.)
737 double chi = std::acos(dotprod);
738 ATH_MSG_DEBUG(
" patterns phi1 " << phi1 <<
" phi2 " << phi2 <<
" psi " << psi);
739 ATH_MSG_DEBUG(
" patterns the1 " << the1 <<
" the2 " << the2 <<
" chi " << chi);
740 if (chi < 0.5 || psi < 0.5) {
742 ATH_MSG_DEBUG(
" Phi Overlap " << overlap <<
" size1 " << houghpattern1->size() <<
" size2 "
743 << houghpattern2->size());
744 int ns1 = houghpattern1->size();
745 int ns2 = houghpattern2->size();
746 if (overlap <= ns1 && overlap == ns2) {
748 mergedpatterns[houghpattern2.get()] = 1;
751 if (overlap == ns1 && overlap < ns2) {
753 mergedpatterns[houghpattern1.get()] = 1;
758 std::unique_ptr<Muon::MuonPrdPattern> muonpattern;
759 if ((overlap > 0.8 * ns1 || overlap > 0.8 * ns2) && ns1 >= ns2) {
762 if ((overlap > 0.8 * ns1 || overlap > 0.8 * ns2) && ns1 < ns2) {
767 phipatterncollection->push_back(std::move(muonpattern));
768 mergedpatterns[houghpattern1.get()] = 1;
769 mergedpatterns[houghpattern2.get()] = 1;
779 for (
unsigned int i = 0; i < phipatterns.size(); ++i) {
780 for (
unsigned int j = 0; j < phipatterns[i].size(); ++j) {
781 std::unique_ptr<MuonHoughPattern>& houghpattern = phipatterns[i][j];
782 if (!houghpattern) {
continue; }
783 if (mergedpatterns[houghpattern.get()] == 1)
continue;
785 if (!phipatterns[i][j]->
empty()) {
786 std::unique_ptr<Muon::MuonPrdPattern> muonpattern;
795 ATH_MSG_DEBUG(
" Lift MuonPhiPattern size " << muonpattern->numberOfContainedPrds());
797 phipatterncollection->push_back(std::move(muonpattern));
803 return phipatterncollection;
807 std::unique_ptr<MuonPrdPatternCollection> etapatterncollection = std::make_unique<MuonPrdPatternCollection>();
811 if (
m_use_curvedhough) maximum_number_of_patterns = 2 * maximum_number_of_patterns;
813 etapatterncollection->reserve(maximum_number_of_patterns);
818 ATH_MSG_DEBUG(
" GetEtaMuonPatterns Use RZ curved hough patterns ");
821 ATH_MSG_DEBUG(
" GetEtaMuonPatterns Use curved hough patterns ");
830 std::map<MuonHoughPattern*, int> mergedpatterns;
831 for (
unsigned int i = 0; i < etapatterns.size(); ++i) {
832 for (
unsigned int j = 0; j < etapatterns[i].size(); ++j) {
833 std::unique_ptr<MuonHoughPattern>& houghpattern = etapatterns[i][j];
834 if (!houghpattern)
continue;
835 mergedpatterns[houghpattern.get()] = 0;
842 for (
unsigned int i = 0; i < etapatterns.size(); ++i) {
843 for (
unsigned int j = 0; j < etapatterns[i].size(); ++j) {
844 std::unique_ptr<MuonHoughPattern>& houghpattern1 = etapatterns[i][j];
845 if (!houghpattern1)
continue;
847 ATH_MSG_DEBUG(
" Eta patterns size before Merge " << etapatterns[i][j]->size());
848 for (
unsigned int k = i; k < etapatterns.size(); k++) {
849 for (
unsigned int l = 0; l < etapatterns[k].size(); l++) {
850 std::unique_ptr<MuonHoughPattern>& houghpattern2 = etapatterns[k][l];
851 if (!houghpattern2)
continue;
854 if (houghpattern1.get() == houghpattern2.get())
continue;
855 if (mergedpatterns[houghpattern1.get()] == 1)
continue;
856 if (mergedpatterns[houghpattern2.get()] == 1)
continue;
861 double curv1 = houghpattern1->getECurvature();
862 double curv2 = houghpattern2->getECurvature();
863 if (std::abs(curv1) < 1001. || std::abs(curv2) < 1001.) {
864 ATH_MSG_DEBUG(
"Curvature too small, should not be possible: " << curv1 <<
" " << curv2);
868 double angle1 = std::acos((std::abs(curv1) - 1000.) / curv1);
869 double angle2 = std::acos((std::abs(curv2) - 1000.) / curv2);
870 alpha = std::abs(std::sin(angle1 - angle2));
872 ATH_MSG_DEBUG(
" patterns curv1 " << curv1 <<
" curv2 " << curv2 <<
" alpha " << alpha);
875 double phi1 = houghpattern1->getEPhi();
876 double phi2 = houghpattern2->getEPhi();
877 double dotprod = std::cos(phi1) * std::cos(phi2) + std::sin(phi1) * std::sin(phi2);
880 else if (dotprod < -1.)
882 double psi = std::acos(dotprod);
883 double the1 = houghpattern1->getETheta();
884 double the2 = houghpattern2->getETheta();
885 dotprod = std::cos(the1) * std::cos(the2) + std::sin(the1) * std::sin(the2);
888 else if (dotprod < -1.)
890 double chi = std::acos(dotprod);
892 ATH_MSG_DEBUG(
" patterns phi1 " << phi1 <<
" phi2 " << phi2 <<
" psi " << psi);
893 ATH_MSG_DEBUG(
" patterns the1 " << the1 <<
" the2 " << the2 <<
" chi " << chi);
895 if (chi < 0.5 && psi < 0.5 && alpha < 0.05) {
898 const int ns1 = houghpattern1->size();
899 const int ns2 = houghpattern2->size();
901 ATH_MSG_DEBUG(
" Eta Overlap " << overlap <<
" size1 " << ns1 <<
" size2 " << ns2);
903 if (overlap == ns2 && overlap <= ns1) {
905 mergedpatterns[houghpattern2.get()] = 1;
908 if (overlap == ns1 && overlap < ns2) {
910 mergedpatterns[houghpattern1.get()] = 1;
913 std::unique_ptr<Muon::MuonPrdPattern> muonpattern;
915 if ((overlap > 0.8 * ns1 || overlap > 0.8 * ns2) && ns1 >= ns2) {
918 if ((overlap > 0.8 * ns1 || overlap > 0.8 * ns2) && ns1 < ns2) {
922 etapatterncollection->push_back(std::move(muonpattern));
923 mergedpatterns[houghpattern1.get()] = 1;
924 mergedpatterns[houghpattern2.get()] = 1;
933 for (
unsigned int i = 0; i < etapatterns.size(); ++i) {
934 for (
unsigned int j = 0; j < etapatterns[i].size(); ++j) {
935 std::unique_ptr<MuonHoughPattern>& houghpattern = etapatterns[i][j];
936 if (!houghpattern) {
continue; }
937 if (mergedpatterns[houghpattern.get()] == 1)
continue;
939 if (!etapatterns[i][j]->
empty()) {
943 etapatterncollection->push_back(std::move(muonpattern));
944 ATH_MSG_DEBUG(
" Lift MuonEtaPattern size " << etapatterns[i][j]->size());
950 return etapatterncollection;
954 std::unique_ptr<MuonPrdPatternCollection> curvedpatterncollection = std::make_unique<MuonPrdPatternCollection>();
958 curvedpatterncollection->reserve(maximum_number_of_patterns);
961 for (
unsigned int i = 0; i < curvedpatterns.size(); ++i) {
962 for (
unsigned int j = 0; j < curvedpatterns[i].size(); ++j) {
963 std::unique_ptr<MuonHoughPattern>& houghpattern = curvedpatterns[i][j];
964 if (!houghpattern) {
continue; }
966 if (!curvedpatterns[i][j]->
empty()) {
968 curvedpatterncollection->push_back(std::move(muonpattern));
969 ATH_MSG_DEBUG(
" Lift MuoncurvedPattern size " << curvedpatterns[i][j]->size());
973 return curvedpatterncollection;
983 double charge = curvature < 0 ? -1 : 1.;
984 double pscale = std::abs(curvature);
994 ATH_MSG_DEBUG(
"position: " << x0 <<
" " << y0 <<
" " << position[2]);
995 ATH_MSG_DEBUG(
"direction: " << direction[0] <<
" " << direction[1] <<
" " << direction[2]);
997 ATH_MSG_DEBUG(
" Lift Eta Hough Pattern with charge " <<
charge <<
" Curvature " << pscale);
998 std::unique_ptr<Muon::MuonPrdPattern> muonpattern = std::make_unique<Muon::MuonPrdPattern>(pos, dir);
1000 for (
unsigned int i = 0; i < houghpattern.
size(); ++i) { muonpattern->addPrd(houghpattern.
getPrd(i)); }
1010 ATH_MSG_DEBUG(
"position: " << pos[0] <<
" " << pos[1] <<
" " << pos[2]);
1011 ATH_MSG_DEBUG(
"direction: " << dir[0] <<
" " << dir[1] <<
" " << dir[2]);
1012 std::unique_ptr<Muon::MuonPrdPattern> muonpattern = std::make_unique<Muon::MuonPrdPattern>(pos, dir);
1014 for (
unsigned int i = 0; i < houghpattern.
size(); ++i) {
1015 muonpattern->addPrd(houghpattern.
getPrd(i));
1027 const int ns1 = houghpattern1.
size();
1028 const int ns2 = houghpattern2.
size();
1030 const double the1 = houghpattern1.
getETheta();
1031 const double the2 = houghpattern2.
getETheta();
1032 const double theta = (ns1 * the1 + ns2 * the2) / (ns1 + ns2);
1034 const double phi1 = houghpattern1.
getEPhi();
1035 const double phi2 = houghpattern2.
getEPhi();
1036 const double cos_phi = (ns1 * std::cos(phi1) + ns2 * std::cos(phi2)) / (ns1 + ns2);
1037 const double sin_phi = (ns1 * std::sin(phi1) + ns2 * std::sin(phi2)) / (ns1 + ns2);
1038 const double phi = std::atan2(sin_phi, cos_phi);
1045 const double z0 = (ns1 * position1[2] + ns2 * position2[2]) / (ns1 + ns2);
1047 const double invcur = (ns1 * invcur1 + ns2 * invcur2) / (ns1 + ns2);
1049 ATH_MSG_DEBUG(
"Start Making one eta pattern theta " <<
theta <<
" phi " <<
phi <<
" invcur " << invcur);
1051 ATH_MSG_DEBUG(
"eta patterns theta1 " << the1 <<
" theta2 " << the2 <<
" phi1 " << phi1 <<
" phi2 " << phi2 <<
" invcur1 " << invcur1
1052 <<
" invcur2 " << invcur2 <<
" ns1 " << ns1 <<
" ns2 " << ns2);
1054 ATH_MSG_DEBUG(
" z values " << z0 <<
" z1 " << position1[2] <<
" z2 " << position2[2]);
1058 if (ns1 + ns2 < 2)
return nullptr;
1060 double invcurvature = invcur;
1062 if (invcurvature < 0)
charge = -1;
1064 if (invcurvature != 0) pscale = 1. / std::abs(invcurvature);
1069 r0 = (ns1 * houghpattern1.
getERPhi() + ns2 * houghpattern2.
getERPhi()) / (ns1 + ns2);
1073 double x0 =
charge * r0 * sin_phi;
1074 double y0 = -
charge * r0 * cos_phi;
1082 std::unique_ptr<Muon::MuonPrdPattern> muonpattern = std::make_unique<Muon::MuonPrdPattern>(pos, dir);
1085 for (
unsigned int i = 0; i < houghpattern1.
size(); ++i) {
1086 double the = houghpattern1.
getTheta(i);
1087 muonpattern->addPrd(houghpattern1.
getPrd(i));
1092 for (
unsigned int i = 0; i < houghpattern2.
size(); ++i) {
1094 double the = houghpattern2.
getTheta(i);
1095 for (
unsigned int j = 0; j < houghpattern1.
size(); ++j) {
1096 if (houghpattern2.
getPrd(i) == houghpattern1.
getPrd(j)) accept =
false;
1099 muonpattern->addPrd(houghpattern2.
getPrd(i));
1119 double cos_phi{0.}, sin_phi{0.};
1121 for (
unsigned int i = 0; i < houghpattern1.
size(); ++i) {
1123 cos_phi += std::cos(
phi);
1124 sin_phi += std::sin(
phi);
1127 for (
unsigned int i = 0; i < houghpattern2.
size(); ++i) {
1130 for (
unsigned int j = 0; j < houghpattern1.
size(); ++j) {
1131 if (houghpattern2.
getPrd(i) == houghpattern1.
getPrd(j)) accept =
false;
1134 cos_phi += std::cos(
phi);
1135 sin_phi += std::sin(
phi);
1140 ATH_MSG_VERBOSE(
"Start Merged Phi hits cleaning with " << nphi <<
" hits ");
1143 if (nphi < 2)
return nullptr;
1145 double cphit = cos_phi / nphi;
1146 double sphit = sin_phi / nphi;
1152 for (
unsigned int i = 0; i < houghpattern1.
size(); ++i) {
1154 double dotprod = cphit * std::cos(
phi) + sphit * std::sin(
phi);
1155 if (dotprod > 0.95) {
1156 cos_phi += std::cos(
phi);
1157 sin_phi += std::sin(
phi);
1162 for (
unsigned int i = 0; i < houghpattern2.
size(); ++i) {
1164 double dotprod = cphit * std::cos(
phi) + sphit * std::sin(
phi);
1165 if (dotprod > 0.95) {
1167 for (
unsigned int j = 0; j < houghpattern1.
size(); ++j) {
1168 if (houghpattern2.
getPrd(i) == houghpattern1.
getPrd(j)) accept =
false;
1171 cos_phi += std::cos(
phi);
1172 sin_phi += std::sin(
phi);
1178 if (nphi < 2)
return nullptr;
1179 cphit = cos_phi / nphi;
1180 sphit = sin_phi / nphi;
1185 for (
unsigned int i = 0; i < houghpattern1.
size(); ++i) {
1187 double dotprod = cphit * std::cos(
phi) + sphit * std::sin(
phi);
1188 if (dotprod > 0.99) {
1189 cos_phi += std::cos(
phi);
1190 sin_phi += std::sin(
phi);
1194 for (
unsigned int i = 0; i < houghpattern2.
size(); ++i) {
1196 double dotprod = cphit * std::cos(
phi) + sphit * std::sin(
phi);
1197 if (dotprod > 0.99) {
1199 for (
unsigned int j = 0; j < houghpattern1.
size(); ++j) {
1200 if (houghpattern2.
getPrd(i) == houghpattern1.
getPrd(j)) accept =
false;
1203 cos_phi += std::cos(
phi);
1204 sin_phi += std::sin(
phi);
1209 if (nphi < 2)
return nullptr;
1210 cphit = cos_phi / nphi;
1211 sphit = sin_phi / nphi;
1217 for (
unsigned int i = 0; i < houghpattern1.
size(); ++i) {
1219 double thetah = houghpattern1.
getTheta(i);
1220 double dotprod = cphit * std::cos(
phi) + sphit * std::sin(
phi);
1221 if (dotprod > 0.995) {
1222 cos_phi += std::cos(
phi);
1223 sin_phi += std::sin(
phi);
1228 for (
unsigned int i = 0; i < houghpattern2.
size(); ++i) {
1230 double thetah = houghpattern2.
getTheta(i);
1231 double dotprod = cphit * std::cos(
phi) + sphit * std::sin(
phi);
1232 if (dotprod > 0.995) {
1234 for (
unsigned int j = 0; j < houghpattern1.
size(); ++j) {
1235 if (houghpattern2.
getPrd(i) == houghpattern1.
getPrd(j)) accept =
false;
1238 cos_phi += std::cos(
phi);
1239 sin_phi += std::sin(
phi);
1245 if (nphi < 2)
return nullptr;
1246 cphit = cos_phi / nphi;
1247 sphit = sin_phi / nphi;
1251 double x0 = r0 * sphit;
1252 double y0 = -r0 * cphit;
1258 std::unique_ptr<Muon::MuonPrdPattern> muonpattern = std::make_unique<Muon::MuonPrdPattern>(pos, dir);
1261 for (
unsigned int i = 0; i < houghpattern1.
size(); ++i) {
1263 double dotprod = cphit * std::cos(
phi) + sphit * std::sin(
phi);
1264 if (dotprod > 0.995) {
1265 muonpattern->addPrd(houghpattern1.
getPrd(i));
1273 for (
unsigned int i = 0; i < houghpattern2.
size(); ++i) {
1275 double dotprod = cphit * std::cos(
phi) + sphit * std::sin(
phi);
1276 if (dotprod > 0.995) {
1278 for (
unsigned int j = 0; j < houghpattern1.
size(); ++j) {
1279 if (houghpattern2.
getPrd(i) == houghpattern1.
getPrd(j)) accept =
false;
1282 muonpattern->addPrd(houghpattern2.
getPrd(i));
1305 if (msgLevel(MSG::VERBOSE)) {
1306 for (
unsigned int i = 0; i < houghpattern.
size(); ++i) {
1307 const std::shared_ptr<MuonHoughHit> hit = houghpattern.
getHit(i);
1308 ATH_MSG_VERBOSE(hit->getHitx() <<
" " << hit->getHity() <<
" " << hit->getHitz() <<
" " << hit->getPhi() <<
" "
1309 << hit->getMeasuresPhi() <<
" " << hit->getWhichDetector() <<
" " << hit->getWeight() <<
" "
1310 << hit->getAssociated());
1315 unsigned int size = houghpattern.
size();
1317 double r0 = houghpattern.
getERPhi();
1319 ATH_MSG_DEBUG(
"Start Phi hits cleaning with " << size <<
" hits "
1320 <<
" theta " <<
theta);
1323 unsigned int newsize = houghpattern.
size();
1329 const int number_of_iterations = 4;
1330 static constexpr std::array<double, number_of_iterations> cutvalues{1000., 500., 250., 125.};
1333 std::unique_ptr<MuonHoughPattern> pat_owner{};
1334 for (
int it = 0; it < number_of_iterations; it++) {
1339 double max_dist = 0.;
1340 unsigned int max_i = UINT_MAX;
1341 for (
unsigned int i = 0; i < newpattern->
size(); ++i) {
1342 double dist = newpattern->
getHitx(i) * scphi.
sn - newpattern->
getHity(i) * scphi.
cs - r0;
1344 if (dist > max_dist) {
1349 if (max_dist < cutvalues[it]) {
1352 std::unique_ptr<MuonHoughPattern> newpattern2 = std::make_unique<MuonHoughPattern>(
MuonHough::hough_xy);
1353 for (
unsigned int i = 0; i < newpattern->
size(); ++i) {
1354 if (i != max_i) { newpattern2->addHit(newpattern->
getHit(i)); }
1356 newpattern2->updateParametersRPhi();
1357 phi = newpattern2->getEPhi();
1358 r0 = newpattern2->getERPhi();
1359 newsize = newpattern2->size();
1360 pat_owner = std::move(newpattern2);
1361 newpattern = pat_owner.get();
1367 ATH_MSG_DEBUG(
"Final size: " << newsize <<
" r0: " << r0 <<
" phi: " <<
phi);
1369 double thetanew = 0.;
1370 for (
unsigned int i = 0; i < newpattern->
size(); ++i) {
1371 double thetah = newpattern->
getTheta(i);
1375 thetanew = thetanew / (newpattern->
size() + 1e-7);
1378 double x0_new = r0_new * scphi.
sn;
1379 double y0_new = -r0_new * scphi.
cs;
1387 std::unique_ptr<Muon::MuonPrdPattern> muonpattern = std::make_unique<Muon::MuonPrdPattern>(pos, dir);
1389 for (
unsigned int i = 0; i < newpattern->
size(); ++i) { muonpattern->addPrd(newpattern->
getPrd(i)); }
1391 ATH_MSG_DEBUG(
"END Clean Phi hits " << newsize <<
" theta " << thetanew);
1399 std::unique_ptr<MuonHoughHitContainer> hits_not_in_patterns = std::make_unique<MuonHoughHitContainer>();
1401 for (
unsigned int hitid = 0; hitid <
event.size(); ++hitid) {
1402 if (!event.getHit(hitid)->getAssociated()) { hits_not_in_patterns->addHit(event.getHit(hitid)); }
1404 return hits_not_in_patterns;
1407 unsigned int thresholdpattern = 0;
1408 switch (id_number) {
1418 return thresholdpattern;
1422 double thresholdhisto = 0.;
1423 switch (id_number) {
1433 return thresholdhisto;
1441 int mdthits =
event.getMDThitno();
1442 weightmdt = mdthits > 0. ? 1. - 5. / std::sqrt(mdthits) : 0.;
1462 ATH_MSG_VERBOSE(
"mdt " << k <<
" x: " << gpos.x() <<
" y: " << gpos.y() <<
" z: " << gpos.z());
1463 }
else if (!mdtprd) {
1467 ATH_MSG_VERBOSE(
"cluster " << k <<
" x: " << gpos.x() <<
" y: " << gpos.y() <<
" z: " << gpos.z());
Scalar phi() const
phi method
Scalar theta() const
theta method
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
double charge(const T &p)
std::vector< std::unique_ptr< MuonHoughPattern > > MuonHoughPatternCollection
This typedef represents a collection and container of MuonHoughPattern objects.
std::vector< MuonHoughPatternContainer > MuonHoughPatternContainerShip
std::vector< MuonHoughPatternCollection > MuonHoughPatternContainer
static const Attributes_t empty
bool msgLvl(const MSG::Level lvl) const
virtual const Trk::Surface & surface() const override final
Return surface associated with this detector element.
unsigned int size() const
returns size of hitcontainer
double getHitx(unsigned int hitno) const
returns x position of hit hitno
double getPhi(unsigned int hitno) const
returns phi of hit hitno
double getHity(unsigned int hitno) const
returns y position of hit hitno
std::shared_ptr< MuonHoughHit > getHit(int hitno) const
returns Hit at position hitno
int getHitId(unsigned int hitno) const
returns hitid of hit hitno
bool getMeasuresPhi(unsigned int hitno) const
returns if hit hitno measures phi
const Trk::PrepRawData * getPrd(unsigned int hitno) const
returns preprawdata pointer of hit hitno
double getTheta(unsigned int hitno) const
returns theta of hit hitno
Amg::Vector3D getEPos() const
calulates 3d point closest to ip
double getEPhi() const
returns phi of pattern
void updateParametersRPhi(bool cosmics=false)
update parameters in rphi plane based on weighted fit
double getERPhi() const
returns r0/d0 of pattern
Amg::Vector3D getEDir() const
calculates direction at point closest to ip
double getECurvature() const
returns curvature of pattern
double getETheta() const
returns theta of pattern
Class to represent measurements from the Monitored Drift Tubes.
virtual const MuonGM::MdtReadoutElement * detectorElement() const override
Returns the detector element corresponding to this PRD.
Class representing clusters in the muon system.
virtual const Amg::Vector3D & globalPosition() const =0
Returns the global position of the measurement (calculated on the fly)
Class to store a pattern in the muon system containing PrepRawData pointers.
virtual unsigned int numberOfContainedPrds() const
Number or PrepRawData contained by this Pattern.
virtual const Trk::PrepRawData * prd(unsigned int index) const
returns the PrepRawData objects depending on the integer, return zero if index out of range
Identifier identify() const
return the identifier
Abstract Base Class for tracking surfaces.
const Amg::Vector3D & center() const
Returns the center position of the Surface.
Eigen::Matrix< double, 3, 1 > Vector3D
@ hough_curved_at_a_cylinder
DetectorTechnology
enum to identify the muondetectortechnology
Helper to simultaneously calculate sin and cos of the same angle.
Helper to simultaneously calculate sin and cos of the same angle.