File indexing completed on 2024-11-26 02:34:40
0001
0002
0003 import argparse
0004
0005 import Validation.RecoTrack.plotting.ntuple as ntuple
0006
0007
0008 def findEvent(ntpl, event):
0009 eventId = event.split(":")
0010 if len(eventId) != 3:
0011 raise Exception("Malformed eventId %s, is not run:lumi:event" % eventId)
0012 eventId = (int(eventId[0]), int(eventId[1]), int(eventId[2]))
0013
0014 for ev in ntpl:
0015 if ev.eventId() == eventId:
0016 return ev
0017
0018 raise Exception("Did not find event %s from file %s" % (eventId, ntpl.file().GetPath()))
0019
0020 def main(opts):
0021 if opts.track is None and opts.trackingParticle is None and opts.seed is None and opts.pixelHit is None and opts.stripHit is None:
0022 return
0023
0024 ntpl = ntuple.TrackingNtuple(opts.file)
0025
0026 if opts.entry is not None:
0027 event = ntpl.getEvent(opts.entry)
0028 print(event.eventIdStr())
0029 elif opts.event is not None:
0030 event = findEvent(ntpl, opts.event)
0031 print("Entry %d" % event.entry())
0032
0033 hasHits = ntpl.hasHits()
0034 hasSeeds = ntpl.hasSeeds()
0035
0036 if not hasSeeds and opts.seed is not None:
0037 print("Ntuple %s does not have seeds saved!" % opts.file)
0038 return
0039 if not hasHits and (opts.pixelHit is not None or opts.stripHit is not None):
0040 print("Ntuple %s does not have hits saved!" % opts.file)
0041 return
0042
0043 seedArgs = dict(hits=hasHits, bestMatchingTrackingParticle=hasHits)
0044 trackArgs = dict(hits=hasHits, bestMatchingTrackingParticle=hasHits)
0045 tpArgs = dict(hits=hasHits, bestMatchingTrack=hasHits)
0046 if not hasSeeds:
0047 trackArgs["seedPrinter"] = None
0048 tpArgs["seedPrinter"] = None
0049 elif not hasHits:
0050 trackArgs["seedPrinter"] = ntuple.SeedPrinter(**seedArgs)
0051 tpArgs["seedPrinter"] = ntuple.SeedPrinter(**seedArgs)
0052
0053 printSeed = ntuple.SeedPrinter(trackingParticles=True, trackingParticlePrinter=ntuple.TrackingParticlePrinter(**tpArgs), **seedArgs)
0054 printTrack = ntuple.TrackPrinter(trackingParticlePrinter=ntuple.TrackingParticlePrinter(**tpArgs), **trackArgs)
0055 printTrackingParticle = ntuple.TrackingParticlePrinter(trackPrinter=ntuple.TrackPrinter(**trackArgs), **tpArgs)
0056
0057 if opts.track is not None:
0058 trks = event.tracks()
0059 if opts.track >= len(trks):
0060 print("You requested track %d, but this event has only %d tracks" % (opts.track, len(trks)))
0061 return
0062 trk = trks[opts.track]
0063 printTrack(trk)
0064
0065 if opts.trackingParticle is not None:
0066 tps = event.trackingParticles()
0067 if opts.trackingParticle >= len(tps):
0068 print("You requested TrackingParticle %d, but this event has ony %d TrackingParticles" % (opts.trackingParticle, len(tps)))
0069 return
0070 tp = tps[opts.trackingParticle]
0071 printTrackingParticle(tp)
0072
0073 if opts.seed is not None:
0074 seeds = event.seeds()
0075 if opts.seedIteration is not None:
0076 algo = getattr(ntuple.Algo, opts.seedIteration)
0077 if opts.seed >= seeds.nSeedsForAlgo(algo):
0078 print("You requested seed %d for algo %s, but this event has only %d seeds for that algo" % (opts.seed, opts.seedIteration, seeds.nSeedsForAlgo(algo)))
0079 return
0080 seed = seeds.seedForAlgo(algo, opts.seed)
0081 else:
0082 if opts.seed >= len(seeds):
0083 print("You requested seed %d, but this event has only %d seeds" % (opts.seed, len(seeds)))
0084 return
0085 seed = seeds[opts.seed]
0086 printSeed(seed)
0087
0088 if opts.pixelHit is not None:
0089 hits = event.pixelHits()
0090 if opts.pixelHit >= len(hits):
0091 print("You requested pixel hit %d, but this event has only %d pixel hits" % (opts.pixelHit, len(hits)))
0092 return
0093
0094 hit = hits[opts.pixelHit]
0095 print("Pixel hit %d tracks" % opts.pixelHit)
0096 for t in hit.tracks():
0097 printTrack(t)
0098 if hasSeeds:
0099 print("Pixel hit %d seeds" % opts.pixelHit)
0100 for s in hit.seeds():
0101 printSeed(s)
0102
0103 if opts.stripHit is not None:
0104 hits = event.stripHits()
0105 if opts.stripHit >= len(hits):
0106 print("You requested strip hit %d, but this event has only %d strip hits" % (opts.stripHit, len(hits)))
0107 return
0108 hit = hits[opts.stripHit]
0109 print("Strip hit %d tracks" % opts.stripHit)
0110 for t in hit.tracks():
0111 printTrack(t)
0112 if hasSeeds:
0113 print("Strip hit %d seeds" % opts.stripHit)
0114 for s in hit.seeds():
0115 printSeed(s)
0116
0117
0118 if __name__ == "__main__":
0119 parser = argparse.ArgumentParser(description="Print information from a TrackingNtuple file")
0120 parser.add_argument("file", type=str,
0121 help="Input file")
0122
0123 parser.add_argument("--entry", type=int,
0124 help="Entry in a file to print information for (conflicts with --event)")
0125 parser.add_argument("--event", type=str,
0126 help="Event in a file to print information for, in a format run:lumi:event (conflicts with --entry)")
0127
0128 parser.add_argument("--track", type=int,
0129 help="Index of a track to print information for")
0130 parser.add_argument("--trackingParticle", type=int,
0131 help="Index of a TrackingParticle to print information for")
0132 parser.add_argument("--seed", type=int,
0133 help="Index of a seed to print information for. If --seedIteration is specified, the index is within the iteration. Without --seedIteration it is used as a global index.")
0134 parser.add_argument("--seedIteration", type=str,
0135 help="Seed iteration, used optionally with --seed")
0136 parser.add_argument("--pixelHit", type=int,
0137 help="Index of a pixel hit")
0138 parser.add_argument("--stripHit", type=int,
0139 help="Index of a strip hit")
0140
0141 opts = parser.parse_args()
0142
0143 if opts.entry is None and opts.event is None:
0144 parser.error("Need either --entry or --event, neither was given")
0145 if opts.entry is not None and opts.event is not None:
0146 parser.error("--entry and --event conflict, please give only one of them")
0147
0148 main(opts)
0149
0150