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