Belle II Software  release-05-01-25
PXDValidationTTreeDigit.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import sys
5 import math
6 from basf2 import *
7 
8 # Some ROOT tools
9 import ROOT
10 from ROOT import Belle2
11 from ROOT import gROOT, AddressOf
12 
13 # Define a ROOT struct to hold output data in the TTree.
14 gROOT.ProcessLine('struct EventDataDigit {\
15  unsigned long exp;\
16  unsigned long run;\
17  unsigned long evt;\
18  int vxd_id;\
19  int layer;\
20  int ladder;\
21  int sensor;\
22  int cluster_index;\
23  int pixel_type;\
24  float digit_u;\
25  float digit_v;\
26  int digit_uID;\
27  int digit_vID;\
28  float digit_charge;\
29 };'
30  )
31 
32 from ROOT import EventDataDigit
33 
34 
36 
37  """
38  A simple module to check the simulation of PXDTrueHits with Geant4 steps.
39  This module writes its output to a ROOT tree.
40  Primary goal is supporting of validation plots
41  """
42 
43  def __init__(self):
44  """Initialize the module"""
45 
46  super(PXDValidationTTreeDigit, self).__init__()
47 
48  self.file = ROOT.TFile('PXDValidationTTreeDigitOutput.root', 'recreate'
49  )
50 
51  self.tree = ROOT.TTree('tree', 'Event data of PXD simulation')
52 
53  self.data = EventDataDigit()
54  # Declare tree branches
55  for key in EventDataDigit.__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 beginRun(self):
63  """ Does nothing """
64 
65  def event(self):
66  """Find digits with a clusters and save needed information."""
67 
68  # Start with clusters and use the relation to get the corresponding
69  # digits and truehits.
70  pxd_clusters = Belle2.PyStoreArray('PXDClusters')
71  for cluster in pxd_clusters:
72  cluster_truehits = cluster.getRelationsTo('PXDTrueHits')
73 
74  # Here we ask only for clusters with exactly one TrueHit.
75  if len(cluster_truehits) != 1:
76  continue
77 
78  cluster_digits = cluster.getRelationsTo('PXDDigits')
79  for digit in cluster_digits:
80  # Now let's store some data
81  # Event identification
82  self.data.exp = Belle2.PyStoreObj('EventMetaData').obj().getExperiment()
83  self.data.run = Belle2.PyStoreObj('EventMetaData').obj().getRun()
84  self.data.evt = Belle2.PyStoreObj('EventMetaData').obj().getEvent()
85  # Sesnor identification
86  vxd_id = digit.getSensorID()
87  self.data.vxd_id = vxd_id.getID()
88  self.data.layer = vxd_id.getLayerNumber()
89  self.data.ladder = vxd_id.getLadderNumber()
90  self.data.sensor = vxd_id.getSensorNumber()
91 # if vxd_id.getLayerNumber() == 1:
92 # continue
93 # if vxd_id.getSensorNumber() == 2:
94 # continue
95  # self.data.cluster_index = digit.getArrayIndex()
96  self.data.cluster_index = cluster.getArrayIndex()
97  # self.data.cluster_index = truehit.getArrayIndex()
98  # Get sensor geometry information
99  sensor_info = Belle2.VXD.GeoCache.get(vxd_id)
100  thickness = sensor_info.getThickness()
101  UPitch = sensor_info.getUPitch()
102  VPitch = sensor_info.getVPitch(digit.getVCellPosition())
103  self.data.pixel_type = (vxd_id.getLayerNumber() - 1) * 2
104  if vxd_id.getLayerNumber() == 1:
105  if VPitch > 0.0058:
106  self.data.pixel_type += 1
107  if vxd_id.getLayerNumber() == 2:
108  if VPitch > 0.0080:
109  self.data.pixel_type += 1
110  # Digit information
111  self.data.digit_u = digit.getUCellPosition()
112  self.data.digit_v = digit.getVCellPosition()
113  self.data.digit_uID = digit.getUCellID()
114  self.data.digit_vID = digit.getVCellID()
115  self.data.digit_charge = digit.getCharge()
116  # Fill tree
117  self.file.cd()
118  self.tree.Fill()
119 
120  def terminate(self):
121  """ Close the output file."""
122 
123  self.file.cd()
124  self.file.Write()
125  self.file.Close()
PXDValidationTTreeDigit.PXDValidationTTreeDigit.beginRun
def beginRun(self)
Definition: PXDValidationTTreeDigit.py:62
Belle2::VXD::GeoCache::get
static const SensorInfoBase & get(Belle2::VxdID id)
Return a reference to the SensorInfo of a given SensorID.
Definition: GeoCache.h:141
PXDValidationTTreeDigit.PXDValidationTTreeDigit.__init__
def __init__(self)
Definition: PXDValidationTTreeDigit.py:43
PXDValidationTTreeDigit.PXDValidationTTreeDigit.terminate
def terminate(self)
Definition: PXDValidationTTreeDigit.py:120
Belle2::PyStoreObj
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:69
PXDValidationTTreeDigit.PXDValidationTTreeDigit.file
file
Output ROOT file.
Definition: PXDValidationTTreeDigit.py:48
PXDValidationTTreeDigit.PXDValidationTTreeDigit.tree
tree
TTree for output data.
Definition: PXDValidationTTreeDigit.py:51
Belle2::getRun
static ExpRun getRun(map< ExpRun, pair< double, double >> runs, double t)
Get exp number + run number from time.
Definition: Splitter.cc:262
PXDValidationTTreeDigit.PXDValidationTTreeDigit
Definition: PXDValidationTTreeDigit.py:35
Belle2::PyStoreArray
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:58
PXDValidationTTreeDigit.PXDValidationTTreeDigit.event
def event(self)
Definition: PXDValidationTTreeDigit.py:65
PXDValidationTTreeDigit.PXDValidationTTreeDigit.data
data
Instance of EventData class.
Definition: PXDValidationTTreeDigit.py:53