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