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. 328 idx = self.bestSimTrkIdx()
334 """Fraction of shared hits with reco hits as denominator for best-matching TrackingParticle.""" 335 return self.bestSimTrkShareFrac()
338 """Fraction of shared hits with TrackingParticle::numberOfTrackerHits() as denominator for best-matching TrackingParticle.""" 339 return self.bestSimTrkShareFracSimDenom()
342 """Fraction of shared hits with number of reco clusters associated to a TrackingParticle as denominator for best-matching TrackingParticle.""" 343 return self.bestSimTrkShareFracSimClusterDenom()
346 """Normalized chi2 calculated from track parameters+covariance matrix and TrackingParticle parameters for best-matching TrackingParticle.""" 347 return self.bestSimTrkNChi2()
350 """Returns best-matching TrackingParticle, even for fake tracks, or None if there is no best-matching TrackingParticle. 352 Best-matching is defined as the one with largest number of 353 hits matched to the hits of a track (>= 3) starting from the 354 beginning of the track. If there are many fulfilling the same 355 number of hits, "a first TP" is chosen (a bit arbitrary, but 358 idx = self.bestFromFirstHitSimTrkIdx()
364 """Fraction of shared hits with reco hits as denominator for best-matching TrackingParticle starting from the first hit of a track.""" 365 return self.bestFromFirstHitSimTrkShareFrac()
368 """Fraction of shared hits with TrackingParticle::numberOfTrackerHits() as denominator for best-matching TrackingParticle starting from the first hit of a track.""" 369 return self.bestFromFirstHitSimTrkShareFracSimDenom()
372 """Fraction of shared hits with number of reco clusters associated to a TrackingParticle as denominator for best-matching TrackingParticle starting from the first hit of a track.""" 373 return self.bestFromFirstHitSimTrkShareFracSimClusterDenom()
376 """Normalized chi2 calculated from track parameters+covariance matrix and TrackingParticle parameters for best-matching TrackingParticle starting from the first hit of a track.""" 377 return self.bestFromFirstHitSimTrkNChi2()
381 """Class abstracting the whole ntuple/TTree. 383 Main benefit is to provide nice interface for 384 - iterating over events 385 - querying whether hit/seed information exists 387 Note that to iteratate over the evets with zip(), you should use 388 itertools.izip() instead. 390 def __init__(self, fileName, tree="trackingNtuple/tree"):
394 fileName -- String for path to the ROOT file 395 tree -- Name of the TTree object inside the ROOT file (default: 'trackingNtuple/tree') 397 super(TrackingNtuple, self).
__init__()
398 self.
_file = ROOT.TFile.Open(fileName)
412 """Returns true if the ntuple has hit information.""" 413 return hasattr(self.
_tree,
"pix_isBarrel")
416 """Returns true if the ntuple has seed information.""" 417 return hasattr(self.
_tree,
"see_fitok")
420 """Returns generator for iterating over TTree entries (events) 422 Generator returns Event objects. 425 for jentry
in xrange(self.
_entries):
427 ientry = self._tree.LoadTree( jentry )
430 nb = self._tree.GetEntry( jentry )
436 """Returns Event for a given index""" 437 ientry = self._tree.LoadTree(index)
438 if ientry < 0:
return None 439 nb = self._tree.GetEntry(ientry)
446 """Class abstracting a single event. 448 Main benefit is to provide nice interface to get various objects 449 or collections of objects. 456 entry -- Entry number in the tree 466 """Returns event number.""" 467 return self._tree.event
470 """Returns lumisection number.""" 471 return self._tree.lumi
474 """Returns run number.""" 475 return self._tree.run
478 """Returns (run, lumi, event) tuple.""" 479 return (self._tree.run, self._tree.lumi, self._tree.event)
482 """Returns 'run:lumi:event' string.""" 483 return "%d:%d:%d" % self.
eventId()
486 """Returns BeamSpot object.""" 490 """Returns Tracks object.""" 494 """Returns PixelHits object.""" 498 """Returns StripHits object.""" 502 """Returns GluedHits object.""" 506 """Returns Phase2OTHits object.""" 510 """Returns Seeds object.""" 514 """Returns TrackingParticles object.""" 518 """Returns Vertices object.""" 522 """Returns TrackingVertices object.""" 527 """Class representing the beam spot.""" 539 """Return object member variable. 541 'attr' is translated as a branch in the TTree (bsp_<attr>). 548 """Class representing a match to a SimHit. 550 The point of this class is to provide, in addition to the matched 551 SimHit, also other information about the match (e.g. fraction of 552 charge from this SimHit). 559 index -- Index of the hit matched to SimHit 560 shindex -- Index of the SimHit match (second index in _simHitIdx branch) 561 prefix -- String for prefix of the object (track/seed/hit) matched to TrackingParticle 563 super(SimHitMatchInfo, self).
__init__(tree, index, prefix)
567 """Custom __getattr__ because of the second index needed to access the branch.""" 572 """Returns matched SimHit.""" 578 """Class representing a match to a TrackingParticle. 580 The point of this class is to provide, in addition to the matched 581 TrackingParticle, also other information about the match (e.g. 582 shared hit fraction for tracks/seeds). 589 index -- Index of the object (track/seed) matched to TrackingParticle 590 tpindex -- Index of the TrackingParticle match (second index in _simTrkIdx branch) 591 prefix -- String for prefix of the object (track/seed) matched to TrackingParticle 593 super(TrackingParticleMatchInfo, self).
__init__(tree, index, prefix)
597 """Custom __getattr__ because of the second index needed to access the branch. 599 Note that when mapping the 'attr' to a branch, a 'simTrk' is 600 prepended and the first letter of 'attr' is turned to upper 607 """Returns matched TrackingParticle.""" 611 """Class representing a match to a Track. 613 The point of this class is to provide, in addition to the matched 614 Track, also other information about the match (e.g. shared hit fraction. 621 index -- Index of the object (TrackingParticle) matched to track 622 trkindex -- Index of the track match (second index in _trkIdx branch) 623 prefix -- String for prefix of the object (TrackingParticle) matched to track 625 super(TrackMatchInfo, self).
__init__(tree, index, prefix)
629 """Custom __getattr__ because of the second index needed to access the branch. 631 Note that when mapping the 'attr' to a branch, a 'trk' is 632 prepended and the first letter of 'attr' is turned to upper 639 """Returns matched Track.""" 643 """Class representing a match to a Seed. 645 The point of this class is to provide an interface compatible with 646 all other "MatchInfo" classes 649 def __init__(self, tree, index, seedindex, prefix):
654 index -- Index of the object (TrackingParticle) matched to seed 655 seedindex -- Index of the seed match (second index in _trkIdx branch) 656 prefix -- String for prefix of the object (TrackingParticle) matched to seed 658 super(SeedMatchInfo, self).
__init__(tree, index, prefix)
662 """Returns matched Seed.""" 668 """Class presenting a track.""" 674 index -- Index of the track 676 super(Track, self).
__init__(tree, index,
"trk")
679 """Returns Seed of the track.""" 684 """Returns Vertex that used this track in its fit.""" 692 return (self.pt() - tp.pca_pt())/self.ptErr()
698 return (getattr(self,
"lambda")() - tp.pca_lambda())/self.lambdaErr()
704 return (self.phi() - tp.pca_phi())/self.phiErr()
710 return (self.dxy() - tp.pca_dxy())/self.dxyErr()
716 return (self.dz() - tp.pca_dz())/self.dzErr()
719 """Class presenting a collection of tracks.""" 726 super(Tracks, self).
__init__(tree,
"trk_pt", Track)
730 """Class representing a pixel hit.""" 736 index -- Index of the hit 738 super(PixelHit, self).
__init__(tree, index,
"pix")
744 """Class presenting a collection of pixel hits.""" 751 super(PixelHits, self).
__init__(tree,
"pix_isBarrel", PixelHit)
755 """Class representing a strip hit.""" 761 index -- Index of the hit 763 super(StripHit, self).
__init__(tree, index,
"str")
769 """Class presenting a collection of strip hits.""" 776 super(StripHits, self).
__init__(tree,
"str_isBarrel", StripHit)
780 """Class representing a matched strip hit.""" 786 index -- Index of the hit 788 super(GluedHit, self).
__init__(tree, index,
"glu")
794 """Returns a StripHit for the mono hit.""" 799 """Returns a StripHit for the stereo hit.""" 804 """Returns the number of seeds containing this hit.""" 806 return self._tree.glu_seeIdx[self.
_index].
size()
809 """Returns generator for seeds containing this hit. 811 The generator returns Seed objects 814 for iseed
in self._tree.glu_seeIdx[self.
_index]:
818 """Class presenting a collection of matched strip hits.""" 825 super(GluedHits, self).
__init__(tree,
"glu_isBarrel", GluedHit)
838 """Class representing an invalid hit.""" 844 index -- Index of the hit 846 super(InvalidHit, self).
__init__(tree, index,
"inv")
852 """Returns a string describing the layer of the hit.""" 853 invalid_type = self._tree.inv_type[self.
_index]
854 return super(InvalidHit, self).
layerStr() +
" (%s)"%InvalidHit.Type.toString(invalid_type)
858 """Class representing a phase2 OT hit.""" 864 index -- Index of the hit 866 super(Phase2OTHit, self).
__init__(tree, index,
"ph2")
872 """Class presenting a collection of phase2 OT hits.""" 879 super(Phase2OTHits, self).
__init__(tree,
"ph2_isBarrel", Phase2OTHit)
883 """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.""" 884 for ioffset, offset
in enumerate(tree.see_offset):
885 if tree.see_algo[offset] == algo:
886 next_offset = tree.see_offset[ioffset+1]
if ioffset < tree.see_offset.size()-1
else tree.see_algo.size()
887 return (offset, next_offset)
891 """Class presenting a seed.""" 897 index -- Index of the seed 899 super(Seed, self).
__init__(tree, index,
"see")
902 """Returns the seed index within the seeds of the same algo. 904 In case of errors, -1 is returned. 907 algo = self._tree.see_algo[self.
_index]
911 return self.
_index - offset
914 """Returns Track that was made from this seed.""" 919 """Class presenting a collection of seeds.""" 926 super(Seeds, self).
__init__(tree,
"see_pt", Seed)
929 """Returns the number of seeds for a given 'algo'.""" 931 return next_offset - offset
934 """Returns generator iterating over the seeds of a given 'algo'. 936 Generator returns Seed object. 939 for isee
in xrange(offset, next_offset):
943 """Returns Seed of index 'iseed' for 'algo'.""" 945 if iseed >= (next_offset-offset):
946 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)))
951 """Class representing a SimHit which has not induced a RecHit.""" 957 index -- Index of the SimHit 959 super(SimHit, self).
__init__(tree, index,
"simhit")
963 return self._tree.simhit_hitIdx[self.
_index].
size()
971 """Class representing a TrackingParticle.""" 977 index -- Index of the TrackingParticle 979 super(TrackingParticle, self).
__init__(tree, index,
"sim")
982 """Internal function to get the number of matched tracks.""" 983 return self._tree.sim_trkIdx[self.
_index].
size()
986 """Returns the number of matched tracks.""" 991 """Returns a generator for matched tracks. 993 The generator returns TrackMatchInfo objects. 1000 """Returns best-matching track, even for non-reconstructed TrackingParticles, or None, if there is no best-matching track. 1002 Best-matching is defined as the one with largest number of 1003 hits matched to the hits of a TrackingParticle (>= 3). If 1004 there are many fulfilling the same number of hits, the one 1005 inducing the innermost hit of the TrackingParticle is chosen. 1011 tracks = collections.OrderedDict()
1013 for recHit
in hit.hits():
1014 for track
in recHit.tracks():
1015 if track.index()
in tracks:
1016 tracks[track.index()] += 1
1018 tracks[track.index()] = 1
1021 for trackIndex, nhits
in tracks.iteritems():
1023 best = (trackIndex, nhits)
1029 """Internal function to get the number of matched seeds.""" 1030 return self._tree.sim_seedIdx[self.
_index].
size()
1033 """Returns the number of matched seeds.""" 1038 """Returns a generator for matched tracks. 1040 The generator returns SeedMatchInfo objects. 1048 return self.simHitIdx().
size()
1051 """Returns generator for SimHits.""" 1053 for ihit
in self.simHitIdx():
1057 """Returns the parent TrackingVertex.""" 1062 """Returns a generator for decay vertices. 1064 The generator returns TrackingVertex objects. 1067 for ivtx
in self._tree.sim_decayVtxIdx[self.
_index]:
1071 """Returns True if this TrackingParticle is a looper. 1073 Note that the check involves looping over the SimHits, so it is not too cheap.""" 1076 for ihit
in self.simHitIdx():
1086 """Class presenting a collection of TrackingParticles.""" 1091 tree -- TTree object 1093 super(TrackingParticles, self).
__init__(tree,
"sim_pt", TrackingParticle)
1097 """Class presenting a primary vertex.""" 1102 tree -- TTree object 1103 index -- Index of the vertex 1105 super(Vertex, self).
__init__(tree, index,
"vtx")
1108 """Returns the number of tracks used in the vertex fit.""" 1110 return self._tree.vtx_trkIdx[self.
_index].
size()
1113 """Returns a generator for the tracks used in the vertex fit. 1115 The generator returns Track object. 1118 for itrk
in self._tree.vtx_trkIdx[self.
_index]:
1122 """Class presenting a collection of vertices.""" 1127 tree -- TTree object 1129 super(Vertices, self).
__init__(tree,
"vtx_valid", Vertex)
1133 """Class representing a TrackingVertex.""" 1138 tree -- TTree object 1139 index -- Index of the TrackingVertex 1141 super(TrackingVertex, self).
__init__(tree, index,
"simvtx")
1144 """Returns the number of source TrackingParticles.""" 1146 return self._tree.simvtx_sourceSimIdx[self.
_index].
size()
1149 """Returns the number of daughter TrackingParticles.""" 1151 return self._tree.simvtx_daughterSimIdx[self.
_index].
size()
1154 """Returns a generator for the source TrackingParticles.""" 1156 for isim
in self._tree.simvtx_sourceSimIdx[self.
_index]:
1160 """Returns a generator for the daughter TrackingParticles.""" 1162 for isim
in self._tree.simvtx_daughterSimIdx[self.
_index]:
1166 """Class presenting a collection of TrackingVertices.""" 1171 tree -- TTree object 1173 super(TrackingVertex, self).
__init__(tree,
"simvtx_x")
def bestMatchingTrackingParticleShareFracSimDenom(self)
def matchedTrackingParticleInfos(self)
def __getattr__(self, attr)
def __init__(self, tree, index)
def bestMatchingTrackingParticleFromFirstHitShareFracSimClusterDenom(self)
def bestMatchingTrack(self)
def _nMatchedTrackingParticles(self)
def bestMatchingTrackingParticleShareFracSimClusterDenom(self)
def matchedTrackInfos(self)
def bestMatchingTrackingParticleFromFirstHitNormalizedChi2(self)
def bestMatchingTrackingParticle(self)
def bestMatchingTrackingParticleShareFrac(self)
def matchedSeedInfos(self)
def bestMatchingTrackingParticleNormalizedChi2(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 bestMatchingTrackingParticleFromFirstHitShareFracSimDenom(self)
def _nMatchedTracks(self)
def bestMatchingTrackingParticleFromFirstHitShareFrac(self)
def bestMatchingTrackingParticleFromFirstHit(self)
T get(const Candidate &c)
def trackingParticle(self)