11 """Adaptor class representing a collection of objects. 13 Concrete collection classes should inherit from this class. 16 def __init__(self, tree, sizeBranch, objclass):
21 sizeBranch -- Name of the branch to be used in size() 22 objclass -- Class to be used for the objects in __getitem__() 30 """Number of objects in the collection.""" 34 """Number of objects in the collection.""" 38 """Get object 'index' in the collection.""" 42 """Returns generator for the objects.""" 43 for index
in xrange(self.
size()):
47 """Adaptor class representing a single object in a collection. 49 The member variables of the object are obtained from the branches 50 with common prefix and a given index. 52 Concrete object classes should inherit from this class. 59 index -- Index for this object 60 prefix -- Prefix of the branchs 68 """Return object member variable. 70 'attr' is translated as a branch in the TTree (<prefix>_<attr>). 77 """Raise an exception if the object index is not valid.""" 79 raise Exception(
"%s is not valid" % self.__class__.__name__)
82 """Check if object index is valid.""" 86 """Return object index.""" 90 """Adaptor class for objects containgin DetId (hits).""" 92 super(_DetIdStrAdaptor, self).
__init__()
95 """Returns a string describing the layer of the hit.""" 97 get =
lambda name: getattr(self._tree, self._prefix+
"_"+name)[self._index]
98 subdet =
get(
"subdet")
100 isPhase2OTBarrel = (subdet == SubDet.TOB
and hasattr(self._tree, self._prefix+
"_isLower"))
101 if subdet
in [SubDet.FPix, SubDet.TID, SubDet.TEC]
or isPhase2OTBarrel:
102 sideNum =
get(
"side")
107 elif isPhase2OTBarrel
and sideNum == 3:
111 return "%s%d%s" % (SubDet.toString(subdet),
112 getattr(self._tree, self._prefix+
"_layer")[self._index],
116 """Returns a string describing the DetId fields.""" 118 get =
lambda name: getattr(self._tree, self._prefix+
"_"+name)[self._index]
119 isPhase2 = hasattr(self._tree, self._prefix+
"_isLower")
137 subdet =
get(
"subdet")
138 if subdet == SubDet.BPix:
139 return "ladder {} module {}".
format(
get(
"ladder"),
get(
"module"))
140 if subdet == SubDet.FPix:
141 return "blade {} panel {} module {}".
format(
get(
"blade"),
get(
"panel"),
get(
"module"))
142 if subdet == SubDet.TIB:
143 return "side {} order {} string {} module {}{}".
format(
get(
"side"),
get(
"order"),
get(
"string"),
get(
"module"), stereo())
144 if subdet == SubDet.TID:
145 return "ring {} order {} module {}{}".
format(
get(
"ring"),
get(
"order"),
get(
"module"), stereo())
146 if subdet == SubDet.TOB:
148 return "rod {} module {}{}".
format(
get(
"rod"),
get(
"module"), stereo())
150 return "side {} rod {} module {}{}".
format(
get(
"side"),
get(
"rod"),
get(
"module"), stereo())
151 if subdet == SubDet.TEC:
152 return "order {} petal {} ring {} module {}{}".
format(
get(
"order"),
get(
"petalNumber"),
get(
"ring"),
get(
"module"), stereo())
153 raise Exception(
"Unknown subdet %d" % subdet)
156 """Adaptor class for pixel/strip hit objects.""" 162 index -- Index for this object 163 prefix -- Prefix of the branchs 167 super(_HitObject, self).
__init__(tree, index, prefix)
170 """Returns number of tracks containing this hit.""" 175 """Returns generator for tracks containing this hit. 177 The generator returns Track objects 184 """Returns number of seeds containing this hit.""" 189 """Returns generator for tracks containing this hit. 191 The generator returns Seed objects 198 return math.sqrt(self.x()**2 + self.y()**2)
201 return math.sqrt(self.x()**2 + self.y()**2 + self.z()**2)
204 """Adaptor class for objects containing hits (e.g. tracks)""" 206 super(_RecoHitAdaptor, self).
__init__()
209 """Internal method to generate pairs of hit index and type.""" 210 for ihit, hitType
in zip(self.hitIdx(), self.hitType()):
211 yield (ihit, hitType)
214 """Returns generator for hits. 216 Generator returns PixelHit/StripHit/GluedHit/Phase2OT depending on the 220 for ihit, hitType
in self.
_hits():
232 raise Exception(
"Unknown hit type %d" % hitType)
235 """Returns generator for pixel hits.""" 237 for ihit, hitType
in self.
_hits():
243 """Returns generator for strip hits.""" 245 for ihit, hitType
in self.
_hits():
251 """Returns generator for matched strip hits.""" 253 for ihit, hitType
in self.
_hits():
259 """Returns generator for invalid hits.""" 261 for ihit, hitType
in self.
_hits():
267 """Returns generator for phase2 outer tracker hits.""" 269 for ihit, hitType
in self.
_hits():
275 """Adaptor class for objects containing or matched to SimHits (e.g. reco hits).""" 277 super(_SimHitMatchAdaptor, self).
__init__()
280 """Internal method to get the number of matched SimHits.""" 281 return getattr(self._tree, self._prefix+
"_simHitIdx")[self._index].
size()
284 """Returns the number of matched SimHits.""" 289 """Returns a generator for matched SimHits. 291 The generator returns SimHitMatchInfo objects. 298 """Adaptor class for objects matched to TrackingParticles.""" 300 super(_TrackingParticleMatchAdaptor, self).
__init__()
303 """Internal method to get the number of matched TrackingParticles.""" 304 return getattr(self._tree, self._prefix+
"_simTrkIdx")[self._index].
size()
307 """Returns the number of matched TrackingParticles.""" 312 """Returns a generator for matched TrackingParticles. 314 The generator returns TrackingParticleMatchInfo objects. 322 """Returns best-matching TrackingParticle, even for fake tracks, or None if there is no best-matching TrackingParticle. 324 Best-matching is defined as the one with largest number of 325 hits matched to the hits of a track (>= 3). If there are many 326 fulfilling the same number of hits, the one inducing the 327 innermost hit of the track is chosen. 329 idx = self.bestSimTrkIdx()
335 """Fraction of shared hits with reco hits as denominator for best-matching TrackingParticle.""" 336 return self.bestSimTrkShareFrac()
339 """Fraction of shared hits with TrackingParticle::numberOfTrackerHits() as denominator for best-matching TrackingParticle.""" 340 return self.bestSimTrkShareFracSimDenom()
343 """Fraction of shared hits with number of reco clusters associated to a TrackingParticle as denominator for best-matching TrackingParticle.""" 344 return self.bestSimTrkShareFracSimClusterDenom()
347 """Normalized chi2 calculated from track parameters+covariance matrix and TrackingParticle parameters for best-matching TrackingParticle.""" 348 return self.bestSimTrkNChi2()
351 """Returns best-matching TrackingParticle, even for fake tracks, or None if there is no best-matching TrackingParticle. 353 Best-matching is defined as the one with largest number of 354 hits matched to the hits of a track (>= 3) starting from the 355 beginning of the track. If there are many fulfilling the same 356 number of hits, "a first TP" is chosen (a bit arbitrary, but 359 idx = self.bestFromFirstHitSimTrkIdx()
365 """Fraction of shared hits with reco hits as denominator for best-matching TrackingParticle starting from the first hit of a track.""" 366 return self.bestFromFirstHitSimTrkShareFrac()
369 """Fraction of shared hits with TrackingParticle::numberOfTrackerHits() as denominator for best-matching TrackingParticle starting from the first hit of a track.""" 370 return self.bestFromFirstHitSimTrkShareFracSimDenom()
373 """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.""" 374 return self.bestFromFirstHitSimTrkShareFracSimClusterDenom()
377 """Normalized chi2 calculated from track parameters+covariance matrix and TrackingParticle parameters for best-matching TrackingParticle starting from the first hit of a track.""" 378 return self.bestFromFirstHitSimTrkNChi2()
382 """Class abstracting the whole ntuple/TTree. 384 Main benefit is to provide nice interface for 385 - iterating over events 386 - querying whether hit/seed information exists 388 Note that to iteratate over the evets with zip(), you should use 389 itertools.izip() instead. 391 def __init__(self, fileName, tree="trackingNtuple/tree"):
395 fileName -- String for path to the ROOT file 396 tree -- Name of the TTree object inside the ROOT file (default: 'trackingNtuple/tree') 398 super(TrackingNtuple, self).
__init__()
399 self.
_file = ROOT.TFile.Open(fileName)
413 """Returns true if the ntuple has hit information.""" 414 return hasattr(self.
_tree,
"pix_isBarrel")
417 """Returns true if the ntuple has seed information.""" 418 return hasattr(self.
_tree,
"see_fitok")
421 """Returns generator for iterating over TTree entries (events) 423 Generator returns Event objects. 426 for jentry
in xrange(self.
_entries):
428 ientry = self._tree.LoadTree( jentry )
431 nb = self._tree.GetEntry( jentry )
437 """Returns Event for a given index""" 438 ientry = self._tree.LoadTree(index)
439 if ientry < 0:
return None 440 nb = self._tree.GetEntry(ientry)
447 """Class abstracting a single event. 449 Main benefit is to provide nice interface to get various objects 450 or collections of objects. 457 entry -- Entry number in the tree 467 """Returns event number.""" 468 return self._tree.event
471 """Returns lumisection number.""" 472 return self._tree.lumi
475 """Returns run number.""" 476 return self._tree.run
479 """Returns (run, lumi, event) tuple.""" 480 return (self._tree.run, self._tree.lumi, self._tree.event)
483 """Returns 'run:lumi:event' string.""" 484 return "%d:%d:%d" % self.
eventId()
487 """Returns BeamSpot object.""" 491 """Returns Tracks object.""" 495 """Returns PixelHits object.""" 499 """Returns StripHits object.""" 503 """Returns GluedHits object.""" 507 """Returns Phase2OTHits object.""" 511 """Returns Seeds object.""" 515 """Returns TrackingParticles object.""" 519 """Returns Vertices object.""" 523 """Returns TrackingVertices object.""" 528 """Class representing the beam spot.""" 540 """Return object member variable. 542 'attr' is translated as a branch in the TTree (bsp_<attr>). 549 """Class representing a match to a SimHit. 551 The point of this class is to provide, in addition to the matched 552 SimHit, also other information about the match (e.g. fraction of 553 charge from this SimHit). 560 index -- Index of the hit matched to SimHit 561 shindex -- Index of the SimHit match (second index in _simHitIdx branch) 562 prefix -- String for prefix of the object (track/seed/hit) matched to TrackingParticle 564 super(SimHitMatchInfo, self).
__init__(tree, index, prefix)
568 """Custom __getattr__ because of the second index needed to access the branch.""" 573 """Returns matched SimHit.""" 579 """Class representing a match to a TrackingParticle. 581 The point of this class is to provide, in addition to the matched 582 TrackingParticle, also other information about the match (e.g. 583 shared hit fraction for tracks/seeds). 590 index -- Index of the object (track/seed) matched to TrackingParticle 591 tpindex -- Index of the TrackingParticle match (second index in _simTrkIdx branch) 592 prefix -- String for prefix of the object (track/seed) matched to TrackingParticle 594 super(TrackingParticleMatchInfo, self).
__init__(tree, index, prefix)
598 """Custom __getattr__ because of the second index needed to access the branch. 600 Note that when mapping the 'attr' to a branch, a 'simTrk' is 601 prepended and the first letter of 'attr' is turned to upper 608 """Returns matched TrackingParticle.""" 612 """Class representing a match to a Track. 614 The point of this class is to provide, in addition to the matched 615 Track, also other information about the match (e.g. shared hit fraction. 622 index -- Index of the object (TrackingParticle) matched to track 623 trkindex -- Index of the track match (second index in _trkIdx branch) 624 prefix -- String for prefix of the object (TrackingParticle) matched to track 626 super(TrackMatchInfo, self).
__init__(tree, index, prefix)
630 """Custom __getattr__ because of the second index needed to access the branch. 632 Note that when mapping the 'attr' to a branch, a 'trk' is 633 prepended and the first letter of 'attr' is turned to upper 640 """Returns matched Track.""" 644 """Class representing a match to a Seed. 646 The point of this class is to provide an interface compatible with 647 all other "MatchInfo" classes 650 def __init__(self, tree, index, seedindex, prefix):
655 index -- Index of the object (TrackingParticle) matched to seed 656 seedindex -- Index of the seed match (second index in _trkIdx branch) 657 prefix -- String for prefix of the object (TrackingParticle) matched to seed 659 super(SeedMatchInfo, self).
__init__(tree, index, prefix)
663 """Returns matched Seed.""" 669 """Class presenting a track.""" 675 index -- Index of the track 677 super(Track, self).
__init__(tree, index,
"trk")
680 """Returns Seed of the track.""" 685 """Returns Vertex that used this track in its fit.""" 693 return (self.pt() - tp.pca_pt())/self.ptErr()
699 return (getattr(self,
"lambda")() - tp.pca_lambda())/self.lambdaErr()
705 return (self.phi() - tp.pca_phi())/self.phiErr()
711 return (self.dxy() - tp.pca_dxy())/self.dxyErr()
717 return (self.dz() - tp.pca_dz())/self.dzErr()
720 """Class presenting a collection of tracks.""" 727 super(Tracks, self).
__init__(tree,
"trk_pt", Track)
731 """Class representing a pixel hit.""" 737 index -- Index of the hit 739 super(PixelHit, self).
__init__(tree, index,
"pix")
745 """Class presenting a collection of pixel hits.""" 752 super(PixelHits, self).
__init__(tree,
"pix_isBarrel", PixelHit)
756 """Class representing a strip hit.""" 762 index -- Index of the hit 764 super(StripHit, self).
__init__(tree, index,
"str")
770 """Class presenting a collection of strip hits.""" 777 super(StripHits, self).
__init__(tree,
"str_isBarrel", StripHit)
781 """Class representing a matched strip hit.""" 787 index -- Index of the hit 789 super(GluedHit, self).
__init__(tree, index,
"glu")
795 """Returns a StripHit for the mono hit.""" 800 """Returns a StripHit for the stereo hit.""" 805 """Returns the number of seeds containing this hit.""" 807 return self._tree.glu_seeIdx[self.
_index].
size()
810 """Returns generator for seeds containing this hit. 812 The generator returns Seed objects 815 for iseed
in self._tree.glu_seeIdx[self.
_index]:
819 """Class presenting a collection of matched strip hits.""" 826 super(GluedHits, self).
__init__(tree,
"glu_isBarrel", GluedHit)
839 """Class representing an invalid hit.""" 845 index -- Index of the hit 847 super(InvalidHit, self).
__init__(tree, index,
"inv")
853 """Returns a string describing the layer of the hit.""" 854 invalid_type = self._tree.inv_type[self.
_index]
855 return super(InvalidHit, self).
layerStr() +
" (%s)"%InvalidHit.Type.toString(invalid_type)
859 """Class representing a phase2 OT hit.""" 865 index -- Index of the hit 867 super(Phase2OTHit, self).
__init__(tree, index,
"ph2")
873 """Class presenting a collection of phase2 OT hits.""" 880 super(Phase2OTHits, self).
__init__(tree,
"ph2_isBarrel", Phase2OTHit)
884 """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.""" 885 for ioffset, offset
in enumerate(tree.see_offset):
886 if tree.see_algo[offset] == algo:
887 next_offset = tree.see_offset[ioffset+1]
if ioffset < tree.see_offset.size()-1
else tree.see_algo.size()
888 return (offset, next_offset)
892 """Class presenting a seed.""" 898 index -- Index of the seed 900 super(Seed, self).
__init__(tree, index,
"see")
903 """Returns the seed index within the seeds of the same algo. 905 In case of errors, -1 is returned. 908 algo = self._tree.see_algo[self.
_index]
912 return self.
_index - offset
915 """Returns Track that was made from this seed.""" 920 """Class presenting a collection of seeds.""" 927 super(Seeds, self).
__init__(tree,
"see_pt", Seed)
930 """Returns the number of seeds for a given 'algo'.""" 932 return next_offset - offset
935 """Returns generator iterating over the seeds of a given 'algo'. 937 Generator returns Seed object. 940 for isee
in xrange(offset, next_offset):
944 """Returns Seed of index 'iseed' for 'algo'.""" 946 if iseed >= (next_offset-offset):
947 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)))
952 """Class representing a SimHit which has not induced a RecHit.""" 958 index -- Index of the SimHit 960 super(SimHit, self).
__init__(tree, index,
"simhit")
964 return self._tree.simhit_hitIdx[self.
_index].
size()
972 """Class representing a TrackingParticle.""" 978 index -- Index of the TrackingParticle 980 super(TrackingParticle, self).
__init__(tree, index,
"sim")
983 """Internal function to get the number of matched tracks.""" 984 return self._tree.sim_trkIdx[self.
_index].
size()
987 """Returns the number of matched tracks.""" 992 """Returns a generator for matched tracks. 994 The generator returns TrackMatchInfo objects. 1001 """Returns best-matching track, even for non-reconstructed TrackingParticles, or None, if there is no best-matching track. 1003 Best-matching is defined as the one with largest number of 1004 hits matched to the hits of a TrackingParticle (>= 3). If 1005 there are many fulfilling the same number of hits, the one 1006 inducing the innermost hit of the TrackingParticle is chosen. 1012 tracks = collections.OrderedDict()
1014 for recHit
in hit.hits():
1015 for track
in recHit.tracks():
1016 if track.index()
in tracks:
1017 tracks[track.index()] += 1
1019 tracks[track.index()] = 1
1022 for trackIndex, nhits
in six.iteritems(tracks):
1024 best = (trackIndex, nhits)
1030 """Internal function to get the number of matched seeds.""" 1031 return self._tree.sim_seedIdx[self.
_index].
size()
1034 """Returns the number of matched seeds.""" 1039 """Returns a generator for matched tracks. 1041 The generator returns SeedMatchInfo objects. 1049 return self.simHitIdx().
size()
1052 """Returns generator for SimHits.""" 1054 for ihit
in self.simHitIdx():
1058 """Returns the parent TrackingVertex.""" 1063 """Returns a generator for decay vertices. 1065 The generator returns TrackingVertex objects. 1068 for ivtx
in self._tree.sim_decayVtxIdx[self.
_index]:
1072 """Returns True if this TrackingParticle is a looper. 1074 Note that the check involves looping over the SimHits, so it is not too cheap.""" 1077 for ihit
in self.simHitIdx():
1087 """Class presenting a collection of TrackingParticles.""" 1092 tree -- TTree object 1094 super(TrackingParticles, self).
__init__(tree,
"sim_pt", TrackingParticle)
1098 """Class presenting a primary vertex.""" 1103 tree -- TTree object 1104 index -- Index of the vertex 1106 super(Vertex, self).
__init__(tree, index,
"vtx")
1109 """Returns the number of tracks used in the vertex fit.""" 1111 return self._tree.vtx_trkIdx[self.
_index].
size()
1114 """Returns a generator for the tracks used in the vertex fit. 1116 The generator returns Track object. 1119 for itrk
in self._tree.vtx_trkIdx[self.
_index]:
1123 """Class presenting a collection of vertices.""" 1128 tree -- TTree object 1130 super(Vertices, self).
__init__(tree,
"vtx_valid", Vertex)
1134 """Class representing a TrackingVertex.""" 1139 tree -- TTree object 1140 index -- Index of the TrackingVertex 1142 super(TrackingVertex, self).
__init__(tree, index,
"simvtx")
1145 """Returns the number of source TrackingParticles.""" 1147 return self._tree.simvtx_sourceSimIdx[self.
_index].
size()
1150 """Returns the number of daughter TrackingParticles.""" 1152 return self._tree.simvtx_daughterSimIdx[self.
_index].
size()
1155 """Returns a generator for the source TrackingParticles.""" 1157 for isim
in self._tree.simvtx_sourceSimIdx[self.
_index]:
1161 """Returns a generator for the daughter TrackingParticles.""" 1163 for isim
in self._tree.simvtx_daughterSimIdx[self.
_index]:
1167 """Class presenting a collection of TrackingVertices.""" 1172 tree -- TTree object 1174 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)