25 *args, **kw):
26 """Helper for setting up a nearest-DR association to a contained object.
27
28 We get an source object and a collection of target objects.
29 We pick the target object that's closest in DR to the source object.
30 By default, the target collection is a DataVector from StoreGate.
31
32 parent: The parent D3PDobject or block.
33 type_name: The C++ type of the target object collection.
34 default_sgkey: Default StoreGate key for the target collection.
35 default_drcut: Default DR cut. If no target objects are within
36 this DR, the association will fail.
37 prefix: Prefix to add to the contained variables, if any.
38 matched: If not null, a flag variable with this name will
39 be created, set to true when the association succeeds.
40 level: Level of detail for the block.
41 blockname: Name for the block.
42
43 Extra arguments are passed to the association tool.
44
45 Here's an example. Suppose we have an electron object, and we
46 want to record the 4-vector of a matching jet.
47
48 Usage is something like this:
49
50 ElectronObject = ...
51
52 EleJetAssoc = DRAssociation (ElectronObject,
53 'JetCollection',
54 'Cone4H1TowerJets',
55 0.2,
56 'jet_',
57 level = 2,
58 blockname = 'JetMatch')
59 EleJetAssoc.defineBlock (2, 'JetKinematics',
60 D3PD.FourMomFillerTool)
61
62 The DRAssociation call makes the association. We'll look in SG
63 for a JetCollection called `Cone4H1TowerJets' and find the jet from
64 there that's closest in DR to the electron (but not farther away
65 than 0.2). If the electron prefix is `el_', then we'll automatically
66 create the variables `el_jet_matched' and `el_jet_dr'. The second
67 call then adds the jet kinematic variables: `el_jet_pt', etc.
68 Additional blocks can be added if desired.
69"""
70 if blockname is None:
71 blockname = prefix + 'DRAssoc'
72
73 def maker (name, prefix, object_name,
74 sgkey = default_sgkey,
75 getter = None,
76 assoc = None,
77 drcut = default_drcut):
78
79 if not getter:
81 (name + '_Getter',
82 TypeName = type_name,
83 SGKey = sgkey)
84 if not assoc:
86 Getter = getter,
87 DRCut = drcut)
88
90 Prefix = prefix,
91 Associator = assoc,
92 Matched = matched)
93
94 obj = D3PDObject (maker, prefix)
95 parent.defineBlock (level, blockname, obj)
96 return obj