Belle II Software  release-06-02-00
SVDValidationTTreeSpacePoint.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 """
13 <header>
14  <contact>G. Casarosa giulia.casarosa@desy.de</contact>
15  <description>
16  This module is used for the SVD validation.
17  It gets information about SpacePoints, saving
18  in a ttree in a ROOT file.
19  </description>
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 digit with a cluster and save needed information"""
68 
69  # Start with SpacePoints and use the relation to get the corresponding
70  # digits
71  spacepoints = Belle2.PyStoreArray('SVDSpacePoints')
72 
73  for sp in spacepoints:
74 
75  # Sensor identification
76  sensorID = sp.getVxdID()
77  self.datadata.sensor_id = int(sensorID)
78  sensorNum = sensorID.getSensorNumber()
79  self.datadata.sensor = sensorNum
80  layerNum = sensorID.getLayerNumber()
81 
82  # look at SP on SVD only
83  sp_type = sp.getType()
84  if sp_type != 1:
85  continue
86 
87  self.datadata.layer = layerNum
88  if (layerNum == 3):
89  sensorType = 1
90  else:
91  if (sensorNum == 1):
92  sensorType = 0
93  else:
94  sensorType = 1
95  self.datadata.sensor_type = sensorType
96  ladderNum = sensorID.getLadderNumber()
97  self.datadata.ladder = ladderNum
98 
99  # space point information
100  timeU = sp.TimeU()
101  timeV = sp.TimeV()
102  self.datadata.time_u = timeU
103  self.datadata.time_v = timeV
104 
105  # Fill tree
106  self.filefile.cd()
107  self.treetree.Fill()
108 
109  def terminate(self):
110  """Close the output file. """
111  self.filefile.cd()
112  self.filefile.Write()
113  self.filefile.Close()
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:56