CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
ntuplePrintersDiff.TrackingParticlePrinter Class Reference
Inheritance diagram for ntuplePrintersDiff.TrackingParticlePrinter:
ntuplePrintersDiff._IndentPrinter

Public Member Functions

def __call__ (self, tp, out=sys.stdout)
 
def __init__ (self, indent=0, parentage=True, hits=True, tracks=True, trackPrinter=None, bestMatchingTrack=True, seedPrinter=SeedPrinter())
 
def diff (self, tp1, tp2)
 
def diffMatchedSeeds (self, tp1, tp2)
 
def diffMatchedTracks (self, tp1, tp2)
 
def printHits (self, tp)
 
def printMatchedSeeds (self, tp)
 
def printMatchedTracks (self, tp, useTrackPrinter=True)
 
def printTrackingParticle (self, tp)
 
- Public Member Functions inherited from ntuplePrintersDiff._IndentPrinter
def __init__ (self, indent=0)
 
def indent (self, num)
 
def restoreIndent (self)
 
def setIndentFrom (self, printer, adjust=0)
 

Private Member Functions

def _parentageChain (self, tp)
 
def _printMatchedSeeds0 (self)
 
def _printMatchedSeedsHeader (self)
 
def _printMatchedTracks (self, tracks, header=None, useTrackPrinter=True)
 
def _printMatchedTracksHeader (self)
 
def _printTP (self, tp)
 

Private Attributes

 _bestMatchingTrack
 
 _hits
 
 _parentage
 
 _seedPrinter
 
 _trackPrinter
 
 _tracks
 

Detailed Description

Definition at line 1051 of file ntuplePrintersDiff.py.

Constructor & Destructor Documentation

def ntuplePrintersDiff.TrackingParticlePrinter.__init__ (   self,
  indent = 0,
  parentage = True,
  hits = True,
  tracks = True,
  trackPrinter = None,
  bestMatchingTrack = True,
  seedPrinter = SeedPrinter() 
)

Definition at line 1052 of file ntuplePrintersDiff.py.

1052  def __init__(self, indent=0, parentage=True, hits=True, tracks=True, trackPrinter=None, bestMatchingTrack=True, seedPrinter=SeedPrinter()):
1053  super(TrackingParticlePrinter, self).__init__(indent)
1054  self._parentage = parentage
1055  self._hits = hits
1056  self._tracks = tracks
1057  self._trackPrinter = trackPrinter
1058  self._bestMatchingTrack = bestMatchingTrack
1059  self._seedPrinter = seedPrinter
1060 
def __init__(self, indent=0, parentage=True, hits=True, tracks=True, trackPrinter=None, bestMatchingTrack=True, seedPrinter=SeedPrinter())

Member Function Documentation

def ntuplePrintersDiff.TrackingParticlePrinter.__call__ (   self,
  tp,
  out = sys.stdout 
)

Definition at line 1226 of file ntuplePrintersDiff.py.

References HGCalEgammaIDHelper.printHits(), TkAccumulatingSensitiveDetector.printHits, hgcal::EGammaPCAHelper.printHits(), MuonSensitiveDetector.printHits, GlobalTrajectoryBuilderBase.printHits(), GlobalMuonRefitter.printHits(), ntuplePrintersDiff.SeedPrinter.printHits(), ntuplePrintersDiff.TrackPrinter.printHits(), ntuplePrintersDiff.TrackingParticlePrinter.printHits(), ntuplePrintersDiff.TrackingParticlePrinter.printMatchedSeeds(), ntuplePrintersDiff.TrackingParticlePrinter.printMatchedTracks(), and ntuplePrintersDiff.TrackingParticlePrinter.printTrackingParticle().

1226  def __call__(self, tp, out=sys.stdout):
1227  if isinstance(out, list):
1228  lst = out
1229  else:
1230  lst = []
1231 
1232  lst.extend(self.printTrackingParticle(tp))
1233  lst.extend(self.printHits(tp))
1234  lst.extend(self.printMatchedTracks(tp))
1235  lst.extend(self.printMatchedSeeds(tp))
1236 
1237  for line in lst:
1238  out.write(line)
1239  out.write("\n")
1240 
def printMatchedTracks(self, tp, useTrackPrinter=True)
def ntuplePrintersDiff.TrackingParticlePrinter._parentageChain (   self,
  tp 
)
private

Definition at line 1074 of file ntuplePrintersDiff.py.

References ntuplePrintersDiff.TrackingParticlePrinter._parentageChain(), ntuplePrintersDiff.TrackingParticlePrinter._printTP(), Mixins.PrintOptions.indent(), FWLayoutBuilder.indent(), edm::DocFormatHelper.indent(), Json::StyledWriter.indent(), FWDialogBuilder.indent(), edm::service::ELdestination.indent, Json::StyledStreamWriter.indent(), JsonOutputProducer.indent(), ntuplePrintersDiff._IndentPrinter.indent(), and GetRecoTauVFromDQM_MC_cff.next.

Referenced by ntuplePrintersDiff.TrackingParticlePrinter._parentageChain(), and ntuplePrintersDiff.TrackingParticlePrinter.printTrackingParticle().

1074  def _parentageChain(self, tp):
1075  lst = []
1076  prodVtx = tp.parentVertex()
1077  if prodVtx.nSourceTrackingParticles() == 1:
1078  lst.extend(self._printTP(next(prodVtx.sourceTrackingParticles())))
1079  elif prodVtx.nSourceTrackingParticles() >= 2:
1080  self.indent(1)
1081  for tp in prodVtx.sourceTrackingParticles():
1082  self._printTP(tp, out)
1083  self.indent(1)
1084  lst.extend(self._parentageChain(tp))
1085  self.indent(-1)
1086  self.indent(-1)
1087  return lst
1088 
def ntuplePrintersDiff.TrackingParticlePrinter._printMatchedSeeds0 (   self)
private
def ntuplePrintersDiff.TrackingParticlePrinter._printMatchedSeedsHeader (   self)
private
def ntuplePrintersDiff.TrackingParticlePrinter._printMatchedTracks (   self,
  tracks,
  header = None,
  useTrackPrinter = True 
)
private

Definition at line 1119 of file ntuplePrintersDiff.py.

References CommonAnalyzer._prefix, ntupleDataFormat._Object._prefix, ntupleDataFormat.BeamSpot._prefix, html.PageSet._prefix, ntuplePrintersDiff._IndentPrinter._prefix, ntuplePrintersDiff.TrackingParticlePrinter._printMatchedTracksHeader(), ntuplePrintersDiff.TrackingParticlePrinter._trackPrinter, join(), and harvestTrackValidationPlots.str.

Referenced by ntuplePrintersDiff.TrackingParticlePrinter.printMatchedTracks().

1119  def _printMatchedTracks(self, tracks, header=None, useTrackPrinter=True):
1120  lst = []
1121  if header is not None:
1122  lst.append(self._prefix+" "+header)
1123  else:
1124  lst.extend(self._printMatchedTracksHeader())
1125  if self._trackPrinter is None or not useTrackPrinter:
1126  lst[-1] += " "+",".join([str(track.index()) for track in tracks])
1127  else:
1128  self._trackPrinter.indent(2)
1129  for track in tracks:
1130  lst.extend(self._trackPrinter.printTrack(track))
1131  self._trackPrinter.restoreIndent()
1132  return lst
1133 
def _printMatchedTracks(self, tracks, header=None, useTrackPrinter=True)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def ntuplePrintersDiff.TrackingParticlePrinter._printMatchedTracksHeader (   self)
private
def ntuplePrintersDiff.TrackingParticlePrinter._printTP (   self,
  tp 
)
private

Definition at line 1061 of file ntuplePrintersDiff.py.

References CommonAnalyzer._prefix, ntupleDataFormat._Object._prefix, ntupleDataFormat.BeamSpot._prefix, html.PageSet._prefix, ntuplePrintersDiff._IndentPrinter._prefix, join(), and harvestTrackValidationPlots.str.

Referenced by ntuplePrintersDiff.TrackingParticlePrinter._parentageChain(), and ntuplePrintersDiff.TrackingParticlePrinter.printTrackingParticle().

1061  def _printTP(self, tp):
1062  genIds = ""
1063  if len(tp.genPdgIds()) > 0:
1064  genIds = " genPdgIds "+",".join([str(pdgId) for pdgId in tp.genPdgIds()])
1065  fromB = ""
1066  if tp.isFromBHadron():
1067  fromB = " from B hadron"
1068  return [
1069  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()),
1070  self._prefix+" pixel hits %d strip hits %d dxy %f dz %f" % (tp.nPixel(), tp.nStrip(), tp.pca_dxy(), tp.pca_dz())
1071  ]
1072 
1073 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def ntuplePrintersDiff.TrackingParticlePrinter.diff (   self,
  tp1,
  tp2 
)

Definition at line 1241 of file ntuplePrintersDiff.py.

References ntuplePrintersDiff._mapdiff(), ntuplePrintersDiff.TrackingParticlePrinter.diffMatchedSeeds(), ntuplePrintersDiff.TrackingParticlePrinter.diffMatchedTracks(), HGCalEgammaIDHelper.printHits(), TkAccumulatingSensitiveDetector.printHits, hgcal::EGammaPCAHelper.printHits(), MuonSensitiveDetector.printHits, GlobalTrajectoryBuilderBase.printHits(), GlobalMuonRefitter.printHits(), ntuplePrintersDiff.SeedPrinter.printHits(), ntuplePrintersDiff.TrackPrinter.printHits(), ntuplePrintersDiff.TrackingParticlePrinter.printHits(), and ntuplePrintersDiff.TrackingParticlePrinter.printTrackingParticle().

1241  def diff(self, tp1, tp2):
1242  ret = _DiffResult()
1243  ret.extend(_mapdiff(self.printTrackingParticle, tp1, tp2))
1244  ret.extend(_mapdiff(self.printHits, tp1, tp2))
1245  ret.extend(self.diffMatchedTracks(tp1, tp2))
1246  ret.extend(self.diffMatchedSeeds(tp1, tp2))
1247  return ret
1248 
def ntuplePrintersDiff.TrackingParticlePrinter.diffMatchedSeeds (   self,
  tp1,
  tp2 
)

Definition at line 1196 of file ntuplePrintersDiff.py.

References ntuplePrintersDiff._makediff(), ntuplePrintersDiff._matchTracksByHits(), ntuplePrintersDiff.TrackingParticlePrinter._printMatchedSeedsHeader(), ntuplePrintersDiff.TrackPrinter._seedPrinter, ntuplePrintersDiff.TrackingParticlePrinter._seedPrinter, and ntuplePrintersDiff.TrackingParticlePrinter.printMatchedSeeds().

Referenced by ntuplePrintersDiff.TrackingParticlePrinter.diff().

1196  def diffMatchedSeeds(self, tp1, tp2):
1197  if not self._seedPrinter:
1198  return []
1199 
1200  nseed1 = tp1.nMatchedSeeds()
1201  nseed2 = tp2.nMatchedSeeds()
1202  if nseed1 == 0 or nseed2 == 0:
1203  return _makediff(self.printMatchedSeeds(tp1), self.printMatchedSeeds(tp2))
1204 
1205  self._seedPrinter.setIndentFrom(self, adjust=2)
1206 
1208  seeds2 = [seedInfo2.seed() for seedInfo2 in tp2.matchedSeedInfos()]
1209  for seedInfo1 in tp1.matchedSeedInfos():
1210  seed1 = seedInfo1.seed()
1211  matchedSeed2 = _matchTracksByHits(seed1, seeds2)[0]
1212 
1213  if matchedSeed2 is None: # no more seeds in tp2
1214  diff.extend(_makediff(self._seedPrinter.printSeed(seed1), []))
1215  else: # diff seed1 to best-matching seed from tp2
1216  seeds2.remove(matchedSeed2)
1217  diff.extend(_makediff(self._seedPrinter.printSeed(seed1), self._seedPrinter.printSeed(matchedSeed2)))
1218 
1219  for seed2 in seeds2: # remiaining seeds in tp2
1220  diff.extend(_makediff([], self._seedPrinter.printSeed(seed2)))
1221 
1222  self._seedPrinter.restoreIndent()
1223 
1224  return diff
1225 
def _makediff(list1, list2, equalPrefix=" ")
def _matchTracksByHits(reftrk, trklist)
def ntuplePrintersDiff.TrackingParticlePrinter.diffMatchedTracks (   self,
  tp1,
  tp2 
)

Definition at line 1148 of file ntuplePrintersDiff.py.

References ntuplePrintersDiff._makediff(), ntuplePrintersDiff.TrackingParticlePrinter._printMatchedTracksHeader(), ntuplePrintersDiff.TrackingParticlePrinter._trackPrinter, ntuplePrintersDiff.diffTrackListsFromSameTrackingParticle(), and ntuplePrintersDiff.TrackingParticlePrinter.printMatchedTracks().

Referenced by ntuplePrintersDiff.TrackingParticlePrinter.diff().

1148  def diffMatchedTracks(self, tp1, tp2):
1149  ntrk1 = tp1.nMatchedTracks()
1150  ntrk2 = tp2.nMatchedTracks()
1151 
1152  if ntrk1 == 0 or ntrk2 == 0 or self._trackPrinter is None:
1153  return _makediff(self.printMatchedTracks(tp1), self.printMatchedTracks(tp2))
1154 
1155  self._trackPrinter.indent(2)
1156 
1158  trks1 = [trkInfo1.track() for trkInfo1 in tp1.matchedTrackInfos()]
1159  trks2 = [trkInfo2.track() for trkInfo2 in tp2.matchedTrackInfos()]
1160  #for trkInfo1 in tp1.matchedTrackInfos():
1161  # trk1 = trkInfo1.track()
1162  # matchedTrk2 = _matchTracksByHits(trk1, trks2)
1163  #
1164  # if matchedTrk2 is None: # no more tracks in tp2
1165  # diff.extend(_makediff(self._trackPrinter.printTrack(trk1), []))
1166  # else: # diff trk1 to best-matching track from tp2
1167  # trks2.remove(matchedTrk2)
1168  # diff.extend(self._trackPrinter.diff(trk1, matchedTrk2))
1169  #
1170  #for trk2 in trks2: # remaining tracks in tp2
1171  # diff.extend(_makediff([], self._trackPrinter.printTrack(trk2)))
1172  diff.extend(diffTrackListsFromSameTrackingParticle(self._trackPrinter, trks1, trks2))
1173 
1174  self._trackPrinter.restoreIndent()
1175  return diff
1176 
def _makediff(list1, list2, equalPrefix=" ")
def diffTrackListsFromSameTrackingParticle(trackPrinter, lst1, lst2, lst1extra=[], lst2extra=[], diffByHitsOnly=False)
def printMatchedTracks(self, tp, useTrackPrinter=True)
def ntuplePrintersDiff.TrackingParticlePrinter.printHits (   self,
  tp 
)

Definition at line 1100 of file ntuplePrintersDiff.py.

References ntuplePrintersDiff._hitPatternSummary(), TrackerHitsObject._hits, FP420HitsObject._hits, SortingOutput._hits, MatchingOutput._hits, DTBtiChip._hits, ntuplePrintersDiff.SeedPrinter._hits, ntuplePrintersDiff.TrackPrinter._hits, ntuplePrintersDiff.TrackingParticlePrinter._hits, CommonAnalyzer._prefix, ntupleDataFormat._Object._prefix, ntupleDataFormat.BeamSpot._prefix, html.PageSet._prefix, ntuplePrintersDiff._IndentPrinter._prefix, join(), and harvestTrackValidationPlots.str.

Referenced by ntuplePrintersDiff.TrackingParticlePrinter.__call__(), and ntuplePrintersDiff.TrackingParticlePrinter.diff().

1100  def printHits(self, tp):
1101  lst = []
1102  if self._hits:
1103  lst.append(self._prefix+" sim hits"+_hitPatternSummary(tp.simHits()))
1104  for simhit in tp.simHits():
1105  tmp = []
1106  for h in simhit.hits():
1107  tmp.append(",".join([str(trk.index()) for trk in h.tracks()]) + ":%d"%h.index())
1108  if len(tmp) == 0:
1109  matched = "not matched to any Track/RecHit"
1110  else:
1111  matched = "matched to Tracks:RecHits "+";".join(tmp)
1112 
1113  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))
1114  return lst
1115 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def ntuplePrintersDiff.TrackingParticlePrinter.printMatchedSeeds (   self,
  tp 
)

Definition at line 1183 of file ntuplePrintersDiff.py.

References ntuplePrintersDiff.TrackingParticlePrinter._printMatchedSeeds0(), ntuplePrintersDiff.TrackingParticlePrinter._printMatchedSeedsHeader(), ntuplePrintersDiff.TrackPrinter._seedPrinter, and ntuplePrintersDiff.TrackingParticlePrinter._seedPrinter.

Referenced by ntuplePrintersDiff.TrackingParticlePrinter.__call__(), and ntuplePrintersDiff.TrackingParticlePrinter.diffMatchedSeeds().

1183  def printMatchedSeeds(self, tp):
1184  lst = []
1185  if self._seedPrinter:
1186  if tp.nMatchedSeeds() == 0:
1187  lst.extend(self._printMatchedSeeds0())
1188  else:
1189  lst.extend(self._printMatchedSeedsHeader())
1190  self._seedPrinter.setIndentFrom(self, adjust=2)
1191  for seedInfo in tp.matchedSeedInfos():
1192  lst.extend(self._seedPrinter.printSeed(seedInfo.seed()))
1193  self._seedPrinter.restoreIndent()
1194  return lst
1195 
def ntuplePrintersDiff.TrackingParticlePrinter.printMatchedTracks (   self,
  tp,
  useTrackPrinter = True 
)

Definition at line 1134 of file ntuplePrintersDiff.py.

References ntuplePrintersDiff.TrackingParticlePrinter._bestMatchingTrack, CommonAnalyzer._prefix, ntupleDataFormat._Object._prefix, ntupleDataFormat.BeamSpot._prefix, html.PageSet._prefix, ntuplePrintersDiff._IndentPrinter._prefix, and ntuplePrintersDiff.TrackingParticlePrinter._printMatchedTracks().

Referenced by ntuplePrintersDiff.TrackingParticlePrinter.__call__(), and ntuplePrintersDiff.TrackingParticlePrinter.diffMatchedTracks().

1134  def printMatchedTracks(self, tp, useTrackPrinter=True):
1135  lst = []
1136  if tp.nMatchedTracks() == 0:
1137  header = "not matched to any track"
1138  lst.append(self._prefix+" "+header)
1139  if self._bestMatchingTrack:
1140  bestTrack = tp.bestMatchingTrack()
1141  if bestTrack is not None:
1142  lst.pop()
1143  lst.extend(self._printMatchedTracks([bestTrack], header+", but a following track with >= 3 matched hits is found", useTrackPrinter=useTrackPrinter))
1144  else:
1145  lst.extend(self._printMatchedTracks([trkInfo.track() for trkInfo in tp.matchedTrackInfos()], useTrackPrinter=useTrackPrinter))
1146  return lst
1147 
def _printMatchedTracks(self, tracks, header=None, useTrackPrinter=True)
def printMatchedTracks(self, tp, useTrackPrinter=True)
def ntuplePrintersDiff.TrackingParticlePrinter.printTrackingParticle (   self,
  tp 
)

Definition at line 1089 of file ntuplePrintersDiff.py.

References ntuplePrintersDiff.TrackingParticlePrinter._parentage, ntuplePrintersDiff.TrackingParticlePrinter._parentageChain(), CommonAnalyzer._prefix, ntupleDataFormat._Object._prefix, ntupleDataFormat.BeamSpot._prefix, html.PageSet._prefix, ntuplePrintersDiff._IndentPrinter._prefix, ntuplePrintersDiff.TrackingParticlePrinter._printTP(), Mixins.PrintOptions.indent(), FWLayoutBuilder.indent(), edm::DocFormatHelper.indent(), Json::StyledWriter.indent(), FWDialogBuilder.indent(), edm::service::ELdestination.indent, Json::StyledStreamWriter.indent(), JsonOutputProducer.indent(), and ntuplePrintersDiff._IndentPrinter.indent().

Referenced by ntuplePrintersDiff.TrackingParticlePrinter.__call__(), and ntuplePrintersDiff.TrackingParticlePrinter.diff().

1089  def printTrackingParticle(self, tp):
1090  lst = []
1091  lst.extend(self._printTP(tp))
1092  if self._parentage:
1093  if tp.parentVertex().nSourceTrackingParticles() > 0:
1094  lst.append(self._prefix+" parentage chain")
1095  self.indent(2)
1096  lst.extend(self._parentageChain(tp))
1097  self.indent(-2)
1098  return lst
1099 

Member Data Documentation

ntuplePrintersDiff.TrackingParticlePrinter._bestMatchingTrack
private
ntuplePrintersDiff.TrackingParticlePrinter._parentage
private
ntuplePrintersDiff.TrackingParticlePrinter._seedPrinter
private
ntuplePrintersDiff.TrackingParticlePrinter._trackPrinter
private
ntuplePrintersDiff.TrackingParticlePrinter._tracks
private

Definition at line 1056 of file ntuplePrintersDiff.py.