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