1 from builtins
import range
9 from operator
import itemgetter, methodcaller
15 """Returns the number of common hits in trk1 and trk2. Matching is 16 done via the hit type and index, so effectively the matching is 17 done by clusters. Invalid hits are ignored. 21 for hit
in trk1.hits():
22 if not hit.isValidHit():
continue 23 hits1.add( (type(hit), hit.index()) )
26 for hit
in trk2.hits():
27 if not hit.isValidHit():
continue 28 if (type(hit), hit.index())
in hits1:
38 for hit
in reftrk.hits():
39 if not hit.isValidHit():
continue 40 hits1.add( (type(hit), hit.index()) )
45 for hit
in trk.hits():
46 if not hit.isValidHit():
continue 47 if (type(hit), hit.index())
in hits1:
56 super(_TracksByHitsMatcher, self).
__init__()
59 for hit
in trk.hits():
64 tracks = collections.defaultdict(int)
66 for hit
in trk.hits():
67 if not hit.isValidHit():
continue 69 idx = (type(hit), hit.index())
75 for ot
in otherTracks:
79 for t, ncommon
in tracks.items():
87 def __init__(self, diff=[], hasDifference=False):
99 if isinstance(diff, _DiffResult):
101 if diff.hasDifference():
114 return line[0]+char+line[1:]
117 if not (plus
or minus):
120 for i, line
in enumerate(self.
_diff):
121 if isinstance(line, _DiffResult):
122 line.highlight(plus, minus)
127 if len(plusregexs) == 0
and len(minusregexs) == 0:
130 for i, line
in enumerate(self.
_diff):
131 if isinstance(line, _DiffResult):
132 raise Exception(
"highlightLines() is currently allowed only for text-only _DiffResult objects")
139 for m
in minusregexs:
146 for line
in self.
_diff:
147 if isinstance(line, _DiffResult):
148 for l
in line.lines():
154 return "\n".
join([s
for s
in (
str(item)
for item
in self.
_diff)
if s !=
""])
157 return len(self.
_diff)
160 diff = difflib.unified_diff(list1, list2, lineterm=
"", n=len(list1))
169 return _DiffResult([equalPrefix+s
for s
in list1], hasDifference=
False)
174 lst1 =
func(obj1)
if obj1
is not None else []
175 lst2 =
func(obj2)
if obj2
is not None else []
182 if not (ncommon == trk1.nValid()
and ncommon == trk2.nValid()):
186 if not (trk1.algoMask() == trk2.algoMask()
and trk1.algo() == trk2.algo()
and trk1.originalAlgo() == trk2.originalAlgo()):
192 if trk1.nMatchedTrackingParticles() != trk2.nMatchedTrackingParticles():
195 for tpInfo1, tpInfo2
in itertools.izip(trk1.matchedTrackingParticleInfos(), trk2.matchedTrackingParticleInfos()):
196 if tpInfo1.trackingParticle().
index() != tpInfo2.trackingParticle().
index():
202 """lst1 and lst2 are the main lists to make the diff from. 204 lst1extra and lst2extra are optional to provide suplementary 205 tracks. Use case: lst1 and lst2 are subset of full tracks, 206 lst1extra and lst2extra contain tracks matched to the same 207 TrackingParticle but are outside of the selection of lst1/lst2. 212 _trks1extra = list(lst1extra)
213 _trks2extra = list(lst2extra)
215 trks1 = list(lst1)+_trks1extra
216 trks2 = list(lst2)+_trks2extra
218 trks1extra = set([t.index()
for t
in _trks1extra])
219 trks2extra = set([t.index()
for t
in _trks2extra])
221 trks1Empty = (len(trks1) == 0)
222 trks2Empty = (len(trks2) == 0)
224 if trks1Empty
and trks2Empty:
230 def _findCommonTP(_lst, _commonTP, _name):
232 if trk.nMatchedTrackingParticles() != 1:
233 raise Exception(
"Track %d from %s is matched to %d TPs. This is not supported by this function yet." % (trk.index(), _name, trk.nMatchedTrackingParticles()))
234 if _commonTP
is None:
235 _commonTP =
next(trk.matchedTrackingParticleInfos()).trackingParticle()
237 tp =
next(trk.matchedTrackingParticleInfos()).trackingParticle()
238 if tp.index() != _commonTP.index():
239 raise Exception(
"Track %d from %s is matched to TP %d, which differs from the TP %d of already processed tracks." % (trk.index(), _name, _commonTP.index(), tp.index()))
241 commonTP = _findCommonTP(trks1, commonTP,
"lst1")
242 commonTP = _findCommonTP(trks2, commonTP,
"lst2")
245 someTrk1 = trks1[0]
if not trks1Empty
else None 246 someTrk2 = trks2[0]
if not trks2Empty
else None 252 if matchedTrk2
is None:
253 if trk1.index()
in trks1extra:
254 raise Exception(
"Track %d was found in trks1extra but matchedTrk2 is None, this should not happen" % trk1.index())
255 diff.extend(
_makediff(trackPrinter.printTrack(trk1), []))
257 someTrk2 = matchedTrk2
258 trks2.remove(matchedTrk2)
259 tmp = trackPrinter.diff(trk1, matchedTrk2, diffTrackingParticles=
False)
261 tmp.setDifference(
False)
262 tmp.highlight(plus=(matchedTrk2.index()
in trks2extra), minus=(trk1.index()
in trks1extra))
266 if trk2.index()
in trks2extra:
267 raise Exception(
"Track %d was found in trks2extra, but without matching track in trks1, this should not happen" % trk2.index())
268 diff.extend(
_makediff([], trackPrinter.printTrack(trk2)))
272 tmp =
_mapdiff(trackPrinter.printMatchedTrackingParticles, someTrk1, someTrk2)
273 tmp.setDifference(
False)
276 for i
in lst: r.extend([re.compile(
"Tracks:.*%d:"%i), re.compile(
"matched to tracks.*%d"%i)])
278 plusre = _makere(trks2extra)
279 minusre = _makere(trks1extra)
280 tmp.highlightLines(plusre, minusre)
287 super(_TrackAssociation, self).
__init__()
299 lst = getattr(self, name)
300 ind = getattr(self, name+
"Ind")
302 if not t.index()
in ind:
306 def extend(self, trks1=[], trks2=[], trks1OutsideList=[], trks2OutsideList=[]):
319 self.
_extend(trks,
"_trks1OutsideList")
322 self.
_extend(trks,
"_trks2OutsideList")
333 except StopIteration:
335 if first.nMatchedTrackingParticles() != 1:
338 tpIndex =
next(first.matchedTrackingParticleInfos()).trackingParticle().
index()
341 if t.nMatchedTrackingParticles() != 1:
343 if next(t.matchedTrackingParticleInfos()).trackingParticle().
index() != tpIndex:
355 _min =
lambda lst:
min([t.eta()
for t
in lst])
363 if len(self._trks2_outsideList) > 0:
365 raise Exception(
"This _TrackAssociation is empty, minEta() makes no sense")
368 s =
lambda l:
str([t.index()
for t
in l])
379 trks1Dict = {t.index(): t
for t
in trks1}
380 trks2Dict = {t.index(): t
for t
in trks2}
386 tps1 = TrackingParticles(trks1[0]._tree)
388 tps2 = TrackingParticles(trks2[0]._tree)
393 def _getOrCreateAssoc(trk, d, **kwargs):
402 while len(trks1) > 0:
404 assoc1 = _getOrCreateAssoc(trk1, trkAssoc1, trks1=[trk1])
407 if trk1.nMatchedTrackingParticles() > 0
and tps2:
410 for tpInfo1
in trk1.matchedTrackingParticleInfos():
411 tp1 = tpInfo1.trackingParticle()
414 for trkInfo1
in tp1.matchedTrackInfos():
415 t1 = trkInfo1.track()
417 if t1Index != trk1.index():
418 if t1Index
in trks1Dict:
419 assoc1.extend(trks1=[t1])
420 _getOrCreateAssoc(t1, trkAssoc1, trks1=[t1, trk1])
422 trks1.remove(trks1Dict[t1Index])
425 assoc1.extend(trks1OutsideList=[t1])
428 tp2 = tps2[tp1.index()]
429 for trkInfo2
in tp2.matchedTrackInfos():
431 t2 = trkInfo2.track()
433 if t2Index
in trks2Dict:
434 assoc1.extend(trks2=[t2])
435 _getOrCreateAssoc(t2, trkAssoc2, trks1=[trk1], trks2=[t2])
438 trks2.remove(trks2Dict[t2Index])
443 assoc1.extend(trks2OutsideList=[t2])
450 (matchedTrk2, ncommon) = trks2Matcher.match(trk1)
451 if matchedTrk2
is not None and ncommon >= 3:
452 assoc1.extend(trks2=[matchedTrk2])
453 assoc2 = _getOrCreateAssoc(matchedTrk2, trkAssoc2, trks1=[trk1], trks2=[matchedTrk2])
456 trks2.remove(matchedTrk2)
460 (matchedTrk1, ncommon1) = trks1Matcher.match(matchedTrk2)
462 if (matchedTrk1.nMatchedTrackingParticles() == 0
or not tps2)
and matchedTrk1.index() != trk1.index():
463 assoc2.extend(trks1=[matchedTrk1])
464 _getOrCreateAssoc(matchedTrk1, trkAssoc1, trks1=[matchedTrk1], trks2=[matchedTrk2])
471 assoc2 = _getOrCreateAssoc(trk2, trkAssoc2, trks2=[trk2])
473 if trk2.nMatchedTrackingParticles() > 0:
474 for tpInfo2
in trk2.matchedTrackingParticleInfos():
475 tp2 = tpInfo2.trackingParticle()
476 for trkInfo2
in tp2.matchedTrackInfos():
477 t2 = trkInfo2.track()
479 if t2Index
in trks2Dict:
480 assoc2.extend(trks2=[t2])
483 assoc2.extend(trks2OutsideList=[t2])
488 for ind, assoc
in trkAssoc1.items():
489 for t1
in assoc.trks1():
490 a = trkAssoc1[t1.index()]
493 for t2
in assoc.trks2():
494 a = trkAssoc2[t2.index()]
497 for ind, assoc
in trkAssoc2.items():
498 for t2
in assoc.trks2():
499 a = trkAssoc2[t2.index()]
502 for t1
in assoc.trks1():
503 a = trkAssoc1[t1.index()]
507 for ind, assoc
in itertools.chain(trkAssoc1.items(), trkAssoc2.items()):
511 for t1
in assoc.trks1():
512 a = trkAssoc1[t1.index()]
519 for t2
in assoc.trks2():
520 a = trkAssoc2[t2.index()]
529 while len(trkAssoc1) > 0:
530 (t1Index, assoc) = trkAssoc1.popitem()
534 for t1
in assoc.trks1():
535 if t1.index() == t1Index:
continue 536 trkAssoc1.pop(t1.index())
537 for t2
in assoc.trks2():
538 trkAssoc2.pop(t2.index())
539 allAssocs.append(assoc)
540 while len(trkAssoc2) > 0:
541 (t2Index, assoc) = trkAssoc2.popitem()
542 if len(assoc.trks1()) > 0:
543 raise Exception(
"len(assoc.trks1()) %d != 0 !!! %s for t2 %d" % (len(assoc.trks1()),
str([t.index()
for t
in assoc.trks1()]), t2Index))
544 for t2
in assoc.trks2():
545 if t2.index() == t2Index:
continue 546 trkAssoc2.pop(t2.index())
547 allAssocs.append(assoc)
555 associations.sort(key=methodcaller(
"minEta"))
558 for assoc
in associations:
559 if assoc.hasCommonTrackingParticle():
560 if len(assoc.trks1()) == 0
and ignoreAdditionalLst2:
564 if tmp.hasDifference():
567 elif len(assoc.trks1()) == 1
and len(assoc.trks2()) == 1:
568 trk1 = assoc.trks1()[0]
569 trk2 = assoc.trks2()[0]
572 diff.extend(trackPrinter.diff(trk1, trk2))
574 elif len(assoc.trks2()) == 0:
575 for t
in assoc.trks1():
576 diff.extend(trackPrinter.diff(t,
None))
578 elif len(assoc.trks1()) == 0:
579 if ignoreAdditionalLst2:
581 for t
in assoc.trks1():
582 diff.extend(trackPrinter.diff(
None, t))
586 trks1 = list(assoc.trks1())
587 trks2 = list(assoc.trks2())
588 trks1.sort(key=
lambda t:
next(t.hits()).
r())
589 trks2.sort(key=
lambda t:
next(t.hits()).
r())
593 for i1, t1
in enumerate(trks1):
594 for i2, t2
in enumerate(trks2):
598 ncommon.sort(key=itemgetter(2), reverse=
True)
601 pairs = [
None]*len(trks1)
602 usedT2 = [
False]*len(trks2)
603 for i1, i2, ncom
in ncommon:
604 if pairs[i1]
is None:
608 for i1, i2
in enumerate(pairs):
611 diff.extend(trackPrinter.diff(t1, t2))
612 for i2, used
in enumerate(usedT2):
614 diff.extend(trackPrinter.diff(
None, trks2[i2]))
620 line_re = re.compile(
"(?P<sign>[ \-+])\s+(?P<det>[a-zA-Z]+)(?P<lay>\d+)\D*?(\((?P<missing>missing|inactive)\))?\s+\d+")
625 diffLines = diffHits.lines()
628 for line
in diffLines:
633 for line
in diffLines:
642 m = line_re.search(line)
645 raise Exception(
"regex not found from line %s" % line.rstrip())
646 sign = m.group(
"sign")
652 summary.append(
"%ENDCOLOR%")
654 summary.extend([
" ", det])
659 summary.append(
"%ENDCOLOR%")
661 summary.append(
"%RED%")
663 summary.append(
"%GREEN%")
682 if m.group(
"missing"):
683 if m.group(
"missing") ==
"missing":
684 summary.append(
"(m)")
685 elif m.group(
"missing") ==
"inactive":
686 summary.append(
"(i)")
689 summary.append(
"%ENDCOLOR%")
692 while i < len(summary)-5:
693 if summary[i] ==
"(i)" or summary[i] ==
"(m)":
694 if summary[i-2] ==
"%RED%" and summary[i+1] ==
"%ENDCOLOR%" and summary[i+2] ==
"%GREEN%" and summary[i+3] == summary[i-1]
and summary[i+4] == summary[i]
and summary[i+5] ==
"%ENDCOLOR%":
695 summary[i-2:i+6] = [summary[i-1], summary[i]]
698 line =
" "+
"".
join(summary)
699 return [
"?"+prefix+line]
711 summary +=
" "+SubDet.toString(det)
715 if isinstance(hit, InvalidHit):
716 summary +=
"(%s)"%InvalidHit.Type.toString(hit.type())[0]
745 super(_RecHitPrinter, self).
__init__(indent)
754 if hasattr(hit,
"matchedSimHitInfos"):
755 matched =
" from %s " % HitSimType.toString(hit.simType())
757 hasChargeFraction =
False 758 for shInfo
in hit.matchedSimHitInfos():
759 m =
"%d:%d" % (shInfo.simHit().trackingParticle().
index(), shInfo.simHit().
index())
760 if hasattr(shInfo,
"chargeFraction"):
761 m +=
"(%.1f)"%(shInfo.chargeFraction()*100)
762 hasChargeFraction =
True 764 if len(matches) == 0:
765 matched +=
"not matched to any TP/SimHit" 767 matched +=
"matched to TP:SimHit" 768 if hasChargeFraction:
770 matched +=
" "+
",".
join(matches)
773 if isinstance(hit, GluedHit):
774 glued =
"monoHit %d stereoHit %d " % (hit.monoHit().
index(), hit.stereoHit().
index())
776 lst.append(self.
_prefix+
"{layer} {hit} detid {detid} {detidStr} {glued}{coord}{matched}".
format(layer=hit.layerStr(), hit=hit.index(),
777 detid=hit.detId(), detidStr=hit.detIdStr(),
778 glued=glued, coord=coord, matched=matched))
782 def __init__(self, trackingParticles, trackingParticlePrinter, bestMatchingTrackingParticle):
793 lst.append(prefix+header+
" "+
",".
join([
str(tp.index())
for tp
in tps]))
795 lst.append(prefix+header)
811 if track.nMatchedTrackingParticles() == 0:
813 bestTP = track.bestMatchingTrackingParticle()
814 if bestTP
is not None:
815 lst.extend(self.
_printTrackingParticles(pfx, [bestTP],
"not matched to any TP, but a following TP with >= 3 matched hits is found (shared hit fraction %.2f)" % track.bestMatchingTrackingParticleShareFrac()))
817 lst.append(prefix+
"not matched to any TP")
819 lst.append(prefix+
"not matched to any TP")
821 lst.extend(self.
_printTrackingParticles(pfx, [tpInfo.trackingParticle()
for tpInfo
in track.matchedTrackingParticleInfos()],
"matched to TPs"))
829 def __init__(self, indent=0, hits=True, trackingParticles=False, trackingParticlePrinter=None, bestMatchingTrackingParticle=True):
830 super(SeedPrinter, self).
__init__(indent)
838 madeTrack =
"made track %d" % track.index()
840 madeTrack =
"did not make a track, stopReason %s" % SeedStopReason.toString(seed.stopReason())
841 if seed.stopReason() == SeedStopReason.NOT_STOPPED:
842 madeTrack +=
" (usually this means that the track was reconstructed, but rejected by the track selection)" 844 lst.append(self.
_prefix+
"Seed %d algo %s %s" % (seed.indexWithinAlgo(), Algo.toString(seed.algo()), madeTrack))
845 lst.append(self.
_prefix+
" starting state: pT %f local pos x,y %f,%f mom x,y,z %f,%f,%f" % (seed.statePt(), seed.stateTrajX(), seed.stateTrajY(), seed.stateTrajPx(), seed.stateTrajPy(), seed.stateTrajPz()))
868 if isinstance(out, list):
875 if not isinstance(out, list):
880 def diff(self, seed1, seed2, diffForTwiki=False, diffTrackingParticles=False):
892 if diffTrackingParticles:
897 def __init__(self, indent=0, hits=True, seedPrinter=SeedPrinter(), trackingParticles=
True, trackingParticlePrinter=
None, bestMatchingTrackingParticle=
True, diffForTwiki=
False):
898 super(TrackPrinter, self).
__init__(indent)
906 lst.append(self.
_prefix+
"Track %d pT %f eta %f phi %f dxy %f err %f dz %f err %f" % (track.index(), track.pt(), track.eta(), track.phi(), track.dxy(), track.dxyErr(), track.dz(), track.dzErr()))
913 oriAlgo = track.originalAlgo()
915 algoMask = track.algoMask()
916 for i
in range(Algo.algoSize):
918 algos.append(Algo.toString(i))
919 algoMask = algoMask >> 1
922 algoMaskStr =
" algoMask "+
",".
join(algos)
925 lst.append(self.
_prefix+
" pixel hits %d strip hits %d chi2/ndof %f" % (track.nPixel(), track.nStrip(), track.nChi2()))
926 lst.append(self.
_prefix+
" is %s algo %s originalAlgo %s%s stopReason %s" % (hp, Algo.toString(track.algo()), Algo.toString(track.originalAlgo()), algoMaskStr, StopReason.toString(track.stopReason())))
927 lst.append(self.
_prefix+
" px %f py %f pz %f p %f" % (track.px(), track.py(), track.pz(), math.sqrt(track.px()**2+track.py()**2+track.pz()**2)))
929 bestTP = track.bestMatchingTrackingParticle()
931 lst.append(self.
_prefix+
" best-matching TP %d" % bestTP.index())
932 lst.append(self.
_prefix+
" shared hits %d reco denom %.3f sim denom %.3f sim cluster denom %.3f" % (track.bestMatchingTrackingParticleShareFrac()*track.nValid(), track.bestMatchingTrackingParticleShareFrac(), track.bestMatchingTrackingParticleShareFracSimDenom(), track.bestMatchingTrackingParticleShareFracSimClusterDenom()))
933 lst.append(self.
_prefix+
" matching chi2/ndof %f" % track.bestMatchingTrackingParticleNormalizedChi2())
934 lst.append(self.
_prefix+
" pulls pt %f theta %f phi %f dxy %f dz %f" % (track.ptPull(), track.thetaPull(), track.phiPull(), track.dxyPull(), track.dzPull()))
978 if isinstance(out, list):
985 if not isinstance(out, list):
990 def diff(self, track1, track2, diffTrackingParticles=True):
1001 trk1TPs = [tpInfo.trackingParticle()
for tpInfo
in track1.matchedTrackingParticleInfos()]
1002 trk2TPs = [tpInfo.trackingParticle()
for tpInfo
in track2.matchedTrackingParticleInfos()]
1011 ptPull1 = track1.ptPull()
1012 ptPull2 = track2.ptPull()
1013 if ptPull1
is not None and ptPull2
is not None:
1015 pt_pull1 = fmt.format(pull=ptPull1)
1016 pt_pull2 = fmt.format(pull=ptPull2)
1017 dxy_pull1 = fmt.format(pull=track1.dxyPull())
1018 dxy_pull2 = fmt.format(pull=track2.dxyPull())
1019 dz_pull1 = fmt.format(pull=track1.dzPull())
1020 dz_pull2 = fmt.format(pull=track2.dzPull())
1024 self.
_prefix+
" pt %RED%{pt1:.3g}%ENDCOLOR% %GREEN%{pt2:.3g}%ENDCOLOR%".
format(pt1=track1.pt(), pt2=track2.pt()),
1026 if pt_pull1 !=
"None":
1027 lst.append(self.
_prefix+
" pull %RED%{pull1}%ENDCOLOR% %GREEN%{pull2}%ENDCOLOR%".
format(pull1=pt_pull1, pull2=pt_pull2))
1029 self.
_prefix+
" eta %RED%{eta1:.3g}%ENDCOLOR% %GREEN%{eta2:.3g}%ENDCOLOR%".
format(eta1=track1.eta(), eta2=track2.eta()),
1030 self.
_prefix+
" phi %RED%{phi1:.3g}%ENDCOLOR% %GREEN%{phi2:.3g}%ENDCOLOR%".
format(phi1=track1.phi(), phi2=track2.phi()),
1031 self.
_prefix+
" dxy %RED%{dxy1:.3g}%ENDCOLOR% %GREEN%{dxy2:.3g}%ENDCOLOR% ({dxy1rel:.2f}*err1, {dxy2rel:.2f}*err2)".
format(dxy1=track1.dxy(), dxy2=track2.dxy(), dxy1rel=(track2.dxy()-track1.dxy())/track1.dxyErr(), dxy2rel=(track2.dxy()-track1.dxy())/track2.dxyErr()),
1033 if dxy_pull1 !=
"None":
1034 lst.append(self.
_prefix+
" pull %RED%{pull1}%ENDCOLOR% %GREEN%{pull2}%ENDCOLOR%".
format(pull1=dxy_pull1, pull2=dxy_pull2))
1036 self.
_prefix+
" dz %RED%{dz1:.3g}%ENDCOLOR% %GREEN%{dz2:.3g}%ENDCOLOR% ({dz1rel:.2f}*err1, {dz2rel:.2f}*err2)".
format(dz1=track1.dz(), dz2=track2.dz(), dz1rel=(track2.dz()-track1.dz())/track1.dzErr(), dz2rel=(track2.dz()-track1.dz())/track2.dzErr()),
1038 if dz_pull1 !=
"None":
1039 lst.append(self.
_prefix+
" pull %RED%{pull1}%ENDCOLOR% %GREEN%{pull2}%ENDCOLOR%".
format(pull1=dz_pull1, pull2=dz_pull2))
1041 self.
_prefix+
" chi2/ndof %RED%{chi1:.3g}%ENDCOLOR% %GREEN%{chi2:.3g}%ENDCOLOR%".
format(chi1=track1.nChi2(), chi2=track2.nChi2()),
1043 ret.extend(
_makediff(lst, lst, equalPrefix=
"?"))
1046 ret.extend(diffHits)
1050 ret.extend(self.
diffSeeds(track1, track2))
1051 if diffTrackingParticles:
1056 def __init__(self, indent=0, parentage=True, hits=True, tracks=True, trackPrinter=None, bestMatchingTrack=True, seedPrinter=SeedPrinter()):
1057 super(TrackingParticlePrinter, self).
__init__(indent)
1067 if len(tp.genPdgIds()) > 0:
1068 genIds =
" genPdgIds "+
",".
join([
str(pdgId)
for pdgId
in tp.genPdgIds()])
1070 if tp.isFromBHadron():
1071 fromB =
" from B hadron" 1073 self.
_prefix+
"TP %d pdgId %d%s%s ev:bx %d:%d pT %f eta %f phi %f" % (tp.index(), tp.pdgId(), genIds, fromB, tp.event(), tp.bunchCrossing(), tp.pt(), tp.eta(), tp.phi()),
1074 self.
_prefix+
" pixel hits %d strip hits %d numberOfTrackerHits() %d associated reco clusters %d dxy %f dz %f" % (tp.nPixel(), tp.nStrip(), tp.nTrackerHits(), tp.nRecoClusters(), tp.pca_dxy(), tp.pca_dz())
1080 prodVtx = tp.parentVertex()
1081 if prodVtx.nSourceTrackingParticles() == 1:
1082 lst.extend(self.
_printTP(
next(prodVtx.sourceTrackingParticles())))
1083 elif prodVtx.nSourceTrackingParticles() >= 2:
1085 for tp
in prodVtx.sourceTrackingParticles():
1097 if tp.parentVertex().nSourceTrackingParticles() > 0:
1098 lst.append(self.
_prefix+
" parentage chain")
1108 for simhit
in tp.simHits():
1110 for h
in simhit.hits():
1111 tmp.append(
",".
join([
str(trk.index())
for trk
in h.tracks()]) +
":%d"%h.index())
1113 matched =
"not matched to any Track/RecHit" 1115 matched =
"matched to Tracks:RecHits "+
";".
join(tmp)
1117 lst.append(self.
_prefix+
" %s %d pdgId %d process %d detId %d %s x,y,z %f,%f,%f %s" % (simhit.layerStr(), simhit.index(), simhit.particle(), simhit.process(), simhit.detId(), simhit.detIdStr(), simhit.x(), simhit.y(), simhit.z(), matched))
1121 return [self.
_prefix+
" matched to tracks"]
1125 if header
is not None:
1126 lst.append(self.
_prefix+
" "+header)
1130 lst[-1] +=
" "+
",".
join([
str(track.index())
for track
in tracks])
1133 for track
in tracks:
1140 if tp.nMatchedTracks() == 0:
1141 header =
"not matched to any track" 1142 lst.append(self.
_prefix+
" "+header)
1144 bestTrack = tp.bestMatchingTrack()
1145 if bestTrack
is not None:
1147 lst.extend(self.
_printMatchedTracks([bestTrack], header+
", but a following track with >= 3 matched hits is found", useTrackPrinter=useTrackPrinter))
1149 lst.extend(self.
_printMatchedTracks([trkInfo.track()
for trkInfo
in tp.matchedTrackInfos()], useTrackPrinter=useTrackPrinter))
1153 ntrk1 = tp1.nMatchedTracks()
1154 ntrk2 = tp2.nMatchedTracks()
1162 trks1 = [trkInfo1.track()
for trkInfo1
in tp1.matchedTrackInfos()]
1163 trks2 = [trkInfo2.track()
for trkInfo2
in tp2.matchedTrackInfos()]
1182 return [self.
_prefix+
" not matched to any seed"]
1185 return [self.
_prefix+
" matched to seeds"]
1190 if tp.nMatchedSeeds() == 0:
1195 for seedInfo
in tp.matchedSeedInfos():
1196 lst.extend(self.
_seedPrinter.printSeed(seedInfo.seed()))
1204 nseed1 = tp1.nMatchedSeeds()
1205 nseed2 = tp2.nMatchedSeeds()
1206 if nseed1 == 0
or nseed2 == 0:
1212 seeds2 = [seedInfo2.seed()
for seedInfo2
in tp2.matchedSeedInfos()]
1213 for seedInfo1
in tp1.matchedSeedInfos():
1214 seed1 = seedInfo1.seed()
1217 if matchedSeed2
is None:
1220 seeds2.remove(matchedSeed2)
1223 for seed2
in seeds2:
1231 if isinstance(out, list):
def printHeader(self, seed)
def _mapdiff(func, obj1, obj2)
def printSeed(self, track)
def printMatchedTrackingParticles(self, prefix, track)
def printHits(self, track)
def __init__(self, trackingParticles, trackingParticlePrinter, bestMatchingTrackingParticle)
def trks2OutsideList(self)
def setIndentFrom(self, printer, adjust=0)
def __init__(self, indent=0)
def __call__(self, tp, out=sys.stdout)
def __init__(self, indent=0, parentage=True, hits=True, tracks=True, trackPrinter=None, bestMatchingTrack=True, seedPrinter=SeedPrinter())
_trackingParticleMatchPrinter
def hasCommonTrackingParticle(self)
def bestMatchingTrackingParticle(self)
def highlightLines(self, plusregexs=[], minusregexs=[])
def _highlightLine(self, line, plus, minus)
def diff(self, track1, track2, diffTrackingParticles=True)
def _areSameTracks(trk1, trk2)
def printTrackAndMatchedTrackingParticles(self, track)
def diffMatchedTracks(self, tp1, tp2)
def _makediff(list1, list2, equalPrefix=" ")
def _printMatchedTracksHeader(self)
def __init__(self, indent=0, hits=True, seedPrinter=SeedPrinter(), trackingParticles=True, trackingParticlePrinter=None, bestMatchingTrackingParticle=True, diffForTwiki=False)
def _formatHitDiffForTwiki(diffHits, prefix)
def setDifference(self, diff=True)
def highlight(self, plus=False, minus=False)
def __call__(self, seed, out=sys.stdout)
def __init__(self, diff=[], hasDifference=False)
def printMatchedSeeds(self, tp)
def extendTrks1(self, trks)
def diffTrackListsFromSameTrackingParticle(trackPrinter, lst1, lst2, lst1extra=[], lst2extra=[], diffByHitsOnly=False)
def __init__(self, indent=0, hits=True, trackingParticles=False, trackingParticlePrinter=None, bestMatchingTrackingParticle=True)
def _matchTracksByHits(reftrk, trklist)
def _commonHits(trk1, trk2)
def __init__(self, trklist)
def _hitPatternSummary(hits)
def _printTrackingParticles(self, prefix, tps, header)
def diffTrackListsGeneric(trackPrinter, lst1, lst2, ignoreAdditionalLst2=False)
def _printMatchedTracks(self, tracks, header=None, useTrackPrinter=True)
def __init__(self, indent=0)
def printMatchedTrackingParticles(self, track)
def printHits(self, seed)
def _parentageChain(self, tp)
def extendTrks2(self, trks)
static std::string join(char **cmd)
def __call__(self, track, out=sys.stdout)
def printMatchedTracks(self, tp, useTrackPrinter=True)
def printTrack(self, track)
_bestMatchingTrackingParticle
def extend(self, trks1=[], trks2=[], trks1OutsideList=[], trks2OutsideList=[])
def _difflist(list1, list2)
def extendTrks2OutsideList(self, trks)
def printSeed(self, seed)
def trks1OutsideList(self)
def diffSeeds(self, track1, track2)
def extendTrks1OutsideList(self, trks)
def diffMatchedSeeds(self, tp1, tp2)
def printHeader(self, track)
def diff(self, seed1, seed2, diffForTwiki=False, diffTrackingParticles=False)
def _printMatchedSeeds0(self)
def _associateTracksByTrackingParticlesAndHits(lst1, lst2)
def _printMatchedSeedsHeader(self)
_trackingParticleMatchPrinter
def _printHits(self, hits)
def _extend(self, trks, name)
def printMatchedTrackingParticles(self, seed)
def printTrackingParticle(self, tp)