Belle II Software development
photonFunctions.py
1# !/usr/bin/env python3
2
3
10
11"""
12Functions that work on photon lists.
13
14"""
15
16from basf2 import create_path
17import string
18import random
19import modularAnalysis as ma
20
21
22def getRandomId(size=6, chars=string.ascii_uppercase + string.digits):
23 return ''.join(random.choice(chars) for _ in range(size))
24
25
26def writeClosestParticleExtraClusterInfo(
27 particleList,
28 particleSelection='True',
29 roe_path=None,
30 deadend_path=None,
31 path=None
32):
33 """
34 Add various variables to the first particle that are related to their angular separation and kinematics.
35
36 @param particleList Particle list with particle candidates that will have the extra information in the end
37 @param particleSelection Selection for the other particle
38 @param roe_path a path for the rest of event to be executed
39 @param deadend_path a path for skipping irrelevant RestOfEvent objects that may exist (if this was called twice, for instance)
40 @param path modules are added to this path
41 """
42
43 particleType = particleList.split(":")[0]
44
45 if not roe_path:
46 roe_path = create_path()
47
48 if not deadend_path:
49 deadend_path = create_path()
50
51 # build rest of event
52 ma.buildRestOfEvent(particleList, path=path)
53
54 # get random listnames (in case we run this function multiple times)
55 pListPair = 'vpho:writeClosestParticleExtraClusterInfo' + getRandomId()
56 pList0 = particleType + ':writeClosestParticleExtraClusterInfo' + getRandomId()
57 pList1 = particleType + ':writeClosestParticleExtraClusterInfo' + getRandomId()
58
59 ma.signalSideParticleFilter(particleList, '', roe_path, deadend_path)
60
61 ma.fillSignalSideParticleList(pList0, '^' + particleList, path=roe_path)
62
63 ma.fillParticleList(pList1, 'isInRestOfEvent == 1 and ' + particleSelection, path=roe_path)
64
65 ma.reconstructDecay(pListPair + ' -> ' + pList0 + ' ' + pList1, '', path=roe_path)
66
67 # only keep the one with the smallest opening angle
68 ma.rankByLowest(pListPair, 'daughterClusterAngleInBetween(0, 1)', 1, path=roe_path)
69
70 # add new variables to the signal side particle
71 # NOTE: if somebody needs these variables in the CMS frame, they need to
72 # modify this function since it's not possible outside the roe_path
73 ma.variableToSignalSideExtraInfo(pListPair, {'useLabFrame(daughterClusterAngleInBetween(0, 1))': 'openingAngle'}, path=roe_path)
74 ma.variableToSignalSideExtraInfo(pListPair, {'useLabFrame(daughterDiffOf(0, 1, clusterTheta))': 'deltaTheta'}, path=roe_path)
75 ma.variableToSignalSideExtraInfo(pListPair, {'useLabFrame(daughterDiffOfClusterPhi(0, 1))': 'deltaPhi'}, path=roe_path)
76
77 path.for_each('RestOfEvent', 'RestOfEvents', roe_path)