CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions | Variables
printTrackingNtuple Namespace Reference

Functions

def findEvent
 
def main
 

Variables

string help = "Input file"
 
tuple opts = parser.parse_args()
 
tuple parser = argparse.ArgumentParser(description="Print information from a TrackingNtuple file")
 

Function Documentation

def printTrackingNtuple.findEvent (   ntpl,
  event 
)

Definition at line 9 of file printTrackingNtuple.py.

Referenced by main().

9 
10 def findEvent(ntpl, event):
11  eventId = event.split(":")
12  if len(eventId) != 3:
13  raise Exception("Malformed eventId %s, is not run:lumi:event" % eventId)
14  eventId = (int(eventId[0]), int(eventId[1]), int(eventId[2]))
15 
16  for ev in ntpl:
17  if ev.eventId() == eventId:
18  return ev
19 
20  raise Exception("Did not find event %s from file %s" % (eventId, ntpl.file().GetPath()))
def printTrackingNtuple.main (   opts)

Definition at line 21 of file printTrackingNtuple.py.

References findEvent(), and print().

21 
22 def main(opts):
23  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:
24  return
25 
26  ntpl = ntuple.TrackingNtuple(opts.file)
27 
28  if opts.entry is not None:
29  event = ntpl.getEvent(opts.entry)
30  print(event.eventIdStr())
31  elif opts.event is not None:
32  event = findEvent(ntpl, opts.event)
33  print("Entry %d" % event.entry())
34 
35  hasHits = ntpl.hasHits()
36  hasSeeds = ntpl.hasSeeds()
37 
38  if not hasSeeds and opts.seed is not None:
39  print("Ntuple %s does not have seeds saved!" % opts.file)
40  return
41  if not hasHits and (opts.pixelHit is not None or opts.stripHit is not None):
42  print("Ntuple %s does not have hits saved!" % opts.file)
43  return
44 
45  seedArgs = dict(hits=hasHits, bestMatchingTrackingParticle=hasHits)
46  trackArgs = dict(hits=hasHits, bestMatchingTrackingParticle=hasHits)
47  tpArgs = dict(hits=hasHits, bestMatchingTrack=hasHits)
48  if not hasSeeds:
49  trackArgs["seedPrinter"] = None
50  tpArgs["seedPrinter"] = None
51  elif not hasHits:
52  trackArgs["seedPrinter"] = ntuple.SeedPrinter(**seedArgs)
53  tpArgs["seedPrinter"] = ntuple.SeedPrinter(**seedArgs)
54 
55  printSeed = ntuple.SeedPrinter(trackingParticles=True, trackingParticlePrinter=ntuple.TrackingParticlePrinter(**tpArgs), **seedArgs)
56  printTrack = ntuple.TrackPrinter(trackingParticlePrinter=ntuple.TrackingParticlePrinter(**tpArgs), **trackArgs)
57  printTrackingParticle = ntuple.TrackingParticlePrinter(trackPrinter=ntuple.TrackPrinter(**trackArgs), **tpArgs)
58 
59  if opts.track is not None:
60  trks = event.tracks()
61  if opts.track >= len(trks):
62  print("You requested track %d, but this event has only %d tracks" % (opts.track, len(trks)))
63  return
64  trk = trks[opts.track]
65  printTrack(trk)
66 
67  if opts.trackingParticle is not None:
68  tps = event.trackingParticles()
69  if opts.trackingParticle >= len(tps):
70  print("You requested TrackingParticle %d, but this event has ony %d TrackingParticles" % (opts.trackingParticle, len(tps)))
71  return
72  tp = tps[opts.trackingParticle]
73  printTrackingParticle(tp)
74 
75  if opts.seed is not None:
76  seeds = event.seeds()
77  if opts.seedIteration is not None:
78  algo = getattr(ntuple.Algo, opts.seedIteration)
79  if opts.seed >= seeds.nSeedsForAlgo(algo):
80  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  return
82  seed = seeds.seedForAlgo(algo, opts.seed)
83  else:
84  if opts.seed >= len(seeds):
85  print("You requested seed %d, but this event has only %d seeds" % (opts.seed, len(seeds)))
86  return
87  seed = seeds[opts.seed]
88  printSeed(seed)
89 
90  if opts.pixelHit is not None:
91  hits = event.pixelHits()
92  if opts.pixelHit >= len(hits):
93  print("You requested pixel hit %d, but this event has only %d pixel hits" % (opts.pixelHit, len(hits)))
94  return
95 
96  hit = hits[opts.pixelHit]
97  print("Pixel hit %d tracks" % opts.pixelHit)
98  for t in hit.tracks():
99  printTrack(t)
100  if hasSeeds:
101  print("Pixel hit %d seeds" % opts.pixelHit)
102  for s in hit.seeds():
103  printSeed(s)
104 
105  if opts.stripHit is not None:
106  hits = event.stripHits()
107  if opts.stripHit >= len(hits):
108  print("You requested strip hit %d, but this event has only %d strip hits" % (opts.stripHit, len(hits)))
109  return
110  hit = hits[opts.stripHit]
111  print("Strip hit %d tracks" % opts.stripHit)
112  for t in hit.tracks():
113  printTrack(t)
114  if hasSeeds:
115  print("Strip hit %d seeds" % opts.stripHit)
116  for s in hit.seeds():
117  printSeed(s)
118 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

Variable Documentation

string printTrackingNtuple.help = "Input file"

Definition at line 122 of file printTrackingNtuple.py.

tuple printTrackingNtuple.opts = parser.parse_args()

Definition at line 142 of file printTrackingNtuple.py.

tuple printTrackingNtuple.parser = argparse.ArgumentParser(description="Print information from a TrackingNtuple file")

Definition at line 120 of file printTrackingNtuple.py.