Belle II Software development
SVDValidationTTreeSpacePoint.py
1#!/usr/bin/env python3
2
3
10
11"""
12<header>
13 <description>
14 This module is used for the SVD validation.
15 It gets information about all SpacePoints, saving
16 in a ttree in a ROOT file.
17 </description>
18 <noexecute>SVD validation helper class</noexecute>
19</header>
20"""
21
22import basf2 as b2
23
24# Some ROOT tools
25import ROOT
26from ROOT import Belle2 # noqa: make Belle2 namespace available
27from ROOT import gROOT, addressof
28
29# Define a ROOT struct to hold output data in the TTree
30gROOT.ProcessLine('struct EventDataSpacePoint {\
31 int sensor_id;\
32 int layer;\
33 int ladder;\
34 int sensor;\
35 int sensor_type;\
36 float time_u;\
37 float time_v;\
38 };')
39
40from ROOT import EventDataSpacePoint # noqa
41
42
44 '''class to create spacepoint ttree'''
45
46 def __init__(self):
47 """Initialize the module"""
48
49 super().__init__()
50
51 self.file = ROOT.TFile('../SVDValidationTTreeSpacePoint.root', 'recreate')
52
53 self.tree = ROOT.TTree('tree', 'Event data of SVD validation events')
54
55 self.data = EventDataSpacePoint()
56
57 # Declare tree branches
58 for key in EventDataSpacePoint.__dict__:
59 if '__' not in key:
60 formstring = '/F'
61 if isinstance(self.data.__getattribute__(key), int):
62 formstring = '/I'
63 self.tree.Branch(key, addressof(self.data, key), key + formstring)
64
65 def event(self):
66 """Find SVD SpacePoints in the event"""
67
68 spacepoints = Belle2.PyStoreArray('SVDSpacePoints')
69
70 for sp in spacepoints:
71
72 # Sensor identification
73 sensorID = sp.getVxdID()
74 self.data.sensor_id = int(sensorID)
75 sensorNum = sensorID.getSensorNumber()
76 self.data.sensor = sensorNum
77 layerNum = sensorID.getLayerNumber()
78
79 # look at SP on SVD only
80 sp_type = sp.getType()
81 if sp_type != 1:
82 continue
83
84 self.data.layer = layerNum
85 if (layerNum == 3):
86 sensorType = 1
87 else:
88 if (sensorNum == 1):
89 sensorType = 0
90 else:
91 sensorType = 1
92 self.data.sensor_type = sensorType
93 self.data.ladder = sensorID.getLadderNumber()
94
95 # space point information
96 self.data.time_u = sp.TimeU()
97 self.data.time_v = sp.TimeV()
98
99 # Fill tree
100 self.file.cd()
101 self.tree.Fill()
102
103 def terminate(self):
104 """Close the output file. """
105 self.file.cd()
106 self.file.Write()
107 self.file.Close()
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72