3 from __future__
import print_function
6 import Validation.RecoTrack.plotting.ntuple
as ntuple
10 eventId = event.split(
":")
12 raise Exception(
"Malformed eventId %s, is not run:lumi:event" % eventId)
13 eventId = (
int(eventId[0]),
int(eventId[1]),
int(eventId[2]))
16 if ev.eventId() == eventId:
19 raise Exception(
"Did not find event %s from file %s" % (eventId, ntpl.file().GetPath()))
22 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:
25 ntpl = ntuple.TrackingNtuple(opts.file)
27 if opts.entry
is not None:
28 event = ntpl.getEvent(opts.entry)
29 print(event.eventIdStr())
30 elif opts.event
is not None:
32 print(
"Entry %d" % event.entry())
34 hasHits = ntpl.hasHits()
35 hasSeeds = ntpl.hasSeeds()
37 if not hasSeeds
and opts.seed
is not None:
38 print(
"Ntuple %s does not have seeds saved!" % opts.file)
40 if not hasHits
and (opts.pixelHit
is not None or opts.stripHit
is not None):
41 print(
"Ntuple %s does not have hits saved!" % opts.file)
44 seedArgs = dict(hits=hasHits, bestMatchingTrackingParticle=hasHits)
45 trackArgs = dict(hits=hasHits, bestMatchingTrackingParticle=hasHits)
46 tpArgs = dict(hits=hasHits, bestMatchingTrack=hasHits)
48 trackArgs[
"seedPrinter"] =
None
49 tpArgs[
"seedPrinter"] =
None
51 trackArgs[
"seedPrinter"] = ntuple.SeedPrinter(**seedArgs)
52 tpArgs[
"seedPrinter"] = ntuple.SeedPrinter(**seedArgs)
54 printSeed = ntuple.SeedPrinter(trackingParticles=
True, trackingParticlePrinter=ntuple.TrackingParticlePrinter(**tpArgs), **seedArgs)
55 printTrack = ntuple.TrackPrinter(trackingParticlePrinter=ntuple.TrackingParticlePrinter(**tpArgs), **trackArgs)
56 printTrackingParticle = ntuple.TrackingParticlePrinter(trackPrinter=ntuple.TrackPrinter(**trackArgs), **tpArgs)
58 if opts.track
is not None:
60 if opts.track >= len(trks):
61 print(
"You requested track %d, but this event has only %d tracks" % (opts.track, len(trks)))
63 trk = trks[opts.track]
66 if opts.trackingParticle
is not None:
67 tps = event.trackingParticles()
68 if opts.trackingParticle >= len(tps):
69 print(
"You requested TrackingParticle %d, but this event has ony %d TrackingParticles" % (opts.trackingParticle, len(tps)))
71 tp = tps[opts.trackingParticle]
72 printTrackingParticle(tp)
74 if opts.seed
is not None:
76 if opts.seedIteration
is not None:
77 algo = getattr(ntuple.Algo, opts.seedIteration)
78 if opts.seed >= seeds.nSeedsForAlgo(algo):
79 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)))
81 seed = seeds.seedForAlgo(algo, opts.seed)
83 if opts.seed >= len(seeds):
84 print(
"You requested seed %d, but this event has only %d seeds" % (opts.seed, len(seeds)))
86 seed = seeds[opts.seed]
89 if opts.pixelHit
is not None:
90 hits = event.pixelHits()
91 if opts.pixelHit >= len(hits):
92 print(
"You requested pixel hit %d, but this event has only %d pixel hits" % (opts.pixelHit, len(hits)))
95 hit = hits[opts.pixelHit]
96 print(
"Pixel hit %d tracks" % opts.pixelHit)
97 for t
in hit.tracks():
100 print(
"Pixel hit %d seeds" % opts.pixelHit)
101 for s
in hit.seeds():
104 if opts.stripHit
is not None:
105 hits = event.stripHits()
106 if opts.stripHit >= len(hits):
107 print(
"You requested strip hit %d, but this event has only %d strip hits" % (opts.stripHit, len(hits)))
109 hit = hits[opts.stripHit]
110 print(
"Strip hit %d tracks" % opts.stripHit)
111 for t
in hit.tracks():
114 print(
"Strip hit %d seeds" % opts.stripHit)
115 for s
in hit.seeds():
119 if __name__ ==
"__main__":
120 parser = argparse.ArgumentParser(description=
"Print information from a TrackingNtuple file")
121 parser.add_argument(
"file", type=str,
124 parser.add_argument(
"--entry", type=int,
125 help=
"Entry in a file to print information for (conflicts with --event)")
126 parser.add_argument(
"--event", type=str,
127 help=
"Event in a file to print information for, in a format run:lumi:event (conflicts with --entry)")
129 parser.add_argument(
"--track", type=int,
130 help=
"Index of a track to print information for")
131 parser.add_argument(
"--trackingParticle", type=int,
132 help=
"Index of a TrackingParticle to print information for")
133 parser.add_argument(
"--seed", type=int,
134 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.")
135 parser.add_argument(
"--seedIteration", type=str,
136 help=
"Seed iteration, used optionally with --seed")
137 parser.add_argument(
"--pixelHit", type=int,
138 help=
"Index of a pixel hit")
139 parser.add_argument(
"--stripHit", type=int,
140 help=
"Index of a strip hit")
142 opts = parser.parse_args()
144 if opts.entry
is None and opts.event
is None:
145 parser.error(
"Need either --entry or --event, neither was given")
146 if opts.entry
is not None and opts.event
is not None:
147 parser.error(
"--entry and --event conflict, please give only one of them")