Belle II Software development
Ntuple Class Reference
Inheritance diagram for Ntuple:

Public Member Functions

def initialize (self)
 
def event (self)
 
def terminate (self)
 

Public Attributes

 file
 root file
 
 tree
 root tree
 
 data
 data structure to be written to tree
 
 reso
 histogram of t0 residuals
 
 pull
 histogram of t0 pulls
 

Detailed Description

 makes ntuple for MC studies of TOPCosmicT0Finder performance 

Definition at line 66 of file testCosmicT0Finder.py.

Member Function Documentation

◆ event()

def event (   self)
 event processing: fill ntuple and histograms 

Definition at line 92 of file testCosmicT0Finder.py.

92 def event(self):
93 ''' event processing: fill ntuple and histograms '''
94
95 mcParticles = Belle2.PyStoreArray('MCParticles')
96 timeZeros = Belle2.PyStoreArray('TOPTimeZeros')
97 geo = Belle2.TOP.TOPGeometryPar.Instance().getGeometry()
98 for timeZero in timeZeros:
99 extHit = timeZero.getRelated('ExtHits')
100 if not extHit:
101 b2.B2WARNING('no related extHits')
102 continue
103 barHit = None
104 for barhit in mcParticles[0].getRelationsWith('TOPBarHits'):
105 if barhit.getModuleID() == extHit.getCopyID():
106 barHit = barhit
107 if not barHit:
108 b2.B2WARNING('no corresponding TOPBarHit')
109 continue
110
111 moduleID = timeZero.getModuleID()
112 if extHit.getCopyID() != moduleID:
113 b2.B2ERROR('moduleID in extHit differs: ' + str(extHit.getCopyID()) +
114 ' ' + str(moduleID))
115 if barHit.getModuleID() != moduleID:
116 b2.B2ERROR('moduleID in barHit differs: ' + str(barHit.getModuleID()) +
117 ' ' + str(moduleID))
118
119 self.data.slot = moduleID
120 self.data.nfot = timeZero.getNumPhotons()
121 self.data.pdg = barHit.getPDG()
122 pos = barHit.getLocalPosition()
123 self.data.x = pos.X()
124 self.data.y = pos.Y()
125 self.data.z = pos.Z()
126 self.data.t = barHit.getTime()
127 module = geo.getModule(moduleID)
128 mom = module.momentumToLocal(barHit.getMomentum())
129 self.data.p = mom.R()
130 self.data.theta = math.degrees(mom.Theta())
131 self.data.phi = math.degrees(mom.Phi())
132 dr = module.momentumToLocal(extHit.getPosition() - XYZVector(barHit.getPosition()))
133 self.data.dx = dr.X()
134 self.data.dy = dr.Y()
135 self.data.dz = dr.Z()
136 self.data.dt = extHit.getTOF() - self.data.t
137 momExt = module.momentumToLocal(extHit.getMomentum())
138 self.data.dp = momExt.R() - self.data.p
139 self.data.dtheta = math.degrees(momExt.Theta()) - self.data.theta
140 self.data.dphi = math.degrees(momExt.Phi()) - self.data.phi
141 self.data.t0 = timeZero.getTime()
142 self.data.t0err = timeZero.getError()
143 self.data.timeShift = timeShift
144 self.data.dt0 = self.data.dt + self.data.t0 - self.data.timeShift
145 self.file.cd()
146 self.tree.Fill()
147 self.reso.Fill(self.data.dt0)
148 self.pull.Fill(self.data.dt0/self.data.t0err)
149 if timeZero.getChi2().GetEntries() > 0:
150 timeZero.getChi2().Write()
151 timeZero.getPDF().Write()
152 timeZero.getHits().Write()
153
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.

◆ initialize()

def initialize (   self)
 initialize 

Definition at line 69 of file testCosmicT0Finder.py.

69 def initialize(self):
70 ''' initialize '''
71
72
73 self.file = ROOT.TFile('cosmicT0FinderNtuple.root', 'recreate')
74
75 self.tree = ROOT.TTree('tree', '')
76
77 self.data = TreeStruct()
78
79 for key in TreeStruct.__dict__.keys():
80 if '__' not in key:
81 formstring = '/F'
82 if isinstance(self.data.__getattribute__(key), int):
83 formstring = '/I'
84 self.tree.Branch(key, addressof(self.data, key), key + formstring)
85
86
87 self.reso = TH1F('reso', 'T0 residuals', 200, -1.0, 1.0)
88 self.reso.SetXTitle('#Delta t0 [ns]')
89
90 self.pull = TH1F('pull', 'T0 pulls', 200, -10.0, 10.0)
91

◆ terminate()

def terminate (   self)
 terminate: write and close root file 

Definition at line 154 of file testCosmicT0Finder.py.

154 def terminate(self):
155 ''' terminate: write and close root file '''
156
157 self.file.cd()
158 self.file.Write()
159 self.file.Close()
160
161
162# Suppress messages and warnings during processing:

Member Data Documentation

◆ data

data

data structure to be written to tree

Definition at line 77 of file testCosmicT0Finder.py.

◆ file

file

root file

Definition at line 73 of file testCosmicT0Finder.py.

◆ pull

pull

histogram of t0 pulls

Definition at line 90 of file testCosmicT0Finder.py.

◆ reso

reso

histogram of t0 residuals

Definition at line 87 of file testCosmicT0Finder.py.

◆ tree

tree

root tree

Definition at line 75 of file testCosmicT0Finder.py.


The documentation for this class was generated from the following file: