Belle II Software  release-05-01-25
SVDValidationTTreeRecoDigit.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 """
5 <header>
6  <contact> SVD Software Group, svd-software@belle2.org </contact>
7  <description>
8  This module is used for the SVD validation.
9  It gets information about ShaperDigits and RecoDigits, 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
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 EventDataRecoDigit {\
28  int sensor_id;\
29  int layer;\
30  int ladder;\
31  int sensor;\
32  int sensor_type;\
33  int strip_dir;\
34  float recodigit_time;\
35  float truehit_time;\
36 };')
37 
38 from ROOT import EventDataRecoDigit
39 
40 
42  '''class to create reco digitis ttree'''
43 
44  def __init__(self):
45  """Initialize the module"""
46 
47  super(SVDValidationTTreeRecoDigit, self).__init__()
48  self.file = ROOT.TFile('../SVDValidationTTreeRecoDigit.root', 'recreate')
49  '''Output ROOT file'''
50  self.tree = ROOT.TTree('tree', 'Event data of SVD validation events')
51  '''TTrees for output data'''
52  self.data = EventDataRecoDigit()
53  '''Instance of the EventData class'''
54 
55  # Declare tree branches
56  for key in EventDataRecoDigit.__dict__:
57  if '__' not in key:
58  formstring = '/F'
59  if isinstance(self.data.__getattribute__(key), int):
60  formstring = '/I'
61  self.tree.Branch(key, AddressOf(self.data, key), key + formstring)
62 
63  def event(self):
64  """Take digits from SVDRecoDigits with a truehit and save needed information"""
65  digits = Belle2.PyStoreArray('SVDRecoDigits')
66  for digit in digits:
67  digit_truehits = digit.getRelationsTo('SVDTrueHits')
68  # We want only digits with exactly one associated TrueHit
69  if len(digit_truehits) != 1:
70  continue
71  for truehit in digit_truehits:
72  # Sensor identification
73  sensorID = digit.getSensorID()
74  self.data.sensor_id = int(sensorID)
75  sensorNum = sensorID.getSensorNumber()
76  self.data.sensor = sensorNum
77  layerNum = sensorID.getLayerNumber()
78  self.data.layer = layerNum
79  if (layerNum == 3):
80  sensorType = 1 # Barrel
81  else:
82  if (sensorNum == 1):
83  sensorType = 0
84  else:
85  sensorType = 1
86  self.data.sensor_type = sensorType
87  ladderNum = sensorID.getLadderNumber()
88  self.data.ladder = ladderNum
89  if digit.isUStrip():
90  self.data.strip_dir = 0
91  else:
92  self.data.strip_dir = 1
93  self.data.recodigit_time = digit.getTime()
94  self.data.truehit_time = truehit.getGlobalTime()
95  # Fill tree
96  self.file.cd()
97  self.tree.Fill()
98 
99  def terminate(self):
100  """Close the output file. """
101  self.file.cd()
102  self.file.Write()
103  self.file.Close()
SVDValidationTTreeRecoDigit.SVDValidationTTreeRecoDigit.data
data
Definition: SVDValidationTTreeRecoDigit.py:52
SVDValidationTTreeRecoDigit.SVDValidationTTreeRecoDigit
Definition: SVDValidationTTreeRecoDigit.py:41
SVDValidationTTreeRecoDigit.SVDValidationTTreeRecoDigit.terminate
def terminate(self)
Definition: SVDValidationTTreeRecoDigit.py:99
SVDValidationTTreeRecoDigit.SVDValidationTTreeRecoDigit.event
def event(self)
Definition: SVDValidationTTreeRecoDigit.py:63
SVDValidationTTreeRecoDigit.SVDValidationTTreeRecoDigit.file
file
Definition: SVDValidationTTreeRecoDigit.py:48
SVDValidationTTreeRecoDigit.SVDValidationTTreeRecoDigit.tree
tree
Definition: SVDValidationTTreeRecoDigit.py:50
SVDValidationTTreeRecoDigit.SVDValidationTTreeRecoDigit.__init__
def __init__(self)
Definition: SVDValidationTTreeRecoDigit.py:44
Belle2::PyStoreArray
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:58