12#include "GaudiKernel/ConcurrencyFlags.h"
37 inline double radius()
const {
return prd->localPosition()[0]; }
54 declareInterface<IMuonHoughPatternFinderTool>(
this);
59 if (Gaudi::Concurrency::ConcurrencyFlags::numThreads() > 1) {
60 ATH_MSG_FATAL(
"Filling histograms not supported in MT jobs.");
61 return StatusCode::FAILURE;
64 m_h = std::make_unique<Hists>();
65 m_h->m_file = std::make_unique<TFile>(
"Hough_histos.root",
"RECREATE");
66 m_h->m_weighthistogram = std::make_unique<TH1F>(
"weighthisto",
"weighthisto", 100, -0.5, 2);
67 m_h->m_weighthistogrammdt = std::make_unique<TH1F>(
"weighthistomdt",
"weighthistomdt", 100, -0.3, 2.2);
68 m_h->m_weighthistogramrpc = std::make_unique<TH1F>(
"weighthistorpc",
"weighthistorpc", 100, -0.3, 2.2);
69 m_h->m_weighthistogramcsc = std::make_unique<TH1F>(
"weighthistocsc",
"weighthistocsc", 100, -0.3, 2.2);
70 m_h->m_weighthistogramtgc = std::make_unique<TH1F>(
"weighthistotgc",
"weighthistotgc", 100, -0.3, 2.2);
71 m_h->m_weighthistogramstgc = std::make_unique<TH1F>(
"weighthistostgc",
"weighthistostgc", 100, -0.3, 2.2);
72 m_h->m_weighthistogrammm = std::make_unique<TH1F>(
"weighthistomm",
"weighthistomm", 100, -0.3, 2.2);
103 return StatusCode::SUCCESS;
107 if (!cont)
return {};
108 std::vector<const MuonPrepDataCollection<T>*>
vec;
110 std::transform(cont->
begin(), cont->
end(), std::back_inserter(
vec),
117 const EventContext& ctx)
const {
122 const std::vector<const CscPrepDataCollection*>& cscCols,
123 const std::vector<const TgcPrepDataCollection*>& tgcCols,
124 const std::vector<const RpcPrepDataCollection*>& rpcCols,
126 return find(ctx, mdtCols, cscCols, tgcCols, rpcCols, {}, {}, cscSegmentCombis);
129 const std::vector<const MdtPrepDataCollection*>& mdtCols,
130 const std::vector<const CscPrepDataCollection*>& cscCols,
131 const std::vector<const TgcPrepDataCollection*>& tgcCols,
132 const std::vector<const RpcPrepDataCollection*>& rpcCols,
133 const std::vector<const sTgcPrepDataCollection*>& stgcCols,
134 const std::vector<const MMPrepDataCollection*>& mmCols,
138 std::map<int, std::vector<std::pair<int, int>>> rpcmdtstationmap;
141 std::map<int, std::vector<std::pair<int, int>>> tgcmdtstationmap;
149 std::unique_ptr<MuonHoughHitContainer> hitcontainer{
150 getAllHits(mdtCols, tgcCols, rpcCols, cscSegmentCombis, rpcmdtstationmap, tgcmdtstationmap, phietahitassociation)};
162 std::unique_ptr<MuonPatternCombinationCollection> patCombiCol =
analyse(ctx, *hitcontainer,
163 phietahitassociation);
168 ATH_MSG_DEBUG(
" NO pattern combinations found, creating empty collection ");
169 patCombiCol = std::make_unique<MuonPatternCombinationCollection>();
173 ATH_MSG_INFO(
" summarizing Combined pattern combination output: " <<std::endl <<
m_printer->print(*patCombiCol));
178 return {std::move(patCombiCol),
nullptr};
183 auto save_histo = [
this](std::unique_ptr<TH1>& h_ptr) {
185 m_h->m_file->WriteObject(h_ptr.get(), h_ptr->GetName());
188 save_histo(
m_h->m_weighthistogram);
189 save_histo(
m_h->m_weighthistogrammdt);
190 save_histo(
m_h->m_weighthistogramrpc);
191 save_histo(
m_h->m_weighthistogramcsc);
192 save_histo(
m_h->m_weighthistogramtgc);
193 save_histo(
m_h->m_weighthistogramstgc);
194 save_histo(
m_h->m_weighthistogrammm);
199 return StatusCode::SUCCESS;
207 if (
msgLvl(MSG::VERBOSE)) {
208 std::stringstream sstr{};
209 for (
size_t h = 0;
h < hitcontainer.
size() ; ++
h){
210 const auto& houghHit = hitcontainer.
getHit(
h);
211 sstr<<
m_printer->print(*houghHit->getPrd())<<
" weight: "<<houghHit->getWeight()<<std::endl;
224 std::unique_ptr<MuonPrdPatternCollection> phipatterns{
m_muonHoughPatternTool->getPhiMuonPatterns(houghpattern)};
225 std::unique_ptr<MuonPrdPatternCollection> etapatterns{
m_muonHoughPatternTool->getEtaMuonPatterns(houghpattern)};
228 if (phipatterns->empty())
229 ATH_MSG_INFO(
" summarizing input: Phi pattern combination empty");
231 ATH_MSG_INFO(
" summarizing Phi pattern combination input: " << std::endl <<
m_printer->print(*phipatterns));
232 if (etapatterns->empty())
233 ATH_MSG_INFO(
" summarizing input: Eta pattern combination empty");
235 ATH_MSG_INFO(
" summarizing Eta pattern combination input: " << std::endl <<
m_printer->print(*etapatterns));
239 ATH_MSG_DEBUG(
"size: phi: " << phipatterns->size() <<
" eta: " << etapatterns->size());
241 std::unique_ptr<MuonPrdPatternCollection> combinedpatterns;
242 std::unique_ptr<MuonPatternCombinationCollection> patterncombinations{};
245 if (!etapatterns->empty()) {
246 combinedpatterns =
m_muonCombinePatternTool->combineEtaPhiPatterns(*phipatterns, *etapatterns, phietahitassociation);
249 if (combinedpatterns) {
253 combinedpatterns = std::make_unique<MuonPrdPatternCollection>();
260 return patterncombinations;
264 const std::vector<const MdtPrepDataCollection*>& mdtCols,
265 const std::vector<const TgcPrepDataCollection*>& tgcCols,
const std::vector<const RpcPrepDataCollection*>& rpcCols,
267 std::map<
int, std::vector<std::pair<int, int>>>& tgcmdtstationmap,
271 std::unique_ptr<MuonHoughHitContainer> hitcontainer = std::make_unique<MuonHoughHitContainer>();
275 hitcontainer->reserve(5000);
278 std::set<Identifier> csc_set;
280 std::pair<std::set<Identifier>::iterator,
bool> csc_pair;
281 std::map<int, int> nHitsPerLayer;
285 std::vector<const Muon::CscClusterOnTrack*> csc_rots;
287 std::vector<int> layer_ids;
289 csc_rots.reserve(400);
291 layer_ids.reserve(400);
296 for (
unsigned int ss = 0;
ss < msc->numberOfStations(); ++
ss) {
297 for (
const std::unique_ptr<MuonSegment>& ms : *msc->stationSegments(
ss)) {
304 std::vector<const Trk::PrepRawData*> eta_vector;
306 int nRoTs = ms->numberOfContainedROTs();
307 for (
int i = 0; i < nRoTs; ++i) {
310 ATH_MSG_INFO(
"Dynamic cast to CscClusterOnTrack failed!");
313 csc_rots.push_back(cscOnSeg);
315 bool channel_type =
m_idHelperSvc->cscIdHelper().measuresPhi(
id);
316 csc_pair = csc_set.insert(
id);
317 if (!csc_pair.second) {
318 ATH_MSG_DEBUG(
" CSC hit was already added, weight set to 0");
319 layer_ids.push_back(0);
321 const int layer_id = 1000 *
m_idHelperSvc->cscIdHelper().stationEta(
id) +
324 2 *
m_idHelperSvc->cscIdHelper().wireLayer(
id) + channel_type;
326 ++nHitsPerLayer[layer_id];
327 layer_ids.push_back(layer_id);
337 if (!phi_set.empty()) {
338 ATH_MSG_VERBOSE(
"Number of Phi Csc hits in segment: " << phi_set.size());
339 for (
const Trk::PrepRawData* prd : eta_vector) { phietahitassociation.insert(std::make_pair(prd, phi_set)); }
345 for (
unsigned int i = 0; i < csc_rots.size(); i++) {
348 const Amg::Vector3D& globalpos = csc_rots[i]->globalPosition();
349 bool channel_type =
m_idHelperSvc->cscIdHelper().measuresPhi(csc_rots[i]->identify());
352 if (layer_ids[i] != 0) {
353 double number_of_hits = (double)nHitsPerLayer[layer_ids[i]];
358 std::shared_ptr<MuonHoughHit> hit = std::make_shared<MuonHoughHit>(globalpos, channel_type,
MuonHough::CSC, 1., weight, prd);
360 hitcontainer->addHit(hit);
363 h.m_weighthistogram->Fill(weight);
364 h.m_weighthistogramcsc->Fill(weight);
373 addRpcCollection(rpc_coll, *hitcontainer, rpcmdtstationmap, phietahitassociation);
379 addTgcCollection(tgc_coll, *hitcontainer, tgcmdtstationmap, phietahitassociation);
385 addMdtCollection(prep_coll, *hitcontainer, rpcmdtstationmap, tgcmdtstationmap);
391 if (msgLevel(MSG::VERBOSE)) {
392 ATH_MSG_VERBOSE(
"MuonHoughPatternFinderTool::getAllHits() saving " << hitcontainer->size() <<
" converted hits");
393 for (
unsigned int i = 0; i < hitcontainer->size(); i++) {
394 ATH_MSG_VERBOSE(
" hit " << hitcontainer->getHit(i)->getWhichDetector() <<
" (" << hitcontainer->getHit(i)->getHitx() <<
","
395 << hitcontainer->getHit(i)->getHity() <<
"," << hitcontainer->getHit(i)->getHitz() <<
") "
396 <<
" weight: " << hitcontainer->getHit(i)->getWeight()
397 <<
" measures phi: " << hitcontainer->getHit(i)->getMeasuresPhi());
401 ATH_MSG_VERBOSE(
"MuonHoughPatternFinderTool::getAllHits() saving " << phietahitassociation.size() <<
"associated hits ");
415 ATH_MSG_DEBUG(
"Deleted patterns: " << patCol->size() <<
" at " << key.key());
420 StatusCode
sc = handle.
record(std::move(patCol));
421 if (
sc.isFailure()) {
424 ATH_MSG_DEBUG(
"Saved patterns: " << patCol->size() <<
" at " << key.key());
430 std::map<
int, std::vector<std::pair<int, int>>>& rpcmdtstationmap,
432 std::set<int> layers;
434 int size_begin = hitcontainer.
size();
435 addCollection(*rpc_coll, hitcontainer, phietahitassociation);
436 int size_end = hitcontainer.
size();
443 std::map<
int, std::vector<std::pair<int, int>>>& tgcmdtstationmap,
446 int size_begin = hitcontainer.
size();
447 addCollection(*tgc_coll, hitcontainer, phietahitassociation);
448 int size_end = hitcontainer.
size();
453 std::map<
int, std::vector<std::pair<int, int>>>& rpcmdtstationmap,
454 std::map<
int, std::vector<std::pair<int, int>>>& tgcmdtstationmap)
const {
455 const unsigned int size = mdt_coll->
size();
459 auto new_mdt_hit = [](
const Muon::MdtPrepData* mdt_hit,
double prob,
double weight) {
470 double occupancy = (double)size / (
double)channels;
472 ATH_MSG_DEBUG(
" size: " << size <<
" channels: " << channels <<
" occupancy: " << occupancy);
479 <<
" association to pattern still possible");
485 hitcontainer.
addHit(new_mdt_hit(mdt_hit, 0., 0.));
492 std::map<int, int> nHitsPerLayer;
493 std::map<int, int> number_of_hots_per_layer;
496 std::vector<SegmentData> collected_data{};
497 collected_data.reserve(size);
499 std::vector<double> tubecount(idHelper.
tubeMax() + 2);
515 prd_data.
index = collected_data.size();
518 const int tube = idHelper.
tube(prd_data.
id());
519 const int multi_layer = idHelper.
multilayer(prd_data.
id());
520 const int tube_layer = idHelper.
tubeLayer(prd_data.
id());
523 (multi_layer - 1) * idHelper.
tubeLayerMax() + (tube_layer - 1);
525 tubecount[tube] += 1.;
526 tubecount[tube - 1] += 0.5;
527 tubecount[tube + 1] += 0.5;
530 <<
" tube_layer: " << tube_layer);
531 collected_data.push_back(std::move(prd_data));
534 const unsigned int prdsize = collected_data.size();
536 if (!prdsize)
return;
539 for (
const SegmentData& mdt_hit : collected_data) {
541 hitcontainer.
addHit(new_mdt_hit(mdt_hit.prd, 1., 1.));
546 double tubem = *(std::max_element(tubecount.begin(), tubecount.end()));
551 for (
const SegmentData& mdt_hit : collected_data) {
553 hitcontainer.
addHit(new_mdt_hit(mdt_hit.prd, 0., 0.));
556 h.m_weighthistogram->Fill(0);
557 h.m_weighthistogrammdt->Fill(0);
567 const int tube = idHelper.
tube(mdt_hit.id());
568 if (tubecount[tube] > 1) ++nHitsPerLayer[mdt_hit.layer_number];
571 if (tubecount[tube] <= 1.) mdt_hit.prob = 0.;
575 for (
const auto& map_it : nHitsPerLayer) {
576 const bool count_1 = map_it.first >= idHelper.
tubeLayerMax();
582 if (ml1 + ml2 < 2.01) {
584 for (
const SegmentData& mdt_hit : collected_data) {
586 hitcontainer.
addHit(new_mdt_hit(mdt_hit.prd, 0., 0.));
589 h.m_weighthistogram->Fill(0);
590 h.m_weighthistogrammdt->Fill(0);
597 dcs.reserve(prdsize);
599 for (
const SegmentData& mdt_hit : collected_data) {
600 if (mdt_hit.prob < 0.01)
continue;
609 mdtHelper.
tube(hitId) - 1);
617 dcs.emplace_back(std::move(dc));
620 bool seg_found =
true;
622 std::vector<int>
sel(dcs.size());
623 double angleDif = 0.;
627 if (ml1 + ml2 >= 2.1) {
628 int removed_hits = 0;
629 for (
unsigned int i = 0; i <
sel.size(); ++i) {
631 unsigned int j = dcs[i - removed_hits].index();
634 mdt_hit.
psi = angleDif;
638 dcs.erase(dcs.begin() + i - removed_hits);
649 int stationcode =
stationCode(collected_data[0].
id());
653 std::map<int, std::vector<std::pair<int, int>>>
::const_iterator stationmap_it = rpcmdtstationmap.find(stationcode);
655 if (stationmap_it != rpcmdtstationmap.end()) {
656 const std::vector<std::pair<int, int>>& stationhits = (*stationmap_it).second;
659 for (
unsigned int i = 0; i < stationhits.size(); i++) {
661 for (
int j = stationhits[i].first; j < stationhits[i].second; j++) {
662 const std::shared_ptr<MuonHoughHit> rpchit = hitcontainer.
getHit(j);
663 if (rpchit->getWeight() < 0.01)
continue;
665 const double rpc_radius = rpcPos.perp();
666 const double rpc_rz_ratio = rpc_radius / rpcPos.z();
667 const double rpc_inv_rz_ratio = 1. / rpc_rz_ratio;
674 dis = globalpos.z() - globalpos.perp() * rpc_inv_rz_ratio;
676 dis = globalpos.perp() - rpc_rz_ratio * globalpos.z();
681 if (std::abs(dis) < 250.) {
682 double wnew = 1.5 + (250. - std::abs(dis)) / 251.;
683 mdt_hit.weighted_trigger = std::max(mdt_hit.weighted_trigger, wnew);
692 stationmap_it = tgcmdtstationmap.find(stationcode);
694 if (stationmap_it != tgcmdtstationmap.end()) {
695 const std::vector<std::pair<int, int>>& stationhits = (*stationmap_it).second;
698 for (
unsigned int i = 0; i < stationhits.size(); i++) {
700 for (
int j = stationhits[i].first; j < stationhits[i].second; j++) {
701 const std::shared_ptr<MuonHoughHit>
tgchit = hitcontainer.
getHit(j);
704 const double tgc_rz_ratio = tgcPos.perp() / tgcPos.z();
708 if (mdt_hit.weighted_trigger < 0.1) mdt_hit.weighted_trigger = 3.;
710 double dis = globalpos.perp() - tgc_rz_ratio * globalpos.z();
711 if (std::abs(dis) < 250.) {
712 double wnew = 3.5 + (250. - std::abs(dis)) / 251.;
713 mdt_hit.weighted_trigger = std::max(mdt_hit.weighted_trigger, wnew);
726 mdt_hit.tr_confirmation = (mdt_hit.weighted_trigger > 1.5 && mdt_hit.weighted_trigger < 2.55) ||
727 (mdt_hit.weighted_trigger > 3.5 && mdt_hit.weighted_trigger < 4.55);
730 if (mdt_hit.tr_confirmation && !mdt_hit.onsegment) {
731 ++number_of_hots_per_layer[mdt_hit.layer_number];
738 if (mdt_hit.prob < 0.01) {
744 std::map<int, int>::const_iterator map_it = nHitsPerLayer.find(mdt_hit.layer_number);
745 if (map_it != nHitsPerLayer.end()) {
746 int layerhits = (*map_it).second;
747 double layer_weight = 1. / (0.25 * layerhits + 0.75 * std::sqrt(layerhits));
749 if (!mdt_hit.tr_confirmation && !mdt_hit.onsegment) {
751 mdt_hit.prob = std::max(0., mdt_hit.prob - 0.2);
753 mdt_hit.weights = mdt_hit.prob * layer_weight;
758 double rej = 1. / (1. - layer_weight + 0.10);
761 if (mdt_hit.onsegment && mdt_hit.tr_confirmation) {
763 }
else if (mdt_hit.onsegment) {
764 rej0 = 1.75 / (mdt_hit.psi + 0.05);
766 else if (mdt_hit.tr_confirmation) {
770 double rej_total = rej * rej0;
771 mdt_hit.prob = rej_total / (1. + rej_total);
774 map_it = number_of_hots_per_layer.find(mdt_hit.layer_number);
775 if (map_it != number_of_hots_per_layer.end()) {
776 int layerhits_conf = (*map_it).second;
777 mdt_hit.weights = mdt_hit.prob / (0.25 * layerhits_conf + 0.75 * std::sqrt(layerhits_conf));
779 ATH_MSG_INFO(
"Entry not in map! This should not happen");
780 mdt_hit.weights = mdt_hit.prob;
784 ATH_MSG_INFO(
"Entry not in map! This should not happen");
785 mdt_hit.weights = mdt_hit.prob;
791 <<
" trigger weight " << mdt_hit.weighted_trigger <<
" on segment " << mdt_hit.onsegment <<
" psi " << mdt_hit.psi
792 <<
" prob " << mdt_hit.prob <<
" weight " << mdt_hit.weights);
793 hitcontainer.
addHit(new_mdt_hit(mdt_hit.prd, mdt_hit.prob, mdt_hit.weights));
796 h.m_weighthistogram->Fill(mdt_hit.weights);
797 h.m_weighthistogrammdt->Fill(mdt_hit.weights);
805 for (
const auto* cont_ptr : colls)
addCollection(*cont_ptr, hitcontainer, phietahitassociation);
810 if (cont.empty())
return;
811 std::map<Identifier, unsigned> nHitsPerLayer{};
812 hitcontainer.
reserve(cont.size() + hitcontainer.
size());
814 unsigned channel_max{0};
816 if constexpr (std::is_same<CollContainer, CscPrepDataCollection>::value) {
818 }
else if constexpr (std::is_same<CollContainer, TgcPrepDataCollection>::value) {
820 }
else if constexpr (std::is_same<CollContainer, RpcPrepDataCollection>::value) {
822 }
else if constexpr(std::is_same<CollContainer, sTgcPrepDataCollection>::value) {
825 channel_max =
m_idHelperSvc->stgcIdHelper().channelMax(cont.front()->identify()) * 3;
826 }
else if constexpr(std::is_same<CollContainer, MMPrepDataCollection>::value) {
827 channel_max =
m_idHelperSvc->mmIdHelper().channelMax(cont.front()->identify());
830 auto layer_channel = [
this](
const Identifier& id) {
831 if constexpr (std::is_same<CollContainer, CscPrepDataCollection>::value) {
833 }
else if constexpr(std::is_same<CollContainer, TgcPrepDataCollection>::value) {
835 }
else if constexpr(std::is_same<CollContainer, RpcPrepDataCollection>::value) {
837 }
else if constexpr(std::is_same<CollContainer, sTgcPrepDataCollection>::value) {
839 }
else if constexpr(std::is_same<CollContainer, MMPrepDataCollection>::value) {
845 std::set<int> layers{};
847 auto layer_number = [
this, &layers](
const Identifier& id ) ->
int{
848 if constexpr (std::is_same<CollContainer,RpcPrepDataCollection>::value) {
849 const int n_gasGaps =
m_idHelperSvc->rpcIdHelper().gasGapMax(
id);
850 const int n_doubR =
m_idHelperSvc->rpcIdHelper().doubletRMax(
id);
851 return n_gasGaps* (
m_idHelperSvc->rpcIdHelper().doubletR(
id) - 1) +
853 }
else if constexpr(std::is_same<CollContainer,TgcPrepDataCollection>::value) {
854 const int n_gasGaps =
m_idHelperSvc->tgcIdHelper().gasGapMax(
id);
856 }
else if constexpr(std::is_same<CollContainer,CscPrepDataCollection>::value) {
857 const int n_layer =
m_idHelperSvc->cscIdHelper().chamberLayerMax(
id);
858 const int n_chlay =
m_idHelperSvc->cscIdHelper().wireLayerMax(
id);
859 return n_layer*(
m_idHelperSvc->cscIdHelper().wireLayer(
id) -1) +
861 }
else if constexpr(std::is_same<CollContainer,sTgcPrepDataCollection>::value) {
862 const int n_lay =
m_idHelperSvc->stgcIdHelper().gasGapMax(
id);
863 const int n_chtype =
m_idHelperSvc->stgcIdHelper().channelTypeMax(
id);
864 return n_chtype*n_lay*(
m_idHelperSvc->stgcIdHelper().multilayer(
id) - 1) +
867 }
else if constexpr(std::is_same<CollContainer,MMPrepDataCollection>::value) {
869 return n_lay*(
m_idHelperSvc->mmIdHelper().multilayer(
id) - 1) +
873 return static_cast<int>(layers.size());
877 std::vector<float> channelWeights;
881 channelWeights.assign(2*channel_max + 2, 2.);
883 channelWeights.assign(2*channel_max + 2, 0);
884 for (
const auto* prd : cont) {
885 const bool measures_phi =
m_idHelperSvc->measuresPhi(prd->identify());
886 layers.insert(layer_number(prd->identify()));
888 if constexpr (std::is_same<CollContainer, sTgcPrepDataCollection>::value ||
889 std::is_same<CollContainer, MMPrepDataCollection>::value) {
890 for (uint16_t ch : prd->stripNumbers()) {
891 const int channel = ch + measures_phi * channel_max;
892 channelWeights.at(channel -1) += 0.55;
893 channelWeights.at(channel) += 1.;
894 channelWeights.at(channel + 1) +=0.55;
898 const int channel = layer_channel(prd->identify()) + measures_phi * channel_max;
899 channelWeights[channel -1] += 0.55;
900 channelWeights[channel] += 1.;
901 channelWeights[channel + 1] +=0.55;
906 std::map<Identifier, PrepDataSet> gasgapphimap{};
907 for (
const auto* prd : cont) {
908 const bool measures_phi =
m_idHelperSvc->measuresPhi(prd->identify());
909 const int channel = layer_channel(prd->identify()) + measures_phi * channel_max;
911 nHitsPerLayer[
m_idHelperSvc->layerId(prd->identify())] += layers.size() > 1 && (channelWeights[channel] > 1.);
913 if (!measures_phi)
continue;
914 gasgapphimap[
m_idHelperSvc->gasGapId(prd->identify())].insert(prd);
918 if constexpr(std::is_same<CollContainer, TgcPrepDataCollection>::value) {
920 }
else if constexpr(std::is_same<CollContainer, RpcPrepDataCollection>::value) {
924 for (
const auto* prd : cont) {
927 double number_of_hits = nHitsPerLayer[
m_idHelperSvc->layerId(prd->identify())];
928 weight = number_of_hits ? 1. / (0.25 * std::sqrt(number_of_hits) + 0.75 * number_of_hits) : 0.;
929 if( layers.size() == 2) weight /= 2.;
935 std::shared_ptr<MuonHoughHit> hit = std::make_shared<MuonHoughHit>(prd->globalPosition(),
936 measuresPhi, det_tech, (weight > 0.), weight, prd);
942 h.m_weighthistogram->Fill(weight);
943 if constexpr (std::is_same<CollContainer, CscPrepDataCollection>::value) {
944 h.m_weighthistogramcsc->Fill(weight);
945 }
else if constexpr(std::is_same<CollContainer, TgcPrepDataCollection>::value) {
946 h.m_weighthistogramtgc->Fill(weight);
947 }
else if constexpr(std::is_same<CollContainer, RpcPrepDataCollection>::value) {
948 h.m_weighthistogramrpc->Fill(weight);
949 }
else if constexpr(std::is_same<CollContainer, sTgcPrepDataCollection>::value) {
950 h.m_weighthistogramstgc->Fill(weight);
951 }
else if constexpr(std::is_same<CollContainer, MMPrepDataCollection>::value) {
952 h.m_weighthistogrammm->Fill(weight);
957 if (!phi_prds.empty()) phietahitassociation.insert(std::make_pair(prd, phi_prds));
962 std::map<
int, std::vector<std::pair<int, int>>>& rpcmdtstationmap)
const {
970 std::map<int, std::vector<std::pair<int, int>>>
::iterator it;
975 addToStationMap(rpcmdtstationmap, it, stationcode, hit_begin, hit_end);
980 int idphi1 = idphi - 1;
981 if (idphi1 == 0) idphi1 = 8;
982 int idphi2 = idphi + 1;
983 if (idphi2 > 8) idphi2 = 1;
989 int stationNameMDT = station_itr->second;
991 stationcode =
stationCode(stationNameMDT, idphi1, ideta);
992 addToStationMap(rpcmdtstationmap, it, stationcode, hit_begin, hit_end);
994 stationcode =
stationCode(stationNameMDT, idphi2, ideta);
995 addToStationMap(rpcmdtstationmap, it, stationcode, hit_begin, hit_end);
1002 stationNameMDT = station_itr->second;
1003 stationcode =
stationCode(stationNameMDT, idphi, ideta);
1004 addToStationMap(rpcmdtstationmap, it, stationcode, hit_begin, hit_end);
1008 std::map<
int, std::vector<std::pair<int, int>>>& tgcmdtstationmap)
const {
1014 if (st[0] !=
'T')
return;
1016 constexpr std::array<int, 5> T31{2, 3, 3, 4, 4};
1017 constexpr std::array<int, 5> T32{3, 4, 4, 5, 5};
1018 constexpr std::array<int, 5> T11{2, 3, 4, 4, 4};
1019 constexpr std::array<int, 5> T12{3, 4, 5, 5, 5};
1021 std::map<int, std::vector<std::pair<int, int>>>
::iterator it;
1026 if (st[2] ==
'F') modphiTGC = 24;
1027 if (st[1] ==
'4') modphiTGC = 24;
1031 int index = abs(ideta) - 1;
1032 int idphi1MDT = 1 + int(8. * (idphi + 1) / modphiTGC);
1033 int idphi2MDT = 1 + int(8. * (idphi - 1) / modphiTGC);
1034 if (idphi1MDT > 8) idphi1MDT = 1;
1035 if (idphi2MDT > 8) idphi2MDT = 1;
1038 if (ideta < 0)
sign = -1;
1045 ideta1MDT =
sign * 1;
1046 ideta2MDT =
sign * 2;
1051 ideta1MDT =
sign * 4;
1052 ideta2MDT =
sign * 5;
1053 }
else if (st[1] ==
'3') {
1063 std::string station1 =
"EML";
1064 std::string station2 =
"EMS";
1075 int stationcode =
stationCode(stationNameMDT1, idphi1MDT, ideta1MDT);
1076 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1077 stationcode =
stationCode(stationNameMDT2, idphi1MDT, ideta1MDT);
1078 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1079 if (ideta1MDT != ideta2MDT) {
1080 stationcode =
stationCode(stationNameMDT1, idphi1MDT, ideta2MDT);
1081 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1082 stationcode =
stationCode(stationNameMDT2, idphi1MDT, ideta2MDT);
1083 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1085 if (idphi1MDT != idphi2MDT) {
1086 stationcode =
stationCode(stationNameMDT1, idphi2MDT, ideta1MDT);
1087 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1088 stationcode =
stationCode(stationNameMDT2, idphi2MDT, ideta1MDT);
1089 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1090 if (ideta1MDT != ideta2MDT) {
1091 stationcode =
stationCode(stationNameMDT1, idphi2MDT, ideta2MDT);
1092 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1093 stationcode =
stationCode(stationNameMDT2, idphi2MDT, ideta2MDT);
1094 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1099 if (station1 ==
"EMS") { station1 =
"EOS"; }
1100 if (station2 ==
"EML") {
1108 stationcode =
stationCode(stationNameMDT1, idphi1MDT, ideta1MDT);
1109 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1110 stationcode =
stationCode(stationNameMDT2, idphi1MDT, ideta1MDT);
1111 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1112 if (ideta1MDT != ideta2MDT) {
1113 stationcode =
stationCode(stationNameMDT1, idphi1MDT, ideta2MDT);
1114 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1115 stationcode =
stationCode(stationNameMDT2, idphi1MDT, ideta2MDT);
1116 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1118 if (idphi1MDT != idphi2MDT) {
1119 stationcode =
stationCode(stationNameMDT1, idphi2MDT, ideta1MDT);
1120 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1121 stationcode =
stationCode(stationNameMDT2, idphi2MDT, ideta1MDT);
1122 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1124 if (ideta1MDT != ideta2MDT) {
1125 stationcode =
stationCode(stationNameMDT1, idphi2MDT, ideta2MDT);
1126 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1127 stationcode =
stationCode(stationNameMDT2, idphi2MDT, ideta2MDT);
1128 addToStationMap(tgcmdtstationmap, it, stationcode, hit_begin, hit_end);
1139 return 10000000 * stationname + 100000 *
phi + 1000 * (
eta + 10);
1143 std::map<
int, std::vector<std::pair<int, int>>>
::iterator& it,
int& stationcode,
1144 const int& hit_begin,
const int& hit_end) {
1145 it = stationmap.find(stationcode);
1146 if (it == stationmap.end()) {
1147 std::vector<std::pair<int, int>> dummyvec;
1148 dummyvec.emplace_back(hit_begin, hit_end);
1149 stationmap[stationcode] = dummyvec;
1151 (*it).second.emplace_back(hit_begin, hit_end);
1156 std::vector<int>&
sel)
const {
1175 if (dcs.empty())
return;
1177 DCCit it_end = dcs.end();
1178 DCCit it1 = dcs.begin();
1179 std::map<int, DCVec> layerHits;
1180 std::map<int, int> dcsId;
1182 std::map<int, DCVec>::iterator map_it;
1184 for (; it1 != it_end; ++it1, nhits++) {
1187 dcsId[isort] = nhits;
1188 int ilay = 4 * (it1->id().ml()) + it1->id().lay();
1191 map_it = layerHits.find(ilay);
1192 if (map_it != layerHits.end()) {
1193 (*map_it).second.push_back(*it1);
1196 dcl.reserve(dcs.size());
1197 dcl.push_back(*it1);
1198 layerHits[ilay] = dcl;
1202 unsigned int nHits = 0;
1203 unsigned int nHitsLine = 0;
1204 unsigned int nPassedTubes = 0;
1205 double roadWidth = 1.5;
1209 for (
int i = 0; i < 8; i++) {
1210 if (layerHits.count(i) != 1)
continue;
1211 DCVec& dci = layerHits[i];
1212 if (dci.size() > 10)
continue;
1213 DCCit iti = dci.begin();
1214 DCCit iti_end = dci.end();
1215 for (; iti != iti_end; ++iti) {
1217 float tubeRadius = 14.6;
1219 tubeRadius = (*iti).rot()->detectorElement()->innerTubeRadius();
1221 for (
int j = 7; j > i; j--) {
1222 if (layerHits.count(j) != 1)
continue;
1223 DCVec& dcj = layerHits[j];
1224 if (dcj.size() > 10)
continue;
1225 DCCit itj = dcj.begin();
1226 DCCit itj_end = dcj.end();
1227 for (; itj != itj_end; ++itj) {
1229 double hitx = (*itj).x();
1230 double hity = (*itj).y();
1231 double norm = std::hypot(hitx, hity);
1232 double cphi = hitx / norm;
1233 double sphi = hity / norm;
1235 for (TrkDriftCircleMath::TangentToCircles::LineVec::const_iterator lit = lines.begin(); lit != lines.end(); ++lit) {
1236 double coshit = std::cos((*lit).phi());
1237 double sinhit = std::sin((*lit).phi());
1238 const double cospsi = std::min(std::max(-1.,coshit * cphi + sinhit * sphi), 1.);
1239 double psi = std::acos(cospsi);
1240 if (psi > 0.3)
continue;
1243 unsigned int matchedHits = matchWithLine.
hitsOnTrack();
1246 if (matchedHits >
nHits || (matchedHits ==
nHits && psi < angleDif)) {
1247 int dnl = std::abs(
static_cast<int>(matchWithLine.
hitsMl1()) -
static_cast<int>(matchWithLine.
hitsMl2()));
1248 ATH_MSG_DEBUG(
" matchWithLine.hitsOnTrack() > nHits old " <<
nHits <<
" new: " << matchedHits);
1249 ATH_MSG_DEBUG(
" dnl " << dnl <<
" old dnl " << std::abs(nl1 - nl2));
1250 ATH_MSG_DEBUG(
" hit cos phi " << cphi <<
" line " << coshit <<
" sin phi " << sphi <<
" line " << sinhit
1254 nHits = matchedHits;
1255 nl1 = matchWithLine.
hitsMl1();
1256 nl2 = matchWithLine.
hitsMl2();
1257 nHitsLine = hitsOnLine.size();
1259 hitsOnLineSel = hitsOnLine;
1264 if (
nHits >= dcs.size()) stop =
true;
1275 ATH_MSG_DEBUG(
" Fast segment finder Max Layers hit " << dcs.size() <<
" nHitsLine - nHits " << nHitsLine - nl1 - nl2
1276 <<
" passed Tubes -nHits " << nPassedTubes - nl1 - nl2 <<
" nl1 " << nl1
1277 <<
" nl2 " << nl2 <<
" angleDif " << angleDif);
1282 for (; itt != itt_end; ++itt, i++) {
1284 if (dcsId.count(isort) == 1) {
1285 int dcsIndex = dcsId[isort];
1288 ATH_MSG_DEBUG(
" Selected Hit index " << dcsIndex <<
" MultiLayer " << itt->id().ml() <<
" layer " << itt->id().lay()
1289 <<
" tube " << itt->id().tube());
1291 ATH_MSG_WARNING(
" ALARM fastSegmentFinder hit NOT found " << i <<
" isort " << isort);
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::vector< size_t > vec
std::vector< MuonHoughPatternContainer > MuonHoughPatternContainerShip
DataVector< Muon::MuonSegmentCombination > MuonSegmentCombinationCollection
This typedef represents a collection of MuonSegmentCombination objects.
static const uint32_t nHits
#define ATLAS_THREAD_SAFE
bool msgLvl(const MSG::Level lvl) const
const_iterator begin() const noexcept
size_type size() const noexcept
const_iterator end() const
return const_iterator for end of container
size_t size() const
Duplicate of fullSize for backwards compatability.
const_iterator begin() const
return const_iterator for first entry
int multilayer(const Identifier &id) const
Access to components of the ID.
int tube(const Identifier &id) const
static int tubeLayerMax()
int tubeLayer(const Identifier &id) const
static constexpr int maxNTubesPerLayer
The maxNTubesPerLayer represents the absolute maximum of tubes which are built into a single multilay...
int getNLayers() const
Returns the number of tube layers inside the multilayer.
int getNtubesperlayer() const
Returns the number of tubes in each tube layer.
unsigned int size() const
returns size of hitcontainer
std::shared_ptr< MuonHoughHit > getHit(int hitno) const
returns Hit at position hitno
void reserve(int size)
allocates memory for hitvector
void addHit(const std::shared_ptr< MuonHoughHit > &hit)
add hit to container
int stationNameIndex(const std::string &name) const
bool isBarrel(const Identifier &id) const
Class to represent the calibrated clusters created from CSC strips.
virtual const CscPrepData * prepRawData() const override final
Returns the CscPrepData - is a CscPrepData in this scope.
Class representing clusters from the CSC.
Class to represent measurements from the Monitored Drift Tubes.
int adc() const
Returns the ADC (typically range is 0 to 250)
virtual const MuonGM::MdtReadoutElement * detectorElement() const override
Returns the detector element corresponding to this PRD.
MdtDriftCircleStatus status() const
Returns the status of the measurement.
virtual const Amg::Vector3D & globalPosition() const
Returns the global position of the CENTER of the drift tube (i.e.
Template to hold collections of MuonPrepRawData objects.
Class to hold a set of MuonSegments belonging together.
Property holding a SG store/key/clid from which a WriteHandle is made.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
This class represents a drift time measurement.
@ InTime
drift time too small to be compatible with drift spectrum
Implementation of 2 dimensional vector class.
unsigned int hitsMl1() const
unsigned int hitsMl2() const
unsigned int hitsOnTrack() const
const DCOnTrackVec & match(const DCVec &dcs)
unsigned int passedTubes() const
void set(const Line &l, double deltaCut, MatchStrategy strategy, double tubeRadius)
std::vector< Line > LineVec
static LineVec tangentLines(const DriftCircle &dc1, const DriftCircle &dc2)
Identifier identify() const
return the identifier -extends MeasurementBase
double error(const Amg::MatrixX &mat, int index)
return diagonal error of the matrix caller should ensure the matrix is symmetric and the index is in ...
Eigen::Matrix< double, 3, 1 > Vector3D
DetectorTechnology
enum to identify the muondetectortechnology
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
MuonPrepDataCollection< TgcPrepData > TgcPrepDataCollection
MuonPrepDataContainerT< RpcPrepData > RpcPrepDataContainer
MuonPrepDataContainer< MuonPrepDataCollection< PrdType > > MuonPrepDataContainerT
MuonPrepDataContainerT< TgcPrepData > TgcPrepDataContainer
MuonPrepDataContainerT< MdtPrepData > MdtPrepDataContainer
MuonPrepDataContainerT< sTgcPrepData > sTgcPrepDataContainer
@ MdtStatusDriftTime
The tube produced a vaild measurement.
MuonPrepDataContainerT< MMPrepData > MMPrepDataContainer
MuonPrepDataCollection< MdtPrepData > MdtPrepDataCollection
MuonHoughPatternFinderTool::MuonPatternHoughPair MuonPatternHoughPair
MuonPrepDataContainerT< CscPrepData > CscPrepDataContainer
MuonPrepDataCollection< RpcPrepData > RpcPrepDataCollection
Function object to check whether two Segments are sub/super sets or different.
DCVec::const_iterator DCCit
std::vector< DriftCircle > DCVec
DCOnTrackVec::iterator DCOnTrackIt
std::vector< DCOnTrack > DCOnTrackVec
const Muon::MdtPrepData * prd
double radius() const
Identifier of the PRD.