10 """Adaptor class representing a collection of objects. 12 Concrete collection classes should inherit from this class. 15 def __init__(self, tree, sizeBranch, objclass):
20 sizeBranch -- Name of the branch to be used in size() 21 objclass -- Class to be used for the objects in __getitem__() 29 """Number of objects in the collection.""" 33 """Number of objects in the collection.""" 37 """Get object 'index' in the collection.""" 41 """Returns generator for the objects.""" 42 for index
in xrange(self.
size()):
46 """Adaptor class representing a single object in a collection. 48 The member variables of the object are obtained from the branches 49 with common prefix and a given index. 51 Concrete object classes should inherit from this class. 58 index -- Index for this object 59 prefix -- Prefix of the branchs 67 """Return object member variable. 69 'attr' is translated as a branch in the TTree (<prefix>_<attr>). 76 """Raise an exception if the object index is not valid.""" 78 raise Exception(
"%s is not valid" % self.__class__.__name__)
81 """Check if object index is valid.""" 85 """Return object index.""" 89 """Adaptor class for objects containgin DetId (hits).""" 91 super(_DetIdStrAdaptor, self).
__init__()
94 """Returns a string describing the layer of the hit.""" 96 get =
lambda name: getattr(self._tree, self._prefix+
"_"+name)[self._index]
97 subdet =
get(
"subdet")
99 isPhase2OTBarrel = (subdet == SubDet.TOB
and hasattr(self._tree, self._prefix+
"_isLower"))
100 if subdet
in [SubDet.FPix, SubDet.TID, SubDet.TEC]
or isPhase2OTBarrel:
101 sideNum =
get(
"side")
106 elif isPhase2OTBarrel
and sideNum == 3:
110 return "%s%d%s" % (SubDet.toString(subdet),
111 getattr(self._tree, self._prefix+
"_layer")[self._index],
115 """Returns a string describing the DetId fields.""" 117 get =
lambda name: getattr(self._tree, self._prefix+
"_"+name)[self._index]
118 isPhase2 = hasattr(self._tree, self._prefix+
"_isLower")
136 subdet =
get(
"subdet")
137 if subdet == SubDet.BPix:
138 return "ladder {} module {}".
format(
get(
"ladder"),
get(
"module"))
139 if subdet == SubDet.FPix:
140 return "blade {} panel {} module {}".
format(
get(
"blade"),
get(
"panel"),
get(
"module"))
141 if subdet == SubDet.TIB:
142 return "side {} order {} string {} module {}{}".
format(
get(
"side"),
get(
"order"),
get(
"string"),
get(
"module"), stereo())
143 if subdet == SubDet.TID:
144 return "ring {} order {} module {}{}".
format(
get(
"ring"),
get(
"order"),
get(
"module"), stereo())
145 if subdet == SubDet.TOB:
147 return "rod {} module {}{}".
format(
get(
"rod"),
get(
"module"), stereo())
149 return "side {} rod {} module {}{}".
format(
get(
"side"),
get(
"rod"),
get(
"module"), stereo())
150 if subdet == SubDet.TEC:
151 return "order {} petal {} ring {} module {}{}".
format(
get(
"order"),
get(
"petalNumber"),
get(
"ring"),
get(
"module"), stereo())
152 raise Exception(
"Unknown subdet %d" % subdet)
155 """Adaptor class for pixel/strip hit objects.""" 161 index -- Index for this object 162 prefix -- Prefix of the branchs 166 super(_HitObject, self).
__init__(tree, index, prefix)
169 """Returns number of tracks containing this hit.""" 174 """Returns generator for tracks containing this hit. 176 The generator returns Track objects 183 """Returns number of seeds containing this hit.""" 188 """Returns generator for tracks containing this hit. 190 The generator returns Seed objects 197 return math.sqrt(self.x()**2 + self.y()**2)
200 return math.sqrt(self.x()**2 + self.y()**2 + self.z()**2)
203 """Adaptor class for objects containing hits (e.g. tracks)""" 205 super(_RecoHitAdaptor, self).
__init__()
208 """Internal method to generate pairs of hit index and type.""" 209 for ihit, hitType
in zip(self.hitIdx(), self.hitType()):
210 yield (ihit, hitType)
213 """Returns generator for hits. 215 Generator returns PixelHit/StripHit/GluedHit/Phase2OT depending on the 219 for ihit, hitType
in self.
_hits():
231 raise Exception(
"Unknown hit type %d" % hitType)
234 """Returns generator for pixel hits.""" 236 for ihit, hitType
in self.
_hits():
242 """Returns generator for strip hits.""" 244 for ihit, hitType
in self.
_hits():
250 """Returns generator for matched strip hits.""" 252 for ihit, hitType
in self.
_hits():
258 """Returns generator for invalid hits.""" 260 for ihit, hitType
in self.
_hits():
266 """Returns generator for phase2 outer tracker hits.""" 268 for ihit, hitType
in self.
_hits():
274 """Adaptor class for objects containing or matched to SimHits (e.g. reco hits).""" 276 super(_SimHitMatchAdaptor, self).
__init__()
279 """Internal method to get the number of matched SimHits.""" 280 return getattr(self._tree, self._prefix+
"_simHitIdx")[self._index].
size()
283 """Returns the number of matched SimHits.""" 288 """Returns a generator for matched SimHits. 290 The generator returns SimHitMatchInfo objects. 297 """Adaptor class for objects matched to TrackingParticles.""" 299 super(_TrackingParticleMatchAdaptor, self).
__init__()
302 """Internal method to get the number of matched TrackingParticles.""" 303 return getattr(self._tree, self._prefix+
"_simTrkIdx")[self._index].
size()
306 """Returns the number of matched TrackingParticles.""" 311 """Returns a generator for matched TrackingParticles. 313 The generator returns TrackingParticleMatchInfo objects. 321 """Returns best-matching TrackingParticle, even for fake tracks, or None if there is no best-matching TrackingParticle. 323 Best-matching is defined as the one with largest number of 324 hits matched to the hits of a track (>= 3). If there are many 325 fulfilling the same number of hits, the one inducing the 326 innermost hit of the track is chosen. 332 tps = collections.OrderedDict()
333 for hit
in self.hits():
334 if not isinstance(hit, _SimHitMatchAdaptor):
336 for shInfo
in hit.matchedSimHitInfos():
337 tp = shInfo.simHit().trackingParticle()
338 if tp.index()
in tps:
344 for tpIndex, nhits
in tps.iteritems():
346 best = (tpIndex, nhits)
353 """Class abstracting the whole ntuple/TTree. 355 Main benefit is to provide nice interface for 356 - iterating over events 357 - querying whether hit/seed information exists 359 Note that to iteratate over the evets with zip(), you should use 360 itertools.izip() instead. 362 def __init__(self, fileName, tree="trackingNtuple/tree"):
366 fileName -- String for path to the ROOT file 367 tree -- Name of the TTree object inside the ROOT file (default: 'trackingNtuple/tree') 369 super(TrackingNtuple, self).
__init__()
370 self.
_file = ROOT.TFile.Open(fileName)
384 """Returns true if the ntuple has hit information.""" 385 return hasattr(self.
_tree,
"pix_isBarrel")
388 """Returns true if the ntuple has seed information.""" 389 return hasattr(self.
_tree,
"see_fitok")
392 """Returns generator for iterating over TTree entries (events) 394 Generator returns Event objects. 397 for jentry
in xrange(self.
_entries):
399 ientry = self._tree.LoadTree( jentry )
402 nb = self._tree.GetEntry( jentry )
408 """Returns Event for a given index""" 409 ientry = self._tree.LoadTree(index)
410 if ientry < 0:
return None 411 nb = self._tree.GetEntry(ientry)
418 """Class abstracting a single event. 420 Main benefit is to provide nice interface to get various objects 421 or collections of objects. 428 entry -- Entry number in the tree 438 """Returns event number.""" 439 return self._tree.event
442 """Returns lumisection number.""" 443 return self._tree.lumi
446 """Returns run number.""" 447 return self._tree.run
450 """Returns (run, lumi, event) tuple.""" 451 return (self._tree.run, self._tree.lumi, self._tree.event)
454 """Returns 'run:lumi:event' string.""" 455 return "%d:%d:%d" % self.
eventId()
458 """Returns BeamSpot object.""" 462 """Returns Tracks object.""" 466 """Returns PixelHits object.""" 470 """Returns StripHits object.""" 474 """Returns GluedHits object.""" 478 """Returns Phase2OTHits object.""" 482 """Returns Seeds object.""" 486 """Returns TrackingParticles object.""" 490 """Returns Vertices object.""" 494 """Returns TrackingVertices object.""" 499 """Class representing the beam spot.""" 511 """Return object member variable. 513 'attr' is translated as a branch in the TTree (bsp_<attr>). 520 """Class representing a match to a SimHit. 522 The point of this class is to provide, in addition to the matched 523 SimHit, also other information about the match (e.g. fraction of 524 charge from this SimHit). 531 index -- Index of the hit matched to SimHit 532 shindex -- Index of the SimHit match (second index in _simHitIdx branch) 533 prefix -- String for prefix of the object (track/seed/hit) matched to TrackingParticle 535 super(SimHitMatchInfo, self).
__init__(tree, index, prefix)
539 """Custom __getattr__ because of the second index needed to access the branch.""" 544 """Returns matched SimHit.""" 550 """Class representing a match to a TrackingParticle. 552 The point of this class is to provide, in addition to the matched 553 TrackingParticle, also other information about the match (e.g. 554 shared hit fraction for tracks/seeds). 561 index -- Index of the object (track/seed) matched to TrackingParticle 562 tpindex -- Index of the TrackingParticle match (second index in _simTrkIdx branch) 563 prefix -- String for prefix of the object (track/seed) matched to TrackingParticle 565 super(TrackingParticleMatchInfo, self).
__init__(tree, index, prefix)
569 """Custom __getattr__ because of the second index needed to access the branch.""" 574 """Returns matched TrackingParticle.""" 579 """Class representing a match to a Track. 581 The point of this class is to provide, in addition to the matched 582 Track, also other information about the match (e.g. shared hit fraction. 589 index -- Index of the object (TrackingParticle) matched to track 590 trkindex -- Index of the track match (second index in _trkIdx branch) 591 prefix -- String for prefix of the object (TrackingParticle) matched to track 593 super(TrackMatchInfo, self).
__init__(tree, index, prefix)
597 """Returns matched Track.""" 602 """Class representing a match to a Seed. 604 The point of this class is to provide an interface compatible with 605 all other "MatchInfo" classes 608 def __init__(self, tree, index, seedindex, prefix):
613 index -- Index of the object (TrackingParticle) matched to seed 614 seedindex -- Index of the seed match (second index in _trkIdx branch) 615 prefix -- String for prefix of the object (TrackingParticle) matched to seed 617 super(SeedMatchInfo, self).
__init__(tree, index, prefix)
621 """Returns matched Seed.""" 627 """Class presenting a track.""" 633 index -- Index of the track 635 super(Track, self).
__init__(tree, index,
"trk")
638 """Returns Seed of the track.""" 643 """Returns Vertex that used this track in its fit.""" 651 return (self.pt() - tp.pca_pt())/self.ptErr()
657 return (getattr(self,
"lambda")() - tp.pca_lambda())/self.lambdaErr()
663 return (self.phi() - tp.pca_phi())/self.phiErr()
669 return (self.dxy() - tp.pca_dxy())/self.dxyErr()
675 return (self.dz() - tp.pca_dz())/self.dzErr()
678 """Class presenting a collection of tracks.""" 685 super(Tracks, self).
__init__(tree,
"trk_pt", Track)
689 """Class representing a pixel hit.""" 695 index -- Index of the hit 697 super(PixelHit, self).
__init__(tree, index,
"pix")
703 """Class presenting a collection of pixel hits.""" 710 super(PixelHits, self).
__init__(tree,
"pix_isBarrel", PixelHit)
714 """Class representing a strip hit.""" 720 index -- Index of the hit 722 super(StripHit, self).
__init__(tree, index,
"str")
728 """Class presenting a collection of strip hits.""" 735 super(StripHits, self).
__init__(tree,
"str_isBarrel", StripHit)
739 """Class representing a matched strip hit.""" 745 index -- Index of the hit 747 super(GluedHit, self).
__init__(tree, index,
"glu")
753 """Returns a StripHit for the mono hit.""" 758 """Returns a StripHit for the stereo hit.""" 763 """Returns the number of seeds containing this hit.""" 765 return self._tree.glu_seeIdx[self.
_index].
size()
768 """Returns generator for seeds containing this hit. 770 The generator returns Seed objects 773 for iseed
in self._tree.glu_seeIdx[self.
_index]:
777 """Class presenting a collection of matched strip hits.""" 784 super(GluedHits, self).
__init__(tree,
"glu_isBarrel", GluedHit)
797 """Class representing an invalid hit.""" 803 index -- Index of the hit 805 super(InvalidHit, self).
__init__(tree, index,
"inv")
811 """Returns a string describing the layer of the hit.""" 812 invalid_type = self._tree.inv_type[self.
_index]
813 return super(InvalidHit, self).
layerStr() +
" (%s)"%InvalidHit.Type.toString(invalid_type)
817 """Class representing a phase2 OT hit.""" 823 index -- Index of the hit 825 super(Phase2OTHit, self).
__init__(tree, index,
"ph2")
831 """Class presenting a collection of phase2 OT hits.""" 838 super(Phase2OTHits, self).
__init__(tree,
"ph2_isBarrel", Phase2OTHit)
842 """Internal function for returning a pair of indices for the beginning of seeds of a given 'algo', and the one-beyond-last index of the seeds.""" 843 for ioffset, offset
in enumerate(tree.see_offset):
844 if tree.see_algo[offset] == algo:
845 next_offset = tree.see_offset[ioffset+1]
if ioffset < tree.see_offset.size()-1
else tree.see_algo.size()
846 return (offset, next_offset)
850 """Class presenting a seed.""" 856 index -- Index of the seed 858 super(Seed, self).
__init__(tree, index,
"see")
861 """Returns the seed index within the seeds of the same algo. 863 In case of errors, -1 is returned. 866 algo = self._tree.see_algo[self.
_index]
870 return self.
_index - offset
873 """Returns Track that was made from this seed.""" 878 """Class presenting a collection of seeds.""" 885 super(Seeds, self).
__init__(tree,
"see_pt", Seed)
888 """Returns the number of seeds for a given 'algo'.""" 890 return next_offset - offset
893 """Returns generator iterating over the seeds of a given 'algo'. 895 Generator returns Seed object. 898 for isee
in xrange(offset, next_offset):
902 """Returns Seed of index 'iseed' for 'algo'.""" 904 if iseed >= (next_offset-offset):
905 raise Exception(
"Seed index %d is larger than the number of seeds %d for algo %d (%s)" % (iseed, next_offset-offset, algo, Algo.toString(algo)))
910 """Class representing a SimHit which has not induced a RecHit.""" 916 index -- Index of the SimHit 918 super(SimHit, self).
__init__(tree, index,
"simhit")
922 return self._tree.simhit_hitIdx[self.
_index].
size()
930 """Class representing a TrackingParticle.""" 936 index -- Index of the TrackingParticle 938 super(TrackingParticle, self).
__init__(tree, index,
"sim")
941 """Internal function to get the number of matched tracks.""" 942 return self._tree.sim_trkIdx[self.
_index].
size()
945 """Returns the number of matched tracks.""" 950 """Returns a generator for matched tracks. 952 The generator returns TrackMatchInfo objects. 959 """Returns best-matching track, even for non-reconstructed TrackingParticles, or None, if there is no best-matching track. 961 Best-matching is defined as the one with largest number of 962 hits matched to the hits of a TrackingParticle (>= 3). If 963 there are many fulfilling the same number of hits, the one 964 inducing the innermost hit of the TrackingParticle is chosen. 970 tracks = collections.OrderedDict()
972 for recHit
in hit.hits():
973 for track
in recHit.tracks():
974 if track.index()
in tracks:
975 tracks[track.index()] += 1
977 tracks[track.index()] = 1
980 for trackIndex, nhits
in tracks.iteritems():
982 best = (trackIndex, nhits)
988 """Internal function to get the number of matched seeds.""" 989 return self._tree.sim_seedIdx[self.
_index].
size()
992 """Returns the number of matched seeds.""" 997 """Returns a generator for matched tracks. 999 The generator returns SeedMatchInfo objects. 1007 return self.simHitIdx().
size()
1010 """Returns generator for SimHits.""" 1012 for ihit
in self.simHitIdx():
1016 """Returns the parent TrackingVertex.""" 1021 """Returns a generator for decay vertices. 1023 The generator returns TrackingVertex objects. 1026 for ivtx
in self._tree.sim_decayVtxIdx[self.
_index]:
1030 """Returns True if this TrackingParticle is a looper. 1032 Note that the check involves looping over the SimHits, so it is not too cheap.""" 1035 for ihit
in self.simHitIdx():
1045 """Class presenting a collection of TrackingParticles.""" 1050 tree -- TTree object 1052 super(TrackingParticles, self).
__init__(tree,
"sim_pt", TrackingParticle)
1056 """Class presenting a primary vertex.""" 1061 tree -- TTree object 1062 index -- Index of the vertex 1064 super(Vertex, self).
__init__(tree, index,
"vtx")
1067 """Returns the number of tracks used in the vertex fit.""" 1069 return self._tree.vtx_trkIdx[self.
_index].
size()
1072 """Returns a generator for the tracks used in the vertex fit. 1074 The generator returns Track object. 1077 for itrk
in self._tree.vtx_trkIdx[self.
_index]:
1081 """Class presenting a collection of vertices.""" 1086 tree -- TTree object 1088 super(Vertices, self).
__init__(tree,
"vtx_valid", Vertex)
1092 """Class representing a TrackingVertex.""" 1097 tree -- TTree object 1098 index -- Index of the TrackingVertex 1100 super(TrackingVertex, self).
__init__(tree, index,
"simvtx")
1103 """Returns the number of source TrackingParticles.""" 1105 return self._tree.simvtx_sourceSimIdx[self.
_index].
size()
1108 """Returns the number of daughter TrackingParticles.""" 1110 return self._tree.simvtx_daughterSimIdx[self.
_index].
size()
1113 """Returns a generator for the source TrackingParticles.""" 1115 for isim
in self._tree.simvtx_sourceSimIdx[self.
_index]:
1119 """Returns a generator for the daughter TrackingParticles.""" 1121 for isim
in self._tree.simvtx_daughterSimIdx[self.
_index]:
1125 """Class presenting a collection of TrackingVertices.""" 1130 tree -- TTree object 1132 super(TrackingVertex, self).
__init__(tree,
"simvtx_x")
def matchedTrackingParticleInfos(self)
def __getattr__(self, attr)
def __init__(self, tree, index)
def bestMatchingTrack(self)
def _nMatchedTrackingParticles(self)
def matchedTrackInfos(self)
def bestMatchingTrackingParticle(self)
def matchedSeedInfos(self)
def __init__(self, tree, index, tpindex, prefix)
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def nMatchedTrackingParticles(self)
def _nMatchedTracks(self)
T get(const Candidate &c)
def trackingParticle(self)