12 #include "GaudiKernel/MsgStream.h"
92 for (; mit != mit_end; ++mit) {
104 std::ostringstream sout;
110 std::ostringstream sout;
111 TrackVec::const_iterator trk = tracks.begin();
112 TrackVec::const_iterator trk_end = tracks.end();
113 TrackVec::const_iterator trk_last = trk_end - 1;
114 for (; trk != trk_end; ++trk) {
115 sout << (*trk)->dump();
116 if (trk != trk_last) sout << std::endl;
122 std::ostringstream sout;
123 SegmentVec::const_iterator seg = segments.begin();
124 SegmentVec::const_iterator seg_end = segments.end();
125 SegmentVec::const_iterator seg_last = seg_end - 1;
126 for (; seg != seg_end; ++seg) {
127 sout << (*seg)->dump();
128 if (seg != seg_last) sout << std::endl;
134 std::ostringstream sout;
148 std::ostringstream sout;
154 std::ostringstream sout;
157 if (
it.first == 1 ||
it.first == 2)
continue;
159 sout <<
" Track Author " <<
it.first <<
" number of tracks " <<
it.second.size();
190 int author = track_ptr->author();
194 ExtendedTrackPtr extendedTrack = std::make_shared<MuonCalibExtendedTrack>(*track_ptr, 0, 0);
199 previousMooreTrack = extendedTrack;
200 }
else if ((
author == 1 ||
author == 2) && previousMooreTrack) {
201 std::cout <<
"Perform proper track association " << __FILE__ <<
" " << __LINE__ << std::endl;
204 }
else if (
author == 10 && track_ptr->nrHits() == 0) {
207 double dotprodmax = -1.;
208 if (trackVec0.size() > 0) {
209 int trackcount10 = trackVec.size();
214 for (; it0 != it0_end; ++it0) {
216 if (trackcount10 > trackcount0)
continue;
217 double dotprod = extendedTrack->
direction().dot((*it0)->direction());
218 if (extendedTrack->isAssociated(*it0))
continue;
219 if ((*it0)->isAssociated(extendedTrack))
continue;
220 if (dotprod > dotprodmax) {
221 dotprodmax = dotprod;
222 associatedMooreTrack = *it0;
223 if (dotprodmax > 0.8)
break;
226 if (dotprodmax > 0.8 && associatedMooreTrack) {
227 extendedTrack->addAssociatedTrack(associatedMooreTrack);
228 associatedMooreTrack->addAssociatedTrack(extendedTrack);
233 trackVec.push_back(extendedTrack);
238 for (
const auto& hit_ptr : container) {
239 int barcode = hit_ptr->barCode();
241 barcode_map[
barcode].insert(hit_ptr);
257 std::map<int, TruthPtr> truthTrkME, truthTrkIP, truthTrkRest;
259 std::map<int, std::set<TruthMdtPtr>> truthTrkMdtHitMap;
260 std::map<int, std::set<TruthCscPtr>> truthTrkCscHitMap;
261 std::map<int, std::set<TruthRpcPtr>> truthTrkRpcHitMap;
262 std::map<int, std::set<TruthTgcPtr>> truthTrkTgcHitMap;
266 int barcode = truth_part->barCode();
270 if (truth_part->position().perp() < 4000 && std::abs(truth_part->position().z()) < 6000.) {
271 if (truth_part->position().perp() < 100 && std::abs(truth_part->position().z()) < 500.) {
273 truthTrkIP[
barcode] = truth_part;
275 truthTrkRest[
barcode] = truth_part;
279 truthTrkME[
barcode] = truth_part;
288 if (truthTrkMdtHitMap.empty())
return;
305 for (
const auto& it_IP : truthTrkIP) {
306 std::shared_ptr<MuonCalibTrack_E> truth_trk =
307 transform_to_trk(it_IP.second, truthTrkMdtHitMap, truthTrkCscHitMap, truthTrkRpcHitMap, truthTrkTgcHitMap);
309 int pdgcode = it_IP.second->PDGCode();
311 if (std::abs(pdgcode) != 13)
author = -113;
313 std::shared_ptr<MuonCalibExtendedTrack> extendedTrack = std::make_shared<MuonCalibExtendedTrack>(*truth_trk, pdgcode,
barcode);
314 trackVec.push_back(extendedTrack);
316 if (
m_debug) extendedTrack->dump();
319 for (
const auto& it_ME : truthTrkME) {
320 std::shared_ptr<MuonCalibTrack_E> truth_trk =
321 transform_to_trk(it_ME.second, truthTrkMdtHitMap, truthTrkCscHitMap, truthTrkRpcHitMap, truthTrkTgcHitMap);
324 int pdgcode = it_ME.second->PDGCode();
326 if (std::abs(pdgcode) != 13)
author = -1113;
328 std::shared_ptr<MuonCalibExtendedTrack> extendedTrack = std::make_shared<MuonCalibExtendedTrack>(*truth_trk, pdgcode,
barcode);
329 trackVec.push_back(extendedTrack);
331 if (
m_debug) extendedTrack->dump();
335 const std::map<
int, std::set<TruthMdtPtr>>& mdt_hits,
336 const std::map<
int, std::set<TruthCscPtr>>& csc_hits,
337 const std::map<
int, std::set<TruthRpcPtr>>& rpc_hits,
338 const std::map<
int, std::set<TruthTgcPtr>>& tgc_hits) {
339 const int barcode = truth_part->barCode();
341 build_pars.
x0 = truth_part->position().x();
342 build_pars.y0 = truth_part->position().y();
343 build_pars.z0 = truth_part->position().z();
344 build_pars.phi = truth_part->momentum().phi();
345 build_pars.theta = truth_part->momentum().theta();
346 build_pars.author = std::abs(truth_part->PDGCode());
347 build_pars.qOverP = (1. - 2. * (truth_part->PDGCode() < 0)) / (truth_part->momentum().mag());
348 build_pars.cov.setZero();
349 std::shared_ptr<MuonCalibTrack_E> track_ptr = std::make_shared<MuonCalibTrack_E>(build_pars);
351 std::map<int, std::set<TruthMdtPtr>>::const_iterator mdt_itr = mdt_hits.find(
barcode);
352 if (mdt_itr != mdt_hits.end()) {
353 for (
const TruthMdtPtr& mdt_hit : mdt_itr->second) {
356 hit_pars.pos =
Amg::Vector3D(0., mdt_hit->positionAlongTube(), 0.);
357 track_ptr->addHit(std::make_shared<MuonCalibHit_E>(mdt_hit->identify(), hit_pars));
360 std::map<int, std::set<TruthCscPtr>>::const_iterator csc_itr = csc_hits.find(
barcode);
361 if (csc_itr != csc_hits.end()) {
362 for (
const TruthCscPtr& csc_hit : csc_itr->second) {
365 track_ptr->addHit(std::make_shared<MuonCalibHit_E>(csc_hit->identify(), hit_pars));
369 std::map<int, std::set<TruthRpcPtr>>::const_iterator rpc_itr = rpc_hits.find(
barcode);
370 if (rpc_itr != rpc_hits.end()) {
371 for (
const TruthRpcPtr& rpc_hit : rpc_itr->second) {
374 track_ptr->addHit(std::make_shared<MuonCalibHit_E>(rpc_hit->identify(), hit_pars));
377 std::map<int, std::set<TruthTgcPtr>>::const_iterator tgc_itr = tgc_hits.find(
barcode);
378 if (tgc_itr != tgc_hits.end()) {
379 for (
const TruthTgcPtr& tgc_hit : tgc_itr->second) {
382 track_ptr->addHit(std::make_shared<MuonCalibHit_E>(tgc_hit->identify(), hit_pars));
395 int author = seg_ptr->author();
400 segVec.emplace_back(extendedSegment);
407 struct segmentMatchQual {
409 int assoc_quality{0};
412 if (assoc_quality !=
other.assoc_quality)
return assoc_quality >
other.assoc_quality;
413 return seg->chi2() <
other.seg->chi2();
419 std::vector<segmentMatchQual> segmentTrackMatch;
422 if (
match > 200) { segmentTrackMatch.emplace_back(seg,
match); }
426 std::sort(mit, mit_end);
427 for (; mit != mit_end; ++mit) {
429 for (; mit2 != mit_end; ++mit2) {
430 if (
segmentOverlap(*mit->seg, *mit2->seg) > 1) { mit2->vetoed =
true; }
433 std::cout <<
"We need to refine the track to segment association " << __FILE__ <<
" " << __LINE__ << std::endl;
444 std::set<MuonFixedId> segmentIds;
449 log << MSG::WARNING <<
"segmentOverlap(), invalid MDT id! " <<
endmsg;
452 segmentIds.insert(
id);
458 log << MSG::WARNING <<
"segmentOverlap(), invalid MDT id! " <<
endmsg;
461 overlap += (segmentIds.count(
id) > 0);
465 std::set<MuonFixedId> segmentIds;
470 log << MSG::WARNING <<
"segmentOverlap(), invalid CSC id! " <<
endmsg;
473 segmentIds.insert(
id);
479 log << MSG::WARNING <<
"segmentOverlap(), invalid CSC id! " <<
endmsg;
482 overlap += (segmentIds.count(
id) > 0);
488 double minRadius = 1.;
489 unsigned int noppositeSign{0}, nsameSign{0}, nnotOnTrack{0};
494 log << MSG::WARNING <<
"associateSegmentWithTrack(), invalid MDT id! " <<
endmsg;
498 IdHitMap::const_iterator trkHit =
track.idHitMap().find(
id);
499 if (trkHit !=
track.idHitMap().end()) {
501 double signSeg = mdt_hit->driftRadius() < -minRadius ? -1. : 1.;
502 double signTrk = trkHit->second->driftRadius() < -minRadius ? -1. : 1.;
503 if (signSeg == signTrk)
516 log << MSG::WARNING <<
"associateSegmentWithTrack(), invalid CSC id! " <<
endmsg;
520 IdHitMap::const_iterator trkHit =
track.idHitMap().find(
id);
521 if (trkHit !=
track.idHitMap().end()) {
529 return nnotOnTrack + 10 * noppositeSign + 100 * nsameSign;
542 for (; rit != rit_end; ++rit) {
546 for (; ait != ait_end; ++ait) {
548 if (ait->first == referenceIndex)
continue;
552 match(**rit, tracks);
563 for (;
it != it_end; ++
it) {
571 bestMatch =
it->get();
572 bestOverlap = overlap;
577 std::cout <<
" Still need to be done a proper association " << __FILE__ <<
" " << __LINE__ << std::endl;